import { CheckCircle2, Loader2, X, XCircle } from 'lucide-react' import { useEffect } from 'react' export interface ToastItem { id: string level: 'info' | 'success' | 'error' message: string spinner?: boolean link?: { label: string, url: string } dismissOnTimer?: number } interface Props { toasts: ToastItem[] onDismiss: (id: string) => void onOpenUrl: (url: string) => void } function levelClasses(level: ToastItem['level']): string { switch (level) { case 'success': return 'border-state-green/60 bg-state-green/10' case 'error': return 'border-state-red/60 bg-state-red/10' default: return 'border-state-blue/60 bg-state-blue/10' } } function LevelIcon({ toast }: { toast: ToastItem }) { if (toast.spinner) return if (toast.level === 'success') return if (toast.level === 'error') return return null } function ToastRow({ toast, onDismiss, onOpenUrl, }: { toast: ToastItem onDismiss: (id: string) => void onOpenUrl: (url: string) => void }) { useEffect(() => { if (!toast.dismissOnTimer) return const t = setTimeout(() => onDismiss(toast.id), toast.dismissOnTimer) return () => clearTimeout(t) }, [toast.id, toast.dismissOnTimer, onDismiss]) return (
{toast.message} {toast.link && ( <> {' '} )}
) } export function ToastStack({ toasts, onDismiss, onOpenUrl }: Props) { if (toasts.length === 0) return null return (
{toasts.map(t => (
))}
) }