import SwiftUI

struct OnboardingView: View {
    @EnvironmentObject private var localization: LocalizationStore
    @EnvironmentObject private var analytics: HermesAnalyticsClient

    let onStartSession: () -> Void

    var body: some View {
        VStack(alignment: .leading, spacing: HermesTheme.sectionSpacing) {
            HermesSectionHeader(
                title: localization.string(for: "onboarding.title"),
                subtitle: localization.string(for: "onboarding.subtitle")
            )

            VStack(alignment: .leading, spacing: 12) {
                Label {
                    Text(localization.string(for: "onboarding.consent_body"))
                } icon: {
                    Image(systemName: "checkmark.shield.fill")
                        .foregroundStyle(HermesTheme.accent)
                }

                Text(localization.string(for: "onboarding.consent_note"))
                    .font(.callout)
                    .foregroundStyle(HermesTheme.textSecondary)
            }

            Button {
                analytics.track("consent_accepted", attributes: ["screen_name": "onboarding"])
                analytics.track("cta_pressed", attributes: ["screen_name": "onboarding", "action": "start_session"])
                onStartSession()
            } label: {
                Text(localization.string(for: "onboarding.start_session"))
            }
                .buttonStyle(HermesPrimaryButtonStyle())
        }
        .hermesCard(elevated: true)
        .onAppear {
            analytics.track("screen_viewed", attributes: ["screen_name": "onboarding"])
            analytics.track("consent_viewed", attributes: ["screen_name": "onboarding"])
        }
    }
}
