"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var Utilities_1 = require("../../Utilities");
var stylesImport = require("./DetailsRow.scss");
var styles = stylesImport;
var INNER_PADDING = 16; // Account for padding around the cell.
var ISPADDED_WIDTH = 24;
var DetailsRowFields = /** @class */ (function (_super) {
    tslib_1.__extends(DetailsRowFields, _super);
    function DetailsRowFields(props) {
        var _this = _super.call(this, props) || this;
        _this.state = _this._getState(props);
        return _this;
    }
    DetailsRowFields.prototype.componentWillReceiveProps = function (newProps) {
        this.setState(this._getState(newProps));
    };
    DetailsRowFields.prototype.render = function () {
        var _a = this.props, columns = _a.columns, columnStartIndex = _a.columnStartIndex;
        var cellContent = this.state.cellContent;
        return (React.createElement("div", { className: Utilities_1.css('ms-DetailsRow-fields', styles.fields), "data-automationid": 'DetailsRowFields', role: 'presentation' }, columns.map(function (column, columnIndex) { return (React.createElement("div", { key: columnIndex, role: column.isRowHeader ? 'rowheader' : 'gridcell', "aria-colindex": columnIndex + columnStartIndex, className: Utilities_1.css('ms-DetailsRow-cell', styles.cell, column.className, column.isMultiline && 'is-multiline', column.isRowHeader && styles.isRowHeader, column.isPadded && styles.isPadded, column.isMultiline && styles.isMultiline), style: { width: column.calculatedWidth + INNER_PADDING + (column.isPadded ? ISPADDED_WIDTH : 0) }, "data-automationid": 'DetailsRowCell', "data-automation-key": column.key }, cellContent[columnIndex])); })));
    };
    DetailsRowFields.prototype._getState = function (props) {
        var _this = this;
        var item = props.item, itemIndex = props.itemIndex, onRenderItemColumn = props.onRenderItemColumn;
        return {
            cellContent: props.columns.map(function (column) {
                var cellContent;
                try {
                    var render = column.onRender || onRenderItemColumn;
                    cellContent = render ? render(item, itemIndex, column) : _this._getCellText(item, column);
                }
                catch (e) { }
                return cellContent;
            })
        };
    };
    DetailsRowFields.prototype._getCellText = function (item, column) {
        var value = (item && column && column.fieldName) ? item[column.fieldName] : '';
        if (value === null || value === undefined) {
            value = '';
        }
        return value;
    };
    return DetailsRowFields;
}(Utilities_1.BaseComponent));
exports.DetailsRowFields = DetailsRowFields;
//# sourceMappingURL=DetailsRowFields.js.map