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__Action_Drawer_style_mjs__ from "./Action.Drawer.style.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_mjs__ from "./hooks.mjs";
import "./hooks/useSetAriaLabelForDrawer.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',
        '30%'
    ],
    [
        'middle',
        '50%'
    ],
    [
        'large',
        '70%'
    ]
]);
const ActionDrawer = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { footerNodeName = 'Action.Drawer.Footer', ...others } = props;
    const { visible, setVisible, openSize = 'middle', drawerProps } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_mjs__.useActionContext)();
    const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const { componentCls, hashId } = (0, __WEBPACK_EXTERNAL_MODULE__Action_Drawer_style_mjs__.useStyles)();
    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__.Drawer, {
        width: openSizeWidthMap.get(openSize),
        extra: /*#__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)
                })
            ]
        }),
        title: field.title,
        ...others,
        ...drawerProps,
        rootStyle: {
            ...null == drawerProps ? void 0 : drawerProps.style,
            ...null == others ? void 0 : others.style
        },
        destroyOnClose: true,
        closable: false,
        open: visible,
        onClose: ()=>setVisible(false, true),
        rootClassName: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(componentCls, hashId, null == drawerProps ? void 0 : drawerProps.className, others.className, 'reset'),
        footer: footerSchema && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
            className: 'footer',
            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
            })
        }),
        className: "".concat(props.className, " amplifier-block"),
        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: 'ActionDrawer'
});
ActionDrawer.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: 'ActionDrawer.Footer'
});
const Action_Drawer_rslib_entry_ = ActionDrawer;
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, {
        type: "text",
        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, {}),
        className: (0, __WEBPACK_EXTERNAL_MODULE__emotion_css__.css)(_templateObject1()),
        onClick: (e)=>{
            const element = e.target.closest('.ant-drawer-content-wrapper');
            if (isAmplifier) element.style.width = blockWidth;
            else {
                setBlockWidth(element.getBoundingClientRect().width + 'px');
                element.style.width = '100%';
            }
            setIsAmplifier(!isAmplifier);
        }
    });
};
export { ActionDrawer, Amplifier, Action_Drawer_rslib_entry_ as default };
