import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2021-2026 GoodData Corporation
import { useCallback, useMemo } from "react";
import { defineMessages, useIntl } from "react-intl";
import { useDashboardDispatch, useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { selectIsInExportMode } from "../../../model/store/renderMode/renderModeSelectors.js";
import { uiActions } from "../../../model/store/ui/index.js";
import { selectFilterValidationIncompatibleDefaultFiltersOverride } from "../../../model/store/ui/uiSelectors.js";
const commonReplacements = {
    b: (chunks) => _jsx("b", { children: chunks }),
    i: (chunks) => _jsx("i", { children: chunks }),
};
const localizationMessages = defineMessages({
    invalidDrillTitle: { id: "messages.dashboard.incompatibleDefaultFilters.title" },
});
const INCOMPATIBLE_DEFAULT_FILTERS_MESSAGE_ID = "incompatible_default_filters_message";
export function useFilterContextValidationMessages() {
    const intl = useIntl();
    const dispatch = useDashboardDispatch();
    const incompatibleDefaultFiltersOverride = useDashboardSelector(selectFilterValidationIncompatibleDefaultFiltersOverride);
    const isExportMode = useDashboardSelector(selectIsInExportMode);
    const messages = useMemo(() => {
        if (!incompatibleDefaultFiltersOverride || isExportMode) {
            return [];
        }
        return [
            {
                id: INCOMPATIBLE_DEFAULT_FILTERS_MESSAGE_ID,
                type: "warning",
                node: intl.formatMessage(localizationMessages.invalidDrillTitle, commonReplacements),
                createdAt: new Date().getTime(),
                duration: Infinity,
            },
        ];
    }, [incompatibleDefaultFiltersOverride, isExportMode, intl]);
    const removeMessage = useCallback((id) => {
        if (id === INCOMPATIBLE_DEFAULT_FILTERS_MESSAGE_ID) {
            dispatch(uiActions.resetIncompatibleDefaultFiltersOverrideMessage());
        }
    }, [dispatch]);
    const removeAllMessages = useCallback(() => {
        dispatch(uiActions.resetIncompatibleDefaultFiltersOverrideMessage());
    }, [dispatch]);
    return {
        messages,
        removeMessage,
        removeAllMessages,
    };
}
//# sourceMappingURL=useFilterContextValidationMessages.js.map