import{$ as e,A as t,D as n,E as r,H as i,I as a,J as o,K as s,M as c,O as l,Q as u,U as ee,V as d,X as f,Y as p,at as m,et as h,lt as g,ot as _,ut as v,v as te,x as ne}from"../chunks/DyGQ_VXC.js";import"../chunks/CQCxd1p9.js";import{t as re}from"../chunks/wI_OOyoh.js";import{l as y}from"../chunks/CqF5Lomf.js";import{_ as b,f as x,i as S,t as C}from"../chunks/BgPpRtmk.js";import{n as w,t as T}from"../chunks/v8nUY1ct.js";var E=t(`<!> <!>`,1),ie=t(`<div class="board-error svelte-exy7zz" role="alert"><p> </p></div>`),ae=t(`<div class="board-host svelte-exy7zz"><!></div>`),oe=t(`<div role="status" aria-live="polite"> </div>`),se=t(`<div class="dispatch-overlay svelte-exy7zz"><!></div>`),ce=t(`<div class="dispatch-overlay svelte-exy7zz"><!> <div class="overlay-actions svelte-exy7zz"><!></div></div>`),le=t(`<div class="kanban-view svelte-exy7zz"><!> <!> <footer class="kanban-foot svelte-exy7zz"><span class="hint svelte-exy7zz">Drag to transition · Enter inspects · Dispatch spawns a worker (server-side)</span></footer></div> <!> <!>`,1);function D(t,D){_(D,!0);let O=T(),k=e(!1);ee(()=>(O.hydrate().then(()=>{u(k,!0)}),O.connect(),()=>O.disconnect()));let ue=h(()=>D.columns.map(e=>({lane:e.lane,count:e.count,cards:e.cards.map(t=>({...t,lane:e.lane.id}))}))),A=h(()=>a(k)?O.columns:a(ue)),j=h(()=>a(A).map(e=>e.lane)),M=h(()=>a(A).flatMap(e=>e.cards.map(e=>({...e,__lane:e.lane}))));function N(e){return e.__lane??`backlog`}let P=h(()=>a(k)?O.total:D.total),F=h(()=>a(k)?O.runningCount:a(M).filter(e=>e.workerActive).length),I=e(null),L=h(()=>a(I)?a(M).find(e=>e.id===a(I))??null:null),R=h(()=>a(L)?a(L).__lane:null),z=h(()=>a(L)!==null&&(a(R)===`backlog`||a(R)===`ready`)),B=h(()=>a(L)!==null&&a(R)===`running`),V=h(()=>a(L)?{id:a(L).id,title:a(L).title,description:a(L).title,status:a(L).status,priority:a(L).priority,size:a(L).size??void 0,createdAt:new Date().toISOString()}:null);function H(e){u(I,e,!0)}function U(){u(I,null)}let W=e(null),G=null;function K(e,t){u(W,{kind:e,message:t},!0),G&&clearTimeout(G),G=setTimeout(()=>{u(W,null)},4200)}let q=e(!1);async function de(e,t,n){let r=t,i=n,a=S(e,r,i);if(!a.ok){K(`err`,a.message);return}let o=await O.move(e,r,i);if(!o.ok){K(`err`,o.message);return}K(`ok`,a.plan.summary)}async function fe(e){if(!a(L))return;let t=a(L).id;u(q,!0);try{let n=await O.dispatch(t,e);if(!n.ok){K(`err`,n.message);return}K(`ok`,`Dispatched ${t} → worker spawning`)}finally{u(q,!1)}}let J=h(()=>a(k)&&O.connected),pe=h(()=>`${a(P)} tasks · ${a(j).length} lanes${a(F)>0?` · ${a(F)} running`:``}${a(J)?` · live`:``}`);var Y=le();ne(`exy7zz`,e=>{d(()=>{s.title=`Dispatcher Board — CLEO Studio`})});var X=p(Y),Z=o(X);re(Z,{eyebrow:`DISPATCHER`,title:`Agent Lifecycle Board`,subtitle:`Drag cards between lanes to transition · Dispatch Backlog/Ready cards to spawn a worker · watch Running cards live.`,get meta(){return a(pe)},get liveIndicator(){return a(J)},actions:e=>{var t=E(),n=p(t);y(n,{variant:`ghost`,size:`sm`,href:`/tasks`,children:(e,t)=>{g(),l(e,c(`← Tasks`))},$$slots:{default:!0}}),y(f(n,2),{variant:`ghost`,size:`sm`,href:`/tasks/pipeline`,children:(e,t)=>{g(),l(e,c(`Pipeline`))},$$slots:{default:!0}}),l(e,t)},$$slots:{actions:!0}});var me=f(Z,2),he=e=>{var t=ie(),r=o(t),a=o(r);v(r),v(t),i(()=>n(a,`Could not load the board: ${D.error??``}`)),l(e,t)},ge=e=>{var t=ae();w(o(t),{get lanes(){return a(j)},get cards(){return a(M)},laneResolver:N,onSelect:H,onMove:de}),v(t),l(e,t)};r(me,e=>{D.error?e(he):e(ge,-1)}),g(2),v(X);var Q=f(X,2),$=e=>{var t=oe();let r;var s=o(t,!0);v(t),i(()=>{r=te(t,1,`toast svelte-exy7zz`,null,r,{err:a(W).kind===`err`}),n(s,a(W).message)}),l(e,t)};r(Q,e=>{a(W)&&e($)});var _e=f(Q,2),ve=e=>{var t=se();b(o(t),{get taskId(){return a(L).id},get title(){return a(L).title},get lane(){return a(R)},get busy(){return a(q)},onDispatch:fe,onClose:U}),v(t),l(e,t)},ye=e=>{var t=ce(),n=o(t);C(n,{get taskId(){return a(L).id}});var r=f(n,2);y(o(r),{variant:`ghost`,size:`sm`,onclick:U,children:(e,t)=>{g(),l(e,c(`Close stream`))},$$slots:{default:!0}}),v(r),v(t),l(e,t)},be=e=>{x(e,{get task(){return a(V)},onClose:U})};r(_e,e=>{a(z)&&a(L)&&a(R)?e(ve):a(B)&&a(L)?e(ye,1):a(V)&&e(be,2)}),l(t,Y),m()}function O(e,t){_(t,!0),D(e,{get columns(){return t.data.columns},get total(){return t.data.total},get error(){return t.data.error}}),m()}export{O as component};