"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__, {
    tableSelectorBlockSettings: ()=>tableSelectorBlockSettings
});
const external_react_namespaceObject = require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_lodash_namespaceObject = require("lodash");
const external_react_i18next_namespaceObject = require("react-i18next");
const SchemaSettings_js_namespaceObject = require("../../../../application/schema-settings/SchemaSettings.js");
const index_js_namespaceObject = require("../../../../block-provider/index.js");
const external_collection_manager_index_js_namespaceObject = require("../../../../collection-manager/index.js");
const external_schema_component_index_js_namespaceObject = require("../../../../schema-component/index.js");
const SchemaSettingsDataScope_js_namespaceObject = require("../../../../schema-settings/SchemaSettingsDataScope.js");
const setDataLoadingModeSettingsItem_js_namespaceObject = require("../details-multi/setDataLoadingModeSettingsItem.js");
const tableSelectorBlockSettings = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'blockSettings:tableSelector',
    items: [
        {
            name: 'SetTheDataScope',
            Component: SchemaSettingsDataScope_js_namespaceObject.SchemaSettingsDataScope,
            useComponentProps: ()=>{
                var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops;
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const field = (0, schema_namespaceObject.useField)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const { form } = (0, index_js_namespaceObject.useFormBlockContext)();
                const { service, extraFilter } = (0, index_js_namespaceObject.useTableSelectorContext)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                const dataLoadingMode = (0, setDataLoadingModeSettingsItem_js_namespaceObject.useDataLoadingMode)();
                const onDataScopeSubmit = (0, external_react_namespaceObject.useCallback)((param)=>{
                    let { filter } = param;
                    filter = (0, external_schema_component_index_js_namespaceObject.removeNullCondition)(filter);
                    const params = field.decoratorProps.params || {};
                    params.filter = filter;
                    field.decoratorProps.params = params;
                    fieldSchema['x-decorator-props']['params'] = params;
                    let serviceFilter = (0, external_lodash_namespaceObject.cloneDeep)(filter);
                    if (extraFilter) serviceFilter = serviceFilter ? {
                        $and: [
                            extraFilter,
                            serviceFilter
                        ]
                    } : extraFilter;
                    if ('auto' === dataLoadingMode) {
                        var _service_params;
                        service.run({
                            ...null === (_service_params = service.params) || void 0 === _service_params ? void 0 : _service_params[0],
                            filter: serviceFilter,
                            page: 1
                        });
                    }
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                }, [
                    field.decoratorProps,
                    fieldSchema,
                    extraFilter,
                    dataLoadingMode,
                    dn,
                    service
                ]);
                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: form,
                    onSubmit: onDataScopeSubmit
                };
            }
        },
        {
            name: 'treeTable',
            type: 'switch',
            useComponentProps: ()=>{
                const field = (0, schema_namespaceObject.useField)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const { service } = (0, index_js_namespaceObject.useTableSelectorContext)();
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                return {
                    title: t('Tree table'),
                    defaultChecked: true,
                    checked: false !== field.decoratorProps.treeTable,
                    onChange: (flag)=>{
                        var _service_params;
                        field.form.clearFormGraph("".concat(field.address, ".*"));
                        field.decoratorProps.treeTable = flag;
                        fieldSchema['x-decorator-props'].treeTable = flag;
                        const params = {
                            ...null === (_service_params = service.params) || void 0 === _service_params ? void 0 : _service_params[0],
                            tree: !!flag || null
                        };
                        dn.emit('patch', {
                            schema: fieldSchema
                        });
                        dn.refresh();
                        service.run(params);
                    }
                };
            },
            useVisible: ()=>{
                const { getCollectionJoinField } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const collection = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const collectionFieldSchema = (0, index_js_namespaceObject.recursiveParent)(fieldSchema, 'CollectionField');
                const collectionField = getCollectionJoinField(null == collectionFieldSchema ? void 0 : collectionFieldSchema['x-collection-field']);
                return (null == collection ? void 0 : collection.tree) && (null == collectionField ? void 0 : collectionField.target) === (null == collectionField ? void 0 : collectionField.collectionName);
            }
        },
        {
            name: 'SetDefaultSortingRules',
            type: 'modal',
            useComponentProps () {
                var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops;
                const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const field = (0, schema_namespaceObject.useField)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const sortFields = (0, external_collection_manager_index_js_namespaceObject.useSortFields)(name);
                const { service } = (0, index_js_namespaceObject.useTableSelectorContext)();
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                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
                                                        },
                                                        optionLabelProp: 'fullLabel'
                                                    }
                                                },
                                                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
                        });
                    }
                };
            },
            useVisible () {
                const field = (0, schema_namespaceObject.useField)();
                const { dragSort } = field.decoratorProps;
                return !dragSort;
            }
        },
        {
            name: 'setDataLoadingMode',
            Component: setDataLoadingModeSettingsItem_js_namespaceObject.SetDataLoadingMode
        },
        {
            name: 'RecordsPerPage',
            type: 'select',
            useComponentProps () {
                var _field_decoratorProps_params, _field_decoratorProps;
                const field = (0, schema_namespaceObject.useField)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const { service } = (0, index_js_namespaceObject.useTableSelectorContext)();
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                return {
                    title: t('Records per page'),
                    value: (null === (_field_decoratorProps = field.decoratorProps) || void 0 === _field_decoratorProps ? void 0 : null === (_field_decoratorProps_params = _field_decoratorProps.params) || void 0 === _field_decoratorProps_params ? void 0 : _field_decoratorProps_params.pageSize) || 20,
                    options: [
                        {
                            label: '10',
                            value: 10
                        },
                        {
                            label: '20',
                            value: 20
                        },
                        {
                            label: '50',
                            value: 50
                        },
                        {
                            label: '100',
                            value: 100
                        },
                        {
                            label: '200',
                            value: 200
                        }
                    ],
                    onChange: (pageSize)=>{
                        var _service_params;
                        const params = field.decoratorProps.params || {};
                        params.pageSize = pageSize;
                        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],
                            pageSize,
                            page: 1
                        });
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'delete',
            type: 'remove',
            useComponentProps () {
                return {
                    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
});
