1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ScheduleFields-C1Sz5eUX.js","assets/index-BQSuW3M2.js","assets/index-7FVZiXie.css","assets/NewsletterShell-DO5QhaT5.js","assets/skeleton-BarAKMLu.js","assets/calendar-clock-C4w1TAtF.js"])))=>i.map(i=>d[i]); 2import{c as Ee,j as e,aX as z,a9 as U,aK as Pt,aY as we,aZ as G,B as F,r as l,be as qe,bB as Rt,br as Ke,_ as Lt,u as ae,s as oe,P as ie,bW as We,bm as Dt,bX as _t,bj as Ot,bY as $t,bZ as Ve,bq as Ye,b_ as X,b$ as Je,c0 as Ze,c1 as Ft,c2 as Mt,c3 as It,c4 as Ht,c5 as Bt,c6 as zt,c7 as Ut,c8 as Gt,c9 as qt,ca as Kt,C as Wt,cb as Vt,cc as Yt,cd as Jt,ce as pe,cf as $e,cg as Zt,ch as Qt,aE as Qe,aF as Xe,aG as Xt,ci as es,aI as et,L as O,ac as ke,ad as Se,ae as Ce,af as Te,ag as Y,I as re,bx as ts,by as ss,bz as xe,bA as ge,a2 as Fe,cj as ns,X as rs,bf as as,a0 as os,ck as Me,cl as is,aJ as cs,aN as ds,bv as Ie,bw as ls,o as us,p as hs,q as ms,t as ps,v as xs,w as gs,x as fs,y as bs}from"./index-BQSuW3M2.js";import{S as q}from"./skeleton-BarAKMLu.js";import{u as vs,b as js,w as ys,a as tt,c as Ns,S as ws,d as ks,e as Ss,f as Cs,g as Ts,h as Es,r as fe,N as As}from"./NewsletterShell-DO5QhaT5.js";import{C as Ps}from"./calendar-clock-C4w1TAtF.js";const Rs=Ee("Activity",[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]]);const Ls=Ee("CircleSlash",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"9",x2:"15",y1:"15",y2:"9",key:"1dfufj"}]]);const Ds=Ee("Shuffle",[["path",{d:"m18 14 4 4-4 4",key:"10pe0f"}],["path",{d:"m18 2 4 4-4 4",key:"pucp1d"}],["path",{d:"M2 18h1.973a4 4 0 0 0 3.3-1.7l5.454-8.6a4 4 0 0 1 3.3-1.7H22",key:"1ailkh"}],["path",{d:"M2 6h1.972a4 4 0 0 1 3.6 2.2",key:"km57vx"}],["path",{d:"M22 18h-6.041a4 4 0 0 1-3.3-1.8l-.359-.45",key:"os18l9"}]]);function Ae(t){const s=(t.gateway?.withheld??0)+(t.gateway?.redirected??0),n=`${t.stats.successful} of ${t.stats.total} delivered to the provider.`;return s>0&&t.stats.successful===0?{variant:"destructive",title:"Campaign not sent",description:`Nobody received this. ${n} ${s} held by the email gateway.`}:{title:"Campaign sent",description:s>0?`${n} ${s} held by the email gateway.`:n}}function st({result:t}){const s=Ae(t);return e.jsxs(z,{variant:s.variant,children:[s.variant==="destructive"?e.jsx(U,{className:"h-4 w-4"}):e.jsx(Pt,{className:"h-4 w-4"}),e.jsx(we,{children:s.variant==="destructive"?s.title:t.message??"Campaign sent"}),e.jsxs(G,{className:"space-y-2",children:[s.variant==="destructive"&&e.jsx("p",{children:"Nobody received this."}),e.jsxs("p",{children:[t.stats.successful," delivered to the provider, ",t.stats.failed," ","failed, ",t.stats.total," attempted."]}),t.skipped&&t.skipped.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Not sent to:"}),e.jsx("ul",{className:"list-inside list-disc",children:t.skipped.map(n=>e.jsxs("li",{children:[n.email," â ",n.reason.replace(/_/g," ")]},n.email))})]}),t.not_delivered&&t.not_delivered.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Refused by the provider â the only addresses to retry:"}),e.jsx("ul",{className:"list-inside list-disc",children:t.not_delivered.map(n=>e.jsx("li",{children:n},n))})]}),t.in_doubt&&t.in_doubt.length>0&&e.jsxs("p",{children:[t.in_doubt.length," held by another run of this campaign â do not resend them."]}),t.gateway&&t.gateway.withheld+t.gateway.redirected>0&&e.jsxs("p",{children:["The email gateway held ",t.gateway.withheld+t.gateway.redirected," ","of these",t.gateway.redirected>0?` (${t.gateway.withheld} withheld, ${t.gateway.redirected} sent to a redirect inbox)`:"",". Resending will not change that â the gateway's own rules decide it."]}),t.reasons&&t.reasons.length>0&&e.jsx("ul",{className:"list-inside list-disc",children:t.reasons.map(n=>e.jsx("li",{children:n},n))})]})]})}function be(t){const s=new Date(`${t}T12:00:00Z`);return Number.isNaN(s.getTime())?t:s.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short",timeZone:"UTC"}).toUpperCase()}
2function _s(t){const s=t.estimatedRecipients.toLocaleString("en-GB"),n=t.spansDays;if(!t.uncapped&&t.ceiling===0)return`The daily ceiling for this stream is set to zero, so nothing goes out on any day this can name. About ${s} recipients are waiting. Raise MAIL_DAILY_CEILING_BULK in Deliverability first.`;if(n<=1)return t.uncapped?`About ${s} recipients, with no daily ceiling on this stream, so everybody reads it on the same day.`:t.startsToday?`About ${s} recipients fits inside today's remaining ${t.remainingToday.toLocaleString("en-GB")}, so everybody reads it on the same day.`:`About ${s} recipients fits inside the ${t.ceiling.toLocaleString("en-GB")}-a-day ceiling, so everybody reads it on the same day.`;const r=n-1;return`About ${s} recipients against a ${t.ceiling.toLocaleString("en-GB")}-a-day ceiling is ${n} days, so the last person reads this ${r===1?"a day":`${r} days`} after the first. Raise the ceiling in Deliverability, cut the audience, or accept the spread.`}function Os({forecast:t,loading:s,error:n,onRetry:r,stale:a,awaitingAudience:o}){if(o===!0)return e.jsx("p",{className:"animate-in fade-in duration-200 text-xs text-muted-foreground",children:"Choose who this goes to and the spread appears here â how many days the send takes against the daily ceiling, and what arrives on each of them."});if(s)return e.jsxs("div",{className:"flex flex-col gap-2","aria-busy":"true",children:[e.jsx("div",{className:"grid grid-cols-4 gap-2",children:[0,1,2,3].map(m=>e.jsx(q,{className:"h-14"},m))}),e.jsx(q,{className:"h-8"})]});if(n!==void 0||t===void 0)return e.jsxs("div",{className:"animate-in fade-in duration-200 flex flex-col gap-2 border border-dashed p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["The forecast could not be read, so this step cannot say how many days the send will take. ","Scheduling still works â the campaign goes in the queue either way, and its page shows the real spread once the send begins."]}),n!==void 0&&e.jsx("p",{className:"text-xs text-destructive",children:n}),r!==void 0&&e.jsx(F,{variant:"outline",size:"sm",className:"self-start",onClick:r,children:"Try again"})]});const d=t.days.slice(0,5),c=t.days.length-d.length;return e.jsxs("div",{className:`animate-in fade-in duration-200 flex flex-col gap-3 transition-opacity duration-150 ${a===!0?"opacity-50":""}`,"aria-busy":a===!0?"true":void 0,children:[a===!0&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Working out the new spread â these numbers are for what you had a moment ago."}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-4",children:[d.map(m=>e.jsxs("div",{className:"flex flex-col gap-0.5 border p-2.5",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:be(m.date)}),e.jsx("span",{className:"text-lg font-semibold tabular-nums",children:m.count.toLocaleString("en-GB")})]},m.date)),e.jsxs("div",{className:"flex flex-col gap-0.5 border bg-muted/40 p-2.5",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:c>0?`+${c} MORE · FINISHES`:"FINISHES"}),e.jsx("span",{className:"text-sm font-semibold",children:be(t.lastArrives.slice(0,10))}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:t.lastArrives.slice(11)})]})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"font-medium text-foreground",children:[t.estimatedRecipients.toLocaleString("en-GB")," recipients"]})," ","â an estimate. The audience is resolved when the send runs, so anybody who unsubscribes before then is not in it."]}),e.jsx("p",{className:"text-xs leading-relaxed",children:_s(t)}),t.startsToday&&!t.uncapped&&t.ceiling>0&&t.competingToday>0&&t.days[0]!==void 0&&t.days[0].count>=t.remainingToday&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["The first day is short because ",t.competingToday.toLocaleString("en-GB")," ","of today's ",t.ceiling.toLocaleString("en-GB")," have already gone on other sends. Nothing is reserved â another campaign scheduled for the same morning takes from the same budget, and this spread moves."]}),t.heldUntil!==void 0&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Quiet hours are on, so nothing leaves before 08:00 â this starts"," ",e.jsxs("span",{className:"font-medium text-foreground",children:[be(t.heldUntil.slice(0,10))," at ",t.heldUntil.slice(11)]})," ","rather than at the time you picked. Nothing is dropped."]})]})}const ve=[{id:"now",title:"Send now",description:"Starts the moment you confirm. Cannot be recalled.",Icon:qe},{id:"at",title:"At a time",description:"A date and a timezone. Cancellable until it starts.",Icon:Rt}];function $s({value:t,onChange:s}){const n=l.useRef([]);function r(a,o){const d=ve.length-1;let c;switch(a.key){case"ArrowRight":case"ArrowDown":c=o===d?0:o+1;break;case"ArrowLeft":case"ArrowUp":c=o===0?d:o-1;break;case"Home":c=0;break;case"End":c=d;break;default:return}
2a.preventDefault(),n.current[c]?.focus(),s(ve[c].id)}return e.jsx("div",{role:"radiogroup","aria-label":"When it goes out",className:"grid gap-2 sm:grid-cols-2",children:ve.map(({id:a,title:o,description:d,Icon:c},m)=>{const i=t===a;return e.jsxs("button",{ref:h=>{n.current[m]=h},type:"button",role:"radio","aria-checked":i,tabIndex:i?0:-1,onKeyDown:h=>r(h,m),onClick:()=>s(a),className:Ke("flex flex-col items-start gap-1.5 border p-3 text-left","transition-colors duration-150",i?"border-foreground bg-muted/50":"hover:bg-accent"),children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-xs font-semibold",children:[e.jsx(c,{className:"h-3.5 w-3.5","aria-hidden":"true"}),o]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-muted-foreground",children:d})]},a)})})}const Fs=l.lazy(()=>Lt(()=>import("./ScheduleFields-C1Sz5eUX.js"),__vite__mapDeps([0,1,2,3,4,5])).then(t=>({default:t.ScheduleFields}))),Ms=400;function Is(t,s){const[n,r]=l.useState(t);return l.useEffect(()=>{if(s<=0){r(t);return}const a=setTimeout(()=>r(t),s);return()=>clearTimeout(a)},[t,s]),n}function Hs({mode:t,onModeChange:s,schedule:n,onScheduleChange:r,segment:a,recipients:o,debounceMs:d=Ms}){const c=JSON.stringify({at:n.at,tz:n.timezone,segment:a??null,recipients:[...o].sort(),quiet:n.quietHours===!0}),m=Is(c,d),i=JSON.parse(m),h=i.segment!==null||i.recipients.length>0,b=vs(i.segment??void 0,i.recipients,t==="at"&&h?{at:i.at,timezone:i.tz,quietHours:i.quiet}:void 0);return e.jsxs("section",{className:"flex flex-col gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"When it goes out"}),e.jsx($s,{value:t,onChange:s}),t==="at"&&e.jsxs("div",{className:"animate-in fade-in slide-in-from-top-1 duration-200 flex flex-col gap-3",children:[e.jsx(l.Suspense,{fallback:e.jsx(q,{className:"h-[168px]"}),children:e.jsx(Fs,{value:n,onChange:r})}),e.jsxs("div",{className:"flex flex-col gap-2 border p-4",children:[e.jsx("span",{className:"text-xs font-semibold",children:"What the daily budget does to this send"}),e.jsx(Os,{forecast:b.data,awaitingAudience:!h,loading:b.isFetching&&b.data===void 0,stale:c!==m||b.isFetching&&b.data!==void 0,error:b.isError?b.error instanceof Error?b.error.message:String(b.error):void 0,onRetry:()=>void b.refetch()})]})]}),t==="now"&&e.jsx("p",{className:"animate-in fade-in duration-200 text-[11px] text-muted-foreground",children:"The send starts when you confirm and draws on today's remaining budget. What does not fit today goes out tomorrow â the campaign page shows the spread while it runs."})]})}function Bs(t=new Date){const s=new Date(t);return s.setDate(s.getDate()+1),s.setHours(9,0,0,0),{at:ys(s),timezone:js(),quietHours:!1}}function Pe(t){const s={};return t.segment&&(s.segment=t.segment),t.recipients!==void 0&&(s.recipients=[...new Set(t.recipients.map(n=>n.trim().toLowerCase()))].filter(Boolean).sort()),s}function He(t){return JSON.stringify(Pe(t))}const ce={catalogue:t=>["newsletter","variables",He(t)],analysis:t=>["newsletter","analyze",t],previewRecipients:t=>["newsletter","preview-recipients",He(t)],preview:(t,s,n,r)=>["newsletter","variable-preview",t,s??null,n??null,r??null]};function zs(t){return ae({queryKey:ce.catalogue(t),staleTime:300*1e3,queryFn:async()=>{const{data:s,error:n}=await oe.functions.invoke("admin-newsletter",{body:{action:"variables",...Pe(t)}});if(n)throw new Error(await ie(n));return s??{variables:[],takenAt:""}}})}function nt(t){return!t.subject&&!t.preheader&&!t.html&&!t.text}function rt(t,s){return t.subject===s.subject&&t.preheader===s.preheader&&t.html===s.html&&t.text===s.text}function Us(t){const s=nt(t);return ae({queryKey:ce.analysis(t),enabled:!s,staleTime:1/0,queryFn:async()=>{const{data:n,error:r}=await oe.functions.invoke("admin-newsletter",{body:{action:"analyze",...t}});if(r)throw new Error(await ie(r));return n?.errors??[]}})}function Gs(t){return ae({queryKey:ce.previewRecipients(t),staleTime:300*1e3,queryFn:async()=>{const{data:s,error:n}=await oe.functions.invoke("admin-newsletter",{body:{action:"preview-recipients",...Pe(t)}});if(n)throw new Error(await ie(n));return s?.recipients??[]}})}function qs(t,s,n,r){return ae({queryKey:ce.preview(t,s,n,r),enabled:!!s,staleTime:1/0,queryFn:async()=>{const{data:a,error:o}=await oe.functions.invoke("admin-newsletter",{body:{action:"render-preview",email:s,...t,...n===void 0?{}:{senderProfile:n}}});if(o)throw new Error(await ie(o));return a??{errors:[]}}})}const Ks=600;function at(t){const[s,n]=l.useState(()=>({...t}));return l.useEffect(()=>{const r={subject:t.subject,preheader:t.preheader,html:t.html,text:t.text},a=setTimeout(()=>n(r),Ks);return()=>clearTimeout(a)},[t.subject,t.preheader,t.html,t.text]),s}const I="ait-body-slot",Ws=new Set(["A","ABBR","B","BIG","BLOCKQUOTE","BR","CAPTION","CENTER","CITE","CODE","COL","COLGROUP","DD","DIV","DL","DT","EM","FIGCAPTION","FIGURE","FONT","H1","H2","H3","H4","H5","H6","HR","I","IMG","LI","MARK","OL","P","PRE","Q","S","SMALL","SPAN","STRIKE","STRONG","SUB","SUP","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","U","UL","ARTICLE","ASIDE","FOOTER","HEADER","HGROUP","MAIN","NAV","SECTION","BDI","BDO","DATA","DEL","INS","KBD","SAMP","TIME","VAR","WBR"]),Vs=new Set(["align","alt","bgcolor","border","cellpadding","cellspacing","class","color","colspan","dir","face","height","href","lang","role","rowspan","
2size","src","style","target","title","valign","width"]),Ys=new Set(["SCRIPT","STYLE","IFRAME","OBJECT","EMBED","META","LINK","BASE","FORM","NOSCRIPT","TEMPLATE"]);function ne(t){if(typeof DOMParser>"u")return"";const s=new DOMParser().parseFromString(`<body>${t}</body>`,"text/html"),n=r=>{for(const o of Array.from(r.children))n(o);const a=r.tagName.toUpperCase();if(Ys.has(a)){r.remove();return}for(const o of Array.from(r.attributes)){const d=o.name.toLowerCase(),c=o.value;if(!Vs.has(d)){r.removeAttribute(o.name);continue}if(d==="href"||d==="src"){const m=Array.from(c).filter(b=>b.charCodeAt(0)>32).join("").toLowerCase(),i=d==="href"?/^(https?:|mailto:|#)/:/^(https:|cid:)/;!/^\{[{%]/.test(m)&&!i.test(m)&&r.removeAttribute(o.name)}d==="style"&&/expression\s*\(|url\s*\(\s*['"]?\s*javascript:/i.test(c)&&r.removeAttribute(o.name)}Ws.has(a)||r.replaceWith(...Array.from(r.childNodes))};for(const r of Array.from(s.body.children))n(r);return s.body.innerHTML}function Js(t){return typeof DOMParser>"u"?!0:new DOMParser().parseFromString(`<body>${t}</body>`,"text/html").body.innerHTML!==ne(t)}function Zs(t,s,n=!0){const r=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https: data: cid:; style-src 'unsafe-inline'; font-src 'none'; script-src 'none'; frame-src 'none'; object-src 'none'; form-action 'none'; base-uri 'none'; connect-src 'none'">`,a=`<style>#${I}{outline:none}#${I}:focus{outline:2px solid #bf8322;outline-offset:4px}</style>`,o=n?`<div id="${I}" contenteditable="true"></div>`:`<div id="${I}"></div>`;return`${r}${t}${o}${s}${a}`}const Qs={before:'<!doctype html><html><body style="font-family:sans-serif;margin:16px">',after:"</body></html>"};function Be(t){t.target?.closest?.("a")&&t.preventDefault()}const ot=l.forwardRef(function({html:s,onChange:n,chrome:r,error:a,editable:o=!0,caption:d,onFocusWithin:c},m){const i=l.useRef(null),h=l.useRef(n);h.current=n;const b=r??Qs,g=Zs(b.before,b.after,o),S=Js(s),E=l.useRef(null),L=l.useRef(!1),N=o&&!S;return l.useImperativeHandle(m,()=>({insert(v){if(!N)return!1;const y=i.current?.contentDocument,u=y?.getElementById(I);if(!y||!u)return!1;const x=E.current;if(x===null||!u.contains(x.commonAncestorContainer.nodeType===1?x.commonAncestorContainer:x.commonAncestorContainer.parentNode))return!1;x.deleteContents();const T=y.createTextNode(v);x.insertNode(T),x.setStartAfter(T),x.collapse(!0);const A=y.getSelection();return A?.removeAllRanges(),A?.addRange(x),E.current=x.cloneRange(),h.current?.(ne(u.innerHTML)),u.focus(),!0}}),[N]),l.useEffect(()=>{const v=i.current;if(!v)return;const y=()=>{const k=v.contentDocument,P=k?.getElementById(I);if(!P)return;const C=ne(s);P.innerHTML!==C&&(E.current=null,L.current=!1,k?.getSelection()?.removeAllRanges(),P.innerHTML=C),o&&P.setAttribute("contenteditable",S?"false":"true")},u=()=>{if(S)return;const k=v.contentDocument?.getElementById(I);k&&h.current?.(ne(k.innerHTML))},x=()=>{const k=v.contentDocument,P=k?.getElementById(I);if(!k||!P||!L.current)return;const C=k.getSelection();if(!C||C.rangeCount===0)return;const D=C.getRangeAt(0),$=D.commonAncestorContainer,_=$.nodeType===1?$:$.parentNode;_&&P.contains(_)&&(E.current=D.cloneRange())},T=()=>{L.current=!0,c?.()},A=()=>{L.current=!0},R=()=>{y(),o&&(v.contentDocument?.addEventListener("input",u),v.contentDocument?.addEventListener("selectionchange",x),v.contentDocument?.addEventListener("focusin",T),v.contentDocument?.addEventListener("mousedown",A,!0),v.contentDocument?.addEventListener("keydown",A,!0)),v.contentDocument?.addEventListener("click",Be,!0)};return v.contentDocument?.readyState==="complete"&&R(),v.addEventListener("load",R),()=>{v.removeEventListener("load",R),o&&(v.contentDocument?.removeEventListener("input",u),v.contentDocument?.removeEventListener("selectionchange",x),v.contentDocument?.removeEventListener("focusin",T),v.contentDocument?.removeEventListener("mousedown",A,!0),v.contentDocument?.removeEventListener("keydown",A,!0)),v.contentDocument?.removeEventListener("click",Be,!0)}},[g,s,S,o,c]),e.jsxs("div",{className:"space-y-2",children:[!r&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a?`The full preview is unavailable (${a}). This is the body only â the brand header and the footer are added when the message is sent.`:"Loading the header and footer⦠this is the body only for now."}),S&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Part of this body cannot be shown here, so what follows is not the whole message."," ",o?"The preview is read-only for that reason â edit it in the HTML source instead; nothing has been removed from it.":"Nothing has been removed from what will be sent."]}),e.jsx("iframe",{ref:i,title:r?"Rendered message":"Rendered body",srcDoc:g,sandbox:"allow-same-origin",className:`${r?"h-[560px]":"h-[300px]"} w-full rounded-none border bg-white`}),r&&e.jsx("p",{className:"text-xs text-muted-foreground",children:d??"The whole message. Click into the body to edit it â the header, footer and unsubscribe line are added by the template and are not editable here."})]})});
vendor: 4,554 bytes, line 2
2var de="Popover",[it]=Ot(de,[We]),ee=We(),[Xs,H]=it(de),ct=t=>{const{__scopePopover:s,children:n,open:r,defaultOpen:a,onOpenChange:o,modal:d=!1}=t,c=ee(s),m=l.useRef(null),[i,h]=l.useState(!1),[b,g]=Dt({prop:r,defaultProp:a??!1,onChange:o,caller:de});return e.jsx(_t,{...c,children:e.jsx(Xs,{scope:s,contentId:$t(),triggerRef:m,open:b,onOpenChange:g,onOpenToggle:l.useCallback(()=>g(S=>!S),[g]),hasCustomAnchor:i,onCustomAnchorAdd:l.useCallback(()=>h(!0),[]),onCustomAnchorRemove:l.useCallback(()=>h(!1),[]),modal:d,children:n})})};ct.displayName=de;var dt="PopoverAnchor",en=l.forwardRef((t,s)=>{const{__scopePopover:n,...r}=t,a=H(dt,n),o=ee(n),{onCustomAnchorAdd:d,onCustomAnchorRemove:c}=a;return l.useEffect(()=>(d(),()=>c()),[d,c]),e.jsx(Je,{...o,...r,ref:s})});en.displayName=dt;var lt="PopoverTrigger",ut=l.forwardRef((t,s)=>{const{__scopePopover:n,...r}=t,a=H(lt,n),o=ee(n),d=Ve(s,a.triggerRef),c=e.jsx(Ye.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.contentId,"data-state":gt(a.open),...r,ref:d,onClick:X(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?c:e.jsx(Je,{asChild:!0,...o,children:c})});ut.displayName=lt;var Re="PopoverPortal",[tn,sn]=it(Re,{forceMount:void 0}),ht=t=>{const{__scopePopover:s,forceMount:n,children:r,container:a}=t,o=H(Re,s);return e.jsx(tn,{scope:s,forceMount:n,children:e.jsx(Ze,{present:n||o.open,children:e.jsx(Ft,{asChild:!0,container:a,children:r})})})};ht.displayName=Re;var J="PopoverContent",mt=l.forwardRef((t,s)=>{const n=sn(J,t.__scopePopover),{forceMount:r=n.forceMount,...a}=t,o=H(J,t.__scopePopover);return e.jsx(Ze,{present:r||o.open,children:o.modal?e.jsx(rn,{...a,ref:s}):e.jsx(an,{...a,ref:s})})});mt.displayName=J;var nn=Ht("PopoverContent.RemoveScroll"),rn=l.forwardRef((t,s)=>{const n=H(J,t.__scopePopover),r=l.useRef(null),a=Ve(s,r),o=l.useRef(!1);return l.useEffect(()=>{const d=r.current;if(d)return Mt(d)},[]),e.jsx(It,{as:nn,allowPinchZoom:!0,children:e.jsx(pt,{...t,ref:a,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:X(t.onCloseAutoFocus,d=>{d.preventDefault(),o.current||n.triggerRef.current?.focus()}),onPointerDownOutside:X(t.onPointerDownOutside,d=>{const c=d.detail.originalEvent,m=c.button===0&&c.ctrlKey===!0,i=c.button===2||m;o.current=i},{checkForDefaultPrevented:!1}),onFocusOutside:X(t.onFocusOutside,d=>d.preventDefault(),{checkForDefaultPrevented:!1})})})}),an=l.forwardRef((t,s)=>{const n=H(J,t.__scopePopover),r=l.useRef(!1),a=l.useRef(!1);return e.jsx(pt,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||n.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,a.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const d=o.target;n.triggerRef.current?.contains(d)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&a.current&&o.preventDefault()}})}),pt=l.forwardRef((t,s)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:d,onEscapeKeyDown:c,onPointerDownOutside:m,onFocusOutside:i,onInteractOutside:h,...b}=t,g=H(J,n),S=ee(n);return Bt(),e.jsx(zt,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:e.jsx(Ut,{asChild:!0,disableOutsidePointerEvents:d,onInteractOutside:h,onEscapeKeyDown:c,onPointerDownOutside:m,onFocusOutside:i,onDismiss:()=>g.onOpenChange(!1),children:e.jsx(Gt,{"data-state":gt(g.open),role:"dialog",id:g.contentId,...S,...b,ref:s,style:{...b.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),xt="PopoverClose",on=l.forwardRef((t,s)=>{const{__scopePopover:n,...r}=t,a=H(xt,n);return e.jsx(Ye.button,{type:"button",...r,ref:s,onClick:X(t.onClick,()=>a.onOpenChange(!1))})});on.displayName=xt;var cn="PopoverArrow",dn=l.forwardRef((t,s)=>{const{__scopePopover:n,...r}=t,a=ee(n);return e.jsx(qt,{...a,...r,ref:s})});dn.displayName=cn;function gt(t){return t?"open":"closed"}var ln=ct,un=ut,hn=ht,ft=mt;const mn=ln,pn=un,bt=l.forwardRef(({className:t,align:s="center",sideOffset:n=4,...r},a)=>e.jsx(hn,{children:e.jsx(ft,{ref:a,align:s,sideOffset:n,className:Ke("z
2-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...r})}));bt.displayName=ft.displayName;function xn(t,s,n=Math.random){const r=t.filter(a=>a.email!==s);if(r.length!==0)return r[Math.floor(n()*r.length)%r.length].email}function gn(t,s,n,r,a){return t?r?"Loadingâ¦":a?"Unavailable":s!==void 0?s:n.length===0?"Nobody in this audience":"Pick someone":"No one"}function fn({recipients:t,value:s,loading:n,error:r,onChange:a,personalised:o,onPersonalisedChange:d}){const[c,m]=l.useState(!1),i=h=>{a(h),d(!0),m(!1)};return e.jsxs(mn,{open:c,onOpenChange:m,children:[e.jsx(pn,{asChild:!0,children:e.jsxs("button",{type:"button","aria-label":"Preview as","aria-haspopup":"listbox","aria-expanded":c,className:"flex shrink-0 items-center gap-1.5 border bg-background px-2 py-1 text-[11px] transition-colors duration-150 hover:bg-accent",children:[e.jsx(Kt,{className:"h-3 w-3 text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:"text-muted-foreground",children:"Preview as"}),e.jsx("span",{className:"max-w-[200px] truncate font-semibold text-foreground",children:gn(o,s,t,n,r)}),e.jsx(Wt,{className:"h-3 w-3 text-muted-foreground","aria-hidden":"true"})]})}),e.jsx(bt,{align:"end",className:"w-80 rounded-none p-0",children:e.jsxs(Vt,{children:[e.jsx(Yt,{placeholder:"Search the audienceâ¦",className:"h-9 text-[11px]"}),e.jsxs(Jt,{className:"max-h-[320px]",children:[e.jsxs(pe,{forceMount:!0,value:"__unpersonalised__ no one raw unpersonalised",onSelect:()=>{d(!1),m(!1)},className:"items-start gap-2 rounded-none","data-selected-mode":o?void 0:"true",children:[e.jsx(Ls,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold",children:"No one â show it unpersonalised"}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Holes and conditionals stay as written"})]})]}),e.jsx($e,{}),r!==void 0?e.jsx("p",{className:"px-2 py-3 text-[11px] text-destructive",children:"The audience could not be read, so there is nobody to preview as."}):n?e.jsx("p",{className:"px-2 py-3 text-[11px] text-muted-foreground",children:"Loading the audienceâ¦"}):t.length===0?e.jsxs("p",{className:"px-2 py-3 text-[11px] text-muted-foreground",children:["Nobody is in this audience yet, so there is no one to preview as. Pick a group or tick some recipients in"," ",e.jsx("span",{className:"font-medium",children:"Audience"})," first."]}):e.jsxs(e.Fragment,{children:[e.jsxs(Zt,{heading:`From this audience · first ${t.length}, worst cases first`,children:[e.jsxs(Qt,{className:"py-3 text-[11px]",children:["Nobody in these ",t.length," matches that. The list is the start of the audience, not all of it."]}),t.map(h=>e.jsxs(pe,{value:h.email,onSelect:()=>i(h.email),className:"justify-between gap-2 rounded-none",children:[e.jsx("span",{className:"truncate text-[11px]",children:h.email}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[h.label,o&&h.email===s?" · shown":""]})]},h.email))]}),e.jsx($e,{}),e.jsxs(pe,{forceMount:!0,value:"__random__ someone else at random",disabled:t.length<2,onSelect:()=>{const h=xn(t,s);h!==void 0&&i(h)},className:"gap-2 rounded-none",children:[e.jsx(Ds,{className:"h-3 w-3 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"text-[11px]",children:t.length<2?"Someone else at random â there is only one person here":"Someone else at random"})]})]})]})]})})]})}function je({label:t,children:s}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t}),s]})}function bn({email:t,data:s,loading:n,error:r,recipientsError:a,onRetry:o}){return a!==void 0?e.jsxs("p",{className:"border border-destructive/40 bg-destructive/5 p-3 text-xs text-destructive",children:["The audience could not be read, so there is nobody to preview as."," ",a]}):t===void 0?e.jsxs("p",{className:"border bg-muted/30 p-3 text-xs text-muted-foreground",children:["Nobody in this audie
2nce to preview as. Pick a segment or name some recipients, or choose"," ",e.jsx("span",{className:"font-medium",children:"No one â show it unpersonalised"})," in the Preview as menu to keep editing the body."]}):r!==void 0?e.jsxs("p",{className:"border border-destructive/40 bg-destructive/5 p-3 text-xs text-destructive",children:["The preview could not be rendered. ",r]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:n?"Renderingâ¦":`Rendered by the code that sends, for ${t}.`}),s?.html!==void 0&&s.chrome!==void 0&&e.jsx(ot,{html:s.html,chrome:s.chrome,editable:!1,caption:`The whole message as ${t} receives it â header, footer and unsubscribe line included, in the CSS that ships. Read-only: this is their copy, not the draft.`}),s?.html!==void 0&&s.chrome===void 0&&!n&&e.jsxs("div",{className:"space-y-2 border border-amber-500/40 bg-amber-500/5 p-3 text-xs text-amber-700 dark:text-amber-500",children:[e.jsxs("p",{children:["This recipient's copy was rendered, but the header and footer around it could not be. Rather than show a message with no footer and let it read as what ships, the preview is withheld.",s.chromeError!==void 0&&` ${s.chromeError}`]}),o!==void 0&&e.jsx("button",{type:"button",onClick:o,className:"border border-amber-500/40 px-2 py-1 text-[11px] font-medium transition-colors duration-150 hover:bg-amber-500/10",children:"Try again"})]}),s!==void 0&&e.jsxs("div",{className:"space-y-3 border p-3",children:[s.subject!==void 0&&e.jsx(je,{label:"Subject",children:e.jsx("p",{className:"text-sm",children:s.subject})}),s.preheader!==void 0&&s.preheader!==""&&e.jsx(je,{label:"Preheader",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:s.preheader})}),s.text!==void 0&&e.jsx(je,{label:"Plain text body",children:e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap bg-muted/50 p-2 font-mono text-[11px]",children:s.text})})]}),(s?.errors??[]).length>0&&e.jsx("p",{className:"border border-amber-500/40 bg-amber-500/5 p-2 text-xs text-amber-700 dark:text-amber-500",children:s?.errors[0].message})]})}const Q="__blank__",ye="__default__",vn=600;function ze(t,s=vn){const[n,r]=l.useState(t);return l.useEffect(()=>{const a=window.setTimeout(()=>r(t),s);return()=>window.clearTimeout(a)},[t,s]),n}function jn(t){return typeof DOMParser>"u"?t.replace(/ /gi," ").replace(/</gi,"<").replace(/>/gi,">").replace(/"/gi,'"').replace(/'/gi,"'").replace(/&/gi,"&"):new DOMParser().parseFromString(t,"text/html").body.textContent??""}function yn(t){const s=t.replace(/<\s*\/(p|div|h[1-6]|tr|ul|ol|table|blockquote)\s*>/gi,` 3 4`).replace(/<\s*br\s*\/?>/gi,` 5`).replace(/<\s*\/li\s*>/gi,` 6`).replace(/<\s*li[^>]*>/gi,"- ").replace(/<[^>]+>/g,"");return jn(s).replace(/\u00a0/g," ").split(` 7`).map(r=>r.replace(/[ \t]+/g," ").trim()).join(` 8`).replace(/\n{3,}/g,` 9 10`).trim()}function Nn({subject:t,preheader:s,content:n,contentText:r,senderProfile:a,onChange:o,templates:d,templatesLoading:c,audience:m,className:i,previewFrame:h,onPreviewFocus:b}){const[g,S]=l.useState(Q),[E,L]=l.useState("preview"),[N,v]=l.useState(!1),[y,u]=l.useState(void 0),x=Gs(m),T=!x.isError&&(x.data??[]).some(p=>p.email===y),A=at({subject:t,preheader:s,html:n,text:r});l.useEffect(()=>{if(x.isError){u(void 0);return}const p=x.data;if(p===void 0)return;y!==void 0&&p.some(B=>B.email===y)||u(p[0]?.email)},[x.data,x.isError,y]);const R=tt(),k=(R.data??[]).find(p=>a?p.name===a:p.isDefault),P=k?JSON.stringify([k.fromName,k.fromAddress,k.replyTo,k.productName,k.legalEntity,k.postalAddress]):"",C=ze(t),D=ze(s),$=Ns(C,D,a,P),_=qs(A,N&&T?y:void 0,a,P),le=p=>{if(S(p),p===Q)return;const w=(d??[]).find(B=>B.id===p);w&&o({subject:w.subject,preheader:w.preheader,content:w.html,contentText:w.text})},Z=(R.data??[]).find(p=>p.isDefault),M=g!==Q&&(()=>{const p=(d??[]).find(w=>w.id===g);return!!p&&(t!==p.subject||s!==p.preheader||n!==p.html||r!==p.text)})();return e.jsxs(Qe,{className:i,children:[e.jsx(Xe,{className:"sticky top-0 z-10 shrink-0 space-y-0 border-b bg-card p-3.5",children:e.jsxs(Xt,{className:"flex items-center gap-2 text-sm leading-none",children:[e.jsx(es,{className:"h-4 w-4"})," Message"]})}),e.jsxs(et,{className:"space-y-3 p-3.5 lg:min-h-0 lg:flex-1 lg:overflow-y-auto",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(O,{htmlFor:"newsletter-template",className:"text-xs",children:"Template"}),e.jsxs(ke,{value:g,onValueChange:le,children:[e.jsx(Se,{id:"newsletter-template",children:e.jsx(Ce,{placeholder:"Start from blank"})}),e.jsxs(Te,{children:[e.jsx(Y,{value:Q,children:"Start from blank"}),(d??[]).map(p=>e.jsx(Y,{value:p.id,children:p.label},p.id)),(d??[]).length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:c?"Loading templatesâ¦":"No templates could be loaded."})]})]}),e.jsxs("p",{className:"text-[11px] leading-snug text-muted-foreground",children:[g!==Q?(d??[]).find(p=>p.id===g)?.description??"Loaded into the fields below â edit freely.":"Choosing one replaces the subject, preheader and both bodies.",M&&" You have edited it since; what sends is what is below."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(O,{htmlFor:"newsletter-sender",className:"text-xs",children:"Sender"}),e.jsxs(ke,{value:a??ye,onValueChange:p=>o({senderProfile:p===ye?void 0:p}),disabled:R.isLoading||R.isError,children:[e.jsx(Se,{id:"newsletter-sender",children:e.jsx(Ce,{placeholder:"Default sender"})}),e.jsxs(Te,{children:[e.jsx(Y,{value:ye,children:Z?`Default â ${Z.fromN
10ame} <${Z.fromAddress}>`:"Default sender"}),(R.data??[]).filter(p=>!p.isDefault).map(p=>e.jsxs(Y,{value:p.name,children:[p.fromName," <",p.fromAddress,">"]},p.name))]})]}),(R.isError||R.isLoading)&&e.jsx("p",{className:"text-[11px] leading-snug text-muted-foreground",children:R.isError?"The sender list could not be loaded, so this campaign cannot be sent yet â the identity it would go out as cannot be confirmed.":"Loading sendersâ¦"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(O,{htmlFor:"newsletter-subject",className:"text-xs",children:"Subject"}),e.jsx(re,{id:"newsletter-subject",value:t,onChange:p=>o({subject:p.target.value}),placeholder:"What the recipient sees in their list"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(O,{htmlFor:"newsletter-preheader",className:"text-xs",children:"Preheader"}),e.jsx(re,{id:"newsletter-preheader",value:s,onChange:p=>o({preheader:p.target.value}),placeholder:"The grey line after the subject. Optional."})]})]}),e.jsxs(ts,{value:E,onValueChange:L,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-x-3 gap-y-1 border-b",children:[e.jsxs(ss,{className:"h-auto justify-start gap-5 rounded-none border-0 bg-transparent p-0 [&>div]:hidden",children:[e.jsx(xe,{value:"preview",className:"rounded-none border-b-2 border-transparent bg-transparent px-0 pb-2 pt-0 data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:text-foreground",children:"Preview"}),e.jsx(xe,{value:"html",className:"rounded-none border-b-2 border-transparent bg-transparent px-0 pb-2 pt-0 data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:text-foreground",children:"HTML body"}),e.jsx(xe,{value:"text",className:"rounded-none border-b-2 border-transparent bg-transparent px-0 pb-2 pt-0 data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:text-foreground",children:"Plain text body"})]}),E==="preview"&&e.jsx("div",{className:"pb-1.5",children:e.jsx(fn,{recipients:x.data??[],value:T?y:void 0,loading:x.isLoading,error:x.isError?x.error.message:void 0,onChange:u,personalised:N,onPersonalisedChange:v})})]}),e.jsx(ge,{value:"preview",className:"space-y-2",children:N?e.jsx(bn,{email:T?y:void 0,data:_.data,loading:_.isFetching,error:_.isError?_.error.message:void 0,recipientsError:x.isError?x.error.message:void 0,onRetry:()=>void _.refetch()}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{ref:h,html:n,onChange:p=>o({content:p}),chrome:$.data,error:$.error instanceof Error?$.error.message:void 0,onFocusWithin:b}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Type in the body to edit it directly. The brand band, the footer, the postal identity and the unsubscribe link around it are the real ones and are not editable here. The plain text body is separate and is not updated by edits here. Pick somebody above to read the whole message as they will receive it, holes filled."})]})}),e.jsxs(ge,{value:"html",className:"space-y-2",children:[e.jsx(O,{htmlFor:"newsletter-html",className:"sr-only",children:"HTML body"}),e.jsx(Fe,{id:"newsletter-html",value:n,onChange:p=>o({content:p.target.value}),placeholder:"<p>Paste or write the HTML body here.</p>",className:"min-h-[260px] font-mono text-xs"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Paste a fragment, not a whole document â the brand band, the footer, the postal identity and the unsubscribe link are added around it by the campaign template."})]}),e.jsxs(ge,{value:"text",className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{htmlFor:"newsletter-text",className:"sr-only",children:"Plain text body"}),e.jsxs(F,{type:"button",variant:"outline",size:"sm",disabled:!n.trim(),onClick:()=>o({contentText:yn(n)}),children:[e.jsx(ns,{className:"mr-2 h-3.5 w-3.5"}),"Draft from HTML"]})]}),e.jsx(Fe,{id:"newsletter-text",value:r,onChange:p=>o({contentText:p.target.value}),placeholder:"The plaintext version. Required.",className:"min-h-[260px] text-xs"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Required, and worth reading before you send. A text part that does not match the HTML is one of the strongest signals a filter has that a message is not what it claims to be."})]})]})]})]})}function Le({id:t,icon:s,title:n,status:r,summary:a,open:o,onToggle:d,children:c}){return e.jsxs(Qe,{className:o?"relative rounded-none lg:flex lg:min-h-0 lg:flex-1 lg:flex-col":"relative shrink-0 rounded-none",children:[e.jsx(Xe,{className:"shrink-0 space-y-0 p-3.5 pb-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground","aria-hidden":"true",children:s}),e.jsx("h3",{className:"text-sm font-semibold leading-none tracking-tight",children:n}),e.jsx("span",{className:"flex-1"}),r!==void 0&&e.jsx("span",{className:"text-xs text-muted-foreground",children:r}),e.jsx(F,{type:"button",variant:"outline",size:"sm",className:"relative z-20 h-7 rounded-none px-2.5 text-xs","aria-expanded":o,"aria-controls":t,onClick:d,children:o?"Done":"Edit"})]})}),!o&&a!==void 0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 p-3.5 pt-2.5",children:a}),!o&&e.jsx("button",{type:"button","aria-label":`Edit ${n}`,"aria-expanded":!1,"aria-controls":t,onClick:d,className:"absolute inset-0 z-10 cursor-pointer"}),o&&e.jsx(et,{id:t,className:"space-y-4 p-3.5 pt-3 lg:min-h-0 lg:flex-1 lg:overflow-y-auto",children:c})]})}function K({children:t,onRemove:s,removeLabel:n,tone:r="neutral"}){const a={neutral:"border-border bg-muted text-foreground",good:"border-emerald-200 bg-emerald-50 text-emerald-900 dark:border-emerald-900 dark:bg-emerald-950 dark:text-emerald-100",warn:"border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900 dark:bg-amber-950 dar
10k:text-amber-100",muted:"border-dashed border-border bg-transparent text-muted-foreground"};return e.jsxs("span",{className:`inline-flex items-center gap-1.5 rounded-none border px-2.5 py-1 text-xs ${a[r]}`,children:[t,s&&e.jsx("button",{type:"button","aria-label":n,onClick:s,className:"relative z-20 text-muted-foreground transition-colors duration-150 hover:text-foreground",children:e.jsx(rs,{className:"h-3 w-3"})})]})}function vt({label:t,onClick:s}){return e.jsxs("button",{type:"button",onClick:s,className:"relative z-20 inline-flex items-center gap-1.5 rounded-none border border-dashed px-2.5 py-1 text-xs text-muted-foreground transition-colors duration-150 hover:border-foreground/40 hover:text-foreground",children:[e.jsx("span",{"aria-hidden":"true",children:"+"}),t]})}const Ue={subject:"Subject",preheader:"Preheader",html:"HTML body",text:"Plain text body"};function wn({problems:t,loading:s,error:n,onRetry:r,stale:a,fallbackFor:o,onAddFallback:d}){if(n!==void 0)return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-[11px] text-destructive",children:["This draft could not be checked. ",n]}),r!==void 0&&e.jsx(F,{type:"button",variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",onClick:r,children:"Try again"})]});if(s&&t.length===0)return e.jsx("p",{className:"text-xs text-muted-foreground",children:"Checking the draftâ¦"});if(t.length===0)return e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing unresolved. Every variable in this draft can be rendered for every recipient."});const c=t.filter(i=>i.code==="syntax"&&i.offset===null),m=t.filter(i=>!c.includes(i));return e.jsxs("ul",{className:"space-y-2",children:[c.map((i,h)=>e.jsxs("li",{className:"space-y-1 rounded-md border border-destructive/40 bg-destructive/5 px-2 py-1.5",children:[e.jsx("p",{className:"text-[11px] font-medium text-destructive",children:i.field===null?"This draft cannot be sent":`The ${Ue[i.field].toLowerCase()} cannot be sent`}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[i.message,i.path!==null&&e.jsxs(e.Fragment,{children:[" ","The variable is"," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5",children:i.path}),"."]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Every recipient is checked against this before the letter goes, so the send will refuse it until it is changed."})]},`blocking-${i.path??h}`)),m.map((i,h)=>e.jsxs("li",{className:"space-y-1 rounded-md border border-amber-500/40 bg-amber-500/5 px-2 py-1.5",children:[e.jsxs("p",{className:"text-[11px] font-medium",children:[i.field===null?"This draft":Ue[i.field],i.offset!==null&&e.jsxs("span",{className:"font-normal text-muted-foreground",children:[" ","â character ",i.offset]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:i.message}),i.code==="missing_fallback"&&i.path!==null&&(()=>{const b=o(i),g=b===void 0||b==="";return e.jsx(F,{type:"button",variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",disabled:a||g,title:a?"Waiting for the check of what you just typed":g?"Waiting for the catalogue's suggested fallback":void 0,onClick:()=>d(i,b),children:"Add fallback"})})()]},`${i.field}-${i.path??h}-${i.offset??h}`))]})}const kn=.8,Sn={subscriber:"Subscriber",account:"Account",content:"Content"},Cn=["subscriber","account","content"];function Tn(t){return t===null?"coverage unknown":t.total===0?"nobody in this audience":`${Math.round(t.resolved/t.total*100)}% â ${t.resolved} of ${t.total}`}function En(t){return t===null||t.total===0?"text-muted-foreground":t.resolved/t.total<kn?"text-amber-600 dark:text-amber-500":"text-muted-foreground"}function An(t){const s=t.suggestedFallback;return s===void 0||s===""?`{{ ${t.path} }}`:`{{ ${t.path} | fallback: "${s}" }}`}function Pn({variables:t,loading:s,error:n,onInsert:r}){const[a,o]=l.useState(""),d=l.useMemo(()=>{const c=a.trim().toLowerCase(),m=c===""?t:t.filter(i=>`${i.path} ${i.label} ${i.note}`.toLowerCase().includes(c));return Cn.map(i=>({group:i,items:m.filter(h=>h.group===i)})).filter(i=>i.items.length>0)},[t,a]);return s?e.jsxs("div",{className:"space-y-2","aria-busy":"true",children:[e.jsx(q,{className:"h-8 w-full"}),e.jsx(q,{className:"h-12 w-full"}),e.jsx(q,{className:"h-12 w-full"}),e.jsx(q,{className:"h-12 w-full"})]}
10):n?e.jsxs("p",{className:"text-xs text-destructive",children:["The variable list could not be loaded, so nothing can be inserted from it."," ",n]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx(re,{value:a,onChange:c=>o(c.target.value),placeholder:"Search variables","aria-label":"Search variables",className:"h-8 text-xs"}),d.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing matches that."}),d.map(({group:c,items:m})=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:Sn[c]}),m.map(i=>e.jsx(F,{type:"button",variant:"ghost",className:"h-auto w-full justify-start whitespace-normal px-2 py-1.5 text-left",onClick:()=>r(An(i)),children:e.jsxs("span",{className:"flex w-full flex-col gap-0.5",children:[e.jsx("span",{className:"text-xs font-medium",children:i.label}),e.jsx("span",{className:"font-mono text-[11px] text-muted-foreground",children:i.path}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i.note}),e.jsx("span",{className:`text-[11px] ${En(i.coverage)}`,children:Tn(i.coverage)})]})},i.path))]},c))]})}
10function Rn(t){const s=/\{[{%]\s*(?:if\s+|unless\s+)?([a-z_][a-z0-9_]*(?:\.[a-z_][a-z0-9_]*)+)/gi,n=[];for(const r of[t.subject,t.preheader,t.html,t.text])for(const a of(r??"").matchAll(s)){const o=a[1];n.includes(o)||n.push(o)}return n}function Ln({fields:t,audience:s,onInsert:n,onAddFallback:r,onProblemsChange:a,open:o,onToggle:d}){const c=at(t),m=zs(s),i=Us(c),h=i.data??[],b=nt(c)||!i.isError&&i.data!==void 0?c:null;l.useEffect(()=>{a?.(h,b)},[JSON.stringify(h),b,a]);const g=Rn(c),S=new Set(h.map(N=>N.path)),E=i.isFetching?"checkingâ¦":i.isError?"not checked":g.length===0?void 0:h.length===0?"all resolved":`${h.length} unresolved`,L=e.jsxs(e.Fragment,{children:[g.map(N=>{const v=m.data?.variables.find(x=>x.path===N),y=v?.coverage&&v.coverage.total>0?Math.round(v.coverage.resolved/v.coverage.total*100):void 0,u=y!==void 0&&y<100;return e.jsxs(K,{tone:S.has(N)||u?"warn":"good",children:[N,y!==void 0&&e.jsxs("span",{className:"opacity-70",children:[y,"%"]})]},N)}),g.length===0&&e.jsx(vt,{label:"Insert a variable",onClick:d})]});return e.jsx(Le,{id:"newsletter-personalisation",icon:e.jsx(os,{className:"h-4 w-4"}),title:"Personalisation",status:E,summary:L,open:o,onToggle:d,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Pn,{variables:m.data?.variables??[],loading:m.isLoading,error:m.isError?m.error.message:void 0,onInsert:n}),e.jsx(as,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Unresolved"}),e.jsx(wn,{problems:h,loading:i.isFetching,error:i.isError?i.error.message:void 0,onRetry:()=>void i.refetch(),stale:!rt(c,t),fallbackFor:N=>m.data?.variables.find(v=>v.path===N.path)?.suggestedFallback,onAddFallback:r})]})]})})}function Dn(t,s,n,r=n){const a=Math.max(0,Math.min(n,t.length)),o=Math.max(a,Math.min(r,t.length));return{text:`${t.slice(0,a)}${s}${t.slice(o)}`,cursor:a+s.length}}function _n(t,s,n){if(s<0||s>=t.length||!t.startsWith("{{",s))return t;const r=t.indexOf("}}",s+2);if(r===-1)return t;const a=t.slice(s+2,r);if(/\|\s*fallback\s*:/.test(a))return t;const o=n.replace(/"/g,"");return`${t.slice(0,s)}{{${a.trimEnd()} | fallback: "${o}" }}${t.slice(r+2)}`}const Ne="__none__",On={subscriber:"subscriber",user:"user â not subscribed",invited:"invited â never signed up",unconfirmed:"unconfirmed",unsubscribed:"unsubscribed"},$n={not_a_subscriber:"not on the subscriber list",not_eligible:"unconfirmed, unsubscribed or inactive",suppressed:"suppressed â hard bounce or complaint; an admin must remove it"};function Fn({data:t,loading:s,error:n,segment:r,onSegmentChange:a,recipients:o,onRecipientsChange:d,preview:c,previewLoading:m,previewError:i,open:h,onToggle:b}){const[g,S]=l.useState(""),E=l.useMemo(()=>{const u=t?.subscribers??[],x=g.trim().toLowerCase(),T=x?u.filter(C=>C.email.toLowerCase().includes(x)):u,A=new Set(o),k=[...u.filter(C=>A.has(C.email)&&!T.some(D=>D.email===C.email)),...T.filter(C=>A.has(C.email))],P=T.filter(C=>!A.has(C.email));return[...k,...P.slice(0,200)]},[t,g,o]),L=(u,x)=>d(x?[...new Set([...o,u])]:o.filter(T=>T!==u)),N=r!==void 0||o.length>0,v=i!==void 0?"count unavailable":c!==void 0?`${c.count} ${c.count===1?"recipient":"recipients"}`:m?"countingâ¦":void 0,y=e.jsxs(e.Fragment,{children:[r!==void 0&&e.jsx(K,{onRemove:()=>a(void 0),removeLabel:`Clear the group ${r}`,children:r}),o.map(u=>e.jsx(K,{onRemove:()=>d(o.filter(x=>x!==u)),removeLabel:`Remove ${u}`,children:u},u)),e.jsx(vt,{label:N?"Add people":"Choose who receives this",onClick:b}),n!==void 0&&e.jsx(K,{tone:"warn",children:"The subscriber list could not be read"})]});return e.jsx(Le,{id:"newsletter-audience",icon:e.jsx(ds,{className:"h-4 w-4"}),title:"Audience",status:v,summary:y,open:h,onToggle:b,children:e.jsxs("div",{className:"space-y-5",children:[n&&e.jsxs(z,{variant:"destructive",children:[e.jsx(U,{className:"h-4 w-4"}),e.jsxs(G,{children:["The subscriber list could not be read, so the groups and the individual addresses below are empty. ",n]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"newsletter-segment",children:"Group"}),e.jsxs(ke,{value:r??Ne,onValueChange:u=>a(u===Ne?void 0:u),children:[e.jsx(Se,{id:"newsletter-segment",children:e.jsx(Ce,{placeholder:"No group"})}),e.jsxs(Te,{children:[e.jsx(Y,{value:Ne,children:"No group"}),(t?.segments??[]).map(u=>e.jsx(Y,{value:u,children:ws[u]??u},u)),(t?.segments??[]).length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:s?"Loading groupsâ¦":"No groups could be loaded."})]})]}),r==="full"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Everyone eligible on the list. During the warm-up ramp this is the step you take last, not first."}),r==="all_users"&&e.jsxs(z,{variant:"destructive",children:[e.jsx(U,{className:"h-4 w-4"}),e.jsx(G,{className:"text-xs",children:"Every registered account with a confirmed address â these people signed up for the product, not for a newsletter, so this is not a subscription opt-in. Unsubscribed addresses are still excluded. An unexpected campaign is what recipients report as spam, which is the one thing the warm-up ramp cannot recover from."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{htmlFor:"newsletter-search",children:"Individual recipients"}),o.length>0&&e.jsxs(F,{variant:"ghost",size:"sm",onClick:()=>d([]),"aria-label":"Clear chosen recipients",children:["Clear ",o.length]})]}),e.jsx(re,{id:"newsletter-search",placeholder:"Search by address",value:g,onChange:u=>S(u.target.value)}),e.jsx(Me,{className:"h-56 rounded-md border",children:e.jsxs("div",{className:"divide-y",children:[s&&e.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:"Loading subscribersâ¦"}),!s&&E.length===0&&e.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:"No subscriber matches that search."}),E.map(u=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-3 p-2 text-sm hover:bg-muted/50",children:[e.jsx(is,{checked:o.includes(u.email),disabled:u.kind==="unsubscribed",onCheckedChange:x=>L(u.email,x===!0),"aria-label":`Send to ${u.email}`}),e.jsx("span",{className:u.kind==="unsubscribed"?"text-muted-foreground line-through":"",children:u.email}),u.kind!=="subscriber"&&e.jsx(cs,{variant:u.kind==="unsubscribed"?"destructive":"outline",className:"ml-auto whitespace-nowrap text-xs",children:On[u.kind]??u.kind})]},u.email))]})}),t&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.eligible," of ",t.total," people can receive a campaign. Subscribers, registered users who never subscribed, and people who were invited and never signed up â an unsubscribed address cannot be picked at all."]})]}),e.jsxs("div",{className:"rounded-md border bg-muted/30 p-3","aria-live":"polite",children:[!r&&o.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose a group or tick individual subscribers."}),i&&e.jsxs(z,{variant:"destructive",children:[e.jsx(U,{className:"h-4 w-4"}),e.jsx(G,{children:i})]}),m&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Resolving audienceâ¦"}),c&&!m&&!i&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium",children:[c.count," ",c.count===1?"recipient":"recipients"]}),c.recipients.length>0?e.jsx(Me,{className:"h-32 rounded-md border bg-background",children:e.jsx("ul",{className:"divide-y text-sm",children:c.recipients.map(u=>e.jsx("li",{className:"px-2 py-1",children:u},u))})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nobody matches this
10selection. The group and the subscriber list can each be right and still not overlap â check the addresses above against the group you chose."}),c.skipped.length>0&&e.jsxs(z,{variant:"destructive",children:[e.jsx(U,{className:"h-4 w-4"}),e.jsxs(G,{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium",children:[c.skipped.length," chosen"," ",c.skipped.length===1?"address":"addresses"," will not receive this:"]}),e.jsx("ul",{className:"list-inside list-disc",children:c.skipped.map(u=>e.jsxs("li",{children:[u.email," â ",$n[u.reason]??u.reason]},u.email))}),c.suppressed!==void 0&&c.suppressed>0&&e.jsxs("p",{children:[c.suppressed," of them"," ",c.suppressed===1?"is":"are"," on the suppression list and cannot be mailed again from here."]})]})]})]})]})]})})}const Mn=["friends_family"];function In(t){return Mn.includes(t??"")}const Hn="Open rate reads high and nothing fixes that: Apple Mail Privacy Protection fetches the pixel whether or not anybody read the message. Clicks are the number to act on.";function Bn({trackingOpens:t,trackingClicks:s,onChange:n,segment:r,open:a,onToggle:o}){const d=In(r),c=d?!1:t,m=d?!1:s,i=e.jsxs(e.Fragment,{children:[e.jsxs(K,{tone:c?"neutral":"muted",onRemove:c&&!d?()=>n({trackingOpens:!1}):void 0,removeLabel:"Turn open tracking off",children:["Opens ",c?"on":"off"]}),e.jsxs(K,{tone:m?"neutral":"muted",onRemove:m&&!d?()=>n({trackingClicks:!1}):void 0,removeLabel:"Turn click tracking off",children:["Clicks ",m?"on":"off"]}),d&&e.jsx(K,{tone:"warn",children:"This group is never tracked"})]});return e.jsx(Le,{id:"newsletter-tracking",icon:e.jsx(Rs,{className:"h-4 w-4"}),title:"Tracking",summary:i,open:a,onToggle:o,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{htmlFor:"tracking-opens",children:"Track opens"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Adds a 1Ã1 image to the message. ",Hn]})]}),e.jsx(Ie,{id:"tracking-opens",checked:c,disabled:d,onCheckedChange:h=>n({trackingOpens:h})})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{htmlFor:"tracking-clicks",children:"Track clicks"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Rewrites the links in the HTML body to go through our own host first. The plain text body keeps its real links, and the unsubscribe link is never rewritten."})]}),e.jsx(Ie,{id:"tracking-clicks",checked:m,disabled:d,onCheckedChange:h=>n({trackingClicks:h})})]}),d?e.jsx("p",{className:"animate-in fade-in duration-200 text-xs text-muted-foreground",children:"This group is never tracked. It exists to measure how an ordinary message is placed, and two extra remote fetches are not ordinary â so this campaign will be recorded as ânot trackedâ whatever these switches say."},"never-tracked"):e.jsxs("p",{className:"animate-in fade-in duration-200 text-xs text-muted-foreground",children:["Both are off by default while the sending domain is warming up. A remote image and a rewritten link host are both scored against a young sender, so leave them off unless you have a reason. A campaign sent with them off is recorded as ",e.jsx("em",{children:"not tracked"})," â which is a different fact from nobody having opened it."]},"ramp-default")]})})}function zn(t,s){if(t.length!==s.length)return!1;const n=[...t].map(a=>a.toLowerCase()).sort(),r=[...s].map(a=>a.toLowerCase()).sort();return n.every((a,o)=>a===r[o])}const Un={subject:"",preheader:"",content:"",contentText:"",trackingOpens:!1,trackingClicks:!1};function jt(t){return t.complete&&t.chosen&&t.audienceCount>0&&!t.audienceResolving&&!t.audienceFailed&&!t.sending&&!t.sendersUnreadable&&t.personalisationProblems===0&&!t.personalisationUnapproved}function Ge({showHeading:t=!0}={}){const{toast:s}=ls(),[n,r]=l.useState(Un),[a,o]=l.useState(void 0),[d,c]=l.useState([]),[m,i]=l.useState(!1),[h,b]=l.useState(null),[g,S]=l.useState(null),[E,L]=l.useState(null),[N,v]=l.useState([]),[y,u]=l.useState("now"),[x,T]=l.useState(()=>Bs()),[A,R]=l.useState(null),k=l.useCallback((j,f)=>{v(j),R(f)}
10,[]),P=l.useRef(null),C=l.useRef(null),D=l.useRef(!1),$={"newsletter-subject":"subject","newsletter-preheader":"preheader","newsletter-html":"content","newsletter-text":"contentText"},_={subject:"subject",preheader:"preheader",html:"content",text:"contentText"},le=j=>{if(D.current&&C.current?.insert(j))return;const f=P.current,W=f?$[f.id]:void 0;if(f===null||W===void 0){r(se=>({...se,content:`${se.content}${j}`}));return}const V=String(n[W]??""),{text:At,cursor:Oe}=Dn(V,j,f.selectionStart??V.length,f.selectionEnd??f.selectionStart??V.length);r(se=>({...se,[W]:At})),requestAnimationFrame(()=>{f.focus(),f.setSelectionRange(Oe,Oe)})},Z=(j,f)=>{if(j.offset===null)return;const W=_[j.field];r(V=>({...V,[W]:_n(String(V[W]??""),j.offset,f)}))},M=ks(),p=Ss(),w=Cs(a,d),B=Ts(),ue=Es(),yt=!!a||d.length>0,te=n.subject.trim()!==""&&n.content.trim()!==""&&n.contentText.trim()!=="",Nt=tt(),De={subject:n.subject,preheader:n.preheader,html:n.content,text:n.contentText},_e=A===null||!rt(A,De),wt=jt({complete:te,chosen:yt,audienceCount:w.data?.count??0,audienceResolving:w.isFetching,audie
10nceFailed:w.isError,sending:B.isPending,sendersUnreadable:Nt.isError,personalisationProblems:N.length,personalisationUnapproved:_e}),kt=()=>{L(w.data?.recipients??[]),i(!0)},St=async()=>{i(!1);const j=await w.refetch();if(j.isError||!j.data||!E||!zn(j.data.recipients,E)){s({variant:"destructive",title:"Campaign not sent",description:"The audience changed since you confirmed it. Check the recipients and send again."});return}try{const f=await B.mutateAsync({...n,segment:void 0,segmentLabel:a,recipients:E});S(null),b(f),s(Ae(f))}catch(f){if(b(null),f instanceof As){S(f.partial),s({variant:"destructive",title:"Campaign stopped part-way",description:`${f.partial.delivered.length} already delivered. See below before sending again.`});return}S(null),s({variant:"destructive",title:"Campaign not sent",description:f.message})}},[he,Ct]=l.useState(null),me=j=>()=>Ct(f=>f===j?null:j),Tt=async()=>{try{const f=(await ue.mutateAsync({draft:{...n,segment:a,recipients:d},when:x,name:n.subject.trim()||"Untitled campaign"})).forecast;s({title:"Scheduled",description:f===void 0?`It is queued for ${x.at.replace("T"," at ")} ${x.timezone}${x.quietHours?", or the next morning if that is inside quiet hours":""}. The spread could not be worked out just now; the campaign page shows it once the send begins. Cancel it from the campaigns list any time before it starts.`:`It starts ${(f.heldUntil??f.firstArrives).replace("T"," at ")} ${x.timezone}${f.heldUntil===void 0?"":" â quiet hours held it"}, and reaches about ${f.estimatedRecipients.toLocaleString("en-GB")} people over ${f.spansDays} ${f.spansDays===1?"day":"days"}. Cancel it from the campaigns list any time before it starts.`})}catch(j){s({title:"Not scheduled",description:j instanceof Error?j.message:String(j),variant:"destructive"})}},Et=j=>{o(void 0),c(fe(j)),S(null)};return e.jsxs("div",{className:"flex h-full flex-col gap-6",children:[t&&e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Email Campaigns"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Compose a campaign and choose who receives it. Sending cannot be undone."})]}),M.isError&&e.jsxs(z,{variant:"destructive",children:[e.jsx(U,{className:"h-4 w-4"}),e.jsx(we,{children:"Could not read the subscriber list"}),e.jsx(G,{children:M.error.message})]}),e.jsxs("div",{className:"grid min-h-0 flex-1 items-stretch gap-6 lg:grid-cols-[minmax(0,1fr)_380px]",children:[e.jsx("div",{className:"contents",onFocusCapture:j=>{const f=j.target;P.current=f instanceof HTMLInputElement||f instanceof HTMLTextAreaElement?f:null,D.current=!1},children:e.jsx(Nn,{subject:n.subject,preheader:n.preheader,content:n.content,contentText:n.contentText,previewFrame:C,onPreviewFocus:()=>{D.current=!0,P.current=null},senderProfile:n.senderProfile,onChange:j=>r(f=>({...f,...j})),templates:p.data,templatesLoading:p.isLoading,audience:{segment:a,recipients:d},className:"lg:flex lg:h-full lg:min-h-0 lg:flex-col"})}),e.jsxs("div",{className:"flex flex-col gap-3 lg:h-full lg:min-h-0",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:min-h-0 lg:flex-1 lg:overflow-hidden lg:pr-1",children:[e.jsx(Fn,{data:M.data,loading:M.isLoading,error:M.isError?M.error.message:void 0,segment:a,onSegmentChange:o,recipients:d,onRecipientsChange:c,preview:w.data,previewLoading:w.isFetching,previewError:w.isError?w.error.message:void 0,open:he==="audience",onToggle:me("audience")}),e.jsx(Ln,{fields:De,audience:{segment:a,recipients:d},onInsert:le,onAddFallback:Z,onProblemsChange:k,open:he==="personalisation",onToggle:me("personalisation")}),e.jsx(Bn,{trackingOpens:n.trackingOpens,trackingClicks:n.trackingClicks,onChange:j=>r(f=>({...f,...j})),segment:a,open:he==="tracking",onToggle:me("tracking")})]}),e.jsx("div",{className:"shrink-0 border-t pt-3",children:e.jsx(Hs,{mode:y,onModeChange:u,schedule:x,onScheduleChange:T,segment:a,recipients:d})}),e.jsxs("div",{className:"flex shrink-0 flex-col gap-2 border-t bg-background pt-3",children:[e.jsxs(F,{className:"w-full",disabled:!wt||ue.isPending,onClick:y==="at"?Tt:kt,children:[y==="at"?e.jsx(Ps,{className:"mr-2 h-4 w-4"}):e.jsx(qe,{className:"mr-2 h-4 w-4"}),y==="at"?ue.isPending?"Schedulingâ¦":"Schedule this campaign":B.isPending?"Sendingâ¦":`Send to ${w.data?.count??0} ${(w.data?.count??0)===1?"recipient":"recipients"}`]}),!te&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"A subject, an HTML body and a plain text body are all required."}),te&&N.length===0&&_e&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Waiting for the server's check of this draft â see Personalisation."}),te&&N.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[N.length===1?"One variable is unresolved":`${N.length} variables are unresolved`," ","â the sender refuses a template it cannot fill for everyone. See Personalisation above."]})]})]})]}),g&&e.jsxs(z,{variant:"destructive",children:[e.jsx(U,{className:"h-4 w-4"}),e.jsx(we,{children:g.error}),e.jsxs(G,{className:"space-y-2",children:[e.jsxs("p",{children:[g.delivered.length," already delivered â do not send to them again."," ",g.not_delivered.length," refused by the provider,"," ",g.not_attempted.length," not attempted."]}),g.in_doubt&&g.in_doubt.length>0&&e.jsxs("p",{children:[g.in_doubt.length," held by another run of this campaign â they may be receiving it now, so they are not offered for resending."]}),g.remedy&&e.jsx("p",{children:g.remedy}),fe(g).length>0&&e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>Et(g),children:["Select the ",fe(g).length," remaining recipients"]})]})]}),h&&e.jsx(st,{result:h}),e.jsx(us,{open:m,onOpenChange:i,children:e.jsxs(hs,{children:[e.jsxs(m
10s,{children:[e.jsxs(ps,{children:["Send to ",w.data?.count??0," ",(w.data?.count??0)===1?"person":"people","?"]}),e.jsxs(xs,{children:["â",n.subject,"â goes out now and cannot be recalled.",a?` Group: ${a}.`:"",d.length>0?` Named: ${d.length}.`:""]})]}),e.jsxs(gs,{children:[e.jsx(fs,{children:"Cancel"}),e.jsx(bs,{onClick:St,children:"Send now"})]})]})})]})}const Vn=Object.freeze(Object.defineProperty({__proto__:null,AdminNewsletter:Ge,SendOutcomeAlert:st,canSendNow:jt,default:Ge,sendOutcomeMessage:Ae},Symbol.toStringTag,{value:"Module"}));export{Vn as A,mn as P,pn as a,bt as b,Bs as d};
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.