import * as __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__ from "../../../../application/schema-initializer/SchemaInitializer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_hooks_index_mjs__ from "../../../../block-provider/hooks/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__ from "../../../../data-source/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__filter_provider_utils_mjs__ from "../../../../filter-provider/utils.mjs";
const associationFilterFilterBlockInitializer = new __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__.SchemaInitializer({
    name: 'AssociationFilter.FilterBlockInitializer',
    style: {
        marginTop: 16
    },
    icon: 'SettingOutlined',
    title: '{{t("Configure fields")}}',
    items: [
        {
            type: 'itemGroup',
            name: 'associationFields',
            title: '{{t("Association fields")}}',
            useChildren () {
                const associatedFields = (0, __WEBPACK_EXTERNAL_MODULE__filter_provider_utils_mjs__.useAssociatedFields)();
                const children = associatedFields.map((field)=>{
                    var _field_uiSchema, _field_uiSchema1;
                    return {
                        name: field.key,
                        title: null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title,
                        Component: 'AssociationFilterDesignerDisplayField',
                        schema: {
                            name: field.name,
                            title: null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title,
                            type: 'void',
                            'x-toolbar': 'CollapseItemSchemaToolbar',
                            'x-settings': 'fieldSettings:FilterCollapseItem',
                            'x-component': 'AssociationFilter.Item',
                            'x-use-component-props': 'useAssociationFilterBlockProps',
                            'x-component-props': {
                                fieldNames: {
                                    label: field.targetKey || 'id'
                                }
                            },
                            properties: {}
                        }
                    };
                });
                return children;
            }
        },
        {
            name: 'choicesFields',
            type: 'itemGroup',
            title: '{{t("Choices fields")}}',
            hideIfNoChildren: true,
            useChildren () {
                const optionalList = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_hooks_index_mjs__.useOptionalFieldList)();
                const useProps = '{{useAssociationFilterBlockProps}}';
                const optionalChildren = optionalList.map((field)=>({
                        name: field.key,
                        title: field.uiSchema.title,
                        Component: 'AssociationFilterDesignerDisplayField',
                        schema: {
                            name: field.name,
                            title: field.uiSchema.title,
                            interface: field.interface,
                            type: 'void',
                            'x-toolbar': 'CollapseItemSchemaToolbar',
                            'x-settings': 'fieldSettings:FilterCollapseItem',
                            'x-component': 'AssociationFilter.Item',
                            'x-component-props': {
                                fieldNames: {
                                    label: field.name
                                },
                                useProps
                            },
                            properties: {}
                        }
                    }));
                return optionalChildren;
            }
        }
    ]
});
const filterCollapseItemInitializer = new __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__.SchemaInitializer({
    name: 'filterCollapse:configureFields',
    style: {
        marginTop: 16
    },
    icon: 'SettingOutlined',
    title: '{{t("Configure fields")}}',
    items: [
        {
            type: 'itemGroup',
            name: 'associationFields',
            title: '{{t("Association fields")}}',
            useChildren () {
                const associatedFields = (0, __WEBPACK_EXTERNAL_MODULE__filter_provider_utils_mjs__.useAssociatedFields)();
                const cm = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollectionManager)();
                const children = associatedFields.map((field)=>{
                    var _field_uiSchema, _field_uiSchema1, _cm_getCollection;
                    return {
                        name: field.key,
                        title: null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title,
                        Component: 'AssociationFilterDesignerDisplayField',
                        schema: {
                            name: field.name,
                            title: null === (_field_uiSchema1 = field.uiSchema) || void 0 === _field_uiSchema1 ? void 0 : _field_uiSchema1.title,
                            type: 'void',
                            'x-toolbar': 'CollapseItemSchemaToolbar',
                            'x-settings': 'fieldSettings:FilterCollapseItem',
                            'x-component': 'AssociationFilter.Item',
                            'x-use-component-props': 'useAssociationFilterBlockProps',
                            'x-component-props': {
                                fieldNames: {
                                    label: (null === (_cm_getCollection = cm.getCollection(field.target)) || void 0 === _cm_getCollection ? void 0 : _cm_getCollection.getPrimaryKey()) || 'id'
                                }
                            },
                            properties: {}
                        }
                    };
                });
                return children;
            }
        },
        {
            name: 'choicesFields',
            type: 'itemGroup',
            title: '{{t("Choices fields")}}',
            hideIfNoChildren: true,
            useChildren () {
                const optionalList = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_hooks_index_mjs__.useOptionalFieldList)();
                const optionalChildren = optionalList.map((field)=>({
                        name: field.key,
                        title: field.uiSchema.title,
                        Component: 'AssociationFilterDesignerDisplayField',
                        schema: {
                            name: field.name,
                            title: field.uiSchema.title,
                            interface: field.interface,
                            type: 'void',
                            'x-toolbar': 'CollapseItemSchemaToolbar',
                            'x-settings': 'fieldSettings:FilterCollapseItem',
                            'x-component': 'AssociationFilter.Item',
                            'x-use-component-props': 'useAssociationFilterBlockProps',
                            'x-component-props': {
                                fieldNames: {
                                    label: field.name
                                }
                            },
                            properties: {}
                        }
                    }));
                return optionalChildren;
            }
        }
    ]
});
export { associationFilterFilterBlockInitializer, filterCollapseItemInitializer };
