"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (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__, {
    CustomTitleComponentFieldSettings: ()=>CustomTitleComponentFieldSettings
});
const schema_namespaceObject = require("@tachybase/schema");
const external_react_i18next_namespaceObject = require("react-i18next");
const SchemaSettings_js_namespaceObject = require("../../../../application/schema-settings/SchemaSettings.js");
const useFieldComponentName_js_namespaceObject = require("../../../../common/useFieldComponentName.js");
const index_js_namespaceObject = require("../../../../data-source/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 useIsShowMultipleSwitch_js_namespaceObject = require("../../../../schema-settings/hooks/useIsShowMultipleSwitch.js");
const selectComponentFieldSettings_js_namespaceObject = require("../Select/selectComponentFieldSettings.js");
const CustomTitleComponentFieldSettings = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'fieldSettings:component:CustomTitle',
    items: [
        {
            name: 'fieldComponent',
            type: 'select',
            useComponentProps () {
                var _collectionInterface_componentOptions_filter, _collectionInterface_componentOptions;
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const field = (0, schema_namespaceObject.useField)();
                const collectionFieldCurrent = (0, index_js_namespaceObject.useCollectionField)();
                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)();
                const isSelect = [
                    'select',
                    'multipleSelect'
                ].includes(null == collectionFieldCurrent ? void 0 : collectionFieldCurrent.interface);
                const optionsMuiltipleSelect = [
                    {
                        label: t('Select'),
                        value: 'Select'
                    },
                    {
                        label: t('Radio group'),
                        value: 'Radio group'
                    },
                    {
                        label: t('Custom Title'),
                        value: 'CustomTitle'
                    }
                ];
                if ((null == collectionFieldCurrent ? void 0 : collectionFieldCurrent.interface) === 'multipleSelect') {
                    const index = optionsMuiltipleSelect.findIndex((item)=>{
                        if ('Select' === item.value) item.value = 'multiple';
                        return 'Radio group' === item.value;
                    });
                    optionsMuiltipleSelect.splice(index, 1);
                }
                const dm = (0, index_js_namespaceObject.useDataSourceManager)();
                const collectionInterface = dm.collectionFieldInterfaceManager.getFieldInterface(null == collectionField ? void 0 : collectionField.interface);
                const compile = (0, external_schema_component_index_js_namespaceObject.useCompile)();
                const componentOptions = isSelect ? optionsMuiltipleSelect : fieldModeOptions;
                null == collectionInterface || null == (_collectionInterface_componentOptions = collectionInterface.componentOptions) || null == (_collectionInterface_componentOptions_filter = _collectionInterface_componentOptions.filter((item)=>!item.useVisible || item.useVisible())) || _collectionInterface_componentOptions_filter.forEach((item)=>{
                    if (!(null == componentOptions ? void 0 : componentOptions.find((modeItem)=>modeItem.value === item.value))) null == componentOptions || componentOptions.push({
                        label: compile(item.label),
                        value: item.value
                    });
                });
                return {
                    title: t('Field component'),
                    options: componentOptions,
                    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) || _field_setInitialValue.call(field, null);
                            null == field || null == (_field_setValue = field.setValue) || _field_setValue.call(field, null);
                        }
                        dn.emit('patch', {
                            schema
                        });
                        dn.refresh();
                    }
                };
            },
            useVisible () {
                const fieldMode = (0, useFieldComponentName_js_namespaceObject.useFieldComponentName)();
                return 'CustomTitle' === fieldMode;
            }
        },
        {
            ...selectComponentFieldSettings_js_namespaceObject.CustomTitle,
            useVisible () {
                const fieldMode = (0, useFieldComponentName_js_namespaceObject.useFieldComponentName)();
                return 'CustomTitle' === fieldMode;
            }
        },
        {
            ...selectComponentFieldSettings_js_namespaceObject.setTheDataScope,
            useVisible () {
                const isSelectFieldMode = (0, FormItem_Settings_js_namespaceObject.useIsSelectFieldMode)();
                const isFieldReadPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                return isSelectFieldMode && !isFieldReadPretty;
            }
        },
        {
            ...selectComponentFieldSettings_js_namespaceObject.setDefaultSortingRules,
            useComponentProps () {
                const { fieldSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                return {
                    fieldSchema
                };
            },
            useVisible () {
                const isSelectFieldMode = (0, FormItem_Settings_js_namespaceObject.useIsSelectFieldMode)();
                const isFieldReadPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                return isSelectFieldMode && !isFieldReadPretty;
            }
        },
        {
            ...selectComponentFieldSettings_js_namespaceObject.quickCreate,
            useVisible () {
                const isAssociationField = (0, FormItem_Settings_js_namespaceObject.useIsAssociationField)();
                const readPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                const { fieldSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                return isAssociationField && !fieldSchema && !readPretty;
            }
        },
        {
            ...selectComponentFieldSettings_js_namespaceObject.allowMultiple,
            useVisible () {
                const isAssociationField = (0, FormItem_Settings_js_namespaceObject.useIsAssociationField)();
                const IsShowMultipleSwitch = (0, useIsShowMultipleSwitch_js_namespaceObject.useIsShowMultipleSwitch)();
                return isAssociationField && IsShowMultipleSwitch();
            }
        },
        {
            ...selectComponentFieldSettings_js_namespaceObject.enableLink,
            useVisible () {
                const readPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                return (0, FormItem_Settings_js_namespaceObject.useIsAssociationField)() && readPretty;
            }
        }
    ]
});
exports.CustomTitleComponentFieldSettings = __webpack_exports__.CustomTitleComponentFieldSettings;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
    "CustomTitleComponentFieldSettings"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
    value: true
});
