/* =========================================================
   NOVA X — toast.js
   Notificaciones flotantes no intrusivas
   ========================================================= */

const NovaToast = (() => {
  function getContainer() {
    let container = document.querySelector(".toast-container");
    if (!container) {
      container = document.createElement("div");
      container.className = "toast-container";
      container.setAttribute("role", "status");
      container.setAttribute("aria-live", "polite");
      document.body.appendChild(container);
    }
    return container;
  }

  function show(mensaje, icono = "✓") {
    const container = getContainer();
    const toast = document.createElement("div");
    toast.className = "toast";
    toast.innerHTML = `<span class="toast-icon">${icono}</span><span>${mensaje}</span>`;
    container.appendChild(toast);

    setTimeout(() => {
      toast.classList.add("is-leaving");
      toast.addEventListener("animationend", () => toast.remove(), { once: true });
    }, 2600);
  }

  return { show };
})();
