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); }
import { reduce } from "lodash";
import uuid from "shortid";
import sequenceSelector from "./sequenceSelector";
import orfsSelector from "./orfsSelector";
import { createSelector } from "reselect";
import { getAminoAcidDataForEachBaseOfDna } from "@teselagen/sequence-utils";
import each from "lodash/each";
import translationsRawSelector from "./translationsRawSelector";
import translationSearchMatchesSelector from "./translationSearchMatchesSelector";
import { normalizePositionByRangeLength } from "@teselagen/range-utils";
import cdsFeaturesSelector from "./cdsFeaturesSelector";
import circularSelector from "./circularSelector";
function translationsSelector(isCircular, translationSearchMatches, sequence, orfs, showOrfTranslations, showOrfs, cdsFeatures, showCdsFeatureTranslations, showFeatures, translations, frameTranslations) {
  var translationsToPass = _extends({}, translationSearchMatches.reduce(function (acc, match) {
    if (!match) return acc;
    var id = match.id || uuid();
    acc[id] = _extends({}, match, {
      id: id,
      translationType: "AA Search Match",
      isOrf: true,
      //pass isOrf = true here in order to not have it show up in the properties window
      forward: !match.bottomStrand
    });
    return acc;
  }, {}), reduce(translations, function (acc, translation) {
    if (!translation.isOrf) {
      acc[translation.id] = _extends({}, translation, {
        translationType: "User Created"
      });
    }
    return acc;
  }, {}), showOrfTranslations && showOrfs ? reduce(orfs, function (acc, orf) {
    acc[orf.id] = _extends({}, orf, {
      translationType: "ORF"
    });
    return acc;
  }, {}) : {}, showCdsFeatureTranslations && showFeatures && reduce(cdsFeatures, function (acc, cdsFeature) {
    acc[cdsFeature.id] = _extends({}, cdsFeature, {
      translationType: "CDS Feature"
    });
    return acc;
  }, {}), reduce(frameTranslations, function (acc, isActive, frameName) {
    var frameOffset = Number(frameName);
    if (isActive) {
      var id = uuid();
      acc[id] = {
        id: id,
        start: isCircular || frameOffset > 0 ? normalizePositionByRangeLength(0 + frameOffset + (frameOffset > 0 ? -1 : 1), sequence.length) : 0,
        end: isCircular || frameOffset < 0 ? normalizePositionByRangeLength(sequence.length - 1 + frameOffset + (frameOffset > 0 ? -1 : 1), sequence.length) : sequence.length - 1,
        translationType: "Frame",
        forward: frameOffset > 0,
        isOrf: true //pass isOrf = true here in order to not have it show up in the properties window
      };
    }

    return acc;
  }, {}));
  each(translationsToPass, function (translation) {
    translation.aminoAcids = getAminoAcidDataForEachBaseOfDna(sequence, translation.forward, translation);
  });
  return translationsToPass;
}
export default createSelector(circularSelector, translationSearchMatchesSelector, sequenceSelector, orfsSelector, function (state) {
  return state.annotationVisibility.orfTranslations;
}, function (state) {
  return state.annotationVisibility.orfs;
}, cdsFeaturesSelector, function (state) {
  return state.annotationVisibility.cdsFeatureTranslations;
}, function (state) {
  return state.annotationVisibility.features;
}, translationsRawSelector, function (state) {
  return state.frameTranslations;
}, function (state) {
  return state.sequenceData.isProtein;
}, function (state) {
  return state.sequenceData.proteinSequence;
}, translationsSelector);