import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{Eo as r,Oo as i,Ra as a,S as o,aa as s,za as c}from"./index-Ct5uU080.js";import{a as l,i as u,n as d,o as f,t as p}from"./dialog-DuXDR687.js";var m=e(t(),1),h=n();function g({documentType:e,documentId:t}){let[n,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(``),[y,{isLoading:b}]=o(),[x,S]=(0,m.useState)(null),[C,w]=(0,m.useState)(!1),T=async()=>{if(_.trim())try{S(null),w(!1),await y({document_type:e,document_id:t,recipient_email:_.trim()}).unwrap(),w(!0),v(``),setTimeout(()=>{g(!1),w(!1)},1500)}catch(e){S(e?.data?.detail||e?.data?.error||`Failed to send email`)}},E=e=>{g(e),e||(v(``),S(null),w(!1))};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(c,{size:`sm`,variant:`outline`,onClick:()=>g(!0),children:[(0,h.jsx)(r,{className:`mr-1 h-4 w-4`}),` Send Email`]}),(0,h.jsx)(p,{open:n,onOpenChange:E,children:(0,h.jsxs)(d,{className:`sm:max-w-md`,children:[(0,h.jsx)(l,{children:(0,h.jsx)(f,{children:`Send Document via Email`})}),(0,h.jsxs)(`div`,{className:`space-y-4 py-4`,children:[(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(s,{htmlFor:`recipient-email`,children:[`Recipient Email `,(0,h.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,h.jsx)(a,{id:`recipient-email`,type:`email`,placeholder:`Enter recipient email address`,value:_,onChange:e=>v(e.target.value),disabled:b})]}),x&&(0,h.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive`,children:x}),C&&(0,h.jsx)(`div`,{className:`rounded-lg border border-green-300 bg-green-50 px-4 py-3 text-sm text-green-700`,children:`Email sent successfully!`})]}),(0,h.jsxs)(u,{children:[(0,h.jsx)(c,{variant:`outline`,onClick:()=>E(!1),disabled:b,children:`Cancel`}),(0,h.jsx)(c,{onClick:T,disabled:!_.trim()||b,children:b?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(i,{className:`mr-2 h-4 w-4 animate-spin`}),` Sending...`]}):`Send`})]})]})})]})}export{g as t};