import React from 'react'; import { FileText, FileSpreadsheet, FileArchive, FileCode, Image as ImageIcon, Link as LinkIcon, Download, ExternalLink, CheckCircle2, Paperclip } from 'lucide-react'; import { Attachment, AttachmentType } from '../types'; import { useToast } from '../context/ToastContext'; interface MaterialCardProps { attachment: Attachment; onDownload?: (attachment: Attachment) => void; compact?: boolean; } export const getAttachmentIcon = (type: AttachmentType) => { switch (type) { case 'pdf': return ; case 'spreadsheet': return ; case 'zip': return ; case 'doc': return ; case 'image': return ; case 'link': return ; default: return ; } }; export const getAttachmentBadge = (type: AttachmentType) => { switch (type) { case 'pdf': return { label: 'PDF', bg: 'bg-rose-500/15 text-rose-400 font-bold' }; case 'spreadsheet': return { label: 'PLANILHA', bg: 'bg-emerald-500/15 text-emerald-400 font-bold' }; case 'zip': return { label: 'PACOTE ZIP', bg: 'bg-amber-500/15 text-amber-400 font-bold' }; case 'doc': return { label: 'DOCUMENTO', bg: 'bg-blue-500/15 text-blue-400 font-bold' }; case 'image': return { label: 'IMAGEM / ASSET', bg: 'bg-purple-500/15 text-purple-400 font-bold' }; case 'link': return { label: 'LINK EXTERNO', bg: 'bg-sky-500/15 text-sky-400 font-bold' }; default: return { label: 'ARQUIVO', bg: 'bg-gray-500/15 text-gray-400 font-bold' }; } }; export const MaterialCard: React.FC = ({ attachment, onDownload, compact = false, }) => { const [downloaded, setDownloaded] = React.useState(false); const { showDownloadToast, showToast } = useToast(); const badge = getAttachmentBadge(attachment.type); const handleAction = (e: React.MouseEvent) => { setDownloaded(true); if (attachment.type === 'link') { showToast(`Acessando link "${attachment.name}"`, 'info'); } else { showDownloadToast(attachment.name, attachment.size); } if (onDownload) { onDownload(attachment); } // If it has a real URL that is not '#', let the default anchor do its work if (!attachment.url || attachment.url === '#') { e.preventDefault(); // Trigger a synthetic download notification reset setTimeout(() => setDownloaded(false), 3000); } }; if (compact) { return ( {getAttachmentIcon(attachment.type)} {attachment.name} {badge.label} {attachment.size && • {attachment.size}} {downloaded ? ( Baixado ) : ( {attachment.type === 'link' ? ( <> Acessar > ) : ( <> Baixar > )} )} ); } return ( {getAttachmentIcon(attachment.type)} {badge.label} {attachment.name} {attachment.description && ( {attachment.description} )} {attachment.size || 'Disponível'} {attachment.type === 'link' ? ( <> Abrir Link > ) : ( <> Baixar Arquivo > )} ); };
{attachment.name}
{attachment.description}