//TO SWITCH BETWEEN THE REGISTER FORM AND LOGIN FORM
const loginToRegisterButton = document.getElementById('loginToRegisterButton');
const registerToLoginButton = document.getElementById('registerToLoginButton');
const loginForm = document.getElementById('loginForm');
const registerForm = document.getElementById('registerForm');

loginToRegisterButton.addEventListener('click', showRegisterForm);
registerToLoginButton.addEventListener('click', showLoginForm);


function showRegisterForm() {
    loginForm.style.display = 'none';
    registerForm.style.display = 'flex';
}

function showLoginForm() {
    loginForm.style.display = 'flex';
    registerForm.style.display = 'none';
}


//TO SHOW PASSWORD INPUT
const showPasswordButton = document.getElementById('showPasswordButton');
const passwordInput = document.getElementById('passwordInput');

showPasswordButton.addEventListener('click', togglePasswordVisibility);

function togglePasswordVisibility() {
    if (passwordInput.type === 'password') {
        passwordInput.type = 'text';
    } else {
        passwordInput.type = 'password';
    }
}

//FUNCTION TO SHOW AN ERROR MESSAGE WITH AND MAKE IT DISAPPEAR AFTER 10 SECONDS
function showError() {
    const errorMessage = document.getElementById('error-message');
    errorMessage.classList.add("show-message");

    // Automatically hide the message container after 10 seconds
    setTimeout(() => {
        errorMessage.classList.add("hide-message");
    }, 10000);
}

// Check if error messages are present in the rendered HTML
const errorMessages = document.querySelectorAll('.messages p');
if (errorMessages.length > 0) {
    showError();
}
