'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _react = require('react');

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

var _reactIntl = require('react-intl');

var _cspaceInput = require('cspace-input');

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var ComboBoxInput = _cspaceInput.components.ComboBoxInput;


var mapStateToProps = function mapStateToProps(state, ownProps) {
  var intl = ownProps.intl,
      optionListName = ownProps.optionListName;


  var options = (0, _reducers.getOptionList)(state, optionListName);

  return {
    options: options,
    formatOptionLabel: function formatOptionLabel(option) {
      return option.message ? intl.formatMessage(option.message) : option.value;
    }
  };
};

var mapDispatchToProps = {};

var mergeProps = function mergeProps(stateProps, dispatchProps, ownProps) {
  var intl = ownProps.intl,
      optionListName = ownProps.optionListName,
      remainingOwnProps = _objectWithoutProperties(ownProps, ['intl', 'optionListName']);

  return _extends({}, remainingOwnProps, stateProps, dispatchProps);
};

var ConnectedComboBoxInput = exports.ConnectedComboBoxInput = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps, mergeProps)(ComboBoxInput);

var IntlizedConnectedComboBoxInput = (0, _reactIntl.injectIntl)(ConnectedComboBoxInput);

IntlizedConnectedComboBoxInput.propTypes = _extends({}, ComboBoxInput.propTypes, {
  optionListName: _react.PropTypes.string
});

exports.default = IntlizedConnectedComboBoxInput;