// // ActionsView.swift // Werkout_ios // // Created by Trey Tartt on 7/7/23. // import SwiftUI struct ActionsView: View { @ObservedObject var bridgeModule = BridgeModule.shared var completedWorkout: (() -> Void)? var planWorkout: ((Workout) -> Void)? var workout: Workout @Environment(\.dismiss) var dismiss var showAddToCalendar: Bool var startWorkoutAction: (() -> Void) @State var showCompleteSheet: Bool = false var body: some View { HStack { if bridgeModule.isInWorkout == false { Button(action: { bridgeModule.resetCurrentWorkout() dismiss() }, label: { Image(systemName: "xmark.octagon.fill") .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) }) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(.red) .foregroundColor(.white) .accessibilityLabel("Close workout") if showAddToCalendar { Button(action: { planWorkout?(workout) }, label: { Image(systemName: "calendar.badge.plus") .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) }) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(.blue) .foregroundColor(.white) .accessibilityLabel("Plan workout") } Button(action: { startWorkoutAction() }, label: { Image(systemName: "arrowtriangle.forward.fill") .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) }) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(.green) .foregroundColor(.white) .accessibilityLabel("Start workout") } else { Button(action: { showCompleteSheet.toggle() }, label: { Image(systemName: "checkmark") .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) }) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(.blue) .foregroundColor(.white) .accessibilityLabel("Complete workout") Button(action: { AudioEngine.shared.playFinished() bridgeModule.pauseWorkout() }, label: { bridgeModule.isPaused ? Image(systemName: "play.circle.fill") .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) : Image(systemName: "pause.circle.fill") .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) }) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(bridgeModule.isPaused ? .mint : .yellow) .foregroundColor(.white) .accessibilityLabel(bridgeModule.isPaused ? "Resume workout" : "Pause workout") Button(action: { AudioEngine.shared.playFinished() nextExercise() }, label: { Image(systemName: "arrow.forward") .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) }) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(.green) .foregroundColor(.white) .accessibilityLabel("Next exercise") } } .alert("Complete Workout", isPresented: $showCompleteSheet) { Button("Complete Workout", role: .destructive) { AudioEngine.shared.playFinished() completedWorkout?() } Button("Back to workout", role: .cancel) { } } } func nextExercise() { bridgeModule.nextExercise() } } struct ActionsView_Previews: PreviewProvider { static var previews: some View { ActionsView(workout: PreviewData.workout(), showAddToCalendar: true, startWorkoutAction: {}) } }