import { normalizePositionByRangeLength as norm } from "@teselagen/range-utils";
import { getRangeLength } from "@teselagen/range-utils";
export default function calculateTickMarkPositionsForGivenRange(_ref) {
  var _ref$tickSpacing = _ref.tickSpacing,
    _tickSpacing = _ref$tickSpacing === void 0 ? 10 : _ref$tickSpacing,
    range = _ref.range,
    sequenceLength = _ref.sequenceLength,
    isProtein = _ref.isProtein,
    increaseOffset = _ref.increaseOffset;
  if (sequenceLength === 0) {
    return [];
  }
  var tickSpacing = _tickSpacing;
  if (isProtein) {
    tickSpacing = Math.floor(_tickSpacing / 2 * 3);
  }
  var rangeLength = getRangeLength(range, sequenceLength);
  var spacer = 0;
  if (increaseOffset) {
    spacer = range.start;
  }
  var firstTickOffsetFromRangeStart = spacer + tickSpacing - range.start % tickSpacing;
  var tickMarks = [];
  if (range.start === 0) tickMarks.push(isProtein ? 2 : 0);
  var hasCrossedOrigin;
  for (var tick = firstTickOffsetFromRangeStart - 1; tick < spacer + rangeLength; tick += tickSpacing) {
    var normed = norm(tick, sequenceLength);
    if (!hasCrossedOrigin && normed < tick) {
      if (!(normed % 10) && normed !== 0) {
        tick = tick - 1;
        normed = normed - 1;
      }
      if (normed !== 0) hasCrossedOrigin = true;
    }
    tickMarks.push(normed);
  }
  return tickMarks;
}