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_classnames__ from "classnames";
import * as __WEBPACK_EXTERNAL_MODULE__icon_index_mjs__ from "../../../icon/index.mjs";
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__SchemaInitializerSubMenu_mjs__ from "./SchemaInitializerSubMenu.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__style_mjs__ from "./style.mjs";
const SchemaInitializerItem = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)(/*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].forwardRef((props, ref)=>{
    const { style, name = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)(), applyMenuStyle = true, className, items, icon, title, onClick, children } = props;
    const compile = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useCompile)();
    const childrenItems = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useSchemaInitializerMenuItems)(items, name, onClick);
    const { componentCls, hashId } = (0, __WEBPACK_EXTERNAL_MODULE__style_mjs__.useSchemaInitializerStyles)();
    const { attribute } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useAriaAttributeOfMenuItem)();
    const menuItems = (0, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__icon_index_mjs__.Icon, {
                    type: icon
                }) : icon,
                children: childrenItems
            }
        ];
    }, [
        name,
        style,
        className,
        children,
        title,
        onClick,
        icon,
        childrenItems
    ]);
    if (items && items.length > 0) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaInitializerSubMenu_mjs__.SchemaInitializerMenu, {
        items: menuItems
    });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        ref: ref,
        onClick: (event)=>{
            event.stopPropagation();
            null == onClick || onClick({
                event,
                item: props
            });
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
            ...attribute,
            className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])({
                ["".concat(componentCls, "-menu-item")]: applyMenuStyle
            }, className),
            style: style,
            children: children || /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
                children: [
                    icon && 'string' == typeof icon ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__icon_index_mjs__.Icon, {
                        type: icon
                    }) : icon,
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                        className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])({
                            ["".concat(hashId, " ").concat(componentCls, "-item-content")]: icon
                        }),
                        children: compile(title)
                    })
                ]
            })
        })
    });
}));
SchemaInitializerItem.displayName = 'SchemaInitializerItem';
const SchemaInitializerItemInternal = ()=>{
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__context_index_mjs__.useSchemaInitializerItem)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SchemaInitializerItem, {
        ...itemConfig
    });
};
export { SchemaInitializerItem, SchemaInitializerItemInternal };
