PageSourceSearch

https://proudnotproud.com/assets/admin-email-center-pSfNM81C.js

js proudnotproud.com collected 2026-10-02 01:41:25 UTC 32,171 bytes, 5 lines download raw bytes

1import{r as s,j as e}from"./vendor-motion-CWthwBHV.js";import{c as X,ao as T,bv as Q,aY as I,l as ee,u as te,f as se,an as ie,bP as G,ap as re,aw as ne,aZ as ae}from"./session-card-DfDogMnt.js";import{A as oe,R as le}from"./App-DucJjLMU.js";import{P as de}from"./page-footer-DgQVBoUK.js";import{C as N}from"./circle-check-DenAsLo8.js";import{C as q}from"./circle-alert-WYCRbN3w.js";import{C as ce}from"./clock-DS3tHqp7.js";import{E as Y}from"./eye-CI4d3TdP.js";import{U as pe}from"./users-3zLgccbJ.js";import{F as ge}from"./file-text-BdltzrjC.js";import{S as ue}from"./save-te6P837l.js";import{E as fe}from"./eye-off-4BadPNZd.js";import"./index-UQ4Qr5Bx.js";import"./vendor-radix-XKDS9LlS.js";import"./api-base-B8hCG6H6.js";import"./vendor-query-CIlvkMVG.js";import"./vendor-charts-DVgyNbFy.js";import"./clerk-preview-Xs8fmqyU.js";import"./zap-DKaaT3bk.js";const xe=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],be=X("library",xe),J="/".replace(/\/$/,""),me={live:{label:"Live",bg:"rgba(21,128,61,0.08)",color:"#15803d",border:"rgba(21,128,61,0.22)"},ready:{label:"Ready to test",bg:"rgba(180,83,9,0.08)",color:"#92400e",border:"rgba(180,83,9,0.22)"},planned:{label:"Planned",bg:"rgba(58,28,0,0.05)",color:"rgba(58,28,0,0.5)",border:"rgba(58,28,0,0.12)"}},ye={lifecycle:"Lifecycle",transactional:"Transactional",audience:"Audience"};async function D(r){const n=await fetch(`${J}/api/admin${r}`,{credentials:"include"});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}async function he(r,n){const l=await fetch(`${J}/api/admin${r}`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(n)});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error??`HTTP ${l.status}`)}return l.json()}function U({status:r}){const n=me[r];return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"3px 9px",borderRadius:999,fontSize:10,letterSpacing:"0.08em",textTransform:"uppercase",fontFamily:"ui-monospace, Menlo, monospace",background:n.bg,color:n.color,border:`1px solid ${n.border}`},children:n.label})}function je(){const[r,n]=s.useState([]),[l,c]=s.useState([]),[p,x]=s.useState(!0),[d,h]=s.useState(""),[b,L]=s.useState("all"),[v,m]=s.useState("account_welcome"),[j,R]=s.useState(""),[g,k]=s.useState(null),[$,E]=s.useState(!1),[z,C]=s.useState(!1),[y,u]=s.useState(null),[o,S]=s.useState(!1),t=s.useCallback(async()=>{x(!0),h("");try{const i=await D("/email-templates");n(i.templates),c(i.rules??[])}catch{h("Failed to load the email catalog.")}finally{x(!1)}},[]);s.useEffect(()=>{t()},[t]);const a=s.useMemo(()=>b==="all"?r:r.filter(i=>i.category===b),[r,b]),w=s.useMemo(()=>r.filter(i=>i.dayOffset!=null).slice().sort((i,f)=>(i.dayOffset??0)-(f.dayOffset??0)),[r]),A=s.useCallback(async i=>{E(!0),u(null);try{const f=await D(`/email-templates/${i}/preview`);R(f.html),k({subject:f.subject,preheader:f.preheader,when:f.when,why:f.why,audience:f.audience,cadence:f.cadence,status:f.status,name:f.name})}catch{R(""),k(null),u({type:"error",message:"Failed to render preview."})}finally{E(!1)}},[]);s.useEffect(()=>{v&&A(v)},[v,A]);const V=async()=>{C(!0),u(null);try{const i=await he(`/email-templates/${v}/test`,{});u({type:"success",message:`Test sent to ${i.sentTo}`})}catch(i){u({type:"error",message:i instanceof Error?i.message:"Failed to send test."})}finally{C(!1)}};return p?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:60,gap:10},children:[e.jsx(T,{size:18,style:{color:"rgba(58,28,0,0.3)",animation:"spin 0.8s linear infinite"}}),e.jsx("span",{style:{fontSize:13,color:"rgba(58,28,0,0.4)"},children:"Loading catalog…"})]}):d?e.jsx("div",{style:{padding:40,textAlign:"center",fontSize:14,color:"#b91c1c"},children:d}):e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:22},children:[e.jsxs("button",{onClick:()=>S(i=>!i),style:{display:"inline-flex",alignItems:"center",gap:8,padding:"8px 12px",borderRadius:10,border:"1px solid rgba(58,28,0,0.1)",background:"#fff",color:"rgba(58,28,0,0.55)",fontSize:12,cursor:"pointer",fontFamily:"ui-monospace, Menlo, monospace",letterSpacing:"0.08em",textTransform:"uppercase"},children:[e.jsx(Q,{size:13})," ",o?"Hide":"Show"," email system rules"]}),o&&e.jsx("ol",{style:{margin:"12px 0 0",padding:"18px 18px 18px 36px",background:"#fff",border:"1px solid rgba(58,28,0,0.09)",borderRadius:14,color:"rgba(58,28,0,0.7)",fontSize:13,lineHeight:1.65},children:l.map(i=>e.jsx("li",{style:{marginBottom:6},children:i},i))})]}),e.jsx("div",{style:{fontSize:11,fontFamily:"ui-monospace, Menlo, monospace",letterSpacing:"0.14em",textTransform:"uppercase",color:"rgba(58,28,0,0.4)",marginBottom:10},children:"When they go out"}),e.jsx("div",{style:{display:"flex",gap:8,overflowX:"auto",paddingBottom:8,marginBottom:22},children:w.map(i=>{const f=i.key===v;return e.jsxs("button",{onClick:()=>m(i.key),style:{flex:"0 0 auto",textAlign:"left",padding:"12px 14px",minWidth:148,borderRadius:14,cursor:"pointer",border:f?"1px solid #3a1c00":"1px solid rgba(58,28,0,0.09)",background:f?"#433a31":"#fff"},children:[e.jsx("div",{style:{fontFamily:"ui-monospace, Menlo, monospace",fontSize:10,letterSpacing:"0.12em",textTransform:"uppercase",color:f?"rgba(255,190,60,0.85)":"rgba(58,28,0,0.45)",marginBottom:4},children:i.dayOffset===0?"Day 0":`Day ${i.dayOffset}`}),e.jsx("div",{style:{fontSize:13,color:f?"rgba(255,242,215,0.95)":"#3a1c00",fontFamily:"Georgia, serif"},children:i.name})]},i.key)})}),e.jsx("div",{style:{display:"flex",gap:6,marginBottom:16,flexWrap:"wrap"},children:["all","lifecycle","transactional","audience"].map(i=>e.jsx("button",{onClick:()=>L(i),style:{padding:"6px 12px",borderRadius:8,fontSize:12,cursor:"pointer",border:b===i?"1px solid rgba(58,28,0,0.2)":"1px solid rgba(58,28,0,0.1)",background:b===i?"#2e1505":"#fff",color:b===i?"#fff":"rgba(58,28,0,0.55)"},children:i==="all"?"All sends":ye[i]},i))}),e.jsxs("div",{className:"pnp-email-lib-grid",style:{display:"grid",gridTemplateColumns:"minmax(260px, 340px) 1fr",gap:18,alignItems:"start"},children:[e.jsx("style",{children:"@media (max-width: 860px) { .pnp-email-lib-grid { grid-template-columns: 1fr !important; } }"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:a.map(i=>{const f=i.key===v;return e.jsxs("button",{onClick:()=>m(i.key),style:{textAlign:"left",padding:"14px 16px",borderRadius:14,cursor:"pointer",border:f?"1px solid rgba(58,28,0,0.28)":"1px solid rgba(58,28,0,0.09)",background:f?"#fff":"rgba(255,255,255,0.7)",boxShadow:f?"0 8px 24px rgba(58,28,0,0.06)":"none"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8,marginBottom:6},children:[e.jsx("span",{style:{fontSize:14,color:"#3a1c00",fontFamily:"Georgia, serif"},children:i.name}),e.jsx(U,{status:i.status})]}),e.jsx("div",{style:{fontSize:12,color:"rgba(58,28,0,0.5)",lineHeight:1.45},children:i.cadence})]},i.key)})}),e.jsx("div",{style:{background:"#fff",border:"1px solid rgba(58,28,0,0.09)",borderRadius:18,overflow:"hidden",minHeight:520},children:$&&!g?e.jsx("div",{style:{padding:48,display:"flex",justifyContent:"center"},children:e.jsx(T,{size:18,style:{color:"rgba(58,28,0,0.3)",animation:"spin 0.8s linear infinite"}})}):g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"22px 22px 18px",borderBottom:"1px solid rgba(58,28,0,0.07)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"flex-start",marginBottom:10},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontFamily:"Georgia, serif",fontSize:22,color:"#3a1c00",marginBottom:6},children:g.name}),e.jsx(U,{status:g.status})]}),e.jsxs("button",{onClick:V,disabled:z,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"10px 16px",borderRadius:10,border:"none",background:"#2e1505",color:"#fff",fontSize:13,cursor:z?"default":"pointer",opacity:z?.7:1,flexShrink:0},children:[z?e.jsx(T,{size:14,style:{animation:"spin 0.8s linear infinite"}}):e.jsx(I,{size:14}),z?"Sending…":"Send test to me"]})]}),e.jsxs("div",{style:{fontSize:13,color:"#3a1c00",marginBottom:4},children:[e.jsx("span",{style:{color:"rgba(58,28,0,0.4)",fontSize:11,letterSpacing:"0.08em",textTransform:"uppercase",marginRight:8},children:"Subject"}),g.subject]}),e.jsx("div",{style:{fontSize:13,color:"rgba(58,28,0,0.55)",fontStyle:"italic"},children:g.preheader}),y&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:12,padding:"10px 12px",borderRadius:10,background:y.type==="success"?"rgba(21,128,61,0.07)":"rgba(185,28,28,0.07)",color:y.type==="success"?"#15803d":"#b91c1c",fontSize:13},children:[y.type==="success"?e.jsx(N,{size:14}):e.jsx(q,{size:14}),y.message]})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:0,borderBottom:"1px solid rgba(58,28,0,0.07)"},children:[{icon:e.jsx(ce,{size:13}),label:"When",text:g.when},{icon:e.jsx(Y,{size:13}),label:"Why",text:g.why}].map(i=>e.jsxs("div",{style:{padding:"16px 22px",borderRight:i.label==="When"?"1px solid rgba(58,28,0,0.07)":"none"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:10,letterSpacing:"0.12em",textTransform:"uppercase",color:"rgba(58,28,0,0.4)",fontFamily:"ui-monospace, Menlo, monospace",marginBottom:8},children:[i.icon," ",i.label]}),e.jsx("p",{style:{margin:0,fontSize:13,lineHeight:1.55,color:"rgba(58,28,0,0.72)"},children:i.text})]},i.label))}),e.jsxs("div",{style:{padding:"12px 22px",fontSize:12,color:"rgba(58,28,0,0.5)",borderBottom:"1px solid rgba(58,28,0,0.07)"},children:[g.audience," · ",g.cadence]}),e.jsx("div",{style:{background:"#FCF6F0",padding:16},children:$?e.jsx("div",{style:{height:400,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(T,{size:18,style:{color:"rgba(58,28,0,0.3)",animation:"spin 0.8s linear infinite"}})}):e.jsx("iframe",{title:"Email preview",srcDoc:j,sandbox:"",style:{width:"100%",height:640,border:"1px solid rgba(58,28,0,0.08)",borderRadius:12,background:"#FCF6F0"}})})]}):e.jsx("div",{style:{padding:48,textAlign:"center",color:"rgba(58,28,0,0.4)",fontSize:13},children:"Select a send to preview it."})})]})]})}const W="/".replace(/\/$/,"");async function P(r){const n=await fetch(`${W}/api/admin${r}`,{credentials:"include"});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}async function Se(r,n){const l=await fetch(`${W}/api/admin${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(n)});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error??`HTTP ${l.status}`)}return l.json()}async function K(r,n){const l=await fetch(`${W}/api/admin${r}`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(n)});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error??`HTTP ${l.status}`)}return l.json()}async function ve(r){const n=await fetch(`${W}/api/admin${r}`,{method:"DELETE",credentials:"include"});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}
1const M={cta:"Close section",footer:"Footer"},_={cta:{bg:"rgba(180,83,9,0.07)",text:"#92400e",border:"rgba(180,83,9,0.18)"},footer:{bg:"rgba(3,105,161,0.07)",text:"#075985",border:"rgba(3,105,161,0.18)"}};function O(r){return new Date(r).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}function Z({type:r,message:n}){const l=r==="success";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 14px",borderRadius:10,background:l?"rgba(21,128,61,0.07)":"rgba(185,28,28,0.07)",border:`1px solid ${l?"rgba(21,128,61,0.2)":"rgba(185,28,28,0.2)"}`,fontSize:13,color:l?"#15803d":"#b91c1c"},children:[l?e.jsx(N,{size:15}):e.jsx(q,{size:15}),n]})}const H=25;function we(){const[r,n]=s.useState([]),[l,c]=s.useState(!0),[p,x]=s.useState(""),[d,h]=s.useState("all"),[b,L]=s.useState(""),[v,m]=s.useState(1),[j,R]=s.useState(null),g=s.useCallback(async()=>{c(!0),x("");try{const t=d!=="all"?`?source=${d}`:"",a=await P(`/email-signups${t}`);n(a.signups),m(1)}catch{x("Failed to load signups.")}finally{c(!1)}},[d]);s.useEffect(()=>{g()},[g]),s.useEffect(()=>{m(1)},[b]);const k=async t=>{if(confirm("Remove this email from the list?")){R(t);try{await ve(`/email-signups/${t}`),n(a=>a.filter(w=>w.id!==t))}catch{alert("Failed to delete. Try again.")}finally{R(null)}}},$=()=>{window.open(`${W}/api/admin/email-signups/export.csv`,"_blank")},E=r.filter(t=>t.source==="cta").length,z=r.filter(t=>t.source==="footer").length,C=b.toLowerCase().trim(),y=C?r.filter(t=>t.email.toLowerCase().includes(C)):r,u=Math.max(1,Math.ceil(y.length/H)),o=Math.min(v,u),S=y.slice((o-1)*H,o*H);return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16,marginBottom:20,flexWrap:"wrap"},children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:10,flex:1,minWidth:220},children:[{label:"Total",value:r.length,color:"#2e1505"},{label:"Close section",value:E,color:"#92400e"},{label:"Footer",value:z,color:"#075985"}].map(t=>e.jsxs("div",{style:{background:"#fff",borderRadius:14,border:"1px solid rgba(58,28,0,0.09)",padding:"14px 18px"},children:[e.jsx("div",{style:{fontSize:22,fontWeight:300,color:t.color,letterSpacing:"-0.03em"},children:t.value}),e.jsx("div",{style:{fontSize:11,color:"rgba(58,28,0,0.45)",marginTop:2},children:t.label})]},t.label))}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexShrink:0},children:[e.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",borderRadius:10,border:"1px solid rgba(58,28,0,0.12)",background:"#fff",color:"rgba(58,28,0,0.6)",fontSize:13,cursor:"pointer"},children:[e.jsx(le,{size:13})," Refresh"]}),e.jsxs("button",{onClick:$,style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",borderRadius:10,border:"1px solid rgba(21,128,61,0.25)",background:"rgba(21,128,61,0.06)",color:"#15803d",fontSize:13,fontWeight:600,cursor:"pointer"},children:[e.jsx(re,{size:13})," Export CSV"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:10,marginBottom:16,flexWrap:"wrap",alignItems:"center"},children:[e.jsxs("div",{style:{position:"relative",flex:1,minWidth:180},children:[e.jsx(ne,{size:13,style:{position:"absolute",left:10,top:"50%",transform:"translateY(-50%)",color:"rgba(58,28,0,0.35)",pointerEvents:"none"}}),e.jsx("input",{value:b,onChange:t=>L(t.target.value),placeholder:"Search by email…",style:{width:"100%",padding:"8px 12px 8px 30px",borderRadius:10,border:"1px solid rgba(58,28,0,0.12)",background:"#fff",color:"#2e1505",fontSize:13,outline:"none",boxSizing:"border-box"}})]}),e.jsx("div",{style:{display:"flex",gap:6},children:["all","cta","footer"].map(t=>e.jsx("button",{onClick:()=>h(t),style:{padding:"6px 14px",borderRadius:8,fontSize:12,fontWeight:500,border:d===t?"1px solid rgba(58,28,0,0.2)":"1px solid rgba(58,28,0,0.1)",background:d===t?"#2e1505":"#fff",color:d===t?"#fff":"rgba(58,28,0,0.55)",cursor:"pointer",transition:"all 0.1s",textTransform:"capitalize"},children:t==="all"?"All":M[t]??t},t))})]}),e.jsx("div",{style:{background:"#fff",borderRadius:16,border:"1px solid rgba(58,28,0,0.09)",overflow:"hidden"},children:l?e.jsxs("div",{style:{padding:40,display:"flex",alignItems:"center",justifyContent:"center",gap:10},children:[e.jsx(T,{size:18,style:{color:"rgba(58,28,0,0.3)",animation:"spin 0.8s linear infinite"}}),e.jsx("span",{style:{fontSize:13,color:"rgba(58,28,0,0.4)"},children:"Loading…"})]}):p?e.jsx("div",{style:{padding:40,textAlign:"center",fontSize:14,color:"#b91c1c"},children:p}):S.length===0?e.jsxs("div",{style:{padding:60,textAlign:"center"},children:[e.jsx(G,{size:28,style:{color:"rgba(58,28,0,0.2)",marginBottom:10}}),e.jsx("p",{style:{fontSize:14,color:"rgba(58,28,0,0.4)",margin:0}
1,children:C?"No results match your search.":"No signups yet."})]}):e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsx("tr",{style:{borderBottom:"1px solid rgba(58,28,0,0.07)"},children:["Email","Source","Signed up",""].map(t=>e.jsx("th",{style:{textAlign:"left",padding:"12px 18px",fontSize:11,fontWeight:500,letterSpacing:"0.06em",textTransform:"uppercase",color:"rgba(58,28,0,0.38)"},children:t},t))})}),e.jsx("tbody",{children:S.map((t,a)=>{const w=_[t.source]??_.footer;return e.jsxs("tr",{style:{borderBottom:a<S.length-1?"1px solid rgba(58,28,0,0.05)":"none",transition:"background 0.1s"},onMouseEnter:A=>A.currentTarget.style.background="rgba(58,28,0,0.02)",onMouseLeave:A=>A.currentTarget.style.background="transparent",children:[e.jsx("td",{style:{padding:"13px 18px",fontSize:14,color:"#2e1505",fontFamily:"monospace"},children:t.email}),e.jsx("td",{style:{padding:"13px 18px"},children:e.jsx("span",{style:{display:"inline-block",padding:"3px 10px",borderRadius:6,fontSize:11,fontWeight:500,background:w.bg,color:w.text,border:`1px solid ${w.border}`},children:M[t.source]??t.source})}),e.jsx("td",{style:{padding:"13px 18px",fontSize:12,color:"rgba(58,28,0,0.45)",whiteSpace:"nowrap"},children:O(t.createdAt)}),e.jsx("td",{style:{padding:"13px 18px",textAlign:"right"},children:e.jsx("button",{onClick:()=>k(t.id),disabled:j===t.id,style:{padding:"5px 8px",borderRadius:7,border:"1px solid rgba(185,28,28,0.15)",background:"rgba(185,28,28,0.04)",color:"rgba(185,28,28,0.55)",cursor:j===t.id?"default":"pointer",opacity:j===t.id?.5:1,display:"flex",alignItems:"center"},title:"Remove from list",children:j===t.id?e.jsx(T,{size:13,style:{animation:"spin 0.8s linear infinite"}}):e.jsx(ae,{size:13})})})]},t.id)})})]})}),y.length>0&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:12,flexWrap:"wrap",gap:8},children:[e.jsxs("p",{style:{fontSize:12,color:"rgba(58,28,0,0.3)",margin:0},children:[C?`${y.length} match${y.length!==1?"es":""}`:`${y.length} total`,u>1?` · page ${o} of ${u}`:""]}),u>1&&e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>m(t=>Math.max(1,t-1)),disabled:o===1,style:{padding:"5px 12px",borderRadius:8,border:"1px solid rgba(58,28,0,0.12)",background:"#fff",color:"rgba(58,28,0,0.6)",fontSize:12,cursor:o===1?"default":"pointer",opacity:o===1?.4:1},children:"Previous"}),Array.from({length:Math.min(u,7)},(t,a)=>{const w=u<=7?a+1:a===0?1:a===6?u:o-2+a;return e.jsx("button",{onClick:()=>m(w),style:{padding:"5px 10px",borderRadius:8,border:w===o?"1px solid rgba(58,28,0,0.2)":"1px solid rgba(58,28,0,0.1)",background:w===o?"#2e1505":"#fff",color:w===o?"#fff":"rgba(58,28,0,0.55)",fontSize:12,cursor:"pointer",minWidth:32},children:w},w)}),e.jsx("button",{onClick:()=>m(t=>Math.min(u,t+1)),disabled:o===u,style:{padding:"5px 12px",borderRadius:8,border:"1px solid rgba(58,28,0,0.12)",background:"#fff",color:"rgba(58,28,0,0.6)",fontSize:12,cursor:o===u?"default":"pointer",opacity:o===u?.4:1},children:"Next"})]})]})]})}function ze(){const[r,n]=s.useState(null),[l,c]=s.useState(!0),[p,x]=s.useState(!1),[d,h]=s.useState(!1),[b,L]=s.useState(!1),[v,m]=s.useState(null),[j,R]=s.useState(""),[g,k]=s.useState(""),[$,E]=s.useState(""),[z,C]=s.useState(""),[y,u]=s.useState("");s.useEffect(()=>{c(!0),P("/email-templates/welcome").then(a=>{n(a),R(a.subject),k(a.heading),E(a.bodyHtml),C(a.ctaLabel),u(a.ctaUrl)}).catch(()=>m({type:"error",message:"Failed to load template."})).finally(()=>c(!1))},[]);const o=async()=>{x(!0),m(null);try{const a=await Se("/email-templates/welcome",{subject:j,heading:g,bodyHtml:$,ctaLabel:z,ctaUrl:y});n(a),m({type:"success",message:"Template saved. Changes apply to all future signups immediately."})}catch(a){m({type:"error",message:a instanceof Error?a.message:"Failed to save."})}finally{x(!1)}},S=async()=>{h(!0),m(null);try{const a=await K("/email-templates/welcome/test",{});m({type:"success",message:`Test email sent to ${a.sentTo}`})}catch(a){m({type:"error",message:a instanceof Error?a.message:"Failed to send test."})}finally{h(!1)}},t=ke({heading:g,bodyHtml:$,ctaLabel:z,ctaUrl:y}
1);return l?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:60,gap:10},children:[e.jsx(T,{size:18,style:{color:"rgba(58,28,0,0.3)",animation:"spin 0.8s linear infinite"}}),e.jsx("span",{style:{fontSize:13,color:"rgba(58,28,0,0.4)"},children:"Loading template…"})]}):e.jsxs("div",{style:{display:"flex",gap:24,alignItems:"flex-start"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsx(F,{label:"Subject line",children:e.jsx("input",{value:j,onChange:a=>R(a.target.value),placeholder:"You're on the list.",style:B})}),e.jsx(F,{label:"Heading",children:e.jsx("input",{value:g,onChange:a=>k(a.target.value),placeholder:"You're in.",style:B})}),e.jsx(F,{label:"Body (HTML allowed)",children:e.jsx("textarea",{value:$,onChange:a=>E(a.target.value),rows:8,placeholder:"<p>Thanks for signing up…</p>",style:{...B,resize:"vertical",fontFamily:"monospace",fontSize:12}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsx(F,{label:"CTA button label",children:e.jsx("input",{value:z,onChange:a=>C(a.target.value),placeholder:"Create a free account",style:B})}),e.jsx(F,{label:"CTA button URL",children:e.jsx("input",{value:y,onChange:a=>u(a.target.value),placeholder:"https://proudnotproud.app",style:B})})]}),v&&e.jsx(Z,{type:v.type,message:v.message}),e.jsxs("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:[e.jsxs("button",{onClick:o,disabled:p,style:{display:"flex",alignItems:"center",gap:7,padding:"10px 20px",borderRadius:10,border:"none",background:"#2e1505",color:"#fff",fontSize:13,fontWeight:600,cursor:p?"default":"pointer",opacity:p?.7:1},children:[p?e.jsx(T,{size:14,style:{animation:"spin 0.8s linear infinite"}}):e.jsx(ue,{size:14}),p?"Saving…":"Save template"]}),e.jsxs("button",{onClick:S,disabled:d,style:{display:"flex",alignItems:"center",gap:7,padding:"10px 20px",borderRadius:10,border:"1px solid rgba(58,28,0,0.15)",background:"#fff",color:"#2e1505",fontSize:13,fontWeight:600,cursor:d?"default":"pointer",opacity:d?.7:1},children:[d?e.jsx(T,{size:14,style:{animation:"spin 0.8s linear infinite"}}):e.jsx(I,{size:14}),d?"Sending…":"Send test to me"]}),e.jsxs("button",{onClick:()=>L(!b),style:{display:"flex",alignItems:"center",gap:7,padding:"10px 20px",borderRadius:10,border:"1px solid rgba(58,28,0,0.15)",background:"#fff",color:"rgba(58,28,0,0.6)",fontSize:13,cursor:"pointer"},children:[b?e.jsx(fe,{size:14}):e.jsx(Y,{size:14}),b?"Hide preview":"Show preview"]})]}),r&&e.jsxs("p",{style:{fontSize:11,color:"rgba(58,28,0,0.35)",margin:0},children:["Last saved ",O(r.updatedAt)]})]})}),b&&e.jsxs("div",{style:{width:380,flexShrink:0},children:[e.jsx("div",{style:{fontSize:11,fontWeight:500,letterSpacing:"0.06em",textTransform:"uppercase",color:"rgba(58,28,0,0.38)",marginBottom:10},children:"Preview"}),e.jsxs("div",{style:{background:"#fff",border:"1px solid rgba(58,28,0,0.1)",borderRadius:14,overflow:"hidden"},children:[e.jsxs("div",{style:{background:"#f4f0e8",padding:"10px 14px",fontSize:11,color:"rgba(58,28,0,0.5)",borderBottom:"1px solid rgba(58,28,0,0.08)"},children:[e.jsx("strong",{style:{color:"#2e1505"},children:"Subject:"})," ",j||"(no subject)"]}),e.jsx("div",{dangerouslySetInnerHTML:{__html:t},style:{padding:"0 4px"}})]})]})]})}function ke({heading:r,bodyHtml:n,ctaLabel:l,ctaUrl:c}){const p=l&&c?`<div style="margin-top: 24px;"><a href="${c}" style="display: inline-block; padding: 10px 20px; background: #433a31; color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase;">${l}</a></div>`:"";return`<div style="font-family: Georgia, serif; padding: 24px 20px; color: #2e1505; max-width: 100%;">
2  <p style="font-size: 20px; font-weight: bold; margin: 0 0 10px;">${r||"(no heading)"}</p>
3  ${n||'<p style="color: rgba(58,28,0,0.4); font-style: italic;">(no body)</p>'}
4  ${p}
5</div>`}function Ce(){const[r,n]=s.useState(""),[l,c]=s.useState(""),[p,x]=s.useState(""),[d,h]=s.useState("all"),[b,L]=s.useState(null),[v,m]=s.useState(!1),[j,R]=s.useState(!1),[g,k]=s.useState(null),[$,E]=s.useState([]),[z,C]=s.useState(!0);s.useEffect(()=>{P("/email-broadcasts").then(o=>E(o.broadcasts)).catch(()=>{}).finally(()=>C(!1))},[]),s.useEffect(()=>{m(!0);const o=d!=="all"?`?source=${d}`:"";P(`/email-broadcasts/count${o}`).then(S=>L(S.count)).catch(()=>L(null)).finally(()=>m(!1))},[d]);const y=async()=>
5{if(!r.trim()||!p.trim()){k({type:"error",message:"Subject and body are required."});return}const o=b??0;if(confirm(`Send this broadcast to ${o} subscriber${o!==1?"s":""}? This cannot be undone.`)){R(!0),k(null);try{const S={subject:r,preheader:l,bodyHtml:p};d!=="all"&&(S.source=d);const t=await K("/email-broadcasts",S);k({type:"success",message:`Sent to ${t.recipientCount} recipient${t.recipientCount!==1?"s":""} successfully.`}),n(""),c(""),x(""),E(a=>[t.broadcast,...a])}catch(S){k({type:"error",message:S instanceof Error?S.message:"Failed to send broadcast."})}finally{R(!1)}}},u=v?"…":b??"?";return e.jsxs("div",{children:[e.jsxs("div",{style:{background:"#fff",borderRadius:16,border:"1px solid rgba(58,28,0,0.09)",padding:"24px",marginBottom:28},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#2e1505",marginBottom:18},children:"Compose broadcast"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 200px",gap:12},children:[e.jsx(F,{label:"Subject",children:e.jsx("input",{value:r,onChange:o=>n(o.target.value),placeholder:"Monthly update — June 2026",style:B})}),e.jsx(F,{label:"Audience",children:e.jsxs("select",{value:d,onChange:o=>h(o.target.value),style:{...B,cursor:"pointer"},children:[e.jsx("option",{value:"all",children:"All subscribers"}),e.jsx("option",{value:"cta",children:"Close section only"}),e.jsx("option",{value:"footer",children:"Footer only"})]})})]}),e.jsx(F,{label:"Preheader (inbox preview text, optional)",children:e.jsx("input",{value:l,onChange:o=>c(o.target.value),placeholder:"Here's what's new this month — a quick look",style:B})}),e.jsx(F,{label:"Body (HTML allowed)",children:e.jsx("textarea",{value:p,onChange:o=>x(o.target.value),rows:10,placeholder:"<p>Hi everyone,</p><p>Here's what's new this month…</p>",style:{...B,resize:"vertical",fontFamily:"monospace",fontSize:12}})}),g&&e.jsx(Z,{type:g.type,message:g.message}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:12},children:[e.jsxs("div",{style:{fontSize:13,color:"rgba(58,28,0,0.5)"},children:["Recipients:"," ",e.jsx("strong",{style:{color:"#2e1505"},children:u})," ","subscriber",b!==1?"s":"",d!=="all"&&` (${M[d]} only)`]}),e.jsxs("button",{onClick:y,disabled:j||!r.trim()||!p.trim(),style:{display:"flex",alignItems:"center",gap:7,padding:"10px 22px",borderRadius:10,border:"none",background:r.trim()&&p.trim()&&!j?"#2e1505":"rgba(58,28,0,0.2)",color:"#fff",fontSize:13,fontWeight:600,cursor:j||!r.trim()||!p.trim()?"default":"pointer",transition:"background 0.15s"},children:[j?e.jsx(T,{size:14,style:{animation:"spin 0.8s linear infinite"}}):e.jsx(I,{size:14}),j?"Sending…":"Send broadcast"]})]})]})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,fontWeight:400,color:"rgba(58,28,0,0.38)",letterSpacing:"0.1em",textTransform:"uppercase",marginBottom:12},children:"Sent history"}),z?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"20px 0"},children:[e.jsx(T,{size:16,style:{color:"rgba(58,28,0,0.3)",animation:"spin 0.8s linear infinite"}}),e.jsx("span",{style:{fontSize:13,color:"rgba(58,28,0,0.4)"},children:"Loading history…"})]}):$.length===0?e.jsxs("div",{style:{background:"#fff",borderRadius:14,border:"1px solid rgba(58,28,0,0.09)",padding:"32px",textAlign:"center"},children:[e.jsx(I,{size:24,style:{color:"rgba(58,28,0,0.2)",marginBottom:8}}),e.jsx("p",{style:{fontSize:13,color:"rgba(58,28,0,0.4)",margin:0},children:"No broadcasts sent yet."})]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:$.map(o=>e.jsx("div",{style:{background:"#fff",borderRadius:14,border:"1px solid rgba(58,28,0,0.09)",padding:"16px 20px"},children:e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#2e1505",marginBottom:3},children:o.subject}),o.preheader&&e.jsx("div",{style:{fontSize:12,color:"rgba(58,28,0,0.5)",marginBottom:3,fontStyle:"italic"},children:o.preheader}),e.jsx("div",{style:{fontSize:12,color:"rgba(58,28,0,0.4)"},children:O(o.sentAt)})]}),e.jsxs("div",{style:{flexShrink:0,textAlign:"right"},children:[e.jsx("div",{style:{fontSize:18,fontWeight:300,color:"#2e1505",letterSpacing:"-0.02em"},children:o.recipientCount}),e.jsx("div",{style:{fontSize:11,color:"rgba(58,28,0,0.4)"},children:"recipients"})]})]})},o.id))})]})]})}const B={width:"100%",padding:"9px 12px",borderRadius:8,border:"1px solid rgba(58,28,0,0.15)",background:"#faf5ed",color:"#2e1505",fontSize:14,outline:"none",boxSizing:"border-box"};function F({label:r,children:n}){return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,fontWeight:500,color:"rgba(58,28,0,0.55)",marginBottom:6},children:r}),n]})}const Te=[{id:"library",label:"Library",icon:e.jsx(be,{size:14})},{id:"subscribers",label:"Subscribers",icon:e.jsx(pe,{size:14})},{id:"template",label:"Waitlist email",icon:e.jsx(ge,{size:14})},{id:"broadcast",label:"Broadcast",icon:e.jsx(I,{size:14})}];function Ye(){const[,r]=ee(),{isLoaded:n}=te(),{data:l,isLoading:c}=se(),p=!!l?.isAdmin,[x,d]=s.useState("library");return s.useEffect(()=>{!n||c||l!==void 0&&!p&&r("/")}
5,[n,c,l,p,r]),!n||c?e.jsxs("div",{style:{minHeight:"100vh",background:"#FCF6F0",display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(T,{size:28,style:{color:"rgba(58,28,0,0.3)",animation:"spin 0.8s linear infinite"}}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]}):p?e.jsxs("div",{style:{minHeight:"100vh",background:"#FCF6F0"},children:[e.jsx(oe,{}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"}),e.jsxs("div",{style:{maxWidth:1120,margin:"0 auto",padding:"48px 20px 100px"},children:[e.jsxs("button",{onClick:()=>r("/admin"),style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:13,color:"rgba(58,28,0,0.45)",background:"none",border:"none",cursor:"pointer",padding:"0 0 20px"},children:[e.jsx(ie,{size:14})," Admin"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:32},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",background:"rgba(58,28,0,0.07)",border:"1px solid rgba(58,28,0,0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(G,{size:18,color:"#2e1505"})}),e.jsxs("div",{children:[e.jsx("h1",{style:{fontSize:26,fontWeight:400,color:"#2e1505",margin:0,letterSpacing:"-0.02em",fontFamily:"Georgia, serif"},children:"Email"}),e.jsx("p",{style:{fontSize:13,color:"rgba(58,28,0,0.45)",margin:"3px 0 0"},children:"Every send, when it fires, why it exists — preview and test from one repository."})]})]}),e.jsx("div",{style:{display:"flex",gap:4,marginBottom:28,background:"#fff",padding:4,borderRadius:12,border:"1px solid rgba(58,28,0,0.09)",width:"fit-content"},children:Te.map(h=>e.jsxs("button",{onClick:()=>d(h.id),style:{display:"flex",alignItems:"center",gap:7,padding:"8px 16px",borderRadius:9,border:"none",background:x===h.id?"#2e1505":"transparent",color:x===h.id?"#fff":"rgba(58,28,0,0.55)",fontSize:13,fontWeight:x===h.id?600:400,cursor:"pointer",transition:"all 0.15s",whiteSpace:"nowrap"},children:[h.icon," ",h.label]},h.id))}),x==="library"&&e.jsx(je,{}),x==="subscribers"&&e.jsx(we,{}),x==="template"&&e.jsx(ze,{}),x==="broadcast"&&e.jsx(Ce,{})]}),e.jsx(de,{})]}):null}export{Ye 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.