// // PlannedWorkoutView.swift // Werkout_ios // // Created by Trey Tartt on 6/18/24. // import SwiftUI struct PlannedWorkoutView: View { let workouts: [PlannedWorkout] @Binding var selectedPlannedWorkout: Workout? private var sortedWorkouts: [PlannedWorkout] { workouts.sorted(by: { $0.onDate < $1.onDate }) } var body: some View { ScrollView { LazyVStack(spacing: WerkoutTheme.sm) { ForEach(sortedWorkouts, id: \.id) { plannedWorkout in Button(action: { selectedPlannedWorkout = plannedWorkout.workout }, label: { HStack(spacing: WerkoutTheme.md) { VStack(spacing: WerkoutTheme.xs) { Text(plannedWorkout.onDate.plannedDate?.weekDay ?? "-") .font(WerkoutTheme.caption) .foregroundStyle(WerkoutTheme.accent) Text(plannedWorkout.onDate.plannedDate?.dateString ?? "-") .font(.system(size: 28, weight: .black, design: .monospaced)) .foregroundStyle(WerkoutTheme.accent) Text(plannedWorkout.onDate.plannedDate?.monthString ?? "-") .font(WerkoutTheme.caption) .foregroundStyle(WerkoutTheme.textSecondary) } .frame(width: 60) WerkoutTheme.divider.frame(width: 0.5) VStack(alignment: .leading, spacing: WerkoutTheme.xs) { Text(plannedWorkout.workout.name) .font(WerkoutTheme.cardTitle) .foregroundStyle(WerkoutTheme.textPrimary) Text(plannedWorkout.workout.description ?? "") .font(WerkoutTheme.bodyText) .foregroundStyle(WerkoutTheme.textSecondary) } .frame(maxWidth: .infinity, alignment: .leading) } .werkoutCard() }) .buttonStyle(.plain) .accessibilityLabel("Open planned workout \(plannedWorkout.workout.name)") .accessibilityHint("Shows workout details") } } .padding(.horizontal, WerkoutTheme.sm) } .scrollEdgeEffectStyle(.soft, for: .top) } }