
import * as types from '../constant/dictActions';

const initialState = {
  showLoading: false,
  isInit: false,
  token: '123123',
  query: {},
  enterMenuId: window.___EnterMenuId || [],
  quickMenu: [],
  userName: ''
};

export default function update(state = initialState, action) {
  switch (action.type) {
    case types.INIT_APP:
      return {
        ...state,
        ...action.payload
      };
    case types.FETCH_START:
      return { ...state, showLoading: true };
    case types.FETCH_END:
      return { ...state, showLoading: false };
    case types.UPDATE_QUERY:
      return { ...state, query: action.payload };
    case types.INIT_DATA_FROM_SERVER:
      return { ...state, quickMenu: action.payload.quickMenu || state.quickMenu, isInit: true, userName: (localStorage && localStorage.userName) || '' };
    case types.AUTH_LOGIN:
      return {
        ...state,
        token: action.payload
      };
    case types.AUTH_LOGOUT:
      return {
        ...state,
        token: ''
      };
    case types.AUTH_FORCE_LOGOUT:
      return {
        ...state,
        token: ''
      };
    case types.UPDATE_ENTER_MENU_ID:
      return {
        ...state,
        enterMenuId: action.payload
      };
    case types.UPDATE_QUICK_MENU:
      return {
        ...state,
        quickMenu: [...action.payload]
      };
    default:
      return state;
  }
}
