"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    ReadPretty: ()=>ReadPretty,
    ReadFile: ()=>ReadFile
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const client_namespaceObject = require("@tachybase/utils/client");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const style_namespaceObject = require("antd/es/upload/style");
var style_default = /*#__PURE__*/ __webpack_require__.n(style_namespaceObject);
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const external_file_saver_namespaceObject = require("file-saver");
const index_js_namespaceObject = require("../../../application/hooks/index.js");
const external_record_provider_index_js_namespaceObject = require("../../../record-provider/index.js");
const external_shared_js_namespaceObject = require("./shared.js");
const external_style_js_namespaceObject = require("./style.js");
const ReadPretty = ()=>null;
ReadPretty.File = function(props) {
    var _images_fileIndex, _images_, _images_1, _images_fileIndex1;
    const { size, showCount = 0 } = props;
    const record = (0, external_record_provider_index_js_namespaceObject.useRecord)();
    const field = (0, schema_namespaceObject.useField)();
    const images = (0, client_namespaceObject.isString)(field.value) ? record : (0, external_shared_js_namespaceObject.toFileList)(field.value);
    const app = (0, index_js_namespaceObject.useApp)();
    const [fileIndex, setFileIndex] = (0, external_react_namespaceObject.useState)(0);
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const { wrapSSR, hashId, componentCls: prefixCls } = (0, external_style_js_namespaceObject.useStyles)();
    const useUploadStyleVal = style_default()["default"] ? style_default()["default"] : style_default();
    const previewList = app.AttachmentPreviewManager.get();
    useUploadStyleVal(prefixCls);
    return wrapSSR(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                className: external_classnames_default()("".concat(prefixCls, "-wrapper"), "".concat(prefixCls, "-picture-card-wrapper"), "tb-upload", size ? "tb-upload-".concat(size) : null, hashId),
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    className: external_classnames_default()("".concat(prefixCls, "-list"), "".concat(prefixCls, "-list-picture-card")),
                    children: images.map((file, index)=>{
                        if ('small' === size) return 0 === index && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(ReadFile, {
                            file: file,
                            prefixCls: prefixCls,
                            size: size,
                            images: images,
                            setFileIndex: setFileIndex,
                            setVisible: setVisible,
                            preview: previewList['image/jpeg']
                        }, index);
                    })
                })
            }),
            visible && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.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, jsx_runtime_namespaceObject.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, external_file_saver_namespaceObject.saveAs)(file.url, "".concat(file.title).concat(file.extname));
                        },
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.DownloadOutlined, {})
                    }, 'download')
                ]
            })
        ]
    }));
};
ReadPretty.Upload = function() {
    const field = (0, schema_namespaceObject.useField)();
    return (field.value || []).map((item)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            children: item.url ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("a", {
                target: '_blank',
                href: item.url,
                rel: "noreferrer",
                children: item.name
            }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.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, jsx_runtime_namespaceObject.jsxs)("div", {
        className: external_classnames_default()("".concat(prefixCls, "-list-picture-card-container"), "".concat(prefixCls, "-list-item-container")),
        style: {
            position: 'relative'
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                className: external_classnames_default()("".concat(prefixCls, "-list-item"), "".concat(prefixCls, "-list-item-done"), "".concat(prefixCls, "-list-item-list-type-picture-card")),
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                        className: "".concat(prefixCls, "-list-item-info"),
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("span", {
                            className: "".concat(prefixCls, "-span"),
                            children: [
                                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.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, jsx_runtime_namespaceObject.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, jsx_runtime_namespaceObject.jsx)("span", {
                        className: "".concat(prefixCls, "-list-item-actions"),
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Space, {
                            size: 3,
                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                                size: 'small',
                                type: 'text',
                                icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.DownloadOutlined, {}),
                                onClick: (e)=>{
                                    e.preventDefault();
                                    e.stopPropagation();
                                    (0, external_file_saver_namespaceObject.saveAs)(file.url, "".concat(file.title).concat(file.extname));
                                }
                            })
                        })
                    })
                ]
            }),
            images.length > 1 && 'small' === size && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                style: {
                    position: 'absolute',
                    bottom: '0',
                    right: '0',
                    backgroundColor: '#9b999992',
                    width: '50%',
                    height: '30%',
                    lineHeight: '30%',
                    borderRadius: '40%',
                    textAlign: 'center'
                },
                children: "..."
            })
        ]
    }, file.name);
};
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
});
