import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_settings_index_mjs__ from "../../../application/schema-settings/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__ from "../../../record-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__ from "../../../schema-settings/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettingsDataScope_mjs__ from "../../../schema-settings/SchemaSettingsDataScope.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__variables_index_mjs__ from "../../../variables/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../../hooks/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__filter_index_mjs__ from "../filter/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__FormItem_Settings_mjs__ from "./FormItem.Settings.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__ from "./SchemaSettingOptions.mjs";
const filterFormItemSettings = new __WEBPACK_EXTERNAL_MODULE__application_schema_settings_index_mjs__.SchemaSettings({
    name: 'FilterFormItemSettings',
    items: [
        {
            name: 'editFieldTitle',
            Component: __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__.EditTitle
        },
        {
            name: 'editDescription',
            Component: __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__.EditDescription
        },
        {
            name: 'editTooltip',
            Component: __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__.EditTooltip
        },
        {
            name: 'validationRules',
            Component: __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__.EditValidationRules
        },
        {
            name: 'setDataScope',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettingsDataScope_mjs__.SchemaSettingsDataScope,
            useVisible () {
                const isSelectFieldMode = (0, __WEBPACK_EXTERNAL_MODULE__FormItem_Settings_mjs__.useIsSelectFieldMode)();
                const isFormReadPretty = (0, __WEBPACK_EXTERNAL_MODULE__FormItem_Settings_mjs__.useIsFormReadPretty)();
                return isSelectFieldMode && !isFormReadPretty;
            },
            useComponentProps () {
                var _fieldSchema_xcomponentprops_service_params, _fieldSchema_xcomponentprops_service, _fieldSchema_xcomponentprops;
                const { getCollectionJoinField, getAllCollectionsInheritChain } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
                const { getField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const { form } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useFormBlockContext)();
                const record = (0, __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.useRecord)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
                const variables = (0, __WEBPACK_EXTERNAL_MODULE__variables_index_mjs__.useVariables)();
                const localVariables = (0, __WEBPACK_EXTERNAL_MODULE__variables_index_mjs__.useLocalVariables)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.VariableInput, {
                            ...props,
                            form: form,
                            collectionField: props.collectionField,
                            record: record,
                            shouldChange: (0, __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.getShouldChange)({
                                collectionField: props.collectionField,
                                variables,
                                localVariables,
                                getAllCollectionsInheritChain
                            })
                        }),
                    onSubmit: (param)=>{
                        let { filter } = param;
                        filter = (0, __WEBPACK_EXTERNAL_MODULE__filter_index_mjs__.removeNullCondition)(filter);
                        __WEBPACK_EXTERNAL_MODULE_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
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'fieldMode',
            Component: __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__.EditComponent
        },
        {
            name: 'operator',
            Component: __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__.EditOperator
        },
        {
            name: 'titleField',
            Component: __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__.EditTitleField
        },
        {
            name: 'divider',
            type: 'divider',
            useVisible () {
                const { getCollectionJoinField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
                const { getField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
                return !!collectionField;
            }
        },
        {
            name: 'remove',
            type: 'remove',
            useComponentProps () {
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                return {
                    removeParentsIfNoChildren: true,
                    confirm: {
                        title: t('Delete field')
                    },
                    breakRemoveOn: {
                        'x-component': 'Grid'
                    }
                };
            }
        }
    ]
});
export { filterFormItemSettings };
