1import{ac as N,y as v,ad as w,x as S,r as m,j as t,u as k}from"./main-CYl_zR7c.js";import{D}from"./DashboardShell-ky05UZmJ.js";import{S as U}from"./search-CrNI2gWP.js";import{A as C,a as A,b as $}from"./arrow-up-BEjDz8by.js";import"./getStaffMe-ClcgGEqe.js";function _(e){return e.endsWith("/")?e.slice(0,-1):e}async function E(e={}){const l=e.fetchImpl??fetch,a=_(e.baseUrl??""),s=new URLSearchParams;e.page&&s.set("page",String(e.page)),e.limit&&s.set("limit",String(e.limit)),e.search&&s.set("search",e.search),e.sortBy&&s.set("sortBy",e.sortBy),e.sortDir&&s.set("sortDir",e.sortDir);const i=s.toString(),o=`${a}/internal/users${i?`?${i}`:""}`,n=await l(o,{credentials:"include",headers:e.headers});if(!n.ok)throw new N(n.status,`Failed to load users (${n.status})`);return await n.json()}function I(e){return v({queryKey:["internal","users",e],queryFn:()=>E({baseUrl:S,...e}),placeholderData:w,staleTime:15e3})}const h=25,b=[{key:"email",label:"User",sortable:!1},{key:"created_at",label:"Joined",sortable:!0},{key:"orgCount",label:"Orgs",sortable:!1,align:"right"},{key:"lifetime_credits_used",label:"Lifetime credits used",sortable:!0,align:"right"},{key:"last_active_at",label:"Last active",sortable:!0}];function f(e){return e?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"â"}function L(e){if(!e)return"â";const l=Date.now()-new Date(e).getTime();if(l<0)return f(e);const a=Math.floor(l/6e4);if(a<1)return"Just now";if(a<60)return`${a}m ago`;const s=Math.floor(l/36e5);if(s<24)return`${s}h ago`;const i=Math.floor(l/864e5);return i<30?`${i}d ago`:f(e)}function d(e){return e.toLocaleString("en-US")}function P(){const[e,l]=m.useState(""),[a,s]=m.useState(1),[i,o]=m.useState({by:"created_at",dir:"desc"}),{data:n,isLoading:x,isError:y,isFetching:p}=I({page:a,limit:h,search:e.trim()||void 0,sortBy:i.by,sortDir:i.dir}),g=r=>{o(c=>c.by!==r?{by:r,dir:"desc"}:{by:r,dir:c.dir==="desc"?"asc":"desc"}),s(1)},j=r=>{l(r),s(1)};return t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"relative flex-1 max-w-sm",children:[t.jsx(U,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-(--text-muted)"}),t.jsx("input",{type:"search",value:e,onChange:r=>j(r.target.value),placeholder:"Search by email or display nameâ¦",className:"w-full rounded-[12px] border border-(--border-subtle) bg-(--surface-overlay) py-2 pl-9 pr-3 text-sm text-(--text-primary) placeholder:text-(--text-muted) focus:outline-none focus:ring-2 focus:ring-(--ring)"})]}),t.jsx("span",{className:"text-xs text-(--text-muted)",children:x?"Loadingâ¦":n?`${d(n.total)} total${p?" · refreshing":""}`:null})]}),y?t.jsx("div",{className:"rounded-[16px] border border-(--border-subtle) px-6 py-10 text-center",children:t.jsx("p",{className:"text-sm text-(--text-secondary)",children:"Couldn't load users. Try again in a moment."})}):t.jsx("div",{className:"overflow-x-auto rounded-[16px] border border-(--border-subtle) [scrollbar-width:thin]",children:t.jsxs("table",{className:"w-full min-w-[720px] text-sm",children:[t.jsx("thead",{children:t.jsx("tr",{className:"border-b border-(--border-subtle) text-left text-xs font-medium text-(--text-muted)",children:b.map(r=>{const u=r.sortable&&i.by===r.key?i.dir==="desc"?C:A:$;return t.jsx("th",{className:`px-4 py-3 ${r.align==="right"?"text-right":""}`,children:r.sortable?t.jsxs("button",{type:"button",onClick:()=>g(r.key),className:`inline-flex items-center gap-1 ${r.align==="right"?"flex-row-reverse":""} hover:text-(--text-primary)`,children:[t.jsx("span",{children:r.label}),t.jsx(u,{className:"size-3"})]}):r.label},r.key)})})}),t.jsx("tbody",{children:x?Array.from({length:6}).map((r,c)=>t.jsx("tr",{className:"border-b border-(--border-subtle) last:border-0",children:b.map(u=>t.jsx("td",{className:"px-4 py-4",children:t.jsx("div",{className:"h-4 w-24 animate-pulse rounded bg-(--surface-overlay)"})},u.key))},`skeleton-${c}`)):!n||n.users.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:b.length,className:"px-4 py-10 text-center text-sm text-(--text-muted)",children:"No users match this search."})}):n.users.map(r=>
1t.jsx(B,{user:r},r.id))})]})}),n&&n.total>h&&t.jsx(M,{page:a,limit:h,total:n.total,onChange:s,disabled:p})]})}function B({user:e}){const l=k(),a=()=>l({to:"/internal/users/$userId",params:{userId:e.id}});return t.jsxs("tr",{role:"link",tabIndex:0,onClick:a,onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),a())},className:"cursor-pointer border-b border-(--border-subtle) last:border-0 hover:bg-(--surface-overlay) focus:bg-(--surface-overlay) focus:outline-none",children:[t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-(--text-primary)",children:e.displayName||e.email||e.id}),e.displayName&&e.email&&t.jsx("span",{className:"text-xs text-(--text-muted)",children:e.email})]})}),t.jsx("td",{className:"px-4 py-3 text-(--text-secondary)",children:f(e.createdAt)}),t.jsx("td",{className:"px-4 py-3 text-right text-(--text-secondary)",children:e.orgCount}),t.jsx("td",{className:"px-4 py-3 text-right text-(--text-secondary) tabular-nums",children:d(e.lifetimeCreditsUsed)}),t.jsx("td",{className:"px-4 py-3 text-xs text-(--text-muted)",children:L(e.lastActiveAt)})]})}function M({page:e,limit:l,total:a,onChange:s,disabled:i}){const o=Math.max(1,Math.ceil(a/l)),n=(e-1)*l+1,x=Math.min(e*l,a);return t.jsxs("div",{className:"flex items-center justify-between text-xs text-(--text-muted)",children:[t.jsxs("span",{children:["Showing ",d(n),"â",d(x)," of"," ",d(a)]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:i||e<=1,onClick:()=>s(e-1),className:"rounded-[10px] border border-(--border-subtle) px-3 py-1.5 text-xs text-(--text-secondary) enabled:hover:bg-(--surface-overlay) disabled:opacity-40",children:"Previous"}),t.jsxs("span",{className:"tabular-nums",children:["Page ",e," / ",o]}),t.jsx("button",{type:"button",disabled:i||e>=o,onClick:()=>s(e+1),className:"rounded-[10px] border border-(--border-subtle) px-3 py-1.5 text-xs text-(--text-secondary) enabled:hover:bg-(--surface-overlay) disabled:opacity-40",children:"Next"})]})]})}function T(){return t.jsx(D,{activeTab:"users",children:t.jsx("section",{className:"flex flex-col gap-6",children:t.jsx(P,{})})})}const J=T;export{J as component};
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.