"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.Graphic = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

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

var _styles = require("@material-ui/core/styles");

var _unitType = _interopRequireDefault(require("./unit-type"));

var _range = _interopRequireDefault(require("lodash/range"));

var _unit = _interopRequireDefault(require("./unit"));

var _styleUtils = require("../style-utils");

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var Bg = function Bg(_ref) {
  var width = _ref.width,
      height = _ref.height,
      className = _ref.className;
  return /*#__PURE__*/_react["default"].createElement("rect", {
    width: width,
    height: height,
    cx: 0,
    cy: 0,
    className: className
  });
};

Bg.propTypes = {
  width: _propTypes["default"].number.isRequired,
  height: _propTypes["default"].number.isRequired,
  className: _propTypes["default"].string.isRequired
};

var Graphic = /*#__PURE__*/function (_React$PureComponent) {
  (0, _inherits2["default"])(Graphic, _React$PureComponent);

  var _super = _createSuper(Graphic);

  function Graphic() {
    (0, _classCallCheck2["default"])(this, Graphic);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(Graphic, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          width = _this$props.width,
          height = _this$props.height,
          classes = _this$props.classes,
          units = _this$props.units,
          unit = _this$props.unit;
      var viewBox = "0 0 ".concat(width, " ").concat(height);
      var unitWidth = width / units;
      var unitHeight = height;
      return /*#__PURE__*/_react["default"].createElement("svg", {
        viewBox: viewBox
      }, /*#__PURE__*/_react["default"].createElement(Bg, {
        width: width,
        height: height,
        className: classes.bg
      }), /*#__PURE__*/_react["default"].createElement(_unitType["default"], {
        label: unit.type
      }), (0, _range["default"])(1, units + 1).map(function (r) {
        return /*#__PURE__*/_react["default"].createElement(_unit["default"], {
          width: unitWidth,
          height: unitHeight,
          key: r,
          index: r,
          config: unit,
          last: r === units
        });
      }));
    }
  }]);
  return Graphic;
}(_react["default"].PureComponent);

exports.Graphic = Graphic;
(0, _defineProperty2["default"])(Graphic, "propTypes", {
  width: _propTypes["default"].number.isRequired,
  height: _propTypes["default"].number.isRequired,
  units: _propTypes["default"].number.isRequired,
  unit: _propTypes["default"].object.isRequired,
  classes: _propTypes["default"].object.isRequired
});

var styles = function styles(theme) {
  return {
    bg: {
      stroke: (0, _styleUtils.strokeColor)(theme),
      strokeWidth: '2px',
      fill: (0, _styleUtils.fillColor)(theme)
    }
  };
};

var _default = (0, _styles.withStyles)(styles)(Graphic);

exports["default"] = _default;
//# sourceMappingURL=graphic.js.map