"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Table2Beta = exports.cssClass = exports.DEFAULT_VISIBLE_PAGE_RANGE_SIZE = void 0;
var classnames = require("classnames");
var _ = require("lodash");
var React = require("react");
var PropTypes = require("prop-types");
var tablePropTypes = require("./tablePropTypes");
var Cell_1 = require("./Cell");
var Column_1 = require("./Column");
var Footer_1 = require("./Footer");
var Header_1 = require("./Header");
var MorePropTypes_1 = require("../utils/MorePropTypes");
var sortDirection_1 = require("./sortDirection");
require("./Table.less");
var Checkbox_1 = require("../Checkbox");
var HeaderCell_1 = require("./HeaderCell");
var SelectedRowsHeader_1 = require("./SelectedRowsHeader");
var Menu_1 = require("../Menu");
var Button_1 = require("../Button/Button");
var DEFAULT_PAGE_SIZE = 10;
exports.DEFAULT_VISIBLE_PAGE_RANGE_SIZE = 5;
var propTypes = {
    children: PropTypes.arrayOf(MorePropTypes_1.default.instanceOfComponent(Column_1.Column)),
    className: PropTypes.string,
    data: PropTypes.array,
    filter: PropTypes.func,
    fixed: PropTypes.bool,
    initialPage: tablePropTypes.pageNumber,
    initialSortState: tablePropTypes.sortState,
    firstSortDirection: tablePropTypes.sortDirection,
    onPageChange: PropTypes.func,
    onRowClick: PropTypes.func,
    onRowMouseOver: PropTypes.func,
    onSortChange: PropTypes.func,
    onViewChange: PropTypes.func,
    pageSize: PropTypes.number,
    paginated: PropTypes.bool,
    visiblePageRangeSize: PropTypes.number,
    rowIDFn: PropTypes.func.isRequired,
    rowClassNameFn: PropTypes.func,
    noDataContent: PropTypes.node,
    selectable: PropTypes.bool,
    checkboxClassName: PropTypes.string,
    singleActions: PropTypes.array,
    singleActionsClassName: PropTypes.string,
    showSingleActionsOnHover: PropTypes.bool,
    // these must all be set together
    lazy: PropTypes.bool,
    getData: PropTypes.func,
    numRows: PropTypes.number,
};
var defaultProps = {
    onPageChange: function () { },
    onSortChange: function () { },
    pageSize: DEFAULT_PAGE_SIZE,
    visiblePageRangeSize: exports.DEFAULT_VISIBLE_PAGE_RANGE_SIZE,
    firstSortDirection: sortDirection_1.default.ASCENDING,
    singleActions: [],
    selectedRowsHeaderActions: [],
    numDisplayedActions: 4,
};
exports.cssClass = {
    BODY: "Table2Beta--body",
    HEADER: "Table2Beta--header",
    CLICKABLE_ROW: "Table2Beta--clickable_row",
    SELECTABLE: "Table2Beta--selectable_row",
    FIXED: "Table2Beta--fixed",
    NO_DATA: "Table2Beta--no_data_cell",
    NO_DATA_CONTENT: "Table2Beta--no_data_cell_with_content",
    ROW: "Table2Beta--row",
    ROW_ODD: "Table2Beta--rowOdd",
    ROW_EVEN: "Table2Beta--rowEven",
    ROW_SELECTED: "Table2Beta--rowSelected",
    SINGLE_ACTIONS: "Table2Beta--singleActions",
    SINGLE_ACTION_TRIGGER: "Table2Beta--singleActionTrigger",
    ACTION_ICON: "Table2Beta--actions--icon",
    ACTION_ICON_CONTAINER: "Table2Beta--actions--iconContainer",
    ACTION_HOVER_ICON: "Table2Beta--actions--hoverIcon",
    ACTION_TITLE: "Table2Beta--actions--title",
    ACTION_MENU: "Table2Beta--actions--menu",
    ACTION_MENU_ITEM: "Table2Beta--actions--menu--item",
    ACTION_MENU_ITEM_TITLE: "Table2Beta--actions--menu--item--title",
    TABLE: "Table2Beta",
    CHECKBOX_HEADER: "Table2Beta--Checkbox--Header",
};
var Table2Beta = /** @class */ (function (_super) {
    __extends(Table2Beta, _super);
    function Table2Beta(props) {
        var _a;
        var _this = _super.call(this, props) || this;
        _this.actionIconAndHoverIcon = function (action) {
            return (React.createElement(React.Fragment, null,
                action.icon && (React.createElement("img", { className: exports.cssClass.ACTION_ICON, src: action.icon, alt: action.title.singular.toString() })),
                action.hoverIcon && (React.createElement("img", { className: exports.cssClass.ACTION_HOVER_ICON, src: action.hoverIcon, alt: action.title.singular.toString() }))));
        };
        if (props.lazy) {
            for (var _i = 0, _b = ["data", "filter", "initialPage", "preselectedRowFn"]; _i < _b.length; _i++) {
                var p = _b[_i];
                if (props[p]) {
                    console.error("Table: prop \"" + p + "\" may not be set if \"lazy\"");
                }
            }
            if (!props.getData) {
                console.error('Table: prop "getData" must be set if "lazy"');
            }
        }
        else {
            if (!props.data) {
                console.error('Table: prop "data" must be set if not "lazy"');
            }
            for (var _c = 0, _d = ["getData", "numRows"]; _c < _d.length; _c++) {
                var p = _d[_c];
                if (props[p]) {
                    console.error("Table: prop \"" + p + "\" may not be set if not \"lazy\"");
                }
            }
        }
        var selectedRows = new Set();
        var allSelected = false;
        if (props.selectable && props.preselectedRowFn && ((_a = props.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
            props.data.forEach(function (d) {
                if (props.preselectedRowFn(d)) {
                    selectedRows.add(d);
                }
            });
            allSelected = selectedRows.size === props.data.length;
        }
        _this.state = {
            currentPage: props.initialPage || 1,
            sortState: props.initialSortState,
            selectedRows: selectedRows,
            allSelected: allSelected,
            allData: new Set(),
            // lazy table state
            lazyPages: [],
            pageLoading: false,
            allLoaded: false,
        };
        // the epoch is incremented on calls to this.lazyReset, so we know to throw
        // out in-progress fetches if the table gets reset (see this._fetchLazy).
        _this._epoch = 0;
        return _this;
    }
    Table2Beta.prototype.componentDidMount = function () {
        this._isMounted = true;
        if (this.props.lazy) {
            this._fetchLazy(0);
        }
    };
    Table2Beta.prototype.componentDidUpdate = function () {
        var _a = this.state, selectedRows = _a.selectedRows, allSelected = _a.allSelected;
        var allRows = this._getDisplayedData().allRows;
        // This occurs when a new external filter is applied.
        // We want selectedRows to change if the filter affects the selection
        var newSelectedRows = new Set(selectedRows);
        newSelectedRows.forEach(function (item) {
            if (!allRows.includes(item)) {
                newSelectedRows.delete(item);
            }
        });
        var newAllSelected = !!(allRows && newSelectedRows.size === allRows.length);
        if (newSelectedRows.size !== selectedRows.size || allSelected !== newAllSelected) {
            // eslint-disable-next-line react/no-did-update-set-state
            this.setState({ selectedRows: newSelectedRows });
            // eslint-disable-next-line react/no-did-update-set-state
            this.setState({ allSelected: newAllSelected });
        }
    };
    Table2Beta.prototype.componentWillUnmount = function () {
        this._isMounted = false;
    };
    /**
     * @param {number} page - 1-based index of the page to select.
     */
    Table2Beta.prototype.setCurrentPage = function (page) {
        return __awaiter(this, void 0, void 0, function () {
            var _a, onPageChange, onViewChange, lazy, _b, currentPage, pageLoading, pageIdx;
            var _this = this;
            return __generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        _a = this.props, onPageChange = _a.onPageChange, onViewChange = _a.onViewChange, lazy = _a.lazy;
                        _b = this.state, currentPage = _b.currentPage, pageLoading = _b.pageLoading;
                        if (page === currentPage || pageLoading) {
                            return [2 /*return*/];
                        }
                        if (!lazy) return [3 /*break*/, 2];
                        pageIdx = page - 1;
                        return [4 /*yield*/, this._fetchLazy(pageIdx)];
                    case 1:
                        _c.sent();
                        _c.label = 2;
                    case 2:
                        this.setState({ currentPage: page }, function () {
                            onPageChange(page);
                            if (onViewChange) {
                                var displayedData = _this._getDisplayedData().displayedData;
                                onViewChange(displayedData);
                            }
                        });
                        return [2 /*return*/];
                }
            });
        });
    };
    Table2Beta.prototype._fetchLazy = function (pageIdx) {
        return __awaiter(this, void 0, void 0, function () {
            var _a, pageSize, getData, rowIDFn, lazyPages, startEpoch, newPages, idx, query, lastPage, pageData;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = this.props, pageSize = _a.pageSize, getData = _a.getData, rowIDFn = _a.rowIDFn;
                        lazyPages = this.state.lazyPages;
                        // if we've already fetched the page, no need to do anything here -- it's
                        // cached
                        if (pageIdx < lazyPages.length) {
                            return [2 /*return*/];
                        }
                        startEpoch = this._epoch;
                        this.setState({ pageLoading: true });
                        newPages = lazyPages.slice(0);
                        idx = lazyPages.length;
                        _b.label = 1;
                    case 1:
                        if (!(idx <= pageIdx)) return [3 /*break*/, 4];
                        query = { pageSize: pageSize };
                        // the first page shouldn't have a startingAfter parameter
                        if (idx !== 0) {
                            lastPage = newPages[idx - 1];
                            query.startingAfter = rowIDFn(lastPage[lastPage.length - 1]);
                        }
                        return [4 /*yield*/, getData(query)];
                    case 2:
                        pageData = _b.sent();
                        // Check if we should bail out to prevent updating state on an unmounted component.
                        if (!this._isMounted) {
                            return [2 /*return*/];
                        }
                        newPages.push(pageData);
                        _b.label = 3;
                    case 3:
                        idx++;
                        return [3 /*break*/, 1];
                    case 4:
                        if (this._epoch !== startEpoch) {
                            // the table was reset while we were fetching, so we don't want to
                            // actually insert our data
                            return [2 /*return*/];
                        }
                        if (newPages[newPages.length - 1].length < pageSize) {
                            this.setState({ allLoaded: true });
                            if (newPages[newPages.length - 1].length === 0) {
                                // remove the last page if it's empty (this happens if the number of
                                // rows is divisible by the page size)
                                newPages.splice(-1);
                            }
                        }
                        this.setState({ lazyPages: newPages, pageLoading: false });
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Resets all lazily-loaded data. Call this if you change the backing data
     * behind the `getData` function (i.e. apply a search filter).
     */
    Table2Beta.prototype.lazyReset = function () {
        var _this = this;
        if (this.props.lazy) {
            this._epoch++;
            this.setCurrentPage(1);
            this.setState({ lazyPages: [], allLoaded: false }, function () {
                _this._fetchLazy(0);
            });
        }
    };
    Table2Beta.prototype._getColumn = function (columnID) {
        return _.find(React.Children.toArray(this.props.children), function (column) { return column.props.id === columnID; });
    };
    Table2Beta.prototype._toggleSort = function (columnID) {
        var _this = this;
        var oldSortState = this.state.sortState;
        var newSortState = {
            columnID: columnID,
            direction: this.props.firstSortDirection,
        };
        if (oldSortState && oldSortState.columnID === columnID) {
            newSortState.direction =
                oldSortState.direction === sortDirection_1.default.ASCENDING
                    ? sortDirection_1.default.DESCENDING
                    : sortDirection_1.default.ASCENDING;
        }
        // Reset to 1st page since table sort has changed.
        this.setCurrentPage(1);
        this.setState({ sortState: newSortState }, function () {
            _this.props.onSortChange(_this.state.sortState);
            if (_this.props.onViewChange) {
                var displayedData = _this._getDisplayedData().displayedData;
                _this.props.onViewChange(displayedData);
            }
        });
        this.lazyReset();
    };
    Table2Beta.prototype._getSynchronousData = function () {
        var _a = this.props, data = _a.data, filter = _a.filter, pageSize = _a.pageSize, paginated = _a.paginated;
        var _b = this.state, currentPage = _b.currentPage, sortState = _b.sortState;
        var displayedData = _(data);
        if (filter) {
            displayedData = displayedData.filter(filter);
        }
        if (sortState) {
            var sortedColumn_1 = this._getColumn(sortState.columnID);
            // sortedColumn might not exist if a column is removed from the table
            // dynamically. in this case, just ignore the sort state.
            if (sortedColumn_1) {
                displayedData = displayedData.sortBy(function (row) {
                    var value = sortedColumn_1.props.sortValueFn(row);
                    if (typeof value === "string") {
                        value = value.trim().toLowerCase();
                    }
                    return value;
                });
                if (sortState.direction === sortDirection_1.default.DESCENDING) {
                    displayedData = displayedData.reverse();
                }
            }
        }
        displayedData = displayedData.value();
        var pages = [displayedData];
        if (paginated) {
            pages = _.chunk(displayedData, pageSize);
        }
        if (pages.length === 0) {
            // Chunking will return 0 pages if the data array is empty. Since we always show at least one
            // page of (potentially empty) data, add an empty page by default.
            pages = [[]];
        }
        var numPages = pages.length;
        var idx = Math.min(currentPage, numPages) - 1;
        return { displayedData: pages[idx], numPages: numPages, allRows: displayedData };
    };
    Table2Beta.prototype._getLazyData = function () {
        var _a = this.props, numRows = _a.numRows, pageSize = _a.pageSize;
        var _b = this.state, currentPage = _b.currentPage, lazyPages = _b.lazyPages;
        var numPages;
        if (numRows != null) {
            numPages = Math.max(Math.ceil(numRows / pageSize), 1);
        }
        else {
            if (lazyPages.length === 0) {
                numPages = 1;
            }
            else {
                numPages = lazyPages.length;
            }
        }
        var idx = Math.min(currentPage, numPages) - 1;
        if (idx < lazyPages.length) {
            return { displayedData: lazyPages[idx], numPages: numPages };
        }
        return { displayedData: [], numPages: numPages };
    };
    Table2Beta.prototype._getDisplayedData = function () {
        if (!this.props.lazy) {
            return this._getSynchronousData();
        }
        return this._getLazyData();
    };
    Table2Beta.prototype._singleActionsRender = function (rowData) {
        var _this = this;
        var singleActions = this.props.singleActions;
        if (singleActions.length === 1) {
            return (React.createElement(Button_1.Button, { className: singleActions[0].hoverIcon && exports.cssClass.ACTION_ICON_CONTAINER, type: "link", value: React.createElement(React.Fragment, null,
                    this.actionIconAndHoverIcon(singleActions[0]),
                    React.createElement("div", { className: exports.cssClass.ACTION_TITLE }, singleActions[0].title.singular)), onClick: function () { return singleActions[0].callback(rowData); }, size: "small" }));
        }
        else if (singleActions.length >= 2) {
            return (React.createElement(React.Fragment, null,
                React.createElement(Button_1.Button, { className: singleActions[0].hoverIcon && exports.cssClass.ACTION_ICON_CONTAINER, type: "link", value: React.createElement(React.Fragment, null,
                        React.createElement("span", { className: singleActions[0].hoverIcon && exports.cssClass.ACTION_ICON_CONTAINER }, this.actionIconAndHoverIcon(singleActions[0])),
                        React.createElement("div", { className: exports.cssClass.ACTION_TITLE }, singleActions[0].title.singular)), onClick: function () { return singleActions[0].callback(rowData); }, size: "small" }),
                React.createElement(Menu_1.default, { trigger: React.createElement(Button_1.Button, { size: "small", className: exports.cssClass.ACTION_MENU, type: "link" },
                        React.createElement("img", { className: exports.cssClass.SINGLE_ACTION_TRIGGER, src: require("./ellipsis.svg"), 
                            // TODO: alt-texts need to be translated
                            alt: "more actions" })), placement: Menu_1.default.Placement.RIGHT }, singleActions.slice(1).map(function (action) { return (React.createElement(Menu_1.default.Item, { className: classnames(exports.cssClass.ACTION_MENU_ITEM, singleActions[0].hoverIcon && exports.cssClass.ACTION_ICON_CONTAINER), onClick: function (e) { return action.callback(rowData); }, key: "action.title.singular" },
                    React.createElement("div", { className: exports.cssClass.ACTION_MENU_ITEM_TITLE },
                        _this.actionIconAndHoverIcon(action),
                        React.createElement("div", { className: exports.cssClass.ACTION_TITLE }, action.title.singular)))); }))));
        }
        return React.createElement(React.Fragment, null);
    };
    Table2Beta.prototype.render = function () {
        var _this = this;
        var _a = this.props, children = _a.children, className = _a.className, fixed = _a.fixed, paginated = _a.paginated, rowIDFn = _a.rowIDFn, rowClassNameFn = _a.rowClassNameFn, onRowClick = _a.onRowClick, onRowMouseOver = _a.onRowMouseOver, noDataContent = _a.noDataContent, numDisplayedActions = _a.numDisplayedActions, selectable = _a.selectable, checkboxClassName = _a.checkboxClassName, singleActions = _a.singleActions, showSingleActionsOnHover = _a.showSingleActionsOnHover, singleActionsClassName = _a.singleActionsClassName, visiblePageRangeSize = _a.visiblePageRangeSize, selectedRowsHeaderContentType = _a.selectedRowsHeaderContentType, selectedRowsHeaderContentTypeNoSelection = _a.selectedRowsHeaderContentTypeNoSelection, selectedRowsHeaderActions = _a.selectedRowsHeaderActions, disableSelectedRowsHeader = _a.disableSelectedRowsHeader, selectedRowsColumnName = _a.selectedRowsColumnName, onSelect = _a.onSelect;
        var _b = this.props, lazy = _b.lazy, numRows = _b.numRows;
        var _c = this.state, currentPage = _c.currentPage, sortState = _c.sortState, pageLoading = _c.pageLoading, allLoaded = _c.allLoaded;
        var selectedRows = this.state.selectedRows;
        var columns = _.compact(React.Children.toArray(children));
        if (columns.length < 2 && process.env.NODE_ENV !== "production") {
            console.error("Table requires at least 2 columns. Consider using the List component instead.");
        }
        var _d = this._getDisplayedData(), displayedData = _d.displayedData, numPages = _d.numPages, allRows = _d.allRows;
        var displayedPage = Math.min(currentPage, numPages);
        var disableSort = numPages <= 1 && displayedData.length <= 1;
        var numColumns = columns.length;
        // Additional column for selectable checkboxes
        if (selectable) {
            numColumns += 1;
        }
        // Additional column for single actions
        if (singleActions.length > 0) {
            numColumns += 1;
        }
        return (React.createElement(React.Fragment, null,
            selectable && !disableSelectedRowsHeader && (React.createElement(SelectedRowsHeader_1.default, { className: className, selectedRows: selectedRows, contentType: selectedRowsHeaderContentType, contentTypeNoSelection: selectedRowsHeaderContentTypeNoSelection, actions: selectedRowsHeaderActions, numDisplayedActions: numDisplayedActions, allSelected: this.state.allSelected })),
            React.createElement("table", { className: classnames(exports.cssClass.TABLE, fixed && exports.cssClass.FIXED, className) },
                React.createElement("thead", null,
                    React.createElement("tr", { className: exports.cssClass.HEADER },
                        selectable && (React.createElement(HeaderCell_1.default, null,
                            React.createElement(Checkbox_1.default, { checked: selectedRows.size > 0, partial: selectedRows.size < allRows.length, onChange: function (newState) {
                                    if (selectedRows.size === 0) {
                                        selectedRows = new Set(allRows);
                                        _this.setState({ allSelected: true });
                                    }
                                    else {
                                        selectedRows.clear();
                                        _this.setState({ allSelected: false });
                                    }
                                    if (onSelect) {
                                        onSelect(selectedRows);
                                    }
                                    _this.setState({ selectedRows: selectedRows });
                                }, disabled: displayedData.length === 0, className: exports.cssClass.CHECKBOX_HEADER }, selectedRowsColumnName))),
                        React.createElement(Header_1.default, { disableSort: disableSort, onSortChange: function (columnID) { return _this._toggleSort(columnID); }, sortState: sortState, selectable: selectable }, columns),
                        singleActions.length > 0 && (React.createElement(HeaderCell_1.default, null, !showSingleActionsOnHover && "Actions")))),
                React.createElement("tbody", { className: exports.cssClass.BODY }, displayedData.length === 0 ? (React.createElement("tr", { className: exports.cssClass.ROW }, noDataContent ? (React.createElement(Cell_1.default, { className: exports.cssClass.NO_DATA_CONTENT, colSpan: numColumns, noWrap: true }, !pageLoading && noDataContent)) : (React.createElement(Cell_1.default, { className: exports.cssClass.NO_DATA, colSpan: numColumns, noWrap: true }, !pageLoading && "NO DATA")))) : (displayedData.map(function (rowData, index) { return (React.createElement("tr", { className: classnames(exports.cssClass.ROW, index % 2 ? exports.cssClass.ROW_ODD : exports.cssClass.ROW_EVEN, onRowClick && exports.cssClass.CLICKABLE_ROW, selectable && exports.cssClass.SELECTABLE, rowClassNameFn && rowClassNameFn(rowData), selectedRows.has(rowData) && exports.cssClass.ROW_SELECTED), key: rowIDFn(rowData), onClick: function (e) {
                        if (onRowClick) {
                            onRowClick(e, rowIDFn(rowData), rowData);
                        }
                    }, onMouseOver: function (e) {
                        return onRowMouseOver && onRowMouseOver(e, rowIDFn(rowData), rowData);
                    } },
                    selectable && (React.createElement(Cell_1.default, { className: checkboxClassName },
                        React.createElement(Checkbox_1.default, { checked: selectedRows.has(rowData), onChange: function (newState) {
                                if (newState.checked) {
                                    selectedRows.add(rowData);
                                    if (selectedRows.size === (allRows || displayedData).length) {
                                        _this.setState({ allSelected: true });
                                    }
                                }
                                else {
                                    selectedRows.delete(rowData);
                                    _this.setState({ allSelected: false });
                                }
                                if (onSelect) {
                                    onSelect(selectedRows);
                                }
                                _this.setState({ selectedRows: selectedRows });
                            } }, ""))),
                    columns.map(function (_a) {
                        var col = _a.props;
                        return (React.createElement(Cell_1.default, { className: getCellClassName(col, rowData), key: col.id, noWrap: col.noWrap }, col.cell.renderer(rowData)));
                    }),
                    selectable && (React.createElement(Cell_1.default, { noWrap: true, className: singleActionsClassName },
                        React.createElement("div", { className: exports.cssClass.SINGLE_ACTIONS + (showSingleActionsOnHover ? "--hidden" : "") }, _this._singleActionsRender(rowData)))))); }))),
                paginated && (React.createElement(Footer_1.default, { currentPage: displayedPage, onPageChange: function (newPage) { return _this.setCurrentPage(newPage); }, numColumns: numColumns, numPages: numPages, showLastPage: !lazy, visiblePageRangeSize: visiblePageRangeSize, isLoading: pageLoading, lengthUnknown: lazy && numRows == null && !allLoaded })))));
    };
    Table2Beta.propTypes = propTypes;
    Table2Beta.defaultProps = defaultProps;
    Table2Beta.Column = Column_1.Column;
    Table2Beta.sortDirection = sortDirection_1.default;
    return Table2Beta;
}(React.Component));
exports.Table2Beta = Table2Beta;
function getCellClassName(columnProps, rowData) {
    var className = columnProps.cell.className;
    if (typeof className === "function") {
        return className(rowData);
    }
    return className;
}
