"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNodePoolStatus = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const check_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/check-circle-icon");
const exclamation_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/exclamation-circle-icon");
const in_progress_icon_1 = require("@patternfly/react-icons/dist/js/icons/in-progress-icon");
const helpers_1 = require("../../helpers");
const agentStatus_1 = require("../../helpers/agentStatus");
const getNodePoolStatus = (nodePool, agents, t) => {
    var _a, _b, _c;
    if (!agents.length && nodePool.spec.replicas) {
        return {
            type: 'pending',
            icon: react_1.default.createElement(in_progress_icon_1.InProgressIcon, null),
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            text: t('ai:Pending host assignment'),
        };
    }
    const allAgentStatuses = (0, agentStatus_1.agentStatus)(t);
    const agentStatuses = agents.map((a) => (0, helpers_1.getAgentStatus)(a, allAgentStatuses));
    const hasErrorAgents = agentStatuses.some(({ status }) => status.key === 'error');
    if (hasErrorAgents) {
        return {
            type: 'error',
            icon: (react_1.default.createElement(react_core_1.Icon, { status: "danger" },
                react_1.default.createElement(exclamation_circle_icon_1.ExclamationCircleIcon, null))),
            text: t('ai:Error'),
        };
    }
    const hasWarningAgents = agentStatuses.some(({ status }) => [
        'pending-for-input',
        'insufficient',
        'insufficient-unbound',
        'disconnected-unbound',
        'disconnected',
    ].includes(status.key));
    if (hasWarningAgents) {
        return {
            type: 'warning',
            icon: (react_1.default.createElement(react_core_1.Icon, { status: "warning" },
                react_1.default.createElement(exclamation_circle_icon_1.ExclamationCircleIcon, null))),
            text: t('ai:Warning'),
        };
    }
    return ((_c = (_b = (_a = nodePool.status) === null || _a === void 0 ? void 0 : _a.conditions) === null || _b === void 0 ? void 0 : _b.find(({ type }) => type === 'Ready')) === null || _c === void 0 ? void 0 : _c.status) === 'True'
        ? {
            type: 'ok',
            icon: (react_1.default.createElement(react_core_1.Icon, { status: "success" },
                react_1.default.createElement(check_circle_icon_1.CheckCircleIcon, null))),
            text: t('ai:Ready'),
        }
        : {
            type: 'pending',
            icon: react_1.default.createElement(in_progress_icon_1.InProgressIcon, null),
            text: t('ai:Not ready'),
        };
};
exports.getNodePoolStatus = getNodePoolStatus;
//# sourceMappingURL=status.js.map