'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getAdminTab = exports.getUploadType = exports.getForm = exports.getRecordBrowserNavBarItems = exports.isPanelCollapsed = exports.getSearchToRelatePageSize = exports.getSearchResultPagePageSize = exports.getSearchPanelPageSize = exports.getQuickSearchVocabulary = exports.getQuickSearchRecordType = exports.getSearchPageVocabulary = exports.getSearchPageRecordType = 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 || _immutable2.default.Map();
    case _prefs.COLLAPSE_PANEL:
      return state.setIn(['panels', action.meta.recordType, action.meta.name, 'collapsed'], action.payload);
    case _prefs.SET_ADMIN_TAB:
      return state.set('adminTab', action.payload);
    case _prefs.SET_RECORD_BROWSER_NAV_BAR_ITEMS:
      return state.setIn(['recordBrowserNavBarItems', action.meta.recordType], action.payload);
    case _prefs.SET_SEARCH_PAGE_RECORD_TYPE:
      return state.setIn(['searchPage', 'recordType'], action.payload);
    case _prefs.SET_SEARCH_PAGE_VOCABULARY:
      return state.setIn(['searchPage', 'vocabulary', state.getIn(['searchPage', 'recordType'])], action.payload);
    case _prefs.SET_QUICK_SEARCH_RECORD_TYPE:
      return state.setIn(['quickSearch', 'recordType'], action.payload);
    case _prefs.SET_QUICK_SEARCH_VOCABULARY:
      return state.setIn(['quickSearch', 'vocabulary', state.getIn(['quickSearch', 'recordType'])], action.payload);
    case _prefs.SET_SEARCH_PANEL_PAGE_SIZE:
      return state.setIn(['panels', action.meta.recordType, action.meta.name, 'pageSize'], action.payload);
    case _prefs.SET_SEARCH_RESULT_PAGE_PAGE_SIZE:
      return state.set('searchResultPagePageSize', action.payload);
    case _prefs.SET_SEARCH_TO_RELATE_PAGE_SIZE:
      return state.set('searchToRelatePageSize', action.payload);
    case _prefs.SET_FORM:
      return state.setIn(['form', action.meta.recordType], action.payload);
    case _prefs.SET_UPLOAD_TYPE:
      return state.set('uploadType', action.payload);
    default:
      return state;
  }
};

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

var getSearchPageVocabulary = exports.getSearchPageVocabulary = function getSearchPageVocabulary(state, recordType) {
  return state.getIn(['searchPage', 'vocabulary', recordType]);
};

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

var getQuickSearchVocabulary = exports.getQuickSearchVocabulary = function getQuickSearchVocabulary(state, recordType) {
  return state.getIn(['quickSearch', 'vocabulary', recordType]);
};

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

var getSearchResultPagePageSize = exports.getSearchResultPagePageSize = function getSearchResultPagePageSize(state) {
  return state.get('searchResultPagePageSize');
};

var getSearchToRelatePageSize = exports.getSearchToRelatePageSize = function getSearchToRelatePageSize(state) {
  return state.get('searchToRelatePageSize');
};

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

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

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

var getUploadType = exports.getUploadType = function getUploadType(state) {
  return state.get('uploadType');
};

var getAdminTab = exports.getAdminTab = function getAdminTab(state) {
  return state.get('adminTab');
};