let nextId = 0; export type ToastType = 'success' | 'error' | 'warning' | 'info'; export type Toast = { id: number; type: ToastType; message: string; }; let toasts = $state([]); export function getToasts(): Toast[] { return toasts; } export function addToast(type: ToastType, message: string, duration = 4000): number { const id = nextId++; toasts.push({ id, type, message }); if (duration > 0) { setTimeout(() => removeToast(id), duration); } return id; } export function removeToast(id: number) { toasts = toasts.filter((t) => t.id !== id); } export const toast = { success: (msg: string, duration?: number) => addToast('success', msg, duration), error: (msg: string, duration?: number) => addToast('error', msg, duration ?? 6000), warning: (msg: string, duration?: number) => addToast('warning', msg, duration), info: (msg: string, duration?: number) => addToast('info', msg, duration) };