import { HTMLAttributes, useMemo } from 'react'; import { SharedData } from '@/types/global'; import { usePage } from '@inertiajs/react'; import { AlertCircle, Download, ExternalLink } from 'lucide-react'; interface Props extends HTMLAttributes { src: string; fileName?: string; } type DocumentType = 'pdf' | 'office' | 'image' | 'text' | 'unsupported'; const DocumentViewer = ({ src, fileName, className, ...props }: Props) => { const { props: pageProps } = usePage(); const { translate } = pageProps; const { frontend } = translate; const documentInfo = useMemo(() => { const getFileExtension = (url: string): string => { const urlWithoutQuery = url.split('?')[0]; const extension = urlWithoutQuery.split('.').pop()?.toLowerCase() || ''; return extension; }; const getDocumentType = (extension: string): DocumentType => { const pdfFormats = ['pdf']; const officeFormats = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']; const imageFormats = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg']; const textFormats = ['txt', 'rtf', 'csv']; if (pdfFormats.includes(extension)) return 'pdf'; if (officeFormats.includes(extension)) return 'office'; if (imageFormats.includes(extension)) return 'image'; if (textFormats.includes(extension)) return 'text'; return 'unsupported'; }; const extension = getFileExtension(src); const type = getDocumentType(extension); return { extension, type }; }, [src]); const renderDocument = () => { const baseClassName = "h-full max-h-[calc(100vh-60px)] min-h-[80vh] w-full"; switch (documentInfo.type) { case 'pdf': return (