"use strict";

exports.__esModule = true;
var _exportNames = {
  updateSequenceData: true
};
exports["default"] = _default;
exports.updateSequenceData = void 0;
var _deepEqual = _interopRequireDefault(require("deep-equal"));
var _sequenceUtils = require("@teselagen/sequence-utils");
var _shortid = _interopRequireDefault(require("shortid"));
var _createMetaAction = _interopRequireDefault(require("../utils/createMetaAction"));
var _features = _interopRequireWildcard(require("./features"));
Object.keys(_features).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _features[key]) return;
  exports[key] = _features[key];
});
var _parts = _interopRequireWildcard(require("./parts"));
Object.keys(_parts).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _parts[key]) return;
  exports[key] = _parts[key];
});
var _name = _interopRequireWildcard(require("./name"));
Object.keys(_name).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _name[key]) return;
  exports[key] = _name[key];
});
var _description = _interopRequireWildcard(require("./description"));
Object.keys(_description).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _description[key]) return;
  exports[key] = _description[key];
});
var _primers = _interopRequireWildcard(require("./primers"));
Object.keys(_primers).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _primers[key]) return;
  exports[key] = _primers[key];
});
var _sequence = _interopRequireDefault(require("./sequence"));
var _circular = _interopRequireWildcard(require("./circular"));
Object.keys(_circular).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _circular[key]) return;
  exports[key] = _circular[key];
});
var _materiallyAvailable = _interopRequireWildcard(require("./materiallyAvailable"));
Object.keys(_materiallyAvailable).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _materiallyAvailable[key]) return;
  exports[key] = _materiallyAvailable[key];
});
var _translations = _interopRequireWildcard(require("./translations"));
Object.keys(_translations).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _translations[key]) return;
  exports[key] = _translations[key];
});
var _combineReducersDontIgnoreKeys = _interopRequireDefault(require("../../utils/combineReducersDontIgnoreKeys"));
var _reduxAct = require("redux-act");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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); }
// ------------------------------------
// Actions
// ------------------------------------

var _updateSequenceData = (0, _createMetaAction["default"])("SEQUENCE_DATA_UPDATE");
var updateSequenceData = function updateSequenceData(seqData) {
  for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
    rest[_key - 1] = arguments[_key];
  }
  //tnrtodo: currently we're not using that type variable for anything
  return _updateSequenceData.apply(void 0, [(0, _sequenceUtils.tidyUpSequenceData)(seqData, {
    annotationsAsObjects: true
  })].concat(rest));
};

// ------------------------------------
// Reducer
// ------------------------------------
exports.updateSequenceData = updateSequenceData;
var coreReducer = (0, _combineReducersDontIgnoreKeys["default"])({
  primers: _primers["default"],
  features: _features["default"],
  parts: _parts["default"],
  sequence: _sequence["default"],
  translations: _translations["default"],
  size: function size(state) {
    if (state === void 0) {
      state = {};
    }
    return state;
  },
  circular: _circular["default"],
  materiallyAvailable: _materiallyAvailable["default"],
  name: _name["default"],
  description: _description["default"],
  fromFileUpload: (0, _reduxAct.createReducer)({}, false)
});
function _default(state, action) {
  var stateToPass = state;
  if (action.type === "SEQUENCE_DATA_UPDATE") {
    stateToPass = action.payload;
  }
  //tnr: do a clone deep here in order to make sure we are using a totally new object for undo/redo tracking
  // stateToPass = cloneDeep(stateToPass);

  var newState = coreReducer(stateToPass, action);
  if ((0, _deepEqual["default"])(newState, state)) {
    return state;
  } else {
    //tnr: do a clone deep here in order to make sure we are using a totally new object for undo/redo tracking
    // mm: we don't need this if we are not mutating the newState, which we shouldn't be doing.
    return _extends({}, newState, {
      stateTrackingId: newState.stateTrackingId ? (0, _shortid["default"])() : "initialLoadId"
    });
  }
}