import SwiftUI
import AoqClientSdk

struct ContentView: View {
    private let columns = [
        GridItem(.flexible(), spacing: 16),
        GridItem(.flexible(), spacing: 16)
    ]

    var body: some View {
        NavigationStack {
            ScrollView {
                LazyVGrid(columns: columns, spacing: 16) {
                    ForEach(FeatureItem.allCases) { item in
                        NavigationLink(value: item) {
                            FeatureCard(item: item)
                        }
                        .buttonStyle(.plain)
                    }
                }
                .padding(16)
            }
            .background(Color(uiColor: .systemGroupedBackground))
            .navigationTitle("AOQ Client Demo")
            .navigationDestination(for: FeatureItem.self) { item in
                destinationView(for: item)
            }
        }
    }

    @ViewBuilder
    private func destinationView(for item: FeatureItem) -> some View {
        switch item {
        case .audioDevice:
            AudioDeviceView()
        case .videoDevice:
            VideoDeviceView()
        case .videoUnderstand:
            VideoUnderstandingView()
        case .phoneCall:
            PhoneCallView()
        case .settings:
            SettingsView()
        }
    }
}

// MARK: - Feature Card

private struct FeatureCard: View {
    let item: FeatureItem

    var body: some View {
        VStack(spacing: 12) {
            Image(systemName: item.icon)
                .font(.system(size: 36))
                .foregroundStyle(item.color)
                .frame(height: 44)

            Text(item.title)
                .font(.headline)
                .foregroundStyle(.primary)

            Text(item.description)
                .font(.caption)
                .foregroundStyle(.secondary)
                .multilineTextAlignment(.center)
                .lineLimit(2)
        }
        .frame(maxWidth: .infinity)
        .padding(.vertical, 20)
        .padding(.horizontal, 12)
        .background(Color(uiColor: .secondarySystemGroupedBackground))
        .cornerRadius(16)
        .shadow(color: .black.opacity(0.05), radius: 4, x: 0, y: 2)
    }
}

#Preview {
    ContentView()
}
