import{an as k,r as j,j as e,ap as w,Q as C,af as f,q as m,S as _,B as d,L as E}from"./index-Dbk1Plmn.js";import{P as o}from"./page_shell-C0CL85dt.js";import{C as v,a as N,b as y,c as b}from"./card-CfjWPSFY.js";import{A as P}from"./agent_grant_form-BOodcTsk.js";import{e as G,f as I,g as L}from"./use_agents-DbRumskw.js";import{s as Q,a as B}from"./query_loading-BFETHugg.js";import{Q as R}from"./query_refresh_indicator-1_XqkpX1.js";import{A as z}from"./arrow-left-C_rgOt55.js";import"./label-BKULM0qV.js";import"./textarea-BDInZ0Bq.js";import"./select-B273iZTf.js";import"./index-dCMWtMMp.js";import"./Combination-DUY7QPO8.js";import"./index-D3OXdV3z.js";import"./chevron-down-BMaycUN9.js";import"./check-C3ZzJelL.js";import"./plus-DrFK9jPU.js";import"./trash-2-Bj69O07h.js";function D(c){switch(c){case"active":return"default";case"suspended":return"secondary";case"revoked":return"destructive";default:return"outline"}}function ae(){const{id:c}=k(),l=c??"",s=G(l),x=I(l),i=L(l),[A,h]=j.useState(null),[g,p]=j.useState(null);if(Q(s))return e.jsx(o,{title:"Agent grant",children:e.jsx(w,{})});if(s.error)return e.jsx(o,{title:"Agent grant",children:e.jsx(C,{title:"Could not load grant",children:s.error.message})});if(!s.data)return e.jsx(o,{title:"Agent grant",children:e.jsx("div",{className:"text-muted-foreground",children:"Grant not found."})});const t=s.data.grant,a=t.status;async function S(r){h(null);try{await x.mutateAsync(r)}catch(n){h(n instanceof Error?n.message:"Failed to update grant")}}async function u(r){p(null);try{await i.mutateAsync(r)}catch(n){p(n instanceof Error?n.message:"Failed to change grant status")}}return e.jsx(o,{title:t.label,description:e.jsxs("span",{children:["Edit the grant in place; status transitions are tracked as explicit observations on this ",e.jsx("code",{className:"font-mono",children:"agent_grant"})," ","entity. Identity changes are picked up by AAuth admission within one cache TTL."]}),actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[B(s)?e.jsx(R,{}):null,e.jsx(d,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(E,{to:"/agents/grants",children:[e.jsx(z,{className:"mr-1 h-4 w-4"}),"All grants"]})})]}),children:e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs(v,{className:"lg:col-span-2",children:[e.jsx(N,{children:e.jsx(y,{children:"Identity & capabilities"})}),e.jsx(b,{children:e.jsx(P,{initial:t,submitLabel:"Save changes",isSubmitting:x.isPending,errorMessage:A,onSubmit:r=>S(r)})})]}),e.jsxs(v,{children:[e.jsxs(N,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(y,{children:"Status"}),e.jsx(f,{variant:D(a),children:a})]}),e.jsxs(b,{className:"space-y-4",children:[e.jsxs("dl",{className:"grid grid-cols-1 gap-x-4 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]",children:[e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Grant ID"}),e.jsx("dd",{className:"break-all font-mono",children:t.grant_id})]}),e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Owner user"}),e.jsx("dd",{className:"break-all font-mono",children:t.user_id})]}),e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Created"}),e.jsx("dd",{children:m(t.created_at??void 0)})]}),e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Last used"}),e.jsx("dd",{children:m(t.last_used_at??void 0)})]}),e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Last observation"}),e.jsx("dd",{children:m(t.last_observation_at??void 0)})]}),t.import_source&&e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Import source"}),e.jsx("dd",{children:e.jsx(f,{variant:"outline",children:t.import_source})})]})]}),e.jsx(_,{}),e.jsxs("div",{className:"grid gap-2",children:[a!=="active"&&e.jsx(d,{type:"button",variant:"default",size:"sm",disabled:i.isPending,onClick:()=>u("active"),children:"Restore to active"}),a==="active"&&e.jsx(d,{type:"button",variant:"secondary",size:"sm",disabled:i.isPending,onClick:()=>u("suspended"),children:"Suspend"}),a!=="revoked"&&e.jsx(d,{type:"button",variant:"destructive",size:"sm",disabled:i.isPending,onClick:()=>u("revoked"),children:"Revoke"})]}),g&&e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:g})]})]})]})})}export{ae as default};
