"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    GeneralSchemaItems: ()=>GeneralSchemaItems
});
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 index_js_namespaceObject = require("../collection-manager/index.js");
const external_schema_component_index_js_namespaceObject = require("../schema-component/index.js");
const utils_js_namespaceObject = require("../schema-component/antd/form-v2/utils.js");
const external_schema_settings_index_js_namespaceObject = require("../schema-settings/index.js");
const GeneralSchemaItems = (0, schema_namespaceObject.observer)((props)=>{
    var _collectionField_uiSchema, _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
    const { required = true } = props;
    const { getCollectionJoinField } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const { getField } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { dn, refresh } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
    const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
    var _fieldSchema_xdecoratorprops_showTitle;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            collectionField && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsModalItem, {
                title: t('Edit field title'),
                schema: {
                    type: 'object',
                    title: t('Edit field title'),
                    properties: {
                        title: {
                            title: t('Field title'),
                            default: null == field ? void 0 : field.title,
                            description: "".concat(t('Original field title: ')).concat(null == collectionField ? void 0 : null == (_collectionField_uiSchema = collectionField.uiSchema) ? void 0 : _collectionField_uiSchema.title),
                            'x-decorator': 'FormItem',
                            'x-component': 'Input',
                            'x-component-props': {}
                        }
                    }
                },
                onSubmit: (param)=>{
                    let { title } = param;
                    if (title) {
                        field.title = title;
                        fieldSchema.title = title;
                        dn.emit('patch', {
                            schema: {
                                'x-uid': fieldSchema['x-uid'],
                                title: fieldSchema.title
                            }
                        });
                    }
                    dn.refresh();
                }
            }, "edit-field-title"),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsSwitchItem, {
                checked: null != (_fieldSchema_xdecoratorprops_showTitle = null == (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) ? void 0 : _fieldSchema_xdecoratorprops['showTitle']) ? _fieldSchema_xdecoratorprops_showTitle : true,
                title: t('Display title'),
                onChange: (checked)=>{
                    fieldSchema['x-decorator-props'] = fieldSchema['x-decorator-props'] || {};
                    fieldSchema['x-decorator-props']['showTitle'] = checked;
                    field.decoratorProps.showTitle = checked;
                    dn.emit('patch', {
                        schema: {
                            'x-uid': fieldSchema['x-uid'],
                            'x-decorator-props': {
                                ...fieldSchema['x-decorator-props'],
                                showTitle: checked
                            }
                        }
                    });
                    dn.refresh();
                }
            }),
            !field.readPretty && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsModalItem, {
                title: t("Edit description"),
                schema: {
                    type: 'object',
                    title: t("Edit description"),
                    properties: {
                        description: {
                            default: null == field ? void 0 : field.description,
                            'x-decorator': 'FormItem',
                            'x-component': 'Input.TextArea',
                            'x-component-props': {}
                        }
                    }
                },
                onSubmit: (param)=>{
                    let { description } = param;
                    field.description = description;
                    fieldSchema.description = description;
                    dn.emit('patch', {
                        schema: {
                            'x-uid': fieldSchema['x-uid'],
                            description: fieldSchema.description
                        }
                    });
                    dn.refresh();
                }
            }, "edit-description"),
            field.readPretty && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsModalItem, {
                title: t('Edit tooltip'),
                schema: {
                    type: 'object',
                    title: t("Edit description"),
                    properties: {
                        tooltip: {
                            default: null == fieldSchema ? void 0 : null == (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) ? void 0 : _fieldSchema_xdecoratorprops1.tooltip,
                            'x-decorator': 'FormItem',
                            'x-component': 'Input.TextArea',
                            'x-component-props': {}
                        }
                    }
                },
                onSubmit: (param)=>{
                    let { tooltip } = param;
                    field.decoratorProps.tooltip = tooltip;
                    fieldSchema['x-decorator-props'] = fieldSchema['x-decorator-props'] || {};
                    fieldSchema['x-decorator-props']['tooltip'] = tooltip;
                    dn.emit('patch', {
                        schema: {
                            'x-uid': fieldSchema['x-uid'],
                            'x-decorator-props': fieldSchema['x-decorator-props']
                        }
                    });
                    dn.refresh();
                }
            }, "edit-tooltip"),
            !field.readPretty && 'FormField' !== fieldSchema['x-component'] && required && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsSwitchItem, {
                title: t('Required'),
                checked: fieldSchema.required,
                onChange: (required)=>{
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    field.required = required;
                    external_lodash_default().set(field, 'initStateOfLinkageRules.required', (0, utils_js_namespaceObject.getTempFieldState)(true, required));
                    fieldSchema['required'] = required;
                    schema['required'] = required;
                    dn.emit('patch', {
                        schema
                    });
                    refresh();
                }
            }, "required")
        ]
    });
}, {
    displayName: 'GeneralSchemaItems'
});
exports.GeneralSchemaItems = __webpack_exports__.GeneralSchemaItems;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
    "GeneralSchemaItems"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
    value: true
});
