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__tachybase_components__ from "@tachybase/components";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__ from "@tachybase/utils/client";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_antd_es_upload_style__ from "antd/es/upload/style";
import * as __WEBPACK_EXTERNAL_MODULE_classnames__ from "classnames";
import * as __WEBPACK_EXTERNAL_MODULE_file_saver__ from "file-saver";
import * as __WEBPACK_EXTERNAL_MODULE__application_hooks_index_mjs__ from "../../../application/hooks/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__ from "../../../record-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__shared_mjs__ from "./shared.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__style_mjs__ from "./style.mjs";
const ReadPretty = ()=>null;
ReadPretty.File = function(props) {
    var _images_fileIndex, _images_, _images_1, _images_fileIndex1;
    const { size, showCount = 0 } = props;
    const record = (0, __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.useRecord)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const images = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__.isString)(field.value) ? record : (0, __WEBPACK_EXTERNAL_MODULE__shared_mjs__.toFileList)(field.value);
    const app = (0, __WEBPACK_EXTERNAL_MODULE__application_hooks_index_mjs__.useApp)();
    const [fileIndex, setFileIndex] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(0);
    const [visible, setVisible] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const { wrapSSR, hashId, componentCls: prefixCls } = (0, __WEBPACK_EXTERNAL_MODULE__style_mjs__.useStyles)();
    const useUploadStyleVal = __WEBPACK_EXTERNAL_MODULE_antd_es_upload_style__["default"]["default"] ? __WEBPACK_EXTERNAL_MODULE_antd_es_upload_style__["default"]["default"] : __WEBPACK_EXTERNAL_MODULE_antd_es_upload_style__["default"];
    const previewList = app.AttachmentPreviewManager.get();
    useUploadStyleVal(prefixCls);
    return wrapSSR(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])("".concat(prefixCls, "-wrapper"), "".concat(prefixCls, "-picture-card-wrapper"), "tb-upload", size ? "tb-upload-".concat(size) : null, hashId),
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                    className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])("".concat(prefixCls, "-list"), "".concat(prefixCls, "-list-picture-card")),
                    children: images.map((file, index)=>{
                        if ('small' === size) return 0 === index && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ReadFile, {
                            file: file,
                            prefixCls: prefixCls,
                            size: size,
                            images: images,
                            setFileIndex: setFileIndex,
                            setVisible: setVisible,
                            preview: previewList[null == file ? void 0 : file.mimetype] || previewList['default']
                        }, index);
                        return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ReadFile, {
                            file: file,
                            prefixCls: prefixCls,
                            size: size,
                            images: images,
                            setFileIndex: setFileIndex,
                            setVisible: setVisible,
                            preview: previewList['image/jpeg']
                        }, index);
                    })
                })
            }),
            visible && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.Lightbox, {
                mainSrc: null === (_images_fileIndex = images[fileIndex]) || void 0 === _images_fileIndex ? void 0 : _images_fileIndex.imageUrl,
                nextSrc: null === (_images_ = images[(fileIndex + 1) % images.length]) || void 0 === _images_ ? void 0 : _images_.imageUrl,
                prevSrc: null === (_images_1 = images[(fileIndex + images.length - 1) % images.length]) || void 0 === _images_1 ? void 0 : _images_1.imageUrl,
                mainFile: images[fileIndex],
                nextFile: images[(fileIndex + 1) % images.length],
                prevFile: images[(fileIndex + images.length - 1) % images.length],
                previewList: previewList,
                onCloseRequest: (e)=>{
                    e.preventDefault();
                    e.stopPropagation();
                    setVisible(false);
                },
                onMovePrevRequest: ()=>setFileIndex((fileIndex + images.length - 1) % images.length),
                onMoveNextRequest: ()=>setFileIndex((fileIndex + 1) % images.length),
                imageTitle: null === (_images_fileIndex1 = images[fileIndex]) || void 0 === _images_fileIndex1 ? void 0 : _images_fileIndex1.title,
                toolbarButtons: [
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("button", {
                        style: {
                            fontSize: 22,
                            background: 'none',
                            lineHeight: 1
                        },
                        type: "button",
                        "aria-label": "Zoom in",
                        title: "Zoom in",
                        className: "ril-zoom-in ril__toolbarItemChild ril__builtinButton",
                        onClick: (e)=>{
                            e.preventDefault();
                            e.stopPropagation();
                            const file = images[fileIndex];
                            (0, __WEBPACK_EXTERNAL_MODULE_file_saver__.saveAs)(file.url, "".concat(file.title).concat(file.extname));
                        },
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.DownloadOutlined, {})
                    }, 'download')
                ]
            })
        ]
    }));
};
ReadPretty.Upload = function() {
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    return (field.value || []).map((item)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
            children: item.url ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("a", {
                target: '_blank',
                href: item.url,
                rel: "noreferrer",
                children: item.name
            }) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                children: item.name
            })
        }, item.name));
};
const ReadFile = (param)=>{
    let { file, prefixCls, size, images, setFileIndex, setVisible, preview } = param;
    const { viewComponet } = preview;
    const handleClick = (e)=>{
        const index = images.indexOf(file);
        e.preventDefault();
        e.stopPropagation();
        setVisible(true);
        setFileIndex(index);
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])("".concat(prefixCls, "-list-picture-card-container"), "".concat(prefixCls, "-list-item-container")),
        style: {
            position: 'relative'
        },
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])("".concat(prefixCls, "-list-item"), "".concat(prefixCls, "-list-item-done"), "".concat(prefixCls, "-list-item-list-type-picture-card")),
                children: [
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                        className: "".concat(prefixCls, "-list-item-info"),
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("span", {
                            className: "".concat(prefixCls, "-span"),
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("a", {
                                    className: "".concat(prefixCls, "-list-item-thumbnail"),
                                    href: file.url,
                                    target: "_blank",
                                    rel: "noopener noreferrer",
                                    onClick: handleClick,
                                    style: {
                                        lineHeight: '100%'
                                    },
                                    children: viewComponet({
                                        images,
                                        size,
                                        prefixCls,
                                        file,
                                        setFileIndex,
                                        setVisible
                                    })
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("a", {
                                    target: "_blank",
                                    rel: "noopener noreferrer",
                                    className: "".concat(prefixCls, "-list-item-name"),
                                    title: file.title,
                                    href: file.url,
                                    onClick: handleClick,
                                    children: file.title
                                })
                            ]
                        })
                    }),
                    'small' !== size && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                        className: "".concat(prefixCls, "-list-item-actions"),
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                            size: 3,
                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
                                size: 'small',
                                type: 'text',
                                icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.DownloadOutlined, {}),
                                onClick: (e)=>{
                                    e.preventDefault();
                                    e.stopPropagation();
                                    (0, __WEBPACK_EXTERNAL_MODULE_file_saver__.saveAs)(file.url, "".concat(file.title).concat(file.extname));
                                }
                            })
                        })
                    })
                ]
            }),
            images.length > 1 && 'small' === size && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                style: {
                    position: 'absolute',
                    bottom: '0',
                    right: '0',
                    backgroundColor: '#9b999992',
                    width: '50%',
                    height: '30%',
                    lineHeight: '30%',
                    borderRadius: '40%',
                    textAlign: 'center'
                },
                children: "..."
            })
        ]
    }, file.name);
};
export { ReadFile, ReadPretty };
