Files
SwimBuddy/targets/watch/Views/WorkoutDetailView.swift
T

80 lines
3.0 KiB
Swift

import SwiftUI
struct WorkoutDetailView: View {
@ObservedObject var workoutManager: WorkoutManager
var body: some View {
List {
if let workout = workoutManager.selectedWorkout {
Section {
VStack(spacing: 8) {
Text(workout.name ?? "Workout")
.font(.headline)
Text("\(Int(workout.poolLength))m pool")
.font(.caption)
.foregroundColor(.secondary)
let totalM = workout.sets.reduce(0) { $0 + $1.distancePerRep * $1.repCount }
Text("\(totalM)m total")
.font(.caption)
.foregroundColor(.secondary)
}
.frame(maxWidth: .infinity)
.padding(.vertical, 4)
}
Section("Sets") {
ForEach(Array(workout.sets.enumerated()), id: \.offset) { i, set in
VStack(alignment: .leading, spacing: 2) {
HStack {
Text("\(i + 1). \(set.stroke)")
.font(.body)
Spacer()
Text("\(set.repCount)x\(set.distancePerRep)m")
.font(.caption)
.foregroundColor(.secondary)
}
if set.restType != "none", set.restDuration > 0 {
HStack(spacing: 2) {
Spacer().frame(width: 14)
Image(systemName: "clock")
.font(.caption2)
.foregroundColor(.orange)
Text(String(format: "%ds rest", Int(set.restDuration)))
.font(.caption2)
.foregroundColor(.orange)
}
}
}
}
}
Section {
Button {
workoutManager.startWorkout()
} label: {
HStack {
Spacer()
Image(systemName: "play.fill")
Text("Start")
.font(.headline)
Spacer()
}
}
.buttonStyle(.borderedProminent)
.tint(.cyan)
Button("Back") {
workoutManager.selectedWorkout = nil
}
.font(.caption)
.foregroundColor(.secondary)
.frame(maxWidth: .infinity)
}
}
}
.listStyle(.automatic)
}
}