import{av as x,p as i,F as r,r as m,j as n,S as g}from"./bundle.CHKSNOJF.js";const c=!!navigator.userAgent.match(/Android/i);function b(e){const d=x(),{renderAsHTML:o}=e,s=i.useRef(null),a=i.useRef(null),[u,f]=i.useState(!1);return i.useEffect(()=>(e.enabled!==!1&&(e.withToast&&r.processing(),f(!0),d.fetchQuery({queryKey:[e.link,JSON.stringify(e.resource)],retry:0,queryFn:({signal:h})=>(e.onRequest&&e.onRequest(),m(e.method,e.link,e.resource,{responseType:"arraybuffer",signal:h,...e.headers&&{headers:e.headers}}).then(l=>{const y=new Blob([l.data],{type:o?"text/html":"application/pdf"}),t=URL.createObjectURL(y);c&&s.current&&(s.current.href=t,e.onLink&&e.onLink(t)),!c&&a.current&&(a.current.src=t,e.onLink&&e.onLink(t)),r.dismiss()}).catch(l=>{e.onError&&e.onError(l),r.dismiss()}).finally(()=>f(!1)))})),()=>{r.dismiss()}),[e.link,e.resource,e.enabled]),c?n.jsxs("p",{children:["Unable to preview PDF.  ",n.jsx("a",{ref:s,style:{textDecoration:"underline"},children:"Click to download it."})]}):n.jsxs("div",{className:"flex flex-col w-full",style:{height:e.height||1500},children:[u&&n.jsx("div",{className:"flex justify-center items-center w-full",style:{height:"100%"},children:n.jsx(g,{})}),n.jsx("iframe",{ref:a,width:"100%",height:u?0:"100%",loading:"lazy",tabIndex:-1})]})}export{b as I,c as a};
