'use client'; import React, { useState, useEffect, createContext, useContext } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Box } from '@/ui/Box'; import { Text } from '@/ui/Text'; import { Stack } from '@/ui/Stack'; import { CheckCircle, AlertCircle, Info, X } from 'lucide-react'; interface Toast { id: string; message: string; variant: 'success' | 'error' | 'info'; } interface ToastContextType { showToast: (message: string, variant: 'success' | 'error' | 'info') => void; } const ToastContext = createContext(undefined); export function ToastProvider({ children }: { children: React.ReactNode }) { const [toasts, setToasts] = useState([]); const showToast = (message: string, variant: 'success' | 'error' | 'info') => { const id = Math.random().toString(36).substring(2, 9); setToasts((prev) => [...prev, { id, message, variant }]); setTimeout(() => { setToasts((prev) => prev.filter((t) => t.id !== id)); }, 5000); }; return ( {children} {toasts.map((toast) => ( setToasts((prev) => prev.filter((t) => t.id !== toast.id))} /> ))} ); } export function useToast() { const context = useContext(ToastContext); if (!context) { throw new Error('useToast must be used within a ToastProvider'); } return context; } function ToastItem({ toast, onClose }: { toast: Toast; onClose: () => void }) { const variants = { success: { bg: 'bg-deep-graphite', border: 'border-performance-green/30', icon: CheckCircle, iconColor: 'text-performance-green', }, error: { bg: 'bg-deep-graphite', border: 'border-racing-red/30', icon: AlertCircle, iconColor: 'text-racing-red', }, info: { bg: 'bg-deep-graphite', border: 'border-primary-blue/30', icon: Info, iconColor: 'text-primary-blue', }, }; const config = variants[toast.variant]; const Icon = config.icon; return ( {toast.message} ); }