"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__, {
    SchemaSettingsSwitchItem: ()=>SchemaSettingsSwitchItem,
    SchemaSettingsCascaderItem: ()=>SchemaSettingsCascaderItem,
    SchemaSettingsLinkageRules: ()=>SchemaSettingsLinkageRules,
    getFieldDefaultValue: ()=>getFieldDefaultValue,
    SchemaSettingsPopupItem: ()=>SchemaSettingsPopupItem,
    SchemaSettingsFormItemTemplate: ()=>SchemaSettingsFormItemTemplate,
    SchemaSettingsModalItem: ()=>SchemaSettingsModalItem,
    SchemaSettingsEnableChildCollections: ()=>SchemaSettingsEnableChildCollections,
    SchemaSettingsRemove: ()=>SchemaSettingsRemove,
    SchemaSettingsConnectDataBlocks: ()=>SchemaSettingsConnectDataBlocks,
    SchemaSettingsItemGroup: ()=>SchemaSettingsItemGroup,
    SchemaSettingsSortField: ()=>SchemaSettingsSortField,
    SchemaSettingsSelectItem: ()=>SchemaSettingsSelectItem,
    SchemaSettingsSubMenu: ()=>SchemaSettingsSubMenu,
    SchemaSettingsTemplate: ()=>SchemaSettingsTemplate,
    useSchemaSettings: ()=>useSchemaSettings,
    SchemaSettingsDivider: ()=>SchemaSettingsDivider,
    SchemaSettingsDataTemplates: ()=>SchemaSettingsDataTemplates,
    SchemaSettingsBlockTitleItem: ()=>SchemaSettingsBlockTitleItem,
    SchemaSettingsActionModalItem: ()=>SchemaSettingsActionModalItem,
    SchemaSettingsItem: ()=>SchemaSettingsItem,
    SchemaSettingsProvider: ()=>SchemaSettingsProvider,
    findParentFieldSchema: ()=>findParentFieldSchema,
    isSystemField: ()=>isSystemField,
    SchemaSettingsDefaultSortingRules: ()=>SchemaSettingsDefaultSortingRules,
    useDataTemplates: ()=>useDataTemplates,
    SchemaSettingsDropdown: ()=>SchemaSettingsDropdown
});
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 components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const client_namespaceObject = require("@tachybase/utils/client");
const external_antd_namespaceObject = require("antd");
const external_antd_style_namespaceObject = require("antd-style");
const external_lodash_namespaceObject = require("lodash");
var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
const external_react_dom_namespaceObject = require("react-dom");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_react_router_dom_namespaceObject = require("react-router-dom");
const external_index_js_namespaceObject = require("../index.js");
const index_js_namespaceObject = require("../block-provider/index.js");
const hooks_index_js_namespaceObject = require("../block-provider/hooks/index.js");
const SelectWithTitle_js_namespaceObject = require("../common/SelectWithTitle.js");
const useNiceDropdownHeight_js_namespaceObject = require("../common/useNiceDropdownHeight.js");
const DataSourceManagerProvider_js_namespaceObject = require("../data-source/data-source/DataSourceManagerProvider.js");
const DataSourceProvider_js_namespaceObject = require("../data-source/data-source/DataSourceProvider.js");
const utils_js_namespaceObject = require("../filter-provider/utils.js");
const external_flag_provider_index_js_namespaceObject = require("../flag-provider/index.js");
const useMenuItem_js_namespaceObject = require("../hooks/useMenuItem.js");
const DeclareVariable_js_namespaceObject = require("../modules/variable/DeclareVariable.js");
const useVariable_js_namespaceObject = require("../modules/variable/useVariable.js");
const hooks_js_namespaceObject = require("../schema-component/antd/association-field/hooks.js");
const utilts_js_namespaceObject = require("../schema-component/antd/association-filter/utilts.js");
const external_schema_templates_index_js_namespaceObject = require("../schema-templates/index.js");
const BlockTemplate_js_namespaceObject = require("../schema-templates/BlockTemplate.js");
const external_variables_index_js_namespaceObject = require("../variables/index.js");
const external_DataTemplates_index_js_namespaceObject = require("./DataTemplates/index.js");
const external_EnableChildCollections_index_js_namespaceObject = require("./EnableChildCollections/index.js");
const DynamicComponent_js_namespaceObject = require("./EnableChildCollections/DynamicComponent.js");
const external_LinkageRules_index_js_namespaceObject = require("./LinkageRules/index.js");
const action_hooks_js_namespaceObject = require("./LinkageRules/action-hooks.js");
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      .ant-dropdown-menu-item-group-list {\n        max-height: 300px;\n        overflow-y: auto;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
function _templateObject1() {
    const data = _tagged_template_literal([
        "\n      // screen > 576px\n      @media (min-width: 576px) {\n        min-width: 520px;\n      }\n\n      // screen <= 576px\n      @media (max-width: 576px) {\n        min-width: 320px;\n      }\n    "
    ]);
    _templateObject1 = function() {
        return data;
    };
    return data;
}
const SchemaSettingsContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
SchemaSettingsContext.displayName = 'SchemaSettingsContext';
function useSchemaSettings() {
    return (0, external_react_namespaceObject.useContext)(SchemaSettingsContext);
}
const useStyles = (0, external_antd_style_namespaceObject.createStyles)((param)=>{
    let { css } = param;
    return {
        menu: css(_templateObject()),
        modal: css(_templateObject1())
    };
});
const SchemaSettingsProvider = (props)=>{
    const { children, fieldSchema, ...others } = props;
    const { getTemplateBySchema } = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplateManager)();
    const { name } = (0, external_index_js_namespaceObject.useCollection_deprecated)();
    const template = getTemplateBySchema(fieldSchema);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsContext.Provider, {
        value: {
            collectionName: name,
            template,
            fieldSchema,
            ...others
        },
        children: children
    });
};
const SchemaSettingsDropdown = (props)=>{
    const { title, dn, ...others } = props;
    const { styles } = useStyles();
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const { Component, getMenuItems } = (0, useMenuItem_js_namespaceObject.useMenuItem)();
    const [, startTransition] = (0, external_react_namespaceObject.useTransition)();
    const dropdownMaxHeight = (0, useNiceDropdownHeight_js_namespaceObject.useNiceDropdownMaxHeight)([
        visible
    ]);
    const changeMenu = (0, external_react_namespaceObject.useCallback)((nextOpen, info)=>{
        if ('trigger' === info.source || nextOpen) startTransition(()=>{
            setVisible(nextOpen);
        });
    }, []);
    const items = getMenuItems(()=>props.children);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(SchemaSettingsProvider, {
        visible: visible,
        setVisible: setVisible,
        dn: dn,
        ...others,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Component, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Dropdown, {
                open: visible,
                onOpenChange: changeMenu,
                overlayClassName: styles.menu,
                menu: {
                    items,
                    style: {
                        maxHeight: dropdownMaxHeight,
                        overflowY: 'auto'
                    }
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    "data-testid": props['data-testid'],
                    children: 'string' == typeof title ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                        children: title
                    }) : title
                })
            })
        ]
    });
};
const SchemaSettingsTemplate = function(props) {
    const { componentName, collectionName, resourceName, needRender } = props;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { getCollection } = (0, external_index_js_namespaceObject.useCollectionManager_deprecated)();
    const { dn, setVisible, template, fieldSchema } = useSchemaSettings();
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const api = (0, external_index_js_namespaceObject.useAPIClient)();
    const { dn: tdn } = (0, BlockTemplate_js_namespaceObject.useBlockTemplateContext)();
    const { saveAsTemplate, copyTemplateSchema } = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplateManager)();
    const { theme } = (0, external_index_js_namespaceObject.useGlobalTheme)();
    if (!collectionName && !needRender) return null;
    if (template) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: "Convert reference to duplicate",
        onClick: async ()=>{
            const schema = await copyTemplateSchema(template);
            const removed = tdn.removeWithoutEmit();
            tdn.insertAfterEnd(schema, {
                async onSuccess () {
                    await api.request({
                        url: "/uiSchemas:remove/".concat(removed['x-uid'])
                    });
                }
            });
        },
        children: t('Convert reference to duplicate')
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: "Save as template",
        onClick: async ()=>{
            setVisible(false);
            const collection = collectionName && getCollection(collectionName);
            const values = await (0, external_index_js_namespaceObject.FormDialog)(t('Save as template'), ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormLayout, {
                    layout: 'vertical',
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.SchemaComponent, {
                        components: {
                            Input: components_namespaceObject.Input,
                            FormItem: components_namespaceObject.FormItem
                        },
                        schema: {
                            type: 'object',
                            properties: {
                                name: {
                                    title: t('Template name'),
                                    required: true,
                                    default: collection ? "".concat(compile((null == collection ? void 0 : collection.title) || (null == collection ? void 0 : collection.name)), "_").concat(t(componentName)) : t(componentName),
                                    'x-decorator': 'FormItem',
                                    'x-component': 'Input'
                                }
                            }
                        }
                    })
                }), theme).open({});
            const sdn = (0, external_index_js_namespaceObject.createDesignable)({
                t,
                api,
                refresh: dn.refresh.bind(dn),
                current: fieldSchema.parent
            });
            sdn.loadAPIClientEvents();
            const { key } = await saveAsTemplate({
                collectionName,
                resourceName,
                componentName,
                dataSourceKey: collection.dataSource,
                name: values.name,
                uid: fieldSchema['x-uid']
            });
            sdn.removeWithoutEmit(fieldSchema);
            sdn.insertBeforeEnd({
                type: 'void',
                'x-component': 'BlockTemplate',
                'x-component-props': {
                    templateId: key
                }
            });
        },
        children: t('Save as template')
    });
};
const findGridSchema = (fieldSchema)=>fieldSchema.reduceProperties((buf, s)=>{
        if ('FormV2' === s['x-component'] || 'Details' === s['x-component']) {
            const f = s.reduceProperties((buf, s)=>{
                if ('Grid' === s['x-component'] || 'BlockTemplate' === s['x-component']) return s;
                return buf;
            }, null);
            if (f) return f;
        }
        return buf;
    }, null);
const findBlockTemplateSchema = (fieldSchema)=>fieldSchema.reduceProperties((buf, s)=>{
        if ('FormV2' === s['x-component'] || 'Details' === s['x-component']) {
            const f = s.reduceProperties((buf, s)=>{
                if ('BlockTemplate' === s['x-component']) return s;
                return buf;
            }, null);
            if (f) return f;
        }
        return buf;
    }, null);
const SchemaSettingsFormItemTemplate = function(props) {
    const { insertAdjacentPosition = 'beforeEnd', componentName, collectionName, resourceName } = props;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const { getCollection } = (0, external_index_js_namespaceObject.useCollectionManager_deprecated)();
    const { dn, setVisible, template, fieldSchema } = useSchemaSettings();
    const api = (0, external_index_js_namespaceObject.useAPIClient)();
    const { saveAsTemplate, copyTemplateSchema } = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplateManager)();
    const { theme } = (0, external_index_js_namespaceObject.useGlobalTheme)();
    if (!collectionName) return null;
    if (template) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: "Convert reference to duplicate",
        onClick: async ()=>{
            const schema = await copyTemplateSchema(template);
            const templateSchema = findBlockTemplateSchema(fieldSchema);
            const sdn = (0, external_index_js_namespaceObject.createDesignable)({
                t,
                api,
                refresh: dn.refresh.bind(dn),
                current: templateSchema.parent
            });
            sdn.loadAPIClientEvents();
            sdn.removeWithoutEmit(templateSchema);
            sdn.insertAdjacent(insertAdjacentPosition, schema, {
                async onSuccess () {
                    await api.request({
                        url: "/uiSchemas:remove/".concat(templateSchema['x-uid'])
                    });
                }
            });
            fieldSchema['x-template-key'] = null;
            await api.request({
                url: "uiSchemas:patch",
                method: 'post',
                data: {
                    'x-uid': fieldSchema['x-uid'],
                    'x-template-key': null
                }
            });
            dn.refresh();
        },
        children: t('Convert reference to duplicate')
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: "Save as block template",
        onClick: async ()=>{
            setVisible(false);
            const collection = collectionName && getCollection(collectionName);
            const gridSchema = findGridSchema(fieldSchema);
            const values = await (0, external_index_js_namespaceObject.FormDialog)(t('Save as template'), ()=>{
                const componentTitle = {
                    FormItem: t('Form'),
                    ReadPrettyFormItem: t('Details')
                };
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormLayout, {
                    layout: 'vertical',
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.SchemaComponent, {
                        components: {
                            Input: components_namespaceObject.Input,
                            FormItem: components_namespaceObject.FormItem
                        },
                        schema: {
                            type: 'object',
                            properties: {
                                name: {
                                    title: t('Template name'),
                                    required: true,
                                    default: collection ? "".concat(compile((null == collection ? void 0 : collection.title) || (null == collection ? void 0 : collection.name)), "_").concat(t(componentTitle[componentName] || componentName)) : t(componentTitle[componentName] || componentName),
                                    'x-decorator': 'FormItem',
                                    'x-component': 'Input'
                                }
                            }
                        }
                    })
                });
            }, theme).open({});
            const sdn = (0, external_index_js_namespaceObject.createDesignable)({
                t,
                api,
                refresh: dn.refresh.bind(dn),
                current: gridSchema.parent
            });
            sdn.loadAPIClientEvents();
            const { key } = await saveAsTemplate({
                collectionName,
                resourceName,
                componentName,
                dataSourceKey: collection.dataSource,
                name: values.name,
                uid: gridSchema['x-uid']
            });
            sdn.removeWithoutEmit(gridSchema);
            sdn.insertAdjacent(insertAdjacentPosition, {
                type: 'void',
                'x-component': 'BlockTemplate',
                'x-component-props': {
                    templateId: key
                }
            });
            fieldSchema['x-template-key'] = key;
            await api.request({
                url: "uiSchemas:patch",
                method: 'post',
                data: {
                    'x-uid': fieldSchema['x-uid'],
                    'x-template-key': key
                }
            });
        },
        children: t('Save as block template')
    });
};
const SchemaSettingsItem = (props)=>{
    const { pushMenuItem } = (0, useMenuItem_js_namespaceObject.useCollectMenuItems)();
    const { collectMenuItem } = (0, useMenuItem_js_namespaceObject.useCollectMenuItem)();
    const { eventKey, title } = props;
    const { name } = (0, external_index_js_namespaceObject.useSchemaSettingsItem)();
    const item = {
        key: title,
        ...external_lodash_default().omit(props, [
            'children',
            'name'
        ]),
        eventKey: eventKey,
        onClick: (info)=>{
            var _props_onClick;
            info.domEvent.preventDefault();
            info.domEvent.stopPropagation();
            null == props || null === (_props_onClick = props.onClick) || void 0 === _props_onClick || _props_onClick.call(props, info);
        },
        style: {
            minWidth: 120
        },
        label: props.children || props.title,
        title: props.title
    };
    null == pushMenuItem || pushMenuItem(item);
    null == collectMenuItem || collectMenuItem(item);
    return null;
};
const SchemaSettingsItemGroup = (props)=>{
    const { Component, getMenuItems } = (0, useMenuItem_js_namespaceObject.useMenuItem)();
    const { pushMenuItem } = (0, useMenuItem_js_namespaceObject.useCollectMenuItems)();
    const key = (0, external_react_namespaceObject.useMemo)(()=>(0, schema_namespaceObject.uid)(), []);
    const item = {
        key,
        type: 'group',
        title: props.title,
        label: props.title,
        children: getMenuItems(()=>props.children)
    };
    pushMenuItem(item);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Component, {});
};
const SchemaSettingsSubMenu = function(props) {
    const { Component, getMenuItems } = (0, useMenuItem_js_namespaceObject.useMenuItem)();
    const { pushMenuItem } = (0, useMenuItem_js_namespaceObject.useCollectMenuItems)();
    const key = (0, external_react_namespaceObject.useMemo)(()=>(0, schema_namespaceObject.uid)(), []);
    const item = {
        key,
        label: props.title,
        title: props.title,
        children: getMenuItems(()=>props.children)
    };
    pushMenuItem(item);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Component, {});
};
const SchemaSettingsDivider = function() {
    const { pushMenuItem } = (0, useMenuItem_js_namespaceObject.useCollectMenuItems)();
    const key = (0, external_react_namespaceObject.useMemo)(()=>(0, schema_namespaceObject.uid)(), []);
    const item = {
        key,
        type: 'divider'
    };
    pushMenuItem(item);
    return null;
};
const SchemaSettingsRemove = (props)=>{
    const { confirm, removeParentsIfNoChildren, breakRemoveOn } = props;
    const { dn, template } = useSchemaSettings();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const ctx = (0, BlockTemplate_js_namespaceObject.useBlockTemplateContext)();
    const form = (0, schema_namespaceObject.useForm)();
    const { modal } = external_antd_namespaceObject.App.useApp();
    const { removeActiveFieldName } = (0, hooks_index_js_namespaceObject.useFormActiveFields)() || {};
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: "Delete",
        eventKey: "remove",
        onClick: ()=>{
            modal.confirm({
                title: t('Delete block'),
                content: t('Are you sure you want to delete it?'),
                ...confirm,
                async onOk () {
                    var _confirm_onOk;
                    const options = {
                        removeParentsIfNoChildren,
                        breakRemoveOn
                    };
                    if (null == field ? void 0 : field.required) {
                        field.required = false;
                        fieldSchema['required'] = false;
                    }
                    if (template && template.uid === fieldSchema['x-uid'] && (null == ctx ? void 0 : ctx.dn)) await (null == ctx ? void 0 : ctx.dn.remove(null, options));
                    else await dn.remove(null, options);
                    await (null == confirm ? void 0 : null === (_confirm_onOk = confirm.onOk) || void 0 === _confirm_onOk ? void 0 : _confirm_onOk.call(confirm));
                    delete form.values[fieldSchema.name];
                    null == removeActiveFieldName || removeActiveFieldName(fieldSchema.name);
                    if ((null == field ? void 0 : field.setInitialValue) && (null == field ? void 0 : field.reset)) {
                        field.setInitialValue(null);
                        field.reset();
                    }
                }
            });
        },
        children: t('Delete')
    });
};
const SchemaSettingsConnectDataBlocks = (props)=>{
    const { type, emptyDescription } = props;
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const collection = (0, external_index_js_namespaceObject.useCollection_deprecated)();
    const { inProvider } = (0, external_index_js_namespaceObject.useFilterBlock)();
    const dataBlocks = (0, utils_js_namespaceObject.useSupportedBlocks)(type);
    let { targets = [], uid } = (0, hooks_index_js_namespaceObject.findFilterTargets)(fieldSchema);
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const { getAllCollectionsInheritChain } = (0, external_index_js_namespaceObject.useCollectionManager_deprecated)();
    if (!inProvider) return null;
    const Content = dataBlocks.map((block)=>{
        const title = "".concat(compile(block.collection.title), " #").concat(block.uid.slice(0, 4));
        const onHover = ()=>{
            const originalScrollPosition = window.scrollY || window.pageYOffset || document.documentElement.scrollTop;
            const dom = block.dom;
            const designer = dom.querySelector('.general-schema-designer');
            if (designer) designer.style.display = 'block';
            dom.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.2)';
            setTimeout(()=>{
                dom.scrollIntoView({
                    behavior: 'smooth',
                    block: 'center'
                });
            }, 1000);
            setTimeout(()=>{
                window.scrollTo({
                    top: originalScrollPosition,
                    behavior: 'smooth'
                });
            }, 2000);
        };
        const onLeave = ()=>{
            const dom = block.dom;
            const designer = dom.querySelector('.general-schema-designer');
            if (designer) designer.style.display = null;
            dom.style.boxShadow = 'none';
        };
        if ((0, utils_js_namespaceObject.isSameCollection)(block.collection, collection)) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsSwitchItem, {
            title: title,
            checked: targets.some((target)=>target.uid === block.uid),
            onChange: (checked)=>{
                if (checked) targets.push({
                    uid: block.uid
                });
                else {
                    targets = targets.filter((target)=>target.uid !== block.uid);
                    block.clearFilter(uid);
                }
                (0, hooks_index_js_namespaceObject.updateFilterTargets)(fieldSchema, targets);
                dn.emit('patch', {
                    schema: {
                        ['x-uid']: uid,
                        'x-filter-targets': targets
                    }
                }).catch(client_namespaceObject.error);
                dn.refresh();
            },
            onMouseLeave: onLeave,
            onMouseUp: onHover
        }, block.uid);
        const target = targets.find((target)=>target.uid === block.uid);
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsSelectItem, {
            title: title,
            value: (null == target ? void 0 : target.field) || '',
            options: [
                ...(0, utils_js_namespaceObject.getSupportFieldsByAssociation)(getAllCollectionsInheritChain(collection.name), block).map((field)=>({
                        label: compile(field.uiSchema.title) || field.name,
                        value: "".concat(field.name, ".").concat((0, utilts_js_namespaceObject.getTargetKey)(field))
                    })),
                ...(0, utils_js_namespaceObject.getSupportFieldsByForeignKey)(collection, block).map((field)=>({
                        label: "".concat(compile(field.uiSchema.title) || field.name, " [").concat(t('Foreign key'), "]"),
                        value: field.name
                    })),
                {
                    label: t('Unconnected'),
                    value: ''
                }
            ],
            onChange: (value)=>{
                if ('' === value) {
                    targets = targets.filter((target)=>target.uid !== block.uid);
                    block.clearFilter(uid);
                } else {
                    targets = targets.filter((target)=>target.uid !== block.uid);
                    targets.push({
                        uid: block.uid,
                        field: value
                    });
                }
                (0, hooks_index_js_namespaceObject.updateFilterTargets)(fieldSchema, targets);
                dn.emit('patch', {
                    schema: {
                        ['x-uid']: uid,
                        'x-filter-targets': targets
                    }
                });
                dn.refresh();
            },
            onMouseEnter: onHover,
            onMouseLeave: onLeave
        }, block.uid);
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsSubMenu, {
        title: t('Connect data blocks'),
        children: Content.length ? Content : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
            title: "empty",
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Empty, {
                style: {
                    width: 160,
                    padding: '0 1em'
                },
                description: emptyDescription,
                image: external_antd_namespaceObject.Empty.PRESENTED_IMAGE_SIMPLE
            })
        })
    });
};
const SchemaSettingsSelectItem = (props)=>{
    const { title, options, value, onChange, ...others } = props;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: title,
        ...others,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SelectWithTitle_js_namespaceObject.SelectWithTitle, {
            title,
            defaultValue: value,
            onChange,
            options
        })
    });
};
const SchemaSettingsCascaderItem = (props)=>{
    const { title, options, value, onChange, ...others } = props;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: title,
        ...others,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
            style: {
                alignItems: 'center',
                display: 'flex',
                justifyContent: 'space-between'
            },
            children: [
                title,
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Cascader, {
                    variant: "borderless",
                    defaultValue: value,
                    onChange: onChange,
                    options: options,
                    style: {
                        textAlign: 'right',
                        minWidth: 100
                    },
                    multiple: !!props.multiple,
                    ...props
                })
            ]
        })
    });
};
const SchemaSettingsSwitchItem = (props)=>{
    const { title, onChange, ...others } = props;
    const [checked, setChecked] = (0, external_react_namespaceObject.useState)(!!props.checked);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: title,
        ...others,
        onClick: ()=>{
            null == onChange || onChange(!checked);
            setChecked(!checked);
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
            style: {
                alignItems: 'center',
                display: 'flex',
                justifyContent: 'space-between'
            },
            children: [
                title,
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Switch, {
                    size: 'small',
                    checked: checked,
                    style: {
                        marginLeft: 32
                    }
                })
            ]
        })
    });
};
const SchemaSettingsPopupItem = (props)=>{
    const { schema, ...others } = props;
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const ctx = (0, external_react_namespaceObject.useContext)(SchemaSettingsContext);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_index_js_namespaceObject.ActionContextProvider, {
        value: {
            visible,
            setVisible
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
                title: props.title,
                ...others,
                onClick: ()=>{
                    ctx.setVisible(false);
                    setVisible(true);
                },
                children: props.children || props.title
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.SchemaComponent, {
                schema: {
                    name: (0, schema_namespaceObject.uid)(),
                    ...schema
                }
            })
        ]
    });
};
const SchemaSettingsActionModalItem = /*#__PURE__*/ external_react_default().memo((props)=>{
    const { title, onSubmit, initialValues, beforeOpen, initialSchema, schema, modalTip, components, scope, ...others } = props;
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const [schemaUid, setSchemaUid] = (0, external_react_namespaceObject.useState)(props.uid);
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const ctx = (0, external_react_namespaceObject.useContext)(SchemaSettingsContext);
    const { dn } = useSchemaSettings();
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const api = (0, external_index_js_namespaceObject.useAPIClient)();
    const upLevelActiveFields = (0, hooks_index_js_namespaceObject.useFormActiveFields)();
    const form = (0, external_react_namespaceObject.useMemo)(()=>(0, schema_namespaceObject.createForm)({
            initialValues: (0, external_lodash_namespaceObject.cloneDeep)(initialValues),
            values: (0, external_lodash_namespaceObject.cloneDeep)(initialValues)
        }), [
        initialValues
    ]);
    (0, external_react_namespaceObject.useEffect)(()=>{
        form.setInitialValues((0, external_lodash_namespaceObject.cloneDeep)(initialValues));
    }, [
        JSON.stringify(initialValues || {})
    ]);
    const cancelHandler = (0, external_react_namespaceObject.useCallback)(()=>{
        setVisible(false);
        form.reset();
    }, [
        form
    ]);
    const submitHandler = (0, external_react_namespaceObject.useCallback)(async ()=>{
        await form.submit();
        null == onSubmit || onSubmit((0, external_lodash_namespaceObject.cloneDeep)(form.values));
        setVisible(false);
    }, [
        form,
        onSubmit
    ]);
    const openAssignedFieldValueHandler = (0, external_react_namespaceObject.useCallback)(async ()=>{
        if (!schemaUid && (null == initialSchema ? void 0 : initialSchema['x-uid'])) {
            fieldSchema['x-action-settings'].schemaUid = initialSchema['x-uid'];
            dn.emit('patch', {
                schema: fieldSchema
            });
            await api.resource('uiSchemas').insert({
                values: initialSchema
            });
            setSchemaUid(initialSchema['x-uid']);
        }
        if ('function' == typeof beforeOpen) null == beforeOpen || beforeOpen();
        ctx.setVisible(false);
        setVisible(true);
    }, [
        api,
        ctx,
        dn,
        fieldSchema,
        initialSchema,
        schemaUid
    ]);
    const onKeyDown = (0, external_react_namespaceObject.useCallback)((e)=>e.stopPropagation(), []);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
                title: compile(title),
                ...others,
                onClick: openAssignedFieldValueHandler,
                onKeyDown: onKeyDown,
                children: props.children || props.title
            }),
            /*#__PURE__*/ (0, external_react_dom_namespaceObject.createPortal)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Modal, {
                width: '50%',
                title: compile(title),
                ...others,
                destroyOnClose: true,
                open: visible,
                onCancel: cancelHandler,
                footer: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Space, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                            onClick: cancelHandler,
                            children: t('Cancel')
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                            type: "primary",
                            onClick: submitHandler,
                            children: t('Submit')
                        })
                    ]
                }),
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(hooks_index_js_namespaceObject.FormActiveFieldsProvider, {
                    name: "form",
                    getActiveFieldsName: null == upLevelActiveFields ? void 0 : upLevelActiveFields.getActiveFieldsName,
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.FormProvider, {
                        form: form,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.FormLayout, {
                            layout: 'vertical',
                            children: [
                                modalTip && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Alert, {
                                    message: modalTip
                                }),
                                modalTip && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("br", {}),
                                visible && schemaUid && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.RemoteSchemaComponent, {
                                    noForm: true,
                                    components: components,
                                    scope: scope,
                                    uid: schemaUid
                                }),
                                visible && schema && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.SchemaComponent, {
                                    components: components,
                                    scope: scope,
                                    schema: schema
                                })
                            ]
                        })
                    })
                })
            }), document.body)
        ]
    });
});
SchemaSettingsActionModalItem.displayName = 'SchemaSettingsActionModalItem';
const SchemaSettingsModalItem = (props)=>{
    const { hidden, title, components, scope, effects, onSubmit, asyncGetInitialValues, initialValues, width = 'fit-content', ...others } = props;
    const options = (0, external_react_namespaceObject.useContext)(schema_namespaceObject.SchemaOptionsContext);
    options.components = {
        ...options.components,
        Input: external_index_js_namespaceObject.Input,
        'Input.TextArea': external_index_js_namespaceObject.Input.TextArea,
        'Radio.Group': external_index_js_namespaceObject.Radio.Group,
        'Checkbox.Group': external_index_js_namespaceObject.Checkbox.Group,
        DatePicker: external_index_js_namespaceObject.DatePicker,
        Select: external_index_js_namespaceObject.Select,
        AlternativeAssociationSelect: void 0,
        Cascader: external_index_js_namespaceObject.Cascader
    };
    const { styles } = useStyles();
    const collection = (0, external_index_js_namespaceObject.useCollection_deprecated)();
    const apiClient = (0, external_index_js_namespaceObject.useAPIClient)();
    const { theme } = (0, external_index_js_namespaceObject.useGlobalTheme)();
    const ctx = (0, external_index_js_namespaceObject.useBlockRequestContext)();
    const upLevelActiveFields = (0, hooks_index_js_namespaceObject.useFormActiveFields)();
    const { locale } = (0, external_react_namespaceObject.useContext)(external_antd_namespaceObject.ConfigProvider.ConfigContext);
    const dm = (0, DataSourceManagerProvider_js_namespaceObject.useDataSourceManager)();
    const dataSourceKey = (0, DataSourceProvider_js_namespaceObject.useDataSourceKey)();
    const record = (0, external_index_js_namespaceObject.useCollectionRecord)();
    const { association } = (0, external_index_js_namespaceObject.useDataBlockProps)() || {};
    const formCtx = (0, index_js_namespaceObject.useFormBlockContext)();
    const app = (0, external_index_js_namespaceObject.useApp)();
    const { formValue: subFormValue, collection: subFormCollection } = (0, hooks_js_namespaceObject.useSubFormValue)();
    const popupRecordVariable = (0, useVariable_js_namespaceObject.useVariable)('$nPopupRecord');
    if (hidden) return null;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsItem, {
        title: title,
        ...others,
        onClick: async ()=>{
            const values = asyncGetInitialValues ? await asyncGetInitialValues() : initialValues;
            const schema = external_lodash_default().isFunction(props.schema) ? props.schema() : props.schema;
            (0, external_index_js_namespaceObject.FormDialog)({
                title: schema.title || title,
                width
            }, ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(DeclareVariable_js_namespaceObject.DeclareVariable, {
                    name: "$nPopupRecord",
                    title: popupRecordVariable.title,
                    value: popupRecordVariable.value,
                    collection: popupRecordVariable.collection,
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.ApplicationContext.Provider, {
                        value: app,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.CollectionRecordProvider, {
                            record: record,
                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.FormBlockContext.Provider, {
                                value: formCtx,
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(hooks_js_namespaceObject.SubFormProvider, {
                                    value: {
                                        value: subFormValue,
                                        collection: subFormCollection
                                    },
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(hooks_index_js_namespaceObject.FormActiveFieldsProvider, {
                                        name: "form",
                                        getActiveFieldsName: null == upLevelActiveFields ? void 0 : upLevelActiveFields.getActiveFieldsName,
                                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_router_dom_namespaceObject.Router, {
                                            location: location,
                                            navigator: null,
                                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.BlockRequestContext_deprecated.Provider, {
                                                value: ctx,
                                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.DataSourceApplicationProvider, {
                                                    dataSourceManager: dm,
                                                    dataSource: dataSourceKey,
                                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.AssociationOrCollectionProvider, {
                                                        allowNull: true,
                                                        collection: collection.name,
                                                        association: association,
                                                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.SchemaComponentOptions, {
                                                            scope: options.scope,
                                                            components: options.components,
                                                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormLayout, {
                                                                layout: 'vertical',
                                                                className: styles.modal,
                                                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.APIClientProvider, {
                                                                    apiClient: apiClient,
                                                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.ConfigProvider, {
                                                                        locale: locale,
                                                                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.SchemaComponent, {
                                                                            components: components,
                                                                            scope: scope,
                                                                            schema: schema
                                                                        })
                                                                    })
                                                                })
                                                            })
                                                        })
                                                    })
                                                })
                                            })
                                        })
                                    })
                                })
                            })
                        })
                    })
                }), theme).open({
                initialValues: values,
                effects
            }).then((values)=>{
                onSubmit(values);
                return values;
            }).catch((err)=>{
                console.error(err);
            });
        },
        children: props.children || props.title
    });
};
const SchemaSettingsBlockTitleItem = function() {
    var _fieldSchema_xcomponentprops;
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsModalItem, {
        title: t('Edit block title'),
        schema: {
            type: 'object',
            title: t('Edit block title'),
            properties: {
                title: {
                    title: t('Block title'),
                    type: 'string',
                    default: null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['title'],
                    'x-decorator': 'FormItem',
                    'x-component': 'Input'
                }
            }
        },
        onSubmit: (param)=>{
            let { title } = param;
            const componentProps = fieldSchema['x-component-props'] || {};
            componentProps.title = title;
            fieldSchema['x-component-props'] = componentProps;
            field.componentProps.title = title;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-component-props': fieldSchema['x-component-props']
                }
            });
            dn.refresh();
        }
    });
};
const SchemaSettingsDefaultSortingRules = function(props) {
    const { path = 'x-component-props.params.sort' } = props;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const field = (0, schema_namespaceObject.useField)();
    const title = props.title || t('Set default sorting rules');
    const { name } = (0, external_index_js_namespaceObject.useCollection_deprecated)();
    const defaultSort = (0, external_lodash_namespaceObject.get)(fieldSchema, path) || [];
    const sort = null == defaultSort ? void 0 : defaultSort.map((item)=>item.startsWith('-') ? {
            field: item.substring(1),
            direction: 'desc'
        } : {
            field: item,
            direction: 'asc'
        });
    const sortFields = (0, external_index_js_namespaceObject.useSortFields)(props.name || name);
    const onSubmit = async (param)=>{
        let { sort } = param;
        var _props_onSubmitAfter;
        if (null == props ? void 0 : props.onSubmit) return props.onSubmit({
            sort
        });
        const value = sort.map((item)=>'desc' === item.direction ? "-".concat(item.field) : item.field);
        (0, external_lodash_namespaceObject.set)(field, path.replace('x-component-props', 'componentProps').replace('x-decorator-props', 'decoratorProps'), value);
        (0, external_lodash_namespaceObject.set)(fieldSchema, path, value);
        await dn.emit('patch', {
            schema: fieldSchema
        });
        return null === (_props_onSubmitAfter = props.onSubmitAfter) || void 0 === _props_onSubmitAfter ? void 0 : _props_onSubmitAfter.call(props);
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsModalItem, {
        title: title,
        components: {
            ArrayItems: components_namespaceObject.ArrayItems
        },
        schema: {
            type: 'object',
            title,
            properties: {
                sort: {
                    type: 'array',
                    default: sort,
                    'x-component': 'ArrayItems',
                    'x-decorator': 'FormItem',
                    items: {
                        type: 'object',
                        properties: {
                            space: {
                                type: 'void',
                                'x-component': 'Space',
                                properties: {
                                    sort: {
                                        type: 'void',
                                        'x-decorator': 'FormItem',
                                        'x-component': 'ArrayItems.SortHandle'
                                    },
                                    field: {
                                        type: 'string',
                                        enum: sortFields,
                                        required: true,
                                        'x-decorator': 'FormItem',
                                        'x-component': 'Select',
                                        'x-component-props': {
                                            style: {
                                                width: 260
                                            }
                                        }
                                    },
                                    direction: {
                                        type: 'string',
                                        'x-decorator': 'FormItem',
                                        'x-component': 'Radio.Group',
                                        'x-component-props': {
                                            optionType: 'button'
                                        },
                                        enum: [
                                            {
                                                label: t('ASC'),
                                                value: 'asc'
                                            },
                                            {
                                                label: t('DESC'),
                                                value: 'desc'
                                            }
                                        ]
                                    },
                                    remove: {
                                        type: 'void',
                                        'x-decorator': 'FormItem',
                                        'x-component': 'ArrayItems.Remove'
                                    }
                                }
                            }
                        }
                    },
                    properties: {
                        add: {
                            type: 'void',
                            title: t('Add sort field'),
                            'x-component': 'ArrayItems.Addition'
                        }
                    }
                }
            }
        },
        onSubmit: onSubmit
    });
};
const SchemaSettingsLinkageRules = function(props) {
    const { collectionName } = props;
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { form } = (0, index_js_namespaceObject.useFormBlockContext)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { getTemplateById } = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplateManager)();
    const variables = (0, external_variables_index_js_namespaceObject.useVariables)();
    const localVariables = (0, external_variables_index_js_namespaceObject.useLocalVariables)();
    const record = (0, external_index_js_namespaceObject.useRecord)();
    const { type: formBlockType } = (0, index_js_namespaceObject.useFormBlockType)();
    const type = (null == props ? void 0 : props.type) || [
        'Action',
        'Action.Link'
    ].includes(fieldSchema['x-component']) ? 'button' : 'field';
    const gridSchema = findGridSchema(fieldSchema) || fieldSchema;
    const schema = (0, external_react_namespaceObject.useMemo)(()=>({
            type: 'object',
            title: t('Linkage rules'),
            properties: {
                fieldReaction: {
                    'x-component': external_LinkageRules_index_js_namespaceObject.FormLinkageRules,
                    'x-use-component-props': ()=>{
                        const options = (0, external_index_js_namespaceObject.useLinkageCollectionFilterOptions)(collectionName);
                        const result = {
                            options,
                            defaultValues: (null == gridSchema ? void 0 : gridSchema['x-linkage-rules']) || (null == fieldSchema ? void 0 : fieldSchema['x-linkage-rules']),
                            type,
                            linkageOptions: (0, action_hooks_js_namespaceObject.useLinkageCollectionFieldOptions)(collectionName),
                            collectionName,
                            form,
                            variables,
                            localVariables,
                            record,
                            formBlockType
                        };
                        return result;
                    }
                }
            }
        }), [
        collectionName,
        fieldSchema,
        form,
        gridSchema,
        localVariables,
        record,
        t,
        type,
        variables
    ]);
    const components = (0, external_react_namespaceObject.useMemo)(()=>({
            ArrayCollapse: components_namespaceObject.ArrayCollapse,
            FormLayout: components_namespaceObject.FormLayout
        }), []);
    const onSubmit = (0, external_react_namespaceObject.useCallback)((v)=>{
        var _gridSchema_xcomponentprops;
        const rules = [];
        for (const rule of v.fieldReaction.rules)rules.push(external_lodash_default().pickBy(rule, external_lodash_default().identity));
        const templateId = 'BlockTemplate' === gridSchema['x-component'] && (null === (_gridSchema_xcomponentprops = gridSchema['x-component-props']) || void 0 === _gridSchema_xcomponentprops ? void 0 : _gridSchema_xcomponentprops.templateId);
        const uid = templateId && getTemplateById(templateId).uid || gridSchema['x-uid'];
        const schema = {
            ['x-uid']: uid
        };
        gridSchema['x-linkage-rules'] = rules;
        schema['x-linkage-rules'] = rules;
        dn.emit('patch', {
            schema
        });
        dn.refresh();
    }, [
        dn,
        getTemplateById,
        gridSchema
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsModalItem, {
        title: t('Linkage rules'),
        components: components,
        width: 770,
        schema: schema,
        onSubmit: onSubmit
    });
};
const useDataTemplates = (schema)=>{
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    if (schema) return {
        templateData: external_lodash_default().cloneDeep(schema['x-data-templates'])
    };
    const formSchema = (0, external_index_js_namespaceObject.findFormBlock)(fieldSchema) || fieldSchema;
    return {
        templateData: external_lodash_default().cloneDeep(null == formSchema ? void 0 : formSchema['x-data-templates'])
    };
};
const SchemaSettingsDataTemplates = function(props) {
    const designerCtx = (0, external_react_namespaceObject.useContext)(external_index_js_namespaceObject.SchemaComponentContext);
    const { collectionName } = props;
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const formSchema = (0, external_index_js_namespaceObject.findFormBlock)(fieldSchema) || fieldSchema;
    const { templateData } = useDataTemplates();
    const schema = (0, external_react_namespaceObject.useMemo)(()=>({
            type: 'object',
            title: t('Form data templates'),
            properties: {
                fieldReaction: {
                    'x-decorator': (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_flag_provider_index_js_namespaceObject.FlagProvider, {
                            ...props,
                            isInFormDataTemplate: true
                        }),
                    'x-component': external_DataTemplates_index_js_namespaceObject.FormDataTemplates,
                    'x-use-component-props': ()=>({
                            defaultValues: templateData,
                            collectionName
                        }),
                    'x-component-props': {
                        designerCtx,
                        formSchema
                    }
                }
            }
        }), [
        templateData
    ]);
    const onSubmit = (0, external_react_namespaceObject.useCallback)((v)=>{
        const data = {
            ...formSchema['x-data-templates'] || {},
            ...v.fieldReaction
        };
        data.items.forEach((item)=>{
            item.fields = Array.isArray(item.fields) ? item.fields : item.fields.checked;
        });
        const schema = {
            ['x-uid']: formSchema['x-uid'],
            ['x-data-templates']: data
        };
        formSchema['x-data-templates'] = data;
        dn.emit('patch', {
            schema
        });
        dn.refresh();
    }, []);
    const title = (0, external_react_namespaceObject.useMemo)(()=>t('Form data templates'), []);
    const components = (0, external_react_namespaceObject.useMemo)(()=>({
            ArrayCollapse: components_namespaceObject.ArrayCollapse,
            FormLayout: components_namespaceObject.FormLayout
        }), []);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsModalItem, {
        title: title,
        components: components,
        width: 770,
        schema: schema,
        onSubmit: onSubmit
    });
};
function SchemaSettingsEnableChildCollections(props) {
    var _fieldSchema_parent, _fieldSchema_parent1, _fieldSchema_xcomponentprops;
    const { collectionName } = props;
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const field = (0, schema_namespaceObject.useField)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const allowAddToCurrent = null == fieldSchema ? void 0 : fieldSchema['x-allow-add-to-current'];
    const { getCollectionJoinField } = (0, external_index_js_namespaceObject.useCollectionManager_deprecated)();
    const ctx = (0, external_index_js_namespaceObject.useBlockRequestContext)();
    const collectionField = getCollectionJoinField(null == fieldSchema ? void 0 : null === (_fieldSchema_parent = fieldSchema.parent) || void 0 === _fieldSchema_parent ? void 0 : _fieldSchema_parent['x-collection-field']) || {};
    const isAssocationAdd = (null == fieldSchema ? void 0 : null === (_fieldSchema_parent1 = fieldSchema.parent) || void 0 === _fieldSchema_parent1 ? void 0 : _fieldSchema_parent1['x-component']) === 'CollectionField';
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsModalItem, {
        title: t('Enable child collections'),
        components: {
            ArrayItems: components_namespaceObject.ArrayItems,
            FormLayout: components_namespaceObject.FormLayout
        },
        scope: {
            isAssocationAdd
        },
        schema: {
            type: 'object',
            title: t('Enable child collections'),
            properties: {
                enableChildren: {
                    'x-component': external_EnableChildCollections_index_js_namespaceObject.EnableChildCollections,
                    'x-use-component-props': ()=>({
                            defaultValues: null == fieldSchema ? void 0 : fieldSchema['x-enable-children'],
                            collectionName
                        })
                },
                allowAddToCurrent: {
                    type: 'boolean',
                    'x-content': "{{t('Allow adding records to the current collection')}}",
                    'x-decorator': 'FormItem',
                    'x-component': 'Checkbox',
                    default: void 0 === allowAddToCurrent || allowAddToCurrent
                },
                linkageFromForm: {
                    type: 'string',
                    title: "{{t('Linkage with form fields')}}",
                    'x-visible': '{{isAssocationAdd}}',
                    'x-decorator': 'FormItem',
                    'x-component': DynamicComponent_js_namespaceObject.ChildDynamicComponent,
                    'x-component-props': {
                        rootCollection: ctx.props.collection || ctx.props.resource,
                        collectionField
                    },
                    default: null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['linkageFromForm']
                }
            }
        },
        onSubmit: (v)=>{
            const enableChildren = [];
            for (const item of v.enableChildren.childrenCollections)enableChildren.push(external_lodash_default().pickBy(item, external_lodash_default().identity));
            const uid = fieldSchema['x-uid'];
            const schema = {
                ['x-uid']: uid
            };
            fieldSchema['x-enable-children'] = enableChildren;
            fieldSchema['x-allow-add-to-current'] = v.allowAddToCurrent;
            fieldSchema['x-component-props'] = {
                ...fieldSchema['x-component-props'],
                component: 'CreateRecordAction',
                linkageFromForm: null == v ? void 0 : v.linkageFromForm
            };
            schema['x-enable-children'] = enableChildren;
            schema['x-allow-add-to-current'] = v.allowAddToCurrent;
            schema['x-component-props'] = {
                ...fieldSchema['x-component-props'],
                component: 'CreateRecordAction',
                linkageFromForm: null == v ? void 0 : v.linkageFromForm
            };
            field.componentProps['linkageFromForm'] = v.linkageFromForm;
            dn.emit('patch', {
                schema
            });
            dn.refresh();
        }
    });
}
const findParentFieldSchema = (fieldSchema)=>{
    let parent = fieldSchema.parent;
    while(parent){
        if ('CollectionField' === parent['x-component']) return parent;
        parent = parent.parent;
    }
};
const SchemaSettingsSortField = ()=>{
    const { fields } = (0, external_index_js_namespaceObject.useCollection_deprecated)();
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const { service } = (0, index_js_namespaceObject.useTableBlockContext)();
    const options = fields.filter((field)=>!(null == field ? void 0 : field.target) && 'sort' === field.interface).map((field)=>{
        var _field_uiSchema;
        return {
            value: null == field ? void 0 : field.name,
            label: compile(null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || (null == field ? void 0 : field.name)
        };
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsSelectItem, {
        title: t('Drag and drop sorting field'),
        options: options,
        value: field.decoratorProps.dragSortBy,
        onChange: (dragSortBy)=>{
            var _service_params;
            fieldSchema['x-decorator-props'].dragSortBy = dragSortBy;
            service.run({
                ...null === (_service_params = service.params) || void 0 === _service_params ? void 0 : _service_params[0],
                sort: dragSortBy
            });
            field.decoratorProps.dragSortBy = dragSortBy;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-decorator-props': fieldSchema['x-decorator-props']
                }
            });
            dn.refresh();
        }
    }, "sort-field");
};
const isSystemField = (collectionField, getInterface)=>{
    const i = null == getInterface ? void 0 : getInterface(null == collectionField ? void 0 : collectionField.interface);
    return (null == i ? void 0 : i.group) === 'systemInfo';
};
function getFieldDefaultValue(fieldSchema, collectionField) {
    var _fieldSchema_default;
    const result = null !== (_fieldSchema_default = null == fieldSchema ? void 0 : fieldSchema.default) && void 0 !== _fieldSchema_default ? _fieldSchema_default : null == collectionField ? void 0 : collectionField.defaultValue;
    return result;
}
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
});
