'use strict';

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

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

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

  switch (action.type) {
    case _login.RESET_LOGIN:
      return Object.assign({}, state, {
        isPending: false,
        username: undefined,
        response: undefined,
        error: undefined
      });
    case _login.LOGIN_REDIRECTED:
      return Object.assign({}, state, {
        continuation: action.meta.attemptedUrl
      });
    case _login.LOGIN_STARTED:
      return Object.assign({}, state, {
        isPending: true,
        username: action.meta.username,
        response: undefined,
        error: undefined
      });
    case _login.LOGIN_FULFILLED:
      return Object.assign({}, state, {
        isPending: false,
        username: action.meta.username,
        response: action.payload,
        error: undefined
      });
    case _login.LOGIN_REJECTED:
      return Object.assign({}, state, {
        isPending: false,
        username: action.meta.username,
        response: undefined,
        error: action.payload
      });
    default:
      return state;
  }
};

function getContinuation(state) {
  return state.continuation;
}

function isPending(state) {
  return state.isPending;
}

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

function getResponse(state) {
  return state.response;
}

function getError(state) {
  return state.error;
}