"use strict";

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

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

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

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

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

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

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

var lineStyles = function lineStyles(theme) {
  return {
    line: _line.styles.line(theme),
    dashedLine: _line.styles.dashedLine(theme),
    enabledArrow: _line.styles.arrow(theme),
    disabledArrow: _line.styles.disabledArrow(theme),
    disabled: _line.styles.disabled(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 ArrowedLine = function ArrowedLine(props) {
  var markerId = (0, _arrowHead.genUid)();
  var className = props.className,
      classes = props.classes,
      correctness = props.correctness,
      disabled = props.disabled,
      graphProps = props.graphProps,
      _props$fill = props.fill,
      fill = _props$fill === void 0 ? 'Solid' : _props$fill,
      from = props.from,
      to = props.to,
      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, 2),
      eFrom = _trig$edges2[0],
      eTo = _trig$edges2[1];

  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(eFrom.x),
    y1: scale.y(eFrom.y),
    x2: scale.x(eTo.x),
    y2: scale.y(eTo.y),
    className: (0, _classnames["default"])(fill === 'Solid' ? classes.line : classes.dashedLine, disabled && classes.disabled, classes[correctness], className),
    markerEnd: "url(#".concat(props.markerId || markerId, "-").concat(suffix, ")"),
    markerStart: "url(#".concat(props.markerId || markerId, "-").concat(suffix, ")")
  }, rest)));
};

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