// (C) 2020-2026 GoodData Corporation
import { isLocalIdRef, } from "@gooddata/sdk-model";
import { sourceInsightFilterObjRef as getSourceInsightFilterObjRef } from "../../../../../../_staging/drills/drillingUtils.js";
import { canTransferAttributeFilterByDisplayForm, getDateDatasetTitle, getDisabledOptionProps, getDisabledOptionPropsForTransferResult, getDisplayFormTitle, hasMatchingTargetDashboardDateFilter, sourceFilterOptionId, } from "../drillFiltersConfigUtils.js";
import { messages } from "../messages.js";
export function mapSourceMeasureFilterToOption({ sourceMeasureFilter, allCatalogDisplayFormsMap, allCatalogDateDatasets, targetDashboardFilters, targetDashboardAttributeFilters, targetDashboardTextAttributeFilters, targetDashboardAttributeFilterConfigs, isDrillToDashboard, intl, }) {
    const sourceFilterObjRef = getSourceInsightFilterObjRef(sourceMeasureFilter);
    if (!sourceFilterObjRef) {
        return undefined;
    }
    if (sourceFilterObjRef.type === "attributeFilter") {
        const displayFormRef = sourceFilterObjRef.label;
        if (isLocalIdRef(displayFormRef)) {
            return undefined;
        }
        // Measure filters are always list-type attribute filters (from execution model)
        const transferResult = canTransferAttributeFilterByDisplayForm(displayFormRef, false, // measure filters are list-type
        targetDashboardAttributeFilters, targetDashboardAttributeFilterConfigs, targetDashboardTextAttributeFilters);
        return {
            id: sourceFilterOptionId(sourceFilterObjRef),
            title: getDisplayFormTitle({
                displayFormRef,
                allCatalogDisplayFormsMap,
            }),
            ...getDisabledOptionPropsForTransferResult(isDrillToDashboard, transferResult, intl),
            sourceMeasureFilterObjRef: sourceFilterObjRef,
        };
    }
    if (sourceFilterObjRef.type === "dateFilter") {
        const dateDatasetRef = sourceFilterObjRef.dataSet;
        if (isLocalIdRef(dateDatasetRef)) {
            return undefined;
        }
        const hasMatchingTargetDateFilter = hasMatchingTargetDashboardDateFilter(dateDatasetRef, targetDashboardFilters);
        return {
            id: sourceFilterOptionId(sourceFilterObjRef),
            title: getDateDatasetTitle({
                datasetRef: dateDatasetRef,
                allCatalogDateDatasets,
            }),
            ...getDisabledOptionProps(isDrillToDashboard && !hasMatchingTargetDateFilter, intl.formatMessage(messages.drillToDashboardDashboardFilterTooltip), false),
            sourceMeasureFilterObjRef: sourceFilterObjRef,
        };
    }
    return undefined;
}
//# sourceMappingURL=mapSourceMeasureFilterToOption.js.map