import _regeneratorRuntime from "@babel/runtime/regenerator";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import { applyMiddleware, createStore, combineReducers } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import { reducer as formReducer } from 'redux-form';
import { fork, all } from 'redux-saga/effects';
import createSagaMiddleware from 'redux-saga';
import appReducer from '../containers/App/reducer'; // import authReducer from '../containers/Auth/reducer';

import statusReducer from '../containers/Status/reducer';
import routerReducer from '../containers/Router/reducer'; // import authSaga from '../containers/Auth/saga';

import statusSaga from '../containers/Status/saga';
var globalReducer = combineReducers({
  app: appReducer,
  router: routerReducer,
  // auth: authReducer,
  status: statusReducer
});

var registerReducers = function registerReducers(reducers) {
  return combineReducers(_objectSpread({
    form: formReducer,
    global: globalReducer
  }, reducers));
};

var registerSagas = function registerSagas(sagas) {
  return (
    /*#__PURE__*/
    _regeneratorRuntime.mark(function rootSaga() {
      return _regeneratorRuntime.wrap(function rootSaga$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return all([// fork(authSaga),
              fork(statusSaga)].concat(_toConsumableArray(sagas.map(function (x) {
                return fork(x);
              }))));

            case 2:
            case "end":
              return _context.stop();
          }
        }
      }, rootSaga, this);
    })
  );
}; // configure store to register reducers and sagas in combination
// with our reducers and sags, and add dev tools


var configureStore = function configureStore() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var _options$initialState = options.initialState,
      initialState = _options$initialState === void 0 ? {} : _options$initialState,
      _options$reducers = options.reducers,
      reducers = _options$reducers === void 0 ? {} : _options$reducers,
      _options$sagas = options.sagas,
      sagas = _options$sagas === void 0 ? [] : _options$sagas;
  var sagaMiddleware = createSagaMiddleware();
  var middlewares = [sagaMiddleware];
  var rootReducer = registerReducers(reducers);
  var rootSaga = registerSagas(sagas);
  console.log('ROOT: ', rootReducer);
  var store = createStore(rootReducer, initialState, composeWithDevTools(applyMiddleware.apply(void 0, middlewares)));
  sagaMiddleware.run(rootSaga);
  return store;
};

export default configureStore;