1import{r as h,j as e}from"./vendor-motion-BHKvfdub.js";import{c as Z,as as E,bj as q,I as S,B as y,Y as G,u as v,v as U,Z as z,aq as F,o as V,t as Y,aF as W,p as J}from"./index-BDt3UX3X.js";import{B as A}from"./badge-D5ubbIAJ.js";import{D as X,a as ee,b as se,c as $}from"./dropdown-menu-BpV-CY6b.js";import{D as te,a as ae,b as re,c as ne,d as ie,e as oe}from"./dialog-B50exQqv.js";import{L as b}from"./label-4q10JGVi.js";import{T as le}from"./textarea-DxkSw6qQ.js";import{S as ce}from"./send-CrA3iafD.js";import{E as de}from"./ellipsis-mOPgVHct.js";import{G as me}from"./industry-clusters-BmXLRTEh.js";import{R as pe}from"./reply-DD0xUrui.js";import{A as xe}from"./arrow-up-right-Boc6Svtc.js";import{A as ue,u as he,r as fe}from"./useEmailTimeline-5WcimZbc.js";import{f as ge,K as je,d as B}from"./vendor-date-CSkIof3m.js";import"./vendor-recharts-DrQ74lLO.js";import"./vendor-supabase-DXfLReh3.js";import"./index-DIgXukDO.js";import"./index-NejKyax4.js";import"./index-D_q-EAms.js";import"./check-BgfOALFd.js";import"./circle-C6tq3KpR.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ye=Z("ReplyAll",[["polyline",{points:"7 17 2 12 7 7",key:"t83bqg"}],["polyline",{points:"12 17 7 12 12 7",key:"1g4ajm"}],["path",{d:"M22 18v-2a4 4 0 0 0-4-4H7",key:"1fcyog"}]]);function ve({open:s,onOpenChange:d,replyToMessageId:m,mode:p,defaultTo:x,defaultCc:f=[],originalSubject:i,originalFromLabel:c,originalReceivedAt:u,originalBodyPreview:g,contactId:o,dealId:t,companyId:a}){const{t:r}=E(),_=q(),[j,N]=h.useState(x),[n,M]=h.useState(f.join(", ")),[w,T]=h.useState(""),[C,L]=h.useState(!1),I=f.join(",");h.useEffect(()=>{s&&(N(x),M(I),T(""))},[s,x,I]);const K=i!=null&&i.toLowerCase().startsWith("re:")?i:`Re: ${i??""}`,P=async()=>{if(!w.trim()){v.error(r("common.pleaseEnterMessage"));return}L(!0);try{const l=w.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"),D=(g??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"),Q=` 7 <div style="font-family:Segoe UI,Arial,sans-serif;font-size:14px;color:#1f2937;"> 8 <div>${l}</div> 9 <br/> 10 <div style="border-left:3px solid #e5e7eb;padding-left:10px;color:#6b7280;font-size:13px;"> 11 <div style="margin-bottom:6px;"><strong>Am ${new Date(u).toLocaleString("de-DE")} schrieb ${c}:</strong></div> 12 <div>${D}</div> 13 </div> 14 </div> 15 `,H=n.split(",").map(k=>k.trim()).filter(Boolean),O=j.split(",").map(k=>k.trim()).filter(Boolean),{error:R}=await U.functions.invoke("microsoft-mail-send",{body:{mode:p,reply_to_message_id:m,to:O,cc:H,body_html:Q,contact_id:o,deal_id:t,company_id:a}});if(R)throw R;v.success(r("email.replySent")),d(!1),_.invalidateQueries({queryKey:["crm-email-messages"]})}catch(l){const D=l instanceof Error?l.message:String(l);v.error(`Senden fehlgeschlagen: ${D}`)}finally{L(!1)}};return e.jsx(te,{open:s,onOpenChange:d,children:e.jsxs(ae,{className:"sm:max-w-2xl",children:[e.jsxs(re,{children:[e.jsx(ne,{children:p==="reply_all"?"Allen antworten":"Antworten"}),e.jsx(ie,{className:"text-xs",children:r("email.sentViaOutlook")})]}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"text-xs text-muted-foreground",children:"An"}),e.jsx(S,{value:j,onChange:l=>N(l.target.value),placeholder:"[email protected]"})]}),p==="reply_all"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"text-xs text-muted-foreground",children:"CC"}),e.jsx(S,{value:n,onChange:l=>M(l.target.value),placeholder:"[email protected], [email protected]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"text-xs text-muted-foreground",children:"Betreff"}),e.jsx(S,{value:K,disabled:!0,className:"bg-muted/30"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(b,{className:"text-xs text-muted-foreground",children:"Nachricht"}),e.jsx(le,{value:w,onChange:l=>T(l.target.value),rows:8,placeholder:"Hallo, ...",className:"resize-y min-h-[180px] text-sm",autoFocus:!0}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:r("email.originalQuoted")})]})]}),e.jsxs(oe,{children:[e.jsx(y,{variant:"outline",onClick:()=>d(!1),disabled:C,children:r("common.cancel")}),e.jsx(y,{onClick:P,disabled:C||!w.trim(),children:C?e.jsxs(e.Fragment,{children:[e.jsx(G,{className:"h-4 w-4 mr-1.5 animate-spin"})," Sendeâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 mr-1.5"})," Senden"]})})]})]})})}function Ne({email:s,expanded:d,onToggle:m,onReassign:p,availableDeals:x,threaded:f}){const{t:i}=E(),c=s.direction==="outbound",u=c?xe:ue,g=s.sentiment==="positive"?"default":s.sentiment==="negative"?"destructive":"secondary",[o,t]=h.useState(!1),[a,r]=h.useState("reply"),_=s.from_email??s.counterparty_email,j=(s.cc_recipients??[]).map(n=>n==null?void 0:n.email).filter(n=>!!n),N=s.from_name??s.from_email??s.counterparty_email;return e.jsxs("div",{className:f?"pl-7 relative":"",children:[f&&e.jsx("div",{className:`absolute left-2.5 top-3 h-1.5 w-1.5 rounded-full ${c?"bg-primary":"bg-success"} shrink-0 aspect-square`,"aria-hidden":!0}),e.jsx(z,{className:"border",children:e.jsxs(F,{className:"p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[e.jsx(u,{className:`h-4 w-4 mt-0.5 shrink-0 ${c?"text-primary":"text-success"}`}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2 text-sm",children:[e.jsx("span",{className:"font-medium truncate",children:c?`Du an ${s.counterparty_name??s.counterparty_email}`:`${s.from_name??s.from_email??s.counterparty_email} an dich`}),e.jsxs("span",{className:"text-xs text-muted-foreground",title:ge(new Date(s.received_at),"Pp",{locale:B}),children:["· ",je(new Date(s.received_at),{addSuffix:!0,locale:B})]})]}),e.jsxs("button",{onClick:m,className:"text-left w-full mt-0.5 text-sm font-semibold flex items-center gap-1 hover:underline",children:[d?e.jsx(V,{className:"h-3 w-3"}):e.jsx(Y,{className:"h-3 w-3"}),s.subject??"(kein Betreff)"]}),!d&&s.body_preview&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 mt-1",children:s.body_preview})]})]}),e.jsxs(X,{children:[e.jsx(ee,{asChild:!0,children:e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(de,{className:"h-4 w-4"})})}),e.jsxs(se,{align:"end",className:"w-56",children:[e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"Anderem Deal zuordnen"}),x.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs italic text-muted-foreground",children:i("email.noDealsAvailable")}),x.map(n=>e.jsx($,{onClick:()=>p(n.id),disabled:n.id===s.deal_id,children:n.title},n.id)),e.jsx($,{onClick:()=>p(null),children:"â Zuordnung entfernen â"})]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.sentiment&&e.jsx(A,{variant:g,className:"text-[10px]",children:s.sentiment}),s.deal&&e.jsxs(A,{variant:"outline",className:"text-[10px] gap-1",children:[s.inherited_from_thread?e.jsx(me,{className:"h-3 w-3"}):e.jsx(W,{className:"h-3 w-3"}),"KI-Match: ",s.deal.title,s.inherited_from_thread?" · ererbt aus Thread":s.ai_match_confidence!=null?` · ${Math.round(s.ai_match_confidence*100)}%`:""]}),s.manually_reassigned&&e.jsx(A,{variant:"secondary",className:"text-[10px]",children:"manuell korrigiert"}),s.ai_match_reason&&!s.inherited_from_thread&&e.jsxs("span",{className:"text-[11px] text-muted-foreground italic",children:["â",s.ai_match_reason,'"']}
15)]}),d&&e.jsxs("div",{className:"border-t pt-2 mt-2",children:[s.body_html?e.jsx("iframe",{srcDoc:s.body_html,sandbox:"",className:"w-full min-h-[200px] border rounded bg-background",title:s.subject??"Email body"}):e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:s.body_preview}),!c&&e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>{r("reply"),t(!0)},children:[e.jsx(pe,{className:"h-3.5 w-3.5 mr-1.5"})," Antworten"]}),j.length>0&&e.jsxs(y,{size:"sm",variant:"ghost",onClick:()=>{r("reply_all"),t(!0)},children:[e.jsx(ye,{className:"h-3.5 w-3.5 mr-1.5"})," Allen antworten"]})]})]})]})}),!c&&e.jsx(ve,{open:o,onOpenChange:t,replyToMessageId:s.id,mode:a,defaultTo:_,defaultCc:j,originalSubject:s.subject,originalFromLabel:N,originalReceivedAt:s.received_at,originalBodyPreview:s.body_preview,contactId:s.contact_id,dealId:s.deal_id,companyId:s.company_id})]})}function Qe({scope:s,availableDeals:d=[]}){const{t:m}=E(),p=q(),[x,f]=h.useState({}),{data:i,isLoading:c}=he(s);if(c)return e.jsx("div",{className:"text-sm text-muted-foreground",children:"Lade Mailsâ¦"});if(!i||i.length===0)return e.jsx(z,{children:e.jsxs(F,{className:"p-6 text-center text-sm text-muted-foreground",children:[e.jsx(J,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}
15),m("email.noEmailsYet"),e.jsx("p",{className:"text-xs mt-1",children:m("email.enableMailSync")})]})});const u=new Map;for(const o of i){const t=o.conversation_id??o.id;u.has(t)||u.set(t,[]),u.get(t).push(o)}const g=async(o,t)=>{try{await fe(o,t)}catch(a){v.error(m("email.assignFailed"),{description:a instanceof Error?a.message:String(a)});return}v(m("email.assignmentSaved","Zuordnung gespeichert")),p.invalidateQueries({queryKey:["crm-email-messages"]})};return e.jsx("div",{className:"space-y-4",children:Array.from(u.entries()).map(([o,t])=>e.jsxs("div",{className:"relative",children:[t.length>1&&e.jsx("div",{className:"absolute left-3 top-3 bottom-3 w-px bg-border","aria-hidden":!0}),e.jsx("div",{className:"space-y-2",children:t.map(a=>e.jsx(Ne,{email:a,expanded:!!x[a.id],onToggle:()=>f(r=>({...r,[a.id]:!r[a.id]})),onReassign:r=>g(a.id,r),availableDeals:d,threaded:t.length>1},a.id))})]},o))})}export{Qe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.