// (C) 2023-2026 GoodData Corporation
import { areObjRefsEqual } from "@gooddata/sdk-model";
import { useDashboardSelector } from "../../model/react/DashboardStoreProvider.js";
import { selectDateFilterConfigOverrides, selectDateFilterConfigOverridesByTab, } from "../../model/store/tabs/dateFilterConfig/dateFilterConfigSelectors.js";
import { selectDateFilterConfigsOverrides, selectDateFilterConfigsOverridesByTab, } from "../../model/store/tabs/dateFilterConfigs/dateFilterConfigsSelectors.js";
export const useCurrentDateFilterConfig = (dateDataSet, defaultDateFilterTitle, tabId) => {
    // Use tab-specific selectors when tabId is provided
    const dateFilterConfigOverridesByTab = useDashboardSelector(selectDateFilterConfigOverridesByTab);
    const dateFilterConfigOverridesFromActiveTab = useDashboardSelector(selectDateFilterConfigOverrides);
    const filterConfig = tabId
        ? dateFilterConfigOverridesByTab[tabId]
        : dateFilterConfigOverridesFromActiveTab;
    const dateFilterConfigsOverridesByTab = useDashboardSelector(selectDateFilterConfigsOverridesByTab);
    const dateFilterConfigsOverridesFromActiveTab = useDashboardSelector(selectDateFilterConfigsOverrides);
    const filterConfigByDimension = tabId
        ? (dateFilterConfigsOverridesByTab[tabId] ?? [])
        : dateFilterConfigsOverridesFromActiveTab;
    const usedConfig = dateDataSet
        ? filterConfigByDimension.find((config) => areObjRefsEqual(config.dateDataSet, dateDataSet))?.config
        : filterConfig;
    const originalTitle = !usedConfig || usedConfig?.filterName === "" ? defaultDateFilterTitle : usedConfig?.filterName;
    return {
        mode: usedConfig?.mode ?? "active",
        title: originalTitle,
    };
};
//# sourceMappingURL=useCurrentDateFilterConfig.js.map