/**
 * assets/js/login.js
 * Login page interactivity: show/hide password, error animation.
 */

document.addEventListener('DOMContentLoaded', function() {
    const toggleBtn = document.getElementById('togglePassword');
    const passwordInput = document.getElementById('password');
    const errorMsg = document.getElementById('errorMsg');

    // Toggle password visibility
    if (toggleBtn && passwordInput) {
        toggleBtn.addEventListener('click', function() {
            const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
            passwordInput.setAttribute('type', type);
            // Toggle the eye icon
            const icon = this.querySelector('i');
            if (icon) {
                icon.classList.toggle('fa-eye');
                icon.classList.toggle('fa-eye-slash');
            }
        });
    }

    // Auto-focus password field
    if (passwordInput) {
        passwordInput.focus();
    }

    // If error message exists, auto-hide after 5 seconds (optional)
    if (errorMsg) {
        setTimeout(function() {
            errorMsg.style.transition = 'opacity 0.5s ease';
            errorMsg.style.opacity = '0';
            setTimeout(function() {
                errorMsg.style.display = 'none';
            }, 500);
        }, 5000);
    }
});