function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import RowComponent from './row';
import CellComponent from './cell';

var noop = function noop() {};

var Body =
/*#__PURE__*/
function (_React$Component) {
  _inherits(Body, _React$Component);

  function Body() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, Body);

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

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Body)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_this), "getRowRef", function (i, row) {
      _this.props.rowRef(i, row);
    });

    _defineProperty(_assertThisInitialized(_this), "onRowClick", function (record, index, e) {
      _this.props.onRowClick(record, index, e);
    });

    _defineProperty(_assertThisInitialized(_this), "onRowMouseEnter", function (record, index, e) {
      _this.props.onRowMouseEnter(record, index, e);
    });

    _defineProperty(_assertThisInitialized(_this), "onRowMouseLeave", function (record, index, e) {
      _this.props.onRowMouseLeave(record, index, e);
    });

    return _this;
  }

  _createClass(Body, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      /* eslint-disable no-unused-vars */
      var _this$props = this.props,
          prefix = _this$props.prefix,
          className = _this$props.className,
          children = _this$props.children,
          Tag = _this$props.component,
          colGroup = _this$props.colGroup,
          loading = _this$props.loading,
          emptyContent = _this$props.emptyContent,
          components = _this$props.components,
          getCellProps = _this$props.getCellProps,
          primaryKey = _this$props.primaryKey,
          getRowProps = _this$props.getRowProps,
          dataSource = _this$props.dataSource,
          cellRef = _this$props.cellRef,
          columns = _this$props.columns,
          rowRef = _this$props.rowRef,
          onRowClick = _this$props.onRowClick,
          onRowMouseEnter = _this$props.onRowMouseEnter,
          onRowMouseLeave = _this$props.onRowMouseLeave,
          locale = _this$props.locale,
          pure = _this$props.pure,
          expandedIndexSimulate = _this$props.expandedIndexSimulate,
          rtl = _this$props.rtl,
          table = _this$props.table,
          others = _objectWithoutProperties(_this$props, ["prefix", "className", "children", "component", "colGroup", "loading", "emptyContent", "components", "getCellProps", "primaryKey", "getRowProps", "dataSource", "cellRef", "columns", "rowRef", "onRowClick", "onRowMouseEnter", "onRowMouseLeave", "locale", "pure", "expandedIndexSimulate", "rtl", "table"]);

      delete others.table;
      var _components$Row = components.Row,
          Row = _components$Row === void 0 ? RowComponent : _components$Row,
          _components$Cell = components.Cell,
          Cell = _components$Cell === void 0 ? CellComponent : _components$Cell;
      var empty = loading ? React.createElement("span", null, "\xA0") : emptyContent || locale.empty;
      var rows = React.createElement("tr", null, React.createElement("td", {
        colSpan: columns.length
      }, React.createElement("div", {
        className: "".concat(prefix, "table-empty")
      }, empty)));

      if (Tag === 'div') {
        rows = React.createElement("table", {
          role: "table"
        }, React.createElement("tbody", null, rows));
      }

      if (dataSource.length) {
        rows = dataSource.map(function (record, index) {
          var rowProps = {};

          if (expandedIndexSimulate) {
            rowProps = record.__expanded ? {} : getRowProps(record, index / 2);
          } else {
            rowProps = getRowProps(record, index);
          }

          rowProps = rowProps || {};
          var rowClass = rowProps.className;
          var rowClassName = classnames(_defineProperty({
            first: index === 0,
            last: index === dataSource.length - 1
          }, rowClass, rowClass));
          var expanded = record.__expanded ? 'expanded' : '';
          return React.createElement(Row, _extends({
            key: "".concat(record[primaryKey] || index).concat(expanded)
          }, rowProps, {
            ref: _this2.getRowRef.bind(_this2, index),
            colGroup: colGroup,
            rtl: rtl,
            columns: columns,
            primaryKey: primaryKey,
            record: record,
            rowIndex: index,
            prefix: prefix,
            pure: pure,
            cellRef: cellRef,
            getCellProps: getCellProps,
            className: rowClassName,
            Cell: Cell,
            onClick: _this2.onRowClick,
            locale: locale,
            onMouseEnter: _this2.onRowMouseEnter,
            onMouseLeave: _this2.onRowMouseLeave,
            table: table
          }));
        });
      }

      return React.createElement(Tag, _extends({
        className: className
      }, others), rows, children);
    }
  }]);

  return Body;
}(React.Component);

_defineProperty(Body, "propTypes", {
  loading: PropTypes.bool,
  emptyContent: PropTypes.any,
  prefix: PropTypes.string,
  pure: PropTypes.bool,
  components: PropTypes.object,
  getCellProps: PropTypes.func,
  cellRef: PropTypes.func,
  primaryKey: PropTypes.string,
  getRowProps: PropTypes.func,
  rowRef: PropTypes.func,
  dataSource: PropTypes.array,
  children: PropTypes.any,
  className: PropTypes.string,
  component: PropTypes.string,
  colGroup: PropTypes.object,
  columns: PropTypes.array,
  onRowClick: PropTypes.func,
  onRowMouseEnter: PropTypes.func,
  onRowMouseLeave: PropTypes.func,
  locale: PropTypes.object,
  table: PropTypes.object
});

_defineProperty(Body, "defaultProps", {
  loading: false,
  prefix: 'next-',
  components: {},
  getCellProps: noop,
  cellRef: noop,
  primaryKey: 'id',
  getRowProps: noop,
  rowRef: noop,
  dataSource: [],
  component: 'tbody',
  columns: [],
  table: null
});

export { Body as default };