"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__, {
    createDetailsBlockSchema: ()=>createDetailsBlockSchema,
    createReadPrettyFormBlockSchema: ()=>createReadPrettyFormBlockSchema,
    useCollectionDataSourceItems: ()=>useCollectionDataSourceItems,
    useFilterFormItemInitializerFields: ()=>useFilterFormItemInitializerFields,
    itemsMerge: ()=>itemsMerge,
    removeTableColumn: ()=>removeTableColumn,
    useFilterAssociatedFormItemInitializerFields: ()=>useFilterAssociatedFormItemInitializerFields,
    useCustomFormItemInitializerFields: ()=>useCustomFormItemInitializerFields,
    createTableBlockSchema: ()=>createTableBlockSchema,
    findTableColumn: ()=>findTableColumn,
    removeGridFormItem: ()=>removeGridFormItem,
    findSchema: ()=>findSchema,
    useFormItemInitializerFields: ()=>useFormItemInitializerFields,
    useInheritsTableColumnInitializerFields: ()=>useInheritsTableColumnInitializerFields,
    useRecordCollectionDataSourceItems: ()=>useRecordCollectionDataSourceItems,
    useCurrentSchema: ()=>useCurrentSchema,
    gridRowColWrap: ()=>gridRowColWrap,
    useRemoveGridFormItem: ()=>useRemoveGridFormItem,
    useAssociatedTableColumnInitializerFields: ()=>useAssociatedTableColumnInitializerFields,
    useAssociatedFormItemInitializerFields: ()=>useAssociatedFormItemInitializerFields,
    createFormBlockSchema: ()=>createFormBlockSchema,
    useFilterInheritsFormItemInitializerFields: ()=>useFilterInheritsFormItemInitializerFields,
    useInheritsFormItemInitializerFields: ()=>useInheritsFormItemInitializerFields,
    useTableColumnInitializerFields: ()=>useTableColumnInitializerFields
});
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_lodash_namespaceObject = require("lodash");
var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
const external_react_i18next_namespaceObject = require("react-i18next");
const external_index_js_namespaceObject = require("../index.js");
const index_js_namespaceObject = require("../collection-manager/index.js");
const DataSourceManagerProvider_js_namespaceObject = require("../data-source/data-source/DataSourceManagerProvider.js");
const utils_js_namespaceObject = require("../filter-provider/utils.js");
const external_schema_component_index_js_namespaceObject = require("../schema-component/index.js");
const external_schema_templates_index_js_namespaceObject = require("../schema-templates/index.js");
const itemsMerge = (items1)=>items1;
const gridRowColWrap = (schema)=>({
        type: 'void',
        'x-component': 'Grid.Row',
        properties: {
            [(0, schema_namespaceObject.uid)()]: {
                type: 'void',
                'x-component': 'Grid.Col',
                properties: {
                    [schema.name || (0, schema_namespaceObject.uid)()]: schema
                }
            }
        }
    });
const removeTableColumn = (schema, cb)=>{
    cb(schema.parent);
};
const removeGridFormItem = (schema, cb)=>{
    cb(schema, {
        removeParentsIfNoChildren: true,
        breakRemoveOn: {
            'x-component': 'Grid'
        }
    });
};
const useRemoveGridFormItem = ()=>{
    const form = (0, schema_namespaceObject.useForm)();
    return (schema, cb)=>{
        var _form_values;
        cb(schema, {
            removeParentsIfNoChildren: true,
            breakRemoveOn: {
                'x-component': 'Grid'
            }
        });
        null === (_form_values = form.values) || void 0 === _form_values || delete _form_values[schema.name];
    };
};
const findTableColumn = function(schema, key, action) {
    arguments.length > 3 && void 0 !== arguments[3] && arguments[3];
    return schema.reduceProperties((buf, s)=>{
        if (s[key] === action) return s;
        const c = s.reduceProperties((buf, s)=>{
            if (s[key] === action) return s;
            return buf;
        });
        if (c) return c;
        return buf;
    });
};
const quickEditField = [
    'attachment',
    'textarea',
    'markdown',
    'json',
    'richText',
    'polygon',
    'circle',
    'point',
    'lineString'
];
const useTableColumnInitializerFields = ()=>{
    const { name, currentFields = [] } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getCollection } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const isSubTable = 'AssociationField.SubTable' === fieldSchema['x-component'];
    const form = (0, schema_namespaceObject.useForm)();
    const isReadPretty = !isSubTable || form.readPretty;
    return currentFields.filter((field)=>(null == field ? void 0 : field.interface) && (null == field ? void 0 : field.interface) !== 'subTable' && !(null == field ? void 0 : field.isForeignKey) && !(null == field ? void 0 : field.treeChildren)).map((field)=>{
        var _getCollection, _field_uiSchema, _field_uiSchema1;
        const interfaceConfig = getInterface(field.interface);
        const isFileCollection = (null == field ? void 0 : field.target) && (null === (_getCollection = getCollection(null == field ? void 0 : field.target)) || void 0 === _getCollection ? void 0 : _getCollection.template) === 'file';
        const schema = {
            name: field.name,
            'x-collection-field': "".concat(name, ".").concat(field.name),
            'x-component': 'CollectionField',
            'x-component-props': isFileCollection ? {
                fieldNames: {
                    label: 'preview',
                    value: 'id'
                }
            } : {},
            'x-read-pretty': isReadPretty || (null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema['x-read-pretty']),
            'x-decorator': isSubTable ? quickEditField.includes(field.interface) || isFileCollection ? 'QuickEdit' : 'FormItem' : null,
            'x-decorator-props': {
                labelStyle: {
                    display: 'none'
                }
            }
        };
        return {
            type: 'item',
            name: field.name,
            title: (null == field ? void 0 : null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title) || field.name,
            Component: 'TableCollectionFieldInitializer',
            find: findTableColumn,
            remove: removeTableColumn,
            schemaInitialize: (s)=>{
                var _interfaceConfig_schemaInitialize;
                null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                    field,
                    readPretty: isReadPretty,
                    block: 'Table',
                    targetCollection: getCollection(field.target)
                });
            },
            field,
            schema
        };
    });
};
const useAssociatedTableColumnInitializerFields = ()=>{
    var _fields_filter;
    const { name, fields } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getCollectionFields, getCollection } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const groups = null == fields ? void 0 : null === (_fields_filter = fields.filter((field)=>[
            'o2o',
            'oho',
            'obo',
            'm2o'
        ].includes(field.interface))) || void 0 === _fields_filter ? void 0 : _fields_filter.map((field)=>{
        var _subFields_filter, _field_uiSchema, _field_uiSchema1;
        const subFields = getCollectionFields(field.target);
        const items = null == subFields ? void 0 : null === (_subFields_filter = subFields.filter((subField)=>(null == subField ? void 0 : subField.interface) && ![
                'subTable'
            ].includes(null == subField ? void 0 : subField.interface) && !(null == subField ? void 0 : subField.treeChildren))) || void 0 === _subFields_filter ? void 0 : _subFields_filter.map((subField)=>{
            var _subField_uiSchema;
            const interfaceConfig = getInterface(subField.interface);
            const schema = {
                name: "".concat(field.name, ".").concat(subField.name),
                'x-component': 'CollectionField',
                'x-read-pretty': true,
                'x-collection-field': "".concat(name, ".").concat(field.name, ".").concat(subField.name),
                'x-component-props': {}
            };
            return {
                type: 'item',
                name: subField.name,
                title: (null == subField ? void 0 : null === (_subField_uiSchema = subField.uiSchema) || void 0 === _subField_uiSchema ? void 0 : _subField_uiSchema.title) || subField.name,
                Component: 'TableCollectionFieldInitializer',
                find: findTableColumn,
                remove: removeTableColumn,
                schemaInitialize: (s)=>{
                    var _interfaceConfig_schemaInitialize;
                    null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                        field: subField,
                        readPretty: true,
                        block: 'Table',
                        targetCollection: getCollection(field.target)
                    });
                },
                field: subField,
                schema
            };
        });
        return {
            type: 'subMenu',
            name: null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title,
            title: null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title,
            children: items
        };
    });
    return groups;
};
const useInheritsTableColumnInitializerFields = ()=>{
    const { name } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getInheritCollections, getCollection, getParentCollectionFields } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const isSubTable = 'AssociationField.SubTable' === fieldSchema['x-component'];
    const form = (0, schema_namespaceObject.useForm)();
    const isReadPretty = !isSubTable || form.readPretty;
    const inherits = getInheritCollections(name);
    return null == inherits ? void 0 : inherits.map((v)=>{
        const fields = getParentCollectionFields(v, name);
        const targetCollection = getCollection(v);
        return {
            [null == targetCollection ? void 0 : targetCollection.title]: null == fields ? void 0 : fields.filter((field)=>null == field ? void 0 : field.interface).map((k)=>{
                var _getCollection, _k_uiSchema, _k_uiSchema1, _k_uiSchema2;
                const interfaceConfig = getInterface(k.interface);
                const isFileCollection = (null == k ? void 0 : k.target) && (null === (_getCollection = getCollection(null == k ? void 0 : k.target)) || void 0 === _getCollection ? void 0 : _getCollection.template) === 'file';
                const schema = {
                    name: "".concat(k.name),
                    'x-component': 'CollectionField',
                    'x-read-pretty': isReadPretty || (null === (_k_uiSchema = k.uiSchema) || void 0 === _k_uiSchema ? void 0 : _k_uiSchema['x-read-pretty']),
                    'x-collection-field': "".concat(name, ".").concat(k.name),
                    'x-component-props': isFileCollection ? {
                        fieldNames: {
                            label: 'preview',
                            value: 'id'
                        }
                    } : {},
                    'x-decorator': isSubTable ? quickEditField.includes(k.interface) || isFileCollection ? 'QuickEdit' : 'FormItem' : null,
                    'x-decorator-props': {
                        labelStyle: {
                            display: 'none'
                        }
                    }
                };
                return {
                    name: (null == k ? void 0 : null === (_k_uiSchema1 = k.uiSchema) || void 0 === _k_uiSchema1 ? void 0 : _k_uiSchema1.title) || k.name,
                    type: 'item',
                    title: (null == k ? void 0 : null === (_k_uiSchema2 = k.uiSchema) || void 0 === _k_uiSchema2 ? void 0 : _k_uiSchema2.title) || k.name,
                    Component: 'TableCollectionFieldInitializer',
                    find: findTableColumn,
                    remove: removeTableColumn,
                    schemaInitialize: (s)=>{
                        var _interfaceConfig_schemaInitialize;
                        null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                            field: k,
                            readPretty: true,
                            block: 'Table',
                            targetCollection: getCollection(null == k ? void 0 : k.target)
                        });
                    },
                    field: k,
                    schema
                };
            })
        };
    });
};
const useFormItemInitializerFields = (options)=>{
    var _currentFields_filter;
    const { name, currentFields } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getCollection } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const form = (0, schema_namespaceObject.useForm)();
    const { readPretty = form.readPretty, block = 'Form' } = options || {};
    const { fieldSchema } = (0, external_schema_component_index_js_namespaceObject.useActionContext)();
    const action = null == fieldSchema ? void 0 : fieldSchema['x-action'];
    return null == currentFields ? void 0 : null === (_currentFields_filter = currentFields.filter((field)=>(null == field ? void 0 : field.interface) && !(null == field ? void 0 : field.isForeignKey) && !(null == field ? void 0 : field.treeChildren))) || void 0 === _currentFields_filter ? void 0 : _currentFields_filter.map((field)=>{
        var _getCollection, _field_uiSchema_xcomponentprops, _field_uiSchema, _field_uiSchema1;
        const interfaceConfig = getInterface(field.interface);
        const targetCollection = getCollection(field.target);
        const isFileCollection = (null == field ? void 0 : field.target) && (null === (_getCollection = getCollection(null == field ? void 0 : field.target)) || void 0 === _getCollection ? void 0 : _getCollection.template) === 'file';
        const isAssociationField = targetCollection;
        const fieldNames = null == field ? void 0 : null === (_field_uiSchema_xcomponentprops = field.uiSchema['x-component-props']) || void 0 === _field_uiSchema_xcomponentprops ? void 0 : _field_uiSchema_xcomponentprops['fieldNames'];
        const schema = {
            type: 'string',
            name: field.name,
            'x-toolbar': 'FormItemSchemaToolbar',
            'x-settings': 'fieldSettings:FormItem',
            'x-component': 'CollectionField',
            'x-decorator': 'FormItem',
            'x-collection-field': "".concat(name, ".").concat(field.name),
            'x-component-props': isFileCollection ? {
                fieldNames: {
                    label: 'preview',
                    value: 'id'
                }
            } : isAssociationField && fieldNames ? {
                fieldNames: {
                    ...fieldNames,
                    label: (null == targetCollection ? void 0 : targetCollection.titleField) || fieldNames.label
                }
            } : {},
            'x-read-pretty': null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema['x-read-pretty']
        };
        const resultItem = {
            type: 'item',
            name: field.name,
            title: (null == field ? void 0 : null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title) || field.name,
            Component: 'CollectionFieldInitializer',
            remove: removeGridFormItem,
            schemaInitialize: (s)=>{
                var _interfaceConfig_schemaInitialize;
                null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                    field,
                    block,
                    readPretty,
                    action,
                    targetCollection
                });
            },
            schema
        };
        if ('Kanban' === block) resultItem['find'] = (schema, key, action)=>{
            const s = findSchema(schema, 'x-component', block);
            return findSchema(s, key, action);
        };
        return resultItem;
    });
};
const useFilterFormItemInitializerFields = (options)=>{
    var _currentFields_filter;
    const { name, currentFields } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getCollection } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const form = (0, schema_namespaceObject.useForm)();
    const { readPretty = form.readPretty, block = 'FilterForm' } = options || {};
    const { snapshot, fieldSchema } = (0, external_schema_component_index_js_namespaceObject.useActionContext)();
    const action = null == fieldSchema ? void 0 : fieldSchema['x-action'];
    return null == currentFields ? void 0 : null === (_currentFields_filter = currentFields.filter((field)=>{
        var _getInterface;
        return (null == field ? void 0 : field.interface) && !(null == field ? void 0 : field.isForeignKey) && (null === (_getInterface = getInterface(field.interface)) || void 0 === _getInterface ? void 0 : _getInterface.filterable);
    })) || void 0 === _currentFields_filter ? void 0 : _currentFields_filter.map((field)=>{
        var _field_uiSchema, _field_uiSchema1;
        const interfaceConfig = getInterface(field.interface);
        const targetCollection = getCollection(field.target);
        let schema = {
            type: 'string',
            name: field.name,
            required: false,
            'x-toolbar': 'FormItemSchemaToolbar',
            'x-settings': 'fieldSettings:FilterFormItem',
            'x-component': 'CollectionField',
            'x-decorator': 'FormItem',
            'x-collection-field': "".concat(name, ".").concat(field.name),
            'x-component-props': {}
        };
        if ((0, utils_js_namespaceObject.isAssocField)(field)) {
            var _field_uiSchema2;
            schema = {
                type: 'string',
                name: "".concat(field.name),
                required: false,
                'x-toolbar': 'FormItemSchemaToolbar',
                'x-settings': 'fieldSettings:FilterFormItem',
                'x-component': 'CollectionField',
                'x-decorator': 'FormItem',
                'x-collection-field': "".concat(name, ".").concat(field.name),
                'x-component-props': null === (_field_uiSchema2 = field.uiSchema) || void 0 === _field_uiSchema2 ? void 0 : _field_uiSchema2['x-component-props']
            };
        }
        const resultItem = {
            name: (null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || field.name,
            type: 'item',
            title: (null == field ? void 0 : null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title) || field.name,
            Component: 'CollectionFieldInitializer',
            remove: removeGridFormItem,
            schemaInitialize: (s)=>{
                var _interfaceConfig_schemaInitialize;
                null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                    field,
                    block,
                    readPretty,
                    action,
                    targetCollection
                });
            },
            schema
        };
        return resultItem;
    });
};
const useAssociatedFormItemInitializerFields = (options)=>{
    var _fields_filter;
    const { name, fields } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getCollectionFields, getCollection } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const form = (0, schema_namespaceObject.useForm)();
    const { readPretty = form.readPretty, block = 'Form' } = options || {};
    const interfaces = 'Form' === block ? [
        'm2o'
    ] : [
        'o2o',
        'oho',
        'obo',
        'm2o'
    ];
    const groups = null == fields ? void 0 : null === (_fields_filter = fields.filter((field)=>interfaces.includes(field.interface))) || void 0 === _fields_filter ? void 0 : _fields_filter.map((field)=>{
        var _subFields_filter, _field_uiSchema, _field_uiSchema1;
        const subFields = getCollectionFields(field.target);
        const items = null == subFields ? void 0 : null === (_subFields_filter = subFields.filter((subField)=>(null == subField ? void 0 : subField.interface) && ![
                'subTable'
            ].includes(null == subField ? void 0 : subField.interface) && !subField.treeChildren)) || void 0 === _subFields_filter ? void 0 : _subFields_filter.map((subField)=>{
            var _getCollection, _subField_uiSchema, _subField_uiSchema1;
            const interfaceConfig = getInterface(subField.interface);
            const isFileCollection = (null == field ? void 0 : field.target) && (null === (_getCollection = getCollection(null == field ? void 0 : field.target)) || void 0 === _getCollection ? void 0 : _getCollection.template) === 'file';
            const schema = {
                type: 'string',
                name: "".concat(field.name, ".").concat(subField.name),
                'x-toolbar': 'FormItemSchemaToolbar',
                'x-settings': 'fieldSettings:FormItem',
                'x-component': 'CollectionField',
                'x-read-pretty': readPretty,
                'x-component-props': {
                    'pattern-disable': 'Form' === block && readPretty,
                    fieldNames: isFileCollection ? {
                        label: 'preview',
                        value: 'id'
                    } : void 0
                },
                'x-decorator': 'FormItem',
                'x-collection-field': "".concat(name, ".").concat(field.name, ".").concat(subField.name)
            };
            return {
                name: (null == subField ? void 0 : null === (_subField_uiSchema = subField.uiSchema) || void 0 === _subField_uiSchema ? void 0 : _subField_uiSchema.title) || subField.name,
                type: 'item',
                title: (null == subField ? void 0 : null === (_subField_uiSchema1 = subField.uiSchema) || void 0 === _subField_uiSchema1 ? void 0 : _subField_uiSchema1.title) || subField.name,
                Component: 'CollectionFieldInitializer',
                remove: removeGridFormItem,
                schemaInitialize: (s)=>{
                    var _interfaceConfig_schemaInitialize;
                    null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                        field: subField,
                        block,
                        readPretty,
                        targetCollection: getCollection(field.target)
                    });
                },
                schema
            };
        });
        return {
            type: 'subMenu',
            name: null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title,
            title: null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title,
            children: items
        };
    });
    return groups;
};
const getItem = (field, schemaName, collectionName, getCollectionFields, processedCollections, level, fieldPath)=>{
    if (level >= 3) return null;
    if ([
        'm2o',
        'obo',
        'oho',
        'o2m',
        'm2m'
    ].includes(field.interface)) {
        var _field_uiSchema, _field_uiSchema1;
        if (processedCollections.includes(field.target)) return null;
        const subFields = getCollectionFields(field.target);
        const options = [];
        subFields.forEach((subField)=>{
            if ([
                'm2o',
                'obo',
                'oho',
                'o2m',
                'm2m'
            ].includes(subField.interface)) options.push(getResultSchema("".concat(schemaName, ".").concat(subField.name), subField, collectionName, (fieldPath || '') + field.key));
            options.push(getItem(subField, "".concat(schemaName, ".").concat(subField.name), collectionName, getCollectionFields, [
                ...processedCollections,
                field.target
            ], level + 1, (fieldPath || '') + field.key));
        });
        return {
            type: 'subMenu',
            name: null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title,
            title: null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title,
            key: (fieldPath || '') + field.key + 'menu',
            children: options.filter(Boolean)
        };
    }
    if ((0, utils_js_namespaceObject.isAssocField)(field)) return null;
    return getResultSchema(schemaName, field, collectionName, (fieldPath || '') + field.key);
};
const getResultSchema = (schemaName, field, collectionName, fieldPath)=>{
    var _field_uiSchema, _field_uiSchema1, _field_uiSchema2;
    const schema = {
        type: 'string',
        name: schemaName,
        'x-toolbar': 'FormItemSchemaToolbar',
        'x-settings': 'fieldSettings:FilterFormItem',
        'x-designer-props': {
            interface: field.interface
        },
        'x-component': 'CollectionField',
        'x-read-pretty': false,
        'x-decorator': 'FormItem',
        'x-collection-field': "".concat(collectionName, ".").concat(schemaName)
    };
    const result = {
        name: (null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || field.name,
        type: 'item',
        key: ((null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title) || field.name) + fieldPath,
        title: (null === (_field_uiSchema2 = field.uiSchema) || void 0 === _field_uiSchema2 ? void 0 : _field_uiSchema2.title) || field.name,
        Component: 'CollectionFieldInitializer',
        remove: removeGridFormItem,
        schema
    };
    return result;
};
const useFilterAssociatedFormItemInitializerFields = ()=>{
    var _fields_filter;
    const { name, fields } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getCollectionFields } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const interfaces = [
        'm2o',
        'obo',
        'oho',
        'o2m',
        'm2m'
    ];
    const groups = null == fields ? void 0 : null === (_fields_filter = fields.filter((field)=>interfaces.includes(field.interface))) || void 0 === _fields_filter ? void 0 : _fields_filter.map((field)=>getItem(field, field.name, name, getCollectionFields, [], 0));
    return groups;
};
const useInheritsFormItemInitializerFields = (options)=>{
    const { name } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getInheritCollections, getCollection, getParentCollectionFields } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const inherits = getInheritCollections(name);
    const { snapshot } = (0, external_schema_component_index_js_namespaceObject.useActionContext)();
    const form = (0, schema_namespaceObject.useForm)();
    return null == inherits ? void 0 : inherits.map((v)=>{
        var _fields_filter;
        const fields = getParentCollectionFields(v, name);
        const { readPretty = form.readPretty, block = 'Form', component = 'CollectionField' } = options || {};
        const targetCollection = getCollection(v);
        return {
            [null == targetCollection ? void 0 : targetCollection.title]: null == fields ? void 0 : null === (_fields_filter = fields.filter((field)=>(null == field ? void 0 : field.interface) && !(null == field ? void 0 : field.isForeignKey))) || void 0 === _fields_filter ? void 0 : _fields_filter.map((field)=>{
                var _field_uiSchema, _field_uiSchema1, _field_uiSchema2, _field_uiSchema3;
                const interfaceConfig = getInterface(field.interface);
                const targetCollection = getCollection(field.target);
                const schema = {
                    type: 'string',
                    name: field.name,
                    title: (null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || field.name,
                    'x-toolbar': 'FormItemSchemaToolbar',
                    'x-settings': 'fieldSettings:FormItem',
                    'x-component': component,
                    'x-decorator': 'FormItem',
                    'x-collection-field': "".concat(name, ".").concat(field.name),
                    'x-component-props': {},
                    'x-read-pretty': null == field ? void 0 : null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1['x-read-pretty']
                };
                return {
                    name: (null == field ? void 0 : null === (_field_uiSchema2 = field.uiSchema) || void 0 === _field_uiSchema2 ? void 0 : _field_uiSchema2.title) || field.name,
                    type: 'item',
                    title: (null == field ? void 0 : null === (_field_uiSchema3 = field.uiSchema) || void 0 === _field_uiSchema3 ? void 0 : _field_uiSchema3.title) || field.name,
                    Component: 'CollectionFieldInitializer',
                    remove: removeGridFormItem,
                    schemaInitialize: (s)=>{
                        var _interfaceConfig_schemaInitialize;
                        null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                            field,
                            block,
                            readPretty,
                            targetCollection
                        });
                    },
                    schema
                };
            })
        };
    });
};
const useFilterInheritsFormItemInitializerFields = (options)=>{
    const { name } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getInheritCollections, getCollection, getParentCollectionFields } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const inherits = getInheritCollections(name);
    const { snapshot } = (0, external_schema_component_index_js_namespaceObject.useActionContext)();
    const form = (0, schema_namespaceObject.useForm)();
    return null == inherits ? void 0 : inherits.map((v)=>{
        var _fields_filter;
        const fields = getParentCollectionFields(v, name);
        const { readPretty = form.readPretty, block = 'Form' } = options || {};
        const targetCollection = getCollection(v);
        return {
            [targetCollection.title]: null == fields ? void 0 : null === (_fields_filter = fields.filter((field)=>{
                var _getInterface;
                return (null == field ? void 0 : field.interface) && !(null == field ? void 0 : field.isForeignKey) && (null === (_getInterface = getInterface(field.interface)) || void 0 === _getInterface ? void 0 : _getInterface.filterable);
            })) || void 0 === _fields_filter ? void 0 : _fields_filter.map((field)=>{
                var _field_uiSchema, _field_uiSchema1, _field_uiSchema2, _field_uiSchema3;
                const interfaceConfig = getInterface(field.interface);
                const targetCollection = getCollection(field.target);
                const schema = {
                    type: 'string',
                    name: field.name,
                    title: (null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || field.name,
                    required: false,
                    'x-toolbar': 'FormItemSchemaToolbar',
                    'x-settings': 'fieldSettings:FilterFormItem',
                    'x-component': 'CollectionField',
                    'x-decorator': 'FormItem',
                    'x-collection-field': "".concat(name, ".").concat(field.name),
                    'x-component-props': {},
                    'x-read-pretty': null == field ? void 0 : null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1['x-read-pretty']
                };
                return {
                    name: (null == field ? void 0 : null === (_field_uiSchema2 = field.uiSchema) || void 0 === _field_uiSchema2 ? void 0 : _field_uiSchema2.title) || field.name,
                    type: 'item',
                    title: (null == field ? void 0 : null === (_field_uiSchema3 = field.uiSchema) || void 0 === _field_uiSchema3 ? void 0 : _field_uiSchema3.title) || field.name,
                    Component: 'CollectionFieldInitializer',
                    remove: removeGridFormItem,
                    schemaInitialize: (s)=>{
                        var _interfaceConfig_schemaInitialize;
                        null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                            field,
                            block,
                            readPretty,
                            targetCollection
                        });
                    },
                    schema
                };
            })
        };
    });
};
const useCustomFormItemInitializerFields = (options)=>{
    var _currentFields_filter;
    const { name, currentFields } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getInterface, getCollection } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const form = (0, schema_namespaceObject.useForm)();
    const { readPretty = form.readPretty, block = 'Form' } = options || {};
    const remove = useRemoveGridFormItem();
    return null == currentFields ? void 0 : null === (_currentFields_filter = currentFields.filter((field)=>{
        var _field_uiSchema;
        return (null == field ? void 0 : field.interface) && !(null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema['x-read-pretty']) && 'snapshot' !== field.interface && 'sequence' !== field.type;
    })) || void 0 === _currentFields_filter ? void 0 : _currentFields_filter.map((field)=>{
        var _field_uiSchema, _field_uiSchema1, _field_uiSchema2;
        const interfaceConfig = getInterface(field.interface);
        const schema = {
            type: 'string',
            name: field.name,
            title: (null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || field.name,
            'x-toolbar': 'FormItemSchemaToolbar',
            'x-settings': 'fieldSettings:FormItem',
            'x-component': 'AssignedField',
            'x-decorator': 'FormItem',
            'x-collection-field': "".concat(name, ".").concat(field.name)
        };
        return {
            name: (null == field ? void 0 : null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title) || field.name,
            type: 'item',
            title: (null == field ? void 0 : null === (_field_uiSchema2 = field.uiSchema) || void 0 === _field_uiSchema2 ? void 0 : _field_uiSchema2.title) || field.name,
            Component: 'CollectionFieldInitializer',
            remove: remove,
            schemaInitialize: (s)=>{
                var _interfaceConfig_schemaInitialize;
                null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, s, {
                    field,
                    block,
                    readPretty,
                    targetCollection: getCollection(field.target)
                });
            },
            schema
        };
    });
};
const findSchema = (schema, key, action)=>{
    if (!schema_namespaceObject.Schema.isSchemaInstance(schema)) return null;
    return schema.reduceProperties((buf, s)=>{
        if (s[key] === action) return s;
        if ('Action.Container' !== s['x-component'] && 'AssociationField.Viewer' !== s['x-component']) {
            const c = findSchema(s, key, action);
            if (c) return c;
        }
        return buf;
    });
};
const removeSchema = (schema, cb)=>cb(schema);
const recursiveParent = (schema)=>{
    if (!schema.parent) return null;
    if (schema.parent['x-initializer']) return schema.parent;
    return recursiveParent(schema.parent);
};
const useCurrentSchema = function(action, key) {
    let find = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : findSchema, rm = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : removeSchema;
    const { removeActiveFieldName } = (0, external_index_js_namespaceObject.useFormActiveFields)() || {};
    const { form } = (0, external_index_js_namespaceObject.useFormBlockContext)();
    let fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    if (!(null == fieldSchema ? void 0 : fieldSchema['x-initializer']) && (null == fieldSchema ? void 0 : fieldSchema['x-decorator']) === 'FormItem') {
        const recursiveInitializerSchema = recursiveParent(fieldSchema);
        if (recursiveInitializerSchema) fieldSchema = recursiveInitializerSchema;
    }
    const { remove } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
    const schema = find(fieldSchema, key, action);
    return {
        schema,
        exists: !!schema,
        remove () {
            null == removeActiveFieldName || removeActiveFieldName(schema.name);
            null == form || form.query(schema.name).forEach((field)=>{
                var _field_setInitialValue, _field_reset;
                null === (_field_setInitialValue = field.setInitialValue) || void 0 === _field_setInitialValue || _field_setInitialValue.call(field, null);
                null === (_field_reset = field.reset) || void 0 === _field_reset || _field_reset.call(field);
            });
            if (schema) rm(schema, remove);
        }
    };
};
const useRecordCollectionDataSourceItems = function(componentName) {
    let item = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : null, collectionName = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : null, resourceName = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : null;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const collection = (0, index_js_namespaceObject.useCollection_deprecated)();
    const { getTemplatesByCollection } = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplateManager)();
    const templates = getTemplatesByCollection(collection.dataSource, collectionName || collection.name).filter((template)=>componentName && template.componentName === componentName).filter((template)=>[
            'FormItem',
            'ReadPrettyFormItem'
        ].includes(componentName) || template.resourceName === resourceName);
    if (!templates.length) return [];
    const index = 0;
    return [
        {
            key: "".concat(collectionName || componentName, "_table_blank"),
            type: 'item',
            name: collection.name,
            title: t('Blank block'),
            item
        },
        {
            type: 'divider'
        },
        {
            key: "".concat(collectionName || componentName, "_table_subMenu_").concat(index, "_copy"),
            type: 'subMenu',
            name: 'copy',
            title: t('Duplicate template'),
            children: templates.map((template)=>{
                const templateName = [
                    'FormItem',
                    'ReadPrettyFormItem'
                ].includes(null == template ? void 0 : template.componentName) ? "".concat(null == template ? void 0 : template.name, " ").concat(t('(Fields only)')) : null == template ? void 0 : template.name;
                return {
                    type: 'item',
                    mode: 'copy',
                    name: collection.name,
                    template,
                    item,
                    title: templateName || t('Untitled')
                };
            })
        },
        {
            key: "".concat(collectionName || componentName, "_table_subMenu_").concat(index, "_ref"),
            type: 'subMenu',
            name: 'ref',
            title: t('Reference template'),
            children: templates.map((template)=>{
                const templateName = [
                    'FormItem',
                    'ReadPrettyFormItem'
                ].includes(null == template ? void 0 : template.componentName) ? "".concat(null == template ? void 0 : template.name, " ").concat(t('(Fields only)')) : null == template ? void 0 : template.name;
                return {
                    type: 'item',
                    mode: 'reference',
                    name: collection.name,
                    template,
                    item,
                    title: templateName || t('Untitled')
                };
            })
        }
    ];
};
const useCollectionDataSourceItems = (param)=>{
    let { componentName, filter = ()=>true, onlyCurrentDataSource = false, showAssociationFields, filterDataSource, dataBlockInitializerProps, hideOtherRecordsInPopup } = param;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const dm = (0, DataSourceManagerProvider_js_namespaceObject.useDataSourceManager)();
    const dataSourceKey = (0, external_index_js_namespaceObject.useDataSourceKey)();
    const collection = (0, external_index_js_namespaceObject.useCollection)();
    const associationFields = useAssociationFields({
        componentName,
        filterCollections: filter,
        showAssociationFields
    });
    let allCollections = dm.getAllCollections({
        filterCollection: (collection)=>{
            if (onlyCurrentDataSource && collection.dataSource !== dataSourceKey) return false;
            return filter({
                collection
            });
        },
        filterDataSource
    });
    if (onlyCurrentDataSource) allCollections = allCollections.filter((collection)=>collection.key === dataSourceKey);
    const { getTemplatesByCollection } = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplateManager)();
    const noAssociationMenu = (0, external_react_namespaceObject.useMemo)(()=>allCollections.map((param)=>{
            let { key, displayName, collections } = param;
            return {
                name: key,
                label: displayName,
                type: 'subMenu',
                children: [
                    ...getChildren({
                        collections,
                        componentName,
                        searchValue: '',
                        dataSource: key,
                        getTemplatesByCollection,
                        t
                    }).sort((item)=>{
                        const inherits = external_lodash_default().toArray((null == collection ? void 0 : collection.inherits) || []);
                        if (item.name === (null == collection ? void 0 : collection.name) || inherits.some((inheritName)=>inheritName === item.name)) return -1;
                    })
                ]
            };
        }), [
        allCollections,
        null == collection ? void 0 : collection.inherits,
        null == collection ? void 0 : collection.name,
        componentName,
        getTemplatesByCollection,
        t
    ]);
    if (showAssociationFields) return (0, external_react_namespaceObject.useMemo)(()=>{
        const currentRecord = {
            name: 'currentRecord',
            collectionName: collection.name,
            dataSource: collection.dataSource,
            Component: external_index_js_namespaceObject.DataBlockInitializer,
            onClick () {},
            componentProps: {
                ...dataBlockInitializerProps,
                icon: null,
                title: t('Current record'),
                name: 'currentRecord',
                hideSearch: false,
                hideChildrenIfSingleCollection: true,
                items: noAssociationMenu
            }
        };
        const associationRecords = {
            name: 'associationRecords',
            Component: external_index_js_namespaceObject.DataBlockInitializer,
            onClick () {},
            componentProps: {
                ...dataBlockInitializerProps,
                icon: null,
                title: t('Associated records'),
                name: 'associationRecords',
                hideSearch: false,
                items: [
                    {
                        name: 'associationFields',
                        label: t('Association fields'),
                        type: 'subMenu',
                        children: associationFields
                    }
                ]
            }
        };
        const componentTypeMap = {
            ReadPrettyFormItem: 'Details'
        };
        const otherRecords = {
            name: 'otherRecords',
            Component: external_index_js_namespaceObject.DataBlockInitializer,
            onClick () {},
            componentProps: {
                icon: null,
                title: t('Other records'),
                name: 'otherRecords',
                showAssociationFields: false,
                onlyCurrentDataSource: false,
                hideChildrenIfSingleCollection: false,
                onCreateBlockSchema: dataBlockInitializerProps.onCreateBlockSchema,
                fromOthersInPopup: true,
                componentType: componentTypeMap[componentName] || componentName,
                filter (param) {
                    let { collection: c, associationField } = param;
                    return true;
                }
            }
        };
        let children;
        const _associationRecords = associationFields.length ? associationRecords : null;
        if (noAssociationMenu[0].children.length && associationFields.length) children = hideOtherRecordsInPopup ? [
            currentRecord,
            _associationRecords
        ] : [
            currentRecord,
            _associationRecords,
            otherRecords
        ];
        else if (noAssociationMenu[0].children.length) {
            if (hideOtherRecordsInPopup) {
                if (noAssociationMenu[0].children.length <= 1) {
                    var _noAssociationMenu__children_;
                    noAssociationMenu[0].children = (null === (_noAssociationMenu__children_ = noAssociationMenu[0].children[0]) || void 0 === _noAssociationMenu__children_ ? void 0 : _noAssociationMenu__children_.children) || [];
                    return noAssociationMenu;
                }
                children = [
                    currentRecord
                ];
            } else children = [
                currentRecord,
                otherRecords
            ];
        } else children = hideOtherRecordsInPopup ? [
            _associationRecords
        ] : [
            _associationRecords,
            otherRecords
        ];
        return [
            {
                name: 'records',
                label: t('Records'),
                type: 'subMenu',
                children: children.filter(Boolean)
            }
        ];
    }, [
        associationFields,
        collection.dataSource,
        collection.name,
        componentName,
        dataBlockInitializerProps,
        hideOtherRecordsInPopup,
        noAssociationMenu,
        t
    ]);
    return noAssociationMenu;
};
const createDetailsBlockSchema = (options)=>{
    const { formItemInitializers = 'details:configureFields', actionInitializers = 'detailsWithPaging:configureActions', collection, dataSource, association, template, settings, action = 'list', ...others } = options;
    const resourceName = association || collection;
    const schema = {
        type: 'void',
        'x-acl-action': 'get' === action ? "".concat(resourceName, ":get") : "".concat(resourceName, ":view"),
        'x-decorator': 'DetailsBlockProvider',
        'x-decorator-props': {
            dataSource,
            collection,
            association,
            readPretty: true,
            action,
            ...'list' === action ? {
                params: {
                    pageSize: 1
                }
            } : {},
            ...others
        },
        'x-toolbar': 'BlockSchemaToolbar',
        'x-settings': settings,
        'x-component': 'CardItem',
        properties: {
            [(0, schema_namespaceObject.uid)()]: {
                type: 'void',
                'x-component': 'Details',
                'x-use-component-props': 'useDetailsBlockProps',
                'x-read-pretty': true,
                properties: {
                    [(0, schema_namespaceObject.uid)()]: {
                        type: 'void',
                        'x-initializer': actionInitializers,
                        'x-component': 'ActionBar',
                        'x-component-props': {
                            style: {
                                marginBottom: 24
                            }
                        },
                        properties: {}
                    },
                    grid: template || {
                        type: 'void',
                        'x-component': 'Grid',
                        'x-initializer': formItemInitializers,
                        properties: {}
                    },
                    ...'list' === action ? {
                        pagination: {
                            type: 'void',
                            'x-component': 'Pagination',
                            'x-use-component-props': 'useDetailsPaginationProps'
                        }
                    } : {}
                }
            }
        }
    };
    return schema;
};
const createFormBlockSchema = (options)=>{
    const { formItemInitializers = 'form:configureFields', actionInitializers = 'createForm:configureActions', collection, resource, dataSource, association, action, actions = {}, 'x-designer': designer = 'FormV2.Designer', template, title, settings, ...others } = options;
    const resourceName = resource || association || collection;
    const schema = {
        type: 'void',
        'x-acl-action-props': {
            skipScopeCheck: !action
        },
        'x-acl-action': action ? "".concat(resourceName, ":update") : "".concat(resourceName, ":create"),
        'x-decorator': 'FormBlockProvider',
        'x-decorator-props': {
            ...others,
            action,
            dataSource,
            resource: resourceName,
            collection,
            association
        },
        'x-toolbar': 'BlockSchemaToolbar',
        ...settings ? {
            'x-settings': settings
        } : {
            'x-designer': designer
        },
        'x-component': 'CardItem',
        'x-component-props': {
            title
        },
        properties: {
            [(0, schema_namespaceObject.uid)()]: {
                type: 'void',
                'x-component': 'FormV2',
                'x-use-component-props': 'useFormBlockProps',
                properties: {
                    [(0, schema_namespaceObject.uid)()]: {
                        type: 'void',
                        'x-initializer': actionInitializers,
                        'x-component': 'ActionBar',
                        'x-component-props': {
                            style: {
                                marginBottom: 'var(--tb-spacing)'
                            }
                        },
                        properties: actions
                    },
                    grid: template || {
                        type: 'void',
                        'x-component': 'Grid',
                        'x-initializer': formItemInitializers,
                        properties: {}
                    }
                }
            }
        }
    };
    return schema;
};
const createReadPrettyFormBlockSchema = (options)=>{
    const { formItemInitializers = 'details:configureFields', actionInitializers = 'details:configureActions', collection, association, dataSource, resource, template, settings, ...others } = options;
    const resourceName = resource || association || collection;
    const schema = {
        type: 'void',
        'x-acl-action': "".concat(resourceName, ":get"),
        'x-decorator': 'FormBlockProvider',
        'x-decorator-props': {
            resource: resourceName,
            collection,
            association,
            dataSource,
            readPretty: true,
            action: 'get',
            useParams: '{{ useParamsFromRecord }}',
            ...others
        },
        'x-toolbar': 'BlockSchemaToolbar',
        'x-settings': settings,
        'x-component': 'CardItem',
        properties: {
            [(0, schema_namespaceObject.uid)()]: {
                type: 'void',
                'x-component': 'FormV2',
                'x-use-component-props': 'useFormBlockProps',
                'x-read-pretty': true,
                properties: {
                    [(0, schema_namespaceObject.uid)()]: {
                        type: 'void',
                        'x-initializer': actionInitializers,
                        'x-component': 'ActionBar',
                        'x-component-props': {
                            style: {
                                marginBottom: 24
                            }
                        },
                        properties: {}
                    },
                    grid: template || {
                        type: 'void',
                        'x-component': 'Grid',
                        'x-initializer': formItemInitializers,
                        properties: {}
                    }
                }
            }
        }
    };
    return schema;
};
const createTableBlockSchema = (options)=>{
    const { collection, rowKey, tableActionInitializers, tableColumnInitializers, tableActionColumnInitializers, tableBlockProvider, disableTemplate, dataSource, blockType, pageSize = 20, ...others } = options;
    const schema = {
        type: 'void',
        'x-decorator': null != tableBlockProvider ? tableBlockProvider : 'TableBlockProvider',
        'x-acl-action': "".concat(collection, ":list"),
        'x-decorator-props': {
            collection,
            dataSource,
            action: 'list',
            params: {
                pageSize
            },
            rowKey,
            showIndex: true,
            dragSort: false,
            disableTemplate: null != disableTemplate && disableTemplate,
            blockType,
            ...others
        },
        'x-toolbar': 'BlockSchemaToolbar',
        'x-settings': 'blockSettings:table',
        'x-component': 'CardItem',
        'x-filter-targets': [],
        properties: {
            actions: {
                type: 'void',
                'x-initializer': null != tableActionInitializers ? tableActionInitializers : 'table:configureActions',
                'x-component': 'ActionBar',
                'x-component-props': {
                    style: {
                        marginBottom: 'var(--tb-spacing)'
                    }
                },
                properties: {}
            },
            [(0, schema_namespaceObject.uid)()]: {
                type: 'array',
                'x-initializer': null != tableColumnInitializers ? tableColumnInitializers : 'table:configureColumns',
                'x-component': 'TableV2',
                'x-use-component-props': 'useTableBlockProps',
                'x-component-props': {
                    rowKey: 'id',
                    rowSelection: {
                        type: 'checkbox'
                    }
                },
                properties: {
                    actions: {
                        type: 'void',
                        title: '{{ t("Actions") }}',
                        'x-action-column': 'actions',
                        'x-decorator': 'TableV2.Column.ActionBar',
                        'x-component': 'TableV2.Column',
                        'x-component-props': {
                            width: 150,
                            fixed: 'right'
                        },
                        'x-designer': 'TableV2.ActionColumnDesigner',
                        'x-initializer': null != tableActionColumnInitializers ? tableActionColumnInitializers : 'table:configureItemActions',
                        properties: {
                            [(0, schema_namespaceObject.uid)()]: {
                                type: 'void',
                                'x-decorator': 'DndContext',
                                'x-component': 'Space',
                                'x-component-props': {
                                    split: '|'
                                },
                                properties: {}
                            }
                        }
                    }
                }
            }
        }
    };
    return schema;
};
const getChildren = (param)=>{
    let { collections, dataSource, componentName, searchValue, getTemplatesByCollection, t } = param;
    var _collections_filter;
    return null == collections ? void 0 : null === (_collections_filter = collections.filter((item)=>{
        if (item.inherit) return false;
        if (!item.filterTargetKey) return false;
        if ([
            'Kanban',
            'FormItem'
        ].includes(componentName) && ('view' === item.template && !item.writableView || 'sql' === item.template)) return false;
        if ('file' === item.template && [
            'Kanban',
            'FormItem',
            'Calendar'
        ].includes(componentName)) return false;
        else {
            const title = item.title || item.tableName;
            if (!title) return false;
            return title.toUpperCase().includes(searchValue.toUpperCase()) && !((null == item ? void 0 : item.isThrough) && (null == item ? void 0 : item.autoCreate));
        }
    })) || void 0 === _collections_filter ? void 0 : _collections_filter.map((item, index)=>{
        const title = item.title || item.tableName || item.label;
        const templates = getTemplatesByCollection(dataSource, item.name).filter((template)=>componentName && template.componentName === componentName && ([
                'FormItem',
                'ReadPrettyFormItem'
            ].includes(componentName) || !template.resourceName || template.resourceName === item.name));
        if (!templates.length) return {
            type: 'item',
            name: item.name,
            title,
            dataSource
        };
        return {
            key: "".concat(componentName, "_table_subMenu_").concat(index),
            type: 'subMenu',
            name: "".concat(item.name, "_").concat(index),
            title,
            dataSource,
            children: [
                {
                    type: 'item',
                    name: item.name,
                    dataSource,
                    title: t('Blank block')
                },
                {
                    type: 'divider'
                },
                {
                    key: "".concat(componentName, "_table_subMenu_").concat(index, "_copy"),
                    type: 'subMenu',
                    name: 'copy',
                    dataSource,
                    title: t('Duplicate template'),
                    children: templates.map((template)=>{
                        const templateName = [
                            'FormItem',
                            'ReadPrettyFormItem'
                        ].includes(null == template ? void 0 : template.componentName) ? "".concat(null == template ? void 0 : template.name, " ").concat(t('(Fields only)')) : null == template ? void 0 : template.name;
                        return {
                            type: 'item',
                            mode: 'copy',
                            name: item.name,
                            template,
                            dataSource,
                            title: templateName || t('Untitled')
                        };
                    })
                },
                {
                    key: "".concat(componentName, "_table_subMenu_").concat(index, "_ref"),
                    type: 'subMenu',
                    name: 'ref',
                    dataSource,
                    title: t('Reference template'),
                    children: templates.map((template)=>{
                        const templateName = [
                            'FormItem',
                            'ReadPrettyFormItem'
                        ].includes(null == template ? void 0 : template.componentName) ? "".concat(null == template ? void 0 : template.name, " ").concat(t('(Fields only)')) : null == template ? void 0 : template.name;
                        return {
                            type: 'item',
                            mode: 'reference',
                            name: item.name,
                            template,
                            dataSource,
                            title: templateName || t('Untitled')
                        };
                    })
                }
            ]
        };
    });
};
function useAssociationFields(param) {
    let { componentName, filterCollections, showAssociationFields } = param;
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { getCollectionFields } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const collection = (0, index_js_namespaceObject.useCollection_deprecated)();
    const cm = (0, external_index_js_namespaceObject.useCollectionManager)();
    const dataSource = (0, external_index_js_namespaceObject.useDataSourceKey)();
    const { getTemplatesByCollection } = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplateManager)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const compile = (0, external_schema_component_index_js_namespaceObject.useCompile)();
    return (0, external_react_namespaceObject.useMemo)(()=>{
        if (!showAssociationFields) return [];
        let fields = [];
        if (fieldSchema['x-initializer']) fields = collection.fields;
        else {
            const collection = recursiveParent(fieldSchema.parent);
            if (collection) fields = getCollectionFields(collection);
        }
        return fields.filter((field)=>[
                'linkTo',
                'subTable',
                'o2m',
                'm2m',
                'obo',
                'oho',
                'o2o',
                'm2o'
            ].includes(field.interface)).filter((field)=>filterCollections({
                associationField: field
            })).map((field, index)=>{
            const title = compile(field.uiSchema.title || field.name);
            const templates = getTemplatesByCollection(dataSource, field.target).filter((template)=>{
                if ('ReadPrettyFormItem' === componentName) {
                    if ([
                        'hasOne',
                        'belongsTo'
                    ].includes(field.type)) return 'ReadPrettyFormItem' === template.componentName;
                    return 'Details' === template.componentName;
                }
                return componentName && template.componentName === componentName && ([
                    'FormItem',
                    'ReadPrettyFormItem'
                ].includes(componentName) || !template.resourceName || template.resourceName === "".concat(field.collectionName, ".").concat(field.name));
            });
            if (!templates.length) return {
                type: 'item',
                name: "".concat(field.collectionName, ".").concat(field.name),
                collectionName: field.target,
                title,
                dataSource,
                associationField: field
            };
            return {
                key: "associationFiled_".concat(componentName, "_table_subMenu_").concat(index),
                type: 'subMenu',
                name: "".concat(field.target, "_").concat(index),
                title,
                dataSource,
                children: [
                    {
                        type: 'item',
                        name: "".concat(field.collectionName, ".").concat(field.name),
                        collectionName: field.target,
                        dataSource,
                        title: t('Blank block'),
                        associationField: field
                    },
                    {
                        type: 'divider'
                    },
                    {
                        key: "associationFiled_".concat(componentName, "_table_subMenu_").concat(index, "_copy"),
                        type: 'subMenu',
                        name: 'copy',
                        dataSource,
                        title: t('Duplicate template'),
                        children: templates.map((template)=>{
                            const templateName = [
                                'FormItem',
                                'ReadPrettyFormItem'
                            ].includes(null == template ? void 0 : template.componentName) ? "".concat(null == template ? void 0 : template.name, " ").concat(t('(Fields only)')) : null == template ? void 0 : template.name;
                            return {
                                type: 'item',
                                mode: 'copy',
                                name: "".concat(field.collectionName, ".").concat(field.name),
                                collectionName: field.target,
                                template,
                                dataSource,
                                title: templateName || t('Untitled'),
                                associationField: field
                            };
                        })
                    },
                    {
                        key: "associationFiled_".concat(componentName, "_table_subMenu_").concat(index, "_ref"),
                        type: 'subMenu',
                        name: 'ref',
                        dataSource,
                        title: t('Reference template'),
                        children: templates.map((template)=>{
                            const templateName = [
                                'FormItem',
                                'ReadPrettyFormItem'
                            ].includes(null == template ? void 0 : template.componentName) ? "".concat(null == template ? void 0 : template.name, " ").concat(t('(Fields only)')) : null == template ? void 0 : template.name;
                            return {
                                type: 'item',
                                mode: 'reference',
                                name: "".concat(field.collectionName, ".").concat(field.name),
                                collectionName: field.target,
                                template,
                                dataSource,
                                title: templateName || t('Untitled'),
                                associationField: field
                            };
                        })
                    }
                ]
            };
        });
    }, [
        cm,
        collection.fields,
        compile,
        componentName,
        dataSource,
        fieldSchema,
        filterCollections,
        getCollectionFields,
        getTemplatesByCollection,
        showAssociationFields,
        t
    ]);
}
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
});
