import { SubmitActions } from '../actions';
 /// make this playLessonsReducer.
const initialState = {
  answeredQuestions: [],
  unansweredQuestions: []
}

function question(state = initialState, action) {
  switch (action.type) {
    case SubmitActions.NEXT_QUESTION:
      var changes = {};
      if (state.currentQuestion) {
        changes.answeredQuestions = state.answeredQuestions.concat([state.currentQuestion])
      }
      changes.currentQuestion = state.unansweredQuestions[0];
      if (changes.currentQuestion) {
        changes.currentQuestion.attempts = [];
      }
      if (state.unansweredQuestions.length > 0) {
        changes.unansweredQuestions = state.unansweredQuestions.slice(1);
      }
      return Object.assign({}, state, changes)
    case SubmitActions.LOAD_DATA:
      var changes2 = {
        unansweredQuestions: action.data,
        questionSet: action.data};
      return Object.assign({}, state, changes2)
    case SubmitActions.EXIT:
     return Object.assign({}, state, {
        completedQuestions: undefined,
        answeredQuestions: [],
        unansweredQuestions: []
      })
    case SubmitActions.SUBMIT_RESPONSE:
      var changes = {currentQuestion:
        Object.assign({}, state.currentQuestion, {
        attempts: state.currentQuestion.attempts.concat([action.response])
      })}
      return Object.assign({}, state, changes)
    case SubmitActions.START_QUESTION:
    var changes = {currentQuestion:
      Object.assign({}, state.currentQuestion, {
        started: true
      })}
      return Object.assign({}, state, changes)
    case SubmitActions.UPDATE_NAME:
      var changes = {name: action.data}
      return Object.assign({}, state, changes)
    default:
      return state
  }
}

export default question

@@ -936,16 +936,77 @@
 anges2)%0A
+    case SubmitActions.CLEAR_DATA:%0A      return initialState%0A
     case

handle the clear data action.