// // WeeklyDigestCardView.swift // Reflect // // Displays the AI-generated weekly emotional digest card in the Insights tab. // import SwiftUI struct WeeklyDigestCardView: View { let digest: WeeklyDigest let onDismiss: () -> Void @AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system private var textColor: Color { theme.currentTheme.labelColor } private var accentColor: Color { moodTint.color(forMood: .good) } @State private var appeared = false var body: some View { VStack(alignment: .leading, spacing: 16) { // Header HStack { Image(systemName: digest.iconName) .font(.title2) .foregroundStyle(accentColor) VStack(alignment: .leading, spacing: 2) { Text(String(localized: "Weekly Digest")) .font(.caption) .fontWeight(.semibold) .foregroundStyle(.secondary) .textCase(.uppercase) Text(digest.headline) .font(.headline) .foregroundColor(textColor) } Spacer() Button { WeeklyDigest.markDismissed() withAnimation(.easeInOut(duration: 0.3)) { onDismiss() } } label: { Image(systemName: "xmark.circle.fill") .font(.title3) .foregroundStyle(.tertiary) } .accessibilityLabel(String(localized: "Dismiss digest")) .accessibilityIdentifier(AccessibilityID.WeeklyDigest.dismissButton) } // Summary Text(digest.summary) .font(.subheadline) .foregroundColor(textColor) .fixedSize(horizontal: false, vertical: true) Divider() // Highlight HStack(alignment: .top, spacing: 10) { Image(systemName: "star.fill") .font(.caption) .foregroundStyle(.yellow) .padding(.top, 2) Text(digest.highlight) .font(.subheadline) .foregroundColor(textColor) .fixedSize(horizontal: false, vertical: true) } // Intention HStack(alignment: .top, spacing: 10) { Image(systemName: "arrow.right.circle.fill") .font(.caption) .foregroundStyle(accentColor) .padding(.top, 2) Text(digest.intention) .font(.subheadline) .foregroundColor(.secondary) .fixedSize(horizontal: false, vertical: true) } // Date range Text(dateRangeString) .font(.caption2) .foregroundStyle(.tertiary) } .padding(20) .background( RoundedRectangle(cornerRadius: 20) .fill(Color(.secondarySystemBackground)) .overlay( RoundedRectangle(cornerRadius: 20) .stroke( LinearGradient( colors: [accentColor.opacity(0.3), .purple.opacity(0.2)], startPoint: .topLeading, endPoint: .bottomTrailing ), lineWidth: 1 ) ) ) .padding(.horizontal) .opacity(appeared ? 1 : 0) .offset(y: appeared ? 0 : 10) .onAppear { withAnimation(.easeOut(duration: 0.4)) { appeared = true } } .accessibilityIdentifier(AccessibilityID.WeeklyDigest.card) } private var dateRangeString: String { let formatter = DateFormatter() formatter.dateStyle = .medium return "\(formatter.string(from: digest.weekStartDate)) - \(formatter.string(from: digest.weekEndDate))" } }