import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _regeneratorRuntime from "@babel/runtime/regenerator";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(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; })(); }
import React from 'react';
import { Outcome } from '../../domain';
import { BaseViewer } from '../base-viewer';
import { ZoomLevel } from '../../domain/zoomLevel';
import { DocViewer as DocViewerComponent } from './doc-viewer';
export var DocViewer = /*#__PURE__*/function (_BaseViewer) {
  function DocViewer() {
    var _this;
    _classCallCheck(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));
    _defineProperty(_this, "isObjectUrl", false);
    return _this;
  }
  _inherits(DocViewer, _BaseViewer);
  return _createClass(DocViewer, [{
    key: "initialState",
    get: function get() {
      return {
        content: Outcome.pending(),
        zoomLevel: new 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 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        var item;
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              item = this.props.item;
              this.setState({
                content: 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.createElement(DocViewerComponent, {
        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);