import SwiftUI

struct HotkeySettingsView: View {
    @ObservedObject private var settingsController = AppSettingsController.shared

    var body: some View {
        Form {
            Section("Global") {
                HotkeyRecorderView(label: "Toggle notch", binding: settingsController.binding(\.hotkeys.toggle))
            }

            Section("Terminal Tabs (active when notch is open)") {
                HotkeyRecorderView(label: "New tab", binding: settingsController.binding(\.hotkeys.newTab))
                HotkeyRecorderView(label: "Close tab", binding: settingsController.binding(\.hotkeys.closeTab))
                HotkeyRecorderView(label: "Next tab", binding: settingsController.binding(\.hotkeys.nextTab))
                HotkeyRecorderView(label: "Previous tab", binding: settingsController.binding(\.hotkeys.previousTab))
                HotkeyRecorderView(label: "Detach tab", binding: settingsController.binding(\.hotkeys.detachTab))
            }

            Section("Workspaces (active when notch is open)") {
                HotkeyRecorderView(label: "Next workspace", binding: settingsController.binding(\.hotkeys.nextWorkspace))
                HotkeyRecorderView(label: "Previous workspace", binding: settingsController.binding(\.hotkeys.previousWorkspace))
            }

            Section {
                Text("⌘1–9 always switch to tab by number. Size preset hotkeys are configured in Terminal > Size Presets. Per-workspace jump hotkeys are configured in Workspaces.")
                    .font(.caption)
                    .foregroundStyle(.secondary)
            }

            Section {
                Button("Reset to Defaults") {
                    settingsController.update {
                        $0.hotkeys = AppSettings.default.hotkeys
                    }
                }
            }
        }
        .formStyle(.grouped)
    }
}
