'use client'; import * as React from 'react'; import { X } from 'lucide-react'; import { cn } from '@/lib/utils/cn'; export interface Toast { id: string; message: string; type?: 'success' | 'error' | 'info'; duration?: number; } interface ToastContextType { toasts: Toast[]; addToast: (message: string, type?: Toast['type'], duration?: number) => void; removeToast: (id: string) => void; } const ToastContext = React.createContext(undefined); export function ToastProvider({ children }: { children: React.ReactNode }) { const [toasts, setToasts] = React.useState([]); const addToast = React.useCallback((message: string, type: Toast['type'] = 'info', duration = 3000) => { const id = Math.random().toString(36).substring(7); const toast: Toast = { id, message, type, duration }; setToasts((prev) => [...prev, toast]); if (duration > 0) { setTimeout(() => { removeToast(id); }, duration); } }, []); const removeToast = React.useCallback((id: string) => { setToasts((prev) => prev.filter((t) => t.id !== id)); }, []); return ( {children} ); } export function useToast() { const context = React.useContext(ToastContext); if (!context) { throw new Error('useToast must be used within ToastProvider'); } return context; } interface ToastContainerProps { toasts: Toast[]; onRemove: (id: string) => void; } function ToastContainer({ toasts, onRemove }: ToastContainerProps) { if (toasts.length === 0) return null; return (
{toasts.map((toast) => (

{toast.message}

))}
); }