1import{j as e,A as D,m as z}from"./motion-_9tYDDrE.js";import{r as a,R as O}from"./router-DgXk3emn.js";import{D as F}from"./DashboardLayout-DhzVAC15.js";import{u as B}from"./index-DIAuxmTy.js";import{fetchUserTeams as G,fetchPendingApprovals as U,fetchApprovalHistory as K,fetchEscalationPolicies as Y,escalateRequest as J,rejectRequest as Q,approveRequest as X,emergencyIntervene as V}from"./dashboardApi-CPzdTPhA.js";import{C as s}from"./theme-CTp28l_V.js";import{n as W,aK as Z,R as q,bo as M,L as H,C as ee,a as R,z as se,a6 as te,as as le,am as re,bv as ae}from"./ui-utils-BBU9YQ_R.js";import"./ThemeToggle-Zb3SARUx.js";import"./axios-BHfmyy3F.js";const P={low:{color:s.green,label:"Low"},medium:{color:s.yellow,label:"Medium"},high:{color:s.orange,label:"High"},critical:{color:s.red,label:"Critical"}},L={action:{color:s.accent,label:"Action"},spawn:{color:s.purple,label:"Spawn"},budget_override:{color:s.yellow,label:"Budget Override"},data_access:{color:s.cyan,label:"Data Access"},policy_exception:{color:s.orange,label:"Policy Exception"},emergency:{color:s.red,label:"Emergency"}};function T(l){if(!l)return"â";const o=(Date.now()-new Date(l).getTime())/1e3;return o<60?`${Math.round(o)}s ago`:o<3600?`${Math.round(o/60)}m ago`:`${Math.round(o/3600)}h ago`}function oe(l){if(!l)return null;const o=new Date(l).getTime()-Date.now();if(o<0)return{label:"Expired",color:s.red};const d=Math.round(o/6e4);return d<60?{label:`${d}m left`,color:d<15?s.red:s.yellow}:{label:`${Math.round(d/60)}h left`,color:s.green}}const ne=({request:l,onApprove:o,onReject:d,onEscalate:m})=>{const[f,g]=a.useState(!1),[u,b]=a.useState(""),[y,v]=a.useState(""),[w,j]=a.useState(!1),[i,n]=a.useState(!1),N=P[l.risk_level]??{color:s.muted,label:l.risk_level},k=L[l.type]??{color:s.muted,label:l.type},x=oe(l.deadline),C=l.approvals.length,p=l.requires_approvers,$=l.status==="pending",A=async()=>{n(!0);try{await o(l.id,u)}finally{n(!1)}},_=async()=>{if(y.trim()){n(!0);try{await d(l.id,y)}finally{n(!1)}}};return e.jsxs(z.div,{layout:!0,className:"rounded-xl border overflow-hidden",style:{background:s.card,borderColor:l.risk_level==="critical"?`${s.red}40`:s.border},children:[e.jsxs("button",{className:"w-full flex items-center gap-3 p-4 text-left",onClick:()=>g(c=>!c),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:l.title}),e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded",style:{background:`${N.color}15`,color:N.color},children:N.label}),e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded",style:{background:`${k.color}15`,color:k.color},children:k.label}),x&&e.jsxs("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded flex items-center gap-1",style:{background:`${x.color}15`,color:x.color},children:[e.jsx(se,{size:9})," ",x.label]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px]",style:{color:s.muted},children:[e.jsx("span",{children:l.requested_by_agent_name}),e.jsx("span",{children:T(l.created_at)}),e.jsxs("span",{children:[C,"/",p," approvals"]})]})]}),e.jsx(te,{size:14,className:`flex-shrink-0 transition-transform ${f?"rotate-180":""}`,style:{color:s.muted}})]}),e.jsx(D,{children:f&&e.jsxs(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"border-t px-4 pb-4 overflow-hidden",style:{borderColor:s.border},children:[e.jsx("p",{className:"text-xs mt-3 leading-relaxed",style:{color:s.muted},children:l.description}),Object.keys(l.payload).length>0&&e.jsxs("div",{className:"mt-3 rounded-lg p-3",style:{background:`${s.muted}06`},children:[e.jsx("p",{className:"text-[10px] font-mono font-bold uppercase tracking-wider mb-1.5",style:{color:s.muted},children:"Payload"}),e.jsx("pre",{className:"text-[10px] font-mono overflow-x-auto",style:{color:s.muted},children:JSON.stringify(l.payload,null,2).slice(0,300)})]}),l.escalation_path.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-[10px] font-mono uppercase tracking-wider mb-1.5",style:{color:s.muted},children:"Escalation Path"}),e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:l.escalation_path.map((c,S)=>e.jsxs(O.Fragment,{children:[e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded border",style:{borderColor:s.border,color:s.muted},children:c}),S<l.escalation_path.length-1&&e.jsx(le,{size:10,style:{color:s.muted}})]},c))})]}),l.approvals.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("p",{className:"text-[10px] font-mono uppercase tracking-wider mb-1.5",style:{color:s.green},children:["Approvals (",l.approvals.length,")"]}),l.approvals.map(c=>e.jsxs("div",{className:"flex items-center gap-2 text-[10px] mb-1",children:[e.jsx(R,{size:11,style:{color:s.green}}),e.jsx("span",{className:"text-fg",children:c.user_email}),e.jsx("span",{style:{color:s.muted},children:T(c.approved_at)}),c.comment&&e.jsxs("span",{style:{color:s.muted},children:["· ",c.comment]})]}
1,c.user_id))]}),$&&e.jsx("div",{className:"mt-4 space-y-3",children:w?e.jsxs("div",{className:"space-y-2",children:[e.jsx("textarea",{placeholder:"Rejection reason (required)â¦",value:y,onChange:c=>v(c.target.value),className:"w-full px-3 py-2 rounded-lg text-xs border outline-none text-fg resize-none h-20",style:{background:s.bg,borderColor:`${s.red}30`}}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:_,disabled:!y.trim()||i,className:"flex-1 py-2 rounded-lg text-xs font-bold disabled:opacity-50",style:{background:s.red,color:"#fff"},children:i?"Rejectingâ¦":"Confirm Reject"}),e.jsx("button",{onClick:()=>j(!1),className:"px-4 py-2 rounded-lg text-xs border",style:{borderColor:s.border,color:s.muted},children:"Cancel"})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{type:"text",placeholder:"Optional commentâ¦",value:u,onChange:c=>b(c.target.value),className:"w-full px-3 py-1.5 rounded-lg text-xs border outline-none text-fg",style:{background:s.bg,borderColor:s.border}}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:A,disabled:i,className:"flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg text-xs font-bold disabled:opacity-50",style:{background:s.green,color:"#000"},children:[i?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(R,{size:13}),"Approve"]}),e.jsxs("button",{onClick:()=>j(!0),disabled:i,className:"flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg text-xs font-bold",style:{background:`${s.red}15`,color:s.red},children:[e.jsx(re,{size:13})," Reject"]}),e.jsx("button",{onClick:()=>m(l.id),disabled:i,className:"px-3 py-2 rounded-lg text-xs font-bold",style:{background:`${s.yellow}15`,color:s.yellow},children:e.jsx(ae,{size:13})})]})]})}),!$&&e.jsx("div",{className:"mt-3",children:e.jsx("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded",style:{background:l.status==="approved"?`${s.green}15`:`${s.red}15`,color:l.status==="approved"?s.green:s.red},children:l.status.toUpperCase()})})]})})]})},ce=({teamId:l,onDone:o})=>{const[d,m]=a.useState(""),[f,g]=a.useState("kill"),[u,b]=a.useState(""),[y,v]=a.useState(!1),[w,j]=a.useState(!1),i=async()=>{if(!(!d||!u.trim())){v(!0);try{await V(l,d,f,u),j(!0),setTimeout(o,2e3)}catch{}finally{v(!1)}}};return e.jsxs("div",{className:"rounded-xl border p-5",style:{background:`${s.red}06`,borderColor:`${s.red}40`},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(M,{size:16,style:{color:s.red}}),e.jsx("h3",{className:"text-sm font-bold text-fg",children:"Emergency Intervention"}),e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded",style:{background:`${s.red}20`,color:s.red},children:"CRITICAL"})]}),w?e.jsxs("div",{className:"flex items-center gap-2 text-sm",style:{color:s.green},children:[e.jsx(R,{size:16})," Emergency action dispatched"]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",placeholder:"Agent IDâ¦",value:d,onChange:n=>m(n.target.value),className:"w-full px-3 py-2 rounded-lg text-xs border outline-none text-fg",style:{background:s.bg,borderColor:`${s.red}30`}}),e.jsxs("select",{value:f,onChange:n=>g(n.target.value),className:"w-full px-3 py-2 rounded-lg text-xs border outline-none text-fg",style:{background:s.bg,borderColor:`${s.red}30`},children:[e.jsx("option",{value:"kill",children:"Kill Agent"}),e.jsx("option",{value:"pause",children:"Pause Agent"}),e.jsx("option",{value:"quarantine",children:"Quarantine"}),e.jsx("option",{value:"revoke_tokens",children:"Revoke All Tokens"})]}),e.jsx("textarea",{placeholder:"Reason for emergency intervention (required)â¦",value:u,onChange:n=>b(n.target.value),className:"w-full px-3 py-2 rounded-lg text-xs border outline-none text-fg resize-none h-20",style:{background:s.bg,borderColor:`${s.red}30`}}),e.jsx("button",{onClick:i,disabled:!d||!u.trim()||y,className:"w-full py-2 rounded-lg text-sm font-bold disabled:opacity-50",style:{background:s.red,color:"#fff"},children:y?"Sendingâ¦":"DISPATCH EMERGENCY ACTION"})]})]})},fe=()=>{const{user:l}
1=B(),[o,d]=a.useState(null),[m,f]=a.useState([]),[g,u]=a.useState([]),[b,y]=a.useState([]),[v,w]=a.useState(!0),[j,i]=a.useState(null),[n,N]=a.useState("pending"),[k,x]=a.useState(null),C=a.useRef(null);a.useEffect(()=>{l&&G().then(t=>{const r=t.data[0];r&&d(r.id)}).catch(()=>{})},[l]);const p=a.useCallback(async()=>{if(o)try{const[t,r,h]=await Promise.allSettled([U(o),K(o,50),Y(o)]);t.status==="fulfilled"&&f(t.value.data),r.status==="fulfilled"&&u(r.value.data),h.status==="fulfilled"&&y(h.value.data),i(null)}catch{i("Failed to load approval data")}finally{w(!1)}},[o]);a.useEffect(()=>(p(),C.current=setInterval(p,8e3),()=>{C.current&&clearInterval(C.current)}),[p]);const $=async(t,r)=>{await X(t,r),x("Approved"),setTimeout(()=>x(null),2500),await p()},A=async(t,r)=>{await Q(t,r),x("Rejected"),setTimeout(()=>x(null),2500),await p()},_=async t=>{await J(t),x("Escalated"),setTimeout(()=>x(null),2500),await p()},c=m.filter(t=>t.risk_level==="critical").length,S=[{id:"pending",label:"Pending",count:m.length},{id:"history",label:"History",count:g.length},{id:"policies",label:"Escalation Policies",count:b.length},{id:"emergency",label:"Emergency",count:0}];return e.jsxs(F,{children:[e.jsxs("div",{className:"p-6 lg:p-8 max-w-7xl mx-auto space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center border",style:{background:"var(--primary-wash)",borderColor:"var(--primary-wash)"},children:e.jsx(W,{size:20,style:{color:s.accent}})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h1",{className:"text-xl font-black uppercase tracking-tight text-fg font-mono",children:"Human Governance"}),e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded",style:{background:"var(--primary-wash)",color:"var(--primary)"},children:"P6"})]}),e.jsx("p",{className:"text-sm mt-0.5",style:{color:s.muted},children:"4-eye approvals · delegated authority · escalation trees · emergency intervention"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg border animate-pulse",style:{background:`${s.red}12`,borderColor:`${s.red}40`,color:s.red},children:[e.jsx(Z,{size:13})," ",c," Critical"]}),e.jsx("button",{onClick:p,className:"p-2 rounded-lg border",style:{borderColor:s.border,color:s.muted,background:s.card},children:e.jsx(q,{size:14})})]})]}),e.jsx("div",{role:"tablist",className:"flex gap-1 p-1 rounded-xl border",style:{background:s.card,borderColor:s.border},children:S.map(t=>e.jsxs("button",{onClick:()=>N(t.id),role:"tab","aria-selected":n===t.id,className:"flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg text-xs font-medium transition-all",style:{background:n===t.id?t.id==="emergency"?`${s.red}15`:`${s.accent}15`:"transparent",color:n===t.id?t.id==="emergency"?s.red:s.accent:s.muted},children:[t.id==="emergency"&&e.jsx(M,{size:12}),t.label,t.count>0&&e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded-full",style:{background:t.count>0&&m.some(r=>r.risk_level==="critical")?`${s.red}30`:`${s.muted}20`},children:t.count})]},t.id))}),v?e.jsxs("div",{className:"flex items-center justify-center py-20 gap-3",style:{color:s.muted},children:[e.jsx(H,{size:20,className:"animate-spin"}),e.jsx("span",{className:"text-sm",children:"Loading approval queueâ¦"})]}):j?e.jsxs("div",{className:"flex items-center justify-center py-16 gap-2 text-sm",style:{color:s.red},children:[e.jsx(ee,{size:16})," ",j]}):e.jsxs(e.Fragment,{children:[n==="pending"&&(m.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 rounded-2xl border-2 border-dashed",style:{borderColor:s.border},children:[e.jsx(R,{size:32,style:{color:s.green,opacity:.5}}),e.jsx("p",{className:"text-sm mt-3",style:{color:s.muted},children:"No pending approvals"})]}):e.jsx("div",{className:"space-y-3",children:m.map(t=>e.jsx(ne,{request:t,onApprove:$,onReject:A,onEscalate:_},t.id))})),n==="history"&&(g.length===0?e.jsx("div",{className:"text-center py-16 text-sm",style:{color:s.muted},children:"No approval history"}):e.jsxs("div",{className:"rounded-xl border overflow-hidden",style:{background:s.
1card,borderColor:s.border},children:[e.jsx("div",{className:"px-5 py-4 border-b",style:{borderColor:s.border},children:e.jsx("h2",{className:"text-[11px] font-mono font-bold uppercase tracking-widest text-fg",children:"Approval History"})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b",style:{borderColor:s.border},children:["Title","Type","Risk","Outcome","Agent","Time"].map(t=>e.jsx("th",{className:"px-4 py-3 text-left font-medium uppercase tracking-wider",style:{color:s.muted},children:t},t))})}),e.jsx("tbody",{children:g.map((t,r)=>{const h=P[t.risk_level]??{color:s.muted,label:t.risk_level},E=L[t.type]??{color:s.muted,label:t.type},I=t.status==="approved"?s.green:t.status==="rejected"?s.red:s.yellow;return e.jsxs("tr",{className:"border-b transition-colors hover:bg-white/[0.02]",style:{borderColor:r<g.length-1?s.border:"transparent"},children:[e.jsx("td",{className:"px-4 py-3.5 text-fg max-w-48 truncate",children:t.title}),e.jsx("td",{className:"px-4 py-3.5",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px]",style:{background:`${E.color}15`,color:E.color},children:E.label})}),e.jsx("td",{className:"px-4 py-3.5",children:e.jsx("span",{style:{color:h.color},children:h.label})}),e.jsx("td",{className:"px-4 py-3.5",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-bold",style:{background:`${I}15`,color:I},children:t.status})}),e.jsx("td",{className:"px-4 py-3.5",style:{color:s.muted},children:t.requested_by_agent_name}),e.jsx("td",{className:"px-4 py-3.5",style:{color:s.muted},children:T(t.created_at)})]},t.id)})})]})})]})),n==="policies"&&(b.length===0?e.jsx("div",{className:"text-center py-16 text-sm",style:{color:s.muted},children:"No escalation policies configured"}):e.jsx("div",{className:"space-y-4",children:b.map(t=>e.jsxs("div",{className:"rounded-xl border p-5",style:{background:s.card,borderColor:s.border},children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg",children:t.name}),e.jsx("div",{className:"flex gap-1 mt-1",children:t.risk_levels.map(r=>{const h=P[r];return e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{background:`${h.color}15`,color:h.color},children:h.label},r)})})]}),e.jsxs("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded border",style:{borderColor:s.border,color:s.muted},children:["Fallback: ",t.fallback_action]})]}),e.jsx("div",{className:"space-y-2",children:t.steps.map(r=>e.jsxs("div",{className:"flex items-center gap-3 p-2.5 rounded-lg",style:{background:`${s.muted}06`},children:[e.jsxs("span",{className:"text-[10px] font-mono font-bold w-6 text-center rounded",style:{background:`${s.accent}15`,color:s.accent},children:["L",r.level]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-[10px] text-fg",children:r.approvers.join(", ")})}),e.jsxs("span",{className:"text-[10px]",style:{color:s.muted},children:[r.timeout_minutes,"min"]}),r.auto_escalate&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{background:`${s.yellow}15`,color:s.yellow},children:"Auto-escalate"})]},r.level))})]},t.id))})),n==="emergency"&&o&&e.jsx(ce,{teamId:o,onDone:()=>{p(),N("pending")}})]})]}),e.jsx(D,{children:k&&e.jsx(z.div,{initial:{opacity:0,x:60},animate:{opacity:1,x:0},exit:{opacity:0,x:60},className:"fixed bottom-6 right-6 px-4 py-3 rounded-xl border text-sm font-medium shadow-xl z-50",style:{background:s.card,borderColor:`${s.green}40`,color:s.green},children:k})})]})};export{fe as HumanApprovals};
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.