"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    setIsChangOnSelect: ()=>setIsChangOnSelect,
    SchemaSettingsSortingRule: ()=>SchemaSettingsSortingRule,
    cascaderComponentFieldSettings: ()=>cascaderComponentFieldSettings
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_lodash_namespaceObject = require("lodash");
var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
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 useFieldComponentName_js_namespaceObject = require("../../../../common/useFieldComponentName.js");
const external_data_source_index_js_namespaceObject = require("../../../../data-source/index.js");
const external_record_provider_index_js_namespaceObject = require("../../../../record-provider/index.js");
const external_schema_component_index_js_namespaceObject = require("../../../../schema-component/index.js");
const util_js_namespaceObject = require("../../../../schema-component/antd/association-field/util.js");
const FormItem_Settings_js_namespaceObject = require("../../../../schema-component/antd/form-item/FormItem.Settings.js");
const Table_Column_Decorator_js_namespaceObject = require("../../../../schema-component/antd/table-v2/Table.Column.Decorator.js");
const external_schema_settings_index_js_namespaceObject = require("../../../../schema-settings/index.js");
const SchemaSettingsDataScope_js_namespaceObject = require("../../../../schema-settings/SchemaSettingsDataScope.js");
const external_variables_index_js_namespaceObject = require("../../../../variables/index.js");
const SchemaSettingsSortingRule = function(props) {
    var _fieldSchema_xcomponentprops_service_params, _fieldSchema_xcomponentprops_service, _fieldSchema_xcomponentprops;
    const field = (0, schema_namespaceObject.useField)();
    const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const currentSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { getField } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
    const { getCollectionJoinField } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
    var _props_fieldSchema;
    const fieldSchema = null !== (_props_fieldSchema = null == props ? void 0 : props.fieldSchema) && void 0 !== _props_fieldSchema ? _props_fieldSchema : currentSchema;
    const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
    const sortFields = (0, external_collection_manager_index_js_namespaceObject.useSortFields)(null == collectionField ? void 0 : collectionField.target);
    const defaultSort = (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_service = _fieldSchema_xcomponentprops.service) || void 0 === _fieldSchema_xcomponentprops_service ? void 0 : null === (_fieldSchema_xcomponentprops_service_params = _fieldSchema_xcomponentprops_service.params) || void 0 === _fieldSchema_xcomponentprops_service_params ? void 0 : _fieldSchema_xcomponentprops_service_params.sort) || [];
    const sort = null == defaultSort ? void 0 : defaultSort.map((item)=>(null == item ? void 0 : item.startsWith('-')) ? {
            field: item.substring(1),
            direction: 'desc'
        } : {
            field: item,
            direction: 'asc'
        });
    return /*#__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 _props_onSubmitCallBack, _fieldSchema_xcomponentprops, _field_path, _field_path1;
            const sortArr = sort.map((item)=>'desc' === item.direction ? "-".concat(item.field) : item.field);
            external_lodash_default().set(field.componentProps, 'service.params.sort', sortArr);
            null == props || null === (_props_onSubmitCallBack = props.onSubmitCallBack) || void 0 === _props_onSubmitCallBack || _props_onSubmitCallBack.call(props, sortArr);
            const service = null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.service;
            if (service) {
                var _field_componentProps_service_params, _field_componentProps;
                service.params['sort'] = null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : null === (_field_componentProps_service_params = _field_componentProps.service.params) || void 0 === _field_componentProps_service_params ? void 0 : _field_componentProps_service_params.sort;
            } else {
                var _field_componentProps_service_params1, _field_componentProps1;
                fieldSchema['x-component-props']['service'] = {
                    params: {
                        sort: null === (_field_componentProps1 = field.componentProps) || void 0 === _field_componentProps1 ? void 0 : null === (_field_componentProps_service_params1 = _field_componentProps1.service.params) || void 0 === _field_componentProps_service_params1 ? void 0 : _field_componentProps_service_params1.sort
                    }
                };
            }
            const componentProps = fieldSchema['x-component-props'];
            const path = null === (_field_path1 = field.path) || void 0 === _field_path1 ? void 0 : _field_path1.splice((null === (_field_path = field.path) || void 0 === _field_path ? void 0 : _field_path.length) - 1, 1);
            field.form.query("".concat(path.concat("*." + fieldSchema.name))).forEach((f)=>{
                f.componentProps = componentProps;
            });
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-component-props': componentProps
                }
            });
        }
    });
};
const setIsChangOnSelect = function(props) {
    var _fieldSchema_xcomponentprops;
    const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { fieldSchema: tableColumnSchema, collectionField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
    (0, schema_namespaceObject.useField)();
    const schema = (0, schema_namespaceObject.useFieldSchema)();
    const fieldSchema = tableColumnSchema || schema;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsSwitchItem, {
        title: t('Chang on Parent'),
        checked: !!(null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.changOnSelect),
        onChange: (value)=>{
            fieldSchema['x-component-props']['changOnSelect'] = value;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-component-props': {
                        ...fieldSchema['x-component-props']
                    }
                }
            });
            dn.refresh();
        }
    });
};
const titleField = {
    name: 'titleField',
    type: 'select',
    useComponentProps () {
        var _collectionField_uiSchema_xcomponentprops, _collectionField_uiSchema, _field_componentProps, _fieldSchema_xcomponentprops;
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        const options = (0, FormItem_Settings_js_namespaceObject.useTitleFieldOptions)();
        const { uiSchema, fieldSchema: tableColumnSchema, collectionField: tableColumnField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const targetCollectionField = (0, external_data_source_index_js_namespaceObject.useCollectionField)();
        const collectionField = tableColumnField || targetCollectionField;
        const { getCollectionFields } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
        const fieldNames = {
            ...null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : null === (_collectionField_uiSchema_xcomponentprops = _collectionField_uiSchema['x-component-props']) || void 0 === _collectionField_uiSchema_xcomponentprops ? void 0 : _collectionField_uiSchema_xcomponentprops['fieldNames'],
            ...null == field ? void 0 : null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.fieldNames,
            ...null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['fieldNames']
        };
        return {
            title: t('Title field'),
            options,
            value: null == fieldNames ? void 0 : fieldNames.label,
            onChange (label) {
                var _collectionField_uiSchema_xcomponentprops, _collectionField_uiSchema, _fieldSchema_xcomponentprops, _field_path, _field_path1;
                const schema = {
                    ['x-uid']: fieldSchema['x-uid']
                };
                const newFieldNames = {
                    ...null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : null === (_collectionField_uiSchema_xcomponentprops = _collectionField_uiSchema['x-component-props']) || void 0 === _collectionField_uiSchema_xcomponentprops ? void 0 : _collectionField_uiSchema_xcomponentprops['fieldNames'],
                    ...null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['fieldNames'],
                    label
                };
                fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                fieldSchema['x-component-props']['fieldNames'] = newFieldNames;
                const target = getCollectionFields(collectionField.target).find((field)=>field.name === label);
                if ('m2o' === target.interface) fieldSchema['x-component-props']['x-next-title'] = {
                    label,
                    collection: target.collectionName
                };
                else fieldSchema['x-component-props']['x-next-title'] = null;
                schema['x-component-props'] = fieldSchema['x-component-props'];
                field.componentProps.fieldNames = fieldSchema['x-component-props'].fieldNames;
                const path = null === (_field_path1 = field.path) || void 0 === _field_path1 ? void 0 : _field_path1.splice((null === (_field_path = field.path) || void 0 === _field_path ? void 0 : _field_path.length) - 1, 1);
                field.form.query("".concat(path.concat("*." + fieldSchema.name))).forEach((f)=>{
                    f.componentProps.fieldNames = newFieldNames;
                });
                dn.emit('patch', {
                    schema
                });
                dn.refresh();
            }
        };
    }
};
const setDefaultSortingRules = {
    name: 'setDefaultSortingRules',
    Component: SchemaSettingsSortingRule
};
const setTheDataScope = {
    name: 'setTheDataScope',
    Component: SchemaSettingsDataScope_js_namespaceObject.SchemaSettingsDataScope,
    useComponentProps () {
        var _fieldSchema_xcomponentprops_service_params, _fieldSchema_xcomponentprops_service, _fieldSchema_xcomponentprops;
        const { getCollectionJoinField, getAllCollectionsInheritChain } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
        const { getField } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
        const { form } = (0, index_js_namespaceObject.useFormBlockContext)();
        const record = (0, external_record_provider_index_js_namespaceObject.useRecord)();
        const field = (0, schema_namespaceObject.useField)();
        const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const collectionField = tableColumnField || getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
        const variables = (0, external_variables_index_js_namespaceObject.useVariables)();
        const localVariables = (0, external_variables_index_js_namespaceObject.useLocalVariables)();
        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        return {
            collectionName: null == collectionField ? void 0 : collectionField.target,
            defaultFilter: (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_service = _fieldSchema_xcomponentprops.service) || void 0 === _fieldSchema_xcomponentprops_service ? void 0 : null === (_fieldSchema_xcomponentprops_service_params = _fieldSchema_xcomponentprops_service.params) || void 0 === _fieldSchema_xcomponentprops_service_params ? void 0 : _fieldSchema_xcomponentprops_service_params.filter) || {},
            form,
            dynamicComponent: (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.VariableInput, {
                    ...props,
                    form: form,
                    collectionField: props.collectionField,
                    record: record,
                    shouldChange: (0, external_schema_settings_index_js_namespaceObject.getShouldChange)({
                        collectionField: props.collectionField,
                        variables,
                        localVariables,
                        getAllCollectionsInheritChain
                    })
                }),
            onSubmit: (param)=>{
                let { filter } = param;
                var _fieldSchema_xcomponentprops, _field_path, _field_path1;
                filter = (0, external_schema_component_index_js_namespaceObject.removeNullCondition)(filter);
                external_lodash_default().set(field.componentProps, 'service.params.filter', filter);
                const service = null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.service;
                if (service) service.params['filter'] = filter;
                else fieldSchema['x-component-props']['service'] = {
                    params: {
                        filter: {
                            ...filter
                        }
                    }
                };
                const componentProps = fieldSchema['x-component-props'];
                const path = null === (_field_path1 = field.path) || void 0 === _field_path1 ? void 0 : _field_path1.splice((null === (_field_path = field.path) || void 0 === _field_path ? void 0 : _field_path.length) - 1, 1);
                field.form.query("".concat(path.concat("*." + fieldSchema.name))).forEach((f)=>{
                    f.componentProps = componentProps;
                });
                dn.emit('patch', {
                    schema: {
                        ['x-uid']: fieldSchema['x-uid'],
                        'x-component-props': componentProps
                    }
                });
                dn.refresh();
            }
        };
    }
};
const fieldComponent = {
    name: 'fieldComponent',
    type: 'select',
    useComponentProps () {
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const { fieldSchema: tableColumnSchema, collectionField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const fieldModeOptions = (0, external_schema_component_index_js_namespaceObject.useFieldModeOptions)({
            fieldSchema: tableColumnSchema,
            collectionField
        });
        const isAddNewForm = (0, external_schema_component_index_js_namespaceObject.useIsAddNewForm)();
        const fieldMode = (0, useFieldComponentName_js_namespaceObject.useFieldComponentName)();
        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        return {
            title: t('Field component'),
            options: fieldModeOptions,
            value: fieldMode,
            onChange (mode) {
                const schema = {
                    ['x-uid']: fieldSchema['x-uid']
                };
                fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                fieldSchema['x-component-props']['mode'] = mode;
                schema['x-component-props'] = fieldSchema['x-component-props'];
                field.componentProps = field.componentProps || {};
                field.componentProps.mode = mode;
                if ((0, util_js_namespaceObject.isSubMode)(fieldSchema) && isAddNewForm) {
                    var _field_setInitialValue, _field_setValue;
                    schema.default = null;
                    fieldSchema.default = null;
                    null == field || null === (_field_setInitialValue = field.setInitialValue) || void 0 === _field_setInitialValue || _field_setInitialValue.call(field, null);
                    null == field || null === (_field_setValue = field.setValue) || void 0 === _field_setValue || _field_setValue.call(field, null);
                }
                dn.emit('patch', {
                    schema
                });
                dn.refresh();
            }
        };
    }
};
const ChangOnSelect = {
    name: 'changOnSelect',
    Component: setIsChangOnSelect
};
const cascaderComponentFieldSettings = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'fieldSettings:component:Cascader',
    items: [
        {
            ...fieldComponent,
            useVisible: FormItem_Settings_js_namespaceObject.useIsAssociationField
        },
        {
            ...setTheDataScope,
            useVisible () {
                const isFieldReadPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                return !isFieldReadPretty;
            }
        },
        {
            ...setDefaultSortingRules,
            useComponentProps () {
                const { fieldSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                return {
                    fieldSchema
                };
            },
            useVisible () {
                const isFieldReadPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                return !isFieldReadPretty;
            }
        },
        {
            ...titleField,
            useVisible: FormItem_Settings_js_namespaceObject.useIsAssociationField
        },
        {
            ...ChangOnSelect,
            useVisible: FormItem_Settings_js_namespaceObject.useIsAssociationField
        }
    ]
});
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
});
