"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.Unit = 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 _styleUtils = require("../style-utils");

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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 Tick = (0, _styles.withStyles)(function (theme) {
  return {
    tick: {
      stroke: (0, _styleUtils.strokeColor)(theme)
    }
  };
})(function (_ref) {
  var x = _ref.x,
      height = _ref.height,
      bottom = _ref.bottom,
      classes = _ref.classes,
      major = _ref.major,
      minor = _ref.minor;
  var y1 = major ? bottom - height * 2 : minor ? bottom - height * 1.5 : bottom - height;
  return /*#__PURE__*/_react["default"].createElement("line", {
    y1: y1,
    y2: bottom,
    x1: x,
    x2: x,
    className: classes.tick
  });
});

var Ticks = function Ticks(_ref2) {
  var count = _ref2.count,
      width = _ref2.width,
      height = _ref2.height;
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, (0, _range["default"])(1, count).map(function (r) {
    return /*#__PURE__*/_react["default"].createElement(Tick, {
      key: r,
      value: r,
      x: r * (width / count),
      major: r % (count / 2) === 0,
      minor: r % (count / 4) === 0,
      bottom: height,
      height: 10
    });
  }));
};

Ticks.propTypes = {
  count: _propTypes["default"].number.isRequired,
  width: _propTypes["default"].number.isRequired,
  height: _propTypes["default"].number.isRequired
};

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

  var _super = _createSuper(Unit);

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

  (0, _createClass2["default"])(Unit, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          index = _this$props.index,
          width = _this$props.width,
          height = _this$props.height,
          classes = _this$props.classes,
          last = _this$props.last,
          config = _this$props.config;
      var style = {
        transform: "translate(".concat(width * (index - 1), "px, 0px)")
      };
      return /*#__PURE__*/_react["default"].createElement("g", {
        style: style
      }, !last && /*#__PURE__*/_react["default"].createElement("line", {
        x1: width,
        y1: 0,
        x2: width,
        y2: height,
        className: classes.endTick
      }), /*#__PURE__*/_react["default"].createElement(Ticks, {
        count: config.ticks,
        width: width,
        height: height
      }), /*#__PURE__*/_react["default"].createElement("text", {
        width: width,
        className: classes.label,
        x: width - 5,
        y: 15
      }, index));
    }
  }]);
  return Unit;
}(_react["default"].Component);

exports.Unit = Unit;
(0, _defineProperty2["default"])(Unit, "propTypes", {
  index: _propTypes["default"].number.isRequired,
  width: _propTypes["default"].number.isRequired,
  height: _propTypes["default"].number.isRequired,
  classes: _propTypes["default"].object.isRequired,
  last: _propTypes["default"].bool.isRequired,
  config: _propTypes["default"].object.isRequired
});

var _default = (0, _styles.withStyles)(function (theme) {
  return {
    endTick: {
      stroke: (0, _styleUtils.strokeColor)(theme),
      strokeWidth: 1
    },
    label: _objectSpread({
      textAnchor: 'end',
      fontSize: '12px',
      fill: (0, _styleUtils.strokeColor)(theme)
    }, (0, _styleUtils.noSelect)()),
    base: {
      fill: 'none',
      stroke: 'red'
    }
  };
})(Unit);

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