"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _redux = require("redux");

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

var _union = _interopRequireDefault(require("lodash/union"));

var _flowRight = _interopRequireDefault(require("lodash/flowRight"));

var _reduxLogger = _interopRequireDefault(require("redux-logger"));

var _reduxMulti = _interopRequireDefault(require("redux-multi"));

var _reduxThunk = _interopRequireDefault(require("redux-thunk"));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

var _bankSearch = _interopRequireDefault(require("./common/reducers/bankSearch"));

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

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

var _tagAssociations = _interopRequireDefault(require("./common/reducers/tagAssociations"));

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

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

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

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

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

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

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

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

// middleware
// reducers
function configureStore(_ref) {
  var _ref$extraMiddleware = _ref.extraMiddleware,
      extraMiddleware = _ref$extraMiddleware === void 0 ? [] : _ref$extraMiddleware,
      _ref$inDevelopment = _ref.inDevelopment,
      inDevelopment = _ref$inDevelopment === void 0 ? false : _ref$inDevelopment,
      _ref$initialState = _ref.initialState,
      initialState = _ref$initialState === void 0 ? void 0 : _ref$initialState;
  var loggerMiddleware = (0, _reduxLogger.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".concat(String(action.type));
    }
  });
  var kinesisMiddleware = (0, _eventLoggerMiddleware.default)();
  var baseMiddleware = [_alertTimerMiddleware.default, _crossDomainMessagingMiddleware.default, _reduxMulti.default, kinesisMiddleware, _reduxThunk.default];
  var devMiddleware = [loggerMiddleware];
  var middlewareToApply = inDevelopment ? (0, _union.default)(baseMiddleware, devMiddleware) : baseMiddleware;
  middlewareToApply = (0, _union.default)(middlewareToApply, extraMiddleware);
  var createStoreWithMiddlewareApplied = (0, _flowRight.default)(_redux.applyMiddleware.apply(void 0, (0, _toConsumableArray2.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: _dragAndDrop.default,
    alerts: _alerts.default,
    banks: _banks.default,
    bankEntries: _bankEntries.default,
    sharedBanks: _sharedBanks.default,
    calls: _calls.default,
    config: _config.default,
    editing: _editing.default,
    errorsShowing: _errorsShowing.default,
    features: _features.default,
    interactionTypes: _interactionTypes.default,
    items: _items.default,
    modal: _modal.default,
    moderation: _moderation.default,
    modifications: _modifications.default,
    outcomes: _outcomes.default,
    quizzes: _quizzes.default,
    quizEntries: _quizEntries.default,
    quizSessions: _quizSessions.default,
    quizSessionEvents: _quizSessionEvents.default,
    quizSessionResults: _quizSessionResults.default,
    qtiImports: _qtiImports.default,
    regrading: _regrading.default,
    reporting: _reporting.default,
    scrolling: _scrolling.default,
    bankSearch: _bankSearch.default,
    sessionItems: _sessionItems.default,
    sessionItemResults: _sessionItemResults.default,
    sidebar: _sidebar.default,
    stimuli: _stimuli.default,
    tagAssociations: _tagAssociations.default,
    taking: _taking.default,
    ui: _ui.default,
    upload: _upload.default
  });
  return createStoreWithMiddlewareApplied(rootReducer, initialState);
}