"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _shortid = _interopRequireDefault(require("shortid"));
var _circularSelector = _interopRequireDefault(require("./circularSelector"));
var _sequenceSelector = _interopRequireDefault(require("./sequenceSelector"));
var _restrictionEnzymesSelector = _interopRequireDefault(require("./restrictionEnzymesSelector"));
var _cutsiteLabelColorSelector = _interopRequireDefault(require("./cutsiteLabelColorSelector"));
var _reselect = require("reselect");
var _lodash = require("lodash");
var _sequenceUtils = require("@teselagen/sequence-utils");
var _arrayUtils = require("../utils/arrayUtils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function cutsitesSelector(sequence, circular, enzymeList, cutsiteLabelColors) {
  //get the cutsites grouped by enzyme
  var cutsitesByName = (0, _arrayUtils.getLowerCaseObj)((0, _sequenceUtils.getCutsitesFromSequence)(sequence, circular, (0, _lodash.map)(enzymeList)));
  //tag each cutsite with a unique id
  var cutsitesById = {};
  Object.keys(cutsitesByName).forEach(function (enzymeName) {
    var cutsitesForEnzyme = cutsitesByName[enzymeName];
    cutsitesForEnzyme.forEach(function (cutsite) {
      var numberOfCuts = cutsitesByName[enzymeName].length;
      var uniqueId = (0, _shortid["default"])();
      cutsite.id = uniqueId;
      cutsite.numberOfCuts = numberOfCuts;
      cutsite.annotationType = "cutsite";
      cutsitesById[uniqueId] = cutsite;
      var mergedCutsiteColors = Object.assign({
        single: "salmon",
        "double": "lightblue",
        multi: "lightgrey"
      }, cutsiteLabelColors);
      if (numberOfCuts === 1) {
        cutsite.labelColor = mergedCutsiteColors.single;
        cutsite.labelClassname = "singleCutter";
      } else if (numberOfCuts === 2) {
        cutsite.labelColor = mergedCutsiteColors["double"];
        cutsite.labelClassname = "doubleCutter";
      } else {
        cutsite.labelColor = mergedCutsiteColors.multi;
        cutsite.labelClassname = "multiCutter";
      }
    });
  });
  // create an array of the cutsites
  var cutsitesArray = (0, _lodash.flatMap)(cutsitesByName, function (cutsitesForEnzyme) {
    return cutsitesForEnzyme;
  });
  return {
    cutsitesByName: cutsitesByName,
    cutsitesById: cutsitesById,
    cutsitesArray: cutsitesArray
  };
}
var _default = (0, _reselect.createSelector)(_sequenceSelector["default"], _circularSelector["default"], _restrictionEnzymesSelector["default"], _cutsiteLabelColorSelector["default"], cutsitesSelector);
exports["default"] = _default;
module.exports = exports.default;