import React, { createContext, useContext, useState, useCallback } from 'react'; import { CheckCircle2, XCircle, Info, Download, X, FileText, Check } from 'lucide-react'; export type ToastType = 'success' | 'error' | 'info' | 'download'; export interface Toast { id: string; message: string; type: ToastType; fileName?: string; fileSize?: string; } export interface ToastContextType { showToast: (message: string, type?: ToastType, fileName?: string, fileSize?: string) => void; showDownloadToast: (fileName: string, fileSize?: string) => void; } const ToastContext = createContext(undefined); export const ToastProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [toasts, setToasts] = useState([]); const showToast = useCallback((message: string, type: ToastType = 'success', fileName?: string, fileSize?: string) => { const id = Date.now().toString() + Math.random().toString(36).substring(2, 5); setToasts((prev) => [...prev, { id, message, type, fileName, fileSize }]); setTimeout(() => { setToasts((prev) => prev.filter((t) => t.id !== id)); }, 4000); }, []); const showDownloadToast = useCallback((fileName: string, fileSize?: string) => { const id = Date.now().toString() + Math.random().toString(36).substring(2, 5); setToasts((prev) => [...prev, { id, message: `O material "${fileName}" foi baixado com sucesso.`, type: 'download', fileName, fileSize }]); setTimeout(() => { setToasts((prev) => prev.filter((t) => t.id !== id)); }, 4500); }, []); const removeToast = (id: string) => { setToasts((prev) => prev.filter((t) => t.id !== id)); }; return ( {children}
{toasts.map((toast) => { if (toast.type === 'download') { return (
{/* Emerald vertical bar */}
Download Concluído

{toast.fileName || toast.message}

Salvo no seu dispositivo {toast.fileSize && ( <> • {toast.fileSize} )}
); } return (
{toast.type === 'success' && } {toast.type === 'error' && } {toast.type === 'info' && }

{toast.message}

); })}
); }; export const useToast = () => { const context = useContext(ToastContext); if (!context) throw new Error('useToast must be used within ToastProvider'); return context; };