"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _getRangeAnglesSpecial = _interopRequireDefault(require("./getRangeAnglesSpecial"));
var _PositionAnnotationOnCircle = _interopRequireDefault(require("./PositionAnnotationOnCircle"));
var _react = _interopRequireDefault(require("react"));
var _each = _interopRequireDefault(require("lodash/each"));
var _withHover = _interopRequireDefault(require("../helperComponents/withHover"));
var _pureNoFunc = _interopRequireDefault(require("../utils/pureNoFunc"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/* @flow */

function Cutsites(_ref) {
  var radius = _ref.radius,
    noRedux = _ref.noRedux,
    editorName = _ref.editorName,
    showCutsiteLabels = _ref.showCutsiteLabels,
    cutsiteClicked = _ref.cutsiteClicked,
    cutsiteDoubleClicked = _ref.cutsiteDoubleClicked,
    cutsiteRightClicked = _ref.cutsiteRightClicked,
    cutsites = _ref.cutsites,
    _ref$cutsiteWidth = _ref.cutsiteWidth,
    cutsiteWidth = _ref$cutsiteWidth === void 0 ? 1 : _ref$cutsiteWidth,
    _ref$annotationHeight = _ref.annotationHeight,
    annotationHeight = _ref$annotationHeight === void 0 ? 15 : _ref$annotationHeight,
    sequenceLength = _ref.sequenceLength;
  radius += annotationHeight;
  var svgGroup = [];
  var labels = {};
  var index = 0;
  if (!Object.keys(cutsites).length) return null;
  (0, _each["default"])(cutsites, function (annotation /* key */) {
    index++;
    if (!(annotation.topSnipPosition > -1)) {
      //we need this to be present
    }
    var _getRangeAngles = (0, _getRangeAnglesSpecial["default"])({
        start: annotation.topSnipPosition,
        end: annotation.topSnipPosition
      }, sequenceLength),
      startAngle = _getRangeAngles.startAngle;
    if (showCutsiteLabels) {
      //expand the end angle if annotation spans the origin
      labels[annotation.id] = {
        annotationCenterAngle: startAngle,
        annotationCenterRadius: radius,
        text: annotation.restrictionEnzyme.name,
        color: annotation.restrictionEnzyme.color,
        className: " veCutsiteLabel",
        id: annotation.id,
        onClick: function onClick(event) {
          cutsiteClicked({
            event: event,
            annotation: annotation
          });
          event.stopPropagation();
        },
        onDoubleClick: function onDoubleClick(event) {
          cutsiteDoubleClicked({
            event: event,
            annotation: annotation
          });
          event.stopPropagation();
        },
        onContextMenu: function onContextMenu(event) {
          cutsiteRightClicked({
            event: event,
            annotation: annotation
          });
          event.stopPropagation();
        }
      };
    }
    svgGroup.push( /*#__PURE__*/_react["default"].createElement(DrawCutsite, {
      key: "cutsite" + index,
      noRedux: noRedux,
      editorName: editorName,
      id: annotation.id,
      startAngle: startAngle,
      radius: radius,
      cutsiteWidth: cutsiteWidth,
      annotationHeight: annotationHeight
    }));
  });
  return {
    height: annotationHeight,
    labels: labels,
    component: /*#__PURE__*/_react["default"].createElement("g", {
      key: "cutsites",
      className: "cutsites"
    }, svgGroup)
  };
}
var _default = Cutsites;
exports["default"] = _default;
var DrawCutsite = (0, _pureNoFunc["default"])((0, _withHover["default"])(function (_ref2) {
  var className = _ref2.className,
    startAngle = _ref2.startAngle,
    radius = _ref2.radius,
    cutsiteWidth = _ref2.cutsiteWidth,
    annotationHeight = _ref2.annotationHeight,
    onMouseLeave = _ref2.onMouseLeave,
    onMouseOver = _ref2.onMouseOver;
  var _PositionAnnotationOn = (0, _PositionAnnotationOnCircle["default"])({
      sAngle: startAngle,
      eAngle: startAngle,
      height: radius
    }),
    transform = _PositionAnnotationOn.transform;
  return /*#__PURE__*/_react["default"].createElement("rect", {
    onMouseLeave: onMouseLeave,
    onMouseOver: onMouseOver,
    className: className,
    transform: transform,
    width: cutsiteWidth,
    height: annotationHeight
  });
}));
module.exports = exports.default;