import {applyMiddleware, combineReducers, createStore} from "redux";
import {authReducer} from "./authReducer";
import {promiseReducer,promiseWatcher} from "./promiseReducer";
import {routeReducer, routeWatcher} from "./routeReducer";
import {playerReducer} from "./playerReducer";
import {fullLoginWatcher,regWatcher} from "../actions/login-reg-actions";
import {playlistFindByOwnerWatcher} from "../actions/find-actions";
import {setAvatarWatcher} from "../actions/set-avatar-actions";
import {
    fullUploadPlaylistsWatcher,
    playlistByIdWatcher,
    setTrackToPlaylistWatcher
} from "../actions/my-playlist-tracks-actions";
import {aboutMeWatcher,actionAboutMe} from "../actions/about-me-actions";
import {trackPlayWatcher,trackStopWatcher,setPlaylistWatcher,trackVolumeWatcher,trackLoadWatcher,
    nextTrackWatcher,previousTrackWatcher,
    // trackCurrentTimeWatcher,
} from "./playerReducer";


import {localStoredReducer} from "./localStoredReducer";
import createSagaMiddleware from 'redux-saga';
import {all} from 'redux-saga/effects';
import {createPlaylistWatcher} from "../actions/my-playlist-tracks-actions";
// import {setUserPasswordWatcher} from "../pages/header/header-build";


const sagaMiddleware = createSagaMiddleware()
export const store = createStore(combineReducers({promise: localStoredReducer(promiseReducer, 'promise'),
                                                             auth: localStoredReducer(authReducer, 'auth'),
                                                           player: localStoredReducer(playerReducer, 'player'),
                                                            route: localStoredReducer(routeReducer,'route')}),
                                                                   applyMiddleware(sagaMiddleware))

// export const store = createStore(combineReducers({promise: promiseReducer,
//         auth: authReducer}),
//     applyMiddleware(sagaMiddleware))


function* rootSaga(){
    yield all([
        promiseWatcher(),
         fullLoginWatcher(),
         regWatcher(),
         setAvatarWatcher(),
         aboutMeWatcher(),
         createPlaylistWatcher(),
         routeWatcher(),
          playlistFindByOwnerWatcher(),
          setTrackToPlaylistWatcher(),
          fullUploadPlaylistsWatcher(),
         setPlaylistWatcher(),
         trackPlayWatcher(),
        trackStopWatcher(),
        trackVolumeWatcher(),
        trackLoadWatcher(),
        nextTrackWatcher(),
        previousTrackWatcher(),
         playlistByIdWatcher()
         // trackCurrentTimeWatcher(),
         // setUserPasswordWatcher(),
    ])
}
store.dispatch(actionAboutMe())
sagaMiddleware.run(rootSaga)
store.subscribe(() => console.log(store.getState()))

