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_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_settings_index_mjs__ from "../../../application/schema-settings/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_DetailsBlockProvider_mjs__ from "../../../block-provider/DetailsBlockProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_action_hooks_mjs__ from "../../../collection-manager/action-hooks.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__schema_settings_SchemaSettings_mjs__ from "../../../schema-settings/SchemaSettings.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettingsDataScope_mjs__ from "../../../schema-settings/SchemaSettingsDataScope.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 formSettings = new __WEBPACK_EXTERNAL_MODULE__application_schema_settings_index_mjs__.SchemaSettings({
    name: 'FormSettings',
    items: [
        {
            name: 'title',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettings_mjs__.SchemaSettingsBlockTitleItem
        },
        {
            name: 'linkageRules',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettings_mjs__.SchemaSettingsLinkageRules,
            useComponentProps () {
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                return {
                    collectionName: name
                };
            }
        },
        {
            name: 'dataTemplates',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettings_mjs__.SchemaSettingsDataTemplates,
            useVisible () {
                const { action } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useFormBlockContext)();
                return !action;
            },
            useComponentProps () {
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                return {
                    collectionName: name
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'formItemTemplate',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettings_mjs__.SchemaSettingsFormItemTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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 __WEBPACK_EXTERNAL_MODULE__application_schema_settings_index_mjs__.SchemaSettings({
    name: 'ReadPrettyFormSettings',
    items: [
        {
            name: 'title',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettings_mjs__.SchemaSettingsBlockTitleItem
        },
        {
            name: 'formItemTemplate',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettings_mjs__.SchemaSettingsFormItemTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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 __WEBPACK_EXTERNAL_MODULE__application_schema_settings_index_mjs__.SchemaSettings({
    name: 'FormDetailsSettings',
    items: [
        {
            name: 'title',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettings_mjs__.SchemaSettingsBlockTitleItem
        },
        {
            name: 'dataScope',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettingsDataScope_mjs__.SchemaSettingsDataScope,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops;
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                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 { service } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_DetailsBlockProvider_mjs__.useDetailsBlockContext)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.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, __WEBPACK_EXTERNAL_MODULE__filter_index_mjs__.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: __WEBPACK_EXTERNAL_MODULE__modules_blocks_data_blocks_details_multi_setDataLoadingModeSettingsItem_mjs__.SetDataLoadingMode
        },
        {
            name: 'sortingRules',
            type: 'modal',
            useComponentProps () {
                var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops;
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { service } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_DetailsBlockProvider_mjs__.useDetailsBlockContext)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useDesignable)();
                const sortFields = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_action_hooks_mjs__.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: __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,
                                                    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: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettings_mjs__.SchemaSettingsTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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'
                }
            }
        }
    ]
});
export { formDetailsSettings, formSettings, readPrettyFormSettings };
