import { createStore, combineRedusers, applyMiddleware } from 'redux';
import thunk from "redux-thunk";

import { promiseReducer, localStoredReducer, totalReducer, authReducer } from "./reducers";

import { actionPending, actionFulfilled, actionRejected, actionPromise, actionFullLogin, actionLogin } from "./action";

// объект со всеми редьюсерами
// const reducers = {
//     promise: localStoredReducer(promiseReducer, 'promise'),
//     auth: localStoredReducer(authReducer, 'auth'),
//     // cart: localStoredReducer(cartReducer, 'cart'),
// }

// const totalReducer = combineRedusers(reducers)

// создаем store для редьюсера
// export const store = createStore(promiseReducer, applyMiddleware(thunk))
// store.subscribe(() => console.log(store.getState()))

// 2 изменение
export const store = createStore(totalReducer, applyMiddleware(thunk))
store.subscribe(() => console.log(store.getState()))

// запрос на логинизацию
// store.dispatch(actionFullLogin('volddemar4ik', 'Qwerty1324'))



// вот это раскомментитьь
// if (localStorage.authToken == undefined) {
//     store.dispatch(actionFullLogin('volddemar4ik', 'Qwerty1324'))
// }
