"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _get = _interopRequireDefault(require("lodash/get"));

function isInvalidRenderCellText(text) {
  return text && ! /*#__PURE__*/(0, _react.isValidElement)(text) && Object.prototype.toString.call(text) === '[object Object]';
}

var TableCell = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(TableCell, _Component);

  var _super = (0, _createSuper2["default"])(TableCell);

  function TableCell() {
    var _this;

    (0, _classCallCheck2["default"])(this, TableCell);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClick", function (e) {
      var _this$props = _this.props,
          record = _this$props.record,
          onCellClick = _this$props.column.onCellClick;

      if (onCellClick) {
        onCellClick(record, e);
      }
    });
    return _this;
  }

  (0, _createClass2["default"])(TableCell, [{
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          record = _this$props2.record,
          indentSize = _this$props2.indentSize,
          prefixCls = _this$props2.prefixCls,
          indent = _this$props2.indent,
          index = _this$props2.index,
          expandIcon = _this$props2.expandIcon,
          column = _this$props2.column,
          BodyCell = _this$props2.component;
      var dataIndex = column.dataIndex,
          render = column.render,
          _column$className = column.className,
          className = _column$className === void 0 ? '' : _column$className,
          style = column.style; // We should return undefined if no dataIndex is specified, but in order to
      // be compatible with object-path's behavior, we return the record object instead.

      var text;

      if (typeof dataIndex === 'number') {
        text = (0, _get["default"])(record, dataIndex);
      } else if (!dataIndex || dataIndex.length === 0) {
        text = record;
      } else {
        text = (0, _get["default"])(record, dataIndex);
      }

      var tdProps = {
        tabIndex: -1
      };
      var colSpan;
      var rowSpan;

      if (render) {
        text = render(text, record, index);

        if (isInvalidRenderCellText(text)) {
          tdProps = text.props || tdProps;
          colSpan = tdProps.colSpan;
          rowSpan = tdProps.rowSpan;
          text = text.children;
        }
      }

      if (column.onCell) {
        tdProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, tdProps), column.onCell(record, column));
      }

      if (isInvalidRenderCellText(text)) {
        text = null;
      }

      var indentText = expandIcon ? /*#__PURE__*/_react["default"].createElement("span", {
        style: {
          paddingLeft: "".concat(indentSize * indent, "px")
        },
        className: "".concat(prefixCls, "-indent indent-level-").concat(indent)
      }) : null;

      if (rowSpan === 0 || colSpan === 0) {
        return null;
      }

      if (column.align) {
        tdProps.style = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, tdProps.style), {}, {
          textAlign: column.align
        });
      }

      return /*#__PURE__*/_react["default"].createElement(BodyCell, (0, _extends2["default"])({
        onClick: this.handleClick
      }, tdProps, {
        style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), tdProps.style),
        className: (0, _classnames["default"])(className, tdProps.className)
      }), indentText, expandIcon, text);
    }
  }]);
  return TableCell;
}(_react.Component);

exports["default"] = TableCell;
//# sourceMappingURL=TableCell.js.map
