'use strict';

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

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

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

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

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

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

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; }

const ComboBoxInput = _cspaceInput.components.ComboBoxInput;


const mapStateToProps = (state, ownProps) => {
  const intl = ownProps.intl,
        optionListName = ownProps.source;


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

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

const mapDispatchToProps = {};

const mergeProps = (stateProps, dispatchProps, ownProps) => {
  const intl = ownProps.intl,
        source = ownProps.source,
        remainingOwnProps = _objectWithoutProperties(ownProps, ['intl', 'source']);

  return Object.assign({}, remainingOwnProps, stateProps, dispatchProps);
};

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

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

IntlizedConnectedComboBoxInput.propTypes = Object.assign({}, ComboBoxInput.propTypes, {
  source: _propTypes2.default.string
});

exports.default = IntlizedConnectedComboBoxInput;