import { combineReducers } from 'redux';
import auth from './auth';
import user from './user';
import lessons from './lessons';
import card from './card';
import studentDecks from './student-decks';
import studentDeck from './student-deck';
import decks from './decks';
import cart from './cart';
import { LOGOUT } from '../constants/auth';
import order from './order';
import payment from './payment';
import studentTypes from './student-types';
import review from './review';
import lastReview from './last-review';
import ranking from './ranking';
import topStudentScores from './top-student-scores';
import student from './student';
import chapter from './chapter';
import scores from './scores';

const appReducer = combineReducers({
  auth,
  user,
  student,
  lessons,
  card,
  chapter,
  studentDeck,
  studentDecks,
  decks,
  cart,
  order,
  payment,
  studentTypes,
  review,
  lastReview,
  ranking,
  scores,
  topStudentScores
});

function rootReducer(state, action) {
  if (action.type === LOGOUT) state = undefined;
  return appReducer(state, action);
}

export default rootReducer;
