import{i as e}from"./rolldown-runtime-B1FJdls4.js";import{m as t}from"./vendor-dnd-C1cICjTT.js";import{s as n}from"./vendor-markdown-Db1-9wH7.js";import{t as r}from"./sessionStore-DVOX7Q2x.js";import{l as i}from"./issueStore-B3ra7txM.js";import{t as a}from"./AgentGraph-BpBNQR1R.js";var o=e(t(),1),s=n();function c(e){return typeof window>`u`?null:new URLSearchParams(window.location.search).get(e)}function l(){let e=r(e=>e.sessions),t=i(e=>e.issues),n=c(`issue`),l=(0,o.useMemo)(()=>{let r=Array.from(e.values()),i=new Map,a=new Map,o=e=>e.parent_session_id?!0:r.some(t=>t.parent_session_id===e.id);for(let t of r){if(!o(t))continue;let r=t.issue_id??null;if(!(n&&r!==n))if(r){let e=i.get(r)??[];e.push({id:t.id,session:t}),i.set(r,e)}else{let n=t.id,r=t,i=0;for(;r?.parent_session_id&&i++<20;){let t=e.get(r.parent_session_id);if(!t)break;n=t.id,r=t}let o=a.get(n)??[];o.push({id:t.id,session:t}),a.set(n,o)}}let s=[];for(let[e,n]of i.entries()){let r=t.get(e);s.push({key:`issue-${e}`,title:r?.title??`Issue ${e.slice(0,8)}`,sessions:n})}for(let[t,n]of a.entries()){let r=e.get(t);s.push({key:`root-${t}`,title:r?.title??`Session ${t.slice(0,8)}`,sessions:n})}return s.sort((e,t)=>t.sessions.length-e.sessions.length),s},[e,t,n]),u=l.reduce((e,t)=>e+t.sessions.length,0),d=l.reduce((e,t)=>e+t.sessions.filter(e=>e.session.awaiting_approval?!1:e.session.status===`active`||e.session.task_status===`in_progress`||e.session.task_status===`todo`).length,0);return(0,s.jsxs)(`div`,{className:`h-screen-safe flex flex-col bg-terminal-bg text-terminal-text overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`shrink-0 border-b border-terminal-border/60 bg-terminal-surface/50 backdrop-blur px-4 py-2.5 flex items-center justify-between`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,s.jsx)(`button`,{type:`button`,onClick:()=>{window.location.href=`/`},className:`text-[10px] font-mono text-terminal-muted hover:text-terminal-accent transition-colors`,title:`Back to Axis`,children:`← Axis`}),(0,s.jsx)(`div`,{className:`w-px h-4 bg-terminal-border/60`}),(0,s.jsx)(`h1`,{className:`text-[13px] font-mono font-semibold text-terminal-text tracking-wide`,children:`Agent Graph`}),n&&(0,s.jsxs)(`span`,{className:`text-[10px] font-mono text-terminal-muted bg-terminal-bg/60 px-1.5 py-0.5 rounded border border-terminal-border/40`,children:[`issue: `,t.get(n)?.title?.slice(0,40)??n.slice(0,12)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-4 text-[10px] font-mono text-terminal-muted`,children:[(0,s.jsxs)(`span`,{children:[(0,s.jsx)(`span`,{className:`text-terminal-text`,children:l.length}),` clusters`]}),(0,s.jsxs)(`span`,{children:[(0,s.jsx)(`span`,{className:`text-terminal-text`,children:u}),` sessions`]}),(0,s.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,s.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-cyan-400 animate-pulse`}),(0,s.jsx)(`span`,{className:`text-cyan-400 font-semibold`,children:d}),` running`]})]})]}),(0,s.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:l.length===0?(0,s.jsx)(`div`,{className:`h-full flex items-center justify-center text-[11px] font-mono text-terminal-muted/50 text-center`,children:(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`div`,{className:`text-[13px] mb-1 text-terminal-muted`,children:`No parent/child sessions yet.`}),(0,s.jsx)(`div`,{children:`Spawn sub-agents from any issue's detail view to see the graph light up.`})]})}):(0,s.jsx)(`div`,{className:l.length===1?`h-full`:`grid gap-4`,style:l.length>1?{gridTemplateColumns:`repeat(auto-fit, minmax(480px, 1fr))`}:void 0,children:l.map(e=>{let t=l.length===1?Math.max(480,window.innerHeight-120):360;return(0,s.jsxs)(`div`,{className:`flex flex-col bg-terminal-surface/40 border border-terminal-border/40 rounded overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`shrink-0 px-3 py-1.5 border-b border-terminal-border/40 flex items-center justify-between`,children:[(0,s.jsx)(`div`,{className:`text-[11px] font-mono text-terminal-text truncate`,children:e.title}),(0,s.jsxs)(`div`,{className:`text-[9px] font-mono text-terminal-muted shrink-0 ml-2`,children:[e.sessions.length,` sessions`]})]}),(0,s.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,s.jsx)(a,{sessions:e.sessions,height:t,onNodeClick:e=>{window.location.href=`/?session=${e.id}`}})})]},e.key)})})})]})}export{l as AgentGraphPage};