"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.Ruler = 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 _styles = require("@material-ui/core/styles");

var _rotatable = _interopRequireDefault(require("../rotatable"));

var _classnames = _interopRequireDefault(require("classnames"));

var _graphic = _interopRequireDefault(require("./graphic"));

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

var _anchor = _interopRequireDefault(require("../anchor"));

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 Ruler = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(Ruler, _React$Component);

  var _super = _createSuper(Ruler);

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

  (0, _createClass2["default"])(Ruler, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          classes = _this$props.classes,
          width = _this$props.width,
          height = _this$props.height,
          units = _this$props.units,
          measure = _this$props.measure,
          className = _this$props.className,
          startPosition = _this$props.startPosition,
          label = _this$props.label,
          tickCount = _this$props.tickCount;
      var unit = measure === 'imperial' ? {
        type: label,
        ticks: tickCount && tickCount % 4 === 0 ? tickCount : 16
      } : {
        type: label,
        ticks: 10
      };
      return /*#__PURE__*/_react["default"].createElement(_rotatable["default"], {
        className: className,
        startPosition: startPosition,
        handle: [{
          "class": 'leftAnchor',
          origin: 'bottom right'
        }, {
          "class": 'rightAnchor',
          origin: 'bottom left'
        }]
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.ruler,
        style: {
          width: "".concat(width, "px"),
          height: "".concat(height, "px")
        }
      }, /*#__PURE__*/_react["default"].createElement(_graphic["default"], {
        width: width,
        height: height,
        units: units,
        unit: unit
      }), /*#__PURE__*/_react["default"].createElement(_anchor["default"], {
        className: (0, _classnames["default"])('leftAnchor', classes.leftAnchor)
      }), /*#__PURE__*/_react["default"].createElement(_anchor["default"], {
        className: (0, _classnames["default"])('rightAnchor', classes.rightAnchor)
      })));
    }
  }]);
  return Ruler;
}(_react["default"].Component);

exports.Ruler = Ruler;
(0, _defineProperty2["default"])(Ruler, "propTypes", {
  width: _propTypes["default"].number,
  height: _propTypes["default"].number,
  units: _propTypes["default"].number.isRequired,
  measure: _propTypes["default"].oneOf(['imperial', 'metric']).isRequired,
  classes: _propTypes["default"].object.isRequired,
  className: _propTypes["default"].string,
  startPosition: _propTypes["default"].shape({
    left: _propTypes["default"].number.isRequired,
    top: _propTypes["default"].number.isRequired
  }),
  label: _propTypes["default"].string,
  tickCount: _propTypes["default"].number
});
(0, _defineProperty2["default"])(Ruler, "defaultProps", {
  width: 480,
  height: 60,
  measure: 'imperial',
  units: 12
});

var styles = function styles(theme) {
  return {
    ruler: {
      cursor: 'move',
      position: 'relative',
      backgroundColor: theme.palette.secondary.light,
      opacity: 1.0,
      border: "solid 0px ".concat(theme.palette.primary.main)
    },
    leftAnchor: {
      left: '-10px',
      top: '40%'
    },
    rightAnchor: {
      right: '-10px',
      top: '40%'
    }
  };
};

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

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