import React, { useState } from 'react'; import { DocumentIcon } from './icons/DocumentIcon'; import type { PDFPage } from '../types'; interface ProofPreviewProps { file?: File | null; previewUrl: string | null; fileName?: string; pdfPages?: PDFPage[]; } export const ProofPreview: React.FC = ({ file, previewUrl, fileName, pdfPages }) => { const [currentPage, setCurrentPage] = useState(1); if (!previewUrl && (!pdfPages || pdfPages.length === 0)) { return null; } const getMimeType = (): string => { if (file?.type) return file.type; if (previewUrl?.startsWith('data:')) { const match = previewUrl.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+);/); if (match && match[1]) { return match[1]; } } return 'application/octet-stream'; // Fallback }; const fileType = getMimeType(); const displayName = fileName || file?.name || 'Proof Preview'; // Check if we have rasterized PDF pages to display const hasPdfPages = pdfPages && pdfPages.length > 0; const totalPages = pdfPages?.length || 0; const handlePrevPage = () => { setCurrentPage(prev => Math.max(1, prev - 1)); }; const handleNextPage = () => { setCurrentPage(prev => Math.min(totalPages, prev + 1)); }; const renderPdfPages = () => { if (!pdfPages || pdfPages.length === 0) return null; const currentPdfPage = pdfPages[currentPage - 1]; return (
{`${displayName} {totalPages > 1 && (
Page {currentPage} of {totalPages}
)}
); }; const renderPreview = () => { // If we have rasterized PDF pages, use those if (hasPdfPages) { return renderPdfPages(); } if (fileType.startsWith('image/')) { return ( {displayName} ); } if (fileType === 'video/mp4') { return ( ); } if (fileType === 'application/pdf') { // Fallback to iframe if no rasterized pages available return (