'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _class, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _formatMessage = require('../../../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _constants = require('../../../../constants');

var _ImportModal = require('../../ImportModal');

var _ImportModal2 = _interopRequireDefault(_ImportModal);

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

var RceImageImportModal = (_temp2 = _class = function (_Component) {
  (0, _inherits3.default)(RceImageImportModal, _Component);

  function RceImageImportModal() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, RceImageImportModal);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = RceImageImportModal.__proto__ || Object.getPrototypeOf(RceImageImportModal)).call.apply(_ref, [this].concat(args))), _this), _this.successWrapper = function (successAction, fileType, altText) {
      return function (url) {
        _this.props.setUploadStatus(_constants.FILE_UPLOAD_SUCCESS);
        successAction(url, fileType, altText);
      };
    }, _this.fileUpload = function (successAction) {
      return function (file, errorAction, altText) {
        _this.props.interactionFileUpload(_this.props.parentType, _this.props.parentId, file, _this.successWrapper(successAction, file.type, altText), errorAction, _this.props.uploadPath);
      };
    }, _this.storeImportModalRef = function (node) {
      _this.importModal = node;
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  // Pass in a function that allows for successActions to be defined in the RCE
  // (trying to awkwardly fit the importmodal api)


  (0, _createClass3.default)(RceImageImportModal, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(_ImportModal2.default, {
        acceptFileType: [{ fileType: 'image/*', title: 'Image' }, { fileType: '.mp3, .wav, .ogg', title: 'Audio' }, { fileType: '.mp4, .webm, .ogg', title: 'Video' }],
        closeOverride: this.props.closeOverride,
        disableConfirm: true,
        failureMessage: 'Failed to upload your file.',
        fileUpload: this.fileUpload(this.props.onSuccess),
        importMessage: 'Select a file to embed.',
        importModalId: this.props.importModalId,
        onClose: this.props.onClose,
        onContinue: Function.prototype,
        ref: this.storeImportModalRef
      });
    }
  }]);
  RceImageImportModal.displayName = 'RceImageImportModal'
  ;
  return RceImageImportModal;
}(_react.Component), _class.propTypes = {
  closeOverride: _propTypes2.default.func,
  importModalId: _propTypes2.default.string.isRequired,
  interactionFileUpload: _propTypes2.default.func.isRequired,
  onClose: _propTypes2.default.func,
  onSuccess: _propTypes2.default.func.isRequired,
  parentType: _propTypes2.default.string.isRequired,
  parentId: _propTypes2.default.string.isRequired,
  setUploadStatus: _propTypes2.default.func.isRequired,
  uploadPath: _propTypes2.default.string
}, _class.defaultProps = {
  closeOverride: null,
  onClose: function onClose() {},

  uploadPath: null
}, _temp2);
exports.default = RceImageImportModal;