import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_components__ from "@tachybase/components";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__modules_blocks_data_blocks_details_multi_setDataLoadingModeSettingsItem_mjs__ from "../../../modules/blocks/data-blocks/details-multi/setDataLoadingModeSettingsItem.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__ from "../../../record-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__ from "../../../schema-settings/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettingsDataScope_mjs__ from "../../../schema-settings/SchemaSettingsDataScope.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_templates_index_mjs__ from "../../../schema-templates/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../../hooks/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__filter_index_mjs__ from "../filter/index.mjs";
const ListDesigner = ()=>{
    var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1, _fieldSchema_xdecoratorprops2, _fieldSchema_xdecoratorprops_params1, _fieldSchema_xdecoratorprops3, _field_decoratorProps_params, _field_decoratorProps;
    const { name, title } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
    const template = (0, __WEBPACK_EXTERNAL_MODULE__schema_templates_index_mjs__.useSchemaTemplate)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { form } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useFormBlockContext)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useDesignable)();
    const sortFields = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useSortFields)(name);
    (0, __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.useRecord)();
    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 defaultResource = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops1 ? void 0 : _fieldSchema_xdecoratorprops1.resource) || (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops2 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops2 ? void 0 : _fieldSchema_xdecoratorprops2.association);
    const sort = null == defaultSort ? void 0 : defaultSort.map((item)=>item.startsWith('-') ? {
            field: item.substring(1),
            direction: 'desc'
        } : {
            field: item,
            direction: 'asc'
        });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.GeneralSchemaDesigner, {
        template: template,
        title: title || name,
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsBlockTitleItem, {}),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettingsDataScope_mjs__.SchemaSettingsDataScope, {
                collectionName: name,
                defaultFilter: (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops3 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops3 ? void 0 : null === (_fieldSchema_xdecoratorprops_params1 = _fieldSchema_xdecoratorprops3.params) || void 0 === _fieldSchema_xdecoratorprops_params1 ? void 0 : _fieldSchema_xdecoratorprops_params1.filter) || {},
                form: form,
                onSubmit: (param)=>{
                    let { filter } = param;
                    filter = (0, __WEBPACK_EXTERNAL_MODULE__filter_index_mjs__.removeNullCondition)(filter);
                    __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.params.filter', filter);
                    field.decoratorProps.params = {
                        ...fieldSchema['x-decorator-props'].params,
                        page: 1
                    };
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                }
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsModalItem, {
                title: t('Set default sorting rules'),
                components: {
                    ArrayItems: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.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,
                                                '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;
                    const sortArr = sort.map((item)=>'desc' === item.direction ? "-".concat(item.field) : item.field);
                    __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.params.sort', sortArr);
                    field.decoratorProps.params = {
                        ...fieldSchema['x-decorator-props'].params,
                        page: 1
                    };
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                }
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__modules_blocks_data_blocks_details_multi_setDataLoadingModeSettingsItem_mjs__.SetDataLoadingMode, {}),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsSelectItem, {
                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: '80',
                        value: 80
                    },
                    {
                        label: '100',
                        value: 100
                    }
                ],
                onChange: (pageSize)=>{
                    __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.params.pageSize', pageSize);
                    field.decoratorProps.params = {
                        ...fieldSchema['x-decorator-props'].params,
                        page: 1
                    };
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                }
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsTemplate, {
                componentName: 'List',
                collectionName: name,
                resourceName: defaultResource
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsDivider, {}),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsRemove, {
                removeParentsIfNoChildren: true,
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            })
        ]
    });
};
export { ListDesigner };
