"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__, {
    SchemaInitializerItemInternal: ()=>SchemaInitializerItemInternal,
    SchemaInitializerItem: ()=>SchemaInitializerItem
});
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_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const index_js_namespaceObject = require("../../../icon/index.js");
const external_schema_component_index_js_namespaceObject = require("../../../schema-component/index.js");
const external_context_index_js_namespaceObject = require("../context/index.js");
const external_hooks_index_js_namespaceObject = require("../hooks/index.js");
const external_SchemaInitializerSubMenu_js_namespaceObject = require("./SchemaInitializerSubMenu.js");
const external_style_js_namespaceObject = require("./style.js");
const SchemaInitializerItem = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(/*#__PURE__*/ external_react_default().forwardRef((props, ref)=>{
    const { style, name = (0, schema_namespaceObject.uid)(), applyMenuStyle = true, className, items, icon, title, onClick, children } = props;
    const compile = (0, external_schema_component_index_js_namespaceObject.useCompile)();
    const childrenItems = (0, external_hooks_index_js_namespaceObject.useSchemaInitializerMenuItems)(items, name, onClick);
    const { componentCls, hashId } = (0, external_style_js_namespaceObject.useSchemaInitializerStyles)();
    const { attribute } = (0, external_hooks_index_js_namespaceObject.useAriaAttributeOfMenuItem)();
    const menuItems = (0, external_react_namespaceObject.useMemo)(()=>{
        if (!(items && items.length > 0)) return;
        return [
            {
                key: name,
                style: style,
                className: className,
                label: children || compile(title),
                onClick: (info)=>{
                    if (info.key !== name) return;
                    null == onClick || onClick({
                        ...info,
                        item: props
                    });
                },
                icon: 'string' == typeof icon ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.Icon, {
                    type: icon
                }) : icon,
                children: childrenItems
            }
        ];
    }, [
        name,
        style,
        className,
        children,
        title,
        onClick,
        icon,
        childrenItems
    ]);
    if (items && items.length > 0) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_SchemaInitializerSubMenu_js_namespaceObject.SchemaInitializerMenu, {
        items: menuItems
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        ref: ref,
        onClick: (event)=>{
            event.stopPropagation();
            null == onClick || onClick({
                event,
                item: props
            });
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            ...attribute,
            className: external_classnames_default()({
                ["".concat(componentCls, "-menu-item")]: applyMenuStyle
            }, className),
            style: style,
            children: children || /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                children: [
                    icon && 'string' == typeof icon ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.Icon, {
                        type: icon
                    }) : icon,
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                        className: external_classnames_default()({
                            ["".concat(hashId, " ").concat(componentCls, "-item-content")]: icon
                        }),
                        children: compile(title)
                    })
                ]
            })
        })
    });
}));
SchemaInitializerItem.displayName = 'SchemaInitializerItem';
const SchemaInitializerItemInternal = ()=>{
    const itemConfig = (0, external_context_index_js_namespaceObject.useSchemaInitializerItem)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaInitializerItem, {
        ...itemConfig
    });
};
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
});
