import { combineReducers } from 'redux';
import HomeReducer from '@src/store/reducers/HomeReducer';
import UserReducer from '@src/store/reducers/UserReducer';
import ExploreReducer from '@src/store/reducers/ExploreReducer';
import SaleReducer from '@src/store/reducers/SaleReducer';
import TokenReducer from '@src/store/reducers/TokenReducer';
import CollectionReducer from '@src/store/reducers/CollectionReducer';
import { Action, configureStore } from '@reduxjs/toolkit';
import { ThunkAction } from 'redux-thunk';
import NetworkLoadingReducer from './reducers/NetworkLoadingReducer';

const rootReducer = combineReducers({
  home: HomeReducer,
  user: UserReducer,
  explore: ExploreReducer,
  sale: SaleReducer,
  token: TokenReducer,
  collection: CollectionReducer,
  networkLoading: NetworkLoadingReducer
});

declare global {
  interface Window {
    __REDUX_DEVTOOLS_EXTENSION__: any;
  }
}

const devTools =
  process.env.REACT_APP_STAGE !== 'production' && typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() : (f: any) => f;

const store = configureStore({
  reducer: rootReducer,
  devTools,
});

export type RootState = ReturnType<typeof rootReducer>;
export type AppThunk = ThunkAction<void, RootState, null, Action<string>>;
export type AppDispatch = typeof store.dispatch;

export default store;

