import { createStore, compose, applyMiddleware } from 'redux';
import localForage from 'localforage';
import { persistReducer, persistStore } from 'redux-persist';
import { api } from '../middlewares/api';
import { exportStateMiddleware } from '../middlewares/exportState';
import { rootReducer } from '../reducers';
const persistConfig = {
  key: 'redux-devtools',
  blacklist: ['instances', 'socket'],
  storage: localForage
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
export default function configureStore(callback) {
  let composeEnhancers = compose;
  if (process.env.NODE_ENV !== 'production') {
    if (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) {
      composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
    }
  }
  const store = createStore(persistedReducer, composeEnhancers(applyMiddleware(exportStateMiddleware, api)));
  const persistor = persistStore(store, null, () => {
    callback(store);
  });
  return {
    store,
    persistor
  };
}