"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__, {
    fieldSettingsFormItem: ()=>fieldSettingsFormItem
});
const components_namespaceObject = require("@tachybase/components");
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("../../../../application/index.js");
const SchemaSettings_js_namespaceObject = require("../../../../application/schema-settings/SchemaSettings.js");
const external_block_provider_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_schema_component_index_js_namespaceObject = require("../../../../schema-component/index.js");
const FormItem_Settings_js_namespaceObject = require("../../../../schema-component/antd/form-item/FormItem.Settings.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 type_js_namespaceObject = require("../../../../schema-settings/LinkageRules/type.js");
const fieldSettingsFormItem = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'fieldSettings:FormItem',
    items: [
        {
            name: 'decoratorOptions',
            type: 'itemGroup',
            hideIfNoChildren: true,
            useComponentProps () {
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                return {
                    title: t('Generic properties')
                };
            },
            useChildren () {
                return [
                    {
                        name: 'editFieldTitle',
                        type: 'modal',
                        useComponentProps () {
                            var _collectionField_uiSchema;
                            const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                            const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                            const field = (0, schema_namespaceObject.useField)();
                            const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                            const { getCollectionJoinField } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
                            const { getField } = (0, external_collection_manager_index_js_namespaceObject.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();
                                }
                            };
                        }
                    },
                    {
                        name: 'displayTitle',
                        type: 'switch',
                        useComponentProps () {
                            var _fieldSchema_xdecoratorprops;
                            const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                            const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                            const field = (0, schema_namespaceObject.useField)();
                            const fieldSchema = (0, schema_namespaceObject.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, external_react_i18next_namespaceObject.useTranslation)();
                            const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                            const field = (0, schema_namespaceObject.useField)();
                            const fieldSchema = (0, schema_namespaceObject.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();
                                }
                            };
                        }
                    },
                    {
                        name: 'editTooltip',
                        type: 'modal',
                        useComponentProps () {
                            var _fieldSchema_xdecoratorprops;
                            const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                            const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                            const field = (0, schema_namespaceObject.useField)();
                            const fieldSchema = (0, schema_namespaceObject.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();
                                }
                            };
                        }
                    },
                    {
                        name: 'required',
                        type: 'switch',
                        useVisible () {
                            const field = (0, schema_namespaceObject.useField)();
                            const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                            const { required = true } = (0, index_js_namespaceObject.useSchemaToolbar)();
                            return !field.readPretty && 'FormField' !== fieldSchema['x-component'] && required;
                        },
                        useComponentProps () {
                            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('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();
                                }
                            };
                        }
                    },
                    {
                        name: 'setDefaultValue',
                        Component: external_schema_settings_index_js_namespaceObject.SchemaSettingsDefaultValue
                    },
                    {
                        name: 'layoutDirection',
                        type: 'select',
                        useComponentProps () {
                            var _fieldSchema_xdecoratorprops;
                            const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                            const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                            const field = (0, schema_namespaceObject.useField)();
                            const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                            const { layoutDirection = 'column' } = (0, external_data_source_index_js_namespaceObject.useContextConfigSetting)();
                            const initialValue = (null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops.layoutDirection) || layoutDirection;
                            return {
                                title: t('Layout Direction'),
                                options: [
                                    {
                                        label: t('Row'),
                                        value: 'row'
                                    },
                                    {
                                        label: t('Column'),
                                        value: 'column'
                                    }
                                ],
                                value: initialValue,
                                onChange () {
                                    let directionVal = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 'column';
                                    var _fieldSchema_xdecoratorprops;
                                    const oldStyle = null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops.style;
                                    const newStyle = {
                                        ...oldStyle,
                                        display: 'flex',
                                        flexDirection: directionVal,
                                        alignItems: "".concat('row' === directionVal ? 'baseline' : 'unset')
                                    };
                                    external_lodash_default().set(field, 'decoratorProps.style', newStyle);
                                    external_lodash_default().set(field, 'decoratorProps.layoutDirection', directionVal);
                                    dn.emit('patch', {
                                        schema: {
                                            'x-uid': fieldSchema['x-uid'],
                                            'x-decorator-props': {
                                                ...fieldSchema['x-decorator-props'],
                                                layoutDirection: directionVal,
                                                style: newStyle
                                            }
                                        }
                                    });
                                    dn.refresh();
                                }
                            };
                        }
                    },
                    {
                        name: 'pattern',
                        type: 'select',
                        useVisible () {
                            const { form } = (0, external_block_provider_index_js_namespaceObject.useFormBlockContext)();
                            const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                            return form && !(null == form ? void 0 : form.readPretty) && !(0, external_schema_settings_index_js_namespaceObject.isPatternDisabled)(fieldSchema);
                        },
                        useComponentProps () {
                            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)();
                            let readOnlyMode = 'editable';
                            if (true === fieldSchema['x-disabled']) readOnlyMode = 'readonly';
                            if (true === fieldSchema['x-read-pretty']) readOnlyMode = 'read-pretty';
                            return {
                                title: t('Pattern'),
                                options: [
                                    {
                                        label: t('Editable'),
                                        value: 'editable'
                                    },
                                    {
                                        label: t('Readonly'),
                                        value: 'readonly'
                                    },
                                    {
                                        label: t('Easy-reading'),
                                        value: 'read-pretty'
                                    }
                                ],
                                value: readOnlyMode,
                                onChange (v) {
                                    const schema = {
                                        ['x-uid']: fieldSchema['x-uid']
                                    };
                                    switch(v){
                                        case 'readonly':
                                            fieldSchema['x-read-pretty'] = false;
                                            fieldSchema['x-disabled'] = true;
                                            schema['x-read-pretty'] = false;
                                            schema['x-disabled'] = true;
                                            field.readPretty = false;
                                            field.disabled = true;
                                            external_lodash_default().set(field, 'initStateOfLinkageRules.pattern', (0, utils_js_namespaceObject.getTempFieldState)(true, type_js_namespaceObject.ActionType.ReadOnly));
                                            break;
                                        case 'read-pretty':
                                            fieldSchema['x-read-pretty'] = true;
                                            fieldSchema['x-disabled'] = false;
                                            schema['x-read-pretty'] = true;
                                            schema['x-disabled'] = false;
                                            field.readPretty = true;
                                            external_lodash_default().set(field, 'initStateOfLinkageRules.pattern', (0, utils_js_namespaceObject.getTempFieldState)(true, type_js_namespaceObject.ActionType.ReadPretty));
                                            break;
                                        default:
                                            fieldSchema['x-read-pretty'] = false;
                                            fieldSchema['x-disabled'] = false;
                                            schema['x-read-pretty'] = false;
                                            schema['x-disabled'] = false;
                                            field.readPretty = false;
                                            field.disabled = false;
                                            external_lodash_default().set(field, 'initStateOfLinkageRules.pattern', (0, utils_js_namespaceObject.getTempFieldState)(true, type_js_namespaceObject.ActionType.Editable));
                                            break;
                                    }
                                    dn.emit('patch', {
                                        schema
                                    });
                                    dn.refresh();
                                }
                            };
                        }
                    },
                    {
                        name: 'setValidationRules',
                        type: 'modal',
                        useComponentProps () {
                            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)();
                            const validateSchema = (0, external_schema_component_index_js_namespaceObject.useValidateSchema)();
                            const { getCollectionJoinField } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
                            const { getField } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                            const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
                            return {
                                title: t('Set validation rules'),
                                components: {
                                    ArrayCollapse: components_namespaceObject.ArrayCollapse,
                                    FormLayout: components_namespaceObject.FormLayout
                                },
                                schema: {
                                    type: 'object',
                                    title: t('Set validation rules'),
                                    properties: {
                                        rules: {
                                            type: 'array',
                                            default: null == fieldSchema ? void 0 : fieldSchema['x-validator'],
                                            'x-component': 'ArrayCollapse',
                                            'x-decorator': 'FormItem',
                                            'x-component-props': {
                                                accordion: true
                                            },
                                            maxItems: 3,
                                            items: {
                                                type: 'object',
                                                'x-component': 'ArrayCollapse.CollapsePanel',
                                                'x-component-props': {
                                                    header: '{{ t("Validation rule") }}'
                                                },
                                                properties: {
                                                    index: {
                                                        type: 'void',
                                                        'x-component': 'ArrayCollapse.Index'
                                                    },
                                                    layout: {
                                                        type: 'void',
                                                        'x-component': 'FormLayout',
                                                        'x-component-props': {
                                                            labelStyle: {
                                                                marginTop: '6px'
                                                            },
                                                            labelCol: 8,
                                                            wrapperCol: 16
                                                        },
                                                        properties: {
                                                            ...validateSchema,
                                                            message: {
                                                                type: 'string',
                                                                title: '{{ t("Error message") }}',
                                                                'x-decorator': 'FormItem',
                                                                'x-component': 'Input.TextArea',
                                                                'x-component-props': {
                                                                    autoSize: {
                                                                        minRows: 2,
                                                                        maxRows: 2
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    },
                                                    remove: {
                                                        type: 'void',
                                                        'x-component': 'ArrayCollapse.Remove'
                                                    },
                                                    moveUp: {
                                                        type: 'void',
                                                        'x-component': 'ArrayCollapse.MoveUp'
                                                    },
                                                    moveDown: {
                                                        type: 'void',
                                                        'x-component': 'ArrayCollapse.MoveDown'
                                                    }
                                                }
                                            },
                                            properties: {
                                                add: {
                                                    type: 'void',
                                                    title: '{{ t("Add validation rule") }}',
                                                    'x-component': 'ArrayCollapse.Addition',
                                                    'x-reactions': {
                                                        dependencies: [
                                                            'rules'
                                                        ],
                                                        fulfill: {
                                                            state: {
                                                                disabled: '{{$deps[0].length >= 3}}'
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                },
                                onSubmit (v) {
                                    var _collectionField_uiSchema;
                                    const rules = [];
                                    for (const rule of v.rules)rules.push(external_lodash_default().pickBy(rule, external_lodash_default().identity));
                                    const schema = {
                                        ['x-uid']: fieldSchema['x-uid']
                                    };
                                    if ([
                                        'percent'
                                    ].includes(null == collectionField ? void 0 : collectionField.interface)) for (const rule of rules){
                                        if (!!rule.maxValue || !!rule.minValue) rule['percentMode'] = true;
                                        if (rule.percentFormat) rule['percentFormats'] = true;
                                    }
                                    const concatValidator = external_lodash_default().concat([], (null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema['x-validator']) || [], rules);
                                    field.validator = concatValidator;
                                    fieldSchema['x-validator'] = rules;
                                    schema['x-validator'] = rules;
                                    dn.emit('patch', {
                                        schema
                                    });
                                    refresh();
                                }
                            };
                        },
                        useVisible () {
                            const { form } = (0, external_block_provider_index_js_namespaceObject.useFormBlockContext)();
                            const isFormReadPretty = (0, FormItem_Settings_js_namespaceObject.useIsFormReadPretty)();
                            const validateSchema = (0, external_schema_component_index_js_namespaceObject.useValidateSchema)();
                            return form && !isFormReadPretty && validateSchema;
                        }
                    },
                    {
                        ...external_data_source_index_js_namespaceObject.fieldComponentSettingsItem
                    }
                ];
            }
        },
        {
            name: 'componentOptions',
            type: 'itemGroup',
            hideIfNoChildren: true,
            useComponentProps () {
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                return {
                    title: t('Specific properties')
                };
            },
            useChildren () {
                const app = (0, index_js_namespaceObject.useApp)();
                const fieldComponentName = (0, useFieldComponentName_js_namespaceObject.useFieldComponentName)();
                const componentSettings = app.schemaSettingsManager.get("fieldSettings:component:".concat(fieldComponentName));
                return (null == componentSettings ? void 0 : componentSettings.items) || [];
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'delete',
            type: 'remove',
            sort: 100,
            useComponentProps () {
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                return {
                    removeParentsIfNoChildren: true,
                    confirm: {
                        title: t('Delete field')
                    },
                    breakRemoveOn: {
                        'x-component': 'Grid'
                    }
                };
            }
        }
    ]
});
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
});
