'use strict';

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

var _redux = require('redux');

var _reactRouter = require('react-router');

var _reactRouterRedux = require('react-router-redux');

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

var _reduxThunk2 = _interopRequireDefault(_reduxThunk);

var _reduxPromise = require('redux-promise');

var _reduxPromise2 = _interopRequireDefault(_reduxPromise);

var _reducers = require('../reducers');

var _reducers2 = _interopRequireDefault(_reducers);

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

/* eslint-disable import/newline-after-import */

var middleware = [(0, _reactRouterRedux.routerMiddleware)(_reactRouter.browserHistory), _reduxThunk2.default, _reduxPromise2.default];

function configureStore(initialState, onComplete) {
  var finalCreateStore = void 0;
  var devEnhancer = void 0;
  if (process.env.NODE_ENV === 'production') {
    finalCreateStore = _redux.applyMiddleware.apply(undefined, middleware)(_redux.createStore);
  } else {
    /* eslint-disable global-require, import/no-extraneous-dependencies */
    // const devTools = require('remote-redux-devtools');
    var createLogger = require('redux-logger');
    var loggerMiddleware = createLogger({ duration: true });
    finalCreateStore = (0, _redux.compose)(_redux.applyMiddleware.apply(undefined, middleware.concat([loggerMiddleware]))
    // devTools({ realtime: true })
    )(_redux.createStore);

    devEnhancer = window.devToolsExtension && window.devToolsExtension();
  }

  var store = finalCreateStore(_reducers2.default, initialState, devEnhancer);
  onComplete && onComplete();

  // Hot reload reducers (requires Webpack or Browserify HMR to be enabled)
  // if (module.hot) {
  //   module.hot.accept('../reducers', () =>
  //     store.replaceReducer(require('../reducers')/*.default if you use Babel 6+ */)
  //   );
  // }

  return store;
}