import { LinearProgress as LinearProgress$1 } from "../../loading/LinearProgress.mjs";
import ControlPanel from "./ControlPanel.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { makeStyles } from "@material-ui/core";
import { Document, Page, pdfjs } from "react-pdf";
//#region src/UI/fileViewer/pdfViewer/PDFViewer.tsx
const useStyles = makeStyles((theme) => ({
	pdfSection: (props) => ({ minWidth: props?.minWidth }),
	documentContainer: {
		display: "flex",
		justifyContent: "center",
		width: "100%",
		height: "100%",
		overflowX: "auto",
		overflowY: "hidden"
	},
	loadingBox: { width: "100%" }
}));
const PDFViewer = (t0) => {
	const $ = c(18);
	const { isPDFOpen: t1, fileUrl, blobPDF, closePDF, onClickDownload, minWidth } = t0;
	const isPDFOpen = t1 === void 0 ? true : t1;
	const [scale, setScale] = useState(1);
	const [numPages, setNumPages] = useState(null);
	const [pageNumber, setPageNumber] = useState(1);
	const [resolvedFile, setResolvedFile] = useState(null);
	let t2;
	if ($[0] !== minWidth) {
		t2 = { minWidth };
		$[0] = minWidth;
		$[1] = t2;
	} else t2 = $[1];
	const classes = useStyles(t2);
	useEffect(_temp);
	let t3;
	let t4;
	if ($[2] !== blobPDF || $[3] !== fileUrl) {
		t3 = () => {
			if (fileUrl) {
				setResolvedFile(fileUrl);
				return;
			}
			if (blobPDF instanceof Blob) {
				const url = URL.createObjectURL(blobPDF);
				setResolvedFile(url);
				return () => {
					URL.revokeObjectURL(url);
				};
			}
			if (typeof blobPDF === "string" && blobPDF.length > 0) {
				setResolvedFile(`data:application/pdf;base64,${blobPDF}`);
				return;
			}
			setResolvedFile(null);
		};
		t4 = [fileUrl, blobPDF];
		$[2] = blobPDF;
		$[3] = fileUrl;
		$[4] = t3;
		$[5] = t4;
	} else {
		t3 = $[4];
		t4 = $[5];
	}
	useEffect(t3, t4);
	let t5;
	if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
		t5 = function onDocumentLoadSuccess(t6) {
			const { numPages: numPages_0 } = t6;
			setNumPages(numPages_0);
		};
		$[6] = t5;
	} else t5 = $[6];
	const onDocumentLoadSuccess = t5;
	let t6;
	if ($[7] !== classes || $[8] !== closePDF || $[9] !== isPDFOpen || $[10] !== numPages || $[11] !== onClickDownload || $[12] !== pageNumber || $[13] !== resolvedFile || $[14] !== scale) {
		t6 = isPDFOpen && resolvedFile && /* @__PURE__ */ React.createElement("div", {
			id: "pdf-section",
			className: classes.pdfSection
		}, /* @__PURE__ */ React.createElement(ControlPanel, {
			scale,
			setScale,
			numPages,
			pageNumber,
			setPageNumber,
			file: resolvedFile,
			closePDF,
			onClickDownload
		}), /* @__PURE__ */ React.createElement("div", { className: classes.documentContainer }, /* @__PURE__ */ React.createElement(Document, {
			file: resolvedFile,
			onLoadSuccess: onDocumentLoadSuccess
		}, /* @__PURE__ */ React.createElement(Page, {
			pageNumber,
			scale,
			loading: /* @__PURE__ */ React.createElement("div", { className: classes.loadingBox }, /* @__PURE__ */ React.createElement(LinearProgress$1, null))
		}))));
		$[7] = classes;
		$[8] = closePDF;
		$[9] = isPDFOpen;
		$[10] = numPages;
		$[11] = onClickDownload;
		$[12] = pageNumber;
		$[13] = resolvedFile;
		$[14] = scale;
		$[15] = t6;
	} else t6 = $[15];
	let t7;
	if ($[16] !== t6) {
		t7 = /* @__PURE__ */ React.createElement("div", null, t6);
		$[16] = t6;
		$[17] = t7;
	} else t7 = $[17];
	return t7;
};
function _temp() {
	pdfjs.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
}
//#endregion
export { PDFViewer };

//# sourceMappingURL=PDFViewer.mjs.map