"use strict";var e=require("@babel/runtime/helpers/defineProperty"),r=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),a=require("prop-types"),i=require("classnames"),n=require("@material-ui/core"),l=require("@material-ui/icons/Close"),o=require("@material-ui/icons/GetApp"),s=require("./styles.js"),c=require("../LoadingIndicator/LoadingIndicator.js"),d=require("react/jsx-runtime");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=u(e),m=u(r),p=u(a),v=u(i),h=u(l),j=u(o),x=function(e){var r=e.fileUrl,a=e.fileSize,i=e.fileName,l=e.webviewType,o=e.onClose,u=e["data-testid"],p=t.useState(!0),x=m.default(p,2),b=x[0],g=x[1],w=t.useState(!1),y=m.default(w,2),q=y[0],N=y[1],I=t.createRef(null),S=t.createRef(null),z=s.useStyles(),C=t.useCallback((function(){return"office"===l?"https://view.officeapps.live.com/op/embed.aspx?src=".concat(window.encodeURIComponent(r)):"https://docs.google.com/viewer?url=".concat(encodeURIComponent(r),"&embedded=true")}),[r]),T=function(){S.current&&(S.current.src=C(),S.current.contentWindow.location.reload())},R=function(){I.current&&clearInterval(I.current),g(!1)};return t.useEffect((function(){g(!0),N(!1);var e=a&&a>=1048576?a/1048576*1e4:1e4;return I&&(clearInterval(I.current),I.current=setInterval(T,e)),function(){clearInterval(I.current)}}),[r]),d.jsxs("div",{"data-testid":"".concat(u,"_file_").concat(i),className:z.viewer,children:[d.jsxs("div",{className:z.toolbar,children:[d.jsx(n.Typography,{"data-testid":"".concat(u,"_fileName"),children:i}),d.jsxs("div",{children:[d.jsx(n.IconButton,{size:"small",className:z.iconButton,children:d.jsx("a",{download:!0,href:r,target:"_blank",rel:"noopener noreferrer",children:d.jsx(j.default,{fontSize:"small"})})}),d.jsx(n.IconButton,{size:"small",onClick:o,className:z.iconButton,children:d.jsx(h.default,{fontSize:"small"})})]})]}),b&&d.jsx("div",{className:z.frame,children:d.jsx(c,{white:!1})}),q?d.jsx("div",{className:z.frame,children:d.jsx(n.Typography,{variant:"body2",className:z.failed,children:"Loading failed"})}):d.jsx("iframe",{"data-testid":"".concat(u,"_frame"),className:v.default(z.frame,f.default({},z.hiddenFrame,b)),title:r,src:C(),onLoad:R,onError:function(){R(),N(!0)},ref:S})]})};x.propTypes={fileUrl:p.default.string.isRequired,webviewType:p.default.oneOf(["google","office"]),fileName:p.default.string,fileSize:p.default.number,onClose:p.default.func.isRequired,"data-testid":p.default.string},x.defaultProps={fileName:void 0,fileSize:void 0,webviewType:"google","data-testid":"DocumentViewer"},module.exports=x;
//# sourceMappingURL=index.js.map
