import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{Ki as r,S as i,ao as a,ga as o,ha as s,ro as c}from"./index-BP3TYB4i.js";import{a as l,i as u,n as d,o as f,t as p}from"./dialog-BeOPOVZK.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}]=i(),[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)(o,{size:`sm`,variant:`outline`,onClick:()=>g(!0),children:[(0,h.jsx)(c,{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)(r,{htmlFor:`recipient-email`,children:[`Recipient Email `,(0,h.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,h.jsx)(s,{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)(o,{variant:`outline`,onClick:()=>E(!1),disabled:b,children:`Cancel`}),(0,h.jsx)(o,{onClick:T,disabled:!_.trim()||b,children:b?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(a,{className:`mr-2 h-4 w-4 animate-spin`}),` Sending...`]}):`Send`})]})]})})]})}export{g as t};