import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_index_mjs__ from "../../../application/schema-initializer/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__utils_index_mjs__ from "../utils/index.mjs";
const AssociationCollectionFields = (props)=>{
    const { filterAssociationField, filterSelfField = ()=>true, getSchema, ...otherProps } = props;
    const { collection, t, collectionManager } = props.context;
    const fields = collection.getFields();
    const associationInterfaces = [
        'o2o',
        'oho',
        'obo',
        'm2o'
    ];
    const associationFields = fields.filter((field)=>associationInterfaces.includes(field.interface)).filter((field)=>filterSelfField(field, props.context));
    if (!associationFields.length) return null;
    const children = associationFields.map((associationField)=>{
        const associationCollection = collectionManager.getCollection(associationField.target);
        if (!associationCollection) return null;
        const associationCollectionFields = null == associationCollection ? void 0 : associationCollection.getAllFields();
        if (!associationCollectionFields.length) return null;
        return {
            associationField,
            associationCollection,
            associationCollectionFields
        };
    }).filter(Boolean).map((param)=>{
        let { associationField, associationCollection, associationCollectionFields } = param;
        var _associationField_uiSchema, _associationField_uiSchema1;
        const newContext = {
            ...props.context,
            collection: associationCollection
        };
        const getAssociationFieldSchema = (field, context)=>{
            const schema = getSchema(field, context);
            return {
                ...schema || {},
                'x-read-pretty': true,
                name: "".concat(associationField.name, ".").concat(field.name),
                'x-collection-field': "".concat(collection.name, ".").concat(associationField.name, ".").concat(field.name)
            };
        };
        return {
            type: 'subMenu',
            name: null === (_associationField_uiSchema = associationField.uiSchema) || void 0 === _associationField_uiSchema ? void 0 : _associationField_uiSchema.title,
            title: null === (_associationField_uiSchema1 = associationField.uiSchema) || void 0 === _associationField_uiSchema1 ? void 0 : _associationField_uiSchema1.title,
            children: (0, __WEBPACK_EXTERNAL_MODULE__utils_index_mjs__.getInitializerItemsByFields)({
                ...otherProps,
                filter: filterAssociationField,
                getSchema: getAssociationFieldSchema
            }, associationCollectionFields, newContext)
        };
    });
    if (!children.length) return null;
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_schema_initializer_index_mjs__.SchemaInitializerItemGroup, {
        title: t('Display association fields'),
        children: children
    });
};
export { AssociationCollectionFields };
