import { createSignal } from 'solid-js'; import { Button } from '@/components/ui/Button'; import { ModalPortal } from '@/components/ui/ModalPortal'; import { IconX, IconDownload, IconExternalLink, IconEye, IconFile, IconCode, IconFileText, IconAlertTriangle, IconMusic, IconFileDescription, IconChartBar, IconChartLine } from '@tabler/icons-solidjs'; import { isDemoMode } from '@/lib/demo-mode'; interface FilePreviewModalProps { isOpen: boolean; onClose: () => void; file: any; } export const FilePreviewModal = (props: FilePreviewModalProps) => { const [previewError, setPreviewError] = createSignal(false); const getFileIcon = (fileType: string) => { if (fileType.startsWith('image/')) return ; if (fileType.startsWith('video/')) return ; if (fileType.startsWith('audio/')) return ; if (fileType.includes('pdf')) return ; if (fileType.includes('json') || fileType.includes('xml') || fileType.includes('csv')) return ; if (fileType.startsWith('text/') || fileType === 'txt' || fileType === 'md') return ; if (fileType === 'docx' || fileType === 'pptx' || fileType === 'xlsx') return ; return ; }; const getFilePreview = (file: any) => { if (previewError()) { return (

Preview Failed

Unable to load preview for this file

); } if (file.type.startsWith('image/')) { return (
{file.name} setPreviewError(true)} onLoad={() => setPreviewError(false)} />
); } else if (file.type.startsWith('video/')) { return (
); } else if (file.type.startsWith('audio/')) { return (

{file.name}

); } else if (file.type.startsWith('text/') || file.type.includes('json') || file.type.includes('xml') || file.type.includes('csv') || file.type === 'txt' || file.type === 'md') { return (
            {file.preview || `# Preview of ${file.name}\n\nFile content would be displayed here...\n\nIn a real implementation, this would show the actual file content.\n\nFor text files, this would display the full text content.\nFor code files, this would show syntax-highlighted code.\nFor markdown files, this would render the formatted content.`}
          
); } else if (file.type.includes('pdf')) { return (

PDF Document

{file.name}

); } else if (file.type === 'docx' || file.type === 'pptx' || file.type === 'xlsx') { return (
{file.type === 'docx' ? : file.type === 'pptx' ? : }

{file.type === 'docx' ? 'Word Document' : file.type === 'pptx' ? 'PowerPoint Presentation' : 'Excel Spreadsheet'}

{file.name}

{file.preview && (
{file.preview.substring(0, 200)}...
)}
); } else { return (
{getFileIcon(file.type)}

File Preview

{file.name}

Type: {file.type}

Size: {formatFileSize(file.size)}

{file.preview && (
{file.preview.substring(0, 150)}...
)}
); } }; const formatFileSize = (bytes: number) => { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; const handleDownload = () => { if (isDemoMode()) { // Simulate download in demo mode alert(`Download simulated for: ${props.file.name}\n\nIn production, this would download the actual file.`); return; } // Create download link const link = document.createElement('a'); link.href = props.file?.downloadUrl || '#'; link.download = props.file?.name; link.target = '_blank'; document.body.appendChild(link); link.click(); document.body.removeChild(link); }; return ( <> {/* Backdrop */} {props.isOpen && (
)} {/* Modal */}
{/* Header */}

{props.file?.name}

{props.file?.size ? formatFileSize(props.file.size) : 'Unknown size'}
{/* Preview Area */}
{props.file && getFilePreview(props.file)}
{/* Footer */}
{props.file?.type || 'Unknown file type'}
); };