// ==================== Baby Tracker Toast Notifications ==================== document.addEventListener('alpine:init', () => { Alpine.store('toast', { messages: [], _seq: 0, show(message, type = 'info', duration = 0) { if (!message) return; const defaults = { success: 2800, error: 4500, warning: 3500, info: 2800 }; const id = `${Date.now()}-${++this._seq}`; this.messages.push({ id, message, type, visible: true }); // Cap queue length to avoid stacking forever if (this.messages.length > 5) { const oldest = this.messages[0]; this.dismiss(oldest.id); } const ms = duration > 0 ? duration : (defaults[type] || 2800); setTimeout(() => this.dismiss(id), ms); }, dismiss(id) { const msg = this.messages.find(m => m.id === id); if (!msg || !msg.visible) return; msg.visible = false; setTimeout(() => { this.messages = this.messages.filter(m => m.id !== id); }, 300); }, success(msg) { this.show(msg, 'success'); }, error(msg) { this.show(msg, 'error'); }, warning(msg) { this.show(msg, 'warning'); }, info(msg) { this.show(msg, 'info'); } }); });