// (C) 2020-2026 GoodData Corporation
import { selectCrossFilteringItems } from "../../store/drill/drillSelectors.js";
import { useDashboardSelector } from "../DashboardStoreProvider.js";
import { useWidgetFilters } from "../useWidgetFilters.js";
import { sanitizeWidgetFilters } from "./shared.js";
/**
 * Hook for getting filters for widget alert.
 *
 * Note:
 * - In case of existing widget alert, it returns the saved filters from the widget alert.
 * - Otherwise, it returns the filters ready to be saved in new widget alert, sanitized according to the following rules:
 *     - Cross-filtering filters are excluded as they are typically not desired in the widget alert.
 *     - The widget's ignored filters configuration is honored.
 *
 * @alpha
 * @deprecated - can be removed, once `enableAutomationFilterContext` is removed
 */
export function useWidgetAlertFilters({ alertToEdit, widget, insight, }) {
    const newScheduledExportFiltersQuery = useFiltersForNewWidgetAlert(widget, insight);
    const existingWidgetScheduledExportFilters = alertToEdit?.alert?.execution?.filters;
    if (existingWidgetScheduledExportFilters) {
        return {
            result: existingWidgetScheduledExportFilters,
            error: undefined,
            status: "success",
        };
    }
    return newScheduledExportFiltersQuery;
}
/**
 * @internal
 */
function useFiltersForNewWidgetAlert(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=useWidgetAlertFilters.js.map