// (C) 2020-2026 GoodData Corporation
import { filterIsEmpty, filterLocalIdentifier, isAttributeFilter, isNoopAllTimeDateFilter, } from "@gooddata/sdk-model";
/**
 * @internal
 */
function removeCrossFilteringFilters(filters, crossFilteringItems) {
    const crossFilteringFilterLocalIdentifiers = crossFilteringItems.flatMap((c) => c.filterLocalIdentifiers);
    return filters.filter((f) => {
        const filterLocalId = filterLocalIdentifier(f);
        return filterLocalId ? !crossFilteringFilterLocalIdentifiers.includes(filterLocalId) : true;
    });
}
/**
 * @internal
 */
export function sanitizeWidgetFilters(filters, crossFilteringItems) {
    const withoutCrossFiltering = removeCrossFilteringFilters(filters, crossFilteringItems);
    const withoutAllTimeDateFilters = removeAllTimeDateFilters(withoutCrossFiltering);
    return removeEmptyAttributeFilters(withoutAllTimeDateFilters);
}
/**
 * @internal
 */
function removeEmptyAttributeFilters(filters) {
    return filters.filter((f) => {
        if (isAttributeFilter(f)) {
            return !filterIsEmpty(f);
        }
        return true;
    });
}
/**
 * @internal
 * @returns
 */
function removeAllTimeDateFilters(filters) {
    return filters.filter((f) => !isNoopAllTimeDateFilter(f));
}
//# sourceMappingURL=shared.js.map