'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _recompose = require('recompose');

var _Loader = require('../Loader');

var _Loader2 = _interopRequireDefault(_Loader);

var _TableStyles = require('./styles/TableStyles');

var _TableStyles2 = _interopRequireDefault(_TableStyles);

var _TableOverlay = require('./styles/TableOverlay');

var _TableOverlay2 = _interopRequireDefault(_TableOverlay);

var _TableCell = require('./styles/TableCell');

var _TableCell2 = _interopRequireDefault(_TableCell);

var _TableHeader = require('./TableHeader');

var _TableHeader2 = _interopRequireDefault(_TableHeader);

var _TableRow = require('./styles/TableRow');

var _TableRow2 = _interopRequireDefault(_TableRow);

var _TableControls = require('./TableControls');

var _TableControls2 = _interopRequireDefault(_TableControls);

var _SimpleTable = require('./SimpleTable');

var _SimpleTable2 = _interopRequireDefault(_SimpleTable);

var _TableRowDetails = require('./TableRowDetails');

var _TableRowDetails2 = _interopRequireDefault(_TableRowDetails);

var _TableWrap = require('./TableWrap');

var _TableWrap2 = _interopRequireDefault(_TableWrap);

var _TableBody = require('./styles/TableBody');

var _TableBody2 = _interopRequireDefault(_TableBody);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Table = function (_React$Component) {
  (0, _inherits3.default)(Table, _React$Component);

  function Table() {
    (0, _classCallCheck3.default)(this, Table);
    return (0, _possibleConstructorReturn3.default)(this, (Table.__proto__ || (0, _getPrototypeOf2.default)(Table)).apply(this, arguments));
  }

  (0, _createClass3.default)(Table, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          children = _props.children,
          headers = _props.headers,
          loading = _props.loading,
          className = _props.className,
          id = _props.id,
          wrapBody = _props.wrapBody,
          Wrap = _props.Wrap,
          Styles = _props.Styles,
          Overlay = _props.Overlay;

      return _react2.default.createElement(
        Wrap,
        null,
        _react2.default.createElement(
          Styles,
          { cellPadding: 0, cellSpacing: 0, className: className, id: id },
          _react2.default.createElement(
            'thead',
            null,
            headers
          ),
          wrapBody ? _react2.default.createElement(
            _TableBody2.default,
            null,
            children
          ) : children
        ),
        loading && _react2.default.createElement(
          Overlay,
          null,
          _react2.default.createElement(_Loader2.default, null)
        )
      );
    }
  }]);
  return Table;
}(_react2.default.Component);

Table.propTypes = {
  /**
   * Render the rows of the Table within its children.
   */
  children: _propTypes2.default.node.isRequired,
  /**
   * Render headers for the columns with this property.
   */
  headers: _propTypes2.default.node,
  /**
   * Renders a loading spinner over the table body.
   */
  loading: _propTypes2.default.bool,
  /**
   * Adds a class name to the table element.
   */
  className: _propTypes2.default.string,
  /**
   * Adds an id to the table element.
   */
  id: _propTypes2.default.string,
  /**
   * Whether to wrap the passed children in a <Table.Body>. Defaults true.
   */
  wrapBody: _propTypes2.default.bool,
  /**
   * A component to render the table element
   */
  Styles: _propTypes2.default.func,
  /**
   * A component to render any content that overlays the table itself
   */
  Overlay: _propTypes2.default.func,
  /**
   * A component that wraps the whole table as a scroll context
   */
  Wrap: _propTypes2.default.func
};
Table.defaultProps = {
  loading: false,
  className: null,
  id: null,
  headers: null,
  wrapBody: true,
  Styles: _TableStyles2.default,
  Overlay: _TableOverlay2.default,
  Wrap: _TableWrap2.default
};


Table.Row = _TableRow2.default;
Table.Header = _TableHeader2.default;
Table.Cell = _TableCell2.default;
Table.Controls = _TableControls2.default;
Table.Simple = _SimpleTable2.default;
Table.RowDetails = _TableRowDetails2.default;
Table.Wrap = _TableWrap2.default;
Table.Body = _TableBody2.default;

Table.Small = (0, _recompose.withProps)({
  Styles: _TableStyles2.default.Small
})(Table);

exports.default = Table;