"use strict";

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

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

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

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

var _line = require("../shared/line");

var _point = require("../shared/point");

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

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

var _plot = require("../../../plot");

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

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

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

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

var lineStyles = function lineStyles(theme) {
  return {
    line: _line.styles.line(theme),
    disabled: _line.styles.disabled(theme),
    disabledSecondary: _line.styles.disabledSecondary(theme),
    correct: _line.styles.correct(theme, 'stroke'),
    incorrect: _line.styles.incorrect(theme, 'stroke'),
    missing: _line.styles.missing(theme, 'stroke')
  };
};

var Line = function Line(props) {
  var className = props.className,
      classes = props.classes,
      disabled = props.disabled,
      correctness = props.correctness,
      scale = props.graphProps.scale,
      from = props.from,
      to = props.to,
      rest = (0, _objectWithoutProperties2["default"])(props, _excluded);
  var startPoint = {
    x: scale.x(from.x),
    y: scale.y(from.y)
  };
  var endPoint = {
    x: scale.x(to.x),
    y: scale.y(to.y)
  };
  var length = (0, _utils.getDistanceBetweenTwoPoints)(startPoint, endPoint);
  return /*#__PURE__*/_react["default"].createElement("line", (0, _extends2["default"])({
    className: (0, _classnames["default"])(classes.line, disabled && classes.disabledSecondary, classes[correctness], className),
    x1: startPoint.x,
    y1: startPoint.y,
    x2: endPoint.x,
    y2: endPoint.y,
    strokeDasharray: length - 7
  }, rest));
};

exports.Line = Line;
Line.propTypes = {
  className: _propTypes["default"].string,
  classes: _propTypes["default"].object,
  disabled: _propTypes["default"].bool,
  correctness: _propTypes["default"].string,
  graphProps: _propTypes["default"].any,
  from: _plot.types.PointType,
  to: _plot.types.PointType
};
var StyledLine = (0, _styles.withStyles)(lineStyles)(Line);
var Vector = (0, _line.lineBase)(StyledLine, {
  to: _point.Arrow
});
var Component = (0, _line.lineToolComponent)(Vector);
var _default = Component;
exports["default"] = _default;
//# sourceMappingURL=component.js.map