'use strict';

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

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

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

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

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

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

var _StructuredDateInput2 = _interopRequireDefault(_StructuredDateInput);

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

const mapStateToProps = state => {
  const optionLists = {};
  const terms = {};

  _StructuredDateInput.optionListNames.forEach(optionListName => {
    optionLists[optionListName] = (0, _reducers.getOptionList)(state, optionListName);
  });

  _StructuredDateInput.vocabNames.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 = exports.ConnectedStructuredDateInput = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_StructuredDateInput2.default);

ConnectedStructuredDateInput.propTypes = _StructuredDateInput2.default.propTypes;

exports.default = ConnectedStructuredDateInput;