import * as types from '../actions/types';

const initialState = {
  loading: false
};

const reducer = (state = initialState, action: any) => {
  switch (action.type) {
    case types.LOGIN_REQUEST:
    case types.LOGOUT_REQUEST:
    case types.REGISTER_REQUEST:
    case types.NAVIGATE_TO_HOME:
    case types.UPDATE_PROFILE_DETAILS_REQUEST:
    case types.FORGOT_PASSWORD_REQUEST:
    case types.RESET_PASSWORD_REQUEST:
    case types.CHANGE_PASSWORD_REQUEST:
      return { ...state, ...action.payload, loading: true };
    case types.GET_PROFILE_DETAILS_REQUEST:
    case types.GET_PROFILE_DETAILS_SUCCESS:
    case types.GET_PROFILE_DETAILS_FAIL:
    case types.FORGOT_PASSWORD_SUCCESS:
    case types.FORGOT_PASSWORD_FAIL:
    case types.RESET_PASSWORD_SUCCESS:
    case types.RESET_PASSWORD_FAIL:
    case types.CHANGE_PASSWORD_SUCCESS:
    case types.CHANGE_PASSWORD_FAIL:
      return { ...state, ...action.payload, loading: false };
    case types.REGISTER_SUCCESS:
      return { ...state, ...action.payload };
    case types.LOGIN_SUCCESS:
    case types.LOGIN_FAIL:
    case types.REGISTER_FAIL:
    case types.INIT_REQUEST:
    case types.LOGOUT_SUCCESS:
    case types.LOGOUT_FAIL:
    case types.GET_PROFILE_DETAILS_SUCCESS:
    case types.GET_PROFILE_DETAILS_FAIL:
    case types.UPDATE_PROFILE_DETAILS_SUCCESS:
    case types.UPDATE_PROFILE_DETAILS_FAIL:
      return { ...state, ...action.payload, loading: false };
    default:
      return state;
  }
};

export default reducer;
