"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-common/lib/format-message"));

var _constants = require("@instructure/quiz-common/lib/constants");

var _ImportModal = _interopRequireDefault(require("../../ImportModal"));

var RceImageImportModal =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(RceImageImportModal, _Component);

  function RceImageImportModal() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(RceImageImportModal)).call.apply(_getPrototypeOf2, [this].concat(args)));

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

    return _this;
  }

  (0, _createClass2.default)(RceImageImportModal, [{
    key: "render",
    value: function render() {
      return _react.default.createElement(_ImportModal.default, {
        acceptFileType: [{
          fileType: 'image/*',
          title: "Image"
        }, {
          fileType: '.mp3, .wav, .ogg',
          title: "Audio"
        }, {
          fileType: '.mp4, .webm, .ogg',
          title: "Vid\xE9o"
        }],
        closeOverride: this.props.closeOverride,
        disableConfirm: true,
        failureMessage: "\xC9chec de t\xE9l\xE9versement de votre fichier.",
        fileUpload: this.fileUpload(this.props.onSuccess),
        importMessage: "S\xE9lectionner un fichier \xE0 ins\xE9rer.",
        importModalId: this.props.importModalId,
        onClose: this.props.onClose,
        onContinue: Function.prototype,
        ref: this.storeImportModalRef
      });
    }
  }]);
  RceImageImportModal.displayName = "RceImageImportModal";
  return RceImageImportModal;
}(_react.Component);

exports.default = RceImageImportModal;
RceImageImportModal.propTypes = {
  closeOverride: _propTypes.default.func,
  importModalId: _propTypes.default.string.isRequired,
  interactionFileUpload: _propTypes.default.func.isRequired,
  onClose: _propTypes.default.func,
  onSuccess: _propTypes.default.func.isRequired,
  parentType: _propTypes.default.string.isRequired,
  parentId: _propTypes.default.string.isRequired,
  setUploadStatus: _propTypes.default.func.isRequired,
  uploadPath: _propTypes.default.string
};
RceImageImportModal.defaultProps = {
  closeOverride: null,
  onClose: function onClose() {},
  uploadPath: null
};