"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__, {
    AssociationSelect: ()=>AssociationSelect,
    default: ()=>AssociationSelect_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const icons_namespaceObject = require("@ant-design/icons");
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 index_js_namespaceObject = require("../../../block-provider/index.js");
const external_collection_manager_index_js_namespaceObject = require("../../../collection-manager/index.js");
const external_schema_items_index_js_namespaceObject = require("../../../schema-items/index.js");
const GeneralSchemaDesigner_js_namespaceObject = require("../../../schema-settings/GeneralSchemaDesigner.js");
const useIsAllowToSetDefaultValue_js_namespaceObject = require("../../../schema-settings/hooks/useIsAllowToSetDefaultValue.js");
const useIsShowMultipleSwitch_js_namespaceObject = require("../../../schema-settings/hooks/useIsShowMultipleSwitch.js");
const isPatternDisabled_js_namespaceObject = require("../../../schema-settings/isPatternDisabled.js");
const SchemaSettings_js_namespaceObject = require("../../../schema-settings/SchemaSettings.js");
const SchemaSettingsDataScope_js_namespaceObject = require("../../../schema-settings/SchemaSettingsDataScope.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const external_filter_index_js_namespaceObject = require("../filter/index.js");
const external_remote_select_index_js_namespaceObject = require("../remote-select/index.js");
const external_select_index_js_namespaceObject = require("../select/index.js");
const external_ReadPretty_js_namespaceObject = require("./ReadPretty.js");
const external_useServiceOptions_js_namespaceObject = require("./useServiceOptions.js");
var external_useServiceOptions_js_default = /*#__PURE__*/ __webpack_require__.n(external_useServiceOptions_js_namespaceObject);
const divWrap = (schema)=>({
        type: 'void',
        'x-component': 'div',
        properties: {
            [schema.name || (0, schema_namespaceObject.uid)()]: schema
        }
    });
const InternalAssociationSelect = (0, schema_namespaceObject.connect)((props)=>{
    const { fieldNames, objectValue = true } = props;
    const service = external_useServiceOptions_js_default()(props);
    (0, external_hooks_index_js_namespaceObject.useFieldTitle)();
    const normalizeValues = (0, external_react_namespaceObject.useCallback)((obj)=>{
        if (!objectValue && 'object' == typeof obj) return obj[fieldNames.value];
        return obj;
    }, [
        objectValue,
        fieldNames.value
    ]);
    const value = (0, external_react_namespaceObject.useMemo)(()=>{
        if (void 0 === props.value || null === props.value) return;
        if (Array.isArray(props.value)) return props.value.map(normalizeValues);
        return normalizeValues(props.value);
    }, [
        props.value,
        normalizeValues
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_remote_select_index_js_namespaceObject.RemoteSelect, {
        ...props,
        objectValue: objectValue,
        value: value,
        service: service
    });
}, (0, schema_namespaceObject.mapProps)({
    dataSource: 'options',
    loading: true
}, (props, field)=>({
        ...props,
        fieldNames: {
            ...external_select_index_js_namespaceObject.defaultFieldNames,
            ...props.fieldNames,
            ...field.componentProps.fieldNames
        },
        suffixIcon: (null == field ? void 0 : field['loading']) || (null == field ? void 0 : field['validating']) ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.LoadingOutlined, {}) : props.suffixIcon
    })), (0, schema_namespaceObject.mapReadPretty)(external_ReadPretty_js_namespaceObject.ReadPretty));
const AssociationSelect = InternalAssociationSelect;
AssociationSelect.Designer = function() {
    var _interfaceConfig_validateSchema, _collectionField_uiSchema, _field_componentProps_service_params, _field_componentProps_service, _field_componentProps, _fieldSchema_xcomponentprops, _field_componentProps_service_params1, _field_componentProps_service1, _field_componentProps1, _field_componentProps_fieldNames, _field_componentProps2;
    const { getCollectionFields, getInterface, getCollectionJoinField, getCollection, isTitleField } = (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 field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const tk = (0, index_js_namespaceObject.useFilterByTk)();
    const { dn, refresh, insertAdjacent } = (0, external_hooks_index_js_namespaceObject.useDesignable)();
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const IsShowMultipleSwitch = (0, useIsShowMultipleSwitch_js_namespaceObject.useIsShowMultipleSwitch)();
    const { isAllowToSetDefaultValue } = (0, useIsAllowToSetDefaultValue_js_namespaceObject.useIsAllowToSetDefaultValue)();
    const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
    const fieldComponentOptions = (0, external_hooks_index_js_namespaceObject.useFieldComponentOptions)();
    const isSubFormAssociationField = field.address.segments.includes('__form_grid');
    const interfaceConfig = getInterface(null == collectionField ? void 0 : collectionField.interface);
    const validateSchema = null == interfaceConfig ? void 0 : null === (_interfaceConfig_validateSchema = interfaceConfig['validateSchema']) || void 0 === _interfaceConfig_validateSchema ? void 0 : _interfaceConfig_validateSchema.call(interfaceConfig, fieldSchema);
    const originalTitle = null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema.title;
    const targetFields = (null == collectionField ? void 0 : collectionField.target) ? getCollectionFields(null == collectionField ? void 0 : collectionField.target) : [];
    const initialValue = {
        title: field.title === originalTitle ? void 0 : field.title
    };
    const sortFields = (0, external_collection_manager_index_js_namespaceObject.useSortFields)(null == collectionField ? void 0 : collectionField.target);
    const defaultSort = (null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : null === (_field_componentProps_service = _field_componentProps.service) || void 0 === _field_componentProps_service ? void 0 : null === (_field_componentProps_service_params = _field_componentProps_service.params) || void 0 === _field_componentProps_service_params ? void 0 : _field_componentProps_service_params.sort) || [];
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (field.readPretty !== fieldSchema['x-read-pretty']) field.readPretty = !!fieldSchema['x-read-pretty'];
    }, [
        fieldSchema['x-read-pretty']
    ]);
    const sort = null == defaultSort ? void 0 : defaultSort.map((item)=>item.startsWith('-') ? {
            field: item.substring(1),
            direction: 'desc'
        } : {
            field: item,
            direction: 'asc'
        });
    if (!field.readPretty) initialValue['required'] = field.required;
    const options = targetFields.filter((field)=>isTitleField(field)).map((field)=>{
        var _field_uiSchema;
        return {
            value: null == field ? void 0 : field.name,
            label: compile(null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || (null == field ? void 0 : field.name)
        };
    });
    let readOnlyMode = 'editable';
    if (true === fieldSchema['x-disabled']) readOnlyMode = 'readonly';
    if (true === fieldSchema['x-read-pretty']) readOnlyMode = 'read-pretty';
    const fieldSchemaWithoutRequired = external_lodash_default().omit(fieldSchema, 'required');
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(GeneralSchemaDesigner_js_namespaceObject.GeneralSchemaDesigner, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_items_index_js_namespaceObject.GeneralSchemaItems, {}),
            form && !(null == form ? void 0 : form.readPretty) && validateSchema && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
                title: t('Set validation rules'),
                components: {
                    ArrayCollapse: components_namespaceObject.ArrayCollapse,
                    FormLayout: components_namespaceObject.FormLayout
                },
                schema: {
                    type: 'object',
                    title: t('Set validation rules'),
                    properties: {
                        rules: {
                            type: 'array',
                            default: null == fieldSchema ? void 0 : fieldSchema['x-validator'],
                            'x-component': 'ArrayCollapse',
                            'x-decorator': 'FormItem',
                            'x-component-props': {
                                accordion: true
                            },
                            maxItems: 3,
                            items: {
                                type: 'object',
                                'x-component': 'ArrayCollapse.CollapsePanel',
                                'x-component-props': {
                                    header: '{{ t("Validation rule") }}'
                                },
                                properties: {
                                    index: {
                                        type: 'void',
                                        'x-component': 'ArrayCollapse.Index'
                                    },
                                    layout: {
                                        type: 'void',
                                        'x-component': 'FormLayout',
                                        'x-component-props': {
                                            labelStyle: {
                                                marginTop: '6px'
                                            },
                                            labelCol: 8,
                                            wrapperCol: 16
                                        },
                                        properties: {
                                            ...validateSchema,
                                            message: {
                                                type: 'string',
                                                title: '{{ t("Error message") }}',
                                                'x-decorator': 'FormItem',
                                                'x-component': 'Input.TextArea',
                                                'x-component-props': {
                                                    autoSize: {
                                                        minRows: 2,
                                                        maxRows: 2
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    remove: {
                                        type: 'void',
                                        'x-component': 'ArrayCollapse.Remove'
                                    },
                                    moveUp: {
                                        type: 'void',
                                        'x-component': 'ArrayCollapse.MoveUp'
                                    },
                                    moveDown: {
                                        type: 'void',
                                        'x-component': 'ArrayCollapse.MoveDown'
                                    }
                                }
                            },
                            properties: {
                                add: {
                                    type: 'void',
                                    title: '{{ t("Add validation rule") }}',
                                    'x-component': 'ArrayCollapse.Addition',
                                    'x-reactions': {
                                        dependencies: [
                                            'rules'
                                        ],
                                        fulfill: {
                                            state: {
                                                disabled: '{{$deps[0].length >= 3}}'
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                onSubmit: (v)=>{
                    var _collectionField_uiSchema;
                    const rules = [];
                    for (const rule of v.rules)rules.push(external_lodash_default().pickBy(rule, external_lodash_default().identity));
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    if ([
                        'percent'
                    ].includes(null == collectionField ? void 0 : collectionField.interface)) for (const rule of rules){
                        if (!!rule.maxValue || !!rule.minValue) rule['percentMode'] = true;
                        if (rule.percentFormat) rule['percentFormats'] = true;
                    }
                    const concatValidator = external_lodash_default().concat([], (null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema['x-validator']) || [], rules);
                    field.validator = concatValidator;
                    fieldSchema['x-validator'] = rules;
                    schema['x-validator'] = rules;
                    dn.emit('patch', {
                        schema
                    });
                    refresh();
                }
            }),
            isAllowToSetDefaultValue() && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
                title: t('Set default value'),
                components: {
                    ArrayCollapse: components_namespaceObject.ArrayCollapse,
                    FormLayout: components_namespaceObject.FormLayout
                },
                width: 800,
                schema: {
                    type: 'object',
                    title: t('Set default value'),
                    properties: {
                        default: {
                            ...fieldSchemaWithoutRequired || {},
                            'x-decorator': 'FormItem',
                            'x-component-props': {
                                ...fieldSchemaWithoutRequired['x-component-props'],
                                component: (null == collectionField ? void 0 : collectionField.target) ? 'AssociationSelect' : void 0,
                                service: {
                                    resource: null == collectionField ? void 0 : collectionField.target
                                }
                            },
                            name: 'default',
                            title: t('Default value'),
                            default: fieldSchema.default || (null == collectionField ? void 0 : collectionField.defaultValue),
                            'x-read-pretty': false,
                            'x-disabled': false
                        }
                    }
                },
                onSubmit: (v)=>{
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    if (field.value !== v.default) field.value = v.default;
                    fieldSchema.default = v.default;
                    schema.default = v.default;
                    dn.emit('patch', {
                        schema
                    });
                    refresh();
                }
            }),
            form && !isSubFormAssociationField && fieldComponentOptions && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSelectItem, {
                title: t('Field component'),
                options: fieldComponentOptions,
                value: fieldSchema['x-component'],
                onChange: (type)=>{
                    var _collectionField_uiSchema, _interfaceConfig_schemaInitialize;
                    const schema = {
                        name: null == collectionField ? void 0 : collectionField.name,
                        type: 'void',
                        required: fieldSchema['required'],
                        description: fieldSchema['description'],
                        default: fieldSchema['default'],
                        'x-decorator': 'FormItem',
                        'x-toolbar': 'FormItemSchemaToolbar',
                        'x-settings': 'fieldSettings:FormItem',
                        'x-component': type,
                        'x-validator': fieldSchema['x-validator'],
                        'x-collection-field': fieldSchema['x-collection-field'],
                        'x-decorator-props': fieldSchema['x-decorator-props'],
                        'x-component-props': {
                            ...null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema['x-component-props'],
                            ...fieldSchema['x-component-props']
                        }
                    };
                    null == interfaceConfig || null === (_interfaceConfig_schemaInitialize = interfaceConfig.schemaInitialize) || void 0 === _interfaceConfig_schemaInitialize || _interfaceConfig_schemaInitialize.call(interfaceConfig, schema, {
                        field: collectionField,
                        block: 'Form',
                        readPretty: field.readPretty,
                        action: tk ? 'get' : null,
                        targetCollection: getCollection(null == collectionField ? void 0 : collectionField.target)
                    });
                    if ('CollectionField' === type) schema['type'] = 'string';
                    insertAdjacent('beforeBegin', divWrap(schema), {
                        onSuccess: ()=>{
                            dn.remove(null, {
                                removeParentsIfNoChildren: true,
                                breakRemoveOn: {
                                    'x-component': 'Grid'
                                }
                            });
                        }
                    });
                }
            }),
            IsShowMultipleSwitch() ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSwitchItem, {
                title: t('Allow multiple'),
                checked: (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 || fieldSchema['x-component-props'].multiple,
                onChange: (value)=>{
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                    field.componentProps = field.componentProps || {};
                    fieldSchema['x-component-props'].multiple = value;
                    field.componentProps.multiple = value;
                    schema['x-component-props'] = fieldSchema['x-component-props'];
                    dn.emit('patch', {
                        schema
                    });
                    refresh();
                }
            }, "multiple") : null,
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsDataScope_js_namespaceObject.SchemaSettingsDataScope, {
                collectionName: null == collectionField ? void 0 : collectionField.target,
                defaultFilter: (null === (_field_componentProps1 = field.componentProps) || void 0 === _field_componentProps1 ? void 0 : null === (_field_componentProps_service1 = _field_componentProps1.service) || void 0 === _field_componentProps_service1 ? void 0 : null === (_field_componentProps_service_params1 = _field_componentProps_service1.params) || void 0 === _field_componentProps_service_params1 ? void 0 : _field_componentProps_service_params1.filter) || {},
                form: form,
                onSubmit: (param)=>{
                    let { filter } = param;
                    filter = (0, external_filter_index_js_namespaceObject.removeNullCondition)(filter);
                    external_lodash_default().set(field.componentProps, 'service.params.filter', filter);
                    fieldSchema['x-component-props'] = field.componentProps;
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-component-props': field.componentProps
                        }
                    });
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_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,
                                                '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);
                    external_lodash_default().set(field.componentProps, 'service.params.sort', sortArr);
                    fieldSchema['x-component-props'] = field.componentProps;
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-component-props': field.componentProps
                        }
                    });
                }
            }),
            form && !(null == form ? void 0 : form.readPretty) && !(0, isPatternDisabled_js_namespaceObject.isPatternDisabled)(fieldSchema) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSelectItem, {
                title: t('Pattern'),
                options: [
                    {
                        label: t('Editable'),
                        value: 'editable'
                    },
                    {
                        label: t('Readonly'),
                        value: 'readonly'
                    },
                    {
                        label: t('Easy-reading'),
                        value: 'read-pretty'
                    }
                ],
                value: readOnlyMode,
                onChange: (v)=>{
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    switch(v){
                        case 'readonly':
                            fieldSchema['x-read-pretty'] = false;
                            fieldSchema['x-disabled'] = true;
                            schema['x-read-pretty'] = false;
                            schema['x-disabled'] = true;
                            field.readPretty = false;
                            field.disabled = true;
                            break;
                        case 'read-pretty':
                            fieldSchema['x-read-pretty'] = true;
                            fieldSchema['x-disabled'] = false;
                            schema['x-read-pretty'] = true;
                            schema['x-disabled'] = false;
                            field.readPretty = true;
                            break;
                        default:
                            fieldSchema['x-read-pretty'] = false;
                            fieldSchema['x-disabled'] = false;
                            schema['x-read-pretty'] = false;
                            schema['x-disabled'] = false;
                            field.readPretty = false;
                            field.disabled = false;
                            break;
                    }
                    dn.emit('patch', {
                        schema
                    });
                    dn.refresh();
                }
            }, "pattern"),
            (null == collectionField ? void 0 : collectionField.target) && [
                'CollectionField',
                'AssociationSelect'
            ].includes(fieldSchema['x-component']) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSelectItem, {
                title: t('Title field'),
                options: options,
                value: null == field ? void 0 : null === (_field_componentProps2 = field.componentProps) || void 0 === _field_componentProps2 ? void 0 : null === (_field_componentProps_fieldNames = _field_componentProps2.fieldNames) || void 0 === _field_componentProps_fieldNames ? void 0 : _field_componentProps_fieldNames.label,
                onChange: (label)=>{
                    var _collectionField_uiSchema_xcomponentprops, _collectionField_uiSchema;
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    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'],
                        ...field.componentProps.fieldNames,
                        label
                    };
                    field.componentProps.fieldNames = fieldNames;
                    fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                    fieldSchema['x-component-props']['fieldNames'] = fieldNames;
                    schema['x-component-props'] = fieldSchema['x-component-props'];
                    dn.emit('patch', {
                        schema
                    });
                    dn.refresh();
                }
            }, "title-field"),
            collectionField && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsDivider, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsRemove, {
                removeParentsIfNoChildren: true,
                confirm: {
                    title: t('Delete field')
                },
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            }, "remove")
        ]
    });
};
AssociationSelect.FilterDesigner = function() {
    var _interfaceConfig_validateSchema, _collectionField_uiSchema, _field_componentProps_service_params, _field_componentProps_service, _field_componentProps, _collectionField_uiSchema1, _field_componentProps_service_params1, _field_componentProps_service1, _field_componentProps1, _field_componentProps_fieldNames, _field_componentProps2;
    const { getCollectionFields, getInterface, getCollectionJoinField } = (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 field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { dn, refresh } = (0, external_hooks_index_js_namespaceObject.useDesignable)();
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
    const interfaceConfig = getInterface(null == collectionField ? void 0 : collectionField.interface);
    const validateSchema = null == interfaceConfig ? void 0 : null === (_interfaceConfig_validateSchema = interfaceConfig['validateSchema']) || void 0 === _interfaceConfig_validateSchema ? void 0 : _interfaceConfig_validateSchema.call(interfaceConfig, fieldSchema);
    const originalTitle = null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema.title;
    const targetFields = (null == collectionField ? void 0 : collectionField.target) ? getCollectionFields(null == collectionField ? void 0 : collectionField.target) : [];
    const initialValue = {
        title: field.title === originalTitle ? void 0 : field.title
    };
    const sortFields = (0, external_collection_manager_index_js_namespaceObject.useSortFields)(null == collectionField ? void 0 : collectionField.target);
    const defaultSort = (null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : null === (_field_componentProps_service = _field_componentProps.service) || void 0 === _field_componentProps_service ? void 0 : null === (_field_componentProps_service_params = _field_componentProps_service.params) || void 0 === _field_componentProps_service_params ? void 0 : _field_componentProps_service_params.sort) || [];
    const sort = null == defaultSort ? void 0 : defaultSort.map((item)=>item.startsWith('-') ? {
            field: item.substring(1),
            direction: 'desc'
        } : {
            field: item,
            direction: 'asc'
        });
    if (!field.readPretty) initialValue['required'] = field.required;
    const options = targetFields.filter((field)=>!(null == field ? void 0 : field.target) && 'boolean' !== field.type).map((field)=>{
        var _field_uiSchema;
        return {
            value: null == field ? void 0 : field.name,
            label: compile(null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || (null == field ? void 0 : field.name)
        };
    });
    if (true === fieldSchema['x-disabled']) 'readonly';
    if (true === fieldSchema['x-read-pretty']) 'read-pretty';
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(GeneralSchemaDesigner_js_namespaceObject.GeneralSchemaDesigner, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_items_index_js_namespaceObject.GeneralSchemaItems, {
                required: false
            }),
            form && !(null == form ? void 0 : form.readPretty) && validateSchema && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
                title: t('Set validation rules'),
                components: {
                    ArrayCollapse: components_namespaceObject.ArrayCollapse,
                    FormLayout: components_namespaceObject.FormLayout
                },
                schema: {
                    type: 'object',
                    title: t('Set validation rules'),
                    properties: {
                        rules: {
                            type: 'array',
                            default: null == fieldSchema ? void 0 : fieldSchema['x-validator'],
                            'x-component': 'ArrayCollapse',
                            'x-decorator': 'FormItem',
                            'x-component-props': {
                                accordion: true
                            },
                            maxItems: 3,
                            items: {
                                type: 'object',
                                'x-component': 'ArrayCollapse.CollapsePanel',
                                'x-component-props': {
                                    header: '{{ t("Validation rule") }}'
                                },
                                properties: {
                                    index: {
                                        type: 'void',
                                        'x-component': 'ArrayCollapse.Index'
                                    },
                                    layout: {
                                        type: 'void',
                                        'x-component': 'FormLayout',
                                        'x-component-props': {
                                            labelStyle: {
                                                marginTop: '6px'
                                            },
                                            labelCol: 8,
                                            wrapperCol: 16
                                        },
                                        properties: {
                                            ...validateSchema,
                                            message: {
                                                type: 'string',
                                                title: '{{ t("Error message") }}',
                                                'x-decorator': 'FormItem',
                                                'x-component': 'Input.TextArea',
                                                'x-component-props': {
                                                    autoSize: {
                                                        minRows: 2,
                                                        maxRows: 2
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    remove: {
                                        type: 'void',
                                        'x-component': 'ArrayCollapse.Remove'
                                    },
                                    moveUp: {
                                        type: 'void',
                                        'x-component': 'ArrayCollapse.MoveUp'
                                    },
                                    moveDown: {
                                        type: 'void',
                                        'x-component': 'ArrayCollapse.MoveDown'
                                    }
                                }
                            },
                            properties: {
                                add: {
                                    type: 'void',
                                    title: '{{ t("Add validation rule") }}',
                                    'x-component': 'ArrayCollapse.Addition',
                                    'x-reactions': {
                                        dependencies: [
                                            'rules'
                                        ],
                                        fulfill: {
                                            state: {
                                                disabled: '{{$deps[0].length >= 3}}'
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                onSubmit: (v)=>{
                    var _collectionField_uiSchema;
                    const rules = [];
                    for (const rule of v.rules)rules.push(external_lodash_default().pickBy(rule, external_lodash_default().identity));
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    if ([
                        'percent'
                    ].includes(null == collectionField ? void 0 : collectionField.interface)) for (const rule of rules){
                        if (!!rule.maxValue || !!rule.minValue) rule['percentMode'] = true;
                        if (rule.percentFormat) rule['percentFormats'] = true;
                    }
                    const concatValidator = external_lodash_default().concat([], (null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema['x-validator']) || [], rules);
                    field.validator = concatValidator;
                    fieldSchema['x-validator'] = rules;
                    schema['x-validator'] = rules;
                    dn.emit('patch', {
                        schema
                    });
                    refresh();
                }
            }),
            form && !(null == form ? void 0 : form.readPretty) && (null == collectionField ? void 0 : null === (_collectionField_uiSchema1 = collectionField.uiSchema) || void 0 === _collectionField_uiSchema1 ? void 0 : _collectionField_uiSchema1.type) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
                title: t('Set default value'),
                components: {
                    ArrayCollapse: components_namespaceObject.ArrayCollapse,
                    FormLayout: components_namespaceObject.FormLayout
                },
                schema: {
                    type: 'object',
                    title: t('Set default value'),
                    properties: {
                        default: {
                            ...external_lodash_default().omit(null == collectionField ? void 0 : collectionField.uiSchema, 'required'),
                            name: 'default',
                            title: t('Default value'),
                            'x-decorator': 'FormItem',
                            default: fieldSchema.default || (null == collectionField ? void 0 : collectionField.defaultValue)
                        }
                    }
                },
                onSubmit: (v)=>{
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    if (field.value !== v.default) field.value = v.default;
                    fieldSchema.default = v.default;
                    schema.default = v.default;
                    dn.emit('patch', {
                        schema
                    });
                    refresh();
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettingsDataScope_js_namespaceObject.SchemaSettingsDataScope, {
                collectionName: null == collectionField ? void 0 : collectionField.target,
                defaultFilter: (null === (_field_componentProps1 = field.componentProps) || void 0 === _field_componentProps1 ? void 0 : null === (_field_componentProps_service1 = _field_componentProps1.service) || void 0 === _field_componentProps_service1 ? void 0 : null === (_field_componentProps_service_params1 = _field_componentProps_service1.params) || void 0 === _field_componentProps_service_params1 ? void 0 : _field_componentProps_service_params1.filter) || {},
                form: form,
                onSubmit: (param)=>{
                    let { filter } = param;
                    filter = (0, external_filter_index_js_namespaceObject.removeNullCondition)(filter);
                    external_lodash_default().set(field.componentProps, 'service.params.filter', filter);
                    fieldSchema['x-component-props'] = field.componentProps;
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-component-props': field.componentProps
                        }
                    });
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_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,
                                                '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);
                    external_lodash_default().set(field.componentProps, 'service.params.sort', sortArr);
                    fieldSchema['x-component-props'] = field.componentProps;
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-component-props': field.componentProps
                        }
                    });
                }
            }),
            (null == collectionField ? void 0 : collectionField.target) && [
                'CollectionField',
                'AssociationSelect'
            ].includes(fieldSchema['x-component']) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSelectItem, {
                title: t('Title field'),
                options: options,
                value: null == field ? void 0 : null === (_field_componentProps2 = field.componentProps) || void 0 === _field_componentProps2 ? void 0 : null === (_field_componentProps_fieldNames = _field_componentProps2.fieldNames) || void 0 === _field_componentProps_fieldNames ? void 0 : _field_componentProps_fieldNames.label,
                onChange: (label)=>{
                    var _collectionField_uiSchema_xcomponentprops, _collectionField_uiSchema;
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    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'],
                        ...field.componentProps.fieldNames,
                        label
                    };
                    field.componentProps.fieldNames = fieldNames;
                    fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                    fieldSchema['x-component-props']['fieldNames'] = fieldNames;
                    schema['x-component-props'] = fieldSchema['x-component-props'];
                    dn.emit('patch', {
                        schema
                    });
                    dn.refresh();
                }
            }, "title-field"),
            collectionField && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsDivider, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsRemove, {
                removeParentsIfNoChildren: true,
                confirm: {
                    title: t('Delete field')
                },
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            }, "remove")
        ]
    });
};
const AssociationSelect_rslib_entry_ = AssociationSelect;
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
});
