import SwiftUI
import Bedrock

struct RitualCardView: View {
    private let title: String
    private let theme: String
    private let dayLabel: String
    private let completionSummary: String
    private let iconName: String
    private let timeOfDay: TimeOfDay
    private let hasActiveArc: Bool

    init(
        title: String,
        theme: String,
        dayLabel: String,
        completionSummary: String,
        iconName: String = "sparkles",
        timeOfDay: TimeOfDay = .anytime,
        hasActiveArc: Bool = true
    ) {
        self.title = title
        self.theme = theme
        self.dayLabel = dayLabel
        self.completionSummary = completionSummary
        self.iconName = iconName
        self.timeOfDay = timeOfDay
        self.hasActiveArc = hasActiveArc
    }

    var body: some View {
        VStack(alignment: .leading, spacing: Design.Spacing.medium) {
            HStack(spacing: Design.Spacing.small) {
                // Icon
                Image(systemName: iconName)
                    .foregroundStyle(hasActiveArc ? AppAccent.primary : AppTextColors.tertiary)
                    .accessibilityHidden(true)
                
                // Title
                Text(title)
                    .font(.headline)
                    .foregroundStyle(hasActiveArc ? AppTextColors.primary : AppTextColors.tertiary)
                
                Spacer(minLength: Design.Spacing.medium)
                                
                // Day label
                Text(dayLabel)
                    .font(.caption)
                    .foregroundStyle(AppTextColors.secondary)
                    .padding(.horizontal, Design.Spacing.small)
                    .padding(.vertical, Design.Spacing.xxxSmall)
                    .background(AppAccent.light.opacity(Design.Opacity.light))
                    .clipShape(.rect(cornerRadius: Design.CornerRadius.medium))
                    .accessibilityLabel(Text(dayLabel))
            }
            
            Text(theme)
                .font(.subheadline)
                .foregroundStyle(hasActiveArc ? AppTextColors.secondary : AppTextColors.tertiary)
            
            Text(completionSummary)
                .font(.caption)
                .foregroundStyle(AppTextColors.secondary)
        }
        .padding(Design.Spacing.large)
        .background(AppSurface.card)
        .clipShape(.rect(cornerRadius: Design.CornerRadius.large))
        .opacity(hasActiveArc ? 1.0 : Design.Opacity.medium)
        .accessibilityElement(children: .combine)
    }
}

#Preview {
    VStack(spacing: Design.Spacing.medium) {
        RitualCardView(
            title: "Morning Clarity",
            theme: "Fresh starts",
            dayLabel: "Day 6 of 28",
            completionSummary: "2 of 3 habits complete",
            iconName: "sunrise.fill",
            timeOfDay: .morning,
            hasActiveArc: true
        )
        
        RitualCardView(
            title: "Midday Reset",
            theme: "Lunch break rituals",
            dayLabel: "Day 14 of 28",
            completionSummary: "1 of 2 habits complete",
            iconName: "sun.max.fill",
            timeOfDay: .midday,
            hasActiveArc: true
        )
        
        RitualCardView(
            title: "Evening Wind Down",
            theme: "Soft landings",
            dayLabel: "Day 14 of 28",
            completionSummary: "0 of 3 habits complete",
            iconName: "moon.stars.fill",
            timeOfDay: .evening,
            hasActiveArc: true
        )
        
        RitualCardView(
            title: "Flexible Routine",
            theme: "Anytime habits",
            dayLabel: "Day 7 of 21",
            completionSummary: "3 of 3 habits complete",
            iconName: "clock.fill",
            timeOfDay: .anytime,
            hasActiveArc: true
        )
    }
    .padding(Design.Spacing.large)
    .background(AppSurface.primary)
}
