"use strict";

exports.__esModule = true;
exports.PairwiseAlignmentView = void 0;
var _react = _interopRequireDefault(require("react"));
var _getPairwiseOverviewLinearViewOptions = require("./getPairwiseOverviewLinearViewOptions");
var _index = require("./index");
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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
//this view is shown if we detect pairwise alignments
var PairwiseAlignmentView = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(PairwiseAlignmentView, _React$Component);
  function PairwiseAlignmentView() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _defineProperty(_assertThisInitialized(_this), "state", {
      currentPairwiseAlignmentIndex: undefined
    });
    return _this;
  }
  var _proto = PairwiseAlignmentView.prototype;
  _proto.render = function render() {
    var _this2 = this;
    var _this$props = this.props,
      pairwiseAlignments = _this$props.pairwiseAlignments,
      pairwiseOverviewAlignmentTracks = _this$props.pairwiseOverviewAlignmentTracks;
    var currentPairwiseAlignmentIndex = this.state.currentPairwiseAlignmentIndex;
    if (currentPairwiseAlignmentIndex > -1) {
      //we can render the AlignmentView directly
      //get the alignmentTracks based on currentPairwiseAlignmentIndex
      var alignmentTracks = pairwiseAlignments[currentPairwiseAlignmentIndex];
      var templateLength = alignmentTracks[0].alignmentData.sequence.length;
      return /*#__PURE__*/_react["default"].createElement(_index.AlignmentView, _extends({}, this.props, {
        sequenceData: {
          //pass fake seq data in so editor interactions work
          sequence: Array.from(templateLength).map(function () {
            return "a";
          }).join("")
        },
        allowTrackRearrange: false,
        alignmentTracks: alignmentTracks,
        hasTemplate: true,
        isPairwise: true,
        currentPairwiseAlignmentIndex: currentPairwiseAlignmentIndex,
        handleBackButtonClicked: function handleBackButtonClicked() {
          _this2.setState({
            currentPairwiseAlignmentIndex: undefined
          });
        }
      }));
    } else {
      //we haven't yet selected an alignment to view
      // render the AlignmentView zoomed out for each track in pairwiseOverviewAlignmentTracks
      // when the view eye icon is hit (maybe next to the name?)
      return /*#__PURE__*/_react["default"].createElement(_index.AlignmentView, _extends({}, this.props, {
        alignmentTracks: pairwiseOverviewAlignmentTracks,
        allowTrackRearrange: false,
        allowTrimming: false,
        hasTemplate: true,
        isPairwise: true,
        isInPairwiseOverviewView: true,
        isFullyZoomedOut: true,
        noClickDragHandlers: true,
        linearViewOptions: _getPairwiseOverviewLinearViewOptions.getPairwiseOverviewLinearViewOptions,
        handleSelectTrack: function handleSelectTrack(trackIndex) {
          //set currentPairwiseAlignmentIndex
          _this2.setState({
            currentPairwiseAlignmentIndex: trackIndex - 1
          });
        }
      }));
    }
  };
  return PairwiseAlignmentView;
}(_react["default"].Component);
exports.PairwiseAlignmentView = PairwiseAlignmentView;