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'; import { downloadCourseAsset } from '../services/api'; 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 = async () => { if (attachment.type === 'link') { showToast(`Acessando link "${attachment.name}"`, 'info'); window.open(attachment.url, '_blank', 'noopener,noreferrer'); return; } try { await downloadCourseAsset(attachment.id, attachment.name); setDownloaded(true); showDownloadToast(attachment.name, attachment.size); onDownload?.(attachment); window.setTimeout(() => setDownloaded(false), 3000); } catch (error) { showToast(error instanceof Error ? error.message : 'Não foi possível baixar este material.', 'error'); } }; if (compact) { return ( ); } return (
{getAttachmentIcon(attachment.type)}
{badge.label}

{attachment.name}

{attachment.description && (

{attachment.description}

)}
{attachment.size || 'Disponível'}
); };