"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 addBankEntries = function addBankEntries(state, bankEntries) {
  return state.merge((0, _immutable.fromJS)((0, _keyBy.default)(bankEntries, 'id')));
};

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

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

  switch (action.type) {
    case _constants.ADD_BANK_ENTRIES:
      return addBankEntries(state, action.payload);

    case _constants.ARCHIVE_BANK_ENTRY:
      return state.setIn([action.payload, 'archived'], true);

    default:
      return state;
  }
};

exports.default = _default;