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_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE__emotion_css__ from "@emotion/css";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_classnames__ from "classnames";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "./index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__Action_Modal_style_mjs__ from "./Action.Modal.style.mjs";
import "./hooks/useSetAriaLabelForModal.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n                  background: none;\n                  border: none;\n                "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
function _templateObject1() {
    const data = _tagged_template_literal([
        "\n        background: none;\n        border: none;\n      "
    ]);
    _templateObject1 = function() {
        return data;
    };
    return data;
}
const openSizeWidthMap = new Map([
    [
        'small',
        '40%'
    ],
    [
        'middle',
        '60%'
    ],
    [
        'large',
        '80%'
    ]
]);
const ActionModal = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { footerNodeName = 'Action.Modal.Footer', width, ...others } = props;
    const { styles } = (0, __WEBPACK_EXTERNAL_MODULE__Action_Modal_style_mjs__.useStyles)();
    const { visible, setVisible, openSize = 'middle', modalProps } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useActionContext)();
    const actualWidth = null != width ? width : openSizeWidthMap.get(openSize);
    const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const footerSchema = schema.reduceProperties((buf, s)=>{
        if (s['x-component'] === footerNodeName) return s;
        return buf;
    });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Modal, {
        className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(others.className, null == modalProps ? void 0 : modalProps.className, styles.container, 'amplifier-block'),
        style: {
            ...null == modalProps ? void 0 : modalProps.style,
            ...null == others ? void 0 : others.style
        },
        width: actualWidth,
        title: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
            style: {
                display: 'flex'
            },
            children: [
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                    style: {
                        flex: 1
                    },
                    children: field.title
                }),
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Amplifier, {}),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
                            type: "text",
                            icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.CloseOutlined, {}),
                            className: (0, __WEBPACK_EXTERNAL_MODULE__emotion_css__.css)(_templateObject()),
                            onClick: ()=>setVisible(false, true)
                        })
                    ]
                })
            ]
        }),
        ...others,
        ...modalProps,
        destroyOnClose: true,
        open: visible,
        closable: false,
        footer: !!footerSchema && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
            basePath: field.address,
            schema: schema,
            onlyRenderProperties: true,
            filterProperties: (s)=>s['x-component'] === footerNodeName
        }),
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
            className: styles.modalClassName,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                basePath: field.address,
                schema: schema,
                onlyRenderProperties: true,
                filterProperties: (s)=>s['x-component'] !== footerNodeName
            })
        })
    });
}, {
    displayName: 'ActionModal'
});
ActionModal.Footer = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)(()=>{
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
        basePath: field.address,
        schema: schema,
        onlyRenderProperties: true
    });
}, {
    displayName: 'ActionModal.Footer'
});
const Action_Modal_rslib_entry_ = ActionModal;
const Amplifier = ()=>{
    const [isAmplifier, setIsAmplifier] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const [blockWidth, setBlockWidth] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)('');
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
        icon: isAmplifier ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.FullscreenExitOutlined, {}) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.FullscreenOutlined, {}),
        type: "text",
        className: (0, __WEBPACK_EXTERNAL_MODULE__emotion_css__.css)(_templateObject1()),
        onClick: (e)=>{
            const element = e.target.closest('.ant-modal-content');
            const modal = document.querySelector('.ant-modal');
            const mask = document.querySelector('.ant-modal-mask');
            if (isAmplifier) {
                modal.style.width = blockWidth;
                element.style.width = '';
                modal.style.top = '';
                modal.style.padding = '';
                modal.style.margin = '';
                mask.style.backgroundColor = '';
            } else {
                setBlockWidth(modal.getBoundingClientRect().width + 'px');
                element.style.width = '100vw';
                modal.style.width = '100%';
                modal.style.top = '0';
                modal.style.padding = '0';
                modal.style.margin = '0';
                mask.style.backgroundColor = '#f3f3f3';
            }
            setIsAmplifier(!isAmplifier);
        }
    });
};
export { ActionModal, Amplifier, Action_Modal_rslib_entry_ as default };
