"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.initialState = void 0;

var _immutable = require("immutable");

var _defaultSetting = _interopRequireDefault(require("../../../../config/defaultSetting"));

var _routes = _interopRequireDefault(require("../../../utils/routes"));

var _constants = require("./constants");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var initialState = (0, _immutable.fromJS)({
  globalConfig: {},
  globalConfigError: '',
  currentRoutes: {},
  instance: null,
  menu: [],
  defaultSetting: _defaultSetting["default"]
});
/* eslint-disable default-case, no-param-reassign */

exports.initialState = initialState;

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

  switch (action.type) {
    case _constants.GET_CONFIG:
      console.log('updateConfig', action.data);
      window.__INITIAL_STATE__ = Object.assign({}, action.data, {
        allWidgets: action.data.widgets || []
      });
      window.globalConfig = require('kit_global_config')["default"];
      createStoreage.set('globalConfig', window.globalConfig);
      var config = createStoreage.get('globalConfig');
      return state.merge({
        globalConfig: config,
        menu: (0, _routes["default"])(config.widgets || [])
      });

    case _constants.GET_ERROR_CONFIG:
      return state.merge({
        globalConfigError: action.data
      });

    case _constants.GET_CURRENT_ROUTES:
      return state.merge({
        currentRoutes: action.data
      });

    case _constants.CREATE_CONEXT:
      return state.merge({
        instance: action.data
      });

    case _constants.GENERATE_MENU:
      return state.merge({
        menu: action.data
      });

    case _constants.GET_THEME_CONFIG:
      return state.merge({
        defaultSetting: action.data
      });

    default:
      return state;
  }
};

var _default = appReducer;
exports["default"] = _default;