import SwiftUI struct ContentView: View { @EnvironmentObject var workoutManager: WorkoutManager var body: some View { NavigationView { VStack(spacing: 16) { if workoutManager.workoutSummary != nil { WorkoutSummaryView(workoutManager: workoutManager) } else if workoutManager.isWorkoutActive { ActiveWorkoutView(workoutManager: workoutManager) } else if workoutManager.selectedWorkout != nil { WorkoutDetailView(workoutManager: workoutManager) } else { WorkoutListView(workoutManager: workoutManager) } } .navigationTitle(workoutManager.isWorkoutActive ? "" : "SwimBuddy") } } } struct WorkoutListView: View { @ObservedObject var workoutManager: WorkoutManager var body: some View { List { if workoutManager.savedWorkouts.isEmpty { Section { VStack(spacing: 12) { Image(systemName: "figure.pool.swim") .font(.system(size: 40)) .foregroundColor(.cyan) Text("No workouts yet") .font(.headline) .foregroundColor(.secondary) Text("Create a workout on your iPhone to get started") .font(.caption) .foregroundColor(.secondary) .multilineTextAlignment(.center) } .frame(maxWidth: .infinity) .padding(.vertical, 20) .listRowBackground(.clear) } } else { Section("Saved Workouts") { ForEach(workoutManager.savedWorkouts) { (workout: StoredWorkout) in Button { workoutManager.selectWorkout(workout) } label: { HStack { VStack(alignment: .leading, spacing: 4) { Text(workout.name ?? "Workout") .font(.headline) .foregroundColor(.primary) Text("\(workout.sets.reduce(0) { $0 + $1.distancePerRep * $1.repCount })m ยท \(workout.sets.count) sets") .font(.caption) .foregroundColor(.secondary) } Spacer() Image(systemName: "chevron.right") .foregroundColor(.secondary) .font(.caption) } } .listRowBackground(.clear) } .onDelete { indexSet in workoutManager.deleteSavedWorkouts(at: indexSet) } } if workoutManager.completedWorkouts.count > 0 { Section("Recent") { ForEach(workoutManager.completedWorkouts.prefix(3)) { workout in HStack { VStack(alignment: .leading, spacing: 2) { Text(workout.name ?? "Workout") .font(.subheadline) .foregroundColor(.primary) Text(workout.completedAt ?? "") .font(.caption2) .foregroundColor(.secondary) } Spacer() Image(systemName: "checkmark.circle.fill") .foregroundColor(.green) .font(.caption) } .listRowBackground(.clear) } .onDelete { indexSet in workoutManager.deleteCompletedWorkouts(at: indexSet) } } } } } .listStyle(.automatic) .onAppear { workoutManager.loadSavedWorkouts() } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }