1import{j as e,u as T,r as C}from"./index-DKJ0tKwF.js";import{u as pe}from"./useDesktopToolbarAction-BjAss24h.js";import{u as he}from"./useDesktopStatusUpdate-V-hQXDku.js";import{u as ge}from"./useTabSearchParams-DIYQBoVd.js";import{aR as te,g as fe,q as b,J as N,aE as L,f as E,$ as B,aI as q,aJ as M,aK as R,aQ as $,ba as K,aY as je,dL as z,r as k,aw as ye,dv as be,cw as Y,b1 as H,s as Ne,v as ve,w as we,x as _e,y as U,cC as Ce,h3 as ke,bj as Se,bM as De,bN as Ee,bO as S,bP as D,bm as qe}from"./App-CL-mfmhu.js";import{E as Me,a as Re,b as Te,c as Ae,d as Fe}from"./EmailDragDropBuilder-vCVa0YVl.js";import{D as A,d as J,m as F,G as Le,M as ie,J as j,q as Pe,r as Oe,l as I,o as $e,K as Be}from"./button-DFML8rOM.js";import{a as Ke}from"./useEmailSendingDomains-NbQNazAe.js";import{a as Ie}from"./useEmailSenders-nLhUUeXd.js";import{L as ne,Z as Ve}from"./tracker-DzJH7QDt.js";import{T as re,a as le,b as P,c as v,d as de,e as w}from"./table-LmnZO84H.js";import{O as V,F as Qe,C as We,ao as Z,a0 as X,am as O,al as ee}from"./V2Layout-DEbe2yZA.js";import{d as Ge}from"./differenceInDays-DVnkPVlP.js";import{w as ze,a as Ye,f as He}from"./v3LegalOverrides-BUgTGJPl.js";import{exportToCSV as Ue}from"./export-BcRDJOy3.js";import{S as Je}from"./SegmentsManager-BB2WTHtN.js";import{O as Ze}from"./OnboardingTooltip-BBv7ZwBy.js";import{I as Xe}from"./InternalPageSEO-loZWkmv4.js";import"./mouse-pointer-2-CzsmklB8.js";import"./index-BNGwt955.js";import"./SEOHead-B5IBZJEm.js";import"./types-DU7944Yl.js";import"./useEmailCampaigns-Ce5FuaOK.js";import"./calendar-C4_pM52F.js";import"./startOfMonth-C0iNPykm.js";import"./endOfWeek-CPg4SqbP.js";import"./addMonths-BWpr5jec.js";import"./isSameMonth-Bs-aNtni.js";import"./addWeeks-OY5PkLlx.js";import"./isAfter-DrKDRHf5.js";import"./addYears-Cm967pk8.js";import"./toggle-C2nGyYDk.js";import"./alert-6VEnsWT3.js";import"./useSMSCampaigns-CcLh4QgW.js";import"./chart-CyswYVrv.js";import"./generateCategoricalChart-b5rLhkau.js";import"./value-DqH_WevB.js";import"./AreaChart-BJYXKA2p.js";import"./YAxis-juuueSy8.js";import"./PieChart-fTyslHWb.js";import"./BarChart-CqmLOmE4.js";import"./core.esm-CQopMhiN.js";import"./sortable.esm-BM3toCXR.js";import"./slider-wKlj6rAS.js";import"./mergeTags-DreIBWcr.js";function es({children:s,inline:x=!1}){const{domains:c,isLoading:u}=Ke(),t=te(),{isPlatformWorkspace:i}=Ie(),r=c.filter(p=>p.status==="verified"),o=c.filter(p=>p.status!=="verified");return u?e.jsxs("div",{className:"flex items-center justify-center py-16 text-muted-foreground",children:[e.jsx(ne,{className:"h-5 w-5 animate-spin mr-2"}),"Checking your sending domainâ¦"]}):r.length>0||i?e.jsx(e.Fragment,{children:s}):x?e.jsxs("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-4 flex items-start gap-3",children:[e.jsx(fe,{className:"h-5 w-5 text-amber-500 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"Add a verified sending domain"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"You'll send emails from your own domain â never a shared platform address."})]}),e.jsxs(A,{size:"sm",onClick:()=>t("/settings/domains"),children:["Set up domain",e.jsx(J,{className:"h-3.5 w-3.5 ml-1"})]})]}):e.jsx(b,{className:"overflow-hidden",children:e.jsx(N,{className:"p-0",children:e.jsx("div",{className:"bg-gradient-to-br from-primary/10 via-primary/5 to-transparent p-8 sm:p-12",children:e.jsxs("div",{className:"max-w-xl mx-auto text-center space-y-5",children:[e.jsx("div",{className:"inline-flex h-14 w-14 items-center justify-center rounded-2xl bg-primary/15 text-primary",children:e.jsx(F,{className:"h-7 w-7"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:"Add your sending domain to unlock email"}),e.jsx("p",{className:"text-muted-foreground",children:"For deliverability and security, every workspace sends from its own verified domain. We'll never send your campaigns from a shared platform address â that protects your sender reputation and stops your emails landing in spam."})]}),e.jsxs("div",{className:"grid sm:grid-cols-3 gap-3 pt-2 text-left",children:[e.jsxs("div",{className:"rounded-lg border bg-background/60 p-3",children:[e.jsx(Le,{className:"h-4 w-4 text-primary mb-2"}),e.jsx("p",{className:"text-xs font-medium",children:"Your domain"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Send from [email protected]"})]}),e.jsxs("div",{className:"rounded-lg border bg-background/60 p-3",children:[e.jsx(F,{className:"h-4 w-4 text-primary mb-2"}),e.jsx("p",{className:"text-xs font-medium",children:"SPF + DKIM signed"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Authenticated and trusted by inbox providers"})]}),e.jsxs("div",{className:"rounded-lg border bg-background/60 p-3",children:[e.jsx(ie,{className:"h-4 w-4 text-primary mb-2"}),e.jsx("p",{className:"text-xs font-medium",children:"Inbox, not spam"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Reputation built on your domain only"})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-center gap-3 pt-3",children:[e.jsxs(A,{size:"lg",onClick:()=>t("/settings/domains"),children:["Set up sending domain",e.jsx(J,{className:"h-4 w-4 ml-2"})]}),o.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[o.length," domain",o.length===1?"":"s"," awaiting DNS verification"]})]})]})})})})}function ss(){const{workspace:s}
1=L(),x=V(),c=E({queryKey:["workspace-email-settings",s==null?void 0:s.id],queryFn:async()=>{if(!(s!=null&&s.id))return null;const{data:t,error:i}=await j.from("workspaces").select("settings").eq("id",s.id).single();if(i)throw i;const r=(t==null?void 0:t.settings)||{};return{email_from_name:r.email_from_name||"",email_from_address:r.email_from_address||"",email_domain_verified:r.email_domain_verified||!1}},enabled:!!(s!=null&&s.id)}),u=B({mutationFn:async t=>{if(!(s!=null&&s.id))throw new Error("No workspace");const{data:i}=await j.from("workspaces").select("settings").eq("id",s.id).single(),r={...(i==null?void 0:i.settings)||{},...t},{error:o}=await j.from("workspaces").update({settings:r}).eq("id",s.id);if(o)throw o},onSuccess:()=>{x.invalidateQueries({queryKey:["workspace-email-settings",s==null?void 0:s.id]}),T.success("Email settings saved")},onError:t=>{T.error(t.message||"Failed to save email settings")}});return{settings:c.data,isLoading:c.isLoading,saveSettings:u.mutate,isSaving:u.isPending}}function as(){const{workspace:s}=L(),c=E({queryKey:["email-warmup-stats",s==null?void 0:s.id],queryFn:async()=>{var n;if(!(s!=null&&s.id))return null;const{data:u}=await j.from("workspaces").select("created_at").eq("id",s.id).single(),t=u!=null&&u.created_at?new Date(u.created_at):new Date,i=Ge(new Date,t),r=je(new Date,14).toISOString(),{data:o}=await j.from("email_send_log").select("status, created_at").eq("workspace_id",s.id).gte("created_at",r).order("created_at",{ascending:!0}),p=o||[],l={};p.forEach(m=>{const y=Z(X(new Date(m.created_at)),"yyyy-MM-dd");l[y]||(l[y]={sent:0,bounced:0,complained:0}),m.status==="sent"&&l[y].sent++,m.status==="bounced"&&l[y].bounced++,m.status==="complained"&&l[y].complained++});const h=Object.entries(l).map(([m,y])=>({date:m,...y})).sort((m,y)=>m.date.localeCompare(y.date)),d=Math.min(50+i*32,1e3),f=Z(X(new Date),"yyyy-MM-dd"),g=((n=l[f])==null?void 0:n.sent)||0,a=Math.min(Math.round(i/30*100),100);return{accountAgeDays:i,warmupTarget:d,todayVolume:g,warmupProgress:a,dailyStats:h}},enabled:!!(s!=null&&s.id)}).data;return c?e.jsxs(b,{children:[e.jsxs(q,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(Qe,{className:"h-5 w-5 text-orange-500"}),"Domain Warmup Tracker"]}),e.jsx(R,{children:"Gradually increase sending volume to build a strong sender reputation"})]}),e.jsxs(N,{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(We,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Account Age: ",c.accountAgeDays," days"]}),e.jsxs("span",{className:"text-muted-foreground",children:[c.warmupProgress,"% warmed up"]})]}),e.jsx($,{value:c.warmupProgress,className:"h-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c.warmupProgress>=100?"â
Domain is fully warmed up â send at full volume":`Recommended max today: ${c.warmupTarget} emails/day`})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pe,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-sm font-medium",children:"Today's Volume"})]}),e.jsxs("span",{className:"text-lg font-bold",children:[c.todayVolume," ",e.jsxs("span",{className:"text-sm text-muted-foreground font-normal",children:["/ ",c.warmupTarget]})]})]}),c.dailyStats.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Last 14 Days"}),e.jsx("div",{className:"grid grid-cols-7 gap-1",children:c.dailyStats.slice(-14).map(u=>{const t=Math.min(u.sent/Math.max(c.warmupTarget,1),1);return e.jsx("div",{className:"aspect-square rounded-sm border",style:{backgroundColor:`hsl(var(--primary) / ${.1+t*.8})`},title:`${K(u.date,"MMM d")}: ${u.sent} sent, ${u.bounced} bounced`},u.date)})})]})]})]}):null}function ts(){const{workspace:s}=L(),{settings:x}=ss(),c=E({queryKey:["suppressed-emails",s==null?void 0:s.id],queryFn:async()=>
1{if(!(s!=null&&s.id))return[];const{data:d,error:f}=await j.from("suppressed_emails").select("*").eq("workspace_id",s.id).order("created_at",{ascending:!1}).limit(100);if(f)throw f;return d||[]},enabled:!!(s!=null&&s.id)}),t=E({queryKey:["deliverability-stats",s==null?void 0:s.id],queryFn:async()=>{if(!(s!=null&&s.id))return null;const{data:d,error:f}=await j.from("email_send_log").select("status, created_at").eq("workspace_id",s.id).order("created_at",{ascending:!1}).limit(1e3);if(f)return null;const g=d||[],a=g.length,n=g.filter(_=>_.status==="sent").length,m=g.filter(_=>_.status==="bounced").length,y=g.filter(_=>_.status==="complained").length,Q=g.filter(_=>_.status==="failed"||_.status==="dlq").length,W=a>0?m/a*100:0,G=a>0?y/a*100:0,ce=a>0?n/a*100:0,oe=Math.min(W*5,40),me=Math.min(G*20,40),ue=Math.min(Q/Math.max(a,1)*100*2,20),xe=Math.max(0,Math.round(100-oe-me-ue));return{total:a,sent:n,bounced:m,complained:y,failed:Q,bounceRate:W.toFixed(1),complaintRate:G.toFixed(1),deliveryRate:ce.toFixed(1),reputationScore:xe}},enabled:!!(s!=null&&s.id)}).data,i=c.data||[],r=(x==null?void 0:x.email_domain_verified)||!1,o=(x==null?void 0:x.email_from_address)||"",p=o?o.split("@")[1]:"",l=d=>d>=80?"text-success":d>=50?"text-warning":"text-destructive",h=d=>d>=80?"Excellent":d>=60?"Good":d>=40?"Fair":"Poor";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(b,{children:e.jsxs(N,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${r?"bg-success/10":"bg-warning/10"}`,children:r?e.jsx(F,{className:"h-5 w-5 text-success"}):e.jsx(z,{className:"h-5 w-5 text-warning"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Domain Status"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p||"Not configured"})]})]}),e.jsx(k,{variant:r?"default":"secondary",children:r?"Verified":"Pending Verification"})]})}),e.jsx(b,{children:e.jsxs(N,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ye,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Sender Reputation"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Overall health"})]})]}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:`text-2xl font-bold ${l((t==null?void 0:t.reputationScore)||0)}`,children:(t==null?void 0:t.reputationScore)??"â"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["/ 100 · ",h((t==null?void 0:t.reputationScore)||0)]})]})]})}),e.jsx(b,{children:e.jsxs(N,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-destructive/10",children:e.jsx(ze,{className:"h-5 w-5 text-destructive"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Bounce Rate"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(t==null?void 0:t.bounced)||0," bounced"]})]})]}),e.jsxs("p",{className:"text-2xl font-bold",children:[(t==null?void 0:t.bounceRate)??"0","%"]}),e.jsx($,{value:parseFloat((t==null?void 0:t.bounceRate)||"0"),className:"h-1.5 mt-2"})]})}),e.jsx(b,{children:e.jsxs(N,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-warning/10",children:e.jsx(Oe,{className:"h-5 w-5 text-warning"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Complaint Rate"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(t==null?void 0:t.complained)||0," complaints"]})]})]}),e.jsxs("p",{className:"text-2xl font-bold",children:[(t==null?void 0:t.complaintRate)??"0","%"]}),e.jsx($,{value:parseFloat((t==null?void 0:t.complaintRate)||"0"),className:"h-1.5 mt-2"})]})})]}),e.jsx(as,{}),e.jsxs(b,{children:[e.jsxs(q,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(F,{className:"h-5 w-5"}),"Email Authentication"]}),e.jsx(R,{children:"DNS records that prove you own your sending domain"})]}),e.jsx(N,{children:e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:[{name:"SPF",description:"Sender Policy Framework â authorises servers to send on your behalf"},{name:"DKIM",description:"DomainKeys â cryptographic signature proving email integrity"},{name:"DMARC",description:"Domain-based Message Authentication â policy enforcement"}].map(d=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border bg-card",children:[r?e.jsx(F,{className:"h-5 w-5 text-success shrink-0 mt-0.5"}):e.jsx(z,{className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:d.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d.description})]})]},d.name))})})]}),e.jsxs(b,{children:[e.jsx(q,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(be,{className:"h-5 w-5"}),"Suppression List"]}),e.jsxs(R,{children:["Emails that are blocked from receiving future campaigns (",i.length," suppressed)"]})]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>c.refetch(),disabled:c.isFetching,children:[e.jsx(I,{className:`h-4 w-4 mr-2 ${c.isFetching?"animate-spin":""}`}),"Refresh"]})]})}),e.jsx(N,{children:i.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ie,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No suppressed emails â your list is clean!"})]}):e.jsx("div",{className:"rounded-md border max-h-[400px] overflow-auto",children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsxs(P,{children:[e.jsx(v,{children:"Email"}),e.jsx(v,{children:"Reason"}),e.jsx(v,{children:"Date"})]})}),e.jsx(de,{children:i.map(d=>e.jsxs(P,{children:[e.jsx(w,{className:"font-mono text-sm",children:d.email}),e.jsx(w,{children:e.jsx(k,{variant:"secondary",className:"capitalize",children:d.reason||"unknown"})}),e.jsx(w,{className:"text-muted-foreground text-sm",children:d.created_at?K(d.created_at,"MMM d, yyyy"):"â"})]},d.id))})]})})})]})]})}const se={enabled:!1,classify_replies:!0,extract_ooo_contacts:!0,auto_stop_sequences:!0,auto_suppress_unsubscribe:!0,auto_suppress_left_company:!1,update_contact_email_on_change:!1,create_task_on_positive:!0,min_confidence:.6},is=[{key:"classify_replies",label:"Classify inbound replies",description:"Every reply is tagged as out-of-office, interested, unsubscribe, bounce and more."},{key:"extract_ooo_contacts",label:"Extract alternate contacts",description:"Pull 'in my absence contactâ¦' names, emails and numbers into the CRM."},{key:"auto_stop_sequences",label:"Auto-stop sequences",description:"Cancel running automations and queued campaign sends for that contact."},{key:"auto_suppress_unsubscribe",label:"Suppress on unsubscribe requests",description:"Add the address to this workspace's suppression list automatically."},{key:"auto_suppress_left_company",label:"Suppress when the person has left",description:"Also suppress addresses that reply 'no longer works here'."},{key:"update_contact_email_on_change",label:"Apply change-of-email automatically",description:"Off by default â otherwise the new address is only flagged on the contact."},{key:"create_task_on_positive",label:"Create a task on positive replies",description:"A follow-up task is added for the contact owner when interest is detected."}],ns={interested:"bg-emerald-500/15 text-emerald-500 border-emerald-500/30",not_interested:"bg-amber-500/15 text-amber-500 border-amber-500/30",unsubscribe:"bg-red-500/15 text-red-500 border-red-500/30",bounce:"bg-red-500/15 text-red-500 border-red-500/30",out_of_office:"bg-sky-500/15 text-sky-500 border-sky-500/30",left_company:"bg-purple-500/15 text-purple-500 border-purple-500/30",email_changed:"bg-blue-500/15 text-blue-500 border-blue-500/30"},ae=s=>s.replace(/_/g," ");function rs(){const{workspace:s}=L(),x=V(),[c,u]=C.useState("all"),[t,i]=C.useState(""),r=E({queryKey:["reply-settings",s==null?void 0:s.id],queryFn:async()=>
1{if(!(s!=null&&s.id))return null;const{data:a,error:n}=await j.from("email_reply_settings").select("*").eq("workspace_id",s.id).maybeSingle();if(n)throw n;return a??{workspace_id:s.id,...se}},enabled:!!(s!=null&&s.id)}),o=B({mutationFn:async a=>{if(!(s!=null&&s.id))throw new Error("No workspace");const n={...se,...r.data||{},...a,workspace_id:s.id},{error:m}=await j.from("email_reply_settings").upsert(n,{onConflict:"workspace_id"});if(m)throw m;return n},onSuccess:()=>{x.invalidateQueries({queryKey:["reply-settings",s==null?void 0:s.id]}),T.success("Reply intelligence settings saved")},onError:a=>T.error(a.message||"Could not save settings")}),p=E({queryKey:["reply-classifications",s==null?void 0:s.id],queryFn:async()=>{if(!(s!=null&&s.id))return[];const{data:a,error:n}=await j.from("email_reply_classifications").select("*").eq("workspace_id",s.id).order("created_at",{ascending:!1}).limit(300);if(n)throw n;return a||[]},enabled:!!(s!=null&&s.id)}),l=r.data,h=p.data||[],d=C.useMemo(()=>{const a=t.trim().toLowerCase();return h.filter(n=>(c==="all"||n.category===c)&&(!a||n.from_email.toLowerCase().includes(a)||(n.subject||"").toLowerCase().includes(a)))},[h,c,t]),f=C.useMemo(()=>{const a={};return h.forEach(n=>a[n.category]=(a[n.category]||0)+1),a},[h]),g=()=>{Ue(d.map(a=>{var n,m;return{...a,actions_applied:(a.actions_applied||[]).join(" | "),alternate_email:((n=a.extracted)==null?void 0:n.alternate_email)??"",new_email:((m=a.extracted)==null?void 0:m.new_email)??""}}),[{key:"created_at",label:"Date"},{key:"from_email",label:"From"},{key:"subject",label:"Subject"},{key:"category",label:"Category"},{key:"confidence",label:"Confidence"},{key:"summary",label:"Summary"},{key:"alternate_email",label:"Alternate Email"},{key:"new_email",label:"New Email"},{key:"actions_applied",label:"Actions"}],"reply_intelligence")};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(b,{children:[e.jsx(q,{children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(Ye,{className:"h-5 w-5"})," Bounces & Replies Intelligence"]}),e.jsx(R,{children:"Reads inbound replies, pulls out-of-office and change-of-email details into the CRM, and stops sequences automatically. Every behaviour below is controlled by this workspace."})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsx(O,{htmlFor:"ri-enabled",className:"text-sm",children:l!=null&&l.enabled?"On":"Off"}),e.jsx(Y,{id:"ri-enabled",checked:!!(l!=null&&l.enabled),disabled:r.isLoading||o.isPending,onCheckedChange:a=>o.mutate({enabled:a})})]})]})}),e.jsx(N,{className:"space-y-4",children:r.isLoading?e.jsx(H,{className:"h-40 w-full"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:is.map(a=>e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-lg border border-border/60 p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(O,{htmlFor:`ri-${a.key}`,className:"text-sm font-medium",children:a.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.description})]}),e.jsx(Y,{id:`ri-${a.key}`,checked:!!(l!=null&&l[a.key]),disabled:!(l!=null&&l.enabled)||o.isPending,onCheckedChange:n=>o.mutate({[a.key]:n})})]},a.key))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-lg border border-border/60 p-3",children:[e.jsx(O,{htmlFor:"ri-confidence",className:"text-sm",children:"Minimum confidence before acting"}),e.jsx(ee,{id:"ri-confidence",type:"number",min:0,max:1,step:.05,className:"w-28",disabled:!(l!=null&&l.enabled),value:(l==null?void 0:l.min_confidence)??.6,onChange:a=>x.setQueryData(["reply-settings",s==null?void 0:s.id],{...l,min_confidence:Number(a.target.value)}),onBlur:a=>o.mutate({min_confidence:Number(a.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Lower-confidence replies are still logged below, but no action is taken."})]})]})})]}),e.jsxs(b,{children:[e.jsx(q,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(M,{children:"Classified replies"}),e.jsxs(R,{children:[h.length," analysed · ",f.out_of_office||0," out-of-office · ",f.bounce||0," bounces ·"," ",f.unsubscribe||0," unsubscribes"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ee,{placeholder:"Search email or subject",value:t,onChange:a=>i(a.target.value),className:"w-56"}),e.jsxs(Ne,{value:c,onValueChange:u,children:[e.jsx(ve,{className:"w-44",children:e.jsx(we,{placeholder:"All categories"})}),e.jsxs(_e,{children:[e.jsx(U,{value:"all",children:"All categories"}
1),Object.keys(f).map(a=>e.jsxs(U,{value:a,children:[ae(a)," (",f[a],")"]},a))]})]}),e.jsx(A,{variant:"outline",size:"sm",onClick:()=>p.refetch(),children:e.jsx(I,{className:"h-4 w-4"})}),e.jsxs(A,{variant:"outline",size:"sm",onClick:g,disabled:d.length===0,children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"})," Export CSV"]})]})]})}),e.jsx(N,{children:p.isLoading?e.jsx(H,{className:"h-48 w-full"}):d.length===0?e.jsx("p",{className:"py-10 text-center text-sm text-muted-foreground",children:"No classified replies yet. Turn the module on and inbound replies will appear here automatically."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(re,{children:[e.jsx(le,{children:e.jsxs(P,{children:[e.jsx(v,{children:"Date"}),e.jsx(v,{children:"From"}),e.jsx(v,{children:"Category"}),e.jsx(v,{children:"Summary"}),e.jsx(v,{children:"Extracted"}),e.jsx(v,{children:"Actions taken"})]})}),e.jsx(de,{children:d.map(a=>{const n=a.extracted||{};return e.jsxs(P,{children:[e.jsx(w,{className:"whitespace-nowrap text-xs text-muted-foreground",children:K(a.created_at,"dd MMM HH:mm")}),e.jsxs(w,{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:a.from_email}),e.jsx("div",{className:"text-xs text-muted-foreground line-clamp-1",children:a.subject})]}),e.jsxs(w,{children:[e.jsx(k,{variant:"outline",className:ns[a.category]||"",children:ae(a.category)}),e.jsxs("div",{className:"mt-1 text-[11px] text-muted-foreground",children:[Math.round((a.confidence||0)*100),"%"]})]}),e.jsx(w,{className:"max-w-xs text-xs text-muted-foreground",children:a.summary}),e.jsxs(w,{className:"text-xs",children:[n.alternate_email&&e.jsxs("div",{children:["Alt: ",n.alternate_email]}),n.alternate_phone&&e.jsxs("div",{children:["Tel: ",n.alternate_phone]}),n.new_email&&e.jsxs("div",{children:["New: ",n.new_email]}),n.return_date&&e.jsxs("div",{children:["Back: ",n.return_date]}),!n.alternate_email&&!n.new_email&&!n.return_date&&e.jsx("span",{className:"text-muted-foreground",children:"â"})]}),e.jsx(w,{className:"text-xs",children:(a.actions_applied||[]).length===0?e.jsx("span",{className:"text-muted-foreground",children:"None"}):e.jsx("div",{className:"flex flex-wrap gap-1",children:(a.actions_applied||[]).map(m=>e.jsx(k,{variant:"secondary",className:"text-[10px]",children:m.replace(/_/g," ")},m))})})]},a.id)})})]})})})]})]})}const ls=[{kind:"welcome",title:"Welcome Series",description:"Greet brand-new contacts and convert them in their first 7 days.",icon:$e,cadence:"Day 0 · Day 2 · Day 6",emails:[{delayDays:0,subject:"Welcome â here's the quickest win first",preview:"A 60-second tour of what to do today."},{delayDays:2,subject:"The one thing most people miss",preview:"Set this up and the rest gets easier."},{delayDays:6,subject:"Ready when you are",preview:"Two ways to go from idea to outcome."}]},{kind:"abandoned_form",title:"Abandoned Form Follow-up",description:"Re-engage contacts who started a lead form but did not finish.",icon:He,cadence:"+1 hour · +1 day",emails:[{delayDays:0,subject:"Quick â pick up where you left off",preview:"Your draft is saved. One click finishes it."},{delayDays:1,subject:"Still want us to take a look?",preview:"We'll keep this slot open another 24 hours."}]},{kind:"reengagement",title:"Re-engagement",description:"Win back contacts who haven't opened in 90+ days.",icon:I,cadence:"Single send",emails:[{delayDays:0,subject:"We miss you â and we shipped a lot",preview:"Three things worth a 30-second look."}]}];function ds(){const{workspace:s}=L(),x=V(),c=E({queryKey:["lifecycle-drips",s==null?void 0:s.id],queryFn:async()=>{if(!(s!=null&&s.id))return[];const{data:i,error:r}=await j.from("campaigns").select("id, name, status, lifecycle_kind, parent_campaign_id, settings, stats").eq("workspace_id",s.id).eq("type","email").not("lifecycle_kind","is",null);if(r)throw r;return i??[]},enabled:!!(s!=null&&s.id)}),u=C.useMemo(()=>{const i={};return(c.data??[]).forEach(r=>{r.lifecycle_kind&&!r.parent_campaign_id&&(i[r.lifecycle_kind]=r.status!=="paused"&&r.status!=="archived")}),i},[c.data]),t=B({mutationFn:async i=>{if(!(s!=null&&s.id))throw new Error("No workspace");const{data:r,error:o}=await j.from("campaigns").insert({workspace_id:s.id,type:"email",name:`[Drip] ${i.title}`,subject:i.title,content:`Lifecycle drip: ${i.title}`,status:"draft",lifecycle_kind:i.kind,settings:{cadence:i.cadence,steps:i.emails.length}}).select().single();if(o)throw o;const p=i.emails.map((h,d)=>({workspace_id:s.id,type:"email",name:`[Drip] ${i.title} · Step ${d+1}`,subject:h.subject,content:h.preview,status:"draft",lifecycle_kind:i.kind,parent_campaign_id:r.id,settings:{delay_days:h.delayDays,step_index:d}})),{error:l}=await j.from("campaigns").insert(p);if(l)throw l},onSuccess:()=>{T.success("Drip sequence enabled"),x.invalidateQueries({queryKey:["lifecycle-drips"]})},onError:i=>T.error(i.message)});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{children:e.jsxs(q,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(Ve,{className:"h-4 w-4"}),"Lifecycle Drips"]}),e.jsx(R,{children:"Pre-built automated email sequences. Enable one to spin up draft campaigns you can edit and activate."})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:ls.map(i=>{var l;const r=i.icon,o=!!u[i.kind],p=t.isPending&&((l=t.variables)==null?void 0:l.kind)===i.kind;return e.jsxs(b,{className:"flex flex-col",children:[e.jsxs(q,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10 text-primary",children:e.jsx(r,{className:"h-4 w-4"})}),e.jsx(M,{className:"text-base",children:i.title})]}),o&&e.jsx(k,{variant:"secondary",children:"Enabled"})]}),e.jsx(R,{children:i.description})]}),e.jsxs(N,{className:"flex-1 flex flex-col gap-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:i.cadence}),e.jsx("ul",{className:"space-y-2 text-sm flex-1",children:i.emails.map((h,d)=>e.jsxs("li",{className:"border rounded-md p-2",children:[e.jsx("div",{className:"font-medium truncate",children:h.subject}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:["+",h.delayDays,"d · ",h.preview]})]},d))}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:o?"Drafts created â edit & activate":"Not yet enabled"}),e.jsx(A,{size:"sm",variant:o?"outline":"default",disabled:o||p,onClick:()=>t.mutate(i),children:p?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-3 w-3 mr-1 animate-spin"})," Creatingâ¦"]}):o?"Already enabled":"Enable drip"})]})]})]},i.kind)})})]})}function ea(){const s=Be(),x=te(),c=ke(),[u,t]=C.useState("list"),[i,r]=C.useState(null),[o,p]=ge("campaigns");pe("email",{"+ New Campaign":()=>l(),Templates:()=>p("templates")}
1),he("email","Email Campaigns"),C.useEffect(()=>{const g=c||`${s.pathname}${s.search}`,a=g.indexOf("?"),n=a>=0?g.slice(a):"",m=new URLSearchParams(n);!m.get("to")&&!m.get("contact")&&!m.get("contactId")||(m.set("channel","email"),m.set("compose","email"),x(`/inbox?${m.toString()}`))},[c,s.pathname,s.search,x]);const l=()=>{r(null),t("editor")},h=g=>{r(g),t("editor")},d=g=>{r(g),t("analytics")},f=()=>{t("list"),r(null)};return e.jsxs(Se,{children:[e.jsx(Xe,{title:"Email Campaigns",description:"Create and manage email marketing campaigns"}),e.jsx("main",{className:"flex-1 p-6 overflow-auto",children:u==="editor"?e.jsx(Me,{campaign:i,onBack:f}):u==="analytics"&&i?e.jsx(Re,{campaign:i,onBack:f}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Email Campaigns"}),e.jsx("p",{className:"text-muted-foreground",children:"Create and manage email marketing campaigns"})]}),e.jsx(es,{inline:!0}),e.jsxs(De,{value:o,onValueChange:p,children:[e.jsxs(Ee,{children:[e.jsx(S,{value:"campaigns",children:"Campaigns"}),e.jsx(Ze,{id:"email-visual-builder",title:"Visual Email Builder",description:"Create stunning emails with our drag-and-drop builder. No coding required - just drag blocks and customize!",side:"bottom",children:e.jsxs(S,{value:"visual-builder",className:"relative",children:["Visual Builder",e.jsx(k,{variant:"secondary",className:"ml-2 text-xs",children:"New"})]})}),e.jsx(S,{value:"templates",children:"Templates"}),e.jsxs(S,{value:"lifecycle",className:"relative",children:["Lifecycle",e.jsx(k,{variant:"secondary",className:"ml-2 text-xs",children:"New"})]}),e.jsx(S,{value:"deliverability",children:"Deliverability"}),e.jsxs(S,{value:"replies",className:"relative",children:["Replies AI",e.jsx(k,{variant:"secondary",className:"ml-2 text-xs",children:"New"})]}),e.jsx(S,{value:"segments",children:"Segments"})]}),e.jsx(D,{value:"campaigns",className:"mt-6",children:e.jsx(Te,{onCreateCampaign:l,onEditCampaign:h,onViewAnalytics:d})}),e.jsx(D,{value:"visual-builder",className:"mt-6",children:e.jsx(Ae,{})}),e.jsx(D,{value:"templates",className:"mt-6",children:e.jsx(Fe,{})}),e.jsx(D,{value:"lifecycle",className:"mt-6",children:e.jsx(ds,{})}),e.jsx(D,{value:"deliverability",className:"mt-6",children:e.jsx(ts,{})}),e.jsx(D,{value:"replies",className:"mt-6",children:e.jsx(rs,{})}),e.jsx(D,{value:"segments",className:"mt-6",children:e.jsx(Je,{})})]})]})}),e.jsx(qe,{})]})}export{ea 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.