import React, { useState } from "react"; import { Document, Page } from "react-pdf"; import { AlertCircle, Download } from "lucide-react"; import { Button } from "@termix/plugin-sdk/ui"; import { useTranslation } from "react-i18next"; // No workerSrc: the termix-plugin CLI's esbuild step has no asset-copy // pipeline for a worker file the way core's Vite build does with `?url`, so // pdfjs falls back to parsing on the main thread instead. Fine for the // config/log-sized files this preview usually opens; a real worker needs the // CLI to gain static-asset output first (see FINISH-LIST.md). interface PdfPreviewProps { content: string; onDownload?: () => void; onMediaDimensionsChange?: (dimensions: { width: number; height: number; }) => void; } export function PdfPreview({ content, onDownload, onMediaDimensionsChange, }: PdfPreviewProps) { const { t } = useTranslation(); const [numPages, setNumPages] = useState(null); const [pageNumber, setPageNumber] = useState(1); const [pdfScale, setPdfScale] = useState(1.2); const [pdfError, setPdfError] = useState(false); return (
{t("fileManager.pageXOfY", { current: pageNumber, total: numPages || 0, })}
{Math.round(pdfScale * 100)}%
{pdfError ? (

{t("fileManager.cannotLoadPdf")}

{t("fileManager.pdfLoadError")}

{onDownload && ( )}
) : ( { setNumPages(numPages); setPdfError(false); onMediaDimensionsChange?.({ width: 800, height: 600, }); }} onLoadError={(error) => { console.error("PDF load error:", error); setPdfError(true); }} loading={

{t("fileManager.loadingPdf")}

} >

{t("fileManager.loadingPage")}

} /> )}
); }