"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__, {
    recordPickerComponentFieldSettings: ()=>recordPickerComponentFieldSettings,
    titleField: ()=>titleField
});
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 titleField = {
    name: 'titleField',
    type: 'select',
    useComponentProps () {
        var _field_componentProps, _fieldSchema_xcomponentprops, _uiSchema_xcomponentprops;
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const { uiSchema, fieldSchema: tableColumnSchema, collectionField: tableColumnField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const options = (0, FormItem_Settings_js_namespaceObject.useTitleFieldOptions)();
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const targetCollectionField = (0, index_js_namespaceObject.useCollectionField)();
        const collectionField = tableColumnField || targetCollectionField;
        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        const fieldNames = (null == field ? void 0 : null == (_field_componentProps = field.componentProps) ? void 0 : _field_componentProps.fieldNames) || (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops['fieldNames']) || (null == uiSchema ? void 0 : null == (_uiSchema_xcomponentprops = uiSchema['x-component-props']) ? void 0 : _uiSchema_xcomponentprops['fieldNames']);
        return {
            title: t('Title field'),
            options,
            value: null == fieldNames ? void 0 : 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 : null == (_collectionField_uiSchema_xcomponentprops = _collectionField_uiSchema['x-component-props']) ? void 0 : _collectionField_uiSchema_xcomponentprops['fieldNames'],
                    ...field.componentProps.fieldNames,
                    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.fieldNames = fieldSchema['x-component-props'].fieldNames;
                dn.emit('patch', {
                    schema
                });
                dn.refresh();
            }
        };
    }
};
const allowMultiple = {
    name: 'allowMultiple',
    type: 'switch',
    useVisible () {
        const isFieldReadPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
        const collectionField = (0, index_js_namespaceObject.useCollectionField)();
        return !isFieldReadPretty && [
            'hasMany',
            'belongsToMany'
        ].includes(null == collectionField ? void 0 : collectionField.type);
    },
    useComponentProps () {
        var _fieldSchema_xcomponentprops;
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
        const { dn, refresh } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        return {
            title: t('Allow multiple'),
            checked: (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 ? true : 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();
            }
        };
    }
};
const fieldComponent = {
    name: 'fieldComponent',
    type: 'select',
    useComponentProps () {
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const isAddNewForm = (0, external_schema_component_index_js_namespaceObject.useIsAddNewForm)();
        const fieldComponentName = (0, useFieldComponentName_js_namespaceObject.useFieldComponentName)();
        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 { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        return {
            title: t('Field component'),
            options: fieldModeOptions,
            value: fieldComponentName,
            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();
            }
        };
    }
};
const recordPickerComponentFieldSettings = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'fieldSettings:component:Picker',
    items: [
        fieldComponent,
        {
            name: 'popupSize',
            type: 'select',
            useVisible () {
                const isFieldReadPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                return !isFieldReadPretty;
            },
            useComponentProps () {
                var _fieldSchema_xcomponentprops, _fieldSchema_xcomponentprops1;
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const field = (0, schema_namespaceObject.useField)();
                const { fieldSchema: tableColumnSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                const schema = (0, schema_namespaceObject.useFieldSchema)();
                const fieldSchema = tableColumnSchema || schema;
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                var _fieldSchema_xcomponentprops_openSize;
                return {
                    title: t('Popup size'),
                    options: [
                        {
                            label: t('Small'),
                            value: 'small'
                        },
                        {
                            label: t('Middle'),
                            value: 'middle'
                        },
                        {
                            label: t('Large'),
                            value: 'large'
                        }
                    ],
                    value: null != (_fieldSchema_xcomponentprops_openSize = null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops['openSize']) ? _fieldSchema_xcomponentprops_openSize : (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops1['openMode']) == 'modal' ? 'large' : 'middle',
                    onChange: (value)=>{
                        field.componentProps.openSize = value;
                        fieldSchema['x-component-props'] = {
                            ...fieldSchema['x-component-props'],
                            openSize: value
                        };
                        dn.emit('patch', {
                            schema: {
                                'x-uid': fieldSchema['x-uid'],
                                'x-component-props': fieldSchema['x-component-props']
                            }
                        });
                        dn.refresh();
                    }
                };
            }
        },
        allowMultiple,
        titleField
    ]
});
exports.recordPickerComponentFieldSettings = __webpack_exports__.recordPickerComponentFieldSettings;
exports.titleField = __webpack_exports__.titleField;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
    "recordPickerComponentFieldSettings",
    "titleField"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
    value: true
});
