import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__js_preview_excel__ from "@js-preview/excel";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE__file_sheet_style_mjs__ from "./file-sheet.style.mjs";
import "@js-preview/excel/lib/index.css";
const ExcelView = (props)=>{
    const { file } = props;
    const fileUrl = file.url;
    const { styles } = (0, __WEBPACK_EXTERNAL_MODULE__file_sheet_style_mjs__.useStyles)();
    const excelContainerRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
    const excelPreviewerRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
    const [isLoading, setIsLoading] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(true);
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        const containerElement = excelContainerRef.current;
        if (containerElement && !excelPreviewerRef.current) {
            const myExcelPreviewer = __WEBPACK_EXTERNAL_MODULE__js_preview_excel__["default"].init(containerElement);
            excelPreviewerRef.current = myExcelPreviewer;
            setIsLoading(true);
            const handleShowPreviewer = async ()=>{
                await myExcelPreviewer.preview(fileUrl);
                setIsLoading(false);
            };
            try {
                handleShowPreviewer();
            } catch (e) {
                console.log('%c Line:36 🥟 e', e);
            }
        }
    }, [
        fileUrl
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        className: styles.excelPreview,
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                ref: excelContainerRef,
                className: styles.container
            }),
            isLoading && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                className: styles.loading,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Spin, {
                    size: "large"
                })
            })
        ]
    });
};
const OnlineView = (props)=>{
    const { file } = props;
    var _file_url;
    let fileUrl = null !== (_file_url = file.url) && void 0 !== _file_url ? _file_url : '';
    if (fileUrl.startsWith('/storage') && window.location.origin) fileUrl = window.location.origin + fileUrl;
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("iframe", {
        src: "https://view.officeapps.live.com/op/embed.aspx?src=".concat(fileUrl),
        width: "100%",
        height: "600px",
        frameBorder: "0"
    });
};
const ViewComponent = (props)=>{
    const { file, prefixCls } = props;
    return file.imageUrl && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("img", {
        src: "".concat(file.imageUrl).concat(file.thumbnailRule || ''),
        style: {
            width: '100%',
            height: '100%'
        },
        alt: file.title,
        className: "".concat(prefixCls, "-list-item-image")
    });
};
const fileXLS = {
    key: 'application/vnd.ms-excel',
    type: 'application/vnd.ms-excel',
    viewComponet: (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ViewComponent, {
            ...props
        }),
    checkedComponent: (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(OnlineView, {
            ...props
        })
};
const fileXLSX = {
    key: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    viewComponet: (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ViewComponent, {
            ...props
        }),
    checkedComponent: (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(OnlineView, {
            ...props
        })
};
const fileCSV = {
    key: 'text/csv',
    type: 'text/csv',
    viewComponet: (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ViewComponent, {
            ...props
        }),
    checkedComponent: (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ExcelView, {
            ...props
        })
};
export { fileCSV, fileXLS, fileXLSX };
