import { combineReducers } from '@reduxjs/toolkit';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';

import reducerMessages from '../messages/reducer'
import reducerAllMessages from '../allMessages/reducer'
import reducerContacts from '../contacts/reducer'
import reducerChat from '../chat/reducer'
import reducerChats from '../chats/reducer'
import reducerControl from '../control/reducer'
import reducerLoading from '../loading/reducer';
import reducerAuthorization from '../authorization/reducer';

const authorizationPersistConfig = {
  key: 'auth',
  storage: storage,
};

export const rootReducer = combineReducers({
  isLoading: reducerLoading,
  messages: reducerMessages,
  allMessages: reducerAllMessages,
  chat:reducerChat,
  chats: reducerChats,
  contacts:reducerContacts,
  control: reducerControl,
  authorization: persistReducer(
    authorizationPersistConfig,
    reducerAuthorization,
  ),
});
