"use client"; import { useState } from "react"; import { X, Trash2, ExternalLink, Loader2 } from "lucide-react"; import { toast } from "sonner"; interface DocumentPreviewModalProps { isOpen: boolean; onClose: () => void; document: { key: string; name: string; type: string; size: number; downloadUrl: string; } | null; onDelete: (fileKey: string) => Promise; } export function DocumentPreviewModal({ isOpen, onClose, document, onDelete }: DocumentPreviewModalProps) { const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [isDeleting, setIsDeleting] = useState(false); if (!isOpen || !document) return null; const isImage = document.name.match(/\.(jpg|jpeg|png)$/i); const isPdf = document.name.match(/\.pdf$/i); const handleDelete = async () => { setIsDeleting(true); try { await onDelete(document.key); toast.success("Document supprimé avec succès"); onClose(); } catch (error) { toast.error("Erreur lors de la suppression du document"); console.error(error); } finally { setIsDeleting(false); setShowDeleteConfirm(false); } }; const formatFileSize = (bytes: number) => { if (bytes === 0) return '0 B'; const k = 1024; const sizes = ['B', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i]; }; return (
{/* Header */}

{document.name}

{document.type} {formatFileSize(document.size)}
{/* Content */}
{isImage && (
{document.name}
)} {isPdf && (