import { useEffect, useState } from 'react' import { useToastStore, type ToastType } from '@/stores/useToastStore' const typeColors: Record = { success: 'var(--color-semantic-success)', error: 'var(--color-semantic-error)', info: 'var(--color-semantic-info)', warning: 'var(--color-semantic-warning)', } const typeIcons: Record = { success: '✓', error: '✗', info: 'i', warning: '!', } function ToastItem({ id, message, type }: { id: string; message: string; type: ToastType }) { const [exiting, setExiting] = useState(false) const removeToast = useToastStore((s) => s.removeToast) const color = typeColors[type] useEffect(() => { const exitTimer = setTimeout(() => setExiting(true), 3000) return () => clearTimeout(exitTimer) }, []) return (
{ if (exiting) removeToast(id) }} > {typeIcons[type]} {message}
) } export default function Toasts() { const toasts = useToastStore((s) => s.toasts) if (toasts.length === 0) return null return (
{toasts.map((t) => (
))}
) }