import{r as s,j as e}from"./vendor-react-wBh_31cN.js";import{R as w,G as R,S as v,cY as i,cF as c,dJ as U,cB as k}from"./index-BKr2rJhV.js";import{u as A}from"./useCurrentProject-C6qZaZgv.js";import"./vendor-redux-CJZrIb6x.js";import"./vendor-router-D1GqFWiT.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./useProject-FSnHbCQX.js";import"./index-BeaoFlb1.js";const x=50*1024*1024,h=o=>`${(o/(1024*1024)).toFixed(1)} MB`,G=({attributes:{size:o,path:r,name:j}})=>{const{id:l}=A(),[y,d]=s.useState(null),[g,f]=s.useState(!0),[b,u]=s.useState(!1),[p,m]=s.useState(null),n=o>x;if(s.useEffect(()=>{if(n)return()=>{};let t=!1;return(async()=>{f(!0),m(null);try{const D=(await i.getDownloadToken(+l,r,c.DATASET)).data.data,S=i.getUrl(`${l}/dataset/download/with_token/${encodeURIComponent(r)}?token=${D}&type=${c.DATASET}`),T=await U.get(S,{responseType:"arraybuffer",headers:k.getHeaders()});if(t)return;const E=new Blob([T.data],{type:"application/pdf"});d(URL.createObjectURL(E))}catch{t||m("Failed to load PDF file.")}finally{t||f(!1)}})(),()=>{t=!0,d(a=>(a&&URL.revokeObjectURL(a),null))}},[l,r,n]),n){const t=async()=>{u(!0);try{await i.download(+l,r,c.DATASET)}finally{u(!1)}};return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 p-5 w-full h-full",children:[e.jsxs(w,{children:["This file (",h(o),") is too large to preview. The preview limit is ",h(x),"."]}),e.jsx(R,{onClick:t,loading:b,children:"Download file"})]})}return g?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx(v,{})}):p?e.jsx("div",{className:"flex justify-center p-5 w-full",children:e.jsx(w,{children:p})}):e.jsx("div",{className:"w-full h-full",children:e.jsx("iframe",{title:`pdf-${j}`,src:y??void 0,style:{width:"100%",height:"100%",border:"none"}})})};export{G as default};
