//
//  ConfirmButtonView.swift
//  PadelClub
//
//  Created by razmig on 21/08/2024.
//

import SwiftUI

struct ConfirmButtonView<T:View>: View {
    @State private var showingConfirmDialog = false
    @State private var actionConfirmed = false
    
    var shouldConfirm: Bool
    var message: String
    var confirmButtonText: String = "OK"
    var cancelButtonText: String = "Annuler"
    var onConfirm: () -> Void
    var label: () -> T

    var body: some View {
        Button {
            if shouldConfirm {
                showingConfirmDialog = true
            } else {
                onConfirm()
            }
        } label: {
            label()
        }
        .confirmationDialog("Attention", isPresented: $showingConfirmDialog) {
            Button(confirmButtonText, role: .destructive) {
                onConfirm()
            }
            Button(cancelButtonText, role: .cancel) { }
        } message: {
            Text(message)
        }
    }
}
