"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AITableMemo = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_table_1 = require("@patternfly/react-table");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
require("./HostsTable.css");
exports.AITableMemo = react_1.default.memo(({ rows, cols, onCollapse, className, variant, onSort, sortBy, testId }) => {
    const getSortParams = (columnIndex) => ({
        sortBy,
        onSort,
        columnIndex,
    });
    return (react_1.default.createElement(react_table_1.InnerScrollContainer, null,
        react_1.default.createElement(react_table_1.Table, { "aria-label": "Hosts table", className: (0, classnames_1.default)(className, 'hosts-table'), "data-testid": testId, variant: variant },
            react_1.default.createElement(react_table_1.Thead, null,
                react_1.default.createElement(react_table_1.Tr, null,
                    onCollapse && react_1.default.createElement(react_table_1.Th, null),
                    cols.map((col, i) => (react_1.default.createElement(react_table_1.Th, Object.assign({ key: `col-${i}` }, col.props, { sort: col.sort ? getSortParams(i) : undefined }), col.title)))),
                react_1.default.createElement(react_table_1.Tr, { isBorderRow: true })),
            react_1.default.createElement(react_table_1.Tbody, null, rows.map((row, i) => {
                var _a;
                return (react_1.default.createElement(react_1.default.Fragment, { key: `row-wrapper-${i}` },
                    react_1.default.createElement(react_table_1.Tr, { key: `row-${i}`, "data-testid": `host-row-${Number(i)}` },
                        row.nestedComponent && (react_1.default.createElement(react_table_1.Td, { expand: {
                                rowIndex: i,
                                isExpanded: !!row.isOpen,
                                onToggle: onCollapse,
                            } })),
                        row.cells.map((cell, j) => (react_1.default.createElement(react_table_1.Td, Object.assign({ key: `cell-${i}-${j}` }, cell.props), cell.title))),
                        !!((_a = row.actions) === null || _a === void 0 ? void 0 : _a.length) && (react_1.default.createElement(react_table_1.Td, { isActionCell: true },
                            react_1.default.createElement(react_table_1.ActionsColumn, { items: row.actions, popperProps: { appendTo: () => document.body, position: 'end' } })))),
                    row.nestedComponent && (react_1.default.createElement(react_table_1.Tr, { key: `nested-row-${i}`, isExpanded: row.isOpen },
                        react_1.default.createElement(react_table_1.Td, { colSpan: Object.keys(cols).length + 1 },
                            react_1.default.createElement(react_table_1.ExpandableRowContent, null, row.nestedComponent))))));
            })))));
});
exports.AITableMemo.displayName = 'tableMemo';
//# sourceMappingURL=AITableMemo.js.map