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__schema_component_index_mjs__ from "../../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__context_index_mjs__ from "../context/index.mjs";
const SchemaInitializerChildren = (props)=>{
    const { children } = props;
    if (!children) return null;
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
        children: children.sort((a, b)=>(a.sort || 0) - (b.sort || 0)).map((item, index)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.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, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useFindComponent)();
    const componentVal = Component || component;
    const isBuiltType = !componentVal && type && typeComponentMap[type];
    const componentChildren = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        const res = [
            ...useChildrenRes || [],
            ...children || []
        ];
        return 0 === res.length ? void 0 : res;
    }, [
        useChildrenRes,
        children
    ]);
    const contextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_index_mjs__.SchemaInitializerItemContext.Provider, {
        value: contextValue,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(C, {
            ...componentProps,
            ...useComponentPropsRes,
            children: componentChildren
        })
    });
});
SchemaInitializerChild.displayName = 'SchemaInitializerChild';
export { SchemaInitializerChild, SchemaInitializerChildren };
