"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    formSettings: ()=>formSettings,
    formDetailsSettings: ()=>formDetailsSettings,
    readPrettyFormSettings: ()=>readPrettyFormSettings
});
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../../application/schema-settings/index.js");
const external_block_provider_index_js_namespaceObject = require("../../../block-provider/index.js");
const DetailsBlockProvider_js_namespaceObject = require("../../../block-provider/DetailsBlockProvider.js");
const external_collection_manager_index_js_namespaceObject = require("../../../collection-manager/index.js");
const action_hooks_js_namespaceObject = require("../../../collection-manager/action-hooks.js");
const setDataLoadingModeSettingsItem_js_namespaceObject = require("../../../modules/blocks/data-blocks/details-multi/setDataLoadingModeSettingsItem.js");
const SchemaSettings_js_namespaceObject = require("../../../schema-settings/SchemaSettings.js");
const SchemaSettingsDataScope_js_namespaceObject = require("../../../schema-settings/SchemaSettingsDataScope.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const external_filter_index_js_namespaceObject = require("../filter/index.js");
const formSettings = new index_js_namespaceObject.SchemaSettings({
    name: 'FormSettings',
    items: [
        {
            name: 'title',
            Component: SchemaSettings_js_namespaceObject.SchemaSettingsBlockTitleItem
        },
        {
            name: 'linkageRules',
            Component: SchemaSettings_js_namespaceObject.SchemaSettingsLinkageRules,
            useComponentProps () {
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                return {
                    collectionName: name
                };
            }
        },
        {
            name: 'dataTemplates',
            Component: SchemaSettings_js_namespaceObject.SchemaSettingsDataTemplates,
            useVisible () {
                const { action } = (0, external_block_provider_index_js_namespaceObject.useFormBlockContext)();
                return !action;
            },
            useComponentProps () {
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                return {
                    collectionName: name
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'formItemTemplate',
            Component: SchemaSettings_js_namespaceObject.SchemaSettingsFormItemTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const defaultResource = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops.resource) || (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops1 ? void 0 : _fieldSchema_xdecoratorprops1.association);
                return {
                    componentName: 'FormItem',
                    collectionName: name,
                    resourceName: defaultResource
                };
            }
        },
        {
            name: 'divider2',
            type: 'divider'
        },
        {
            name: 'remove',
            type: 'remove',
            componentProps: {
                removeParentsIfNoChildren: true,
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            }
        }
    ]
});
const readPrettyFormSettings = new index_js_namespaceObject.SchemaSettings({
    name: 'ReadPrettyFormSettings',
    items: [
        {
            name: 'title',
            Component: SchemaSettings_js_namespaceObject.SchemaSettingsBlockTitleItem
        },
        {
            name: 'formItemTemplate',
            Component: SchemaSettings_js_namespaceObject.SchemaSettingsFormItemTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const defaultResource = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops.resource) || (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops1 ? void 0 : _fieldSchema_xdecoratorprops1.association);
                return {
                    insertAdjacentPosition: 'beforeEnd',
                    componentName: 'ReadPrettyFormItem',
                    collectionName: name,
                    resourceName: defaultResource
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'remove',
            type: 'remove',
            componentProps: {
                removeParentsIfNoChildren: true,
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            }
        }
    ]
});
const formDetailsSettings = new index_js_namespaceObject.SchemaSettings({
    name: 'FormDetailsSettings',
    items: [
        {
            name: 'title',
            Component: SchemaSettings_js_namespaceObject.SchemaSettingsBlockTitleItem
        },
        {
            name: 'dataScope',
            Component: SchemaSettingsDataScope_js_namespaceObject.SchemaSettingsDataScope,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops;
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const { form } = (0, external_block_provider_index_js_namespaceObject.useFormBlockContext)();
                const field = (0, schema_namespaceObject.useField)();
                const { service } = (0, DetailsBlockProvider_js_namespaceObject.useDetailsBlockContext)();
                const { dn } = (0, external_hooks_index_js_namespaceObject.useDesignable)();
                return {
                    collectionName: name,
                    defaultFilter: (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : null === (_fieldSchema_xdecoratorprops_params = _fieldSchema_xdecoratorprops.params) || void 0 === _fieldSchema_xdecoratorprops_params ? void 0 : _fieldSchema_xdecoratorprops_params.filter) || {},
                    form,
                    onSubmit: (param)=>{
                        let { filter } = param;
                        var _service_params;
                        filter = (0, external_filter_index_js_namespaceObject.removeNullCondition)(filter);
                        const params = field.decoratorProps.params || {};
                        params.filter = filter;
                        field.decoratorProps.params = params;
                        fieldSchema['x-decorator-props']['params'] = params;
                        service.run({
                            ...null === (_service_params = service.params) || void 0 === _service_params ? void 0 : _service_params[0],
                            filter
                        });
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'setDataLoadingMode',
            Component: setDataLoadingModeSettingsItem_js_namespaceObject.SetDataLoadingMode
        },
        {
            name: 'sortingRules',
            type: 'modal',
            useComponentProps () {
                var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops;
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const field = (0, schema_namespaceObject.useField)();
                const { service } = (0, DetailsBlockProvider_js_namespaceObject.useDetailsBlockContext)();
                const { dn } = (0, external_hooks_index_js_namespaceObject.useDesignable)();
                const sortFields = (0, action_hooks_js_namespaceObject.useSortFields)(name);
                const defaultSort = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : null === (_fieldSchema_xdecoratorprops_params = _fieldSchema_xdecoratorprops.params) || void 0 === _fieldSchema_xdecoratorprops_params ? void 0 : _fieldSchema_xdecoratorprops_params.sort) || [];
                const sort = null == defaultSort ? void 0 : defaultSort.map((item)=>item.startsWith('-') ? {
                        field: item.substring(1),
                        direction: 'desc'
                    } : {
                        field: item,
                        direction: 'asc'
                    });
                return {
                    title: t('Set default sorting rules'),
                    components: {
                        ArrayItems: components_namespaceObject.ArrayItems
                    },
                    schema: {
                        type: 'object',
                        title: t('Set default sorting rules'),
                        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 (param) {
                        let { sort } = param;
                        var _service_params;
                        const sortArr = sort.map((item)=>'desc' === item.direction ? "-".concat(item.field) : item.field);
                        const params = field.decoratorProps.params || {};
                        params.sort = sortArr;
                        field.decoratorProps.params = params;
                        fieldSchema['x-decorator-props']['params'] = params;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                        service.run({
                            ...null === (_service_params = service.params) || void 0 === _service_params ? void 0 : _service_params[0],
                            sort: sortArr
                        });
                    }
                };
            }
        },
        {
            name: 'template',
            Component: SchemaSettings_js_namespaceObject.SchemaSettingsTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const defaultResource = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops.resource) || (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops1 ? void 0 : _fieldSchema_xdecoratorprops1.association);
                return {
                    componentName: 'Details',
                    collectionName: name,
                    resourceName: defaultResource
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'remove',
            type: 'remove',
            componentProps: {
                removeParentsIfNoChildren: true,
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            }
        }
    ]
});
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
});
