import{u as A,e as O,j as t,k as F,B as I,L as P,I as k,c as B}from"./index-DXI13nSQ.js";import{r as i}from"./react-Cb2sDjhD.js";import{D as _}from"./data-table-BVcXWtPw.js";import{E as U}from"./empty-state-WHzNYVaT.js";import{b as $}from"./use-observability-Bum0mmDO.js";import{L as q}from"./loader-circle-BS5FFFg-.js";import{R as z}from"./refresh-ccw-BPKXoMZa.js";import{A as H}from"./activity-B5erGuWa.js";import"./table-oUi0mGOn.js";import"./arrow-up-DtrvOH7Z.js";import"./arrow-down-OdSfpgG4.js";import"./useQuery-CEwGD94N.js";const G=300;function nt(){const{t:e}=A(["observability","common"]),[s,d]=O(),c=Math.max(1,Number(s.get("days"))||7),n=s.get("agent")??"",l=s.get("platform")??"",r=s.get("user")??"",o=s.get("intent")??"",[u,j]=i.useState(n),[x,b]=i.useState(l),[f,w]=i.useState(r),[h,C]=i.useState(o);i.useEffect(()=>{j(n)},[n]),i.useEffect(()=>{b(l)},[l]),i.useEffect(()=>{w(r)},[r]),i.useEffect(()=>{C(o)},[o]),i.useEffect(()=>{const a=window.setTimeout(()=>{R({agent:u||null,platform:x||null,user:f||null,intent:h||null})},G);return()=>window.clearTimeout(a)},[u,x,f,h]);const E=i.useMemo(()=>({days:c,limit:200,...n?{agent:n}:{},...l?{platform:l}:{},...r?{user:r}:{},...o?{intent:o}:{}}),[c,n,l,r,o]),{data:v,isLoading:S,isFetching:y,refetch:M}=$(E),L=v?.invocations??[],p=v?.stats;function R(a){const g=new URLSearchParams(s);for(const[D,N]of Object.entries(a))N==null||N===""?g.delete(D):g.set(D,N);d(g,{replace:!0})}const T=i.useMemo(()=>[{id:"ts",header:e("audit.col.ts"),cell:a=>t.jsx("span",{className:"text-text-dim text-xs tabular-nums",children:J(a.ts)}),headClassName:"w-32"},{id:"agent",header:e("audit.col.agent"),cell:a=>t.jsx("span",{className:"font-medium",children:a.agent}),headClassName:"w-32"},{id:"platform",header:e("audit.col.platform"),cell:a=>t.jsx("span",{className:"text-text-dim",children:a.platform}),headClassName:"w-24",hideOnMobile:!0},{id:"user",header:e("audit.col.user"),cell:a=>t.jsx("span",{className:"font-mono text-xs text-text-dim line-clamp-1",children:a.user_id}),headClassName:"w-32",hideOnMobile:!0},{id:"intent",header:e("audit.col.intent"),cell:a=>t.jsx("span",{className:"text-text-dim line-clamp-1",children:a.intent||"—"}),asCardTitle:!0},{id:"duration",header:e("audit.col.duration"),cell:a=>t.jsxs("span",{className:"tabular-nums text-text-dim",children:[Math.round(a.duration_ms),"ms"]}),headClassName:"w-20"},{id:"cost",header:e("audit.col.cost"),cell:a=>t.jsxs("span",{className:"tabular-nums text-text-dim",children:["$",a.cost.toFixed(4)]}),headClassName:"w-24",hideOnMobile:!0},{id:"outcome",header:e("audit.col.outcome"),cell:a=>t.jsx(F,{variant:a.success?"success":"danger",title:a.error??"",children:a.success?e("audit.outcome.ok"):e("audit.outcome.fail")}),headClassName:"w-20"}],[e]);return t.jsxs("div",{className:"mx-auto flex max-w-7xl flex-col gap-4",children:[t.jsx("header",{className:"flex flex-col gap-1",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[t.jsx("h1",{className:"text-xl font-semibold",children:e("audit.title")}),t.jsxs(I,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>M(),disabled:y,"aria-label":e("actions.refresh",{ns:"common"}),children:[y?t.jsx(q,{className:"h-4 w-4 animate-spin"}):t.jsx(z,{className:"h-4 w-4"}),t.jsx("span",{className:"hidden sm:inline",children:e("actions.refresh",{ns:"common"})})]})]})}),p&&t.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[t.jsxs("span",{className:"text-text-dim",children:[e("audit.stats.total"),": ",t.jsx("span",{className:"tabular-nums font-medium text-text",children:p.total})]}),t.jsxs("span",{className:"text-text-dim",children:[e("audit.stats.totalCost"),": ",t.jsxs("span",{className:"tabular-nums font-medium text-text",children:["$",p.totalCost.toFixed(4)]})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[t.jsx(m,{id:"agent",label:e("audit.filter.agent"),value:u,onChange:j}),t.jsx(m,{id:"platform",label:e("audit.filter.platform"),value:x,onChange:b}),t.jsx(m,{id:"user",label:e("audit.filter.user"),value:f,onChange:w}),t.jsx(m,{id:"intent",label:e("audit.filter.intent"),value:h,onChange:C})]}),t.jsx(_,{columns:T,rows:L,getRowId:a=>String(a.id),loading:S,emptyState:t.jsx(U,{icon:t.jsx(H,{}),title:e("audit.empty.title"),description:e("audit.empty.description")})})]})}function m({id:e,label:s,value:d,onChange:c}){return t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx(P,{htmlFor:e,className:"text-xs text-text-dim",children:s}),t.jsx(k,{id:e,value:d,onChange:n=>c(n.target.value),className:B("h-9")})]})}function J(e){try{const s=new Date(e);return Number.isNaN(s.getTime())?e:s.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return e}}export{nt as default};
//# sourceMappingURL=audit-CSk2rv6z.js.map
