import SwiftUI

@main
struct RebreakMagicApp: App {
    @State private var model = WizardModel()

    var body: some Scene {
        WindowGroup("Rebreak Magic") {
            ContentView()
                .environment(model)
                .frame(minWidth: 720, idealWidth: 800, minHeight: 600, idealHeight: 720)
        }
        .windowResizability(.contentSize)
        .windowStyle(.titleBar)
        .commands {
            CommandMenu("Account") {
                Button("Abmelden") {
                    Task { await model.handleLogout() }
                }
                .keyboardShortcut("l", modifiers: [.command, .shift])
                .disabled(model.authSession == nil)
            }
            
#if DEBUG
            CommandMenu("Aktionen") {
                Menu("Debug Supervision Mode") {
                    Button(DebugSupervisionMode.none.title) {
                        model.supervisionMode = .none
                    }
                    Button(DebugSupervisionMode.forceSupervised.title) {
                        model.supervisionMode = .forceSupervised
                    }
                    Button(DebugSupervisionMode.forceUnsupervised.title) {
                        model.supervisionMode = .forceUnsupervised
                    }
                }

                Toggle("Profile + App entfernen", isOn: $model.resetAll)
                Toggle("MDM Enrollment-Profil", isOn: $model.resetEnrollmentProfile)
                    .disabled(model.resetAll)
                Toggle("Lock-Profil", isOn: $model.resetLockProfile)
                    .disabled(model.resetAll)
                Toggle("ReBreak-App", isOn: $model.resetApp)
                    .disabled(model.resetAll)

                Divider()

                Button("Debug-Reset ausführen") {
                    model.startDebugReset()
                }
                .keyboardShortcut("r", modifiers: [.command, .shift, .option])
                .disabled(model.device == nil || model.resetRunning)
            }
#endif
        }
    }
}
