"use strict";
var __extends = (this && this.__extends) || (function () {
    var 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 function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var get = require("lodash/get");
var isEqual = require("lodash/isEqual");
var isFunction = require("lodash/isFunction");
var map = require("lodash/map");
var React = require("react");
var renderField = function (row, column) {
    var value = get(row, column.field);
    if (column.render) {
        return column.render(value, row);
    }
    return value == null ? '' : value;
};
var TableRow = (function (_super) {
    __extends(TableRow, _super);
    function TableRow() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    TableRow.prototype.shouldComponentUpdate = function (nextProps) {
        var update = !isEqual(nextProps, this.props);
        return update;
    };
    TableRow.prototype.render = function () {
        var _this = this;
        var _a = this.props, attributes = _a.attributes, checkboxAttributes = _a.checkboxAttributes, columns = _a.columns, className = _a.className, data = _a.data, href = _a.href, keyAttribute = _a.keyAttribute, isChecked = _a.isChecked, isHighlighted = _a.isHighlighted, showCheck = _a.showCheck;
        return (React.createElement("div", { "data-display": "table-row", "data-highlight": isChecked || isHighlighted, className: className },
            showCheck && (React.createElement("span", { "data-display": "table-cell" },
                React.createElement("input", __assign({ checked: isChecked, "data-key": keyAttribute, onChange: this.props.toggleChecked }, checkboxAttributes, { type: "checkbox" })))),
            map(columns, function (column) {
                var cellAttributes = isFunction(column.cellAttributes)
                    ? column.cellAttributes(data, get(data, column.field))
                    : column.cellAttributes || {};
                return (React.createElement("a", __assign({}, attributes, { href: href, "data-display": "table-cell", "data-key": keyAttribute, onClick: _this.props.onRowClick }, cellAttributes, { key: column.field }), renderField(data, column)));
            })));
    };
    return TableRow;
}(React.Component));
exports.TableRow = TableRow;
