function shouldDisplayInputForFacetRange(facetRange) {
    const { hasInput, hasInputRange, searchStatusState, facetValues } = facetRange;
    if (!hasInput) return false;
    if (hasInputRange) return true;
    if (!searchStatusState.hasResults) return false;
    const onlyValuesWithResultsOrActive = facetValues.filter((value)=>value.numberOfResults || 'idle' !== value.state) || [];
    if (!onlyValuesWithResultsOrActive.length) return false;
    return true;
}
function sortFacetVisibility(facetElements, facetInfoMap) {
    const visibleFacets = [];
    const invisibleFacets = [];
    facetElements.forEach((facet)=>{
        if (facetInfoMap[facet.facetId] && facetInfoMap[facet.facetId].isHidden()) invisibleFacets.push(facet);
        else visibleFacets.push(facet);
    });
    return {
        visibleFacets,
        invisibleFacets
    };
}
function collapseFacetsAfter(facets, visibleFacetsCount) {
    if (-1 === visibleFacetsCount) return;
    facets.forEach((facet, index)=>{
        facet.isCollapsed = index + 1 > visibleFacetsCount;
    });
}
function isAutomaticFacetGenerator(element) {
    return 'ATOMIC-AUTOMATIC-FACET-GENERATOR' === element.tagName;
}
function isPseudoFacet(el) {
    return 'facetId' in el;
}
function getFacetsInChildren(parent) {
    const facets = Array.from(parent.children).filter((child)=>isPseudoFacet(child));
    return facets;
}
function getAutomaticFacetGenerator(parent) {
    return Array.from(parent.children).find(isAutomaticFacetGenerator);
}
function findFacetParent(facet, parents) {
    for(let i = 0; i < parents.length; i++)if (parents[i]?.contains(facet)) return parents[i];
    return null;
}
function triageFacetsByParents(facets, ...parents) {
    const sortedFacets = new Map(parents.concat([
        null
    ]).map((parent)=>[
            parent,
            []
        ]));
    for (const facet of facets){
        const parent = findFacetParent(facet, parents);
        sortedFacets.get(parent).push(facet);
    }
    return sortedFacets;
}
export { collapseFacetsAfter, getAutomaticFacetGenerator, getFacetsInChildren, isAutomaticFacetGenerator, shouldDisplayInputForFacetRange, sortFacetVisibility, triageFacetsByParents };
