"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__, {
    FilterItemCustomSettings: ()=>FilterItemCustomSettings
});
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 external_schema_component_index_js_namespaceObject = require("../../../../schema-component/index.js");
const external_schema_settings_index_js_namespaceObject = require("../../../../schema-settings/index.js");
const EditFormulaTitleField_js_namespaceObject = require("../../../../schema-settings/EditFormulaTitleField.js");
const SchemaSettingComponent_js_namespaceObject = require("../../../../schema-settings/SchemaSettingComponent.js");
const FilterItemCustomSettings = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'fieldSettings:FilterFormCustomSettings',
    items: [
        {
            name: 'editFieldTitle',
            type: 'modal',
            useComponentProps () {
                var _collectionField_uiSchema;
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const field = (0, schema_namespaceObject.useField)();
                const { getCollectionJoinField } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
                const { getField } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
                return {
                    title: t('Edit field title'),
                    schema: {
                        type: 'object',
                        title: t('Edit field title'),
                        properties: {
                            title: {
                                title: t('Field title'),
                                default: null == field ? void 0 : field.title,
                                description: "".concat(t('Original field title: ')).concat(null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema.title),
                                'x-decorator': 'FormItem',
                                'x-component': 'Input',
                                'x-component-props': {}
                            }
                        }
                    },
                    onSubmit (param) {
                        let { title } = param;
                        if (title) {
                            field.title = title;
                            fieldSchema.title = title;
                            dn.emit('patch', {
                                schema: {
                                    'x-uid': fieldSchema['x-uid'],
                                    title: fieldSchema.title
                                }
                            });
                        }
                        dn.refresh();
                    }
                };
            }
        },
        {
            name: 'editDescription',
            type: 'modal',
            useComponentProps () {
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                const field = (0, schema_namespaceObject.useField)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                return {
                    title: t('Edit description'),
                    schema: {
                        type: 'object',
                        title: t('Edit description'),
                        properties: {
                            description: {
                                default: null == field ? void 0 : field.description,
                                'x-decorator': 'FormItem',
                                'x-component': 'Input.TextArea',
                                'x-component-props': {}
                            }
                        }
                    },
                    onSubmit (param) {
                        let { description } = param;
                        field.description = description;
                        fieldSchema.description = description;
                        dn.emit('patch', {
                            schema: {
                                'x-uid': fieldSchema['x-uid'],
                                description: fieldSchema.description
                            }
                        });
                        dn.refresh();
                    }
                };
            }
        },
        {
            name: 'setTheDataScope',
            Component: external_schema_settings_index_js_namespaceObject.SchemaSettingsDataScope,
            useComponentProps () {
                var _fieldSchema_xcomponentprops_params, _fieldSchema_xcomponentprops;
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const { form } = (0, index_js_namespaceObject.useFormBlockContext)();
                const field = (0, schema_namespaceObject.useField)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                const fieldName = fieldSchema['name'];
                const name = fieldName.includes('__custom') ? fieldSchema['collectionName'] : fieldName;
                return {
                    collectionName: name,
                    defaultFilter: (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_params = _fieldSchema_xcomponentprops.params) || void 0 === _fieldSchema_xcomponentprops_params ? void 0 : _fieldSchema_xcomponentprops_params.filter) || {},
                    form: form,
                    onSubmit: (param)=>{
                        let { filter } = param;
                        var _field_componentProps;
                        external_lodash_default().set(field.componentProps, 'params', {
                            ...null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.params,
                            filter
                        });
                        fieldSchema['x-component-props']['params'] = field.componentProps.params;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-component-props': fieldSchema['x-component-props']
                            }
                        });
                    }
                };
            },
            useVisible () {
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                return null == fieldSchema ? void 0 : fieldSchema['collectionName'];
            }
        },
        {
            name: 'fieldCollection',
            Component: external_schema_settings_index_js_namespaceObject.SchemaSettingCollection,
            useVisible () {
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const component = fieldSchema['x-component'];
                return 'Select' === component || 'AutoComplete' === component;
            }
        },
        {
            name: 'fieldComponent',
            Component: SchemaSettingComponent_js_namespaceObject.SchemaSettingComponent,
            useVisible () {
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const component = fieldSchema['x-component'];
                const items = [
                    'Select',
                    'AutoComplete',
                    'Radio.Group',
                    'Checkbox.Group'
                ];
                return items.includes(component);
            }
        },
        {
            name: 'titleField',
            type: 'select',
            useComponentProps () {
                var _fieldSchema_xcomponentprops_fieldNames, _fieldSchema_xcomponentprops;
                const { getCollectionFields, getCollectionJoinField } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
                const { getField } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                const field = (0, schema_namespaceObject.useField)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                const compile = (0, external_schema_component_index_js_namespaceObject.useCompile)();
                const collectionManage = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
                var _fieldSchema_name;
                const isCustomFilterItem = (null !== (_fieldSchema_name = null == fieldSchema ? void 0 : fieldSchema.name) && void 0 !== _fieldSchema_name ? _fieldSchema_name : '').startsWith('__custom.');
                const collectionManageField = isCustomFilterItem ? collectionManage.collections.filter((value)=>value.name === fieldSchema['x-decorator-props'])[0] : {};
                const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
                let targetFields = [];
                if (collectionField) {
                    var _getCollectionFields;
                    targetFields = (null == collectionField ? void 0 : collectionField.target) ? getCollectionFields(null == collectionField ? void 0 : collectionField.target) : null !== (_getCollectionFields = getCollectionFields(null == collectionField ? void 0 : collectionField.targetCollection)) && void 0 !== _getCollectionFields ? _getCollectionFields : [];
                } else if (collectionManageField) targetFields = collectionManageField['fields'];
                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)
                    };
                });
                return {
                    title: t('Title field'),
                    options,
                    value: (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_fieldNames = _fieldSchema_xcomponentprops['fieldNames']) || void 0 === _fieldSchema_xcomponentprops_fieldNames ? void 0 : _fieldSchema_xcomponentprops_fieldNames.label) || 'id',
                    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
                        };
                        if (isCustomFilterItem) fieldNames['value'] = label;
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props']['fieldNames'] = fieldNames;
                        schema['x-component-props'] = fieldSchema['x-component-props'];
                        field.componentProps = fieldSchema['x-component-props'];
                        dn.emit('patch', {
                            schema
                        });
                        dn.refresh();
                    }
                };
            },
            useVisible () {
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const component = fieldSchema['x-component'];
                return 'Select' === component || 'AutoComplete' === component;
            }
        },
        {
            name: 'EditFormulaTitleField',
            Component: EditFormulaTitleField_js_namespaceObject.EditFormulaTitleField,
            useVisible () {
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const component = fieldSchema['x-component'];
                return 'Select' === component || 'AutoComplete' === component;
            }
        },
        {
            name: 'EditCustomDefaultValue',
            type: 'modal',
            useComponentProps () {
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                const field = (0, schema_namespaceObject.useField)();
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                const title = fieldSchema.title;
                return {
                    title: t('Set default value'),
                    schema: {
                        type: 'void',
                        title: t('Set default value'),
                        properties: {
                            default: {
                                title,
                                'x-decorator': 'FormItem',
                                'x-component': external_schema_settings_index_js_namespaceObject.FilterCustomVariableInput,
                                'x-component-props': {
                                    fieldSchema
                                }
                            }
                        }
                    },
                    onSubmit (param) {
                        let { default: { value = null } } = param;
                        field.setValue(value);
                        fieldSchema['default'] = value;
                        fieldSchema['x-component-props']['defaultValue'] = value;
                        dn.emit('patch', {
                            schema: {
                                'x-uid': fieldSchema['x-uid'],
                                ['x-component-props']: fieldSchema['x-component-props'],
                                default: fieldSchema.default
                            }
                        });
                        dn.refresh();
                    }
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'delete',
            type: 'remove'
        }
    ]
});
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
});
