import React, { useState, useEffect } from 'react'; import { FileText, Download, Eye, Loader } from 'lucide-react'; const MedicalDocuments = ({ demandeId }) => { const [documents, setDocuments] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchDocuments = async () => { if (!demandeId) { setLoading(false); return; } try { setLoading(true); const response = await fetch(`/api/medical-documents/${demandeId}`); const data = await response.json(); if (data.success) { setDocuments(data.documents || []); } else { setError(data.message); } } catch (err) { console.error('Erreur récupération documents:', err); setError('Impossible de charger les documents'); } finally { setLoading(false); } }; fetchDocuments(); }, [demandeId]); const formatFileSize = (bytes) => { if (bytes === 0) return '0 B'; const k = 1024; const sizes = ['B', 'KB', 'MB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; const getFileIcon = (type) => { if (type === 'application/pdf') { return ( ); } return ( ); }; const formatDate = (dateString) => { const date = new Date(dateString); return date.toLocaleDateString('fr-FR', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' }); }; if (loading) { return (