summaryrefslogtreecommitdiff
path: root/DayByDay/SeasonCard.swift
blob: c84dfb61353a5a7f7fe5d2160173f2edbb72bfc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
//  SeasonCard.swift
//  DayByDay
//

import SwiftUI

/// A single large, colorful card representing one season.
/// Tapping the card plays a bounce animation and speaks the season name aloud.
struct SeasonCard: View {
    let season: Season
    var isHighlighted = false
    @State private var isTapped = false

    var body: some View {
        ZStack {
            RoundedRectangle(cornerRadius: 32, style: .continuous)
                .fill(season.color.gradient)
                .shadow(color: season.color.opacity(0.4), radius: 8, y: 4)

            VStack(spacing: 16) {
                Image(systemName: season.symbol)
                    .font(.system(size: 64))
                    .foregroundStyle(.white)
                    .symbolRenderingMode(.hierarchical)

                Text(season.name)
                    .font(.system(size: 32, weight: .bold, design: .rounded))
                    .foregroundStyle(.white)
            }
        }
        .overlay {
            if isHighlighted {
                RoundedRectangle(cornerRadius: 32, style: .continuous)
                    .strokeBorder(.white, lineWidth: 5)
            }
        }
        .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
        .scaleEffect(isTapped ? 1.12 : (isHighlighted ? 1.04 : 1.0))
        .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
        .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
        .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
        .onTapGesture {
            isTapped = true
            SpeechSynthesizer.shared.speak(season.name)
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
                isTapped = false
            }
        }
        .accessibilityLabel(season.name)
        .accessibilityAddTraits(.isButton)
    }
}

// MARK: - Season model

enum Season: Int, CaseIterable, Identifiable {
    case spring, summer, fall, winter

    var id: Int { rawValue }

    /// The season for today's date.
    /// Spring: March–May, Summer: June–August,
    /// Fall: September–November, Winter: December–February.
    static var current: Season {
        let month = Calendar.current.component(.month, from: Date())
        switch month {
        case 3...5:  return .spring
        case 6...8:  return .summer
        case 9...11: return .fall
        default:     return .winter
        }
    }

    var name: String {
        switch self {
        case .spring: "Spring"
        case .summer: "Summer"
        case .fall:   "Fall"
        case .winter: "Winter"
        }
    }

    var symbol: String {
        switch self {
        case .spring: "leaf.fill"
        case .summer: "sun.max.fill"
        case .fall:   "wind"
        case .winter: "snowflake"
        }
    }

    var color: Color {
        switch self {
        case .spring: Color(red: 0.45, green: 0.8, blue: 0.5)   // fresh green
        case .summer: Color(red: 1.0, green: 0.6, blue: 0.15)   // sunny orange
        case .fall:   Color(red: 0.85, green: 0.45, blue: 0.2)  // autumn orange
        case .winter: Color(red: 0.4, green: 0.65, blue: 0.95)  // cool blue
        }
    }
}

#Preview {
    HStack(spacing: 24) {
        SeasonCard(season: .spring, isHighlighted: true)
            .frame(width: 200, height: 260)
        SeasonCard(season: .summer)
            .frame(width: 200, height: 260)
    }
    .padding()
}