import SwiftUI

public struct SettingsView: View {
    @Environment(AppModel.self) private var model

    public init() {}

    public var body: some View {
        Form {
            Section("Radio Browser") {
                TextField("Base URL", text: Binding(
                    get: { model.settings.radioBrowserBaseURL },
                    set: {
                        model.settings.radioBrowserBaseURL = $0
                        model.applySettings()
                    }
                ))
                .textFieldStyle(.roundedBorder)
            }

            Section("Playback") {
                Toggle("Resume last station on launch", isOn: Binding(
                    get: { model.settings.resumeOnLaunch },
                    set: { model.settings.resumeOnLaunch = $0 }
                ))
            }

            Section("Menu Bar") {
                Toggle("Show playback details in menu bar", isOn: Binding(
                    get: { model.settings.showMenuBarExtraDetails },
                    set: { model.settings.showMenuBarExtraDetails = $0 }
                ))
            }
        }
        .formStyle(.grouped)
        .padding(20)
    }
}
