'use strict';

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

var _immutable = require('immutable');

var _constants = require('../../constants');

function addQuizSessionEvents(state, quizSessionEvents) {
  // in practice all events will share the same quizSessionId for now
  var quizSessionId = quizSessionEvents[0].quizSessionId;

  // add a new list or concat with a preexisting list

  return state.updateIn([quizSessionId], (0, _immutable.List)(), function (events) {
    return events.concat((0, _immutable.fromJS)(quizSessionEvents));
  });
}

var defaultState = (0, _immutable.fromJS)({});

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

  switch (action.type) {
    case _constants.ADD_QUIZ_SESSION_EVENTS:
      return addQuizSessionEvents(state, action.payload);
    default:
      return state;
  }
};