"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DocViewer = 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 _domain = require("../../domain");
var _baseViewer = require("../base-viewer");
var _zoomLevel = require("../../domain/zoomLevel");
var _docViewer = require("./doc-viewer");
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 DocViewer = exports.DocViewer = /*#__PURE__*/function (_BaseViewer) {
  function DocViewer() {
    var _this;
    (0, _classCallCheck2.default)(this, DocViewer);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, DocViewer, [].concat(args));
    (0, _defineProperty2.default)(_this, "isObjectUrl", false);
    return _this;
  }
  (0, _inherits2.default)(DocViewer, _BaseViewer);
  return (0, _createClass2.default)(DocViewer, [{
    key: "initialState",
    get: function get() {
      return {
        content: _domain.Outcome.pending(),
        zoomLevel: new _zoomLevel.ZoomLevel(1.75),
        isPasswordProtected: false,
        hasPasswordError: false
      };
    }
  }, {
    key: "needsReset",
    value: function needsReset(propsA, propsB) {
      if (this.state.content.status === 'SUCCESSFUL') {
        return false;
      }
      return propsA.item.status !== propsB.item.status;
    }
  }, {
    key: "init",
    value: function () {
      var _init = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
        var item;
        return _regenerator.default.wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              item = this.props.item;
              this.setState({
                content: _domain.Outcome.successful(item.id)
              });
            case 2:
            case "end":
              return _context.stop();
          }
        }, _callee, this);
      }));
      function init() {
        return _init.apply(this, arguments);
      }
      return init;
    }()
  }, {
    key: "release",
    value: function release() {
      if (!this.isObjectUrl) {
        return;
      }
      var content = this.state.content;
      if (content.data) {
        URL.revokeObjectURL(content.data);
      }
    }
  }, {
    key: "renderSuccessful",
    value: function renderSuccessful() {
      return /*#__PURE__*/_react.default.createElement(_docViewer.DocViewer, {
        mediaClient: this.props.mediaClient,
        fileState: this.props.item,
        collectionName: this.props.collectionName,
        onError: this.props.onError,
        onSuccess: this.props.onSuccess,
        traceContext: this.props.traceContext
      });
    }
  }]);
}(_baseViewer.BaseViewer);