function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React, { Component } from 'react';
import 'whatwg-fetch';
import { ConfigConsumer } from "../config-provider/context";
import { replaceMessage } from "../locale/utils";
import "./PdfViewer.less";
var TOOLBAR_HEIGHT = 40;
var AUTO_SCALE = 1.25;
var Viewer = /*#__PURE__*/function (_Component) {
  _inherits(Viewer, _Component);
  var _super = _createSuper(Viewer);
  // eslint-disable-next-line react/sort-comp

  function Viewer(props) {
    var _this;
    _classCallCheck(this, Viewer);
    _this = _super.call(this, props);
    _defineProperty(_assertThisInitialized(_this), "container", void 0);
    _defineProperty(_assertThisInitialized(_this), "hideControlsTimer", void 0);
    _defineProperty(_assertThisInitialized(_this), "hidingControls", void 0);
    _defineProperty(_assertThisInitialized(_this), "initilized", false);
    _defineProperty(_assertThisInitialized(_this), "lastUpdateTime", void 0);
    _defineProperty(_assertThisInitialized(_this), "pageHeight", 0);
    _defineProperty(_assertThisInitialized(_this), "pageInput", void 0);
    _defineProperty(_assertThisInitialized(_this), "pageWidth", 0);
    _defineProperty(_assertThisInitialized(_this), "scaleSelect", void 0);
    _defineProperty(_assertThisInitialized(_this), "scrollHideControls", false);
    _defineProperty(_assertThisInitialized(_this), "scrollTimer", void 0);
    _defineProperty(_assertThisInitialized(_this), "scrollTop", void 0);
    _defineProperty(_assertThisInitialized(_this), "styleLink", void 0);
    _defineProperty(_assertThisInitialized(_this), "initViewer", function () {
      _this.initilized = false;
      var _this$props = _this.props,
        file = _this$props.file,
        startPage = _this$props.startPage,
        host = _this$props.host;
      var link = document.createElement('link');
      link.rel = 'stylesheet';
      link.href = host + "/api/office/km/file/convert/info/".concat(file, "?fileName=index.css");
      link.onload = function () {
        setTimeout(function () {
          _this.resetScale();
          var pageDiv = document.querySelector('.pdf2html-viewer-page');
          _this.pageWidth = (pageDiv === null || pageDiv === void 0 ? void 0 : pageDiv.clientWidth) || 0;
          _this.pageHeight = (pageDiv === null || pageDiv === void 0 ? void 0 : pageDiv.clientHeight) || 0;
          _this.setState({
            pages: {},
            scaleValue: 'width'
          });
          _this.gotoPage(startPage);
          _this.updatePageIndex();
          _this.fitWidth();
          setTimeout(function () {
            _this.scrollTop = _this.container.scrollTop;
            _this.initilized = true;
          }, 0);
        }, 0);
      };
      document.head.appendChild(link);
      _this.styleLink = link;
    });
    _defineProperty(_assertThisInitialized(_this), "hideScrollbar", function () {
      var pagesDiv = document.querySelector('.pdf2html-viewer-pages');
      if (pagesDiv) {
        var scrollbarWidth = (pagesDiv === null || pagesDiv === void 0 ? void 0 : pagesDiv.offsetWidth) - (pagesDiv === null || pagesDiv === void 0 ? void 0 : pagesDiv.clientWidth);
        pagesDiv.style.right = "".concat(-scrollbarWidth, "px");
      }
    });
    _defineProperty(_assertThisInitialized(_this), "scrollListener", function () {
      var scrollTop = _this.container.scrollTop;
      if (_this.scrollHideControls && !_this.hidingControls && scrollTop > 100 && scrollTop > _this.scrollTop) {
        _this.hideControls();
      }
      if (_this.container.scrollTop <= 100 || scrollTop < _this.scrollTop) {
        _this.showControls();
      }
      _this.scrollTop = scrollTop;
      var time = Date.now();
      if (!_this.lastUpdateTime) {
        _this.lastUpdateTime = time;
      }
      if (time - _this.lastUpdateTime > 50) {
        _this.updatePageIndex();
        _this.lastUpdateTime = time;
      } else {
        clearTimeout(_this.scrollTimer);
        _this.scrollTimer = setTimeout(function () {
          return _this.updatePageIndex();
        }, 50);
      }
    });
    _defineProperty(_assertThisInitialized(_this), "updatePageIndex", function () {
      var pageCount = _this.props.pageCount;
      var minY = _this.container.scrollTop + TOOLBAR_HEIGHT;
      var maxY = minY + _this.container.clientHeight;
      var pageDivs = [].slice.call(document.querySelectorAll('.pdf2html-viewer-page'));
      var start = 0;
      var end = pageCount - 1;
      while (start < end) {
        var middleIndex = Math.floor((start + end) / 2);
        var middleDiv = pageDivs[middleIndex];
        var divBottom = (middleDiv === null || middleDiv === void 0 ? void 0 : middleDiv.offsetTop) + (middleDiv === null || middleDiv === void 0 ? void 0 : middleDiv.offsetHeight);
        if (divBottom > minY) {
          end = middleIndex;
        } else {
          start = middleIndex + 1;
        }
      }
      var visibleIndexes = [];
      var maxVisibleHeight = 0;
      var maxVisibleIndex = start;
      var i;
      var len;
      for (i = start, len = pageCount; i < len; i++) {
        var pageDiv = pageDivs[i];
        var visibleHeight = Math.min(maxY, (pageDiv === null || pageDiv === void 0 ? void 0 : pageDiv.offsetTop) + (pageDiv === null || pageDiv === void 0 ? void 0 : pageDiv.offsetHeight)) - Math.max(minY, pageDiv.offsetTop);
        if (visibleHeight > 0) {
          visibleIndexes.push(i);
          if (visibleHeight > maxVisibleHeight) {
            maxVisibleHeight = visibleHeight;
            maxVisibleIndex = i;
          }
        } else {
          break;
        }
      }
      if (start > 0) visibleIndexes.push(start - 1);
      if (i < pageCount) visibleIndexes.push(i);
      _this.setState({
        currentPage: maxVisibleIndex + 1,
        visibleIndexes: visibleIndexes
      });
      _this.pageInput.value = maxVisibleIndex + 1;
      visibleIndexes.forEach(function (index) {
        return index >= 0 && index < pageCount && _this.loadPage(index);
      });
    });
    _defineProperty(_assertThisInitialized(_this), "loadPage", function (index) {
      var _this$props2 = _this.props,
        file = _this$props2.file,
        onPageLoaded = _this$props2.onPageLoaded,
        host = _this$props2.host;
      var _this$state = _this.state,
        pages = _this$state.pages,
        scaleValue = _this$state.scaleValue;
      var page = pages[index];
      if (!file) return;
      if (page && (page.loaded || page.loading)) return;
      var url = host + "/api/office/km/file/convert/info/".concat(file, "?page=").concat(index + 1);
      _this.setState({
        pages: _objectSpread(_objectSpread({}, pages), {}, _defineProperty({}, index, page ? _objectSpread(_objectSpread({}, page), {}, {
          loading: true
        }) : {
          loading: true
        }))
      }, function () {
        fetch(url, {
          credentials: 'same-origin'
        }).then(function (res) {
          return res.text();
        }).then(function (json) {
          var html = new DOMParser().parseFromString(json, 'text/html');
          var pages = _this.state.pages;
          var page = pages[index];
          var prefixUrl = host + "/api/office/km/file/convert/info/".concat(file);
          var targetHtml = html.querySelector('.pf');
          var imgEles = targetHtml === null || targetHtml === void 0 ? void 0 : targetHtml.querySelectorAll('img');
          if (imgEles) {
            imgEles.forEach(function (img) {
              var path = img.src || '';
              var name = path.lastIndexOf('/') ? path.substring(path.lastIndexOf('/') + 1, path.length) : '';
              img.src = "".concat(prefixUrl, "?fileName=").concat(name);
            });
          }
          _this.setState({
            pages: _objectSpread(_objectSpread({}, pages), {}, _defineProperty({}, index, page ? _objectSpread(_objectSpread({}, page), {}, {
              html: targetHtml,
              loading: false,
              loaded: true
            }) : {
              html: targetHtml,
              loaded: true
            }))
          }, function () {
            if (scaleValue === 'width') {
              _this.fitWidth();
            }
          });
          onPageLoaded && onPageLoaded(index + 1);
        });
      });
    });
    _defineProperty(_assertThisInitialized(_this), "gotoPage", function (page) {
      var delta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
      if (!page) return;
      _this.container.scrollTop = 0;
      var pageDiv = document.querySelector("div[data-page-no=\"".concat(page, "\"]"));
      if (pageDiv) {
        _this.container.scrollTop = pageDiv.offsetTop - TOOLBAR_HEIGHT - delta;
      }
    });
    _defineProperty(_assertThisInitialized(_this), "prevPage", function () {
      var currentPage = _this.state.currentPage;
      _this.gotoPage(Math.max(1, currentPage - 1));
    });
    _defineProperty(_assertThisInitialized(_this), "nextPage", function () {
      var pageCount = _this.props.pageCount;
      var currentPage = _this.state.currentPage;
      _this.gotoPage(Math.min(pageCount, currentPage + 1));
    });
    _defineProperty(_assertThisInitialized(_this), "enterPage", function (e) {
      var value = e.target.value;
      if (!/^\d+$/.test(value)) return;
      var page = parseInt(value, 10);

      // eslint-disable-next-line react/destructuring-assignment
      if (page < 1 || page > _this.props.pageCount) return;
      _this.gotoPage(page);
      e.target.blur();
    });
    _defineProperty(_assertThisInitialized(_this), "resetScale", function () {
      var pageDivs = [].slice.call(document.querySelectorAll('.pdf2html-viewer-page'));
      pageDivs.forEach(function (div) {
        div.style.width = '';
        div.style.height = '';
        div.style.opacity = '';
      });
      _this.setState({
        currentScale: 1
      });
    });
    _defineProperty(_assertThisInitialized(_this), "setScale", function (scale) {
      var _this$container;
      var currentPage = _this.state.currentPage;
      var pageDiv = document.querySelector("div[data-page-no=\"".concat(currentPage, "\"]"));
      var delta = (pageDiv === null || pageDiv === void 0 ? void 0 : pageDiv.offsetTop) - ((_this$container = _this.container) === null || _this$container === void 0 ? void 0 : _this$container.scrollTop) - TOOLBAR_HEIGHT;
      var pageDivs = [].slice.call(document.querySelectorAll('.pdf2html-viewer-page'));
      pageDivs.forEach(function (div) {
        div.style.width = "".concat(Math.round(_this.pageWidth * scale), "px");
        div.style.height = "".concat(Math.round(_this.pageHeight * scale), "px");
        div.style.opacity = '1';
      });
      _this.setState({
        currentScale: scale || 1
      }, function () {
        _this.gotoPage(currentPage, delta);
        _this.updatePageIndex();
      });
    });
    _defineProperty(_assertThisInitialized(_this), "zoomOut", function () {
      var currentScale = _this.state.currentScale;
      var nextScale;
      if (currentScale <= 1.1) {
        nextScale = currentScale + 0.1 + 0.0001;
      } else if (currentScale <= 2) {
        nextScale = currentScale + 0.2 + 0.0001;
      } else if (currentScale <= 3) {
        nextScale = currentScale + 0.3 + 0.0001;
      } else {
        nextScale = currentScale + 0.4 + 0.0001;
      }
      if (nextScale > 4) {
        nextScale = 4;
      }
      nextScale = Math.floor(nextScale * 10) / 10;
      var scaleValue = "".concat(Math.round(nextScale * 100), "%");
      _this.setScale(nextScale);
      _this.setState({
        scaleValue: scaleValue
      });
      // 兼容Firefox
      _this.scaleSelect.value = scaleValue;
    });
    _defineProperty(_assertThisInitialized(_this), "zoomIn", function () {
      var currentScale = _this.state.currentScale;
      var nextScale;
      if (currentScale > 3) {
        nextScale = currentScale - 0.4 - 0.0001;
      } else if (currentScale > 2) {
        nextScale = currentScale - 0.3 - 0.0001;
      } else if (currentScale > 1.1) {
        nextScale = currentScale - 0.2 - 0.0001;
      } else {
        nextScale = currentScale - 0.1 - 0.0001;
      }
      if (nextScale < 0.5) {
        nextScale = 0.5;
      }
      nextScale = Math.ceil(nextScale * 10) / 10;
      var scaleValue = "".concat(Math.round(nextScale * 100), "%");
      _this.setScale(nextScale);
      _this.setState({
        scaleValue: scaleValue
      });
      // 兼容Firefox
      _this.scaleSelect.value = scaleValue;
    });
    _defineProperty(_assertThisInitialized(_this), "changeScale", function (value) {
      switch (value) {
        case 'auto':
          _this.autoScale();
          break;
        case 'actual':
          _this.setScale(1);
          _this.setState({
            scaleValue: 'actual'
          });
          break;
        case 'fit':
          _this.fitPage();
          break;
        case 'width':
          _this.fitWidth();
          break;
        default:
          _this.setScale(value - 0);
          _this.setState({
            scaleValue: "".concat(Math.round(value * 100), "%")
          });
          break;
      }
    });
    _defineProperty(_assertThisInitialized(_this), "autoScale", function () {
      var pageDiv = document.querySelector('.pdf2html-viewer-page');
      var scaleX = pageDiv !== null && pageDiv !== void 0 && pageDiv.parentElement ? pageDiv.parentElement.clientWidth / _this.pageWidth : 1;
      var scale = Math.min(AUTO_SCALE, scaleX);
      _this.setScale(scale);
      _this.setState({
        scaleValue: 'auto'
      });
    });
    _defineProperty(_assertThisInitialized(_this), "fitPage", function () {
      var pageDiv = document.querySelector('.pdf2html-viewer-page');
      var scaleX = pageDiv !== null && pageDiv !== void 0 && pageDiv.parentElement ? pageDiv.parentElement.clientWidth / _this.pageWidth : 1;
      var scaleY = pageDiv !== null && pageDiv !== void 0 && pageDiv.parentElement ? (pageDiv.parentElement.offsetHeight - TOOLBAR_HEIGHT) / _this.pageHeight : 1;
      var scale = Math.min(scaleX, scaleY);
      _this.setScale(scale);
      _this.setState({
        scaleValue: 'fit'
      });
    });
    _defineProperty(_assertThisInitialized(_this), "fitWidth", function () {
      var pageDiv = document.querySelector('.pdf2html-viewer-page');
      var childDiv = pageDiv === null || pageDiv === void 0 ? void 0 : pageDiv.querySelector('.pf');
      if (childDiv) {
        _this.pageWidth = childDiv.clientWidth;
        _this.pageHeight = childDiv.clientHeight;
      }
      var scale = pageDiv !== null && pageDiv !== void 0 && pageDiv.parentElement ? ((pageDiv.parentElement.clientWidth - 20) / _this.pageWidth).toFixed(2) : 1;
      _this.setScale(Number(scale));
      _this.setState({
        scaleValue: 'width'
      });
    });
    _defineProperty(_assertThisInitialized(_this), "toggleFullScreen", function () {
      var onFullScreenChange = _this.props.onFullScreenChange;
      var _this$state2 = _this.state,
        fullscreen = _this$state2.fullscreen,
        scaleValue = _this$state2.scaleValue;
      fullscreen ? document.body.style.overflow = '' : document.body.style.overflow = 'hidden';
      _this.setState({
        fullscreen: !fullscreen
      }, function () {
        var nextFullscreen = _this.state.fullscreen;
        if (['auto', 'fit', 'width'].includes(scaleValue)) {
          _this.changeScale(scaleValue);
        }
        _this.updatePageIndex();
        onFullScreenChange && onFullScreenChange(nextFullscreen);
      });
    });
    _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (e) {
      switch (e.keyCode) {
        case 38:
          e.preventDefault();
          return _this.prevPage();
        case 40:
          e.preventDefault();
          return _this.nextPage();
        default:
      }
    });
    _defineProperty(_assertThisInitialized(_this), "handleMouseMove", function (e) {
      if (!_this.initilized) return;
      var rect = e.currentTarget.getBoundingClientRect();
      var offsetTop = e.clientY - rect.top;
      var offsetLeft = e.clientX - rect.left;
      var offsetRight = rect.right - e.clientX;
      if (offsetTop < 80 || offsetLeft < 80 || offsetRight < 80) {
        _this.scrollHideControls = false;
        _this.showControls();
      } else {
        _this.scrollHideControls = true;
      }
    });
    _defineProperty(_assertThisInitialized(_this), "hideControls", function () {
      _this.hidingControls = true;
      _this.hideControlsTimer = setTimeout(function () {
        // eslint-disable-next-line no-return-assign
        _this.setState({
          hideControls: true
        }, function () {
          return TOOLBAR_HEIGHT = 0;
        });
        _this.hidingControls = false;
      }, 2000);
    });
    _defineProperty(_assertThisInitialized(_this), "showControls", function () {
      clearTimeout(_this.hideControlsTimer);
      // eslint-disable-next-line no-return-assign
      _this.setState({
        hideControls: false
      }, function () {
        return TOOLBAR_HEIGHT = 40;
      });
      _this.hidingControls = false;
    });
    _this.state = {
      currentPage: 1,
      currentScale: 1,
      fullscreen: props.fullscreen,
      hideControls: false,
      pages: {},
      scaleValue: '',
      visibleIndexes: []
    };
    return _this;
  }
  _createClass(Viewer, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.initViewer();
      this.hideScrollbar();
      this.container.addEventListener('scroll', this.scrollListener);
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps, prevState) {
      var _this$props3 = this.props,
        file = _this$props3.file,
        onPageChanged = _this$props3.onPageChanged,
        onToggleControls = _this$props3.onToggleControls;
      var _this$state3 = this.state,
        currentPage = _this$state3.currentPage,
        hideControls = _this$state3.hideControls;
      if (file !== prevProps.file) {
        this.styleLink && document.head.removeChild(this.styleLink);
        this.initViewer();
      }
      if (currentPage !== prevState.currentPage && onPageChanged) {
        onPageChanged(currentPage);
      }
      if (hideControls !== prevState.hideControls && onToggleControls) {
        onToggleControls(!hideControls);
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.styleLink && document.head.removeChild(this.styleLink);
      this.container.removeEventListener('scroll', this.scrollListener);
      document.body.style.overflow = '';
    }

    // eslint-disable-next-line react/sort-comp
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;
      var _this$props4 = this.props,
        pageCount = _this$props4.pageCount,
        title = _this$props4.title,
        allowDownload = _this$props4.allowDownload,
        onDownload = _this$props4.onDownload;
      var _this$state4 = this.state,
        pages = _this$state4.pages,
        visibleIndexes = _this$state4.visibleIndexes,
        currentScale = _this$state4.currentScale,
        scaleValue = _this$state4.scaleValue,
        currentPage = _this$state4.currentPage,
        fullscreen = _this$state4.fullscreen,
        hideControls = _this$state4.hideControls;
      var classCls = "pdf2html-viewer-container pdf2html-viewer-container".concat(fullscreen ? ' pdf2html-viewer-fullscreen' : '').concat(hideControls ? ' hide-controls' : '');
      return /*#__PURE__*/React.createElement(ConfigConsumer, null, function (props) {
        var uiLocale = props.uiLocale;
        return /*#__PURE__*/React.createElement("div", {
          className: classCls,
          tabIndex: -1,
          onKeyDown: _this2.handleKeyDown,
          onMouseMove: _this2.handleMouseMove
        }, /*#__PURE__*/React.createElement("div", {
          className: "pdf2html-viewer-toolbar"
        }, /*#__PURE__*/React.createElement("div", {
          className: "toolbar-title"
        }, title), /*#__PURE__*/React.createElement("div", {
          className: "toolbar-center"
        }, /*#__PURE__*/React.createElement("button", {
          onClick: _this2.zoomIn,
          className: "toolbar-btn btn-zoom-in",
          type: "button"
        }, ' '), /*#__PURE__*/React.createElement("button", {
          onClick: _this2.zoomOut,
          className: "toolbar-btn btn-zoom-out",
          type: "button"
        }, ' '), /*#__PURE__*/React.createElement("span", {
          className: "toolbar-scale-select"
        }, /*#__PURE__*/React.createElement("select", {
          value: scaleValue,
          onChange: function onChange(e) {
            return _this2.changeScale(e.target.value);
          }
          // eslint-disable-next-line no-return-assign
          ,
          ref: function ref(el) {
            return _this2.scaleSelect = el;
          }
        }, /*#__PURE__*/React.createElement("option", {
          value: "auto"
        }, uiLocale.Preview.auto), /*#__PURE__*/React.createElement("option", {
          value: "actual"
        }, uiLocale.Preview.actual), /*#__PURE__*/React.createElement("option", {
          value: "fit"
        }, uiLocale.Preview.fitPage), /*#__PURE__*/React.createElement("option", {
          value: "width"
        }, uiLocale.Preview.fitWidth), /*#__PURE__*/React.createElement("option", {
          value: scaleValue,
          disabled: true,
          hidden: true
        }, scaleValue), [50, 75, 100, 125, 150, 200, 300, 400].map(function (value) {
          return /*#__PURE__*/React.createElement("option", {
            value: value / 100,
            key: value
          }, "".concat(value, "%"));
        })))), /*#__PURE__*/React.createElement("div", {
          className: "toolbar-right"
        }, allowDownload && /*#__PURE__*/React.createElement("button", {
          onClick: function onClick() {
            return onDownload && onDownload();
          },
          className: "toolbar-btn btn-download",
          type: "button"
        }, ' '), /*#__PURE__*/React.createElement("button", {
          onClick: _this2.prevPage,
          className: "toolbar-btn btn-prev-page",
          disabled: currentPage <= 1,
          type: "button"
        }, ' '), /*#__PURE__*/React.createElement("button", {
          onClick: _this2.nextPage,
          className: "toolbar-btn btn-next-page",
          disabled: currentPage >= pageCount,
          type: "button"
        }, ' '), /*#__PURE__*/React.createElement("span", {
          className: "toolbar-current-page"
        }, /*#__PURE__*/React.createElement("input", {
          ref: function ref(input) {
            _this2.pageInput = input;
          },
          onKeyUp: function onKeyUp(e) {
            return e.key === 'Enter' && _this2.enterPage(e);
          }
        }), '/ ', pageCount), /*#__PURE__*/React.createElement("button", {
          onClick: _this2.toggleFullScreen,
          className: "toolbar-btn ".concat(fullscreen ? 'btn-exit-fullscreen' : 'btn-fullscreen'),
          type: "button"
        }, ' '))), /*#__PURE__*/React.createElement("div", {
          className: "pdf2html-viewer-pages-wrapper"
        }, /*#__PURE__*/React.createElement("div", {
          className: "pdf2html-viewer-pages",
          ref: function ref(div) {
            _this2.container = div;
          }
        }, Array.from({
          length: pageCount
        }, function (item, index) {
          return index;
        }).map(function (index) {
          var page = pages[index];
          if (page && page.loading) {
            return /*#__PURE__*/React.createElement("div", {
              key: index,
              "data-page-no": "".concat(index + 1),
              className: "pdf2html-viewer-page w0 h0 is-loading"
            }, /*#__PURE__*/React.createElement("div", {
              className: "pdf2html-viewer-spin"
            }));
          }
          var inner = null;
          if (page && page.html) {
            inner = page.html;
            inner.style.transform = "scale(".concat(currentScale, ")");
          }
          return /*#__PURE__*/React.createElement("div", {
            className: "pdf2html-viewer-page w0 h0",
            key: index,
            "data-page-no": "".concat(index + 1),
            dangerouslySetInnerHTML: {
              __html: inner && visibleIndexes.includes(index) ? inner.outerHTML : ''
            }
          });
        }))), /*#__PURE__*/React.createElement("div", {
          className: "pdf2html-viewer-progress"
        }, /*#__PURE__*/React.createElement("div", {
          className: "progress-bar",
          style: {
            width: "".concat(currentPage / pageCount * 100, "%")
          }
        }), /*#__PURE__*/React.createElement("span", {
          className: "progress-text"
        }, replaceMessage(uiLocale.Preview.readPercent, {
          percent: "".concat(Math.round(currentPage / pageCount * 100))
        }))));
      });
    }
  }]);
  return Viewer;
}(Component);
_defineProperty(Viewer, "defaultProps", {
  pageCount: 1,
  fullscreen: false
});
export { Viewer as default };