1import{r as x,j as e,m as ge}from"./animation-CddyXVCz.js";import{P as ae}from"./PageWrapper-C3-XQErc.js";import{s as K,p as _e,F as Le,h as S,E as H,B as M,a9 as Q,S as ne,U as Re,a5 as Me,q as Ie,af as Ee,aP as de,x as ie,Y as qe,u as Z,y as Ae,aH as De,r as Pe,a3 as Fe}from"./index-DnWsV7cE.js";import{T as be}from"./Tooltip-DaQZLjbJ.js";import{c as Oe}from"./clipboard-C0L7pyCw.js";import"./react-vendor-CbN3pvl2.js";import"./billingLimits-4ln6JCGI.js";import"./supabase-iKSPld20.js";import"./docgen-Bp8WKBAE.js";import"./query-DPqpbKNH.js";async function Be(t=30){var n;if(!K)throw new Error("Auth not available");const c=((n=(await K.auth.getSession()).data.session)==null?void 0:n.access_token)||"",l=await fetch(`/api/admin/founder/metrics?windowDays=${encodeURIComponent(String(t))}`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`}});if(!l.ok){const u=await l.json().catch(()=>null);throw new Error((u==null?void 0:u.error)||`HTTP ${l.status}`)}return l.json()}async function X(){var i;return K?((i=(await K.auth.getSession()).data.session)==null?void 0:i.access_token)??"":""}async function Ge(t){const i=await X(),c=new URLSearchParams;t.search&&c.set("search",t.search),t.tier&&c.set("tier",t.tier),c.set("limit",String(t.limit)),t.offset!=null&&c.set("offset",String(t.offset));const l=await fetch(`/api/admin/users?${c.toString()}`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}});if(!l.ok){const n=await l.json().catch(()=>({}));throw new Error((n==null?void 0:n.error)??`HTTP ${l.status}`)}return l.json()}async function ze(t,i){const c=await X(),l=await fetch(`/api/admin/users/${encodeURIComponent(t)}/grant-pro`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify(i)});if(!l.ok){const n=await l.json().catch(()=>({}));throw new Error((n==null?void 0:n.error)??`HTTP ${l.status}`)}return l.json()}async function We(t,i){const c=await X(),l=await fetch(`/api/admin/users/${encodeURIComponent(t)}/revoke-pro`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify({note:i??null})});if(!l.ok){const n=await l.json().catch(()=>({}));throw new Error((n==null?void 0:n.error)??`HTTP ${l.status}`)}return l.json()}async function He(t=50,i=0){const c=await X(),l=await fetch(`/api/admin/audit-log?limit=${t}&offset=${i}`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`}});if(!l.ok){const n=await l.json().catch(()=>({}));throw new Error((n==null?void 0:n.error)??`HTTP ${l.status}`)}return l.json()}const Ve=[{label:"24h",days:1},{label:"7d",days:7},{label:"14d",days:14},{label:"30d",days:30}],Je={tailor:"Resume Tailoring",tailor_stream:"Resume Tailoring (Stream)",cover_letter:"Cover Letter",chat:"Chat with Resume",embedding:"Embeddings",job_search:"Job Search",autocomplete:"Location Autocomplete"},Ke={429:"Rate Limited",500:"Internal Server Error",503:"Service Unavailable",401:"Unauthorized",403:"Forbidden"},Qe={gemini:"Gemini",jsearch:"JSearch",maps:"Maps"},Ye={sky:"from-sky-500/18 via-white to-white text-sky-600 dark:from-sky-500/14 dark:via-slate-900 dark:to-slate-900 dark:text-sky-300",emerald:"from-emerald-500/18 via-white to-white text-emerald-600 dark:from-emerald-500/14 dark:via-slate-900 dark:to-slate-900 dark:text-emerald-300",amber:"from-amber-500/18 via-white to-white text-amber-600 dark:from-amber-500/14 dark:via-slate-900 dark:to-slate-900 dark:text-amber-300",rose:"from-rose-500/18 via-white to-white text-rose-600 dar
1k:from-rose-500/14 dark:via-slate-900 dark:to-slate-900 dark:text-rose-300",violet:"from-violet-500/18 via-white to-white text-violet-600 dark:from-violet-500/14 dark:via-slate-900 dark:to-slate-900 dark:text-violet-300"},o=t=>new Intl.NumberFormat("en-US").format(t),z=t=>new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:1}).format(t),w=t=>`${t.toFixed(t>=100?0:1)}%`,T=t=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:2}).format(t),re=t=>new Date(`${t}T00:00:00`).toLocaleDateString("en-US",{month:"short",day:"numeric"}),G=t=>new Date(t).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),Ze=t=>t?t<60?`${Math.round(t)}s`:`${Math.round(t/60)}m`:"0s",Xe=t=>`${t.slice(0,8)}...${t.slice(-4)}`,O=()=>new Date().toISOString().slice(0,10),es=t=>`${Math.abs(t).toFixed(Math.abs(t)>=100?0:1)}%`,xe=t=>/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t,B=(t,i,c)=>{const l=[i.map(xe).join(","),...c.map(j=>j.map(xe).join(","))].join(` 2`),n=new Blob([l],{type:"text/csv;charset=utf-8"}),u=window.URL.createObjectURL(n),f=document.createElement("a");f.href=u,f.download=t,f.click(),window.URL.revokeObjectURL(u)},me=t=>Je[t]??t,ue=t=>Ke[t]??t,pe=t=>Qe[t]??t,ss=t=>t<500?"bg-emerald-500":t<=2e3?"bg-amber-500":"bg-rose-500",V=t=>e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full bg-[var(--bg-secondary)] px-2.5 py-1 text-xs font-semibold text-[var(--text-primary)]",children:[e.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${ss(t)}`}),Math.round(t),"ms"]}),ts=(t,i)=>
2t?"text-emerald-600 dark:text-emerald-300":"text-rose-600 dark:text-rose-300",as=(t,i,c=!1,l=o)=>{if(typeof t!="number"||typeof i!="number"||!Number.isFinite(t)||!Number.isFinite(i))return null;if(i<=0)return{label:"â",className:"text-slate-500 dark:text-slate-400"};const n=(t-i)/i*100;if(Math.abs(n)<.01)return{label:`â 0% vs ${l(i)} last period`,className:"text-slate-500 dark:text-slate-400"};const u=c?n<0:n>0;return{label:`${n>0?"â":"â"} ${es(n)} vs ${l(i)} last period`,className:ts(u)}},rs=(t,i)=>{if(!t)return"Updated just now";const c=Math.max(0,Math.floor((i.getTime()-t.getTime())/6e4));if(c<1)return"Updated just now";if(c===1)return"Updated 1 min ago";if(c<60)return`Updated ${c} min ago`;const l=Math.floor(c/60);if(l===1)return"Updated 1 hr ago";if(l<24)return`Updated ${l} hrs ago`;const n=Math.floor(l/24);return n===1?"Updated 1 day ago":`Updated ${n} days ago`},P=({eyebrow:t,title:i,description:c,onExport:l,exportLabel:n="Export CSV"})=>e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.24em] text-[var(--text-secondary)]",children:t}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-[var(--text-primary)]",children:i}),e.jsx("p",{className:"mt-1 text-sm text-[var(--text-secondary)]",children:c})]})]}),l?e.jsx(M,{variant:"outline",size:"sm",className:"shrink-0",leftIcon:e.jsx(De,{className:"h-4 w-4"}),onClick:l,children:n}):null]}),q=({label:t,value:i,detail:c,icon:l,tone:n,currentValue:u,previousValue:f,inverseTrend:j=!1,trendFormatter:m=o,title:U})=>{const C=as(u,f,j,m);return e.jsx(ge.div,{initial:{opacity:0,y:14},animate:{opacity:1,y:0},transition:{duration:.28},title:U,children:e.jsx(S,{variant:"glass",className:`bg-gradient-to-br ${Ye[n]}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-[var(--text-secondary)]",children:t}),e.jsx("div",{className:"mt-3 text-3xl font-bold text-[var(--text-primary)]",children:i}),C?e.jsx("p",{className:`mt-2 text-xs font-semibold ${C.className}`,children:C.label}):null,e.jsx("div",{className:"mt-2 text-sm text-[var(--text-secondary)]",children:c})]}),e.jsx("div",{className:"rounded-2xl bg-white/70 p-3 dark:bg-slate-900/70",children:l})]})})})},_=({title:t,description:i,emptyMessage:c,rows:l})=>e.jsxs(S,{variant:"glass",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-[var(--text-primary)]",children:t}),e.jsx("p",{className:"mt-1 text-sm text-[var(--text-secondary)]",children:i})]}),e.jsx(ie,{className:"h-5 w-5 text-[var(--text-secondary)]"})]}),l.length?e.jsx("div",{className:"mt-6 space-y-3",children:l.map((n,u)=>e.jsx("div",{className:"rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70 p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-[var(--bg-tertiary)] text-xs font-semibold text-[var(--text-secondary)]",children:u+1}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[var(--text-primary)]",children:typeof n.label=="string"||typeof n.label=="number"?e.jsx("span",{className:"block truncate font-medium",children:n.label}):n.label}),n.detail?e.jsx("div",{className:"mt-2 text-sm text-[var(--text-secondary)]",children:n.detail}):null]})]})}),e.jsx("div",{className:"whitespace-nowrap text-right text-sm font-semibold text-[var(--text-primary)]",children:n.value})]})},n.key))}):e.jsx("div",{className:"mt-6 rounded-2xl border border-dashed border-[var(--border-default)] p-4 text-sm text-[var(--text-secondary)]",children:c})]}),J=({title:t,description:i,labels:c,series:l,valueFormatter:n=o})=>{var h,v;
2const[u,f]=x.useState(null),[j,m]=x.useState(!1),U=l.filter(d=>d.values.length===c.length&&d.values.length>0),C=Math.max(1,...U.flatMap(d=>d.values)),N=x.useMemo(()=>U.map(d=>({...d,valueFormatter:d.valueFormatter??n,points:d.values.map((b,$)=>{const R=c.length===1?50:$/Math.max(c.length-1,1)*100,y=72-b/C*72;return{x:R,y,label:c[$]??`Point ${$+1}`,seriesLabel:d.label,value:b,color:d.color}})})),[c,C,U]),A=x.useMemo(()=>c.map((d,b)=>({key:`${t}-${d}-${b}`,label:d,values:N.map($=>{var R;return{label:$.label,value:((R=$.points[b])==null?void 0:R.value)??0,formatter:$.valueFormatter??n}})})),[c,N,t]),I=d=>{f(d)},L=()=>{f(null)};return e.jsxs(S,{variant:"glass",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-[var(--text-primary)]",children:t}),e.jsx("p",{className:"mt-1 text-sm text-[var(--text-secondary)]",children:i})]}),e.jsx(ne,{className:"h-5 w-5 text-[var(--text-secondary)]"})]}),U.length?e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"relative overflow-visible rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70 p-4",children:[e.jsxs("svg",{viewBox:"0 0 100 80",className:"h-40 w-full overflow-visible",onMouseLeave:L,children:[e.jsx("defs",{children:N.map(d=>e.jsxs("linearGradient",{id:`${t.replace(/\s+/g,"-").toLowerCase()}-${d.label.replace(/\s+/g,"-").toLowerCase()}-gradient`,x1:"0",x2:"0",y1:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:d.color,stopOpacity:"0.28"}),e.jsx("stop",{offset:"100%",stopColor:d.color,stopOpacity:"0.02"})]},`${t}-${d.label}-gradient`))}),[0,1,2,3].map(d=>{const b=8+d*18;return e.jsx("line",{x1:"0",x2:"100",y1:b,y2:b,stroke:"currentColor",opacity:"0.12"},d)}),N.map(d=>{const b=d.points.map(y=>`${y.x},${y.y}`).join(" "),$=`0,72 ${b} 100,72`,R=`${t.replace(/\s+/g,"-").toLowerCase()}-${d.label.replace(/\s+/g,"-").toLowerCase()}-gradient`;return e.jsxs("g",{children:[e.jsx("polygon",{points:$,fill:`url(#${R})`}),e.jsx("polyline",{fill:"none",stroke:d.color,strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2.4",points:b}),d.points.map(y=>e.jsx("circle",{cx:y.x,cy:y.y,r:"5",fill:"transparent",stroke:"transparent",className:"cursor-pointer",onMouseEnter:()=>I({x:y.x,y:y.y,label:y.label,seriesLabel:y.seriesLabel,value:y.value,color:y.color})},`${d.label}-${y.label}-${y.x}`))]},d.label)}),u?e.jsx("circle",{cx:u.x,cy:u.y,r:"2.8",fill:u.color,stroke:"white",strokeWidth:"1.5"}):null]}),u?e.jsxs("div",{className:"pointer-events-none absolute z-20 rounded-2xl border border-[var(--border-default)] bg-white/95 px-3 py-2 text-xs shadow-xl backdrop-blur dark:bg-slate-900/95",style:{left:`${u.x}%`,top:`${u.y/80*100}%`,transform:"translate(-50%, -120%)"},children:[e.jsx("p",{className:"font-semibold text-[var(--text-primary)]",children:u.seriesLabel}),e.jsx("p",{className:"mt-0.5 text-[var(--text-secondary)]",children:u.label}),e.jsx("p",{className:"mt-1 font-semibold text-[var(--text-primary)]",children:((v=(h=N.find(d=>d.label===u.seriesLabel))==null?void 0:h.valueFormatter)==null?void 0:v.call(h,u.value))??n(u.value)})]}):null]}),e.jsx("div",{className:"flex flex-wrap gap-3",children:N.map(d=>e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[var(--border-default)] bg-[var(--bg-secondary)] px-3 py-1.5 text-xs text-[var(--text-secondary)]",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:d.color}}),e.jsx("span",{children:d.label}),e.jsx("span",{className:"font-semibold text-[var(--text-primary)]",children:z(d.values[d.values.length-1]||0)})]},d.label))}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-[var(--text-secondary)]",children:c.map(d=>e.jsx("span",{className:"rounded-full bg-[var(--bg-secondary)] px-2.5 py-1",children:d},d))}),e.jsx(M,{variant:"ghost",size:"sm",className:"px-3",onClick:()=>m(d=>!d),children:j?"Hide table":"View as table"})]}),j?e.jsx("div",{className:"overflow-x-auto rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"border-b border-[var(--border-default)] bg-[var(--bg-secondary)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Date"}),N.map(d=>e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:d.label},d.label))]})}),e.jsx("tbody",{children:A.map(d=>e.jsxs("tr",{className:"border-b border-[var(--border-default)] last:border-b-0",children:[e.jsx("td",{className:"px-4 py-3 font-medium text-[var(--text-primary)]",children:d.label}),d.values.map(b=>e.jsx("td",{className:"px-4 py-3 text-[var(--text-secondary)]",children:b.formatter(b.value)},`${d.key}-${b.label}`))]},d.key))})]})}):null]}):e.jsx("div",{className:"mt-6 rounded-2xl border border-dashed border-[var(--border-default)] p-4 text-sm text-[var(--text-secondary)]",children:"Not enough data yet."})]})},he=({userId:t,email:i})=>{const{toast:c}=Z(),[l,n]=x.useState(!1),u=i?i.split("@")[0]||i:Xe(t),f=i?`User ID: ${t} ⢠Email: ${i}
2`:`User ID: ${t}`,j=async()=>{try{await Oe(t),n(!0),c.success("User ID copied","The full user ID is on your clipboard."),window.setTimeout(()=>n(!1),1600)}catch(m){console.error("Failed to copy user ID:",m),c.error("Copy failed","Could not copy the user ID.")}};return e.jsx(be,{content:f,position:"top",children:e.jsxs("button",{type:"button",onClick:j,className:"group flex w-full items-center justify-between gap-3 rounded-xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70 px-3 py-2 text-left transition-colors hover:bg-[var(--bg-secondary)]",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate font-medium text-[var(--text-primary)]",children:u}),i?e.jsx("span",{className:"block truncate text-xs text-[var(--text-secondary)]",children:i}):null]}),e.jsx("span",{className:"shrink-0 text-[var(--text-secondary)] transition-colors group-hover:text-[var(--text-primary)]",children:l?e.jsx(Pe,{className:"h-4 w-4 text-emerald-500"}):e.jsx(Fe,{className:"h-4 w-4"})})]})})},ve=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsx(S,{variant:"glass",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-4 w-24 rounded-full bg-[var(--bg-tertiary)]"}),e.jsx("div",{className:"h-7 w-72 rounded-2xl bg-[var(--bg-tertiary)]"}),e.jsx("div",{className:"h-4 w-96 max-w-full rounded-2xl bg-[var(--bg-tertiary)]"})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5",children:Array.from({length:5}).map((t,i)=>e.jsx(S,{variant:"glass",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-4 w-32 rounded-full bg-[var(--bg-tertiary)]"}),e.jsx("div",{className:"h-10 w-24 rounded-2xl bg-[var(--bg-tertiary)]"}),e.jsx("div",{className:"h-4 w-40 rounded-2xl bg-[var(--bg-tertiary)]"})]})},i))}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-3",children:Array.from({length:3}).map((t,i)=>e.jsx(S,{variant:"glass",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-4 w-40 rounded-2xl bg-[var(--bg-tertiary)]"}),e.jsx("div",{className:"h-40 rounded-2xl bg-[var(--bg-tertiary)]"}),e.jsx("div",{className:"h-4 w-full rounded-2xl bg-[var(--bg-tertiary)]"})]})},i))})]}),fe=({tier:t})=>t==="paid"?e.jsx("span",{className:"inline-flex items-center rounded-full bg-amber-500/15 px-2.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide text-amber-600 dark:text-amber-300",children:"Pro"}):e.jsx("span",{className:"inline-flex items-center rounded-full bg-sky-500/15 px-2.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide text-sky-600 dark:text-sky-300",children:"Free"}),Y=t=>{if(!t)return"â";const i=Date.now()-new Date(t).getTime(),c=Math.floor(i/6e4);if(c<2)return"just now";if(c<60)return`${c}m ago`;const l=Math.floor(c/60);if(l<24)return`${l}h ago`;const n=Math.floor(l/24);return n<30?`${n}d ago`:`${Math.floor(n/30)}mo ago`},oe=[{label:"7 days",days:7,permanent:!1},{label:"30 days",days:30,permanent:!1},{label:"90 days",days:90,permanent:!1},{label:"1 year",days:365,permanent:!1},{label:"Permanent",days:null,permanent:!0}],os=({user:t,onClose:i,onGranted:c})=>{const{toast:l}=Z(),[n,u]=x.useState(0),[f,j]=x.useState(""),[m,U]=x.useState(!1),[C,N]=x.useState(!1),A=t.tier==="paid",I=async()=>{const h=oe[n];U(!0);try{const v=await ze(t.id,{durationDays:h.permanent?void 0:h.days??void 0,permanent:h.permanent,note:f.trim()||void 0});l.success("Pro granted",`Pro access ${h.permanent?"permanent":`extended by ${h.days} days`}. Expires: ${v.pro_credits_expires_at?new Date(v.pro_credits_expires_at).toLocaleDateString():"never"}`),c({...t,tier:v.tier??"paid",is_comp:v.is_comp??t.is_comp,paid_source:v.paid_source??t.paid_source,pro_credits_expires_at:v.pro_credits_expires_at}),i()}catch(v){l.error("Grant failed",v instanceof Error?v.message:"Unknown error")}finally{U(!1)}},L=async()=>{N(!0);try{const h=await We(t.id,f.trim()||void 0),v=h.tier==="paid";l.success("Pro credits revoked",v?`${t.email??t.id} still has Pro via ${h.paid_source==="subscription"?"an active subscription":h.paid_source==="apple"?"an Apple purchase":"another grant"}.`:`${t.email??t.id} is now on the Free tier.`),c({...t,tier:h.tier??"signed_in",is_comp:h.is_comp??t.is_comp,paid_source:h.paid_source??"none",pro_credits_expires_at:null}),i()}catch(h){l.error("Revoke failed",h instanceof Error?h.message:"Unknown error")}finally{N(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm",onClick:i,children:e.jsxs("div",{className:"w-full max-w-md rounded-3xl border border-[var(--border-default)] bg-white p-6 shadow-2xl dark:bg-slate-900",onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-[var(--text-primary)]",children:"User Actions"}),e.jsx("p",{className:"mt-0.5 text-sm text-[var(--text-secondary)] truncate",children:t.email??t.id})]}),e.jsx(fe,{tier:t.tier})]}),e.jsxs("div",{className:"mb-4 space-y-1 rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/60 p-3 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:"Name"}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:t.full_name??"â"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:"Tailors"}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:t.total_tailors})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:"Last active"}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:Y(t.last_active_at)})]}),t.pro_credits_expires_at?e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:"Pro expires"}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:new Date(t.pro_credits_expires_at).toLocaleDateString()})]}):null]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-[var(--text-secondary)]",children:"Grant Pro"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:oe.map((h,v)=>e.jsx("button",{type:"button",onClick:()=>u(v),className:`rounded-xl border px-3 py-1.5 text-sm font-medium transition-colors ${n===v?"border-sky-500 bg-sky-500/15 text-sky-600 dark:text-sky-300":"border-[var(--border-default)] bg-[var(--bg-secondary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,children:h.label},h.label))})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"mb-1 block text-xs font-semibold uppercase tracking-wide text-[var(--text-secondary)]",children:"Note (optional)"}),e.jsx("textarea",{value:f,onChange:h=>j(h.target.value),placeholder:"Reason for grant or revoke...",rows:2,className:"w-full rounded-xl border border-[var(--border-default)] bg-[var(--bg-secondary)] px-3 py-2 text-sm text-[var(--text-primary)] placeholder:text-[var(--text-secondary)] focus:outline-none focus:ring-2 focus:ring-sky-500/50"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[A?e.jsx(M,{variant:"outline",size:"sm",loading:C,onClick:L,children:"Revoke Pro"}):e.jsx("span",{}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{variant:"ghost",size:"sm",onClick:i,children:"Cancel"}),e.jsxs(M,{variant:"primary",size:"sm",loading:m,onClick:I,children:["Grant â ",oe[n].label]})]})]})]})})},ns=[{value:"all",label:"All tiers"},{value:"paid",label:"Pro"},{value:"signed_in",label:"Free"}],is=()=>{const{toast:t}
2=Z(),[i,c]=x.useState([]),[l,n]=x.useState(0),[u,f]=x.useState(null),[j,m]=x.useState(0),[U,C]=x.useState(""),[N,A]=x.useState(""),[I,L]=x.useState("all"),[h,v]=x.useState(!0),[d,b]=x.useState(null),$=x.useRef(null),R=x.useCallback(a=>{C(a),$.current&&clearTimeout($.current),$.current=setTimeout(()=>{A(a)},300)},[]),[,y]=x.useState(null),r=x.useCallback(async()=>{v(!0);try{const a=await Ge({search:N,tier:I,limit:100});c(a.users),n(a.total),f(a.paying_customers??null),m(a.comped_customers??0),y(null)}catch(a){const E=a instanceof Error?a.message:"Unknown error";y(D=>(D===null&&t.error("Failed to load users",E),E))}finally{v(!1)}},[N,I]);x.useEffect(()=>{r()},[r]);const p=a=>{c(E=>E.map(D=>D.id===a.id?a:D)),b(null)};return e.jsxs("div",{className:"space-y-4",children:[d?e.jsx(os,{user:d,onClose:()=>b(null),onGranted:p}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-48",children:[e.jsx(Ae,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--text-secondary)]"}),e.jsx("input",{type:"text",value:U,onChange:a=>R(a.target.value),placeholder:"Search by email or name...",className:"w-full rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/80 py-2 pl-9 pr-4 text-sm text-[var(--text-primary)] placeholder:text-[var(--text-secondary)] focus:outline-none focus:ring-2 focus:ring-sky-500/50"})]}),e.jsx("select",{value:I,onChange:a=>L(a.target.value),className:"rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/80 px-4 py-2 text-sm text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-sky-500/50",children:ns.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))}),e.jsx(M,{variant:"outline",size:"sm",leftIcon:e.jsx(Q,{className:`h-4 w-4 ${h?"animate-spin":""}`}),onClick:()=>{r()},children:"Refresh"}),e.jsxs("span",{className:"text-sm text-[var(--text-secondary)]",children:[l," users",u!==null&&e.jsxs(e.Fragment,{children:[" · ",e.jsxs("span",{className:"font-medium text-[var(--text-primary)]",children:[u," paying"]}),j>0&&` · ${j} comped`]})]})]}),e.jsx(S,{variant:"glass",className:"overflow-hidden p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"border-b border-[var(--border-default)] bg-[var(--bg-secondary)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Email"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Name"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Tier"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Pro expires"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Last active"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Tailors"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Actions"})]})}),e.jsx("tbody",{children:h?Array.from({length:5}).map((a,E)=>e.jsx("tr",{className:"border-b border-[var(--border-default)]",children:Array.from({length:7}).map((D,W)=>e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"h-4 animate-pulse rounded-full bg-[var(--bg-tertiary)]",style:{width:`${60+W*10%40}px`}})},W))},E)):i.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-8 text-center text-[var(--text-secondary)]",children:"No users found."})}):i.map(a=>e.jsxs("tr",{className:"border-b border-[var(--border-default)] last:border-b-0 hover:bg-[var(--bg-secondary)]/50 cursor-pointer",onClick:()=>b(a),children:[e.jsx("td",{className:"px-4 py-3 font-medium text-[var(--text-primary)] max-w-[200px] truncate",children:a.email??e.jsx("span",{className:"text-[var(--text-secondary)]",children:"â"})}),e.jsx("td",{className:"px-4 py-3 text-[var(--text-secondary)] max-w-[160px] truncate",children:a.full_name??"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(fe,{tier:a.tier})}),e.jsx("td",{className:"px-4 py-3 text-[var(--text-secondary)]",children:a.pro_credits_expires_at?e.jsx(be,{content:new Date(a.pro_credits_expires_at).toLocaleStr
2ing(),position:"top",children:e.jsx("span",{className:"cursor-default",children:Y(a.pro_credits_expires_at)})}):"â"}),e.jsx("td",{className:"px-4 py-3 text-[var(--text-secondary)]",children:Y(a.last_active_at)}),e.jsx("td",{className:"px-4 py-3 text-[var(--text-secondary)]",children:a.total_tailors}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(M,{variant:"outline",size:"sm",onClick:E=>{E.stopPropagation(),b(a)},children:"Manage"})})]},a.id))})]})})})]})},ls=()=>{const{toast:t}=Z(),[i,c]=x.useState([]),[l,n]=x.useState(0),[u,f]=x.useState(!0),j=x.useCallback(async()=>{f(!0);try{const m=await He(100,0);c(m.entries),n(m.total)}catch(m){t.error("Failed to load audit log",m instanceof Error?m.message:"Unknown error")}finally{f(!1)}},[t]);return x.useEffect(()=>{j()},[j]),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-[var(--text-secondary)]",children:[l," entries"]}),e.jsx(M,{variant:"outline",size:"sm",leftIcon:e.jsx(Q,{className:`h-4 w-4 ${u?"animate-spin":""}`}),onClick:()=>{j()},children:"Refresh"})]}),e.jsx(S,{variant:"glass",className:"overflow-hidden p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"border-b border-[var(--border-default)] bg-[var(--bg-secondary)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Timestamp"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Actor"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Action"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Target"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Metadata"})]})}),e.jsx("tbody",{children:u?Array.from({length:5}).map((m,U)=>e.jsx("tr",{className:"border-b border-[var(--border-default)]",children:Array.from({length:5}).map((C,N)=>e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"h-4 animate-pulse rounded-full bg-[var(--bg-tertiary)]",style:{width:`${60+N*15%60}px`}})},N))},U)):i.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-8 text-center text-[var(--text-secondary)]",children:"No audit entries yet."})}):i.map(m=>e.jsxs("tr",{className:"border-b border-[var(--border-default)] last:border-b-0",children:[e.jsx("td",{className:"px-4 py-3 text-[var(--text-secondary)] whitespace-nowrap",children:Y(m.created_at)}),e.jsx("td",{className:"px-4 py-3 text-[var(--text-primary)] max-w-[160px] truncate",children:m.actor_email}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex items-center rounded-full px-2.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide ${m.action==="grant_pro"?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-300":"bg-rose-500/15 text-rose-600 dar
2k:text-rose-300"}`,children:m.action.replace("_"," ")})}),e.jsx("td",{className:"px-4 py-3 text-[var(--text-secondary)] max-w-[200px] truncate",children:m.target_user_email??m.target_user_id??"â"}),e.jsx("td",{className:"px-4 py-3 text-[var(--text-secondary)] max-w-[200px] truncate text-xs font-mono",children:m.metadata?JSON.stringify(m.metadata):"â"})]},m.id))})]})})})]})},fs=()=>{var ce;_e({title:"Founder Dashboard | CareerDiary",description:"Private founder metrics for product usage, retention, AI spend, and LLM health.",canonical:"https://careerdiary.io/app/founder"});const{usage:t}=Le(),i=t.isFounder,[c,l]=x.useState("metrics"),[n,u]=x.useState(30),[f,j]=x.useState(0),[m,U]=x.useState(null),[C,N]=x.useState(null),[A,I]=x.useState(!0),[L,h]=x.useState(!1),[v,d]=x.useState(!0),[b,$]=x.useState(null),[R,y]=x.useState(()=>new Date);x.useEffect(()=>{const s=window.setInterval(()=>{y(new Date)},3e4);return()=>window.clearInterval(s)},[]),x.useEffect(()=>{if(!v)return;const s=window.setInterval(()=>{L||j(g=>g+1)},300*1e3);return()=>window.clearInterval(s)},[v,L]),x.useEffect(()=>{let s=!0;return(async()=>{N(null),m?h(!0):I(!0);try{const k=await Be(n);s&&(U(k),$(new Date))}catch(k){if(s){const te=k instanceof Error?k.message:"Failed to load founder metrics.";N(te)}}finally{s&&(I(!1),h(!1))}})(),()=>{s=!1}},[f,n]);const r=(m==null?void 0:m.usage)??null,p=(m==null?void 0:m.health)??null,a=x.useMemo(()=>{if(!r||!p)return null;const s=r.activeUsers.totalSignups||r.trends.dailySnapshots.reduce(($e,Te)=>$e+Te.signups,0),g=r.product.totals.resumeTailorStarted>0?r.product.totals.resumeTailorCompleted/r.product.totals.resumeTailorStarted*100:0,k=r.priorPeriod.totals.resumeTailorCompletionRate,te=r.costs.totals.requests>0?r.costs.totals.costUsd/r.costs.totals.requests:0;return{totalSignups:s,completionRate:g,priorCompletionRate:k,avgCostPerRequest:te,activeUsers:r.activeUsers,priorActiveUsers:r.priorPeriod.activeUsers,engagedUsers:r.engagedUsers??{window:0,lifetime:0},retention:r.retention,priorRetention:r.priorPeriod.retention,costs:r.costs.totals,priorCosts:r.priorPeriod.totals,llm:p.llm,product:r.product}},[p,r]),E=x.useMemo(()=>rs(b,R),[b,R]),D=x.useMemo(()=>(r==null?void 0:r.trends.dailySnapshots.map(s=>re(s.day)))??[],[r]),W=x.useMemo(()=>(r==null?void 0:r.costs.daily.map(s=>re(s.day)))??[],[r]),ee=x.useMemo(()=>new Map(((r==null?void 0:r.trends.analyticsDaily)??[]).map(s=>[s.day,s])),[r]),F=x.useMemo(()=>r?{labels:r.trends.dailySnapshots.map(s=>re(s.day)),signups:r.trends.dailySnapshots.map(s=>s.signups),sessions:r.trends.dailySnapshots.map(s=>{var g;return((g=ee.get(s.day))==null?void 0:g.totalSessions)??0})}:{labels:[],signups:[],sessions:[]},[ee,r]),le=x.useMemo(()=>{if(!(r!=null&&r.acquisition))return[];const s=[...r.acquisition.sources];return s.some(g=>g.source==="reddit")||s.push({source:"reddit",sessions:0,signups:0}),s},[r]),se=r!=null&&r.trends.analyticsDaily.length?r.trends.analyticsDaily[r.trends.analyticsDaily.length-1]:null,je=x.useMemo(()=>{var s;return Object.entries(((s=p==null?void 0:p.logs)==null?void 0:s.events)??{}).sort((g,k)=>k[1]-g[1])},[p]),ye=()=>{!a||!r||B(`careerdiary-users-${O()}.csv`,["metric","current","previous","change_percent"],[["Active Users (Signed In)",String(a.activeUsers.dau),String(a.priorActiveUsers.dau),a.priorActiveUsers.dau>0?w((a.activeUsers.dau-a.priorActiveUsers.dau)/a.priorActiveUsers.dau*100):""],["Guest Visitors",String(a.activeUsers.guestDau),String(a.priorActiveUsers.guestDau),a.priorActiveUsers.guestDau>0?w((a.activeUsers.guestDau-a.priorActiveUsers.guestDau)/a.priorActiveUsers.guestDau*100):""],["Retention Rate",w(a.retention.returningRate),w(a.priorRetention.returningRate),a.priorRetention.returningRate>0?w((a.retention.returningRate-a.priorRetention.returningRate)/a.priorRetention.returningRate*100):""],["Resume Tailor Completion",w(a.completionRate),w(a.priorCompletionRate),a.priorCompletionRate>0?w((a.completionRate-a.priorCompletionRate)/a.priorCompletionRate*100):""],["AI Cost",T(a.costs.costUsd),T(a.priorCosts.costUsd),a.priorCosts.costUsd>0?w((a.costs.costUsd-a.priorCosts.costUsd)/a.priorCosts.costUsd*100):""],["Signups",o(a.totalSignups),o(a.priorCosts.signups),a.priorCosts.signups>0?w((a.totalSignups-a.priorCosts.signups)/a.priorCosts.signups*100):""]])},Ne=()=>{if(!r)return;
2const s=r.trends.dailySnapshots.map(g=>{const k=ee.get(g.day);return[g.day,o(g.signups),o(g.pageViews),o(g.jobSearchesTotal),o(g.resumeTailorStartedTotal),o(g.resumeTailorCompletedTotal),w(g.tailorCompletionRate),o((k==null?void 0:k.totalSessions)??0),o((k==null?void 0:k.uniqueUsers)??0),o((k==null?void 0:k.avgSessionDurationSeconds)??0)]});B(`careerdiary-usage-${O()}.csv`,["day","signups","page_views","job_searches","tailor_started","tailor_completed","tailor_completion_rate","total_sessions","unique_users","avg_session_duration_seconds"],s)},we=()=>{r&&B(`careerdiary-product-${O()}.csv`,["group","name","count","guest","authed"],[...r.product.featureBreakdown.map(s=>["feature_breakdown",s.eventName,String(s.count),String(s.guest),String(s.authed)]),...r.product.topPages.map(s=>["top_pages",s.page_path,String(s.count),String(s.guest),String(s.authed)]),...r.product.topSearchQueries.map(s=>["search_queries",s.query,String(s.count),String(s.guest),String(s.authed)])])},ke=()=>{r&&B(`careerdiary-costs-${O()}.csv`,["group","name","requests","input_tokens","output_tokens","total_tokens","cost_usd","email"],[...r.costs.byRequestType.map(s=>["request_type",me(s.requestType),String(s.requests),String(s.inputTokens),String(s.outputTokens),String(s.totalTokens),T(s.costUsd),""]),...r.costs.byModel.map(s=>["model",s.model,String(s.requests),String(s.inputTokens),String(s.outputTokens),String(s.totalTokens),T(s.costUsd),""]),...r.costs.byService.map(s=>["service",pe(s.service),String(s.requests),"","",String(s.totalTokens),T(s.costUsd),""]),...r.costs.topUsers.map(s=>["top_user",s.email?`${s.email.split("@")[0]||s.email}`:s.userId,String(s.requests),"","",String(s.totalTokens),T(s.costUsd),s.email||""])])},Se=()=>{p&&B(`careerdiary-health-${O()}.csv`,["group","name","requests","success_rate","avg_latency_ms","blocked_count","count"],[...p.llm.byModel.map(s=>["by_model",s.model,String(s.requests),w(s.successRate),o(Math.round(s.avgLatencyMs)),String(s.blockedCount),""]),...p.llm.byEndpoint.map(s=>["by_endpoint",s.endpoint,String(s.requests),w(s.successRate),o(Math.round(s.avgLatencyMs)),String(s.blockedCount),""]),...p.llm.topErrorCodes.map(s=>["error_code",ue(s.errorCode),"","","","",String(s.count)])])},Ce=()=>{B(`careerdiary-revenue-${O()}.csv`,["metric","value"],[["status","pre-revenue placeholder"]])},Ue=L&&!!m;return A&&!m?e.jsx(ae,{title:"Founder Dashboard",description:"Loading product, growth, and model health metrics...",maxWidth:"full",children:e.jsx(ve,{})}):!m&&C?e.jsx(ae,{title:"Founder Dashboard",description:"Private metrics across product usage, retention, and AI health.",maxWidth:"full",children:e.jsx(S,{variant:"glass",className:"border border-rose-500/30",children:e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-rose-500/10 px-3 py-1 text-xs font-semibold uppercase tracking-[0.18em] text-rose-500",children:[e.jsx(H,{className:"h-4 w-4"}),"Founder access or data fetch failed"]}),e.jsx("p",{className:"text-base font-semibold text-[var(--text-primary)]",children:C}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:"This page is restricted by founder middleware and depends on Supabase plus Cloud Logging availability."})]}),e.jsx(M,{variant:"primary",size:"md",leftIcon:e.jsx(Q,{className:"h-4 w-4"}),onClick:()=>j(s=>s+1),children:"Retry"})]})})}):!m||!a||!r||!p?null:e.jsxs(ae,{title:"Founder Dashboard",description:"Product usage, retention, spend, and model health pulled from Supabase and Cloud Logging.",maxWidth:"full",children:[e.jsx(S,{variant:"glass",className:"overflow-hidden bg-gradient-to-br from-sky-500/14 via-white to-emerald-500/10 dark:from-sky-500/10 dark:via-slate-900 dark:to-emerald-500/10",children:e.jsxs("div",{className:"flex flex-col gap-6 xl:flex-row xl:items-end xl:justify-between",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-white/80 px-3 py-1 text-xs font-semibold uppercase tracking-[0.24em] text-sky-700 dark:bg-slate-900/80 dark:text-sky-300",children:[e.jsx(ne,{className:"h-4 w-4"}
2),"Founder-only analytics"]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-[var(--text-primary)]",children:"Live operational view of CareerDiary"}),e.jsxs("p",{className:"mt-2 max-w-3xl text-sm text-[var(--text-secondary)]",children:["Growth, retention, and usage come from Supabase aggregates. LLM health comes from audit logs plus Cloud Logging. Last refresh request ID: ",e.jsx("span",{className:"font-semibold text-[var(--text-primary)]",children:m.requestId})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-3",children:[e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:E}),e.jsxs(M,{variant:"outline",size:"sm",className:"h-9 rounded-full px-3",onClick:()=>d(s=>!s),children:["Auto-refresh: ",v?"ON":"OFF"]})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsxs("label",{className:"flex min-w-[140px] flex-col gap-2 text-sm text-[var(--text-secondary)]",children:[e.jsx("span",{children:"Window"}),e.jsx("select",{value:n,onChange:s=>u(Number(s.target.value)),className:"rounded-2xl border border-[var(--border-default)] bg-white/80 px-4 py-2 text-[var(--text-primary)] dark:bg-slate-900/80",children:Ve.map(s=>e.jsxs("option",{value:s.days,children:["Last ",s.label]},s.days))})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx(M,{variant:"primary",size:"lg",className:"h-auto rounded-2xl px-5 py-3",leftIcon:e.jsx(Q,{className:`h-4 w-4 ${L?"animate-spin":""}`}),onClick:()=>j(s=>s+1),loading:L,children:"Refresh"})})]})]})}),C?e.jsx(S,{variant:"glass",className:"border border-amber-500/30",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(H,{className:"mt-0.5 h-5 w-5 text-amber-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-[var(--text-primary)]",children:"Showing last successful snapshot"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--text-secondary)]",children:C})]})]})}):null,i?e.jsx("div",{className:"flex gap-1 rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/60 p-1",children:[{id:"metrics",label:"Metrics"},{id:"users",label:"Users"},{id:"audit",label:"Audit Log"}].map(s=>e.jsx("button",{type:"button",onClick:()=>l(s.id),className:`flex-1 rounded-xl px-4 py-2 text-sm font-semibold transition-colors ${c===s.id?"bg-white text-[var(--text-primary)] shadow-sm dark:bg-slate-800":"text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,children:s.label},s.id))}):null,c==="users"&&i?e.jsx(is,{}):c==="audit"&&i?e.jsx(ls,{}):Ue?e.jsx(ve,{}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-4",children:[e.jsx(P,{eyebrow:"Users",title:"Core KPIs",description:"The fastest read on acquisition, engagement, and model reliability in the selected window.",onExport:ye}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:[e.jsx(q,{label:"Engaged Users",value:o(a.engagedUsers.window),detail:`${o(a.engagedUsers.lifetime)} lifetime · tailored a resume or tracked an application`,icon:e.jsx(ne,{className:"h-7 w-7"}),tone:"emerald",title:"Distinct users who tailored a resume or tracked an application in the window â the headline number, immune to bot signups."}),e.jsx(q,{label:"Active Users (Signed In)",value:o(a.activeUsers.dau),detail:`WAU ${o(a.activeUsers.wau)} · MAU ${o(a.activeUsers.mau)}`,icon:e.jsx(Re,{className:"h-7 w-7"}),tone:"sky",currentValue:a.activeUsers.dau,previousValue:a.priorActiveUsers.dau,trendFormatter:o}),e.jsx(q,{label:"Guest Visitors",value:o(a.activeUsers.guestDau),detail:`WAU ${o(a.activeUsers.guestWau)} · MAU ${o(a.activeUsers.guestMau)}`,icon:e.jsx(Me,{className:"h-7 w-7"}),tone:"violet",currentValue:a.activeUsers.guestDau,previousValue:a.priorActiveUsers.guestDau,trendFormatter:o}),e.jsx(q,{label:"Retention",value:w(a.retention.returningRate),detail:`${o(a.retention.returningUsers)} returning of ${o(a.retention.currentUsers)} current users`,icon:e.jsx(Ie,{className:"h-7 w-7"}),tone:"emerald",currentValue:a.retention.returningRate,previousValue:a.priorRetention.returningRate,trendFormatter:w,title:"Retention is returning users divided by current users in the selected window."}
2),e.jsx(q,{label:"Resume Tailor Completion",value:w(a.completionRate),detail:`${o(a.product.totals.resumeTailorCompleted)} completed from ${o(a.product.totals.resumeTailorStarted)} starts`,icon:e.jsx(Ee,{className:"h-7 w-7"}),tone:"amber",currentValue:a.completionRate,previousValue:a.priorCompletionRate,trendFormatter:w}),e.jsx(q,{label:"AI Cost",value:T(a.costs.costUsd),detail:`${o(a.costs.requests)} requests · ${T(a.avgCostPerRequest)} per request`,icon:e.jsx(de,{className:"h-7 w-7"}),tone:"rose",currentValue:a.costs.costUsd,previousValue:a.priorCosts.costUsd,inverseTrend:!0,trendFormatter:T})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsx(P,{eyebrow:"Usage",title:"Daily movement",description:"Watch demand, funnel completion, sessions, and token spend without leaving the app.",onExport:Ne}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-3",children:[e.jsx(J,{title:"Resume tailoring funnel",description:"Started vs completed tailoring runs from daily snapshots.",labels:D,series:[{label:"Started",color:"#0ea5e9",values:r.trends.dailySnapshots.map(s=>s.resumeTailorStartedTotal)},{label:"Completed",color:"#10b981",values:r.trends.dailySnapshots.map(s=>s.resumeTailorCompletedTotal)}]}),e.jsx(J,{title:"Acquisition and sessions",description:"Signups and total sessions over the same period.",labels:F.labels,series:[{label:"Signups",color:"#f59e0b",values:F.signups},{label:"Sessions",color:"#6366f1",values:F.sessions}]}),e.jsx(J,{title:"Daily AI spend",description:"Estimated token cost by day, using Gemini pricing constants.",labels:W,series:[{label:"Cost (USD)",color:"#ef4444",values:r.costs.daily.map(s=>s.costUsd),valueFormatter:T},{label:"Requests",color:"#8b5cf6",values:r.costs.daily.map(s=>s.requests),valueFormatter:o}]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsx(P,{eyebrow:"Acquisition",title:"Acquisition by source",description:"Where external sessions came from in the selected window. Internal, auth, and bot/crawler traffic excluded; utm_source wins over referrer when present."}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-3",children:[e.jsxs(S,{variant:"glass",className:"overflow-hidden p-0 xl:col-span-2",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"border-b border-[var(--border-default)] bg-[var(--bg-secondary)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-[var(--text-secondary)]",children:"Source"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold text-[var(--text-secondary)]",children:"Sessions"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold text-[var(--text-secondary)]",children:"Signups"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold text-[var(--text-secondary)]",children:"Share"})]})}),e.jsx("tbody",{children:le.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-4 py-6 text-center text-[var(--text-secondary)]",children:"No external sessions recorded in this window yet."})}):le.map(s=>e.jsxs("tr",{className:"border-b border-[var(--border-default)] last:border-b-0",children:[e.jsxs("td",{className:`px-4 py-3 font-medium ${s.source==="reddit"?"text-[var(--color-accent)]":"text-[var(--text-primary)]"}`,children:[s.source,s.source==="reddit"&&s.sessions===0?e.jsx("span",{className:"ml-2 text-xs font-normal text-[var(--text-secondary)]",children:"expected 0 until tagged links go out"}):null]}),e.jsx("td",{className:"px-4 py-3 text-right text-[var(--text-secondary)]",children:o(s.sessions)}),e.jsx("td",{className:"px-4 py-3 text-right text-[var(--text-secondary)]",children:o(s.signups)}),e.jsx("td",{className:"px-4 py-3 text-right text-[var(--text-secondary)]",children:r.acquisition&&r.acquisition.externalSessions>0?`${(s.sessions/r.acquisition.externalSessions*100).toFixed(1)}%`:"â"})]},s.source))})]})}),e.jsx("p",{className:"border-t border-[var(--border-default)] px-4 py-3 text-xs text-[var(--text-secondary)]",children:r.acquisition?`${o(r.acquisition.externalSessions)} external of ${o(r.acquisition.totalSessions)} total sessions (${o(r.acquisition.internalSessions)} internal/auth excluded). utm_source is the reliable signal once shared links are tagged.`:"Source data unavailable for this window."})]}
2),e.jsx(J,{title:"External signups and sessions",description:"Daily signups vs sessions across the window.",labels:F.labels,series:[{label:"Signups",color:"#f59e0b",values:F.signups},{label:"Sessions",color:"#10b981",values:F.sessions}]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsx(P,{eyebrow:"Product",title:"Usage breakdown",description:"Feature mix, top content surfaces, and the search demand showing up inside product events.",onExport:we}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-3",children:[e.jsx(_,{title:"Feature breakdown",description:"Most frequent product events captured in the current window.",emptyMessage:"No product events found for this window.",rows:r.product.featureBreakdown.map(s=>({key:s.eventName,label:s.eventName,value:o(s.count),detail:`Guest ${o(s.guest)} · Authed ${o(s.authed)}`}))}),e.jsx(_,{title:"Top pages",description:"Page view volume from product events.",emptyMessage:"No page view events found for this window.",rows:r.product.topPages.map(s=>({key:s.page_path,label:s.page_path,value:o(s.count),detail:`Guest ${o(s.guest)} · Authed ${o(s.authed)}`}))}),e.jsx(_,{title:"Top search queries",description:"Normalized job search terms pulled from event properties.",emptyMessage:"No search query data found for this window.",rows:r.product.topSearchQueries.map(s=>({key:s.query,label:s.query,value:o(s.count),detail:`Guest ${o(s.guest)} · Authed ${o(s.authed)}`}))})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsx(P,{eyebrow:"Costs",title:"Token usage and lifetime value signals",description:"Blend per-request spend with lifetime engagement so the expensive paths are obvious.",onExport:ke}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-4",children:[e.jsx(_,{title:"By request type",description:"Which flows are driving AI consumption.",emptyMessage:"No token usage rows found in this window.",rows:r.costs.byRequestType.map(s=>({key:s.requestType,label:me(s.requestType),value:T(s.costUsd),detail:`${o(s.requests)} requests · ${z(s.totalTokens)} tokens`}))}),e.jsx(_,{title:"By model",description:"Model-level request counts and cost concentration.",emptyMessage:"No model usage found in this window.",rows:r.costs.byModel.map(s=>({key:s.model,label:s.model,value:T(s.costUsd),detail:`${o(s.requests)} requests · ${z(s.totalTokens)} tokens`}))}),e.jsx(_,{title:"By service",description:"Gemini vs JSearch vs Maps cost concentration.",emptyMessage:"No service cost rows found in this window.",rows:r.costs.byService.map(s=>({key:s.service,label:pe(s.service),value:T(s.costUsd),detail:`${o(s.requests)} requests · ${z(s.totalTokens)} tokens`}))}),e.jsx(_,{title:"Highest spend users",description:"Top user IDs by estimated token spend.",emptyMessage:"No user token data found in this window.",rows:r.costs.topUsers.map(s=>({key:s.userId,label:e.jsx(he,{userId:s.userId,email:s.email}),value:T(s.costUsd),detail:`${o(s.requests)} requests · ${z(s.totalTokens)} tokens`}))})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsxs(S,{variant:"glass",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-[var(--text-primary)]",children:"Lifetime user counters"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--text-secondary)]",children:"Aggregated from `user_stats` across the full product lifetime."})]}),e.jsx(ie,{className:"h-5 w-5 text-[var(--text-secondary)]"})]}),e.jsxs("div",{className:"mt-6 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70 p-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-[var(--text-secondary)]",children:"Resumes Tailored"}),e.jsx("p",{className:"mt-2 text-2xl font-bold text-[var(--text-primary)]",children:o(r.lifetimeUserStats.totals.resumesTailored)})]}),e.jsxs("div",{className:"rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70 p-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-[var(--text-secondary)]",children:"Cover Letters"}),e.jsx("p",{className:"mt-2 text-2xl font-bold text-[var(--text-primary)]",children:o(r.lifetimeUserStats.totals.coverLettersGenerated)})]}),e.jsxs("div",{className:"rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70 p-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-[var(--text-secondary)]",children:"Job Searches"}),e.jsx("p",{className:"mt-2 text-2xl font-bold text-[var(--text-primary)]",children:o(r.lifetimeUserStats.totals.jobSearches)})]}),e.jsxs("div",{className:"rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70 p-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-[var(--text-secondary)]",children:"Jobs Viewed"}),e.jsx("p",{className:"mt-2 text-2xl font-bold text-[var(--text-primary)]",children:o(r.lifetimeUserStats.totals.jobsViewed)})]})]})]}),e.jsx(_,{title:"Top lifetime users",description:"Users with the highest cumulative product output.",emptyMessage:"No lifetime user stats found.",rows:r.lifetimeUserStats.topUsers.map(s=>({key:s.userId,label:e.jsx(he,{userId:s.userId,email:s.email}),value:o(s.resumesTailored+s.coverLettersGenerated+s.jobSearches),detail:`Resumes ${o(s.resumesTailored)} · Letters ${o(s.coverLettersGenerated)} · Searches ${o(s.jobSearches)}`}))})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsx(P,{eyebrow:"Health",title:"LLM reliability and backend signals",description:"Success, latency, safety, endpoint mix, and Cloud Logging errors in one place.",onExport:Se}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(q,{label:"Requests",value:o(p.llm.totalRequests),detail:`${o(p.llm.successCount)} succeeded`,icon:e.jsx(de,{className:"h-7 w-7"}),tone:"sky"}),e.jsx(q,{label:"Avg Latency",value:V(p.llm.avgLatencyMs),detail:e.jsxs("span",{className:"inline-flex items-center gap-2",children:["P95 ",V(p.llm.p95LatencyMs)]}),icon:e.jsx(qe,{className:"h-7 w-7"}),tone:"amber"}),e.jsx(q,{label:"Blocked",value:o(p.llm.blockedCount),detail:`Avg safety score ${p.llm.avgSafetyScore.toFixed(3)} (0-1, higher = safer)`,icon:e.jsx(H,{className:"h-7 w-7"}),tone:"rose"}),e.jsx(q,{label:"Cloud Log Errors",value:o(((ce=p.logs)==null?void 0:ce.errors.total)??0),detail:p.logs?`${o(p.logs.totalEvents)} founder log events`:p.logsUnavailableReason||"Cloud Logging unavailable",icon:e.jsx(ie,{className:"h-7 w-7"}),tone:"emerald"})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-3",children:[e.jsx(_,{title:"LLM by model",description:"Volume, success rate, and latency by model.",emptyMessage:"No LLM audit rows found in this window.",rows:p.llm.byM
2odel.map(s=>({key:s.model,label:s.model,value:w(s.successRate),detail:e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-2",children:[e.jsxs("span",{children:[o(s.requests)," requests"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[V(s.avgLatencyMs)," avg"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[o(s.blockedCount)," blocked"]})]})}))}),e.jsx(_,{title:"LLM by endpoint",description:"Operational view by API surface.",emptyMessage:"No endpoint metrics found in this window.",rows:p.llm.byEndpoint.map(s=>({key:s.endpoint,label:s.endpoint,value:w(s.successRate),detail:e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-2",children:[e.jsxs("span",{children:[o(s.requests)," requests"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[V(s.avgLatencyMs)," avg"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[o(s.blockedCount)," blocked"]})]})}))}),e.jsx(_,{title:"Top error codes",description:"Most common LLM audit failures.",emptyMessage:"No LLM error codes recorded in this window.",rows:p.llm.topErrorCodes.map(s=>({key:s.errorCode,label:`${s.errorCode} â ${ue(s.errorCode)}`,value:o(s.count)}))})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(_,{title:"Cloud Logging event mix",description:"Counts from the `careerdiary-events` log stream.",emptyMessage:p.logsUnavailableReason||"No Cloud Logging event data available.",rows:je.slice(0,12).map(([s,g])=>({key:s,label:s,value:o(g)}))}),e.jsxs(S,{variant:"glass",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-[var(--text-primary)]",children:"Cloud Logging error samples"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--text-secondary)]",children:"Recent founder-visible errors from the `careerdiary-errors` log stream."})]}),e.jsx(H,{className:"h-5 w-5 text-[var(--text-secondary)]"})]}),p.logs?p.logs.errors.sample.length?e.jsx("div",{className:"mt-6 space-y-3",children:p.logs.errors.sample.slice(0,6).map((s,g)=>e.jsxs("div",{className:"rounded-2xl border border-[var(--border-default)] bg-[var(--bg-secondary)]/70 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-secondary)]",children:G(s.timestamp)}),e.jsx("span",{className:"rounded-full bg-rose-500/10 px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.16em] text-rose-500",children:"Error"})]}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-[var(--text-primary)]",children:s.message})]},`${s.timestamp}-${g}`))}):e.jsx("div",{className:"mt-6 rounded-2xl border border-dashed border-[var(--border-default)] p-4 text-sm text-[var(--text-secondary)]",children:"No error samples recorded in the current window."}):e.jsx("div",{className:"mt-6 rounded-2xl border border-dashed border-[var(--border-default)] p-4 text-sm text-[var(--text-secondary)]",children:p.logsUnavailableReason||"Cloud Logging unavailable."})]})]})]}),e.jsxs(ge.section,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4,delay:.3},className:"mt-2",children:[e.jsx(P,{eyebrow:"Revenue",title:"Revenue & Billing",description:"Financial metrics and subscription tracking",onExport:Ce}),e.jsxs(S,{variant:"glass",className:"text-center py-12",children:[e.jsx("span",{className:"mb-3 inline-block rounded-full bg-amber-500/10 px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.16em] text-amber-500",children:"Coming Soon"}),e.jsx("h3",{className:"mb-2 text-lg font-semibold text-[var(--text-primary)]",children:"Pre-Revenue"}),e.jsx("p",{className:"mx-auto max-w-md text-sm leading-6 text-[var(--text-secondary)]",children:"Revenue tracking will activate when billing is enabled. This section will show MRR, subscriber count, churn rate, and conversion metrics."})]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs(S,{variant:"glass",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-[var(--text-secondary)]",children:"Data Window"}),e.jsxs("p",{className:"mt-3 text-sm text-[var(--text-primary)]",children:["Usage: ",G(r.startTimeIso)," to ",G(r.endTimeIso)]}),e.jsxs("p",{className:"mt-2 text-sm text-[var(--text-secondary)]",children:["Product metrics scan ",o(r.product.uniqueSessions)," sessions and ",o(r.product.uniqueUsers)," authenticated users in the selected range."]})]}),e.jsxs(S,{variant:"glass",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-[var(--text-secondary)]",children:"Model Health Window"}),e.jsxs("p",{className:"mt-3 text-sm text-[var(--text-primary)]",children:["Health: ",G(p.startTimeIso)," to ",G(p.endTimeIso)]}),e.jsxs("p",{className:"mt-2 text-sm text-[var(--text-secondary)]",children:["Average session duration is ",Ze((se==null?void 0:se.avgSessionDurationSeconds)??0)," on the latest analytics day."]})]})]})]})]})};export{fs as FounderDashboardPage,fs 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.