"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _AnnotationPositioner = require("../AnnotationPositioner");

var _AnnotationPositioner2 = _interopRequireDefault(_AnnotationPositioner);

var _AnnotationContainerHolder = require("../AnnotationContainerHolder");

var _AnnotationContainerHolder2 = _interopRequireDefault(_AnnotationContainerHolder);

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _pureNoFunc = require("../../utils/pureNoFunc");

var _pureNoFunc2 = _interopRequireDefault(_pureNoFunc);

require("./style.css");

var _getXStartAndWidthOfRangeWrtRow = require("../getXStartAndWidthOfRangeWrtRow");

var _getXStartAndWidthOfRangeWrtRow2 = _interopRequireDefault(_getXStartAndWidthOfRangeWrtRow);

var _veRangeUtils = require("ve-range-utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function LineageLines(props) {
  var charWidth = props.charWidth,
      bpsPerRow = props.bpsPerRow,
      row = props.row,
      sequenceLength = props.sequenceLength,
      _props$lineageLines = props.lineageLines,
      lineageLines = _props$lineageLines === undefined ? [] : _props$lineageLines,
      _props$lineageLineHei = props.lineageLineHeight,
      lineageLineHeight = _props$lineageLineHei === undefined ? 6 : _props$lineageLineHei,
      getGaps = props.getGaps;


  var lineageLinesToUse = lineageLines;
  if (!Array.isArray(lineageLines)) {
    lineageLinesToUse = [lineageLines];
  }
  return _react2.default.createElement(
    _AnnotationContainerHolder2.default,
    {
      className: "veRowViewLineageLines",
      containerHeight: lineageLineHeight
    },
    lineageLinesToUse.sort(function (lineageLine) {
      return lineageLine.inBetweenBps ? 1 : 0;
    }).map(function (lineageLine, index) {
      var rangeSpansSequence = lineageLine.start === lineageLine.end + 1 || lineageLine.start === 0 && lineageLine.end === sequenceLength - 1;
      var color = lineageLine.color;

      var overlaps = (0, _veRangeUtils.getOverlapsOfPotentiallyCircularRanges)(lineageLine, row, sequenceLength);
      return overlaps.map(function (overlap) {
        var _getXStartAndWidthOfR = _getXStartAndWidthOfRangeWrtRow2.default.apply(undefined, [overlap, row, bpsPerRow, charWidth, sequenceLength].concat(_toConsumableArray(getGaps ? getGaps(row) : []))),
            xStart = _getXStartAndWidthOfR.xStart,
            width = _getXStartAndWidthOfR.width;

        var lineageStart = (getGaps ? getGaps(overlap.start).gapsBefore : 0) + overlap.start === lineageLine.start;
        var lineageEnd = overlap.end === lineageLine.end;

        return [_react2.default.createElement(
          _AnnotationPositioner2.default,
          {
            height: lineageLineHeight,
            width: width,
            key: index,
            top: 0
            // className={classnames() }
            , left: xStart + (lineageLine.inBetweenBps ? charWidth / 1.2 : 0)
          },
          _react2.default.createElement(
            "g",
            null,
            _react2.default.createElement("rect", {
              fill: color,
              x: "0",
              y: "0",
              height: lineageLineHeight,
              width: width
            }),
            rangeSpansSequence && lineageStart && _react2.default.createElement("rect", {
              fill: "#408CE1",
              x: "0",
              y: "0",
              height: lineageLineHeight,
              width: 4
            }),
            rangeSpansSequence && lineageEnd && _react2.default.createElement("rect", {
              fill: "#408CE1",
              x: width - 4,
              y: "0",
              height: lineageLineHeight,
              width: 4
            })
          )
        )];
      });
    })
  );
}

exports.default = (0, _pureNoFunc2.default)(LineageLines);