'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 _StructuredDateInput = require('../../components/record/StructuredDateInput');

var _StructuredDateInput2 = _interopRequireDefault(_StructuredDateInput);

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

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

var _withConfig2 = _interopRequireDefault(_withConfig);

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

const mapStateToProps = (state, ownProps) => {
  const config = ownProps.config;
  const structDateOptionListNames = config.structDateOptionListNames,
        structDateVocabNames = config.structDateVocabNames;


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

const ConnectedStructuredDateInputWithConfig = (0, _withConfig2.default)(ConnectedStructuredDateInput);

ConnectedStructuredDateInputWithConfig.propTypes = _StructuredDateInput2.default.propTypes;

exports.default = ConnectedStructuredDateInputWithConfig;