1import{j as e}from"./vendor-ui-DQHO55SA.js";import{i as Ge,d as Ze,r as c}from"./vendor-react-DvT_7ksp.js";import{s as x,I as b,B as Se,k as h,a as p,L as P,t as Ce,d as j,f as Je,g as Ke,h as Xe,i as Ye,j as es}from"./index-DM0socOE.js";import{p as R,l as ss,m as ts,n as X,o as Y,T as ee,g as se,h as S,i as m,j as te,k as d,D as as}from"./switch-DXixMgHE.js";import{A as rs}from"./AdminSidebar-IX28dQ9Z.js";import{C as ns}from"./CreativePreviewDialog-Dr51Ubyk.js";import{r as ls,i as ae,c as re,C as is,q as cs,o as ds,S as os,d as ms}from"./EmailCreativeEditor-RDNnp-41.js";import{C as q,c as L}from"./card-B7kqqMYO.js";import{T as us}from"./textarea-Dx42AVsh.js";import{S as U,a as V,b as H,c as B,d as M}from"./select-B6MLd_ju.js";import{A as xs,a as hs,b as ps,c as js,d as gs,e as _s,f as fs,g as vs}from"./alert-dialog-CcqH78Lh.js";import{A as ke}from"./arrow-left-GeBJYhZD.js";import{C as bs}from"./copy-0lg8yaI5.js";import{a as Ns,d as ws,A as ys,c as Ss,P as Cs}from"./type-DWOgmWnf.js";import{Z as ks}from"./zap-Bi8P_nl5.js";import{R as Ds}from"./refresh-cw-DQMQ9_i4.js";import{P as De}from"./plus-Bk_Pn1eT.js";import{E as As}from"./eye-CKoSa8Xb.js";import{S as qs}from"./send-BKnV8BZ2.js";import"./vendor-supabase-BDrnlzN_.js";import"./vendor-query-BV9R99bn.js";import"./skeleton-C63uJQjt.js";import"./panel-left-C8U6OxE1.js";import"./index-YYxqAwMx.js";import"./mp3ify-logo-CwDpZ1WH.js";import"./shield-CDrRreiL.js";import"./sun-BzybZhkK.js";import"./layout-dashboard-Hy5w7nVh.js";import"./users-BSYTVtoA.js";import"./settings-DR0bwkQm.js";import"./crown-BMC5HIVS.js";import"./globe-BUZzaqCM.js";import"./search-CcBais5Z.js";import"./message-square-Cc0XXH_C.js";import"./file-text-CI6B2Yv9.js";import"./megaphone-DhP1ICmR.js";import"./external-link-CLMTLdHe.js";import"./image-plus-Cca-rucx.js";import"./upload-CTJKoDES.js";import"./check-BA3REW7K.js";import"./sparkles-9vsrunsn.js";import"./mouse-pointer-click-Cbhs6SlR.js";import"./chevron-up-Bw6GThAd.js";const Q=(r,o)=>o>0?`${(r/o*100).toFixed(1)}%`:"â",Ls=[{value:"entry",label:"Campaign entry"},{value:"trial_start",label:"Trial start"},{value:"trial_end",label:"Trial end"},{value:"signup",label:"Signup"},{value:"subscription_end",label:"Subscription end"}],Ts={trial_to_paid:"Free-trial users without a paid plan",onboarding_new_users:"Newly verified users (last 14 days)",dormant_30d:"Previously active users with no conversion in 30 days",winback_expired:"Subscribers whose paid plan lapsed in the last 30 days"},Ae=(r,o)=>({first_name:"Alex",app_url:"https://mp3ify.io",cta_url:o,goal_url:o,upgrade_url:o,discount_code:r.offer_percent?"TRIAL-PREVIEW":"",discount_percent:r.offer_percent?String(r.offer_percent):"",offer_expires_at:new Date(Date.now()+(r.offer_valid_days??3)*864e5).toISOString().slice(0,10),trial_end_date:new Date(Date.now()+3*864e5).toISOString().slice(0,10)}),ne=(r,o)=>r.replace(/\{\{\s*([\w.-]+)\s*\}\}/g,(C,g)=>g in o?o[g]:C),qe=(r,o)=>({theme:r?.theme,blocks:(r?.blocks??[]).map(C=>{const g={...C};for(const A of["text","href","src","html"])typeof g[A]=="string"&&(g[A]=ne(g[A],o));return g})}),v=({label:r,value:o,hint:C,onClick:g})=>e.jsx(q,{className:g?"cursor-pointer hover:border-primary/60 transition-colors":void 0,onClick:g,children:e.jsxs(L,{className:"p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:r}),e.jsx("div",{className:"text-lg font-semibold tabular-nums",children:o}),C&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:C})]})}),Nt=()=>{const{id:r}=Ge(),o=Ze(),[C,g]=c.useState(!0),[A,O]=c.useState(!1),[le,ie]=c.useState(!1),[a,ce]=c.useState(null),[N,T]=c.useState([]),[z,de]=c.useState([]),[I,Le]=c.useState([]),[Te,Ee]=c.useState(null),[oe,Oe]=c.useState([]),[k,me]=c.useState(null),[D,ue]=c.useState(null),[ze,xe]=c.useState(!1),[Ie,W]=c.useState(!1),[he,pe]=c.useState(null),[je,ge]=c.useState(null),[G,_e]=c.useState(null),[fe,$e]=c.useState([]),[Fe,ve]=c.useState(!1),be=async s=>{if(!r)return;_e(s),ve(!0);const{data:t,error:n}=await x.rpc("admin_followup_conversions_list",{_campaign_id:r,_mode:s});n&&h.error(n.message),$e(t??[]),ve(!1)},E=c.useCallback(async()=>
1{if(!r)return;g(!0);const[{data:s},{data:t},{data:n},{data:i},{data:f},{data:y}]=await Promise.all([x.from("followup_campaigns").select("*").eq("id",r).maybeSingle(),x.from("followup_campaign_steps").select("*").eq("campaign_id",r).order("step_order"),x.from("email_creatives").select("id,name,subject,design_json,html_cache").eq("status","active").order("name"),x.rpc("admin_followup_step_stats",{_campaign_id:r}),x.rpc("admin_followup_campaign_overview",{_campaign_id:r}),x.rpc("admin_followup_recent_sends",{_campaign_id:r,_limit:200})]);ce(s),T(t??[]),de(n??[]),Le(i??[]),Ee((f??[])[0]??null),Oe(y??[]),g(!1)},[r]);c.useEffect(()=>{E()},[E]);const _=(s,t)=>ce(n=>({...n,[s]:t})),w=(s,t)=>T(n=>n.map(i=>i.id===s?{...i,...t}:i)),Pe=s=>I.find(t=>t.step_id===s),Z=s=>z.find(t=>t.id===s)??null,$=a?.goal_destination_url||"https://mp3ify.io/free-trial?upgrade=1",J=c.useMemo(()=>{if(!k)return null;const s=Z(k.creative_id);if(!s)return null;const t=Ae(k,$);return{creative:s,design:qe(s.design_json||{blocks:[]},t),subject:ne(s.subject||"",t)}},[k,z,$]),F=c.useMemo(()=>{if(!D)return null;const s=Z(D.creative_id);if(!s)return null;const t=Ae(D,$);return{subject:ne(s.subject||"",t),html:ls(qe(s.design_json||{blocks:[]},t)),name:`${a?.name??"Follow-up"} â ${D.name}`}},[D,z,$,a?.name]),Re=async()=>{if(!r||!a)return;O(!0);const{error:s}=await x.from("followup_campaigns").update({name:a.name,description:a.description,audience_key:a.audience_key,throttle_per_hour:Number(a.throttle_per_hour)||0,quiet_hours_start:a.quiet_hours_start===null||a.quiet_hours_start===""?null:Number(a.quiet_hours_start),quiet_hours_end:a.quiet_hours_end===null||a.quiet_hours_end===""?null:Number(a.quiet_hours_end),quiet_hours_tz:a.quiet_hours_tz||ae,exit_on_conversion:a.exit_on_conversion,goal_destination_url:a.goal_destination_url,goal_type:a.goal_type??"purchase",utm_campaign:a.utm_campaign,updated_at:new Date().toISOString()}).eq("id",r);if(s)return O(!1),h.error(s.message);for(const t of N){const{error:n}=await x.from("followup_campaign_steps").update({name:t.name,step_order:t.step_order,anchor:t.anchor,delay_days:Number(t.delay_days)||0,creative_id:t.creative_id,offer_percent:t.offer_percent?Number(t.offer_percent):null,offer_valid_days:t.offer_valid_days?Number(t.offer_valid_days):null,enabled:t.enabled,updated_at:new Date().toISOString()}).eq("id",t.id);if(n)return O(!1),h.error(n.message)}O(!1),h.success("Saved"),E()},Ue=async s=>{if(!r)return;const{error:t}=await x.from("followup_campaigns").update({enabled:s,updated_at:new Date().toISOString()}).eq("id",r);if(t)return h.error(t.message);_("enabled",s),h.success(s?"Automation enabled":"Automation paused")},Ve=async()=>{if(!r)return;const s=(N[N.length-1]?.step_order??0)+1,{data:t,error:n}=await x.from("followup_campaign_steps").insert({campaign_id:r,step_order:s,name:`Step ${s}`,anchor:"trial_start",delay_days:0}).select("*").single();if(n)return h.error(n.message);T(i=>[...i,t])},He=async s=>{const{error:t}=await x.from("followup_campaign_steps").delete().eq("id",s);if(t)return h.error(t.message);T(n=>n.filter(i=>i.id!==s)),h.success("Step removed")},Ne=(s,t)=>{const n=s+t;if(n<0||n>=N.length)return;const i=[...N];[i[s],i[n]]=[i[n],i[s]],T(i.map((f,y)=>({...f,step_order:y+1})))},Be=async()=>{if(!a)return;const{id:s,created_at:t,updated_at:n,...i}=a,{data:f,error:y}=await x.from("followup_campaigns").insert({...i,name:`${a.name} (copy)`,enabled:!1}).select("id").single();if(y||!f)return h.error(y?.message??"Duplicate failed");N.length&&await x.from("followup_campaign_steps").insert(N.map(({id:l,campaign_id:ye,...We})=>({...We,campaign_id:f.id}))),h.success("Duplicated"),o(`/secure-portal-7x9k2m/dashboard/followup/${f.id}`)},Me=async()=>{if(!r)return;const{error:s}=await x.from("followup_campaigns").delete().eq("id",r);if(s)return h.error(s.message);h.success("Deleted"),o("/secure-portal-7x9k2m/dashboard?tab=marketing")},Qe=async()=>{ie(!0);const{error:s}=await x.functions.invoke("followup-tick",{body:{manual:!0}});if(ie(!1),s)return h.error(s.message);h.success("Automation tick executed"),E()},K=s=>e.jsx(as,{title:"Follow-up automation",subtitle:"Email marketing",sidebar:e.jsx(rs,{activeTab:"marketing",onTabChange:t=>o(`/secure-portal-7x9k2m/dashboard?tab=${t}`)}),children:s});if(C)return K(e.jsx("div",{className:"flex items-center justify-center py-24",children:e.jsx(P,{className:"h-6 w-6 animate-spin text-muted-foreground"})}));if(!a)return K(e.jsxs("div",{className:"py-24 text-center space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This follow-up automation no longer exists."}),e.jsxs(p,{variant:"outline",onClick:()=>o("/secure-portal-7x9k2m/dashboard?tab=marketing"),children:[e.jsx(ke,{className:"h-4 w-4 mr-2"}),"Back to Email marketing"]})]}));const u=Te,we={start:a.quiet_hours_start===null||a.quiet_hours_start===""?null:Number(a.quiet_hours_start),end:a.quiet_hours_end===null||a.quiet_hours_end===""?null:Number(a.quiet_hours_end),tz:a.quiet_hours_tz||ae};return K(e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("button",{className:"text-xs text-muted-foreground hover:text-foreground flex items-center gap-1",onClick:()=>o("/secure-portal-7x9k2m/dashboard?tab=marketing"),children:[e.jsx(ke,{className:"h-3.5 w-3.5"}),"Email marketing â Follow-ups"]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(b,{value:a.name??"",onChange:s=>_("name",s.target.value),className:"h-9 text-base font-semibold max-w-md"}),e.jsx(Se,{variant:a.enabled?"default":"secondary",children:a.enabled?"Running":"Paused"}),e.jsx(R,{checked:!!a.enabled,onCheckedChange:Ue})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:"ID"}),e.jsx("code",{className:"font-mono text-[11px] text-muted-foreground break-all",children:a.id}),e.jsx("button",{className:"text-muted-foreground hover:text-foreground",onClick:()=>{navigator.clipboard.writeText(a.id),h.success("Campaign ID copied")},children:e.jsx(bs,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(p,{size:"sm",onClick:Re,disabled:A,children:[A?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ns,{className:"h-4 w-4 mr-2"}),"Save"]}),e.jsxs(p,{size:"sm",variant:"outline",onClick:Qe,disabled:le,children:[le?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ks,{className:"h-4 w-4 mr-2"}),"Run tick"]}),e.jsx(p,{size:"sm",variant:"outline",onClick:E,children:e.jsx(Ds,{className:"h-4 w-4"})}),e.jsxs(p,{size:"sm",variant:"outline",onClick:Be,children:[e.jsx(ws,{className:"h-4 w-4 mr-2"}),"Duplicate"]}),e.jsxs(p,{size:"sm",variant:"outline",className:"text-destructive",onClick:()=>xe(!0),children:[e.jsx(Ce,{className:"h-4 w-4 mr-2"}),"Delete"]})]})]}),e.jsxs(ss,{defaultValue:"overview",children:[e.jsxs(ts,{children:[e.jsx(X,{value:"overview",children:"Overview"}),e.jsx(X,{value:"series",children:"Series"}),e.jsx(X,{value:"settings",children:"Settings"})]}
1),e.jsxs(Y,{value:"overview",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-5 gap-2",children:[e.jsx(v,{label:"Entered",value:(u?.entered??0).toLocaleString()}),e.jsx(v,{label:"Active",value:(u?.active??0).toLocaleString()}),e.jsx(v,{label:"Completed",value:(u?.completed??0).toLocaleString()}),e.jsx(v,{label:"Converted (attributed)",value:(u?.converted_attributed??0).toLocaleString(),hint:re(a.goal_type),onClick:()=>be("attributed")}),e.jsx(v,{label:"Upgraded (any source)",value:(u?.exited_converted??0).toLocaleString(),hint:"Started a paid plan while enrolled â not necessarily from this email.",onClick:()=>be("upgraded")}),e.jsx(v,{label:"Revenue",value:`$${((u?.revenue_cents??0)/100).toFixed(2)}`,hint:"Purchases attributed to this campaign"}),e.jsx(v,{label:"Exited (other)",value:(u?.exited_other??0).toLocaleString()}),e.jsx(v,{label:"Emails sent",value:(u?.sent??0).toLocaleString()}),e.jsx(v,{label:"Failed",value:(u?.failed??0).toLocaleString()}),e.jsx(v,{label:"Opens",value:(u?.opened??0).toLocaleString(),hint:Q(u?.opened??0,u?.sent??0)}),e.jsx(v,{label:"Clicks",value:(u?.clicked??0).toLocaleString(),hint:Q(u?.clicked??0,u?.sent??0)}),e.jsx(v,{label:"Last send",value:u?.last_send_at?new Date(u.last_send_at).toLocaleString():"â"})]}),e.jsx(q,{children:e.jsxs(L,{className:"p-0",children:[e.jsx("div",{className:"px-3 py-2 text-xs font-medium border-b",children:"Series funnel"}),e.jsxs(ee,{className:"admin-cards",children:[e.jsx(se,{children:e.jsxs(S,{children:[e.jsx(m,{className:"text-xs",children:"Step"}),e.jsx(m,{className:"text-xs",children:"Sent"}),e.jsx(m,{className:"text-xs",children:"Opened"}),e.jsx(m,{className:"text-xs",children:"Clicked"}),e.jsx(m,{className:"text-xs",children:"Converted (attributed)"}),e.jsx(m,{className:"text-xs",children:"Failed"}),e.jsx(m,{className:"text-xs",children:"Last send"})]})}),e.jsxs(te,{children:[I.map(s=>e.jsxs(S,{children:[e.jsxs(d,{className:"text-xs font-medium","data-label":"Step",children:[s.step_order,". ",s.step_name]}),e.jsxs(d,{className:"text-xs tabular-nums","data-label":"Sent",children:[e.jsx("div",{children:s.sent.toLocaleString()}),e.jsx("div",{className:"h-1 mt-1 rounded bg-muted overflow-hidden max-w-[120px]",children:e.jsx("div",{className:"h-full bg-primary",style:{width:`${Math.min(100,s.sent/Math.max(1,I[0]?.sent||1)*100)}%`}})})]}),e.jsxs(d,{className:"text-xs tabular-nums","data-label":"Opened",children:[s.opened," ",e.jsxs("span",{className:"text-muted-foreground",children:["(",Q(s.opened,s.sent),")"]})]}),e.jsxs(d,{className:"text-xs tabular-nums","data-label":"Clicked",children:[s.clicked," ",e.jsxs("span",{className:"text-muted-foreground",children:["(",Q(s.clicked,s.sent),")"]})]}),e.jsx(d,{className:"text-xs tabular-nums","data-label":"Converted",children:s.converted}),e.jsx(d,{className:"text-xs tabular-nums","data-label":"Failed",children:s.failed}),e.jsx(d,{className:"text-xs","data-label":"Last send",children:s.last_send_at?new Date(s.last_send_at).toLocaleString():"â"})]},s.step_id)),I.length===0&&e.jsx(S,{children:e.jsx(d,{colSpan:7,className:"text-center text-xs py-6 text-muted-foreground",children:"No steps yet"})})]})]})]})}),e.jsx(q,{children:e.jsxs(L,{className:"p-0",children:[e.jsx("div",{className:"px-3 py-2 text-xs font-medium border-b",children:"Recent sends"}),e.jsx("div",{className:"max-h-[420px] overflow-y-auto",children:e.jsxs(ee,{className:"admin-cards",children:[e.jsx(se,{children:e.jsxs(S,{children:[e.jsx(m,{className:"text-xs",children:"Recipient"}),e.jsx(m,{className:"text-xs",children:"Step"}),e.jsx(m,{className:"text-xs",children:"Status"}),e.jsx(m,{className:"text-xs",children:"Sent"}),e.jsx(m,{className:"text-xs",children:"Opened"}),e.jsx(m,{className:"text-xs",children:"Clicked"}),e.jsx(m,{className:"text-xs",children:"Code"})]})}),e.jsxs(te,{children:[oe.map(s=>e.jsxs(S,{children:[e.jsx(d,{className:"text-xs max-w-[200px] truncate","data-label":"Recipient",children:s.user_id?e.jsx("button",{className:"hover:underline",onClick:()=>o(`/secure-portal-7x9k2m/dashboard/user/${s.user_id}`),children:s.email}):s.email}),e.jsxs(d,{className:"text-xs","data-label":"Step",children:[s.step_order?`${s.step_order}. `:"",s.step_name??"â"]}),e.jsx(d,{className:"text-xs","data-label":"Status",children:e.jsx(Se,{variant:s.status==="sent"?"secondary":"destructive",title:s.error??void 0,children:s.status})}),e.jsx(d,{className:"text-xs","data-label":"Sent",children:s.sent_at?new Date(s.sent_at).toLocaleStr
1ing():"â"}),e.jsx(d,{className:"text-xs","data-label":"Opened",children:s.opened_at?new Date(s.opened_at).toLocaleDateString():"â"}),e.jsx(d,{className:"text-xs","data-label":"Clicked",children:s.clicked_at?new Date(s.clicked_at).toLocaleDateString():"â"}),e.jsx(d,{className:"text-xs font-mono","data-label":"Code",children:s.discount_code??"â"})]},s.id)),oe.length===0&&e.jsx(S,{children:e.jsx(d,{colSpan:7,className:"text-center text-xs py-6 text-muted-foreground",children:"No sends yet"})})]})]})})]})})]}),e.jsxs(Y,{value:"series",className:"space-y-3 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Steps are scheduled from their anchor. Negative offsets send before the anchor date."}),e.jsxs(p,{size:"sm",variant:"outline",onClick:Ve,children:[e.jsx(De,{className:"h-4 w-4 mr-2"}),"Add step"]})]}),N.length===0&&e.jsx(q,{children:e.jsx(L,{className:"py-10 text-center text-sm text-muted-foreground",children:"No steps yet."})}),N.map((s,t)=>{const n=Pe(s.id),i=Z(s.creative_id),f=s.offer_percent!==null||s.offer_valid_days!==null,y=i?/\{\{\s*(discount_|offer_expires_at)/.test(JSON.stringify(i.design_json??{})+(i.subject??"")):!1;return e.jsx(q,{children:e.jsxs(L,{className:"pt-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"text-xs text-muted-foreground w-6",children:[s.step_order,"."]}),e.jsx(b,{className:"max-w-xs h-8",value:s.name,onChange:l=>w(s.id,{name:l.target.value})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(p,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>Ne(t,-1),disabled:t===0,children:e.jsx(ys,{className:"h-4 w-4"})}),e.jsx(p,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>Ne(t,1),disabled:t===N.length-1,children:e.jsx(Ss,{className:"h-4 w-4"})}),e.jsxs(p,{variant:"outline",size:"sm",disabled:!i,onClick:()=>me(s),children:[e.jsx(As,{className:"h-3.5 w-3.5 mr-1"}),"Preview"]}),e.jsxs(p,{variant:"outline",size:"sm",disabled:!i,onClick:()=>ue(s),children:[e.jsx(qs,{className:"h-3.5 w-3.5 mr-1"}),"Send test"]}),e.jsx(R,{checked:s.enabled,onCheckedChange:l=>w(s.id,{enabled:l})}),e.jsx(p,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>He(s.id),children:e.jsx(Ce,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-xs",children:"Anchor"}),e.jsxs(U,{value:s.anchor,onValueChange:l=>w(s.id,{anchor:l}),children:[e.jsx(V,{className:"h-9",children:e.jsx(H,{})}),e.jsx(B,{children:Ls.map(l=>e.jsx(M,{value:l.value,children:l.label},l.value))})]})]}),e.jsxs("div",{children:[e.jsx(j,{className:"text-xs",children:"Offset (days)"}),e.jsx(b,{className:"h-9",type:"number",value:s.delay_days,onChange:l=>w(s.id,{delay_days:Number(l.target.value)})})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(j,{className:"text-xs",children:"Creative"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(U,{value:s.creative_id??"",onValueChange:l=>w(s.id,{creative_id:l}),children:[e.jsx(V,{className:"h-9",children:e.jsx(H,{placeholder:"Select a creative"})}),e.jsx(B,{children:z.map(l=>e.jsx(M,{value:l.id,children:l.name},l.id))})]}),e.jsx(p,{variant:"outline",size:"icon",className:"h-9 w-9 shrink-0",title:"Edit creative",disabled:!i,onClick:()=>{pe(s.creative_id),ge(s.id),W(!0)},children:e.jsx(Cs,{className:"h-4 w-4"})}),e.jsx(p,{variant:"outline",size:"icon",className:"h-9 w-9 shrink-0",title:"New creative",onClick:()=>{pe(null),ge(s.id),W(!0)},children:e.jsx(De,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:i?e.jsxs(e.Fragment,{children:["Subject: ",e.jsx("span",{className:"text-foreground",children:i.subject||e.jsx("em",{children:"none"})})]}):"No creative selected â this step will be skipped."})]}),e.jsxs("div",{className:"sm:col-span-4 rounded-md border p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"Attach a discount offer"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Generates a unique discount code for each recipient and injects"," ",e.jsx("code",{children:"{{discount_code}}"}),", ",e.jsx("code",{children:"{{discount_percent}}"})," and"," ",e.jsx("code",{children:"{{offer_expires_at}}"})," into the email."]})]}),e.jsx(R,{checked:f,onCheckedChange:l=>w(s.id,l?{offer_percent:s.offer_percent??20,offer_valid_days:s.offer_valid_days??3}:{offer_percent:null,offer_valid_days:null})})]}),f&&e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-xs",children:"Discount %"}),e.jsx(b,{className:"h-9",type:"number",min:1,max:100,value:s.offer_percent??"",onChange:l=>w(s.id,{offer_percent:l.target.value===""?null:Number(l.target.value)})}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Percent off, e.g. 20."})]}),e.jsxs("div",{children:[e.jsx(j,{className:"text-xs",children:"Valid for (days)"}),e.jsx(b,{className:"h-9",type:"number",min:1,value:s.offer_valid_days??"",onChange:l=>w(s.id,{offer_valid_days:l.target.value===""?null:Number(l.target.value)})}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"How long that code stays redeemable."})]})]}),y&&!f&&e.jsx("p",{className:"text-xs text-destructive",children:"This creative uses discount tokens but no offer is attached â they will render empty."}),f&&i&&!y&&e.jsx("p",{className:"text-xs text-amber-500",children:"A code will be generated, but the creative never shows it. Add a discount token to the email."})]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-6 gap-3 text-xs border-t pt-3",children:[["Sent",n?.sent??0],["Opened",n?.opened??0],["Clicked",n?.clicked??0],["Converted",n?.converted??0],["Upgraded",n?.upgraded??0],["Failed",n?.failed??0]].map(([l,ye])=>e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground",children:l}),e.jsx("div",{className:"font-semibold tabular-nums",children:Number(ye).toLocaleStr
1ing()})]},l))})]})},s.id)})]}),e.jsx(Y,{value:"settings",className:"mt-4",children:e.jsx(q,{children:e.jsxs(L,{className:"pt-5 space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(j,{children:"Description"}),e.jsx(us,{rows:2,value:a.description??"",onChange:s=>_("description",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Audience"}),e.jsxs(U,{value:a.audience_key,onValueChange:s=>_("audience_key",s),children:[e.jsx(V,{children:e.jsx(H,{})}),e.jsx(B,{children:Object.entries(Ts).map(([s,t])=>e.jsx(M,{value:s,children:t},s))})]})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Throttle (emails / hour, 0 = unlimited)"}),e.jsx(b,{type:"number",min:0,value:a.throttle_per_hour??0,onChange:s=>_("throttle_per_hour",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Quiet hours start (0-23)"}),e.jsx(b,{type:"number",min:0,max:23,value:a.quiet_hours_start??"",onChange:s=>_("quiet_hours_start",s.target.value===""?null:s.target.value)})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Quiet hours end (0-23)"}),e.jsx(b,{type:"number",min:0,max:23,value:a.quiet_hours_end??"",onChange:s=>_("quiet_hours_end",s.target.value===""?null:s.target.value)})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Timezone"}),e.jsx(b,{value:a.quiet_hours_tz??ae,onChange:s=>_("quiet_hours_tz",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Conversion goal"}),e.jsxs(U,{value:a.goal_type??"purchase",onValueChange:s=>_("goal_type",s),children:[e.jsx(V,{children:e.jsx(H,{})}),e.jsx(B,{children:is.map(s=>e.jsx(M,{value:s.type,children:s.label},s.type))})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:re(a.goal_type)})]}),e.jsxs("div",{children:[e.jsx(j,{children:"UTM campaign"}),e.jsx(b,{value:a.utm_campaign??"",onChange:s=>_("utm_campaign",s.target.value),placeholder:"trial_to_paid"})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(j,{children:"Default CTA URL"}),e.jsx(b,{value:a.goal_destination_url??"",onChange:s=>_("goal_destination_url",s.target.value),placeholder:"https://mp3ify.io/free-trial?upgrade=1"})]}),e.jsxs("div",{className:"sm:col-span-2 flex items-center justify-between rounded-md border p-3 flex-wrap gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"Exit on conversion"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Stop the series as soon as the user starts a paid plan."})]}),e.jsx(R,{checked:!!a.exit_on_conversion,onCheckedChange:s=>_("exit_on_conversion",s)})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:cs(we)?`Sending pauses ${ds(we)}.`:"No quiet hours set â the automation can send at any time of day."})]})})})]}),k&&J&&e.jsx(ns,{open:!!k,onOpenChange:s=>!s&&me(null),name:`${a.name} â ${k.name}`,subject:J.subject,design:J.design}),D&&F&&e.jsx(os,{open:!!D,onOpenChange:s=>!s&&ue(null),subject:F.subject,html:F.html,creativeName:F.name}),e.jsx(ms,{open:Ie,onOpenChange:W,creativeId:he,onSaved:async s=>{je&&!he&&w(je,{creative_id:s});const{data:t}=await x.from("email_creatives").select("id,name,subject,design_json,html_cache").eq("status","active").order("name");de(t??[])}}),e.jsx(Je,{open:!!G,onOpenChange:s=>!s&&_e(null),children:e.jsxs(Ke,{className:"max-w-3xl",children:[e.jsxs(Xe,{children:[e.jsx(Ye,{children:G==="upgraded"?"Upgraded (any source)":"Converted (attributed)"}),e.jsx(es,{children:G==="upgraded"?"Users who started a paid plan while enrolled â the email may not be the cause.":re(a.goal_type)})]}),Fe?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(P,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"max-h-[60vh] overflow-y-auto",children:e.jsxs(ee,{className:"admin-cards",children:[e.jsx(se,{children:e.jsxs(S,{children:[e.jsx(m,{className:"text-xs",children:"Email"}),e.jsx(m,{className:"text-xs",children:"Event"}),e.jsx(m,{className:"text-xs",children:"Step"}),e.jsx(m,{className:"text-xs",children:"Amount"}),e.jsx(m,{className:"text-xs",children:"When"})]})}),e.jsxs(te,{children:[fe.map((s,t)=>e.jsxs(S,{children:[e.jsx(d,{className:"text-xs","data-label":"Email",children:s.user_id?e.jsx("button",{className:"hover:underline",onClick:()=>o(`/secure-portal-7x9k2m/dashboard/user/${s.user_id}`),children:s.email}):s.email}),e.jsx(d,{className:"text-xs","data-label":"Event",children:s.event_type}),e.jsx(d,{className:"text-xs","data-label":"Step",children:s.step_name??"â"}),e.jsx(d,{className:"text-xs tabular-nums","data-label":"Amount",children:s.amount_cents?`$${(s.amount_cents/100).toFixed(2)}`:"â"}),e.jsx(d,{className:"text-xs","data-label":"When",children:s.occurred_at?new Date(s.occurred_at).toLocaleStr
1ing():"â"})]},`${s.user_id??t}-${t}`)),fe.length===0&&e.jsx(S,{children:e.jsx(d,{colSpan:5,className:"text-center text-xs py-6 text-muted-foreground",children:"Nothing recorded yet"})})]})]})})]})}),e.jsx(xs,{open:ze,onOpenChange:xe,children:e.jsxs(hs,{children:[e.jsxs(ps,{children:[e.jsx(js,{children:"Delete this automation?"}),e.jsxs(gs,{children:["Steps, enrollments and send logs for â",a.name,"â are removed. User accounts and their data are untouched."]})]}),e.jsxs(_s,{children:[e.jsx(fs,{children:"Cancel"}),e.jsx(vs,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:Me,children:"Delete"})]})]})})]}))};export{Nt 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.