"use strict";

exports.__esModule = true;
exports.default = exports.LOGOUT = exports.ERROR = void 0;
var _immutable = _interopRequireDefault(require("immutable"));
var _utils = require("../utils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var initialState = _immutable.default.fromJS({
  actives: _immutable.default.Map(),
  logout: false,
  error: null
});
var ERROR = exports.ERROR = "error";
var LOGOUT = exports.LOGOUT = "logout";
var requestReducer = function requestReducer(state, action) {
  if (state === void 0) {
    state = initialState;
  }
  if (action.type.endsWith("_REQUEST")) {
    if ((0, _utils.safeGet)(action, "meta", "addToActiveRequests") === false) {
      // this flag should only be used by requests triggered by a background process to avoid the spinner
      return state;
    }
    var requestName = action.type.replace(/_REQUEST$/, "");
    return state.setIn(["actives", requestName], true);
  }
  if (action.type.endsWith("_SUCCESS")) {
    var _requestName = action.type.replace(/_SUCCESS$/, "");
    return state.deleteIn(["actives", _requestName]).set("logout", false);
  }
  if (action.type.endsWith("_FAILURE")) {
    var _requestName2 = action.type.replace(/_FAILURE$/, "");
    var status = (0, _utils.safeGet)(action, "payload", "status");
    if (status === 403 || status === 401) {
      return state.deleteIn(["actives", _requestName2]).set("logout", true);
    } else {
      return state.deleteIn(["actives", _requestName2]).set("error", _immutable.default.fromJS(action));
    }
  }
  return state;
};
var _default = requestReducer;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(initialState, "initialState", "/home/vsts/work/1/s/src/reducers/request.js");
  reactHotLoader.register(ERROR, "ERROR", "/home/vsts/work/1/s/src/reducers/request.js");
  reactHotLoader.register(LOGOUT, "LOGOUT", "/home/vsts/work/1/s/src/reducers/request.js");
  reactHotLoader.register(requestReducer, "requestReducer", "/home/vsts/work/1/s/src/reducers/request.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/reducers/request.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(initialState, "initialState", "/home/vsts/work/1/s/src/reducers/request.js");
  reactHotLoader.register(ERROR, "ERROR", "/home/vsts/work/1/s/src/reducers/request.js");
  reactHotLoader.register(LOGOUT, "LOGOUT", "/home/vsts/work/1/s/src/reducers/request.js");
  reactHotLoader.register(requestReducer, "requestReducer", "/home/vsts/work/1/s/src/reducers/request.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/reducers/request.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();