"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BMHStatusInfo = 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 pending_icon_1 = require("@patternfly/react-icons/dist/js/icons/pending-icon");
const exclamation_triangle_icon_1 = require("@patternfly/react-icons/dist/js/icons/exclamation-triangle-icon");
const common_1 = require("../../../common");
const BMHEventsModal_1 = require("./BMHEventsModal");
const BMHStatusInfo = ({ bmhStatus, bmh, }) => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
    const { t } = (0, common_1.useTranslation)();
    const [isModalOpen, setModalOpen] = react_1.default.useState(false);
    let alertVariant = react_core_1.AlertVariant.warning;
    if (!!((_a = bmh.status) === null || _a === void 0 ? void 0 : _a.errorMessage)) {
        alertVariant = react_core_1.AlertVariant.danger;
    }
    else if (((_c = (_b = bmh.status) === null || _b === void 0 ? void 0 : _b.provisioning) === null || _c === void 0 ? void 0 : _c.state) === 'provisioned' ||
        ((_e = (_d = bmh.status) === null || _d === void 0 ? void 0 : _d.provisioning) === null || _e === void 0 ? void 0 : _e.state) === 'externally provisioned') {
        alertVariant = react_core_1.AlertVariant.success;
    }
    let icon;
    switch ((_f = bmh.status) === null || _f === void 0 ? void 0 : _f.operationalStatus) {
        case 'OK':
        case 'discovered':
            icon = (react_1.default.createElement(react_core_1.Icon, { status: "success" },
                react_1.default.createElement(check_circle_icon_1.CheckCircleIcon, null)));
            break;
        case 'error':
            icon = (react_1.default.createElement(react_core_1.Icon, { status: "warning" },
                react_1.default.createElement(exclamation_triangle_icon_1.ExclamationTriangleIcon, null)));
            break;
        default:
            icon = react_1.default.createElement(pending_icon_1.PendingIcon, null);
            break;
    }
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Level, null,
            react_1.default.createElement(react_core_1.LevelItem, { className: "pf-v6-u-font-weight-bold" }, t('ai:Bare metal host')),
            react_1.default.createElement(react_core_1.LevelItem, null, (_g = bmh.status) === null || _g === void 0 ? void 0 :
                _g.operationalStatus,
                " ",
                icon)),
        react_1.default.createElement(react_core_1.Alert, { title: bmhStatus.state.title, variant: alertVariant, isInline: true },
            !!((_h = bmh.status) === null || _h === void 0 ? void 0 : _h.errorMessage) && (react_1.default.createElement(react_core_1.Content, { component: react_core_1.ContentVariants.p }, (_j = bmh.status) === null || _j === void 0 ? void 0 : _j.errorMessage)),
            react_1.default.createElement(react_core_1.Level, { hasGutter: true },
                react_1.default.createElement(react_core_1.LevelItem, null,
                    react_1.default.createElement(react_core_1.Button, { variant: react_core_1.ButtonVariant.link, isInline: true, onClick: () => setModalOpen(true) }, t('ai:View BMH events'))),
                react_1.default.createElement(react_core_1.LevelItem, null,
                    react_1.default.createElement(react_core_1.Content, { component: react_core_1.ContentVariants.small },
                        t('ai:Last updated:'),
                        " ",
                        (0, common_1.getHumanizedDateTime)((_k = bmh.status) === null || _k === void 0 ? void 0 : _k.lastUpdated))))),
        isModalOpen && (react_1.default.createElement(BMHEventsModal_1.BMHEventsModal, { isOpen: isModalOpen, onClose: () => setModalOpen(false), namespace: ((_l = bmh.metadata) === null || _l === void 0 ? void 0 : _l.namespace) || '', bmhName: ((_m = bmh.metadata) === null || _m === void 0 ? void 0 : _m.name) || '' }))));
};
exports.BMHStatusInfo = BMHStatusInfo;
//# sourceMappingURL=BMHStatusInfo.js.map