//
//  ExtCountdownView.swift
//  Werkout_ios
//
//  Created by Trey Tartt on 6/17/24.
//

import SwiftUI

struct ExtCountdownView: View {
    @StateObject var bridgeModule = BridgeModule.shared
    
    var body: some View {
        GeometryReader { metrics in
            VStack {
                if let currenExercise = bridgeModule.currentExerciseInfo.currentExercise {
                    HStack {
                        Text(currenExercise.exercise.extName)
                            .font(.system(size: 200))
                            .scaledToFit()
                            .minimumScaleFactor(0.01)
                            .lineLimit(1)
                            .frame(maxWidth: .infinity, alignment: .leading)
                    }
                    .frame(height: metrics.size.height * 0.5)
                    
                    HStack {
                        if let duration = currenExercise.duration,
                           duration > 0 {
                            ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
                                .scaleEffect(x: 1, y: 6, anchor: .center)
                            Text("\(bridgeModule.currentExerciseTimeLeft)")
                                .font(Font.system(size: 100))
                                .scaledToFit()
                                .minimumScaleFactor(0.01)
                                .lineLimit(1)
                                .padding(.leading)
                                .padding(.trailing, 100)
                        }
                        
                        if let reps = currenExercise.reps,
                           reps > 0 {
                            Text(" X \(reps)")
                                .font(Font.system(size: 100))
                                .scaledToFit()
                                .minimumScaleFactor(0.01)
                                .lineLimit(1)
                                .frame(maxWidth: .infinity, alignment: .leading)
                        }
                        
                        if let weight = currenExercise.weight,
                           weight > 0 {
                            Text(" @ \(weight)")
                                .font(Font.system(size: 100))
                                .scaledToFit()
                                .minimumScaleFactor(0.01)
                                .lineLimit(1)
                                .padding(.trailing, 100)
                                .frame(maxWidth: .infinity, alignment: .leading)
                        }
                    }
                    .frame(height: metrics.size.height * 0.5)
                }
            }
        }
    }
}

#Preview {
    ExtCountdownView()
}
