"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _openseadragon = _interopRequireDefault(require("openseadragon"));
var _blank = _interopRequireDefault(require("../../../images/blank.svg"));
var _imageFullscreen = _interopRequireDefault(require("../../../images/imageFullscreen.svg"));
var _imageFullscreenActive = _interopRequireDefault(require("../../../images/imageFullscreenActive.svg"));
var _imageHome = _interopRequireDefault(require("../../../images/imageHome.svg"));
var _imageHomeActive = _interopRequireDefault(require("../../../images/imageHomeActive.svg"));
var _imageRotateLeft = _interopRequireDefault(require("../../../images/imageRotateLeft.svg"));
var _imageRotateLeftActive = _interopRequireDefault(require("../../../images/imageRotateLeftActive.svg"));
var _imageRotateRight = _interopRequireDefault(require("../../../images/imageRotateRight.svg"));
var _imageRotateRightActive = _interopRequireDefault(require("../../../images/imageRotateRightActive.svg"));
var _imageZoomIn = _interopRequireDefault(require("../../../images/imageZoomIn.svg"));
var _imageZoomInActive = _interopRequireDefault(require("../../../images/imageZoomInActive.svg"));
var _imageZoomOut = _interopRequireDefault(require("../../../images/imageZoomOut.svg"));
var _imageZoomOutActive = _interopRequireDefault(require("../../../images/imageZoomOutActive.svg"));
var _ImageViewer = _interopRequireDefault(require("../../../styles/cspace-ui/ImageViewer.css"));
var _ImageViewerSaveLink = _interopRequireDefault(require("../../../styles/cspace-ui/ImageViewerSaveLink.css"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/* global document */

const propTypes = {
  blobUrl: _propTypes.default.string.isRequired,
  filename: _propTypes.default.string
};
const defaultProps = {
  filename: ''
};
class ImageViewer extends _react.Component {
  constructor() {
    super();
    this.handleContainerRef = this.handleContainerRef.bind(this);
  }
  componentDidMount() {
    const {
      blobUrl,
      filename
    } = this.props;
    const viewer = (0, _openseadragon.default)({
      element: this.containerElement,
      navImages: {
        zoomIn: {
          REST: _imageZoomIn.default,
          GROUP: _blank.default,
          HOVER: _imageZoomInActive.default,
          DOWN: _imageZoomInActive.default
        },
        zoomOut: {
          REST: _imageZoomOut.default,
          GROUP: _blank.default,
          HOVER: _imageZoomOutActive.default,
          DOWN: _imageZoomOutActive.default
        },
        home: {
          REST: _imageHome.default,
          GROUP: _blank.default,
          HOVER: _imageHomeActive.default,
          DOWN: _imageHomeActive.default
        },
        fullpage: {
          REST: _imageFullscreen.default,
          GROUP: _blank.default,
          HOVER: _imageFullscreenActive.default,
          DOWN: _imageFullscreenActive.default
        },
        rotateleft: {
          REST: _imageRotateLeft.default,
          GROUP: _blank.default,
          HOVER: _imageRotateLeftActive.default,
          DOWN: _imageRotateLeftActive.default
        },
        rotateright: {
          REST: _imageRotateRight.default,
          GROUP: _blank.default,
          HOVER: _imageRotateRightActive.default,
          DOWN: _imageRotateRightActive.default
        }
      },
      gestureSettingsTouch: {
        pinchRotate: true
      },
      prefixUrl: '',
      showNavigator: true,
      showRotationControl: true,
      tileSources: {
        type: 'image',
        url: blobUrl
      }
    });
    const saveLink = document.createElement('a');
    saveLink.className = _ImageViewerSaveLink.default.common;
    saveLink.href = blobUrl;
    saveLink.download = filename;
    saveLink.title = 'Save';
    viewer.buttons.element.appendChild(saveLink);
    this.viewer = viewer;
  }
  componentWillUnmount() {
    if (this.viewer) {
      this.viewer.destroy();
    }
    this.viewer = null;
  }
  handleContainerRef(ref) {
    this.containerElement = ref;
  }
  render() {
    return /*#__PURE__*/_react.default.createElement("div", {
      className: _ImageViewer.default.common
    }, /*#__PURE__*/_react.default.createElement("div", {
      ref: this.handleContainerRef
    }));
  }
}
exports.default = ImageViewer;
ImageViewer.propTypes = propTypes;
ImageViewer.defaultProps = defaultProps;