//
//  ContentView.swift
//  StackDex
//
//  Created by Matthias Meister on 18.04.26.
//

import SwiftData
import SwiftUI

struct ContentView: View {
    @StateObject private var flowModel = ScanFlowModel()

    var body: some View {
        NavigationStack(path: $flowModel.path) {
            ScanView(flowModel: flowModel)
                .navigationDestination(for: ScanRoute.self) { route in
                    switch route {
                    case .result:
                        ResultEditorView(flowModel: flowModel, mode: .recognized)
                    case .manual:
                        ResultEditorView(flowModel: flowModel, mode: .manual)
                    }
                }
                .task {
                    flowModel.startObservers()
                    await flowModel.prepareVisibleServices()
                }
                .onDisappear {
                    flowModel.stopObservers()
                }
        }
    }
}

#Preview {
    ContentView()
        .modelContainer(for: ConfirmedScanRecord.self, inMemory: true)
}
