"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__, {
    tableColumnInitializers: ()=>tableColumnInitializers
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_react_i18next_namespaceObject = require("react-i18next");
const SchemaInitializerChildren_js_namespaceObject = require("../../../../application/schema-initializer/components/SchemaInitializerChildren.js");
const SchemaInitializer_js_namespaceObject = require("../../../../application/schema-initializer/SchemaInitializer.js");
const index_js_namespaceObject = require("../../../../schema-component/index.js");
const utils_js_namespaceObject = require("../../../../schema-initializer/utils.js");
const ParentCollectionFields = ()=>{
    const inheritFields = (0, utils_js_namespaceObject.useInheritsTableColumnInitializerFields)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const compile = (0, index_js_namespaceObject.useCompile)();
    if (!(null == inheritFields ? void 0 : inheritFields.length)) return null;
    const res = [];
    inheritFields.forEach((inherit)=>{
        Object.values(inherit)[0].length && res.push({
            type: 'itemGroup',
            divider: true,
            title: t("Parent collection fields") + '(' + compile("".concat(Object.keys(inherit)[0])) + ')',
            children: Object.values(inherit)[0].filter((v)=>{
                var _v_field;
                return !(null == v ? void 0 : null === (_v_field = v.field) || void 0 === _v_field ? void 0 : _v_field.isForeignKey);
            })
        });
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaInitializerChildren_js_namespaceObject.SchemaInitializerChildren, {
        children: res
    });
};
const AssociatedFields = ()=>{
    const associatedFields = (0, utils_js_namespaceObject.useAssociatedTableColumnInitializerFields)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const schema = (0, external_react_namespaceObject.useMemo)(()=>[
            {
                type: 'itemGroup',
                title: t('Display association fields'),
                children: associatedFields
            }
        ], [
        associatedFields,
        t
    ]);
    if (!(null == associatedFields ? void 0 : associatedFields.length) || 'AssociationField.SubTable' === fieldSchema['x-component']) return null;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaInitializerChildren_js_namespaceObject.SchemaInitializerChildren, {
        children: schema
    });
};
const tableColumnInitializers = new SchemaInitializer_js_namespaceObject.SchemaInitializer({
    name: 'table:configureColumns',
    insertPosition: 'beforeEnd',
    icon: 'SettingOutlined',
    title: '{{t("Configure columns")}}',
    wrap: (s, param)=>{
        let { isInSubTable } = param;
        if (s['x-action-column']) return s;
        return {
            type: 'void',
            'x-decorator': 'TableV2.Column.Decorator',
            'x-toolbar': 'TableColumnSchemaToolbar',
            'x-settings': 'fieldSettings:TableColumn',
            'x-component': 'TableV2.Column',
            properties: {
                [s.name]: {
                    ...s
                }
            }
        };
    },
    items: [
        {
            name: 'displayFields',
            type: 'itemGroup',
            title: '{{t("Display fields")}}',
            useChildren: utils_js_namespaceObject.useTableColumnInitializerFields
        },
        {
            name: 'parentCollectionFields',
            Component: ParentCollectionFields
        },
        {
            name: 'associationFields',
            Component: AssociatedFields
        },
        {
            name: 'divider',
            type: 'divider',
            useVisible () {
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                return 'AssociationField.SubTable' !== fieldSchema['x-component'];
            }
        },
        {
            type: 'item',
            name: 'add',
            title: '{{t("Action column")}}',
            Component: 'TableActionColumnInitializer',
            useVisible () {
                const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                return 'AssociationField.SubTable' !== fieldSchema['x-component'];
            }
        }
    ]
});
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
});
