import {  createStore, applyMiddleware } from "redux"
import logger from 'redux-logger'
import thunk from 'redux-thunk'
import createSagaMiddleware from 'redux-saga'
import rootReducer from "./root-reducer"
//import root-sagas for actions
import rootSaga from "./root-saga"

const sagaMiddleware = createSagaMiddleware()
const middlewares = [thunk, sagaMiddleware]
if(process.env.NODE_ENV === 'development'){
    middlewares.push(logger)
}

const createStoreWithMiddleWare = applyMiddleware(...middlewares)( createStore )
const store = createStoreWithMiddleWare(rootReducer,     
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
)
sagaMiddleware.run(rootSaga)

export default store