"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    tagComponentFieldSettings: ()=>tagComponentFieldSettings
});
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 Table_Column_Designer_js_namespaceObject = require("../../../../schema-component/antd/table-v2/Table.Column.Designer.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 = (0, schema_namespaceObject.useFieldSchema)();
        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 _field_componentProps_fieldNames, _field_componentProps;
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (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 options = (0, FormItem_Settings_js_namespaceObject.useTitleFieldOptions)();
        const targetCollectionField = (0, index_js_namespaceObject.useCollectionField)();
        const collectionField = tableColumnField || targetCollectionField;
        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
        return {
            title: t('Title field'),
            options,
            value: null == field ? void 0 : null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : null === (_field_componentProps_fieldNames = _field_componentProps.fieldNames) || void 0 === _field_componentProps_fieldNames ? void 0 : _field_componentProps_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 === _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
                };
                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 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 { fieldSchema: tableColumnSchema, collectionField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
        const fieldModeOptions = (0, external_schema_component_index_js_namespaceObject.useFieldModeOptions)({
            fieldSchema: tableColumnSchema,
            collectionField
        });
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const fieldComponentName = (0, useFieldComponentName_js_namespaceObject.useFieldComponentName)();
        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) {
                    schema.default = null;
                    fieldSchema.default = null;
                    field.setInitialValue(null);
                    field.setValue(null);
                }
                dn.emit('patch', {
                    schema
                });
                dn.refresh();
            }
        };
    }
};
const tagComponentFieldSettings = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'fieldSettings:component:Tag',
    items: [
        fieldComponent,
        {
            name: 'tagColorField',
            type: 'select',
            useComponentProps () {
                var _field_componentProps;
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                const field = (0, schema_namespaceObject.useField)();
                const schema = (0, schema_namespaceObject.useFieldSchema)();
                const targetCollectionField = (0, index_js_namespaceObject.useCollectionField)();
                const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                const fieldSchema = tableColumnSchema || schema;
                const collectionField = tableColumnField || targetCollectionField;
                const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                var _collectionField_target;
                const colorFieldOptions = (0, Table_Column_Designer_js_namespaceObject.useColorFields)(null !== (_collectionField_target = null == collectionField ? void 0 : collectionField.target) && void 0 !== _collectionField_target ? _collectionField_target : null == collectionField ? void 0 : collectionField.targetCollection);
                return {
                    title: t('Tag color field'),
                    options: colorFieldOptions,
                    value: null == field ? void 0 : null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.tagColorField,
                    onChange (tagColorField) {
                        const schema = {
                            ['x-uid']: fieldSchema['x-uid']
                        };
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props']['tagColorField'] = tagColorField;
                        schema['x-component-props'] = fieldSchema['x-component-props'];
                        field.componentProps.tagColorField = tagColorField;
                        dn.emit('patch', {
                            schema
                        });
                        dn.refresh();
                    }
                };
            }
        },
        titleField,
        enableLink
    ]
});
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
});
