import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{t as r}from"./download-DV-8H5Y0.js";import{ao as i,ga as a,y as o}from"./index-BP3TYB4i.js";var s=e(t(),1),c=n();function l({documentType:e,documentId:t}){let[n,{isLoading:l}]=o(),[u,d]=(0,s.useState)(null);return(0,c.jsxs)(`div`,{className:`inline-flex flex-col items-end`,children:[(0,c.jsx)(a,{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){d(e?.data?.detail||e?.data?.error||`Failed to generate PDF`)}},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};