"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.ConnectedStructuredDateInput = void 0;

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

var _structuredDate = require("../../actions/structuredDate");

var _vocabulary = require("../../actions/vocabulary");

var _StructuredDateInput = _interopRequireDefault(require("../../components/record/StructuredDateInput"));

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

var _withConfig = _interopRequireDefault(require("../../enhancers/withConfig"));

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

const mapStateToProps = (state, ownProps) => {
  const {
    config
  } = ownProps;
  const {
    structDateOptionListNames,
    structDateVocabNames
  } = config;
  const optionLists = {};
  const terms = {};
  structDateOptionListNames.forEach(optionListName => {
    optionLists[optionListName] = (0, _reducers.getOptionList)(state, optionListName);
  });
  structDateVocabNames.forEach(vocabName => {
    const vocab = (0, _reducers.getVocabulary)(state, vocabName);
    terms[vocabName] = vocab ? vocab.items : null;
  });
  return {
    optionLists,
    terms,
    perms: (0, _reducers.getUserPerms)(state)
  };
};

const mapDispatchToProps = {
  parseDisplayDate: _structuredDate.parseDisplayDate,
  readTerms: _vocabulary.readVocabularyItems
};
const ConnectedStructuredDateInput = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_StructuredDateInput.default);
exports.ConnectedStructuredDateInput = ConnectedStructuredDateInput;
const ConnectedStructuredDateInputWithConfig = (0, _withConfig.default)(ConnectedStructuredDateInput);
ConnectedStructuredDateInputWithConfig.propTypes = _StructuredDateInput.default.propTypes;
var _default = ConnectedStructuredDateInputWithConfig;
exports.default = _default;