"use strict";

exports.__esModule = true;
exports["default"] = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

require("./style.css");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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["default"].createElement("tr", {
      key: index
    }, rowData.map(function (data, index) {
      return /*#__PURE__*/_react["default"].createElement("td", {
        key: index,
        "data-heading": data.key
      }, data.val);
    }));
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "coach-table-container"
  }, title && /*#__PURE__*/_react["default"].createElement("div", {
    className: "coach-generic-table-container__title"
  }, /*#__PURE__*/_react["default"].createElement("h2", null, title)), /*#__PURE__*/_react["default"].createElement("table", {
    className: tableClass
  }, /*#__PURE__*/_react["default"].createElement("thead", null, /*#__PURE__*/_react["default"].createElement("tr", null, headingColumns.map(function (col, index) {
    return /*#__PURE__*/_react["default"].createElement("th", {
      key: index
    }, col);
  }))), /*#__PURE__*/_react["default"].createElement("tbody", null, data)));
};

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

var _default = (0, _react.memo)(Table);

exports["default"] = _default;
module.exports = exports.default;