var _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; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { tagPropType, mapToCssModules } from './Shared/helper.js';

//component - CoreUI / CTable

var CTable = function CTable(props) {
  var Tag = props.tag,
      className = props.className,
      cssModule = props.cssModule,
      custom = props.custom,
      innerRef = props.innerRef,
      size = props.size,
      bordered = props.bordered,
      borderless = props.borderless,
      striped = props.striped,
      dark = props.dark,
      hover = props.hover,
      responsive = props.responsive,
      ResponsiveTag = props.responsiveTag,
      attributes = _objectWithoutProperties(props, ['tag', 'className', 'cssModule', 'custom', 'innerRef', 'size', 'bordered', 'borderless', 'striped', 'dark', 'hover', 'responsive', 'responsiveTag']);

  //render

  var classes = mapToCssModules(classNames(className, 'table', size ? 'table-' + size : false, bordered ? 'table-bordered' : false, borderless ? 'table-borderless' : false, striped ? 'table-striped' : false, dark ? 'table-dark' : false, hover ? 'table-hover' : false), cssModule);

  var table = void 0;
  if (custom) table = React.createElement(Tag, _extends({}, attributes, { className: classes }));else {
    table = React.createElement(
      Tag,
      _extends({}, attributes, { className: classes }),
      React.createElement(
        'tbody',
        null,
        attributes.children
      )
    );
  }

  if (responsive) {
    var responsiveClassName = responsive === true ? 'table-responsive' : 'table-responsive-' + responsive;
    return React.createElement(
      ResponsiveTag,
      { className: responsiveClassName, ref: innerRef },
      table
    );
  }

  return table;
};

CTable.propTypes = process.env.NODE_ENV !== "production" ? {
  tag: tagPropType,
  className: PropTypes.string,
  cssModule: PropTypes.object,
  custom: PropTypes.bool,
  //
  innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string, PropTypes.object]),
  size: PropTypes.string,
  bordered: PropTypes.bool,
  borderless: PropTypes.bool,
  striped: PropTypes.bool,
  dark: PropTypes.bool,
  hover: PropTypes.bool,
  responsive: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
  responsiveTag: tagPropType
} : {};

CTable.defaultProps = {
  tag: 'table',
  responsiveTag: 'div'
};

export default CTable;