import { getTranslation } from './i18n.js'; const ICONS = { info: "fa-circle-info", warning: "fa-triangle-exclamation", error: "fa-circle-xmark", success: "fa-circle-check" }; export function announce(msg) { const el = document.getElementById("sr_status"); if (!el || !msg) return; el.textContent = ""; setTimeout(() => { el.textContent = msg; }, 50); } export function showToast(message, severity = "info", duration = 6000) { let container = document.getElementById("toast-container"); if (!container) { container = document.createElement("div"); container.id = "toast-container"; container.setAttribute("aria-live", "polite"); document.body.appendChild(container); } duration = Math.max(duration, 6000); const toast = document.createElement("div"); toast.className = `toast toast-${severity}`; toast.setAttribute("role", severity === "error" ? "alert" : "status"); const icon = document.createElement("i"); icon.className = `fas ${ICONS[severity] || ICONS.info}`; icon.setAttribute("aria-hidden", "true"); const text = document.createElement("span"); text.className = "toast__text"; text.textContent = message; const close = document.createElement("button"); close.type = "button"; close.className = "toast__close"; close.setAttribute("aria-label", getTranslation("toast_close") || "Close"); close.innerHTML = ''; toast.append(icon, text, close); container.appendChild(toast); requestAnimationFrame(() => toast.classList.add("show")); let timer = null; let removed = false; const dismiss = () => { if (removed) return; removed = true; clearTimeout(timer); toast.classList.remove("show"); setTimeout(() => toast.remove(), 300); }; const start = () => { clearTimeout(timer); timer = setTimeout(dismiss, duration); }; const pause = () => clearTimeout(timer); toast.addEventListener("mouseenter", pause); toast.addEventListener("mouseleave", start); toast.addEventListener("focusin", pause); toast.addEventListener("focusout", start); close.addEventListener("click", dismiss); start(); return toast; } export function highlightInput(inputTextbox) { const container = inputTextbox.closest(".text-area-container") || inputTextbox; inputTextbox.scrollIntoView({ behavior: "smooth", block: "center" }); inputTextbox.focus({ preventScroll: true }); container.classList.remove("input-attention"); void container.offsetWidth; // Force reflow container.classList.add("input-attention"); setTimeout(() => container.classList.remove("input-attention"), 1900); }