"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__, {
    tableColumnSettings: ()=>tableColumnSettings
});
const schema_namespaceObject = require("@tachybase/schema");
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_collection_manager_index_js_namespaceObject = require("../../../../collection-manager/index.js");
const CollectionProvider_js_namespaceObject = require("../../../../data-source/collection/CollectionProvider.js");
const fieldComponent_js_namespaceObject = require("../../../../data-source/commonsSettingsItem/fieldComponent.js");
const external_schema_component_index_js_namespaceObject = require("../../../../schema-component/index.js");
const hooks_js_namespaceObject = require("../../../../schema-component/antd/association-field/hooks.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 external_utils_js_namespaceObject = require("./utils.js");
const tableColumnSettings = new SchemaSettings_js_namespaceObject.SchemaSettings({
    name: 'fieldSettings:TableColumn',
    items: [
        {
            name: 'decoratorOptions',
            type: 'itemGroup',
            hideIfNoChildren: true,
            useComponentProps () {
                const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                return {
                    title: t('Generic properties')
                };
            },
            children: [
                {
                    name: 'customColumnTitle',
                    type: 'modal',
                    useComponentProps () {
                        var _collectionField_uiSchema;
                        const { fieldSchema, collectionField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                        const field = (0, schema_namespaceObject.useField)();
                        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                        const columnSchema = (0, schema_namespaceObject.useFieldSchema)();
                        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                        return {
                            title: t('Custom column title'),
                            schema: {
                                type: 'object',
                                title: t('Custom column title'),
                                properties: {
                                    title: {
                                        title: t('Column title'),
                                        default: null == columnSchema ? void 0 : columnSchema.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) || (null == fieldSchema ? void 0 : fieldSchema.title)),
                                        'x-decorator': 'FormItem',
                                        'x-component': 'Input',
                                        'x-component-props': {}
                                    }
                                }
                            },
                            onSubmit: (param)=>{
                                let { title } = param;
                                if (title) {
                                    field.title = title;
                                    columnSchema.title = title;
                                    dn.emit('patch', {
                                        schema: {
                                            'x-uid': columnSchema['x-uid'],
                                            title: columnSchema.title
                                        }
                                    });
                                }
                                dn.refresh();
                            }
                        };
                    }
                },
                {
                    name: 'columnWidth',
                    type: 'modal',
                    useComponentProps () {
                        var _columnSchema_xcomponentprops;
                        const field = (0, schema_namespaceObject.useField)();
                        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                        const columnSchema = (0, schema_namespaceObject.useFieldSchema)();
                        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                        return {
                            title: t('Column width'),
                            schema: {
                                type: 'object',
                                title: t('Column width'),
                                properties: {
                                    width: {
                                        default: (null == columnSchema ? void 0 : null === (_columnSchema_xcomponentprops = columnSchema['x-component-props']) || void 0 === _columnSchema_xcomponentprops ? void 0 : _columnSchema_xcomponentprops['width']) || 200,
                                        'x-decorator': 'FormItem',
                                        'x-component': 'InputNumber',
                                        'x-component-props': {}
                                    }
                                }
                            },
                            onSubmit: (param)=>{
                                let { width } = param;
                                const props = columnSchema['x-component-props'] || {};
                                props['width'] = width;
                                const schema = {
                                    ['x-uid']: columnSchema['x-uid']
                                };
                                schema['x-component-props'] = props;
                                columnSchema['x-component-props'] = props;
                                field.componentProps.width = width;
                                dn.emit('patch', {
                                    schema
                                });
                                dn.refresh();
                            }
                        };
                    }
                },
                {
                    name: 'columnAlign',
                    type: 'select',
                    useComponentProps () {
                        var _fieldSchema_xcomponentprops;
                        const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                        const field = (0, schema_namespaceObject.useField)();
                        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                        return {
                            key: 'align',
                            title: t('Align'),
                            options: [
                                {
                                    label: t('Left'),
                                    value: 'left'
                                },
                                {
                                    label: t('Center'),
                                    value: 'center'
                                },
                                {
                                    label: t('Right'),
                                    value: 'right'
                                }
                            ],
                            value: (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.align) || 'left',
                            onChange: (align)=>{
                                const props = fieldSchema['x-component-props'] || {};
                                props['align'] = align;
                                const schema = {
                                    ['x-uid']: fieldSchema['x-uid']
                                };
                                schema['x-component-props'] = props;
                                fieldSchema['x-component-props'] = props;
                                field.componentProps.align = align;
                                dn.emit('patch', {
                                    schema
                                });
                                dn.refresh();
                            }
                        };
                    }
                },
                {
                    name: 'sortable',
                    type: 'switch',
                    useVisible () {
                        (0, CollectionProvider_js_namespaceObject.useCollection)();
                        const { collectionField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                        const { getInterface } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
                        const interfaceCfg = getInterface(null == collectionField ? void 0 : collectionField.interface);
                        const { currentMode } = (0, hooks_js_namespaceObject.useAssociationFieldContext)();
                        return (null == interfaceCfg ? void 0 : interfaceCfg.sortable) === true && !currentMode;
                    },
                    useComponentProps () {
                        const field = (0, schema_namespaceObject.useField)();
                        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                        const columnSchema = (0, schema_namespaceObject.useFieldSchema)();
                        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                        return {
                            title: t('Sortable'),
                            checked: field.componentProps.sorter,
                            onChange: (v)=>{
                                const schema = {
                                    ['x-uid']: columnSchema['x-uid']
                                };
                                columnSchema['x-component-props'] = {
                                    ...columnSchema['x-component-props'],
                                    sorter: v
                                };
                                schema['x-component-props'] = columnSchema['x-component-props'];
                                field.componentProps.sorter = v;
                                dn.emit('patch', {
                                    schema
                                });
                                dn.refresh();
                            }
                        };
                    }
                },
                {
                    name: 'setDefaultValue',
                    useVisible () {
                        const { fieldSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                        if (!fieldSchema) return false;
                        return !(null == fieldSchema ? void 0 : fieldSchema['x-read-pretty']);
                    },
                    Component: external_schema_settings_index_js_namespaceObject.SchemaSettingsDefaultValue,
                    useComponentProps () {
                        const { fieldSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                        return {
                            fieldSchema
                        };
                    }
                },
                {
                    name: 'required',
                    type: 'switch',
                    useVisible () {
                        const { uiSchema, fieldSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                        const field = (0, schema_namespaceObject.useField)();
                        if (!fieldSchema) return false;
                        const isSubTableColumn = [
                            'QuickEdit',
                            'FormItem'
                        ].includes(fieldSchema['x-decorator']);
                        return isSubTableColumn && !field.readPretty && !(null == uiSchema ? void 0 : uiSchema['x-read-pretty']);
                    },
                    useComponentProps () {
                        const { fieldSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                        const field = (0, schema_namespaceObject.useField)();
                        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                        return {
                            key: 'required',
                            title: t('Required'),
                            checked: fieldSchema.required,
                            onChange: (required)=>{
                                var _field_path, _field_path1;
                                if (!fieldSchema) return console.error('fieldSchema is required');
                                const schema = {
                                    ['x-uid']: fieldSchema['x-uid']
                                };
                                fieldSchema['required'] = required;
                                schema['required'] = required;
                                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.required = required;
                                });
                                dn.emit('patch', {
                                    schema
                                });
                                dn.refresh();
                            }
                        };
                    }
                },
                {
                    name: 'pattern',
                    type: 'select',
                    useVisible () {
                        const { fieldSchema, collectionField } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                        const field = (0, schema_namespaceObject.useField)();
                        if (!fieldSchema) return false;
                        const isSubTableColumn = [
                            'QuickEdit',
                            'FormItem'
                        ].includes(fieldSchema['x-decorator']);
                        return isSubTableColumn && !(null == field ? void 0 : field.readPretty) && (null == collectionField ? void 0 : collectionField.interface) !== 'o2m' && !(0, external_schema_settings_index_js_namespaceObject.isPatternDisabled)(fieldSchema);
                    },
                    useComponentProps () {
                        const { fieldSchema } = (0, Table_Column_Decorator_js_namespaceObject.useColumnSchema)();
                        const field = (0, schema_namespaceObject.useField)();
                        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                        const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                        let readOnlyMode = 'editable';
                        if (!fieldSchema) return console.error('fieldSchema is required');
                        if (true === fieldSchema['x-disabled']) readOnlyMode = 'readonly';
                        if (true === fieldSchema['x-read-pretty']) readOnlyMode = 'read-pretty';
                        return {
                            key: 'pattern',
                            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)=>{
                                var _field_path, _field_path1;
                                const schema = {
                                    ['x-uid']: fieldSchema['x-uid']
                                };
                                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);
                                switch(v){
                                    case 'readonly':
                                        fieldSchema['x-read-pretty'] = false;
                                        fieldSchema['x-disabled'] = true;
                                        schema['x-read-pretty'] = false;
                                        schema['x-disabled'] = true;
                                        field.form.query("".concat(path.concat("*." + fieldSchema.name))).forEach((f)=>{
                                            f.readonly = true;
                                            f.disabled = true;
                                        });
                                        break;
                                    case 'read-pretty':
                                        fieldSchema['x-read-pretty'] = true;
                                        fieldSchema['x-disabled'] = false;
                                        schema['x-read-pretty'] = true;
                                        schema['x-disabled'] = false;
                                        field.form.query("".concat(path.concat("*." + fieldSchema.name))).forEach((f)=>{
                                            f.readPretty = true;
                                        });
                                        break;
                                    default:
                                        fieldSchema['x-read-pretty'] = false;
                                        fieldSchema['x-disabled'] = false;
                                        schema['x-read-pretty'] = false;
                                        schema['x-disabled'] = false;
                                        field.form.query("".concat(path.concat("*." + fieldSchema.name))).forEach((f)=>{
                                            f.readPretty = false;
                                            f.disabled;
                                        });
                                        break;
                                }
                                dn.emit('patch', {
                                    schema
                                });
                                dn.refresh();
                            }
                        };
                    }
                },
                fieldComponent_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, external_utils_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
});
