//
//  HelloVisionOSApp.swift
//  HelloVisionOS - Niall George Horn - June 2026
//
//  ImmersiveSpace + head-anchored ControlPanel.
//
//  LAUNCH REQUIREMENT: always use `./deploy/launch.sh` (or the equivalent full
//  FrontBoard clear cycle). Do NOT relaunch from within Simulator.app — visionOS
//  writes an SFBSystemService scene session to FrontBoard when ImmersiveSpace opens;
//  without clearing it first the app crashes on the next cold-start. launch.sh
//  handles this automatically. (How many crashes did this cause... too many!)
//

import SwiftUI
import UIKit

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     shouldSaveSecureApplicationState coder: NSCoder) -> Bool { false }
    func application(_ application: UIApplication,
                     shouldRestoreSecureApplicationState coder: NSCoder) -> Bool { false }
}

@main
struct HelloVisionOSApp: App {

    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
    @State private var appModel = AppModel()

    var body: some Scene {
        // Minimal launcher window — opens the ImmersiveSpace immediately, hopefully...
        WindowGroup(id: "main") {
            ContentView()
                .environment(appModel)
        }
        .defaultSize(width: 80, height: 80)

        ImmersiveSpace(id: "ImmersiveSpace") {
            ImmersiveView()
                .environment(appModel)
        }
        .immersionStyle(selection: .constant(.mixed), in: .mixed)
    }
}
