'use strict';

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

var _cspace = require('../actions/cspace');

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

var _logout = require('../actions/logout');

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

  switch (action.type) {
    case _cspace.CSPACE_CONFIGURED:
      return Object.assign({}, state, {
        username: action.payload.username
      });
    case _login.LOGIN_FULFILLED:
      return Object.assign({}, state, {
        username: action.meta.username
      });
    case _logout.LOGOUT_FULFILLED:
      return Object.assign({}, state, {
        username: null
      });
    default:
      return state;
  }
};

function getUsername(state) {
  return state.username;
}