export type ToastType = 'success' | 'error' | 'warning' | 'info'; export interface ToastItem { id: string; type: ToastType; message: string; duration?: number; } // Global toast state export const toastListeners: ((toasts: ToastItem[]) => void)[] = []; export const toasts: ToastItem[] = []; export function notifyListeners() { toastListeners.forEach(fn => fn([...toasts])); } export function showToast(type: ToastType, message: string, duration = 5000) { const id = Math.random().toString(36).slice(2); toasts.push({ id, type, message, duration }); notifyListeners(); if (duration > 0) { setTimeout(() => { const idx = toasts.findIndex(t => t.id === id); if (idx >= 0) toasts.splice(idx, 1); notifyListeners(); }, duration); } } export function toast(message: string) { showToast('info', message); } toast.success = (msg: string) => showToast('success', msg); toast.error = (msg: string) => showToast('error', msg, 7000); toast.warning = (msg: string) => showToast('warning', msg); toast.info = (msg: string) => showToast('info', msg);