1import{j as e,r as o}from"./index-DcaT-yCh.js";const t={navy:"#0d1f3c",gold:"#b8962e",cream:"#f8f4ef",creamDark:"#ede7de",text:"#1a1a2e",muted:"#5a6278",danger:"#8b1a1a",warn:"#8a6d1f",success:"#1a5c3a",white:"#ffffff",border:"#ddd6cc"},d="Arial,sans-serif",Z={padding:"7px 9px",border:`1px solid ${t.border}`,borderRadius:3,fontFamily:d,fontSize:".82rem",color:t.text,background:t.white},Q=(s=t.navy,n={})=>({padding:"7px 14px",background:s,color:t.white,border:"none",borderRadius:3,fontSize:".75rem",letterSpacing:".06em",textTransform:"uppercase",cursor:"pointer",fontFamily:d,...n}),N=(s={})=>({padding:"7px 14px",background:"transparent",color:t.navy,border:`1px solid ${t.border}`,borderRadius:3,fontSize:".75rem",letterSpacing:".06em",textTransform:"uppercase",cursor:"pointer",fontFamily:d,...s}),H={padding:"6px 8px",textAlign:"left",color:t.muted,fontSize:".72rem",letterSpacing:".08em",textTransform:"uppercase",borderBottom:`1px solid ${t.border}`,whiteSpace:"nowrap"},E={padding:"6px 8px",fontSize:".84rem",color:t.text,borderBottom:`1px solid ${t.creamDark}`,fontFamily:d},J={background:t.white,border:`1px solid ${t.border}`,borderRadius:4,padding:"1.4rem",marginBottom:"1.2rem"},q={fontSize:".7rem",letterSpacing:".18em",textTransform:"uppercase",color:t.gold,fontFamily:d,marginBottom:"1rem",paddingBottom:6,borderBottom:`1px solid ${t.creamDark}`},tt={active:{bg:"#e8f2ec",fg:t.success,label:"Active"},unsubscribed:{bg:"#f0ece4",fg:t.muted,label:"Unsubscribed"},bounced:{bg:"#f7ece6",fg:t.danger,label:"Bounced"},complained:{bg:"#f7e6e6",fg:t.danger,label:"Complained"},suppressed:{bg:"#f0ece4",fg:t.warn,label:"Suppressed"}};function Ge({status:s}){const n=tt[s]||{bg:t.creamDark,fg:t.muted,label:s||"â"};return e.jsx("span",{style:{background:n.bg,color:n.fg,padding:"2px 8px",borderRadius:10,fontSize:".7rem",letterSpacing:".04em",fontFamily:d,whiteSpace:"nowrap",textTransform:"uppercase",fontWeight:700},children:n.label})}function xe({children:s}){return e.jsx("div",{style:{padding:"2rem",textAlign:"center",color:t.muted,fontFamily:d,fontSize:".85rem",fontStyle:"italic"},children:s})}function ye({children:s="Loadingâ¦"}){return e.jsx("div",{style:{padding:"2rem",color:t.muted,fontFamily:d,fontSize:".85rem",fontStyle:"italic"},children:s})}function se({children:s,onRetry:n}){return e.jsxs("div",{style:{padding:"1rem",background:"#f9ecec",border:`1px solid ${t.danger}`,borderRadius:3,color:t.danger,fontFamily:d,fontSize:".84rem"},children:[e.jsxs("div",{children:["â ",s]}),n&&e.jsx("button",{onClick:n,style:{...N(),marginTop:10,borderColor:t.danger,color:t.danger},children:"Try again"})]})}const st=/^\d{4}-\d{2}-\d{2}$/;function ge(s){if(!s)return"â";const n=typeof s=="string"&&st.test(s.trim()),l=new Date(n?`${s.trim()}T12:00:00Z`:s);return Number.isNaN(l.getTime())?"â":l.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric",...n?{timeZone:"UTC"}:{}})}const me=["en","es","fr","ar"],ue={en:"English",es:"Español",fr:"Français",ar:"Ø§ÙØ¹Ø±Ø¨ÙØ©"},V={en:"English",es:"Spanish",fr:"French",ar:"Arabic"},ce=s=>s==="ar",nt={not_generated:{bg:"#f0ece4",fg:t.muted,label:"Not generated"},draft:{bg:"#f7f0e0",fg:t.warn,label:"Draft"},reviewed:{bg:"#eaf0f7",fg:"#2a4a7a",label:"Reviewed"},ready:{bg:"#e8f2ec",fg:t.success,label:"Ready"}};function we({status:s,small:n=!1}){const l=nt[s]||{bg:t.creamDark,fg:t.muted,label:s||"â"};return e.jsx("span",{style:{background:l.bg,color:l.fg,padding:n?"1px 6px":"2px 8px",borderRadius:10,fontSize:n?".64rem":".7rem",letterSpacing:".04em",fontFamily:d,whiteSpace:"nowrap",textTransform:"uppercase",fontWeight:700},children:l.label})}function Ve({language:s}){const n=me.includes(s)?s:"en",l=n==="en";return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:l?"transparent":"#eaf0f7",color:l?t.muted:"#2a4a7a",border:l?`1px solid ${t.creamDark}`:"1px solid #cfdcec",padding:"1px 8px",borderRadius:10,fontSize:".7rem",fontFamily:d,whiteSpace:"nowrap"},children:[e.jsx("span",{lang:n,dir:ce(n)?"rtl":"ltr",style:{fontWeight:700},children:ue[n]}),!l&&e.jsx("span",{style:{opacity:.7},children:V[n]})]})}function je(s={}){const n=new URLSearchParams;for(const[a,r]of Object.entries(s))r!=null&&r!==""&&n.set(a,r);const l=n.toString();return l?`?${l}`:""}const M=encodeURIComponent;function lt(s){const n="/api/admin/newsletter";return{listSubscribers:(l={})=>s(`${n}/subscribers${je(l)}`),getSubscriber:l=>s(`${n}/subscribers/${M(l)}`),createSubscriber:l=>s(`${n}/subscribers`,{method:"POST",body:JSON.stringify(l)}),updateSubscriber:(l,a)=>s(`${n}/subscribers/${M(l)}`,{method:"PATCH",body:JSON.stringify(a)}),setStatus:(l,a)=>s(`${n}/subscribers/${M(l)}/status`,{method:"POST",body:JSON.stringify(a)}),setTags:(l,{add:a=[],remove:r=[]})=>s(`${n}/subscribers/${M(l)}/tags`,{method:"POST",body:JSON.stringify({add:a,remove:r})}),listTags:()=>s(`${n}/tags`),listIssues:(l={})=>s(`${n}/issues${je(l)}`),getIssue:l=>s(`${n}/issues/${M(l)}`),createIssue:l=>s(`${n}/issues`,{method:"POST",body:JSON.stringify(l)}),updateIssue:(l,a)=>s(`${n}/issues/${M(l)}`,{method:"PATCH",body:JSON.stringify(a)}),duplicateIssue:(l,a={})=>s(`${n}/issues/${M(l)}/duplicate`,{method:"POST",body:JSON.stringify(a)}),saveSections:(l,a)=>s(`${n}/issues/${M(l)}/sections`,{method:"PUT",body:JSON.stringify({sections:a})}),listBlogPosts:(l={})=>s(`${n}/blog-posts${je(l)}`),buildIssueFromBlog:l=>s(`${n}/issues/from-blog`,{method:"POST",body:JSON.stringify(l)}),insertLibraryItem:(l,a)=>s(`${n}/issues/${M(l)}/sections/from-library`,{method:"POST",body:JSON.stringify({contentLibraryId:a})}),previewIssue:(l,a)=>s(`${n}/issues/${M(l)}/preview${a?`?language=${M(a)}`:""}`),preflightIssue:l=>s(`${n}/issues/${M(l)}/preflight`),testSend:(l,a,r)=>s(`${n}/issues/${M(l)}/test-send`,{method:"POST",body:JSON.stringify({recipients:a,...r?{language:r}:{}})}),audiencePreview:(l,a)=>s(`${n}/issues/${M(l)}/audience-preview`,{method:"POST",body:JSON.stringify({audience:a})}),sendCampaign:(l,{audience:a,confirmationToken:r,expectedRecipientCount:m})=>s(`${n}/issues/${M(l)}/campaigns`,{method:"POST",body:JSON.stringify({audience:a,confirmationToken:r,expectedRecipientCount:m})}),sendBatch:(l,a)=>s(`${n}/campaigns/${M(l)}/send-batch`,{method:"POST",body:JSON.stringify({batchSize:a})}),listCampaigns:(l={})=>s(`${n}/campaigns${je(l)}`),getCampaign:l=>s(`${n}/campaigns/${M(l)}`),getCampaignSnapshot:l=>s(`${n}/campaigns/${M(l)}/snapshot`),getTranslations:l=>s(`${n}/issues/${M(l)}/translations`),generateTranslation:(l,a,r={})=>s(`${n}/issues/${M(l)}/translations/${M(a)}/generate`,{method:"POST",body:JSON.stringify(r)}),saveTranslation:(l,a,r)=>s(`${n}/issues/${M(l)}/translations/${M(a)}`,{method:"PUT",body:JSON.stringify(r)}),setTranslationStatus:(l,a,r)=>s(`${n}/issues/${M(l)}/translations/${M(a)}/status`,{method:"POST",body:JSON.stringify({status:r})}),getLibraryTranslations:l=>s(`${n}/library/${M(l)}/translations`),saveLibraryTranslation:(l,a,r)=>s(`${n}/library/${M(l)}/translations/${M(a)}`,{method:"PUT",body:JSON.stringify(r)}),languageAnalytics:()=>s(`${n}/analytics/languages`),listLibrary:(l={})=>s(`${n}/library${je(l)}`),createLibraryItem:l=>s(`${n}/library`,{method:"POST",body:JSON.stringify(l)}),updateLibraryItem:(l,a)=>s(`${n}/library/${M(l)}`,{method:"PATCH",body:JSON.stringify(a)}),getSettings:()=>s(`${n}/settings`),saveSettings:l=>s(`${n}/settings`,{method:"PUT",body:JSON.stringify(l)}
1),previewImport:({file:l,mapping:a,source:r,sourceDetail:m})=>{const u=new FormData;return u.append("file",l),a&&u.append("mapping",JSON.stringify(a)),r&&u.append("source",r),m&&u.append("sourceDetail",m),s(`${n}/imports/preview`,{method:"POST",body:u})},commitImport:({file:l,importId:a,fileHash:r,mapping:m,tags:u})=>{const x=new FormData;return x.append("file",l),x.append("importId",a),x.append("fileHash",r),m&&x.append("mapping",JSON.stringify(m)),u!=null&&u.length&&x.append("tags",JSON.stringify(u)),s(`${n}/imports/commit`,{method:"POST",body:x})},listImports:(l={})=>s(`${n}/imports${je(l)}`)}}const rt=[{value:"unsubscribed",label:"Unsubscribed",help:"They asked to stop receiving the newsletter."},{value:"suppressed",label:"Suppressed",help:"Held off the list manually, for any other reason."},{value:"bounced",label:"Bounced",help:"Mail to this address is failing."},{value:"complained",label:"Complained",help:"They marked a newsletter as spam."}],ve={display:"block",fontSize:".7rem",letterSpacing:".1em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:4},Se={marginBottom:"1rem"};function it({api:s,subscriber:n,onClose:l,onSaved:a,showToast:r}){const m=!(n!=null&&n.id),[u,x]=o.useState({email:(n==null?void 0:n.email)||"",firstName:(n==null?void 0:n.first_name)||"",lastName:(n==null?void 0:n.last_name)||"",source:(n==null?void 0:n.source)||(m?"admin-manual":""),sourceDetail:(n==null?void 0:n.source_detail)||"",notes:(n==null?void 0:n.notes)||""}),[c,_]=o.useState(n||null),[C,T]=o.useState(""),[y,j]=o.useState((n==null?void 0:n.tags)||[]),[f,F]=o.useState(!1),[h,L]=o.useState(null),[w,i]=o.useState(null),[g,p]=o.use
1State(!1);o.useEffect(()=>{p(!1)},[n==null?void 0:n.id]);const k=A=>K=>{x(D=>({...D,[A]:K.target.value})),i(null)},O=c&&c.status!=="active";function P(){return u.email.trim()?/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(u.email.trim())?null:"That does not look like a valid email address.":"An email address is required."}async function ne(){var K,D,ie;const A=P();if(A){i(A);return}F(!0),L(null);try{const z=C.trim(),ee={email:u.email.trim(),firstName:u.firstName.trim(),lastName:u.lastName.trim(),source:u.source||void 0,sourceDetail:u.sourceDetail.trim(),notes:u.notes.trim()},le=m?await s.createSubscriber(ee):await s.updateSubscriber(c.id,ee);_(le.subscriber);let G=!1,Y=!1,ae=null;const re=((K=le.subscriber)==null?void 0:K.id)||(c==null?void 0:c.id);if(z&&re)try{ae=(await s.setTags(re,{add:[z],remove:[]})).tags||[],j(ae),T(""),G=!0}catch(oe){Y=!0,L(`Saved, but the tag could not be added: ${((D=oe.body)==null?void 0:D.error)||oe.message}`)}Y?r==null||r("error","Subscriber saved, but the tag was not added."):r==null||r("success",m?"Subscriber added.":G?"Subscriber and tag saved.":"Subscriber saved."),a==null||a(ae?{...le.subscriber,tags:ae}:le.subscriber),m&&(l==null||l())}catch(z){L(((ie=z.body)==null?void 0:ie.error)||z.message)}finally{F(!1)}}async function v(A){var K;F(!0),L(null);try{const D=await s.setStatus(c.id,{status:A,...A==="active"?{resubscribeConfirmed:g}:{}});_(D.subscriber),p(!1),r==null||r("success",A==="active"?"Subscriber reactivated.":"Subscriber suppressed."),a==null||a(D.subscriber)}catch(D){L(((K=D.body)==null?void 0:K.error)||D.message)}finally{F(!1)}}async function W(){var K;const A=C.trim();if(A){F(!0);try{const D=await s.setTags(c.id,{add:[A],remove:[]});j(D.tags||[]),T(""),a==null||a({...c,tags:D.tags})}catch(D){L(((K=D.body)==null?void 0:K.error)||D.message)}finally{F(!1)}}}async function X(A){var K;F(!0);try{const D=await s.setTags(c.id,{add:[],remove:[A]});j(D.tags||[]),a==null||a({...c,tags:D.tags})}catch(D){L(((K=D.body)==null?void 0:K.error)||D.message)}finally{F(!1)}}return e.jsxs("div",{style:{...J,marginBottom:0},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"1.2rem"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{...q,border:"none",margin:0,padding:0},children:m?"Add subscriber":"Edit subscriber"}),!m&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginTop:8,display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[e.jsx(Ge,{status:c.status}),e.jsx(Ve,{language:c.preferred_language}),e.jsxs("span",{style:{fontSize:".76rem",color:t.muted,fontFamily:d},children:["Added ",ge(c.created_at)]})]}),c.preferred_language&&c.preferred_language!=="en"&&e.jsxs("div",{style:{fontSize:".76rem",color:t.muted,fontFamily:d,marginTop:6},children:["They chose ",V[c.preferred_language]," from a newsletter, so future issues go out in ",V[c.preferred_language],"."]})]})]}),e.jsx("button",{onClick:l,"aria-label":"Close editor",style:{...N(),padding:"4px 10px"},children:"Close"})]}),h&&e.jsx("div",{style:{marginBottom:"1rem"},children:e.jsx(se,{children:h})}),e.jsxs("div",{style:Se,children:[e.jsx("label",{style:ve,htmlFor:"nl-email",children:"Email"}),e.jsx("input",{id:"nl-email",style:{...Z,width:"100%",boxSizing:"border-box"},value:u.email,onChange:k("email"),autoComplete:"off"}),w&&e.jsx("div",{style:{color:t.danger,fontSize:".76rem",fontFamily:d,marginTop:4},children:w})]}),e.jsxs("div",{style:{display:"flex",gap:"1rem",flexWrap:"wrap"},children:[e.jsxs("div",{style:{...Se,flex:"1 1 160px"},children:[e.jsx("label",{style:ve,htmlFor:"nl-first",children:"First name"}),e.jsx("input",{id:"nl-first",style:{...Z,width:"100%",boxSizing:"border-box"},value:u.firstName,onChange:k("firstName")})]}),e.jsxs("div",{style:{...Se,flex:"1 1 160px"},children:[e.jsx("label",{style:ve,htmlFor:"nl-last",children:"Last name"}),e.jsx("input",{id:"nl-last",style:{...Z,width:"100%",boxSizing:"border-box"},value:u.lastName,onChange:k("lastName")})]})]}),e.jsxs("div",{style:{display:"flex",gap:"1rem",flexWrap:"wrap"},children:[e.jsxs("div",{style:{...Se,flex:"1 1 160px"},children:[e.jsx("label",{style:ve,htmlFor:"nl-source",children:"Source"}),e.jsx("input",{id:"nl-source",style:{...Z,width:"100%",boxSizing:"border-box"}
1,value:u.source,onChange:k("source")})]}),e.jsxs("div",{style:{...Se,flex:"1 1 160px"},children:[e.jsx("label",{style:ve,htmlFor:"nl-source-detail",children:"Source detail"}),e.jsx("input",{id:"nl-source-detail",style:{...Z,width:"100%",boxSizing:"border-box"},value:u.sourceDetail,onChange:k("sourceDetail")})]})]}),e.jsxs("div",{style:Se,children:[e.jsx("label",{style:ve,htmlFor:"nl-notes",children:"Notes"}),e.jsx("textarea",{id:"nl-notes",rows:3,style:{...Z,width:"100%",boxSizing:"border-box",resize:"vertical"},value:u.notes,onChange:k("notes")})]}),e.jsx("button",{onClick:ne,disabled:f,style:{...Q(t.navy),opacity:f?.6:1},children:f?"Savingâ¦":m?"Add subscriber":"Save changes"}),!m&&e.jsxs("div",{style:{marginTop:"1.8rem"},children:[e.jsx("div",{style:q,children:"Tags"}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:10},children:[y.length===0&&e.jsx("span",{style:{color:t.muted,fontSize:".8rem",fontFamily:d,fontStyle:"italic"},children:"No tags yet."}),y.map(A=>e.jsxs("span",{style:{background:t.cream,border:`1px solid ${t.border}`,borderRadius:10,padding:"2px 8px",fontSize:".76rem",fontFamily:d,display:"inline-flex",gap:6,alignItems:"center"},children:[A,e.jsx("button",{onClick:()=>X(A),"aria-label":`Remove tag ${A}`,style:{background:"none",border:"none",cursor:"pointer",color:t.muted,padding:0,lineHeight:1},children:"Ã"})]},A))]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("input",{"aria-label":"New tag",placeholder:"Add a tag",style:{...Z,flex:1},value:C,onChange:A=>T(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),W())}}),e.jsx("button",{onClick:W,disabled:f||!C.trim(),style:N(),children:"Add tag"})]}),C.trim()&&e.jsxs("div",{style:{fontSize:".76rem",color:t.warn,fontFamily:d,marginTop:6},children:["â",C.trim(),"â is not added yet â press ",e.jsx("strong",{children:"Add tag"}),", or it will be saved when you press ",e.jsx("strong",{children:"Save changes"}),"."]})]}),!m&&e.jsxs("div",{style:{marginTop:"1.8rem"},children:[e.jsx("div",{style:q,children:"Sending status"}),!O&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{style:{fontSize:".82rem",color:t.muted,fontFamily:d,lineHeight:1.5,marginTop:0},children:["This person is ",e.jsx("strong",{children:"eligible"})," to receive campaigns. Taking them off the list stops that immediately."]}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:rt.map(A=>e.jsx("button",{title:A.help,disabled:f,onClick:()=>v(A.value),style:N({borderColor:t.border}),children:A.label},A.value))})]}),O&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{style:{fontSize:".82rem",color:t.muted,fontFamily:d,lineHeight:1.5,marginTop:0},children:["This person is ",e.jsx("strong",{children:c.status}),c.suppression_reason?` (${c.suppression_reason.replace(/_/g," ")})`:"",c.suppressed_at?` since ${ge(c.suppressed_at)}`:"","."," ","They will not receive campaigns, and imports or website signups will not put them back."]}),e.jsxs("label",{style:{display:"flex",gap:8,alignItems:"flex-start",fontSize:".82rem",fontFamily:d,color:t.text,marginBottom:10},children:[e.jsx("input",{type:"checkbox",checked:g,onChange:A=>p(A.target.checked)}),e.jsx("span",{children:"I have this personâs permission to add them back to the list."})]}),e.jsx("button",{disabled:f||!g,onClick:()=>v("active"),style:{...Q(t.navy),opacity:g?1:.45,cursor:g?"pointer":"not-allowed"},children:"Reactivate subscriber"})]})]})]})}const ke=25,at=[{value:"",label:"All"},{value:"active",label:"Active"},{value:"unsubscribed",label:"Unsubscribed"},{value:"bounced",label:"Bounced"},{value:"complained",label:"Complained"},{value:"suppressed",label:"Suppressed"}];function ot({api:s,showToast:n}){const[l,a]=o.useState(""),[r,m]=o.useState(""),[u,x]=o.useState(""),[c,_]=o.useState(""),[C,T]=o.useState("created_at"),[y,j]=o.useState("desc"),[f,F]=o.useState(0),[h,L]=o.useState({subscribers:[],total:0}
1),[w,i]=o.useState([]),[g,p]=o.useState(!0),[k,O]=o.useState(null),[P,ne]=o.useState(null),v=o.useRef(null);o.useEffect(()=>(clearTimeout(v.current),v.current=setTimeout(()=>{m(l),F(0)},250),()=>clearTimeout(v.current)),[l]);const W=o.useCallback(async()=>{var z;p(!0),O(null);try{const ee=await s.listSubscribers({search:r,status:u,tag:c,sort:C,dir:y,limit:ke,offset:f});L({subscribers:ee.subscribers||[],total:ee.total||0,unavailable:ee.unavailable})}catch(ee){O(((z=ee.body)==null?void 0:z.error)||ee.message),L({subscribers:[],total:0})}finally{p(!1)}},[s,r,u,c,C,y,f]);o.useEffect(()=>{W()},[W]),o.useEffect(()=>{s.listTags().then(z=>i(z.tags||[])).catch(()=>i([]))},[s]);const X=Math.max(1,Math.ceil(h.total/ke)),A=Math.floor(f/ke)+1,K=o.useMemo(()=>h.subscribers.filter(z=>z.status==="active").length,[h.subscribers]);function D(z){C===z?j(ee=>ee==="asc"?"desc":"asc"):(T(z),j("asc")),F(0)}function ie(z){L(ee=>({...ee,subscribers:ee.subscribers.map(le=>le.id===z.id?{...le,...z}:le)})),W()}return e.jsxs("div",{style:{padding:"1.5rem"},children:[e.jsxs("div",{style:{display:"flex",gap:10,flexWrap:"wrap",alignItems:"center",marginBottom:"1rem"},children:[e.jsx("input",{"aria-label":"Search subscribers",placeholder:"Search name or emailâ¦",value:l,onChange:z=>a(z.target.value),style:{...Z,flex:"1 1 240px",minWidth:180}}),e.jsx("select",{"aria-label":"Filter by status",value:u,onChange:z=>{x(z.target.value),F(0)},style:Z,children:at.map(z=>e.jsx("option",{value:z.value,children:z.label},z.value))}),e.jsxs("select",{"aria-label":"Filter by tag",value:c,onChange:z=>{_(z.target.value),F(0)},style:Z,children:[e.jsx("option",{value:"",children:"All tags"}),w.map(z=>e.jsx("option",{value:z.name,children:z.name},z.id))]}),e.jsx("button",{onClick:()=>ne({}),style:Q(t.navy),children:"ï¼ Add subscriber"})]}),e.jsx("div",{style:{fontSize:".76rem",color:t.muted,fontFamily:d,marginBottom:10},children:g?"Loadingâ¦":e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:h.total})," subscriber",h.total===1?"":"s",u||c||r?" matching this filter":" in total",h.subscribers.length>0&&e.jsxs(e.Fragment,{children:[" · ",K," of ",h.subscribers.length," on this page are active"]})]})}),k&&e.jsx(se,{onRetry:W,children:k}),h.unavailable&&!k&&e.jsx(se,{children:"Newsletter storage is not available yet â the database migration has not been applied."}),!k&&e.jsxs("div",{style:{...J,padding:0,overflowX:"auto"},children:[g&&h.subscribers.length===0&&e.jsx(ye,{children:"Loading subscribersâ¦"}),!g&&h.subscribers.length===0&&e.jsx(xe,{children:r||u||c?"No subscribers match this filter.":"No subscribers yet. Add one, or import a list from the Imports tab."}),h.subscribers.length>0&&e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:760},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsxs("th",{style:{...H,cursor:"pointer"},onClick:()=>D("email_normalized"),children:["Email ",C==="email_normalized"?y==="asc"?"â²":"â¼":""]}),e.jsx("th",{style:H,children:"Name"}),e.jsxs("th",{style:{...H,cursor:"pointer"},onClick:()=>D("status"),children:["Status ",C==="status"?y==="asc"?"â²":"â¼":""]}),e.jsx("th",{style:H,children:"Language"}),e.jsx("th",{style:H,children:"Source"}),e.jsx("th",{style:H,children:"Tags"}),e.jsxs("th",{style:{...H,cursor:"pointer"},onClick:()=>D("created_at"),children:["Added ",C==="created_at"?y==="asc"?"â²":"â¼":""]}),e.jsx("th",{style:H})]})}),e.jsx("tbody",{children:h.subscribers.map(z=>e.jsxs("tr",{children:[e.jsx("td",{style:{...E,wordBreak:"break-all"},children:z.email}),e.jsx("td",{style:E,children:z.full_name||[z.first_name,z.last_name].filter(Boolean).join(" ")||"â"}),e.jsx("td",{style:E,children:e.jsx(Ge,{status:z.status})}),e.jsx("td",{style:E,children:e.jsx(Ve,{language:z.preferred_language})}),e.jsx("td",{style:{...E,color:t.muted,fontSize:".78rem"},children:z.source||"â"}),e.jsx("td",{style:{...E,fontSize:".76rem",color:t.muted},children:(z.tags||[]).join(", ")||"â"}),e.jsx("td",{style:{...E,whiteSpace:"nowrap",color:t.muted,fontSize:".78rem"},children:ge(z.created_at)}),e.jsx("td",{style:{...E,textAlign:"right"},children:e.jsx("button",{onClick:()=>ne(z),style:N({padding:"4px 10px"}),children:"Open"})})]},z.id))})]})]}),h.total>ke&&e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",fontFamily:d,fontSize:".78rem",color:t.muted},children:[e.jsx("button",{disabled:f===0,onClick:()=>F(Math.max(0,f-ke)),style:N({opacity:f===0?.4:1}),children:"â Previous"}),e.jsxs("span",{children:["Page ",A," of ",X]}),e.jsx("button",{disabled:A>=X,onClick:()=>F(f+ke),style:N({opacity:A>=X?.4:1}),children:"Next â"})]}),P&&e.jsx("div",{style:{marginTop:"1.5rem"},children:e.jsx(it,{api:s,subscriber:P.id?P:null,showToast:n,onClose:()=>ne(null),onSaved:ie})})]})}const dt=[{field:"email",label:"Email",required:!0},{field:"firstName",label:"First name"},{field:"lastName",label:"Last name"},{field:"fullName",label:"Full name"},{field:"source",label:"Source"},{field:"sourceDetail",label:"Source detail"},{field:"tags",label:"Tags"}],Re=[{key:"newSubscribers",action:"create",label:"Will be added",tone:"good",help:"New people who are not on the list yet."},{key:"updates",action:"update",label:"Will be updated",tone:"good",help:"Already on the list â blank fields will be filled
1in. Existing details are never overwritten."},{key:"unchanged",action:"unchanged",label:"Already up to date",tone:"muted",help:"Already on the list with nothing new to add."},{key:"suppressedPreserved",action:"skipped_suppressed",label:"Left unsubscribed",tone:"warn",help:"These people opted out, bounced, or complained. They will NOT be added back."},{key:"duplicatesInFile",action:"duplicate_in_file",label:"Duplicates in file",tone:"muted",help:"The same address appears more than once in this file. Only the first is used."},{key:"invalidRows",action:"invalid",label:"Invalid rows",tone:"bad",help:"No email address, or one that is not usable. These are skipped; the rest still import."}],ct={good:t.success,warn:t.warn,bad:t.danger,muted:t.muted};function ut({api:s,showToast:n,onImported:l}){const[a,r]=o.useState(null),[m,u]=o.useState(null),[x,c]=o.useState(null),[_,C]=o.useState(!1),[T,y]=o.useState(null),[j,f]=o.useState(null);function F(){r(null),u(null),c(null),y(null),f(null)}function h(p){var O;const k=((O=p.target.files)==null?void 0:O[0])||null;r(k),u(null),c(null),y(null),f(null)}async function L(p){var k,O;if(a){C(!0),y(null),f(null);try{const P=await s.previewImport({file:a,mapping:p||void 0});u(P),c(P.mapping)}catch(P){((k=P.body)==null?void 0:k.code)==="EMAIL_COLUMN_REQUIRED"&&P.body.headers?(u({headers:P.body.headers,suggestedMapping:P.body.suggestedMapping||{},needsMapping:!0}),c(P.body.mapping||{}),y("No email column was detected. Choose which column holds the email address, then preview again.")):(y(((O=P.body)==null?void 0:O.error)||P.message),u(null))}finally{C(!1)}}}async function w(){var p;if(!(!a||!(m!=null&&m.importId))){C(!0),y(null);try{const k=await s.commitImport({file:a,importId:m.importId,fileHash:m.fileHash,mapping:x});f(k.results),n==null||n("success",`Import complete â ${k.results.created} added, ${k.results.updated} updated.`),l==null||l(k.results)}catch(k){y(((p=k.body)==null?void 0:p.error)||k.message)}finally{C(!1)}}}const i=m==null?void 0:m.summary,g=!!(m!=null&&m.importId)&&!j;return e.jsxs("div",{style:{padding:"1.5rem"},children:[e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"1 · Choose a file"}),e.jsxs("p",{style:{fontSize:".84rem",color:t.muted,fontFamily:d,lineHeight:1.55,marginTop:0},children:["A ",e.jsx("strong",{children:".csv"})," or ",e.jsx("strong",{children:".xlsx"})," file with a header row and an email column. Nothing is saved until you confirm the import on the next step."]}),e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("input",{type:"file",accept:".csv,.xlsx",onChange:h,"aria-label":"Choose a CSV or XLSX file",style:{fontFamily:d,fontSize:".82rem"}}),e.jsx("button",{onClick:()=>L(null),disabled:!a||_,style:{...Q(t.navy),opacity:!a||_?.5:1},children:_&&!j?"Readingâ¦":"Preview import"}),(a||m)&&e.jsx("button",{onClick:F,disabled:_,style:N(),children:"Start over"})]}),a&&e.jsxs("div",{style:{marginTop:8,fontSize:".78rem",color:t.muted,fontFamily:d},children:["Selected: ",a.name]})]}),T&&e.jsx("div",{style:{marginBottom:"1.2rem"},children:e.jsx(se,{children:T})}),(m==null?void 0:m.headers)&&e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"2 · Match your columns"}),e.jsx("div",{style:{display:"flex",gap:"1rem",flexWrap:"wrap"},children:dt.map(({field:p,label:k,required:O})=>e.jsxs("div",{style:{flex:"1 1 180px"},children:[e.jsxs("label",{htmlFor:`map-${p}`,style:{display:"block",fontSize:".7rem",letterSpacing:".1em",textTransform:"uppercase",color:O?t.navy:t.muted,fontFamily:d,marginBottom:4},children:[k,O?" *":""]}),e.jsxs("select",{id:`map-${p}`,"aria-label":`${k} column`,value:(x==null?void 0:x[p])||"",onChange:P=>c(ne=>({...ne,[p]:P.target.value||void 0})),style:{...Z,width:"100%"},children:[e.jsx("option",{value:"",children:"â not imported â"}),m.headers.map(P=>e.jsx("option",{value:P,children:P},P))]})]},p))}),e.jsx("button",{onClick:()=>L(x),disabled:_||!(x!=null&&x.email),style:{...N(),marginTop:"1rem",opacity:_||!(x!=null&&x.email)?.5:1},children:"Re-check with these columns"})]}),i&&e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"3 · Review before importing"}),e.jsxs("p",{style:{fontSize:".84rem",color:t.muted,fontFamily:d,marginTop:0},children:[e.jsx("strong",{children:i.totalRows})," rows read from ",e.jsx("strong",{children:m.filename}),"."," ","Nothing has been saved yet."]}),e.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",marginBottom:"1.2rem"},children:Re.map(({key:p,label:k,tone:O,help:P})=>e.jsxs("div",{title:P,style:{flex:"1 1 150px",border:`1px solid ${t.border}`,borderRadius:4,padding:"10px 12px",background:t.cream}
1,children:[e.jsx("div",{style:{fontSize:"1.5rem",color:ct[O],fontFamily:d,fontWeight:700},children:i[p]??0}),e.jsx("div",{style:{fontSize:".72rem",letterSpacing:".06em",textTransform:"uppercase",color:t.muted,fontFamily:d},children:k})]},p))}),i.suppressedPreserved>0&&e.jsxs("div",{style:{background:"#faf4e6",border:`1px solid ${t.warn}`,borderRadius:3,padding:"10px 12px",marginBottom:"1.2rem",fontFamily:d,fontSize:".82rem",color:t.text},children:[e.jsx("strong",{children:i.suppressedPreserved})," ",i.suppressedPreserved===1?"address in this file has":"addresses in this file have"," opted out or stopped receiving mail",i.suppressedByStatus&&Object.keys(i.suppressedByStatus).length>0&&e.jsxs(e.Fragment,{children:[" (",Object.entries(i.suppressedByStatus).map(([p,k])=>`${k} ${p}`).join(", "),")"]}),"."," ","They will stay off the list â importing cannot put them back."]}),i.withConflicts>0&&e.jsxs("div",{style:{fontSize:".8rem",color:t.muted,fontFamily:d,marginBottom:"1.2rem"},children:[i.withConflicts," row",i.withConflicts===1?" has a value that differs":"s have values that differ"," from what is already saved. Existing details are kept; the fileâs versions are ignored."]}),Re.map(({key:p,action:k,label:O})=>{var ne;const P=((ne=m.samples)==null?void 0:ne[k])||[];return P.length?e.jsxs("details",{style:{marginBottom:8},children:[e.jsxs("summary",{style:{cursor:"pointer",fontFamily:d,fontSize:".8rem",color:t.navy},children:[O," â showing ",P.length," of ",i[p]]}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",marginTop:8},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:H,children:"Row"}),e.jsx("th",{style:H,children:"Email"}),e.jsx("th",{style:H,children:"Name"}),e.jsx("th",{style:H,children:"Note"})]})}),e.jsx("tbody",{children:P.map((v,W)=>e.jsxs("tr",{children:[e.jsx("td",{style:E,children:v.rowNumber}),e.jsx("td",{style:{...E,wordBreak:"break-all"},children:v.email||"â"}),e.jsx("td",{style:E,children:[v.firstName,v.lastName].filter(Boolean).join(" ")||"â"}),e.jsxs("td",{style:{...E,color:t.muted,fontSize:".78rem"},children:[v.existingStatus?`currently ${v.existingStatus}`:"",v.reason?String(v.reason).replace(/_/g," "):"",(v.conflicts||[]).map(X=>`keeps "${X.kept}" over "${X.ignored}"`).join("; ")]})]},`${k}-${W}`))})]})})]},k):null}),g&&e.jsxs("div",{style:{marginTop:"1.4rem",paddingTop:"1.2rem",borderTop:`1px solid ${t.creamDark}`},children:[e.jsx("button",{onClick:w,disabled:_,style:{...Q(t.navy),opacity:_?.6:1},children:_?"Importingâ¦":`Import ${i.newSubscribers+i.updates} record${i.newSubscribers+i.updates===1?"":"s"}`}),e.jsx("span",{style:{marginLeft:12,fontSize:".78rem",color:t.muted,fontFamily:d},children:"This adds people to the mailing list. It does not send anything."})]})]}),j&&e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Import complete"}),e.jsxs("ul",{style:{fontFamily:d,fontSize:".86rem",color:t.text,lineHeight:1.8,margin:0,paddingLeft:"1.2rem"},children:[e.jsxs("li",{children:[e.jsx("strong",{children:j.created})," added"]}),e.jsxs("li",{children:[e.jsx("strong",{children:j.updated})," updated"]}),e.jsxs("li",{children:[e.jsx("strong",{children:j.skipped})," skipped (already up to date or duplicated in the file)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:j.suppressedPreserved})," left unsubscribed"]}),e.jsxs("li",{children:[e.jsx("strong",{children:j.invalid})," invalid"]}),j.failed>0&&e.jsxs("li",{style:{color:t.danger},children:[e.jsx("strong",{children:j.failed})," failed"]})]}),e.jsx("button",{onClick:F,style:{...N(),marginTop:"1.2rem"},children:"Import another file"})]}),!a&&!m&&!j&&e.jsx(xe,{children:"Choose a CSV or XLSX file above to get started."})]})}const Oe=[{id:"desktop",label:"Desktop",width:700},{id:"mobile",label:"Mobile",width:375},{id:"text",label:"Plain text"}];function mt({preview:s,onClose:n,onSendTest:l,language:a=null,onLanguage:r=null,readiness:m=null,busy:u=!1}){const[x,c]=o.useState("desktop"),_=Oe.find(y=>y.id===x),C=a||s.language||"en",T=ce(C);return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Newsletter preview",style:{position:"fixed",inset:0,background:"rgba(13,3
11,48,0.55)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"},onClick:y=>{y.target===y.currentTarget&&n()},children:e.jsxs("div",{style:{background:t.white,borderRadius:4,width:"100%",maxWidth:860,maxHeight:"92vh",display:"flex",flexDirection:"column",overflow:"hidden",border:`1px solid ${t.border}`},children:[e.jsxs("div",{style:{padding:"0.9rem 1.2rem",borderBottom:`1px solid ${t.border}`,display:"flex",gap:12,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs("div",{style:{flex:1,minWidth:200},children:[e.jsx("div",{style:{fontSize:".7rem",letterSpacing:".16em",textTransform:"uppercase",color:t.gold,fontFamily:d},children:"Preview"}),e.jsxs("div",{style:{fontFamily:d,fontSize:".9rem",color:t.navy,marginTop:3},children:[e.jsx("strong",{children:"Subject:"})," ",s.subject||"(no subject)"]}),s.preheader&&e.jsxs("div",{style:{fontFamily:d,fontSize:".76rem",color:t.muted,marginTop:2},children:["Preview line: ",s.preheader]}),s.from&&e.jsxs("div",{style:{fontFamily:d,fontSize:".76rem",color:t.muted,marginTop:2},children:["From: ",s.from]}),r&&T&&e.jsx("div",{style:{fontFamily:d,fontSize:".72rem",color:"#2a4a7a",marginTop:4},children:"Right-to-left layout â this is the real rendered document, not a mirrored preview."})]}),e.jsx("div",{style:{display:"flex",gap:6},children:Oe.map(y=>e.jsx("button",{onClick:()=>c(y.id),"aria-pressed":x===y.id,style:x===y.id?Q(t.navy,{padding:"5px 12px"}):N({padding:"5px 12px"}),children:y.label},y.id))}),e.jsx("button",{onClick:n,"aria-label":"Close preview",style:N({padding:"5px 12px"}),children:"Close"})]}),r&&e.jsxs("div",{style:{padding:"0.6rem 1.2rem",borderBottom:`1px solid ${t.border}`,background:t.cream,display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:".7rem",letterSpacing:".12em",textTransform:"uppercase",color:t.muted,fontFamily:d},children:"Language"}),me.map(y=>{const j=y===C;return e.jsxs("button",{onClick:()=>!j&&r(y),disabled:u,"aria-pressed":j,title:V[y],style:{...j?Q(t.navy,{padding:"4px 11px"}):N({padding:"4px 11px"}),textTransform:"none",letterSpacing:0,fontSize:".8rem",opacity:u&&!j?.5:1,cursor:u?"wait":"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx("span",{lang:y,dir:ce(y)?"rtl":"ltr",children:ue[y]}),(m==null?void 0:m[y])&&y!=="en"&&e.jsx(we,{status:m[y].status,small:!0})]},y)}),u&&e.jsx("span",{style:{fontSize:".75rem",color:t.muted,fontFamily:d},children:"Renderingâ¦"})]}),e.jsx("div",{style:{flex:1,overflow:"auto",background:t.cream,padding:"1.2rem",display:"flex",justifyContent:"center"},children:x==="text"?e.jsx("pre",{lang:C,dir:T?"rtl":"ltr",style:{fontFamily:"ui-monospace,SFMono-Regular,Menlo,monospace",fontSize:".78rem",lineHeight:1.6,color:t.text,background:t.white,border:`1px solid ${t.border}`,padding:"1.2rem",width:"100%",maxWidth:700,whiteSpace:"pre-wrap",wordBreak:"break-word",margin:0,textAlign:T?"right":"left"},children:s.text}):e.jsx("iframe",{title:`Newsletter preview â ${_.label} â ${V[C]||C}`,sandbox:"",srcDoc:s.html,style:{width:_.width,maxWidth:"100%",height:"70vh",border:`1px solid ${t.border}`,background:t.white}},`${C}-${x}`)}),l&&e.jsxs("div",{style:{padding:"0.8rem 1.2rem",borderTop:`1px solid ${t.border}`,display:"flex",gap:12,alignItems:"center"},children:[e.jsx("button",{onClick:l,style:N(),children:"Send a test of this"}),e.jsx("span",{style:{fontSize:".76rem",color:t.muted,fontFamily:d},children:r?`This is exactly what a ${V[C]||C} reader will receive â preview and send use the same renderer.`:"This is exactly what will be sent â preview and send use the same renderer."})]})]})})}const gt=["es","fr","ar"],Pe={display:"block",fontSize:".68rem",letterSpacing:".1em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:4},yt=[{key:"subject",label:"Subject line",rows:0},{key:"preheader",label:"Preview line",rows:0},{key:"title",label:"Headline shown in the email",rows:0},{key:"opening_content",label:"Opening note",rows:3}],pt=[{key:"category_label",label:"Category",rows:0},{key:"headline",label:"Headline",rows:0},{key:"body",label:"Body",rows:4},{key:"link_text",label:"Link text",rows:0}];function ht({text:s}){return e.jsx("div",{style:{background:t.cream,border:`1px solid ${t.creamDark}`,borderRadius:3,padding:"7px 9px",fontFamily:d,fontSize:".82rem",lineHeight:1.55,color:t.muted,whiteSpace:"pre-wrap",wordBreak:"break-word",minHeight:34},children:s||e.jsx("em",{style:{opacity:.65},children:"(empty)"})})}
1function De({field:s,sourceText:n,value:l,onChange:a,lang:r,disabled:m}){const u=ce(r),x={...Z,width:"100%",boxSizing:"border-box",direction:u?"rtl":"ltr",textAlign:u?"right":"left",...s.rows?{resize:"vertical",lineHeight:1.55}:{}};return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(0,1fr) minmax(0,1fr)",gap:12,marginBottom:14},children:[e.jsxs("div",{children:[e.jsxs("label",{style:Pe,children:[s.label," â English"]}),e.jsx(ht,{text:n})]}),e.jsxs("div",{children:[e.jsxs("label",{style:Pe,htmlFor:`t-${r}-${s.key}`,children:[s.label," â ",e.jsx("span",{lang:r,dir:u?"rtl":"ltr",children:ue[r]})]}),s.rows?e.jsx("textarea",{id:`t-${r}-${s.key}`,rows:s.rows,style:x,disabled:m,lang:r,dir:u?"rtl":"ltr",value:l||"",onChange:c=>a(c.target.value)}):e.jsx("input",{id:`t-${r}-${s.key}`,style:x,disabled:m,lang:r,dir:u?"rtl":"ltr",value:l||"",onChange:c=>a(c.target.value)})]})]})}function ft({api:s,issueId:n,frozen:l,onClose:a,onChanged:r,showToast:m}){var ie,z,ee,le,G,Y,ae,re,oe;const[u,x]=o.useState(null),[c,_]=o.useState("es"),[C,T]=o.useState(!0),[y,j]=o.useState(null),[f,F]=o.useState(null),[h,L]=o.useState({}),w=o.useCallback(async()=>{var $;T(!0),j(null);try{x(await s.getTranslations(n))}catch(R){j((($=R.body)==null?void 0:$.error)||R.message)}finally{T(!1)}},[s,n]);o.useEffect(()=>{w()},[w]);const i=((ie=u==null?void 0:u.translations)==null?void 0:ie[c])||null,g=((ee=(z=u==null?void 0:u.readiness)==null?void 0:z[c])==null?void 0:ee.status)||"not_generated",p=h[c],k=!!p,O=$=>{var R;return(p!=null&&p.issue&&$ in p.issue?p.issue[$]:(R=i==null?void 0:i.issue)==null?void 0:R[$])??""},P=($,R)=>{var U,te,pe;const B=(U=p==null?void 0:p.sections)==null?void 0:U[$];return B&&R in B?B[R]??"":((pe=(te=i==null?void 0:i.sections)==null?void 0:te.find(be=>be.id===$))==null?void 0:pe[R])??""},ne=$=>R=>L(B=>{var U;return{...B,[c]:{...B[c]||{},issue:{...((U=B[c])==null?void 0:U.issue)||{},[$]:R}}}}),v=($,R)=>B=>L(U=>{var te,pe,be;return{...U,[c]:{...U[c]||{},sections:{...((te=U[c])==null?void 0:te.sections)||{},[$]:{...((be=(pe=U[c])==null?void 0:pe.sections)==null?void 0:be[$])||{},[R]:B}}}}});async function W(){var $;if(!(k&&!window.confirm(`You have unsaved ${V[c]} edits. Translating with AI replaces this language and discards them. Continue?`))){F("generate"),j(null);try{const R=await s.generateTranslation(n,c);L(B=>{const U={...B};return delete U[c],U}),await w(),m==null||m("success",`${V[c]} drafted by AI. ${R.note||"Review it before marking it ready."}`),r==null||r()}catch(R){const B=(($=R.body)==null?void 0:$.error)||R.message;j(B),m==null||m("error",B)}finally{F(null)}}}async function X(){var $;if(p){F("save"),j(null);try{const R={};p.issue&&(R.issue=p.issue),p.sections&&(R.sections=Object.entries(p.sections).map(([U,te])=>({id:U,...te})));const B=await s.saveTranslation(n,c,R);L(U=>{const te={...U};return delete te[c],te}),await w(),m==null||m("success",B.demoted?`${V[c]} saved â back to draft, because the wording changed since it was approved.`:`${V[c]} saved.`),r==null||r()}catch(R){const B=(($=R.body)==null?void 0:$.error)||R.message;j(B),m==null||m("error",B)}finally{F(null)}}}async function A($){var R;F("status"),j(null);try{await s.setTranslationStatus(n,c,$),await w(),m==null||m("success",$==="ready"?`${V[c]} is ready to send.`:`${V[c]} marked ${$}.`),r==null||r()}catch(B){const U=((R=B.body)==null?void 0:R.error)||B.message;j(U),m==null||m("error",U)}finally{F(null)}}const K=o.useMemo(()=>Object.keys(h).length>0,[h]);function D(){K&&!window.confirm("You have unsaved translation edits. Close anyway?")||a()}return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Translations",style:{position:"fixed",inset:0,background:"rgba(13,31,48,0.55)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"},onClick:$=>{$.target===$.currentTarget&&D()},children:e.jsxs("div",{style:{background:t.white,borderRadius:4,width:"100%",maxWidth:1040,maxHeight:"94vh",display:"flex",flexDirection:"column",overflow:"hidden",border:`1px solid ${t.border}`},children:[e.jsxs("div",{style:{padding:"0.9rem 1.2rem",borderBottom:`1px solid ${t.border}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[e.jsxs("div",{style:{flex:1,minWidth:200},children:[e.jsx("div",{style:{fontSize:".7rem",letterSpacing:".16em",textTransform:"uppercase",color:t.gold,fontFamily:d},children:"Translations"}),e.jsx("div",{style:{fontFamily:d,fontSize:".82rem",color:t.muted,marginTop:3},children:"English is the original. Each language is sent only once you mark it ready."})]}),e.jsx("button",{onClick:D,style:N({padding:"5px 12px"}),children:"Close"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:12,flexWrap:"wrap",alignItems:"center"},children:[e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:7,padding:"5px 11px",border:`1px dashed ${t.border}`,borderRadius:3,fontFamily:d,fontSize:".8rem",color:t.muted},children:[e.jsx("span",{lang:"en",children:"English"}),e.jsx("span",{style:{fontSize:".64rem",letterSpacing:".06em",textTransform:"uppercase",opacity:.8},children:"Original"})]}),gt.map($=>{var U,te;const R=$===c,B=((te=(U=u==null?void 0:u.readiness)==null?void 0:U[$])==null?void 0:te.status)||"not_generated";return e.jsxs("button",{onClick:()=>_($),"aria-pressed":R,style:{...R?Q(t.navy,{padding:"5px 11px"}):N({padding:"5px 11px"}),textTransform:"none",letterSpacing:0,fontSize:".82rem",display:"inline-flex",alignItems:"center",gap:7},children:[e.jsx("span",{lang:$,dir:ce($)?"rtl":"ltr",children:ue[$]}),e.jsx(we,{status:B,small:!0}),h[$]&&e.jsx("span",{title:"Unsaved changes",style:{color:t.gold,fontWeight:700},children:"â¢"})]},$)})]})]}),e.jsx("div",{style:{flex:1,overflow:"auto",background:t.cream,padding:"1.2rem"},children:C?e.jsx(ye,{}):y&&!u?e.jsx(se,{onRetry:w,children:y}):e.jsxs(e.Fragment,{children:[y&&e.jsx("div",{style:{marginBottom:"1rem"},children:e.jsx(se,{children:y})}),e.jsxs("div",{style:{...J,marginBottom:"1rem",display:"flex",gap:12,alignItems:"center",flexWrap:"wrap"},children:[e.jsx(we,{status:g}),e.jsx("div",{style:{fontFamily:d,fontSize:".84rem",color:t.text,flex:"1 1 320px"},children:g==="ready"?`Subscribers who read in ${V[c]} will receive this version.`:g==="not_generated"?`There is no ${V[c]} version yet. A send to anyone who reads in ${V[c]} will be blocked until there is.`:`This ${V[c]} version is not approved yet, so it cannot be sent. Read it through, then mark it ready.`}),((Y=(G=(le=u==null?void 0:u.readiness)==null?void 0:le[c])==null?void 0:G.translatedBy)==null?void 0:Y.startsWith("ai:"))&&g!=="ready"&&e.jsx("div",{style:{fontFamily:d,fontSize:".76rem",color:t.warn,background:"#f7f0e0",border:`1px solid ${t.warn}`,borderRadius:3,padding:"5px 9px"},children:"Machine translation â not yet checked by a person"})]}),((re=(ae=u==null?void 0:u.readiness)==null?void 0:ae[c])==null?void 0:re.lastError)&&e.jsxs("div",{style:{...J,marginBottom:"1rem",borderColor:t.danger,background:"#f9ecec",fontFamily:d,fontSize:".82rem",color:t.danger},children:["The last attempt to generate ",V[c]," failed. Nothing was lost â try again when you are ready."]}),e.jsxs("div",{style:J,children:[e.jsx("div",{style:{fontSize:".7rem",letterSpacing:".18em",textTransform:"uppercase",color:t.gold,fontFamily:d,marginBottom:"1rem",paddingBottom:6,borderBottom:`1px solid ${t.creamDark}`},children:"Email details"}),yt.map($=>{var R,B;return e.jsx(De,{field:$,lang:c,disabled:l||!!f,sourceText:(B=(R=u==null?void 0:u.source)==null?void 0:R.issue)==null?void 0:B[$.key],value:O($.key),onChange:ne($.key)},$.key)})]}),(((oe=u==null?void 0:u.source)==null?void 0:oe.sections)||[]).map(($,R)=>e.jsxs("div",{style:{...J,opacity:$.included===!1?.55:1},children:[e.jsxs("div",{style:{fontSize:".7rem",letterSpacing:".18em",textTransform:"uppercase",color:t.gold,fontFamily:d,marginBottom:"1rem",paddingBottom:6,borderBottom:`1px solid ${t.creamDark}`,display:"flex",justifyContent:"space-between",gap:10},children:[e.jsxs("span",{children:["Card ",R+1]}),$.included===!1&&e.jsx("span",{style:{color:t.muted,letterSpacing:".06em"},children:"Excluded â not sent, not translated"})]}),pt.map(B=>e.jsx(De,{field:B,lang:c,disabled:l||!!f,sourceText:$[B.key],value:P($.id,B.key),onChange:v($.id,B.key)},B.key))]},$.id)),e.jsx("div",{style:{fontFamily:d,fontSize:".78rem",color:t.muted,padding:"0 4px 8px"},children:"Web addresses and images are shared by all four languages and are not translated â a translated link
1would be a broken link."})]})}),!l&&e.jsxs("div",{style:{padding:"0.85rem 1.2rem",borderTop:`1px solid ${t.border}`,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("button",{onClick:W,disabled:!!f,title:g==="ready"?`${V[c]} is approved. Unmark it ready before regenerating.`:void 0,style:N({opacity:f?.6:1}),children:f==="generate"?"Translatingâ¦":`Translate into ${V[c]} with AI`}),e.jsx("button",{onClick:X,disabled:!k||!!f,style:{...Q(t.navy),opacity:!k||f?.45:1},children:f==="save"?"Savingâ¦":"Save changes"}),e.jsx("div",{style:{flex:1}}),g==="draft"&&e.jsx("button",{onClick:()=>A("reviewed"),disabled:k||!!f,title:k?"Save your changes first":void 0,style:N({opacity:k||f?.45:1}),children:"Mark reviewed"}),(g==="reviewed"||g==="draft")&&e.jsx("button",{onClick:()=>A("ready"),disabled:k||!!f,title:k?"Save your changes first":void 0,style:{...Q(t.success),opacity:k||f?.45:1},children:"Mark ready to send"}),g==="ready"&&e.jsx("button",{onClick:()=>A("draft"),disabled:!!f,style:N(),children:"Unmark ready"})]})]})})}const We=5;function xt({api:s,issueId:n,onClose:l,showToast:a,readiness:r=null,initialLanguage:m="en"}){const[u,x]=o.useState(""),[c,_]=o.useState(me.includes(m)?m:"en"),[C,T]=o.useState(!1),[y,j]=o.useState(null),[f,F]=o.useState(null),h=u.split(/[,\s;]+/).map(i=>i.trim()).filter(Boolean).slice(0,We),L=h.length>0&&h.every(i=>/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(i));async function w(){var i;T(!0),j(null);try{const g=await s.testSend(n,h,c);F(g),g.attempted-g.sent===0?a==null||a("success",`${V[c]} test sent to ${g.sent} address${g.sent===1?"":"es"}.`):a==null||a("error",`${g.sent} of ${g.attempted} test emails sent.`)}catch(g){j(((i=g.body)==null?void 0:i.error)||g.message)}finally{T(!1)}}return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send a test",style:{position:"fixed",inset:0,background:"rgba(13,31,48,0.55)",zIndex:1001,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"},onClick:i=>{i.target===i.currentTarget&&l()},children:e.jsxs("div",{style:{background:t.white,borderRadius:4,width:"100%",maxWidth:470,border:`1px solid ${t.border}`,padding:"1.6rem"},children:[e.jsx("div",{style:{fontSize:".7rem",letterSpacing:".16em",textTransform:"uppercase",color:t.gold,fontFamily:d,marginBottom:8},children:"Send a test"}),e.jsxs("p",{style:{fontFamily:d,fontSize:".84rem",color:t.muted,lineHeight:1.55,marginTop:0},children:["Sends this draft to the addresses you type below â ",e.jsx("strong",{children:"not"})," to your subscribers. The issue stays a draft."]}),y&&e.jsx("div",{style:{marginBottom:"1rem"},children:e.jsx(se,{children:y})}),!f&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{style:{fontSize:".7rem",letterSpacing:".1em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:6},children:"Language to test"}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:me.map(i=>{const g=i===c;return e.jsxs("button",{onClick:()=>_(i),"aria-pressed":g,title:V[i],style:{...g?Q(t.navy,{padding:"4px 10px"}):N({padding:"4px 10px"}),textTransform:"none",letterSpacing:0,fontSize:".8rem",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx("span",{lang:i,dir:ce(i)?"rtl":"ltr",children:ue[i]}),i!=="en"&&(r==null?void 0:r[i])&&e.jsx(we,{status:r[i].status,small:!0})]},i)})}),c!=="en"&&(r==null?void 0:r[c])&&r[c].status!=="ready"&&e.jsxs("div",{style:{fontFamily:d,fontSize:".76rem",color:t.warn,marginTop:7},children:["This ",V[c]," version is not approved yet. You can still test it â that is how you check it before approving."]})]}),e.jsxs("label",{htmlFor:"test-recipients",style:{display:"block",fontSize:".7rem",letterSpacing:".1em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:4},children:["Test addresses (up to ",We,")"]}),e.jsx("textarea",{id:"test-recipients",rows:2,value:u,onChange:i=>x(i.target.value),placeholder:"[email protected], [email protected]",style:{...Z,width:"100%",boxSizing:"border-box",resize:"vertical"}}),e.jsxs("div",{style:{fontSize:".74rem",color:t.muted,fontFamily:d,marginTop:6,minHeight:18},children:[h.length>0&&!L&&"One of those does not look like an email address.",h.length>0&&L&&`Will send to ${h.length} address${h.length===1?"":"es"}.`]}),e.jsxs("div",{style:{display:"flex",gap:10,marginTop:"1.2rem"},children:[e.jsx("button",{onClick:w,disabled:!L||C,style:{...Q(t.navy),opacity:!L||C?.5:1},children:C?"Sendingâ¦":"Send test"}),e.jsx("button",{onClick:l,disabled:C,style:N(),children:"Cancel"})]})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("ul",{style:{fontFamily:d,fontSize:".84rem",lineHeight:1.8,paddingLeft:"1.1rem",margin:"0 0 1rem"},children:f.results.map(i=>e.jsxs("li",{style:{color:i.ok?t.success:t.danger},children:[i.recipient," â ",i.ok?"sent":`failed (${String(i.failure||"unknown").replace(/_/g," ")})`]},i.recipient))}),e.jsxs("div",{style:{fontSize:".78rem",color:t.muted,fontFamily:d,marginBottom:"1rem"},children:["The issue is still ",e.jsx("strong",{children:f.issueStatus}),". Sending a test never marks it sent."]}),e.jsx("button",{onClick:l,style:Q(t.navy),children:"Done"})]})]})})}const He="SEND";function bt(){var n,l;const s=((l=(n=globalThis.crypto)==null?void 0:n.randomUUID)==null?void 0:l.call(n))||`${Date.now()}-${Math.random()}`;return`send-${String(s).replace(/[^A-Za-z0-9_-]/g,"")}`.slice(0,60)}function jt({api:s,issue:n,tags:l=[],onClose:a,onSent:r,showToast:m}
1){const[u,x]=o.useState("audience"),[c,_]=o.useState(null),[C,T]=o.useState([]),[y,j]=o.useState(""),[f,F]=o.useState([]),[h,L]=o.useState(null),[w,i]=o.useState(!1),[g,p]=o.useState(null),[k,O]=o.useState(""),[P,ne]=o.useState(null),[v,W]=o.useState(null),X=o.useRef(bt()),A=o.useRef(!1);o.useEffect(()=>()=>{A.current=!0},[]);const K=y==="all"?{type:"all"}:{type:"tags",tags:f,match:"any"},D=y==="all"||y==="tags",ie=o.useCallback(async()=>{var G;if(!D){L(null);return}i(!0),p(null);try{const Y=await s.audiencePreview(n.id,K);L(Y.audience),_(Y.readiness||null),T(Y.sendable===!1?Y.blocking||[]:[])}catch(Y){p(((G=Y.body)==null?void 0:G.error)||Y.message),L(null),_(null),T([])}finally{i(!1)}},[s,n.id,y,D,f.join(",")]);o.useEffect(()=>{ie()},[ie]);async function z(){var G;i(!0),p(null),x("sending");try{const Y=await s.sendCampaign(n.id,{audience:K,confirmationToken:X.current,expectedRecipientCount:h.eligibleCount});ne(Y.campaign),await ee(Y.campaign.id)}catch(Y){p(((G=Y.body)==null?void 0:G.error)||Y.message),x("confirm")}finally{i(!1)}}async function ee(G){var ae;let Y=0;for(;;){if(A.current)return;let re;try{re=await s.sendBatch(G)}catch(oe){p(((ae=oe.body)==null?void 0:ae.error)||oe.message);return}if(W(re),re.done){x("done"),m==null||m("success",`Newsletter sent to ${re.campaignStatus==="sent"?"all":"the"} recipients.`),r==null||r(G);return}if(Y+=1,Y>500)return;await new Promise(oe=>setTimeout(oe,400))}}const le=k.trim().toUpperCase()===He&&(h==null?void 0:h.eligibleCount)>0&&!w;return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send newsletter",style:{position:"fixed",inset:0,background:"rgba(13,31,48,0.6)",zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"},onClick:G=>{G.target===G.currentTarget&&u!=="sending"&&a()},children:e.jsxs("div",{style:{background:t.white,borderRadius:4,width:"100%",maxWidth:520,border:`1px solid ${t.border}`,padding:"1.7rem",maxHeight:"90vh",overflowY:"auto"},children:[u==="audience"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:q,children:"Choose who receives this"}),!D&&e.jsx("p",{style:{fontFamily:d,fontSize:".84rem",color:t.muted,marginTop:0},children:"Nothing is selected. Pick an audience to see how many people it reaches."}),e.jsxs("div",{style:{marginBottom:"1.2rem"},children:[e.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center",fontFamily:d,fontSize:".88rem",marginBottom:8},children:[e.jsx("input",{type:"radio",name:"aud",checked:y==="all",onChange:()=>j("all")}),"All active subscribers"]}
1),e.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center",fontFamily:d,fontSize:".88rem"},children:[e.jsx("input",{type:"radio",name:"aud",checked:y==="tags",onChange:()=>j("tags")}),"Only subscribers with certain tags"]}),y==="tags"&&e.jsxs("div",{style:{marginTop:10,paddingLeft:24,display:"flex",flexWrap:"wrap",gap:8},children:[l.length===0&&e.jsx("span",{style:{fontFamily:d,fontSize:".8rem",color:t.muted,fontStyle:"italic"},children:"No tags exist yet."}),l.map(G=>e.jsxs("label",{style:{display:"flex",gap:5,alignItems:"center",fontFamily:d,fontSize:".82rem",background:t.cream,border:`1px solid ${t.border}`,borderRadius:10,padding:"3px 9px"},children:[e.jsx("input",{type:"checkbox",checked:f.includes(G.name),onChange:Y=>F(ae=>Y.target.checked?[...ae,G.name]:ae.filter(re=>re!==G.name))}),G.name]},G.id))]})]}),g&&e.jsx("div",{style:{marginBottom:"1rem"},children:e.jsx(se,{onRetry:ie,children:g})}),w&&e.jsx(ye,{children:"Counting recipientsâ¦"}),h&&!w&&e.jsx(Ue,{preview:h}),h&&!w&&e.jsx(Me,{preview:h,readiness:c}),h&&!w&&C.length>0&&e.jsx(vt,{blocking:C}),e.jsxs("div",{style:{display:"flex",gap:10,marginTop:"1.4rem"},children:[e.jsx("button",{onClick:()=>x("confirm"),disabled:!D||w||!h||h.eligibleCount===0||C.length>0,title:C.length?"Finish the missing translations first":void 0,style:{...Q(t.navy),opacity:!D||w||!h||h.eligibleCount===0||C.length>0?.5:1},children:"Review and send"}),e.jsx("button",{onClick:a,style:N(),children:"Cancel"})]})]}),u==="confirm"&&h&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{...q,color:t.danger,borderColor:t.danger},children:"Final confirmation"}),e.jsxs("div",{style:{textAlign:"center",padding:"1rem 0 1.2rem"},children:[e.jsx("div",{style:{fontFamily:d,fontSize:".72rem",letterSpacing:".16em",textTransform:"uppercase",color:t.muted},children:"Send newsletter to"}),e.jsx("div",{style:{fontFamily:"Georgia,serif",fontSize:"2.6rem",color:t.navy,lineHeight:1.1,margin:"6px 0"},children:h.eligibleCount.toLocaleString()}),e.jsxs("div",{style:{fontFamily:d,fontSize:".82rem",color:t.muted},children:["subscriber",h.eligibleCount===1?"":"s"]})]}),e.jsxs("dl",{style:{fontFamily:d,fontSize:".84rem",margin:"0 0 1.2rem",display:"grid",gridTemplateColumns:"auto 1fr",gap:"6px 14px"},children:[e.jsx("dt",{style:{color:t.muted},children:"Issue"}),e.jsx("dd",{style:{margin:0,color:t.text},children:n.title}),e.jsx("dt",{style:{color:t.muted},children:"Subject"}),e.jsx("dd",{style:{margin:0,color:t.text},children:n.subject||"(none)"}),e.jsx("dt",{style:{color:t.muted},children:"Audience"}),e.jsx("dd",{style:{margin:0,color:t.text},children:h.description})]}),e.jsx(Ue,{preview:h}),e.jsx(Me,{preview:h,readiness:c}),e.jsx("div",{style:{background:t.cream,border:`1px solid ${t.border}`,borderRadius:3,padding:"10px 12px",margin:"1.2rem 0",fontFamily:d,fontSize:".8rem",color:t.muted,lineHeight:1.55},children:"These counts are checked again the moment you send. If someone unsubscribes in between, the send is stopped and you will be asked to confirm the new number."}),g&&e.jsx("div",{style:{marginBottom:"1rem"},children:e.jsx(se,{children:g})}),e.jsxs("label",{htmlFor:"confirm-word",style:{display:"block",fontFamily:d,fontSize:".82rem",color:t.text,marginBottom:6},children:["Type ",e.jsx("strong",{children:He})," to confirm"]}),e.jsx("input",{id:"confirm-word",value:k,onChange:G=>O(G.target.value),autoComplete:"off",style:{...Z,width:"100%",boxSizing:"border-box",letterSpacing:".2em",textAlign:"center",fontSize:"1rem"}}),e.jsxs("div",{style:{display:"flex",gap:10,marginTop:"1.2rem"},children:[e.jsxs("button",{onClick:z,disabled:!le,style:{...Q(t.danger),opacity:le?1:.45,cursor:le?"pointer":"not-allowed"},children:["Send to ",h.eligibleCount.toLocaleString()," subscriber",h.eligibleCount===1?"":"s"]}),e.jsx("button",{onClick:()=>x("audience"),style:N(),children:"Back"})]})]}),u==="sending"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:q,children:"Sending"}),e.jsx("p",{style:{fontFamily:d,fontSize:".86rem",color:t.muted,lineHeight:1.55},children:"Going out in batches. You can close this window â sending continues on the server and picks up where it left off if anything is interrupted."}),v&&e.jsxs("div",{style:{fontFamily:d,fontSize:".9rem",color:t.navy,marginTop:10},children:[e.jsx("strong",{children:v.remaining})," remaining",v.failed>0&&e.jsxs("span",{style:{color:t.danger},children:[" · ",v.failed," failed"]})]}),g&&e.jsx("div",{style:{marginTop:"1rem"},children:e.jsx(se,{children:g})}),e.jsx("button",{onClick:a,style:{...N(),marginTop:"1.2rem"},children:"Close"})]}),u==="done"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:q,children:"Sent"}),e.jsx("p",{style:{fontFamily:d,fontSize:".9rem",color:t.text,lineHeight:1.6},children:"The newsletter has gone out. Delivery results appear in Analytics as the email provider reports them."}),(v==null?void 0:v.failed)>0&&e.jsxs("p",{style:{fontFamily:d,fontSize:".84rem",color:t.danger},children:[v.failed," recipient",v.failed===1?"":"s"," could not be delivered to. See Analytics for detail."]}),e.jsx("button",{onClick:a,style:{...Q(t.navy),marginTop:"1rem"},children:"Done"})]})]})})}function Ue({preview:s}
1){const n=[{label:"Matched this audience",value:s.matched,tone:t.text},{label:"Removed (unsubscribed, bounced, complained)",value:s.suppressedRemoved,tone:t.warn},{label:"Will receive this newsletter",value:s.eligibleCount,tone:t.success,strong:!0}];return e.jsxs("div",{style:{border:`1px solid ${t.border}`,borderRadius:3,overflow:"hidden"},children:[n.map((l,a)=>e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 12px",fontFamily:d,fontSize:".84rem",background:a===n.length-1?t.cream:t.white,borderTop:a?`1px solid ${t.creamDark}`:"none"},children:[e.jsx("span",{style:{color:t.muted},children:l.label}),e.jsx("span",{style:{color:l.tone,fontWeight:l.strong?700:400,fontSize:l.strong?".95rem":".84rem"},children:Number(l.value||0).toLocaleString()})]},l.label)),s.suppressedRemoved>0&&s.suppressedByStatus&&e.jsxs("div",{style:{padding:"8px 12px",borderTop:`1px solid ${t.creamDark}`,fontFamily:d,fontSize:".76rem",color:t.muted},children:["Removed: ",Object.entries(s.suppressedByStatus).map(([l,a])=>`${a} ${l}`).join(", ")]})]})}function Me({preview:s,readiness:n}){const l=s==null?void 0:s.byLanguage;if(!l)return null;const a=me.filter(r=>(l[r]||0)>0);return!a.length||a.length===1&&a[0]==="en"?null:e.jsxs("div",{style:{border:`1px solid ${t.border}`,borderRadius:3,overflow:"hidden",marginTop:10},children:[e.jsx("div",{style:{padding:"7px 12px",background:t.cream,borderBottom:`1px solid ${t.creamDark}`,fontFamily:d,fontSize:".7rem",letterSpacing:".12em",textTransform:"uppercase",color:t.muted},children:"By language"}),a.map(r=>{var x;const m=r==="en"?"ready":((x=n==null?void 0:n[r])==null?void 0:x.status)||"not_generated",u=m==="ready";return e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:10,padding:"8px 12px",fontFamily:d,fontSize:".84rem",borderTop:`1px solid ${t.creamDark}`,background:u?t.white:"#fdf7ea"},children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:8},children:[e.jsx("span",{lang:r,dir:ce(r)?"rtl":"ltr",style:{color:t.text,fontWeight:700},children:ue[r]}),e.jsx("span",{style:{color:t.muted,fontSize:".78rem"},children:V[r]}),r==="en"?e.jsx("span",{style:{fontSize:".64rem",letterSpacing:".06em",textTransform:"uppercase",color:t.muted},children:"Original"}):e.jsx(we,{status:m,small:!0})]}),e.jsx("span",{style:{color:u?t.text:t.warn,fontWeight:700},children:Number(l[r]||0).toLocaleString()})]},r)})]})}function vt({blocking:s}){return e.jsxs("div",{style:{marginTop:10,padding:"0.9rem 1rem",background:"#fdf7ea",border:`1px solid ${t.warn}`,borderRadius:3,fontFamily:d},children:[e.jsx("div",{style:{fontSize:".84rem",color:t.warn,fontWeight:700,marginBottom:6},children:"This send is blocked until these translations are ready"}),e.jsx("ul",{style:{margin:"0 0 8px",paddingLeft:"1.1rem",fontSize:".83rem",color:t.text,lineHeight:1.7},children:s.map(n=>e.jsxs("li",{children:[e.jsx("strong",{children:V[n.language]})," â ",n.recipients.toLocaleString()," ","recipient",n.recipients===1?"":"s"," read in ",V[n.language],", and that version is"," ",String(n.status).replace("_"," "),"."]},n.language))}),e.jsxs("div",{style:{fontSize:".79rem",color:t.muted,lineHeight:1.6},children:["Open ",e.jsx("strong",{children:"Translations"})," to finish them, or choose an audience that does not include these readers. They are not sent the English version instead â they chose their language, and that choice is honoured."]})]})}const $e={display:"block",fontSize:".7rem",letterSpacing:".1em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:4},fe={...Z,width:"100%",boxSizing:"border-box"},Je=s=>({id:s.id,categoryLabel:s.category_label||"",headline:s.headline||"",body:s.body||"",url:s.url||"",linkText:s.link_text||"",imageUrl:s.image_url||"",included:s.included!==!1,contentLibraryId:s.content_library_id||null});function St({api:s,issueId:n,onClose:l,onChanged:a,showToast:r}){const[m,u]=o.useState(null),[x,c]=o.useState([]),[_,C]=o.useState(!0),[T,y]=o.useState(!1),[j,f]=o.useState(null),[F,h]=o.useState(!1),[L,w]=o.useState(null),[i,g]=o.useState(!1),[p,k]=o.useState(!1),[O,P]=o.useState(null),[ne,v]=o.useState([]),[W,X]=o.useState(!1),[A,K]=o.useState([]),[D,ie]=o.useState(!1),[z,ee]=o.useState(null),[le,G]=o.useState("en"),[Y,ae]=o.useState("en"),[re,oe]=o.useState([]),$=o.useCallback(async()=>{var b;C(!0),f(null);try{const S=await s.getIssue(n);
1u(S.issue),c((S.sections||[]).map(Je)),h(!1)}catch(S){f(((b=S.body)==null?void 0:b.error)||S.message)}finally{C(!1)}},[s,n]);o.useEffect(()=>{$()},[$]);const R=o.useCallback(async()=>{try{const b=await s.getTranslations(n);ee(b.readiness)}catch{}},[s,n]);o.useEffect(()=>{R()},[R]),o.useEffect(()=>{s.listLibrary({limit:100}).then(b=>v(b.items||[])).catch(()=>v([]))},[s]),o.useEffect(()=>{var b;(b=s.listBlogPosts)==null||b.call(s,{limit:200}).then(S=>oe((S.posts||[]).filter(I=>I.issueId===n))).catch(()=>oe([]))},[s,n]),o.useEffect(()=>{var b;(b=s.listTags)==null||b.call(s).then(S=>K(S.tags||[])).catch(()=>K([]))},[s]);const B=m&&["sending","sent"].includes(m.status),U=b=>S=>{u(I=>({...I,[b]:S.target.value})),h(!0)},te=(b,S,I)=>{c(de=>de.map((he,et)=>et===b?{...he,[S]:I}:he)),h(!0)};function pe(b,S){c(I=>{const de=[...I],he=b+S;return he<0||he>=de.length?I:([de[b],de[he]]=[de[he],de[b]],de)}),h(!0)}function be(){c(b=>[...b,{id:null,categoryLabel:"",headline:"",body:"",url:"",linkText:"",imageUrl:"",included:!0}]),h(!0)}function Xe(b){c(S=>S.filter((I,de)=>de!==b)),h(!0)}async function Ae(){var b;y(!0),f(null);try{await s.updateIssue(n,{title:m.title,subject:m.subject||"",preheader:m.preheader||"",openingContent:m.opening_content||"",publicationDate:m.publication_date||""});const S=await s.saveSections(n,x.map((I,de)=>({...I,sortOrder:de})));return c((S.sections||[]).map(Je)),h(!1),r==null||r("success","Draft saved."),a==null||a(),!0}catch(S){return f(((b=S.body)==null?void 0:b.error)||S.message),!1}finally{y(!1)}}async function Ce(){return F?Ae():!0}async function Ne(b="en"){var S;g(!0),f(null);try{if(!await Ce())return;const I=await s.previewIssue(n,b);w(I),G(I.language||b),I.readiness&&ee(I.readiness),P(I.preflight)}catch(I){f(((S=I.body)==null?void 0:S.error)||I.message)}finally{g(!1)}}async function qe(b){var S;g(!0);try{const I=await s.previewIssue(n,b);w(I),G(I.language||b),P(I.preflight)}catch(I){r==null||r("error",((S=I.body)==null?void 0:S.error)||I.message)}finally{g(!1)}}async function Ke(){var b;try{if(!await Ce())return;const S=await s.preflightIssue(n);if(P(S.preflight),S.preflight.ok){const I=await s.updateIssue(n,{status:"ready"});u(I.issue),r==null||r("success","Issue marked ready."),a==null||a()}else r==null||r("error","Not ready yet â see the checks below.")}catch(S){f(((b=S.body)==null?void 0:b.error)||S.message)}}async function Ee(b="en"){await Ce()&&(ae(me.includes(b)?b:"en"),k(!0))}async function Ze(){await Ce()&&X(!0)}async function Qe(b){var S;if(b)try{if(!await Ce())return;await s.insertLibraryItem(n,b),await $(),r==null||r("success","Library item added as a card.")}catch(I){f(((S=I.body)==null?void 0:S.error)||I.message)}}return _?e.jsx(ye,{children:"Loading issueâ¦"}):m?e.jsxs("div",{style:{padding:"1.5rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:12,marginBottom:"1.2rem",flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{...q,border:"none",margin:0,padding:0},children:"Issue"}),e.jsx("div",{style:{fontFamily:"Georgia,serif",fontSize:"1.3rem",color:t.navy,marginTop:6},children:m.title}),e.jsxs("div",{style:{fontSize:".76rem",color:t.muted,fontFamily:d,marginTop:4},children:["Status: ",e.jsx("strong",{children:m.status}),F&&" · unsaved changes"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[e.jsx("button",{onClick:()=>Ne("en"),disabled:i,style:N(),children:i?"Renderingâ¦":"Preview"}),e.jsx("button",{onClick:()=>ie(!0),style:N(),children:"Translations"}),e.jsx("button",{onClick:()=>Ee("en"),disabled:T,style:N(),children:"Send test"}),m.status==="ready"&&e.jsx("button",{onClick:Ze,disabled:T,style:Q(t.danger),children:"Send to subscribersâ¦"}),e.jsx("button",{onClick:Ae,disabled:T||B,style:{...Q(t.navy),opacity:T||B?.5:1},children:T?"Savingâ¦":"Save draft"}),e.jsx("button",{onClick:l,style:N(),children:"Close"})]})]}),B&&e.jsxs("div",{style:{...J,background:t.cream,borderColor:t.gold},children:[e.jsx("strong",{style:{fontFamily:d,fontSize:".86rem",color:t.navy},children:"This issue has been sent."}),e.jsx("div",{style:{fontFamily:d,fontSize:".82rem",color:t.muted,marginTop:6},children:"Sent issues are kept exactly as they went out. Duplicate it from the Issues list to start a new one."})]}),j&&e.jsx("div",{style:{marginBottom:"1.2rem"},children:e.jsx(se,{children:j})}),re.length>0&&e.jsxs("div",{style:{...J,background:t.cream,borderColor:t.gold,display:"flex",gap:8,alignItems:"baseline",flexWrap:"wrap"},children:[e.jsxs("strong",{style:{fontFamily:d,fontSize:".82rem",color:t.navy},children:["Created from ",re.length," Legal Beagle blog post",re.length===1?"":"s","."]}),e.jsx("span",{style:{fontFamily:d,fontSize:".78rem",color:t.muted},children:"Every card is fully editable â this note never appears in the newsletter itself."})]}),z&&e.jsxs("div",{style:{...J,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("div",{style:{fontSize:".7rem",letterSpacing:".14em",textTransform:"uppercase",color:t.gold,fontFamily:d},children:"Languages"}),me.map(b=>{var S;return e.jsxs("button",{onClick:()=>b==="en"?Ne("en"):ie(!0),title:b==="en"?"Preview the English version":`Open the ${V[b]} translation`,style:{...N({padding:"5px 11px"}),textTransform:"none",letterSpacing:0,fontSize:".82rem",display:"inline-flex",alignItems:"center",gap:7},children:[e.jsx("span",{lang:b,dir:ce(b)?"rtl":"ltr",children:ue[b]}),b==="en"?e.jsx("span",{style:{fontSize:".64rem",letterSpacing:".06em",textTransform:"uppercase",color:t.muted},children:"Original"}):e.jsx(we,{status:(S=z[b])==null?void 0:S.status,small:!0})]},b)}),e.jsx("div",{style:{flex:1}}),e.jsxs("div",{style:{fontFamily:d,fontSize:".76rem",color:t.muted},children:["Only languages marked ",e.jsx("strong",{children:"Ready"})," can be sent."]})]}),e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Email details"}),e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:$e,htmlFor:"iss-title",children:"Internal title"}),e.jsx("input",{id:"iss-title",style:fe,value:m.title||"",onChange:U("title"),disabled:B})]}),e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:$e,htmlFor:"iss-subject",children:"Subject line"}),e.jsx("input",{id:"iss-subject",style:fe,value:m.subject||"",onChange:U("subject"),disabled:B})]}),e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:$e,htmlFor:"iss-preheader",children:"Preview line"}),e.jsx("input",{id:"iss-preheader",style:fe,value:m.preheader||"",onChange:U("preheader"),disabled:B,placeholder:"The line inboxes show next to the subject"})]}),e.jsx("div",{style:{display:"flex",gap:"1rem",flexWrap:"wrap"},children:e.jsxs("div",{style:{flex:"1 1 160px"},children:[e.jsx("label",{style:$e,htmlFor:"iss-date",children:"Publication date"}),e.jsx("input",{id:"iss-date",type:"date",style:fe,value:m.publication_date||"",onChange:U("publication_date"),disabled:B})]})}),e.jsxs("div",{style:{marginTop:"1rem"},children:[e.jsx("label",{style:$e,htmlFor:"iss-opening",children:"Opening note (optional)"}),e.jsx("textarea",{id:"iss-opening",rows:3,style:{...fe,resize:"vertical"},value:m.opening_content||"",onChange:U("opening_content"),disabled:B})]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10,flexWrap:"wrap",gap:10},children:[e.jsxs("div",{style:{...q,border:"none",margin:0,padding:0},children:["Content cards (",x.length,")"]}),!B&&e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsxs("select",{"aria-label":"Insert from content library",defaultValue:"",onChange:b=>{Qe(b.target.value),b.target.value=""},style:Z,children:[e.jsx("option",{value:"",children:"Insert from libraryâ¦"}),ne.map(b=>e.jsx("option",{value:b.id,children:b.title},b.id))]}),e.jsx("button",{onClick:be,style:N(),children:"ï¼ Add card"})]})]}),x.map((b,S)=>e.jsxs("div",{style:{...J,opacity:b.included?1:.6,borderLeft:`3px solid ${b.included?t.gold:t.border}`},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12,gap:10,flexWrap:"wrap"},children:[e.jsx("input",{"aria-label":`Card ${S+1} category`,value:b.categoryLabel,disabled:B,onChange:I=>te(S,"categoryLabel",I.target.value),placeholder:"Category label",style:{...Z,flex:"1 1 200px",fontWeight:700,letterSpacing:".08em",textTransform:"uppercase",fontSize:".74rem",color:t.gold}}),!B&&e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[e.jsx("button",{onClick:()=>pe(S,-1),disabled:S===0,"aria-label":`Move card ${S+1} up`,style:N({padding:"4px 9px",opacity:S===0?.35:1}),children:"â"}),e.jsx("button",{onClick:()=>pe(S,1),disabled:S===x.length-1,"aria-label":`Move card ${S+1} down`,style:N({padding:"4px 9px",opacity:S===x.length-1?.35:1}),children:"â"}),e.jsxs("label",{style:{display:"flex",gap:5,alignItems:"center",fontSize:".76rem",fontFamily:d,color:t.muted},children:[e.jsx("input",{type:"checkbox",checked:b.included,"aria-label":`Include card ${S+1}`,onChange:I=>te(S,"included",I.target.checked)}),"Include"]}),e.jsx("button",{onClick:()=>Xe(S),"aria-label":`Delete card ${S+1}`,style:N({padding:"4px 9px",color:t.danger,borderColor:t.border}),children:"Delete"})]})]}),e.jsx("input",{"aria-label":`Card ${S+1} headline`,value:b.headline,disabled:B,onChange:I=>te(S,"headline",I.target.value),placeholder:"Headline",style:{...fe,marginBottom:10,fontFamily:"Georgia,serif",fontSize:"1rem"}}),e.jsx("textarea",{"aria-label":`Card ${S+1} body`,rows:4,value:b.body,disabled:B,onChange:I=>te(S,"body",I.target.value),placeholder:"Body text. Leave a blank line between paragraphs.",style:{...fe,marginBottom:10,resize:"vertical"}}),e.jsxs("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:[e.jsx("input",{"aria-label":`Card ${S+1} link URL`,value:b.url,disabled:B,onChange:I=>te(S,"url",I.target.value),placeholder:"https://⦠(optional link)",style:{...Z,flex:"2
11 240px"}}),e.jsx("input",{"aria-label":`Card ${S+1} link text`,value:b.linkText,disabled:B,onChange:I=>te(S,"linkText",I.target.value),placeholder:"Link text",style:{...Z,flex:"1 1 140px"}}),e.jsx("input",{"aria-label":`Card ${S+1} image URL`,value:b.imageUrl,disabled:B,onChange:I=>te(S,"imageUrl",I.target.value),placeholder:"https://⦠(optional image)",style:{...Z,flex:"2 1 240px"}})]}),re.some(I=>I.canonicalUrl&&I.canonicalUrl===b.url)&&e.jsx("div",{style:{fontSize:".7rem",color:t.gold,fontFamily:d,marginTop:10,letterSpacing:".08em",textTransform:"uppercase",fontWeight:700},children:"From the blog"}),!b.included&&e.jsx("div",{style:{fontSize:".76rem",color:t.muted,fontFamily:d,marginTop:10,fontStyle:"italic"},children:"Not included â this card will not appear in the newsletter."})]},b.id||`new-${S}`)),!B&&e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Before sending"}),O?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontFamily:d,fontSize:".86rem",color:O.ok?t.success:t.danger,marginBottom:10},children:O.ok?"â This issue passes every check.":"This issue is not ready yet."}),O.errors.length>0&&e.jsx("ul",{style:{fontFamily:d,fontSize:".82rem",color:t.danger,lineHeight:1.7,paddingLeft:"1.1rem",marginTop:0},children:O.errors.map((b,S)=>e.jsx("li",{children:b.message},S))}),O.warnings.length>0&&e.jsx("ul",{style:{fontFamily:d,fontSize:".82rem",color:t.warn,lineHeight:1.7,paddingLeft:"1.1rem"},children:O.warnings.map((b,S)=>e.jsx("li",{children:b.message},S))}),e.jsx("div",{style:{fontSize:".74rem",color:t.muted,fontFamily:d,marginTop:8},children:"Links are checked for correct format only â not for whether the page loads."})]}):e.jsx("p",{style:{fontFamily:d,fontSize:".84rem",color:t.muted,marginTop:0},children:"Run the checks to confirm the subject, content, links, and footer are all in place."}),e.jsx("button",{onClick:Ke,style:{...N(),marginTop:10},children:"Run checks & mark ready"})]}),L&&e.jsx(mt,{preview:L,language:le,onLanguage:qe,readiness:z,busy:i,onClose:()=>w(null),onSendTest:()=>{w(null),Ee(le)}}),p&&e.jsx(xt,{api:s,issueId:n,showToast:r,readiness:z,initialLanguage:Y,onClose:()=>k(!1)}),D&&e.jsx(ft,{api:s,issueId:n,frozen:B,showToast:r,onClose:()=>ie(!1),onChanged:()=>{R(),a==null||a()}}),W&&e.jsx(jt,{api:s,issue:m,tags:A,showToast:r,onClose:()=>{X(!1),$()},onSent:()=>{$(),a==null||a()}})]}):e.jsx(se,{onRetry:$,children:j||"Issue not found."})}const Te=10,Ye={eligible:{label:"Available",bg:"#e8f2ec",fg:t.success,selectable:!0},baseline:{label:"Historical",bg:t.creamDark,fg:t.muted,selectable:!0},consumed:{label:"Already used",bg:"#e8eef5",fg:t.navy,selectable:!0},claimed:{label:"In progress",bg:"#f7edcc",fg:t.warn,selectable:!1},unavailable:{label:"Unavailable",bg:t.creamDark,fg:t.muted,selectable:!1}};function kt({status:s}){const n=Ye[s]||{label:s||"â",bg:t.creamDark,fg:t.muted};return e.jsx("span",{style:{background:n.bg,color:n.fg,padding:"2px 8px",borderRadius:10,fontSize:".66rem",fontFamily:d,textTransform:"uppercase",fontWeight:700,whiteSpace:"nowrap"},children:n.label})}function wt({api:s,showToast:n,onClose:l,onCreated:a}){const[r,m]=o.useState([]),[u,x]=o.useState(!0),[c,_]=o.useState(null),[C,T]=o.useState(!1),[y,j]=o.useState(()=>new Set),[f,F]=o.useState(!0),[h,L]=o.useState(!1),[w,i]=o.useState(null),g=o.useCallback(async()=>{var v;x(!0),_(null);try{const W=await s.listBlogPosts({refresh:"true",limit:100});m(W.posts||[]),T(W.refreshFailed===!0),W.unavailable&&_("Blog tracking is not available on the server yet.")}catch(W){_(((v=W.body)==null?void 0:v.error)||W.message)}finally{x(!1)}},[s]);o.useEffect(()=>{g()},[g]);const p=new Map(r.map(v=>[v.id,v])),k=[...y].map(v=>p.get(v)).filter(Boolean),O=k.filter(v=>v.status==="consumed").length;function P(v){i(null),j(W=>{const X=new Set(W);if(X.has(v.id))return X.delete(v.id),X;if(X.size>=Te)return W;if(v.status==="consumed"){const A=v.issueTitle?` in â${v.issueTitle}â`:" in another newsletter";if(!window.confirm(`â${v.title}â has already been used${A}. Use it again?`))return W}return X.add(v.id),X})}async function ne(){var v;if(!(h||y.size===0)){L(!0),i(null);try{const W=await s.buildIssueFromBlog({postIds:[...y],useAI:f,...O>0?{reuseConsumed:!0}:{}});a==null||a(W.issue,k.length)}catch(W){i(((v=W.body)==null?void 0:v.error)||W.message),L(!1)}}}return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Build draft from blog posts",style:{position:"fixed",inset:0,background:"rgba(13,3
11,48,0.55)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"},onClick:v=>{v.target===v.currentTarget&&!h&&l()},children:e.jsxs("div",{style:{background:t.white,borderRadius:4,width:"100%",maxWidth:680,border:`1px solid ${t.border}`,maxHeight:"90vh",overflowY:"auto",padding:"1.2rem 1.4rem"},children:[e.jsx("div",{style:q,children:"Build draft from blog posts"}),e.jsxs("p",{style:{fontFamily:d,fontSize:".82rem",color:t.muted,lineHeight:1.55,marginTop:0},children:["Pick 1â",Te," recent articles. This creates an ordinary ",e.jsx("strong",{children:"draft"})," â you edit and send it exactly like any other issue. Nothing is sent automatically."]}),C&&e.jsx("div",{style:{background:t.cream,border:`1px solid ${t.border}`,borderRadius:3,padding:"8px 10px",marginBottom:10,fontFamily:d,fontSize:".78rem",color:t.muted},children:"Couldnât refresh from the blog just now â showing the most recently known posts."}),c&&e.jsx("div",{style:{marginBottom:10},children:e.jsx(se,{onRetry:g,children:c})}),u&&e.jsx(ye,{children:"Loading blog postsâ¦"}),!u&&!c&&r.length===0&&e.jsx(xe,{children:"No tracked blog posts yet."}),!u&&r.length>0&&e.jsx("div",{style:{border:`1px solid ${t.border}`,borderRadius:3,marginBottom:12,maxHeight:320,overflowY:"auto"},children:r.map(v=>{const W=Ye[v.status]||{},X=y.has(v.id),A=!W.selectable||h||!X&&y.size>=Te;return e.jsxs("label",{style:{display:"flex",gap:10,alignItems:"flex-start",padding:"8px 10px",borderBottom:`1px solid ${t.border}`,opacity:W.selectable?1:.55,cursor:W.selectable?"pointer":"default"},children:[e.jsx("input",{type:"checkbox",checked:X,disabled:A,"aria-label":`Select post: ${v.title}`,onChange:()=>P(v),style:{marginTop:3}}),e.jsxs("span",{style:{flex:1},children:[e.jsx("span",{style:{fontFamily:"Georgia,serif",fontSize:".92rem",color:t.navy,display:"block"},children:v.title}),e.jsxs("span",{style:{fontFamily:d,fontSize:".74rem",color:t.muted},children:[v.publishedAt?ge(v.publishedAt):"â",v.category?` · ${v.category}`:"",v.status==="consumed"&&v.issueTitle?` · used in â${v.issueTitle}â`:""]})]}),e.jsx(kt,{status:v.status})]},v.id)})}),e.jsxs("label",{style:{display:"flex",gap:8,alignItems:"flex-start",fontFamily:d,fontSize:".84rem",color:t.navy,marginBottom:4},children:[e.jsx("input",{type:"checkbox",checked:f,disabled:h,onChange:v=>F(v.target.checked),style:{marginTop:3}}),e.jsxs("span",{children:["Generate newsletter teaser copy with AI",e.jsxs("span",{style:{display:"block",fontSize:".76rem",color:t.muted},children:["Creates editable newsletter copy from the selected blog posts. Nothing is sent automatically."," ","Turned off, each card starts from the articleâs own excerpt instead."]})]})]}),w&&e.jsx("div",{style:{margin:"10px 0"},children:e.jsx(se,{children:w})}),e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",marginTop:12,flexWrap:"wrap"},children:[e.jsx("button",{onClick:ne,disabled:h||y.size===0,style:{...Q(t.navy),opacity:h||y.size===0?.5:1},children:h?"Creating draftâ¦":`Create draft from ${y.size||"â¦"} post${y.size===1?"":"s"}`}),e.jsx("button",{onClick:l,disabled:h,style:N(),children:"Cancel"}),e.jsx("span",{style:{fontFamily:d,fontSize:".76rem",color:t.muted},children:h?"AI drafting can take up to a minute â leave this open.":O>0?`Includes ${O} already-used post${O===1?"":"s"} (confirmed).`:`${y.size}/${Te} selected.`})]})]})})}const Ct={draft:{bg:t.creamDark,fg:t.muted,label:"Draft"},ready:{bg:"#e8f2ec",fg:t.success,label:"Ready"},scheduled:{bg:"#f7edcc",fg:t.warn,label:"Scheduled"},sending:{bg:"#f7edcc",fg:t.warn,label:"Sending"},sent:{bg:"#e8eef5",fg:t.navy,label:"Sent"},archived:{bg:t.creamDark,fg:t.muted,label:"Archived"}};function $t({status:s}){const n=Ct[s]||{bg:t.creamDark,fg:t.muted,label:s||"â"};return e.jsx("span",{style:{background:n.bg,color:n.fg,padding:"2px 8px",borderRadius:10,fontSize:".7rem",fontFamily:d,textTransform:"uppercase",fontWeight:700,whiteSpace:"nowrap"},children:n.label})}function zt({api:s,showToast:n}){const[l,a]=o.useState([]),[r,m]=o.useState(!0),[u,x]=o.useState(null),[c,_]=o.useState(null),[C,T]=o.useState(!1),[y,j]=o.useState(""),[f,F]=o.use
1State(!1),h=o.useCallback(async()=>{var i;m(!0),x(null);try{const g=await s.listIssues({limit:50});a(g.issues||[])}catch(g){x(((i=g.body)==null?void 0:i.error)||g.message)}finally{m(!1)}},[s]);o.useEffect(()=>{h()},[h]);async function L(){var g;const i=y.trim();if(i)try{const p=await s.createIssue({title:i});n==null||n("success","Issue created with the standard cards."),T(!1),j(""),await h(),_(p.issue.id)}catch(p){n==null||n("error",((g=p.body)==null?void 0:g.error)||p.message)}}async function w(i){var g;try{const p=await s.duplicateIssue(i);n==null||n("success","Issue duplicated."),await h(),_(p.issue.id)}catch(p){n==null||n("error",((g=p.body)==null?void 0:g.error)||p.message)}}return c?e.jsx(St,{api:s,issueId:c,showToast:n,onClose:()=>{_(null),h()},onChanged:h}):e.jsxs("div",{style:{padding:"1.5rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1rem",gap:10,flexWrap:"wrap"},children:[e.jsx("div",{style:{fontSize:".76rem",color:t.muted,fontFamily:d},children:r?"Loadingâ¦":`${l.length} issue${l.length===1?"":"s"}`}),!C&&e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[e.jsx("button",{onClick:()=>F(!0),style:N(),children:"Build draft from blog posts"}),e.jsx("button",{onClick:()=>T(!0),style:Q(t.navy),children:"ï¼ New issue"})]})]}),f&&e.jsx(wt,{api:s,showToast:n,onClose:()=>F(!1),onCreated:async(i,g)=>{F(!1),n==null||n("success",`Draft created from ${g} blog post${g===1?"":"s"}.`),await h(),_(i.id)}}),C&&e.jsxs("div",{style:J,children:[e.jsx("label",{htmlFor:"new-issue-title",style:{display:"block",fontSize:".7rem",letterSpacing:".1em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:4},children:"Issue title"}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[e.jsx("input",{id:"new-issue-title",value:y,onChange:i=>j(i.target.value),onKeyDown:i=>{i.key==="Enter"&&L()},placeholder:"Legal Beagle Newsletter #1",style:{...Z,flex:"1 1 260px"}}),e.jsx("button",{onClick:L,disabled:!y.trim(),style:{...Q(t.navy),opacity:y.trim()?1:.5},children:"Create"}),e.jsx("button",{onClick:()=>{T(!1),j("")},style:N(),children:"Cancel"})]}),e.jsx("div",{style:{fontSize:".78rem",color:t.muted,fontFamily:d,marginTop:8},children:"A new issue starts with the standard Legal Beagle cards, ready to fill in. You can rename, reorder, add, or remove them."})]}),u&&e.jsx(se,{onRetry:h,children:u}),!u&&e.jsxs("div",{style:{...J,padding:0,overflowX:"auto"},children:[r&&l.length===0&&e.jsx(ye,{children:"Loading issuesâ¦"}),!r&&l.length===0&&e.jsx(xe,{children:"No issues yet. Create one to get started."}),l.length>0&&e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:640},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:H,children:"Title"}),e.jsx("th",{style:H,children:"Subject"}),e.jsx("th",{style:H,children:"Status"}),e.jsx("th",{style:H,children:"Publication"}),e.jsx("th",{style:H,children:"Created"}),e.jsx("th",{style:H})]})}),e.jsx("tbody",{children:l.map(i=>e.jsxs("tr",{children:[e.jsxs("td",{style:E,children:[i.title,i.autoCreated===!0&&e.jsx("span",{style:{marginLeft:8,background:t.cream,color:t.gold,border:`1px solid ${t.gold}`,padding:"1px 7px",borderRadius:10,fontSize:".64rem",fontFamily:d,textTransform:"uppercase",fontWeight:700,letterSpacing:".06em",whiteSpace:"nowrap"},children:"Auto"})]}),e.jsx("td",{style:{...E,color:t.muted,fontSize:".8rem"},children:i.subject||"â"}),e.jsx("td",{style:E,children:e.jsx($t,{status:i.status})}),e.jsx("td",{style:{...E,color:t.muted,fontSize:".78rem",whiteSpace:"nowrap"},children:i.publication_date?ge(i.publication_date):"â"}),e.jsx("td",{style:{...E,color:t.muted,fontSize:".78rem",whiteSpace:"nowrap"},children:ge(i.created_at)}),e.jsxs("td",{style:{...E,textAlign:"right",whiteSpace:"nowrap"},children:[e.jsx("button",{onClick:()=>_(i.id),style:N({padding:"4px 10px",marginRight:6}),children:"Open"}),e.jsx("button",{onClick:()=>w(i.id),style:N({padding:"4px 10px"}),children:"Duplicate"})]})]},i.id))})]})]})]})}const ze={display:"block",fontSize:".7rem",letterSpacing:".1em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:4},Fe={...Z,width:"100%",boxSizing:"border-box"},Ft={title:"",category:"",body:"",url:"",linkText:""};function Tt({api:s,showToast:n}
1){const[l,a]=o.useState([]),[r,m]=o.useState(""),[u,x]=o.useState(""),[c,_]=o.useState(!0),[C,T]=o.useState(null),[y,j]=o.useState(null),[f,F]=o.useState(!1),h=o.useRef(null);o.useEffect(()=>(clearTimeout(h.current),h.current=setTimeout(()=>x(r),250),()=>clearTimeout(h.current)),[r]);const L=o.useCallback(async()=>{var g;_(!0),T(null);try{const p=await s.listLibrary({search:u,limit:100});a(p.items||[])}catch(p){T(((g=p.body)==null?void 0:g.error)||p.message)}finally{_(!1)}},[s,u]);o.useEffect(()=>{L()},[L]);async function w(){var g;F(!0);try{const p={title:y.title,category:y.category,body:y.body,url:y.url,linkText:y.linkText};y.id?await s.updateLibraryItem(y.id,p):await s.createLibraryItem(p),n==null||n("success",y.id?"Library item saved.":"Library item created."),j(null),L()}catch(p){n==null||n("error",((g=p.body)==null?void 0:g.error)||p.message)}finally{F(!1)}}const i=g=>p=>j(k=>({...k,[g]:p.target.value}));return e.jsxs("div",{style:{padding:"1.5rem"},children:[e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",marginBottom:"1rem",flexWrap:"wrap"},children:[e.jsx("input",{"aria-label":"Search content library",placeholder:"Search the libraryâ¦",value:r,onChange:g=>m(g.target.value),style:{...Z,flex:"1 1 240px"}}),e.jsx("button",{onClick:()=>j({...Ft}),style:Q(t.navy),children:"ï¼ New item"})]}),C&&e.jsx(se,{onRetry:L,children:C}),y&&e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:y.id?"Edit library item":"New library item"}),e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:ze,htmlFor:"lib-title",children:"Title"}),e.jsx("input",{id:"lib-title",style:Fe,value:y.title||"",onChange:i("title")})]}),e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:ze,htmlFor:"lib-category",children:"Category"}),e.jsx("input",{id:"lib-category",style:Fe,value:y.category||"",onChange:i("category"),placeholder:"e.g. Good to Know"})]}),e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:ze,htmlFor:"lib-body",children:"Body"}),e.jsx("textarea",{id:"lib-body",rows:5,style:{...Fe,resize:"vertical"},value:y.body||"",onChange:i("body")})]}),e.jsxs("div",{style:{display:"flex",gap:10,flexWrap:"wrap",marginBottom:"1rem"},children:[e.jsxs("div",{style:{flex:"2 1 240px"},children:[e.jsx("label",{style:ze,htmlFor:"lib-url",children:"Link URL"}),e.jsx("input",{id:"lib-url",style:Fe,value:y.url||"",onChange:i("url"),placeholder:"https://â¦"})]}),e.jsxs("div",{style:{flex:"1 1 140px"},children:[e.jsx("label",{style:ze,htmlFor:"lib-linktext",children:"Link text"}),e.jsx("input",{id:"lib-linktext",style:Fe,value:y.linkText||y.link_text||"",onChange:i("linkText")})]})]}),e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsx("button",{onClick:w,disabled:f||!String(y.title||"").trim(),style:{...Q(t.navy),opacity:f||!String(y.title||"").trim()?.5:1},children:f?"Savingâ¦":"Save item"}),e.jsx("button",{onClick:()=>j(null),style:N(),children:"Cancel"})]})]}),c&&l.length===0&&e.jsx(ye,{children:"Loading the libraryâ¦"}),!c&&l.length===0&&!y&&e.jsx(xe,{children:u?"Nothing in the library matches that.":"The library is empty. Save a piece of content here to reuse it in future issues."}),l.map(g=>e.jsx("div",{style:J,children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"flex-start",flexWrap:"wrap"},children:[e.jsxs("div",{style:{flex:"1 1 300px"},children:[g.category&&e.jsx("div",{style:{fontSize:".7rem",letterSpacing:".16em",textTransform:"uppercase",color:t.gold,fontFamily:d,marginBottom:5},children:g.category}),e.jsx("div",{style:{fontFamily:"Georgia,serif",fontSize:"1.05rem",color:t.navy,marginBottom:6},children:g.title}),g.body&&e.jsxs("div",{style:{fontFamily:d,fontSize:".84rem",color:t.muted,lineHeight:1.55,whiteSpace:"pre-wrap"},children:[String(g.body).slice(0,260),String(g.body).length>260?"â¦":""]})]}),e.jsxs("div",{style:{textAlign:"right",fontFamily:d,fontSize:".74rem",color:t.muted,whiteSpace:"nowrap"},children:[e.jsx("div",{children:g.use_count?`Used ${g.use_count}Ã`:"Never used"}),g.last_used_at&&e.jsxs("div",{children:["Last: ",ge(g.last_used_at)]}),e.jsx("button",{onClick:()=>j({...g,linkText:g.link_text||""}),style:{...N({padding:"4px 10px"}),marginTop:8},children:"Edit"})]})]})},g.id))]})}const Be={display:"block",fontSize:".7rem",letterSpacing:".1em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:4},Ie={...Z,width:"100%",boxSizing:"border-box"},_e=[{key:"fromName",col:"from_name",label:"Sender name",hint:"Shown as the sender in the inbox."},{key:"fromEmail",col:"from_email",label:"Sender address",hint:"Must be on a domain verified with the email provider."},{key:"replyTo",col:"reply_to",label:"Reply-to address",hint:"Where replies go, if different."},{key:"orgName",col:"org_name",label:"Organisation name"},{key:"addressLine1",col:"address_line1",label:"Address line 1"},{key:"addressLine2",col:"address_line2",label:"Address line 2"},{key:"city",col:"city",label:"City"},{key:"state",col:"state",label:"State"},{key:"postalCode",col:"postal_code",label:"Postal code"},{key:"websiteUrl",col:"website_url",label:"Website URL"}];function Bt({api:s,showToast:n}
1){const[l,a]=o.useState(null),[r,m]=o.useState(null),[u,x]=o.useState(null),[c,_]=o.useState(!0),[C,T]=o.useState(!1),[y,j]=o.useState(null),f=o.useCallback(async()=>{var w;_(!0),j(null);try{const i=await s.getSettings(),g=i.settings||{},p={footerText:g.footer_text||""};for(const k of _e)p[k.key]=g[k.col]||"";p.blogAutomationEnabled=g.blog_automation_enabled===!0,p.blogAutoGenerateCopy=g.blog_auto_generate_copy!==!1,p.blogNotifyOnDraft=g.blog_notify_on_draft!==!1,p.blogPostsPerDraft=Number.isInteger(g.blog_posts_per_draft)?g.blog_posts_per_draft:5,x(g.blog_baseline_at||null),a(p),m(i.fromHeader)}catch(i){j(((w=i.body)==null?void 0:w.error)||i.message)}finally{_(!1)}},[s]);o.useEffect(()=>{f()},[f]);const F=w=>i=>a(g=>({...g,[w]:i.target.value})),h=w=>i=>a(g=>({...g,[w]:i.target.checked}));async function L(){var i,g;const w=Number(l.blogPostsPerDraft);if(!Number.isInteger(w)||w<2||w>10){j("Posts per draft must be a whole number between 2 and 10.");return}T(!0),j(null);try{const p=await s.saveSettings({...l,blogPostsPerDraft:w}),k=p.settings||{};a(O=>({...O,blogAutomationEnabled:k.blog_automation_enabled===!0,blogAutoGenerateCopy:k.blog_auto_generate_copy!==!1,blogNotifyOnDraft:k.blog_notify_on_draft!==!1,blogPostsPerDraft:Number.isInteger(k.blog_posts_per_draft)?k.blog_posts_per_draft:w})),m(p.fromHeader),n==null||n("success","Newsletter settings saved.")}catch(p){j(((i=p.body)==null?void 0:i.error)||p.message),((g=p.body)==null?void 0:g.code)==="ACTIVATION_REQUIRED"&&a(k=>({...k,blogAutomationEnabled:!1}))}finally{T(!1)}}return c?e.jsx(ye,{children:"Loading settingsâ¦"}):l?e.jsxs("div",{style:{padding:"1.5rem",maxWidth:640},children:[y&&e.jsx("div",{style:{marginBottom:"1.2rem"},children:e.jsx(se,{children:y})}),e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Sender"}),r&&e.jsxs("div",{style:{background:t.cream,border:`1px solid ${t.border}`,borderRadius:3,padding:"8px 10px",marginBottom:"1rem",fontFamily:d,fontSize:".82rem",color:t.navy},children:["Newsletters will be sent from ",e.jsx("strong",{children:r})]}),_e.slice(0,3).map(w=>e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:Be,htmlFor:`set-${w.key}`,children:w.label}),e.jsx("input",{id:`set-${w.key}`,style:Ie,value:l[w.key],onChange:F(w.key)}),w.hint&&e.jsx("div",{style:{fontSize:".74rem",color:t.muted,fontFamily:d,marginTop:4},children:w.hint})]},w.key))]}),e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Footer"}),e.jsx("p",{style:{fontFamily:d,fontSize:".82rem",color:t.muted,lineHeight:1.55,marginTop:0},children:"These appear at the bottom of every newsletter, alongside the unsubscribe link. A bulk newsletter is normally expected to identify its sender and carry a postal address."}),_e.slice(3).map(w=>e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:Be,htmlFor:`set-${w.key}`,children:w.label}),e.jsx("input",{id:`set-${w.key}`,style:Ie,value:l[w.key],onChange:F(w.key)})]},w.key)),e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("label",{style:Be,htmlFor:"set-footerText",children:"Footer note"}),e.jsx("textarea",{id:"set-footerText",rows:3,style:{...Ie,resize:"vertical"},value:l.footerText,onChange:F("footerText"),placeholder:"e.g. You are receiving this because you signed up at mylegalbeagle.com."})]})]}),e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Blog automation"}),e.jsxs("p",{style:{fontFamily:d,fontSize:".82rem",color:t.muted,lineHeight:1.55,marginTop:0},children:["Turns new Legal Beagle blog posts into newsletter ",e.jsx("strong",{children:"drafts"})," for you to review. Nothing is ever sent automatically, and articles published before automation was first enabled are never drafted on their own."]}),e.jsxs("label",{style:{display:"flex",gap:8,alignItems:"flex-start",fontFamily:d,fontSize:".84rem",color:t.navy,marginBottom:12},children:[e.jsx("input",{type:"checkbox",checked:l.blogAutomationEnabled,onChange:h("blogAutomationEnabled"),style:{marginTop:3},"aria-label":"Automatic draft creation"}),e.jsxs("span",{children:["Automatic draft creation",e.jsx("span",{style:{display:"block",fontSize:".76rem",color:t.muted},children:"Once active, the system checks for new posts every few hours and turns each batch into a draft for you to review. Turning it on for the first time needs a one-time activation step (done by your operator) that protects the existing blog archive â this switch will explain if that hasnât happened yet. Turning it off always works immediately."})]})]}),e.jsxs("div",{style:{marginBottom:12,maxWidth:180},children:[e.jsx("label",{style:Be,htmlFor:"set-blogPostsPerDraft",children:"Posts per draft"}),e.jsx("input",{id:"set-blogPostsPerDraft",type:"number",min:2,max:10,step:1,style:Ie,value:l.blogPostsPerDraft,onChange:F("blogPostsPerDraft")}),e.jsx("div",{style:{fontSize:".74rem",color:t.muted,fontFamily:d,marginTop:4},children:"Between 2 and 10. Default 5."})]}),e.jsxs("label",{style:{display:"flex",gap:8,alignItems:"flex-start",fontFamily:d,fontSize:".84rem",color:t.navy,marginBottom:12},children:[e.jsx("input",{type:"checkbox",checked:l.blogAutoGenerateCopy,onChange:h("blogAutoGenerateCopy"),style:{marginTop:3},"aria-label":"Generate newsletter copy with AI"}),e.jsxs("span",{children:["Generate newsletter copy with AI",e.jsx("span",{style:{display:"block",fontSize:".76rem",color:t.muted},children:"Off, automatic drafts use each articleâs own excerpt instead."})]})]}),e.jsxs("label",{style:{display:"flex",gap:8,alignItems:"flex-start",fontFamily:d,fontSize:".84rem",color:t.navy,marginBottom:12},children:[e.jsx("input",{type:"checkbox",checked:l.blogNotifyOnDraft,onChange:h("blogNotifyOnDraft"),style:{marginTop:3},"aria-label":"Notify me when a draft is created"}),e.jsx("span",{children:"Notify me when a draft is created"})]}),e.jsxs("div",{style:{background:t.cream,border:`1px solid ${t.border}`,borderRadius:3,padding:"8px 10px",fontFamily:d,fontSize:".78rem",color:t.muted},children:["Historical baseline: ",u?e.jsxs(e.Fragment,{children:["articles published before ",e.jsx("strong",{style:{color:t.navy},children:ge(u)})," are treated as archive and never auto-drafted."]}):e.jsx(e.Fragment,{children:"not set yet â it is recorded the first time automation runs, so the existing archive is never auto-drafted."})]})]}),e.jsx("button",{onClick:L,disabled:C,style:{...Q(t.navy),opacity:C?.6:1},children:C?"Savingâ¦":"Save settings"})]}):e.jsx("div",{style:{padding:"1.5rem"},children:e.jsx(se,{onRetry:f,children:y||"Settings unavailable."})})}const It={sent:t.success,partially_failed:t.warn,sending:t.warn,queued:t.muted,failed:t.danger,canceled:t.muted,pending:t.muted};function _t({api:s,showToast:n}
1){const[l,a]=o.useState([]),[r,m]=o.useState(!0),[u,x]=o.useState(null),[c,_]=o.useState(null),[C,T]=o.useState(null),y=o.useCallback(async()=>{var f;m(!0),x(null);try{const F=await s.listCampaigns({limit:50});a(F.campaigns||[])}catch(F){x(((f=F.body)==null?void 0:f.error)||F.message)}finally{m(!1)}},[s]),j=o.useCallback(async()=>{try{T(await s.languageAnalytics())}catch{}},[s]);return o.useEffect(()=>{j()},[j]),o.useEffect(()=>{y()},[y]),c?e.jsx(Lt,{api:s,campaignId:c,onClose:()=>{_(null),y()}}):e.jsxs("div",{style:{padding:"1.5rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1rem"},children:[e.jsx("div",{style:{fontSize:".76rem",color:t.muted,fontFamily:d},children:r?"Loadingâ¦":`${l.length} campaign${l.length===1?"":"s"}`}),e.jsx("button",{onClick:y,style:N(),children:"Refresh"})]}),u&&e.jsx(se,{onRetry:y,children:u}),C&&e.jsx(At,{data:C}),!u&&e.jsxs("div",{style:{...J,padding:0,overflowX:"auto"},children:[r&&l.length===0&&e.jsx(ye,{children:"Loading campaignsâ¦"}),!r&&l.length===0&&e.jsx(xe,{children:"No campaigns yet. Results appear here once a newsletter has been sent."}),l.length>0&&e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:720},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:H,children:"Subject"}),e.jsx("th",{style:H,children:"Kind"}),e.jsx("th",{style:H,children:"Status"}),e.jsx("th",{style:H,children:"Recipients"}),e.jsx("th",{style:H,children:"Sent"}),e.jsx("th",{style:H,children:"Delivered"}),e.jsx("th",{style:H,children:"Sent at"}),e.jsx("th",{style:H})]})}),e.jsx("tbody",{children:l.map(f=>e.jsxs("tr",{children:[e.jsx("td",{style:E,children:f.subject_snapshot||"â"}),e.jsx("td",{style:{...E,fontSize:".76rem",color:t.muted,textTransform:"uppercase"},children:f.kind}),e.jsx("td",{style:{...E,color:It[f.status]||t.muted,fontWeight:700,fontSize:".78rem",textTransform:"uppercase"},children:String(f.status).replace(/_/g," ")}),e.jsx("td",{style:E,children:f.recipient_count}),e.jsx("td",{style:E,children:f.sent_count}),e.jsx("td",{style:E,children:f.delivered_count}),e.jsx("td",{style:{...E,color:t.muted,fontSize:".78rem",whiteSpace:"nowrap"},children:ge(f.completed_at||f.created_at)}),e.jsx("td",{style:{...E,textAlign:"right"},children:e.jsx("button",{onClick:()=>_(f.id),style:N({padding:"4px 10px"}),children:"Open"})})]},f.id))})]})]})]})}function Lt({api:s,campaignId:n,onClose:l}){const[a,r]=o.useState(null),[m,u]=o.useState(!0),[x,c]=o.useState(null),[_,C]=o.useState(null);if(o.useEffect(()=>{let i=!0;return u(!0),s.getCampaign(n).then(g=>{i&&r(g)}).catch(g=>{var p;i&&c(((p=g.body)==null?void 0:p.error)||g.message)}).finally(()=>{i&&u(!1)}),()=>{i=!1}},[s,n]),m)return e.jsx(ye,{children:"Loading campaignâ¦"});if(x)return e.jsx("div",{style:{padding:"1.5rem"},children:e.jsx(se,{children:x})});if(!a)return null;const{campaign:T,deliveries:y,engagement:j,byLanguage:f,audienceByLanguage:F,languageChanges:h}=a,L=(i,g)=>g>0?`${Math.round(i/g*100)}%`:null,w=[{label:"Recipients",value:T.recipient_count},{label:"Handed to the provider",value:T.sent_count},{label:"Delivered",value:y.delivered,of:T.sent_count},{label:"Bounced",value:y.bounced,of:T.sent_count,tone:t.danger},{label:"Complained",value:y.complained,of:T.sent_count,tone:t.danger},{label:"Failed",value:y.failed,tone:t.danger},{label:"Skipped (unsubscribed before sending)",value:y.skipped,tone:t.muted},{label:"Still queued",value:y.pending+y.sending,tone:t.warn}];return e.jsxs("div",{style:{padding:"1.5rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"1.2rem",gap:12,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{...q,border:"none",margin:0,padding:0},children:"Campaign"}),e.jsx("div",{style:{fontFamily:"Georgia,serif",fontSize:"1.2rem",color:t.navy,marginTop:6},children:T.subject_snapshot}),e.jsxs("div",{style:{fontFamily:d,fontSize:".78rem",color:t.muted,marginTop:4},children:[T.audience_description||"â"," · ",String(T.status).replace(/_/g," "),T.completed_at?` · ${ge(T.completed_at)}`:""]})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[a.hasSnapshot&&e.jsx("button",{onClick:()=>s.getCampaignSnapshot(n).then(C),style:N(),children:"View what was sent"}),e.jsx("button",{onClick:l,style:N(),children:"Back"})]})]}),e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Delivery"}),e.jsx("table",{style:{width:"100%",borderCollapse:"collapse"},children:e.jsx("tbody",{children:w.map(i=>e.jsxs("tr",{children:[e.jsx("td",{style:{...E,color:t.muted},children:i.label}),e.jsxs("td",{style:{...E,textAlign:"right",color:i.tone||t.text,fontWeight:700},children:[i.value,i.of?e.jsx("span",{style:{color:t.muted,fontWeight:400,marginLeft:8},children:L(i.value,i.of)}):null]})]},i.label))})})]}),f&&e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"By language"}),me.filter(i=>{var g;return(((g=f[i])==null?void 0:g.queued)||0)>0}).join()==="en"?e.jsx("div",{style:{fontFamily:d,fontSize:".82rem",color:t.muted},children:"Everyone on this send reads in English."}):e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:H,children:"Language"}),e.jsx("th",{style:{...H,textAlign:"right"},children:"Recipients"}),e.jsx("th",{style:{...H,textAlign:"right"},children:"Sent"})]})}),e.jsx("tbody",{children:me.filter(i=>{var g;return(((g=f[i])==null?void 0:g.queued)||0)>0}).map(i=>e.jsxs("tr",{children:[e.jsxs("td",{style:E,children:[e.jsx("span",{lang:i,dir:ce(i)?"rtl":"ltr",style:{fontWeight:700},children:ue[i]}),e.jsx("span",{style:{color:t.muted,marginLeft:8,fontSize:".78rem"},children:V[i]})]}),e.jsx("td",{style:{...E,textAlign:"right"},children:f[i].queued}),e.jsx("td",{style:{...E,textAlign:"right",fontWeight:700},children:f[i].sent})]},i))})]}),F&&e.jsx("div",{style:{fontFamily:d,fontSize:".76rem",color:t.muted,marginTop:10},children:"The split is fixed at the moment you confirmed the send, so it stays accurate even after people change their language afterwards."})]}),e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Engagement"}),e.jsx("table",{style:{width:"100%",borderCollapse:"collapse"},children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{style:{...E,color:t.muted},children:"Unsubscribed from this newsletter"}),e.jsx("td",{style:{...E,textAlign:"right",fontWeight:700},children:j.unsubscribed})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{...E,color:t.muted},children:"Opened"}),e.jsx("td",{style:{...E,textAlign:"right",fontWeight:700},children:j.openTrackingObserved?e.jsxs(e.Fragment,{children:[j.opened,e.jsx("span",{style:{color:t.muted,fontWeight:400,marginLeft:8},children:L(j.opened,y.delivered)})]}):e.jsx("span",{style:{color:t.muted,fontWeight:400,fontStyle:"italic"},children:"not tracked"})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{...E,color:t.muted},children:"Clicked"}),e.jsx("td",{style:{...E,textAlign:"right",fontWeight:700},children:j.clickTrackingObserved?e.jsxs(e.Fragment,{children:[j.clicked,e.jsx("span",{style:{color:t.muted,fontWeight:400,marginLeft:8},children:L(j.clicked,y.delivered)})]}):e.jsx("span",{style:{color:t.muted,fontWeight:400,fontStyle:"italic"},children:"not tracked"})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{...E,color:t.muted},children:"Changed their language from this issue"}),e.jsx("td",{style:{...E,textAlign:"right",fontWeight:700},children:h??0})]})]})}),(!j.openTrackingObserved||!j.clickTrackingObserved)&&e.jsx("p",{style:{fontFamily:d,fontSize:".78rem",color:t.muted,lineHeight:1.55,marginBottom:0},children:"No open or click events have been received for this campaign. That means either nobody opened it, or open and click tracking is not switched on for the sending domain with the email provider â those are different things, so no figure is shown rather than a misleading zero."})]}),_&&e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"What was sent",style:{position:"fixed",inset:0,background:"rgba(13,3
11,48,0.55)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"},onClick:i=>{i.target===i.currentTarget&&C(null)},children:e.jsxs("div",{style:{background:t.white,borderRadius:4,width:"100%",maxWidth:760,maxHeight:"90vh",display:"flex",flexDirection:"column",border:`1px solid ${t.border}`},children:[e.jsxs("div",{style:{padding:"0.9rem 1.2rem",borderBottom:`1px solid ${t.border}`,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("div",{style:{fontFamily:d,fontSize:".84rem",color:t.navy},children:"Exactly what was sent â this copy cannot change"}),e.jsx("button",{onClick:()=>C(null),"aria-label":"Close snapshot",style:N({padding:"4px 10px"}),children:"Close"})]}),e.jsx("div",{style:{flex:1,overflow:"auto",background:t.cream,padding:"1rem",display:"flex",justifyContent:"center"},children:e.jsx("iframe",{title:"Sent newsletter",sandbox:"",srcDoc:_.html,style:{width:700,maxWidth:"100%",height:"70vh",border:`1px solid ${t.border}`,background:t.white}})})]})})]})}function At({data:s}){const n=s.distribution||{},l=me.reduce((r,m)=>{var u;return r+(((u=n[m])==null?void 0:u.active)||0)},0),a=Object.entries(s.transitions||{}).sort((r,m)=>m[1]-r[1]).slice(0,8);return e.jsxs("div",{style:J,children:[e.jsx("div",{style:q,children:"Languages"}),e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:H,children:"Language"}),e.jsx("th",{style:{...H,textAlign:"right"},children:"Can be sent to"}),e.jsx("th",{style:{...H,textAlign:"right"},children:"On the list"}),e.jsx("th",{style:{...H,textAlign:"right"},children:"Share"})]})}),e.jsx("tbody",{children:me.map(r=>{var x,c;const m=((x=n[r])==null?void 0:x.active)||0,u=((c=n[r])==null?void 0:c.total)||0;return e.jsxs("tr",{children:[e.jsxs("td",{style:E,children:[e.jsx("span",{lang:r,dir:ce(r)?"rtl":"ltr",style:{fontWeight:700},children:ue[r]}),e.jsx("span",{style:{color:t.muted,marginLeft:8,fontSize:".78rem"},children:V[r]})]}),e.jsx("td",{style:{...E,textAlign:"right",fontWeight:700},children:m}),e.jsx("td",{style:{...E,textAlign:"right",color:t.muted},children:u}),e.jsx("td",{style:{...E,textAlign:"right",color:t.muted},children:l>0?`${Math.round(m/l*100)}%`:"â"})]},r)})})]}),e.jsxs("div",{style:{marginTop:"1.1rem"},children:[e.jsx("div",{style:{fontSize:".7rem",letterSpacing:".12em",textTransform:"uppercase",color:t.muted,fontFamily:d,marginBottom:8},children:"Language changes"}),a.length===0?e.jsx("div",{style:{fontFamily:d,fontSize:".82rem",color:t.muted},children:"Nobody has changed their language yet."}):e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:a.map(([r,m])=>{const[u,x]=r.split("->");return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 10px",background:t.cream,border:`1px solid ${t.creamDark}`,borderRadius:12,fontFamily:d,fontSize:".8rem",color:t.text},children:[e.jsx("span",{lang:u,dir:ce(u)?"rtl":"ltr",children:ue[u]||u}),e.jsx("span",{style:{color:t.muted},children:"â"}),e.jsx("span",{lang:x,dir:ce(x)?"rtl":"ltr",children:ue[x]||x}),e.jsx("strong",{style:{marginLeft:3},children:m})]},r)})}),s.transitionsTruncated&&e.jsxs("div",{style:{fontFamily:d,fontSize:".74rem",color:t.muted,marginTop:8},children:["Counted from the most recent ",s.changesCounted," changes; there are older ones."]})]})]})}const Le=[{id:"issues",label:"Issues",ready:!0},{id:"subscribers",label:"Subscribers",ready:!0},{id:"content",label:"Content",ready:!0},{id:"imports",label:"Imports",ready:!0},{id:"analytics",label:"Analytics",ready:!0},{id:"settings",label:"Settings",ready:!0}];function Et({apiFetch:s,showToast:n}){const l=o.useMemo(()=>lt(s),[s]),[a,r]=o.useState("issues"),[m,u]=o.useState(0),x=Le.find(c=>c.id===a)||Le[0];return e.jsxs("div",{style:{background:t.cream,minHeight:"calc(100vh - 143px)"},children:[e.jsx("div",{style:{background:t.white,borderBottom:`1px solid ${t.border}`,display:"flex",padding:"0 1.5rem",alignItems:"stretch",overflowX:"auto",height:40},children:Le.map(c=>e.jsxs("button",{onClick:()=>
1r(c.id),"aria-current":a===c.id?"page":void 0,style:{padding:"0 16px",background:"transparent",border:"none",borderBottom:a===c.id?`2px solid ${t.gold}`:"2px solid transparent",color:a===c.id?t.navy:c.ready?t.muted:"#a09a90",fontSize:".78rem",fontFamily:d,fontWeight:a===c.id?700:400,cursor:"pointer",letterSpacing:".04em",whiteSpace:"nowrap"},children:[c.label,!c.ready&&" ·"]},c.id))}),a==="subscribers"&&e.jsx(ot,{api:l,showToast:n},`subs-${m}`),a==="imports"&&e.jsx(ut,{api:l,showToast:n,onImported:()=>u(c=>c+1)}),a==="issues"&&e.jsx(zt,{api:l,showToast:n}),a==="content"&&e.jsx(Tt,{api:l,showToast:n}),a==="analytics"&&e.jsx(_t,{api:l,showToast:n}),a==="settings"&&e.jsx(Bt,{api:l,showToast:n}),!x.ready&&e.jsx("div",{style:{padding:"1.5rem"},children:e.jsx("div",{style:J,children:e.jsxs(xe,{children:[e.jsxs("div",{style:{fontStyle:"normal",color:t.navy,fontWeight:700,marginBottom:6},children:[x.label," is not built yet"]}),e.jsx("div",{children:x.note})]})})})]})}export{Et 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.