/* eslint-disable global-require */
/* global window */
import { createStore, applyMiddleware, combineReducers } from 'redux';
import createSagaMiddleware from 'redux-saga';
import { isTest } from 'worona-deps';
import { reduxReactRouter } from 'redux-router';
import { composeWithDevTools } from 'redux-devtools-extension';
import build from '../reducers';
import settings from '../../settings-app-extension-worona/reducers';
import router from '../../router-app-extension-worona/reducers';

const sagaMiddleware = createSagaMiddleware();

const reducers = { build: build(), router: router(), settings: settings() };
const sagas = {};

const composeEnhancers = composeWithDevTools({
  serialize: false,
});

export const store = createStore(
  combineReducers(reducers),
  composeEnhancers(
    reduxReactRouter({
      createHistory: (
        !isTest ? require('history').createHistory : require('history').createMemoryHistory
      ),
    }),
    applyMiddleware(sagaMiddleware),
  ),
);

export default store;

export const dispatch = action => store.dispatch(action);
export const reloadReducers = () => store.replaceReducer(combineReducers(reducers));
export const addReducer = (namespace, reducer) => {
  if (reducer) reducers[namespace] = reducer;
};
export const removeReducer = namespce => {
  if (reducers[namespce]) delete reducers[namespce];
};
export const startSaga = (namespace, saga) => {
  sagas[namespace] = sagaMiddleware.run(saga);
};
export const stopSaga = namespace => {
  if (sagas[namespace]) sagas[namespace].cancel();
};
export const getState = store.getState.bind(store);
export const history = store.history;

@@ -182,16 +182,27 @@
 %7B isTest
+, isAndroid
  %7D from 
@@ -717,154 +717,137 @@
 );%0A%0A
-export const store = createStore(%0A  combineReducers(reducers),%0A  composeEnhancers(%0A    reduxReactRouter(%7B%0A      createHistory: (%0A        !isTest ?
+let createHistory = null;%0Aif (isTest) createHistory = require('history').createMemoryHistory;%0Aelse if (isAndroid) createHistory =
  req
@@ -873,16 +873,40 @@
 ateH
+ashH
 istory
- :
+;%0Aelse createHistory =
  req
@@ -931,42 +931,136 @@
 eate
-Memory
 History
-%0A      ),%0A    %7D),%0A   
+;%0A%0Aexport const store = createStore(%0A  combineReducers(reducers),%0A  composeEnhancers(reduxReactRouter(%7B createHistory %7D),
  app
@@ -1091,14 +1091,9 @@
 are)
-,%0A  ),
+)
 %0A);%0A

Use hash history if it's android