import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_toolbar_index_mjs__ from "../application/schema-toolbar/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../schema-component/index.mjs";
const generalSettingsItems = [
    {
        name: 'editFieldTitle',
        type: 'modal',
        useComponentProps () {
            var _collectionField_uiSchema;
            const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
            const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
            const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
            const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
            const { getCollectionJoinField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
            const { getField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
            const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
            return {
                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 ? 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();
                }
            };
        },
        useVisible () {
            const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
            const { getCollectionJoinField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
            const { getField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
            const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
            return !!collectionField;
        }
    },
    {
        name: 'displayTitle',
        type: 'switch',
        useComponentProps () {
            var _fieldSchema_xdecoratorprops;
            const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
            const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
            const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
            const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
            var _fieldSchema_xdecoratorprops_showTitle;
            return {
                title: t('Display title'),
                checked: null === (_fieldSchema_xdecoratorprops_showTitle = null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops['showTitle']) || void 0 === _fieldSchema_xdecoratorprops_showTitle || _fieldSchema_xdecoratorprops_showTitle,
                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();
                }
            };
        }
    },
    {
        name: 'editDescription',
        type: 'modal',
        useComponentProps () {
            const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
            const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
            const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
            const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
            return {
                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();
                }
            };
        },
        useVisible () {
            const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
            return !field.readPretty;
        }
    },
    {
        name: 'editTooltip',
        type: 'modal',
        useComponentProps () {
            var _fieldSchema_xdecoratorprops;
            const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
            const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
            const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
            const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
            return {
                title: t('Edit tooltip'),
                schema: {
                    type: 'object',
                    title: t('Edit tooltip'),
                    properties: {
                        tooltip: {
                            default: null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops.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();
                }
            };
        },
        useVisible () {
            const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
            return field.readPretty;
        }
    },
    {
        name: 'required',
        type: 'switch',
        useComponentProps () {
            const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
            const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
            const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
            const { dn, refresh } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
            return {
                title: t('Required'),
                checked: fieldSchema.required,
                onChange (required) {
                    const schema = {
                        ['x-uid']: fieldSchema['x-uid']
                    };
                    field.required = required;
                    fieldSchema['required'] = required;
                    schema['required'] = required;
                    dn.emit('patch', {
                        schema
                    });
                    refresh();
                }
            };
        },
        useVisible () {
            const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
            const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
            const { required = true } = (0, __WEBPACK_EXTERNAL_MODULE__application_schema_toolbar_index_mjs__.useSchemaToolbar)();
            return !field.readPretty && 'FormField' !== fieldSchema['x-component'] && required;
        }
    }
];
export { generalSettingsItems };
