import { useCallback, useMemo } from 'react'; import type { JSX } from 'react'; import DocumentInfoPanel from '../documents/DocumentInfoPanel'; import { DownloadIcon } from '../ui/icons'; interface DocumentLike { id?: string | number; title?: string; content_type?: string; filename?: string; original_name?: string; [key: string]: unknown; } interface PreviewEntry { url?: string; contentType?: string; filename?: string; } interface ContentTabConfig { id?: string; label?: string; enabled?: boolean; forceDisplay?: boolean; loadContent?: (options?: { signal?: AbortSignal }) => unknown | Promise; loadingMessage?: string; emptyMessage?: string; unavailableMessage?: string; errorMessage?: string; [key: string]: unknown; } type LayoutMode = 'split' | 'stacked' | (string & {}); interface DocumentViewerLayoutProps { document?: DocumentLike | null; previewEntry?: PreviewEntry | null; summaryProps?: Record; metadataPayload?: unknown; contentTabConfig?: ContentTabConfig | null; resetKey?: string | number | null; classNamePrefix?: string; defaultTabId?: string; infoPanelProps?: Record; previewLoadingMessage?: string; layoutMode?: LayoutMode; } const DocumentViewerLayout = ({ document, previewEntry, summaryProps = {}, metadataPayload, contentTabConfig, resetKey, classNamePrefix = 'document-viewer', defaultTabId = 'details', infoPanelProps = {}, previewLoadingMessage = 'Preparing preview…', layoutMode = 'split', }: DocumentViewerLayoutProps): JSX.Element => { const isStacked = layoutMode === 'stacked'; const previewContent = useMemo(() => { if (!document || !previewEntry?.url) { return null; } const normalizedContentType = (previewEntry.contentType || document.content_type || '') .toLowerCase(); const isImage = normalizedContentType.startsWith('image/'); const isPdf = normalizedContentType === 'application/pdf' || normalizedContentType === 'application/x-pdf'; if (isImage) { return ( {`Preview ); } if (isPdf) { return (