"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Table = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactRouterDom = require("react-router-dom");
var _Padder = require("./Padder");
var _Button = require("./Button");
require("../styles/main.css");
require("../styles/table.css");
var Table = function Table(_ref) {
  var columns = _ref.columns,
    data = _ref.data,
    name = _ref.name,
    empty = _ref.empty,
    width = _ref.width,
    height = _ref.height;
  var tableWidth = width ? width : '100%';
  var tableHeight = height ? height : 300;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "table-container",
    style: {
      minWidth: tableWidth,
      height: tableHeight + 75
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    style: {
      borderBottom: '1px solid #DCDCDC'
    }
  }, /*#__PURE__*/_react.default.createElement(_Padder.Padder, {
    top: "1em",
    bottom: "1em",
    left: "2em",
    right: "2em"
  }, name && /*#__PURE__*/_react.default.createElement("h6", {
    style: {
      textAlign: 'center'
    }
  }, name), /*#__PURE__*/_react.default.createElement("div", {
    className: "table-row"
  }, columns.map(function (column) {
    if (column.hasOwnProperty('index')) {
      if (column.index === true) {
        return /*#__PURE__*/_react.default.createElement("div", {
          className: "row-item"
        }, /*#__PURE__*/_react.default.createElement("label", {
          style: {
            margin: 0
          }
        }, column.header));
      }
    } else {
      return /*#__PURE__*/_react.default.createElement("div", {
        className: "row-item"
      }, /*#__PURE__*/_react.default.createElement("p", {
        style: {
          margin: 0
        }
      }, column.header));
    }
  })))), /*#__PURE__*/_react.default.createElement("div", {
    style: {
      overflowY: 'scroll',
      height: tableHeight
    }
  }, data.length > 0 ? data.map(function (row) {
    return /*#__PURE__*/_react.default.createElement("div", {
      style: {
        borderBottom: '1px solid #DCDCDC'
      }
    }, /*#__PURE__*/_react.default.createElement(_Padder.Padder, {
      top: "1em",
      bottom: "1em",
      left: "2em",
      right: "2em"
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: "table-row"
    }, columns.map(function (column) {
      if (column.hasOwnProperty('index')) {
        if (column.index === true) {
          if (row[column.accessor].hasOwnProperty('color')) {
            return /*#__PURE__*/_react.default.createElement("div", {
              className: "row-item"
            }, /*#__PURE__*/_react.default.createElement("label", {
              style: {
                margin: 0,
                color: row[column.accessor].color
              }
            }, row[column.accessor].text));
          } else if (row[column.accessor].hasOwnProperty('link')) {
            return /*#__PURE__*/_react.default.createElement("div", {
              className: "row-item"
            }, /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, {
              to: row[column.accessor].link
            }, /*#__PURE__*/_react.default.createElement(_Button.Button, {
              intent: "minimal"
            }, row[column.accessor].text)));
          } else {
            return /*#__PURE__*/_react.default.createElement("div", {
              className: "row-item"
            }, /*#__PURE__*/_react.default.createElement("label", {
              style: {
                margin: 0
              }
            }, row[column.accessor]));
          }
        }
      } else {
        if (row[column.accessor].hasOwnProperty('color')) {
          return /*#__PURE__*/_react.default.createElement("div", {
            className: "row-item"
          }, /*#__PURE__*/_react.default.createElement("p", {
            style: {
              margin: 0,
              color: row[column.accessor].color
            }
          }, row[column.accessor].text));
        } else if (row[column.accessor].hasOwnProperty('link')) {
          return /*#__PURE__*/_react.default.createElement("div", {
            className: "row-item"
          }, /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, {
            to: row[column.accessor].link
          }, /*#__PURE__*/_react.default.createElement(_Button.Button, {
            intent: "minimal"
          }, row[column.accessor].text)));
        } else {
          return /*#__PURE__*/_react.default.createElement("div", {
            className: "row-item"
          }, /*#__PURE__*/_react.default.createElement("p", {
            style: {
              margin: 0
            }
          }, row[column.accessor]));
        }
      }
    }))));
  }) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Padder.Padder, {
    top: "4em"
  }, /*#__PURE__*/_react.default.createElement("p", {
    style: {
      textAlign: "center"
    }
  }, empty || 'No data here yet')))));
};
exports.Table = Table;