import{r as e}from"./react-vendor-f6QdChhz.js";import{j as s}from"./ui-vendor-CJlQk0Tq.js";import{f as n,g as l,h as t,i as a,ba as r,y as i,v as o,B as c,al as d,z as m}from"./index-CUIxi1yy.js";const u=()=>{const[s,n]=e.useState(!1),[l,t]=e.useState(null),[a,r]=e.useState(!1),[i,o]=e.useState("document.pdf"),[c,d]=e.useState(null);return{isOpen:s,pdfBlob:l,isGenerating:a,filename:i,openPreview:async(e,s)=>{try{r(!0),n(!0),o(s),d(e);const l=e.getBlob();t(l)}catch(l){t(null)}finally{r(!1)}},closePreview:()=>{n(!1),t(null),d(null)},handleDownload:()=>{if(l){const e=URL.createObjectURL(l),s=document.createElement("a");s.href=e,s.download=i,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(e)}},handlePrint:()=>{if(l){const e=URL.createObjectURL(l),s=window.open(e,"_blank");s&&s.addEventListener("load",()=>{s.print()}),setTimeout(()=>URL.revokeObjectURL(e),1e3)}}}},x=({open:u,onOpenChange:x,pdfBlob:f,isGenerating:h,filename:j,onDownload:p,onPrint:v})=>{const[w,b]=e.useState(null);return e.useEffect(()=>{if(f){const e=URL.createObjectURL(f);return b(e),()=>{URL.revokeObjectURL(e)}}},[f]),s.jsx(n,{open:u,onOpenChange:x,children:s.jsxs(l,{className:"max-w-4xl h-[90vh] flex flex-col",children:[s.jsxs(t,{children:[s.jsx(a,{children:"PDF Preview"}),s.jsx(r,{children:"Preview your PDF before downloading"})]}),s.jsx("div",{className:"flex-1 overflow-hidden border rounded-lg bg-muted/20",children:h?s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx(i,{className:"h-8 w-8 animate-spin text-primary"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating PDF preview..."})]})}):w?s.jsx("iframe",{src:w,className:"w-full h-full",title:"PDF Preview"}):s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx("p",{className:"text-sm text-muted-foreground",children:"No PDF to preview"})})}),s.jsxs(o,{className:"gap-2",children:[v&&s.jsxs(c,{variant:"outline",onClick:v,disabled:!w||h,children:[s.jsx(d,{className:"mr-2 h-4 w-4"}),"Print"]}),s.jsxs(c,{onClick:p,disabled:!w||h,children:[s.jsx(m,{className:"mr-2 h-4 w-4"}),"Download"]}),s.jsx(c,{variant:"outline",onClick:()=>x(!1),children:"Close"})]})]})})};export{x as P,u};