"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__, {
    SchemaSettingsChild: ()=>SchemaSettingsChild,
    SchemaSettingsChildren: ()=>SchemaSettingsChildren
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const useFieldComponentName_js_namespaceObject = require("../../../common/useFieldComponentName.js");
const index_js_namespaceObject = require("../../../schema-component/index.js");
const SchemaSettings_js_namespaceObject = require("../../../schema-settings/SchemaSettings.js");
const external_context_index_js_namespaceObject = require("../context/index.js");
const typeComponentMap = {
    item: SchemaSettings_js_namespaceObject.SchemaSettingsItem,
    itemGroup: SchemaSettings_js_namespaceObject.SchemaSettingsItemGroup,
    subMenu: SchemaSettings_js_namespaceObject.SchemaSettingsSubMenu,
    divider: SchemaSettings_js_namespaceObject.SchemaSettingsDivider,
    remove: SchemaSettings_js_namespaceObject.SchemaSettingsRemove,
    select: SchemaSettings_js_namespaceObject.SchemaSettingsSelectItem,
    cascader: SchemaSettings_js_namespaceObject.SchemaSettingsCascaderItem,
    switch: SchemaSettings_js_namespaceObject.SchemaSettingsSwitchItem,
    popup: SchemaSettings_js_namespaceObject.SchemaSettingsPopupItem,
    actionModal: SchemaSettings_js_namespaceObject.SchemaSettingsActionModalItem,
    modal: SchemaSettings_js_namespaceObject.SchemaSettingsModalItem
};
const SchemaSettingsChildren = (props)=>{
    const { children } = props;
    const { visible } = (0, SchemaSettings_js_namespaceObject.useSchemaSettings)();
    const firstVisible = (0, external_react_namespaceObject.useRef)(false);
    const fieldComponentName = (0, useFieldComponentName_js_namespaceObject.useFieldComponentName)();
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (visible) firstVisible.current = true;
    }, [
        visible
    ]);
    if (!visible && !firstVisible.current) return null;
    if (!children || 0 === children.length) 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)=>{
            const key = "".concat(fieldComponentName ? fieldComponentName + '-' : '').concat(item.name);
            return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsChild, {
                ...item
            }, key);
        })
    });
};
const useChildrenDefault = ()=>void 0;
const useComponentPropsDefault = ()=>void 0;
const useVisibleDefault = ()=>true;
const InternalComponent = (param)=>{
    let { Component, componentProps, useComponentProps, children } = param;
    const useComponentPropsRes = useComponentProps();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Component, {
        ...componentProps,
        ...useComponentPropsRes,
        children: children
    });
};
const SchemaSettingsChild = /*#__PURE__*/ (0, external_react_namespaceObject.memo)((props)=>{
    const { useVisible = useVisibleDefault, useChildren = useChildrenDefault, useComponentProps = useComponentPropsDefault, type, Component, children, hideIfNoChildren = true, componentProps } = props;
    const useChildrenRes = useChildren();
    const findComponent = (0, index_js_namespaceObject.useFindComponent)();
    const componentChildren = (0, external_react_namespaceObject.useMemo)(()=>{
        const res = [
            ...useChildrenRes || [],
            ...children || []
        ];
        return 0 === res.length ? void 0 : res;
    }, [
        useChildrenRes,
        children
    ]);
    const visibleResult = useVisible();
    const ComponentValue = (0, external_react_namespaceObject.useMemo)(()=>!Component && type && typeComponentMap[type] ? typeComponentMap[type] : Component, [
        type,
        Component
    ]);
    if (!visibleResult) return null;
    if (!type && !Component) return null;
    const C = findComponent(ComponentValue);
    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.SchemaSettingItemContext.Provider, {
        value: props,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(InternalComponent, {
            Component: C,
            useComponentProps: useComponentProps,
            componentProps: componentProps,
            children: Array.isArray(componentChildren) && componentChildren.length > 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsChildren, {
                children: componentChildren
            })
        })
    });
});
SchemaSettingsChild.displayName = 'SchemaSettingsChild';
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
});
