"use client"; import * as React from "react"; import { X } from "lucide-react"; import { cn } from "@/lib/utils"; type ToastVariant = "default" | "success" | "warning" | "danger"; type ToastItem = { id: string; title: string; description?: string; variant?: ToastVariant; }; type ToastContextValue = { toast: (item: Omit) => void; }; const ToastContext = React.createContext(null); function getToastId() { if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") { return crypto.randomUUID(); } return `toast_${Date.now()}_${Math.random().toString(16).slice(2)}`; } const variantStyles: Record = { default: "border-border bg-card text-foreground", success: "border-emerald-500/40 bg-emerald-500/10 text-emerald-100", warning: "border-amber-500/40 bg-amber-500/10 text-amber-100", danger: "border-rose-500/40 bg-rose-500/10 text-rose-100", }; export function ToastProvider({ children }: { children: React.ReactNode }) { const [toasts, setToasts] = React.useState([]); const toast = React.useCallback((item: Omit) => { const id = getToastId(); setToasts((prev) => [...prev, { id, ...item }]); window.setTimeout(() => { setToasts((prev) => prev.filter((toastItem) => toastItem.id !== id)); }, 3200); }, []); const remove = React.useCallback((id: string) => { setToasts((prev) => prev.filter((toastItem) => toastItem.id !== id)); }, []); return ( {children}
{toasts.map((item) => (

{item.title}

{item.description ?

{item.description}

: null}
))}
); } export function useToast() { const context = React.useContext(ToastContext); if (!context) { throw new Error("useToast must be used within ToastProvider"); } return context; }