'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 = (state = _immutable2.default.Map(), action) => {
  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;
  }
};

const getAdvanced = exports.getAdvanced = state => state.get('advanced');
const getKeyword = exports.getKeyword = state => state.get('keyword');
const getRecordType = exports.getRecordType = state => state.get('recordType');
const getVocabulary = exports.getVocabulary = (state, recordType) => state.getIn(['vocabulary', recordType]);