"use client"; import dynamic from "next/dynamic"; import { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { Check, Copy, Download, FileText, PanelLeftClose, PanelLeftOpen, } from "lucide-react"; import { apiUrl } from "@/lib/api"; import { docIconFor, formatBytes } from "@/lib/doc-attachments"; import { previewKindFor, resolveSourceUrl, type FilePreviewSource, } from "@/components/chat/preview/previewerFor"; // Reuse the chat renderers โ they're pure presentation given (url, filename) // and don't carry chat-specific state. const PdfPreview = dynamic( () => import("@/components/chat/preview/previewers/PdfPreview"), ); const ImagePreview = dynamic( () => import("@/components/chat/preview/previewers/ImagePreview"), ); const SvgPreview = dynamic( () => import("@/components/chat/preview/previewers/SvgPreview"), ); const MarkdownPreview = dynamic( () => import("@/components/chat/preview/previewers/MarkdownPreview"), ); const TextPreview = dynamic( () => import("@/components/chat/preview/previewers/TextPreview"), ); const OfficeTextPreview = dynamic( () => import("@/components/chat/preview/previewers/OfficeTextPreview"), ); const FallbackPreview = dynamic( () => import("@/components/chat/preview/previewers/FallbackPreview"), ); interface KbFilePreviewProps { source: FilePreviewSource | null; /** * Optional slot rendered to the right of the breadcrumb / title โ used * to surface metadata (e.g. file count, modified date) inline in the * preview header, since this component is the right pane of the * master-detail and there's no separate header above it. */ metaSuffix?: React.ReactNode; /** Current collapsed state of the file list. When provided, the preview * header shows a toggle so the user can claim more width without * reaching for the file list's own toggle button. */ fileListCollapsed?: boolean; onToggleFileList?: () => void; } /** * Inline file preview pane that fits the /knowledge master-detail layout. * * Unlike the chat's slide-in drawer, this is just an in-flow panel โ header * (filename + actions) on top, body (renderer) below. It owns no animation * timers and no portal; the parent decides how/when to mount it. That keeps * the visual language consistent with the rest of the knowledge surface * (tabs, sidebars, plain panels) instead of pulling in a drawer chrome that * fights the page's existing master-detail. */ export default function KbFilePreview({ source, metaSuffix, fileListCollapsed, onToggleFileList, }: KbFilePreviewProps) { const { t } = useTranslation(); const [copied, setCopied] = useState(false); const previewUrl = useMemo( () => (source ? resolveSourceUrl(source, apiUrl) : null), [source], ); const kind = useMemo( () => (source ? previewKindFor(source) : null), [source], ); if (!source) { return (
{t( "Pick any document from the list on the left to view it here without leaving the knowledge base.", )}