"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
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 _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireDefault(require("react"));
var _modalSpinner = _interopRequireDefault(require("../modalSpinner"));
var _errorMessage = _interopRequireDefault(require("../../errorMessage"));
var _errors = require("../../errors");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var ArchiveViewerLoader = exports.default = /*#__PURE__*/function (_React$PureComponent) {
  function ArchiveViewerLoader() {
    var _this;
    (0, _classCallCheck2.default)(this, ArchiveViewerLoader);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, ArchiveViewerLoader, [].concat(args));
    (0, _defineProperty2.default)(_this, "state", {
      ArchiveViewer: ArchiveViewerLoader.ArchiveViewer,
      isErrored: false
    });
    return _this;
  }
  (0, _inherits2.default)(ArchiveViewerLoader, _React$PureComponent);
  return (0, _createClass2.default)(ArchiveViewerLoader, [{
    key: "componentDidMount",
    value: function () {
      var _componentDidMount = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
        var archive;
        return _regenerator.default.wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              if (this.state.ArchiveViewer) {
                _context.next = 12;
                break;
              }
              _context.prev = 1;
              _context.next = 4;
              return Promise.resolve().then(function () {
                return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_media-archive-viewer" */'./archive'));
              });
            case 4:
              archive = _context.sent;
              ArchiveViewerLoader.ArchiveViewer = archive.ArchiveViewer;
              this.setState({
                ArchiveViewer: ArchiveViewerLoader.ArchiveViewer
              });
              _context.next = 12;
              break;
            case 9:
              _context.prev = 9;
              _context.t0 = _context["catch"](1);
              this.setState({
                isErrored: true
              });
            case 12:
            case "end":
              return _context.stop();
          }
        }, _callee, this, [[1, 9]]);
      }));
      function componentDidMount() {
        return _componentDidMount.apply(this, arguments);
      }
      return componentDidMount;
    }()
  }, {
    key: "render",
    value: function render() {
      var _this$state = this.state,
        ArchiveViewer = _this$state.ArchiveViewer,
        isErrored = _this$state.isErrored;
      var item = this.props.item;
      if (isErrored) {
        return /*#__PURE__*/_react.default.createElement(_errorMessage.default, {
          fileId: item.id,
          fileState: item,
          error: new _errors.MediaViewerError('archiveviewer-bundle-loader')
        });
      }
      if (ArchiveViewer) {
        return /*#__PURE__*/_react.default.createElement(ArchiveViewer, this.props);
      } else {
        return /*#__PURE__*/_react.default.createElement(_modalSpinner.default, null);
      }
    }
  }]);
}(_react.default.PureComponent);