import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
import React, { useState } from "react";
import { Document, Page, pdfjs } from "react-pdf";
import { repeat } from "../../utils";
import { jsx as ___EmotionJSX } from "@emotion/react";
// TODO check this https://github.com/wojtekmaj/react-pdf#browserify-and-others
pdfjs.GlobalWorkerOptions.workerSrc = "//cdnjs.cloudflare.com/ajax/libs/pdf.js/".concat(pdfjs.version, "/pdf.worker.js");
/**
 * Component rendering pdf attachments. Uses [react-pdf](http://projects.wojtekmaj.pl/react-pdf/) under the hood.
 */

export var PdfRenderer = function PdfRenderer(_ref) {
  var attachment = _ref.attachment;

  var _useState = useState(0),
      _useState2 = _slicedToArray(_useState, 2),
      numberOfPages = _useState2[0],
      setNumberOfPages = _useState2[1];

  return ___EmotionJSX(Document, {
    file: "data:application/pdf;base64,".concat(attachment.data),
    onLoadSuccess: function onLoadSuccess(_ref2) {
      var numPages = _ref2.numPages;
      setNumberOfPages(numPages);
    }
  }, ___EmotionJSX("style", {
    scoped: true,
    dangerouslySetInnerHTML: {
      __html: "\n      canvas {\n        margin: auto;\n      }\n    "
    }
  }), repeat(numberOfPages)(function (index) {
    return (// TODO: Dynamically resize width to fit container
      // https://github.com/wojtekmaj/react-pdf/issues/129
      ___EmotionJSX(Page, {
        key: "page_".concat(index + 1),
        pageNumber: index + 1
      })
    );
  }));
};
//# sourceMappingURL=PdfRenderer.js.map