"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__, {
    allowMultiple: ()=>allowMultiple,
    fieldComponent: ()=>fieldComponent,
    quickCreate: ()=>quickCreate,
    setDefaultSortingRules: ()=>setDefaultSortingRules,
    titleField: ()=>titleField,
    CustomTitle: ()=>CustomTitle,
    enableLink: ()=>enableLink,
    selectComponentFieldSettings: ()=>selectComponentFieldSettings,
    setTheDataScope: ()=>setTheDataScope
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
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 useFieldComponentName_js_namespaceObject = require("../../../../common/useFieldComponentName.js");
const external_data_source_index_js_namespaceObject = require("../../../../data-source/index.js");
const external_record_provider_index_js_namespaceObject = require("../../../../record-provider/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 external_schema_settings_index_js_namespaceObject = require("../../../../schema-settings/index.js");
const useIsShowMultipleSwitch_js_namespaceObject = require("../../../../schema-settings/hooks/useIsShowMultipleSwitch.js");
const SchemaSettingsDataScope_js_namespaceObject = require("../../../../schema-settings/SchemaSettingsDataScope.js");
const SchemaSettingsSortingRule_js_namespaceObject = require("../../../../schema-settings/SchemaSettingsSortingRule.js");
const external_variables_index_js_namespaceObject = require("../../../../variables/index.js");
const enableLink = {
    name: 'enableLink',
    type: 'switch',
    useVisible () {
        const field = (0, schema_namespaceObject.useField)();
        return field.readPretty;
    },
    useComponentProps () {
        var _fieldSchema_xcomponentprops;
        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)();
        return {
            title: t('Enable link'),
            checked: (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.enableLink) !== false,
            onChange (flag) {
                fieldSchema['x-component-props'] = {
                    ...null == fieldSchema ? void 0 : fieldSchema['x-component-props'],
                    enableLink: flag
                };
                field.componentProps['enableLink'] = flag;
                dn.emit('patch', {
                    schema: {
                        'x-uid': fieldSchema['x-uid'],
                        'x-component-props': {
                            ...null == fieldSchema ? void 0 : fieldSchema['x-component-props']
                        }
                    }
                });
                dn.refresh();
            }
        };
    }
};
const titleField = {
    name: 'titleField',
    type: 'select',
    useComponentProps () {
        var _collectionField_uiSchema_xcomponentprops, _collectionField_uiSchema, _field_componentProps, _fieldSchema_xcomponentprops;
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        const options = (0, FormItem_Settings_js_namespaceObject.useTitleFieldOptions)();
        const { uiSchema, fieldSchema: tableColumnSchema, collectionField: tableColumnField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const targetCollectionField = (0, external_data_source_index_js_namespaceObject.useCollectionField)();
        const collectionField = tableColumnField || targetCollectionField;
        const { getCollectionFields } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
        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'],
            ...null == field ? void 0 : null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.fieldNames,
            ...null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['fieldNames']
        };
        return {
            title: t('Title field'),
            options,
            value: null == fieldNames ? void 0 : fieldNames.label,
            onChange (label) {
                var _collectionField_uiSchema_xcomponentprops, _collectionField_uiSchema, _fieldSchema_xcomponentprops, _field_path, _field_path1;
                const schema = {
                    ['x-uid']: fieldSchema['x-uid']
                };
                const newFieldNames = {
                    ...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'],
                    ...null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['fieldNames'],
                    label
                };
                fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                fieldSchema['x-component-props']['fieldNames'] = newFieldNames;
                const target = getCollectionFields(collectionField.target).find((field)=>field.name === label);
                if ('m2o' === target.interface) fieldSchema['x-component-props']['x-next-title'] = {
                    label,
                    collection: target.collectionName
                };
                else fieldSchema['x-component-props']['x-next-title'] = null;
                schema['x-component-props'] = fieldSchema['x-component-props'];
                field.componentProps.fieldNames = fieldSchema['x-component-props'].fieldNames;
                const path = null === (_field_path1 = field.path) || void 0 === _field_path1 ? void 0 : _field_path1.splice((null === (_field_path = field.path) || void 0 === _field_path ? void 0 : _field_path.length) - 1, 1);
                field.form.query("".concat(path.concat("*." + fieldSchema.name))).forEach((f)=>{
                    f.componentProps.fieldNames = 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, external_data_source_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: tableColumnSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        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 ? 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();
            }
        };
    }
};
const quickCreate = {
    name: 'quickCreate',
    type: 'select',
    useComponentProps () {
        var _field_componentProps;
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
        const { dn, insertAdjacent } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        return {
            title: t('Quick create'),
            options: [
                {
                    label: t('None'),
                    value: 'none'
                },
                {
                    label: t('Dropdown'),
                    value: 'quickAdd'
                },
                {
                    label: t('Pop-up'),
                    value: 'modalAdd'
                }
            ],
            value: (null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.addMode) || 'none',
            onChange (mode) {
                if ('modalAdd' === mode) {
                    const hasAddNew = fieldSchema.reduceProperties((buf, schema)=>{
                        if ('Action' === schema['x-component']) return schema;
                        return buf;
                    }, null);
                    if (!hasAddNew) {
                        const addNewActionschema = {
                            'x-action': 'create',
                            'x-acl-action': 'create',
                            title: "{{t('Add new')}}",
                            'x-toolbar': 'ActionSchemaToolbar',
                            'x-settings': 'actionSettings:addNew',
                            'x-component': 'Action',
                            'x-decorator': 'ACLActionProvider',
                            'x-component-props': {
                                openMode: 'drawer',
                                type: 'default',
                                component: 'CreateRecordAction'
                            }
                        };
                        insertAdjacent('afterBegin', addNewActionschema);
                    }
                }
                const schema = {
                    ['x-uid']: fieldSchema['x-uid']
                };
                fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                fieldSchema['x-component-props']['addMode'] = mode;
                schema['x-component-props'] = fieldSchema['x-component-props'];
                field.componentProps = field.componentProps || {};
                field.componentProps.addMode = mode;
                dn.emit('patch', {
                    schema
                });
                dn.refresh();
            }
        };
    }
};
const setDefaultSortingRules = {
    name: 'setDefaultSortingRules',
    Component: SchemaSettingsSortingRule_js_namespaceObject.SchemaSettingsSortingRule
};
const setTheDataScope = {
    name: 'setTheDataScope',
    Component: SchemaSettingsDataScope_js_namespaceObject.SchemaSettingsDataScope,
    useComponentProps () {
        var _fieldSchema_xcomponentprops_service_params, _fieldSchema_xcomponentprops_service, _fieldSchema_xcomponentprops;
        const { getCollectionJoinField, getAllCollectionsInheritChain } = (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 record = (0, external_record_provider_index_js_namespaceObject.useRecord)();
        (0, schema_namespaceObject.useField)();
        const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const collectionField = tableColumnField || getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
        const variables = (0, external_variables_index_js_namespaceObject.useVariables)();
        const localVariables = (0, external_variables_index_js_namespaceObject.useLocalVariables)();
        const { dn } = (0, external_schema_component_index_js_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.VariableInput, {
                    ...props,
                    form: form,
                    collectionField: props.collectionField,
                    record: record,
                    shouldChange: (0, external_schema_settings_index_js_namespaceObject.getShouldChange)({
                        collectionField: props.collectionField,
                        variables,
                        localVariables,
                        getAllCollectionsInheritChain
                    })
                }),
            onSubmit: (param)=>{
                let { filter } = param;
                filter = (0, external_schema_component_index_js_namespaceObject.removeNullCondition)(filter);
                external_lodash_default().set(fieldSchema['x-component-props'], 'service.params.filter', filter);
                dn.emit('patch', {
                    schema: {
                        ['x-uid']: fieldSchema['x-uid'],
                        'x-component-props': fieldSchema['x-component-props']
                    }
                });
            }
        };
    }
};
const fieldComponent = {
    name: 'fieldComponent',
    type: 'select',
    useComponentProps () {
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const collectionFieldCurrent = (0, external_data_source_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 isMuiltipleSelect = [
            'select'
        ].includes(null == collectionFieldCurrent ? void 0 : collectionFieldCurrent.interface);
        const optionsMuiltipleSelect = [
            {
                label: t('Select'),
                value: 'Select'
            },
            {
                label: t('Radio group'),
                value: 'Radio group'
            }
        ];
        return {
            title: t('Field component'),
            options: isMuiltipleSelect ? optionsMuiltipleSelect : fieldModeOptions,
            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) || void 0 === _field_setInitialValue || _field_setInitialValue.call(field, null);
                    null == field || null === (_field_setValue = field.setValue) || void 0 === _field_setValue || _field_setValue.call(field, null);
                }
                dn.emit('patch', {
                    schema
                });
                dn.refresh();
            }
        };
    }
};
const CustomTitle = {
    name: 'customTitle',
    type: 'modal',
    useComponentProps () {
        var _fieldSchema_xcomponentprops_fieldNames, _fieldSchema_xcomponentprops;
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const { fieldSchema: tableColumnSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        const options = (0, external_schema_settings_index_js_namespaceObject.useFormulaTitleOptions)();
        const def = 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.formula;
        const field = (0, schema_namespaceObject.useField)();
        return {
            title: t('Custom option label'),
            schema: {
                type: 'object',
                title: t('Custom option label'),
                properties: {
                    formula: {
                        required: true,
                        'x-decorator': 'FormItem',
                        'x-component': 'Variable.TextArea',
                        'x-component-props': {
                            scope: options
                        },
                        default: def
                    }
                }
            },
            onSubmit: (param)=>{
                let { formula } = param;
                if (formula) {
                    var _fieldSchema_xcomponentprops, _field_componentProps;
                    const componentProps = {
                        ...fieldSchema['x-component-props'],
                        fieldNames: {
                            ...null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['fieldNames'],
                            formula
                        }
                    };
                    field.componentProps = {
                        ...field.componentProps,
                        fieldNames: {
                            ...null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.fieldNames,
                            formula
                        }
                    };
                    fieldSchema['x-component-props'] = componentProps;
                    dn.emit('patch', {
                        schema: {
                            'x-uid': fieldSchema['x-uid'],
                            'x-component-props': componentProps
                        }
                    });
                }
                dn.refresh();
            }
        };
    }
};
const selectComponentFieldSettings = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'fieldSettings:component:Select',
    items: [
        {
            ...fieldComponent,
            useVisible: FormItem_Settings_js_namespaceObject.useIsMuiltipleAble
        },
        {
            ...setTheDataScope,
            useVisible () {
                const isSelectFieldMode = (0, FormItem_Settings_js_namespaceObject.useIsSelectFieldMode)();
                const isFieldReadPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                return isSelectFieldMode && !isFieldReadPretty;
            }
        },
        {
            ...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;
            }
        },
        {
            ...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;
            }
        },
        {
            ...allowMultiple,
            useVisible () {
                const isAssociationField = (0, FormItem_Settings_js_namespaceObject.useIsAssociationField)();
                const IsShowMultipleSwitch = (0, useIsShowMultipleSwitch_js_namespaceObject.useIsShowMultipleSwitch)();
                return isAssociationField && IsShowMultipleSwitch();
            }
        },
        {
            ...titleField,
            useVisible: FormItem_Settings_js_namespaceObject.useIsAssociationField
        },
        {
            ...enableLink,
            useVisible () {
                const readPretty = (0, FormItem_Settings_js_namespaceObject.useIsFieldReadPretty)();
                return (0, FormItem_Settings_js_namespaceObject.useIsAssociationField)() && readPretty;
            }
        }
    ]
});
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
});
