"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _style = _interopRequireDefault(require("./style.css"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } /* eslint-disable css-modules/no-unused-class */
const ErrorsTable = props => {
  const {
    columns = [],
    rows = [],
    ariaDescribedby
  } = props;
  const headerRow = columns.map((column, cIndex) => {
    const {
      title
    } = column;
    return /*#__PURE__*/_react.default.createElement("th", {
      className: (0, _classnames.default)(_style.default[`header-${cIndex + 1}`]),
      key: `${title}-${cIndex + 1}`,
      role: "columnheader"
    }, /*#__PURE__*/_react.default.createElement("div", null, title));
  });
  const headerView = [/*#__PURE__*/_react.default.createElement("th", {
    className: (0, _classnames.default)(_style.default[`header-0`]),
    key: "header"
  }, /*#__PURE__*/_react.default.createElement("div", null, " ", ''))].concat(headerRow);
  const bodyView = rows.map((row, index) => {
    const {
      fields = []
    } = row;
    const bodyRow = fields.map((field, fIndex) => {
      return /*#__PURE__*/_react.default.createElement("td", {
        className: (0, _classnames.default)(_style.default.col, _style.default[`col-${fIndex + 1}`]),
        key: `${field}-${fIndex}`
      }, field || '');
    });
    bodyRow.unshift(/*#__PURE__*/_react.default.createElement("td", {
      className: (0, _classnames.default)(_style.default.col, _style.default[`col-0`]),
      key: "header"
    }, index + 1));
    return /*#__PURE__*/_react.default.createElement("tr", {
      key: `line-${index}`
    }, bodyRow);
  });
  return /*#__PURE__*/_react.default.createElement("table", _extends({}, ariaDescribedby ? {
    'aria-describedby': ariaDescribedby
  } : {}, {
    className: _style.default.table
  }), /*#__PURE__*/_react.default.createElement("thead", {
    className: _style.default.thead
  }, /*#__PURE__*/_react.default.createElement("tr", null, headerView)), /*#__PURE__*/_react.default.createElement("tbody", null, bodyView));
};
ErrorsTable.propTypes = process.env.NODE_ENV !== "production" ? _types.propTypes : {};
var _default = exports.default = ErrorsTable;
//# sourceMappingURL=index.js.map