// (C) 2021-2025 GoodData Corporation
import { uniqBy } from "lodash-es";
import { isDashboardAttributeFilter, objRefToString, } from "@gooddata/sdk-model";
export function preloadAttributeFiltersData(ctx, dashboard) {
    const { backend, workspace } = ctx;
    const dashboardAttributeFilterRefs = dashboard?.filterContext?.filters
        .filter(isDashboardAttributeFilter)
        .map((filter) => filter.attributeFilter.displayForm);
    const tabsAttributeFilterRefs = dashboard?.tabs?.reduce((acc, tab) => {
        const refs = tab.filterContext?.filters
            .filter(isDashboardAttributeFilter)
            .map((filter) => filter.attributeFilter.displayForm);
        return [...acc, ...(refs ?? [])];
    }, []);
    const allRefs = [...(dashboardAttributeFilterRefs ?? []), ...(tabsAttributeFilterRefs ?? [])];
    // Remove duplicates by comparing ObjRef string representations
    const uniqueRefs = uniqBy(allRefs, objRefToString);
    if (!uniqueRefs?.length) {
        return Promise.resolve([]);
    }
    return backend.workspace(workspace).attributes().getAttributesWithReferences(uniqueRefs);
}
//# sourceMappingURL=preloadAttributeFiltersData.js.map