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); }
//tnr: not actually used yet. I don't think it is necessary
// for the cutsite label heights to be perfect

import getXStartAndWidthOfRowAnnotation from "./getXStartAndWidthOfRowAnnotation";
import IntervalTree from "node-interval-tree";
import getYOffset from "../CircularView/getYOffset";
import forEach from "lodash/forEach";
export default function getCutsiteLabelHeights(_ref) {
  var bpsPerRow = _ref.bpsPerRow,
    charWidth = _ref.charWidth,
    annotationRanges = _ref.annotationRanges,
    annotationHeight = _ref.annotationHeight,
    spaceBetweenAnnotations = _ref.spaceBetweenAnnotations,
    textWidth = _ref.textWidth;
  var rowLength = bpsPerRow * charWidth;
  var counter = 0;
  var maxAnnotationYOffset = 0;
  var rowCenter = rowLength / 2;
  var iTree = new IntervalTree(rowCenter);
  forEach(annotationRanges, function (annotationRange) {
    counter++;
    if (counter > 50) return;
    var annotation = annotationRange.annotation;
    if (!annotation) {
      annotation = annotationRange;
    }
    var labelLength = annotation.restrictionEnzyme.name.length * textWidth;
    var _getXStartAndWidthOfR = getXStartAndWidthOfRowAnnotation(annotationRange, bpsPerRow, charWidth),
      xStart = _getXStartAndWidthOfR.xStart;
    var xEnd = xStart + labelLength;
    if (xEnd > rowLength) {
      xStart = xStart - (xEnd - rowLength);
      xEnd = rowLength;
    }
    var yOffset = getYOffset(iTree, xStart, xEnd);
    iTree.insert(xStart, xEnd, _extends({}, annotationRange, {
      yOffset: yOffset
    }));
    if (yOffset > maxAnnotationYOffset) {
      maxAnnotationYOffset = yOffset;
    }
    var height = yOffset * (annotationHeight + spaceBetweenAnnotations);
    annotation.height = height;
  });
  var containerHeight = (maxAnnotationYOffset + 1) * (annotationHeight + spaceBetweenAnnotations);
  return containerHeight;
}