"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isSuccess = exports.isPending = exports.getUsername = exports.getError = exports.default = void 0;
var _immutable = _interopRequireDefault(require("immutable"));
var _actionCodes = require("../constants/actionCodes");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = function _default() {
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _immutable.default.Map();
  let action = arguments.length > 1 ? arguments[1] : undefined;
  switch (action.type) {
    case _actionCodes.RESET_LOGIN:
      return state.clear().set('username', action.meta.username);
    case _actionCodes.LOGIN_STARTED:
      return state.set('isPending', true).delete('isSuccess').set('username', action.meta.username).delete('error');
    case _actionCodes.LOGIN_FULFILLED:
      return state.delete('isPending').set('isSuccess', true).delete('username').delete('error');
    case _actionCodes.LOGIN_REJECTED:
      return state.delete('isPending').delete('isSuccess').set('username', action.meta.username).set('error', _immutable.default.Map({
        code: action.payload.code,
        error: action.payload.error
      }));
    default:
      return state;
  }
};
exports.default = _default;
const isPending = state => state.get('isPending');
exports.isPending = isPending;
const isSuccess = state => state.get('isSuccess');
exports.isSuccess = isSuccess;
const getUsername = state => state.get('username');
exports.getUsername = getUsername;
const getError = state => state.get('error');
exports.getError = getError;