"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_core_1 = require("@patternfly/react-core");
const exclamation_triangle_icon_1 = require("@patternfly/react-icons/dist/js/icons/exclamation-triangle-icon");
const helpers_1 = require("../helpers");
const common_1 = require("../common");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const agentStatus_1 = require("../helpers/agentStatus");
const InfraEnvHostsTabAgentsWarning = ({ infraAgents, infraBMHs, }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const agentsBMHNames = infraAgents.reduce((names, agent) => {
        var _a, _b;
        const name = (_b = (_a = agent.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b[common_1.AGENT_BMH_NAME_LABEL_KEY];
        name && names.push(name);
        return names;
    }, []);
    const bmhsWithoutAgents = infraBMHs.filter((bmh) => { var _a; return agentsBMHNames.includes(((_a = bmh.metadata) === null || _a === void 0 ? void 0 : _a.name) || ''); });
    const agentStatuses = (0, agentStatus_1.agentStatus)(t);
    const bmhStatuses = (0, agentStatus_1.bmhStatus)(t);
    const agentStates = infraAgents.map((agent) => (0, helpers_1.getAgentStatus)(agent, agentStatuses, true).status);
    const bmhStates = bmhsWithoutAgents.map((bmh) => (0, helpers_1.getBMHStatus)(bmh, bmhStatuses).state);
    const hostStates = [...agentStates, ...bmhStates];
    const problemStates = [
        'bmh-error',
        'preparing-failed',
        'disconnected-unbound',
        'disconnected',
        'insufficient-unbound',
        'insufficient',
        'cancelled',
        'error',
    ];
    const hostsWithProblemsCount = hostStates.filter(({ key }) => problemStates.includes(key)).length;
    if (hostsWithProblemsCount) {
        return (React.createElement(react_core_1.Tooltip, { content: t('ai:{{count}} host has problems', { count: hostsWithProblemsCount }) },
            React.createElement(react_core_1.Icon, { status: "warning" },
                React.createElement(exclamation_triangle_icon_1.ExclamationTriangleIcon, { className: "infra-env-hosts-tab-title__icon" }))));
    }
    return null;
};
exports.default = InfraEnvHostsTabAgentsWarning;
//# sourceMappingURL=InfraEnvHostsTabAgentsWarning.js.map