"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _AnnotationPositioner = _interopRequireDefault(require("../AnnotationPositioner"));
var _AnnotationContainerHolder = _interopRequireDefault(require("../AnnotationContainerHolder"));
var _react = _interopRequireDefault(require("react"));
var _pureNoFunc = _interopRequireDefault(require("../../utils/pureNoFunc"));
require("./style.css");
var _getXStartAndWidthOfRangeWrtRow = _interopRequireDefault(require("../getXStartAndWidthOfRangeWrtRow"));
var _rangeUtils = require("@teselagen/range-utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function DeletionLayers(props) {
  var charWidth = props.charWidth,
    row = props.row,
    sequenceLength = props.sequenceLength,
    deletionLayerClicked = props.deletionLayerClicked,
    deletionLayerRightClicked = props.deletionLayerRightClicked,
    _props$deletionLayers = props.deletionLayers,
    deletionLayers = _props$deletionLayers === void 0 ? {} : _props$deletionLayers,
    _props$deletionLineHe = props.deletionLineHeight,
    deletionLineHeight = _props$deletionLineHe === void 0 ? 6 : _props$deletionLineHe;
  var deletionLayersToUse = Object.keys(deletionLayers).map(function (key) {
    return deletionLayers[key];
  });
  if (!deletionLayersToUse.length) return null;
  return /*#__PURE__*/_react["default"].createElement(_AnnotationContainerHolder["default"], {
    className: "veRowViewDeletionLayers",
    containerHeight: deletionLineHeight
  }, deletionLayersToUse.sort(function (deletionLayer) {
    return deletionLayer.inBetweenBps ? 1 : 0;
  }).map(function (deletionLayer, index) {
    var rangeSpansSequence = deletionLayer.start === deletionLayer.end + 1 || deletionLayer.start === 0 && deletionLayer.end === sequenceLength - 1;
    var color = deletionLayer.color;
    var overlaps = (0, _rangeUtils.getOverlapsOfPotentiallyCircularRanges)(deletionLayer, row, sequenceLength);
    return overlaps.map(function (overlap) {
      var _getXStartAndWidthOfR = (0, _getXStartAndWidthOfRangeWrtRow["default"])({
          range: overlap,
          row: row,
          charWidth: charWidth,
          sequenceLength: sequenceLength
        }),
        xStart = _getXStartAndWidthOfR.xStart,
        width = _getXStartAndWidthOfR.width;
      var deletionStart = overlap.start === deletionLayer.start;
      var deletionEnd = overlap.end === deletionLayer.end;
      return [/*#__PURE__*/_react["default"].createElement(_AnnotationPositioner["default"], {
        height: deletionLineHeight,
        width: width,
        key: index,
        top: 0
        // className={classnames() }
        ,
        left: xStart + (deletionLayer.inBetweenBps ? charWidth / 1.2 : 0)
      }, /*#__PURE__*/_react["default"].createElement("g", {
        className: "clickable",
        onClick: function onClick(event) {
          deletionLayerClicked({
            annotation: deletionLayer,
            event: event
          });
        },
        onContextMenu: function onContextMenu(event) {
          deletionLayerRightClicked({
            annotation: deletionLayer,
            event: event
          });
        }
      }, /*#__PURE__*/_react["default"].createElement("rect", {
        fill: color,
        x: "0",
        y: "0",
        height: deletionLineHeight,
        width: width
      }), rangeSpansSequence && deletionStart && /*#__PURE__*/_react["default"].createElement("rect", {
        fill: "blue",
        x: "0",
        y: "0",
        height: deletionLineHeight,
        width: 4
      }), rangeSpansSequence && deletionEnd && /*#__PURE__*/_react["default"].createElement("rect", {
        fill: "blue",
        x: width - 4,
        y: "0",
        height: deletionLineHeight,
        width: 4
      })))];
    });
  }));
}
var _default = (0, _pureNoFunc["default"])(DeletionLayers);
exports["default"] = _default;
module.exports = exports.default;