import{jsx as i}from"react/jsx-runtime";import{k as e,l as o,m as r,i as s,e as a,j as t}from"./index-CQXsL1YZ.js";import{useEffect as l,useRef as d,useState as m}from"react";import{getUUID as n}from"@bbodek/utils";import{u as p}from"./usePreviewImage-DqIO3PcZ.js";import"react-dom";import"@bbodek/hooks";import"overlay-kit";const f=({file:i,width:r,listRef:s,setUrls:a,setIsLoading:t})=>{l((()=>{t(!0),s.current&&(s.current.scrollTop=0),(async()=>{try{const s=await e({file:i.original}),t=Array.from({length:s.numPages},((i,e)=>o({doc:s,pageNum:e+1,width:r}))),l=await Promise.all(t);a(l.map((i=>({id:n(),url:i,isLoaded:!1}))))}catch(i){}finally{t(!1)}})()}),[i,s,r])},u=a((()=>import("./PreviewPdfViewerImage-D3F7-6hd.js")),{ssr:!1}),c=({file:e,viewerSize:o,previewOptions:a})=>{const l=d(null),[n,c]=m(null),{models:{imgSize:w},status:{isLoading:g,isError:h},operations:{setIsLoading:L,onLoadImage:v,setIsError:I}}=p(),b=()=>{n&&(c((i=>i.map((i=>({...i,isLoaded:!0}))))),I(!0))};f({file:e,width:o.width,listRef:l,setUrls:c,setIsLoading:L});const j=g||(n??[]).some((i=>!i.isLoaded)),k={url:e.blob,name:e.name};return!g&&!n||h?i(r,{downloadOptions:k}):i("div",{className:"h-full max-h-full w-full max-w-full overflow-auto",ref:l,children:i(s,{isLoading:j,loadingComponent:i(t,{}),children:n&&n.map((({id:e,url:r})=>i(u,{downloadOptions:k,imgSize:w,isError:h,previewOptions:a,src:r,viewerSize:o,onLoadImage:i=>{v(i),(({id:i})=>{n&&c((e=>e.map((e=>e.id===i?{...e,isLoaded:!0}:e))))})({id:e})},onError:b},e)))})})};export{c as default};
//# sourceMappingURL=PreviewPdfViewer-_C8n6C7L.js.map
