text: 'use strict';
  
  exports.__esModule = true;
  exports.SET_RESULTS = exports.NEXT_QUESTION = exports.ANSWER_COLLECTION = undefined;
  exports.nextQuestion = nextQuestion;
  exports.postAnswerGetQuestion = postAnswerGetQuestion;
  
  var _axiosConfigInitial = require('./axiosConfigInitial');
  
  var _axiosConfigInitial2 = _interopRequireDefault(_axiosConfigInitial);
  
  var _fetch = require('./fetch');
  
  var _error = require('./error');
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  var ANSWER_COLLECTION = exports.ANSWER_COLLECTION = 'ANSWER_COLLECTION';
  var NEXT_QUESTION = exports.NEXT_QUESTION = 'NEXT_QUESTION';
  var SET_RESULTS = exports.SET_RESULTS = 'SET_RESULTS';
  
  function nextQuestion(nextQuestion) {
    return {
      type: NEXT_QUESTION,
      nextQuestion: nextQuestion
    };
  }
  function setResults(results) {
    return {
      type: SET_RESULTS,
      results: results
    };
  }
  function saveAnswers(answer) {
    return {
      type: ANSWER_COLLECTION,
      answer: answer
    };
  }
  function postAnswerGetQuestion(response, answer) {
    return function (dispatch, getState) {
      var state = getState().pushkin;
      dispatch((0, _fetch.requestQuestionBegin)());
      if (Array.isArray(response.choiceId) && response.choiceId.length > 0) {
        return Promise.all(response.choiceId.map(function (currentId) {
          return _axiosConfigInitial2.default.post('response', {
            choiceId: currentId,
            questionId: response.questionId,
            user: {
              id: response.user.id
            }
          }).then(function (resp) {
            return resp.data;
          });
        })).then(function (data) {
          if (!data[0]) {
            return _axiosConfigInitial2.default.get('/results/' + state.userInfo.id).then(function (resp) {
              return resp.data.results;
            }).then(function (results) {
              dispatch(setResults(results));
              dispatch(nextQuestion(null));
            });
          } else {
            // if (state.options.saveAnswers) {
            //   dispatch(saveAnswers(answer))
            // }
            dispatch(nextQuestion(data[0]));
          }
        }).catch(function (err) {
          return dispatch((0, _error.error)(err));
        });
      }
      return _axiosConfigInitial2.default.post('response', response).then(function (resp) {
        if (resp.error) {
          return dispatch((0, _error.error)(resp.error));
        }
        if (!resp.data) {
          return _axiosConfigInitial2.default.get('/results/' + state.userInfo.id).then(function (resp) {
            return resp.data.results;
          }).then(function (results) {
            dispatch(setResults(results));
            dispatch(nextQuestion(null));
          });
        } else {
          // if (state.options.saveAnswers) {
          //   dispatch(saveAnswers(answer))
          // }
          dispatch(nextQuestion(resp.data));
        }
      });
      // .catch(err => {
      //   return dispatch(error(err));
      // });
    };
  }