1import{j as e,r as h}from"./auth-DsVcSKZ9.js";import{v as P}from"./main-CmoY06Gm.js";import{B as R}from"./button-BYBg-T5J.js";import{C as x}from"./card-CGasuqT9.js";import{I as D}from"./input-DW45IALI.js";import{L as E}from"./label-DSszkxcP.js";import{A,S as u}from"./admin-page-DjdjQOCv.js";import{b as f,Q as C,S as U,L as N,E as F}from"./keys-arFKYfDR.js";import{a as Q,e as B,R as O,d as I,f as M,g as G,h as V}from"./engagement-BOpbQI8N.js";import{S as g,a as o,M as p}from"./stat-card-Mkj2N7mv.js";import{l as m,p as X}from"./format-DiX-5RdV.js";import{R as _}from"./rotate-cw-DOo91cGG.js";import"./return-DT4MUmgu.js";import"./utils-DCADjnpI.js";import"./index-Bd0gGWGF.js";import"./index-zbHvUVpj.js";import"./skeleton-B2SZzIOM.js";import"./triangle-alert-BGsekZeV.js";import"./createLucideIcon-6AUHJR7K.js";import"./index-B6ZZvVMk.js";import"./index-DW1OIlAD.js";import"./index-3aCLg1bC.js";import"./index-D8e7urwq.js";import"./select-CQR_BflU.js";import"./chevron-down-n9UFMhaJ.js";import"./check-CrdqM7YH.js";import"./index-Cnq7JSFq.js";import"./calendar-range-C-bbRnJ2.js";import"./QueryClientProvider-TxuI3zrR.js";import"./useQuery-CnxdLOm_.js";import"./api-error-BiTMa16K.js";function w({stages:s,empty:a="No activity in this window."}){var r;const t=((r=s[0])==null?void 0:r.value)??0;return t===0?e.jsx(f,{children:a}):e.jsx("div",{className:"space-y-2",children:s.map((l,n)=>{const i=l.value/t*100,c=n>0?s[n-1].value:null,d=c&&c>0?l.value/c*100:null;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-muted-foreground w-28 shrink-0 truncate text-xs sm:w-32",children:l.label}),e.jsxs("div",{className:"bg-card relative h-7 flex-1 overflow-hidden rounded-full ring-1 ring-foreground/10",children:[e.jsx("div",{className:"bg-primary/30 absolute inset-y-0 left-0",style:{width:`${Math.max(i,l.value>0?3:0)}%`}}),e.jsxs("div",{className:"absolute inset-0 flex items-center justify-between px-3",children:[e.jsx("span",{className:"text-xs font-bold tabular-nums",children:l.value.toLocaleString()}),d!==null&&e.jsxs("span",{className:"text-muted-foreground text-[10px] tabular-nums",children:[d.toFixed(0),"%"]})]})]})]},l.label)})})}function H({data:s}){if(s.length===0)return null;const r=Math.max(...s,1),l=Math.min(...s,0),n=r-l||1,i=s.length>1?140/(s.length-1):0,c=s.map((d,b)=>{const v=b*i,q=36-(d-l)/n*36;return`${v.toFixed(1)},${q.toFixed(1)}`}).join(" ");return e.jsx("svg",{viewBox:"0 0 140 36",preserveAspectRatio:"none",className:"h-9 w-full","aria-hidden":!0,children:e.jsx("polyline",{points:c,fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round"})})}function k(s,a){const t=X(s,a);return t===null?void 0:`${Math.round(t)}% of attempts blocked`}const S=90;function $e(){const s=Q("7d"),a={range:s.range,key:s.key},t=B(a),[r]=P(),[l,n]=h.useState(r.get("league")),[i,c]=h.useState(r.get("user")),b=(s.range.to.getTime()-s.range.from.getTime())/864e5>S;return e.jsxs(A,{title:"Engagement",description:"Scout and tool usage, content delivery, paywall pressure, and the two share loops.",meta:t.data?e.jsxs(e.Fragment,{children:[I(s.state)," · ",m(t.data.range.from)," â"," ",m(t.data.range.to)," ·"," ",t.data.range.granularity==="hour"?"hourly":"daily"," buckets"]}):void 0,actions:e.jsxs(e.Fragment,{children:[e.jsx(O,{controller:s}),e.jsxs(R,{variant:"outline",disabled:t.isFetching,onClick:()=>t.refetch(),children:[e.jsx(_,{className:t.isFetching?"animate-spin":void 0}),"Refresh"]})]}),children:[e.jsx(C,{query:t,skeleton:e.jsx(U,{}),children:v=>e.jsx(K,{data:v})}),e.jsx(u,{title:"Most active â leaderboards",description:e.jsxs(e.Fragment,{children:["Top leagues and users by Scout queries + tool runs over the range. Click a row to drill in. Backed by Logs Insights (~2-5s).",b&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"text-amber-400",children:["Range clamped to the last ",S," days here."]})]})]}),children:e.jsx(Y,{rangeArg:a,onPickLeague:n,onPickUser:c})}),e.jsx(u,{title:"Per-user drill-down",description:"One user's Scout queries, tool runs, paywall hits, and active leagues over the range. Click a league to drill into
1it.",children:e.jsx(z,{focusUserId:i,rangeArg:a,onPickLeague:n})}),e.jsx(u,{title:"Per-league drill-down",description:"The same metrics filtered to a single league.",children:e.jsx(Z,{focusLeagueId:l,rangeArg:a})})]})}function K({data:s}){const a=s.range,t=a.totals,r=a.series,l=t.emailsFailed??0;return e.jsxs(e.Fragment,{children:[e.jsxs(u,{title:"Selected range",description:"Totals over the range; the line is the bucket-by-bucket shape.",children:[e.jsxs(g,{cols:4,children:[e.jsx(j,{label:"Scout queries",total:t.scoutQueries,series:r.scoutQueries,sub:`${(t.scoutActiveUsers??0).toLocaleString()} distinct user-weeks`,accent:!0}),e.jsx(j,{label:"Tool runs",total:t.toolRuns,series:r.toolRuns,sub:`${(t.toolActiveUsers??0).toLocaleString()} distinct user-weeks`,accent:!0}),e.jsx(j,{label:"Newsletters published",total:t.newslettersPublished,series:r.newslettersPublished}),e.jsx(j,{label:"Emails sent",total:t.emailsSent,series:r.emailsSent,sub:l>0?`${l.toLocaleString()} failed · ${(t.emailsSkipped??0).toLocaleString()} skipped`:`${(t.emailsSkipped??0).toLocaleString()} skipped`,tone:l>0?"warning":"default"})]}),l>0&&e.jsx(x,{className:"border-destructive/30 bg-destructive/5 ring-destructive/30 mt-3 px-4 py-3",children:e.jsxs("span",{className:"text-destructive text-xs font-semibold tracking-[0.15em] uppercase",children:[l," email",l===1?"":"s"," failed in this range"]})})]}),e.jsx(u,{title:"Tools â selected range",description:"Successful runs per tool, including Boosted users on unlimited tools.",children:e.jsx(T,{data:a.toolRuns,empty:"No tool runs in this range."})}),e.jsxs(u,{title:"Paywall pressure â selected range",description:"Times users hit a free weekly wall. Wall-hit rate is the strongest upgrade-intent signal we have.",children:[e.jsxs(g,{cols:2,children:[e.jsx(o,{label:"Scout walls hit",value:t.scoutWalls,sub:k(t.scoutWalls,t.scoutQueries+t.scoutWalls),tone:t.scoutWalls>0?"warning":"default"}),e.jsx(o,{label:"Tool walls hit",value:t.toolWalls,sub:k(t.toolWalls,t.toolRuns+t.toolWalls),tone:t.toolWalls>0?"warning":"default"})]}),e.jsx("div",{className:"mt-3",children:e.jsx(T,{data:a.toolWalls,empty:"No tool walls hit in this range."})})]}),e.jsx(u,{title:"Scout Note funnel â selected range",description:"Proactive push moments: fire â push â open â CTA, then the share loop. The right-hand percent is stage-over-stage conversion.",children:e.jsx(w,{stages:[{label:"Fired",value:t.scoutNotesFired},{label:"Pushed",value:t.scoutNotesPushed},{label:"Push opened",value:t.scoutNotesPushOpened},{label:"CTA clicked",value:t.scoutNotesCtaClicked},{label:"Share clicked",value:t.scoutNotesShareClicked},{label:"Share viewed",value:t.scoutNotesShareView},{label:"Share CTA",value:t.scoutNotesShareCtaClick}],empty:"No Scout Notes fired in this range."})}),e.jsx(u,{title:"Trade share loop â selected range",description:"Public trade-analysis share views â signup CTA clicks.",children:e.jsx(w,{stages:[{label:"Share views",value:t.tradeShareViews},{label:"CTA clicks",value:t.tradeShareCtaClicks}],empty:"No trade shares viewed in this range."})}),e.jsx(u,{title:"This week â quota bucket",description:e.jsxs(e.Fragment,{children:["Week ",e.jsx("span",{className:"font-mono",children:s.weekKey}),", resets"," ",m(s.resetAt),". Free-tier quotas reset on this boundary, so these stay week-aligned regardless of the range above."]}),children:e.jsxs(g,{cols:4,children:[e.jsx(o,{label:"Scout queries",value:s.scout.queriesThisWeek,sub:`${s.scout.activeUsersThisWeek} active user${s.scout.activeUsersThisWeek===1?"":"s"}`}),e.jsx(o,{label:"Tool runs",value:s.tools.totalRunsThisWeek,sub:`${s.tools.activeUsersThisWeek} active user${s.tools.activeUsersThisWeek===1?"":"s"}`}),e.jsx(o,{label:"Scout walls",value:s.scout.quotaReachedThisWeek,tone:s.scout.quotaReachedThisWeek>0?"warning":"default"}),e.jsx(o,{label:"Tool walls",value:s.tools.quotaReachedThisWeek,tone:s.tools.quotaReachedThisWeek>0?"warning":"default"})]})})]})}function T({data:s,empty:a}){const t=Object.entries(s).sort((r,l)=>l[1]-r[1]);return t.length===0?e.jsx(f,{children:a}):e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4",children:t.map(([r,l])=>e.jsxs(x,{className:"gap-1 px-4 py-3",children:[e.jsx("span",{className:"text-muted-foreground block text-[11px] leading-tight tracking-[0.15em] uppercase",children:r}),e.jsx("p",{className:"mt-1 text-xl font-bold tabular-nums sm:text-2xl",children:l.toLocaleStr
1ing()})]},r))})}function j({label:s,total:a,series:t,sub:r,accent:l,tone:n="default"}){return e.jsxs(x,{className:`gap-1 px-4 py-4 ${l?"ring-primary/40 ring-1":""}`,children:[e.jsx("span",{className:"text-muted-foreground block text-[11px] leading-tight tracking-[0.15em] uppercase",children:s}),e.jsx("p",{className:`mt-1 text-2xl font-bold tabular-nums sm:text-3xl ${n==="warning"?"text-amber-400":l?"text-primary":""}`,children:a.toLocaleString()}),r&&e.jsx("p",{className:"text-muted-foreground text-xs leading-snug",children:r}),e.jsx("div",{className:"text-primary mt-2",children:e.jsx(H,{data:t??[]})})]})}function Y({rangeArg:s,onPickLeague:a,onPickUser:t}){const r=M(s);return e.jsx(C,{query:r,skeleton:e.jsx(N,{rows:2,label:"Querying Logs Insights"}),children:l=>e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:[e.jsx(L,{title:"Top leagues",rows:l.topLeagues,onPick:a,empty:"No league activity in this range."}),e.jsx(L,{title:"Top users",rows:l.topUsers,onPick:t,empty:"No user activity in this range."})]})})}function L({title:s,rows:a,onPick:t,empty:r}){return e.jsxs(x,{className:"gap-3 px-4 py-4 sm:px-5",children:[e.jsx("h3",{className:"text-muted-foreground text-xs font-semibold tracking-[0.15em] uppercase",children:s}),a.length===0?e.jsx(f,{children:r}):e.jsx("ol",{className:"space-y-0.5",children:a.map((l,n)=>{const i=!!(l.displayName||l.email),c=l.displayName||l.email||l.id,d=l.displayName?l.email||l.id:l.email?l.id:null;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>t(l.id),className:"hover:bg-muted/50 flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left transition",children:[e.jsx("span",{className:"text-muted-foreground w-5 shrink-0 text-[11px] tabular-nums",children:n+1}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`block truncate text-xs ${i?"":"font-mono"}`,children:c}),d&&e.jsx("span",{className:"text-muted-foreground block truncate font-mono text-[10px]",children:d})]}),e.jsxs("span",{className:"text-muted-foreground shrink-0 text-[10px] tabular-nums",children:[l.scoutQueries.toLocaleString(),"s ·"," ",l.toolRuns.toLocaleString(),"t"]}),e.jsx("span",{className:"w-12 shrink-0 text-right font-bold tabular-nums",children:l.total.toLocaleString()})]})},l.id)})})]})}function W(s){const[a,t]=h.useState(s??""),[r,l]=h.useState(s??null);return h.useEffect(()=>{s&&(t(s),l(s))},[s]),{draft:a,setDraft:t,submitted:r,submit:n=>{n.preventDefault();const i=a.trim();i&&l(i)}}}function $({label:s,placeholder:a,draft:t,setDraft:r,onSubmit:l,busy:n}){return e.jsx(x,{className:"px-4 py-4",children:e.jsxs("form",{onSubmit:l,className:"flex flex-col gap-3 sm:flex-row sm:items-end",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1.5",children:[e.jsx(E,{className:"text-muted-foreground text-[11px] font-medium tracking-[0.15em] uppercase",children:s}),e.jsx(D,{value:t,onChange:i=>r(i.target.value),placeholder:a,className:"font-mono"})]}),e.jsx(R,{type:"submit",disabled:!t.trim()||n,children:n?"Queryingâ¦":"Look up"})]})})}function z({focusUserId:s,rangeArg:a,onPickLeague:t}){const r=W(s),l=G(r.submitted,a);return e.jsxs("div",{className:"space-y-4",children:[e.jsx($,{label:"User ID",placeholder:"Cognito user id",draft:r.draft,setDraft:r.setDraft,onSubmit:r.submit,busy:l.isFetching}),r.submitted&&l.error&&!l.data&&e.jsx(F,{error:l.error,onRetry:()=>l.refetch()}),r.submitted&&!l.data&&!l.error&&e.jsx(N,{rows:2,label:"Querying Logs Insights"}),l.data&&e.jsx(J,{data:l.data,onPickLeague:t})]})}function J({data:s,onPickLeague:a}){const t=Object.entries(s.tools.runsByTool).sort((n,i)=>i[1]-n[1]),r=Object.entries(s.leaguesActive).sort((n,i)=>i[1]-n[1]),l=s.scout.quotaReached+Object.values(s.tools.quotaReachedByTool).reduce((n,i)=>n+i,0);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s.displayName&&e.jsx("span",{className:"text-foreground font-semibold",children:s.displayName}),s.email&&e.jsxs("span",{children:[" · ",s.email]}),e.jsx("span",{className:"mt-0.5 block font-mono",children:s.userId}),m(s.windowStart)," â ",m(s.windowEnd)]}),e.jsxs(g,{cols:4,children:[e.jsx(o,{label:"Scout queries",value:s.scout.queries,accent:!0}),e.jsx(o,{label:"Tool runs",value:s.tools.totalRuns,accent:!0}),e.jsx(o,{label:"Paywall walls hit",value:l,tone:l>0?"warning":"default"}),e.jsx(o,{label:"Leagues active",value:r.length})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:[e.jsx(y,{title:"Tool runs by tool",entries:t,empty:"No tool runs in this range."}),e.jsx(y,{title:"Active in leagues",entries:r,empty:"No league-tagged activity in this range.",onPick:a})]})]})}function Z({focusLeagueId:s,rangeArg:a}){const t=W(s),r=V(t.submitted,a);return e.jsxs("div",{className:"space-y-4",children:[e.jsx($,{label:"League ID",placeholder:"e.g. 1234567890123456789",draft:t.draft,setDraft:t.setDraft,onSubmit:t.submit,busy:r.is
1Fetching}),t.submitted&&r.error&&!r.data&&e.jsx(F,{error:r.error,onRetry:()=>r.refetch()}),t.submitted&&!r.data&&!r.error&&e.jsx(N,{rows:2,label:"Querying Logs Insights"}),r.data&&e.jsx(ee,{data:r.data})]})}function ee({data:s}){const a=Object.entries(s.tools.runsByTool).sort((r,l)=>l[1]-r[1]),t=Object.values(s.tools.failuresByTool).reduce((r,l)=>r+l,0);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-muted-foreground text-xs",children:[e.jsx("span",{className:"font-mono",children:s.leagueId})," ·"," ",m(s.windowStart)," â ",m(s.windowEnd)]}),e.jsxs(g,{cols:4,children:[e.jsx(o,{label:"Scout queries",value:s.scout.queries,accent:!0}),e.jsx(o,{label:"Tool runs",value:s.tools.totalRuns,accent:!0,sub:t>0?`${t} failure${t===1?"":"s"}`:void 0,tone:t>0?"warning":"default"}),e.jsx(o,{label:"Newsletter",value:s.newsletter.rendered,sub:s.newsletter.published>0?`${s.newsletter.published} published`:void 0}),e.jsx(o,{label:"Emails sent",value:s.email.sent,sub:s.email.failed>0?`${s.email.failed} failed`:s.email.skipped>0?`${s.email.skipped} skipped`:void 0,tone:s.email.failed>0?"error":"default"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:[e.jsx(y,{title:"Tool runs by tool",entries:a,empty:"No tool runs in this range."}),e.jsxs(x,{className:"gap-3 px-4 py-4 sm:px-5",children:[e.jsx("h3",{className:"text-muted-foreground text-xs font-semibold tracking-[0.15em] uppercase",children:"Podcast"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(p,{label:"Rendered",value:s.podcast.rendered}),e.jsx(p,{label:"Published",value:s.podcast.published})]}),e.jsx("h3",{className:"text-muted-foreground mt-2 text-xs font-semibold tracking-[0.15em] uppercase",children:"Email delivery"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(p,{label:"Sent",value:s.email.sent}),e.jsx(p,{label:"Failed",value:s.email.failed,tone:s.email.failed>0?"error":"default"}),e.jsx(p,{label:"Skipped",value:s.email.skipped})]})]})]})]})}function y({title:s,entries:a,empty:t,onPick:r}){return e.jsxs(x,{className:"gap-3 px-4 py-4 sm:px-5",children:[e.jsx("h3",{className:"text-muted-foreground text-xs font-semibold tracking-[0.15em] uppercase",children:s}),a.length===0?e.jsx(f,{children:t}):e.jsx("ul",{className:r?"space-y-0.5":"space-y-1.5",children:a.map(([l,n])=>r?e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>r(l),className:"hover:bg-muted/50 flex w-full items-center justify-between gap-2 rounded-lg px-2 py-1.5 text-left transition",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:l}),e.jsx("span",{className:"shrink-0 font-bold tabular-nums",children:n.toLocaleString()})]})},l):e.jsxs("li",{className:"flex items-center justify-between gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground truncate font-mono text-xs",children:l}),e.jsx("span",{className:"font-bold tabular-nums",children:n.toLocaleString()})]},l))})]})}export{$e 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.