import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{s as n}from"./utils-BO1RPuol.js";import{t as r}from"./download-CcXpNtZ6.js";import{ko as i,y as a,za as o}from"./index-B4NicEaS.js";var s=e(t(),1),c=n();function l({documentType:e,documentId:t}){let[n,{isLoading:l}]=a(),[u,d]=(0,s.useState)(null);return(0,c.jsxs)(`div`,{className:`inline-flex flex-col items-end`,children:[(0,c.jsx)(o,{size:`sm`,variant:`outline`,onClick:async()=>{try{d(null);let r=await n({document_type:e,document_id:t}).unwrap(),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`${e}_${t}.pdf`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}catch(e){let t=e?.data?.detail||e?.data?.error||`Failed to generate PDF`;d(t)}},disabled:l,children:l?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(i,{className:`mr-1 h-4 w-4 animate-spin`}),` Generating...`]}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(r,{className:`mr-1 h-4 w-4`}),` Print / Download`]})}),u&&(0,c.jsx)(`span`,{className:`text-xs text-destructive mt-1`,children:u})]})}export{l as t};