//
//  PlannedWorkoutView.swift
//  Werkout_ios
//
//  Created by Trey Tartt on 6/18/24.
//

import SwiftUI

struct PlannedWorkoutView: View {
    let workouts: [PlannedWorkout]
    @Binding var selectedPlannedWorkout: Workout?
    
    var body: some View {
        List {
            ForEach(workouts, id:\.workout.name) { plannedWorkout in
                HStack {
                    VStack(alignment: .leading) {
                        Text(plannedWorkout.onDate.plannedDate?.weekDay ?? "-")
                            .font(.title)
                        
                        Text(plannedWorkout.onDate.plannedDate?.monthString ?? "-")
                            .font(.title)
                        
                        Text(plannedWorkout.onDate.plannedDate?.dateString ?? "-")
                            .font(.title)
                    }
                    
                    Divider()
                    
                    VStack {
                        Text(plannedWorkout.workout.name)
                            .font(.title)
                            .frame(maxWidth: .infinity, alignment: .leading)
                        
                        Text(plannedWorkout.workout.description ?? "")
                            .font(.body)
                            .frame(maxWidth: .infinity, alignment: .leading)
                        
                        Text(plannedWorkout.onDate)
                            .font(.footnote)
                            .frame(maxWidth: .infinity, alignment: .leading)
                    }
                    .contentShape(Rectangle())
                    .onTapGesture {
                        selectedPlannedWorkout = plannedWorkout.workout
                    }
                }
            }
        }
    }
}

//#Preview {
//    PlannedWorkoutView()
//}
