(function () {
  const form = document.querySelector("[data-login-form]");
  if (!form) {
    return;
  }

  const passwordInput = form.querySelector("[data-password-input]");
  const toggleButton = form.querySelector("[data-password-toggle]");
  const submitButton = form.querySelector("[data-submit-button]");

  if (toggleButton && passwordInput) {
    toggleButton.addEventListener("click", () => {
      const nextType = passwordInput.type === "password" ? "text" : "password";
      const isVisible = nextType === "text";
      passwordInput.type = nextType;
      toggleButton.setAttribute("aria-pressed", String(isVisible));
      toggleButton.textContent = isVisible ? "Ocultar" : "Mostrar";
    });
  }

  form.addEventListener("submit", () => {
    form.classList.add("is-submitting");
    if (submitButton) {
      submitButton.disabled = true;
      submitButton.setAttribute("aria-disabled", "true");
    }
  });
})();
