'use client' import { createContext, useContext, useState, useCallback, useEffect, useRef } from 'react' import { CheckCircle2, AlertCircle, Zap, X } from 'lucide-react' import { cn } from '@/lib/utils' type ToastType = 'success' | 'error' | 'event' interface Toast { id: string; type: ToastType; title: string; body?: string } interface ToastCtx { fire: (t: Omit) => void } const Ctx = createContext({ fire: () => {} }) export const useToast = () => useContext(Ctx) const ICONS = { success: CheckCircle2, error: AlertCircle, event: Zap, } const COLORS = { success: 'border-trading-up/40 bg-trading-up/10', error: 'border-trading-down/40 bg-trading-down/10', event: 'border-brand-yellow/40 bg-brand-yellow/10', } const ICON_COLORS = { success: 'text-trading-up', error: 'text-trading-down', event: 'text-brand-yellow', } function ToastItem({ toast, onDismiss }: { toast: Toast; onDismiss: () => void }) { const [visible, setVisible] = useState(false) const Icon = ICONS[toast.type] useEffect(() => { requestAnimationFrame(() => setVisible(true)) const t = setTimeout(() => { setVisible(false); setTimeout(onDismiss, 300) }, 4000) return () => clearTimeout(t) }, [onDismiss]) return (

{toast.title}

{toast.body &&

{toast.body}

}
) } export function ToastProvider({ children }: { children: React.ReactNode }) { const [toasts, setToasts] = useState([]) const counter = useRef(0) const fire = useCallback((t: Omit) => { const id = `t-${counter.current++}` setToasts(p => [...p.slice(-4), { ...t, id }]) }, []) const dismiss = useCallback((id: string) => { setToasts(p => p.filter(t => t.id !== id)) }, []) return ( {children}
{toasts.map(t => (
dismiss(t.id)} />
))}
) }