'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.logout = exports.LOGOUT_FULFILLED = exports.LOGOUT_STARTED = undefined;

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

var _cspace2 = _interopRequireDefault(_cspace);

var _prefs = require('./prefs');

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

const LOGOUT_STARTED = exports.LOGOUT_STARTED = 'LOGOUT_STARTED';
const LOGOUT_FULFILLED = exports.LOGOUT_FULFILLED = 'LOGOUT_FULFILLED';

const logout = exports.logout = () => dispatch => {
  dispatch({
    type: LOGOUT_STARTED
  });

  dispatch((0, _prefs.savePrefs)());

  return (0, _cspace2.default)().logout().then(response => dispatch({
    type: LOGOUT_FULFILLED,
    payload: response
  })).then(() => dispatch((0, _prefs.loadPrefs)()));
};