"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RawArrow = void 0;

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

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

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 _classnames = _interopRequireDefault(require("classnames"));

var _plot = require("@pie-lib/plot");

var _isEqual = _interopRequireDefault(require("lodash/isEqual"));

var _utils = require("../../../utils");

var _excluded = ["classes", "className", "x", "y", "disabled", "correctness", "graphProps", "from", "to"];

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

  var _super = _createSuper(RawArrow);

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

  (0, _createClass2["default"])(RawArrow, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          classes = _this$props.classes,
          className = _this$props.className,
          x = _this$props.x,
          y = _this$props.y,
          disabled = _this$props.disabled,
          correctness = _this$props.correctness,
          graphProps = _this$props.graphProps,
          from = _this$props.from,
          to = _this$props.to,
          rest = (0, _objectWithoutProperties2["default"])(_this$props, _excluded); // x & y are the initial coordinates for the arrow
      // from & to are used only to calculate the angle that the arrow should be rotated with

      var scale = graphProps.scale;
      var angle = (0, _utils.getAngleDeg)(from.x, from.y, to.x, to.y);
      var points = '';

      if ((0, _isEqual["default"])(from, to)) {
        points = '0,0 0,0 0,0';
      } else {
        points = "0,0 ".concat(_utils.arrowDimensions.vector, ",").concat(_utils.arrowDimensions.vector * 2, " \n      -").concat(_utils.arrowDimensions.vector, ",").concat(_utils.arrowDimensions.vector * 2);
      }

      return /*#__PURE__*/_react["default"].createElement("g", (0, _extends2["default"])({
        className: (0, _classnames["default"])(classes.point, disabled && classes.disabled, classes[correctness], className)
      }, rest), /*#__PURE__*/_react["default"].createElement("polygon", {
        points: points,
        transform: "\n          translate(".concat(scale.x(x), ", ").concat(scale.y(y), ")\n          rotate(").concat(angle, " 0 0)")
      }));
    }
  }]);
  return RawArrow;
}(_react["default"].Component);

exports.RawArrow = RawArrow;
(0, _defineProperty2["default"])(RawArrow, "propTypes", {
  classes: _propTypes["default"].object,
  className: _propTypes["default"].string,
  correctness: _propTypes["default"].string,
  disabled: _propTypes["default"].bool,
  x: _propTypes["default"].number,
  y: _propTypes["default"].number,
  from: _propTypes["default"].shape({
    x: _propTypes["default"].number,
    y: _propTypes["default"].number
  }).isRequired,
  to: _propTypes["default"].shape({
    x: _propTypes["default"].number,
    y: _propTypes["default"].number
  }),
  graphProps: _plot.types.GraphPropsType.isRequired
});
(0, _defineProperty2["default"])(RawArrow, "defaultProps", {
  from: {},
  to: {}
});
//# sourceMappingURL=arrow-point.js.map