1import{e as W,f as U,r as i,j as e,s as j}from"./index-DqAv76bN.js";import{u as Y}from"./useServerFn-DaNWYITm.js";import{r as G}from"./auth-middleware-CZwnglRG.js";import{s as H}from"./search-fold-Du8AqxmT.js";import{C as J}from"./copy-EqA_zeAR.js";const K=W({method:"POST"}).middleware([G]).handler(U("bddeb21089bb93e490a8e746e940f35fc7166fb7ff282675cc6b05902cfedfb6")),V="w-full rounded-md border border-white/15 bg-white/[0.04] px-3 py-2 text-sm text-summit-white placeholder:text-summit-white/40 focus:border-[#00acf0] focus:outline-none";function Q(){const[r,c]=i.useState([]),p=async()=>{const{data:g}=await j.from("angel_message_templates").select("id, code, label, subject, body, sort_order").order("sort_order",{ascending:!0});c(g??[])};return i.useEffect(()=>{p()},[]),{templates:r,reload:p}}function F(r,c,p="The Summit team"){const g={name:c.full_name??"",first_name:(c.full_name??"").trim().split(/\s+/)[0]??"",email:c.email??"",phone:c.phone??"",city:c.city??"",organization:c.organization??"",status:c.status??"",sender_name:p,tickets_link:"https://rosummit.org/tickets",agenda_link:"https://rosummit.org/agenda",summit_link:"https://rosummit.org"};return r.replace(/\{(\w+)\}/g,(S,_)=>g[_]??"")}const X=[{key:"name",what:"Full name"},{key:"first_name",what:"First name only"},{key:"email",what:"Their email"},{key:"phone",what:"Their phone"},{key:"city",what:"Their city"},{key:"organization",what:"Their organization"},{key:"status",what:"Angel, prospect, contacted, declined"},{key:"sender_name",what:"Your name (typed in the send box)"},{key:"tickets_link",what:"Ticket page"},{key:"agenda_link",what:"Program page"},{key:"summit_link",what:"Summit homepage"}];function Z({templates:r,onClose:c,onSaved:p}){const[g,S]=i.useState(r),[_,h]=i.useState(!1),[T,N]=i.useState(null),[b,x]=i.useState(!1),v=(a,n)=>S(m=>m.map(u=>u.id===a?{...u,...n}:u)),C=()=>S(a=>[...a,{id:`new-${Math.random().toString(16).slice(2)}`,code:`A${a.length+1}`,label:"",subject:"",body:"",sort_order:a.length+1}]),$=async a=>{if(confirm(`Delete template ${a.code}?`)){if(!a.id.startsWith("new-")){const{error:n}=await j.from("angel_message_templates").delete().eq("id",a.id);if(n){N(n.message);return}}S(n=>n.filter(m=>m.id!==a.id)),p()}},f=async()=>{h(!0),N(null);try{for(const[a,n]of g.entries()){if(!n.code.trim()||!n.body.trim())continue;const m={code:n.code.trim(),label:n.label??"",subject:n.subject??"",body:n.body,sort_order:a+1},u=n.id.startsWith("new-")?await j.from("angel_message_templates").insert(m):await j.from("angel_message_templates").update(m).eq("id",n.id);if(u.error)throw new Error(u.error.message)}p(),c()}catch(a){N(a instanceof Error?a.message:"Could not save templates.")}finally{h(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",children:e.jsxs("div",{className:"max-h-[90vh] w-full max-w-5xl space-y-4 overflow-y-auto rounded-xl border border-white/15 bg-[#0b1220] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-widest text-summit-white",children:"Angel message templates"}),e.jsx("p",{className:"text-[11px] text-summit-white/50",children:"Used when you click A1, A2 ⦠on an angel row or send to a selection."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>x(a=>!a),className:"rounded-md border border-white/20 px-3 py-1.5 text-[11px] font-bold uppercase tracking-widest text-summit-white hover:bg-white/10",children:"Variables"}),e.jsx("button",{onClick:c,className:"text-summit-white/60 hover:text-summit-white",children:"â"})]})]}),b&&e.jsx("ul",{className:"grid gap-1 rounded-lg border border-white/15 bg-white/[0.03] p-3 sm:grid-cols-2",children:X.map(a=>e.jsxs("li",{className:"text-[11px] text-summit-white/60",children:[e.jsx("code",{className:"text-summit-white/90",children:`{${a.key}}`})," â ",a.what]},a.key))}),g.map(a=>e.jsxs("div",{className:"space-y-2 rounded-lg border border-white/10 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:a.code,onChange:n=>v(a.id,{code:n.target.value}),placeholder:"A1",className:`${V} max-w-[90px]`}),e.jsx("input",{value:a.label??"",onChange:n=>v(a.id,{label:n.target.value}),placeholder:"Label (e.g. Intro / invitation)",className:`${V} max-w-xs`}),e.jsx("button",{onClick:()=>{$(a)},className:"ml-auto rounded-md border border-red-400/40 px-2 py-1 text-[10px] uppercase tracking-widest text-red-300 hover:bg-red-500/10",children:"Delete"})]}),e.jsx("input",{value:a.subject??"",onChange:n=>v(a.id,{subject:n.target.value}),placeholder:"Subject line",className:V}),e.jsx("textarea",{value:a.body,onChange:n=>v(a.id,{body:n.target.value}),rows:9,className:`${V} resize-y font-mono text-xs`})]},a.id)),T&&e.jsx("p",{className:"text-xs text-red-300",children:T}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:C,className:"rounded-md border border-white/20 px-3 py-1.5 text-[11px] uppercase tracking-widest text-summit-white hover:bg-white/10",children:"Add template"}),e.jsx("button",{onClick:c,className:"rounded-md border border-white/20 px-3 py-1.5 text-[11px] uppercase tracking-widest text-summit-white/70",children:"Cancel"}),e.jsx("button",{onClick:()=>{f()},disabled:_,className:"rounded-md bg-summit-white px-4 py-1.5 text-[11px] font-bold uppercase tracking-widest text-midnight disabled:opacity-50",children:_?"Savingâ¦":"Save templates"})]})]})})}function ee({rows:r,templates:c,initialCode:p,onClose:g,onSent:S}){const _=Y(K),h=[...c,{id:"blank",code:"Blank",label:"Empty message",subject:"",body:"",sort_order:999}],[T,N]=i.useState((p&&h.find(o=>o.code===p)?.code)??h[0]?.code??"Blank"),b=h.find(o=>o.code===T)??h[0],[x,v]=i.useState("The Summit team"),[C,$]=i.useState(""),[f,a]=i.useState(""),[n,m]=i.useState(!1),[u,M]=i.useState(!1),[R,w]=i.useState([]),[P,k]=i.useState(null),z=r[0];i.useEffect(()=>{n||!z||($(F(b.subject??"",z,x)),a(F(b.body??"",z,x)))},[b,z,x,n]);const A=r.filter(o=>(o.email??"").includes("@")),q=async()=>
1{if(!z)return;M(!0),k(null),w([]);const o=n?C:b.subject??"",y=n?f:b.body??"";for(const E of A)try{await _({data:{angelId:E.id,to:E.email,subject:r.length>1?F(o,E,x):C,body:r.length>1?F(y,E,x):f,templateCode:b.code}}),w(t=>[...t,`â ${E.full_name}`])}catch(t){w(l=>[...l,`â ${E.full_name} â ${t instanceof Error?t.message:"failed"}`])}M(!1),S?.()};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",children:e.jsxs("div",{className:"max-h-[90vh] w-full max-w-3xl space-y-3 overflow-y-auto rounded-xl border border-white/15 bg-[#0b1220] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold uppercase tracking-widest text-summit-white",children:["Email ",r.length===1?r[0].full_name:`${A.length} people`]}),r.length>1&&e.jsx("p",{className:"text-[11px] text-summit-white/50",children:r.length-A.length>0?`${r.length-A.length} selected have no email and will be skipped.`:"Each person gets their own personalized copy."})]}),e.jsx("button",{onClick:g,className:"text-summit-white/60 hover:text-summit-white",children:"â"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.map(o=>e.jsx("button",{onClick:()=>{N(o.code),m(!1)},className:`rounded-md px-2.5 py-1 text-[11px] font-bold uppercase tracking-widest ${o.code===T?"bg-[#00acf0] text-midnight":"border border-white/20 text-summit-white/70 hover:bg-white/10"}`,title:o.label,children:o.code},o.code))}),e.jsx("input",{value:x,onChange:o=>v(o.target.value),placeholder:"Your name (used by {sender_name})",className:V}),e.jsx("input",{value:C,onChange:o=>{m(!0),$(o.target.value)},placeholder:"Subject",className:V}),e.jsx("textarea",{value:f,onChange:o=>{m(!0),a(o.target.value)},rows:12,className:`${V} resize-y`}),P&&e.jsx("p",{className:"text-xs text-red-300",children:P}),R.length>0&&e.jsx("div",{className:"max-h-40 overflow-auto rounded-md border border-white/10 bg-white/[0.03] p-2 text-[11px] text-summit-white/70",children:R.map((o,y)=>e.jsx("p",{children:o},y))}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:g,className:"rounded-md border border-white/20 px-3 py-1.5 text-[11px] uppercase tracking-widest text-summit-white/70",children:"Close"}),e.jsx("button",{onClick:()=>{q()},disabled:u||A.length===0||!C.trim()||!f.trim(),className:"rounded-md bg-summit-white px-4 py-1.5 text-[11px] font-bold uppercase tracking-widest text-midnight disabled:opacity-50",children:u?"Sendingâ¦":`Send to ${A.length}`})]})]})})}const I=["angel","prospect","contacted","declined"],B="w-full rounded-md border border-white/10 bg-white/[0.04] px-2 py-1 text-xs text-summit-white placeholder:text-summit-white/30 focus:border-[#00acf0] focus:outline-none",O="id, full_name, email, phone, city, organization, status, notes, source_list, amount, last_contacted_at, created_at";function ie(){const[r,c]=i.useState([]),[p,g]=i.useState({}),[S,_]=i.useState({}),[h,T]=i.useState(["angel","prospect","contacted"]),[N,b]=i.useState(""),[x,v]=i.useState(new Set),[C,$]=i.useState(!1),[f,a]=i.useState(null),[n,m]=i.useState(!0),{templates:u,reload:M}=Q(),R=async()=>{m(!0);const[{data:t},{data:l},{data:d}]=await Promise.all([j.from("angels").select(O).order("full_name",{ascending:!0}),j.rpc("get_angel_confirmations"),j.from("angel_message_sends").select("angel_id, template_code")]);c(t??[]);const s={};for(const L of l??[])s[L.angel_id]=L.kinds??[];g(s);const D={};for(const L of d??[])(D[L.angel_id]??=new Set).add(L.template_code);_(D),m(!1)};i.useEffect(()=>{R()},[]);const w=i.useMemo(()=>r.filter(t=>h.includes(t.status)?H(N,t.full_name,t.email,t.phone,t.city,t.organization,t.notes):!1),[r,h,N]),P=i.useMemo(()=>{const t={};for(const l of r)t[l.status]=(t[l.status]??0)+1;return t},[r]),k=async(t,l)=>{c(d=>d.map(s=>s.id===t?{...s,...l}:s)),await j.from("angels").update(l).eq("id",t)},z=async()=>{const t=prompt("Full name");if(!t?.trim())return;const{data:l}=await j.from("angels").insert({full_name:t.trim(),status:"prospect"}).select(O).maybeSingle();l&&c(d=>[...d,l])},A=async t=>{confirm(`Remove ${t.full_name} from the angels list?`)&&(await j.from("angels").delete().eq("id",t.id),c(l=>l.filter(d=>d.id!==t.id)))},q=t=>v(l=>{const d=new Set(l);return d.has(t)?d.delete(t):d.add(t),d}),o=w.length>0&&w.every(t=>x.has(t.id)),y=r.filter(t=>x.has(t.id)),E=async()=>{const t=y.map(l=>l.email).filter(l=>!!l&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l));if(!t.length){alert("No valid emails among the selected rows.");return}try{await navigator.clipboard.writeText(t.join(", ")),alert(`Copied ${t.length} email${t.length>
11?"s":""} to clipboard.`)}catch{alert(t.join(", "))}};return e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"text-sm font-semibold uppercase tracking-widest text-summit-white",children:"Angels & prospects"}),e.jsxs("span",{className:"text-[11px] text-summit-white/50",children:[w.length," shown · ",r.length," total"]}),e.jsxs("div",{className:"ml-auto flex flex-wrap gap-2",children:[e.jsx("input",{value:N,onChange:t=>b(t.target.value),placeholder:"Search name, email, cityâ¦",className:"rounded-md border border-white/15 bg-white/[0.04] px-3 py-1.5 text-xs text-summit-white placeholder:text-summit-white/40 focus:border-[#00acf0] focus:outline-none"}),e.jsx("button",{onClick:()=>{z()},className:"rounded-md border border-white/20 px-3 py-1.5 text-[11px] font-bold uppercase tracking-widest text-summit-white hover:bg-white/10",children:"Add person"}),e.jsx("button",{onClick:()=>$(!0),className:"rounded-md border border-white/20 px-3 py-1.5 text-[11px] font-bold uppercase tracking-widest text-summit-white hover:bg-white/10",children:"Templates"}),e.jsxs("button",{onClick:()=>y.length&&a({rows:y}),disabled:y.length===0,className:"rounded-md bg-summit-white px-3 py-1.5 text-[11px] font-bold uppercase tracking-widest text-midnight disabled:opacity-40",children:["Email selected (",y.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>{E()},disabled:y.length===0,title:"Copy all selected emails",className:"inline-flex items-center gap-1 rounded-md border border-white/20 px-3 py-1.5 text-[11px] font-bold uppercase tracking-widest text-summit-white hover:bg-white/10 disabled:opacity-40",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),"Copy emails"]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:I.map(t=>e.jsxs("button",{onClick:()=>T(l=>l.includes(t)?l.filter(d=>d!==t):[...l,t]),className:`rounded-full px-3 py-1 text-[11px] font-bold uppercase tracking-widest ${h.includes(t)?"bg-[#00acf0] text-midnight":"border border-white/20 text-summit-white/60 hover:bg-white/10"}`,children:[t," (",P[t]??0,")"]},t))}),n?e.jsx("p",{className:"text-sm text-summit-white/60",children:"Loading angelsâ¦"}):w.length===0?e.jsx("p",{className:"text-sm text-summit-white/60",children:"No one here yet. Send me the Angels and Prospects lists and I will load them in."}):e.jsx("div",{className:"overflow-x-auto rounded-xl border border-white/10",children:e.jsxs("table",{className:"w-full min-w-[1100px] text-left text-xs",children:[e.jsx("thead",{className:"bg-white/[0.04] text-[10px] uppercase tracking-widest text-summit-white/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-2 py-2",children:e.jsx("input",{type:"checkbox",checked:o,onChange:t=>v(l=>{const d=new Set(l);for(const s of w)t.target.checked?d.add(s.id):d.delete(s.id);return d})})}),e.jsx("th",{className:"px-2 py-2",children:"Name"}),e.jsx("th",{className:"px-2 py-2",children:"Confirmed"}),e.jsx("th",{className:"px-2 py-2",children:"Messages"}),e.jsx("th",{className:"px-2 py-2",children:"Status"}),e.jsx("th",{className:"px-2 py-2",children:"Email"}),e.jsx("th",{className:"px-2 py-2",children:"Phone"}),e.jsx("th",{className:"px-2 py-2",children:"City"}),e.jsx("th",{className:"px-2 py-2",children:"Organization"}),e.jsx("th",{className:"px-2 py-2",children:"Notes"}),e.jsx("th",{className:"px-2 py-2"})]})}),e.jsx("tbody",{children:w.map(t=>{const l=p[t.id]??[],d=S[t.id]??new Set;return e.jsxs("tr",{className:`border-t border-white/5 align-top ${l.length>0?"bg-emerald-500/[0.07]":""}`,children:[e.jsx("td",{className:"px-2 py-2",children:e.jsx("input",{type:"checkbox",checked:x.has(t.id),onChange:()=>q(t.id)})}),e.jsx("td",{className:"px-2 py-2 min-w-[160px]",children:e.jsx("input",{defaultValue:t.full_name,onBlur:s=>s.target.value.trim()&&s.target.value!==t.full_name&&void k(t.id,{full_name:s.target.value.trim()}),className:B})}),e.jsx("td",{className:"px-2 py-2 whitespace-nowrap",children:l.length>0?e.jsxs("span",{className:"text-emerald-300",title:`Already ${l.join(", ")}
1`,children:["â ",l.join(", ")]}):e.jsx("span",{className:"text-summit-white/30",children:"â"})}),e.jsx("td",{className:"px-2 py-2",children:e.jsx("div",{className:"flex flex-wrap gap-1",style:{maxWidth:130},children:u.map(s=>e.jsx("button",{onClick:()=>a({rows:[t],code:s.code}),title:`${s.label||s.code}${d.has(s.code)?" â already sent":""}`,className:`rounded px-1.5 py-0.5 text-[10px] font-bold uppercase ${d.has(s.code)?"bg-emerald-500/25 text-emerald-200":"border border-white/20 text-summit-white/60 hover:bg-white/10"}`,children:s.code},s.code))})}),e.jsx("td",{className:"px-2 py-2",children:e.jsx("select",{value:t.status,onChange:s=>{k(t.id,{status:s.target.value})},className:B,children:I.map(s=>e.jsx("option",{value:s,className:"bg-[#0b1220]",children:s},s))})}),e.jsx("td",{className:"px-2 py-2 min-w-[180px]",children:e.jsx("input",{defaultValue:t.email??"",onBlur:s=>s.target.value!==(t.email??"")&&void k(t.id,{email:s.target.value.trim()||null}),className:B})}),e.jsx("td",{className:"px-2 py-2 min-w-[130px]",children:e.jsx("input",{defaultValue:t.phone??"",onBlur:s=>s.target.value!==(t.phone??"")&&void k(t.id,{phone:s.target.value.trim()||null}),className:B})}),e.jsx("td",{className:"px-2 py-2 min-w-[110px]",children:e.jsx("input",{defaultValue:t.city??"",onBlur:s=>s.target.value!==(t.city??"")&&void k(t.id,{city:s.target.value.trim()||null}),className:B})}),e.jsx("td",{className:"px-2 py-2 min-w-[140px]",children:e.jsx("input",{defaultValue:t.organization??"",onBlur:s=>s.target.value!==(t.organization??"")&&void k(t.id,{organization:s.target.value.trim()||null}),className:B})}),e.jsx("td",{className:"px-2 py-2 min-w-[180px]",children:e.jsx("input",{defaultValue:t.notes??"",onBlur:s=>s.target.value!==(t.notes??"")&&void k(t.id,{notes:s.target.value.trim()||null}),className:B})}),e.jsx("td",{className:"px-2 py-2",children:e.jsx("button",{onClick:()=>{A(t)},className:"rounded border border-red-400/40 px-2 py-0.5 text-[10px] uppercase text-red-300 hover:bg-red-500/10",children:"Del"})})]},t.id)})})]})}),C&&e.jsx(Z,{templates:u,onClose:()=>$(!1),onSaved:()=>{M()}}),f&&e.jsx(ee,{rows:f.rows,templates:u,initialCode:f.code,onClose:()=>a(null),onSent:()=>{R()}})]})}export{ie 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.