"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _teselagenReactComponents = require("teselagen-react-components");
var _Caret = _interopRequireDefault(require("./Caret"));
var _sector = _interopRequireDefault(require("paths-js/sector"));
var _getRangeAnglesSpecial = _interopRequireDefault(require("./getRangeAnglesSpecial"));
var _PositionAnnotationOnCircle = _interopRequireDefault(require("./PositionAnnotationOnCircle"));
var _react = _interopRequireDefault(require("react"));
var _draggableClassnames = _interopRequireDefault(require("../constants/draggableClassnames"));
var _pureNoFunc = _interopRequireDefault(require("../utils/pureNoFunc"));
var _editorUtils = require("../utils/editorUtils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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); }
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 = (0, _getRangeAnglesSpecial["default"])(selectionLayer, sequenceLength),
    startAngle = _getRangeAngles.startAngle,
    endAngle = _getRangeAngles.endAngle,
    totalAngle = _getRangeAngles.totalAngle;
  var section = (0, _sector["default"])({
    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 = (0, _editorUtils.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 = (0, _PositionAnnotationOnCircle["default"])({
      sAngle: startAngle,
      eAngle: endAngle,
      height: 0
    }),
    transform = _PositionAnnotationOn.transform;
  return /*#__PURE__*/_react["default"].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["default"].createElement("title", null, selectionMessage), /*#__PURE__*/_react["default"].createElement("path", {
    transform: transform,
    className: "selectionLayer",
    style: _extends({
      opacity: 0.3
    }, style),
    d: section.path.print(),
    fill: color
  }), !hideCarets && /*#__PURE__*/_react["default"].createElement(_Caret["default"], {
    key: "caret1",
    className: className + " selectionLayerCaret " + (isDraggable ? _draggableClassnames["default"].selectionStart : ""),
    isSelection: true,
    onClick: onClick ? _teselagenReactComponents.noop : _editorUtils.preventDefaultStopPropagation,
    selectionMessage: selectionMessage,
    caretPosition: start,
    sequenceLength: sequenceLength,
    innerRadius: innerRadius,
    outerRadius: radius
  }), !hideCarets && /*#__PURE__*/_react["default"].createElement(_Caret["default"], {
    key: "caret2",
    className: className + " selectionLayerCaret " + (isDraggable ? _draggableClassnames["default"].selectionEnd : ""),
    isSelection: true,
    onClick: onClick ? _teselagenReactComponents.noop : _editorUtils.preventDefaultStopPropagation,
    selectionMessage: selectionMessage,
    caretPosition: end + 1,
    sequenceLength: sequenceLength,
    innerRadius: innerRadius,
    outerRadius: radius
  }));
}
var _default = (0, _pureNoFunc["default"])(SelectionLayer);
exports["default"] = _default;
module.exports = exports.default;