'use strict';

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

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

exports.default = configureStore;

var _redux = require('redux');

var _reduxImmutable = require('redux-immutable');

var _union = require('lodash/union');

var _union2 = _interopRequireDefault(_union);

var _flowRight = require('lodash/flowRight');

var _flowRight2 = _interopRequireDefault(_flowRight);

var _reduxLogger = require('redux-logger');

var _reduxLogger2 = _interopRequireDefault(_reduxLogger);

var _reduxMulti = require('redux-multi');

var _reduxMulti2 = _interopRequireDefault(_reduxMulti);

var _reduxThunk = require('redux-thunk');

var _reduxThunk2 = _interopRequireDefault(_reduxThunk);

var _alertTimerMiddleware = require('./common/middleware/alertTimerMiddleware');

var _alertTimerMiddleware2 = _interopRequireDefault(_alertTimerMiddleware);

var _crossDomainMessagingMiddleware = require('./common/middleware/crossDomainMessagingMiddleware');

var _crossDomainMessagingMiddleware2 = _interopRequireDefault(_crossDomainMessagingMiddleware);

var _eventLoggerMiddleware = require('./common/middleware/eventLoggerMiddleware');

var _eventLoggerMiddleware2 = _interopRequireDefault(_eventLoggerMiddleware);

var _alerts = require('./common/reducers/alerts');

var _alerts2 = _interopRequireDefault(_alerts);

var _banks = require('./common/reducers/banks');

var _banks2 = _interopRequireDefault(_banks);

var _bankEntries = require('./common/reducers/bankEntries');

var _bankEntries2 = _interopRequireDefault(_bankEntries);

var _calls = require('./common/reducers/calls');

var _calls2 = _interopRequireDefault(_calls);

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

var _config2 = _interopRequireDefault(_config);

var _editing = require('./common/reducers/editing');

var _editing2 = _interopRequireDefault(_editing);

var _errorsShowing = require('./common/reducers/errorsShowing');

var _errorsShowing2 = _interopRequireDefault(_errorsShowing);

var _features = require('./common/reducers/features');

var _features2 = _interopRequireDefault(_features);

var _interactionTypes = require('./common/reducers/interactionTypes');

var _interactionTypes2 = _interopRequireDefault(_interactionTypes);

var _items = require('./common/reducers/items');

var _items2 = _interopRequireDefault(_items);

var _modal = require('./common/reducers/modal');

var _modal2 = _interopRequireDefault(_modal);

var _moderation = require('./common/reducers/moderation');

var _moderation2 = _interopRequireDefault(_moderation);

var _modifications = require('./common/reducers/modifications');

var _modifications2 = _interopRequireDefault(_modifications);

var _outcomes = require('./common/reducers/outcomes');

var _outcomes2 = _interopRequireDefault(_outcomes);

var _quizzes = require('./common/reducers/quizzes');

var _quizzes2 = _interopRequireDefault(_quizzes);

var _quizEntries = require('./common/reducers/quizEntries');

var _quizEntries2 = _interopRequireDefault(_quizEntries);

var _quizSessions = require('./common/reducers/quizSessions');

var _quizSessions2 = _interopRequireDefault(_quizSessions);

var _quizSessionEvents = require('./common/reducers/quizSessionEvents');

var _quizSessionEvents2 = _interopRequireDefault(_quizSessionEvents);

var _quizSessionResults = require('./common/reducers/quizSessionResults');

var _quizSessionResults2 = _interopRequireDefault(_quizSessionResults);

var _regrading = require('./common/reducers/regrading');

var _regrading2 = _interopRequireDefault(_regrading);

var _reporting = require('./common/reducers/reporting');

var _reporting2 = _interopRequireDefault(_reporting);

var _scrolling = require('./common/reducers/scrolling');

var _scrolling2 = _interopRequireDefault(_scrolling);

var _sessionItems = require('./common/reducers/sessionItems');

var _sessionItems2 = _interopRequireDefault(_sessionItems);

var _sessionItemResults = require('./common/reducers/sessionItemResults');

var _sessionItemResults2 = _interopRequireDefault(_sessionItemResults);

var _sidebar = require('./common/reducers/sidebar');

var _sidebar2 = _interopRequireDefault(_sidebar);

var _stimuli = require('./common/reducers/stimuli');

var _stimuli2 = _interopRequireDefault(_stimuli);

var _taking = require('./common/reducers/taking');

var _taking2 = _interopRequireDefault(_taking);

var _ui = require('./common/reducers/ui');

var _ui2 = _interopRequireDefault(_ui);

var _upload = require('./common/reducers/upload');

var _upload2 = _interopRequireDefault(_upload);

var _qtiImports = require('./common/reducers/qtiImports');

var _qtiImports2 = _interopRequireDefault(_qtiImports);

var _dragAndDrop = require('./common/reducers/dragAndDrop');

var _dragAndDrop2 = _interopRequireDefault(_dragAndDrop);

var _sharedBanks = require('./common/reducers/sharedBanks');

var _sharedBanks2 = _interopRequireDefault(_sharedBanks);

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

// reducers


// middleware
function configureStore(_ref) {
  var _ref$extraMiddleware = _ref.extraMiddleware,
      extraMiddleware = _ref$extraMiddleware === undefined ? [] : _ref$extraMiddleware,
      _ref$inDevelopment = _ref.inDevelopment,
      inDevelopment = _ref$inDevelopment === undefined ? false : _ref$inDevelopment,
      _ref$initialState = _ref.initialState,
      initialState = _ref$initialState === undefined ? void 0 : _ref$initialState;

  var loggerMiddleware = (0, _reduxLogger2.default)({
    // immutable state returned as raw JS
    // for readability's sake
    stateTransformer: function stateTransformer(s) {
      return s.toJS();
    },
    collapsed: true,
    titleFormatter: function titleFormatter(action) {
      return 'SDK action %c' + String(action.type);
    }
  });

  var kinesisMiddleware = (0, _eventLoggerMiddleware2.default)();

  var baseMiddleware = [_alertTimerMiddleware2.default, _crossDomainMessagingMiddleware2.default, _reduxMulti2.default, kinesisMiddleware, _reduxThunk2.default];

  var devMiddleware = [loggerMiddleware];

  var middlewareToApply = inDevelopment ? (0, _union2.default)(baseMiddleware, devMiddleware) : baseMiddleware;

  middlewareToApply = (0, _union2.default)(middlewareToApply, extraMiddleware);

  var createStoreWithMiddlewareApplied = (0, _flowRight2.default)(_redux.applyMiddleware.apply(undefined, (0, _toConsumableArray3.default)(middlewareToApply)),
  // todo: tweak middleware to handle (re)routing with devtools
  window.devToolsExtension ? window.devToolsExtension({ name: 'quiz-core' }) : function (f) {
    return f;
  })(_redux.createStore);

  var rootReducer = (0, _reduxImmutable.combineReducers)({
    dragAndDrop: _dragAndDrop2.default,
    alerts: _alerts2.default,
    banks: _banks2.default,
    bankEntries: _bankEntries2.default,
    sharedBanks: _sharedBanks2.default,
    calls: _calls2.default,
    config: _config2.default,
    editing: _editing2.default,
    errorsShowing: _errorsShowing2.default,
    features: _features2.default,
    interactionTypes: _interactionTypes2.default,
    items: _items2.default,
    modal: _modal2.default,
    moderation: _moderation2.default,
    modifications: _modifications2.default,
    outcomes: _outcomes2.default,
    quizzes: _quizzes2.default,
    quizEntries: _quizEntries2.default,
    quizSessions: _quizSessions2.default,
    quizSessionEvents: _quizSessionEvents2.default,
    quizSessionResults: _quizSessionResults2.default,
    qtiImports: _qtiImports2.default,
    regrading: _regrading2.default,
    reporting: _reporting2.default,
    scrolling: _scrolling2.default,
    sessionItems: _sessionItems2.default,
    sessionItemResults: _sessionItemResults2.default,
    sidebar: _sidebar2.default,
    stimuli: _stimuli2.default,
    taking: _taking2.default,
    ui: _ui2.default,
    upload: _upload2.default
  });

  return createStoreWithMiddlewareApplied(rootReducer, initialState);
}