"use strict";

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

var _immutable = require("immutable");

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

var defaultState = (0, _immutable.fromJS)({
  interactionTypes: (0, _immutable.Set)()
}).set('tags', []);

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.SEARCH_RESET:
      return defaultState;

    case _constants.SEARCH_UPDATE:
      return state.set('text', action.payload.text);

    case _constants.SEARCH_TOGGLE:
      {
        var _action$payload = action.payload,
            filter = _action$payload.filter,
            key = _action$payload.key;
        var prior = state.get(filter, (0, _immutable.Set)());
        var toggled = prior.has(key) ? prior.remove(key) : prior.add(key);
        return state.set(filter, toggled);
      }

    case _constants.SEARCH_SET:
      {
        var _action$payload2 = action.payload,
            _filter = _action$payload2.filter,
            value = _action$payload2.value;
        return state.set(_filter, value);
      }

    default:
      return state;
  }
};

exports.default = _default;