'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = update;

var _dictActions = require('../constant/dictActions');

var types = _interopRequireWildcard(_dictActions);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

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

function update() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
  var action = arguments[1];

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