import React from "react"; import { FaTimes, FaDownload, FaFileAlt, FaFilePdf, FaFileWord, FaFileExcel, FaFilePowerpoint, FaFileImage, } from "react-icons/fa"; import { PsProjectDocument } from "../../../types/ps"; import dayjs from "dayjs"; import { getPsDocumentTypeText } from "../../../utils/erp"; interface DocumentViewerModalProps { isOpen: boolean; onClose: () => void; document: PsProjectDocument | null; onDownload?: (document: PsProjectDocument) => void; } const DocumentViewerModal: React.FC = ({ isOpen, onClose, document, onDownload, }) => { const getFileIcon = (fileName: string) => { const extension = fileName.toLowerCase().split(".").pop(); switch (extension) { case "pdf": return ; case "doc": case "docx": return ; case "xls": case "xlsx": return ; case "ppt": case "pptx": return ; case "jpg": case "jpeg": case "png": case "gif": return ; default: return ; } }; const formatFileSize = (sizeInMB: number): string => { if (sizeInMB < 1) { return `${(sizeInMB * 1024).toFixed(0)} KB`; } return `${sizeInMB.toFixed(2)} MB`; }; const handleDownload = () => { if (document && onDownload) { onDownload(document); } else if (document) { // Fallback: create a download link const link = window.document.createElement("a"); link.href = document.filePath; link.download = document.documentName; link.click(); } }; const isImageFile = (fileName: string): boolean => { const extension = fileName.toLowerCase().split(".").pop(); return ["jpg", "jpeg", "png", "gif"].includes(extension || ""); }; const isPdfFile = (fileName: string): boolean => { const extension = fileName.toLowerCase().split(".").pop(); return extension === "pdf"; }; if (!isOpen || !document) return null; return (
{/* Header */}
{getFileIcon(document.documentName)}

{document.documentName}

{getPsDocumentTypeText(document.documentType)} •{" "} {formatFileSize(document.fileSize)}

{/* Document Info */}
Yükleyen:

{document.uploadedBy}

Yüklenme Tarihi:

{dayjs(document.uploadedAt).format("DD.MM.YYYY HH:mm")}

Versiyon:

v{document.version}

Dosya Boyutu:

{formatFileSize(document.fileSize)}

{/* Document Preview */}
{isImageFile(document.documentName) ? (
{document.documentName} { const target = e.target as HTMLImageElement; target.style.display = "none"; }} />
) : isPdfFile(document.documentName) ? (