//
//  PasswordView.swift
//  PadelClub
//
//  Created by Laurent Morvillier on 25/06/2024.
//

import SwiftUI

struct PasswordField: View {
    
    var label: String
    @Binding var password: String
    
    @State var visible: Bool = false
    
    init(_ label: String, text: Binding<String>) {
        self.label = label
        self._password = text
    }
    
    var body: some View {
        
        HStack {
            
            if self.visible {
                TextField(self.label, text: self.$password)
            } else {
                SecureField(self.label, text: self.$password)
            }
            Spacer()
            Button {
                self.visible.toggle()
            } label: {
                let image = self.visible ? "eye.slash" : "eye"
                Image(systemName: image)
            }
        }
        .autocorrectionDisabled(true)
        
    }
    
}
