import _defineProperty from "@babel/runtime/helpers/defineProperty";
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 class DocViewer extends BaseViewer {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "isObjectUrl", false);
  }
  get initialState() {
    return {
      content: Outcome.pending(),
      zoomLevel: new ZoomLevel(1.75),
      isPasswordProtected: false,
      hasPasswordError: false
    };
  }
  needsReset(propsA, propsB) {
    if (this.state.content.status === 'SUCCESSFUL') {
      return false;
    }
    return propsA.item.status !== propsB.item.status;
  }
  async init() {
    const {
      item
    } = this.props;
    this.setState({
      content: Outcome.successful(item.id)
    });
  }
  release() {
    if (!this.isObjectUrl) {
      return;
    }
    const {
      content
    } = this.state;
    if (content.data) {
      URL.revokeObjectURL(content.data);
    }
  }
  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
    });
  }
}