'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _immutable = require('immutable');

var _store = require('store');

var _store2 = _interopRequireDefault(_store);

var _sessionStore = require('./sessionStore');

var _sessionStore2 = _interopRequireDefault(_sessionStore);

var _constants = require('../../constants');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var PersistedState = function () {
  function PersistedState() {
    (0, _classCallCheck3.default)(this, PersistedState);
  }

  (0, _createClass3.default)(PersistedState, [{
    key: 'load',

    /**
     * Some of our redux store values are stored in browser client-side storage
     * for easy recall in the event of a page refresh, etc. This provides a single
     * place to load all of those values in a form mimicking our redux store so
     * that it can easily be used, for example, for setting the redux initial
     * state.
     *
     * See also src/common/middleware/persistedStorageMiddleware.js for how these
     * values are set.
     */
    value: function load() {
      if (!_sessionStore2.default.enabled) {
        return;
      }

      return (0, _immutable.Map)({
        taking: (0, _immutable.Map)({
          sessionIdForCurrentItem: _store2.default.get(_constants.CACHED_SESSION_ID),
          currentSessionItemPosition: parseInt(_store2.default.get(_constants.ACTIVE_QUESTION), 10) || 1
        })
      });
    }
  }]);
  return PersistedState;
}();

exports.default = new PersistedState();