import React, { useState, useEffect } from 'react' import { Box, Typography, Paper, IconButton, Button, Dialog, DialogTitle, DialogContent, DialogActions, CircularProgress, Alert, } from '@mui/material' import { PictureAsPdf, Download, Close, ZoomIn, ZoomOut, NavigateBefore, NavigateNext, } from '@mui/icons-material' import type { Document } from '../types' interface FilePreviewProps { document: Document onClose: () => void } export const FilePreview: React.FC = ({ document, onClose }) => { const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [page, setPage] = useState(1) const [scale, setScale] = useState(1.0) const [numPages, setNumPages] = useState(0) useEffect(() => { setLoading(true) setError(null) setPage(1) setScale(1.0) // Simuler le chargement du PDF const timer = setTimeout(() => { setNumPages(3) // Simuler 3 pages setLoading(false) }, 1000) return () => clearTimeout(timer) }, [document]) const handleDownload = () => { if (document.previewUrl) { const link = window.document.createElement('a') link.href = document.previewUrl link.download = document.name link.click() } } const isPDF = document.mimeType.includes('pdf') || document.name.toLowerCase().endsWith('.pdf') const isImage = document.mimeType.startsWith('image/') || ['.png', '.jpg', '.jpeg', '.gif', '.webp'].some((ext) => document.name.toLowerCase().endsWith(ext)) if (!isPDF && isImage) { return ( {document.name} {Math.round(scale * 100)}% {document.previewUrl ? ( {document.name} setLoading(false)} onError={() => { setError('Erreur de chargement de l\'image') setLoading(false) }} /> ) : ( Aperçu image Le fichier a été uploadé avec succès. Taille: {(document.size / 1024 / 1024).toFixed(2)} MB )} ) } return ( {document.name} {loading && ( Chargement du PDF... )} {error && ( {error} )} {!loading && !error && ( {/* Contrôles de navigation */} Page {page} sur {numPages} {Math.round(scale * 100)}% {/* Aperçu PDF avec viewer intégré */} {document.previewUrl ? ( {/* Utiliser un viewer PDF intégré */}