'use strict';

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

var _immutable = require('immutable');

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

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

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

  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);
      }
    default:
      return state;
  }
};