var _excluded = ["start", "end"];
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 _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { findSequenceMatches } from "@teselagen/sequence-utils";
import sequenceSelector from "./sequenceSelector";
import { createSelector } from "reselect";
import circularSelector from "./circularSelector";
function searchLayersSelector(sequence, isCircular, isOpen, searchString, ambiguousOrLiteral, dnaOrAA, isProtein, proteinSequence) {
  if (!searchString || !isOpen) {
    return [];
  }
  if (isProtein) {
    var searchingDna = dnaOrAA === "DNA";
    var _matches = findSequenceMatches(searchingDna ? sequence : proteinSequence, searchString, {
      isCircular: false,
      isProteinSequence: true,
      isAmbiguous: ambiguousOrLiteral === "AMBIGUOUS",
      // isProteinSearch: dnaOrAA !== "DNA",
      searchReverseStrand: false
    }).sort(function (_ref, _ref2) {
      var start = _ref.start;
      var start2 = _ref2.start;
      return start - start2;
    });
    return searchingDna ? _matches : _matches.map(function (_ref3) {
      var start = _ref3.start,
        end = _ref3.end,
        rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
      return _extends({}, rest, {
        isSearchLayer: true,
        start: start * 3,
        end: end * 3 + 2
      });
    });
  }
  var matches = findSequenceMatches(sequence, searchString, {
    isCircular: isCircular,
    isAmbiguous: ambiguousOrLiteral === "AMBIGUOUS",
    isProteinSearch: dnaOrAA !== "DNA",
    searchReverseStrand: true
  }).sort(function (_ref4, _ref5) {
    var start = _ref4.start;
    var start2 = _ref5.start;
    return start - start2;
  });
  return matches.map(function (match) {
    return _extends({}, match, {
      forward: !match.bottomStrand,
      className: "veSearchLayer " + (match.bottomStrand ? " veSearchLayerBottomStrand" : ""),
      isSearchLayer: true
    });
  });
}
export default createSelector(sequenceSelector, circularSelector, function (state) {
  return state.findTool && state.findTool.isOpen;
}, function (state) {
  return state.findTool && state.findTool.searchText;
}, function (state) {
  return state.findTool && state.findTool.ambiguousOrLiteral;
}, function (state) {
  return state.findTool && state.findTool.dnaOrAA;
}, function (state) {
  return state.sequenceData.isProtein;
}, function (state) {
  return state.sequenceData.proteinSequence;
}, searchLayersSelector);