import SwiftUI
import Bedrock

struct HabitRowModel: Identifiable {
    let id: UUID
    let title: String
    let symbolName: String
    let isCompleted: Bool
    let action: () -> Void
}

struct TodayRitualSectionView: View {
    let focusTitle: String
    let focusTheme: String
    let dayLabel: String
    let completionSummary: String
    let progress: Double
    let habitRows: [HabitRowModel]
    var iconName: String = "sparkles"
    var timeOfDay: TimeOfDay = .anytime

    var body: some View {
        VStack(alignment: .leading, spacing: Bedrock.Design.Spacing.large) {
            // Section header with time indicator
            HStack {
                VStack(alignment: .leading, spacing: Bedrock.Design.Spacing.xSmall) {
                    Text(focusTitle)
                        .font(.headline)
                        .foregroundStyle(AppTextColors.primary)
                    Text(focusTheme)
                        .font(.subheadline)
                        .foregroundStyle(AppTextColors.secondary)
                }
                
                Spacer()
                
                // Time of day indicator
                Image(systemName: timeOfDay.symbolName)
                    .foregroundStyle(AppTextColors.tertiary)
                    .accessibilityLabel(timeOfDay.displayName)
            }

            focusCard

            SectionHeaderView(
                title: String(localized: "Habits"),
                subtitle: String(localized: "Tap to check in")
            )

            habitsList
        }
    }

    private var focusCard: some View {
        RitualFocusCardView(
            title: focusTitle,
            theme: focusTheme,
            dayLabel: dayLabel,
            completionSummary: completionSummary,
            progress: progress,
            iconName: iconName
        )
    }

    private var habitsList: some View {
        VStack(spacing: Bedrock.Design.Spacing.medium) {
            ForEach(habitRows) { habit in
                TodayHabitRowView(
                    title: habit.title,
                    symbolName: habit.symbolName,
                    isCompleted: habit.isCompleted,
                    action: habit.action
                )
            }
        }
    }
}

#Preview {
    TodayRitualSectionView(
        focusTitle: "Morning Flow",
        focusTheme: "Light and steady",
        dayLabel: "Day 3 of 28",
        completionSummary: "2 of 3 habits complete",
        progress: 0.66,
        habitRows: [
            HabitRowModel(id: UUID(), title: "Hydrate", symbolName: "drop.fill", isCompleted: true, action: {}),
            HabitRowModel(id: UUID(), title: "Move", symbolName: "figure.walk", isCompleted: false, action: {})
        ],
        iconName: "sunrise.fill",
        timeOfDay: .morning
    )
}
