function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import { noop } from "teselagen-react-components";
import Caret from "./Caret";
import sector from "paths-js/sector";
import getRangeAngles from "./getRangeAnglesSpecial";
import PositionAnnotationOnCircle from "./PositionAnnotationOnCircle";
import React from "react";
import draggableClassnames from "../constants/draggableClassnames";
import pureNoFunc from "../utils/pureNoFunc";
import { getSelectionMessage, preventDefaultStopPropagation } from "../utils/editorUtils";
function SelectionLayer(_ref) {
  var isDraggable = _ref.isDraggable,
    selectionLayer = _ref.selectionLayer,
    sequenceLength = _ref.sequenceLength,
    radius = _ref.radius,
    hideTitle = _ref.hideTitle,
    innerRadius = _ref.innerRadius,
    onRightClicked = _ref.onRightClicked,
    onClick = _ref.onClick,
    index = _ref.index,
    isProtein = _ref.isProtein;
  var color = selectionLayer.color,
    start = selectionLayer.start,
    end = selectionLayer.end,
    _selectionLayer$hideC = selectionLayer.hideCarets,
    hideCarets = _selectionLayer$hideC === void 0 ? false : _selectionLayer$hideC,
    style = selectionLayer.style,
    className = selectionLayer.className;
  var _getRangeAngles = getRangeAngles(selectionLayer, sequenceLength),
    startAngle = _getRangeAngles.startAngle,
    endAngle = _getRangeAngles.endAngle,
    totalAngle = _getRangeAngles.totalAngle;
  var section = sector({
    center: [0, 0],
    //the center is always 0,0 for our annotations :) we rotate later!
    r: innerRadius,
    R: radius,
    start: 0,
    end: totalAngle
  });
  var selectionMessage = getSelectionMessage({
    sequenceLength: sequenceLength,
    selectionLayer: selectionLayer,
    isProtein: isProtein
  });
  // let section2 = sector({
  //   center: [0, 0], //the center is always 0,0 for our annotations :) we rotate later!
  //   r: innerRadius,
  //   R: radius,
  //   start: 0,
  //   end: Math.PI * 2 - totalAngle
  // });
  var _PositionAnnotationOn = PositionAnnotationOnCircle({
      sAngle: startAngle,
      eAngle: endAngle,
      height: 0
    }),
    transform = _PositionAnnotationOn.transform;
  return /*#__PURE__*/React.createElement("g", {
    onContextMenu: function onContextMenu(event) {
      onRightClicked && onRightClicked({
        annotation: selectionLayer,
        event: event
      });
    },
    onClick: onClick ? function (event) {
      onClick({
        annotation: selectionLayer,
        event: event
      });
    } : undefined,
    key: "veSelectionLayer" + index,
    className: "veSelectionLayer " + (className || "")
  }, !hideTitle && /*#__PURE__*/React.createElement("title", null, selectionMessage), /*#__PURE__*/React.createElement("path", {
    transform: transform,
    className: "selectionLayer",
    style: _extends({
      opacity: 0.3
    }, style),
    d: section.path.print(),
    fill: color
  }), !hideCarets && /*#__PURE__*/React.createElement(Caret, {
    key: "caret1",
    className: className + " selectionLayerCaret " + (isDraggable ? draggableClassnames.selectionStart : ""),
    isSelection: true,
    onClick: onClick ? noop : preventDefaultStopPropagation,
    selectionMessage: selectionMessage,
    caretPosition: start,
    sequenceLength: sequenceLength,
    innerRadius: innerRadius,
    outerRadius: radius
  }), !hideCarets && /*#__PURE__*/React.createElement(Caret, {
    key: "caret2",
    className: className + " selectionLayerCaret " + (isDraggable ? draggableClassnames.selectionEnd : ""),
    isSelection: true,
    onClick: onClick ? noop : preventDefaultStopPropagation,
    selectionMessage: selectionMessage,
    caretPosition: end + 1,
    sequenceLength: sequenceLength,
    innerRadius: innerRadius,
    outerRadius: radius
  }));
}
export default pureNoFunc(SelectionLayer);