// (C) 2024-2026 GoodData Corporation
import { absoluteDateFilterValues, isRelativeDateFilter, relativeDateFilterValues, } from "@gooddata/sdk-model";
import { DateFilterHelpers } from "@gooddata/sdk-ui-filters";
export function translateDateFilter(intl, filter, dateFormat) {
    const metadata = filterMetadata(filter);
    // Keep consistent with `getDateFilterTitleUsingTranslator` in sdk-ui-filters:
    // - Special case for "All time" with excluded empty values.
    // - For included empty values, decorate the base representation.
    // - For "only" empty values, use the dedicated title.
    if (metadata.type === "relative" &&
        metadata.granularity === "ALL_TIME_GRANULARITY" &&
        metadata.emptyValueHandling === "exclude") {
        return intl.formatMessage({ id: "filters.allTime.exceptEmptyValues.title" });
    }
    if (metadata.emptyValueHandling === "only") {
        return intl.formatMessage({ id: "filters.emptyValues.title" });
    }
    const base = metadata.type === "absolute"
        ? DateFilterHelpers.formatAbsoluteDateRange(metadata.from, metadata.to, dateFormat)
        : DateFilterHelpers.formatRelativeDateRange(metadata.from, metadata.to, metadata.granularity, intl, "full", metadata.boundedFilter);
    if (metadata.type === "relative" &&
        metadata.granularity === "ALL_TIME_GRANULARITY" &&
        metadata.emptyValueHandling === "include") {
        return base;
    }
    if (metadata.emptyValueHandling === "include") {
        return intl.formatMessage({ id: "filters.emptyValues.label" }, { title: base });
    }
    return base;
}
function filterMetadata(filter) {
    if (isRelativeDateFilter(filter)) {
        return { ...relativeDateFilterValues(filter), type: "relative" };
    }
    return { ...absoluteDateFilterValues(filter), type: "absolute" };
}
//# sourceMappingURL=dateFilterNaming.js.map