"use client"; import React, { useState, useEffect, createContext, useContext, useCallback } from "react"; import { X, CheckCircle2, AlertCircle, Info } from "lucide-react"; import { motion, AnimatePresence } from "framer-motion"; type ToastType = "success" | "error" | "info"; interface Toast { id: string; message: string; type: ToastType; } interface ToastContextType { toast: (message: string, type?: ToastType) => void; } const ToastContext = createContext({ toast: () => {}, }); export const useToast = () => useContext(ToastContext); export function ToastProvider({ children }: { children: React.ReactNode }) { const [toasts, setToasts] = useState([]); const toast = React.useCallback((message: string, type: ToastType = "info") => { const id = Math.random().toString(36).substring(2, 9); setToasts((prev) => [...prev, { id, message, type }]); setTimeout(() => { setToasts((prev) => prev.filter((t) => t.id !== id)); }, 5000); }, []); const removeToast = (id: string) => { setToasts((prev) => prev.filter((t) => t.id !== id)); }; return ( {children}
{toasts.map((t) => ( {t.type === "success" && } {t.type === "error" && } {t.type === "info" && }

{t.message}

))}
); }