import { deepEqual } from '../../utils/compare-utils.js';
export function getQ(section, querySelector, initialState) {
    if (section === undefined) {
        return {};
    }
    const q = querySelector(section);
    const shouldInclude = q !== initialState;
    return shouldInclude ? { q } : {};
}
export function getSortCriteria(section, sortCriteriaSelector, initialState) {
    if (section === undefined) {
        return {};
    }
    const sortCriteria = sortCriteriaSelector(section);
    const shouldInclude = !deepEqual(sortCriteria, initialState);
    return shouldInclude ? { sortCriteria } : {};
}
export function getFacets(section, facetIsEnabled, valuesSelector, out) {
    if (section === undefined) {
        return {};
    }
    const facets = Object.entries(section)
        .filter(([facetId]) => facetIsEnabled(facetId))
        .map(([facetId, { request }]) => {
        const selectedValues = valuesSelector(request);
        return selectedValues.length ? { [facetId]: selectedValues } : {};
    })
        // oxlint-disable-next-line oxc/no-accumulating-spread -- <>
        .reduce((acc, obj) => ({ ...acc, ...obj }), {});
    return Object.keys(facets).length ? { [out]: facets } : {};
}
export function getTab(section, tabSelector, initialState) {
    if (section === undefined) {
        return {};
    }
    const tab = tabSelector(section);
    const shouldInclude = tab !== initialState;
    return shouldInclude ? { tab } : {};
}
