'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isPanelCollapsed = exports.getSearchPanelPageSize = exports.getSearchPageSize = exports.getKeywordSearchVocabulary = exports.getKeywordSearchRecordType = undefined;

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _prefs = require('../actions/prefs');

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 _prefs.PREFS_LOADED:
      return action.payload || state;
    case _prefs.COLLAPSE_PANEL:
      return state.setIn(['panels', action.meta.recordType, action.meta.name, 'collapsed'], action.payload);
    case _prefs.SET_KEYWORD_SEARCH_RECORD_TYPE:
      return state.setIn(['keywordSearch', 'recordType'], action.payload).deleteIn(['keywordSearch', 'vocabulary']);
    case _prefs.SET_KEYWORD_SEARCH_VOCABULARY:
      return state.setIn(['keywordSearch', 'vocabulary'], action.payload);
    case _prefs.SET_SEARCH_PAGE_SIZE:
      return state.set('searchPageSize', action.payload);
    case _prefs.SET_SEARCH_PANEL_PAGE_SIZE:
      return state.setIn(['panels', action.meta.recordType, action.meta.name, 'pageSize'], action.payload);
    default:
      return state;
  }
};

var getKeywordSearchRecordType = exports.getKeywordSearchRecordType = function getKeywordSearchRecordType(state) {
  return state.getIn(['keywordSearch', 'recordType']);
};

var getKeywordSearchVocabulary = exports.getKeywordSearchVocabulary = function getKeywordSearchVocabulary(state) {
  return state.getIn(['keywordSearch', 'vocabulary']);
};

var getSearchPageSize = exports.getSearchPageSize = function getSearchPageSize(state) {
  return state.get('searchPageSize');
};

var getSearchPanelPageSize = exports.getSearchPanelPageSize = function getSearchPanelPageSize(state, recordType, name) {
  return state.getIn(['panels', recordType, name, 'pageSize']);
};

var isPanelCollapsed = exports.isPanelCollapsed = function isPanelCollapsed(state, recordType, name) {
  return state.getIn(['panels', recordType, name, 'collapsed']);
};