//
//  PauseView.swift
//  Gran Fondo
//
//  Created by Willem L. Middelkoop on 27/05/2024.
//

import SwiftUI

struct PauseView: View {
    
    @Environment(\.presentationMode) var presentationMode
    @EnvironmentObject var bluetoothManager: BluetoothManager
    @EnvironmentObject var activityRecorder: ActivityRecorder
    
    
    var body: some View {
        
        VStack(alignment: .center, spacing: 0){
            HStack{
                VStack{
                    Text("paused")
                        .font(.system(size: 20))
                        .fontWeight(.bold)
                        .textCase(.uppercase)
                        .foregroundColor(.yellow)
                    Text(activityRecorder.getDistanceString(activityRecorder.totalDistance))
                        .font(.system(size: 50).monospacedDigit())
                        .foregroundColor(.white)
                        .lineLimit(1)
                        .allowsTightening(false)
                        .frame(minWidth: 100, alignment: .center)
                }
                .padding()
                .frame(maxWidth: .infinity)
            }
            
            .padding()
            .background(Color(red: 0.2, green: 0.2, blue: 0.2))
            
            VStack(alignment: .center){
                VStack {
                    Button(action: {
                        /*
                         isSaving = true
                         showStopConfirmation = false
                         withAnimation {
                         activityRecorder.stopRecording { success in
                         print("ContentVIew: recordingButton completion handler succes")
                         isSaving = false  // Enable the button once saving is complete
                         }
                         }*/
                        
                        activityRecorder.stopRecording()
                        
                    }) {
                        HStack {
                            Text("END")
                                .frame(alignment: .center)
                                .fontWeight(.bold)
                                .font(.system(size: 30)
                                    .monospacedDigit())
                                .frame(height: 30)
                                .padding()
                                .foregroundColor(.white)
                        }
                        .frame(height:30)
                        .frame(maxWidth: .infinity, alignment: .center)
                        .padding()
                        .background(Color.red)
                        .foregroundColor(.white)
                        .clipShape(Capsule())
                    }
                    Text("Save recording")
                        .font(.system(size: 10))
                        .fontWeight(.bold)
                        .textCase(.uppercase)
                        .foregroundColor(.white)
                }
                
                Spacer(minLength: 20)
                  VStack {
                    Button(action: {
                        activityRecorder.resumeRecording()
                    }) {
                        HStack {
                            Text("CONTINUE")
                                .frame(alignment: .center)
                                .fontWeight(.bold)
                                .font(.system(size: 30)
                                    .monospacedDigit())
                                .frame(height: 30)
                                .padding()
                                .foregroundColor(.white)
                        }
                        .frame(height:30)
                        .frame(maxWidth: .infinity, alignment: .center)
                        .padding()
                        .background(Color.green)
                        .foregroundColor(.white)
                        .clipShape(Capsule())
                    }
                    Text("Resume recording")
                        .font(.system(size: 10))
                        .fontWeight(.bold)
                        .textCase(.uppercase)
                        .foregroundColor(.white)
                }
                
            }   // vstack with buttons
            .padding(.horizontal)
            .padding(.bottom, 10)
            .padding(.top, 10)
            .background(Color(red: 0.2, green: 0.2, blue: 0.2))
            
        } // vstack of view
    }
}
