1import{r as g,j as e}from"./vendor-BwygqmH8.js";import{S as we}from"./SDRFullAutoConfirm-COk-K1y_.js";import{u as oe,s as p,i as ee}from"./index-BqHqKq3I.js";import{g as ze}from"./LeadWatchPage-BKmR39dn.js";import{a6 as U,aT as Ie,a as de,T as O,N as We,bg as Ce,f as K,J as Ae,am as Re,k as le,bl as Te,p as De,X as ce,a4 as se,i as Ee,e1 as ie,b1 as qe,C as te}from"./icons-B7bQwT6M.js";import"./monitoring-DqjV4dpj.js";import"./deps-D_AQaZss.js";import"./supabase-BM56svY1.js";import"./App-CwTlHduM.js";import"./Field-DQ05uNMW.js";import"./leadImportFields-_LlMDVd_.js";function Be({teamId:l,teamOwnerUserId:c,onClose:b}){var C,w,A;const{user:z}=oe(),[I,$]=g.useState(!0),[f,v]=g.useState(!1),[k,D]=g.useState(!1),[P,y]=g.useState(""),[E,q]=g.useState(!1);async function M(a){const{error:i}=await p.from("teams").update({sdr_auto_send_approved:a,sdr_auto_send_approved_by:a&&(z==null?void 0:z.id)||null,sdr_auto_send_approved_at:a?new Date().toISOString():null}).eq("id",l);if(i){y(`Couldn't update send mode: ${i.message}`);return}q(a),_(h=>({...h,sdr_default_mode:a?"auto":"draft",sdr_enabled:!0}))}const[o,_]=g.useState({sdr_enabled:!0,sdr_default_mode:"draft",sdr_personality:"balanced",sdr_channels:{sms:!0,email:!0},sdr_email_provider:"auto",sdr_grace_period_seconds:120,sdr_handoff_score:70,sdr_max_drips:5,sdr_business_hours:{start:"08:00",end:"20:00",timezone:"America/Los_Angeles"},thresholds:{warning:15,urgent:60,critical:240}}),[x,W]=g.useState({auto_stale_alerts:!0,stale_lead_days:7,auto_reassign_enabled:!1,reassign_after_days:14});g.useEffect(()=>{if(!l)return;let a=!1;return(async()=>{const i=p.from("lead_watch_config").select("sdr_enabled, sdr_default_mode, sdr_personality, sdr_channels, sdr_email_provider, sdr_grace_period_seconds, sdr_handoff_score, sdr_max_drips, sdr_business_hours, thresholds"),[{data:h,error:m},{data:u,error:N},{data:L}]=await Promise.all([c?i.eq("user_id",c).maybeSingle():i.eq("team_id",l).maybeSingle(),c?p.from("ai_automation_config").select("auto_stale_alerts, stale_lead_days, auto_reassign_enabled, reassign_after_days").eq("user_id",c).maybeSingle():Promise.resolve({data:null,error:null}),p.from("teams").select("sdr_auto_send_approved").eq("id",l).maybeSingle()]);if(!a){if(m){y(m.message),$(!1);return}h&&_(S=>({...S,...h,sdr_channels:h.sdr_channels||S.sdr_channels,sdr_business_hours:h.sdr_business_hours||S.sdr_business_hours,thresholds:h.thresholds||S.thresholds})),!N&&u&&W(S=>({...S,...u})),q(!!(L!=null&&L.sdr_auto_send_approved)),$(!1)}})(),()=>{a=!0}},[l]);async function B(){var a,i,h;v(!0),y("");try{const m=p.from("lead_watch_config").update({sdr_enabled:o.sdr_enabled,sdr_default_mode:o.sdr_default_mode,sdr_personality:o.sdr_personality,sdr_channels:o.sdr_channels,sdr_email_provider:o.sdr_email_provider||"auto",sdr_grace_period_seconds:Number(o.sdr_grace_period_seconds)||120,sdr_handoff_score:Number(o.sdr_handoff_score)||70,sdr_max_drips:Number(o.sdr_max_drips)||5,sdr_business_hours:o.sdr_business_hours,thresholds:{warning:Number((a=o.thresholds)==null?void 0:a.warning)||15,urgent:Number((i=o.thresholds)==null?void 0:i.urgent)||60,critical:Number((h=o.thresholds)==null?void 0:h.critical)||240}}),[{error:u},{error:N}]=await Promise.all([c?m.eq("user_id",c):m.eq("team_id",l),c?p.from("ai_automation_config").upsert({user_id:c,auto_stale_alerts:!!x.auto_stale_alerts,stale_lead_days:Number(x.stale_lead_days)||7,auto_reassign_enabled:!!x.auto_reassign_enabled,reassign_after_days:Number(x.reassign_after_days)||14},{onConflict:"user_id"}):Promise.resolve({error:null})]);if(u)throw u;if(N)throw N;b==null||b()}catch(m){y((m==null?void 0:m.message)||String(m))}finally{v(!1)}}return e.jsx("div",{onClick:b,style:{position:"fixed",inset:0,background:"rgba(0,0,0,.55)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",padding:20},children:e.jsxs("div",{onClick:a=>a.stopPropagation(),style:{width:"100%",maxWidth:640,maxHeight:"92vh",overflow:"auto",background:"var(--surface)",borderRadius:16,border:"1px solid var(--b1)",boxShadow:"0 24px 60px rgba(0,0,0,.35)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"18px 22px",borderBottom:"1px solid var(--b1)"},children:[e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:10},children:[e.jsx(U,{size:20,strokeWidth:2.2,color:"var(--brand)"}),e.jsxs("div",{children:[e.jsx("div",{className:"serif",style:{fontSize:17,fontWeight:700,color:"var(--text)"},children:"AI SDR Settings"}),e.jsx("div",{style:{fontSize:11,color:"var(--muted)"},children:"How the AI talks to your leads"})]})]}),e.jsx("button",{onClick:b,style:{background:"none",border:"none",cursor:"pointer",color:"var(--muted)",padding:4},children:e.jsx(ce,{size:18,strokeWidth:2.2})})]}),I?e.jsx("div",{style:{padding:40,textAlign:"center",color:"var(--muted)",fontSize:13},children:"Loadingâ¦"}):e.jsxs("div",{style:{padding:22,display:"flex",flexDirection:"column",gap:18},children:[P&&e.jsx("div",{style:{padding:10,background:"rgba(239,68,68,.08)",color:"#ef4444",borderRadius:8,fontSize:12},children:P}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!o.sdr_enabled,onChange:a=>_(i=>({...i,sdr_enabled:a.target.checked})),style:{width:18,height:18,accentColor:"var(--brand)"}}),e.jsx("span",{style:{fontSize:14,fontWeight:600,color:o.sdr_enabled?"var(--brand)":"var(--muted)"},children:o.sdr_enabled?"AI SDR Active":"AI SDR Disabled"})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:700,color:"var(--muted)",marginBottom:6,textTransform:"uppercase",letterSpacing:".04em"},children:"Default Send Mode"}),e.jsx("div",{style:{display:"flex",gap:8},children:[{val:"draft",label:"Draft & Approve",desc:"AI drafts, you send (safest)"}
1,{val:"auto",label:"Full Auto",desc:"AI sends immediately"}].map(a=>{const i=a.val==="auto"?E:!E;return e.jsxs("button",{onClick:()=>{if(a.val==="auto"){D(!0);return}M(!1)},style:{flex:1,padding:"12px 14px",borderRadius:10,border:i?"2px solid var(--brand)":"1px solid var(--b1)",background:i?"rgba(var(--brand-rgb), .08)":"var(--bg)",cursor:"pointer",textAlign:"left"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:a.label}),e.jsx("div",{style:{fontSize:10,color:"var(--muted)",marginTop:2},children:a.desc})]},a.val)})}),e.jsx(we,{open:k,onCancel:()=>D(!1),onConfirm:()=>{M(!0),D(!1)}})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:700,color:"var(--muted)",marginBottom:6,textTransform:"uppercase",letterSpacing:".04em"},children:"Channels"}),e.jsx("div",{style:{display:"flex",gap:18},children:[{key:"sms",label:"SMS"},{key:"email",label:"Email"}].map(a=>e.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:13,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:(o.sdr_channels||{})[a.key]??!0,onChange:i=>_(h=>({...h,sdr_channels:{...h.sdr_channels||{},[a.key]:i.target.checked}})),style:{accentColor:"var(--brand)"}}),a.label]},a.key))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:700,color:"var(--muted)",marginBottom:6,textTransform:"uppercase",letterSpacing:".04em"},children:"Email Provider"}),e.jsx("div",{style:{display:"flex",gap:8},children:[{val:"auto",label:"Auto",desc:"Gmail, fall back to Resend"},{val:"gmail",label:"Gmail",desc:"Send as agent via Gmail OAuth"},{val:"resend",label:"Resend",desc:"Send via your connected domain"}].map(a=>{const i=(o.sdr_email_provider||"auto")===a.val;return e.jsxs("button",{onClick:()=>_(h=>({...h,sdr_email_provider:a.val})),style:{flex:1,padding:"10px 12px",borderRadius:10,border:i?"2px solid var(--brand)":"1px solid var(--b1)",background:i?"rgba(var(--brand-rgb), .08)":"var(--bg)",cursor:"pointer",textAlign:"left"},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:a.label}),e.jsx("div",{style:{fontSize:10,color:"var(--muted)",marginTop:2},children:a.desc})]},a.val)})}),e.jsx("div",{style:{fontSize:10,color:"var(--dim)",marginTop:6},children:"Gmail mode lands the email in the lead's inbox under your real address and replies route to your inbox natively. Use Resend if you've connected a marketing domain."})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:700,color:"var(--muted)",marginBottom:6,textTransform:"uppercase",letterSpacing:".04em"},children:"Personality"}),e.jsx("div",{style:{display:"flex",gap:8},children:[{val:"aggressive",label:"Aggressive",desc:"Pushes for appointments"},{val:"balanced",label:"Balanced",desc:"Friendly + consultative"},{val:"supportive",label:"Supportive",desc:"Warm + educational"}].map(a=>{const i=(o.sdr_personality||"balanced")===a.val;return e.jsxs("button",{onClick:()=>_(h=>({...h,sdr_personality:a.val})),style:{flex:1,padding:"10px 12px",borderRadius:10,border:i?"2px solid var(--brand)":"1px solid var(--b1)",background:i?"rgba(var(--brand-rgb), .08)":"var(--bg)",cursor:"pointer",textAlign:"left"},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:a.label}),e.jsx("div",{style:{fontSize:10,color:"var(--muted)",marginTop:2},children:a.desc})]},a.val)})})]}),e.jsxs("div",{style:{paddingTop:4,borderTop:"1px solid var(--b1)"},children:[e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:8,marginTop:14,marginBottom:4},children:[e.jsx(O,{size:14,strokeWidth:2.2,color:"#f59e0b"}),e.jsx("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Alerts & Escalation"})]}),e.jsx("div",{style:{fontSize:10,color:"var(--muted)",marginBottom:10},children:"What the AI flags in your inbox when leads go cold or get stuck. Pings appear as cards above your drafts."}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:8,marginBottom:14},children:[{key:"warning",label:"Warning",color:"#f59e0b",help:"min before flag"},{key:"urgent",label:"Urgent",color:"#f97316",help:"min before flag"},{key:"critical",label:"Critical",color:"#ef4444",help:"min before flag"}].map(a=>{var i;return e.jsxs("div",{style:{padding:10,borderRadius:10,border:"1px solid var(--b1)",background:"var(--bg)",display:"flex",flexDirection:"column",alignItems:"center",gap:4},children:[e.jsx("div",{style:{fontSize:9,fontWeight:700,color:a.color,textTransform:"uppercase",letterSpacing:".04em"},children:a.label}),e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"number",min:1,max:1440,value:((i=o.thresholds)==null?void 0:i[a.key])??"",onChange:h=>_(m=>({...m,thresholds:{...m.thresholds||{},[a.key]:h.target.value}})),style:{width:56,padding:"4px 8px",borderRadius:6,border:"1px solid var(--b1)",background:"var(--surface)",color:a.color,fontSize:14,fontWeight:700,textAlign:"center"}}
1),e.jsx("span",{style:{fontSize:10,color:"var(--muted)"},children:"min"})]})]},a.key)})}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8,cursor:"pointer",fontSize:12},children:[e.jsx("input",{type:"checkbox",checked:!!x.auto_stale_alerts,onChange:a=>W(i=>({...i,auto_stale_alerts:a.target.checked})),style:{width:16,height:16,accentColor:"var(--brand)"}}),e.jsx("span",{style:{fontWeight:700,color:"var(--text)"},children:"Stale lead alerts"}),e.jsx("span",{style:{color:"var(--muted)"},children:"Flag after:"}),e.jsx("input",{type:"number",min:1,max:365,value:x.stale_lead_days??7,onChange:a=>W(i=>({...i,stale_lead_days:a.target.value})),disabled:!x.auto_stale_alerts,style:{width:50,padding:"3px 8px",borderRadius:6,border:"1px solid var(--b1)",background:"var(--surface)",color:"var(--text)",fontSize:12,textAlign:"center"}}),e.jsx("span",{style:{color:"var(--muted)"},children:"days"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,cursor:"pointer",fontSize:12},children:[e.jsx("input",{type:"checkbox",checked:!!x.auto_reassign_enabled,onChange:a=>W(i=>({...i,auto_reassign_enabled:a.target.checked})),style:{width:16,height:16,accentColor:"var(--brand)"}}),e.jsx("span",{style:{fontWeight:700,color:"var(--text)"},children:"Reassignment suggestions"}),e.jsx("span",{style:{color:"var(--muted)"},children:"after"}),e.jsx("input",{type:"number",min:1,max:365,value:x.reassign_after_days??14,onChange:a=>W(i=>({...i,reassign_after_days:a.target.value})),disabled:!x.auto_reassign_enabled,style:{width:50,padding:"3px 8px",borderRadius:6,border:"1px solid var(--b1)",background:"var(--surface)",color:"var(--text)",fontSize:12,textAlign:"center"}}),e.jsx("span",{style:{color:"var(--muted)"},children:"days â AI suggests moving stale leads to faster agents"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:11,fontWeight:700,color:"var(--muted)",marginBottom:4,textTransform:"uppercase",letterSpacing:".04em"},children:["Agent Grace Period â ",o.sdr_grace_period_seconds||120,"s (",Math.round((o.sdr_grace_period_seconds||120)/60),"min)"]}),e.jsx("div",{style:{fontSize:10,color:"var(--muted)",marginBottom:6},children:"Time agents have to claim a new lead before AI fires the first touch. Set 0 for instant AI response."}),e.jsx("input",{type:"range",min:0,max:300,step:15,value:o.sdr_grace_period_seconds??120,onChange:a=>_(i=>({...i,sdr_grace_period_seconds:Number(a.target.value)})),style:{width:"100%",accentColor:"var(--brand)"}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--muted)"},children:[e.jsx("span",{children:"Instant"}),e.jsx("span",{children:"1 min"}),e.jsx("span",{children:"2 min"}),e.jsx("span",{children:"3 min"}),e.jsx("span",{children:"5 min"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:11,fontWeight:700,color:"var(--muted)",marginBottom:4,textTransform:"uppercase",letterSpacing:".04em"},children:["Max Follow-Ups â ",o.sdr_max_drips||5]}),e.jsx("input",{type:"range",min:1,max:10,step:1,value:o.sdr_max_drips??5,onChange:a=>_(i=>({...i,sdr_max_drips:Number(a.target.value)})),style:{width:"100%",accentColor:"var(--brand)"}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--muted)"},children:[e.jsx("span",{children:"1"}),e.jsx("span",{children:"3"}),e.jsx("span",{children:"5"}),e.jsx("span",{children:"7"}),e.jsx("span",{children:"10"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:11,fontWeight:700,color:"var(--muted)",marginBottom:4,textTransform:"uppercase",letterSpacing:".04em"},children:["Auto-Handoff Score Threshold â ",o.sdr_handoff_score||70]}),e.jsx("div",{style:{fontSize:10,color:"var(--muted)",marginBottom:6},children:"When a lead's score reaches this level, AI hands off to a human agent."}),e.jsx("input",{type:"range",min:50,max:100,step:5,value:o.sdr_handoff_score??70,onChange:a=>_(i=>({...i,sdr_handoff_score:Number(a.target.value)})),style:{width:"100%",accentColor:"var(--brand)"}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--muted)"},children:[e.jsx("span",{children:"50 (early)"}),e.jsx("span",{children:"70 (balanced)"}),e.jsx("span",{children:"100 (fully qualified)"})]})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:700,color:"var(--muted)",marginBottom:4,textTransform:"uppercase",letterSpacing:".04em"},children:"Business Hours"}
1),e.jsx("div",{style:{fontSize:10,color:"var(--muted)",marginBottom:8},children:"AI SDR only sends during these hours; messages queued outside the window."}),e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs("label",{style:{fontSize:12},children:["Start",e.jsx("input",{type:"time",value:((C=o.sdr_business_hours)==null?void 0:C.start)||"08:00",onChange:a=>_(i=>({...i,sdr_business_hours:{...i.sdr_business_hours||{},start:a.target.value}})),style:{marginLeft:6,padding:"4px 8px",borderRadius:6,border:"1px solid var(--b1)",background:"var(--bg)",color:"var(--text)",fontSize:12}})]}),e.jsxs("label",{style:{fontSize:12},children:["End",e.jsx("input",{type:"time",value:((w=o.sdr_business_hours)==null?void 0:w.end)||"20:00",onChange:a=>_(i=>({...i,sdr_business_hours:{...i.sdr_business_hours||{},end:a.target.value}})),style:{marginLeft:6,padding:"4px 8px",borderRadius:6,border:"1px solid var(--b1)",background:"var(--bg)",color:"var(--text)",fontSize:12}})]}),e.jsxs("label",{style:{fontSize:12},children:["Timezone",e.jsxs("select",{value:((A=o.sdr_business_hours)==null?void 0:A.timezone)||"America/Los_Angeles",onChange:a=>_(i=>({...i,sdr_business_hours:{...i.sdr_business_hours||{},timezone:a.target.value}})),style:{marginLeft:6,padding:"4px 8px",borderRadius:6,border:"1px solid var(--b1)",background:"var(--bg)",color:"var(--text)",fontSize:12},children:[e.jsx("option",{value:"America/Los_Angeles",children:"Pacific"}),e.jsx("option",{value:"America/Denver",children:"Mountain"}),e.jsx("option",{value:"America/Chicago",children:"Central"}),e.jsx("option",{value:"America/New_York",children:"Eastern"}),e.jsx("option",{value:"America/Phoenix",children:"Arizona"}),e.jsx("option",{value:"Pacific/Honolulu",children:"Hawaii"})]})]})]})]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"14px 22px",borderTop:"1px solid var(--b1)",background:"var(--bg)"},children:[e.jsx("button",{onClick:b,disabled:f,style:{padding:"8px 16px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--surface)",color:"var(--text)",cursor:"pointer"},children:"Cancel"}),e.jsx("button",{onClick:B,disabled:f||I,style:{padding:"8px 18px",fontSize:12,fontWeight:700,border:"none",borderRadius:8,background:"var(--brand)",color:"#fff",cursor:f?"not-allowed":"pointer",opacity:f?.6:1},children:f?"Savingâ¦":"Save settings"})]})]})})}function ue(l){if(!l)return"";const c=new Date(l).getTime(),b=Math.floor((Date.now()-c)/1e3);return b<60?`${b}s ago`:b<3600?`${Math.floor(b/60)}m ago`:b<86400?`${Math.floor(b/3600)}h ago`:`${Math.floor(b/86400)}d ago`}async function Ne(l){var c;try{if(typeof window>"u"||!((c=window.crypto)!=null&&c.subtle))return null;const b=await window.crypto.subtle.digest("SHA-256",new TextEncoder().encode(l));return Array.from(new Uint8Array(b)).map(z=>z.toString(16).padStart(2,"0")).join("")}catch{return null}}function Le(l){if(!l||l==="__regenerating__")return{channel:null,subject:"",body:"",isJson:!1};if(typeof l=="string"&&l.trim().startsWith("{"))try{const c=JSON.parse(l);if(c&&typeof c=="object"&&typeof c.body=="string")return{channel:c.channel||"email",subject:c.subject||"",body:c.body||"",isJson:!0}}catch{}return{channel:null,subject:"",body:String(l),isJson:!1}}function $e({suggestion:l,busy:c,isTeamOwner:b,currentUserId:z,teamId:I,onDismiss:$,onSnooze:f,onAddTask:v,onDraftReengagement:k,onReassign:D}){var a,i,h,m;const y={stale_alert:{Icon:qe,label:"STALE LEAD",accent:"var(--brand-secondary, var(--brand))"},reassign:{Icon:ie,label:"REASSIGNMENT",accent:"var(--brand-secondary, var(--brand))"},follow_up:{Icon:Ee,label:"FOLLOW-UP",accent:"var(--brand)"},coaching:{Icon:se,label:"COACHING",accent:"var(--brand)"},performance:{Icon:se,label:"PERFORMANCE",accent:"var(--brand)"},deal_risk:{Icon:O,label:"DEAL AT RISK",accent:"#ef4444"}}[l.type]||{Icon:O,label:(l.type||"ALERT").toUpperCase(),accent:"var(--muted)"},E=l.priority==="critical"?"#ef4444":l.priority==="high"?"#f59e0b":l.priority==="medium"?"var(--brand)":"var(--muted)",[q,M]=g.useState([]),[o,_]=g.useState(!1),[x,W]=g.useState("");g.useEffect(()=>{if(l.type!=="reassign"||!I||q.length>0)return;let u=!1;return _(!0),p.from("profiles").select("id, full_name, email").eq("team_id",I).then(({data:N})=>{var S;if(u)return;
1const L=((S=l.action_data)==null?void 0:S.current_agent_user_id)||l.user_id;M((N||[]).filter(V=>V.id!==L))}).finally(()=>{u||_(!1)}),()=>{u=!0}},[l.type,I]);const B=((a=l.action_data)==null?void 0:a.lead_name)||"Unknown lead",C=((i=l.action_data)==null?void 0:i.lead_phone)||"",w=((h=l.action_data)==null?void 0:h.lead_source)||"",A=(m=l.action_data)==null?void 0:m.days_stale;return e.jsxs("div",{style:{padding:18,borderRadius:14,border:"1px solid var(--b1)",background:"var(--surface)",display:"flex",flexDirection:"column",gap:12,borderLeft:`4px solid ${E}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,minWidth:0,flex:1},children:[e.jsx("div",{style:{width:34,height:34,borderRadius:"50%",background:`${y.accent}1a`,color:y.accent,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(y.Icon,{size:16,strokeWidth:2.2})}),e.jsxs("div",{style:{minWidth:0,flex:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:B}),e.jsx("span",{style:{fontSize:9,fontWeight:700,padding:"2px 7px",borderRadius:999,background:`${y.accent}1a`,color:y.accent,textTransform:"uppercase",letterSpacing:".05em"},children:y.label}),A!=null&&e.jsxs("span",{style:{fontSize:9,fontWeight:700,padding:"2px 7px",borderRadius:999,background:`${E}1a`,color:E,textTransform:"uppercase",letterSpacing:".05em"},children:[A,"d stale"]})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--muted)",marginTop:2},children:[C||w||"",C&&w?` · ${w}`:""]})]})]}),e.jsx("span",{style:{fontSize:10,color:"var(--dim)",flexShrink:0},children:ue(l.created_at)})]}),e.jsx("div",{style:{padding:14,background:"var(--bg)",borderRadius:10,fontSize:13,lineHeight:1.55,color:"var(--text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:l.body}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[l.type==="stale_alert"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>k(l),disabled:c,title:"Have the AI write a re-engagement message for this lead",style:{padding:"8px 16px",fontSize:12,fontWeight:700,border:"none",borderRadius:8,background:"var(--brand)",color:"#fff",cursor:c?"not-allowed":"pointer",opacity:c?.6:1,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(K,{size:13,strokeWidth:2.4})," Draft re-engagement"]}),e.jsxs("button",{onClick:()=>v(l),disabled:c,title:"Create a lead task to call/follow up",style:{padding:"8px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--text)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(te,{size:12,strokeWidth:2.4})," Add task"]})]}),l.type==="reassign"&&e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:x,onChange:u=>W(u.target.value),disabled:c||o,style:{padding:"7px 10px",fontSize:12,borderRadius:8,border:"1px solid var(--b1)",background:"var(--bg)",color:"var(--text)",cursor:"pointer",minWidth:180},children:[e.jsx("option",{value:"",children:o?"Loadingâ¦":"Reassign toâ¦"}),q.map(u=>e.jsx("option",{value:u.id,children:u.full_name||u.email},u.id))]}),e.jsxs("button",{onClick:()=>D(l,x),disabled:c||!x,style:{padding:"8px 16px",fontSize:12,fontWeight:700,border:"none",borderRadius:8,background:x?"var(--brand)":"var(--b1)",color:x?"#fff":"var(--muted)",cursor:x?"pointer":"not-allowed",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(ie,{size:13,strokeWidth:2.4})," Reassign"]}),e.jsxs("button",{onClick:()=>v(l),disabled:c,style:{padding:"8px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--text)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(te,{size:12,strokeWidth:2.4})," Add task instead"]})]}),(l.type==="follow_up"||l.type==="deal_risk")&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>k(l),disabled:c,style:{padding:"8px 16px",fontSize:12,fontWeight:700,border:"none",borderRadius:8,background:"var(--brand)",color:"#fff",cursor:c?"not-allowed":"pointer",opacity:c?.6:1,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(K,{size:13,strokeWidth:2.4})," Draft message"]}),e.jsxs("button",{onClick:()=>v(l),disabled:c,style:{padding:"8px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--text)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(te,{size:12,strokeWidth:2.4})," Add task"]})]}),(l.type==="coaching"||l.type==="performance")&&e.jsxs("button",{onClick:()=>$(l,"completed"),disabled:c,style:{padding:"8px 16px",fontSize:12,fontWeight:700,border:"none",borderRadius:8,background:"var(--brand)",color:"#fff",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(le,{size:13,strokeWidth:2.4})," Acknowledge"]}),e.jsxs("div",{style:{marginLeft:"auto",display:"inline-flex",gap:8},children:[e.jsxs("button",{onClick:()=>f(l),disabled:c,title:"Snooze 3 days",style:{padding:"8px 12px",fontSize:11,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--muted)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(de,{size:11,strokeWidth:2.4})," Snooze"]}),e.jsxs("button",{onClick:()=>$(l),disabled:c,title:"Dismiss this alert",style:{padding:"8px 12px",fontSize:11,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--muted)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(ce,{size:11,strokeWidth:2.4})," Dismiss"]})]})]})]})}function Ve({setViewMode:l,isTeamOwner:c=!1,teamOwnerUserId:b=null}){const{profile:z,user:I,effectiveUserId:$}=oe(),f=z==null?void 0:z.team_id,v=$||(I==null?void 0:I.id),[k,D]=g.useState([]),[P,y]=g.useState([]),[E,q]=g.useState(!0),[M,o]=g.useState(null),[_,x]=g.useState(null),[W,B]=g.useState(""),[C,w]=g.useState(""),[A,a]=g.useState(!1),[i,h]=g.useState(null),[m,u]=g.useState(""),[N,L]=g.useState(!1),[S,V]=g.useState("all"),[Y,ge]=g.useState({pen
1ding:0,suggestions:0,sent_today:0,sent_week:0});async function R(){if(f){q(!0);try{let t=null;if(v){const{data:n}=await p.from("lead_watch_events").select("id").eq("team_id",f).eq("assigned_to",v);if(t=(n||[]).map(j=>j.id),t.length===0){D([]);return}}let r=p.from("sdr_conversations").select(` 2 id, lead_id, mode, step, drip_count, pending_draft, pending_draft_at, 3 last_ai_message_at, last_lead_reply_at, next_drip_at, active, 4 lead:lead_watch_events(id, lead_name, lead_email, lead_phone, source) 5 `).eq("team_id",f).eq("active",!0).not("pending_draft","is",null).neq("pending_draft","__regenerating__").order("pending_draft_at",{ascending:!1});t&&(r=r.in("lead_id",t));const{data:s,error:d}=await r;if(d)throw d;D(s||[])}catch(t){u((t==null?void 0:t.message)||String(t))}finally{q(!1)}}}async function ae(){if(f)try{let t=p.from("ai_suggestions").select("id, user_id, type, title, body, priority, action_data, status, created_at").eq("status","pending").order("priority",{ascending:!1}).order("created_at",{ascending:!1}).limit(50);if(c){const{data:d}=await p.from("profiles").select("id").eq("team_id",f),n=(d||[]).map(j=>j.id);if(n.length===0){y([]);return}t=t.in("user_id",n)}else if(v)t=t.eq("user_id",v);else{y([]);return}const{data:r,error:s}=await t;if(s)throw s;y(r||[])}catch(t){console.warn("[sdr-inbox] loadSuggestions failed:",(t==null?void 0:t.message)||t)}}async function F(){if(f)try{const t=new Date(Date.now()-864e5).toISOString(),r=new Date(Date.now()-7*86400*1e3).toISOString(),s=c?p.from("profiles").select("id").eq("team_id",f):null,d=s?((await s).data||[]).map(Z=>Z.id):v?[v]:[];let n=p.from("ai_suggestions").select("id",{count:"exact",head:!0}).eq("status","pending");d.length>0&&(n=n.in("user_id",d));let j=p.from("sdr_conversations").select("id",{count:"exact",head:!0}).eq("team_id",f).eq("active",!0).not("pending_draft","is",null).neq("pending_draft","__regenerating__");if(v){const{data:Z}=await p.from("lead_watch_events").select("id").eq("team_id",f).eq("assigned_to",v),ne=(Z||[]).map(ke=>ke.id);j=j.in("lead_id",ne.length?ne:["00000000-0000-0000-0000-000000000000"])}const[{count:T},{count:H},{count:G},{count:Se}]=await Promise.all([p.from("agent_ai_messages").select("id",{count:"exact",head:!0}).eq("team_id",f).contains("metadata",{source:"sdr_auto_send"}).gte("created_at",t),p.from("agent_ai_messages").select("id",{count:"exact",head:!0}).eq("team_id",f).contains("metadata",{source:"sdr_auto_send"}).gte("created_at",r),j,n]);ge({pending:G||0,suggestions:Se||0,sent_today:T||0,sent_week:H||0})}catch{}}g.useEffect(()=>{R(),ae(),F()},[f,v,c]),g.useEffect(()=>{if(!f)return;const t=p.channel(`sdr-inbox-${f}`).on("postgres_changes",{event:"*",schema:"public",table:"sdr_conversations",filter:`team_id=eq.${f}`},()=>{R(),F()}).on("postgres_changes",{event:"*",schema:"public",table:"ai_suggestions"},()=>{ae(),F()}).subscribe();return()=>{p.removeChannel(t)}},[f]);async function pe(t){o(t.id),u("");try{const r={action:"approve_draft",conversation_id:t.id},s=typeof t.pending_draft=="string"?await Ne(t.pending_draft):null;s&&(r.expected_draft_hash=s);const{data:d,error:n}=await ee("ai-sdr",r);if(n||d!=null&&d.error)throw new Error((n==null?void 0:n.message)||(d==null?void 0:d.error)||"Send failed");await R(),await F()}catch(r){const s=(r==null?void 0:r.message)||String(r);/draft_changed/i.test(s)||s==="HTTP 409"?(await R(),u("Draft changed â review the new version")):u(s)}finally{o(null)}}async function fe(t){o(t.id),u("");try{await p.from("sdr_conversations").update({pending_draft:"__regenerating__"}).eq("id",t.id);const{error:r}=await ee("ai-sdr",{action:"regenerate_draft",conversation_id:t.id});if(r)throw r;await R()}catch(r){u((r==null?void 0:r.message)||String(r))}finally{o(null)}}async function he(t){if(confirm("Discard this draft? The conversation stays active â AI will draft another follow-up at the next interval.")){o(t.id);try{await p.from("sdr_conversations").update({pending_draft:null,pending_draft_at:null}).eq("id",t.id),await R(),await F()}catch(r){u((r==null?void 0:r.message)||String(r))}finally{o(null)}}}async function xe(t){var r;if(confirm(`Turn AI SDR OFF for ${((r=t.lead)==null?void 0:r.lead_name)||"this lead"}? They'll stay in the system but the AI will stop drafting and sending.`)){o(t.id);try{await p.from("lead_watch_events").update({sdr_enabled:!1}).eq("id",t.lead_id),await p.from("sdr_conversations").update({active:!1,pending_draft:null,pending_draft_at:null}).eq("id",t.id),await R(),await F()}catch(s){u((s==null?void 0:s.message)||String(s))}finally{o(null)}}}async function J(t,r="dismissed"){o(`sug-${t.id}`);try{await p.from("ai_suggestions").update({status:r,resolved_at:new Date().toISOString()}).eq("id",t.id),y(s=>s.filter(d=>d.id!==t.id)),await F()}catch(s){u((s==null?void 0:s.message)||String(s))}finally{o(null)}}async function be(t){return J(t,"snoozed")}async function me(t){var r,s,d;o(`sug-${t.id}`);try{const n=(r=t.action_data)==null?void 0:r.event_id,j=((s=t.action_data)==null?void 0:s.lead_name)||"lead";if(!n)throw new Error("No lead reference on this alert");const{data:T}=await p.from("lead_watch_events").select("team_id").eq("id",n).maybeSingle();
5if(!(T!=null&&T.team_id))throw new Error("Lead not found");const H=t.type==="stale_alert"?`Call ${j} â uncontacted ${((d=t.action_data)==null?void 0:d.days_stale)||""}d`:t.type==="reassign"?`Decide on reassigning ${j}`:`Follow up with ${j}`;await p.from("lead_tasks").insert({lead_id:n,team_id:T.team_id,title:H,status:"pending",created_by:v}),await J(t,"completed")}catch(n){u((n==null?void 0:n.message)||String(n)),o(null)}}async function ve(t){var r;o(`sug-${t.id}`);try{const s=(r=t.action_data)==null?void 0:r.event_id;if(!s)throw new Error("No lead reference on this alert");const{data:d,error:n}=await ee("ai-sdr",{action:"draft_reengagement",lead_event_id:s});if(n||d!=null&&d.error)throw new Error((n==null?void 0:n.message)||(d==null?void 0:d.error)||"Draft failed");await J(t,"completed"),await R()}catch(s){u((s==null?void 0:s.message)||String(s)),o(null)}}async function _e(t,r){var s;if(r){o(`sug-${t.id}`);try{const d=(s=t.action_data)==null?void 0:s.event_id;if(!d)throw new Error("No lead reference on this alert");const{data:n}=await p.from("profiles").select("full_name, email").eq("id",r).maybeSingle(),j=(n==null?void 0:n.full_name)||(n==null?void 0:n.email)||"agent";await p.from("lead_watch_events").update({assigned_to:r,assigned_agent:j,user_id:r,reassigned_at:new Date().toISOString()}).eq("id",d),await J(t,"completed")}catch(d){u((d==null?void 0:d.message)||String(d)),o(null)}}}async function ye(t){o(t.id);try{const r=A?JSON.stringify({channel:i||"email",subject:(W||"").trim(),body:C}):C;await p.from("sdr_conversations").update({pending_draft:r}).eq("id",t.id),x(null),B(""),w(""),a(!1),h(null),await R()}catch(r){u((r==null?void 0:r.message)||String(r))}finally{o(null)}}const je=t=>{var r,s,d,n;return(r=t.lead)!=null&&r.lead_email&&((s=t.lead)!=null&&s.lead_phone)?"either":(d=t.lead)!=null&&d.lead_email?"email":(n=t.lead)!=null&&n.lead_phone?"sms":"either"},re=g.useMemo(()=>new Set(k.map(t=>t.id).filter(Boolean)),[k]),X=g.useMemo(()=>new Set(k.map(t=>t.lead_id).filter(Boolean)),[k]),Q=g.useMemo(()=>{const t=new Set,r=[];for(const s of P){const d=s.action_data||{};if(d.type==="sdr_draft"||d.sdr_conversation_id&&re.has(d.sdr_conversation_id)||d.lead_id&&X.has(d.lead_id)||d.event_id&&X.has(d.event_id))continue;const n=d.sdr_conversation_id||d.lead_id||d.event_id;if(n){if(t.has(n))continue;t.add(n)}r.push(s)}return r},[P,re,X]);return e.jsxs("div",{style:{padding:"20px 24px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:18},children:[e.jsxs("div",{children:[e.jsxs("div",{className:"serif",style:{fontSize:22,fontWeight:700,display:"inline-flex",alignItems:"center",gap:10},children:[e.jsx(U,{size:22,strokeWidth:2.2,color:"var(--brand)"}),e.jsx("span",{title:ze("SDR Inbox"),children:"AI SDR Inbox"})]}),e.jsx("div",{style:{fontSize:12,color:"var(--muted)",marginTop:4},children:"Drafts to approve, stale leads, reassignment suggestions â every action your AI SDR wants you to take, in one place."})]}),c&&e.jsxs("button",{onClick:()=>L(!0),style:{padding:"8px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--surface)",color:"var(--text)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(Ie,{size:13,strokeWidth:2.2})," SDR Settings"]})]}),N&&c&&e.jsx(Be,{teamId:f,teamOwnerUserId:b,onClose:()=>L(!1)}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:10,marginBottom:22},children:[{label:"Pending review",value:Y.pending,accent:"brand",Icon:de},{label:"Alerts",value:Y.suggestions,accent:"amber",Icon:O},{label:"Sent today",value:Y.sent_today,accent:"brand",Icon:We},{label:"Sent this week",value:Y.sent_week,accent:"muted",Icon:U}].map(t=>{const r=t.accent==="brand"?"rgba(var(--brand-rgb), .12)":t.accent==="amber"?"rgba(245,158,11,.12)":"rgba(0,0,0,.05)",s=t.accent==="brand"?"var(--brand)":t.accent==="amber"?"#f59e0b":"var(--muted)";return e.jsxs("div",{style:{padding:"14px 16px",borderRadius:12,border:"1px solid var(--b1)",background:"var(--surface)",display:"flex",alignItems:"center",gap:12},children:[e.jsx("div",{style:{width:36,height:36,borderRadius:10,background:r,color:s,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(t.Icon,{size:18,strokeWidth:2.2})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"var(--muted)",fontWeight:600,textTransform:"uppercase",letterSpacing:".04em"},children:t.label}),e.jsx("div",{style:{fontSize:22,fontWeight:800,color:"var(--text)"},children:t.value})]})]},t.label)})}),m&&e.jsxs("div",{style:{padding:12,background:"rgba(239,68,68,.08)",color:"#ef4444",borderRadius:10,fontSize:12,marginBottom:16,display:"flex",alignItems:"center",gap:8},children:[e.jsx(Ce,{size:14,strokeWidth:2.2})," ",m]}),e.jsx("div",{className:"tabs",style:{marginBottom:14,alignItems:"center"},children:[{key:"all",label:"All",count:k.length+Q.length},{key:"alerts",label:"Alerts",count:Q.length,Icon:O},{key:"drafts",label:"Drafts",count:k.length,Icon:K}].map(t=>e.jsxs("button",{className:`tab-item${S===t.key?" on":""}`,onClick:()=>V(t.key),style:{fontSize:12,padding:"8px 14px",display:"inline-flex",alignItems:"center",gap:6},children:[t.Icon&&e.jsx(t.Icon,{size:12,strokeWidth:2.2}),t.label,t.count>0?` (${t.count})`:""]},t.key))}),E?e.jsx("div",{style:{padding:60,textAlign:"center",color:"var(--muted)",fontSize:13},children:"Loadingâ¦"}):k.length===0&&Q.length===0?e.jsxs("div",{style:{padding:60,textAlign:"center",background:"var(--surface)",border:"1px dashed var(--b1)",borderRadius:14},children:[e.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:12,color:"var(--brand)"},children:e.jsx(U,{size:40,strokeWidth:1.5})}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)",marginBottom:6},children:"Nothing waiting"}),e.jsx("div",{style:{fontSize:12,color:"var(--muted)",maxWidth:420,margin:"0 auto"},children:"Your inbox is clear. When the AI drafts a follow-up, spots a stale lead, or sees a reason to nudge you â it'll show up here."})]}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(S==="all"||S==="alerts")&&Q.map(t=>e.jsx($e,{suggestion:t,busy:M===`sug-${t.id}`,isTeamOwner:c,currentUserId:v,teamId:f,onDismiss:J,onSnooze:be,onAddTask:me,onDraftReengagement:ve,onReassign:_e},t.id)),(S==="all"||S==="drafts")&&k.map(t=>{var j,T,H;const r=Le(t.pending_draft),s=r.channel||je(t),d=_===t.id,n=M===t.id;return e.jsxs("div",{style:{padding:18,borderRadius:14,border:"1px solid var(--b1)",background:"var(--surface)",display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,minWidth:0}
5,children:[e.jsx("div",{style:{width:34,height:34,borderRadius:"50%",background:"rgba(var(--brand-rgb), .12)",color:"var(--brand)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(Ae,{size:16,strokeWidth:2.2})}),e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:((j=t.lead)==null?void 0:j.lead_name)||"Unknown lead"}),e.jsxs("div",{style:{fontSize:11,color:"var(--muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[((T=t.lead)==null?void 0:T.lead_email)||((H=t.lead)==null?void 0:H.lead_phone)||"",t.drip_count>0?` · drip #${t.drip_count+1}`:" · first touch"]})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[e.jsxs("span",{style:{fontSize:10,fontWeight:700,padding:"3px 8px",borderRadius:999,background:s==="either"?"rgba(0,0,0,.06)":"rgba(var(--brand-rgb), .12)",color:s==="either"?"var(--muted)":"var(--brand)",textTransform:"uppercase",letterSpacing:".05em",display:"inline-flex",alignItems:"center",gap:4},children:[s==="email"?e.jsx(K,{size:10,strokeWidth:2.4}):s==="sms"?e.jsx(Re,{size:10,strokeWidth:2.4}):null,s]}),e.jsx("span",{style:{fontSize:10,color:"var(--dim)"},children:ue(t.pending_draft_at)})]})]}),d?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[A&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,color:"var(--muted)",marginBottom:4,textTransform:"uppercase",letterSpacing:".04em"},children:"Subject"}),e.jsx("input",{type:"text",value:W,onChange:G=>B(G.target.value),placeholder:"Subject line",style:{width:"100%",boxSizing:"border-box",padding:"10px 12px",borderRadius:10,border:"1px solid var(--b1)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"inherit"}})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,color:"var(--muted)",marginBottom:4,textTransform:"uppercase",letterSpacing:".04em"},children:A?"Message":"Text"}),e.jsx("textarea",{value:C,onChange:G=>w(G.target.value),rows:A?8:4,style:{width:"100%",boxSizing:"border-box",padding:12,borderRadius:10,border:"1px solid var(--b1)",background:"var(--bg)",color:"var(--text)",fontSize:13,lineHeight:1.55,fontFamily:"inherit",resize:"vertical"}})]})]}):r.isJson?e.jsxs("div",{style:{background:"var(--bg)",borderRadius:10,overflow:"hidden",border:"1px solid var(--b1)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--b1)",background:"rgba(var(--brand-rgb), .04)",display:"flex",flexDirection:"column",gap:4},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,color:"var(--muted)",textTransform:"uppercase",letterSpacing:".04em"},children:"Subject"}),e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)",lineHeight:1.3},children:r.subject||e.jsx("span",{style:{color:"var(--muted)",fontStyle:"italic"},children:"(no subject)"})})]}),e.jsx("div",{style:{padding:14,fontSize:13,lineHeight:1.6,color:"var(--text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:r.body})]}):e.jsx("div",{style:{padding:14,background:"var(--bg)",borderRadius:10,fontSize:13,lineHeight:1.6,color:"var(--text)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:r.body}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:d?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>ye(t),disabled:n||!C.trim(),style:{padding:"8px 16px",fontSize:12,fontWeight:700,border:"none",borderRadius:8,background:"var(--brand)",color:"#fff",cursor:n?"not-allowed":"pointer",opacity:n?.6:1},children:"Save edit"}),e.jsx("button",{onClick:()=>{x(null),B(""),w(""),a(!1),h(null)},disabled:n,style:{padding:"8px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--text)",cursor:"pointer"},children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>pe(t),disabled:n,title:"Send this message now",style:{padding:"8px 16px",fontSize:12,fontWeight:700,border:"none",borderRadius:8,background:"var(--brand)",color:"#fff",cursor:n?"not-allowed":"pointer",opacity:n?.6:1,display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(le,{size:13,strokeWidth:2.4})," Approve & Send"]}),e.jsx("button",{onClick:()=>{x(t.id),B(r.subject||""),w(r.body||""),a(r.isJson),h(r.channel)},disabled:n,style:{padding:"8px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--text)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:"â Edit & Send"}),e.jsxs("button",{onClick:()=>fe(t),disabled:n,title:"Have the AI write a different version",style:{padding:"8px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--text)",cursor:n?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(Te,{size:12,strokeWidth:2.4})," Regenerate"]}),e.jsxs("button",{onClick:()=>he(t),disabled:n,title:"Drop this draft (the conversation stays active)",
5style:{padding:"8px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--b1)",borderRadius:8,background:"var(--bg)",color:"var(--muted)",cursor:n?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(De,{size:12,strokeWidth:2.4})," Discard"]}),e.jsx("button",{onClick:()=>xe(t),disabled:n,title:"Stop AI SDR for this lead entirely",style:{marginLeft:"auto",padding:"8px 12px",fontSize:11,fontWeight:600,border:"1px solid rgba(239,68,68,.3)",borderRadius:8,background:"transparent",color:"#ef4444",cursor:n?"not-allowed":"pointer"},children:"Stop SDR for this lead"})]})})]},t.id)})]})]})}export{Ve 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.