import { UMB_MEMBER_PICKER_MODAL, } from '../member-picker-modal/member-picker-modal.token.js';
import { UMB_MEMBER_ITEM_REPOSITORY_ALIAS, UMB_MEMBER_SEARCH_PROVIDER_ALIAS } from '../../constants.js';
import { UmbPickerInputContext } from '../../../../core/picker-input/index.js';
export class UmbMemberPickerInputContext extends UmbPickerInputContext {
    constructor(host) {
        super(host, UMB_MEMBER_ITEM_REPOSITORY_ALIAS, UMB_MEMBER_PICKER_MODAL);
    }
    async openPicker(pickerData, args) {
        const combinedPickerData = {
            ...pickerData,
        };
        // combine internal allowedContentTypes filter with user-supplied pickableFilter
        combinedPickerData.pickableFilter = this._combinePickableFilters((item) => this.#pickableFilter(item, args?.allowedContentTypes), pickerData?.pickableFilter);
        // set default search data
        if (!pickerData?.search) {
            combinedPickerData.search = {
                providerAlias: UMB_MEMBER_SEARCH_PROVIDER_ALIAS,
                ...pickerData?.search,
            };
        }
        // pass allowedContentTypes to the search request args
        combinedPickerData.search.queryParams = {
            allowedContentTypes: args?.allowedContentTypes,
            ...pickerData?.search?.queryParams,
        };
        await super.openPicker(combinedPickerData);
    }
    #pickableFilter = (item, allowedContentTypes) => {
        if (allowedContentTypes && allowedContentTypes.length > 0) {
            return allowedContentTypes
                .map((contentTypeReference) => contentTypeReference.unique)
                .includes(item.memberType.unique);
        }
        return true;
    };
}
