export type ToastVariant = "success" | "error" | "info"; export type ToastItem = { id: string; variant: ToastVariant; message: string; createdAt: number }; const listeners = new Set<() => void>(); let items: ToastItem[] = []; function emit() { for (const fn of listeners) fn(); } export function subscribe(fn: () => void) { listeners.add(fn); return () => listeners.delete(fn); } export function snapshot() { return items; } function push(variant: ToastVariant, message: string) { const id = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`; items = [...items, { id, variant, message, createdAt: Date.now() }]; emit(); return id; } export function dismissToast(id: string) { items = items.filter((t) => t.id !== id); emit(); } export const toast = { success: (message: string) => push("success", message), error: (message: string) => push("error", message), info: (message: string) => push("info", message), dismiss: dismissToast, };