import React, { useEffect, useState } from 'react'; import { X, FileText, Image as ImageIcon, Code } from 'lucide-react'; interface FilePreviewProps { isOpen: boolean; fileName: string; blob: Blob | null; onClose: () => void; } export const FilePreview: React.FC = ({ isOpen, fileName, blob, onClose }) => { const [content, setContent] = useState(null); const [objectUrl, setObjectUrl] = useState(null); useEffect(() => { if (!blob) return; const type = blob.type; // Handle Images if (type.startsWith('image/')) { const url = URL.createObjectURL(blob); setObjectUrl(url); return () => URL.revokeObjectURL(url); } // Handle Text/JSON/Code if (type.startsWith('text/') || type.includes('json') || type.includes('javascript') || type.includes('xml')) { blob.text().then(text => setContent(text)); } else { // Fallback for unknown text-like files blob.text().then(text => setContent(text)); } }, [blob]); if (!isOpen || !blob) return null; const isImage = blob.type.startsWith('image/'); return (
{/* Header */}
{isImage ? : }

{fileName}

{blob.type || 'Unknown Type'}

{/* Content */}
{isImage && objectUrl && ( {fileName} )} {!isImage && content && (
                                {content.slice(0, 50000)}
                                {content.length > 50000 && ...Content truncated...}
                            
)} {!isImage && !content && (

Binary file or loading...

)}
{/* Footer */}
); };