"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BMHEventsModal = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const react_table_1 = require("@patternfly/react-table");
const common_1 = require("../../../common");
const hooks_1 = require("../../hooks");
const BMHEventsModal = ({ isOpen, onClose, namespace, bmhName, }) => {
    const { t } = (0, common_1.useTranslation)();
    const [events, loaded, error] = (0, hooks_1.useEvents)({
        namespace: namespace,
        isList: true,
        fieldSelector: `involvedObject.name=${bmhName}`,
    });
    let modalBody;
    if (!loaded) {
        modalBody = react_1.default.createElement(common_1.LoadingState, null);
    }
    else if (error) {
        modalBody = react_1.default.createElement(react_core_1.Content, { component: react_core_1.ContentVariants.p }, error);
    }
    else if (!events.length) {
        modalBody = react_1.default.createElement(react_core_1.Content, { component: react_core_1.ContentVariants.p }, t('ai:No BMH events found.'));
    }
    else {
        modalBody = (react_1.default.createElement("div", { style: { height: '400px' } },
            react_1.default.createElement(react_table_1.InnerScrollContainer, null,
                react_1.default.createElement(react_table_1.Table, { variant: "compact", borders: false, className: "pf-v6-u-mb-sm", gridBreakPoint: "", isStickyHeader: true },
                    react_1.default.createElement(react_table_1.Thead, null,
                        react_1.default.createElement(react_table_1.Tr, null,
                            react_1.default.createElement(react_table_1.Th, { width: 25 }, t('ai:Time')),
                            react_1.default.createElement(react_table_1.Th, null, t('ai:Type')),
                            react_1.default.createElement(react_table_1.Th, null, t('ai:Message')))),
                    react_1.default.createElement(react_table_1.Tbody, null, events
                        .sort((a, b) => {
                        var _a, _b, _c;
                        return ((_b = (_a = b.metadata) === null || _a === void 0 ? void 0 : _a.creationTimestamp) === null || _b === void 0 ? void 0 : _b.localeCompare(((_c = a.metadata) === null || _c === void 0 ? void 0 : _c.creationTimestamp) || '')) || 0;
                    })
                        .map((e, i) => {
                        var _a;
                        return (react_1.default.createElement(react_table_1.Tr, { key: `bmc-event-${i}` },
                            react_1.default.createElement(react_table_1.Td, { className: "pf-v6-u-font-weight-bold" }, (0, common_1.getHumanizedDateTime)((_a = e.metadata) === null || _a === void 0 ? void 0 : _a.creationTimestamp)),
                            react_1.default.createElement(react_table_1.Td, null, e.type),
                            react_1.default.createElement(react_table_1.Td, null, e.message)));
                    }))))));
    }
    return (react_1.default.createElement(react_core_1.Modal, { isOpen: isOpen, onClose: onClose, variant: react_core_1.ModalVariant.medium },
        react_1.default.createElement(react_core_1.ModalHeader, { title: t('ai:Bare metal host events') }),
        react_1.default.createElement(react_core_1.ModalBody, null, modalBody)));
};
exports.BMHEventsModal = BMHEventsModal;
//# sourceMappingURL=BMHEventsModal.js.map