PageSourceSearch

https://eisenhowertodoist.netlify.app/assets/Admin-BAtFewQU.js

js eisenhowertodoist.netlify.app collected 2026-10-03 10:41:48 UTC 82,341 bytes, 1 lines download raw bytes

1import{N as M,j as e,c as y,cv as bt,Z as k,aT as Ve,cw as _t,cx as be,a4 as Qe,cy as yt,cz as Nt,cA as jt,aH as Ze,bF as $e,cB as vt,cC as wt,aW as kt,cu as $t,cD as Tt,cE as St,cF as Ct,bO as At,cG as It,bJ as Dt,cH as oe,cI as Mt,ad as Et,cJ as Ot,bP as Rt,cK as Lt,bW as Pt,cL as Ft,bV as zt,a_ as qt,cM as Ut,aS as Bt,bb as Ht,bH as Gt,ba as ue,cN as Wt,b4 as Kt,bQ as Vt,cO as Qt,cP as Zt,cQ as Yt,cR as me,cS as Jt,as as Xt,cT as es,cU as ts,aB as Ye,M as ss,cq as ns,$ as as,cp as Te,b7 as rs}from"./vendor-1kUQ7zn2.js";import{d as os}from"./vendor-supabase-Dh2gyaRa.js";import{s as $,C as T,c as h,P as is,g as ds,S as cs,Q as ls,R as us,T as ms,U as ps,B as Se}from"./index--kdl1ae9.js";import{m as xs}from"./vendor-motion-BX-jsy7E.js";import"./vendor-date-en1IyhsK.js";const pe=5,hs="supabase/migrations/20261007090000_active_presence.sql",Je=60;function fs(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}async function gs(){const{data:t,error:s}=await $.rpc("admin_dashboard",{p_tz:fs()});if(s)throw s.code==="PGRST202"||/admin_dashboard/.test(s.message)&&/not find|does not exist/i.test(s.message)?new Error("The admin_dashboard database function is missing. Apply supabase/migrations/20260929120000_admin_dashboard_rpc.sql in the Supabase SQL Editor."):s;const r=t,a=bs(r.people??[],{now:Date.now(),todayStart:r.today_start,honest:(r.presence_version??0)>=2});return{generatedAt:r.generated_at,tz:r.tz,todayStart:r.today_start,...a,loginsToday:a.activeToday.filter(n=>n.logged_in_today).length,actionsToday:r.actions_today??0,actionsByType:r.actions_by_type??[],prioritizedToday:r.prioritized_today??[],prioritizedTasksToday:r.prioritized_tasks_today??0,signups:r.signups}}const ie=(t,s)=>{const r=s?Date.parse(s):NaN;return Number.isNaN(r)?null:Math.max(0,(t-r)/6e4)};function bs(t,{now:s,todayStart:r,honest:a}){const n=Date.parse(r),o=t.map(c=>({...c,minutes_since_seen:ie(s,c.last_seen)??1/0,minutes_since_active:a?ie(s,c.last_active_at):ie(s,c.last_seen)})),i=o.filter(c=>!c.is_admin),d=c=>a?!!c.online_now:c.minutes_since_seen<pe,l=i.filter(d),x=i.filter(c=>!d(c)&&c.minutes_since_active!=null&&c.minutes_since_active<Je),u=c=>a?!!c.opened_today:Date.parse(c.last_seen)>=n,p=c=>a?!!c.did_something_today:c.actions_today>0,b=(c,f)=>(f.active_seconds_today??0)-(c.active_seconds_today??0)||(f.product_actions_today??f.actions_today)-(c.product_actions_today??c.actions_today)||(c.minutes_since_active??1/0)-(f.minutes_since_active??1/0),m=i.filter(c=>p(c)&&(u(c)||!a)).sort(b),_=i.filter(c=>u(c)&&!p(c)).sort(b);return{people:o,honest:a,online:l,lastHour:x,didSomething:m,onlyOpened:_,activeToday:[...m,..._],adminsOnline:o.filter(c=>c.is_admin&&d(c)).length,productActionsToday:m.reduce((c,f)=>c+(a?f.product_actions_today??0:f.actions_today),0)}}function _s(t){return M({queryKey:["admin-dashboard"],queryFn:gs,enabled:t,refetchInterval:6e4,staleTime:3e4,retry:1})}const ys={app_opened:"Opened the app",signed_up:"Signed up",signed_in:"Signed in",connect_todoist_viewed:"Saw Connect Todoist",connect_todoist_clicked:"Clicked Connect Todoist",connect_todoist_result:"Todoist connection",matrix_viewed:"Saw the matrix",categorize_opened:"Opened Categorize",task_categorized:"Sorted tasks into quadrants",ai_suggest_run:"Ran AI suggestions",ai_consent:"AI consent",task_added:"Added a task",task_completed:"Completed a task",task_deleted:"Deleted a task",task_delete_undone:"Undid a delete",follow_up_created:"Created a follow-up",focus_started:"Started Focus",focus_ended:"Ended Focus",daily_review_opened:"Opened Daily Review",stats_opened:"Opened Statistics",filters_used:"Used filters",settings_opened:"Opened Settings",tour_started:"Started the tour",tour_completed:"Finished the tour",tour_skipped:"Skipped the tour",plans_viewed:"Saw plans",checkout_started:"Started checkout",checkout_result:"Checkout",license_dialog_opened:"Opened license key",license_activated:"Activated a license",logged_out:"Logged out",session_active:"Active time",starter_card:"Sort card",view_changed:"Changed the view",task_opened:"Opened a task",due_changed:"Changed a due date",error_shown:"Saw an error"};function Ns(t){const s=t.props||{};return t.name==="connect_todoist_result"?s.result==="ok"?"good":"bad":t.name==="ai_suggest_run"&&s.result==="error"?"bad":t.name==="checkout_result"?s.result==="activated"?"good":"bad":t.name==="license_activated"?"good":t.name==="error_shown"||t.name==="starter_card"&&s.action==="dism
1issed"?"bad":t.name==="signed_up"||t.name==="checkout_started"||t.name==="matrix_viewed"?"key":null}const Ce=(t,s,r=s+"s")=>`${t} ${t===1?s:r}`,js={quadrant_tab:"quadrant tab",layout:"layout",density:"density"},vs={sheet:"action sheet",expand:"subtasks",detail:"task menu"},ws={picker:"picker",nl:"typed in the title",swipe:"swipe",quick:"quick action"},ks={tasks_load:"couldn't load tasks",todoist_auth:"Todoist connection expired",network:"offline",other:"something broke"};function G(t){const s=Number.isFinite(t)?Math.max(0,t):0;if(s===0)return"0 min active";if(s<60)return"under 1 min active";const r=Math.round(s/60);if(r<60)return`${r} min active`;const a=Math.floor(r/60);return r%60?`${a} h ${r%60} min active`:`${a} h active`}function $s(t,s){const r=s||{},a=[],n=i=>typeof r[i]=="string"?r[i]:null,o=i=>typeof r[i]=="number"?r[i]:null;switch(t){case"signed_up":n("method")&&a.push(`with ${n("method")}`),n("utm_source")&&a.push(`source ${n("utm_source")}`),n("utm_campaign")&&a.push(`campaign ${n("utm_campaign")}`),n("utm_medium")&&a.push(`medium ${n("utm_medium")}`),n("ref")&&a.push(`from ${n("ref")}`);break;case"signed_in":n("method")&&a.push(`with ${n("method")}`);break;case"connect_todoist_result":n("result")&&a.push(n("result")==="ok"?"connected":n("result")),n("code")&&a.push(`code ${n("code")}`),n("via")==="login"&&a.push("via Todoist sign-in");break;case"matrix_viewed":n("tasks")&&a.push(`${n("tasks")} tasks`),n("unsorted")&&a.push(`${n("unsorted")} unsorted`),n("view")&&a.push(`${n("view")} view`);break;case"task_categorized":o("n")!=null&&a.push(Ce(o("n"),"task")),n("quadrant")&&a.push(`to ${n("quadrant")}`),n("via")&&a.push(`via ${n("via")}`),n("sheet")&&n("sheet")!=="categorize"&&a.push(`in ${n("sheet")}`);break;case"task_deleted":n("quadrant")&&a.push(n("quadrant")),r.recurring===!0&&a.push("recurring"),n("via")&&a.push(`via ${n("via")}`);break;case"task_delete_undone":o("n")!=null&&a.push(Ce(o("n"),"task"));break;case"task_added":case"task_completed":o("n")!=null&&o("n")>1&&a.push(`×${o("n")}`),n("quadrant")&&a.push(n("quadrant")),r.focus===!0&&a.push("in Focus"),n("via")&&a.push(`via ${n("via")}`);break;case"focus_ended":n("minutes")&&a.push(`${n("minutes")} min`),r.idle===!0&&a.push("ended idle");break;case"daily_review_opened":a.push(r.auto===!0?"automatically":"by hand");break;case"ai_suggest_run":n("result")&&a.push(n("result")),n("code")&&a.push(n("code")),n("tasks")&&a.push(`${n("tasks")} tasks`);break;case"view_changed":n("kind")&&a.push(js[n("kind")]??n("kind")),n("to")&&a.push(`to ${n("to")}`);break;case"task_opened":n("surface")&&a.push(vs[n("surface")]??n("surface"));break;case"due_changed":n("kind")&&a.push(n("kind")==="cleared"?"cleared":n("kind")==="time"?"time":"date"),n("via")&&a.push(ws[n("via")]??`via ${n("via")}`);break;case"error_shown":n("kind")&&a.push(ks[n("kind")]??n("kind"));break;case"starter_card":break;case"session_active":o("seconds")!=null&&a.push(G(o("seconds")));break;case"tour_skipped":n("kind")&&a.push(n("kind")),o("step")!=null&&a.push(`at step ${o("step")+1}`);break;default:for(const[i,d]of Object.entries(r))i!=="layout"&&(typeof d=="boolean"?a.push(d?i:`no ${i}`):d!=null&&a.push(String(d)))}return n("layout")&&a.push(n("layout")),a.join(" · ")}const Ts=30*6e4,Ss=t=>{const s=new Date(t),r=a=>String(a).padStart(2,"0");return`${s.getFullYear()}-${r(s.getMonth()+1)}-${r(s.getDate())}`};function Cs(t){const s=[...t].filter(n=>n&&typeof n.created_at=="string"&&!Number.isNaN(Date.parse(n.created_at))).sort((n,o)=>Date.parse(o.created_at)-Date.parse(n.created_at)),r=[];let a=null;for(const n of s){const o=Date.parse(n.created_at),i=Ss(n.created_at);let d=r[r.length-1];(!d||d.day!==i)&&(d={day:i,sessions:[],count:0},r.push(d),a=null);let l=d.sessions[d.sessions.length-1];if((!l||a==null||a-o>
1=Ts)&&(l={start:n.created_at,end:n.created_at,events:[],activeSeconds:0},d.sessions.push(l)),l.start=n.created_at,a=o,n.name==="session_active"){const x=typeof n.props?.seconds=="number"?n.props.seconds:0;l.activeSeconds+=Math.max(0,x);continue}l.events.push(n),d.count++}return r}const As=new Set(["app_opened","signed_in","connect_todoist_viewed","matrix_viewed","categorize_opened","filters_used","settings_opened","stats_opened","plans_viewed","daily_review_opened","license_dialog_opened","view_changed","task_opened","error_shown"]);function Is(t){const s=[];let r=[];for(const a of t){const n=$s(a.name,a.props),o=s[s.length-1];if(o&&o.event.name===a.name&&(As.has(a.name)||o.detail===n)){o.count++,o.first=a.created_at,n&&!r.includes(n)&&(r.push(n),o.detail=r.join(" / "));continue}r=n?[n]:[],s.push({event:a,count:1,first:a.created_at,detail:n})}return s}function Ds(t){const s=t.props&&typeof t.props.result=="string"?t.props.result:null;if(t.name==="connect_todoist_result"){if(s==="ok")return"Connected Todoist";if(s==="cancelled")return"Cancelled connecting Todoist";if(s==="error")return"Todoist connection failed"}if(t.name==="checkout_result"){if(s==="activated")return"Payment went through";if(s==="closed")return"Closed checkout";if(s==="cancelled")return'Left checkout ("Not now")';if(s==="slow")return"Checkout still confirming"}if(t.name==="ai_consent"&&t.props?.state==="granted")return"Allowed AI suggestions";if(t.name==="ai_consent"&&t.props?.state==="revoked")return"Turned off AI suggestions";if(t.name==="starter_card"){const r=t.props?.action;if(r==="shown")return"Saw the sort card";if(r==="started")return"Started from the sort card";if(r==="dismissed")return"Dismissed the sort card"}return ys[t.name]??t.name.replace(/_/g," ")}function Ms(t){const s=Ds(t.event);return t.count>1?`${s} ×${t.count}`:s}const Ae={emerald:"from-emerald-500/15 to-emerald-500/5 text-emerald-600 dark:text-emerald-400",blue:"from-blue-500/15 to-blue-500/5 text-blue-600 dark:text-blue-400",amber:"from-amber-500/15 to-amber-500/5 text-amber-600 dark:text-amber-400",violet:"from-violet-500/15 to-violet-500/5 text-violet-600 dark:text-violet-400"};function K({label:t,value:s,hint:r,icon:a,accent:n="blue",loading:o}){return e.jsxs(T,{className:"relative overflow-hidden p-5",children:[e.jsx("div",{className:h("absolute inset-0 bg-gradient-to-br opacity-60",Ae[n])}),e.jsxs("div",{className:"relative flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-3xl font-semibold tabular-nums",children:o?e.jsx("span",{className:"inline-block h-8 w-12 animate-pulse rounded bg-muted-foreground/20"}):s}),r&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r})]}),e.jsx("div",{className:h("rounded-xl bg-background/60 p-2.5 backdrop-blur-sm",Ae[n]),children:e.jsx(a,{className:"h-5 w-5"})})]})]})}const Es={green:"bg-emerald-500",amber:"bg-amber-500",muted:"bg-muted-foreground/40"};function Ie({rows:t,emptyText:s,onSelect:r}){return t.length===0?e.jsx("p",{className:"px-5 py-6 text-center text-sm text-muted-foreground",children:s}):e.jsx(e.Fragment,{children:t.map(a=>{const n=e.jsxs(e.Fragment,{children:[a.dot&&e.jsx("span",{className:h("h-2 w-2 shrink-0 rounded-full",Es[a.dot])}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:a.email??"unknown user"}),a.sub&&e.jsx("p",{className:"truncate text-xs text-muted-foreground","data-testid":"user-row-sub",children:a.sub})]}),a.meta&&e.jsx("span",{className:"shrink-0 text-xs font-medium tabular-nums text-muted-foreground",children:a.meta})]});return r?e.jsx("button",{type:"button","data-testid":"user-row","data-user":a.key,onClick:()=>r(a),className:"flex w-full items-center gap-3 px-5 py-3 text-left transition-colors hover:bg-muted/50 focus-visible:bg-muted/50 focus-visible:outline-none",children:n},a.key):e.jsx("div",{className:"flex items-center gap-3 px-5 py-3","data-user":a.key,children:n},a.key)})})}function V({title:t,icon:s,rows:r,sections:a,emptyText:n,note:o,testId:i,loading:d,onSelect:l}){const x=a?a.reduce((u,p)=>u+p.rows.length,0):r?.length??0;return e.jsxs(T,{className:"flex flex-col overflow-hidden","data-testid":i,children:[e.jsxs("div",{className:"border-b px-5 py-3.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-sm font-semibold",children:t}),!d&&e.jsx("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground",children:x})]}),o&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o})]}),e.jsx("div",{className:"max-h-[22rem] divide-y overflow-y-auto",children:d?e.jsx("div",{className:"space-y-3 p-5",children:[0,1,2].map(u=>e.jsx("div",{className:"h-9 animate-pulse rounded bg-muted-foreground
1/10"},u))}):a?a.map(u=>e.jsxs("section",{"data-testid":u.testId,className:"divide-y",children:[e.jsxs("h3",{className:"flex items-center bg-muted/30 px-5 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:[u.title,e.jsx("span",{className:"ml-auto tabular-nums",children:u.rows.length})]}),e.jsx(Ie,{rows:u.rows,emptyText:u.emptyText,onSelect:l})]},u.title)):x===0?e.jsx("p",{className:"px-5 py-8 text-center text-sm text-muted-foreground",children:n}):e.jsx(Ie,{rows:r??[],emptyText:n,onSelect:l})})]})}const Xe=y.forwardRef(({className:t,...s},r)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:r,className:h("w-full caption-bottom text-sm",t),...s})}));Xe.displayName="Table";const et=y.forwardRef(({className:t,...s},r)=>e.jsx("thead",{ref:r,className:h("[&_tr]:border-b",t),...s}));et.displayName="TableHeader";const tt=y.forwardRef(({className:t,...s},r)=>e.jsx("tbody",{ref:r,className:h("[&_tr:last-child]:border-0",t),...s}));tt.displayName="TableBody";const Os=y.forwardRef(({className:t,...s},r)=>e.jsx("tfoot",{ref:r,className:h("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t),...s}));Os.displayName="TableFooter";const xe=y.forwardRef(({className:t,...s},r)=>e.jsx("tr",{ref:r,className:h("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t),...s}));xe.displayName="TableRow";const U=y.forwardRef(({className:t,...s},r)=>e.jsx("th",{ref:r,className:h("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",t),...s}));U.displayName="TableHead";const B=y.forwardRef(({className:t,...s},r)=>e.jsx("td",{ref:r,className:h("p-4 align-middle [&:has([role=checkbox])]:pr-0",t),...s}));B.displayName="TableCell";const Rs=y.forwardRef(({className:t,...s},r)=>e.jsx("caption",{ref:r,className:h("mt-4 text-sm text-muted-foreground",t),...s}));Rs.displayName="TableCaption";function Ls(t){if(!t)return"—";const s=Math.max(0,Math.round((Date.now()-new Date(t).getTime())/6e4));if(s<1)return"just now";if(s<60)return`${s}m ago`;const r=Math.round(s/60);return r<24?`${r}h ago`:`${Math.round(r/24)}d ago`}function De(t){return(t.log_write_failures??0)+(t.task_update_failures??0)}function Ps(){const{data:t,isLoading:s,error:r}=M({queryKey:["auto-prioritize-run-health"],refetchInterval:3e4,queryFn:async()=>{const{data:n,error:o}=await $.from("auto_prioritization_runs").select("user_id, ran_at, total_tasks, candidates, prioritized, log_write_failures, task_update_failures, error").order("ran_at",{ascending:!1});if(o)throw o;const i=[...new Set((n??[]).map(l=>l.user_id))],d=new Map;if(i.length>0){const{data:l,error:x}=await $.rpc("admin_profile_emails",{p_ids:i});let u=l??null;if(x&&x.code==="PGRST202"){const{data:p}=await $.from("profiles").select("id, email").in("id",i);u=p}for(const p of u??[])d.set(p.id,p.email)}return(n??[]).map(l=>({...l,email:d.get(l.user_id)??null}))}}),a=(t??[]).filter(n=>n.error||De(n)>0).length;return e.jsxs(T,{className:"mt-4 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b px-5 py-3.5",children:[e.jsx(bt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-sm font-semibold",children:"Auto-prioritize · run health"}),!s&&t&&e.jsx("span",{className:h("ml-auto text-xs font-medium tabular-nums",a>0?"text-amber-600 dark:text-amber-400":"text-muted-foreground"),children:a>0?`${a} with issues`:"all healthy"})]}),s?e.jsx("div",{className:"space-y-3 p-5",children:[0,1,2].map(n=>e.jsx("div",{className:"h-9 animate-pulse rounded bg-muted-foreground/10"},n))}):r?e.jsxs("div",{className:"flex items-start gap-2 p-5 text-sm text-destructive",children:[e.jsx(k,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:r.message})]}):!t||t.length===0?e.jsx("p",{className:"px-5 py-8 text-center text-sm text-muted-foreground",children:"No runs recorded yet. Once the cron runs (after the function is deployed and the auto_prioritization_runs table exists), per-user run health shows up here."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Xe,{children:[e.jsx(et,{children:e.jsxs(xe,{children:[e.jsx(U,{children:"User"}),e.jsx(U,{children:"Last run"}),e.jsx(U,{className:"text-right",children:"Tasks"}),e.jsx(U,{className:"text-right",children:"Moved"}),e.jsx(U,{children:"Status"})]})}),e.jsx(tt,{children:t.map(n=>{const o=De(n),i=!!n.error;return e.jsxs(xe,{className:h((i||o>0)&&"bg-amber-500/5"),children:[e.jsx(B,{className:"max-w-[14rem] truncate font-medium",children:n.email??n.user_id}),e.jsx(B,{className:"whitespace-nowrap text-xs text-muted-foreground",children:Ls(n.ran_at)}),e.jsx(B,{className:"text-right tabular-nums text-muted-foreground",children:n.total_tasks??"—"}),e.jsx(B,{className:"text-right tabular-nums",children:n.prioritized??"—"}),e.jsx(B,{children:i?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-destructive/15 px-2 py-0.5 text-[0.7rem] font-medium text-destructive",title:n.error??void 0,children:[e.jsx(k,{className:"h-3 w-3"}),"error"]}):o>
10?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-500/15 px-2 py-0.5 text-[0.7rem] font-medium text-amber-600 dark:text-amber-400",children:[e.jsx(k,{className:"h-3 w-3"}),o," failed"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-emerald-500/15 px-2 py-0.5 text-[0.7rem] font-medium text-emerald-600 dark:text-emerald-400",children:[e.jsx(Ve,{className:"h-3 w-3"}),"ok"]})})]},n.user_id)})})]})})]})}const Fs=.75,Me=7,st={LCP:{good:2500,poor:4e3,unit:"s"},INP:{good:200,poor:500,unit:"ms"},CLS:{good:.1,poor:.25,unit:""},FCP:{good:1800,poor:3e3,unit:"s"},TTFB:{good:800,poor:1800,unit:"ms"}},zs=["LCP","INP","CLS","FCP","TTFB"];function qs(t,s){if(t.length===0)return 0;const r=Math.min(t.length-1,Math.ceil(t.length*s)-1);return t[Math.max(0,r)]}function Us(t,s){const r=st[t];return r?r.unit==="s"?`${(s/1e3).toFixed(2)}s`:r.unit==="ms"?`${Math.round(s)}ms`:s.toFixed(3):String(Math.round(s))}function Bs(t,s){const r=st[t];return r?s<=r.good?"good":s<=r.poor?"mid":"poor":"mid"}function Hs(){const{data:t,isLoading:s}=M({queryKey:["admin-web-vitals"],staleTime:3e5,queryFn:async()=>{const r=new Date(Date.now()-Me*864e5).toISOString(),{data:a,error:n}=await $.from("web_vitals").select("metric, value").gte("created_at",r).limit(2e4);if(n)throw n;const o=new Map;for(const d of a??[]){const l=o.get(d.metric)??[];l.push(d.value),o.set(d.metric,l)}return{summaries:zs.filter(d=>o.has(d)).map(d=>{const l=(o.get(d)??[]).sort((x,u)=>x-u);return{metric:d,p75:qs(l,Fs),samples:l.length}}),total:(a??[]).length}}});return!s&&(!t||t.total===0)?null:e.jsxs(T,{className:"mt-4 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b px-5 py-3.5",children:[e.jsx(_t,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("h2",{className:"text-sm font-semibold",children:["Web Vitals · real users · p75, last ",Me," days"]}),t&&e.jsxs("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground",children:[t.total," samples"]})]}),s?e.jsx("div",{className:"grid grid-cols-2 gap-3 p-5 sm:grid-cols-5",children:[0,1,2,3,4].map(r=>e.jsx("div",{className:"h-16 animate-pulse rounded-lg bg-muted-foreground/10"},r))}):e.jsx("div",{className:"grid grid-cols-2 gap-3 p-5 sm:grid-cols-5",children:(t?.summaries??[]).map(r=>{const a=Bs(r.metric,r.p75);return e.jsxs("div",{className:h("rounded-lg border px-3 py-2.5",a==="good"&&"border-emerald-500/30 bg-emerald-500/[0.06]",a==="mid"&&"border-amber-500/30 bg-amber-500/[0.06]",a==="poor"&&"border-red-500/30 bg-red-500/[0.06]"),children:[e.jsx("div",{className:"text-[11px] font-medium text-muted-foreground",children:r.metric}),e.jsx("div",{className:h("text-lg font-semibold tabular-nums",a==="good"&&"text-emerald-600 dark:text-emerald-400",a==="mid"&&"text-amber-600 dark:text-amber-400",a==="poor"&&"text-red-600 dark:text-red-400"),children:Us(r.metric,r.p75)}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[r.samples," samples"]})]},r.metric)})})]})}const w=[{key:"signed_up",label:"Signed up"},{key:"saw_connect",label:"Saw Connect"},{key:"clicked_connect",label:"Clicked Connect"},{key:"connected",label:"Connected Todoist"},{key:"saw_matrix",label:"Saw the matrix"},{key:"categorized",label:"Sorted ≥1 task"},{key:"returned",label:"Came back another day"},{key:"checkout",label:"Started checkout"},{key:"paid",label:"Paid"}];function R(t){const s=t??{},r=!!s.categorized,a=!!s.saw_matrix||r,n=!!s.connected||a,o=!!s.clicked_connect||n;return[!0,!!s.saw_connect||o,o,n,a,r,!!s.returned,!!s.checkout,!!s.paid]}function D(t){return R(t).lastIndexOf(!0)}function nt(t){const s=w.map(()=>0),r=w.map(()=>0);for(const n of t){const o=R(n.steps);o.forEach((i,d)=>{i&&(s[d]++,d>0&&o[d-1]&&r[d]++)})}const a=s[0];return w.map((n,o)=>({key:n.key,label:n.label,count:s[o],ofStart:a?s[o]/a:null,ofPrev:o===0?null:s[o-1]?r[o]/s[o-1]:null,fromPrev:o===0?s[0]:r[o],skipped:o===0?0:s[o]-r[o],lost:o===0?0:s[o-1]-r[o]}))}function at(t,s,r=Date.now(),a){const n=r-s*864e5,o=a?Date.parse(a):NaN;return t.filter(i=>{const d=Date.parse(i.created_at);return d>=n?Number.isNaN(o)||d>=o-6e4:!1})}const Gs=(t,s)=>s==="method"?t.method||t.provider||"unknown":t.utm_source||(t.ref?`ref: ${t.ref}`:"(direct)");function Ee(t,s){const r=new Map;for(const a of t){const n=Gs(a,s),o=r.get(n)??w.map(()=>0);
1R(a.steps).forEach((i,d)=>{i&&o[d]++}),r.set(n,o)}return[...r.entries()].map(([a,n])=>({group:a,total:n[0],counts:n})).sort((a,n)=>n.total-a.total||a.group.localeCompare(n.group))}const Ws=6e4;function A(t,s){if(!s)return!1;const r=Date.parse(s),a=Date.parse(t.created_at);return Number.isNaN(r)||Number.isNaN(a)?!1:a>=r-Ws}const Q=["stopped after sign-up","stopped at Connect","Connect didn't finish","stopped before the matrix","never categorized","not back yet","no checkout yet","checkout not finished","paid"];function rt(t,s){if(!t)return null;const r=D(t.steps),a=r===Q.length-1;return!t.events||s!==void 0&&!A(t,s)?a?Q[r]:null:Q[r]}const se=t=>t==null?"—":`${Math.round(t*100)}%`;function ot(t,s){const r=R(t.steps),a=r.lastIndexOf(!0),n=A(t,s)&&(t.events??0)>0;return w.map((o,i)=>r[i]?"done":n?i<a?"skipped":"not_done":"unknown")}const he={signed_up:"Created an account (Google, email or Todoist sign-in).",saw_connect:"Was shown the Connect Todoist screen. Todoist sign-ups skip it and count as past it.",clicked_connect:"Pressed Connect with Todoist (or Try again) and left for Todoist.",connected:"Has a Todoist connection: the token is saved, the connection came back ok, or they signed up with Todoist. Seeing the matrix implies it.",saw_matrix:"The matrix loaded with their tasks at least once (sorting a task implies it).",categorized:"Sorted at least one task into a quadrant. Only counted when it happened; paying or coming back never implies it.",returned:"Used the app again on a later calendar day than the sign-up day, whether or not they sorted.",checkout:"Opened a checkout (or a checkout status) for a paid plan. A license key bought elsewhere skips it.",paid:"Has a paid or lifetime plan, or activated a license."},Ks=["","signed up but never saw Connect Todoist","saw Connect Todoist but didn't click it","clicked Connect but didn't finish connecting","connected Todoist but never saw the matrix","saw the matrix but didn't sort a task","sorted tasks but haven't come back on a later day","came back but haven't started checkout","started checkout but didn't pay"];function it(t){let s=null;for(let r=1;r<t.length;r++){const a=t[r-1].count,n=t[r].fromPrev??t[r].count,o=a-n;if(a<=0||o<=0)continue;const i=o/a;(!s||o>s.lost||o===s.lost&&i>s.rate)&&(s={index:r,from:a,to:n,lost:o,rate:i,phrase:Ks[r]??""})}return s}function Vs(t,s){const r=t.filter(n=>A(n,s)),a=w.map((n,o)=>({index:o,key:n.key,label:n.label,count:0,share:null,userIds:[]}));for(const n of r){const o=a[D(n.steps)];o.count++,o.userIds.push(n.user_id)}for(const n of a)n.share=r.length?n.count/r.length:null;return a}const Qs=[{key:"connected_at",label:"Sign-up → connected Todoist",note:"first successful Connect (Todoist sign-ups that never used Connect are not in it)"},{key:"matrix_at",label:"Sign-up → saw the matrix",note:"first time the matrix loaded"},{key:"categorized_at",label:"Sign-up → first sort",note:"first task sorted into a quadrant"}],dt=3;function Zs(t){if(!t.length)return null;const s=[...t].sort((a,n)=>a-n),r=Math.floor(s.length/2);return s.length%2?s[r]:(s[r-1]+s[r])/2}function Ys(t,s){const r=new Map(s.map(a=>[a.user_id,a]));return Qs.map(a=>{const n=[];for(const o of t){const d=r.get(o.user_id)?.[a.key];if(!d)continue;const l=(Date.parse(d)-Date.parse(o.created_at))/6e4;Number.isNaN(l)||n.push(Math.max(0,l))}return{key:a.key,label:a.label,note:a.note,n:n.length,medianMinutes:n.length>=dt?Zs(n):null}})}function Js(t){if(t<1)return"under 1 min";if(t<90)return`${Math.round(t)} min`;const s=t/60;return s<48?`${Math.round(s*10)/10} h`.replace(".0 h"," h"):`${Math.round(s/24)} days`}const te=(t,s,r=`${s}s`)=>`${t} ${t===1?s:r}`,Oe={google:"via Google",todoist:"via Todoist",email:"via email"},ct=t=>t.startsWith("ref: ")?t.slice(5):t.charAt(0).toUpperCase()+t.slice(1),_e=t=>new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric"}),ne=t=>t&&!Number.isNaN(Date.parse(t))?_e(t):null;function Xs({users:t,days:s,trackingSince:r,now:a=Date.now()}){if(!r||Number.isNaN(Date.parse(r)))return["Nothing tracked yet: no product events have been recorded, so there is no funnel to read."];const n=a-s*864e5,o=t.filter(N=>Date.parse(N.created_at)>=n&&A(N,r)),i=_e(r),d=Date.parse(r)>n,l=`in the last ${s} days`,x=d?`; tracked since ${i}`:"",u=o.length;if(u===0)return[`No tracked sign-ups ${l}${x}.`];const p=[],b=new Map;for(const N of o){const j=N.method||N.provider||"unknown";
1b.set(j,(b.get(j)??0)+1)}const m=[...b.entries()].sort((N,j)=>j[1]-N[1]||N[0].localeCompare(j[0])).map(([N,j])=>`${j} ${Oe[N]??`via ${N}`}`),_=b.size===1?`all ${Oe[[...b.keys()][0]]??`via ${[...b.keys()][0]}`}`:m.join(", ");p.push(`${u===1?"1 person":`${u} people`} signed up ${l} (${_})${x}.`);const c=nt(o),f=N=>c.find(j=>j.key===N)?.count??0,v=it(c);v&&p.push(`Biggest drop: ${v.lost} of ${v.from} ${v.phrase} (${Math.round(v.rate*100)}%).`);const S=f("saw_matrix");S===0?p.push(`Nobody has reached the matrix yet; ${te(f("connected"),"person","people")} connected Todoist.`):p.push(`${S} reached the matrix; ${f("categorized")} sorted at least one task; ${f("returned")} came back on a later day.`);const L=new Map;for(const N of o){const j=N.utm_source||(N.ref?`ref: ${N.ref}`:null);j&&L.set(j,[...L.get(j)??[],N])}const E=[...L.entries()].sort((N,j)=>j[1].length-N[1].length||N[0].localeCompare(j[0]))[0];if(E){const N=E[1].filter(j=>R(j.steps)[3]).length;p.push(`${ct(E[0])} brought ${te(E[1].length,"sign-up")}; ${N===0?"none":N} connected Todoist.`)}const W=f("checkout"),P=f("paid");return W===0&&P===0?p.push(`No checkouts yet from sign-ups ${l}.`):p.push(`${te(W,"person","people")} started checkout; ${P} paid.`),p.slice(0,5)}const fe=[{kind:"all",label:"All"},{kind:"tracked",label:"Tracked only"},{kind:"stopped_connect",label:"Stopped at Connect"},{kind:"connected_unsorted",label:"Connected, not sorted"},{kind:"paid",label:"Paid"}],en=new Set(["lifetime","monthly","yearly","paid"]);function Re(t,s,r,a){if(r.kind==="all")return!0;if(r.kind==="stop"&&r.userIds)return r.userIds.includes(t.user_id);if(r.kind==="paid")return!!s?.steps.paid||en.has((t.plan??"").toLowerCase());if(!(A(t,a)&&!!s))return!1;if(r.kind==="tracked")return!0;const o=R(s.steps);return r.kind==="stopped_connect"?o[1]&&!o[3]:r.kind==="connected_unsorted"?o[3]&&!o[5]:D(s.steps)===r.step}function de(t){return t.kind==="stop"?`Stopped at: ${w[t.step]?.label??"?"}`:fe.find(s=>
1s.kind===t.kind)?.label??"All"}function tn(t){const s=r=>{const a=Date.parse(r.created_at);return Number.isNaN(a)?-1/0:a};return[...t].sort((r,a)=>s(a)-s(r))}const sn={google:"Google",todoist:"Todoist",email:"email"},nn=[["connected","connected Todoist"],["saw_matrix","saw the matrix"],["categorized","sorted at least one task"],["returned","came back on a later day"],["checkout","started checkout"],["paid","paid"]],an=["hasn't reached Connect Todoist yet","didn't click Connect yet","didn't finish connecting Todoist","hasn't seen the matrix yet","didn't sort anything yet","hasn't come back on a later day yet","no checkout yet","didn't finish checkout",""];function Le(t){const s=t.steps??{},r=[];s.connected||(s.clicked_connect?r.push("clicked Connect"):s.saw_connect&&r.push("saw Connect Todoist"));for(const[a,n]of nn)s[a]&&r.push(n);return r}function rn(t,s,r){const a=t.method?sn[t.method]??t.method:null,n=t.utm_source?ct(t.utm_source):t.ref?t.ref:null,o=t.last_seen?` Last seen ${r(t.last_seen)}.`:"",i=t.events??0;if(!A(t,s)){const p=[t.todoist_connected?"Todoist is connected":"Todoist is not connected",t.plan?`plan: ${t.plan}`:null].filter(Boolean);let b=`Signed up before tracking started${s?` (${_e(s)})`:""}; only profile facts are known: ${p.join(", ")}.`;if(i>0){const m=Le(t).filter(_=>_!=="connected Todoist"&&_!=="paid");b+=m.length?` Since tracking began: ${m.join(", ")}.`:` ${te(i,"event")} recorded since tracking began.`}return b+o}let d=`Signed up${a?` with ${a}`:""}${n?` from ${n}`:""}`;if(i===0){const p=t.todoist_connected?" Todoist is connected (profile).":"";return`${d}, but no events were recorded for this account.${p}${o}`}const l=an[D(t.steps)],x=!R(t.steps)[5]&&D(t.steps)>5?["never sorted a task"]:[],u=[...Le(t),...x,...l?[l]:[]];return u.length&&(d+=`, ${u.join(", ")}`),`${d}.${o}`}const on=new Set(["task_categorized","task_completed","task_added"]);function lt(t){const s={matrixViews:0,appOpens:0,activeSeconds:0,activeKnown:!1,actions:0,usedMatrix:!1,starter:null,errors:[]},r={shown:1,started:2,dismissed:3};for(const a of t){const n=a.props||{};if(a.name==="matrix_viewed")s.matrixViews++;else if(a.name==="app_opened")s.appOpens++;else if(a.name==="session_active")s.activeKnown=!0,typeof n.seconds=="number"&&n.seconds>0&&(s.activeSeconds+=n.seconds);else if(a.name==="starter_card"){const o=n.action;(o==="shown"||o==="started"||o==="dismissed")&&(!s.starter||r[o]>r[s.starter])&&(s.starter=o)}else a.name==="error_shown"&&typeof n.kind=="string"&&!s.errors.includes(n.kind)&&s.errors.push(n.kind);on.has(a.name)&&(s.usedMatrix=!0),s.actions+=is(a.name,n)}return s}const Pe=t=>t===1?"once":t===2?"twice":`${t} times`,dn={dismissed:"dismissed the sort card",started:"opened the sort card but stopped",shown:"ignored the sort card"},cn={tasks_load:`saw "Couldn't load tasks"`,todoist_auth:'saw "Todoist connection expired"',network:"was offline",other:"hit an error screen"};function ln(t){const s=lt(t);if(s.usedMatrix)return null;const r=[];let a;if(s.matrixViews>0)r.push(`saw the matrix ${Pe(s.matrixViews)}`),a="never sorted";else if(s.appOpens>0)r.push(`opened the app ${Pe(s.appOpens)}`),a="never saw the matrix";else return null;s.activeKnown&&r.push(G(s.activeSeconds)),s.starter&&r.push(dn[s.starter]);for(const o of s.errors.slice(0,2))r.push(cn[o]??"saw an error");r.push(a);const n=r.join(", ");return`${n.charAt(0).toUpperCase()}${n.slice(1)}.`}const Fe={kind:"all"};function Z(t,s={month:"short",day:"numeric"}){const[r,a,n]=t.split("-").map(Number);return new Date(r,a-1,n).toLocaleDateString(void 0,s)}function un(t){return t?Math.ceil((new Date(t).getTime()-Date.now())/864e5):null}function mn(t){return t==="google"?"Google":t==="email"?"Email":t.charAt(0).toUpperCase()+t.slice(1)}function pn(t){if(t.plan==="trial"){const s=un(t.trial_end_date);return s!=null?`trial · ${s}d left`:"trial"}return t.plan}const F="inline-flex items-center rounded-full border px-1.5 py-px text-[11px] leading-4",Y="border-border bg-muted/40 text-muted-foreground";function ce({label:t,value:s}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("p",{className:"mt-0.5 text-2xl font-semibold tabular-nums",children:s})]})}function xn({daily:t}){const[s,r]=y.useState(null),a=Math.max(1,...t.map(i=>i.count)),n=t.length-1,o=s!=null?t[s]:null;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-baseline justify-between gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Daily sign-ups, last 30 days"}),e.jsx("span",{className:"tabular-nums text-foreground","aria-live":"polite",children:o?`${Z(o.day,{weekday:"short",month:"short",day:"numeric"})} · ${o.count}`:`peak ${a}`})]}),e.jsxs("div",{className:"relative h-28",onMouseLeave:()=>r(null),children:[e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 border-t border-dashed border-border/70"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 border-t border-border"}),e.jsx("div",{className:"absolute inset-0 flex items-end gap-[2px]",children:t.map((i,d)=>{const l=i.count/a*100,x=d===n;return e.jsx("div",{className:"flex h-full min-w-0 flex-1 cursor-default items-end",onMouseEnter:()=>r(d),onFocus:()=>r(d),onBlur:()=>r(null),tabIndex:0,role:"img","aria-label":`${Z(i.day)}: ${i.count} sign-up${i.count===1?"":"s"}`,children:e.jsx("div",{className:h("w-full rounded-t-[3px] transition-colors",i.count===0?"bg-muted-foreground
1/15":x?"bg-violet-500":"bg-violet-500/60",s===d&&"bg-violet-600 dark:bg-violet-400"),style:{height:i.count===0?2:`${Math.max(l,6)}%`}})},i.day)})})]}),t.length>0&&e.jsxs("div",{className:"mt-1.5 flex justify-between text-[11px] tabular-nums text-muted-foreground",children:[e.jsx("span",{children:Z(t[0].day)}),e.jsx("span",{children:Z(t[Math.floor(n/2)].day)}),e.jsx("span",{children:"Today"})]})]})}const hn=new Set(["lifetime","monthly","yearly","paid"]);function fn(t,s,r,a){if(s?.steps.paid||hn.has(t.plan))return{label:"paid",tone:"paid",testId:"signup-dropoff"};if(!r)return null;if(!s||!A(t,a))return{label:"before tracking",tone:"muted",testId:"signup-before-tracking"};if(!s.events)return{label:"no events recorded",tone:"muted",testId:"signup-no-events"};const n=rt(s,a);return n?{label:n,tone:D(s.steps)<=4?"early":"later",testId:"signup-dropoff"}:null}const ze={paid:"border-emerald-500/40 bg-emerald-500/15 font-medium text-emerald-800 dark:text-emerald-200",early:"border-amber-500/40 bg-amber-500/15 font-medium text-amber-900 dark:text-amber-100",later:"border-sky-500/40 bg-sky-500/15 font-medium text-sky-900 dark:text-sky-100",muted:"border-dashed border-border bg-transparent text-muted-foreground"};function gn({data:t,loading:s,relativeTime:r,onSelect:a,activity:n,activityLoaded:o,trackingSince:i,filter:d,onFilter:l,listRef:x}){const u=y.useMemo(()=>tn(t?.recent??[]),[t]),p=d??Fe,b=y.useMemo(()=>{const c={};for(const f of fe){const v={kind:f.kind};c[f.kind]=u.filter(S=>Re(S,n?.get(S.user_id),v,i)).length}return c},[u,n,i]),m=y.useMemo(()=>u.filter(c=>Re(c,n?.get(c.user_id),p,i)),[u,n,p,i]),_=p.kind==="stop"&&p.userIds?p.userIds.filter(c=>!u.some(f=>f.user_id===c)).length:0;return e.jsxs(T,{className:"mb-8 scroll-mt-4 overflow-hidden",ref:x,"data-testid":"admin-signups",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b px-5 py-3.5",children:[e.jsx(be,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-sm font-semibold",children:"Sign-ups"}),t&&e.jsxs("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground",children:[t.total," total"]})]}),s?e.jsxs("div",{className:"space-y-3 p-5",children:[e.jsx("div",{className:"h-12 animate-pulse rounded bg-muted-foreground/10"}),e.jsx("div",{className:"h-28 animate-pulse rounded bg-muted-foreground/10"})]}):t?e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-5",children:[e.jsxs("div",{className:"space-y-5 p-5 lg:col-span-2 lg:border-r",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(ce,{label:"Today",value:t.today}),e.jsx(ce,{label:"7 days",value:t.last_7_days}),e.jsx(ce,{label:"30 days",value:t.last_30_days})]}),e.jsx(xn,{daily:t.daily})]}),e.jsxs("div",{className:"min-w-0 border-t lg:col-span-3 lg:border-t-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 pb-1 pt-3.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Recent sign-ups, newest first"}),e.jsx("span",{className:"tabular-nums","data-testid":"signup-shown",children:m.length===u.length?u.length:`${m.length} of ${u.length}`})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 px-5 pb-2 pt-1",role:"radiogroup","aria-label":"Filter sign-ups","data-testid":"signup-filters",children:[fe.map(c=>{const f=p.kind===c.kind;return e.jsxs("button",{type:"button",role:"radio","aria-checked":f,"data-testid":`signup-filter-${c.kind}`,onClick:()=>l?.({kind:c.kind}),className:h("inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs transition-colors",f?"border-violet-500/50 bg-violet-500/15 font-medium text-foreground":"border-border text-muted-foreground hover:bg-muted hover:text-foreground"),children:[c.label,e.jsx("span",{className:"tabular-nums opacity-70",children:b[c.kind]})]},c.kind)}),p.kind==="stop"&&e.jsxs("button",{type:"button","data-testid":"signup-filter-stop",onClick:()=>l?.(Fe),"aria-label":`${de(p)}. Clear filter`,className:"inline-flex items-center gap-1 rounded-full border border-violet-500/50 bg-violet-500/15 px-2 py-0.5 text-xs font-medium",children:[de(p),e.jsx(Qe,{className:"h-3 w-3"})]})]}),_>0&&e.jsxs("p",{className:"px-5 pb-2 text-[11px] text-muted-foreground","data-testid":"signup-filter-note",children:[_," of them signed up before the ",u.length," newest sign-ups listed here."]}),u.length===0?e.jsx("p",{className:"px-5 py-8 text-center text-sm text-muted-foreground",children:"No one has signed up yet."}):m.length===0?e.jsxs("p",{className:"px-5 py-8 text-center text-sm text-muted-foreground","data-testid":"signup-filter-empty",children:['No sign-ups match "',de(p),'".']}):e.jsx("div",{className:"max-h-[26rem] divide-y overflow-y-auto border-t",children:m.map(c=>
1{const f=n?.get(c.user_id),v=fn(c,f,!!o,i),S=!!o&&v?.tone==="paid"&&(!f||!A(c,i));return e.jsxs("button",{type:"button","data-testid":"signup-row","data-user":c.user_id,onClick:()=>a?.({user_id:c.user_id,email:c.email}),className:"flex w-full items-start gap-3 px-5 py-3 text-left transition-colors hover:bg-muted/50 focus-visible:bg-muted/50 focus-visible:outline-none",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:c.email??"unknown user"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[v&&e.jsx("span",{className:h(F,ze[v.tone]),"data-testid":v.testId,children:v.label}),S&&e.jsx("span",{className:h(F,ze.muted),"data-testid":"signup-before-tracking",children:"before tracking"}),e.jsx("span",{className:h(F,Y),children:mn(f?.method||c.provider)}),e.jsx("span",{className:h(F,Y),children:c.todoist_connected?"Todoist connected":"no Todoist"}),e.jsx("span",{className:h(F,Y),children:pn(c)}),e.jsx("span",{className:h(F,Y),children:c.returned?"came back":"not back yet"})]})]}),e.jsxs("div",{className:"shrink-0 text-right text-xs tabular-nums text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground/80",children:r(c.created_at)}),c.last_seen&&e.jsxs("p",{className:"mt-0.5 text-[11px]",children:["seen ",r(c.last_seen)]})]})]},c.user_id)})})]})]}):e.jsx("p",{className:"px-5 py-8 text-center text-sm text-muted-foreground",children:"No sign-up data."})]})}const J=t=>new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),bn=(t,s)=>t==null?"":`${(t/100).toFixed(2)} ${(s??"").toUpperCase()}`.trim(),qe=(t,s)=>`${t} ${s}${t===1?"":"s"}`,_n={active:"text-emerald-600 dark:text-emerald-400",cancelled:"text-amber-600 dark:text-amber-400",failed:"text-amber-600 dark:text-amber-400",ended:"text-muted-foreground",refunded:"text-destructive",chargebacked:"text-destructive",disputed:"text-destructive"};function X({title:t,rows:s,empty:r,render:a}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:t}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:r}):e.jsx("ul",{className:"divide-y rounded-lg border text-xs",children:s.map(a)})]})}function yn(){const{data:t,isLoading:s,error:r}=M({queryKey:["admin-purchases"],staleTime:6e4,retry:1,queryFn:async()=>{const{data:n,error:o}=await $.rpc("admin_purchases");if(o)throw o.code==="PGRST202"?new Error("admin_purchases() is missing. Apply supabase/migrations/20261001120000_purchases.sql."):o;return n}}),a=t?.totals;return e.jsxs(T,{className:"mb-8 p-4 sm:p-5","data-testid":"admin-purchases",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsx(yt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-base font-semibold",children:"Purchases"}),a&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a.active_lifetime," lifetime · ",qe(a.active_memberships,"membership")," · ",a.last_7_days," in 7 days",a.unclaimed?` · ${a.unclaimed} unclaimed`:"",a.problems_7_days?` · ${qe(a.problems_7_days,"problem")} in 7 days`:""]})]}),r&&e.jsxs("p",{className:"mb-3 flex items-start gap-2 text-sm text-destructive",children:[e.jsx(k,{className:"mt-0.5 h-4 w-4 shrink-0"}),r.message]}),s&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}),t&&e.jsxs("div",{className:"grid grid-cols-1 gap-5 lg:grid-cols-2",children:[e.jsx(X,{title:"Recent purchases",rows:t.recent,empty:"No purchases recorded yet.",render:n=>e.jsxs("li",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5 px-3 py-2",children:[e.jsxs("span",{className:"font-medium",children:[n.product,n.recurrence&&n.product!=="lifetime"?` (${n.recurrence})`:""]}),e.jsx("span",{className:h(_n[n.status]),children:n.status}),n.is_test&&e.jsx("span",{className:"text-muted-foreground",children:"test"}),e.jsx("span",{className:"text-muted-foreground",children:bn(n.price_cents,n.currency)}),e.jsx("span",{className:"ml-auto text-muted-foreground",children:J(n.created_at)}),e.jsxs("span",{className:"w-full truncate text-muted-foreground",children:[n.account_email??"unclaimed",n.buyer_email&&n.buyer_email!==n.account_email?` · paid as ${n.buyer_email}`:"",n.claimed_via?` · via ${n.claimed_via}`:""]})]},n.id)}),e.jsxs("div",{className:"space-y-5",children:[e.jsx(X,{title:"Unclaimed",rows:t.unclaimed,empty:"Every purchase is attached to an account.",render:n=>e.jsxs("li",{className:"flex flex-wrap items-center gap-x-2 px-3 py-2",children:[e.jsx("span",{className:"font-medium",children:n.product}),e.jsx("span",{className:"truncate text-muted-foreground",children:n.buyer_email??"—"}),n.key_last4&&e.jsxs("span",{className:"text-muted-foreground",children:["key …",n.key_last4]}),e.jsx("span",{className:"ml-auto text-muted-foreground",children:J(n.created_at)})]},n.id)}),e.jsx(X,{title:"Pings and activations to look at (30 days)",rows:t.problems,empty:"No failed or unmatched pings.",render:n=>e.jsxs("li",{className:"px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:n.event_type}),e.jsx("span",{className:n.result==="error"||n.result==="rejected"?"text-destructive":"text-amber-600 dar
1k:text-amber-400",children:n.result}),e.jsx("span",{className:"ml-auto text-muted-foreground",children:J(n.received_at)})]}),n.detail&&e.jsx("p",{className:"truncate text-muted-foreground",title:n.detail,children:n.detail})]},n.id)}),e.jsx(X,{title:"Failed license activations (7 days)",rows:t.failed_activations,empty:"None.",render:n=>e.jsxs("li",{className:"flex flex-wrap items-center gap-x-2 px-3 py-2",children:[e.jsx("span",{className:"font-medium",children:n.result??"no result"}),n.key_last4&&e.jsxs("span",{className:"text-muted-foreground",children:["…",n.key_last4]}),e.jsx("span",{className:"truncate text-muted-foreground",children:n.account_email??""}),e.jsx("span",{className:"ml-auto text-muted-foreground",children:J(n.created_at)})]},n.id)})]})]})]})}const ut=.8,O=t=>typeof t=="number"&&Number.isFinite(t)?t:Number(t)||0;function ge(t){const s=O(t?.accepted),r=O(t?.overridden),a=O(t?.ignored),n=s+r,o=n+a;return{shown:o,decided:n,acceptance:n?s/n:null,override:n?r/n:null,ignoredShare:o?a/o:null}}const Ue={do:"Do First",schedule:"Schedule",delegate:"Delegate",backlog:"Backlog"},z=t=>t==null?"—":`${Math.round(t*100)}%`,Nn=t=>[...t??[]].sort((s,r)=>O(r.n)-O(s.n)).map(s=>`${Ue[s.suggested]??s.suggested} → ${Ue[s.final]??s.final}: ${O(s.n)}`),jn=t=>[...t??[]].sort((s,r)=>(Date.parse(r.last_run??"")||0)-(Date.parse(s.last_run??"")||0)).map(s=>({version:s.prompt_version,runs:O(s.runs),rates:ge(s),lastRun:s.last_run})),vn=t=>t.acceptance==null?null:t.acceptance>=ut,wn=t=>t?new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"}):"—";function q({label:t,value:s,sub:r,tone:a,testId:n}){return e.jsxs("div",{className:"min-w-0 rounded-lg border px-3 py-2","data-testid":n,children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("p",{className:h("text-lg font-semibold tabular-nums",a==="good"&&"text-emerald-600 dark:text-emerald-400",a==="bad"&&"text-amber-600 dark:text-amber-400"),children:s}),r&&e.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:r})]})}const ee=t=>{const s=vn(t);return s==null?void 0:s?"good":"bad"};function kn(){const{data:t,isLoading:s,error:r}=M({queryKey:["admin-ai-suggestions"],staleTime:6e4,retry:1,queryFn:async()=>{const{data:d,error:l}=await $.rpc("admin_ai_suggestions");if(l)throw l.code==="PGRST202"?new Error("admin_ai_suggestions() is missing. Apply supabase/migrations/20261002090000_ai_feedback.sql."):l;const x=d;if(!x||typeof x!="object"||Array.isArray(x)||!x.runs)throw new Error("admin_ai_suggestions() returned no data.");const u={accepted:0,overridden:0,ignored:0};return{generated_at:x.generated_at??new Date().toISOString(),runs:{d7:0,d30:0,errors_d7:0,users_d7:0,users_d30:0,...x.runs},outcomes_d7:{...u,...x.outcomes_d7},outcomes_d30:{...u,...x.outcomes_d30},confusions:Array.isArray(x.confusions)?x.confusions:[],by_prompt_version:Array.isArray(x.by_prompt_version)?x.by_prompt_version:[]}}}),a=ge(t?.outcomes_d7),n=ge(t?.outcomes_d30),o=Nn(t?.confusions),i=jn(t?.by_prompt_version);return e.jsxs(T,{className:"mb-8 p-4 sm:p-5","data-testid":"admin-ai-suggestions",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsx(Nt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-base font-semibold",children:"AI suggestions"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Acceptance = accepted ÷ (accepted + overridden). Target ",z(ut),"."]})]}),r&&e.jsxs("p",{className:"mb-3 flex items-start gap-2 text-sm text-destructive",children:[e.jsx(k,{className:"mt-0.5 h-4 w-4 shrink-0"}),r.message]}),s&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}),t&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-6",children:[e.jsx(q,{label:"Runs 7d",value:String(t.runs.d7),sub:`${t.runs.users_d7} users · ${t.runs.errors_d7} failed`,testId:"ai-stat-runs7"}),e.jsx(q,{label:"Runs 30d",value:String(t.runs.d30),sub:`${t.runs.users_d30} users`,testId:"ai-stat-runs30"}),e.jsx(q,{label:"Acceptance 7d",value:z(a.acceptance),sub:`${a.decided}
1 decided`,tone:ee(a),testId:"ai-stat-accept7"}),e.jsx(q,{label:"Acceptance 30d",value:z(n.acceptance),sub:`${n.decided} decided`,tone:ee(n),testId:"ai-stat-accept30"}),e.jsx(q,{label:"Overridden 30d",value:z(n.override),sub:`${t.outcomes_d30.overridden} times`,testId:"ai-stat-override30"}),e.jsx(q,{label:"Ignored 30d",value:z(n.ignoredShare),sub:`${t.outcomes_d30.ignored} of ${n.shown} shown`,testId:"ai-stat-ignored30"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-5 lg:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Top corrections (30 days)"}),o.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No overrides yet."}):e.jsx("ul",{className:"divide-y rounded-lg border text-xs","data-testid":"ai-confusions",children:o.map(d=>e.jsx("li",{className:"px-3 py-2 tabular-nums",children:d},d))})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"By prompt version (90 days)"}),i.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No runs yet."}):e.jsx("div",{className:"overflow-x-auto rounded-lg border",children:e.jsxs("table",{className:"w-full text-xs","data-testid":"ai-versions",children:[e.jsx("thead",{className:"text-left text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 font-medium",children:"Prompt"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Runs"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Acceptance"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Decided"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Last run"})]})}),e.jsx("tbody",{className:"divide-y",children:i.map(d=>e.jsxs("tr",{children:[e.jsx("td",{className:"max-w-[12rem] truncate px-3 py-2 font-mono",children:d.version}),e.jsx("td",{className:"px-3 py-2 tabular-nums",children:d.runs}),e.jsx("td",{className:h("px-3 py-2 tabular-nums",ee(d.rates)==="good"&&"text-emerald-600 dark:text-emerald-400",ee(d.rates)==="bad"&&"text-amber-600 dark:text-amber-400"),children:z(d.rates.acceptance)}),e.jsx("td",{className:"px-3 py-2 tabular-nums",children:d.rates.decided}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground",children:wn(d.lastRun)})]},d.version))})]})})]})]})]})]})}function mt({days:t,onDays:s,testPrefix:r}){return e.jsx("div",{className:"flex gap-1 rounded-lg bg-muted/60 p-1",role:"radiogroup","aria-label":"Window",children:[7,30].map(a=>e.jsxs("button",{type:"button",role:"radio","aria-checked":t===a,"data-testid":`${r}-${a}d`,onClick:()=>s(a),className:h("rounded-md px-2.5 py-1 text-xs font-medium transition-colors",t===a?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[a,"d"]},a))})}function $n({data:t,loading:s,error:r,days:a,onDays:n}){const o=y.useMemo(()=>t?Xs({users:t.users,days:a,trackingSince:t.tracking_since}):[],[t,a]),i=ne(t?.tracking_since);return e.jsxs(T,{className:"mb-6 p-4 sm:p-5","data-testid":"activity-summary",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsx(jt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-base font-semibold",children:"What's happening"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i?`tracked since ${i}`:"product activity"}),e.jsx("div",{className:"ml-auto",children:e.jsx(mt,{days:a,onDays:n,testPrefix:"summary"})})]}),r&&e.jsxs("p",{className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(k,{className:"mt-0.5 h-4 w-4 shrink-0"}),r.message]}),s&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 w-3/4 animate-pulse rounded bg-muted-foreground/10"}),e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-muted-foreground/10"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-muted-foreground/10"})]}),t&&e.jsx("ul",{className:"space-y-1.5 text-sm leading-relaxed","data-testid":"summary-sentences",children:o.map((d,l)=>e.jsxs("li",{className:"flex gap-2","data-testid":"summary-sentence",children:[e.jsx("span",{className:h("mt-2 h-1.5 w-1.5 shrink-0 rounded-full",/^Biggest drop/.test(d)?"bg-amber-500":"bg-violet-500/70"),"aria-hidden":!0}),e.jsx("span",{className:"min-w-0 break-words",children:d})]},l))})]})}const Be=[3,4,5,6,8],Tn={3:"Connected",4:"Saw matrix",5:"Sorted",6:"Came back",8:"Paid"};function He({title:t,rows:s,testId:r}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:t}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No tracked sign-ups in this window."}):e.jsx("div",{className:"overflow-x-auto rounded-lg border",children:e.jsxs("table",{className:"w-full text-xs","data-testid":r,children:[e.jsx("thead",{className:"text-left text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 font-medium",children:"Group"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Sign-ups"}),Be.map(a=>e.jsx("th",{className:"whitespace-nowrap px-3 py-2 text-right font-medium",children:T
1n[a]},a))]})}),e.jsx("tbody",{className:"divide-y",children:s.map(a=>e.jsxs("tr",{children:[e.jsx("td",{className:"max-w-[11rem] truncate px-3 py-2 font-medium",title:a.group,children:a.group}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:a.total}),Be.map(n=>e.jsxs("td",{className:"whitespace-nowrap px-3 py-2 text-right tabular-nums",children:[a.counts[n],a.total?e.jsx("span",{className:"ml-1.5 text-muted-foreground",children:se(a.counts[n]/a.total)}):null]},n))]},a.group))})]})})]})}function Sn({data:t,loading:s,error:r,days:a,onDays:n}){const[o,i]=y.useState(!1),d=!!t?.tracking_since,l=y.useMemo(()=>t&&d?at(t.users,a,Date.now(),t.tracking_since):[],[t,a,d]),x=y.useMemo(()=>nt(l),[l]),u=y.useMemo(()=>it(x),[x]),p=y.useMemo(()=>Ee(l,"method"),[l]),b=y.useMemo(()=>Ee(l,"utm_source"),[l]),m=ne(t?.tracking_since),_=u?u.rate>=.5:!1;return e.jsxs(T,{className:"mb-8 p-4 sm:p-5","data-testid":"admin-activation-funnel",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsx(Ze,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-base font-semibold",children:"Activation funnel"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Sign-ups of the last ",a," days. A step counts only when it was done (prerequisites like Connect are implied by a connection)."]}),e.jsx("div",{className:"ml-auto",children:e.jsx(mt,{days:a,onDays:n,testPrefix:"funnel"})})]}),e.jsxs("p",{className:"mb-4 flex items-start gap-2 rounded-md border border-sky-500/30 bg-sky-500/10 px-3 py-2 text-xs text-sky-900 dark:text-sky-100","data-testid":"funnel-tracking-note",children:[e.jsx($e,{className:"mt-px h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:m?`Counts only sign-ups since tracking started (${m}). Older accounts have no events, so they are not in the funnel.`:"Tracking has not recorded any events yet, so there is no funnel to show."})]}),r&&e.jsxs("p",{className:"mb-3 flex items-start gap-2 text-sm text-destructive",children:[e.jsx(k,{className:"mt-0.5 h-4 w-4 shrink-0"}),r.message]}),s&&e.jsx("div",{className:"h-48 animate-pulse rounded bg-muted-foreground/10"}),t&&d&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:"People who did the step · % of sign-ups · (% of those at the step before who did it)"}),e.jsxs("button",{type:"button",onClick:()=>i(c=>!c),"aria-expanded":o,"data-testid":"funnel-explain",className:"inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 font-medium text-foreground/80 hover:bg-muted hover:text-foreground",children:[e.jsx($e,{className:"h-3 w-3"}),o?"Hide what the steps mean":"What the steps mean"]})]}),e.jsx("ol",{className:"space-y-1","data-testid":"funnel-steps",children:x.map((c,f)=>{const v=u?.index===f;return e.jsxs("li",{"data-testid":`funnel-step-${c.key}`,"data-biggest-drop":v?"true":void 0,title:he[c.key],className:h("rounded-md border-l-[3px] px-2 py-1",v?_?"border-l-red-500 bg-red-500/10":"border-l-amber-500 bg-amber-500/10":"border-l-transparent"),children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 text-sm sm:grid-cols-[12rem_minmax(0,1fr)_9.5rem]",children:[e.jsxs("span",{className:"min-w-0 truncate text-xs sm:text-sm",children:[e.jsxs("span",{className:"mr-1.5 tabular-nums text-muted-foreground",children:[f+1,"."]}),c.label]}),e.jsx("span",{className:"order-last col-span-2 sm:order-none sm:col-span-1",children:e.jsx("span",{className:"relative block h-2.5 min-w-0 overflow-hidden rounded bg-muted/60 sm:h-5",children:e.jsx("span",{className:h("block h-full rounded",v?_?"bg-red-500/70":"bg-amber-500/80":f===w.length-1?"bg-emerald-500/80":"bg-violet-500/70"),style:{width:`${Math.max(c.count?2:0,(c.ofStart??0)*100)}%`}})})}),e.jsxs("span",{className:"whitespace-nowrap text-right text-xs tabular-nums",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground","data-testid":"funnel-count",children:c.count}),e.jsx("span",{className:"ml-1.5 text-muted-foreground",children:se(c.ofStart)}),f>0&&e.jsxs("span",{className:"ml-1 text-muted-foreground",title:"of the step before",children:["(",se(c.ofPrev),")"]})]})]}),c.skipped>0&&e.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground","data-testid":"funnel-skipped",children:["incl. ",c.skipped," who skipped “",w[f
1-1].label,"”"]}),v&&u&&e.jsxs("p",{className:h("mt-1 flex flex-wrap items-center gap-1.5 text-xs",_?"text-red-700 dark:text-red-300":"text-amber-800 dark:text-amber-200"),children:[e.jsxs("span",{"data-testid":"funnel-biggest-drop",className:h("inline-flex items-center gap-1 rounded-full border px-1.5 py-px text-[11px] font-semibold uppercase tracking-wide",_?"border-red-500/40 bg-red-500/15":"border-amber-500/40 bg-amber-500/15"),children:[e.jsx(vt,{className:"h-3 w-3"}),"biggest drop"]}),e.jsxs("span",{children:[u.lost," of ",u.from," ",u.phrase," (",Math.round(u.rate*100),"%)"]})]}),o&&e.jsx("p",{className:"mt-0.5 text-[11px] leading-snug text-muted-foreground","data-testid":"funnel-step-meaning",children:he[c.key]})]},c.key)})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-5",children:[e.jsx(He,{title:"By sign-up method",rows:p,testId:"funnel-by-method"}),e.jsx(He,{title:"By source (utm_source, else referrer)",rows:b,testId:"funnel-by-source"})]})]})]})}const pt="supabase/migrations/20261003090000_app_events.sql",Cn="supabase/migrations/20261004090000_admin_activation_timing.sql";function xt(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function ye(t,s){return t.code==="PGRST202"||new RegExp(s).test(t.message??"")&&/not find|does not exist/i.test(t.message??"")}const Ne=t=>Array.isArray(t)?t:[];function An(t){return M({queryKey:["admin-activation"],enabled:t,staleTime:6e4,refetchInterval:12e4,retry:1,queryFn:async()=>{const{data:s,error:r}=await $.rpc("admin_activation",{p_days:90,p_tz:xt()});if(r)throw ye(r,"admin_activation")?new Error(`admin_activation() is missing. Apply ${pt}.`):r;const a=s??{};return{generated_at:a.generated_at??new Date().toISOString(),tz:a.tz??"UTC",days:a.days??90,tracking_since:a.tracking_since??null,users:Ne(a.users).map(n=>({...n,steps:n.steps??{}}))}}})}function In(t){return M({queryKey:["admin-user-activity",t],enabled:!!t,staleTime:3e4,retry:1,queryFn:async()=>{const{data:s,error:r}=await $.rpc("admin_user_activity",{p_user_id:t,p_tz:xt(),p_limit:1e3});if(r)throw ye(r,"admin_user_activity")?new Error(`admin_user_activity() is missing. Apply ${pt}.`):r;const a=s??{};return{generated_at:a.generated_at??new Date().toISOString(),tz:a.tz??"UTC",user:a.user?{...a.user,steps:a.user.steps??{}}:null,events:Ne(a.events)}}})}class Ge extends Error{}function Dn(t){return M({queryKey:["admin-activation-timing"],enabled:t,staleTime:6e4,refetchInterval:3e5,retry:(s,r)=>!(r instanceof Ge)&&s<1,queryFn:async()=>{const{data:s,error:r}=await $.rpc("admin_activation_timing",{p_days:90});if(r)throw ye(r,"admin_activation_timing")?new Ge(`admin_activation_timing() is missing. Apply ${Cn}.`):r;const a=s??{};return{generated_at:a.generated_at??new Date().toISOString(),days:a.days??90,users:Ne(a.users)}}})}const Mn={app_opened:Jt,signed_up:be,signed_in:me,connect_todoist_viewed:Yt,connect_todoist_clicked:Zt,connect_todoist_result:Qt,matrix_viewed:Vt,categorize_opened:Kt,task_categorized:Wt,ai_suggest_run:ue,ai_consent:Gt,task_added:Ht,task_completed:Ve,task_deleted:Bt,task_delete_undone:Ut,follow_up_created:qt,focus_started:zt,focus_ended:Ft,daily_review_opened:Pt,stats_opened:Lt,filters_used:Ze,settings_opened:Rt,tour_started:Ot,tour_completed:Et,tour_skipped:Mt,plans_viewed:oe,checkout_started:oe,checkout_result:oe,license_dialog_opened:Dt,license_activated:It,logged_out:At,session_active:Ct,starter_card:St,view_changed:Tt,task_opened:$t,due_changed:kt,error_shown:wt},le={done:"done",skipped:"skipped (a later step was done, this one never was)",not_done:"not done",unknown:"unknown (no events)"},En={good:"text-emerald-600 dark:text-emerald-400",bad:"text-amber-600 dark:text-amber-400",key:"text-violet-600 dark:text-violet-400",none:"text-muted-foreground"},H=t=>new Date(t).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),On=t=>{const[s,r,a]=t.split("-").map(Number);return new Date(s,r-1,a).toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric",year:"numeric"})};function C({label:t,value:s,testId:r,tone:a}){return e.jsxs("div",{className:"min-w-0 rounded-lg border px-3 py-2","data-testid":r,children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("p",{className:h("truncate text-sm font-medium",a==="good"&&"text-emerald-700 dark:text-emerald-300",a==="bad"&&"text-amber-700 dark:text-amber-300"),title:s,children:s})]})}function Rn(t){const s=[t.utm_source,t.utm_campaign&&`campaign ${t.utm_campaign}`,t.ref&&`via ${t.ref}
1`].filter(Boolean);return s.length?s.join(" · "):"direct / unknown"}const Ln=t=>t==="google"?"Google":t==="todoist"?"Todoist":t==="email"?"Email":t||"unknown",We={done:"bg-violet-500",skipped:"bg-amber-500/25 ring-1 ring-inset ring-amber-500/70",not_done:"bg-muted-foreground/20",unknown:"border border-dashed border-muted-foreground/50 bg-transparent"};function Pn({u:t,trackingSince:s}){const r=ot(t,s),a=D(t.steps),n=r.includes("unknown"),o=w.filter((i,d)=>r[d]==="skipped");return e.jsxs("div",{children:[e.jsx("ol",{className:"flex gap-1","aria-label":"Activation steps","data-testid":"drawer-steps",children:w.map((i,d)=>{const l=r[d];return e.jsxs("li",{title:`${d+1}. ${i.label}: ${le[l]}. ${he[i.key]}`,"data-state":l,className:h("group relative h-2.5 flex-1 rounded-full",l==="done"&&d===8?"bg-emerald-500":We[l]),children:[e.jsxs("span",{className:"sr-only",children:[i.label,": ",le[l]]}),e.jsxs("span",{className:h("pointer-events-none absolute bottom-full z-10 mb-1.5 hidden w-max max-w-[11rem] rounded-md border bg-popover px-2 py-1 text-[11px] text-popover-foreground shadow-md group-hover:block",d<2?"left-0":d>6?"right-0":"left-1/2 -translate-x-1/2"),"aria-hidden":!0,children:[i.label," · ",le[l]]})]},i.key)})}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:[e.jsxs("span",{"data-testid":"drawer-furthest",children:["Furthest: ",e.jsx("span",{className:"font-medium text-foreground",children:w[a].label}),o.length>0&&e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" (skipped: ",o.map(i=>i.label).join(", "),")"]})]}),e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1",children:[e.jsx("span",{className:"h-2 w-3 rounded-full bg-violet-500"})," done"]}),o.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:h("h-2 w-3 rounded-full",We.skipped)})," skipped"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"h-2 w-3 rounded-full bg-muted-foreground/20"})," not done"]}),n&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"h-2 w-3 rounded-full border border-dashed border-muted-foreground/50"})," unknown"]})]})]})}function Fn({u:t,relativeTime:s,trackingSince:r,events:a}){const n=D(t.steps),o=rt(t,r),i=A(t,r),d=ln(a),l=ot(t,r).filter(u=>u==="skipped").length,x=lt(a);return e.jsxs("div",{className:"space-y-3","data-testid":"drawer-summary",children:[e.jsx("p",{className:h("rounded-lg border px-3 py-2.5 text-sm leading-relaxed",i?"border-violet-500/30 bg-violet-500/5":"border-dashed bg-muted/30 text-muted-foreground"),"data-testid":"drawer-verdict",children:rn(t,r,s)}),d&&e.jsx("p",{className:"rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-sm leading-relaxed text-amber-900 dark:text-amber-100","data-testid":"drawer-stalled",children:d}),e.jsx(Pn,{u:t,trackingSince:r}),e.jsx(C,{label:"Source",value:Rn(t),testId:"fact-source"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(C,{label:"Signed up with",value:Ln(t.method),testId:"fact-method"}),e.jsx(C,{label:"Todoist",value:t.todoist_connected?"Connected":"Not connected",tone:t.todoist_connected?"good":"bad",testId:"fact-todoist"}),e.jsx(C,{label:"Plan",value:t.plan||"—",testId:"fact-plan"}),e.jsx(C,{label:"Last seen",value:t.last_seen?s(t.last_seen):"—",testId:"fact-last-seen"}),e.jsx(C,{label:i?"Furthest step":"Furthest known step",value:l?`${w[n].label} (${l} skipped)`:w[n].label,tone:l?"bad":void 0,testId:"fact-furthest"}),e.jsx(C,{label:"Events (90 days)",value:String(t.events??0),testId:"fact-events"}),e.jsx(C,{label:"Active time (90 days)",value:x.activeKnown?G(x.activeSeconds).replace(/ active$/,""):"not recorded",testId:"fact-active"}),e.jsx(C,{label:"Actions (90 days)",value:String(x.actions),testId:"fact-actions"})]}),o&&o!=="paid"&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Drop-off: ",e.jsx("span",{className:"font-medium text-foreground",children:o})]})]})}function zn({user:t,onClose:s,relativeTime:r,trackingSince:a}){const n=ds(),{data:o,isLoading:i,error:d}=In(t?.user_id??null),l=o?Cs(o.events):[],x=l.reduce((p,b)=>p+b.count,0),u=o?.user??null;return e.jsx(cs,{open:!!t,onOpenChange:p=>!p&&s(),children:e.jsxs(ls,{side:n?"bottom":"right","data-testid":"admin-user-drawer",className:h("flex flex-col gap-0 p-0 [&>button]:hidden",n?"h-[92dvh] rounded-t-2xl":"w-full sm:max-w-xl"),children:[e.jsxs("div",{className:"flex items-start gap-3 border-b px-5 py-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(us,{className:"truncate text-base","data-testid":"drawer-email",children:t?.email??u?.email??"unknown user"}),e.jsx(ms,{className:"text-xs",children:u?`Signed up ${new Date(u.created_at).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})} · ${r(u.created_at)}`:"Activity, newest first"})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close",className:"-mr-1 rounded-md p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground",children:e.jsx(Qe,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto overscroll-contain px-5 py-4",children:[d&&e.jsxs("p",{className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(k,{className:"mt-0.5 h-4 w-4 shrink-0"}),d.message]}),i&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-24 animate-pulse rounded bg-muted-foreground
1/10"}),e.jsx("div",{className:"h-48 animate-pulse rounded bg-muted-foreground/10"})]}),u&&e.jsx(Fn,{u,relativeTime:r,trackingSince:a??null,events:o?.events??[]}),o&&e.jsxs("div",{"data-testid":"drawer-timeline",children:[e.jsxs("div",{className:"mb-2 flex items-baseline justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Timeline"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[x," event",x===1?"":"s"," · 90 days kept"]})]}),l.length===0?e.jsxs("p",{className:"rounded-lg border border-dashed px-4 py-6 text-center text-sm text-muted-foreground",children:["No activity recorded yet. Tracking started on ",ne(a)??"Oct 1",", so anything this account did before then (or before this version reached their browser) isn't here."]}):e.jsx("div",{className:"space-y-4",children:l.map(p=>e.jsxs("section",{"data-testid":"timeline-day",children:[e.jsxs("h4",{className:"mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[On(p.day)," · ",p.count]}),e.jsx("div",{className:"space-y-2",children:p.sessions.map(b=>e.jsxs("div",{className:"rounded-lg border","data-testid":"timeline-session",children:[e.jsxs("p",{className:"border-b bg-muted/30 px-3 py-1.5 text-[11px] tabular-nums text-muted-foreground",children:["Session ",H(b.start),b.start!==b.end?`–${H(b.end)}`:""," · ",b.events.length," event",b.events.length===1?"":"s",b.activeSeconds>0&&e.jsxs("span",{"data-testid":"session-active",children:[" · ",G(b.activeSeconds)]})]}),e.jsx("ol",{className:"divide-y",children:Is(b.events).map(m=>{const _=m.event,c=Mn[_.name]??Xt;return e.jsxs("li",{className:"flex items-start gap-2.5 px-3 py-2 text-sm","data-testid":"timeline-event","data-event":_.name,"data-count":m.count,children:[e.jsx("span",{className:"w-16 shrink-0 whitespace-nowrap pt-px text-xs tabular-nums text-muted-foreground",title:m.count>1?`${H(m.first)} to ${H(_.created_at)}`:void 0,children:H(_.created_at)}),e.jsx(c,{className:h("mt-0.5 h-3.5 w-3.5 shrink-0",En[Ns(_)??"none"]),"aria-hidden":!0}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:h("font-medium",m.count>1&&"text-foreground/80"),children:Ms(m)}),m.detail&&e.jsx("span",{className:"block break-words text-xs text-muted-foreground",children:m.detail})]})]},_.id)})})]},b.start+b.end))})]},p.day))}),e.jsx("p",{className:"mt-4 text-[11px] text-muted-foreground",children:"Product events only: no task titles, notes, projects or labels are recorded."})]})]})]})})}function qn({data:t,days:s,timing:r,timingLoading:a,timingError:n,onShowUsers:o}){const i=t?.tracking_since??null,d=y.useMemo(()=>t&&i?at(t.users,s,Date.now(),i):[],[t,s,i]),l=y.useMemo(()=>Vs(d,i),[d,i]),x=l.reduce((m,_)=>m+_.count,0),u=l.reduce((m,_)=>_.index<l.length-1&&_.count>(m?.count??0)?_:m,null),p=y.useMemo(()=>r?Ys(d,r):null,[d,r]),b=ne(i);return t?e.jsxs(T,{className:"mb-8 overflow-hidden","data-testid":"admin-stop-points",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b px-4 py-3.5 sm:px-5",children:[e.jsx(es,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-sm font-semibold",children:"Where people stop"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["tracked sign-ups of the last ",s," days",b?` (since ${b})`:""," · furthest step reached"]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-5",children:[e.jsxs("div",{className:"min-w-0 p-4 sm:p-5 lg:col-span-3 lg:border-r",children:[x===0?e.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"stop-empty",children:i?"No tracked sign-ups in this window.":"Nothing tracked yet."}):e.jsx("div",{className:"overflow-x-auto rounded-lg border",children:e.jsxs("table",{className:"w-full text-xs","data-testid":"stop-table",children:[e.jsx("thead",{className:"text-left text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 font-medium",children:"Stopped at"}),e.jsx("th",{className:"px-2 py-2 text-right font-medium sm:px-3",children:"People"}),e.jsx("th",{className:"hidden px-3 py-2 text-right font-medium sm:table-cell",children:"Share"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:e.jsx("span",{className:"sr-only",children:"Show"})})]})}),e.jsx("tbody",{className:"divide-y",children:l.map(m=>{const _=m.index===l.length-1,c=u?.index===m.index&&m.count>0;return e.jsxs("tr",{"data-testid":`stop-row-${m.key}`,className:h(c&&"bg-amber-500/10"),children:[e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("span",{className:h("font-medium",m.count===0&&"text-muted-foreground"),children:_?"Paid (finished)":m.label}),c&&e.jsx("span",{className:"mt-0.5 block w-fit whitespace-nowrap rounded-full border sm:ml-1.5 sm:mt-0 sm:inline border-amber-500/40 bg-amber-500/15 px-1.5 py-px text-[10px] font-semibold uppercase tracking-wide text-amber-800 dark:text-amber-200",children:"most stop here"})]}),e.jsx("td",{className:"px-3 py-2 text-right font-semibold tabular-nums","data-testid":"stop-count",children:m.count}),e.jsx("td",{className:"hidden px-3 py-2 text-right tabular-nums text-muted-foreground sm:table-cell",children:se(m.share)}),e.jsx("td",{className:"whitespace-nowrap px-3 py-2 text-right",children:m.count>0?e.jsxs("button",{type:"button","data-testid":`stop-show-${m.key}`,onClick:()=>o(m.index,m.userIds),className:"inline-flex items-center gap-0.5 rounded px-1 font-medium text-violet-700 underline-offset-2 hover:underline dark:text-violet-300",children:["Show ",m.count,e.jsx(ts,{className:"h-3 w-3 -rotate-90"})]}):null})]},m.key)})})]})}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:"Each tracked person is counted once, at the furthest step they reached. Accounts from before tracking are left out."})]}),e.jsxs("div",{className:"min-w-0 border-t p-4 sm:p-5 lg:col-span-2 lg:border-t-0","data-testid":"time-to-step",children:[e.jsxs("h3",{className:"mb-2 flex items-center gap-1.5 text-sm font-medium",children:[e.jsx(Ye,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Time to each step"]}),n?e.jsxs("p",{className:"flex items-start gap-2 text-xs text-muted-foreground","data-testid":"time-to-step-missing",children:[e.jsx(k,{className:"mt-px h-3.5 w-3.5 shrink-0 text-amber-500"}),n.message]}):a||!p?e.jsx("div",{className:"h-20 animate-pulse rounded bg-muted-foreground
1/10"}):e.jsx("ul",{className:"space-y-2",children:p.map(m=>e.jsxs("li",{className:"rounded-lg border px-3 py-2","data-testid":`time-${m.key}`,title:m.note,children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 text-xs",children:m.label}),e.jsx("span",{className:"shrink-0 text-sm font-semibold tabular-nums","data-testid":"time-median",children:m.medianMinutes==null?"—":Js(m.medianMinutes)})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:m.medianMinutes==null?`not enough data (n=${m.n}; needs ${dt})`:`median of ${m.n} people`})]},m.key))}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:"From sign-up to the first time each step was recorded."})]})]})]}):null}function Ke(t){if(!t)return"—";const s=Date.now()-new Date(t).getTime(),r=Math.max(0,Math.round(s/6e4));if(r<1)return"just now";if(r<60)return`${r}m ago`;const a=Math.round(r/60);return a<24?`${a}h ago`:`${Math.round(a/24)}d ago`}function Un(t){return t==null?"—":t<1?"now":t<60?`${Math.floor(t)}m ago`:`${Math.round(t/60)}h ago`}function Bn(t){return t?new Date(t).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",month:"short",day:"numeric"}):""}function Hn(t){return new Date(t).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}const Gn=y.memo(()=>{const t=ss(),{session:s,isLoading:r}=os.useSessionContext(),a=s?.user?.email??null,n=ps(a);y.useEffect(()=>{r||(!s||!n)&&t("/",{replace:!0})},[r,s,n,t]);const{data:o,isLoading:i,isFetching:d,error:l,refetch:x}=_s(n),u=An(n),p=Dn(n),[b,m]=y.useState(null),_=y.useCallback(g=>m({user_id:g.key,email:g.email}),[]),c=y.useMemo(()=>{const g=new Map;for(const I of u.data?.users??[])g.set(I.user_id,I);return g},[u.data]),[f,v]=y.useState(30),[S,L]=y.useState({kind:"all"}),E=y.useRef(null),W=y.useCallback((g,I)=>{L({kind:"stop",step:g,userIds:I}),requestAnimationFrame(()=>E.current?.scrollIntoView({behavior:"smooth",block:"start"}))},[]);if(r||!s||!n)return null;const P=!!o?.honest,N=g=>`${g} action${g===1?"":"s"}`,j=g=>{const I=g.minutes_since_active??g.minutes_since_seen,ft=P?[G(g.active_seconds_today??0),N(g.product_actions_today??0),(g.honest_sessions??0)>1?`${g.honest_sessions} tabs`:null]:[g.first_seen_today?`${g.logged_in_today?"signed in":"since"} ${Hn(g.first_seen_today)}`:null,g.actions_today>0?N(g.actions_today):null,g.open_sessions>1?`${g.open_sessions} tabs`:null],gt=P?!!g.online_now:I<pe;return{key:g.user_id,email:g.email,meta:Un(I),sub:ft.filter(Boolean).join(" · ")||void 0,dot:gt?"green":I<Je?"amber":"muted"}},ae=(o?.online??[]).map(j),je=(o?.lastHour??[]).map(j),ve=(o?.didSomething??[]).map(j),we=(o?.onlyOpened??[]).map(j),ht=o?.adminsOnline??0,re=(o?.prioritizedToday??[]).map(g=>({key:g.user_id,email:g.email,meta:`${g.task_count} task${g.task_count===1?"":"s"}`,sub:`last ${Bn(g.last_prioritized_at)}`,dot:"amber"})),ke=(o?.actionsByType??[]).map(g=>`${g.type.replace(/_/g," ")} ${g.count}`).join(" · ");return e.jsxs(xs.div,{initial:{opacity:0}
1,animate:{opacity:1},transition:{duration:.3},className:"min-h-screen bg-background",children:[e.jsxs("div",{className:"mx-auto max-w-6xl px-4 py-8 sm:px-6",children:[e.jsxs("div",{className:"mb-8 flex flex-wrap items-center gap-3",children:[e.jsxs(Se,{variant:"ghost",size:"sm",onClick:()=>t("/"),className:"gap-1.5",children:[e.jsx(ns,{className:"h-4 w-4"}),"Matrix"]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl font-semibold leading-tight",children:"Admin Dashboard"}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:["Signed in as ",a,o?` · days in ${o.tz}`:""]})]}),e.jsxs(Se,{variant:"outline",size:"sm",onClick:()=>{x(),u.refetch(),p.refetch()},disabled:d,className:"ml-auto gap-1.5",children:[e.jsx(as,{className:d?"h-4 w-4 animate-spin":"h-4 w-4"}),"Refresh"]})]}),l&&e.jsxs("div",{className:"mb-6 flex items-start gap-2 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive",children:[e.jsx(k,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Couldn't load dashboard data."}),e.jsx("p",{className:"text-destructive/80",children:l.message})]})]}),e.jsxs("div",{className:"mb-8 grid grid-cols-2 gap-3 sm:gap-4 lg:grid-cols-4",children:[e.jsx(K,{label:"Online now",value:ae.length,hint:o?`${je.length+ae.length} in the last hour${ht?" · admins not counted":""}`:`using the app in the last ${pe} min`,icon:Te,accent:"emerald",loading:i}),e.jsx(K,{label:"Active today",value:ve.length,hint:o?`did something · ${we.length} only opened · ${N(o.productActionsToday)}`:"people who used the app since midnight",icon:me,accent:"blue",loading:i}),e.jsx(K,{label:"Sign-ups today",value:o?.signups?.today??0,hint:o?.signups?`${o.signups.last_7_days} in 7 days · ${o.signups.last_30_days} in 30`:"new accounts",icon:be,accent:"violet",loading:i}),e.jsx(K,{label:"Prioritized today",value:o?.prioritizedTasksToday??0,hint:o?`${re.length} user${re.length===1?"":"s"} since midnight`:"tasks auto-prioritized",icon:ue,accent:"amber",loading:i})]}),ke&&e.jsxs("div",{className:"mb-8 flex items-start gap-2 rounded-lg border bg-muted/30 px-4 py-3 text-xs text-muted-foreground",children:[e.jsx(Te,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsxs("p",{className:"leading-relaxed",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Today's actions:"})," ",ke]})]}),o&&!P&&e.jsxs("p",{className:"mb-3 text-xs text-muted-foreground","data-testid":"presence-missing",children:["Online and active lists still count open background tabs. Run ",hs," to see only people who are using the app."]}),e.jsxs("div",{className:"mb-8 grid grid-cols-1 gap-4 lg:grid-cols-3",children:[e.jsx(V,{title:"Online now",icon:rs,rows:ae,note:"Tab open and used in the last 5 minutes.",testId:"list-online",emptyText:"No one is using the app right now.",loading:i,onSelect:_}),e.jsx(V,{title:"Active in the last hour",icon:Ye,rows:je,testId:"list-last-hour",emptyText:"No one else in the last hour.",loading:i,onSelect:_}),e.jsx(V,{title:"Active today",icon:me,note:"Time with the tab open and in use, and product actions.",testId:"list-active-today",sections:[{title:"Did something",rows:ve,emptyText:"No one has sorted, added or completed anything today.",testId:"active-did"},{title:"Only opened",rows:we,emptyText:"No one opened the app without doing something.",testId:"active-opened"}],emptyText:"No one has used the app today yet.",loading:i,onSelect:_})]}),e.jsx($n,{data:u.data,loading:u.isLoading,error:u.error,days:f,onDays:v}),e.jsx(gn,{data:o?.signups,loading:i,relativeTime:Ke,onSelect:m,activity:c,activityLoaded:!!u.data,trackingSince:u.data?.tracking_since??null,filter:S,onFilter:L,listRef:E}),e.jsx(Sn,{data:u.data,loading:u.isLoading,error:u.error,days:f,onDays:v}),e.jsx(qn,{data:u.data,days:f,timing:p.data?.users,timingLoading:p.isLoading,timingError:p.error,onShowUsers:W}),e.jsx(yn,{}),e.jsx(kn,{}),e.jsx("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-3",children:e.jsx(V,{title:"Prioritized today",icon:ue,rows:re,emptyText:"No tasks were prioritized today.",loading:i,onSelect:_})}),e.jsx(Ps,{}),e.jsx(Hs,{})]}),e.jsx(zn,{user:b,onClose:()=>m(null),relativeTime:Ke,trackingSince:u.data?.tracking_since??null})]})});Gn.displayName="Admin";export{Gn 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.