/** * Toast Notification System * Displays temporary notification messages */ import { CONFIG } from '../core/config.js'; export class Toast { static container = null; static toasts = []; static maxToasts = CONFIG.TOAST.MAX_VISIBLE; /** * Initialize toast container */ static init() { if (this.container) return; this.container = document.getElementById('toast-container'); if (!this.container) { this.container = document.createElement('div'); this.container.id = 'toast-container'; this.container.className = 'toast-container'; document.body.appendChild(this.container); } } /** * Show a toast notification */ static show(message, type = 'info', options = {}) { this.init(); const toast = { id: Date.now() + Math.random(), message, type, duration: options.duration || (type === 'error' ? CONFIG.TOAST.ERROR_DURATION : CONFIG.TOAST.DEFAULT_DURATION), dismissible: options.dismissible !== false, action: options.action || null, }; // Remove oldest toast if at max if (this.toasts.length >= this.maxToasts) { const oldest = this.toasts.shift(); this.dismiss(oldest.id); } this.toasts.push(toast); this.render(toast); // Auto-dismiss if (toast.duration > 0) { setTimeout(() => this.dismiss(toast.id), toast.duration); } return toast.id; } /** * Render toast element */ static render(toast) { const el = document.createElement('div'); el.className = `toast toast-${toast.type}`; el.setAttribute('data-toast-id', toast.id); el.setAttribute('role', 'alert'); el.setAttribute('aria-live', 'polite'); const icon = this.getIcon(toast.type); el.innerHTML = `