"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__, {
    TableVoidDesigner: ()=>TableVoidDesigner
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
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("../../../collection-manager/index.js");
const action_hooks_js_namespaceObject = require("../../../collection-manager/action-hooks.js");
const external_schema_settings_index_js_namespaceObject = require("../../../schema-settings/index.js");
const external_schema_templates_index_js_namespaceObject = require("../../../schema-templates/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const TableVoidDesigner = ()=>{
    var _fieldSchema_xdecoratorprops_request_params, _fieldSchema_xdecoratorprops_request, _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops_request_params1, _fieldSchema_xdecoratorprops_request1, _fieldSchema_xdecoratorprops1, _field_decoratorProps_request_params;
    const { name, title } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const dataSource = (0, action_hooks_js_namespaceObject.useCollectionFilterOptions)(name);
    const sortFields = (0, action_hooks_js_namespaceObject.useSortFields)(name);
    const ctx = (0, index_js_namespaceObject.useResourceActionContext)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { dn } = (0, external_hooks_index_js_namespaceObject.useDesignable)();
    const defaultFilter = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : null === (_fieldSchema_xdecoratorprops_request = _fieldSchema_xdecoratorprops.request) || void 0 === _fieldSchema_xdecoratorprops_request ? void 0 : null === (_fieldSchema_xdecoratorprops_request_params = _fieldSchema_xdecoratorprops_request.params) || void 0 === _fieldSchema_xdecoratorprops_request_params ? void 0 : _fieldSchema_xdecoratorprops_request_params.filter) || {};
    const defaultSort = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops1 ? void 0 : null === (_fieldSchema_xdecoratorprops_request1 = _fieldSchema_xdecoratorprops1.request) || void 0 === _fieldSchema_xdecoratorprops_request1 ? void 0 : null === (_fieldSchema_xdecoratorprops_request_params1 = _fieldSchema_xdecoratorprops_request1.params) || void 0 === _fieldSchema_xdecoratorprops_request_params1 ? void 0 : _fieldSchema_xdecoratorprops_request_params1.sort) || [];
    const sort = null == defaultSort ? void 0 : defaultSort.map((item)=>item.startsWith('-') ? {
            field: item.substring(1),
            direction: 'desc'
        } : {
            field: item,
            direction: 'asc'
        });
    const template = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplate)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_schema_settings_index_js_namespaceObject.GeneralSchemaDesigner, {
        template: template,
        title: title || name,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsSwitchItem, {
                title: t('Enable drag and drop sorting'),
                checked: field.decoratorProps.dragSort,
                onChange: (dragSort)=>{
                    var _ctx_params;
                    field.decoratorProps.dragSort = dragSort;
                    fieldSchema['x-decorator-props'].dragSort = dragSort;
                    ctx.run({
                        ...null === (_ctx_params = ctx.params) || void 0 === _ctx_params ? void 0 : _ctx_params[0],
                        sort: 'sort'
                    });
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsModalItem, {
                title: '设置数据范围',
                schema: {
                    type: 'object',
                    title: '设置数据范围',
                    properties: {
                        filter: {
                            default: defaultFilter,
                            title: '数据范围',
                            enum: dataSource,
                            'x-component': 'Filter',
                            'x-component-props': {}
                        }
                    }
                },
                onSubmit: (param)=>{
                    let { filter } = param;
                    var _ctx_params;
                    const params = field.decoratorProps.request.params || {};
                    params.filter = filter;
                    field.decoratorProps.request.params = params;
                    fieldSchema['x-decorator-props']['request']['params'] = params;
                    ctx.run({
                        ...null === (_ctx_params = ctx.params) || void 0 === _ctx_params ? void 0 : _ctx_params[0],
                        filter
                    });
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsModalItem, {
                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 _ctx_params;
                    const sortArr = sort.map((item)=>'desc' === item.direction ? "-".concat(item.field) : item.field);
                    const params = field.decoratorProps.request.params || {};
                    params.sort = sortArr;
                    field.decoratorProps.request.params = params;
                    fieldSchema['x-decorator-props']['request']['params'] = params;
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                    ctx.run({
                        ...null === (_ctx_params = ctx.params) || void 0 === _ctx_params ? void 0 : _ctx_params[0],
                        sort: sortArr
                    });
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsSelectItem, {
                title: '每页显示',
                value: (null === (_field_decoratorProps_request_params = field.decoratorProps.request.params) || void 0 === _field_decoratorProps_request_params ? void 0 : _field_decoratorProps_request_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 _ctx_params;
                    const params = field.decoratorProps.request.params || {};
                    params.pageSize = pageSize;
                    field.decoratorProps.request.params = params;
                    fieldSchema['x-decorator-props']['request']['params'] = params;
                    ctx.run({
                        ...null === (_ctx_params = ctx.params) || void 0 === _ctx_params ? void 0 : _ctx_params[0],
                        pageSize
                    });
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsDivider, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsTemplate, {
                componentName: 'Table',
                collectionName: name
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsDivider, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsRemove, {
                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
});
