"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    SchemaInitializerChild: ()=>SchemaInitializerChild,
    SchemaInitializerChildren: ()=>SchemaInitializerChildren
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const index_js_namespaceObject = require("../../../schema-component/index.js");
const external_context_index_js_namespaceObject = require("../context/index.js");
const SchemaInitializerChildren = (props)=>{
    const { children } = props;
    if (!children) return null;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
        children: children.sort((a, b)=>(a.sort || 0) - (b.sort || 0)).map((item, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaInitializerChild, {
                ...item
            }, item.name || item.key || index))
    });
};
const typeComponentMap = {
    item: 'SchemaInitializerItemInternal',
    itemGroup: 'SchemaInitializerItemGroupInternal',
    divider: 'SchemaInitializerDivider',
    subMenu: 'SchemaInitializerSubMenuInternal',
    actionModal: 'SchemaInitializerActionModalInternal'
};
const useChildrenDefault = ()=>void 0;
const useVisibleDefault = ()=>true;
const useComponentPropsDefault = ()=>void 0;
const SchemaInitializerChild = /*#__PURE__*/ (0, external_react_namespaceObject.memo)((props)=>{
    const { type, Component, component, children, useVisible = useVisibleDefault, useChildren = useChildrenDefault, useComponentProps = useComponentPropsDefault, hideIfNoChildren, componentProps, sort: _unUse, ...others } = props;
    const useChildrenRes = useChildren();
    const useComponentPropsRes = useComponentProps();
    const findComponent = (0, index_js_namespaceObject.useFindComponent)();
    const componentVal = Component || component;
    const isBuiltType = !componentVal && type && typeComponentMap[type];
    const componentChildren = (0, external_react_namespaceObject.useMemo)(()=>{
        const res = [
            ...useChildrenRes || [],
            ...children || []
        ];
        return 0 === res.length ? void 0 : res;
    }, [
        useChildrenRes,
        children
    ]);
    const contextValue = (0, external_react_namespaceObject.useMemo)(()=>({
            ...others,
            ...isBuiltType ? useComponentPropsRes : {},
            ...isBuiltType ? componentProps : {},
            children: componentChildren
        }), [
        others,
        isBuiltType,
        useComponentPropsRes,
        componentProps,
        componentChildren
    ]);
    const visibleResult = useVisible();
    if (!visibleResult) return null;
    if (!type && !componentVal) return null;
    const C = findComponent(isBuiltType ? typeComponentMap[type] : componentVal);
    if (!C) return null;
    if (hideIfNoChildren && Array.isArray(componentChildren) && 0 === componentChildren.length) return null;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_index_js_namespaceObject.SchemaInitializerItemContext.Provider, {
        value: contextValue,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(C, {
            ...componentProps,
            ...useComponentPropsRes,
            children: componentChildren
        })
    });
});
SchemaInitializerChild.displayName = 'SchemaInitializerChild';
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
});
