import React from 'react'; import { Download } from 'lucide-react'; import { cn } from '@/utils/utils'; import type { Document } from '@/types/Document'; import { Button } from './Button'; import { useDocumentDownload } from '@/hooks/useDocumentDownload'; interface DocumentObjectProps { doc: Document; } export const DocumentObject: React.FC = ({ doc }) => { // 2. On initialise le Hook pour ce document spécifique const { downloadFile, isDownloading } = useDocumentDownload(); const getCategoryBadge = (category: string) => { switch (category) { case 'Audit': return 'bg-purple-50 text-purple-700 border-purple-200'; case 'Facture': return 'bg-slate-100 text-slate-700 border-slate-200'; case 'Rapport de conformité': return 'bg-emerald-50 text-emerald-700 border-emerald-200'; default: return 'bg-blue-50 text-blue-700 border-blue-200'; } }; return (
{doc.title}
{doc.file} • PDF
{doc.category} {/* Petit conseil d'optimisation : utiliser une fonction date pour éviter les crashs si doc.created est mal formaté */} {doc.created ? `${doc.created.split(" ")[0]} ${doc.created.split(" ")[1]?.substring(0,5)}` : 'N/A'} {/* 3. On relie le bouton à l'état et à la fonction du Hook */} ); };