import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { createSelector } from "@reduxjs/toolkit";
import { FormattedMessage, defineMessage } from "react-intl";
import { Message } from "@gooddata/sdk-ui-kit";
import { useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { selectIsNewDashboard } from "../../../model/store/meta/metaSelectors.js";
import { selectIsInEditMode } from "../../../model/store/renderMode/renderModeSelectors.js";
import { selectDateFilterConfigValidationWarnings } from "../../../model/store/tabs/dateFilterConfig/dateFilterConfigSelectors.js";
const workspaceValidationMessagesMapping = {
    ConflictingIdentifiers: defineMessage({ id: "filters.config.warning.conflictingIdentifiers" }),
    NO_CONFIG: defineMessage({ id: "filters.config.warning.workspace.notAvailable" }),
    NoVisibleOptions: defineMessage({ id: "filters.config.warning.allOptionsHidden" }),
    SelectedOptionInvalid: defineMessage({ id: "filters.config.warning.selectedFilterNotValid" }),
    TOO_MANY_CONFIGS: defineMessage({ id: "filters.config.warning.multipleWorkspacesConfigs" }),
};
// Some warnings make sense only when creating a new dashboard, for existing dashboards they are irrelevant
// because existing dashboard just has some option selected anyway.
const validationsRelevantToNewDashboardOnly = new Set([
    "NoVisibleOptions",
    "SelectedOptionInvalid",
]);
const selectRelevantWarnings = createSelector(selectDateFilterConfigValidationWarnings, selectIsNewDashboard, (warnings, isNew) => {
    return isNew
        ? warnings
        : warnings.filter((warning) => !validationsRelevantToNewDashboardOnly.has(warning));
});
export function DateFilterConfigWarnings() {
    const isInEditMode = useDashboardSelector(selectIsInEditMode);
    const warnings = useDashboardSelector(selectRelevantWarnings);
    return isInEditMode && warnings.length > 0 ? (_jsx(Message, { type: "warning", contrast: true, className: "gd-date-filter-config-warning-message", children: _jsx("ul", { className: "gd-date-filter-config-warning-message-items", children: warnings.map((warning) => {
                const message = workspaceValidationMessagesMapping[warning];
                if (message) {
                    return (_jsx("li", { children: _jsx(FormattedMessage, { id: message.id }) }, warning));
                }
                return null;
            }) }) })) : null;
}
