const password = document.getElementById("password");
const confirmPassword = document.getElementById("confirmPassword");
const submitBtn = document.getElementById("submitBtn");
const passwordHelp = document.getElementById("passwordHelp");
const passwordPolicyError = document.getElementById("passwordPolicyError");

function checkPasswords() {
    const pwValue = password.value;
    const confirmValue = confirmPassword.value;

    // Check length
    if (pwValue.length < 13) {
        passwordPolicyError.classList.remove("d-none");
        submitBtn.disabled = true;
        return;
    } else {
        passwordPolicyError.classList.add("d-none");
    }

    // Check match
    if (pwValue && confirmValue) {
        if (pwValue === confirmValue) {
            passwordHelp.classList.add("d-none");
            submitBtn.disabled = false;
        } else {
            passwordHelp.classList.remove("d-none");
            submitBtn.disabled = true;
        }
    } else {
        passwordHelp.classList.add("d-none");
        submitBtn.disabled = true;
    }
}

password.addEventListener("input", checkPasswords);
confirmPassword.addEventListener("input", checkPasswords);