import{u as b,j as e,k as j,p as C,c as m,B as f,C as k,a as N,b as E,d as w,T as q,q as $,l as v,m as I}from"./index-DXI13nSQ.js";import{r as M}from"./react-Cb2sDjhD.js";import{X as R}from"./x-OHUicFfn.js";import{E as L}from"./empty-state-WHzNYVaT.js";import{u as K}from"./useQuery-CEwGD94N.js";import{u as O}from"./use-event-stream-DgGpGKop.js";import{L as Q}from"./loader-circle-BS5FFFg-.js";import{R as _}from"./refresh-ccw-BPKXoMZa.js";function z({approval:s,onResolve:t,busy:a=!1,className:l}){const{t:n}=b("approvals"),u=B(s.ageMs),o=F(s.input,12);return e.jsxs("div",{className:m("flex flex-col gap-3","rounded-md border bg-surface p-4",s.ageMs>9e4?"border-danger/60":"border-border",l),children:[e.jsxs("header",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium text-text",children:s.toolName}),e.jsx(j,{variant:"secondary",children:s.platform}),s.autoAllow&&e.jsx(j,{variant:"info",title:n("autoAllowedTitle"),children:n("autoAllowedTag")}),e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-xs text-text-dim",children:[s.ageMs>9e4&&e.jsx(C,{className:"h-3 w-3 text-danger"}),u]})]}),e.jsxs("div",{className:"flex flex-col gap-1 text-xs",children:[e.jsx("div",{className:"text-text-muted",children:n("threadLabel")}),e.jsx("code",{className:"rounded bg-surface-2 px-1.5 py-0.5 font-mono text-xs text-text-dim line-clamp-1",title:s.threadId,children:s.threadId})]}),e.jsx("pre",{className:m("max-h-48 overflow-auto rounded-md","bg-surface-2 px-2 py-2","font-mono text-xs leading-5 text-text-dim","whitespace-pre-wrap break-words"),children:o}),e.jsxs("footer",{className:"flex justify-end gap-2",children:[e.jsxs(f,{type:"button",variant:"destructive",size:"sm",disabled:a,onClick:()=>void t("deny"),children:[e.jsx(R,{className:"h-4 w-4"}),n("deny")]}),e.jsxs(f,{type:"button",size:"sm",disabled:a,onClick:()=>void t("allow"),children:[e.jsx(k,{className:"h-4 w-4"}),n("allow")]})]})]})}function B(s){if(s<1e3)return`${s}ms`;const t=Math.floor(s/1e3);if(t<60)return`${t}s`;const a=Math.floor(t/60);return a<60?`${a}m`:`${Math.floor(a/60)}h`}function F(s,t){let a;try{a=JSON.stringify(s,null,2)}catch{a=String(s)}const l=a.split(`
`);return l.length<=t?a:`${l.slice(0,t).join(`
`)}
… +${l.length-t} more`}const p={all:["approvals"],list:["approvals","list"]};function D(){return K({queryKey:p.list,queryFn:()=>w.listApprovals()})}function J(){const s=N();return()=>s.invalidateQueries({queryKey:p.all})}function P(){const s=N();return E({mutationFn:({reqId:t,body:a})=>w.resolveApproval(t,a),onSuccess:()=>s.invalidateQueries({queryKey:p.all})})}const U={connected:"text-success",connecting:"text-text-dim",reconnecting:"text-warning",closed:"text-text-muted"};function ae(){const{t:s}=b(["approvals","common"]),t=J(),{data:a,isLoading:l,isFetching:n,refetch:u}=D(),o=a?.pending??[],i=a?.metrics,h=O({approval:()=>t()}),y=P(),[A,g]=M.useState(null);async function S(r,c){g(r);try{await y.mutateAsync({reqId:r,body:{behavior:c}}),v.success(s(c==="allow"?"toast.allowedShort":"toast.deniedShort"))}catch(d){const{message:T}=I(d,s);v.error(T)}finally{g(d=>d===r?null:d)}}return e.jsxs("div",{className:"flex min-h-dvh flex-col bg-bg",children:[e.jsx(q,{}),e.jsxs("main",{className:"mx-auto flex w-full max-w-5xl flex-1 flex-col gap-4 px-3 py-4 sm:px-4 pb-safe",children:[e.jsxs("header",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h1",{className:"text-xl font-semibold",children:s("pageTitle")}),e.jsx("span",{className:m("text-xs font-medium tabular-nums",U[h]),children:s(`live.${h}`)}),e.jsxs(f,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>u(),disabled:n,"aria-label":s("actions.refresh",{ns:"common"}),children:[n?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:s("actions.refresh",{ns:"common"})})]})]}),e.jsx("p",{className:"text-sm text-text-dim",children:s("subtitle")})]}),i&&e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsx(x,{label:s("stats.pending"),value:i.pending,tone:"info"}),e.jsx(x,{label:s("stats.totalAllowed"),value:i.totalAllowed,tone:"success"}),e.jsx(x,{label:s("stats.totalDenied"),value:i.totalDenied,tone:"danger"}),e.jsx(x,{label:s("stats.totalTimedOut"),value:i.totalTimedOut,tone:"warning"})]}),l?e.jsx(X,{}):o.length===0?e.jsx(L,{icon:e.jsx($,{}),title:s("empty.title"),description:s("empty.description")}):e.jsx("div",{className:"flex flex-col gap-3",children:o.map(r=>e.jsx(z,{approval:r,busy:A===r.reqId,onResolve:c=>S(r.reqId,c)},r.reqId))})]})]})}const V={info:"border-info/30    text-info",success:"border-success/30 text-success",warning:"border-warning/30 text-warning",danger:"border-danger/30  text-danger"};function x({label:s,value:t,tone:a}){return e.jsxs("div",{className:m("rounded-md border bg-surface px-3 py-2",V[a]),children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-text-dim",children:s}),e.jsx("div",{className:"text-2xl font-semibold tabular-nums",children:t})]})}function X(){return e.jsx("div",{className:"flex flex-col gap-3",children:Array.from({length:2}).map((s,t)=>e.jsxs("div",{className:"flex flex-col gap-3 rounded-md border border-border bg-surface p-4",children:[e.jsx("div",{className:"h-4 w-1/3 rounded bg-surface-2 animate-pulse"}),e.jsx("div",{className:"h-3 w-1/2 rounded bg-surface-2 animate-pulse"}),e.jsx("div",{className:"h-24 w-full rounded bg-surface-2 animate-pulse"}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[e.jsx("div",{className:"h-8 w-16 rounded bg-surface-2 animate-pulse"}),e.jsx("div",{className:"h-8 w-16 rounded bg-surface-2 animate-pulse"})]})]},`skel-${t}`))})}export{ae as default};
//# sourceMappingURL=approvals-BZULwrl5.js.map
