// (C) 2020-2026 GoodData Corporation
import { areObjRefsEqual, } from "@gooddata/sdk-model";
export function findDashboardAttributeFilterByDisplayForm(dashboardAttributeFilters, displayForm) {
    return dashboardAttributeFilters.find((dashboardFilter) => areObjRefsEqual(dashboardFilter.attributeFilter.displayForm, displayForm));
}
export function findDashboardAttributeFilterByAttributeDisplayForms(dashboardAttributeFilters, attributeDisplayForms) {
    for (const displayForm of attributeDisplayForms) {
        const matchingDashboardFilter = findDashboardAttributeFilterByDisplayForm(dashboardAttributeFilters, displayForm.ref);
        if (matchingDashboardFilter) {
            return matchingDashboardFilter;
        }
    }
    return undefined;
}
export function findDashboardAttributeFilterByIncomingDisplayAsLabel(attributeFilter, attributeFilterConfigs, dashboardAttributeFilters) {
    const filterConfig = attributeFilterConfigs.find((config) => config.localIdentifier === attributeFilter.attributeFilter.localIdentifier);
    if (!filterConfig?.displayAsLabel) {
        return undefined;
    }
    return findDashboardAttributeFilterByDisplayForm(dashboardAttributeFilters, filterConfig.displayAsLabel);
}
export function findDashboardAttributeFilterByTargetDisplayAsLabel(filterRef, dashboardAttributeFilters, dashboardAttributeFilterConfigs) {
    const matchingDashboardFilterConfig = dashboardAttributeFilterConfigs.find((config) => areObjRefsEqual(config.displayAsLabel, filterRef));
    if (!matchingDashboardFilterConfig) {
        return undefined;
    }
    return dashboardAttributeFilters.find((dashboardFilter) => dashboardFilter.attributeFilter.localIdentifier === matchingDashboardFilterConfig.localIdentifier);
}
