"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.ComponentTable = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _react = _interopRequireDefault(require("react"));


var _utils = require("../lib/utils");
var _createPropsGetter = require("../lib/createPropsGetter");

// TODO We should output state too
var renderPropsDesc = function renderPropsDesc(props) {
  return Object.keys(props).
  map(function (key) {
    var value = props[key];
    switch (typeof value) {
      case 'boolean':
        return value ? key : key + ": false";
      case 'string':
        return key + ": \"" + value + "\"";
      case 'object':
        if ( /*#__PURE__*/_react.default.isValidElement(value)) {
          return /*#__PURE__*/_react.default.createElement('span', {}, [key + ": ", value]);
        }
        return key + ": " + JSON.stringify(value);
      default:
        return key + ": " + value;
    }
  }).
  map(function (node, index, nodes) {return /*#__PURE__*/(
      _react.default.createElement("span", { key: index },
      node, " ", index + 1 < nodes.length ? ', ' : null
      ));}
  );
};var



















ComponentTable = exports.ComponentTable = /*#__PURE__*/function (_React$Component) {function ComponentTable() {var _this;for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;_this.











    getProps = (0, _createPropsGetter.createPropsGetter)(ComponentTable.defaultProps);return _this;}(0, _inheritsLoose2.default)(ComponentTable, _React$Component);var _proto = ComponentTable.prototype;_proto.

  render = function render() {
    var _this$props = this.props,_this$props$rows = _this$props.rows,rows = _this$props$rows === void 0 ? [] : _this$props$rows,_this$props$cols = _this$props.cols,cols = _this$props$cols === void 0 ? [] : _this$props$cols,Component = _this$props.Component;
    var _this$getProps = this.getProps(),presetProps = _this$getProps.presetProps,presetState = _this$getProps.presetState;
    return /*#__PURE__*/(
      _react.default.createElement("table", { style: { borderSpacing: 10, marginBottom: 20 } }, /*#__PURE__*/
      _react.default.createElement("caption", { style: { captionSide: 'bottom' } }, renderPropsDesc(presetProps)), /*#__PURE__*/
      _react.default.createElement("thead", null, /*#__PURE__*/
      _react.default.createElement("tr", null, /*#__PURE__*/
      _react.default.createElement("th", null),
      cols.map(function (_ref, i) {var _ref$props = _ref.props,colProps = _ref$props === void 0 ? {} : _ref$props;return /*#__PURE__*/(
          _react.default.createElement("th", { style: { whiteSpace: 'nowrap' }, key: i },
          renderPropsDesc(colProps)
          ));}
      )
      )
      ), /*#__PURE__*/
      _react.default.createElement("tbody", null,
      rows.map(function (_ref2, rowIndex) {var _ref2$props = _ref2.props,rowProps = _ref2$props === void 0 ? {} : _ref2$props,_ref2$state = _ref2.state,rowState = _ref2$state === void 0 ? {} : _ref2$state;return /*#__PURE__*/(
          _react.default.createElement("tr", { key: rowIndex }, /*#__PURE__*/
          _react.default.createElement("td", { style: { whiteSpace: 'nowrap' } }, renderPropsDesc(rowProps)),
          cols.map(function (_ref3, colIndex) {var _ref3$props = _ref3.props,colProps = _ref3$props === void 0 ? {} : _ref3$props,_ref3$state = _ref3.state,colState = _ref3$state === void 0 ? {} : _ref3$state;return /*#__PURE__*/(
              _react.default.createElement("td", { key: colIndex }, /*#__PURE__*/

              _react.default.createElement(Component, (0, _extends2.default)({},
              presetProps,
              rowProps,
              colProps, {
                ref:
                // NOTE Call setState from outside is bad practice, but here it needed for test state combinations
                (0, _utils.isFunctionalComponent)(Component) ?
                undefined :
                function (el) {return (
                    el &&
                    el.setState(function (state) {return (0, _extends2.default)({},
                      state,
                      presetState,
                      rowState,
                      colState);}
                    ));} })

              )
              ));}
          )
          ));}
      )
      )
      ));

  };return ComponentTable;}(_react.default.Component);ComponentTable.defaultProps = { presetProps: {}, presetState: {} };