'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getVocabulary = exports.getRecordType = exports.getKeyword = exports.getAdvanced = undefined;

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _searchToRelate = require('../actions/searchToRelate');

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

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

  switch (action.type) {
    case _searchToRelate.SET_SEARCH_TO_RELATE_ADVANCED:
      return state.set('advanced', _immutable2.default.fromJS(action.payload));
    case _searchToRelate.SET_SEARCH_TO_RELATE_KEYWORD:
      return state.set('keyword', action.payload);
    case _searchToRelate.SET_SEARCH_TO_RELATE_RECORD_TYPE:
      return state.set('recordType', action.payload).delete('advanced');
    case _searchToRelate.SET_SEARCH_TO_RELATE_VOCABULARY:
      return state.setIn(['vocabulary', state.get('recordType')], action.payload);
    default:
      return state;
  }
};

var getAdvanced = exports.getAdvanced = function getAdvanced(state) {
  return state.get('advanced');
};
var getKeyword = exports.getKeyword = function getKeyword(state) {
  return state.get('keyword');
};
var getRecordType = exports.getRecordType = function getRecordType(state) {
  return state.get('recordType');
};
var getVocabulary = exports.getVocabulary = function getVocabulary(state, recordType) {
  return state.getIn(['vocabulary', recordType]);
};