//
//  ContentView.swift
//  OnCuePresenter Watch App
//
//  Created by Pradyun Setti on 22/06/2024.
//

import SwiftUI
import SwiftData

struct MainViewPresenter: View {
    @Environment(\.modelContext) private var modelContext
    @Query private var items: [OCProject]
    
    @State private var newProjectName = ""
    @State private var addNewProject = false
    
    var body: some View {
        NavigationSplitView {
            List {
                ForEach(items) { project in
                    NavigationLink {
                        CueCardViewPresenter(project: project)
                    } label: {
                        VStack(alignment: .leading) {
                            Text("\(project.name)")
                                .bold()
                                .font(.title2)
                                .foregroundStyle(Color(hex: project.color) ?? .white)
                            Text("\(project.cards.count) \(project.cards.count == 1 ? "Card" : "Cards")")
                        }
                    }
                    .padding(.vertical, 3)
                }
                
            }
            .toolbar {
                ToolbarItem(placement: .primaryAction) {
                    Button {
                        
                    } label: {
                        Label("Sync", systemImage: "arrow.triangle.2.circlepath")
                    }

                }
            }
            .navigationTitle("Projects")
        } detail: {
            Text("Select an item")
        }
    }
}

#Preview {
    let config = ModelConfiguration(isStoredInMemoryOnly: true)
    let container = try! ModelContainer(for: OCProject.self, configurations: config)
    
    container.mainContext.insert(PreviewData.project)
    
    return MainViewPresenter()
            .modelContainer(container)
}
