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

const getSearchPageRecordType = exports.getSearchPageRecordType = state => state.getIn(['searchPage', 'recordType']);

const getSearchPageVocabulary = exports.getSearchPageVocabulary = (state, recordType) => state.getIn(['searchPage', 'vocabulary', recordType]);

const getQuickSearchRecordType = exports.getQuickSearchRecordType = state => state.getIn(['quickSearch', 'recordType']);

const getQuickSearchVocabulary = exports.getQuickSearchVocabulary = (state, recordType) => state.getIn(['quickSearch', 'vocabulary', recordType]);

const getSearchPanelPageSize = exports.getSearchPanelPageSize = (state, recordType, name) => state.getIn(['panels', recordType, name, 'pageSize']);

const getSearchResultPagePageSize = exports.getSearchResultPagePageSize = state => state.get('searchResultPagePageSize');

const getSearchToRelatePageSize = exports.getSearchToRelatePageSize = state => state.get('searchToRelatePageSize');

const isPanelCollapsed = exports.isPanelCollapsed = (state, recordType, name) => state.getIn(['panels', recordType, name, 'collapsed']);

const getRecordBrowserNavBarItems = exports.getRecordBrowserNavBarItems = (state, recordType) => state.getIn(['recordBrowserNavBarItems', recordType]);

const getForm = exports.getForm = (state, recordType) => state.getIn(['form', recordType]);

const getUploadType = exports.getUploadType = state => state.get('uploadType');

const getAdminTab = exports.getAdminTab = state => state.get('adminTab');