import SwiftUI struct ContentView: View { @StateObject private var workoutManager = WorkoutManager() var body: some View { NavigationView { VStack(spacing: 16) { if workoutManager.isWorkoutActive { ActiveWorkoutView(workoutManager: workoutManager) } else { WorkoutListView(workoutManager: workoutManager) } } .navigationTitle("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) } } 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.totalDistance)m ยท \(workout.sets.count) sets") .font(.caption) .foregroundColor(.secondary) } Spacer() Image(systemName: "chevron.right") .foregroundColor(.secondary) .font(.caption) } } } } 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) } } } } } } .listStyle(.grouped) .onAppear { workoutManager.loadSavedWorkouts() } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }