// import { simpleNotification } from '../comps/notify.js';
import { simpleNotification } from '../z_comps/notify.js';

document.addEventListener('DOMContentLoaded', function () {
  const form = document.querySelector('form');
  const newPswdInput = document.querySelector('#new_pswd');

  const rules = {
    lengt10: (pwd) => pwd.length >= 10,
    atl1num: (pwd) => /\d/.test(pwd),
    atl1mayusc: (pwd) => /[A-Z]/.test(pwd),
    // atl1chrspe: (pwd) => /[!@"#$%&\/()=?¡]/.test(pwd)
    atl1chrspe: (pwd) => /[!@#$%&*()_+\-=[\]{};':"\\|,.<>\/?¡¿]/.test(pwd)
  };

  newPswdInput.addEventListener('input', function () {
    const pwd = this.value;
    for (let id in rules) {
      document.querySelector(`#${id}`).textContent = rules[id](pwd) ? '✅' : '❌';
    }
  });

  form.addEventListener('submit', function (e) {
    const pwd = newPswdInput.value;
    const valid = Object.values(rules).every(fn => fn(pwd));
    if (!valid) {
      e.preventDefault();
      simpleNotification("Error", "La contraseña no cumple con todos los requisitos indicados.", "error");
    }
  });
});


// ver contraseñas
const toggleButtons = document.querySelectorAll('.password-toggle');

toggleButtons.forEach(btn => {
  btn.addEventListener('click', () => {
    const passwordInput = btn.previousElementSibling; 

    if (passwordInput.type === 'password') {
      passwordInput.type = 'text';
      btn.innerHTML = '<i class="bi bi-eye"></i>'; 
    } else {
      passwordInput.type = 'password';
      btn.innerHTML = '<i class="bi bi-eye-slash"></i>'; 
    }
  });
});