"use strict";

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

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

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

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

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

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

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

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

var _arrowHead = require("../shared/arrow-head");

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

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

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

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

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

var rayStyles = function rayStyles(theme) {
  return {
    line: _line.styles.line(theme),
    enabledArrow: _line.styles.arrow(theme),
    disabledArrow: _line.styles.disabledArrow(theme),
    disabled: _line.styles.disabled(theme),
    disabledSecondary: _line.styles.disabledSecondary(theme),
    correct: _line.styles.correct(theme, 'stroke'),
    correctArrow: _line.styles.correct(theme),
    incorrect: _line.styles.incorrect(theme, 'stroke'),
    incorrectArrow: _line.styles.incorrect(theme),
    missing: _line.styles.missing(theme, 'stroke'),
    missingArrow: _line.styles.missing(theme)
  };
};

var RayLine = function RayLine(props) {
  var markerId = (0, _arrowHead.genUid)();
  var graphProps = props.graphProps,
      from = props.from,
      to = props.to,
      classes = props.classes,
      disabled = props.disabled,
      correctness = props.correctness,
      className = props.className,
      rest = (0, _objectWithoutProperties2["default"])(props, _excluded);
  var scale = graphProps.scale;

  var _getAdjustedGraphLimi = (0, _utils.getAdjustedGraphLimits)(graphProps),
      domain = _getAdjustedGraphLimi.domain,
      range = _getAdjustedGraphLimi.range;

  var _trig$edges = _plot.trig.edges(domain, range)(from, to),
      _trig$edges2 = (0, _slicedToArray2["default"])(_trig$edges, 1),
      aToB = _trig$edges2[0];

  var suffix = correctness || disabled && 'disabled' || 'enabled';
  return /*#__PURE__*/_react["default"].createElement("g", null, /*#__PURE__*/_react["default"].createElement("defs", null, /*#__PURE__*/_react["default"].createElement(_arrowHead.ArrowMarker, {
    size: (0, _utils.thinnerShapesNeeded)(graphProps) ? 4 : 5,
    id: "".concat(props.markerId || markerId, "-").concat(suffix),
    className: (0, _classnames["default"])(classes["".concat(suffix, "Arrow")])
  })), /*#__PURE__*/_react["default"].createElement("line", (0, _extends2["default"])({
    x1: scale.x(from.x),
    y1: scale.y(from.y),
    x2: scale.x(aToB.x),
    y2: scale.y(aToB.y)
  }, rest, {
    className: (0, _classnames["default"])(classes.line, disabled && classes.disabledSecondary, classes[correctness], className),
    markerEnd: "url(#".concat(props.markerId || markerId, "-").concat(suffix, ")")
  })));
};

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