PageSourceSearch

https://snf-insights.ai/assets/AdminActivityPage-CpOGpdEw.js

js snf-insights.ai collected 2026-10-05 15:07:25 UTC 94,781 bytes, 5 lines download raw bytes

1import{c as T,r as m,j as e,b as q,L as _,cU as ws,U as ks,e as _s,br as be,cV as Ss,F as Cs,W as zs,S as Ls,cW as Fs,cX as As,X as I,cr as ce,cq as xe,a5 as Te,aF as qs,Y as $s,C as Ps,cY as Ds,cZ as Rs,c_ as Ts,c$ as Es,d0 as Ms,d1 as Us,d2 as Os,d3 as Bs,d4 as Is,d5 as Hs,d6 as Ks,d7 as Ws,d8 as Qs,d9 as Vs,da as Xs,db as Ys,dc as Gs,dd as Js,de as Zs,df as et,dg as st}from"./index-Df108JlE.js";import{u as V}from"./useModalA11y-B5_bs4oH.js";import{af as he,ag as Ee,ah as Me,ai as ue,L as tt,at}from"./CartesianChart-CxTC1H5D.js";import{a as lt,L as rt}from"./LineChart-BhL0DOVD.js";import{C as Ue}from"./CartesianGrid-CgHY_Blv.js";import{B as nt,c as it}from"./BarChart-C3zlDDul.js";import{S as dt}from"./Sankey-IHob80vp.js";import{C as Oe}from"./copy-9tgRzl0w.js";import{C as ot}from"./circle-alert-DxMkBaLP.js";const ct=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],xt=T("globe",ct);const mt=[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]],pt=T("key-round",mt);const ht=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]],ut=T("lock-open",ht);const bt=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],gt=T("monitor",bt);const jt=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],ft=T("power",jt);const yt=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Be=T("upload",yt);const Nt=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],vt=T("user-plus",Nt),wt=[{key:"metrics",label:"Business Metrics"},{key:"activity",label:"Activity"},{key:"flow",label:"Navigation Flow"},{key:"users",label:"User Management"},{key:"engagement",label:"Engagement"},{key:"requests",label:"Analysis Requests"},{key:"changes",label:"Data Changes"},{key:"rate-flags",label:"Rate Flags"},{key:"health",label:"System Health"}],kt=[1,3,7,14,30],Ie=["trial","operator","business_office_manager","professional","enterprise"],He=t=>{const p=new Date;return p.setDate(p.getDate()+t),p.toISOString().slice(0,10)},_t={trial:"bg-amber-100 text-amber-700",expired_trial:"bg-rose-100 text-rose-700",operator:"bg-emerald-100 text-emerald-700",business_office_manager:"bg-slate-100 text-slate-700",professional:"bg-sky-100 text-sky-700",enterprise:"bg-purple-100 text-purple-700"},te={trial:"Trial",operator:"Operator",business_office_manager:"Business Office Manager",professional:"Professional",enterprise:"Enterprise",expired_trial:"Expired"};function R(t){if(!t)return"—";const p=new Date(t),x=Math.floor((new Date-p)/1e3);return x<60?"just now":x<3600?`${Math.floor(x/60)}m ago`:x<86400?`${Math.floor(x/3600)}h ago`:`${Math.floor(x/86400)}d ago`}function St({code:t}){if(!t)return null;const p=t<300?"bg-emerald-100 text-emerald-700":t<400?"bg-sky-100 text-sky-700":t<500?"bg-amber-100 text-amber-700":"bg-red-100 text-red-700";return e.jsx("span",{className:`text-[11px] font-mono font-semibold px-1.5 py-0.5 rounded ${p}`,children:t})}function Ct(){const{data:t,isLoading:p}=q({queryKey:["admin-metrics"],queryFn:Qs,refetchInterval:6e4,refetchIntervalInBackground:!1});if(p)return e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 py-12 justify-center",children:[e.jsx(_,{size:18,className:"animate-spin"})," Loading metrics..."]});if(!t)return null;const n={operator:"#10b981",professional:"#0ea5e9",enterprise:"#8b5cf6"},x=["#0ea5e9","#10b981","#f59e0b","#8b5cf6","#ef4444","#06b6d4","#f97316","#e
1c4899","#64748b"];return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm px-5 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-x-8 gap-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"Users"})," ",e.jsx("span",{className:"font-bold text-slate-800 ml-1",children:t.total_active_users})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"New 7d"})," ",e.jsx("span",{className:"font-bold text-emerald-600 ml-1",children:t.new_users_7d})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"New 30d"})," ",e.jsx("span",{className:"font-bold text-slate-800 ml-1",children:t.new_users_30d})]}),e.jsxs("div",{className:"border-l border-slate-200 pl-8",children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"Stripe"})," ",e.jsx("span",{className:"font-bold text-slate-800 ml-1",children:t.active_subscriptions})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"MRR"})," ",e.jsxs("span",{className:"font-bold text-emerald-600 ml-1",children:["$",(t.mrr_cents/100).toFixed(0)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"Manual"})," ",e.jsx("span",{className:"font-bold text-slate-800 ml-1",children:t.manual_users})]}),t.expired_manual>0&&e.jsx("div",{children:e.jsxs("span",{className:"text-xs font-semibold text-red-500",children:[t.expired_manual," expired"]})}),e.jsxs("div",{className:"border-l border-slate-200 pl-8",children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"DAU"})," ",e.jsx("span",{className:"font-bold text-slate-800 ml-1",children:t.dau})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"WAU"})," ",e.jsx("span",{className:"font-bold text-slate-800 ml-1",children:t.wau})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"MAU"})," ",e.jsx("span",{className:"font-bold text-slate-800 ml-1",children:t.mau})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-xs",children:"Sticky"})," ",e.jsx("span",{className:"font-bold text-slate-800 ml-1",children:t.mau>0?`${Math.round(t.dau/t.mau*100)}%`:"—"})]}),t.pending_requests>0&&e.jsx("div",{className:"border-l border-slate-200 pl-8",children:e.jsxs("span",{className:"text-xs font-semibold text-sky-600",children:[t.pending_requests," pending requests"]})}),t.expiring_soon>0&&e.jsx("div",{children:e.jsxs("span",{className:"text-xs font-semibold text-amber-600",children:[t.expiring_soon," expiring soon"]})})]})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:"Daily Active Users"}),e.jsx(he,{width:"100%",height:180,children:e.jsxs(lt,{data:t.dau_trend,children:[e.jsx(Ue,{strokeDasharray:"3 3",stroke:"#e2e8f0"}),e.jsx(Ee,{dataKey:"date",tick:{fontSize:10},tickFormatter:l=>l.slice(5)}),e.jsx(Me,{tick:{fontSize:10}}),e.jsx(ue,{labelFormatter:l=>new Date(l).toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsx(rt,{type:"monotone",dataKey:"users",stroke:"#0ea5e9",strokeWidth:2,dot:!1})]})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:"New Signups"}),e.jsx(he,{width:"100%",height:180,children:e.jsxs(nt,{data:t.signup_trend,children:[e.jsx(Ue,{strokeDasharray:"3 3",stroke:"#e2e8f0"}),e.jsx(Ee,{dataKey:"date",tick:{fontSize:10},tickFormatter:l=>l.slice(5)}),e.jsx(Me,{tick:{fontSize:10},allowDecimals:!1}),e.jsx(ue,{labelFormatter:l=>new Date(l).toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsx(it,{dataKey:"count",name:"Signups",fill:"#10b981",radius:[4,4,0,0]})]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wide mb-3",children:"By Tier"}),e.jsx("div",{className:"space-y-2",children:t.tier_breakdown.map(l=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:n[l.tier]||"#94a3b8"}}),e.jsx("span",{className:"text-slate-700 capitalize",children:l.tier})]}),e.jsx("span",{className:"font-semibold text-slate-800",children:l.count})]},l.tier))})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wide mb-3",children:"By Role"}),e.jsxs("div",{className:"space-y-2",children:[(t.by_role||[]).map((l,y)=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:x[y%x.length]}}),e.jsx("span",{className:"text-slate-700 truncate text-xs",children:l.label})]}),e.jsx("span",{className:"font-semibold text-slate-800",children:l.count})]},l.label)),!(t.by_role||[]).length&&e.jsx("p",{className:"text-xs text-slate-400",children:"No data yet"})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wide mb-3",children:"By Facility Count"}),e.jsxs("div",{className:"space-y-2",children:[(t.by_facility_count||[]).map((l,y)=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:x[y%x.length]}}),e.jsxs("span",{className:"text-slate-700",children:[l.label," facilities"]})]}),e.jsx("span",{className:"font-semibold text-slate-800",children:l.count})]},l.label)),!(t.by_facility_count||[]).length&&e.jsx("p",{className:"text-xs text-slate-400",children:"No data yet"})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wide mb-3",children:"How They Found Us"}),e.jsxs("div",{className:"space-y-2",children:[(t.by_referral||[]).map((l,y)=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:x[y%x.length]}}),e.jsx("span",{className:"text-slate-700 truncate text-xs",children:l.label})]}),e.jsx("span",{className:"font-semibold text-slate-800",children:l.count})]},l.label)),!(t.by_referral||[]).length&&e.jsx("p",{className:"text-xs text-slate-400",children:"No data yet"})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-4",children:"Feature Usage (30d)"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-600 uppercase",children:"Endpoint"}),e.jsx("th",{scope:"col",className:"text-right px-4 py-2 text-xs font-semibold text-slate-600 uppercase",children:"Hits"}),e.jsx("th",{scope:"col",className:"text-right px-4 py-2 text-xs font-semibold text-slate-600 uppercase",children:"Unique Users"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-50",children:t.feature_usage.map((l,y)=>e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-2 font-mono text-xs text-slate-700",children:l.path}),e.jsx("td",{className:"px-4 py-2 text-right text-slate-600",children:l.hits.toLocaleStr
1ing()}),e.jsx("td",{className:"px-4 py-2 text-right text-slate-600",children:l.users})]},y))})]})})]}),t.expiring_users?.length>0&&e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-amber-800 mb-3",children:"Users Expiring Soon"}),e.jsx("div",{className:"space-y-2",children:t.expiring_users.map(l=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-800",children:l.name}),e.jsx("span",{className:"text-slate-500 ml-2",children:l.email}),e.jsx("span",{className:`text-xs ml-2 px-1.5 py-0.5 rounded-full ${n[l.tier]||"bg-slate-100 text-slate-600"}`,children:l.tier})]}),e.jsxs("span",{className:`text-xs font-medium ${new Date(l.paid_through)<new Date?"text-red-600":"text-amber-600"}`,children:[new Date(l.paid_through)<new Date?"EXPIRED":"Expires"," ",new Date(l.paid_through).toLocaleDateString("en-US",{month:"short",day:"numeric"})]})]},l.id))})]})]})}function zt(){const[t,p]=m.useState(7),[n,x]=m.useState(""),[l,y]=m.useState(""),[h,j]=m.useState("last_seen"),[g,b]=m.useState("desc"),{data:d,isLoading:i,isError:a,error:u,refetch:o,isFetching:v}=q({queryKey:["admin-activity",t,n],queryFn:()=>Vs({days:t,email:n||void 0,limit:500}),refetchInterval:3e4,refetchIntervalInBackground:!1}),w=c=>{h===c?b(f=>f==="asc"?"desc":"asc"):(j(c),b("desc"))},$=[...d?.users||[]].sort((c,f)=>{let N,S;switch(h){case"email":N=c.email,S=f.email;break;case"requests":N=c.requests,S=f.requests;break;case"unique_pages":N=c.unique_pages,S=f.unique_pages;break;case"last_seen":N=c.last_seen,S=f.last_seen;break;case"first_seen":N=c.first_seen,S=f.first_seen;break;default:N=c.last_seen,S=f.last_seen}return N<S?g==="asc"?-1:1:N>S?g==="asc"?1:-1:0}),P=({col:c})=>h!==c?null:g==="asc"?e.jsx($s,{size:12}):e.jsx(Ps,{size:12}),L=m.useMemo(()=>{const c=d?.recent||[];if(!l.trim())return c;const f=l.toLowerCase();return c.filter(N=>(N.email||"").toLowerCase().includes(f)||(N.path||"").toLowerCase().includes(f)||(N.query_params||"").toLowerCase().includes(f)||(N.ip||"").includes(f)||(N.method||"").toLowerCase().includes(f)||String(N.status_code||"").includes(f))},[d?.recent,l]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-6",children:[e.jsx("div",{className:"flex items-center gap-1.5 bg-white border border-slate-200 rounded-lg px-1",children:kt.map(c=>e.jsxs("button",{onClick:()=>p(c),className:`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${t===c?"bg-sky-600 text-white":"text-slate-500 hover:text-slate-700"}`,children:[c,"d"]},c))}),e.jsx("input",{value:n,onChange:c=>x(c.target.value),placeholder:"Filter by email...","aria-label":"Filter by email",className:"border border-slate-300 rounded-lg px-3 py-1.5 text-sm w-64 focus:outline-none focus:ring-2 focus:ring-sky-500"}),e.jsxs("button",{onClick:()=>o(),disabled:v,className:"flex items-center gap-1.5 text-slate-500 hover:text-sky-600 text-sm disabled:opacity-50",children:[e.jsx(ws,{size:14,className:v?"animate-spin":""})," Refresh"]})]}),i&&e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 py-12 justify-center",children:[e.jsx(_,{size:18,className:"animate-spin"})," Loading activity..."]}),a&&e.jsx("div",{className:"bg-red-50 border border-red-200 text-red-700 rounded-lg p-4 text-sm",children:u.message}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-400 text-xs uppercase tracking-wide mb-2",children:[e.jsx(ks,{size:14})," Unique Users"]}),e.jsx("p",{className:"text-3xl font-bold text-slate-800",children:d.unique_users})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-400 text-xs uppercase tracking-wide mb-2",children:[e.jsx(xt,{size:14})," Total Requests"]}),e.jsx("p",{className:"text-3xl font-bold text-slate-800",children:d.total_requests.toLocaleStr
1ing()})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-400 text-xs uppercase tracking-wide mb-2",children:[e.jsx(gt,{size:14})," Top Page"]}),e.jsx("p",{className:"text-lg font-bold text-slate-800 truncate",children:d.top_pages?.[0]?.path||"—"}),e.jsxs("p",{className:"text-sm text-slate-400",children:[d.top_pages?.[0]?.hits||0," hits"]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-400 text-xs uppercase tracking-wide mb-2",children:[e.jsx(_s,{size:14})," Time Range"]}),e.jsxs("p",{className:"text-lg font-bold text-slate-800",children:["Last ",d.days," days"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-6",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-slate-100",children:e.jsx("h2",{className:"text-sm font-semibold text-slate-700",children:"Top Pages"})}),e.jsxs("div",{className:"divide-y divide-slate-50",children:[d.top_pages?.map((c,f)=>e.jsxs("div",{className:"px-5 py-2.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-slate-700 font-mono truncate",children:c.path}),e.jsx("span",{className:"text-sm font-semibold text-slate-500 ml-3",children:c.hits})]},f)),!d.top_pages?.length&&e.jsx("p",{className:"text-slate-400 text-sm px-5 py-4",children:"No page views yet."})]})]}),e.jsxs("div",{className:"col-span-2 bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-slate-100",children:e.jsx("h2",{className:"text-sm font-semibold text-slate-700",children:"User Sessions"})}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsx("tr",{children:[{key:"email",label:"User"},{key:"requests",label:"Requests"},{key:"unique_pages",label:"Pages"},{key:"first_seen",label:"First Seen"},{key:"last_seen",label:"Last Active"}].map(c=>e.jsx("th",{scope:"col",onClick:()=>w(c.key),className:"text-left px-4 py-2.5 text-xs font-semibold text-slate-600 uppercase tracking-wide cursor-pointer hover:text-sky-600 select-none",children:e.jsxs("span",{className:"flex items-center gap-1",children:[c.label," ",e.jsx(P,{col:c.key})]})},c.key))})}),e.jsxs("tbody",{className:"divide-y divide-slate-50",children:[$.map(c=>e.jsxs("tr",{className:"hover:bg-sky-50 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium text-slate-800",children:c.email}),e.jsx("td",{className:"px-4 py-2.5 text-slate-600",children:c.requests}),e.jsx("td",{className:"px-4 py-2.5 text-slate-600",children:c.unique_pages}),e.jsx("td",{className:"px-4 py-2.5 text-slate-500 text-xs",children:R(c.first_seen)}),e.jsx("td",{className:"px-4 py-2.5 text-slate-500 text-xs",children:R(c.last_seen)})]},c.email)),!$.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-slate-400 text-sm px-4 py-6 text-center",children:"No user sessions."})})]})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-slate-100 flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-semibold text-slate-700",children:"Recent Activity"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{value:l,onChange:c=>y(c.target.value),placeholder:"Search user, path, IP...","aria-label":"Search recent activity",className:"border border-slate-300 rounded-lg px-3 py-1 text-xs w-56 focus:outline-none focus:ring-2 focus:ring-sky-500"}),e.jsxs("span",{className:"text-xs text-slate-400",children:[L.length,L.length!==(d.recent?.length||0)?` / ${d.recent?.length||0}`:""," events"]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsx("tr",{children:["User","Method","Path","Params","Status","Time","Speed","IP"].map(c=>e.jsx("th",{scope:"col",className:"text-left px-4 py-2.5 text-xs font-semibold text-slate-600 uppercase tracking-wide",children:c},c))})}),e.jsxs("tbody",{className:"divide-y divide-slate-50",children:[L.map((c,f)=>e.jsxs("tr",{className:"hover:bg-slate-50 transition-colors",children:[e.jsx("td",{className:"px-4 py-2 text-slate-700",children:c.email||e.jsx("span",{className:"text-slate-300 italic",children:"anon"})}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("span",{className:`text-xs font-semibold ${c.method==="GET"?"text-emerald-600":c.method==="POST"?"text-sky-600":"text-slate-500"}`,children:c.method})}),e.jsx("td",{className:"px-4 py-2 font-mono text-slate-700 text-xs",children:c.path}),e.jsx("td",{className:"px-4 py-2 font-mono text-slate-400 text-xs max-w-48 truncate",children:c.query_params||"—"}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(St,{code:c.status_code})}),e.jsx("td",{className:"px-4 py-2 text-slate-500 text-xs whitespace-nowrap",children:R(c.time)}),e.jsxs("td",{className:"px-4 py-2 text-slate-500 text-xs",children:[c.response_time_ms,"ms"]}),e.jsx("td",{className:"px-4 py-2 text-slate-400 text-xs font-mono",children:c.ip})]},f)),!d.recent?.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"text-slate-400 text-sm px-4 py-6 text-center",children:"No recent activity."})})]})]})})]})]})]})}function Lt(){const t=be(),{data:p,isLoading:n,isError:x,error:l}=q({queryKey:["admin-users"],queryFn:Xs}),[y,h]=m.useState(!1),[j,g]=m.useState({email:"",password:"",name:"",tier:"professional",is_admin:!1,organization:"",role:"",trial_expires_at:""}),[b,d]=m.useState(""),[i,a]=m.useState(!1),[u,o]=m.useState(null),[v,w]=m.useState({}),[$,P]=m.useState(""),[L,c]=m.useState(!1),[f,N]=m.useState(null),[S,X]=m.useState(null),[Ke,E]=m.useState(!1),[Y,We]=m.useState(""),[G,Qe]=m.useState(""),[Ve,ge]=m.useState(!1),[ae,le]=m.useState(""),[A,M]=m.useState(null),[je,fe]=m.useState(!1),[k,ye]=m.useState(null),[Ne,U]=m.useState(""),[Xe,re]=m.useState(!1),[ve,we]=m.useState("Summit2026!"),[ke,_e]=m.useState(!1),[Ye,Se]=m.useState(!1);m.useEffect(()=>{Ss().then(s=>_e(s.enabled)).catch(()=>{})},[]);async function Ge(){Se(!0);try{const s=await Ds();_e(s.enabled)}catch{}Se(!1)}const[Ce,ze]=m.useState(null),[Le,Fe]=m.useState(null),[Ae,qe]=m.useState(null),[$e,Pe]=m.useState(null);async function Je(s){ze(s);try{await Rs(s),t.invalidateQueries({queryKey:["admin-users"]})}catch(r){alert(r.message)}ze(null)}async function Ze(s){Fe(s);try{const r=await Ts(s);alert(r.detail),t.invalidateQueries({queryKey:["admin-users"]})}catch(r){alert(r.message)}Fe(null)}async function es(s){qe(s);try{await Es(s),t.invalidateQueries({queryKey:["admin-users"]})}catch(r){alert(r.message)}qe(null)}async function ss(s,r){if(confirm(`Permanently delete ${r}? This cannot be undone.`)){Pe(s);try{await Ms(s),t.invalidateQueries({queryKey:["admin-users"]})}catch(z){alert(z.message)}Pe(null)}}async function ts(s){s.preventDefault(),d(""),a(!0);try{await Us(j),t.invalidateQueries({queryKey:["admin-users"]}),h(!1),g({email:"",password:"",name:"",tier:"professional",is_admin:!1,organization:"",role:"",trial_expires_at:""})}catch(r){d(r.message)}a(!1)}function as(s){o(s),w({name:s.name,tier:s.tier,active:s.active,is_admin:s.is_admin,paid_through:s.paid_through||"",organization:s.organization||"",role:s.role||"",trial_expires_at:s.trial_expires_at?s.trial_expires_at.slice(0,10):"",force_password_change:!!s.force_password_change}),P("")}async function ls(s){s.preventDefault(),P(""),c(!0);try{const{force_password_change:r,...z}=v;await Os(u.id,z),r!==!!u.force_password_change&&await Bs(u.id,{required:r}),t.invalidateQueries({queryKey:["admin-users"]}),o(null)}catch(r){P(r.message)}c(!1)}const[ne,O]=m.useState(null),[K,ie]=m.useState(""),[J,rs]=m.useState(!1),[Z,ns]=m.useState(!1),[ee,is]=m.useState(!1),[De,de]=m.useState(!0);async function ds(s){X(s);try{const r=K.length>=8?{password:K,force_change:De}:{}
1,z=await Is(s,r);N(z),O(null),ie(""),de(!0)}catch(r){alert(r.message)}X(null)}function os(s){navigator.clipboard.writeText(s),E(!0),setTimeout(()=>E(!1),2e3)}function cs(s){const r=s.trim().split(`
2`).filter(F=>F.trim());if(r.length===0)return[];const z=r[0].toLowerCase();if(z.includes("email")&&z.includes("name")){const F=r[0].split(",").map(D=>D.trim().toLowerCase().replace(/\s+/g,"_"));return r.slice(1).map(D=>{const Ns=D.split(",").map(oe=>oe.trim()),C={};return F.forEach((oe,vs)=>{C[oe]=Ns[vs]||""}),{email:C.email||"",name:C.name||C.full_name||"",organization:C.organization||C.org||C.company||"",role:C.role||C.title||C.job_title||"",tier:C.tier||C.access_level||""}}).filter(D=>D.email&&D.email.includes("@"))}return r.map(F=>{const B=F.split(",").map(D=>D.trim());return{email:B[0]||"",name:B[1]||"",organization:B[2]||"",role:B[3]||"",tier:B[4]||""}}).filter(F=>F.email&&F.email.includes("@"))}function xs(){U("");const s=cs(ae);if(s.length===0){U("No valid rows found. Expected format: email,name,organization,role,tier"),M(null);return}M(s)}function ms(s){const r=s.target.files?.[0];if(!r)return;const z=new FileReader;z.onload=Re=>{const F=Re.target?.result||"";le(F),U(""),M(null)},z.readAsText(r),s.target.value=""}async function ps(){if(!(!A||A.length===0)){fe(!0),U("");try{const s=await Hs({users:A.map(r=>({email:r.email,name:r.name,organization:r.organization||void 0,role:r.role||void 0,tier:r.tier||void 0})),default_password:ve.trim()||void 0});ye(s),M(null),t.invalidateQueries({queryKey:["admin-users"]})}catch(s){U(s.message)}fe(!1)}}function hs(){if(!k?.created?.length)return;const s=k.created.map(r=>`${r.email}	${r.temporary_password}`).join(`
3`);navigator.clipboard.writeText(s),re(!0),setTimeout(()=>re(!1),2e3)}function W(){ge(!1),le(""),M(null),ye(null),U(""),re(!1),we("Summit2026!")}const us=V(()=>h(!1)),bs=V(()=>o(null)),gs=V(()=>O(null)),js=V(()=>{N(null),E(!1)}),fs=V(W);if(n)return e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 py-12 justify-center",children:[e.jsx(_,{size:18,className:"animate-spin"})," Loading users..."]});if(x)return e.jsx("div",{className:"bg-red-50 border border-red-200 text-red-700 rounded-lg p-4 text-sm",children:l.message});const Q=p||[],ys=[...new Set(Q.map(s=>s.organization).filter(Boolean))].sort();let se=Y?Q.filter(s=>s.organization===Y):Q;if(G.trim()){const s=G.toLowerCase();
3se=se.filter(r=>(r.name||"").toLowerCase().includes(s)||(r.email||"").toLowerCase().includes(s)||(r.organization||"").toLowerCase().includes(s)||(r.role||"").toLowerCase().includes(s))}return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("input",{value:G,onChange:s=>Qe(s.target.value),placeholder:"Search name, email, org, position...","aria-label":"Search users",className:"border border-slate-300 rounded-lg px-3 py-2 text-sm w-72 focus:outline-none focus:ring-2 focus:ring-sky-500"}),e.jsxs("select",{value:Y,onChange:s=>We(s.target.value),className:"px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500 bg-white",children:[e.jsx("option",{value:"",children:"All Organizations"}),ys.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsx("p",{className:"text-sm text-slate-500",children:Y||G.trim()?e.jsxs(e.Fragment,{children:["Showing ",e.jsx("span",{className:"font-semibold text-slate-700",children:se.length})," of ",Q.length," users"]}):e.jsxs(e.Fragment,{children:[Q.length," users"]})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:Ge,disabled:Ye,className:`flex items-center gap-1.5 px-4 py-2 rounded-lg text-sm font-medium transition-colors border ${ke?"bg-emerald-50 hover:bg-emerald-100 text-emerald-700 border-emerald-300":"bg-slate-100 hover:bg-slate-200 text-slate-700 border-slate-300"}`,children:[e.jsx(Cs,{size:14})," Account Lookup ",ke?"ON":"OFF"]}),e.jsxs("button",{onClick:()=>ge(!0),className:"flex items-center gap-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-2 rounded-lg text-sm font-medium transition-colors border border-slate-300",children:[e.jsx(Be,{size:14})," Bulk Import"]}),e.jsxs("button",{onClick:()=>h(!0),className:"flex items-center gap-1.5 bg-sky-600 hover:bg-sky-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors",children:[e.jsx(vt,{size:14})," Add User"]})]})]}),e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsx("tr",{children:["Name","Org","Position","Email","Tier","Billing","Status","Last Login","Created","Actions"].map(s=>e.jsx("th",{scope:"col",className:"text-left px-4 py-3 text-xs font-semibold text-slate-600 uppercase tracking-wide whitespace-nowrap",children:s},s))})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:se.map(s=>{const r=s.locked_until&&new Date(s.locked_until)>new Date;return e.jsxs("tr",{className:`hover:bg-slate-50 transition-colors ${s.active?"":"opacity-60"}`,children:[e.jsx("td",{className:"px-4 py-3 font-medium text-slate-800",children:s.name}),e.jsx("td",{className:"px-4 py-3 text-slate-500 text-xs",children:s.organization||e.jsx("span",{className:"text-slate-300",children:"--"})}),e.jsx("td",{className:"px-4 py-3 text-slate-500 text-xs",children:s.role||e.jsx("span",{className:"text-slate-300",children:"--"})}),e.jsx("td",{className:"px-4 py-3 text-slate-600",children:s.email}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("span",{className:`text-xs font-semibold px-2 py-0.5 rounded-full ${_t[s.tier]||"bg-slate-100 text-slate-600"}`,children:te[s.tier]||s.tier}),s.tier_mismatch&&e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[11px] text-rose-600",title:s.effective_tier_reason,children:[e.jsx(zs,{className:"w-3 h-3 flex-none"}),e.jsxs("span",{children:["serving ",te[s.effective_tier]||s.effective_tier]})]})]}),e.jsx("td",{className:"px-4 py-3",children:s.stripe_customer_id?e.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-sky-50 text-sky-600",children:"Stripe"}):s.manually_provisioned?e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-violet-50 text-violet-600",children:"Manual"}),s.paid_through&&e.jsxs("p",{className:`text-[10px] mt-0.5 ${new Date(s.paid_through)<new Date?"text-red-500 font-semibold":new Date(s.paid_through)<new Date(Date.now()+30*864e5)?"text-amber-500":"text-slate-400"}`,children:[new Date(s.paid_through)<new Date?"EXPIRED ":"thru ",new Date(s.paid_through).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"2-digit"})]}),!s.paid_through&&e.jsx("p",{className:"text-[10px] text-slate-400 mt-0.5",children:"no expiry set"})]}):e.jsx("span",{className:"text-[10px] text-slate-400",children:"None"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[s.active?e.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-emerald-100 text-emerald-700",children:"Active"}):e.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-red-100 text-red-700",children:"Off"}),s.is_admin&&e.jsx(Ls,{size:12,className:"text-purple-500"}),r&&e.jsx("span",{className:"text-[10px] font-semibold px-1.5 py-0.5 rounded-full bg-amber-100 text-amber-700",title:`${s.failed_login_attempts} failed attempts`,children:"Locked"})]})}),e.jsx("td",{className:"px-4 py-3 text-slate-500 text-xs whitespace-nowrap",children:s.last_login?R(s.last_login):"Never"}),e.jsx("td",{className:"px-4 py-3 text-slate-500 text-xs whitespace-nowrap",children:s.created_at?new Date(s.created_at).toLocaleDateString():"—"}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>as(s),className:"text-xs text-sky-600 hover:text-sky-700 font-medium",children:"Edit"}),e.jsxs("button",{onClick:()=>Je(s.id),disabled:Ce===s.id,className:`text-xs font-medium flex items-center gap-0.5 disabled:opacity-50 ${s.active?"text-slate-500 hover:text-red-600":"text-emerald-600 hover:text-emerald-700"}`,title:s.active?"Deactivate user":"Activate user",children:[Ce===s.id?e.jsx(_,{size:11,className:"animate-spin"}):e.jsx(ft,{size:11}),s.active?"Deactivate":"Activate"]}),s.active_sessions>0&&e.jsxs("button",{onClick:()=>Ze(s.id),disabled:Le===s.id,className:"text-xs text-slate-500 hover:text-amber-600 font-medium flex items-center gap-0.5 disabled:opacity-50",title:"Force end all sessions",children:[Le===s.id?e.jsx(_,{size:11,className:"animate-spin"}):e.jsx(Fs,{size:11})," Logout"]}),r&&e.jsxs("button",{onClick:()=>es(s.id),disabled:Ae===s.id,className:"text-xs text-amber-600 hover:text-amber-700 font-medium flex items-center gap-0.5 disabled:opacity-50",title:"Unlock account",children:[Ae===s.id?e.jsx(_,{size:11,className:"animate-spin"}):e.jsx(ut,{size:11})," Unlock"]}),s.force_password_change&&e.jsxs("span",{className:"text-xs text-amber-600 font-medium flex items-center gap-0.5",title:"Will be asked to choose a new password at next sign-in. Change this under Edit.",children:[e.jsx(As,{size:11})," PW change"]}),e.jsxs("button",{onClick:()=>{O(s),ie(""),de(!0)},className:"text-xs text-slate-500 hover:text-amber-600 font-medium flex items-center gap-0.5",children:[e.jsx(pt,{size:11})," Reset PW"]}),!s.is_admin&&e.jsxs("button",{onClick:()=>ss(s.id,s.email),disabled:$e===s.id,className:"text-xs text-slate-400 hover:text-red-600 font-medium flex items-center gap-0.5 disabled:opacity-50",children:[$e===s.id?e.jsx(_,{size:11,className:"animate-spin"}):e.jsx(I,{size:11})," Delete"]})]})})]},s.id)})})]})})}),y&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",onClick:()=>h(!1),children:e.jsxs("div",{ref:us,role:"dialog","aria-modal":"true","aria-labelledby":"
3create-user-title",className:"bg-white rounded-xl shadow-xl w-full max-w-md p-6",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h3",{id:"create-user-title",className:"text-lg font-semibold text-slate-800",children:"Create User"}),e.jsx("button",{onClick:()=>h(!1),"aria-label":"Close",className:"text-slate-400 hover:text-slate-600",children:e.jsx(I,{size:18})})]}),b&&e.jsx("div",{className:"bg-red-50 border border-red-200 text-red-700 text-sm rounded-lg px-4 py-3 mb-4",children:b}),e.jsxs("form",{onSubmit:ts,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Name"}),e.jsx("input",{value:j.name,onChange:s=>g(r=>({...r,name:s.target.value})),required:!0,className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Email"}),e.jsx("input",{type:"email",value:j.email,onChange:s=>g(r=>({...r,email:s.target.value})),required:!0,className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:J?"text":"password",autoComplete:"new-password",value:j.password,onChange:s=>g(r=>({...r,password:s.target.value})),required:!0,minLength:8,placeholder:"Min 8 characters",className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500 pr-10"}),e.jsx("button",{type:"button",onClick:()=>rs(!J),"aria-label":J?"Hide password":"Show password",className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",children:J?e.jsx(ce,{size:16}):e.jsx(xe,{size:16})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Organization"}),e.jsx("input",{value:j.organization,onChange:s=>g(r=>({...r,organization:s.target.value})),placeholder:"Company name",className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Position"}),e.jsx("input",{value:j.role,onChange:s=>g(r=>({...r,role:s.target.value})),placeholder:"e.g. VP Operations",className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Tier"}),e.jsx("select",{value:j.tier,onChange:s=>g(r=>({...r,tier:s.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500",children:Ie.map(s=>e.jsx("option",{value:s,children:te[s]},s))})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:j.is_admin,onChange:s=>g(r=>({...r,is_admin:s.target.checked})),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),e.jsx("span",{className:"text-sm text-slate-700",children:"Admin access"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:["Demo access until ",e.jsx("span",{className:"font-normal text-slate-400",children:"(optional)"})]}),e.jsx("input",{type:"date",value:j.trial_expires_at,onChange:s=>g(r=>({...r,trial_expires_at:s.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"Qu
3ick demo:"}),[7,14,30].map(s=>e.jsxs("button",{type:"button",onClick:()=>g(r=>({...r,tier:"professional",trial_expires_at:He(s)})),className:"text-xs px-2 py-1 rounded border border-slate-300 hover:border-sky-400 hover:text-sky-600",children:[s," days"]},s)),j.trial_expires_at&&e.jsx("button",{type:"button",onClick:()=>g(s=>({...s,trial_expires_at:""})),className:"text-xs px-2 py-1 text-slate-400 hover:text-red-500",children:"clear"})]}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"After this date the account locks out. Quick-demo presets set Professional tier."})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>h(!1),className:"px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-100 rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:i,className:"flex items-center gap-2 bg-sky-600 hover:bg-sky-700 disabled:opacity-50 text-white font-medium px-5 py-2 rounded-lg text-sm transition-colors",children:i?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:14,className:"animate-spin"})," Creating..."]}):"Create User"})]})]})]})}),u&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",onClick:()=>o(null),children:e.jsxs("div",{ref:bs,role:"dialog","aria-modal":"true","aria-labelledby":"edit-user-title",className:"bg-white rounded-xl shadow-xl w-full max-w-md p-6",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h3",{id:"edit-user-title",className:"text-lg font-semibold text-slate-800",children:"Edit User"}),e.jsx("button",{onClick:()=>o(null),"aria-label":"Close",className:"text-slate-400 hover:text-slate-600",children:e.jsx(I,{size:18})})]}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:u.email}),$&&e.jsx("div",{className:"bg-red-50 border border-red-200 text-red-700 text-sm rounded-lg px-4 py-3 mb-4",children:$}),e.jsxs("form",{onSubmit:ls,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Name"}),e.jsx("input",{value:v.name,onChange:s=>w(r=>({...r,name:s.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Tier"}),e.jsx("select",{value:v.tier,onChange:s=>w(r=>({...r,tier:s.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500",children:Ie.map(s=>e.jsx("option",{value:s,children:te[s]},s))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Organization"}),e.jsx("input",{value:v.organization,onChange:s=>w(r=>({...r,organization:s.target.value})),placeholder:"e.g. Signature Healthcare",className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Position"}),e.jsx("input",{value:v.role,onChange:s=>w(r=>({...r,role:s.target.value})),placeholder:"e.g. Administrator, DON, VP of Operations",className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:v.active,onChange:s=>w(r=>({...r,active:s.target.checked})),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),e.jsx("span",{className:"text-sm text-slate-700",children:"Active"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:v.is_admin,onChange:s=>w(r=>({...r,is_admin:s.target.checked})),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),e.jsx("span",{className:"text-sm text-slate-700",children:"Admin"})]})]}),!v.active&&u?.active&&e.jsx("p",{className:"text-xs text-amber-600",children:"Saving this ends any session they have open, so they are signed out immediately."}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:!!v.force_password_change,onChange:s=>w(r=>({...r,force_password_change:s.target.checked})),className:"mt-0.5 rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),e.jsxs("span",{className:"text-sm text-slate-700",children:["Require a new password at next sign-in",e.jsx("span",{className:"block text-xs text-slate-500",children:"Does not change their current password. Saving this ends their active sessions."})]})]}),u?.manually_provisioned&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Paid Through"}),e.jsx("input",{type:"date",value:v.paid_through||"",onChange:s=>w(r=>({...r,paid_through:s.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1",children:"Set the date this user's access is paid through"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:["Demo access until ",e.jsx("span",{className:"font-normal text-slate-400",children:"(blank = no expiry)"})]}),e.jsx("input",{type:"date",value:v.trial_expires_at||"",onChange:s=>w(r=>({...r,trial_expires_at:s.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"Extend:"}),[7,14,30].map(s=>e.jsxs("button",{type:"button",onClick:()=>w(r=>({...r,trial_expires_at:He(s)})),className:"text-xs px-2 py-1 rounded border border-slate-300 hover:border-sky-400 hover:text-sky-600",children:[s," days"]},s)),v.trial_expires_at&&e.jsx("button",{type:"button",onClick:()=>w(s=>({...s,trial_expires_at:""})),className:"text-xs px-2 py-1 text-slate-400 hover:text-red-500",children:"clear"})]}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1",children:"After this date, operator/professional accounts lock out (enterprise never expires)."})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>o(null),className:"px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-100 rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:L,className:"flex items-center gap-2 bg-sky-600 hover:bg-sky-700 disabled:opacity-50 text-white font-medium px-5 py-2 rounded-lg text-sm transition-colors",children:L?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:14,className:"animate-spin"})," Saving..."]}):"Save Changes"})]})]})]})}),ne&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",onClick:()=>O(null),children:e.jsxs("div",{ref:gs,role:"dialog","aria-modal":"true","aria-labelledby":"reset-pw-input-title",className:"bg-white rounded-xl shadow-xl w-full max-w-md p-6",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{id:"reset-pw-input-title",className:"text-lg font-semibold text-slate-800",children:"Reset Password"}),e.jsx("button",{onClick:()=>O(null),"aria-label":"Close",className:"text-slate-400 hover:text-slate-600",children:e.jsx(I,{size:18})})]}),e.jsxs("p",{className:"text-sm text-slate-600 mb-4",children:["Resetting password for ",e.jsx("strong",{children:ne.email})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"New password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:Z?"text":"password",autoComplete:"new-password",value:K,onChange:s=>ie(s.target.value),placeholder:"Leave blank to auto-generate",className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500 pr-10"}),e.jsx("button",{type:"button",onClick:()=>ns(!Z),"aria-label":Z?"Hide password":"Show password",className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",children:Z?e.jsx(ce,{size:16}):e.jsx(xe,{size:16})})]}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1",children:"Min 8 characters, or leave blank for a random password"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:De,onCh
3ange:s=>de(s.target.checked),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),e.jsx("span",{className:"text-sm text-slate-700",children:"Require password change on next login"})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx("button",{onClick:()=>O(null),className:"px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-100 rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{onClick:()=>ds(ne.id),disabled:S||K.length>0&&K.length<8,className:"flex items-center gap-2 bg-amber-500 hover:bg-amber-600 disabled:opacity-50 text-white font-medium px-5 py-2 rounded-lg text-sm transition-colors",children:S?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:14,className:"animate-spin"})," Resetting..."]}):"Reset Password"})]})]})]})}),f&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",onClick:()=>{N(null),E(!1)},children:e.jsxs("div",{ref:js,role:"dialog","aria-modal":"true","aria-labelledby":"reset-pw-result-title",className:"bg-white rounded-xl shadow-xl w-full max-w-md p-6",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{id:"reset-pw-result-title",className:"text-lg font-semibold text-slate-800",children:"Password Reset"}),e.jsx("button",{onClick:()=>{N(null),E(!1)},"aria-label":"Close",className:"text-slate-400 hover:text-slate-600",children:e.jsx(I,{size:18})})]}),e.jsxs("p",{className:"text-sm text-slate-600 mb-3",children:["Temporary password for ",e.jsx("strong",{children:f.email}),":"]}),e.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 rounded-lg px-4 py-3 border border-slate-200",children:[e.jsx("code",{className:"flex-1 text-sm font-mono text-slate-800 select-all",children:f.temporary_password}),e.jsx("button",{onClick:()=>os(f.temporary_password),className:"text-slate-400 hover:text-sky-600 transition-colors",children:Ke?e.jsx(Te,{size:16,className:"text-emerald-500"}):e.jsx(Oe,{size:16})})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-3",children:"Share this password securely. The user should change it after logging in."}),e.jsx("div",{className:"flex justify-end mt-5",children:e.jsx("button",{onClick:()=>{N(null),E(!1)},className:"px-4 py-2 text-sm font-medium bg-slate-100 hover:bg-slate-200 text-slate-700 rounded-lg transition-colors",children:"Done"})})]})}),Ve&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",onClick:W,children:e.jsxs("div",{ref:fs,role:"dialog","aria-modal":"true","aria-labelledby":"bulk-import-title",className:"bg-white rounded-2xl shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto p-6",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Be,{size:18,className:"text-sky-600"}),e.jsx("h3",{id:"bulk-import-title",className:"text-lg font-semibold text-slate-800",children:"Bulk Import Users"})]}),e.jsx("button",{onClick:W,"aria-label":"Close",className:"text-slate-400 hover:text-slate-600",children:e.jsx(I,{size:18})})]}),Ne&&e.jsxs("div",{className:"flex items-start gap-2 bg-red-50 border border-red-200 text-red-700 text-sm rounded-lg px-4 py-3 mb-4",children:[e.jsx(ot,{size:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:Ne})]}),!A&&!k&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Paste CSV data"}),e.jsxs("p",{className:"text-xs text-slate-400 mb-2",children:["Format: ",e.jsx("code",{className:"bg-slate-100 px-1.5 py-0.5 rounded",children:"email,name,organization,role,tier"})," (one user per line)"]}),e.jsx("textarea",{value:ae,onChange:s=>le(s.target.value),placeholder:`email,name,organization,role,tier
4[email protected],Jane Smith,Acme Health,Administrator,professional
5[email protected],John Doe,Acme Health,Analyst,operator`,rows:8,className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-sky-500 resize-y"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"or"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-sm text-sky-600 hover:text-sky-700 cursor-pointer font-medium",children:[e.jsx(qs,{size:14}),"Upload CSV file",e.jsx("input",{type:"file",accept:".csv,.txt",className:"hidden",onChange:ms})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Default password for all users"}),e.jsx("p",{className:"text-xs text-slate-400 mb-2",children:"All users will be required to change this on first login. Leave blank for random passwords."}),e.jsxs("div",{className:"relative max-w-xs",children:[e.jsx("input",{type:ee?"text":"password",autoComplete:"new-password",value:ve,onChange:s=>we(s.target.value),placeholder:"e.g. Summit2026!",className:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500 pr-10"}),e.jsx("button",{type:"button",onClick:()=>is(!ee),"aria-label":ee?"Hide password":"Show password",className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",children:ee?e.jsx(ce,{size:16}):e.jsx(xe,{size:16})})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:W,className:"px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-100 rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{type:"button",onClick:xs,disabled:!ae.trim(),className:"flex items-center gap-2 bg-sky-600 hover:bg-sky-700 disabled:opacity-50 text-white font-medium px-5 py-2 rounded-lg text-sm transition-colors",children:"Preview"})]})]}),A&&!k&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-slate-600",children:[e.jsx("span",{className:"font-semibold",children:A.length})," user",A.length!==1?"s":""," will be created with temporary passwords (tier: operator)."]}),e.jsx("div",{className:"bg-white rounded-lg border border-slate-200 overflow-hidden max-h-64 overflow-y-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200 sticky top-0",children:e.jsx("tr",{children:["Email","Name","Organization","Role","Tier"].map(s=>e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-slate-600 uppercase tracking-wide",children:s},s))})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:A.map((s,r)=>e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-3 py-2 text-slate-800",children:s.email}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:s.name}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:s.organization||e.jsx("span",{className:"text-slate-300",children:"--"})}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:s.role||e.jsx("span",{className:"text-slate-300",children:"--"})}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:s.tier||e.jsx("span",{className:"text-slate-400",children:"operator"})})]},r))})]})}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>M(null),className:"px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-100 rounded-lg transition-colors",children:"Back"}),e.jsx("button",{type:"button",onClick:ps,disabled:je,className:"flex items-center gap-2 bg-emerald-600 hover:bg-emerald-700 disabled:opacity-50 text-white font-medium px-5 py-2 rounded-lg text-sm transition-colors",children:je?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:14,className:"animate-spin"})," Importing..."]}):`Import ${A.length} Users`})]})]}),k&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[k.created.length>0&&e.jsxs("span",{className:"text-sm font-semibold text-emerald-600",children:[k.created.length," created"]}),k.skipped.length>0&&e.jsxs("span",{className:"text-sm font-semibold text-amber-600",children:[k.skipped.length," skipped"]})]}),k.created.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700",children:"Created Users"}),e.jsx("button",{onClick:hs,className:"flex items-center gap-1.5 text-xs text-sky-600 hover:text-sky-700 font-medium",children:Xe?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:12,className:"text-emerald-500"})," Copied!"]}):e.jsxs(e.Fragment,{children:[e.jsx(Oe,{size:12})," Copy All"]})})]}),k.created.length>1&&k.created.every(s=>s.temporary_password===k.created[0].temporary_password)&&e.jsxs("div",{className:"flex items-center gap-2 bg-sky-50 border border-sky-200 text-sky-800 text-sm rounded-lg px-4 py-3 mb-3",children:[e.jsxs("span",{children:["Shared password for all users: ",e.jsx("code",{className:"font-mono bg-sky-100 text-sky-700 px-2 py-0.5 rounded font-semibold select-all",children:k.created[0].temporary_password})]}),e.jsx("span",{className:"text-xs text-sky-500 ml-1",children:"(forced change on first login)"})]}),e.jsx("div",{className:"bg-white rounded-lg border border-slate-200 overflow-hidden max-h-48 overflow-y-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200 sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-slate-600",children:"Email"}),e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-slate-600",children:"Name"}),e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-slate-600",children:"Org"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:k.created.map((s,r)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 text-slate-800",children:s.email}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:s.name}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:s.organization||"—"})]},r))})]})})]}),k.skipped.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-slate-700 mb-2",children:"Skipped"}),e.jsx("div",{className:"bg-amber-50 rounded-lg border border-amber-200 overflow-hidden max-h-32 overflow-y-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-amber-50 border-b border-amber-200 sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-amber-700",children:"Email"}),e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-amber-700",children:"Reason"})]})}),e.jsx("tbody",{className:"divide-y divide-amber-100",children:k.skipped.map((s,r)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 text-amber-800",children:s.email}),e.jsx("td",{className:"px-3 py-2 text-amber-600",children:s.reason})]},r))})]})})]}),e.jsx("div",{className:"flex justify-end pt-2",children:e.jsx("button",{onClick:W,className:"px-4 py-2 text-sm font-medium bg-slate-100 hover:bg-slate-200 text-slate-700 rounded-lg transition-colors",children:"Done"})})]})]})})]})}const Ft={new:"bg-sky-100 text-sky-700",contacted:"bg-amber-100 text-amber-700",in_progress:"bg-violet-100 text-violet-700",completed:"bg-emerald-100 text-emerald-700"},me={new:"New",contacted:"Contacted",in_progress:"In Progress",completed:"Completed"},At=["new","contacted","in_progress","completed"];function qt(){const t=be(),[p,n]=m.useState(""),[x,l]=m.useState(1),[y,h]=m.useState(null),{data:j,isLoading:g}=q({queryKey:["admin-analysis-requests",p,x],queryFn:()=>Ys({status:p||void 0,page:x,page_size:20})});async function b(a,u){h(a);try{await Ks(a,u),t.invalidateQueries({queryKey:["admin-analysis-requests"]})}catch(o){alert(o.message)}h(null)}const d=j?.requests||[],i=j?.total||0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-6",children:[{key:"",label:"All",color:"text-slate-700"},{key:"new",label:"New",color:"text-sky-600"},{key:"contacted",label:"Contacted",color:"text-amber-600"},{key:"in_progress",label:"In Progress",color:"text-violet-600"}].map(a=>e.jsxs("button",{onClick:()=>{n(a.key),l(1)},className:`bg-white rounded-xl border shadow-sm p-4 text-left transition-colors ${p===a.key?"border-sky-300 ring-1 ring-sky-200":"border-slate-200 hover:border-slate-300"}`,children:[e.jsx("p",{className:"text-[10px] text-slate-400 uppercase tracking-wide",children:a.label}),e.jsx("p",{className:`text-2xl font-bold mt-1 ${a.color}`,children:p===a.key?i:"—"})]},a.key))}),g&&e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 py-12 justify-center",children:[e.jsx(_,{size:18,className:"animate-spin"})," Loading..."]}),!g&&d.length===0&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-8 text-center text-sm text-slate-500",children:["No analysis requests",p?` with status "${me[p]}"`:"","."]}),d.length>0&&e.jsx("div",{className:"space-y-3",children:d.map(a=>e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full ${Ft[a.status]||"bg-slate-100 text-slate-600"}`,children:me[a.status]||a.status}),e.jsx("span",{className:"text-xs text-slate-400",children:R(a.created_at)})]}),e.jsx("h3",{className:"text-sm font-semibold text-slate-800",children:a.analysis_type}),e.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:[e.jsx("span",{className:"font-medium",children:a.name}),a.organization&&e.jsxs("span",{className:"text-slate-400",children:[" · ",a.organization]})," ","·"," ",e.jsx("a",{href:`mailto:${a.email}`,className:"text-sky-600 hover:underline",children:a.email}),a.contact_phone&&e.jsxs("span",{className:"text-slate-400",children:[" · ",a.contact_phone]})]}),a.description&&e.jsx("p",{className:"text-xs text-slate-500 mt-2 leading-relaxed bg-slate-50 rounded-lg px-3 py-2",children:a.description}),a.page_context&&e.jsxs("p",{className:"text-[10px] text-slate-400 mt-1",children:["From: ",a.page_context]})]}),e.jsx("select",{value:a.status,onChange:u=>b(a.id,u.target.value),disabled:y===a.id,className:"text-xs border border-slate-300 rounded-lg px-2 py-1.5 focus:outline-none focus:ring-2 focus:ring-sky-500 disabled:opacity-50",children:At.map(u=>e.jsx("option",{value:u,children:me[u]},u))})]})},a.id))}),i>20&&e.jsxs("div",{className:"flex items-center justify-center gap-3 mt-6",children:[e.jsx("button",{onClick:()=>l(a=>Math.max(1,a-1)),disabled:x===1,className:"px-3 py-1.5 rounded text-sm border border-slate-300 text-slate-600 disabled:opacity-40 hover:bg-slate-50",children:"Previous"}),e.jsxs("span",{className:"text-sm text-slate-500",children:["Page ",x," of ",Math.
5ceil(i/20)]}),e.jsx("button",{onClick:()=>l(a=>a+1),disabled:x>=Math.ceil(i/20),className:"px-3 py-1.5 rounded text-sm border border-slate-300 text-slate-600 disabled:opacity-40 hover:bg-slate-50",children:"Next"})]})]})}const $t={pending:"bg-amber-100 text-amber-700",approved:"bg-emerald-100 text-emerald-700",rejected:"bg-red-100 text-red-700"};function Pt(){const t=be(),[p,n]=m.useState("pending"),[x,l]=m.useState(1),[y,h]=m.useState(null),[j,g]=m.useState({}),{data:b,isLoading:d}=q({queryKey:["admin-change-requests",p,x],queryFn:()=>Gs({status:p||void 0,page:x,page_size:20})});async function i(o,v){h(o);try{await Ws(o,{status:v,reviewer_notes:j[o]||null}),t.invalidateQueries({queryKey:["admin-change-requests"]})}catch(w){alert(w.message)}h(null)}const a=b?.requests||[],u=b?.total||0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex gap-2 mb-6",children:["","pending","approved","rejected"].map(o=>e.jsx("button",{onClick:()=>{n(o),l(1)},className:`px-3 py-1.5 text-xs rounded-lg transition-colors ${p===o?"bg-sky-500 text-white":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,children:o||"All"},o))}),d&&e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 py-12 justify-center",children:[e.jsx(_,{size:18,className:"animate-spin"})," Loading..."]}),!d&&a.length===0&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-8 text-center text-sm text-slate-500",children:["No change requests",p?` with status "${p}"`:"","."]}),a.length>0&&e.jsx("div",{className:"space-y-3",children:a.map(o=>e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full ${$t[o.status]||"bg-slate-100 text-slate-600"}`,children:o.status}),e.jsx("span",{className:"text-[10px] text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded",children:o.entity_type}),e.jsx("span",{className:"text-xs text-slate-400",children:R(o.created_at)})]}),e.jsxs("p",{className:"text-sm font-semibold text-slate-800",children:[o.field,": ",e.jsx("span",{className:"text-red-400 line-through",children:o.old_value||"(empty)"})," → ",e.jsx("span",{className:"text-emerald-600",children:o.new_value})]}),e.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:["Entity: ",e.jsx("span",{className:"font-medium",children:o.entity_id})," · ","Submitted by: ",e.jsx("span",{className:"font-medium",children:o.email||`user #${o.user_id}`}),o.reviewer_email&&e.jsxs("span",{children:[" · Reviewed by: ",o.reviewer_email]})]}),o.reviewer_notes&&e.jsxs("p",{className:"text-xs text-slate-400 mt-1 italic",children:["Note: ",o.reviewer_notes]})]}),o.status==="pending"&&e.jsxs("div",{className:"flex flex-col gap-2 shrink-0",children:[e.jsx("input",{placeholder:"Review notes (optional)","aria-label":"Review notes",value:j[o.id]||"",onChange:v=>g(w=>({...w,[o.id]:v.target.value})),className:"text-xs border border-slate-300 rounded-lg px-2 py-1.5 w-48 focus:outline-none focus:ring-2 focus:ring-sky-500"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>i(o.id,"approved"),disabled:y===o.id,className:"flex-1 text-xs bg-emerald-500 text-white rounded-lg px-3 py-1.5 hover:bg-emerald-600 disabled:opacity-50",children:"Approve"}),e.jsx("button",{onClick:()=>i(o.id,"rejected"),disabled:y===o.id,className:"flex-1 text-xs bg-red-500 text-white rounded-lg px-3 py-1.5 hover:bg-red-600 disabled:opacity-50",children:"Reject"})]})]})]})},o.id))}),u>20&&e.jsxs("div",{className:"flex items-center justify-center gap-3 mt-6",children:[e.jsx("button",{onClick:()=>l(o=>Math.max(1,o-1)),disabled:x===1,className:"px-3 py-1.5 rounded text-sm border border-slate-300 text-slate-600 disabled:opacity-40 hover:bg-slate-50",children:"Previous"}),e.jsxs("span",{className:"text-sm text-slate-500",children:["Page ",x," of ",Math.
5ceil(u/20)]}),e.jsx("button",{onClick:()=>l(o=>o+1),disabled:x>=Math.ceil(u/20),className:"px-3 py-1.5 rounded text-sm border border-slate-300 text-slate-600 disabled:opacity-40 hover:bg-slate-50",children:"Next"})]})]})}const Dt={confirm:"bg-emerald-100 text-emerald-700",dispute:"bg-red-100 text-red-700",high:"bg-amber-100 text-amber-700",low:"bg-sky-100 text-sky-700"};function Rt(){const[t,p]=m.useState("dispute"),[n,x]=m.useState(1),{data:l,isLoading:y}=q({queryKey:["admin-rate-flags",t,n],queryFn:()=>Js({page:n,page_size:30})}),h=l?.flags||[],j=l?.total||0,g=t?h.filter(d=>d.flag_type===t):h,b={};for(const d of h)b[d.flag_type]=(b[d.flag_type]||0)+1;return e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-xs text-slate-400 mb-4",children:["Rates flagged by users. Focus on ",e.jsx("strong",{className:"text-red-500",children:"disputed"})," rates to investigate data quality issues."]}),e.jsx("div",{className:"flex gap-2 mb-6",children:["","dispute","high","low","confirm"].map(d=>e.jsxs("button",{onClick:()=>{p(d),x(1)},className:`px-3 py-1.5 text-xs rounded-lg transition-colors ${t===d?"bg-sky-500 text-white":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,children:[d||"All",b[d]?` (${b[d]})`:""]},d))}),y&&e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 py-12 justify-center",children:[e.jsx(_,{size:18,className:"animate-spin"})," Loading..."]}),!y&&g.length===0&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-8 text-center text-sm text-slate-500",children:["No rate flags",t?` of type "${t}"`:"","."]}),g.length>0&&e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-100 bg-slate-50",children:[e.jsx("th",{scope:"col",className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-500",children:"Type"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-500",children:"Payer"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-500",children:"Code"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-500",children:"NPI"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-500",children:"User"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-500",children:"Note"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-500",children:"When"})]})}),e.jsx("tbody",{children:g.map(d=>e.jsxs("tr",{className:"border-b border-slate-50 hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-2",children:e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full ${Dt[d.flag_type]||"bg-slate-100 text-slate-600"}`,children:d.flag_type})}),e.jsx("td",{className:"px-4 py-2 text-xs font-medium text-slate-700",children:d.payer}),e.jsx("td",{className:"px-4 py-2 text-xs font-mono text-slate-600",children:d.billing_code}),e.jsx("td",{className:"px-4 py-2 text-xs font-mono text-slate-600",children:d.npi}),e.jsx("td",{className:"px-4 py-2 text-xs text-slate-500",children:d.email||`#${d.user_id}`}),e.jsx("td",{className:"px-4 py-2 text-xs text-slate-400 max-w-[200px] truncate",children:d.note||"—"}),e.jsx("td",{className:"px-4 py-2 text-xs text-slate-400",children:R(d.created_at)})]},d.id))})]})}),j>30&&e.jsxs("div",{className:"flex items-center justify-center gap-3 mt-6",children:[e.jsx("button",{onClick:()=>x(d=>Math.max(1,d-1)),disabled:n===1,className:"px-3 py-1.5 rounded text-sm border border-slate-300 text-slate-600 disabled:opacity-40 hover:bg-slate-50",children:"Previous"}),e.jsxs("span",{className:"text-sm text-slate-500",children:["Page ",n," of ",Math.
5ceil(j/30)]}),e.jsx("button",{onClick:()=>x(d=>d+1),disabled:n>=Math.ceil(j/30),className:"px-3 py-1.5 rounded text-sm border border-slate-300 text-slate-600 disabled:opacity-40 hover:bg-slate-50",children:"Next"})]})]})}function Tt(){const{data:t,isLoading:p}=q({queryKey:["admin-engagement"],queryFn:Zs});return p?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(_,{className:"animate-spin text-sky-500",size:24})}):t?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-slate-200",children:e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:"User Favorites & Digest Status"})}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"User"}),e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"Email"}),e.jsx("th",{scope:"col",className:"text-right px-4 py-2 text-xs font-semibold text-slate-500",children:"Favorites"}),e.jsx("th",{scope:"col",className:"text-center px-4 py-2 text-xs font-semibold text-slate-500",children:"Digest"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:t.users.map(n=>e.jsxs("tr",{className:n.favorites>0?"":"opacity-50",children:[e.jsx("td",{className:"px-4 py-2 font-medium text-slate-700",children:n.name}),e.jsx("td",{className:"px-4 py-2 text-slate-500",children:n.email}),e.jsx("td",{className:"px-4 py-2 text-right font-semibold",children:n.favorites}),e.jsx("td",{className:"px-4 py-2 text-center",children:n.digest_enabled?e.jsx("span",{className:"text-emerald-600 text-xs font-medium",children:"On"}):e.jsx("span",{className:"text-slate-400 text-xs",children:"Off"})})]},n.id))})]})]}),t.favorites.length>0&&e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-slate-200",children:e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:"Saved Facilities Detail"})}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"User"}),e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"Facility"}),e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"State"}),e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"Chain"}),e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"Saved"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:t.favorites.map((n,x)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-2 text-slate-700",children:n.user}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("a",{href:`/facility/${n.ccn}`,target:"_blank",rel:"noopener noreferrer",className:"text-sky-600 hover:underline",children:n.facility})}),e.jsx("td",{className:"px-4 py-2 text-slate-500",children:n.state}),e.jsx("td",{className:"px-4 py-2 text-slate-500 text-xs",children:n.chain||"—"}),e.jsx("td",{className:"px-4 py-2 text-slate-400 text-xs",children:n.added?.slice(0,10)})]},x))})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-slate-200",children:e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:"Digest Email History"})}),t.digests.length>0?e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"User"}),e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"Email"}),e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"Snapshot"}),e.jsx("th",{scope:"col",className:"text-left px-4 py-2 text-xs font-semibold text-slate-500",children:"Sent"}),e.jsx("th",{scope:"col",className:"text-right px-4 py-2 text-xs font-semibold text-slate-500",children:"Facilities"}),e.jsx("th",{scope:"col",className:"text-right px-4 py-2 text-xs font-semibold text-slate-500",children:"Changes"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:t.digests.map((n,x)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-2 text-slate-700",children:n.user}),e.jsx("td",{className:"px-4 py-2 text-slate-500",children:n.email}),e.jsx("td",{className:"px-4 py-2 text-slate-500",children:n.snapshot}),e.jsx("td",{className:"px-4 py-2 text-slate-400 text-xs",children:n.sent_at?.slice(0,16).replace("T"," ")}),e.jsx("td",{className:"px-4 py-2 text-right",children:n.facilities}),e.jsx("td",{className:"px-4 py-2 text-right font-medium",children:n.changes})]},x))})]}):e.jsx("p",{className:"px-4 py-6 text-center text-slate-400 text-sm",children:"No digests sent yet"})]})]}):null}function H({label:t,value:p,sub:n,status:x}){const l={good:"border-emerald-200 bg-emerald-50",warn:"border-amber-200 bg-amber-50",bad:"border-red-200 bg-red-50",neutral:"border-slate-200 bg-white"};return e.jsxs("div",{className:`rounded-xl border p-4 ${l[x]||l.neutral}`,children:[e.jsx("p",{className:"text-xs font-medium text-slate-500 uppercase tracking-wide",children:t}),e.jsx("p",{className:"text-xl font-bold mt-1 text-slate-800",children:p}),n&&e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:n})]})}function Et(){const{data:t,isLoading:p}=q({queryKey:["system-health"],queryFn:et});if(p)return e.jsxs("div",{className:"flex items-center gap-2 text-slate-400 py-12 justify-center",children:[e.jsx(_,{size:18,className:"animate-spin"})," Loading..."]});if(!t)return e.jsx("p",{className:"text-slate-400 text-center py-12",children:"No health data available. Run: python tools/run_tests.py"});const n=t.live_freshness||{},x=t.runs||[],l=x[0],y=n.cms?.days_old<=35?"good":n.cms?.days_old<=50?"warn":"bad",h=n.ai_summaries?.coverage_pct||0,j=h>=99?"good":h>=95?"warn":"bad",g=l?l.failed===0&&l.errors===0?"good":"bad":"neutral",b={};for(const i of x){const a=i.data_freshness?._source||(i.notes?.startsWith("perf-monitor")?"perf-monitor":"run-tests");!b[a]&&new Date(l.run_at)-new Date(i.run_at)<36*3600*1e3&&(b[a]=i)}const d=Object.values(b).flatMap(i=>i.data_freshness?._flags||[]);return e.jsxs("div",{className:"space-y-6",children:[d.length>0&&e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-4",children:[e.jsxs("p",{className:"text-xs font-semibold text-amber-800 uppercase tracking-wide mb-2",children:["Warnings (",d.length,")"]}),e.jsx("ul",{className:"space-y-1",children:d.map((i,a)=>e.jsxs("li",{className:"text-xs text-amber-800 font-mono",children:["• ",i]},a))})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-slate-700 mb-3",children:"Live Data Freshness"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(H,{label:"CMS Snapshot",value:n.cms?.latest||"—",sub:n.cms?.days_old!=null?`${n.cms.days_old} days old`:"",status:y}),e.jsx(H,{label:"AI Summaries",value:`${h}
5%`,sub:`${n.ai_summaries?.summaries?.toLocaleString()||"?"} / ${n.ai_summaries?.facilities?.toLocaleString()||"?"}`,status:j}),e.jsx(H,{label:"PBJ Staffing",value:n.pbj?.latest_quarter||"—",sub:"Latest quarter",status:"neutral"}),e.jsx(H,{label:"Job Postings",value:n.jobs?.active_postings?.toLocaleString()||"—",sub:"Active listings",status:"neutral"}),e.jsx(H,{label:"Surveys Pulled",value:n.surveys?.parsed?.toLocaleString()||"0",sub:`${n.surveys?.queued?.toLocaleString()||"?"} remaining`,status:"neutral"}),e.jsx(H,{label:"Narratives",value:n.surveys?.narratives?.toLocaleString()||"0",sub:"Citation narratives",status:"neutral"})]})]}),l&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-slate-700 mb-3",children:"Latest Test Run"}),e.jsxs("div",{className:`rounded-xl border p-5 ${g==="good"?"border-emerald-200 bg-emerald-50":"border-red-200 bg-red-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx("span",{className:`text-2xl font-bold ${g==="good"?"text-emerald-700":"text-red-700"}`,children:g==="good"?"ALL TESTS PASSING":`${l.failed} FAILURES`}),e.jsxs("span",{className:"text-sm text-slate-600",children:[l.passed," passed, ",l.xfailed||0," xfail, ",l.errors||0," errors"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:[l.duration_seconds,"s · ",new Date(l.run_at).toLocaleString()]})]}),l.failures&&l.failures.length>0&&e.jsx("div",{className:"mt-3 space-y-1",children:l.failures.map((i,a)=>e.jsx("p",{className:"text-xs font-mono text-red-700 bg-red-100 rounded px-2 py-1",children:i},a))})]})]}),l?.data_freshness?._performance&&!l.data_freshness._performance._error&&e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-semibold text-slate-700 mb-3",children:["Endpoint Performance ",e.jsx("span",{className:"font-normal text-slate-400",children:"(cold cache, last run)"})]}),e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsx("tr",{children:["Endpoint","Response","Budget","Status"].map(i=>e.jsx("th",{scope:"col",className:"text-left px-4 py-2.5 text-xs font-semibold text-slate-600 uppercase tracking-wide",children:i},i))})}),e.jsx("tbody",{className:"divide-y divide-slate-50",children:Object.entries(l.data_freshness._performance).map(([i,a])=>e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-2.5 text-xs text-slate-600",children:i}),e.jsx("td",{className:`px-4 py-2.5 text-xs tabular-nums font-medium ${a.ok?"text-slate-700":"text-red-600"}`,children:a.ms!=null?`${a.ms.toLocaleString()}ms`:"ERR"}),e.jsxs("td",{className:"px-4 py-2.5 text-xs tabular-nums text-slate-400",children:[a.budget_ms?.toLocaleString(),"ms"]}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full ${a.ok?"bg-emerald-100 text-emerald-700":"bg-red-100 text-red-700"}`,children:a.ok?"OK":a.status!==200?`HTTP ${a.status}`:"SLOW"})})]},i))})]})})]}),x.length>1&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-slate-700 mb-3",children:"Test Run History"}),e.jsx("div",{className:"bg-white rounded-xl border border-slate-200 overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsx("tr",{children:["When","Duration","Passed","Failed","XFail","Errors","Status"].map(i=>e.jsx("th",{scope:"col",className:"text-left px-4 py-2.5 text-xs font-semibold text-slate-600 uppercase tracking-wide",children:i},i))})}),e.jsx("tbody",{className:"divide-y divide-slate-50",children:x.map(i=>{const a=i.failed===0&&i.errors===0;return e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-4 py-2.5 text-xs text-slate-500",children:new Date(i.run_at).toLocaleString()}),e.jsxs("td",{className:"px-4 py-2.5 text-xs tabular-nums",children:[i.duration_seconds,"s"]}),e.jsx("td",{className:"px-4 py-2.5 text-xs tabular-nums text-emerald-600 font-medium",children:i.passed}),e.jsx("td",{className:`px-4 py-2.5 text-xs tabular-nums font-medium ${i.failed>0?"text-red-600":"text-slate-400"}`,children:i.failed}),e.jsx("td",{className:"px-4 py-2.5 text-xs tabular-nums text-slate-400",children:i.xfailed||0}),e.jsx("td",{className:`px-4 py-2.5 text-xs tabular-nums ${i.errors>0?"text-red-600":"text-slate-400"}`,children:i.errors||0}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full ${a?"bg-emerald-100 text-emerald-700":"bg-red-100 text-red-700"}`,children:a?"PASS":"FAIL"})})]},i.id)})})]})})]}),!l&&e.jsxs("div",{className:"text-center py-8 text-slate-400 text-sm",children:["No test runs recorded yet. Run: ",e.jsx("code",{className:"bg-slate-100 px-2 py-1 rounded",children:"python tools/run_tests.py"})]})]})}const Mt=[30,90,180];function Ut({x:t,y:p,width:n,height:x,index:l,payload:y,containerWidth:h}){const j=(y.name||"").replace("Facility · ","Fac·").replace("Chain · ","Chn·"),g=t<h*.12,b=t>h*.82;let d,i,a;return g?(d=t-6,i=p+x/2,a="end"):b?(d=t+n+6,i=p+x/2,a="start"):(d=t+n/2,i=p-4,a="middle"),e.jsxs(tt,{children:[e.jsx(at,{x:t,y:p,width:n,height:x,fill:"#0284c7",fillOpacity:.85}),e.jsx("text",{textAnchor:a,x:d,y:i,dy:a==="middle"?0:"0.35em",fontSize:"10.5",fill:"#334155",children:j})]},`node-${l}`)}function Ot({graph:t}){if(!t||t.nodes.length<2||!t.links.length)return e.jsx("div",{className:"text-sm text-slate-400 py-8 text-center",children:"Not enough traffic to draw a network yet."});const p=780,n=480,x=p/2,l=n/2,y=165,h=t.nodes.length,j=Math.max(...t.nodes.map(i=>i.visits)),g=Math.max(...t.links.map(i=>i.value)),b={};
5t.nodes.forEach((i,a)=>{const u=-Math.PI/2+a/h*2*Math.PI;b[i.page]={x:x+y*Math.cos(u),y:l+y*Math.sin(u),r:6+20*Math.sqrt(i.visits/j),a:u,node:i}});const d=i=>i.replace("Facility · ","Fac·").replace("Chain · ","Chn·");return e.jsxs("svg",{viewBox:`0 0 ${p} ${n}`,className:"w-full",style:{maxHeight:"70vh"},children:[e.jsx("defs",{children:e.jsx("marker",{id:"nf-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:e.jsx("path",{d:"M0,0 L10,5 L0,10 z",fill:"#0284c7",fillOpacity:"0.5"})})}),t.links.map((i,a)=>{const u=b[i.source],o=b[i.target];if(!u||!o)return null;const v=(u.x+o.x)/2,w=(u.y+o.y)/2,$=o.x-u.x,P=o.y-u.y,L=Math.hypot($,P)||1,c=L*.16,f={x:v-P/L*c,y:w+$/L*c},N=Math.atan2(o.y-f.y,o.x-f.x),S=o.x-Math.cos(N)*(o.r+2),X=o.y-Math.sin(N)*(o.r+2);return e.jsx("path",{d:`M${u.x},${u.y} Q${f.x},${f.y} ${S},${X}`,fill:"none",stroke:"#0284c7",strokeOpacity:.28,strokeWidth:1+6*(i.value/g),markerEnd:"url(#nf-arrow)",children:e.jsx("title",{children:`${i.source} → ${i.target}: ${i.value}`})},a)}),t.nodes.map(i=>{const a=b[i.page],u=a.x+Math.cos(a.a)*(a.r+6),o=a.y+Math.sin(a.a)*(a.r+6),v=Math.cos(a.a)>.15?"start":Math.cos(a.a)<-.15?"end":"middle";return e.jsxs("g",{children:[e.jsx("circle",{cx:a.x,cy:a.y,r:a.r,fill:"#0284c7",fillOpacity:.85,children:e.jsx("title",{children:`${i.page}: ${i.visits} visits`})}),e.jsx("text",{x:u,y:o,dy:"0.35em",textAnchor:v,fontSize:"10.5",fill:"#334155",children:d(i.page)})]},i.page)})]})}const Bt=t=>t==null?null:t>=60?`${Math.floor(t/60)}m ${Math.round(t%60)}s`:`${Math.round(t)}s`;function pe({rows:t,invert:p}){const n=Math.max(1,...t.map(l=>l.count)),x=t.some(l=>l.dwell_s!=null);return e.jsx("div",{className:"space-y-1",children:t.map(l=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-40 shrink-0 truncate text-slate-600",title:l.page,children:l.page}),e.jsx("div",{className:"flex-1 h-4 bg-slate-100 rounded-sm overflow-hidden",children:e.jsx("div",{className:`h-full rounded-sm ${p?"bg-amber-400":"bg-sky-500"}`,style:{width:`${l.count/n*100}%`}})}),x&&e.jsx("div",{className:"w-14 shrink-0 text-right tabular-nums text-slate-400",title:"median time on page",children:Bt(l.dwell_s)||"—"}),e.jsxs("div",{className:"w-16 shrink-0 text-right tabular-nums text-slate-500",children:[l.count,l.pct!=null&&e.jsxs("span",{className:"text-slate-400",children:[" · ",l.pct,"%"]})]})]},l.page))})}function It(){const[t,p]=m.useState(90),[n,x]=m.useState("sankey"),[l,y]=m.useState(!1),{data:h,isLoading:j,isError:g}=q({queryKey:["admin-nav-flow",t,l],queryFn:()=>st(t,l),staleTime:300*1e3}),b=h?.meta,d=h?.flow,i=d&&d.links&&d.links.length>0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-slate-500",children:"Window"}),e.jsx("div",{className:"flex items-center rounded-md border border-slate-200 overflow-hidden",children:Mt.map(a=>e.jsxs("button",{onClick:()=>p(a),className:`text-xs px-2.5 py-1 font-medium transition-colors ${t===a?"bg-slate-800 text-white":"text-slate-500 hover:text-sky-600"}`,children:[a,"d"]},a))}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-slate-500 cursor-pointer select-none",title:"Admins are a large share of internal navigation and skew how customers actually use the site — excluded by default.",children:[e.jsx("input",{type:"checkbox",checked:l,onChange:a=>y(a.target.checked),className:"accent-sky-600"}),"Include admins"]}),b&&e.jsxs("span",{className:"text-xs text-slate-400",children:[b.sessions.toLocaleString()," sessions · ",b.users," users · ",b.events.toLocaleString()," events"]}),b&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${b.source==="pageviews"?"bg-emerald-50 text-emerald-700 border border-emerald-200":"bg-slate-100 text-slate-500 border border-slate-200"}`,title:b.source==="pageviews"?"True page views from the beacon — exact, with time on page":"Derived from the API-activity log — approximate, no time-on-page yet",children:b.source==="pageviews"?"page views":"API activity"})]}),j&&e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(_,{className:"animate-spin text-sky-500",size:20})}),g&&e.jsx("div",{className:"text-sm text-red-500 py-8 text-center",children:"Could not load navigation flow."}),!j&&!g&&h&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-3",children:"Funnel — did sessions reach value?"}),e.jsx("div",{className:"flex flex-col sm:flex-row gap-3 mb-4",children:h.funnel.steps.map((a,u)=>e.jsxs("div",{className:"flex-1 bg-slate-50 border border-slate-200 rounded-lg px-4 py-3",children:[e.jsxs("div",{className:"text-2xl font-bold text-slate-800 tabular-nums",children:[a.pct,"%"]}),e.jsx("div",{className:"text-[11px] text-slate-500 mt-0.5",children:a.label}),e.jsxs("div",{className:"text-[11px] text-slate-400",children:[a.count.toLocaleStr
5ing()," sessions",u>0&&h.funnel.steps[0].count?` of ${h.funnel.steps[0].count.toLocaleString()}`:""]})]},a.label))}),h.funnel.money_pages.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wide text-slate-400 mb-1.5",children:"Which money pages get reached"}),e.jsx(pe,{rows:h.funnel.money_pages})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:n==="sankey"?"Where sessions go next":"Page network — hubs & links"}),e.jsx("p",{className:"text-[11px] text-slate-400 mb-3",children:n==="sankey"?`Reads left → right: landing page, then the next pages. Band width = sessions. Flows below ${b?.min_flow} are hidden.`:"Each bubble is a page, sized by total visits; arrows show where sessions move next, thickness = how often. Bigger, more-connected bubbles are the hubs."})]}),e.jsx("div",{className:"flex items-center rounded-md border border-slate-200 overflow-hidden shrink-0",children:[["sankey","Flow"],["network","Network"]].map(([a,u])=>e.jsx("button",{onClick:()=>x(a),className:`text-xs px-2.5 py-1 font-medium transition-colors ${n===a?"bg-slate-800 text-white":"text-slate-500 hover:text-sky-600"}`,children:u},a))})]}),n==="sankey"?i?e.jsx(he,{width:"100%",height:Math.max(340,d.nodes.length*22),children:e.jsx(dt,{data:d,nodePadding:16,nodeWidth:10,node:e.jsx(Ut,{}),link:{stroke:"#0284c7",strokeOpacity:.18},margin:{left:70,right:100,top:18,bottom:10},children:e.jsx(ue,{formatter:a=>[`${a} sessions`,"flow"]})})}):e.jsx("div",{className:"text-sm text-slate-400 py-8 text-center",children:"Not enough multi-page sessions in this window to draw a flow."}):e.jsx(Ot,{graph:h.graph})]}),e.jsxs("div",{className:"grid md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-1",children:"Entry pages"}),e.jsx("p",{className:"text-[11px] text-slate-400 mb-3",children:"Where sessions start."}),e.jsx(pe,{rows:h.entries})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-1",children:"Exit pages"}),e.jsx("p",{className:"text-[11px] text-slate-400 mb-3",children:"The last page before leaving."}),e.jsx(pe,{rows:h.exits})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-1",children:"Dead-ends"}),e.jsx("p",{className:"text-[11px] text-slate-400 mb-3",children:"High exit rate = people often leave from here."}),e.jsx("div",{className:"space-y-1",children:h.dead_ends.map(a=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-32 shrink-0 truncate text-slate-600",title:a.page,children:a.page}),e.jsx("div",{className:"flex-1 h-4 bg-slate-100 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm bg-amber-400",style:{width:`${a.exit_rate}%`}})}),e.jsxs("div",{className:"w-20 shrink-0 text-right tabular-nums text-slate-500",children:[a.exit_rate,"%",e.jsxs("span",{className:"text-slate-400",children:[" ·",a.visits]})]})]},a.page))})]})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:b?.source==="pageviews"?e.jsx(e.Fragment,{children:"True page views from the beacon: one row per page a user actually saw, with time on page. Sessions split on a 30-minute gap; repeat views collapsed. Median time-on-page shows beside each list."}):e.jsx(e.Fragment,{children:"Derived from the API-activity log (not true page views) until the page-view beacon accumulates enough data, so it’s approximate: each session is a user’s calls split on a 30-minute gap, mapped to pages, repeats collapsed. Facility/chain tabs load on click, so those are real navigation; pure client-side moves that hit no API are invisible. The beacon is now live — this switches to exact page views (and time-on-page) automatically once ~200 views are logged in the window."})})]})]})}function Zt(){const[t,p]=m.useState("metrics");return e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-800",children:"Admin"}),e.jsx("p",{className:"text-slate-500 text-sm mt-1",children:"User management and activity monitoring"})]}),e.jsx("div",{className:"flex gap-1 bg-slate-100 rounded-lg p-1 
5w-fit mb-6",children:wt.map(n=>e.jsx("button",{onClick:()=>p(n.key),className:`px-4 py-2 rounded-md text-sm font-medium transition-colors ${t===n.key?"bg-white text-slate-800 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:n.label},n.key))}),t==="metrics"&&e.jsx(Ct,{}),t==="activity"&&e.jsx(zt,{}),t==="flow"&&e.jsx(It,{}),t==="users"&&e.jsx(Lt,{}),t==="engagement"&&e.jsx(Tt,{}),t==="requests"&&e.jsx(qt,{}),t==="changes"&&e.jsx(Pt,{}),t==="rate-flags"&&e.jsx(Rt,{}),t==="health"&&e.jsx(Et,{})]})}export{Zt 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.