1import{r as a,j as e,di as H,a7 as ne,dJ as k,dA as re,dz as le,b as oe,c as B,dC as ce,S as M,d5 as Y,at as de,dy as me,x as Z,ap as Q,N as ue,e2 as pe,ed as xe,L as be,dF as he,e3 as ge,dG as fe,C as ye,e8 as je,U as F,dI as C}from"./index-Dp6uzjnE.js";import{A as Ne,o as ve,c as we}from"./arionMarketingShared-L_eE-bBc.js";import{b as ke}from"./ArionMarketingTemplateGallery-B0IH4ETq.js";const Se=[{id:"UTC",label:"UTC â Coordinated Universal Time",city:"UTC",region:"Global"},{id:"Africa/Johannesburg",label:"Johannesburg (SAST)",city:"Johannesburg",region:"Africa"},{id:"Africa/Lagos",label:"Lagos (WAT)",city:"Lagos",region:"Africa"},{id:"Africa/Nairobi",label:"Nairobi (EAT)",city:"Nairobi",region:"Africa"},{id:"Africa/Cairo",label:"Cairo (EET)",city:"Cairo",region:"Africa"},{id:"Europe/London",label:"London (GMT/BST)",city:"London",region:"Europe"},{id:"Europe/Paris",label:"Paris (CET/CEST)",city:"Paris",region:"Europe"},{id:"America/New_York",label:"New York (ET)",city:"New York",region:"Americas"},{id:"America/Chicago",label:"Chicago (CT)",city:"Chicago",region:"Americas"},{id:"America/Los_Angeles",label:"Los Angeles (PT)",city:"Los Angeles",region:"Americas"},{id:"Asia/Dubai",label:"Dubai (GST)",city:"Dubai",region:"Asia"},{id:"Asia/Singapore",label:"Singapore (SGT)",city:"Singapore",region:"Asia"}];function Ce(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function Te(i){try{return new Intl.DateTimeFormat("en-US",{timeZone:i,timeZoneName:"shortOffset",hour:"2-digit",minute:"2-digit"}).formatToParts(new Date).find(n=>n.type==="timeZoneName")?.value||""}catch{return""}}function Ae(i){const l=new Map(Se.map(n=>[n.id,n]));if(!l.has(i)){const n=i.split("/").pop()?.replace(/_/g," ")||i;l.set(i,{id:i,label:`${n} (detected)`,city:n,region:"Detected"})}return[...l.values()].sort((n,r)=>n.label.localeCompare(r.label))}function _e(i,l){const[n,r]=i.split("T");if(!n||!r)return new Date(i).toISOString().slice(0,19).replace("T"," ");const[u,d,p]=n.split("-").map(Number),[h,m]=r.split(":").map(Number);let y=Date.UTC(u,d-1,p,h,m,0);for(let x=0;x<3;x++){const j=new Intl.DateTimeFormat("en-US",{timeZone:l,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}).formatToParts(new Date(y)),o=g=>Number(j.find(b=>b.type===g)?.value||0),N=Date.UTC(o("year"),o("month")-1,o("day"),o("hour"),o("minute"),o("second")),v=Date.UTC(u,d-1,p,h,m,0);y+=v-N}return new Date(y).toISOString().slice(0,19).replace("T"," ")}function Ee({campaignName:i,open:l,onClose:n,onSchedule:r}){const u=a.useMemo(()=>Ce(),[]),d=a.useMemo(()=>Ae(u),[u]),[p,h]=a.useState(""),[m,y]=a.useState(u),[x,j]=a.useState(""),[o,N]=a.useState(!1),v=a.useMemo(()=>{const s=x.trim().toLowerCase();return s?d.filter(c=>c.id.toLowerCase().includes(s)||c.label.toLowerCase().includes(s)||c.city.toLowerCase().includes(s)||c.region.toLowerCase().includes(s)):d},[d,x]),g=d.find(s=>s.id===m)||d[0],b=Te(m);if(!l)return null;const S=new Date(Date.now()+300*1e3).toISOString().slice(0,16);async function A(){if(p){N(!0);try{const s=_e(p,m);await r(s),n()}finally{N(!1)}}}return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-ink-950/50 backdrop-blur-sm p-4",role:"dialog","aria-modal":!0,children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl bg-white shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4 text-primary"}),e.jsx("h2",{className:"text-sm font-bold text-ink-950",children:"Schedule campaign"})]}),e.jsx("button",{type:"button",onClick:n,className:"rounded-lg p-1.5 text-ink-400 hover:bg-surface-muted","aria-label":"Close",children:e.jsx(ne,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("p",{className:"text-sm text-ink-600",children:["Send ",e.jsx("strong",{className:"text-ink-900",children:i})," at a specific date and time. Choose a city timezone that matches the wall clock below."]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-semibold uppercase tracking-wide text-ink-400 mb-1",children:"Timezone"}),e.jsx("input",{type:"search",className:`${k} mb-2`,placeholder:"Search city or regionâ¦",value:x,onChange:s=>j(s.target.value),"aria-label":"Search timezones"}),e.jsx("div",{className:"max-h-40 overflow-y-auto rounded-xl border border-border divide-y divide-border",children:v.length===0?e.jsx("p",{className:"px-3 py-3 text-sm text-ink-500",children:"No matching timezones."}):v.map(s=>{const c=s.id===m;return e.jsxs("button",{type:"button",onClick:()=>{y(s.id),j("")},className:`w-full text-left px-3 py-2.5 text-sm transition-colors ${c?"bg-[#edf3ee] text-ink-950 font-semibold":"hover:bg-surface-muted text-ink-700"}`,children:[e.jsx("span",{className:"block",children:s.label}),e.jsxs("span",{className:"block text-[11px] text-ink-400 mt-0.5",children:[s.id,s.id===u?" · detected":"",c&&b?` · ${b}`:""]})]},s.id)})}),g?e.jsxs("p",{className:"mt-2 text-xs text-ink-500",children:["Selected: ",e.jsx("span",{className:"font-medium text-ink-700",children:g.label}),b?` (${b})`:""]}):null]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[10px] font-semibold uppercase tracking-wide text-ink-400 mb-1",children:["Send date & time (",g?.city||m,")"]}),e.jsx("input",{type:"datetime-local",className:k,min:S,value:p,onChange:s=>h(s.target.value)})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("button",{type:"button",disabled:!p||o,onClick:()=>{A()},className:"flex-1 rounded-xl bg-primary px-4 py-2.5 text-sm font-semibold text-white disabled:opacity-50",children:o?"Schedulingâ¦":"Schedule send"}),e.jsx("button",{type:"button",onClick:n,className:"rounded-xl border border-border px-4 py-2.5 text-sm font-semibold text-ink-700",children:"Cancel"})]})]})]})})}function Me(){const{orgId:i}
1=re(),l=le(),[n]=oe(),[r,u]=a.useState([]),[d,p]=a.useState([]),[h,m]=a.useState([]),[y,x]=a.useState(!0),[j,o]=a.useState(!1),[N,v]=a.useState(null),[g,b]=a.useState(!0),[S,A]=a.useState(""),[s,c]=a.useState(""),[_,G]=a.useState("system:healthcare-newsletter"),[I,z]=a.useState(""),[q,V]=a.useState("This quarter we're tracking regulatory shifts, digital health adoption, and private-market activity across your sector."),[U,W]=a.useState(""),[E,J]=a.useState(null),[P,X]=a.useState(!1),[$,K]=a.useState(""),[O,ee]=a.useState(20);a.useEffect(()=>{document.title="Arion â Marketing campaigns â Medarion"},[]),a.useEffect(()=>{const t=n.get("template");t&&G(t)},[n]);const w=a.useMemo(()=>h.find(t=>String(t.id)===_),[h,_]);a.useEffect(()=>{w?.subject_line&&!s&&c(w.subject_line.replace(/\{\{org_name\}\}/g,"Your organization"))},[w,s]);const T=a.useCallback(async()=>{if(i){x(!0);try{const[t,f,L]=await Promise.all([B(`/api/v1/crm/marketing/campaigns?org_profile_id=${i}`),B(`/api/v1/crm/marketing/audiences?org_profile_id=${i}`),B(`/api/v1/crm/marketing/templates?org_profile_id=${i}`)]);u(t.results||[]),p(f.results||[]),m(L.results||[]),f.results?.[0]&&I===""&&z(f.results[0].id)}finally{x(!1)}}},[i]);a.useEffect(()=>{T()},[T]);async function te(){if(!(!i||!S.trim()||!s.trim())){o(!0);try{await F("/api/v1/crm/marketing/campaigns",{org_profile_id:i,name:S.trim(),subject:s.trim(),template_id:_,preheader:w?.preheader||null,audience_id:I||null,body_content:q,cta_url:"https://medarion.ai/arion/marketing",cta_label:w?.category==="event"?"Reserve your seat":"View briefing",ab_enabled:P&&$.trim()?1:0,ab_subject_b:P?$.trim():null,ab_test_pct:O,ab_winner_criteria:"open"}),A(""),c(""),b(!1),await T(),C("Campaign draft created")}catch{C("Could not create campaign","error")}finally{o(!1)}}}async function R(t,f){if(i){v(t);try{const L={org_profile_id:i};f&&U.trim()&&(L.test_email=U.trim());const D=await F(`/api/v1/crm/marketing/campaigns/${t}/send`,L);C(f?`Test sent (${D.sent} ok)`:D.ab_testing?`A/B test started (${D.sent} test sends)`:`Sent to ${D.sent} recipients`),await T()}catch{C("Send failed â check audience & SMTP","error")}finally{v(null)}}}async function ae(t,f){if(i)try{await F(`/api/v1/crm/marketing/campaigns/${t}/schedule`,{org_profile_id:i,scheduled_at:f}),C("Campaign scheduled"),await T()}catch{C("Could not schedule","error")}}const se=r.filter(t=>t.status==="sent").length,ie=r.filter(t=>t.status==="draft").length;return e.jsx(ce,{title:"Email campaigns",lead:"Pick a pro template, personalize copy, test in your inbox, then broadcast to synced audiences.",badge:"Campaigns",icon:Y,loading:y,stats:[{icon:Y,label:"Total",value:r.length,color:M.indigo},{icon:de,label:"Drafts",value:ie,color:M.slate},{icon:H,label:"Scheduled",value:r.filter(t=>t.status==="scheduled").length,color:M.amber},{icon:me,label:"Sent",value:se,color:M.emerald}],children:e.jsxs("div",{className:"space-y-5",children:[e.jsx(Ne,{}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("p",{className:"text-sm text-ink-500",children:["Need inspiration?"," ",e.jsx(Z,{to:`${l.base}/marketing/templates`,className:"font-medium text-primary hover:underline",children:"Browse the template gallery"})]}),e.jsxs("button",{type:"button",onClick:()=>b(t=>!t),className:"inline-flex items-center gap-2 rounded-lg border border-border bg-white px-3 py-1.5 text-xs font-semibold text-ink-800 hover:bg-surface-muted transition",children:[e.jsx(Q,{className:"h-3.5 w-3.5"}),g?"Hide composer":"New campaign"]})]}),g&&e.jsxs("div",{className:"rounded-2xl border border-border bg-white shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"border-b border-border bg-gradient-to-r from-[#fffefa] to-indigo-50/30 px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-4 w-4 text-violet-600"}),e.jsx("h2",{className:"text-sm font-bold text-ink-950",children:"Campaign composer"})]}),e.jsx("p",{className:"text-xs text-ink-500 mt-0.5",children:"Select a template, write your message, choose an audience."})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-0 lg:divide-x divide-border",children:[e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx(ke,{templates:h,value:_,onCh
1ange:G}),w&&e.jsx("p",{className:"text-xs text-ink-500 leading-relaxed",children:w.description})]}),e.jsxs("div",{className:"p-5 space-y-3 bg-surface-muted/10",children:[e.jsx("input",{className:k,placeholder:"Campaign name (internal)",value:S,onChange:t=>A(t.target.value)}),e.jsx("input",{className:k,placeholder:"Email subject line",value:s,onChange:t=>c(t.target.value)}),e.jsxs("select",{className:pe,value:I,onChange:t=>z(t.target.value?Number(t.target.value):""),children:[e.jsx("option",{value:"",children:"Select audienceâ¦"}),d.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (",t.member_count," subscribers)"]},t.id))]}),e.jsx("textarea",{className:`${k} min-h-[120px]`,value:q,onChange:t=>V(t.target.value),placeholder:"Main body copy â this fills the template content areaâ¦"}),e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3 space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-semibold text-ink-700 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:P,onChange:t=>X(t.target.checked),className:"rounded border-border"}),e.jsx(xe,{className:"h-3.5 w-3.5 text-violet-600"})," A/B test subject lines"]}),P&&e.jsxs(e.Fragment,{children:[e.jsx("input",{className:k,placeholder:"Subject line B (variant)",value:$,onChange:t=>K(t.target.value)}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-[10px] font-semibold text-ink-400 uppercase shrink-0",children:"Test size"}),e.jsx("input",{type:"range",min:10,max:50,value:O,onChange:t=>ee(Number(t.target.value)),className:"flex-1"}),e.jsxs("span",{className:"text-xs font-semibold text-ink-600 w-10",children:[O,"%"]})]}),e.jsx("p",{className:"text-[10px] text-ink-400",children:"Sends test group first, then pick winner and send to remainder from analytics."})]})]}),e.jsxs("button",{type:"button",disabled:j||!S.trim()||!s.trim(),onClick:()=>{te()},className:"inline-flex w-full items-center justify-center gap-2 rounded-xl bg-primary px-4 py-2.5 text-sm font-semibold text-white disabled:opacity-50 shadow-sm",children:[j?e.jsx(be,{className:"h-4 w-4 animate-spin"}):e.jsx(Q,{className:"h-4 w-4"}),"Save as draft"]})]})]})]}),e.jsxs(he,{title:"Campaigns",lead:"Test before you send. Scheduled campaigns dispatch automatically.",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-end gap-3 rounded-xl bg-surface-muted/30 p-3",children:[e.jsxs("div",{className:"flex-1 min-w-[200px]",children:[e.jsx("label",{className:"block text-[10px] font-semibold uppercase tracking-wide text-ink-400 mb-1",children:"Test inbox"}),e.jsx("input",{className:k,placeholder:"[email protected]",value:U,onChange:t=>W(t.target.value)})]}),e.jsx("p",{className:"text-xs text-ink-400 max-w-xs",children:"Send a test from any draft to preview the full designed email."})]}),r.length?e.jsx("div",{className:"overflow-x-auto -mx-1",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[10px] uppercase tracking-wider text-ink-400 border-b border-border",children:[e.jsx("th",{className:"pb-3 pr-4 font-semibold",children:"Campaign"}),e.jsx("th",{className:"pb-3 pr-4 font-semibold",children:"Status"}),e.jsx("th",{className:"pb-3 pr-4 font-semibold text-right",children:"Sent"}),e.jsx("th",{className:"pb-3 pr-4 font-semibold text-right",children:"Open"}),e.jsx("th",{className:"pb-3 pr-4 font-semibold text-right",children:"Click"}),e.jsx("th",{className:"pb-3 font-semibold",children:"Actions"})]})}),e.jsx("tbody",{children:r.map(t=>e.jsxs("tr",{className:"border-b border-border/50 last:border-0 hover:bg-surface-muted/20 transition",children:[e.jsxs("td",{className:"py-4 pr-4",children:[e.jsx("p",{className:"font-semibold text-ink-900",children:t.name}),e.jsx("p",{className:"text-xs text-ink-500 truncate max-w-[240px] mt-0.5",children:t.subject})]}),e.jsx("td",{className:"py-4 pr-4",children:e.jsx(fe,{status:t.status})}),e.jsx("td",{className:"py-4 pr-4 text-right tabular-nums text-ink-700",children:t.sent_count||"â"}),e.jsx("td",{className:"py-4 pr-4 text-right tabular-nums text-ink-700",children:t.status==="sent"||t.status==="ab_testing"?ve(t):"â"}),e.jsx("td",{className:"py-4 pr-4 text-right tabular-nums text-ink-700",children:t.status==="sent"||t.status==="ab_testing"?we(t):"â"}),e.jsx("td",{className:"py-4",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.status==="sent"||t.status==="ab_testing")&&e.jsxs(Z,{to:l.marketingCampaignDetail(t.id),className:"inline-flex items-center gap-1 rounded-lg border border-border bg-white px-2.5 py-1 text-xs font-semibold hover:bg-surface-muted",children:[e.jsx(ye,{className:"h-3 w-3"})," Analytics"]}),(t.status==="draft"||t.status==="scheduled")&&e.jsxs(e.Fragment,{children:[e.jsxs(Z,{to:l.marketingEditorCampaign(t.id),className:"inline-flex items-center gap-1 rounded-lg border border-primary/30 bg-primary/5 px-2.5 py-1 text-xs font-semibold text-primary hover:bg-primary/10",children:[e.jsx(je,{className:"h-3 w-3"}),"Edit design"]}),e.jsx("button",{type:"button",disabled:N===t.id,onClick:()=>{R(t.id,!0)},className:"rounded-lg border border-border bg-white px-2.5 py-1 text-xs font-semibold hover:bg-surface-muted",children:"Test"}),e.jsx("button",{type:"button",disabled:N===t.id,onClick:()=>{R(t.id)},className:"rounded-lg bg-primary px-2.5 py-1 text-xs font-semibold text-white disabled:opacity-50",children:"Send"}),e.jsx("button",{type:"button",onClick:()=>J(t),className:"rounded-lg border border-border bg-white px-2.5 py-1 text-xs font-semibold hover:bg-surface-muted",children:"Schedule"})]})]})})]},t.id))})]})}):e.jsx(ge,{title:"No campaigns yet",description:"Use the composer above to create your first broadcast."})]}),e.jsx(Ee,{campaignName:E?.name||"Campaign",open:!!E,onClose:()=>J(null),onSchedule:async t=>{E&&await ae(E.id,t)}})]})})}export{Me as ArionMarketingCampaignsPage};
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.