//
//  AccountView.swift
//  PadelClub
//
//  Created by Laurent Morvillier on 21/02/2024.
//

import SwiftUI
import LeStorage

struct AccountView: View {
    
    var user: User
    var handler: () -> ()
    
    var body: some View {
        Form {
            Section {
                NavigationLink("Changer de mot de passe") {
                    ChangePasswordView()
                }
            }
            Section {
                RowButtonView("Déconnexion", role: .destructive) {
                    DataStore.shared.disconnect()
                    handler()
                }
            }
            Section {
                RowButtonView("Supprimer mon compte", role: .destructive, confirmationMessage: "Voulez-vous vraiment supprimer définitivement votre compte et ses données associées ?") {
                    DataStore.shared.deleteAccount()
                    handler()
                }
            }
        }.navigationTitle(user.username)
    }
}

//#Preview {
//    AccountView(user: User(username: "coco", email: ",mail", firstName: "first", lastName: "last", phone: "44444", country: "US")) {
//        
//    }
//}
