"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _immutable = require("immutable");

var _keyBy = _interopRequireDefault(require("lodash/keyBy"));

var _constants = require("@instructure/quiz-common/lib/constants");

var addQuizSessionResults = function addQuizSessionResults(state, action) {
  var quizSessionResultsHash = (0, _keyBy.default)(action.payload, 'id');
  return state.mergeDeep(quizSessionResultsHash);
};

var _default = function _default() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _immutable.fromJS)({});
  var action = arguments.length > 1 ? arguments[1] : undefined;

  switch (action.type) {
    case _constants.ADD_QUIZ_SESSION_RESULTS:
      return addQuizSessionResults(state, action);

    default:
      return state;
  }
};

exports.default = _default;