"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    filePdf: ()=>filePdf
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const external_antd_namespaceObject = require("antd");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_react_pdf_namespaceObject = require("react-pdf");
const external_react_zoom_pan_pinch_namespaceObject = require("react-zoom-pan-pinch");
const external_file_pdf_style_js_namespaceObject = require("./file-pdf.style.js");
require("react-pdf/dist/Page/AnnotationLayer.css");
require("react-pdf/dist/Page/TextLayer.css");
const index_js_namespaceObject = require("../../../block-provider/index.js");
const options = {
    cMapUrl: "https://assets.tachybase.com/pdfjs-dist@".concat(external_react_pdf_namespaceObject.pdfjs.version, "/cmaps/"),
    cMapPacked: true,
    standardFontDataUrl: "https://assets.tachybase.com/pdfjs-dist@".concat(external_react_pdf_namespaceObject.pdfjs.version, "/standard_fonts/")
};
external_react_pdf_namespaceObject.pdfjs.GlobalWorkerOptions.workerSrc = "https://assets.tachybase.com/pdfjs-dist@".concat(external_react_pdf_namespaceObject.pdfjs.version, "/build/pdf.worker.min.js");
const TransformInternal = (param)=>{
    let { noTransformWrapper = false, children } = param;
    return noTransformWrapper ? children : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_zoom_pan_pinch_namespaceObject.TransformWrapper, {
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_zoom_pan_pinch_namespaceObject.TransformComponent, {
            children: children
        })
    });
};
const CheckedComponent = (props)=>{
    const { file, fileInfo, width, noTransformWrapper } = props;
    const pdfInfo = (null == file ? void 0 : file.url) || fileInfo;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { styles } = (0, external_file_pdf_style_js_namespaceObject.useStyles)();
    const containerRef = (0, external_react_namespaceObject.useRef)(null);
    const [pdfWidth, setPdfWidth] = (0, external_react_namespaceObject.useState)(600);
    const [numPages, setNumPages] = (0, external_react_namespaceObject.useState)(1);
    const isMobile = (0, index_js_namespaceObject.useIsMobile)();
    const onDocumentLoadSuccess = async (params)=>{
        var _containerRef_current;
        const { numPages, _transport } = params;
        const containerWidth = null === (_containerRef_current = containerRef.current) || void 0 === _containerRef_current ? void 0 : _containerRef_current.offsetWidth;
        const page = await _transport.getPage(1);
        const originalWidth = page.getViewport({
            scale: 1
        }).width;
        const scale = containerWidth / originalWidth;
        const viewport = page.getViewport({
            scale
        });
        setNumPages(numPages);
        setPdfWidth(viewport.width);
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_pdf_namespaceObject.Document, {
        className: styles.container,
        inputRef: containerRef,
        file: pdfInfo,
        options: options,
        onLoadError: (error)=>{
            var _window_Sentry, _window;
            null === (_window = window) || void 0 === _window || null === (_window_Sentry = _window.Sentry) || void 0 === _window_Sentry || _window_Sentry.captureException(error);
        },
        noData: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            style: {
                height: '100vh'
            }
        }),
        error: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            children: t('Load PDF file error')
        }),
        loading: "",
        onLoadSuccess: onDocumentLoadSuccess,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TransformInternal, {
            noTransformWrapper: noTransformWrapper || !isMobile,
            children: Array.from(new Array(numPages), (el, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_pdf_namespaceObject.Page, {
                    pageNumber: index + 1,
                    width: width || pdfWidth,
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                        className: styles.footer,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Tag, {
                            className: styles.footerText,
                            bordered: false,
                            children: [
                                index + 1,
                                "/",
                                numPages
                            ]
                        })
                    })
                }, "page_".concat(index + 1)))
        })
    });
};
const ViewComponent = (props)=>{
    const { file, prefixCls } = props;
    return file.imageUrl && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("img", {
        src: "".concat(file.imageUrl).concat(file.thumbnailRule || ''),
        style: {
            width: '100%',
            height: '100%'
        },
        alt: file.title,
        className: "".concat(prefixCls, "-list-item-image")
    });
};
const filePdf = {
    key: 'application/pdf',
    type: 'application/pdf',
    viewComponet: (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ViewComponent, {
            ...props
        }),
    checkedComponent: (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(CheckedComponent, {
            ...props
        })
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
