//
// SettingsSheet.swift
// IceGlass-iOS
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//

import IndieAbout
import SwiftUI

struct SettingsSheet: View {
    @Environment(ScoreboardViewModel.self) private var viewModel
    @Environment(\.dismiss) private var dismiss

    var body: some View {
        @Bindable var vm = viewModel
        NavigationStack {
            Form {
                Section("Display") {
                    Picker("Days shown", selection: Binding(
                        get: { vm.displayOption },
                        set: { newValue in
                            vm.displayOption = newValue
                            MainService.shared.updateUI()
                        }
                    )) {
                        ForEach(AppSettings.DisplayOption.allCases, id: \.self) { option in
                            Text(option.title).tag(option)
                        }
                    }
                    .pickerStyle(.inline)
                    .labelsHidden()
                }

                Section {
                    IndieAbout(configuration: AppInfoConfiguration(
                        showDeviceInfo: false,
                        documents: [
                            .license(filename: "LICENSE", extension: "md"),
                            .custom(title: "Changelog", filename: "CHANGELOG", extension: "md")
                        ]
                    ))
                }
            }
            .navigationTitle("Settings")
            .navigationBarTitleDisplayMode(.inline)
            .toolbar {
                ToolbarItem(placement: .topBarTrailing) {
                    Button("Done") { dismiss() }
                }
            }
        }
    }
}
