//
//  MainView.swift
//  Werkout_watch Watch App
//
//  Created by Trey Tartt on 7/8/23.
//

import SwiftUI

struct MainWatchView: View {
    @ObservedObject var vm = WatchMainViewModel.shared
    @ObservedObject var watchWorkout = WatchWorkout.shared
    
    var body: some View {
        VStack {
            if watchWorkout.isInWorkout {
                HStack {
                    
                    Text(vm.watchPackageModel.currentExerciseName)
                        .font(.body)
                        .foregroundColor(.white)
                        .lineLimit(10)
                        .fixedSize(horizontal: false, vertical: true)
                        .frame(maxWidth: .infinity, alignment: .leading)
                    Divider()
                    Text("\(vm.watchPackageModel.currentTimeLeft )")
                        .font(.title)
                        .foregroundColor(.white)
                        .lineLimit(10)
                        .fixedSize(horizontal: false, vertical: true)
                }
                
                
                HStack {
                    if let heartValue = watchWorkout.heartValue {
                        VStack {
                            Image(systemName: "heart.fill")
                                .font(Font.system(size: 22))
                                .scaledToFit()
                                .minimumScaleFactor(0.01)
                                .lineLimit(1)
                                .foregroundColor(.red)
                            Text("\(heartValue)")
                                .font(Font.system(size: 55))
                                .scaledToFit()
                                .minimumScaleFactor(0.01)
                                .lineLimit(1)
                                .foregroundColor(.red)
                        }
                        .frame(maxWidth: .infinity, maxHeight: .infinity)
                    }
                    
                    Button(action: {
                        vm.nextExercise()
                    }, label: {
                        Image(systemName: "arrow.forward")
                            .font(.title)
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                    })
                    .buttonStyle(BorderedButtonStyle(tint: .green))
                }
            } else {
                Text("No Werkout")
                Text("🍑")
            }
        }
    }
}

struct MainView_Previews: PreviewProvider {
    static var previews: some View {
        MainWatchView()
    }
}
