'use strict';

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

var _immutable = require('immutable');

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

var toggle = function toggle(state, key) {
  return state.update(key, function (value) {
    return !value;
  });
};

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.CLEAR_UI:
      return state.delete(action.payload);
    case _constants.MERGE_UI:
      return state.mergeDeepIn([action.payload.key], action.payload.value);
    case _constants.SET_UI:
      return state.set(action.payload.key, action.payload.value);
    case _constants.TOGGLE_UI:
      return toggle(state, action.payload);
    case _constants.OCCLUDE_QUIZ_ENTRIES:
      return state.set('quizEntriesOccluded', action.payload);
    case _constants.ACTIVE_BANK_CHANGE:
      return state.set('activeBankId', action.payload);
    case _constants.ACTIVE_BANK_ENTRY_CHANGE:
      return state.set('activeBankEntryId', action.payload);
    default:
      return state;
  }
};