'use strict';

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

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

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

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

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

var _prefs = require('../../actions/prefs');

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 UploadInput = _cspaceInput.components.UploadInput;


var messages = (0, _reactIntl.defineMessages)({
  typeInputLabel: {
    'id': 'UploadInputContainer.typeInputLabel',
    'defaultMessage': 'Upload'
  },
  fileOptionLabel: {
    'id': 'UploadInputContainer.fileOptionLabel',
    'defaultMessage': 'local file'
  },
  urlOptionLabel: {
    'id': 'UploadInputContainer.urlOptionLabel',
    'defaultMessage': 'external media'
  },
  fileInputLabel: {
    'id': 'UploadInputContainer.fileInputLabel',
    'defaultMessage': 'File'
  },
  fileChooseButtonLabel: {
    'id': 'UploadInputContainer.fileChooseButtonLabel',
    'defaultMessage': 'Select\u2026'
  },
  urlInputLabel: {
    'id': 'UploadInputContainer.urlInputLabel',
    'defaultMessage': 'URL'
  },
  fileInfo: {
    'id': 'UploadInputContainer.fileInfo',
    'defaultMessage': '{name} ({type}, {size, number} bytes)'
  }
});

var mapStateToProps = function mapStateToProps(state) {
  return {
    type: (0, _reducers.getUploadType)(state)
  };
};

var mapDispatchToProps = {
  onTypeChanged: _prefs.setUploadType
};

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

  var intlProps = {
    typeInputLabel: intl.formatMessage(messages.typeInputLabel),
    fileOptionLabel: intl.formatMessage(messages.fileOptionLabel),
    urlOptionLabel: intl.formatMessage(messages.urlOptionLabel),
    fileInputLabel: intl.formatMessage(messages.fileInputLabel),
    fileChooseButtonLabel: intl.formatMessage(messages.fileChooseButtonLabel),
    urlInputLabel: intl.formatMessage(messages.urlInputLabel),
    formatFileInfo: function formatFileInfo(name, type, size) {
      return intl.formatMessage(messages.fileInfo, { name: name, type: type, size: size });
    }
  };

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

var ConnectedUploadInput = exports.ConnectedUploadInput = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps, mergeProps)(UploadInput);

var IntlizedUploadInput = (0, _reactIntl.injectIntl)(ConnectedUploadInput);

IntlizedUploadInput.propTypes = UploadInput.propTypes;

exports.default = IntlizedUploadInput;