'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getError = exports.getUsername = exports.isSuccess = exports.isPending = undefined;

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _login = require('../actions/login');

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

exports.default = (state = _immutable2.default.Map(), action) => {
  switch (action.type) {
    case _login.RESET_LOGIN:
      return state.clear().set('username', action.meta.username);
    case _login.LOGIN_STARTED:
      return state.set('isPending', true).delete('isSuccess').set('username', action.meta.username).delete('error');
    case _login.LOGIN_FULFILLED:
      return state.delete('isPending').set('isSuccess', true).delete('username').delete('error');
    case _login.LOGIN_REJECTED:
      return state.delete('isPending').delete('isSuccess').set('username', action.meta.username).set('error', _immutable2.default.fromJS(action.payload));
    default:
      return state;
  }
};

const isPending = exports.isPending = state => state.get('isPending');
const isSuccess = exports.isSuccess = state => state.get('isSuccess');
const getUsername = exports.getUsername = state => state.get('username');
const getError = exports.getError = state => state.get('error');