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