import {AsyncStorage} from "react-native";
import {persistReducer, persistStore} from "redux-persist";
import {createStore, applyMiddleware, compose} from "redux";
import thunk from 'redux-thunk';
import {createLogger} from 'redux-logger';
import rootReducer from "./reducers";
import ApiMiddleware from "../middlewares/ApiMiddleware";


/* const persistConfig = {
     key: 'root',
     storage: AsyncStorage,
     whitelist: ['authKeyReducer'],
     blacklist: []
}; */
const middlewares = [];
middlewares.push(thunk);
middlewares.push(ApiMiddleware);

const loggerMiddleware = createLogger({
    predicate: () => process.env.NODE_ENV === 'development'
})
middlewares.push(loggerMiddleware);

const store = createStore(rootReducer, compose(applyMiddleware(...middlewares)));
let persistor = persistStore(store);

export {store, persistor};
