'use strict';

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

var _config = require('./config');

var _config2 = _interopRequireDefault(_config);

var _persistedState = require('./common/util/persistedState');

var _persistedState2 = _interopRequireDefault(_persistedState);

var _persistedStorageMiddleware = require('./common/middleware/persistedStorageMiddleware');

var _persistedStorageMiddleware2 = _interopRequireDefault(_persistedStorageMiddleware);

var _configureStore = require('./configureStore');

var _configureStore2 = _interopRequireDefault(_configureStore);

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

var store = (0, _configureStore2.default)({
  extraMiddleware: [(0, _persistedStorageMiddleware2.default)()],
  inDevelopment: _config2.default.inDevelopment(),
  initialState: _persistedState2.default.load()
});

if (_config2.default.inDevelopment()) {
  window.store = store;
  window.getState = store.getState;
  window.dispatch = store.dispatch;
}

function setFakeStore(fakeState) {
  store.useFakeState = true;
  store.fakeState = fakeState;
}

function unsetFakeStore(fakeState) {
  store.useFakeState = false;
  store.fakeState = null;
}

store.getAppState = function () {
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

  return store.useFakeState || opts.useFakeState ? store.fakeState : store.getState();
};

exports.default = store;