1import{j as e,m as b}from"./motion-BW5d1p18.js";import{a as m}from"./react-BBilbtQ3.js";import{b as R,d as f,S as J,E as B,P as U,l as y,Q as O,O as V,aW as H}from"./index-CcYhmflC.js";import{F as A}from"./FeatureToggles-DlYlJFvy.js";import{m as w,a as S,b as W}from"./accountMix-CZmw300U.js";import{B as Y,b as G,aP as K,E as Q,U as X,C as q,c as I,b9 as Z,a5 as _,aI as ee,ak as te}from"./icons-DJ5iG1DS.js";import"./supabase-ba8uOG1h.js";const C=r=>`$${(r??0).toLocaleString()}`;function se(r){const l=H.find(a=>a.name.toLowerCase()===r.toLowerCase()||a.match(r));return(l==null?void 0:l.id)??null}function L({value:r,onSave:l}){const[a,h]=m.useState(!1),[i,s]=m.useState(String(r||""));m.useEffect(()=>s(String(r||"")),[r]);function c(){l(Math.max(0,Number(i)||0)),h(!1)}return a?e.jsxs("span",{className:"inline-flex items-center gap-1",onClick:p=>p.stopPropagation(),children:[e.jsx("span",{className:"text-sm t-faint",children:"$"}),e.jsx("input",{autoFocus:!0,type:"number",min:0,value:i,onChange:p=>s(p.target.value),onKeyDown:p=>{p.key==="Enter"&&c(),p.key==="Escape"&&(s(String(r||"")),h(!1))},className:"w-20 rounded-md border border-[var(--accent)] bg-transparent px-1.5 py-0.5 text-sm font-bold t-strong outline-none"}),e.jsx("button",{onClick:c,"aria-label":"Save",className:"grid h-6 w-6 place-items-center rounded-md bg-accent-gradient text-white",children:e.jsx(I,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>{s(String(r||"")),h(!1)},"aria-label":"Cancel",className:"grid h-6 w-6 place-items-center rounded-md surface t-mute",children:e.jsx(te,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{onClick:p=>{p.stopPropagation(),h(!0)},className:"group inline-flex items-center gap-1 rounded-md px-1 text-sm font-bold t-strong hover:bg-[var(--row-hover)]",children:[C(r),e.jsx(ee,{className:"h-3 w-3 opacity-0 transition group-hover:opacity-60",style:{color:"var(--accent)"}})]})}function ne(){var h;const[r,l]=m.useState(null);if(m.useEffect(()=>{f("/api/campaigns",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({op:"platform-email-stats"}),noInvalidate:!0}).then(i=>i.ok?i.json():null).then(l).catch(()=>{})},[]),!((h=r==null?void 0:r.rows)!=null&&h.length))return null;const a=r.totals;return e.jsxs("div",{className:"surface mb-6 rounded-2xl p-5",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 font-display text-sm font-bold t-strong",children:[e.jsx(_,{className:"h-4 w-4",style:{color:"var(--accent)"}})," Email engine",e.jsxs("span",{className:"font-mono text-[9px] font-normal uppercase t-faint",children:[a.sent.toLocaleString()," sent · $",a.cost.toFixed(2)," cost · ",a.opens.toLocaleString()," opens · ",a.clicks.toLocaleString()," clicks (30d)"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[520px] text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b divider font-mono text-[9px] font-bold uppercase tracking-wide t-faint",children:[e.jsx("th",{className:"py-1.5 text-left",children:"Account"}),e.jsx("th",{className:"py-1.5 text-right",children:"Sent"}),e.jsx("th",{className:"py-1.5 text-right",children:"Provider cost"}),e.jsx("th",{className:"py-1.5 text-right",children:"Opens"}),e.jsx("th",{className:"py-1.5 text-right",children:"Clicks"}),e.jsx("th",{className:"py-1.5 text-right",children:"CTR"})]})}),e.jsx("tbody",{children:r.rows.map(i=>e.jsxs("tr",{className:"border-b divider last:border-0",children:[e.jsx("td",{className:"py-1.5 font-semibold t-strong",children:i.account}),e.jsx("td",{className:"py-1.5 text-right tabular-nums t-mute",children:i.sent.toLocaleString()}),e.jsxs("td",{className:"py-1.5 text-right tabular-nums t-mute",children:["$",i.cost.toFixed(2)]}),e.jsx("td",{className:"py-1.5 text-right tabular-nums t-mute",children:i.opens.toLocaleString()}),e.jsx("td",{className:"py-1.5 text-right tabular-nums t-mute",children:i.clicks.toLocaleString()}),e.jsxs("td",{className:"py-1.5 text-right font-mono font-bold",style:{color:"var(--accent)"},children:[i.sent?Math.round(i.clicks/i.sent*1e3)/10:0,"%"]})]},i.account))})]})})]})}function ae(){const[r,l]=m.useState(null);if(m.useEffect(()=>{f("/api/app-telemetry").then(s=>s.json()).then(l).catch(()=>{})},[]),!(r!=null&&r.experience))return null;const a=r.experience,h=s=>s==null?"â":s>=1e3?`${(s/1e3).toFixed(1)}s`:`${s}ms`,i=s=>s===0?"#1f9d55":s<5?"#f0a020":"#d64545";return e.jsxs("div",{className:"surface mb-6 rounded-2xl p-5",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2 font-display text-sm font-bold t-strong",children:[e.jsx(Z,{className:"h-4 w-4",style:{color:"var(--accent)"}})," App experience",e.jsxs("span",{className:"font-mono text-[9px] font-normal uppercase t-faint",children:[r.installs," installs · ",r.launches," opens (90d) · ",a.sessions," measured sessions (30d
1)"]})]}),a.sessions===0?e.jsx("p",{className:"text-xs t-faint",children:"No experience data yet â sessions start reporting as people use the deployed app."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-3 grid grid-cols-2 gap-2 sm:grid-cols-5",children:[{l:"Freezes (1s+ stalls)",v:a.freezes,c:i(a.freezes)},{l:"JS errors",v:a.jsErrors,c:i(a.jsErrors)},{l:"Slow API calls (3s+)",v:a.apiSlow,c:i(a.apiSlow)},{l:"Failed actions",v:a.apiFail,c:i(a.apiFail)},{l:"API calls seen",v:a.apiCalls,c:"var(--text-strong)"}].map(s=>e.jsxs("div",{className:"rounded-xl p-3 text-center",style:{background:"var(--panel)"},children:[e.jsx("div",{className:"font-display text-xl font-extrabold",style:{color:s.c},children:s.v.toLocaleString()}),e.jsx("div",{className:"mt-0.5 font-mono text-[8.5px] uppercase tracking-wide t-faint",children:s.l})]},s.l))}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[560px] text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b divider font-mono text-[9px] font-bold uppercase tracking-wide t-faint",children:[e.jsx("th",{className:"py-1.5 text-left",children:"Device"}),e.jsx("th",{className:"py-1.5 text-right",children:"Sessions"}),e.jsx("th",{className:"py-1.5 text-right",children:"First paint"}),e.jsx("th",{className:"py-1.5 text-right",children:"Full load"}),e.jsx("th",{className:"py-1.5 text-right",children:"Freezes"}),e.jsx("th",{className:"py-1.5 text-right",children:"Errors"}),e.jsx("th",{className:"py-1.5 text-right",children:"Slow API"}),e.jsx("th",{className:"py-1.5 text-right",children:"Misfires"})]})}),e.jsx("tbody",{children:Object.entries(a.byDevice).sort((s,c)=>c[1].sessions-s[1].sessions).map(([s,c])=>e.jsxs("tr",{className:"border-b divider last:border-0",children:[e.jsx("td",{className:"py-1.5 font-semibold capitalize t-strong",children:s}),e.jsx("td",{className:"py-1.5 text-right tabular-nums t-mute",children:c.sessions}),e.jsx("td",{className:"py-1.5 text-right tabular-nums t-mute",children:h(c.avgLcp)}),e.jsx("td",{className:"py-1.5 text-right tabular-nums t-mute",children:h(c.avgLoad)}),e.jsx("td",{className:"py-1.5 text-right font-mono font-bold",style:{color:i(c.freezes)},children:c.freezes}),e.jsx("td",{className:"py-1.5 text-right font-mono font-bold",style:{color:i(c.jsErrors)},children:c.jsErrors}),e.jsx("td",{className:"py-1.5 text-right font-mono font-bold",style:{color:i(c.apiSlow)},children:c.apiSlow}),e.jsx("td",{className:"py-1.5 text-right font-mono font-bold",style:{color:i(c.apiFail)},children:c.apiFail})]},s))})]})}),a.worstEndpoints.length>0&&e.jsxs("div",{className:"mt-3 border-t divider pt-2 text-xs t-mute",children:[e.jsx("b",{className:"t-strong",children:"Misfiring endpoints:"})," ",a.worstEndpoints.map(([s,c])=>`${s} (${c}Ã)`).join(" · ")]}),Object.keys(a.network).length>0&&e.jsxs("div",{className:"mt-1.5 text-[11px] t-faint",children:["Network mix: ",Object.entries(a.network).sort((s,c)=>c[1]-s[1]).map(([s,c])=>`${s} Ã${c}`).join(" · ")]})]})]})}function me(){const r=R(),[l,a]=m.useState(null),[h,i]=m.useState(!0),[s,c]=m.useState(null),[p,D]=m.useState({}),[k,E]=m.useState(null),N=m.useCallback(()=>{i(!0),c(null),f("/api/mission-control").then(t=>t.json()).then(t=>{var d,n;if(t.error||!t.configured&&!t.tree&&!t.agencies)throw new Error(t.error||"Mission Control not configured");a({...t,agencies:((d=t.tree)==null?void 0:d.agencies)??t.agencies??[],direct:((n=t.tree)==null?void 0:n.direct)??t.direct??[]})}).catch(()=>c("We could not load this just now. Try again.")).finally(()=>i(!1))},[]);m.useEffect(()=>{N()},[N]);function F(t,d){a(n=>{if(!n)return n;const x=o=>o.id===t?{...o,features:d}:o;return{...n,agencies:n.agencies.map(o=>({...x(o),clients:o.clients.map(x)})),direct:n.direct.map(x)}}),f("/api/account-update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,features:d})}).catch(()=>{})}function M(t,d){a(n=>{if(!n)return n;const x=o=>o.id===t?{...o,mrr:d}:o;return{...n,agencies:n.agencies.map(o=>{const g={...x(o),clients:o.clients.map(x)};return g.bookMrr=g.mrr+g.clients.reduce((v,z)=>v+(z.mrr||0),0),g}),direct:n.direct.map(x)}}),f("/api/account-update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,mrr:d})}).catch(()=>{})}async function T(t,d,n){var o,g;const x=d==="direct"?"Direct (DI)":d==="agency"?"its own agency":((g=(o=l==null?void 0:l.agencies.find(v=>v.id===d))==null?void 0:o.name)==null?void 0:g.trim())||"agency";await f("/api/account-update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,moveTo:d})}),E(`Moved ${n} â ${x}`),setTimeout(()=>E(null),2800),N()}if(h)return e.jsx(J,{label:"Loading Master Controlâ¦"});if(s)return e.jsx(B,{message:s,onRetry:N});if(!l)return null;const j=l.totals??{accounts:0,agencies:0,directClients:0,mrr:0,margin:0},u=t=>((t==null?void 0:t.name)??"").trim()||"Account",P=({accountId:t,accountName:d})=>e.jsxs("select",{value:"",onClick:n=>n.stopPropagation(),onChange:n=>{n.target.value&&T(t,n.target.value,d)},title:"Move this account",className:"rounded-md border border-[var(--border)] bg-[var(--bg)] px-1.5 py-1 text-[11px] t-mute outline-none transition hover:border-[var(--accent)]",children:[e.jsx("option",{value:"",children:"Moveâ¦"}),(l.agencies??[]).map(n=>e.jsxs("option",{value:n.id,children:["â ",u(n)]},n.id)),e.jsx("option",{value:"direct",children:"â Direct (DI)"}),e.jsx("option",{value:"agency",children:"â Make agency"})]}),$=({a:t,nested:d})=>{var n;return e.jsxs("div",{className:"rounded-xl border border-[var(--border)] p-3.5 ",style:{background:d?"var(--bg)":"var(--panel)"},children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("div",{className:"grid h-8 w-8 shrink-0 place-items-center rounded-lg bg-accent-gradient text-xs font-bold text-white",children:(n=u(t)[0])==null?void 0:n.toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-semibold t-strong",children:u(t)}),e.jsx("div",{className:"truncate text-xs t-faint",children:V(t.domain??"")})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx(P,{accountId:t.id,accountName:u(t)}),e.jsx(O,{status:t.status}),e.jsxs("div",{className:"text-right",children:[e.jsx(L,{value:t.mrr,onSave:x=>M(t.id,x)}),e.jsx("div",{className:"font-mono text-[9px] uppercase t-faint",children:"mrr/mo"})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"font-bold",style:{color:t.mrr-t.cost>=0?"#22c55e":"#f43f5e"},children:C(Math.round((t.mrr-t.cost)*100)/100)}),e.jsx("div",{className:"font-mono text-[9px] uppercase t-faint",children:"margin"})]})]})]}),e.jsx(A,{acct:t,onSave:F})]})};return e.jsxs(e.Fragment,{children:[e.jsx(U,{eyebrow:"Platform",title:e.jsxs(e.Fragment,{children:["Master ",e.jsx("span",{className:"font-serif-i font-normal accent",children:"Control."})]}),subtitle:"Every agency, their clients, and your direct clients â entitlements, sections & books in one place"}),e.jsxs("div",{className:"mb-6 grid grid-cols-2 gap-3.5 md:grid-cols-5",children:[e.jsx(y,{label:"Account records",value:j.accounts,accent:!0,index:0,hint:w(S(W(l.agencies,l.direct)))||"every account record"}),e.jsx(y,{label:"Agencies",value:j.agencies,index:1,hint:w(S(l.agencies??[]))||void 0}
1),e.jsx(y,{label:"Direct Clients",value:j.directClients,index:2,hint:w(S(l.direct??[]))||void 0}),e.jsx(y,{label:"Your MRR",value:j.mrr,prefix:"$",index:3}),e.jsx(y,{label:"Margin",value:j.margin,prefix:"$",accent:!0,index:4})]}),e.jsx(ae,{}),e.jsx(ne,{}),e.jsxs("div",{className:"mb-3 flex items-center gap-2 font-display text-sm font-bold t-strong",children:[e.jsx(Y,{className:"h-4 w-4",style:{color:"var(--accent)"}})," Agencies & their clients"]}),e.jsxs("div",{className:"space-y-3",children:[(l.agencies??[]).map((t,d)=>{const n=p[t.id]??!0,x=se(u(t));return e.jsxs(b.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:d*.04},className:"surface rounded-2xl p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{onClick:()=>D(o=>({...o,[t.id]:!n})),className:"flex min-w-0 items-center gap-2 text-left",children:[n?e.jsx(G,{className:"h-4 w-4 t-faint"}):e.jsx(K,{className:"h-4 w-4 t-faint"}),e.jsx("div",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-xl bg-accent-gradient text-sm font-extrabold text-white",children:u(t)[0]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-display font-bold t-strong",children:u(t)}),e.jsxs("div",{className:"text-xs t-faint",children:[t.clients.length," client",t.clients.length!==1?"s":""," · book ",C(t.bookMrr),"/mo"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(P,{accountId:t.id,accountName:u(t)}),e.jsxs("div",{className:"text-right",children:[e.jsx(L,{value:t.mrr,onSave:o=>M(t.id,o)}),e.jsx("div",{className:"font-mono text-[9px] uppercase t-faint",children:"wholesale/mo"})]}),e.jsx(O,{status:t.status}),x&&e.jsxs("button",{onClick:()=>r.setAgency(x),className:"inline-flex items-center gap-1.5 rounded-lg border border-[var(--border)] px-3 py-1.5 text-xs t-mute transition hover:border-[var(--accent)] hover:t-strong",children:[e.jsx(Q,{className:"h-3.5 w-3.5"})," Preview white-label"]})]})]}),e.jsx("div",{className:"mt-2",children:e.jsx(A,{acct:t,onSave:F})}),n&&e.jsxs("div",{className:"mt-3 space-y-2 border-l-2 border-[var(--border)] pl-3",children:[(t.clients??[]).map(o=>e.jsx($,{a:o,nested:!0},o.id)),!(t.clients??[]).length&&e.jsx("div",{className:"py-2 text-xs t-faint",children:"No clients under this agency yet."})]})]},t.id)}),!(l.agencies??[]).length&&e.jsx("div",{className:"surface rounded-2xl py-8 text-center text-sm t-faint",children:"No agencies yet."})]}),e.jsxs("div",{className:"mb-3 mt-8 flex items-center gap-2 font-display text-sm font-bold t-strong",children:[e.jsx(X,{className:"h-4 w-4",style:{color:"var(--accent)"}})," Your direct clients"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 lg:grid-cols-2",children:[(l.direct??[]).map((t,d)=>e.jsx(b.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:d*.03},children:e.jsx($,{a:t})},t.id)),!(l.direct??[]).length&&e.jsx("div",{className:"surface rounded-2xl py-8 text-center text-sm t-faint lg:col-span-2",children:"No direct clients yet."})]}),e.jsxs("div",{className:"mt-6 flex items-center gap-2 rounded-xl border border-[var(--border)] px-4 py-3 text-xs t-faint",children:[e.jsx(q,{className:"h-3.5 w-3.5",style:{color:"var(--accent)"}}),'Orange chip = released/visible · struck-through = locked/hidden. Changes save instantly to that account. Use the top-bar "View as" to preview any tenant.']}),k&&e.jsxs(b.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"fixed bottom-6 left-1/2 z-50 -translate-x-1/2 flex items-center gap-2 rounded-xl bg-accent-gradient px-4 py-2.5 text-sm font-semibold text-white shadow-2xl",children:[e.jsx(I,{className:"h-4 w-4"})," ",k]})]})}export{me 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.