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_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_antd_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__context_index_mjs__ from "../context/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../hooks/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__style_mjs__ from "./style.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      box-shadow: none !important;\n      border-inline-end: 0 !important;\n      .ant-menu-sub {\n        max-height: 50vh !important;\n      }\n      .ant-menu-item {\n        margin-block: 0;\n      }\n      .ant-menu-root {\n        margin: 0 -",
        "px;\n        .ant-menu-submenu-title,\n        .ant-menu-item-only-child {\n          margin-inline: 0;\n          margin-block: 0;\n          width: 100%;\n        }\n      }\n      // associated issue https://github.com/ant-design/ant-design/issues/51361\n      .ant-menu-title-content {\n        display: inline;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css, token } = param;
    return {
        menu: css(_templateObject(), token.margin)
    };
});
const SchemaInitializerSubMenuContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext({});
const SchemaInitializerMenuProvider = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SchemaInitializerSubMenuContext.Provider, {
        value: {
            isInMenu: true
        },
        children: props.children
    });
const useSchemaInitializerSubMenuContext = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(SchemaInitializerSubMenuContext);
const SchemaInitializerMenu = (props)=>{
    const { componentCls, hashId } = (0, __WEBPACK_EXTERNAL_MODULE__style_mjs__.useSchemaInitializerStyles)();
    const { items, ...others } = props;
    const { token } = __WEBPACK_EXTERNAL_MODULE_antd__.theme.useToken();
    const { styles } = useStyles();
    const itemsWithPopupClass = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>items.map((item)=>({
                ...item,
                popupClassName: "".concat(hashId, " ").concat(componentCls, "-menu-sub")
            })), [
        componentCls,
        hashId,
        items
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SchemaInitializerMenuProvider, {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Menu, {
            selectable: false,
            expandIcon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.RightOutlined, {
                style: {
                    fontSize: token.fontSizeSM,
                    color: token.colorTextDescription
                }
            }),
            rootClassName: styles.menu,
            items: itemsWithPopupClass,
            ...others
        })
    });
};
const SchemaInitializerSubMenu = (props)=>{
    const { children, title, name = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)(), onOpenChange, icon, ...others } = props;
    const compile = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useCompile)();
    const validChildren = null == children ? void 0 : children.filter((item)=>!item.useVisible || item.useVisible());
    const childrenItems = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useSchemaInitializerMenuItems)(validChildren, name);
    const items = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>[
            {
                ...others,
                key: name,
                label: compile(title),
                icon: 'string' == typeof icon ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__["default"], {
                    type: icon
                }) : icon,
                children: childrenItems
            }
        ], [
        childrenItems,
        compile,
        icon,
        name,
        others,
        title
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SchemaInitializerMenu, {
        onOpenChange: onOpenChange,
        items: items
    });
};
const SchemaInitializerSubMenuInternal = ()=>{
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__context_index_mjs__.useSchemaInitializerItem)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SchemaInitializerSubMenu, {
        ...itemConfig
    });
};
export { SchemaInitializerMenu, SchemaInitializerSubMenu, SchemaInitializerSubMenuInternal, useSchemaInitializerSubMenuContext };
