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

import SwiftUI

struct MainWatchView: View {
    @StateObject var vm = WatchMainViewModel.shared
    
    var body: some View {
        VStack {
            HStack {
                if vm.isInWorkout {
                    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 = vm.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)
                }
                
                if vm.isInWorkout {
                    Button(action: {
                        vm.nextExercise()
                    }, label: {
                        Image(systemName: "arrow.forward")
                            .font(.title)
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                    })
                    .buttonStyle(BorderedButtonStyle(tint: .green))
                } else {
                    VStack {
                        Text("No Werkout")
                        Text("🍑")
                    }
                }
            }
        }
    }
}

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