import React, { useState } from "react";
import { Document, Page, pdfjs } from "react-pdf";
import { repeat } from "../../utils";
import "react-pdf/dist/Page/TextLayer.css";
import "react-pdf/dist/Page/AnnotationLayer.css";

// TODO check this https://github.com/wojtekmaj/react-pdf#browserify-and-others
import { jsx as ___EmotionJSX } from "@emotion/react";
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 const PdfRenderer = _ref => {
  let {
    attachment
  } = _ref;
  const [numberOfPages, setNumberOfPages] = useState(0);
  return ___EmotionJSX(Document, {
    file: "data:application/pdf;base64,".concat(attachment.data),
    onLoadSuccess: _ref2 => {
      let {
        numPages
      } = _ref2;
      setNumberOfPages(numPages);
    }
  }, ___EmotionJSX("style", {
    // TODO: The scoped attribute is deprecated and not supported by HTML5. May only be supported by Firefox.
    // eslint-disable-next-line react/no-unknown-property
    scoped: true,
    dangerouslySetInnerHTML: {
      __html: "\n      canvas {\n        margin: auto;\n      }\n    "
    }
  }), repeat(numberOfPages)(index =>
  // 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