import ReactDOM from 'react-dom' import { useState, useEffect } from 'react' import { X, ExternalLink, Loader2 } from 'lucide-react' import { getAuthUrl } from '../../api/authUrl' import { openFile } from '../../utils/fileDownload' import type { NoteFile } from './CollabNotes.types' // ── File Preview Portal ───────────────────────────────────────────────────── interface FilePreviewPortalProps { file: NoteFile | null onClose: () => void } export function FilePreviewPortal({ file, onClose }: FilePreviewPortalProps) { const [authUrl, setAuthUrl] = useState('') const rawUrl = file?.url || '' useEffect(() => { setAuthUrl('') if (!rawUrl) return getAuthUrl(rawUrl, 'download').then(setAuthUrl) }, [rawUrl]) if (!file) return null const isImage = file.mime_type?.startsWith('image/') const isPdf = file.mime_type === 'application/pdf' const isTxt = file.mime_type?.startsWith('text/') const openInNewTab = () => openFile(rawUrl).catch(() => {}) return ReactDOM.createPortal(
{isImage ? ( /* Image lightbox — floating controls */
e.stopPropagation()}> {authUrl ? {file.original_name} : }
{file.original_name}
) : ( /* Document viewer — card with header */
e.stopPropagation()}>
{file.original_name}
{(isPdf || isTxt) ? (

) : (
)}
)}
, document.body ) }