"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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 info_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/info-circle-icon");
const exclamation_triangle_icon_1 = require("@patternfly/react-icons/dist/js/icons/exclamation-triangle-icon");
const exclamation_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/exclamation-circle-icon");
const search_icon_1 = require("@patternfly/react-icons/dist/js/icons/search-icon");
const uiState_1 = require("./uiState");
const utils_1 = require("./utils");
const use_translation_wrapper_1 = require("../../hooks/use-translation-wrapper");
const getEventRowKey = (event) => event.eventTime + event.message;
const getLabelColor = (severity) => {
    switch (severity) {
        case 'info':
            return 'blue';
        case 'warning':
            return 'orange';
        case 'error':
            return 'red';
        case 'critical':
            return 'purple';
    }
};
const getLabelIcon = (severity) => {
    switch (severity) {
        case 'info':
            return react_1.default.createElement(info_circle_icon_1.InfoCircleIcon, null);
        case 'warning':
            return react_1.default.createElement(exclamation_triangle_icon_1.ExclamationTriangleIcon, null);
        case 'error':
        case 'critical':
            return react_1.default.createElement(exclamation_circle_icon_1.ExclamationCircleIcon, null);
    }
};
const EventsList = ({ events, resetFilters }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    if (events.length === 0) {
        return (react_1.default.createElement(uiState_1.EmptyState, { icon: search_icon_1.SearchIcon, title: t('ai:No matching events'), content: t('ai:There are no events that match the current filters. Adjust or clear the filters to view events.'), primaryAction: react_1.default.createElement(react_core_1.Button, { variant: react_core_1.ButtonVariant.primary, onClick: resetFilters, id: "empty-state-cluster-events-clear-filters-button", "data-ouia-id": "button-clear-events-filter" }, t('ai:Clear filters')) }));
    }
    const rows = events.map((event) => ({
        cells: [
            {
                title: (react_1.default.createElement(react_table_1.TableText, { wrapModifier: "fitContent", cellPadding: 0 },
                    react_1.default.createElement(react_core_1.Content, { className: "pf-v6-u-font-weight-bold" }, (0, utils_1.getHumanizedDateTime)(event.eventTime)))),
            },
            {
                title: (react_1.default.createElement(react_table_1.TableText, { wrapModifier: "breakWord" },
                    event.severity !== 'info' && (react_1.default.createElement(react_1.default.Fragment, null,
                        react_1.default.createElement(react_core_1.Label, { color: getLabelColor(event.severity), icon: getLabelIcon(event.severity) }, event.severity),
                        ' ')),
                    event.message.replace(/\\n/, ' '))),
            },
        ],
        props: { event },
    }));
    return (react_1.default.createElement(react_table_1.Table, { variant: react_table_1.TableVariant.compact, "aria-label": t('ai:Events table'), borders: false },
        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, null,
                    react_1.default.createElement(react_table_1.TableText, { wrapModifier: "fitContent", cellPadding: 0 }, t('ai:Time'))),
                react_1.default.createElement(react_table_1.Th, null,
                    react_1.default.createElement(react_table_1.TableText, { wrapModifier: "breakWord" }, t('ai:Message'))))),
        react_1.default.createElement(react_table_1.Tbody, null, rows.map((row, i) => (react_1.default.createElement(react_table_1.Tr, { key: getEventRowKey(row.props.event) }, row.cells.map((cell, j) => (react_1.default.createElement(react_table_1.Td, { key: `cell-${i}-${j}` }, cell.title)))))))));
};
exports.default = EventsList;
//# sourceMappingURL=EventsList.js.map