// (C) 2020-2026 GoodData Corporation
import { getAutomationVisualizationFilters } from "../../../_staging/automation/index.js";
import { selectCrossFilteringItems } from "../../store/drill/drillSelectors.js";
import { useDashboardSelector } from "../DashboardStoreProvider.js";
import { useWidgetFilters } from "../useWidgetFilters.js";
import { sanitizeWidgetFilters } from "./shared.js";
/**
 * Returns filters for widget scheduled export.
 *
 * - In case of existing scheduled export, it returns the saved filters from the scheduled export.
 * - Otherwise, it returns the filters ready to be saved in new scheduled export, sanitized according to the following rules:
 *     - Cross-filtering filters are excluded as they are typically not desired in the scheduled export.
 *     - The widget's ignored filters configuration is honored.
 *
 * @deprecated - can be removed, once `enableAutomationFilterContext` is removed
 * @alpha
 */
export function useWidgetScheduledExportFilters({ scheduledExportToEdit, widget, insight, }) {
    const newScheduledExportFiltersQuery = useFiltersForNewWidgetScheduledExport(widget, insight);
    const { executionFilters: existingWidgetScheduledExportFilters } = getAutomationVisualizationFilters(scheduledExportToEdit);
    if (existingWidgetScheduledExportFilters) {
        return {
            result: existingWidgetScheduledExportFilters,
            error: undefined,
            status: "success",
        };
    }
    return newScheduledExportFiltersQuery;
}
/**
 * @internal
 */
function useFiltersForNewWidgetScheduledExport(widget, insight) {
    const widgetFiltersQuery = useWidgetFilters(widget, insight);
    const { result: widgetFilters, status: widgetFiltersStatus } = widgetFiltersQuery;
    const crossFilteringItems = useDashboardSelector(selectCrossFilteringItems);
    const sanitizedWidgetFilters = widgetFilters
        ? sanitizeWidgetFilters(widgetFilters, crossFilteringItems)
        : undefined;
    if (widgetFiltersStatus === "success" && sanitizedWidgetFilters) {
        return {
            result: sanitizedWidgetFilters,
            error: undefined,
            status: "success",
        };
    }
    return widgetFiltersQuery;
}
//# sourceMappingURL=useWidgetScheduledExportFilters.js.map