export type ToastType = 'success' | 'error' | 'info' | 'warning' export interface Toast { id: number type: ToastType msg: string } let _counter = 0 export function useToast() { const toasts = useState('app:toasts', () => []) function toast(msg: string, type: ToastType = 'info', duration = 3000) { const id = ++_counter toasts.value.push({ id, type, msg }) if (duration > 0) { setTimeout(() => { toasts.value = toasts.value.filter((t) => t.id !== id) }, duration) } } return { toasts, toast, success: (msg: string, duration?: number) => toast(msg, 'success', duration), error: (msg: string, duration?: number) => toast(msg, 'error', duration), info: (msg: string, duration?: number) => toast(msg, 'info', duration), warn: (msg: string, duration?: number) => toast(msg, 'warning', duration), } }