$('.reset_password_button').click(async function (e) {
    e.preventDefault();
    $(this).attr('disabled', true);

    let form = $('.reset_password_form'),
        data = new FormData(form[0]),
        url = form.attr('action'),
        method = form.attr('method');

    const response=await ajax({
        url,
        data,
        dataType: 'json',
        method,
        contentType: false,
        processData: false,
    });

    if (response.errors) {
        toasterError(response.errors);
        $(this).removeAttr('disabled');

    }
    if (response.url) {
        window.location.href = response.url;
    }
});

const togglePassword = document.querySelector('#togglePassword');
const password = document.querySelector('#password');
const passwordConfirmation = document.querySelector('#password_confirmation');

togglePassword.addEventListener('click', function() {
    // toggle the type attribute
    const passwordType = password.getAttribute('type') === 'password' ? 'text' : 'password';
    const passwordConfirmationType = passwordConfirmation.getAttribute('type') === 'password' ? 'text' : 'password';
    password.setAttribute('type', passwordType);
    passwordConfirmation.setAttribute('type', passwordConfirmationType);
    // toggle the eye slash icon
    this.classList.toggle('fa-eye-slash');
});
