"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__, {
    withInitializer: ()=>withInitializer
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_antd_style_namespaceObject = require("antd-style");
const useNiceDropdownHeight_js_namespaceObject = require("../../../common/useNiceDropdownHeight.js");
const index_js_namespaceObject = require("../../../flag-provider/index.js");
const external_schema_component_index_js_namespaceObject = require("../../../schema-component/index.js");
const style_js_namespaceObject = require("../components/style.js");
const external_context_index_js_namespaceObject = require("../context/index.js");
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      .ant-popover-inner {\n        padding: ",
        ";\n        .ant-menu-submenu-title {\n          margin-block: 0;\n        }\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const defaultWrap = (s)=>s;
const useStyles = (0, external_antd_style_namespaceObject.createStyles)((param)=>{
    let { css, token } = param;
    return {
        popover: css(_templateObject(), "".concat(token.paddingXXS, "px 0"))
    };
});
function withInitializer(C) {
    const WithInitializer = (0, schema_namespaceObject.observer)((props)=>{
        const { designable, insertAdjacent } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        const { isInSubTable } = (0, index_js_namespaceObject.useFlag)() || {};
        const { insert, useInsert, wrap = defaultWrap, insertPosition = 'beforeEnd', onSuccess, designable: propsDesignable, popoverProps, children, popover = true, style, componentProps } = props;
        const insertCallback = useInsert ? useInsert() : insert;
        const insertSchema = (0, external_react_namespaceObject.useCallback)((schema)=>{
            if (insertCallback) insertCallback(wrap(schema, {
                isInSubTable
            }));
            else insertAdjacent(insertPosition, wrap(schema, {
                isInSubTable
            }), {
                onSuccess
            });
        }, [
            insertCallback,
            wrap,
            insertAdjacent,
            insertPosition,
            onSuccess
        ]);
        const { wrapSSR, hashId, componentCls } = (0, style_js_namespaceObject.useSchemaInitializerStyles)();
        const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
        const { token } = external_antd_namespaceObject.theme.useToken();
        const { styles } = useStyles();
        const dropdownMaxHeight = (0, useNiceDropdownHeight_js_namespaceObject.useNiceDropdownMaxHeight)([
            visible
        ]);
        const cProps = (0, external_react_namespaceObject.useMemo)(()=>({
                options: props,
                style,
                ...componentProps
            }), [
            componentProps,
            props,
            style
        ]);
        if (!designable && true !== propsDesignable) return null;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_index_js_namespaceObject.SchemaInitializerContext.Provider, {
            value: {
                visible,
                setVisible,
                insert: insertSchema,
                options: props
            },
            children: false === popover ? /*#__PURE__*/ external_react_default().createElement(C, cProps) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Popover, {
                placement: 'bottomLeft',
                ...popoverProps,
                arrow: false,
                overlayClassName: styles.popover,
                open: visible,
                onOpenChange: setVisible,
                content: wrapSSR(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    className: "".concat(componentCls, " ").concat(hashId),
                    style: {
                        maxHeight: dropdownMaxHeight,
                        overflowY: 'auto'
                    },
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.ConfigProvider, {
                        theme: {
                            components: {
                                Menu: {
                                    itemHeight: token.marginXL,
                                    borderRadius: token.borderRadiusSM,
                                    itemBorderRadius: token.borderRadiusSM,
                                    subMenuItemBorderRadius: token.borderRadiusSM
                                }
                            }
                        },
                        children: children
                    })
                })),
                children: /*#__PURE__*/ external_react_default().createElement(C, cProps)
            })
        });
    }, {
        displayName: "WithInitializer(".concat(C.displayName || C.name, ")")
    });
    return WithInitializer;
}
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
});
