'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ConnectedSearchPage = undefined;

var _reactRedux = require('react-redux');

var _SearchPage = require('../../components/pages/SearchPage');

var _SearchPage2 = _interopRequireDefault(_SearchPage);

var _withConfig = require('../../enhancers/withConfig');

var _withConfig2 = _interopRequireDefault(_withConfig);

var _searchPage = require('../../actions/searchPage');

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

var _reducers = require('../../reducers');

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

const mapStateToProps = state => {
  const recordType = (0, _reducers.getSearchPageRecordType)(state);

  return {
    keywordValue: (0, _reducers.getSearchPageKeyword)(state),
    recordTypeValue: recordType,
    vocabularyValue: (0, _reducers.getSearchPageVocabulary)(state, recordType),
    advancedSearchCondition: (0, _reducers.getSearchPageAdvanced)(state),
    perms: (0, _reducers.getUserPerms)(state),
    preferredAdvancedSearchBooleanOp: (0, _reducers.getAdvancedSearchBooleanOp)(state)
  };
};

const mapDispatchToProps = (dispatch, ownProps) => ({
  onAdvancedSearchConditionCommit: value => {
    dispatch((0, _searchPage.setSearchPageAdvanced)(value));
  },
  onKeywordCommit: value => {
    dispatch((0, _searchPage.setSearchPageKeyword)(value));
  },
  onRecordTypeCommit: value => {
    dispatch((0, _prefs.setSearchPageRecordType)(value));
  },
  onVocabularyCommit: value => {
    dispatch((0, _prefs.setSearchPageVocabulary)(value));
  },
  onSearch: () => {
    dispatch((0, _searchPage.initiateSearch)(ownProps.config, ownProps.history.push));
  }
});

const ConnectedSearchPage = exports.ConnectedSearchPage = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_SearchPage2.default);

exports.default = (0, _withConfig2.default)(ConnectedSearchPage);