import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
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_initializer_components_SchemaInitializerChildren_mjs__ from "../../../../application/schema-initializer/components/SchemaInitializerChildren.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__ from "../../../../application/schema-initializer/SchemaInitializer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__ from "../../../../schema-initializer/utils.mjs";
const ParentCollectionFields = ()=>{
    const inheritFields = (0, __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__.useInheritsTableColumnInitializerFields)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const compile = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_schema_initializer_components_SchemaInitializerChildren_mjs__.SchemaInitializerChildren, {
        children: res
    });
};
const AssociatedFields = ()=>{
    const associatedFields = (0, __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__.useAssociatedTableColumnInitializerFields)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const schema = (0, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_schema_initializer_components_SchemaInitializerChildren_mjs__.SchemaInitializerChildren, {
        children: schema
    });
};
const tableColumnInitializers = new __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__.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: __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__.useTableColumnInitializerFields
        },
        {
            name: 'parentCollectionFields',
            Component: ParentCollectionFields
        },
        {
            name: 'associationFields',
            Component: AssociatedFields
        },
        {
            name: 'divider',
            type: 'divider',
            useVisible () {
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                return 'AssociationField.SubTable' !== fieldSchema['x-component'];
            }
        },
        {
            type: 'item',
            name: 'add',
            title: '{{t("Action column")}}',
            Component: 'TableActionColumnInitializer',
            useVisible () {
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                return 'AssociationField.SubTable' !== fieldSchema['x-component'];
            }
        }
    ]
});
export { tableColumnInitializers };
