import { useState, useCallback, createContext, useContext } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { X, CheckCircle, AlertCircle, Info, AlertTriangle } from 'lucide-react'; import { cn } from '../../lib/utils'; type ToastType = 'success' | 'error' | 'info' | 'warning'; interface Toast { id: string; message: string; type: ToastType; } interface ToastContextType { toast: (message: string, type?: ToastType) => void; } const ToastContext = createContext(null); export function useToast() { const context = useContext(ToastContext); if (!context) { throw new Error('useToast must be used within a ToastProvider'); } return context; } const iconMap: Record = { success: , error: , info: , warning: , }; const styleMap: Record = { success: 'bg-green-50 border-green-200 dark:bg-green-900/20 dark:border-green-800', error: 'bg-red-50 border-red-200 dark:bg-red-900/20 dark:border-red-800', info: 'bg-blue-50 border-blue-200 dark:bg-blue-900/20 dark:border-blue-800', warning: 'bg-yellow-50 border-yellow-200 dark:bg-yellow-900/20 dark:border-yellow-800', }; export function ToastProvider({ children }: { children: React.ReactNode }) { const [toasts, setToasts] = useState([]); const toast = useCallback((message: string, type: ToastType = 'info') => { const id = Date.now().toString(); setToasts((prev) => [...prev, { id, message, type }]); setTimeout(() => { setToasts((prev) => prev.filter((t) => t.id !== id)); }, 3000); }, []); const removeToast = useCallback((id: string) => { setToasts((prev) => prev.filter((t) => t.id !== id)); }, []); return ( {children}
{toasts.map((t) => ( {iconMap[t.type]} {t.message} ))}
); }