'use strict';

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

var _keyBy = require('lodash/keyBy');

var _keyBy2 = _interopRequireDefault(_keyBy);

var _immutable = require('immutable');

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

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

var addImports = function addImports(state, items) {
  var importsHash = (0, _keyBy2.default)(items, 'id');
  return state.merge((0, _immutable.fromJS)(importsHash));
};

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_QTI_IMPORTS:
      return addImports(state, action.payload);
    case _constants.CLEAR_QTI_IMPORTS:
      return defaultState;
    default:
      return state;
  }
};