"use client"; import { useEffect } from "react"; import { X, CheckCircle, AlertCircle, Info, AlertTriangle } from "lucide-react"; import { cn } from "@/lib/utils"; export type ToastType = "success" | "error" | "info" | "warning"; export interface Toast { id: string; type: ToastType; title: string; message?: string; duration?: number; onClick?: () => void; } interface ToastProps { toast: Toast; onClose: (id: string) => void; } const icons = { success: CheckCircle, error: AlertCircle, info: Info, warning: AlertTriangle, }; const styles = { success: "bg-green-50 dark:bg-green-950/30 border-green-200 dark:border-green-800 text-green-800 dark:text-green-200", error: "bg-red-50 dark:bg-red-950/30 border-red-200 dark:border-red-800 text-red-800 dark:text-red-200", info: "bg-blue-50 dark:bg-blue-950/30 border-blue-200 dark:border-blue-800 text-blue-800 dark:text-blue-200", warning: "bg-amber-50 dark:bg-amber-950/30 border-amber-200 dark:border-amber-800 text-amber-800 dark:text-amber-200", }; export function ToastItem({ toast, onClose }: ToastProps) { const Icon = icons[toast.type]; useEffect(() => { if (toast.duration && toast.duration > 0) { const timer = setTimeout(() => { onClose(toast.id); }, toast.duration); return () => clearTimeout(timer); } }, [toast, onClose]); return (
{ if (toast.onClick) { toast.onClick(); onClose(toast.id); } }} >

{toast.title}

{toast.message && (

{toast.message}

)}
); } export function ToastContainer({ toasts, onClose }: { toasts: Toast[]; onClose: (id: string) => void }) { return (
{toasts.map((toast) => ( ))}
); }