'use client'; import { create } from 'zustand'; export type ToastItem = { id: string; message: string; variant: 'error' | 'info' }; type ToastState = { toasts: ToastItem[]; show: (message: string, variant?: ToastItem['variant']) => void; dismiss: (id: string) => void; }; export const useToastStore = create((set, get) => ({ toasts: [], show: (message, variant = 'info') => { const id = typeof crypto !== 'undefined' && 'randomUUID' in crypto ? crypto.randomUUID() : String(Date.now()); set((s) => ({ toasts: [...s.toasts, { id, message, variant }] })); const duration = variant === 'error' ? 5200 : 3600; if (typeof window !== 'undefined') { window.setTimeout(() => { get().dismiss(id); }, duration); } }, dismiss: (id) => set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })), }));