import React from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { CheckCircle, AlertCircle, Info, X } from 'lucide-react'; import { cn } from '@/utils/helpers'; export type ToastType = 'success' | 'error' | 'warning' | 'info'; interface ToastProps { type: ToastType; message: string; title?: string; onClose?: () => void; autoClose?: boolean; autoCloseDuration?: number; action?: { label: string; onClick: () => void; }; } const Toast = React.forwardRef( ( { type, message, title, onClose, autoClose = true, autoCloseDuration = 5000, action, }, ref ) => { const [isVisible, setIsVisible] = React.useState(true); React.useEffect(() => { if (!autoClose) return; const timer = setTimeout(() => { setIsVisible(false); onClose?.(); }, autoCloseDuration); return () => clearTimeout(timer); }, [autoClose, autoCloseDuration, onClose]); const icons = { success: , error: , warning: , info: , }; const colors = { success: 'bg-emerald-500/20 border-emerald-500/30 text-emerald-200', error: 'bg-red-500/20 border-red-500/30 text-red-200', warning: 'bg-yellow-500/20 border-yellow-500/30 text-yellow-200', info: 'bg-blue-500/20 border-blue-500/30 text-blue-200', }; const iconColors = { success: 'text-emerald-400', error: 'text-red-400', warning: 'text-yellow-400', info: 'text-blue-400', }; return ( {isVisible && (
{icons[type]}
{title && (

{title}

)}

{message}

{action && ( {action.label} )}
{onClose && ( { setIsVisible(false); onClose?.(); }} className="flex-shrink-0 opacity-50 hover:opacity-100 transition-opacity" > )}
)}
); } ); Toast.displayName = 'Toast'; export default Toast;