import React, { memo } from 'react';
import PropTypes from 'prop-types';
import "./style.css";

var Table = function Table(_ref) {
  var tableData = _ref.tableData,
      headingColumns = _ref.headingColumns,
      title = _ref.title,
      _ref$breakOn = _ref.breakOn,
      breakOn = _ref$breakOn === void 0 ? 'medium' : _ref$breakOn;
  var tableClass = 'coach-table-container__table';

  if (title) {
    console.log('title: ', title);
  }

  if (breakOn === 'none') {
    tableClass += '';
  } else if (breakOn === 'small') {
    tableClass += ' coach-table-container__table--break-sm';
  } else if (breakOn === 'medium') {
    tableClass += ' coach-table-container__table--break-md';
  } else if (breakOn === 'large') {
    tableClass += ' coach-table-container__table--break-lg';
  }

  var data = tableData.map(function (row, index) {
    var rowData = [];
    var i = 0;

    for (var key in row) {
      rowData.push({
        key: headingColumns[i],
        val: row[key]
      });
      i++;
    }

    return /*#__PURE__*/React.createElement("tr", {
      key: index
    }, rowData.map(function (data, index) {
      return /*#__PURE__*/React.createElement("td", {
        key: index,
        "data-heading": data.key
      }, data.val);
    }));
  });
  return /*#__PURE__*/React.createElement("div", {
    className: "coach-table-container"
  }, title && /*#__PURE__*/React.createElement("div", {
    className: "coach-generic-table-container__title"
  }, /*#__PURE__*/React.createElement("h2", null, title)), /*#__PURE__*/React.createElement("table", {
    className: tableClass
  }, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, headingColumns.map(function (col, index) {
    return /*#__PURE__*/React.createElement("th", {
      key: index
    }, col);
  }))), /*#__PURE__*/React.createElement("tbody", null, data)));
};

Table.propTypes = process.env.NODE_ENV !== "production" ? {
  tableData: PropTypes.arrayOf(PropTypes.object).isRequired,
  headingColumns: PropTypes.arrayOf(PropTypes.string).isRequired,
  title: PropTypes.string.isRequired,
  breakOn: PropTypes.oneOf(['none', 'small', 'medium', 'large'])
} : {};
export default memo(Table);