@markus-global/cli 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,4 +58,4 @@ Step 3: Accept and execute tasks, report progress, and communicate with teammate
58
58
  `,`
59
59
  +`).split(`
60
60
  `)),x=h.reduce((g,b)=>g.concat(...b),[]);return[h,x]}return[[],[]]},[e]);return j.useEffect(()=>{const m=r?.target??iv,h=r?.actInsideInputWithModifier??!0;if(e!==null){const x=p=>{if(o.current=p.ctrlKey||p.metaKey||p.shiftKey||p.altKey,(!o.current||o.current&&!h)&&iw(p))return!1;const S=ov(p.code,f);if(c.current.add(p[S]),lv(u,c.current,!1)){const T=p.composedPath?.()?.[0]||p.target,E=T?.nodeName==="BUTTON"||T?.nodeName==="A";r.preventDefault!==!1&&(o.current||!E)&&p.preventDefault(),i(!0)}},g=p=>{const w=ov(p.code,f);lv(u,c.current,!0)?(i(!1),c.current.clear()):c.current.delete(p[w]),p.key==="Meta"&&c.current.clear(),o.current=!1},b=()=>{c.current.clear(),i(!1)};return m?.addEventListener("keydown",x),m?.addEventListener("keyup",g),window.addEventListener("blur",b),window.addEventListener("contextmenu",b),()=>{m?.removeEventListener("keydown",x),m?.removeEventListener("keyup",g),window.removeEventListener("blur",b),window.removeEventListener("contextmenu",b)}}},[e,i]),s}function lv(e,r,s){return e.filter(i=>s||i.length===r.size).some(i=>i.every(o=>r.has(o)))}function ov(e,r){return r.includes(e)?"code":"key"}const fO=()=>{const e=yn();return j.useMemo(()=>({zoomIn:r=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1.2,{duration:r?.duration}):Promise.resolve(!1)},zoomOut:r=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1/1.2,{duration:r?.duration}):Promise.resolve(!1)},zoomTo:(r,s)=>{const{panZoom:i}=e.getState();return i?i.scaleTo(r,{duration:s?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(r,s)=>{const{transform:[i,o,c],panZoom:u}=e.getState();return u?(await u.setViewport({x:r.x??i,y:r.y??o,zoom:r.zoom??c},s),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[r,s,i]=e.getState().transform;return{x:r,y:s,zoom:i}},setCenter:async(r,s,i)=>e.getState().setCenter(r,s,i),fitBounds:async(r,s)=>{const{width:i,height:o,minZoom:c,maxZoom:u,panZoom:f}=e.getState(),m=fx(r,i,o,c,u,s?.padding??.1);return f?(await f.setViewport(m,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(r,s={})=>{const{transform:i,snapGrid:o,snapToGrid:c,domNode:u}=e.getState();if(!u)return r;const{x:f,y:m}=u.getBoundingClientRect(),h={x:r.x-f,y:r.y-m},x=s.snapGrid??o,g=s.snapToGrid??c;return $o(h,i,g,x)},flowToScreenPosition:r=>{const{transform:s,domNode:i}=e.getState();if(!i)return r;const{x:o,y:c}=i.getBoundingClientRect(),u=zu(r,s);return{x:u.x+o,y:u.y+c}}}),[])};function Tw(e,r){const s=[],i=new Map,o=[];for(const c of e)if(c.type==="add"){o.push(c);continue}else if(c.type==="remove"||c.type==="replace")i.set(c.id,[c]);else{const u=i.get(c.id);u?u.push(c):i.set(c.id,[c])}for(const c of r){const u=i.get(c.id);if(!u){s.push(c);continue}if(u[0].type==="remove")continue;if(u[0].type==="replace"){s.push({...u[0].item});continue}const f={...c};for(const m of u)hO(m,f);s.push(f)}return o.length&&o.forEach(c=>{c.index!==void 0?s.splice(c.index,0,{...c.item}):s.push({...c.item})}),s}function hO(e,r){switch(e.type){case"select":{r.selected=e.selected;break}case"position":{typeof e.position<"u"&&(r.position=e.position),typeof e.dragging<"u"&&(r.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(r.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(r.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(r.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(r.resizing=e.resizing);break}}}function _w(e,r){return Tw(e,r)}function Aw(e,r){return Tw(e,r)}function Ya(e,r){return{id:e,type:"select",selected:r}}function Hi(e,r=new Set,s=!1){const i=[];for(const[o,c]of e){const u=r.has(o);!(c.selected===void 0&&!u)&&c.selected!==u&&(s&&(c.selected=u),i.push(Ya(c.id,u)))}return i}function cv({items:e=[],lookup:r}){const s=[],i=new Map(e.map(o=>[o.id,o]));for(const[o,c]of e.entries()){const u=r.get(c.id),f=u?.internals?.userNode??u;f!==void 0&&f!==c&&s.push({id:c.id,item:c,type:"replace"}),f===void 0&&s.push({item:c,type:"add",index:o})}for(const[o]of r)i.get(o)===void 0&&s.push({id:o,type:"remove"});return s}function uv(e){return{id:e.id,type:"remove"}}const dv=e=>IM(e),mO=e=>Jj(e);function Mw(e){return j.forwardRef(e)}const xO=typeof window<"u"?j.useLayoutEffect:j.useEffect;function fv(e){const[r,s]=j.useState(BigInt(0)),[i]=j.useState(()=>gO(()=>s(o=>o+BigInt(1))));return xO(()=>{const o=i.get();o.length&&(e(o),i.reset())},[r]),i}function gO(e){let r=[];return{get:()=>r,reset:()=>{r=[]},push:s=>{r.push(s),e()}}}const Dw=j.createContext(null);function pO({children:e}){const r=yn(),s=j.useCallback(f=>{const{nodes:m=[],setNodes:h,hasDefaultNodes:x,onNodesChange:g,nodeLookup:b,fitViewQueued:p,onNodesChangeMiddlewareMap:w}=r.getState();let S=m;for(const E of f)S=typeof E=="function"?E(S):E;let T=cv({items:S,lookup:b});for(const E of w.values())T=E(T);x&&h(S),T.length>0?g?.(T):p&&window.requestAnimationFrame(()=>{const{fitViewQueued:E,nodes:C,setNodes:N}=r.getState();E&&N(C)})},[]),i=fv(s),o=j.useCallback(f=>{const{edges:m=[],setEdges:h,hasDefaultEdges:x,onEdgesChange:g,edgeLookup:b}=r.getState();let p=m;for(const w of f)p=typeof w=="function"?w(p):w;x?h(p):g&&g(cv({items:p,lookup:b}))},[]),c=fv(o),u=j.useMemo(()=>({nodeQueue:i,edgeQueue:c}),[]);return t.jsx(Dw.Provider,{value:u,children:e})}function bO(){const e=j.useContext(Dw);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const yO=e=>!!e.panZoom;function yx(){const e=fO(),r=yn(),s=bO(),i=Vt(yO),o=j.useMemo(()=>{const c=g=>r.getState().nodeLookup.get(g),u=g=>{s.nodeQueue.push(g)},f=g=>{s.edgeQueue.push(g)},m=g=>{const{nodeLookup:b,nodeOrigin:p}=r.getState(),w=dv(g)?g:b.get(g.id),S=w.parentId?sw(w.position,w.measured,w.parentId,b,p):w.position,T={...w,position:S,width:w.measured?.width??w.width,height:w.measured?.height??w.height};return Ki(T)},h=(g,b,p={replace:!1})=>{u(w=>w.map(S=>{if(S.id===g){const T=typeof b=="function"?b(S):b;return p.replace&&dv(T)?T:{...S,...T}}return S}))},x=(g,b,p={replace:!1})=>{f(w=>w.map(S=>{if(S.id===g){const T=typeof b=="function"?b(S):b;return p.replace&&mO(T)?T:{...S,...T}}return S}))};return{getNodes:()=>r.getState().nodes.map(g=>({...g})),getNode:g=>c(g)?.internals.userNode,getInternalNode:c,getEdges:()=>{const{edges:g=[]}=r.getState();return g.map(b=>({...b}))},getEdge:g=>r.getState().edgeLookup.get(g),setNodes:u,setEdges:f,addNodes:g=>{const b=Array.isArray(g)?g:[g];s.nodeQueue.push(p=>[...p,...b])},addEdges:g=>{const b=Array.isArray(g)?g:[g];s.edgeQueue.push(p=>[...p,...b])},toObject:()=>{const{nodes:g=[],edges:b=[],transform:p}=r.getState(),[w,S,T]=p;return{nodes:g.map(E=>({...E})),edges:b.map(E=>({...E})),viewport:{x:w,y:S,zoom:T}}},deleteElements:async({nodes:g=[],edges:b=[]})=>{const{nodes:p,edges:w,onNodesDelete:S,onEdgesDelete:T,triggerNodeChanges:E,triggerEdgeChanges:C,onDelete:N,onBeforeDelete:k}=r.getState(),{nodes:H,edges:M}=await UM({nodesToRemove:g,edgesToRemove:b,nodes:p,edges:w,onBeforeDelete:k}),Y=M.length>0,$=H.length>0;if(Y){const X=M.map(uv);T?.(M),C(X)}if($){const X=H.map(uv);S?.(H),E(X)}return($||Y)&&N?.({nodes:H,edges:M}),{deletedNodes:H,deletedEdges:M}},getIntersectingNodes:(g,b=!0,p)=>{const w=Iy(g),S=w?g:m(g),T=p!==void 0;return S?(p||r.getState().nodes).filter(E=>{const C=r.getState().nodeLookup.get(E.id);if(C&&!w&&(E.id===g.id||!C.internals.positionAbsolute))return!1;const N=Ki(T?E:C),k=So(N,S);return b&&k>0||k>=N.width*N.height||k>=S.width*S.height}):[]},isNodeIntersecting:(g,b,p=!0)=>{const S=Iy(g)?g:m(g);if(!S)return!1;const T=So(S,b);return p&&T>0||T>=b.width*b.height||T>=S.width*S.height},updateNode:h,updateNodeData:(g,b,p={replace:!1})=>{h(g,w=>{const S=typeof b=="function"?b(w):b;return p.replace?{...w,data:S}:{...w,data:{...w.data,...S}}},p)},updateEdge:x,updateEdgeData:(g,b,p={replace:!1})=>{x(g,w=>{const S=typeof b=="function"?b(w):b;return p.replace?{...w,data:S}:{...w,data:{...w.data,...S}}},p)},getNodesBounds:g=>{const{nodeLookup:b,nodeOrigin:p}=r.getState();return $M(g,{nodeLookup:b,nodeOrigin:p})},getHandleConnections:({type:g,id:b,nodeId:p})=>Array.from(r.getState().connectionLookup.get(`${p}-${g}${b?`-${b}`:""}`)?.values()??[]),getNodeConnections:({type:g,handleId:b,nodeId:p})=>Array.from(r.getState().connectionLookup.get(`${p}${g?b?`-${g}-${b}`:`-${g}`:""}`)?.values()??[]),fitView:async g=>{const b=r.getState().fitViewResolver??YM();return r.setState({fitViewQueued:!0,fitViewOptions:g,fitViewResolver:b}),s.nodeQueue.push(p=>[...p]),b.promise}}},[]);return j.useMemo(()=>({...o,...e,viewportInitialized:i}),[i])}const hv=e=>e.selected,vO=typeof window<"u"?window:void 0;function jO({deleteKeyCode:e,multiSelectionKeyCode:r}){const s=yn(),{deleteElements:i}=yx(),o=Eo(e,{actInsideInputWithModifier:!1}),c=Eo(r,{target:vO});j.useEffect(()=>{if(o){const{edges:u,nodes:f}=s.getState();i({nodes:f.filter(hv),edges:u.filter(hv)}),s.setState({nodesSelectionActive:!1})}},[o]),j.useEffect(()=>{s.setState({multiSelectionActive:c})},[c])}function wO(e){const r=yn();j.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const i=hx(e.current);(i.height===0||i.width===0)&&r.getState().onError?.("004",ms.error004()),r.setState({width:i.width||500,height:i.height||500})};if(e.current){s(),window.addEventListener("resize",s);const i=new ResizeObserver(()=>s());return i.observe(e.current),()=>{window.removeEventListener("resize",s),i&&e.current&&i.unobserve(e.current)}}},[])}const nd={position:"absolute",width:"100%",height:"100%",top:0,left:0},NO=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function kO({onPaneContextMenu:e,zoomOnScroll:r=!0,zoomOnPinch:s=!0,panOnScroll:i=!1,panOnScrollSpeed:o=.5,panOnScrollMode:c=Qa.Free,zoomOnDoubleClick:u=!0,panOnDrag:f=!0,defaultViewport:m,translateExtent:h,minZoom:x,maxZoom:g,zoomActivationKeyCode:b,preventScrolling:p=!0,children:w,noWheelClassName:S,noPanClassName:T,onViewportChange:E,isControlledViewport:C,paneClickDistance:N,selectionOnDrag:k}){const H=yn(),M=j.useRef(null),{userSelectionActive:Y,lib:$,connectionInProgress:X}=Vt(NO,bn),P=Eo(b),q=j.useRef();wO(M);const F=j.useCallback(D=>{E?.({x:D[0],y:D[1],zoom:D[2]}),C||H.setState({transform:D})},[E,C]);return j.useEffect(()=>{if(M.current){q.current=_D({domNode:M.current,minZoom:x,maxZoom:g,translateExtent:h,viewport:m,onDraggingChange:A=>H.setState(G=>G.paneDragging===A?G:{paneDragging:A}),onPanZoomStart:(A,G)=>{const{onViewportChangeStart:U,onMoveStart:K}=H.getState();K?.(A,G),U?.(G)},onPanZoom:(A,G)=>{const{onViewportChange:U,onMove:K}=H.getState();K?.(A,G),U?.(G)},onPanZoomEnd:(A,G)=>{const{onViewportChangeEnd:U,onMoveEnd:K}=H.getState();K?.(A,G),U?.(G)}});const{x:D,y:_,zoom:I}=q.current.getViewport();return H.setState({panZoom:q.current,transform:[D,_,I],domNode:M.current.closest(".react-flow")}),()=>{q.current?.destroy()}}},[]),j.useEffect(()=>{q.current?.update({onPaneContextMenu:e,zoomOnScroll:r,zoomOnPinch:s,panOnScroll:i,panOnScrollSpeed:o,panOnScrollMode:c,zoomOnDoubleClick:u,panOnDrag:f,zoomActivationKeyPressed:P,preventScrolling:p,noPanClassName:T,userSelectionActive:Y,noWheelClassName:S,lib:$,onTransformChange:F,connectionInProgress:X,selectionOnDrag:k,paneClickDistance:N})},[e,r,s,i,o,c,u,f,P,p,T,Y,S,$,F,X,k,N]),t.jsx("div",{className:"react-flow__renderer",ref:M,style:nd,children:w})}const SO=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function CO(){const{userSelectionActive:e,userSelectionRect:r}=Vt(SO,bn);return e&&r?t.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:r.width,height:r.height,transform:`translate(${r.x}px, ${r.y}px)`}}):null}const Vh=(e,r)=>s=>{s.target===r.current&&e?.(s)},EO=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function TO({isSelecting:e,selectionKeyPressed:r,selectionMode:s=ko.Full,panOnDrag:i,paneClickDistance:o,selectionOnDrag:c,onSelectionStart:u,onSelectionEnd:f,onPaneClick:m,onPaneContextMenu:h,onPaneScroll:x,onPaneMouseEnter:g,onPaneMouseMove:b,onPaneMouseLeave:p,children:w}){const S=yn(),{userSelectionActive:T,elementsSelectable:E,dragging:C,connectionInProgress:N}=Vt(EO,bn),k=E&&(e||T),H=j.useRef(null),M=j.useRef(),Y=j.useRef(new Set),$=j.useRef(new Set),X=j.useRef(!1),P=U=>{if(X.current||N){X.current=!1;return}m?.(U),S.getState().resetSelectedElements(),S.setState({nodesSelectionActive:!1})},q=U=>{if(Array.isArray(i)&&i?.includes(2)){U.preventDefault();return}h?.(U)},F=x?U=>x(U):void 0,D=U=>{X.current&&(U.stopPropagation(),X.current=!1)},_=U=>{const{domNode:K}=S.getState();if(M.current=K?.getBoundingClientRect(),!M.current)return;const B=U.target===H.current;if(!B&&!!U.target.closest(".nokey")||!e||!(c&&B||r)||U.button!==0||!U.isPrimary)return;U.target?.setPointerCapture?.(U.pointerId),X.current=!1;const{x:R,y:z}=es(U.nativeEvent,M.current);S.setState({userSelectionRect:{width:0,height:0,startX:R,startY:z,x:R,y:z}}),B||(U.stopPropagation(),U.preventDefault())},I=U=>{const{userSelectionRect:K,transform:B,nodeLookup:L,edgeLookup:W,connectionLookup:R,triggerNodeChanges:z,triggerEdgeChanges:V,defaultEdgeOptions:Q,resetSelectedElements:te}=S.getState();if(!M.current||!K)return;const{x:Z,y:ee}=es(U.nativeEvent,M.current),{startX:ie,startY:je}=K;if(!X.current){const Ze=r?0:o;if(Math.hypot(Z-ie,ee-je)<=Ze)return;te(),u?.(U)}X.current=!0;const ke={startX:ie,startY:je,x:Z<ie?Z:ie,y:ee<je?ee:je,width:Math.abs(Z-ie),height:Math.abs(ee-je)},De=Y.current,Ie=$.current;Y.current=new Set(dx(L,ke,B,s===ko.Partial,!0).map(Ze=>Ze.id)),$.current=new Set;const ze=Q?.selectable??!0;for(const Ze of Y.current){const Ae=R.get(Ze);if(Ae)for(const{edgeId:We}of Ae.values()){const xt=W.get(We);xt&&(xt.selectable??ze)&&$.current.add(We)}}if(!$y(De,Y.current)){const Ze=Hi(L,Y.current,!0);z(Ze)}if(!$y(Ie,$.current)){const Ze=Hi(W,$.current);V(Ze)}S.setState({userSelectionRect:ke,userSelectionActive:!0,nodesSelectionActive:!1})},A=U=>{U.button===0&&(U.target?.releasePointerCapture?.(U.pointerId),!T&&U.target===H.current&&S.getState().userSelectionRect&&P?.(U),S.setState({userSelectionActive:!1,userSelectionRect:null}),X.current&&(f?.(U),S.setState({nodesSelectionActive:Y.current.size>0})))},G=i===!0||Array.isArray(i)&&i.includes(0);return t.jsxs("div",{className:Pn(["react-flow__pane",{draggable:G,dragging:C,selection:e}]),onClick:k?void 0:Vh(P,H),onContextMenu:Vh(q,H),onWheel:Vh(F,H),onPointerEnter:k?void 0:g,onPointerMove:k?I:b,onPointerUp:k?A:void 0,onPointerDownCapture:k?_:void 0,onClickCapture:k?D:void 0,onPointerLeave:p,ref:H,style:nd,children:[w,t.jsx(CO,{})]})}function Cm({id:e,store:r,unselect:s=!1,nodeRef:i}){const{addSelectedNodes:o,unselectNodesAndEdges:c,multiSelectionActive:u,nodeLookup:f,onError:m}=r.getState(),h=f.get(e);if(!h){m?.("012",ms.error012(e));return}r.setState({nodesSelectionActive:!1}),h.selected?(s||h.selected&&u)&&(c({nodes:[h],edges:[]}),requestAnimationFrame(()=>i?.current?.blur())):o([e])}function Ow({nodeRef:e,disabled:r=!1,noDragClassName:s,handleSelector:i,nodeId:o,isSelectable:c,nodeClickDistance:u}){const f=yn(),[m,h]=j.useState(!1),x=j.useRef();return j.useEffect(()=>{x.current=xD({getStoreItems:()=>f.getState(),onNodeMouseDown:g=>{Cm({id:g,store:f,nodeRef:e})},onDragStart:()=>{h(!0)},onDragStop:()=>{h(!1)}})},[]),j.useEffect(()=>{if(!(r||!e.current||!x.current))return x.current.update({noDragClassName:s,handleSelector:i,domNode:e.current,isSelectable:c,nodeId:o,nodeClickDistance:u}),()=>{x.current?.destroy()}},[s,i,r,c,e,o,u]),m}const _O=e=>r=>r.selected&&(r.draggable||e&&typeof r.draggable>"u");function Rw(){const e=yn();return j.useCallback(s=>{const{nodeExtent:i,snapToGrid:o,snapGrid:c,nodesDraggable:u,onError:f,updateNodePositions:m,nodeLookup:h,nodeOrigin:x}=e.getState(),g=new Map,b=_O(u),p=o?c[0]:5,w=o?c[1]:5,S=s.direction.x*p*s.factor,T=s.direction.y*w*s.factor;for(const[,E]of h){if(!b(E))continue;let C={x:E.internals.positionAbsolute.x+S,y:E.internals.positionAbsolute.y+T};o&&(C=Io(C,c));const{position:N,positionAbsolute:k}=Wj({nodeId:E.id,nextPosition:C,nodeLookup:h,nodeExtent:i,nodeOrigin:x,onError:f});E.position=N,E.internals.positionAbsolute=k,g.set(E.id,E)}m(g)},[])}const vx=j.createContext(null),AO=vx.Provider;vx.Consumer;const zw=()=>j.useContext(vx),MO=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),DO=(e,r,s)=>i=>{const{connectionClickStartHandle:o,connectionMode:c,connection:u}=i,{fromHandle:f,toHandle:m,isValid:h}=u,x=m?.nodeId===e&&m?.id===r&&m?.type===s;return{connectingFrom:f?.nodeId===e&&f?.id===r&&f?.type===s,connectingTo:x,clickConnecting:o?.nodeId===e&&o?.id===r&&o?.type===s,isPossibleEndHandle:c===Xi.Strict?f?.type!==s:e!==f?.nodeId||r!==f?.id,connectionInProcess:!!f,clickConnectionInProcess:!!o,valid:x&&h}};function OO({type:e="source",position:r=nt.Top,isValidConnection:s,isConnectable:i=!0,isConnectableStart:o=!0,isConnectableEnd:c=!0,id:u,onConnect:f,children:m,className:h,onMouseDown:x,onTouchStart:g,...b},p){const w=u||null,S=e==="target",T=yn(),E=zw(),{connectOnClick:C,noPanClassName:N,rfId:k}=Vt(MO,bn),{connectingFrom:H,connectingTo:M,clickConnecting:Y,isPossibleEndHandle:$,connectionInProcess:X,clickConnectionInProcess:P,valid:q}=Vt(DO(E,w,e),bn);E||T.getState().onError?.("010",ms.error010());const F=I=>{const{defaultEdgeOptions:A,onConnect:G,hasDefaultEdges:U}=T.getState(),K={...A,...I};if(U){const{edges:B,setEdges:L}=T.getState();L(WM(K,B))}G?.(K),f?.(K)},D=I=>{if(!E)return;const A=lw(I.nativeEvent);if(o&&(A&&I.button===0||!A)){const G=T.getState();Sm.onPointerDown(I.nativeEvent,{handleDomNode:I.currentTarget,autoPanOnConnect:G.autoPanOnConnect,connectionMode:G.connectionMode,connectionRadius:G.connectionRadius,domNode:G.domNode,nodeLookup:G.nodeLookup,lib:G.lib,isTarget:S,handleId:w,nodeId:E,flowId:G.rfId,panBy:G.panBy,cancelConnection:G.cancelConnection,onConnectStart:G.onConnectStart,onConnectEnd:(...U)=>T.getState().onConnectEnd?.(...U),updateConnection:G.updateConnection,onConnect:F,isValidConnection:s||((...U)=>T.getState().isValidConnection?.(...U)??!0),getTransform:()=>T.getState().transform,getFromHandle:()=>T.getState().connection.fromHandle,autoPanSpeed:G.autoPanSpeed,dragThreshold:G.connectionDragThreshold})}A?x?.(I):g?.(I)},_=I=>{const{onClickConnectStart:A,onClickConnectEnd:G,connectionClickStartHandle:U,connectionMode:K,isValidConnection:B,lib:L,rfId:W,nodeLookup:R,connection:z}=T.getState();if(!E||!U&&!o)return;if(!U){A?.(I.nativeEvent,{nodeId:E,handleId:w,handleType:e}),T.setState({connectionClickStartHandle:{nodeId:E,type:e,id:w}});return}const V=aw(I.target),Q=s||B,{connection:te,isValid:Z}=Sm.isValid(I.nativeEvent,{handle:{nodeId:E,id:w,type:e},connectionMode:K,fromNodeId:U.nodeId,fromHandleId:U.id||null,fromType:U.type,isValidConnection:Q,flowId:W,doc:V,lib:L,nodeLookup:R});Z&&te&&F(te);const ee=structuredClone(z);delete ee.inProgress,ee.toPosition=ee.toHandle?ee.toHandle.position:null,G?.(I,ee),T.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":w,"data-nodeid":E,"data-handlepos":r,"data-id":`${k}-${E}-${w}-${e}`,className:Pn(["react-flow__handle",`react-flow__handle-${r}`,"nodrag",N,h,{source:!S,target:S,connectable:i,connectablestart:o,connectableend:c,clickconnecting:Y,connectingfrom:H,connectingto:M,valid:q,connectionindicator:i&&(!X||$)&&(X||P?c:o)}]),onMouseDown:D,onTouchStart:D,onClick:C?_:void 0,ref:p,...b,children:m})}const Na=j.memo(Mw(OO));function RO({data:e,isConnectable:r,sourcePosition:s=nt.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(Na,{type:"source",position:s,isConnectable:r})]})}function zO({data:e,isConnectable:r,targetPosition:s=nt.Top,sourcePosition:i=nt.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(Na,{type:"target",position:s,isConnectable:r}),e?.label,t.jsx(Na,{type:"source",position:i,isConnectable:r})]})}function LO(){return null}function IO({data:e,isConnectable:r,targetPosition:s=nt.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(Na,{type:"target",position:s,isConnectable:r}),e?.label]})}const Lu={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},mv={input:RO,default:zO,output:IO,group:LO};function $O(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}const BO=e=>{const{width:r,height:s,x:i,y:o}=Lo(e.nodeLookup,{filter:c=>!!c.selected});return{width:Wr(r)?r:null,height:Wr(s)?s:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${i}px,${o}px)`}};function HO({onSelectionContextMenu:e,noPanClassName:r,disableKeyboardA11y:s}){const i=yn(),{width:o,height:c,transformString:u,userSelectionActive:f}=Vt(BO,bn),m=Rw(),h=j.useRef(null);j.useEffect(()=>{s||h.current?.focus({preventScroll:!0})},[s]);const x=!f&&o!==null&&c!==null;if(Ow({nodeRef:h,disabled:!x}),!x)return null;const g=e?p=>{const w=i.getState().nodes.filter(S=>S.selected);e(p,w)}:void 0,b=p=>{Object.prototype.hasOwnProperty.call(Lu,p.key)&&(p.preventDefault(),m({direction:Lu[p.key],factor:p.shiftKey?4:1}))};return t.jsx("div",{className:Pn(["react-flow__nodesselection","react-flow__container",r]),style:{transform:u},children:t.jsx("div",{ref:h,className:"react-flow__nodesselection-rect",onContextMenu:g,tabIndex:s?void 0:-1,onKeyDown:s?void 0:b,style:{width:o,height:c}})})}const xv=typeof window<"u"?window:void 0,PO=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Lw({children:e,onPaneClick:r,onPaneMouseEnter:s,onPaneMouseMove:i,onPaneMouseLeave:o,onPaneContextMenu:c,onPaneScroll:u,paneClickDistance:f,deleteKeyCode:m,selectionKeyCode:h,selectionOnDrag:x,selectionMode:g,onSelectionStart:b,onSelectionEnd:p,multiSelectionKeyCode:w,panActivationKeyCode:S,zoomActivationKeyCode:T,elementsSelectable:E,zoomOnScroll:C,zoomOnPinch:N,panOnScroll:k,panOnScrollSpeed:H,panOnScrollMode:M,zoomOnDoubleClick:Y,panOnDrag:$,defaultViewport:X,translateExtent:P,minZoom:q,maxZoom:F,preventScrolling:D,onSelectionContextMenu:_,noWheelClassName:I,noPanClassName:A,disableKeyboardA11y:G,onViewportChange:U,isControlledViewport:K}){const{nodesSelectionActive:B,userSelectionActive:L}=Vt(PO,bn),W=Eo(h,{target:xv}),R=Eo(S,{target:xv}),z=R||$,V=R||k,Q=x&&z!==!0,te=W||L||Q;return jO({deleteKeyCode:m,multiSelectionKeyCode:w}),t.jsx(kO,{onPaneContextMenu:c,elementsSelectable:E,zoomOnScroll:C,zoomOnPinch:N,panOnScroll:V,panOnScrollSpeed:H,panOnScrollMode:M,zoomOnDoubleClick:Y,panOnDrag:!W&&z,defaultViewport:X,translateExtent:P,minZoom:q,maxZoom:F,zoomActivationKeyCode:T,preventScrolling:D,noWheelClassName:I,noPanClassName:A,onViewportChange:U,isControlledViewport:K,paneClickDistance:f,selectionOnDrag:Q,children:t.jsxs(TO,{onSelectionStart:b,onSelectionEnd:p,onPaneClick:r,onPaneMouseEnter:s,onPaneMouseMove:i,onPaneMouseLeave:o,onPaneContextMenu:c,onPaneScroll:u,panOnDrag:z,isSelecting:!!te,selectionMode:g,selectionKeyPressed:W,paneClickDistance:f,selectionOnDrag:Q,children:[e,B&&t.jsx(HO,{onSelectionContextMenu:_,noPanClassName:A,disableKeyboardA11y:G})]})})}Lw.displayName="FlowRenderer";const UO=j.memo(Lw),qO=e=>r=>e?dx(r.nodeLookup,{x:0,y:0,width:r.width,height:r.height},r.transform,!0).map(s=>s.id):Array.from(r.nodeLookup.keys());function VO(e){return Vt(j.useCallback(qO(e),[e]),bn)}const FO=e=>e.updateNodeInternals;function YO(){const e=Vt(FO),[r]=j.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const i=new Map;s.forEach(o=>{const c=o.target.getAttribute("data-id");i.set(c,{id:c,nodeElement:o.target,force:!0})}),e(i)}));return j.useEffect(()=>()=>{r?.disconnect()},[r]),r}function GO({node:e,nodeType:r,hasDimensions:s,resizeObserver:i}){const o=yn(),c=j.useRef(null),u=j.useRef(null),f=j.useRef(e.sourcePosition),m=j.useRef(e.targetPosition),h=j.useRef(r),x=s&&!!e.internals.handleBounds;return j.useEffect(()=>{c.current&&!e.hidden&&(!x||u.current!==c.current)&&(u.current&&i?.unobserve(u.current),i?.observe(c.current),u.current=c.current)},[x,e.hidden]),j.useEffect(()=>()=>{u.current&&(i?.unobserve(u.current),u.current=null)},[]),j.useEffect(()=>{if(c.current){const g=h.current!==r,b=f.current!==e.sourcePosition,p=m.current!==e.targetPosition;(g||b||p)&&(h.current=r,f.current=e.sourcePosition,m.current=e.targetPosition,o.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:c.current,force:!0}]])))}},[e.id,r,e.sourcePosition,e.targetPosition]),c}function XO({id:e,onClick:r,onMouseEnter:s,onMouseMove:i,onMouseLeave:o,onContextMenu:c,onDoubleClick:u,nodesDraggable:f,elementsSelectable:m,nodesConnectable:h,nodesFocusable:x,resizeObserver:g,noDragClassName:b,noPanClassName:p,disableKeyboardA11y:w,rfId:S,nodeTypes:T,nodeClickDistance:E,onError:C}){const{node:N,internals:k,isParent:H}=Vt(Z=>{const ee=Z.nodeLookup.get(e),ie=Z.parentLookup.has(e);return{node:ee,internals:ee.internals,isParent:ie}},bn);let M=N.type||"default",Y=T?.[M]||mv[M];Y===void 0&&(C?.("003",ms.error003(M)),M="default",Y=T?.default||mv.default);const $=!!(N.draggable||f&&typeof N.draggable>"u"),X=!!(N.selectable||m&&typeof N.selectable>"u"),P=!!(N.connectable||h&&typeof N.connectable>"u"),q=!!(N.focusable||x&&typeof N.focusable>"u"),F=yn(),D=rw(N),_=GO({node:N,nodeType:M,hasDimensions:D,resizeObserver:g}),I=Ow({nodeRef:_,disabled:N.hidden||!$,noDragClassName:b,handleSelector:N.dragHandle,nodeId:e,isSelectable:X,nodeClickDistance:E}),A=Rw();if(N.hidden)return null;const G=Hs(N),U=$O(N),K=X||$||r||s||i||o,B=s?Z=>s(Z,{...k.userNode}):void 0,L=i?Z=>i(Z,{...k.userNode}):void 0,W=o?Z=>o(Z,{...k.userNode}):void 0,R=c?Z=>c(Z,{...k.userNode}):void 0,z=u?Z=>u(Z,{...k.userNode}):void 0,V=Z=>{const{selectNodesOnDrag:ee,nodeDragThreshold:ie}=F.getState();X&&(!ee||!$||ie>0)&&Cm({id:e,store:F,nodeRef:_}),r&&r(Z,{...k.userNode})},Q=Z=>{if(!(iw(Z.nativeEvent)||w)){if(Xj.includes(Z.key)&&X){const ee=Z.key==="Escape";Cm({id:e,store:F,unselect:ee,nodeRef:_})}else if($&&N.selected&&Object.prototype.hasOwnProperty.call(Lu,Z.key)){Z.preventDefault();const{ariaLabelConfig:ee}=F.getState();F.setState({ariaLiveMessage:ee["node.a11yDescription.ariaLiveMessage"]({direction:Z.key.replace("Arrow","").toLowerCase(),x:~~k.positionAbsolute.x,y:~~k.positionAbsolute.y})}),A({direction:Lu[Z.key],factor:Z.shiftKey?4:1})}}},te=()=>{if(w||!_.current?.matches(":focus-visible"))return;const{transform:Z,width:ee,height:ie,autoPanOnNodeFocus:je,setCenter:ke}=F.getState();if(!je)return;dx(new Map([[e,N]]),{x:0,y:0,width:ee,height:ie},Z,!0).length>0||ke(N.position.x+G.width/2,N.position.y+G.height/2,{zoom:Z[2]})};return t.jsx("div",{className:Pn(["react-flow__node",`react-flow__node-${M}`,{[p]:$},N.className,{selected:N.selected,selectable:X,parent:H,draggable:$,dragging:I}]),ref:_,style:{zIndex:k.z,transform:`translate(${k.positionAbsolute.x}px,${k.positionAbsolute.y}px)`,pointerEvents:K?"all":"none",visibility:D?"visible":"hidden",...N.style,...U},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:B,onMouseMove:L,onMouseLeave:W,onContextMenu:R,onClick:V,onDoubleClick:z,onKeyDown:q?Q:void 0,tabIndex:q?0:void 0,onFocus:q?te:void 0,role:N.ariaRole??(q?"group":void 0),"aria-roledescription":"node","aria-describedby":w?void 0:`${Sw}-${S}`,"aria-label":N.ariaLabel,...N.domAttributes,children:t.jsx(AO,{value:e,children:t.jsx(Y,{id:e,data:N.data,type:M,positionAbsoluteX:k.positionAbsolute.x,positionAbsoluteY:k.positionAbsolute.y,selected:N.selected??!1,selectable:X,draggable:$,deletable:N.deletable??!0,isConnectable:P,sourcePosition:N.sourcePosition,targetPosition:N.targetPosition,dragging:I,dragHandle:N.dragHandle,zIndex:k.z,parentId:N.parentId,...G})})})}var ZO=j.memo(XO);const QO=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Iw(e){const{nodesDraggable:r,nodesConnectable:s,nodesFocusable:i,elementsSelectable:o,onError:c}=Vt(QO,bn),u=VO(e.onlyRenderVisibleElements),f=YO();return t.jsx("div",{className:"react-flow__nodes",style:nd,children:u.map(m=>t.jsx(ZO,{id:m,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:f,nodesDraggable:r,nodesConnectable:s,nodesFocusable:i,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:c},m))})}Iw.displayName="NodeRenderer";const KO=j.memo(Iw);function JO(e){return Vt(j.useCallback(s=>{if(!e)return s.edges.map(o=>o.id);const i=[];if(s.width&&s.height)for(const o of s.edges){const c=s.nodeLookup.get(o.source),u=s.nodeLookup.get(o.target);c&&u&&QM({sourceNode:c,targetNode:u,width:s.width,height:s.height,transform:s.transform})&&i.push(o.id)}return i},[e]),bn)}const WO=({color:e="none",strokeWidth:r=1})=>{const s={strokeWidth:r,...e&&{stroke:e}};return t.jsx("polyline",{className:"arrow",style:s,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},eR=({color:e="none",strokeWidth:r=1})=>{const s={strokeWidth:r,...e&&{stroke:e,fill:e}};return t.jsx("polyline",{className:"arrowclosed",style:s,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},gv={[Zi.Arrow]:WO,[Zi.ArrowClosed]:eR};function tR(e){const r=yn();return j.useMemo(()=>Object.prototype.hasOwnProperty.call(gv,e)?gv[e]:(r.getState().onError?.("009",ms.error009(e)),null),[e])}const nR=({id:e,type:r,color:s,width:i=12.5,height:o=12.5,markerUnits:c="strokeWidth",strokeWidth:u,orient:f="auto-start-reverse"})=>{const m=tR(r);return m?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${i}`,markerHeight:`${o}`,viewBox:"-10 -10 20 20",markerUnits:c,orient:f,refX:"0",refY:"0",children:t.jsx(m,{color:s,strokeWidth:u})}):null},$w=({defaultColor:e,rfId:r})=>{const s=Vt(c=>c.edges),i=Vt(c=>c.defaultEdgeOptions),o=j.useMemo(()=>sD(s,{id:r,defaultColor:e,defaultMarkerStart:i?.markerStart,defaultMarkerEnd:i?.markerEnd}),[s,i,r,e]);return o.length?t.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:t.jsx("defs",{children:o.map(c=>t.jsx(nR,{id:c.id,type:c.type,color:c.color,width:c.width,height:c.height,markerUnits:c.markerUnits,strokeWidth:c.strokeWidth,orient:c.orient},c.id))})}):null};$w.displayName="MarkerDefinitions";var rR=j.memo($w);function Bw({x:e,y:r,label:s,labelStyle:i,labelShowBg:o=!0,labelBgStyle:c,labelBgPadding:u=[2,4],labelBgBorderRadius:f=2,children:m,className:h,...x}){const[g,b]=j.useState({x:1,y:0,width:0,height:0}),p=Pn(["react-flow__edge-textwrapper",h]),w=j.useRef(null);return j.useEffect(()=>{if(w.current){const S=w.current.getBBox();b({x:S.x,y:S.y,width:S.width,height:S.height})}},[s]),s?t.jsxs("g",{transform:`translate(${e-g.width/2} ${r-g.height/2})`,className:p,visibility:g.width?"visible":"hidden",...x,children:[o&&t.jsx("rect",{width:g.width+2*u[0],x:-u[0],y:-u[1],height:g.height+2*u[1],className:"react-flow__edge-textbg",style:c,rx:f,ry:f}),t.jsx("text",{className:"react-flow__edge-text",y:g.height/2,dy:"0.3em",ref:w,style:i,children:s}),m]}):null}Bw.displayName="EdgeText";const sR=j.memo(Bw);function rd({path:e,labelX:r,labelY:s,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m,interactionWidth:h=20,...x}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...x,d:e,fill:"none",className:Pn(["react-flow__edge-path",x.className])}),h?t.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:h,className:"react-flow__edge-interaction"}):null,i&&Wr(r)&&Wr(s)?t.jsx(sR,{x:r,y:s,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m}):null]})}function pv({pos:e,x1:r,y1:s,x2:i,y2:o}){return e===nt.Left||e===nt.Right?[.5*(r+i),s]:[r,.5*(s+o)]}function Hw({sourceX:e,sourceY:r,sourcePosition:s=nt.Bottom,targetX:i,targetY:o,targetPosition:c=nt.Top}){const[u,f]=pv({pos:s,x1:e,y1:r,x2:i,y2:o}),[m,h]=pv({pos:c,x1:i,y1:o,x2:e,y2:r}),[x,g,b,p]=ow({sourceX:e,sourceY:r,targetX:i,targetY:o,sourceControlX:u,sourceControlY:f,targetControlX:m,targetControlY:h});return[`M${e},${r} C${u},${f} ${m},${h} ${i},${o}`,x,g,b,p]}function Pw(e){return j.memo(({id:r,sourceX:s,sourceY:i,targetX:o,targetY:c,sourcePosition:u,targetPosition:f,label:m,labelStyle:h,labelShowBg:x,labelBgStyle:g,labelBgPadding:b,labelBgBorderRadius:p,style:w,markerEnd:S,markerStart:T,interactionWidth:E})=>{const[C,N,k]=Hw({sourceX:s,sourceY:i,sourcePosition:u,targetX:o,targetY:c,targetPosition:f}),H=e.isInternal?void 0:r;return t.jsx(rd,{id:H,path:C,labelX:N,labelY:k,label:m,labelStyle:h,labelShowBg:x,labelBgStyle:g,labelBgPadding:b,labelBgBorderRadius:p,style:w,markerEnd:S,markerStart:T,interactionWidth:E})})}const aR=Pw({isInternal:!1}),Uw=Pw({isInternal:!0});aR.displayName="SimpleBezierEdge";Uw.displayName="SimpleBezierEdgeInternal";function qw(e){return j.memo(({id:r,sourceX:s,sourceY:i,targetX:o,targetY:c,label:u,labelStyle:f,labelShowBg:m,labelBgStyle:h,labelBgPadding:x,labelBgBorderRadius:g,style:b,sourcePosition:p=nt.Bottom,targetPosition:w=nt.Top,markerEnd:S,markerStart:T,pathOptions:E,interactionWidth:C})=>{const[N,k,H]=wm({sourceX:s,sourceY:i,sourcePosition:p,targetX:o,targetY:c,targetPosition:w,borderRadius:E?.borderRadius,offset:E?.offset,stepPosition:E?.stepPosition}),M=e.isInternal?void 0:r;return t.jsx(rd,{id:M,path:N,labelX:k,labelY:H,label:u,labelStyle:f,labelShowBg:m,labelBgStyle:h,labelBgPadding:x,labelBgBorderRadius:g,style:b,markerEnd:S,markerStart:T,interactionWidth:C})})}const Vw=qw({isInternal:!1}),Fw=qw({isInternal:!0});Vw.displayName="SmoothStepEdge";Fw.displayName="SmoothStepEdgeInternal";function Yw(e){return j.memo(({id:r,...s})=>{const i=e.isInternal?void 0:r;return t.jsx(Vw,{...s,id:i,pathOptions:j.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const iR=Yw({isInternal:!1}),Gw=Yw({isInternal:!0});iR.displayName="StepEdge";Gw.displayName="StepEdgeInternal";function Xw(e){return j.memo(({id:r,sourceX:s,sourceY:i,targetX:o,targetY:c,label:u,labelStyle:f,labelShowBg:m,labelBgStyle:h,labelBgPadding:x,labelBgBorderRadius:g,style:b,markerEnd:p,markerStart:w,interactionWidth:S})=>{const[T,E,C]=dw({sourceX:s,sourceY:i,targetX:o,targetY:c}),N=e.isInternal?void 0:r;return t.jsx(rd,{id:N,path:T,labelX:E,labelY:C,label:u,labelStyle:f,labelShowBg:m,labelBgStyle:h,labelBgPadding:x,labelBgBorderRadius:g,style:b,markerEnd:p,markerStart:w,interactionWidth:S})})}const lR=Xw({isInternal:!1}),Zw=Xw({isInternal:!0});lR.displayName="StraightEdge";Zw.displayName="StraightEdgeInternal";function Qw(e){return j.memo(({id:r,sourceX:s,sourceY:i,targetX:o,targetY:c,sourcePosition:u=nt.Bottom,targetPosition:f=nt.Top,label:m,labelStyle:h,labelShowBg:x,labelBgStyle:g,labelBgPadding:b,labelBgBorderRadius:p,style:w,markerEnd:S,markerStart:T,pathOptions:E,interactionWidth:C})=>{const[N,k,H]=cw({sourceX:s,sourceY:i,sourcePosition:u,targetX:o,targetY:c,targetPosition:f,curvature:E?.curvature}),M=e.isInternal?void 0:r;return t.jsx(rd,{id:M,path:N,labelX:k,labelY:H,label:m,labelStyle:h,labelShowBg:x,labelBgStyle:g,labelBgPadding:b,labelBgBorderRadius:p,style:w,markerEnd:S,markerStart:T,interactionWidth:C})})}const oR=Qw({isInternal:!1}),Kw=Qw({isInternal:!0});oR.displayName="BezierEdge";Kw.displayName="BezierEdgeInternal";const bv={default:Kw,straight:Zw,step:Gw,smoothstep:Fw,simplebezier:Uw},yv={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},cR=(e,r,s)=>s===nt.Left?e-r:s===nt.Right?e+r:e,uR=(e,r,s)=>s===nt.Top?e-r:s===nt.Bottom?e+r:e,vv="react-flow__edgeupdater";function jv({position:e,centerX:r,centerY:s,radius:i=10,onMouseDown:o,onMouseEnter:c,onMouseOut:u,type:f}){return t.jsx("circle",{onMouseDown:o,onMouseEnter:c,onMouseOut:u,className:Pn([vv,`${vv}-${f}`]),cx:cR(r,i,e),cy:uR(s,i,e),r:i,stroke:"transparent",fill:"transparent"})}function dR({isReconnectable:e,reconnectRadius:r,edge:s,sourceX:i,sourceY:o,targetX:c,targetY:u,sourcePosition:f,targetPosition:m,onReconnect:h,onReconnectStart:x,onReconnectEnd:g,setReconnecting:b,setUpdateHover:p}){const w=yn(),S=(k,H)=>{if(k.button!==0)return;const{autoPanOnConnect:M,domNode:Y,connectionMode:$,connectionRadius:X,lib:P,onConnectStart:q,cancelConnection:F,nodeLookup:D,rfId:_,panBy:I,updateConnection:A}=w.getState(),G=H.type==="target",U=(L,W)=>{b(!1),g?.(L,s,H.type,W)},K=L=>h?.(s,L),B=(L,W)=>{b(!0),x?.(k,s,H.type),q?.(L,W)};Sm.onPointerDown(k.nativeEvent,{autoPanOnConnect:M,connectionMode:$,connectionRadius:X,domNode:Y,handleId:H.id,nodeId:H.nodeId,nodeLookup:D,isTarget:G,edgeUpdaterType:H.type,lib:P,flowId:_,cancelConnection:F,panBy:I,isValidConnection:(...L)=>w.getState().isValidConnection?.(...L)??!0,onConnect:K,onConnectStart:B,onConnectEnd:(...L)=>w.getState().onConnectEnd?.(...L),onReconnectEnd:U,updateConnection:A,getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,dragThreshold:w.getState().connectionDragThreshold,handleDomNode:k.currentTarget})},T=k=>S(k,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),E=k=>S(k,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),C=()=>p(!0),N=()=>p(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(jv,{position:f,centerX:i,centerY:o,radius:r,onMouseDown:T,onMouseEnter:C,onMouseOut:N,type:"source"}),(e===!0||e==="target")&&t.jsx(jv,{position:m,centerX:c,centerY:u,radius:r,onMouseDown:E,onMouseEnter:C,onMouseOut:N,type:"target"})]})}function fR({id:e,edgesFocusable:r,edgesReconnectable:s,elementsSelectable:i,onClick:o,onDoubleClick:c,onContextMenu:u,onMouseEnter:f,onMouseMove:m,onMouseLeave:h,reconnectRadius:x,onReconnect:g,onReconnectStart:b,onReconnectEnd:p,rfId:w,edgeTypes:S,noPanClassName:T,onError:E,disableKeyboardA11y:C}){let N=Vt(ke=>ke.edgeLookup.get(e));const k=Vt(ke=>ke.defaultEdgeOptions);N=k?{...k,...N}:N;let H=N.type||"default",M=S?.[H]||bv[H];M===void 0&&(E?.("011",ms.error011(H)),H="default",M=S?.default||bv.default);const Y=!!(N.focusable||r&&typeof N.focusable>"u"),$=typeof g<"u"&&(N.reconnectable||s&&typeof N.reconnectable>"u"),X=!!(N.selectable||i&&typeof N.selectable>"u"),P=j.useRef(null),[q,F]=j.useState(!1),[D,_]=j.useState(!1),I=yn(),{zIndex:A,sourceX:G,sourceY:U,targetX:K,targetY:B,sourcePosition:L,targetPosition:W}=Vt(j.useCallback(ke=>{const De=ke.nodeLookup.get(N.source),Ie=ke.nodeLookup.get(N.target);if(!De||!Ie)return{zIndex:N.zIndex,...yv};const ze=rD({id:e,sourceNode:De,targetNode:Ie,sourceHandle:N.sourceHandle||null,targetHandle:N.targetHandle||null,connectionMode:ke.connectionMode,onError:E});return{zIndex:ZM({selected:N.selected,zIndex:N.zIndex,sourceNode:De,targetNode:Ie,elevateOnSelect:ke.elevateEdgesOnSelect,zIndexMode:ke.zIndexMode}),...ze||yv}},[N.source,N.target,N.sourceHandle,N.targetHandle,N.selected,N.zIndex]),bn),R=j.useMemo(()=>N.markerStart?`url('#${Nm(N.markerStart,w)}')`:void 0,[N.markerStart,w]),z=j.useMemo(()=>N.markerEnd?`url('#${Nm(N.markerEnd,w)}')`:void 0,[N.markerEnd,w]);if(N.hidden||G===null||U===null||K===null||B===null)return null;const V=ke=>{const{addSelectedEdges:De,unselectNodesAndEdges:Ie,multiSelectionActive:ze}=I.getState();X&&(I.setState({nodesSelectionActive:!1}),N.selected&&ze?(Ie({nodes:[],edges:[N]}),P.current?.blur()):De([e])),o&&o(ke,N)},Q=c?ke=>{c(ke,{...N})}:void 0,te=u?ke=>{u(ke,{...N})}:void 0,Z=f?ke=>{f(ke,{...N})}:void 0,ee=m?ke=>{m(ke,{...N})}:void 0,ie=h?ke=>{h(ke,{...N})}:void 0,je=ke=>{if(!C&&Xj.includes(ke.key)&&X){const{unselectNodesAndEdges:De,addSelectedEdges:Ie}=I.getState();ke.key==="Escape"?(P.current?.blur(),De({edges:[N]})):Ie([e])}};return t.jsx("svg",{style:{zIndex:A},children:t.jsxs("g",{className:Pn(["react-flow__edge",`react-flow__edge-${H}`,N.className,T,{selected:N.selected,animated:N.animated,inactive:!X&&!o,updating:q,selectable:X}]),onClick:V,onDoubleClick:Q,onContextMenu:te,onMouseEnter:Z,onMouseMove:ee,onMouseLeave:ie,onKeyDown:Y?je:void 0,tabIndex:Y?0:void 0,role:N.ariaRole??(Y?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":N.ariaLabel===null?void 0:N.ariaLabel||`Edge from ${N.source} to ${N.target}`,"aria-describedby":Y?`${Cw}-${w}`:void 0,ref:P,...N.domAttributes,children:[!D&&t.jsx(M,{id:e,source:N.source,target:N.target,type:N.type,selected:N.selected,animated:N.animated,selectable:X,deletable:N.deletable??!0,label:N.label,labelStyle:N.labelStyle,labelShowBg:N.labelShowBg,labelBgStyle:N.labelBgStyle,labelBgPadding:N.labelBgPadding,labelBgBorderRadius:N.labelBgBorderRadius,sourceX:G,sourceY:U,targetX:K,targetY:B,sourcePosition:L,targetPosition:W,data:N.data,style:N.style,sourceHandleId:N.sourceHandle,targetHandleId:N.targetHandle,markerStart:R,markerEnd:z,pathOptions:"pathOptions"in N?N.pathOptions:void 0,interactionWidth:N.interactionWidth}),$&&t.jsx(dR,{edge:N,isReconnectable:$,reconnectRadius:x,onReconnect:g,onReconnectStart:b,onReconnectEnd:p,sourceX:G,sourceY:U,targetX:K,targetY:B,sourcePosition:L,targetPosition:W,setUpdateHover:F,setReconnecting:_})]})})}var hR=j.memo(fR);const mR=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Jw({defaultMarkerColor:e,onlyRenderVisibleElements:r,rfId:s,edgeTypes:i,noPanClassName:o,onReconnect:c,onEdgeContextMenu:u,onEdgeMouseEnter:f,onEdgeMouseMove:m,onEdgeMouseLeave:h,onEdgeClick:x,reconnectRadius:g,onEdgeDoubleClick:b,onReconnectStart:p,onReconnectEnd:w,disableKeyboardA11y:S}){const{edgesFocusable:T,edgesReconnectable:E,elementsSelectable:C,onError:N}=Vt(mR,bn),k=JO(r);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(rR,{defaultColor:e,rfId:s}),k.map(H=>t.jsx(hR,{id:H,edgesFocusable:T,edgesReconnectable:E,elementsSelectable:C,noPanClassName:o,onReconnect:c,onContextMenu:u,onMouseEnter:f,onMouseMove:m,onMouseLeave:h,onClick:x,reconnectRadius:g,onDoubleClick:b,onReconnectStart:p,onReconnectEnd:w,rfId:s,onError:N,edgeTypes:i,disableKeyboardA11y:S},H))]})}Jw.displayName="EdgeRenderer";const xR=j.memo(Jw),gR=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function pR({children:e}){const r=Vt(gR);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:r},children:e})}function bR(e){const r=yx(),s=j.useRef(!1);j.useEffect(()=>{!s.current&&r.viewportInitialized&&e&&(setTimeout(()=>e(r),1),s.current=!0)},[e,r.viewportInitialized])}const yR=e=>e.panZoom?.syncViewport;function vR(e){const r=Vt(yR),s=yn();return j.useEffect(()=>{e&&(r?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,r]),null}function jR(e){return e.connection.inProgress?{...e.connection,to:$o(e.connection.to,e.transform)}:{...e.connection}}function wR(e){return jR}function NR(e){const r=wR();return Vt(r,bn)}const kR=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function SR({containerStyle:e,style:r,type:s,component:i}){const{nodesConnectable:o,width:c,height:u,isValid:f,inProgress:m}=Vt(kR,bn);return!(c&&o&&m)?null:t.jsx("svg",{style:e,width:c,height:u,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:Pn(["react-flow__connection",Kj(f)]),children:t.jsx(Ww,{style:r,type:s,CustomComponent:i,isValid:f})})})}const Ww=({style:e,type:r=ja.Bezier,CustomComponent:s,isValid:i})=>{const{inProgress:o,from:c,fromNode:u,fromHandle:f,fromPosition:m,to:h,toNode:x,toHandle:g,toPosition:b,pointer:p}=NR();if(!o)return;if(s)return t.jsx(s,{connectionLineType:r,connectionLineStyle:e,fromNode:u,fromHandle:f,fromX:c.x,fromY:c.y,toX:h.x,toY:h.y,fromPosition:m,toPosition:b,connectionStatus:Kj(i),toNode:x,toHandle:g,pointer:p});let w="";const S={sourceX:c.x,sourceY:c.y,sourcePosition:m,targetX:h.x,targetY:h.y,targetPosition:b};switch(r){case ja.Bezier:[w]=cw(S);break;case ja.SimpleBezier:[w]=Hw(S);break;case ja.Step:[w]=wm({...S,borderRadius:0});break;case ja.SmoothStep:[w]=wm(S);break;default:[w]=dw(S)}return t.jsx("path",{d:w,fill:"none",className:"react-flow__connection-path",style:e})};Ww.displayName="ConnectionLine";const CR={};function wv(e=CR){j.useRef(e),yn(),j.useEffect(()=>{},[e])}function ER(){yn(),j.useRef(!1),j.useEffect(()=>{},[])}function eN({nodeTypes:e,edgeTypes:r,onInit:s,onNodeClick:i,onEdgeClick:o,onNodeDoubleClick:c,onEdgeDoubleClick:u,onNodeMouseEnter:f,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:x,onSelectionContextMenu:g,onSelectionStart:b,onSelectionEnd:p,connectionLineType:w,connectionLineStyle:S,connectionLineComponent:T,connectionLineContainerStyle:E,selectionKeyCode:C,selectionOnDrag:N,selectionMode:k,multiSelectionKeyCode:H,panActivationKeyCode:M,zoomActivationKeyCode:Y,deleteKeyCode:$,onlyRenderVisibleElements:X,elementsSelectable:P,defaultViewport:q,translateExtent:F,minZoom:D,maxZoom:_,preventScrolling:I,defaultMarkerColor:A,zoomOnScroll:G,zoomOnPinch:U,panOnScroll:K,panOnScrollSpeed:B,panOnScrollMode:L,zoomOnDoubleClick:W,panOnDrag:R,onPaneClick:z,onPaneMouseEnter:V,onPaneMouseMove:Q,onPaneMouseLeave:te,onPaneScroll:Z,onPaneContextMenu:ee,paneClickDistance:ie,nodeClickDistance:je,onEdgeContextMenu:ke,onEdgeMouseEnter:De,onEdgeMouseMove:Ie,onEdgeMouseLeave:ze,reconnectRadius:Ze,onReconnect:Ae,onReconnectStart:We,onReconnectEnd:xt,noDragClassName:Lt,noWheelClassName:le,noPanClassName:_e,disableKeyboardA11y:ht,nodeExtent:Ct,rfId:Ft,viewport:be,onViewportChange:Me}){return wv(e),wv(r),ER(),bR(s),vR(be),t.jsx(UO,{onPaneClick:z,onPaneMouseEnter:V,onPaneMouseMove:Q,onPaneMouseLeave:te,onPaneContextMenu:ee,onPaneScroll:Z,paneClickDistance:ie,deleteKeyCode:$,selectionKeyCode:C,selectionOnDrag:N,selectionMode:k,onSelectionStart:b,onSelectionEnd:p,multiSelectionKeyCode:H,panActivationKeyCode:M,zoomActivationKeyCode:Y,elementsSelectable:P,zoomOnScroll:G,zoomOnPinch:U,zoomOnDoubleClick:W,panOnScroll:K,panOnScrollSpeed:B,panOnScrollMode:L,panOnDrag:R,defaultViewport:q,translateExtent:F,minZoom:D,maxZoom:_,onSelectionContextMenu:g,preventScrolling:I,noDragClassName:Lt,noWheelClassName:le,noPanClassName:_e,disableKeyboardA11y:ht,onViewportChange:Me,isControlledViewport:!!be,children:t.jsxs(pR,{children:[t.jsx(xR,{edgeTypes:r,onEdgeClick:o,onEdgeDoubleClick:u,onReconnect:Ae,onReconnectStart:We,onReconnectEnd:xt,onlyRenderVisibleElements:X,onEdgeContextMenu:ke,onEdgeMouseEnter:De,onEdgeMouseMove:Ie,onEdgeMouseLeave:ze,reconnectRadius:Ze,defaultMarkerColor:A,noPanClassName:_e,disableKeyboardA11y:ht,rfId:Ft}),t.jsx(SR,{style:S,type:w,component:T,containerStyle:E}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(KO,{nodeTypes:e,onNodeClick:i,onNodeDoubleClick:c,onNodeMouseEnter:f,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:x,nodeClickDistance:je,onlyRenderVisibleElements:X,noPanClassName:_e,noDragClassName:Lt,disableKeyboardA11y:ht,nodeExtent:Ct,rfId:Ft}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}eN.displayName="GraphView";const TR=j.memo(eN),Nv=({nodes:e,edges:r,defaultNodes:s,defaultEdges:i,width:o,height:c,fitView:u,fitViewOptions:f,minZoom:m=.5,maxZoom:h=2,nodeOrigin:x,nodeExtent:g,zIndexMode:b="basic"}={})=>{const p=new Map,w=new Map,S=new Map,T=new Map,E=i??r??[],C=s??e??[],N=x??[0,0],k=g??No;mw(S,T,E);const H=km(C,p,w,{nodeOrigin:N,nodeExtent:k,zIndexMode:b});let M=[0,0,1];if(u&&o&&c){const Y=Lo(p,{filter:q=>!!((q.width||q.initialWidth)&&(q.height||q.initialHeight))}),{x:$,y:X,zoom:P}=fx(Y,o,c,m,h,f?.padding??.1);M=[$,X,P]}return{rfId:"1",width:o??0,height:c??0,transform:M,nodes:C,nodesInitialized:H,nodeLookup:p,parentLookup:w,edges:E,edgeLookup:T,connectionLookup:S,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:i!==void 0,panZoom:null,minZoom:m,maxZoom:h,translateExtent:No,nodeExtent:k,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Xi.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:N,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:u??!1,fitViewOptions:f,fitViewResolver:null,connection:{...Qj},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:qM,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Zj,zIndexMode:b,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},_R=({nodes:e,edges:r,defaultNodes:s,defaultEdges:i,width:o,height:c,fitView:u,fitViewOptions:f,minZoom:m,maxZoom:h,nodeOrigin:x,nodeExtent:g,zIndexMode:b})=>GD((p,w)=>{async function S(){const{nodeLookup:T,panZoom:E,fitViewOptions:C,fitViewResolver:N,width:k,height:H,minZoom:M,maxZoom:Y}=w();E&&(await PM({nodes:T,width:k,height:H,panZoom:E,minZoom:M,maxZoom:Y},C),N?.resolve(!0),p({fitViewResolver:null}))}return{...Nv({nodes:e,edges:r,width:o,height:c,fitView:u,fitViewOptions:f,minZoom:m,maxZoom:h,nodeOrigin:x,nodeExtent:g,defaultNodes:s,defaultEdges:i,zIndexMode:b}),setNodes:T=>{const{nodeLookup:E,parentLookup:C,nodeOrigin:N,elevateNodesOnSelect:k,fitViewQueued:H,zIndexMode:M}=w(),Y=km(T,E,C,{nodeOrigin:N,nodeExtent:g,elevateNodesOnSelect:k,checkEquality:!0,zIndexMode:M});H&&Y?(S(),p({nodes:T,nodesInitialized:Y,fitViewQueued:!1,fitViewOptions:void 0})):p({nodes:T,nodesInitialized:Y})},setEdges:T=>{const{connectionLookup:E,edgeLookup:C}=w();mw(E,C,T),p({edges:T})},setDefaultNodesAndEdges:(T,E)=>{if(T){const{setNodes:C}=w();C(T),p({hasDefaultNodes:!0})}if(E){const{setEdges:C}=w();C(E),p({hasDefaultEdges:!0})}},updateNodeInternals:T=>{const{triggerNodeChanges:E,nodeLookup:C,parentLookup:N,domNode:k,nodeOrigin:H,nodeExtent:M,debug:Y,fitViewQueued:$,zIndexMode:X}=w(),{changes:P,updatedInternals:q}=dD(T,C,N,k,H,M,X);q&&(lD(C,N,{nodeOrigin:H,nodeExtent:M,zIndexMode:X}),$?(S(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),P?.length>0&&(Y&&console.log("React Flow: trigger node changes",P),E?.(P)))},updateNodePositions:(T,E=!1)=>{const C=[];let N=[];const{nodeLookup:k,triggerNodeChanges:H,connection:M,updateConnection:Y,onNodesChangeMiddlewareMap:$}=w();for(const[X,P]of T){const q=k.get(X),F=!!(q?.expandParent&&q?.parentId&&P?.position),D={id:X,type:"position",position:F?{x:Math.max(0,P.position.x),y:Math.max(0,P.position.y)}:P.position,dragging:E};if(q&&M.inProgress&&M.fromNode.id===q.id){const _=ti(q,M.fromHandle,nt.Left,!0);Y({...M,from:_})}F&&q.parentId&&C.push({id:X,parentId:q.parentId,rect:{...P.internals.positionAbsolute,width:P.measured.width??0,height:P.measured.height??0}}),N.push(D)}if(C.length>0){const{parentLookup:X,nodeOrigin:P}=w(),q=bx(C,k,X,P);N.push(...q)}for(const X of $.values())N=X(N);H(N)},triggerNodeChanges:T=>{const{onNodesChange:E,setNodes:C,nodes:N,hasDefaultNodes:k,debug:H}=w();if(T?.length){if(k){const M=_w(T,N);C(M)}H&&console.log("React Flow: trigger node changes",T),E?.(T)}},triggerEdgeChanges:T=>{const{onEdgesChange:E,setEdges:C,edges:N,hasDefaultEdges:k,debug:H}=w();if(T?.length){if(k){const M=Aw(T,N);C(M)}H&&console.log("React Flow: trigger edge changes",T),E?.(T)}},addSelectedNodes:T=>{const{multiSelectionActive:E,edgeLookup:C,nodeLookup:N,triggerNodeChanges:k,triggerEdgeChanges:H}=w();if(E){const M=T.map(Y=>Ya(Y,!0));k(M);return}k(Hi(N,new Set([...T]),!0)),H(Hi(C))},addSelectedEdges:T=>{const{multiSelectionActive:E,edgeLookup:C,nodeLookup:N,triggerNodeChanges:k,triggerEdgeChanges:H}=w();if(E){const M=T.map(Y=>Ya(Y,!0));H(M);return}H(Hi(C,new Set([...T]))),k(Hi(N,new Set,!0))},unselectNodesAndEdges:({nodes:T,edges:E}={})=>{const{edges:C,nodes:N,nodeLookup:k,triggerNodeChanges:H,triggerEdgeChanges:M}=w(),Y=T||N,$=E||C,X=[];for(const q of Y){if(!q.selected)continue;const F=k.get(q.id);F&&(F.selected=!1),X.push(Ya(q.id,!1))}const P=[];for(const q of $)q.selected&&P.push(Ya(q.id,!1));H(X),M(P)},setMinZoom:T=>{const{panZoom:E,maxZoom:C}=w();E?.setScaleExtent([T,C]),p({minZoom:T})},setMaxZoom:T=>{const{panZoom:E,minZoom:C}=w();E?.setScaleExtent([C,T]),p({maxZoom:T})},setTranslateExtent:T=>{w().panZoom?.setTranslateExtent(T),p({translateExtent:T})},resetSelectedElements:()=>{const{edges:T,nodes:E,triggerNodeChanges:C,triggerEdgeChanges:N,elementsSelectable:k}=w();if(!k)return;const H=E.reduce((Y,$)=>$.selected?[...Y,Ya($.id,!1)]:Y,[]),M=T.reduce((Y,$)=>$.selected?[...Y,Ya($.id,!1)]:Y,[]);C(H),N(M)},setNodeExtent:T=>{const{nodes:E,nodeLookup:C,parentLookup:N,nodeOrigin:k,elevateNodesOnSelect:H,nodeExtent:M,zIndexMode:Y}=w();T[0][0]===M[0][0]&&T[0][1]===M[0][1]&&T[1][0]===M[1][0]&&T[1][1]===M[1][1]||(km(E,C,N,{nodeOrigin:k,nodeExtent:T,elevateNodesOnSelect:H,checkEquality:!1,zIndexMode:Y}),p({nodeExtent:T}))},panBy:T=>{const{transform:E,width:C,height:N,panZoom:k,translateExtent:H}=w();return fD({delta:T,panZoom:k,transform:E,translateExtent:H,width:C,height:N})},setCenter:async(T,E,C)=>{const{width:N,height:k,maxZoom:H,panZoom:M}=w();if(!M)return Promise.resolve(!1);const Y=typeof C?.zoom<"u"?C.zoom:H;return await M.setViewport({x:N/2-T*Y,y:k/2-E*Y,zoom:Y},{duration:C?.duration,ease:C?.ease,interpolate:C?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{p({connection:{...Qj}})},updateConnection:T=>{p({connection:T})},reset:()=>p({...Nv()})}},Object.is);function AR({initialNodes:e,initialEdges:r,defaultNodes:s,defaultEdges:i,initialWidth:o,initialHeight:c,initialMinZoom:u,initialMaxZoom:f,initialFitViewOptions:m,fitView:h,nodeOrigin:x,nodeExtent:g,zIndexMode:b,children:p}){const[w]=j.useState(()=>_R({nodes:e,edges:r,defaultNodes:s,defaultEdges:i,width:o,height:c,fitView:h,minZoom:u,maxZoom:f,fitViewOptions:m,nodeOrigin:x,nodeExtent:g,zIndexMode:b}));return t.jsx(XD,{value:w,children:t.jsx(pO,{children:p})})}function MR({children:e,nodes:r,edges:s,defaultNodes:i,defaultEdges:o,width:c,height:u,fitView:f,fitViewOptions:m,minZoom:h,maxZoom:x,nodeOrigin:g,nodeExtent:b,zIndexMode:p}){return j.useContext(ed)?t.jsx(t.Fragment,{children:e}):t.jsx(AR,{initialNodes:r,initialEdges:s,defaultNodes:i,defaultEdges:o,initialWidth:c,initialHeight:u,fitView:f,initialFitViewOptions:m,initialMinZoom:h,initialMaxZoom:x,nodeOrigin:g,nodeExtent:b,zIndexMode:p,children:e})}const DR={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function OR({nodes:e,edges:r,defaultNodes:s,defaultEdges:i,className:o,nodeTypes:c,edgeTypes:u,onNodeClick:f,onEdgeClick:m,onInit:h,onMove:x,onMoveStart:g,onMoveEnd:b,onConnect:p,onConnectStart:w,onConnectEnd:S,onClickConnectStart:T,onClickConnectEnd:E,onNodeMouseEnter:C,onNodeMouseMove:N,onNodeMouseLeave:k,onNodeContextMenu:H,onNodeDoubleClick:M,onNodeDragStart:Y,onNodeDrag:$,onNodeDragStop:X,onNodesDelete:P,onEdgesDelete:q,onDelete:F,onSelectionChange:D,onSelectionDragStart:_,onSelectionDrag:I,onSelectionDragStop:A,onSelectionContextMenu:G,onSelectionStart:U,onSelectionEnd:K,onBeforeDelete:B,connectionMode:L,connectionLineType:W=ja.Bezier,connectionLineStyle:R,connectionLineComponent:z,connectionLineContainerStyle:V,deleteKeyCode:Q="Backspace",selectionKeyCode:te="Shift",selectionOnDrag:Z=!1,selectionMode:ee=ko.Full,panActivationKeyCode:ie="Space",multiSelectionKeyCode:je=Co()?"Meta":"Control",zoomActivationKeyCode:ke=Co()?"Meta":"Control",snapToGrid:De,snapGrid:Ie,onlyRenderVisibleElements:ze=!1,selectNodesOnDrag:Ze,nodesDraggable:Ae,autoPanOnNodeFocus:We,nodesConnectable:xt,nodesFocusable:Lt,nodeOrigin:le=Ew,edgesFocusable:_e,edgesReconnectable:ht,elementsSelectable:Ct=!0,defaultViewport:Ft=lO,minZoom:be=.5,maxZoom:Me=2,translateExtent:Ve=No,preventScrolling:Xe=!0,nodeExtent:rt,defaultMarkerColor:It="#b1b1b7",zoomOnScroll:Ht=!0,zoomOnPinch:_t=!0,panOnScroll:wt=!1,panOnScrollSpeed:xe=.5,panOnScrollMode:Be=Qa.Free,zoomOnDoubleClick:gt=!0,panOnDrag:pt=!0,onPaneClick:ue,onPaneMouseEnter:Se,onPaneMouseMove:Ke,onPaneMouseLeave:At,onPaneScroll:rn,onPaneContextMenu:vn,paneClickDistance:Mt=1,nodeClickDistance:oe=0,children:Le,onReconnect:$e,onReconnectStart:st,onReconnectEnd:at,onEdgeContextMenu:Ue,onEdgeDoubleClick:jn,onEdgeMouseEnter:gn,onEdgeMouseMove:Dt,onEdgeMouseLeave:Dn,reconnectRadius:Un=10,onNodesChange:On,onEdgesChange:on,noDragClassName:cn="nodrag",noWheelClassName:wn="nowheel",noPanClassName:qn="nopan",fitView:ve,fitViewOptions:Qe,connectOnClick:Nt,attributionPosition:Et,proOptions:Nn,defaultEdgeOptions:ar,elevateNodesOnSelect:ir=!0,elevateEdgesOnSelect:Or=!1,disableKeyboardA11y:Rr=!1,autoPanOnConnect:vr,autoPanOnNodeDrag:un,autoPanSpeed:zr,connectionRadius:Ps,isValidConnection:lr,onError:or,style:Us,id:Tn,nodeDragThreshold:Gr,connectionDragThreshold:Sa,viewport:cr,onViewportChange:Lr,width:Yn,height:kn,colorMode:jr="light",debug:ne,onScroll:Oe,ariaLabelConfig:Pe,zIndexMode:et="basic",...re},pe){const Ne=Tn||"1",ye=dO(jr),dt=j.useCallback(He=>{He.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Oe?.(He)},[Oe]);return t.jsx("div",{"data-testid":"rf__wrapper",...re,onScroll:dt,style:{...Us,...DR},ref:pe,className:Pn(["react-flow",o,ye]),id:Tn,role:"application",children:t.jsxs(MR,{nodes:e,edges:r,width:Yn,height:kn,fitView:ve,fitViewOptions:Qe,minZoom:be,maxZoom:Me,nodeOrigin:le,nodeExtent:rt,zIndexMode:et,children:[t.jsx(TR,{onInit:h,onNodeClick:f,onEdgeClick:m,onNodeMouseEnter:C,onNodeMouseMove:N,onNodeMouseLeave:k,onNodeContextMenu:H,onNodeDoubleClick:M,nodeTypes:c,edgeTypes:u,connectionLineType:W,connectionLineStyle:R,connectionLineComponent:z,connectionLineContainerStyle:V,selectionKeyCode:te,selectionOnDrag:Z,selectionMode:ee,deleteKeyCode:Q,multiSelectionKeyCode:je,panActivationKeyCode:ie,zoomActivationKeyCode:ke,onlyRenderVisibleElements:ze,defaultViewport:Ft,translateExtent:Ve,minZoom:be,maxZoom:Me,preventScrolling:Xe,zoomOnScroll:Ht,zoomOnPinch:_t,zoomOnDoubleClick:gt,panOnScroll:wt,panOnScrollSpeed:xe,panOnScrollMode:Be,panOnDrag:pt,onPaneClick:ue,onPaneMouseEnter:Se,onPaneMouseMove:Ke,onPaneMouseLeave:At,onPaneScroll:rn,onPaneContextMenu:vn,paneClickDistance:Mt,nodeClickDistance:oe,onSelectionContextMenu:G,onSelectionStart:U,onSelectionEnd:K,onReconnect:$e,onReconnectStart:st,onReconnectEnd:at,onEdgeContextMenu:Ue,onEdgeDoubleClick:jn,onEdgeMouseEnter:gn,onEdgeMouseMove:Dt,onEdgeMouseLeave:Dn,reconnectRadius:Un,defaultMarkerColor:It,noDragClassName:cn,noWheelClassName:wn,noPanClassName:qn,rfId:Ne,disableKeyboardA11y:Rr,nodeExtent:rt,viewport:cr,onViewportChange:Lr}),t.jsx(uO,{nodes:e,edges:r,defaultNodes:s,defaultEdges:i,onConnect:p,onConnectStart:w,onConnectEnd:S,onClickConnectStart:T,onClickConnectEnd:E,nodesDraggable:Ae,autoPanOnNodeFocus:We,nodesConnectable:xt,nodesFocusable:Lt,edgesFocusable:_e,edgesReconnectable:ht,elementsSelectable:Ct,elevateNodesOnSelect:ir,elevateEdgesOnSelect:Or,minZoom:be,maxZoom:Me,nodeExtent:rt,onNodesChange:On,onEdgesChange:on,snapToGrid:De,snapGrid:Ie,connectionMode:L,translateExtent:Ve,connectOnClick:Nt,defaultEdgeOptions:ar,fitView:ve,fitViewOptions:Qe,onNodesDelete:P,onEdgesDelete:q,onDelete:F,onNodeDragStart:Y,onNodeDrag:$,onNodeDragStop:X,onSelectionDrag:I,onSelectionDragStart:_,onSelectionDragStop:A,onMove:x,onMoveStart:g,onMoveEnd:b,noPanClassName:qn,nodeOrigin:le,rfId:Ne,autoPanOnConnect:vr,autoPanOnNodeDrag:un,autoPanSpeed:zr,onError:or,connectionRadius:Ps,isValidConnection:lr,selectNodesOnDrag:Ze,nodeDragThreshold:Gr,connectionDragThreshold:Sa,onBeforeDelete:B,debug:ne,ariaLabelConfig:Pe,zIndexMode:et}),t.jsx(iO,{onSelectionChange:D}),Le,t.jsx(tO,{proOptions:Nn,position:Et}),t.jsx(eO,{rfId:Ne,disableKeyboardA11y:Rr})]})})}var RR=Mw(OR);function zR(e){const[r,s]=j.useState(e),i=j.useCallback(o=>s(c=>_w(o,c)),[]);return[r,s,i]}function LR(e){const[r,s]=j.useState(e),i=j.useCallback(o=>s(c=>Aw(o,c)),[]);return[r,s,i]}function IR({dimensions:e,lineWidth:r,variant:s,className:i}){return t.jsx("path",{strokeWidth:r,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Pn(["react-flow__background-pattern",s,i])})}function $R({radius:e,className:r}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Pn(["react-flow__background-pattern","dots",r])})}var wa;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(wa||(wa={}));const BR={[wa.Dots]:1,[wa.Lines]:1,[wa.Cross]:6},HR=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function tN({id:e,variant:r=wa.Dots,gap:s=20,size:i,lineWidth:o=1,offset:c=0,color:u,bgColor:f,style:m,className:h,patternClassName:x}){const g=j.useRef(null),{transform:b,patternId:p}=Vt(HR,bn),w=i||BR[r],S=r===wa.Dots,T=r===wa.Cross,E=Array.isArray(s)?s:[s,s],C=[E[0]*b[2]||1,E[1]*b[2]||1],N=w*b[2],k=Array.isArray(c)?c:[c,c],H=T?[N,N]:C,M=[k[0]*b[2]||1+H[0]/2,k[1]*b[2]||1+H[1]/2],Y=`${p}${e||""}`;return t.jsxs("svg",{className:Pn(["react-flow__background",h]),style:{...m,...nd,"--xy-background-color-props":f,"--xy-background-pattern-color-props":u},ref:g,"data-testid":"rf__background",children:[t.jsx("pattern",{id:Y,x:b[0]%C[0],y:b[1]%C[1],width:C[0],height:C[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${M[0]},-${M[1]})`,children:S?t.jsx($R,{radius:N/2,className:x}):t.jsx(IR,{dimensions:H,lineWidth:o,variant:r,className:x})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${Y})`})]})}tN.displayName="Background";const PR=j.memo(tN);function UR(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:t.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function qR(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:t.jsx("path",{d:"M0 0h32v4.2H0z"})})}function VR(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:t.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function FR(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function YR(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function lu({children:e,className:r,...s}){return t.jsx("button",{type:"button",className:Pn(["react-flow__controls-button",r]),...s,children:e})}const GR=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function nN({style:e,showZoom:r=!0,showFitView:s=!0,showInteractive:i=!0,fitViewOptions:o,onZoomIn:c,onZoomOut:u,onFitView:f,onInteractiveChange:m,className:h,children:x,position:g="bottom-left",orientation:b="vertical","aria-label":p}){const w=yn(),{isInteractive:S,minZoomReached:T,maxZoomReached:E,ariaLabelConfig:C}=Vt(GR,bn),{zoomIn:N,zoomOut:k,fitView:H}=yx(),M=()=>{N(),c?.()},Y=()=>{k(),u?.()},$=()=>{H(o),f?.()},X=()=>{w.setState({nodesDraggable:!S,nodesConnectable:!S,elementsSelectable:!S}),m?.(!S)},P=b==="horizontal"?"horizontal":"vertical";return t.jsxs(td,{className:Pn(["react-flow__controls",P,h]),position:g,style:e,"data-testid":"rf__controls","aria-label":p??C["controls.ariaLabel"],children:[r&&t.jsxs(t.Fragment,{children:[t.jsx(lu,{onClick:M,className:"react-flow__controls-zoomin",title:C["controls.zoomIn.ariaLabel"],"aria-label":C["controls.zoomIn.ariaLabel"],disabled:E,children:t.jsx(UR,{})}),t.jsx(lu,{onClick:Y,className:"react-flow__controls-zoomout",title:C["controls.zoomOut.ariaLabel"],"aria-label":C["controls.zoomOut.ariaLabel"],disabled:T,children:t.jsx(qR,{})})]}),s&&t.jsx(lu,{className:"react-flow__controls-fitview",onClick:$,title:C["controls.fitView.ariaLabel"],"aria-label":C["controls.fitView.ariaLabel"],children:t.jsx(VR,{})}),i&&t.jsx(lu,{className:"react-flow__controls-interactive",onClick:X,title:C["controls.interactive.ariaLabel"],"aria-label":C["controls.interactive.ariaLabel"],children:S?t.jsx(YR,{}):t.jsx(FR,{})}),x]})}nN.displayName="Controls";const XR=j.memo(nN);function ZR({id:e,x:r,y:s,width:i,height:o,style:c,color:u,strokeColor:f,strokeWidth:m,className:h,borderRadius:x,shapeRendering:g,selected:b,onClick:p}){const{background:w,backgroundColor:S}=c||{},T=u||w||S;return t.jsx("rect",{className:Pn(["react-flow__minimap-node",{selected:b},h]),x:r,y:s,rx:x,ry:x,width:i,height:o,style:{fill:T,stroke:f,strokeWidth:m},shapeRendering:g,onClick:p?E=>p(E,e):void 0})}const QR=j.memo(ZR),KR=e=>e.nodes.map(r=>r.id),Fh=e=>e instanceof Function?e:()=>e;function JR({nodeStrokeColor:e,nodeColor:r,nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o,nodeComponent:c=QR,onClick:u}){const f=Vt(KR,bn),m=Fh(r),h=Fh(e),x=Fh(s),g=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:f.map(b=>t.jsx(ez,{id:b,nodeColorFunc:m,nodeStrokeColorFunc:h,nodeClassNameFunc:x,nodeBorderRadius:i,nodeStrokeWidth:o,NodeComponent:c,onClick:u,shapeRendering:g},b))})}function WR({id:e,nodeColorFunc:r,nodeStrokeColorFunc:s,nodeClassNameFunc:i,nodeBorderRadius:o,nodeStrokeWidth:c,shapeRendering:u,NodeComponent:f,onClick:m}){const{node:h,x,y:g,width:b,height:p}=Vt(w=>{const S=w.nodeLookup.get(e);if(!S)return{node:void 0,x:0,y:0,width:0,height:0};const T=S.internals.userNode,{x:E,y:C}=S.internals.positionAbsolute,{width:N,height:k}=Hs(T);return{node:T,x:E,y:C,width:N,height:k}},bn);return!h||h.hidden||!rw(h)?null:t.jsx(f,{x,y:g,width:b,height:p,style:h.style,selected:!!h.selected,className:i(h),color:r(h),borderRadius:o,strokeColor:s(h),strokeWidth:c,shapeRendering:u,onClick:m,id:h.id})}const ez=j.memo(WR);var tz=j.memo(JR);const nz=200,rz=150,sz=e=>!e.hidden,az=e=>{const r={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:r,boundingRect:e.nodeLookup.size>0?nw(Lo(e.nodeLookup,{filter:sz}),r):r,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},iz="react-flow__minimap-desc";function rN({style:e,className:r,nodeStrokeColor:s,nodeColor:i,nodeClassName:o="",nodeBorderRadius:c=5,nodeStrokeWidth:u,nodeComponent:f,bgColor:m,maskColor:h,maskStrokeColor:x,maskStrokeWidth:g,position:b="bottom-right",onClick:p,onNodeClick:w,pannable:S=!1,zoomable:T=!1,ariaLabel:E,inversePan:C,zoomStep:N=1,offsetScale:k=5}){const H=yn(),M=j.useRef(null),{boundingRect:Y,viewBB:$,rfId:X,panZoom:P,translateExtent:q,flowWidth:F,flowHeight:D,ariaLabelConfig:_}=Vt(az,bn),I=e?.width??nz,A=e?.height??rz,G=Y.width/I,U=Y.height/A,K=Math.max(G,U),B=K*I,L=K*A,W=k*K,R=Y.x-(B-Y.width)/2-W,z=Y.y-(L-Y.height)/2-W,V=B+W*2,Q=L+W*2,te=`${iz}-${X}`,Z=j.useRef(0),ee=j.useRef();Z.current=K,j.useEffect(()=>{if(M.current&&P)return ee.current=jD({domNode:M.current,panZoom:P,getTransform:()=>H.getState().transform,getViewScale:()=>Z.current}),()=>{ee.current?.destroy()}},[P]),j.useEffect(()=>{ee.current?.update({translateExtent:q,width:F,height:D,inversePan:C,pannable:S,zoomStep:N,zoomable:T})},[S,T,C,N,q,F,D]);const ie=p?De=>{const[Ie,ze]=ee.current?.pointer(De)||[0,0];p(De,{x:Ie,y:ze})}:void 0,je=w?j.useCallback((De,Ie)=>{const ze=H.getState().nodeLookup.get(Ie).internals.userNode;w(De,ze)},[]):void 0,ke=E??_["minimap.ariaLabel"];return t.jsx(td,{position:b,style:{...e,"--xy-minimap-background-color-props":typeof m=="string"?m:void 0,"--xy-minimap-mask-background-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-color-props":typeof x=="string"?x:void 0,"--xy-minimap-mask-stroke-width-props":typeof g=="number"?g*K:void 0,"--xy-minimap-node-background-color-props":typeof i=="string"?i:void 0,"--xy-minimap-node-stroke-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-width-props":typeof u=="number"?u:void 0},className:Pn(["react-flow__minimap",r]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:I,height:A,viewBox:`${R} ${z} ${V} ${Q}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":te,ref:M,onClick:ie,children:[ke&&t.jsx("title",{id:te,children:ke}),t.jsx(tz,{onClick:je,nodeColor:i,nodeStrokeColor:s,nodeBorderRadius:c,nodeClassName:o,nodeStrokeWidth:u,nodeComponent:f}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${R-W},${z-W}h${V+W*2}v${Q+W*2}h${-V-W*2}z
61
- M${$.x},${$.y}h${$.width}v${$.height}h${-$.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}rN.displayName="MiniMap";const lz=j.memo(rN),oz=e=>r=>e?`${Math.max(1/r.transform[2],1)}`:void 0,cz={[Wi.Line]:"right",[Wi.Handle]:"bottom-right"};function uz({nodeId:e,position:r,variant:s=Wi.Handle,className:i,style:o=void 0,children:c,color:u,minWidth:f=10,minHeight:m=10,maxWidth:h=Number.MAX_VALUE,maxHeight:x=Number.MAX_VALUE,keepAspectRatio:g=!1,resizeDirection:b,autoScale:p=!0,shouldResize:w,onResizeStart:S,onResize:T,onResizeEnd:E}){const C=zw(),N=typeof e=="string"?e:C,k=yn(),H=j.useRef(null),M=s===Wi.Handle,Y=Vt(j.useCallback(oz(M&&p),[M,p]),bn),$=j.useRef(null),X=r??cz[s];j.useEffect(()=>{if(!(!H.current||!N))return $.current||($.current=zD({domNode:H.current,nodeId:N,getStoreItems:()=>{const{nodeLookup:q,transform:F,snapGrid:D,snapToGrid:_,nodeOrigin:I,domNode:A}=k.getState();return{nodeLookup:q,transform:F,snapGrid:D,snapToGrid:_,nodeOrigin:I,paneDomNode:A}},onChange:(q,F)=>{const{triggerNodeChanges:D,nodeLookup:_,parentLookup:I,nodeOrigin:A}=k.getState(),G=[],U={x:q.x,y:q.y},K=_.get(N);if(K&&K.expandParent&&K.parentId){const B=K.origin??A,L=q.width??K.measured.width??0,W=q.height??K.measured.height??0,R={id:K.id,parentId:K.parentId,rect:{width:L,height:W,...sw({x:q.x??K.position.x,y:q.y??K.position.y},{width:L,height:W},K.parentId,_,B)}},z=bx([R],_,I,A);G.push(...z),U.x=q.x?Math.max(B[0]*L,q.x):void 0,U.y=q.y?Math.max(B[1]*W,q.y):void 0}if(U.x!==void 0&&U.y!==void 0){const B={id:N,type:"position",position:{...U}};G.push(B)}if(q.width!==void 0&&q.height!==void 0){const L={id:N,type:"dimensions",resizing:!0,setAttributes:b?b==="horizontal"?"width":"height":!0,dimensions:{width:q.width,height:q.height}};G.push(L)}for(const B of F){const L={...B,type:"position"};G.push(L)}D(G)},onEnd:({width:q,height:F})=>{const D={id:N,type:"dimensions",resizing:!1,dimensions:{width:q,height:F}};k.getState().triggerNodeChanges([D])}})),$.current.update({controlPosition:X,boundaries:{minWidth:f,minHeight:m,maxWidth:h,maxHeight:x},keepAspectRatio:g,resizeDirection:b,onResizeStart:S,onResize:T,onResizeEnd:E,shouldResize:w}),()=>{$.current?.destroy()}},[X,f,m,h,x,g,S,T,E,w]);const P=X.split("-");return t.jsx("div",{className:Pn(["react-flow__resize-control","nodrag",...P,s,i]),ref:H,style:{...o,scale:Y,...u&&{[M?"backgroundColor":"borderColor"]:u}},children:c})}j.memo(uz);var Wt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),ns=Wt((e,r)=>{var s=Object.defineProperty,i=(D,_,I)=>_ in D?s(D,_,{enumerable:!0,configurable:!0,writable:!0,value:I}):D[_]=I,o=(D,_)=>()=>(_||D((_={exports:{}}).exports,_),_.exports),c=(D,_,I)=>i(D,typeof _!="symbol"?_+"":_,I),u=o((D,_)=>{var I="\0",A="\0",G="",U=class{constructor(z){c(this,"_isDirected",!0),c(this,"_isMultigraph",!1),c(this,"_isCompound",!1),c(this,"_label"),c(this,"_defaultNodeLabelFn",()=>{}),c(this,"_defaultEdgeLabelFn",()=>{}),c(this,"_nodes",{}),c(this,"_in",{}),c(this,"_preds",{}),c(this,"_out",{}),c(this,"_sucs",{}),c(this,"_edgeObjs",{}),c(this,"_edgeLabels",{}),c(this,"_nodeCount",0),c(this,"_edgeCount",0),c(this,"_parent"),c(this,"_children"),z&&(this._isDirected=Object.hasOwn(z,"directed")?z.directed:!0,this._isMultigraph=Object.hasOwn(z,"multigraph")?z.multigraph:!1,this._isCompound=Object.hasOwn(z,"compound")?z.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[A]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(z){return this._label=z,this}graph(){return this._label}setDefaultNodeLabel(z){return this._defaultNodeLabelFn=z,typeof z!="function"&&(this._defaultNodeLabelFn=()=>z),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var z=this;return this.nodes().filter(V=>Object.keys(z._in[V]).length===0)}sinks(){var z=this;return this.nodes().filter(V=>Object.keys(z._out[V]).length===0)}setNodes(z,V){var Q=arguments,te=this;return z.forEach(function(Z){Q.length>1?te.setNode(Z,V):te.setNode(Z)}),this}setNode(z,V){return Object.hasOwn(this._nodes,z)?(arguments.length>1&&(this._nodes[z]=V),this):(this._nodes[z]=arguments.length>1?V:this._defaultNodeLabelFn(z),this._isCompound&&(this._parent[z]=A,this._children[z]={},this._children[A][z]=!0),this._in[z]={},this._preds[z]={},this._out[z]={},this._sucs[z]={},++this._nodeCount,this)}node(z){return this._nodes[z]}hasNode(z){return Object.hasOwn(this._nodes,z)}removeNode(z){var V=this;if(Object.hasOwn(this._nodes,z)){var Q=te=>V.removeEdge(V._edgeObjs[te]);delete this._nodes[z],this._isCompound&&(this._removeFromParentsChildList(z),delete this._parent[z],this.children(z).forEach(function(te){V.setParent(te)}),delete this._children[z]),Object.keys(this._in[z]).forEach(Q),delete this._in[z],delete this._preds[z],Object.keys(this._out[z]).forEach(Q),delete this._out[z],delete this._sucs[z],--this._nodeCount}return this}setParent(z,V){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(V===void 0)V=A;else{V+="";for(var Q=V;Q!==void 0;Q=this.parent(Q))if(Q===z)throw new Error("Setting "+V+" as parent of "+z+" would create a cycle");this.setNode(V)}return this.setNode(z),this._removeFromParentsChildList(z),this._parent[z]=V,this._children[V][z]=!0,this}_removeFromParentsChildList(z){delete this._children[this._parent[z]][z]}parent(z){if(this._isCompound){var V=this._parent[z];if(V!==A)return V}}children(z=A){if(this._isCompound){var V=this._children[z];if(V)return Object.keys(V)}else{if(z===A)return this.nodes();if(this.hasNode(z))return[]}}predecessors(z){var V=this._preds[z];if(V)return Object.keys(V)}successors(z){var V=this._sucs[z];if(V)return Object.keys(V)}neighbors(z){var V=this.predecessors(z);if(V){let te=new Set(V);for(var Q of this.successors(z))te.add(Q);return Array.from(te.values())}}isLeaf(z){var V;return this.isDirected()?V=this.successors(z):V=this.neighbors(z),V.length===0}filterNodes(z){var V=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});V.setGraph(this.graph());var Q=this;Object.entries(this._nodes).forEach(function([ee,ie]){z(ee)&&V.setNode(ee,ie)}),Object.values(this._edgeObjs).forEach(function(ee){V.hasNode(ee.v)&&V.hasNode(ee.w)&&V.setEdge(ee,Q.edge(ee))});var te={};function Z(ee){var ie=Q.parent(ee);return ie===void 0||V.hasNode(ie)?(te[ee]=ie,ie):ie in te?te[ie]:Z(ie)}return this._isCompound&&V.nodes().forEach(ee=>V.setParent(ee,Z(ee))),V}setDefaultEdgeLabel(z){return this._defaultEdgeLabelFn=z,typeof z!="function"&&(this._defaultEdgeLabelFn=()=>z),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(z,V){var Q=this,te=arguments;return z.reduce(function(Z,ee){return te.length>1?Q.setEdge(Z,ee,V):Q.setEdge(Z,ee),ee}),this}setEdge(){var z,V,Q,te,Z=!1,ee=arguments[0];typeof ee=="object"&&ee!==null&&"v"in ee?(z=ee.v,V=ee.w,Q=ee.name,arguments.length===2&&(te=arguments[1],Z=!0)):(z=ee,V=arguments[1],Q=arguments[3],arguments.length>2&&(te=arguments[2],Z=!0)),z=""+z,V=""+V,Q!==void 0&&(Q=""+Q);var ie=L(this._isDirected,z,V,Q);if(Object.hasOwn(this._edgeLabels,ie))return Z&&(this._edgeLabels[ie]=te),this;if(Q!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(z),this.setNode(V),this._edgeLabels[ie]=Z?te:this._defaultEdgeLabelFn(z,V,Q);var je=W(this._isDirected,z,V,Q);return z=je.v,V=je.w,Object.freeze(je),this._edgeObjs[ie]=je,K(this._preds[V],z),K(this._sucs[z],V),this._in[V][ie]=je,this._out[z][ie]=je,this._edgeCount++,this}edge(z,V,Q){var te=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,Q);return this._edgeLabels[te]}edgeAsObj(){let z=this.edge(...arguments);return typeof z!="object"?{label:z}:z}hasEdge(z,V,Q){var te=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,Q);return Object.hasOwn(this._edgeLabels,te)}removeEdge(z,V,Q){var te=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,Q),Z=this._edgeObjs[te];return Z&&(z=Z.v,V=Z.w,delete this._edgeLabels[te],delete this._edgeObjs[te],B(this._preds[V],z),B(this._sucs[z],V),delete this._in[V][te],delete this._out[z][te],this._edgeCount--),this}inEdges(z,V){return this.isDirected()?this.filterEdges(this._in[z],z,V):this.nodeEdges(z,V)}outEdges(z,V){return this.isDirected()?this.filterEdges(this._out[z],z,V):this.nodeEdges(z,V)}nodeEdges(z,V){if(z in this._nodes)return this.filterEdges({...this._in[z],...this._out[z]},z,V)}filterEdges(z,V,Q){if(z){var te=Object.values(z);return Q?te.filter(function(Z){return Z.v===V&&Z.w===Q||Z.v===Q&&Z.w===V}):te}}};function K(z,V){z[V]?z[V]++:z[V]=1}function B(z,V){--z[V]||delete z[V]}function L(z,V,Q,te){var Z=""+V,ee=""+Q;if(!z&&Z>ee){var ie=Z;Z=ee,ee=ie}return Z+G+ee+G+(te===void 0?I:te)}function W(z,V,Q,te){var Z=""+V,ee=""+Q;if(!z&&Z>ee){var ie=Z;Z=ee,ee=ie}var je={v:Z,w:ee};return te&&(je.name=te),je}function R(z,V){return L(z,V.v,V.w,V.name)}_.exports=U}),f=o((D,_)=>{_.exports="3.0.2"}),m=o((D,_)=>{_.exports={Graph:u(),version:f()}}),h=o((D,_)=>{var I=u();_.exports={write:A,read:K};function A(B){var L={options:{directed:B.isDirected(),multigraph:B.isMultigraph(),compound:B.isCompound()},nodes:G(B),edges:U(B)};return B.graph()!==void 0&&(L.value=structuredClone(B.graph())),L}function G(B){return B.nodes().map(function(L){var W=B.node(L),R=B.parent(L),z={v:L};return W!==void 0&&(z.value=W),R!==void 0&&(z.parent=R),z})}function U(B){return B.edges().map(function(L){var W=B.edge(L),R={v:L.v,w:L.w};return L.name!==void 0&&(R.name=L.name),W!==void 0&&(R.value=W),R})}function K(B){var L=new I(B.options).setGraph(B.value);return B.nodes.forEach(function(W){L.setNode(W.v,W.value),W.parent&&L.setParent(W.v,W.parent)}),B.edges.forEach(function(W){L.setEdge({v:W.v,w:W.w,name:W.name},W.value)}),L}}),x=o((D,_)=>{_.exports=A;var I=()=>1;function A(U,K,B,L){return G(U,String(K),B||I,L||function(W){return U.outEdges(W)})}function G(U,K,B,L){var W={},R=!0,z=0,V=U.nodes(),Q=function(ie){var je=B(ie);W[ie.v].distance+je<W[ie.w].distance&&(W[ie.w]={distance:W[ie.v].distance+je,predecessor:ie.v},R=!0)},te=function(){V.forEach(function(ie){L(ie).forEach(function(je){var ke=je.v===ie?je.v:je.w,De=ke===je.v?je.w:je.v;Q({v:ke,w:De})})})};V.forEach(function(ie){var je=ie===K?0:Number.POSITIVE_INFINITY;W[ie]={distance:je}});for(var Z=V.length,ee=1;ee<Z&&(R=!1,z++,te(),!!R);ee++);if(z===Z-1&&(R=!1,te(),R))throw new Error("The graph contains a negative weight cycle");return W}}),g=o((D,_)=>{_.exports=I;function I(A){var G={},U=[],K;function B(L){Object.hasOwn(G,L)||(G[L]=!0,K.push(L),A.successors(L).forEach(B),A.predecessors(L).forEach(B))}return A.nodes().forEach(function(L){K=[],B(L),K.length&&U.push(K)}),U}}),b=o((D,_)=>{var I=class{constructor(){c(this,"_arr",[]),c(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(A){return A.key})}has(A){return Object.hasOwn(this._keyIndices,A)}priority(A){var G=this._keyIndices[A];if(G!==void 0)return this._arr[G].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(A,G){var U=this._keyIndices;if(A=String(A),!Object.hasOwn(U,A)){var K=this._arr,B=K.length;return U[A]=B,K.push({key:A,priority:G}),this._decrease(B),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var A=this._arr.pop();return delete this._keyIndices[A.key],this._heapify(0),A.key}decrease(A,G){var U=this._keyIndices[A];if(G>this._arr[U].priority)throw new Error("New priority is greater than current priority. Key: "+A+" Old: "+this._arr[U].priority+" New: "+G);this._arr[U].priority=G,this._decrease(U)}_heapify(A){var G=this._arr,U=2*A,K=U+1,B=A;U<G.length&&(B=G[U].priority<G[B].priority?U:B,K<G.length&&(B=G[K].priority<G[B].priority?K:B),B!==A&&(this._swap(A,B),this._heapify(B)))}_decrease(A){for(var G=this._arr,U=G[A].priority,K;A!==0&&(K=A>>1,!(G[K].priority<U));)this._swap(A,K),A=K}_swap(A,G){var U=this._arr,K=this._keyIndices,B=U[A],L=U[G];U[A]=L,U[G]=B,K[L.key]=A,K[B.key]=G}};_.exports=I}),p=o((D,_)=>{var I=b();_.exports=G;var A=()=>1;function G(K,B,L,W){var R=function(z){return K.outEdges(z)};return U(K,String(B),L||A,W||R)}function U(K,B,L,W){var R={},z=new I,V,Q,te=function(Z){var ee=Z.v!==V?Z.v:Z.w,ie=R[ee],je=L(Z),ke=Q.distance+je;if(je<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+Z+" Weight: "+je);ke<ie.distance&&(ie.distance=ke,ie.predecessor=V,z.decrease(ee,ke))};for(K.nodes().forEach(function(Z){var ee=Z===B?0:Number.POSITIVE_INFINITY;R[Z]={distance:ee},z.add(Z,ee)});z.size()>0&&(V=z.removeMin(),Q=R[V],Q.distance!==Number.POSITIVE_INFINITY);)W(V).forEach(te);return R}}),w=o((D,_)=>{var I=p();_.exports=A;function A(G,U,K){return G.nodes().reduce(function(B,L){return B[L]=I(G,L,U,K),B},{})}}),S=o((D,_)=>{_.exports=I;function I(G,U,K){if(G[U].predecessor!==void 0)throw new Error("Invalid source vertex");if(G[K].predecessor===void 0&&K!==U)throw new Error("Invalid destination vertex");return{weight:G[K].distance,path:A(G,U,K)}}function A(G,U,K){for(var B=[],L=K;L!==U;)B.push(L),L=G[L].predecessor;return B.push(U),B.reverse()}}),T=o((D,_)=>{_.exports=I;function I(A){var G=0,U=[],K={},B=[];function L(W){var R=K[W]={onStack:!0,lowlink:G,index:G++};if(U.push(W),A.successors(W).forEach(function(Q){Object.hasOwn(K,Q)?K[Q].onStack&&(R.lowlink=Math.min(R.lowlink,K[Q].index)):(L(Q),R.lowlink=Math.min(R.lowlink,K[Q].lowlink))}),R.lowlink===R.index){var z=[],V;do V=U.pop(),K[V].onStack=!1,z.push(V);while(W!==V);B.push(z)}}return A.nodes().forEach(function(W){Object.hasOwn(K,W)||L(W)}),B}}),E=o((D,_)=>{var I=T();_.exports=A;function A(G){return I(G).filter(function(U){return U.length>1||U.length===1&&G.hasEdge(U[0],U[0])})}}),C=o((D,_)=>{_.exports=A;var I=()=>1;function A(U,K,B){return G(U,K||I,B||function(L){return U.outEdges(L)})}function G(U,K,B){var L={},W=U.nodes();return W.forEach(function(R){L[R]={},L[R][R]={distance:0},W.forEach(function(z){R!==z&&(L[R][z]={distance:Number.POSITIVE_INFINITY})}),B(R).forEach(function(z){var V=z.v===R?z.w:z.v,Q=K(z);L[R][V]={distance:Q,predecessor:R}})}),W.forEach(function(R){var z=L[R];W.forEach(function(V){var Q=L[V];W.forEach(function(te){var Z=Q[R],ee=z[te],ie=Q[te],je=Z.distance+ee.distance;je<ie.distance&&(ie.distance=je,ie.predecessor=ee.predecessor)})})}),L}}),N=o((D,_)=>{function I(G){var U={},K={},B=[];function L(W){if(Object.hasOwn(K,W))throw new A;Object.hasOwn(U,W)||(K[W]=!0,U[W]=!0,G.predecessors(W).forEach(L),delete K[W],B.push(W))}if(G.sinks().forEach(L),Object.keys(U).length!==G.nodeCount())throw new A;return B}var A=class extends Error{constructor(){super(...arguments)}};_.exports=I,I.CycleException=A}),k=o((D,_)=>{var I=N();_.exports=A;function A(G){try{I(G)}catch(U){if(U instanceof I.CycleException)return!1;throw U}return!0}}),H=o((D,_)=>{_.exports=I;function I(G,U,K,B,L){Array.isArray(U)||(U=[U]);var W=(G.isDirected()?G.successors:G.neighbors).bind(G),R={};return U.forEach(function(z){if(!G.hasNode(z))throw new Error("Graph does not have node: "+z);L=A(G,z,K==="post",R,W,B,L)}),L}function A(G,U,K,B,L,W,R){return Object.hasOwn(B,U)||(B[U]=!0,K||(R=W(R,U)),L(U).forEach(function(z){R=A(G,z,K,B,L,W,R)}),K&&(R=W(R,U))),R}}),M=o((D,_)=>{var I=H();_.exports=A;function A(G,U,K){return I(G,U,K,function(B,L){return B.push(L),B},[])}}),Y=o((D,_)=>{var I=M();_.exports=A;function A(G,U){return I(G,U,"post")}}),$=o((D,_)=>{var I=M();_.exports=A;function A(G,U){return I(G,U,"pre")}}),X=o((D,_)=>{var I=u(),A=b();_.exports=G;function G(U,K){var B=new I,L={},W=new A,R;function z(Q){var te=Q.v===R?Q.w:Q.v,Z=W.priority(te);if(Z!==void 0){var ee=K(Q);ee<Z&&(L[te]=R,W.decrease(te,ee))}}if(U.nodeCount()===0)return B;U.nodes().forEach(function(Q){W.add(Q,Number.POSITIVE_INFINITY),B.setNode(Q)}),W.decrease(U.nodes()[0],0);for(var V=!1;W.size()>0;){if(R=W.removeMin(),Object.hasOwn(L,R))B.setEdge(R,L[R]);else{if(V)throw new Error("Input graph is not connected: "+U);V=!0}U.nodeEdges(R).forEach(z)}return B}}),P=o((D,_)=>{var I=p(),A=x();_.exports=G;function G(K,B,L,W){return U(K,B,L,W||function(R){return K.outEdges(R)})}function U(K,B,L,W){if(L===void 0)return I(K,B,L,W);for(var R=!1,z=K.nodes(),V=0;V<z.length;V++){for(var Q=W(z[V]),te=0;te<Q.length;te++){var Z=Q[te],ee=Z.v===z[V]?Z.v:Z.w,ie=ee===Z.v?Z.w:Z.v;L({v:ee,w:ie})<0&&(R=!0)}if(R)return A(K,B,L,W)}return I(K,B,L,W)}}),q=o((D,_)=>{_.exports={bellmanFord:x(),components:g(),dijkstra:p(),dijkstraAll:w(),extractPath:S(),findCycles:E(),floydWarshall:C(),isAcyclic:k(),postorder:Y(),preorder:$(),prim:X(),shortestPaths:P(),reduce:H(),tarjan:T(),topsort:N()}}),F=m();r.exports={Graph:F.Graph,json:h(),alg:q(),version:F.version}}),dz=Wt((e,r)=>{var s=class{constructor(){let c={};c._next=c._prev=c,this._sentinel=c}dequeue(){let c=this._sentinel,u=c._prev;if(u!==c)return i(u),u}enqueue(c){let u=this._sentinel;c._prev&&c._next&&i(c),c._next=u._next,u._next._prev=c,u._next=c,c._prev=u}toString(){let c=[],u=this._sentinel,f=u._prev;for(;f!==u;)c.push(JSON.stringify(f,o)),f=f._prev;return"["+c.join(", ")+"]"}};function i(c){c._prev._next=c._next,c._next._prev=c._prev,delete c._next,delete c._prev}function o(c,u){if(c!=="_next"&&c!=="_prev")return u}r.exports=s}),fz=Wt((e,r)=>{var s=ns().Graph,i=dz();r.exports=c;var o=()=>1;function c(g,b){if(g.nodeCount()<=1)return[];let p=m(g,b||o);return u(p.graph,p.buckets,p.zeroIdx).flatMap(w=>g.outEdges(w.v,w.w))}function u(g,b,p){let w=[],S=b[b.length-1],T=b[0],E;for(;g.nodeCount();){for(;E=T.dequeue();)f(g,b,p,E);for(;E=S.dequeue();)f(g,b,p,E);if(g.nodeCount()){for(let C=b.length-2;C>0;--C)if(E=b[C].dequeue(),E){w=w.concat(f(g,b,p,E,!0));break}}}return w}function f(g,b,p,w,S){let T=S?[]:void 0;return g.inEdges(w.v).forEach(E=>{let C=g.edge(E),N=g.node(E.v);S&&T.push({v:E.v,w:E.w}),N.out-=C,h(b,p,N)}),g.outEdges(w.v).forEach(E=>{let C=g.edge(E),N=E.w,k=g.node(N);k.in-=C,h(b,p,k)}),g.removeNode(w.v),T}function m(g,b){let p=new s,w=0,S=0;g.nodes().forEach(C=>{p.setNode(C,{v:C,in:0,out:0})}),g.edges().forEach(C=>{let N=p.edge(C.v,C.w)||0,k=b(C),H=N+k;p.setEdge(C.v,C.w,H),S=Math.max(S,p.node(C.v).out+=k),w=Math.max(w,p.node(C.w).in+=k)});let T=x(S+w+3).map(()=>new i),E=w+1;return p.nodes().forEach(C=>{h(T,E,p.node(C))}),{graph:p,buckets:T,zeroIdx:E}}function h(g,b,p){p.out?p.in?g[p.out-p.in+b].enqueue(p):g[g.length-1].enqueue(p):g[0].enqueue(p)}function x(g){let b=[];for(let p=0;p<g;p++)b.push(p);return b}}),Hn=Wt((e,r)=>{var s=ns().Graph;r.exports={addBorderNode:b,addDummyNode:i,applyWithChunking:S,asNonCompoundGraph:c,buildLayerMatrix:h,intersectRect:m,mapValues:$,maxRank:T,normalizeRanks:x,notime:N,partition:E,pick:Y,predecessorWeights:f,range:M,removeEmptyRanks:g,simplify:o,successorWeights:u,time:C,uniqueId:H,zipObject:X};function i(P,q,F,D){for(var _=D;P.hasNode(_);)_=H(D);return F.dummy=q,P.setNode(_,F),_}function o(P){let q=new s().setGraph(P.graph());return P.nodes().forEach(F=>q.setNode(F,P.node(F))),P.edges().forEach(F=>{let D=q.edge(F.v,F.w)||{weight:0,minlen:1},_=P.edge(F);q.setEdge(F.v,F.w,{weight:D.weight+_.weight,minlen:Math.max(D.minlen,_.minlen)})}),q}function c(P){let q=new s({multigraph:P.isMultigraph()}).setGraph(P.graph());return P.nodes().forEach(F=>{P.children(F).length||q.setNode(F,P.node(F))}),P.edges().forEach(F=>{q.setEdge(F,P.edge(F))}),q}function u(P){let q=P.nodes().map(F=>{let D={};return P.outEdges(F).forEach(_=>{D[_.w]=(D[_.w]||0)+P.edge(_).weight}),D});return X(P.nodes(),q)}function f(P){let q=P.nodes().map(F=>{let D={};return P.inEdges(F).forEach(_=>{D[_.v]=(D[_.v]||0)+P.edge(_).weight}),D});return X(P.nodes(),q)}function m(P,q){let F=P.x,D=P.y,_=q.x-F,I=q.y-D,A=P.width/2,G=P.height/2;if(!_&&!I)throw new Error("Not possible to find intersection inside of the rectangle");let U,K;return Math.abs(I)*A>Math.abs(_)*G?(I<0&&(G=-G),U=G*_/I,K=G):(_<0&&(A=-A),U=A,K=A*I/_),{x:F+U,y:D+K}}function h(P){let q=M(T(P)+1).map(()=>[]);return P.nodes().forEach(F=>{let D=P.node(F),_=D.rank;_!==void 0&&(q[_][D.order]=F)}),q}function x(P){let q=P.nodes().map(D=>{let _=P.node(D).rank;return _===void 0?Number.MAX_VALUE:_}),F=S(Math.min,q);P.nodes().forEach(D=>{let _=P.node(D);Object.hasOwn(_,"rank")&&(_.rank-=F)})}function g(P){let q=P.nodes().map(A=>P.node(A).rank).filter(A=>A!==void 0),F=S(Math.min,q),D=[];P.nodes().forEach(A=>{let G=P.node(A).rank-F;D[G]||(D[G]=[]),D[G].push(A)});let _=0,I=P.graph().nodeRankFactor;Array.from(D).forEach((A,G)=>{A===void 0&&G%I!==0?--_:A!==void 0&&_&&A.forEach(U=>P.node(U).rank+=_)})}function b(P,q,F,D){let _={width:0,height:0};return arguments.length>=4&&(_.rank=F,_.order=D),i(P,"border",_,q)}function p(P,q=w){let F=[];for(let D=0;D<P.length;D+=q){let _=P.slice(D,D+q);F.push(_)}return F}var w=65535;function S(P,q){if(q.length>w){let F=p(q);return P.apply(null,F.map(D=>P.apply(null,D)))}else return P.apply(null,q)}function T(P){let q=P.nodes().map(F=>{let D=P.node(F).rank;return D===void 0?Number.MIN_VALUE:D});return S(Math.max,q)}function E(P,q){let F={lhs:[],rhs:[]};return P.forEach(D=>{q(D)?F.lhs.push(D):F.rhs.push(D)}),F}function C(P,q){let F=Date.now();try{return q()}finally{console.log(P+" time: "+(Date.now()-F)+"ms")}}function N(P,q){return q()}var k=0;function H(P){var q=++k;return P+(""+q)}function M(P,q,F=1){q==null&&(q=P,P=0);let D=I=>I<q;F<0&&(D=I=>q<I);let _=[];for(let I=P;D(I);I+=F)_.push(I);return _}function Y(P,q){let F={};for(let D of q)P[D]!==void 0&&(F[D]=P[D]);return F}function $(P,q){let F=q;return typeof q=="string"&&(F=D=>D[q]),Object.entries(P).reduce((D,[_,I])=>(D[_]=F(I,_),D),{})}function X(P,q){return P.reduce((F,D,_)=>(F[D]=q[_],F),{})}}),hz=Wt((e,r)=>{var s=fz(),i=Hn().uniqueId;r.exports={run:o,undo:u};function o(f){(f.graph().acyclicer==="greedy"?s(f,m(f)):c(f)).forEach(h=>{let x=f.edge(h);f.removeEdge(h),x.forwardName=h.name,x.reversed=!0,f.setEdge(h.w,h.v,x,i("rev"))});function m(h){return x=>h.edge(x).weight}}function c(f){let m=[],h={},x={};function g(b){Object.hasOwn(x,b)||(x[b]=!0,h[b]=!0,f.outEdges(b).forEach(p=>{Object.hasOwn(h,p.w)?m.push(p):g(p.w)}),delete h[b])}return f.nodes().forEach(g),m}function u(f){f.edges().forEach(m=>{let h=f.edge(m);if(h.reversed){f.removeEdge(m);let x=h.forwardName;delete h.reversed,delete h.forwardName,f.setEdge(m.w,m.v,h,x)}})}}),mz=Wt((e,r)=>{var s=Hn();r.exports={run:i,undo:c};function i(u){u.graph().dummyChains=[],u.edges().forEach(f=>o(u,f))}function o(u,f){let m=f.v,h=u.node(m).rank,x=f.w,g=u.node(x).rank,b=f.name,p=u.edge(f),w=p.labelRank;if(g===h+1)return;u.removeEdge(f);let S,T,E;for(E=0,++h;h<g;++E,++h)p.points=[],T={width:0,height:0,edgeLabel:p,edgeObj:f,rank:h},S=s.addDummyNode(u,"edge",T,"_d"),h===w&&(T.width=p.width,T.height=p.height,T.dummy="edge-label",T.labelpos=p.labelpos),u.setEdge(m,S,{weight:p.weight},b),E===0&&u.graph().dummyChains.push(S),m=S;u.setEdge(m,x,{weight:p.weight},b)}function c(u){u.graph().dummyChains.forEach(f=>{let m=u.node(f),h=m.edgeLabel,x;for(u.setEdge(m.edgeObj,h);m.dummy;)x=u.successors(f)[0],u.removeNode(f),h.points.push({x:m.x,y:m.y}),m.dummy==="edge-label"&&(h.x=m.x,h.y=m.y,h.width=m.width,h.height=m.height),f=x,m=u.node(f)})}}),Iu=Wt((e,r)=>{var{applyWithChunking:s}=Hn();r.exports={longestPath:i,slack:o};function i(c){var u={};function f(m){var h=c.node(m);if(Object.hasOwn(u,m))return h.rank;u[m]=!0;let x=c.outEdges(m).map(b=>b==null?Number.POSITIVE_INFINITY:f(b.w)-c.edge(b).minlen);var g=s(Math.min,x);return g===Number.POSITIVE_INFINITY&&(g=0),h.rank=g}c.sources().forEach(f)}function o(c,u){return c.node(u.w).rank-c.node(u.v).rank-c.edge(u).minlen}}),sN=Wt((e,r)=>{var s=ns().Graph,i=Iu().slack;r.exports=o;function o(m){var h=new s({directed:!1}),x=m.nodes()[0],g=m.nodeCount();h.setNode(x,{});for(var b,p;c(h,m)<g;)b=u(h,m),p=h.hasNode(b.v)?i(m,b):-i(m,b),f(h,m,p);return h}function c(m,h){function x(g){h.nodeEdges(g).forEach(b=>{var p=b.v,w=g===p?b.w:p;!m.hasNode(w)&&!i(h,b)&&(m.setNode(w,{}),m.setEdge(g,w,{}),x(w))})}return m.nodes().forEach(x),m.nodeCount()}function u(m,h){return h.edges().reduce((x,g)=>{let b=Number.POSITIVE_INFINITY;return m.hasNode(g.v)!==m.hasNode(g.w)&&(b=i(h,g)),b<x[0]?[b,g]:x},[Number.POSITIVE_INFINITY,null])[1]}function f(m,h,x){m.nodes().forEach(g=>h.node(g).rank+=x)}}),xz=Wt((e,r)=>{var s=sN(),i=Iu().slack,o=Iu().longestPath,c=ns().alg.preorder,u=ns().alg.postorder,f=Hn().simplify;r.exports=m,m.initLowLimValues=b,m.initCutValues=h,m.calcCutValue=g,m.leaveEdge=w,m.enterEdge=S,m.exchangeEdges=T;function m(k){k=f(k),o(k);var H=s(k);b(H),h(H,k);for(var M,Y;M=w(H);)Y=S(H,k,M),T(H,k,M,Y)}function h(k,H){var M=u(k,k.nodes());M=M.slice(0,M.length-1),M.forEach(Y=>x(k,H,Y))}function x(k,H,M){var Y=k.node(M),$=Y.parent;k.edge(M,$).cutvalue=g(k,H,M)}function g(k,H,M){var Y=k.node(M),$=Y.parent,X=!0,P=H.edge(M,$),q=0;return P||(X=!1,P=H.edge($,M)),q=P.weight,H.nodeEdges(M).forEach(F=>{var D=F.v===M,_=D?F.w:F.v;if(_!==$){var I=D===X,A=H.edge(F).weight;if(q+=I?A:-A,C(k,M,_)){var G=k.edge(M,_).cutvalue;q+=I?-G:G}}}),q}function b(k,H){arguments.length<2&&(H=k.nodes()[0]),p(k,{},1,H)}function p(k,H,M,Y,$){var X=M,P=k.node(Y);return H[Y]=!0,k.neighbors(Y).forEach(q=>{Object.hasOwn(H,q)||(M=p(k,H,M,q,Y))}),P.low=X,P.lim=M++,$?P.parent=$:delete P.parent,M}function w(k){return k.edges().find(H=>k.edge(H).cutvalue<0)}function S(k,H,M){var Y=M.v,$=M.w;H.hasEdge(Y,$)||(Y=M.w,$=M.v);var X=k.node(Y),P=k.node($),q=X,F=!1;X.lim>P.lim&&(q=P,F=!0);var D=H.edges().filter(_=>F===N(k,k.node(_.v),q)&&F!==N(k,k.node(_.w),q));return D.reduce((_,I)=>i(H,I)<i(H,_)?I:_)}function T(k,H,M,Y){var $=M.v,X=M.w;k.removeEdge($,X),k.setEdge(Y.v,Y.w,{}),b(k),h(k,H),E(k,H)}function E(k,H){var M=k.nodes().find($=>!H.node($).parent),Y=c(k,M);Y=Y.slice(1),Y.forEach($=>{var X=k.node($).parent,P=H.edge($,X),q=!1;P||(P=H.edge(X,$),q=!0),H.node($).rank=H.node(X).rank+(q?P.minlen:-P.minlen)})}function C(k,H,M){return k.hasEdge(H,M)}function N(k,H,M){return M.low<=H.lim&&H.lim<=M.lim}}),gz=Wt((e,r)=>{var s=Iu(),i=s.longestPath,o=sN(),c=xz();r.exports=u;function u(x){var g=x.graph().ranker;if(g instanceof Function)return g(x);switch(x.graph().ranker){case"network-simplex":h(x);break;case"tight-tree":m(x);break;case"longest-path":f(x);break;case"none":break;default:h(x)}}var f=i;function m(x){i(x),o(x)}function h(x){c(x)}}),pz=Wt((e,r)=>{r.exports=s;function s(c){let u=o(c);c.graph().dummyChains.forEach(f=>{let m=c.node(f),h=m.edgeObj,x=i(c,u,h.v,h.w),g=x.path,b=x.lca,p=0,w=g[p],S=!0;for(;f!==h.w;){if(m=c.node(f),S){for(;(w=g[p])!==b&&c.node(w).maxRank<m.rank;)p++;w===b&&(S=!1)}if(!S){for(;p<g.length-1&&c.node(w=g[p+1]).minRank<=m.rank;)p++;w=g[p]}c.setParent(f,w),f=c.successors(f)[0]}})}function i(c,u,f,m){let h=[],x=[],g=Math.min(u[f].low,u[m].low),b=Math.max(u[f].lim,u[m].lim),p,w;p=f;do p=c.parent(p),h.push(p);while(p&&(u[p].low>g||b>u[p].lim));for(w=p,p=m;(p=c.parent(p))!==w;)x.push(p);return{path:h.concat(x.reverse()),lca:w}}function o(c){let u={},f=0;function m(h){let x=f;c.children(h).forEach(m),u[h]={low:x,lim:f++}}return c.children().forEach(m),u}}),bz=Wt((e,r)=>{var s=Hn();r.exports={run:i,cleanup:f};function i(m){let h=s.addDummyNode(m,"root",{},"_root"),x=c(m),g=Object.values(x),b=s.applyWithChunking(Math.max,g)-1,p=2*b+1;m.graph().nestingRoot=h,m.edges().forEach(S=>m.edge(S).minlen*=p);let w=u(m)+1;m.children().forEach(S=>o(m,h,p,w,b,x,S)),m.graph().nodeRankFactor=p}function o(m,h,x,g,b,p,w){let S=m.children(w);if(!S.length){w!==h&&m.setEdge(h,w,{weight:0,minlen:x});return}let T=s.addBorderNode(m,"_bt"),E=s.addBorderNode(m,"_bb"),C=m.node(w);m.setParent(T,w),C.borderTop=T,m.setParent(E,w),C.borderBottom=E,S.forEach(N=>{o(m,h,x,g,b,p,N);let k=m.node(N),H=k.borderTop?k.borderTop:N,M=k.borderBottom?k.borderBottom:N,Y=k.borderTop?g:2*g,$=H!==M?1:b-p[w]+1;m.setEdge(T,H,{weight:Y,minlen:$,nestingEdge:!0}),m.setEdge(M,E,{weight:Y,minlen:$,nestingEdge:!0})}),m.parent(w)||m.setEdge(h,T,{weight:0,minlen:b+p[w]})}function c(m){var h={};function x(g,b){var p=m.children(g);p&&p.length&&p.forEach(w=>x(w,b+1)),h[g]=b}return m.children().forEach(g=>x(g,1)),h}function u(m){return m.edges().reduce((h,x)=>h+m.edge(x).weight,0)}function f(m){var h=m.graph();m.removeNode(h.nestingRoot),delete h.nestingRoot,m.edges().forEach(x=>{var g=m.edge(x);g.nestingEdge&&m.removeEdge(x)})}}),yz=Wt((e,r)=>{var s=Hn();r.exports=i;function i(c){function u(f){let m=c.children(f),h=c.node(f);if(m.length&&m.forEach(u),Object.hasOwn(h,"minRank")){h.borderLeft=[],h.borderRight=[];for(let x=h.minRank,g=h.maxRank+1;x<g;++x)o(c,"borderLeft","_bl",f,h,x),o(c,"borderRight","_br",f,h,x)}}c.children().forEach(u)}function o(c,u,f,m,h,x){let g={width:0,height:0,rank:x,borderType:u},b=h[u][x-1],p=s.addDummyNode(c,"border",g,f);h[u][x]=p,c.setParent(p,m),b&&c.setEdge(b,p,{weight:1})}}),vz=Wt((e,r)=>{r.exports={adjust:s,undo:i};function s(x){let g=x.graph().rankdir.toLowerCase();(g==="lr"||g==="rl")&&o(x)}function i(x){let g=x.graph().rankdir.toLowerCase();(g==="bt"||g==="rl")&&u(x),(g==="lr"||g==="rl")&&(m(x),o(x))}function o(x){x.nodes().forEach(g=>c(x.node(g))),x.edges().forEach(g=>c(x.edge(g)))}function c(x){let g=x.width;x.width=x.height,x.height=g}function u(x){x.nodes().forEach(g=>f(x.node(g))),x.edges().forEach(g=>{let b=x.edge(g);b.points.forEach(f),Object.hasOwn(b,"y")&&f(b)})}function f(x){x.y=-x.y}function m(x){x.nodes().forEach(g=>h(x.node(g))),x.edges().forEach(g=>{let b=x.edge(g);b.points.forEach(h),Object.hasOwn(b,"x")&&h(b)})}function h(x){let g=x.x;x.x=x.y,x.y=g}}),jz=Wt((e,r)=>{var s=Hn();r.exports=i;function i(o){let c={},u=o.nodes().filter(g=>!o.children(g).length),f=u.map(g=>o.node(g).rank),m=s.applyWithChunking(Math.max,f),h=s.range(m+1).map(()=>[]);function x(g){if(c[g])return;c[g]=!0;let b=o.node(g);h[b.rank].push(g),o.successors(g).forEach(x)}return u.sort((g,b)=>o.node(g).rank-o.node(b).rank).forEach(x),h}}),wz=Wt((e,r)=>{var s=Hn().zipObject;r.exports=i;function i(c,u){let f=0;for(let m=1;m<u.length;++m)f+=o(c,u[m-1],u[m]);return f}function o(c,u,f){let m=s(f,f.map((w,S)=>S)),h=u.flatMap(w=>c.outEdges(w).map(S=>({pos:m[S.w],weight:c.edge(S).weight})).sort((S,T)=>S.pos-T.pos)),x=1;for(;x<f.length;)x<<=1;let g=2*x-1;x-=1;let b=new Array(g).fill(0),p=0;return h.forEach(w=>{let S=w.pos+x;b[S]+=w.weight;let T=0;for(;S>0;)S%2&&(T+=b[S+1]),S=S-1>>1,b[S]+=w.weight;p+=w.weight*T}),p}}),Nz=Wt((e,r)=>{r.exports=s;function s(i,o=[]){return o.map(c=>{let u=i.inEdges(c);if(u.length){let f=u.reduce((m,h)=>{let x=i.edge(h),g=i.node(h.v);return{sum:m.sum+x.weight*g.order,weight:m.weight+x.weight}},{sum:0,weight:0});return{v:c,barycenter:f.sum/f.weight,weight:f.weight}}else return{v:c}})}}),kz=Wt((e,r)=>{var s=Hn();r.exports=i;function i(u,f){let m={};u.forEach((x,g)=>{let b=m[x.v]={indegree:0,in:[],out:[],vs:[x.v],i:g};x.barycenter!==void 0&&(b.barycenter=x.barycenter,b.weight=x.weight)}),f.edges().forEach(x=>{let g=m[x.v],b=m[x.w];g!==void 0&&b!==void 0&&(b.indegree++,g.out.push(m[x.w]))});let h=Object.values(m).filter(x=>!x.indegree);return o(h)}function o(u){let f=[];function m(x){return g=>{g.merged||(g.barycenter===void 0||x.barycenter===void 0||g.barycenter>=x.barycenter)&&c(x,g)}}function h(x){return g=>{g.in.push(x),--g.indegree===0&&u.push(g)}}for(;u.length;){let x=u.pop();f.push(x),x.in.reverse().forEach(m(x)),x.out.forEach(h(x))}return f.filter(x=>!x.merged).map(x=>s.pick(x,["vs","i","barycenter","weight"]))}function c(u,f){let m=0,h=0;u.weight&&(m+=u.barycenter*u.weight,h+=u.weight),f.weight&&(m+=f.barycenter*f.weight,h+=f.weight),u.vs=f.vs.concat(u.vs),u.barycenter=m/h,u.weight=h,u.i=Math.min(f.i,u.i),f.merged=!0}}),Sz=Wt((e,r)=>{var s=Hn();r.exports=i;function i(u,f){let m=s.partition(u,T=>Object.hasOwn(T,"barycenter")),h=m.lhs,x=m.rhs.sort((T,E)=>E.i-T.i),g=[],b=0,p=0,w=0;h.sort(c(!!f)),w=o(g,x,w),h.forEach(T=>{w+=T.vs.length,g.push(T.vs),b+=T.barycenter*T.weight,p+=T.weight,w=o(g,x,w)});let S={vs:g.flat(!0)};return p&&(S.barycenter=b/p,S.weight=p),S}function o(u,f,m){let h;for(;f.length&&(h=f[f.length-1]).i<=m;)f.pop(),u.push(h.vs),m++;return m}function c(u){return(f,m)=>f.barycenter<m.barycenter?-1:f.barycenter>m.barycenter?1:u?m.i-f.i:f.i-m.i}}),Cz=Wt((e,r)=>{var s=Nz(),i=kz(),o=Sz();r.exports=c;function c(m,h,x,g){let b=m.children(h),p=m.node(h),w=p?p.borderLeft:void 0,S=p?p.borderRight:void 0,T={};w&&(b=b.filter(k=>k!==w&&k!==S));let E=s(m,b);E.forEach(k=>{if(m.children(k.v).length){let H=c(m,k.v,x,g);T[k.v]=H,Object.hasOwn(H,"barycenter")&&f(k,H)}});let C=i(E,x);u(C,T);let N=o(C,g);if(w&&(N.vs=[w,N.vs,S].flat(!0),m.predecessors(w).length)){let k=m.node(m.predecessors(w)[0]),H=m.node(m.predecessors(S)[0]);Object.hasOwn(N,"barycenter")||(N.barycenter=0,N.weight=0),N.barycenter=(N.barycenter*N.weight+k.order+H.order)/(N.weight+2),N.weight+=2}return N}function u(m,h){m.forEach(x=>{x.vs=x.vs.flatMap(g=>h[g]?h[g].vs:g)})}function f(m,h){m.barycenter!==void 0?(m.barycenter=(m.barycenter*m.weight+h.barycenter*h.weight)/(m.weight+h.weight),m.weight+=h.weight):(m.barycenter=h.barycenter,m.weight=h.weight)}}),Ez=Wt((e,r)=>{var s=ns().Graph,i=Hn();r.exports=o;function o(u,f,m,h){h||(h=u.nodes());let x=c(u),g=new s({compound:!0}).setGraph({root:x}).setDefaultNodeLabel(b=>u.node(b));return h.forEach(b=>{let p=u.node(b),w=u.parent(b);(p.rank===f||p.minRank<=f&&f<=p.maxRank)&&(g.setNode(b),g.setParent(b,w||x),u[m](b).forEach(S=>{let T=S.v===b?S.w:S.v,E=g.edge(T,b),C=E!==void 0?E.weight:0;g.setEdge(T,b,{weight:u.edge(S).weight+C})}),Object.hasOwn(p,"minRank")&&g.setNode(b,{borderLeft:p.borderLeft[f],borderRight:p.borderRight[f]}))}),g}function c(u){for(var f;u.hasNode(f=i.uniqueId("_root")););return f}}),Tz=Wt((e,r)=>{r.exports=s;function s(i,o,c){let u={},f;c.forEach(m=>{let h=i.parent(m),x,g;for(;h;){if(x=i.parent(h),x?(g=u[x],u[x]=h):(g=f,f=h),g&&g!==h){o.setEdge(g,h);return}h=x}})}}),_z=Wt((e,r)=>{var s=jz(),i=wz(),o=Cz(),c=Ez(),u=Tz(),f=ns().Graph,m=Hn();r.exports=h;function h(p,w={}){if(typeof w.customOrder=="function"){w.customOrder(p,h);return}let S=m.maxRank(p),T=x(p,m.range(1,S+1),"inEdges"),E=x(p,m.range(S-1,-1,-1),"outEdges"),C=s(p);if(b(p,C),w.disableOptimalOrderHeuristic)return;let N=Number.POSITIVE_INFINITY,k,H=w.constraints||[];for(let M=0,Y=0;Y<4;++M,++Y){g(M%2?T:E,M%4>=2,H),C=m.buildLayerMatrix(p);let $=i(p,C);$<N?(Y=0,k=Object.assign({},C),N=$):$===N&&(k=structuredClone(C))}b(p,k)}function x(p,w,S){let T=new Map,E=(C,N)=>{T.has(C)||T.set(C,[]),T.get(C).push(N)};for(let C of p.nodes()){let N=p.node(C);if(typeof N.rank=="number"&&E(N.rank,C),typeof N.minRank=="number"&&typeof N.maxRank=="number")for(let k=N.minRank;k<=N.maxRank;k++)k!==N.rank&&E(k,C)}return w.map(function(C){return c(p,C,S,T.get(C)||[])})}function g(p,w,S){let T=new f;p.forEach(function(E){S.forEach(k=>T.setEdge(k.left,k.right));let C=E.graph().root,N=o(E,C,T,w);N.vs.forEach((k,H)=>E.node(k).order=H),u(E,T,N.vs)})}function b(p,w){Object.values(w).forEach(S=>S.forEach((T,E)=>p.node(T).order=E))}}),Az=Wt((e,r)=>{var s=ns().Graph,i=Hn();r.exports={positionX:S,findType1Conflicts:o,findType2Conflicts:c,addConflict:f,hasConflict:m,verticalAlignment:h,horizontalCompaction:x,alignCoordinates:p,findSmallestWidthAlignment:b,balance:w};function o(C,N){let k={};function H(M,Y){let $=0,X=0,P=M.length,q=Y[Y.length-1];return Y.forEach((F,D)=>{let _=u(C,F),I=_?C.node(_).order:P;(_||F===q)&&(Y.slice(X,D+1).forEach(A=>{C.predecessors(A).forEach(G=>{let U=C.node(G),K=U.order;(K<$||I<K)&&!(U.dummy&&C.node(A).dummy)&&f(k,G,A)})}),X=D+1,$=I)}),Y}return N.length&&N.reduce(H),k}function c(C,N){let k={};function H(Y,$,X,P,q){let F;i.range($,X).forEach(D=>{F=Y[D],C.node(F).dummy&&C.predecessors(F).forEach(_=>{let I=C.node(_);I.dummy&&(I.order<P||I.order>q)&&f(k,_,F)})})}function M(Y,$){let X=-1,P,q=0;return $.forEach((F,D)=>{if(C.node(F).dummy==="border"){let _=C.predecessors(F);_.length&&(P=C.node(_[0]).order,H($,q,D,X,P),q=D,X=P)}H($,q,$.length,P,Y.length)}),$}return N.length&&N.reduce(M),k}function u(C,N){if(C.node(N).dummy)return C.predecessors(N).find(k=>C.node(k).dummy)}function f(C,N,k){if(N>k){let M=N;N=k,k=M}let H=C[N];H||(C[N]=H={}),H[k]=!0}function m(C,N,k){if(N>k){let H=N;N=k,k=H}return!!C[N]&&Object.hasOwn(C[N],k)}function h(C,N,k,H){let M={},Y={},$={};return N.forEach(X=>{X.forEach((P,q)=>{M[P]=P,Y[P]=P,$[P]=q})}),N.forEach(X=>{let P=-1;X.forEach(q=>{let F=H(q);if(F.length){F=F.sort((_,I)=>$[_]-$[I]);let D=(F.length-1)/2;for(let _=Math.floor(D),I=Math.ceil(D);_<=I;++_){let A=F[_];Y[q]===q&&P<$[A]&&!m(k,q,A)&&(Y[A]=q,Y[q]=M[q]=M[A],P=$[A])}}})}),{root:M,align:Y}}function x(C,N,k,H,M){let Y={},$=g(C,N,k,M),X=M?"borderLeft":"borderRight";function P(D,_){let I=$.nodes().slice(),A={},G=I.pop();for(;G;){if(A[G])D(G);else{A[G]=!0,I.push(G);for(let U of _(G))I.push(U)}G=I.pop()}}function q(D){Y[D]=$.inEdges(D).reduce((_,I)=>Math.max(_,Y[I.v]+$.edge(I)),0)}function F(D){let _=$.outEdges(D).reduce((A,G)=>Math.min(A,Y[G.w]-$.edge(G)),Number.POSITIVE_INFINITY),I=C.node(D);_!==Number.POSITIVE_INFINITY&&I.borderType!==X&&(Y[D]=Math.max(Y[D],_))}return P(q,$.predecessors.bind($)),P(F,$.successors.bind($)),Object.keys(H).forEach(D=>Y[D]=Y[k[D]]),Y}function g(C,N,k,H){let M=new s,Y=C.graph(),$=T(Y.nodesep,Y.edgesep,H);return N.forEach(X=>{let P;X.forEach(q=>{let F=k[q];if(M.setNode(F),P){var D=k[P],_=M.edge(D,F);M.setEdge(D,F,Math.max($(C,q,P),_||0))}P=q})}),M}function b(C,N){return Object.values(N).reduce((k,H)=>{let M=Number.NEGATIVE_INFINITY,Y=Number.POSITIVE_INFINITY;Object.entries(H).forEach(([X,P])=>{let q=E(C,X)/2;M=Math.max(P+q,M),Y=Math.min(P-q,Y)});let $=M-Y;return $<k[0]&&(k=[$,H]),k},[Number.POSITIVE_INFINITY,null])[1]}function p(C,N){let k=Object.values(N),H=i.applyWithChunking(Math.min,k),M=i.applyWithChunking(Math.max,k);["u","d"].forEach(Y=>{["l","r"].forEach($=>{let X=Y+$,P=C[X];if(P===N)return;let q=Object.values(P),F=H-i.applyWithChunking(Math.min,q);$!=="l"&&(F=M-i.applyWithChunking(Math.max,q)),F&&(C[X]=i.mapValues(P,D=>D+F))})})}function w(C,N){return i.mapValues(C.ul,(k,H)=>{if(N)return C[N.toLowerCase()][H];{let M=Object.values(C).map(Y=>Y[H]).sort((Y,$)=>Y-$);return(M[1]+M[2])/2}})}function S(C){let N=i.buildLayerMatrix(C),k=Object.assign(o(C,N),c(C,N)),H={},M;["u","d"].forEach($=>{M=$==="u"?N:Object.values(N).reverse(),["l","r"].forEach(X=>{X==="r"&&(M=M.map(D=>Object.values(D).reverse()));let P=($==="u"?C.predecessors:C.successors).bind(C),q=h(C,M,k,P),F=x(C,M,q.root,q.align,X==="r");X==="r"&&(F=i.mapValues(F,D=>-D)),H[$+X]=F})});let Y=b(C,H);return p(H,Y),w(H,C.graph().align)}function T(C,N,k){return(H,M,Y)=>{let $=H.node(M),X=H.node(Y),P=0,q;if(P+=$.width/2,Object.hasOwn($,"labelpos"))switch($.labelpos.toLowerCase()){case"l":q=-$.width/2;break;case"r":q=$.width/2;break}if(q&&(P+=k?q:-q),q=0,P+=($.dummy?N:C)/2,P+=(X.dummy?N:C)/2,P+=X.width/2,Object.hasOwn(X,"labelpos"))switch(X.labelpos.toLowerCase()){case"l":q=X.width/2;break;case"r":q=-X.width/2;break}return q&&(P+=k?q:-q),q=0,P}}function E(C,N){return C.node(N).width}}),Mz=Wt((e,r)=>{var s=Hn(),i=Az().positionX;r.exports=o;function o(u){u=s.asNonCompoundGraph(u),c(u),Object.entries(i(u)).forEach(([f,m])=>u.node(f).x=m)}function c(u){let f=s.buildLayerMatrix(u),m=u.graph().ranksep,h=u.graph().rankalign,x=0;f.forEach(g=>{let b=g.reduce((p,w)=>{let S=u.node(w).height;return p>S?p:S},0);g.forEach(p=>{let w=u.node(p);h==="top"?w.y=x+w.height/2:h==="bottom"?w.y=x+b-w.height/2:w.y=x+b/2}),x+=b+m})}}),Dz=Wt((e,r)=>{var s=hz(),i=mz(),o=gz(),c=Hn().normalizeRanks,u=pz(),f=Hn().removeEmptyRanks,m=bz(),h=yz(),x=vz(),g=_z(),b=Mz(),p=Hn(),w=ns().Graph;r.exports=S;function S(V,Q={}){let te=Q.debugTiming?p.time:p.notime;return te("layout",()=>{let Z=te(" buildLayoutGraph",()=>P(V));return te(" runLayout",()=>T(Z,te,Q)),te(" updateInputGraph",()=>E(V,Z)),Z})}function T(V,Q,te){Q(" makeSpaceForEdgeLabels",()=>q(V)),Q(" removeSelfEdges",()=>B(V)),Q(" acyclic",()=>s.run(V)),Q(" nestingGraph.run",()=>m.run(V)),Q(" rank",()=>o(p.asNonCompoundGraph(V))),Q(" injectEdgeLabelProxies",()=>F(V)),Q(" removeEmptyRanks",()=>f(V)),Q(" nestingGraph.cleanup",()=>m.cleanup(V)),Q(" normalizeRanks",()=>c(V)),Q(" assignRankMinMax",()=>D(V)),Q(" removeEdgeLabelProxies",()=>_(V)),Q(" normalize.run",()=>i.run(V)),Q(" parentDummyChains",()=>u(V)),Q(" addBorderSegments",()=>h(V)),Q(" order",()=>g(V,te)),Q(" insertSelfEdges",()=>L(V)),Q(" adjustCoordinateSystem",()=>x.adjust(V)),Q(" position",()=>b(V)),Q(" positionSelfEdges",()=>W(V)),Q(" removeBorderNodes",()=>K(V)),Q(" normalize.undo",()=>i.undo(V)),Q(" fixupEdgeLabelCoords",()=>G(V)),Q(" undoCoordinateSystem",()=>x.undo(V)),Q(" translateGraph",()=>I(V)),Q(" assignNodeIntersects",()=>A(V)),Q(" reversePoints",()=>U(V)),Q(" acyclic.undo",()=>s.undo(V))}function E(V,Q){V.nodes().forEach(te=>{let Z=V.node(te),ee=Q.node(te);Z&&(Z.x=ee.x,Z.y=ee.y,Z.order=ee.order,Z.rank=ee.rank,Q.children(te).length&&(Z.width=ee.width,Z.height=ee.height))}),V.edges().forEach(te=>{let Z=V.edge(te),ee=Q.edge(te);Z.points=ee.points,Object.hasOwn(ee,"x")&&(Z.x=ee.x,Z.y=ee.y)}),V.graph().width=Q.graph().width,V.graph().height=Q.graph().height}var C=["nodesep","edgesep","ranksep","marginx","marginy"],N={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},k=["acyclicer","ranker","rankdir","align","rankalign"],H=["width","height","rank"],M={width:0,height:0},Y=["minlen","weight","width","height","labeloffset"],$={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},X=["labelpos"];function P(V){let Q=new w({multigraph:!0,compound:!0}),te=z(V.graph());return Q.setGraph(Object.assign({},N,R(te,C),p.pick(te,k))),V.nodes().forEach(Z=>{let ee=z(V.node(Z)),ie=R(ee,H);Object.keys(M).forEach(je=>{ie[je]===void 0&&(ie[je]=M[je])}),Q.setNode(Z,ie),Q.setParent(Z,V.parent(Z))}),V.edges().forEach(Z=>{let ee=z(V.edge(Z));Q.setEdge(Z,Object.assign({},$,R(ee,Y),p.pick(ee,X)))}),Q}function q(V){let Q=V.graph();Q.ranksep/=2,V.edges().forEach(te=>{let Z=V.edge(te);Z.minlen*=2,Z.labelpos.toLowerCase()!=="c"&&(Q.rankdir==="TB"||Q.rankdir==="BT"?Z.width+=Z.labeloffset:Z.height+=Z.labeloffset)})}function F(V){V.edges().forEach(Q=>{let te=V.edge(Q);if(te.width&&te.height){let Z=V.node(Q.v),ee={rank:(V.node(Q.w).rank-Z.rank)/2+Z.rank,e:Q};p.addDummyNode(V,"edge-proxy",ee,"_ep")}})}function D(V){let Q=0;V.nodes().forEach(te=>{let Z=V.node(te);Z.borderTop&&(Z.minRank=V.node(Z.borderTop).rank,Z.maxRank=V.node(Z.borderBottom).rank,Q=Math.max(Q,Z.maxRank))}),V.graph().maxRank=Q}function _(V){V.nodes().forEach(Q=>{let te=V.node(Q);te.dummy==="edge-proxy"&&(V.edge(te.e).labelRank=te.rank,V.removeNode(Q))})}function I(V){let Q=Number.POSITIVE_INFINITY,te=0,Z=Number.POSITIVE_INFINITY,ee=0,ie=V.graph(),je=ie.marginx||0,ke=ie.marginy||0;function De(Ie){let ze=Ie.x,Ze=Ie.y,Ae=Ie.width,We=Ie.height;Q=Math.min(Q,ze-Ae/2),te=Math.max(te,ze+Ae/2),Z=Math.min(Z,Ze-We/2),ee=Math.max(ee,Ze+We/2)}V.nodes().forEach(Ie=>De(V.node(Ie))),V.edges().forEach(Ie=>{let ze=V.edge(Ie);Object.hasOwn(ze,"x")&&De(ze)}),Q-=je,Z-=ke,V.nodes().forEach(Ie=>{let ze=V.node(Ie);ze.x-=Q,ze.y-=Z}),V.edges().forEach(Ie=>{let ze=V.edge(Ie);ze.points.forEach(Ze=>{Ze.x-=Q,Ze.y-=Z}),Object.hasOwn(ze,"x")&&(ze.x-=Q),Object.hasOwn(ze,"y")&&(ze.y-=Z)}),ie.width=te-Q+je,ie.height=ee-Z+ke}function A(V){V.edges().forEach(Q=>{let te=V.edge(Q),Z=V.node(Q.v),ee=V.node(Q.w),ie,je;te.points?(ie=te.points[0],je=te.points[te.points.length-1]):(te.points=[],ie=ee,je=Z),te.points.unshift(p.intersectRect(Z,ie)),te.points.push(p.intersectRect(ee,je))})}function G(V){V.edges().forEach(Q=>{let te=V.edge(Q);if(Object.hasOwn(te,"x"))switch((te.labelpos==="l"||te.labelpos==="r")&&(te.width-=te.labeloffset),te.labelpos){case"l":te.x-=te.width/2+te.labeloffset;break;case"r":te.x+=te.width/2+te.labeloffset;break}})}function U(V){V.edges().forEach(Q=>{let te=V.edge(Q);te.reversed&&te.points.reverse()})}function K(V){V.nodes().forEach(Q=>{if(V.children(Q).length){let te=V.node(Q),Z=V.node(te.borderTop),ee=V.node(te.borderBottom),ie=V.node(te.borderLeft[te.borderLeft.length-1]),je=V.node(te.borderRight[te.borderRight.length-1]);te.width=Math.abs(je.x-ie.x),te.height=Math.abs(ee.y-Z.y),te.x=ie.x+te.width/2,te.y=Z.y+te.height/2}}),V.nodes().forEach(Q=>{V.node(Q).dummy==="border"&&V.removeNode(Q)})}function B(V){V.edges().forEach(Q=>{if(Q.v===Q.w){var te=V.node(Q.v);te.selfEdges||(te.selfEdges=[]),te.selfEdges.push({e:Q,label:V.edge(Q)}),V.removeEdge(Q)}})}function L(V){var Q=p.buildLayerMatrix(V);Q.forEach(te=>{var Z=0;te.forEach((ee,ie)=>{var je=V.node(ee);je.order=ie+Z,(je.selfEdges||[]).forEach(ke=>{p.addDummyNode(V,"selfedge",{width:ke.label.width,height:ke.label.height,rank:je.rank,order:ie+ ++Z,e:ke.e,label:ke.label},"_se")}),delete je.selfEdges})})}function W(V){V.nodes().forEach(Q=>{var te=V.node(Q);if(te.dummy==="selfedge"){var Z=V.node(te.e.v),ee=Z.x+Z.width/2,ie=Z.y,je=te.x-ee,ke=Z.height/2;V.setEdge(te.e,te.label),V.removeNode(Q),te.label.points=[{x:ee+2*je/3,y:ie-ke},{x:ee+5*je/6,y:ie-ke},{x:ee+je,y:ie},{x:ee+5*je/6,y:ie+ke},{x:ee+2*je/3,y:ie+ke}],te.label.x=te.x,te.label.y=te.y}})}function R(V,Q){return p.mapValues(p.pick(V,Q),Number)}function z(V){var Q={};return V&&Object.entries(V).forEach(([te,Z])=>{typeof te=="string"&&(te=te.toLowerCase()),Q[te]=Z}),Q}}),Oz=Wt((e,r)=>{var s=Hn(),i=ns().Graph;r.exports={debugOrdering:o};function o(c){let u=s.buildLayerMatrix(c),f=new i({compound:!0,multigraph:!0}).setGraph({});return c.nodes().forEach(m=>{f.setNode(m,{label:m}),f.setParent(m,"layer"+c.node(m).rank)}),c.edges().forEach(m=>f.setEdge(m.v,m.w,{},m.name)),u.forEach((m,h)=>{let x="layer"+h;f.setNode(x,{rank:"same"}),m.reduce((g,b)=>(f.setEdge(g,b,{style:"invis"}),b))}),f}}),Rz=Wt((e,r)=>{r.exports="2.0.4"}),zz=Wt((e,r)=>{r.exports={graphlib:ns(),layout:Dz(),debug:Oz(),util:{time:Hn().time,notime:Hn().notime},version:Rz()}});const kv=zz();const Sv={pending:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},pending_approval:{bg:"bg-blue-500/8",border:"border-blue-400/25",text:"text-blue-500"},assigned:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},in_progress:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},blocked:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},review:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},revision:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},accepted:{bg:"bg-green-500/8",border:"border-green-500/25",text:"text-green-600"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},failed:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"}},Lz={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function Iz({data:e}){const{task:r,agentName:s}=e,i=Sv[r.status]??Sv.pending,o=r.taskType==="scheduled"&&!!r.scheduleConfig,c=o?r.scheduleConfig.every?`Every ${r.scheduleConfig.every}`:r.scheduleConfig.cron?"Cron":"":"";return t.jsxs("div",{className:`rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${o?`${i.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${i.bg} ${i.border}`}`,children:[t.jsx(Na,{type:"target",position:nt.Top,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Lz[r.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${i.text}`,children:r.status.replace("_"," ")}),o&&t.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/15 text-blue-600 ml-auto whitespace-nowrap inline-flex items-center gap-0.5",children:[t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})}),c]})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:r.title}),s&&t.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:s}),r.blockedBy&&r.blockedBy.length>0&&t.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[r.blockedBy.length," dep",r.blockedBy.length>1?"s":""]}),t.jsx(Na,{type:"source",position:nt.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const Cv={draft:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-secondary"},pending_review:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},approved:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},in_progress:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},rejected:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"}},Ev={draft:"todo",pending_review:"todo",approved:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done"};function $z({data:e}){const{req:r}=e,s=Cv[r.status]??Cv.draft;return t.jsxs("div",{className:`rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${s.bg} ${s.border}`,children:[t.jsx(Na,{type:"target",position:nt.Top,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:"REQ"}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${s.text}`,children:r.status.replace("_"," ")})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:r.title}),r.taskIds.length>0&&t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[r.taskIds.length," task",r.taskIds.length>1?"s":""]}),t.jsx(Na,{type:"source",position:nt.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const Bz={task:Iz,requirement:$z},Hz=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&window.matchMedia("(prefers-color-scheme: light)").matches,Pz=e=>{const r=new MutationObserver(e);r.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const s=window.matchMedia("(prefers-color-scheme: light)");return s.addEventListener("change",e),()=>{r.disconnect(),s.removeEventListener("change",e)}};function Uz(){return j.useSyncExternalStore(Pz,Hz,()=>!1)}const Em=200,Tm=80;function Tv(e,r,s="TB"){const i=new kv.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:s,nodesep:40,ranksep:60});for(const o of e)i.setNode(o.id,{width:Em,height:Tm});for(const o of r)i.setEdge(o.source,o.target);return kv.layout(i),e.map(o=>{const c=i.node(o.id);return{...o,position:{x:(c?.x??0)-Em/2,y:(c?.y??0)-Tm/2}}})}function qz(e,r){const s=new Map,i=new Map;for(const u of e)i.set(u.id,u),s.set(u.id,new Set);for(const u of r)s.get(u.source)?.add(u.target),s.get(u.target)?.add(u.source);const o=new Set,c=[];for(const u of e){if(o.has(u.id))continue;const f=new Set,m=[u.id];for(;m.length>0;){const h=m.pop();if(!o.has(h)){o.add(h),f.add(h);for(const x of s.get(h)??[])o.has(x)||m.push(x)}}c.push({nodes:e.filter(h=>f.has(h.id)),edges:r.filter(h=>f.has(h.source)&&f.has(h.target))})}return c}function Vz(e,r){if(e.length===0)return[];const s=qz(e,r);if(s.length===1)return Tv(e,r);const i=s.map(g=>{const b=Tv(g.nodes,g.edges);let p=1/0,w=-1/0,S=1/0,T=-1/0;for(const E of b)p=Math.min(p,E.position.x),w=Math.max(w,E.position.x+Em),S=Math.min(S,E.position.y),T=Math.max(T,E.position.y+Tm);for(const E of b)E.position.x-=p,E.position.y-=S;return{nodes:b,w:w-p,h:T-S}});i.sort((g,b)=>b.h-g.h);const o=60,c=i.reduce((g,b)=>g+(b.w+o)*(b.h+o),0),u=Math.sqrt(c)*1.1,f=[];let m=0,h=0,x=0;for(const g of i){m>0&&m+g.w>u&&(m=0,h+=x+o,x=0);for(const b of g.nodes)f.push({...b,position:{x:b.position.x+m,y:b.position.y+h}});m+=g.w+o,x=Math.max(x,g.h)}return f}function Fz(e,r,s){const i=new Set,o=[r];for(;o.length>0;){const c=o.pop();if(c===s)return!0;if(i.has(c))continue;i.add(c);const u=e.get(c);if(u?.blockedBy)for(const f of u.blockedBy)o.push(f)}return!1}const oo=[{id:"todo",label:"To Do",statuses:new Set(["pending_approval","pending","assigned"]),color:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"}},{id:"in_progress",label:"In Progress",statuses:new Set(["in_progress","blocked"]),color:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"}},{id:"review",label:"In Review",statuses:new Set(["review","revision","accepted"]),color:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"}},{id:"done",label:"Done",statuses:new Set(["completed","failed","cancelled"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}],Yh=new Set(oo.map(e=>e.id)),Yz=1440*60*1e3,_v=e=>e.status==="completed"&&e.updatedAt&&Date.now()-new Date(e.updatedAt).getTime()>Yz;function Gz({tasks:e,requirements:r=[],agents:s,showArchived:i,onShowArchivedChange:o,onTaskClick:c,onReqClick:u,onDependencyChange:f}){const m=Uz(),[h,x]=j.useState(null),[g,b]=j.useState(null),[p,w]=j.useState(new Set(Yh)),[S,T]=j.useState(i??!1),E=i??S,C=j.useCallback(Z=>{const ee=typeof Z=="function"?Z(E):Z;T(ee),o?.(ee)},[E,o]);j.useEffect(()=>{i!==void 0&&T(i)},[i]);const N=j.useMemo(()=>e.filter(Z=>_v(Z)).length,[e]),k=j.useMemo(()=>{const Z=new Set;for(const ee of oo)if(p.has(ee.id))for(const ie of ee.statuses)Z.add(ie);return Z},[p]),H=j.useMemo(()=>{const Z=new Set;for(const ee of e)for(const ie of oo)if(ie.statuses.has(ee.status)){Z.add(ie.id);break}for(const ee of r){const ie=Ev[ee.status];ie&&Z.add(ie)}return oo.filter(ee=>Z.has(ee.id))},[e,r]),M=j.useCallback(Z=>{w(ee=>{const ie=new Set(ee);return ie.has(Z)?ie.delete(Z):ie.add(Z),ie})},[]),Y=j.useCallback((Z,ee="success")=>{x({msg:Z,type:ee}),setTimeout(()=>x(null),2500)},[]),$=j.useMemo(()=>{const Z=new Map;for(const ee of s)Z.set(ee.id,ee.name);return Z},[s]),X=j.useMemo(()=>{const Z=new Map;for(const ee of e)Z.set(ee.id,ee);return Z},[e]),P=j.useMemo(()=>{const Z=new Map;for(const ee of r)Z.set(ee.id,ee);return Z},[r]),q=m?"#94a3b8":"#6b7280",F=j.useCallback((Z,ee,ie)=>({id:`${Z}->${ee}`,source:Z,target:ee,animated:ie==="blocked",markerEnd:{type:Zi.ArrowClosed,width:14,height:14,color:ie==="blocked"?"#ef4444":q},style:{stroke:ie==="blocked"?"#ef4444":q,strokeWidth:1.5,cursor:"pointer"}}),[q]),{initialNodes:D,initialEdges:_}=j.useMemo(()=>{const Z=e.filter(Ae=>k.has(Ae.status)&&(E||!_v(Ae))),ee=Z.map(Ae=>({id:Ae.id,type:"task",data:{task:Ae,agentName:Ae.assignedAgentId?$.get(Ae.assignedAgentId):void 0},position:{x:0,y:0}})),ie=new Set(ee.map(Ae=>Ae.id)),je=new Set;for(const Ae of oo)p.has(Ae.id)&&je.add(Ae.id);const ke=r.filter(Ae=>{const We=Ev[Ae.status];return We&&je.has(We)});for(const Ae of ke){const We=`req-${Ae.id}`;ee.push({id:We,type:"requirement",data:{req:Ae},position:{x:0,y:0}}),ie.add(We)}const De=[];for(const Ae of Z)if(Ae.blockedBy)for(const We of Ae.blockedBy)ie.has(We)&&De.push(F(We,Ae.id,Ae.status));const Ie=new Set,ze=(Ae,We)=>{const xt=`${Ae}->${We}`;Ie.has(xt)||(Ie.add(xt),De.push({id:xt,source:Ae,target:We,markerEnd:{type:Zi.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ae of ke){const We=`req-${Ae.id}`;for(const xt of Ae.taskIds)ie.has(xt)&&ze(We,xt)}for(const Ae of Z)if(Ae.requirementId){const We=`req-${Ae.requirementId}`;ie.has(We)&&ze(We,Ae.id)}return{initialNodes:Vz(ee,De),initialEdges:De}},[e,r,$,X,F,k,p,E]),[I,A,G]=zR(D),[U,K,B]=LR(_),L=j.useRef(null);j.useEffect(()=>{A(D),K(_),requestAnimationFrame(()=>{L.current?.fitView({padding:.2,duration:300})})},[D,_,A,K]);const W=j.useCallback((Z,ee)=>{if(ee.id.startsWith("req-")){const ie=P.get(ee.id.slice(4));ie&&u&&u(ie)}else{const ie=X.get(ee.id);ie&&c&&c(ie)}},[X,P,c,u]),R=j.useCallback(async Z=>{const{source:ee,target:ie}=Z;if(!ee||!ie||ee===ie)return;const je=X.get(ie);if(!je)return;if(je.blockedBy?.includes(ee)){Y("Dependency already exists","error");return}if(Fz(X,ee,ie)){Y("Cannot add: would create a cycle","error");return}const ke=[...je.blockedBy??[],ee];try{await ae.tasks.update(ie,{blockedBy:ke}),Y("Dependency added"),f?.()}catch(De){Y(`Failed: ${De instanceof Error?De.message:String(De)}`,"error")}},[X,Y,f]),z=j.useCallback((Z,ee)=>{b(ee)},[]),V=j.useCallback(async()=>{if(!g)return;const Z=X.get(g.target);if(!Z){b(null);return}const ee=(Z.blockedBy??[]).filter(ie=>ie!==g.source);try{await ae.tasks.update(g.target,{blockedBy:ee}),Y("Dependency removed"),f?.()}catch(ie){Y(`Failed: ${ie instanceof Error?ie.message:String(ie)}`,"error")}b(null)},[g,X,Y,f]);if(e.length===0)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:"No tasks to display"});const Q=g?X.get(g.source):null,te=g?X.get(g.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(RR,{nodes:I,edges:U,onNodesChange:G,onEdgesChange:B,onNodeClick:W,onConnect:R,onEdgeClick:z,onInit:Z=>{L.current=Z},nodeTypes:Bz,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[t.jsx(PR,{color:m?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(XR,{showInteractive:!1,className:"!bg-surface-secondary !border-border-default !shadow-xl [&>button]:!bg-surface-elevated [&>button]:!border-border-default [&>button]:!text-fg-secondary [&>button:hover]:!bg-surface-overlay"}),t.jsx(lz,{nodeColor:Z=>{const ee=Z.data?.task,ie=ee?.status;return ee?.taskType==="scheduled"?"#06b6d4":ie==="completed"||ie==="accepted"?"#10b981":ie==="in_progress"?"#f59e0b":ie==="blocked"||ie==="failed"?"#ef4444":m?"#94a3b8":"#6b7280"},maskColor:m?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),t.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-surface-secondary/90 border border-border-default rounded-lg backdrop-blur-sm z-10 flex flex-col items-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[H.map(Z=>{const ee=p.has(Z.id);return t.jsx("button",{onClick:()=>M(Z.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${ee?`${Z.color.bg} ${Z.color.border} ${Z.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:Z.label},Z.id)}),N>0&&t.jsxs("button",{onClick:()=>C(Z=>!Z),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${E?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:["Archived ",N]}),p.size<Yh.size&&t.jsx("button",{onClick:()=>{w(new Set(Yh)),C(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:"Reset"})]}),t.jsx("div",{className:"text-[10px] text-fg-tertiary select-none",children:"Drag to add dependency · Click edge to remove"})]}),h&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${h.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:h.msg}),g&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>b(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:Z=>Z.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:"Remove dependency?"}),t.jsxs("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:[t.jsx("span",{className:"text-fg-secondary font-medium",children:te?.title??g.target.slice(-8)})," ","will no longer be blocked by"," ",t.jsx("span",{className:"text-fg-secondary font-medium",children:Q?.title??g.source.slice(-8)}),"."]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>b(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:"Cancel"}),t.jsx("button",{onClick:V,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:"Remove"})]})]})})]})}function aN({orgId:e,onCreated:r,onClose:s}){const[i,o]=j.useState(""),[c,u]=j.useState(""),[f,m]=j.useState(""),[h,x]=j.useState("main"),[g,b]=j.useState([]),[p,w]=j.useState([]),[S,T]=j.useState(!1),[E,C]=j.useState(""),[N,k]=j.useState(!1),H=gs();j.useEffect(()=>{ae.teams.list().then($=>w($.teams)).catch(()=>{})},[]);const M=j.useCallback(async $=>{if($?.preventDefault(),k(!0),!(!i.trim()||S)){T(!0),C("");try{const X=f.trim()?[{url:f.trim(),defaultBranch:h.trim()||"main"}]:[],P=await ae.projects.create({name:i.trim(),description:c.trim()||void 0,repositories:X.length>0?X:void 0,teamIds:g.length>0?g:void 0,orgId:e??"default"});r(P.project)}catch(X){C(X instanceof Error?X.message:"Failed to create project")}T(!1)}},[i,c,f,h,g,e,S,r]),Y=N&&!i.trim();return K1.createPortal(t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:s,children:t.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto ${H?"w-full":"w-[520px]"}`,onClick:$=>$.stopPropagation(),onSubmit:M,children:[t.jsx("h3",{className:"text-base font-semibold mb-5",children:"New Project"}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Project Name *"}),t.jsx("input",{value:i,onChange:$=>{o($.target.value),C("")},onBlur:()=>k(!0),placeholder:"e.g. Mobile App, Website Redesign",className:`input ${Y?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!H}),Y&&t.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:"Project name is required"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Description"}),t.jsx("textarea",{value:c,onChange:$=>u($.target.value),placeholder:"What is this project about?",className:"input",rows:3})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Assign Teams"}),p.length===0?t.jsx("div",{className:"text-[11px] text-fg-tertiary py-2",children:"No teams available"}):t.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:p.map($=>{const X=g.includes($.id);return t.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer hover:text-fg-primary py-0.5",children:[t.jsx("input",{type:"checkbox",checked:X,onChange:()=>b(P=>X?P.filter(q=>q!==$.id):[...P,$.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:$.name})]},$.id)})})]}),t.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Repository URL"}),t.jsx("input",{value:f,onChange:$=>m($.target.value),placeholder:"https://github.com/org/repo (optional)",className:"input"})]}),f.trim()&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Branch"}),t.jsx("input",{value:h,onChange:$=>x($.target.value),placeholder:"main",className:"input !w-24"})]})]}),E&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:E}),t.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{type:"submit",disabled:!i.trim()||S,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:S?"Creating...":"Create Project"})]})]})]})}),document.body)}function el(e,r,s){if(!e)return null;const i=r.find(c=>c.id===e);if(i)return i.name;const o=s.find(c=>c.id===e);return o?o.name:e==="anonymous"?"Admin":null}function Xz({value:e,onSave:r,className:s,placeholder:i}){const[o,c]=j.useState(!1),[u,f]=j.useState(e),m=j.useRef(null);j.useEffect(()=>{f(e)},[e]),j.useEffect(()=>{o&&m.current?.focus()},[o]);const h=async()=>{c(!1);const x=u.trim();if(x&&x!==e)try{await r(x)}catch{f(e)}else f(e)};return o?t.jsx("input",{ref:m,value:u,onChange:x=>f(x.target.value),onBlur:()=>{h()},onKeyDown:x=>{x.key==="Enter"&&h(),x.key==="Escape"&&(f(e),c(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${s??""}`,placeholder:i}):t.jsx("span",{onClick:()=>c(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${s??""}`,title:"Click to edit",children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:i??"Click to edit"})})}function Zz({value:e,onSave:r,className:s,placeholder:i}){const[o,c]=j.useState(!1),[u,f]=j.useState(e),m=j.useRef(null);j.useEffect(()=>{f(e)},[e]),j.useEffect(()=>{o&&m.current&&(m.current.focus(),m.current.style.height="auto",m.current.style.height=m.current.scrollHeight+"px")},[o]);const h=async()=>{c(!1);const x=u.trim();if(x!==e)try{await r(x)}catch{f(e)}else f(e)};return o?t.jsx("textarea",{ref:m,value:u,onChange:x=>{f(x.target.value),x.target.style.height="auto",x.target.style.height=x.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:x=>{x.key==="Escape"&&(f(e),c(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${s??""}`,placeholder:i,rows:2}):t.jsx("p",{onClick:()=>c(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${s??""}`,title:"Click to edit",children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:i??"Add a description…"})})}const Qz=["pending_approval","in_progress","blocked","review","completed","failed","cancelled","archived"],To=[{id:"failed",label:"Failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",label:"To Do",statuses:["pending_approval"],accent:"border-t-amber-500",dropStatus:"pending_approval"},{id:"in_progress",label:"In Progress",statuses:["in_progress","blocked"],accent:"border-t-brand-500",dropStatus:"in_progress"},{id:"review",label:"In Review",statuses:["review"],accent:"border-t-purple-500",dropStatus:"review"},{id:"done",label:"Done",statuses:["completed"],accent:"border-t-green-500",dropStatus:"completed"},{id:"closed",label:"Closed",statuses:["cancelled"],accent:"border-t-gray-500",dropStatus:"cancelled"}],Kz={pending_approval:"Awaiting Approval",in_progress:"In Progress",blocked:"Blocked",review:"In Review",completed:"Completed",failed:"Failed",cancelled:"Cancelled",archived:"Archived"},iN={pending_approval:{label:"Awaiting",cls:"bg-amber-500/15 text-amber-600"},blocked:{label:"Blocked",cls:"bg-amber-500/15 text-amber-600"},failed:{label:"Failed",cls:"bg-red-500/15 text-red-500"}},Jz={pending_approval:{label:"Pending Approval",cls:"bg-amber-500/15 text-amber-600"},in_progress:{label:"In Progress",cls:"bg-blue-500/15 text-blue-500"},blocked:{label:"Blocked",cls:"bg-orange-500/15 text-orange-500"},review:{label:"In Review",cls:"bg-purple-500/15 text-purple-500"},completed:{label:"Completed",cls:"bg-green-500/15 text-green-600"},failed:{label:"Failed",cls:"bg-red-500/15 text-red-500"},cancelled:{label:"Cancelled",cls:"bg-gray-500/15 text-fg-tertiary"},archived:{label:"Archived",cls:"bg-gray-500/15 text-fg-tertiary"}},_m={urgent:"border-l-red-500",high:"border-l-amber-500",medium:"border-l-blue-500",low:"border-l-gray-500"},lN={pending_approval:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},Av=j.memo(function({comment:r}){return t.jsxs("div",{className:"bg-blue-500/10 border border-blue-500/30 rounded-lg px-3 py-2.5 my-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("span",{className:"w-5 h-5 rounded-full bg-blue-600/30 flex items-center justify-center text-[10px] text-blue-600 font-bold shrink-0",children:r.authorType==="human"?"👤":"🤖"}),t.jsx("span",{className:"text-[11px] font-medium text-blue-600",children:r.authorName}),t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:new Date(r.createdAt).toLocaleString()})]}),t.jsx(er,{content:r.content,className:"text-sm text-fg-secondary"}),r.attachments?.map((s,i)=>s.type==="image"?t.jsx("img",{src:s.url,alt:s.name,className:"mt-2 max-w-full max-h-48 rounded-lg border border-border-default"},i):null)]})});function Wz(e){return e.kind==="log"?e.executionRound??1:0}function eL(e){const r=[];let s=null,i=[],o=1;for(const c of e){if(c.kind==="comment"){s?s.items.push(c):i.push(c);continue}const u=Wz(c);if(c.entry.type==="status"&&(c.entry.content==="started"||c.entry.content==="resumed")){(!s||u!==s.roundNumber)&&(s={id:o++,roundNumber:u,startTime:c.entry.timestamp??c.entry.time??"",status:"running",items:[],preComments:[...i]},i=[],r.push(s)),c.entry.content==="resumed"&&s.items.push(c);continue}if(c.entry.type==="status"&&["completed","failed","cancelled","execution_finished"].includes(c.entry.content)){if(s){const f=c.entry.content==="execution_finished"?"completed":c.entry.content;s.status=f,s.endTime=c.entry.timestamp??c.entry.time}continue}s&&s.items.push(c)}return s&&s.status==="running"&&(s.items.length>0||(s.status="interrupted")),i.length>0&&r.length>0&&r[r.length-1].items.push(...i),r.length===0&&e.length>0&&r.push({id:o++,roundNumber:1,startTime:e[0].kind==="log"?e[0].entry.timestamp??"":new Date(e[0].time).toISOString(),status:"running",items:[...i,...e],preComments:[]}),r}function tL(e,r){if(!r)return"";const s=new Date(r).getTime()-new Date(e).getTime();if(s<1e3)return"<1s";const i=Math.floor(s/1e3);if(i<60)return`${i}s`;const o=Math.floor(i/60);return o<60?`${o}m ${i%60}s`:`${Math.floor(o/60)}h ${o%60}m`}const Mv={running:{label:"Running",color:"text-blue-600",bg:"bg-blue-500/15"},completed:{label:"Completed",color:"text-green-600",bg:"bg-green-500/15"},failed:{label:"Failed",color:"text-red-500",bg:"bg-red-500/15"},cancelled:{label:"Cancelled",color:"text-fg-secondary",bg:"bg-gray-500/15"},interrupted:{label:"Interrupted",color:"text-amber-600",bg:"bg-amber-500/15"}},nL=j.memo(function({round:r,expanded:s,onToggle:i,isLive:o,streamingText:c,isExecuting:u,totalRounds:f}){const m=Mv[r.status]??Mv.running,h=tL(r.startTime,r.endTime),x=Jm(r.startTime),g=r.items.filter(p=>p.kind==="log"&&p.entry.type==="tool").length,b=r.items.filter(p=>p.kind==="log"&&p.entry.type==="error").length;return t.jsxs("div",{className:"border-b border-border-default/60 last:border-b-0",children:[r.preComments.length>0&&t.jsx("div",{className:"px-4 py-2",children:r.preComments.map((p,w)=>p.kind==="comment"?t.jsx(Av,{comment:p.entry},`pc-${p.entry.id}`):null)}),t.jsxs("button",{onClick:i,className:"w-full flex items-center gap-2 px-4 py-2.5 hover:bg-surface-elevated/40 transition-colors text-left min-w-0 overflow-hidden",children:[t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary shrink-0 transition-transform ${s?"rotate-90":""}`,viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M4 2l5 4-5 4V2z"})}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary shrink-0",children:f>1?`Round #${r.id}`:"Execution"}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${m.bg} ${m.color}`,children:m.label}),r.status==="running"&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 animate-pulse shrink-0"}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary ml-auto flex items-center gap-2 shrink-0 truncate",children:[g>0&&t.jsxs("span",{children:[g," tools"]}),b>0&&t.jsxs("span",{className:"text-red-500",children:[b," err"]}),h&&t.jsx("span",{children:h}),t.jsx("span",{children:x})]})]}),s&&t.jsxs("div",{className:"px-4 pb-3 space-y-0.5 overflow-x-hidden min-w-0",children:[r.items.map((p,w)=>p.kind==="comment"?t.jsx(Av,{comment:p.entry},`c-${p.entry.id}`):t.jsx(fT,{entry:p.entry,showTime:!0},`l-${(p.entry.type==="tool"?p.entry.key:void 0)??`${p.entry.timestamp}-${w}`}`)),o&&c&&t.jsx(ej,{content:c}),o&&u&&!c&&t.jsx(Nu,{label:"Thinking"})]})]})});function rL({taskId:e,isVisible:r,isRunning:s,authUser:i}){const[o,c]=j.useState([]),[u,f]=j.useState([]),[m,h]=j.useState(""),[x,g]=j.useState(s),[b,p]=j.useState(!0),[w,S]=j.useState(""),[T,E]=j.useState(!1),[C,N]=j.useState([]),[k,H]=j.useState(new Set),[M,Y]=j.useState(1),$=20,X=j.useRef(null),P=j.useRef(null),q=j.useRef(null),F=j.useRef(!0);j.useEffect(()=>{const z=q.current;if(!z)return;let V=z.parentElement;for(;V&&V.scrollHeight<=V.clientHeight;)V=V.parentElement;if(!V)return;const Q=V,te=()=>{F.current=Q.scrollHeight-Q.scrollTop-Q.clientHeight<80};return Q.addEventListener("scroll",te,{passive:!0}),()=>Q.removeEventListener("scroll",te)},[]),j.useEffect(()=>{g(s)},[s]),j.useEffect(()=>{p(!0),Promise.all([ae.tasks.getLogs(e).catch(()=>({logs:[]})),ae.tasks.getComments(e).catch(()=>({comments:[]}))]).then(([z,V])=>{c(z.logs),f(V.comments),p(!1)})},[e]),j.useEffect(()=>{const z=En.on("task:log",te=>{const Z=te.payload;if(Z.taskId!==e)return;const ee={id:Z.id,taskId:Z.taskId,agentId:Z.agentId,seq:Z.seq,type:Z.logType,content:Z.content,metadata:Z.metadata,executionRound:Z.executionRound,createdAt:Z.createdAt};c(ie=>ee.id&&ie.some(je=>je.id===ee.id)||!ee.id&&ie.some(je=>je.seq===ee.seq&&je.type===ee.type)?ie:[...ie,ee]),ee.type==="text"&&h(""),ee.type==="status"&&(ee.content==="started"||ee.content==="resumed"?g(!0):["completed","failed","cancelled","execution_finished"].includes(ee.content)&&g(!1)),ee.type==="error"&&g(!1)}),V=En.on("task:log:delta",te=>{const Z=te.payload;Z.taskId===e&&h(ee=>ee+Z.text)}),Q=En.on("task:comment",te=>{const Z=te.payload;if(Z.taskId!==e)return;const ee=Z.comment;f(ie=>ie.some(je=>je.id===ee.id)?ie:[...ie,ee])});return()=>{z(),V(),Q()}},[e]);const D=j.useMemo(()=>{const z=new Map;for(const V of o)V.executionRound&&z.set(V.seq,V.executionRound);return z},[o]),_=j.useMemo(()=>{const z=o.map(Z=>({log:Z,entry:Wm(Z)})).filter(Z=>Z.entry!=null),V=bo(z.map(Z=>Z.entry)),Q=new Set(V),te=[...z.filter(Z=>Q.has(Z.entry)).map(({log:Z,entry:ee})=>({kind:"log",entry:ee,time:new Date(ee.timestamp??ee.time??0).getTime(),executionRound:Z.executionRound??D.get(Z.seq)??1})),...u.map(Z=>({kind:"comment",entry:Z,time:new Date(Z.createdAt).getTime()}))];return te.sort((Z,ee)=>Z.time-ee.time),te},[o,u,D]),I=j.useMemo(()=>eL(_),[_]);j.useEffect(()=>{I.length>0&&H(z=>{const V=I[I.length-1].id;return z.has(V)?z:new Set([V])})},[I.length]),j.useEffect(()=>{r&&x&&P.current?.scrollIntoView({behavior:"smooth",block:"start"})},[I.length,r,x]);const A=j.useCallback(z=>{H(V=>{const Q=new Set(V);return Q.has(z)?Q.delete(z):Q.add(z),Q})},[]),G=z=>{const V=z.target.files;if(V){for(const Q of Array.from(V)){if(!Q.type.startsWith("image/"))continue;const te=new FileReader;te.onload=()=>{N(Z=>[...Z,{type:"image",url:te.result,name:Q.name}])},te.readAsDataURL(Q)}z.target.value=""}},U=async()=>{if(!(!w.trim()&&C.length===0)){E(!0);try{const z=await ae.tasks.addComment(e,w,i?.name,C.length>0?C:void 0,i?.id);z.comment&&f(V=>V.some(Q=>Q.id===z.comment.id)?V:[...V,z.comment]),S(""),N([])}catch{}E(!1)}},K=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-secondary z-10",children:[C.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:C.map((z,V)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:z.url,alt:z.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>N(Q=>Q.filter((te,Z)=>Z!==V)),className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-600 text-white text-[10px] flex items-center justify-center opacity-0 group-hover:opacity-100",children:"×"})]},V))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:w,onChange:z=>S(z.target.value),onKeyDown:z=>{z.key==="Enter"&&!z.shiftKey&&(z.preventDefault(),U())},placeholder:"Add a comment or instruction…",className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-blue-500 outline-none text-fg-primary placeholder-gray-600"}),t.jsx("input",{type:"file",ref:X,accept:"image/*",multiple:!0,onChange:G,className:"hidden"}),t.jsx("button",{onClick:()=>X.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:"Attach image",children:"📎"}),t.jsx("button",{onClick:()=>{U()},disabled:T||!w.trim()&&C.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:"Send"})]})]});if(b)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:"Loading logs…"});if(I.length===0&&!m)return t.jsxs("div",{className:"flex flex-col flex-1",children:[t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"text-center text-fg-tertiary",children:[t.jsx("div",{className:"text-2xl mb-2",children:"📋"}),t.jsxs("div",{className:"text-xs",children:["No execution logs yet.",t.jsx("br",{}),'Click "Run with Agent" to start.']})]})}),K]});const B=Math.ceil(I.length/$),L=M*$,W=(M-1)*$,R=I.slice(Math.max(0,I.length-L),I.length-W).slice().reverse();return t.jsxs("div",{children:[B>1&&t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-default",children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[I.length," rounds total"]}),t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:M<=1,onClick:()=>Y(z=>z-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"← Newer"}),t.jsxs("span",{children:[M,"/",B]}),t.jsx("button",{disabled:M>=B,onClick:()=>Y(z=>z+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"Older →"})]})]}),t.jsxs("div",{className:"py-1",children:[t.jsx("div",{ref:P}),R.map(z=>{const V=z.id===I[I.length-1]?.id;return t.jsx(nL,{round:z,expanded:k.has(z.id),onToggle:()=>A(z.id),isLive:V&&x,streamingText:V?m:void 0,isExecuting:V?x:!1,totalRounds:I.length},z.id)}),t.jsx("div",{ref:q})]}),K]})}function sL({filePath:e,onClose:r}){const[s,i]=j.useState(null),[o,c]=j.useState(null),[u,f]=j.useState(!0);j.useEffect(()=>{f(!0),c(null),ae.files.preview(e).then(h=>i(h)).catch(h=>c(String(h))).finally(()=>f(!1))},[e]);const m=e.split("/").pop()??e;return t.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",onClick:r,children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl w-[720px] max-w-[92vw] max-h-[85vh] flex flex-col shadow-2xl",onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),t.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),t.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:m})]}),t.jsx("button",{onClick:r,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0 ml-3",children:"×"})]}),t.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:e})}),t.jsxs("div",{className:"flex-1 overflow-auto min-h-0 p-5",children:[u&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:"Loading..."}),o&&t.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:o}),s&&s.type==="image"&&t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:`data:${s.mimeType};base64,${s.content}`,alt:s.name,className:"max-w-full max-h-[60vh] rounded-lg"})}),s&&s.type==="markdown"&&t.jsx(er,{content:s.content,className:"text-sm text-fg-secondary leading-relaxed"}),s&&s.type==="text"&&t.jsx("pre",{className:"text-xs text-fg-secondary font-mono whitespace-pre-wrap break-words bg-surface-primary/50 rounded-lg p-4 leading-relaxed",children:s.content})]})]})})}function aL({task:e,agents:r,projects:s,requirements:i,allTasks:o,users:c,onClose:u,onRefresh:f,authUser:m}){const[h,x]=j.useState([]),[g,b]=j.useState(""),[p,w]=j.useState(!1),[S,T]=j.useState(null),[E,C]=j.useState(null),[N,k]=j.useState(!1),[H,M]=j.useState("details"),[Y,$]=j.useState(!1),[X,P]=j.useState(null),[q,F]=j.useState(null),[D,_]=j.useState(!1),[I,A]=j.useState(e.description),[G,U]=j.useState(!1),[K,B]=j.useState(""),[L,W]=j.useState(1),[R,z]=j.useState(1),[V,Q]=j.useState(!1),te=gs(),Z=20,ee=j.useCallback(async()=>{try{const xe=await ae.tasks.listSubtasks(e.id);x(xe.subtasks)}catch{}},[e.id]);j.useEffect(()=>{ee()},[ee]);const ie=async xe=>{if(!N){k(!0);try{await xe(),f(),await ee()}catch(Be){P(String(Be).replace("Error: ",""))}finally{k(!1)}}},je=xe=>ie(()=>ae.tasks.update(e.id,{priority:xe})),ke=xe=>ie(()=>ae.tasks.assign(e.id,xe||null)),De=xe=>ie(()=>ae.tasks.update(e.id,{projectId:xe||null})),Ie=async()=>{if(!N){k(!0);try{await ae.tasks.pause(e.id),f()}finally{k(!1)}}},ze=async()=>{if(!Y){$(!0),P(null),M("logs");try{await ae.tasks.resume(e.id),f()}catch(xe){P(String(xe).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{$(!1)}}},Ze=async()=>{g.trim()&&(await ae.tasks.createSubtask(e.id,g.trim()),b(""),w(!1),ee(),f())},Ae=async xe=>{xe.status==="completed"?await ae.tasks.cancelSubtask(e.id,xe.id):await ae.tasks.completeSubtask(e.id,xe.id),ee(),f()},We=async xe=>{await ae.tasks.deleteSubtask(e.id,xe.id),T(null),ee(),f()},xt=async()=>{if(!N){k(!0);try{await ae.tasks.updateStatus(e.id,"pending_approval"),f()}finally{k(!1)}}},Lt=async()=>{if(!N){k(!0),P(null),M("logs");try{await ae.tasks.retry(e.id),f()}catch(xe){P(String(xe).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{k(!1)}}},le=async()=>{if(!Y){$(!0),P(null),M("logs");try{await ae.tasks.runNow(e.id),f()}catch(xe){P(String(xe).replace("Error: API error: 400","Server error").replace("Error: ","")),f()}finally{$(!1)}}};j.useEffect(()=>En.on("task:log:delta",Be=>{Be.payload.taskId===e.id&&M("logs")}),[e.id]);const _e=j.useRef(f);_e.current=f,j.useEffect(()=>En.on("task:update",Be=>{Be.payload.taskId===e.id&&(ee(),_e.current())}),[e.id,ee]);const ht=h.filter(xe=>xe.status==="completed").length,Ct=e.status==="in_progress",Ft=e.status==="blocked",be=e.status==="completed",Me=e.status==="failed",Ve=e.status==="cancelled",Xe=e.status==="archived",rt=be||Me||Ve||Xe,It=e.taskType==="scheduled"&&!!e.scheduleConfig,Ht=It&&!!e.scheduleConfig?.paused,_t=s.find(xe=>xe.id===e.projectId),wt=i.find(xe=>xe.id===e.requirementId);return r.find(xe=>xe.id===e.assignedAgentId),t.jsxs("div",{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3 ${te?"pb-[4.5rem]":""}`,onClick:u,children:[t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl flex flex-col shadow-2xl ${te?"w-full max-h-full":"w-[780px] max-w-[95vw] max-h-[88vh]"}`,onClick:xe=>xe.stopPropagation(),children:[t.jsxs("div",{className:"flex items-start justify-between px-6 pt-5 pb-3 border-b border-border-default shrink-0",children:[t.jsx("div",{className:"flex-1 min-w-0 pr-4",children:t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("h3",{className:"text-base font-semibold leading-snug",children:e.title}),(()=>{const xe=Jz[e.status];return xe?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap ${xe.cls}`,children:xe.label}):t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium bg-gray-500/15 text-fg-tertiary whitespace-nowrap",children:e.status.replace(/_/g," ")})})()]})}),t.jsx("button",{onClick:u,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:D?t.jsxs("div",{className:"space-y-2",children:[t.jsx("textarea",{value:I,onChange:xe=>A(xe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-y min-h-[80px]",rows:4,placeholder:"Add a description…"}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx("button",{onClick:()=>{_(!1),A(e.description)},className:"px-2.5 py-1 text-xs border border-border-default rounded-lg hover:bg-surface-elevated",children:"Cancel"}),t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.update(e.id,{description:I})),_(!1)},disabled:N,className:"px-2.5 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Save"})]})]}):t.jsxs("div",{className:"group relative",children:[e.description?t.jsxs("div",{children:[t.jsx("div",{className:te&&!V?"line-clamp-3":"",children:t.jsx(er,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),te&&e.description.length>150&&t.jsx("button",{onClick:()=>Q(!V),className:"text-[11px] text-brand-500 mt-1 font-medium",children:V?"Collapse":"Show more"})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No description"}),t.jsx("button",{onClick:()=>{A(e.description),_(!0)},className:"absolute top-0 right-0 text-[10px] text-fg-tertiary hover:text-brand-500 opacity-0 group-hover:opacity-100 transition-opacity",children:"Edit"})]})}),(_t||wt)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[_t&&t.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full",children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:"Project"}),_t.name]}),wt&&t.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full",children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:"Req"}),wt.title.length>40?wt.title.slice(0,40)+"…":wt.title]})]}),t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default",children:[t.jsx("div",{className:"flex items-center justify-between mb-1.5",children:t.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:"Dependencies"})}),e.blockedBy&&e.blockedBy.length>0?t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(xe=>{const Be=o.find(pt=>pt.id===xe),gt=Be&&(Be.status==="completed"||Be.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${gt?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:gt?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${gt?"line-through opacity-60":""}`,children:Be?Be.title.slice(0,30):xe.slice(-8)}),!rt&&t.jsx("button",{onClick:async()=>{const pt=(e.blockedBy??[]).filter(ue=>ue!==xe);await ae.tasks.update(e.id,{blockedBy:pt}),f()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:"Remove dependency",children:"×"})]},xe)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:"No dependencies"}),!rt&&t.jsxs("select",{value:"",onChange:async xe=>{const Be=xe.target.value;if(!Be)return;const gt=[...e.blockedBy??[],Be];await ae.tasks.update(e.id,{blockedBy:gt}),f()},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"+ Add dependency…"}),o.filter(xe=>xe.id!==e.id&&!(e.blockedBy??[]).includes(xe.id)).map(xe=>t.jsx("option",{value:xe.id,children:xe.title},xe.id))]})]}),t.jsxs("div",{className:"flex gap-1 px-6 pt-3 border-b border-border-default sticky top-0 z-10 bg-surface-secondary",children:[t.jsx("button",{onClick:()=>M("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${H==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:"Details"}),t.jsxs("button",{onClick:()=>M("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${H==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Execution Log",Ct&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsxs("button",{onClick:()=>M("notes"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${H==="notes"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Notes",e.notes&&e.notes.length>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary font-normal",children:e.notes.length})]}),t.jsxs("button",{onClick:()=>M("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${H==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Deliverables",(()=>{const xe=(e.deliverables??[]).filter(Be=>Be.type!=="branch"&&typeof Be.reference=="string"&&Be.reference.length>0).length;return xe>0?t.jsx("span",{className:"text-[10px] text-fg-tertiary font-normal",children:xe}):null})()]})]}),H==="logs"&&t.jsxs("div",{className:"overflow-x-hidden min-w-0",children:[X&&t.jsxs("div",{className:"mx-4 mt-3 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:[t.jsx("span",{className:"font-medium",children:"Failed to start:"})," ",X]}),t.jsx(rL,{taskId:e.id,isVisible:!0,isRunning:e.status==="in_progress",authUser:m})]}),H==="details"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Project"}),t.jsxs("select",{value:e.projectId??"",onChange:xe=>{De(xe.target.value)},disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"No Project"}),s.map(xe=>t.jsx("option",{value:xe.id,children:xe.name},xe.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Requirement"}),t.jsxs("select",{value:e.requirementId??"",onChange:xe=>ie(()=>ae.tasks.update(e.id,{requirementId:xe.target.value||null})),disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"No Requirement"}),i.filter(xe=>!e.projectId||xe.projectId===e.projectId).map(xe=>t.jsx("option",{value:xe.id,children:xe.title},xe.id))]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Assignee"}),t.jsxs("select",{value:e.assignedAgentId??"",onChange:xe=>{ke(xe.target.value)},disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"Unassigned"}),r.map(xe=>t.jsxs("option",{value:xe.id,children:[xe.name," (",xe.status,")"]},xe.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Reviewer"}),t.jsx("select",{value:e.reviewerAgentId??"",onChange:xe=>{xe.target.value&&xe.target.value!==e.reviewerAgentId&&ie(()=>ae.tasks.update(e.id,{reviewerAgentId:xe.target.value}))},disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:r.map(xe=>t.jsx("option",{value:xe.id,children:xe.name},xe.id))})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Priority"}),t.jsxs("select",{value:e.priority,onChange:xe=>{je(xe.target.value)},disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"low",children:"Low"}),t.jsx("option",{value:"medium",children:"Medium"}),t.jsx("option",{value:"high",children:"High"}),t.jsx("option",{value:"urgent",children:"Urgent"})]})]})]})]}),t.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&t.jsxs("span",{children:["Created by ",t.jsx("span",{className:"text-fg-secondary",children:el(e.createdBy,r,c)??e.createdBy})]}),e.updatedBy&&t.jsxs("span",{children:["Updated by ",t.jsx("span",{className:"text-fg-secondary",children:el(e.updatedBy,r,c)??e.updatedBy})]}),e.createdAt&&t.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&t.jsxs("span",{children:["Started ",new Date(e.startedAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:["Updated ",new Date(e.updatedAt).toLocaleDateString()]}),e.projectId&&t.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&t.jsxs("span",{className:"text-amber-600",children:["Round ",e.executionRound]})]}),t.jsxs("div",{className:"px-6 py-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:["Subtasks ",h.length>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[ht,"/",h.length," done"]})]}),t.jsx("button",{onClick:()=>w(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:"+ Add subtask"})]}),h.length>0&&t.jsx("div",{className:"space-y-1.5 mb-3",children:h.map(xe=>t.jsxs("div",{className:"group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors",children:[t.jsx("button",{onClick:()=>{Ae(xe)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${xe.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:xe.status==="completed"&&t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),t.jsx("span",{className:`flex-1 text-sm ${xe.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:xe.title}),t.jsx("button",{onClick:()=>T(xe),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},xe.id))}),h.length===0&&!p&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:"No subtasks yet."}),p&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:g,onChange:xe=>b(xe.target.value),onKeyDown:xe=>{xe.key==="Enter"&&Ze(),xe.key==="Escape"&&(w(!1),b(""))},placeholder:"Subtask title...",className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{onClick:()=>{Ze()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:"Add"}),t.jsx("button",{onClick:()=>{w(!1),b("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:"Cancel"})]}),(()=>{const xe=(e.deliverables??[]).filter(pt=>pt.type!=="branch"&&typeof pt.reference=="string"&&pt.reference.length>0);if(xe.length===0)return null;const Be={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},gt=xe.slice(0,3);return t.jsxs("div",{className:"mt-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:["Deliverables ",t.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",xe.length,")"]})]}),xe.length>3&&t.jsx("button",{onClick:()=>M("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:"View all →"})]}),t.jsx("div",{className:"space-y-1.5",children:gt.map((pt,ue)=>{const Se=pt.reference.split("/").pop()??pt.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Be[pt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:pt.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>F(pt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:pt.reference,children:Se}),pt.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:pt.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:pt.reference})]})]},ue)})})]})})(),e.notes&&e.notes.length>0&&(()=>{const xe=[...e.notes].reverse().slice(0,3);return t.jsxs("div",{className:"mt-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:["Progress Notes ",t.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",e.notes.length,")"]})]}),e.notes.length>3&&t.jsx("button",{onClick:()=>M("notes"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:"View all →"})]}),t.jsx("div",{className:"space-y-1.5",children:xe.map((Be,gt)=>t.jsx("div",{className:"text-xs text-fg-secondary bg-surface-elevated/60 rounded px-2.5 py-1.5 leading-relaxed",children:t.jsx(er,{content:Be,className:"text-xs text-fg-secondary"})},gt))})]})})()]})]}),H==="notes"&&t.jsx("div",{className:"px-6 py-4",children:e.notes&&e.notes.length>0?(()=>{const xe=[...e.notes].reverse(),Be=Math.ceil(xe.length/Z),gt=xe.slice((R-1)*Z,R*Z);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:["Progress Notes ",t.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",e.notes.length,")"]})]}),Be>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:R<=1,onClick:()=>z(pt=>pt-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[R,"/",Be]}),t.jsx("button",{disabled:R>=Be,onClick:()=>z(pt=>pt+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),t.jsx("div",{className:"space-y-1.5",children:gt.map((pt,ue)=>t.jsx("div",{className:"text-xs text-fg-secondary bg-surface-elevated/60 rounded px-2.5 py-1.5 leading-relaxed",children:t.jsx(er,{content:pt,className:"text-xs text-fg-secondary"})},ue))})]})})():t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:"No progress notes yet."})}),H==="deliverables"&&t.jsx("div",{className:"px-6 py-4",children:(()=>{const xe=(e.deliverables??[]).filter(ue=>ue.type!=="branch"&&typeof ue.reference=="string"&&ue.reference.length>0);if(xe.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:"No deliverables yet."});const Be={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},gt=Math.ceil(xe.length/Z),pt=xe.slice((L-1)*Z,L*Z);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:["Deliverables ",t.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",xe.length,")"]})]}),gt>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:L<=1,onClick:()=>W(ue=>ue-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[L,"/",gt]}),t.jsx("button",{disabled:L>=gt,onClick:()=>W(ue=>ue+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),t.jsx("div",{className:"space-y-1.5",children:pt.map((ue,Se)=>{const Ke=ue.reference.split("/").pop()??ue.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Be[ue.type]??"bg-gray-500/15 text-fg-secondary"}`,children:ue.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>F(ue.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:ue.reference,children:Ke}),ue.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:ue.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:ue.reference})]})]},Se)})})]})})()})]}),It&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Ht?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:Ht?"text-amber-600":"text-brand-500",children:Ht?"⏸ Schedule Paused":t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3.5 h-3.5 inline -mt-0.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})," Scheduled"]})}),t.jsx("span",{className:"text-fg-tertiary",children:"·"}),t.jsx("span",{className:"text-fg-secondary",children:e.scheduleConfig.every?`Every ${e.scheduleConfig.every}`:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.runAt?"One-shot":"N/A"}),!Ht&&e.scheduleConfig.nextRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-fg-tertiary",children:"·"}),t.jsxs("span",{className:"text-fg-secondary",children:["Next: ",(()=>{const xe=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(xe<=0)return"due now";const Be=Math.floor(xe/6e4);if(Be<60)return`in ${Be}m`;const gt=Math.floor(Be/60);return gt<24?`in ${gt}h ${Be%60}m`:`in ${Math.floor(gt/24)}d ${gt%24}h`})()]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[t.jsxs("span",{children:["Runs: ",e.scheduleConfig.currentRuns??0,e.scheduleConfig.maxRuns!=null?` / ${e.scheduleConfig.maxRuns}`:""]}),e.scheduleConfig.lastRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsxs("span",{children:["Last: ",(()=>{const xe=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),Be=Math.floor(xe/6e4);if(Be<1)return"just now";if(Be<60)return`${Be}m ago`;const gt=Math.floor(Be/60);return gt<24?`${gt}h ${Be%60}m ago`:`${Math.floor(gt/24)}d ago`})()]})]})]})]}),t.jsx("div",{className:"px-6 py-4 border-t border-border-default flex items-center justify-between gap-2",children:t.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.status==="pending_approval"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>ie(()=>ae.tasks.approve(e.id)),disabled:N,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:"Approve"}),t.jsx("button",{onClick:()=>ie(()=>ae.tasks.reject(e.id)),disabled:N,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:"Reject"})]}),e.status==="review"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.accept(e.id,m?.id))},disabled:N,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:"✓ Approve"}),G?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:K,onChange:xe=>B(xe.target.value),onKeyDown:xe=>{xe.key==="Enter"&&K.trim()&&(ie(()=>ae.tasks.revision(e.id,K.trim(),m?.id)),U(!1),B(""))},placeholder:"Revision reason…",autoFocus:!0,className:"px-2 py-1 text-xs bg-surface-elevated border border-amber-500/40 rounded-lg text-fg-primary focus:border-amber-400 outline-none w-48"}),t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.revision(e.id,K.trim()||"Revisions needed",m?.id)),U(!1),B("")},disabled:N,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:"Send"}),t.jsx("button",{onClick:()=>{U(!1),B("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>U(!0),disabled:N,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:"↻ Request Revision"})]}),Ct&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{Ie()},disabled:N,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[t.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),t.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),"Pause"]}),t.jsxs("button",{onClick:()=>{Lt()},disabled:N,className:"px-3 py-1.5 text-xs border border-blue-500/30 text-blue-600 rounded-lg hover:bg-blue-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),"Retry"]})]}),Ft&&t.jsx("button",{onClick:()=>{ze()},disabled:Y,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:Y?t.jsx(t.Fragment,{children:"Resuming…"}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),"Resume"]})}),Me&&t.jsxs("button",{onClick:()=>{Lt()},disabled:N,className:"px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),"Retry"]}),It&&(be||Me)&&t.jsx("button",{onClick:()=>{le()},disabled:Y,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1.5",children:Y?t.jsx(t.Fragment,{children:"Running…"}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),"Run Now"]})}),It&&!Ct&&(Ht?t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.resumeSchedule(e.id))},disabled:N,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:"▶ Resume Schedule"}):t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.pauseSchedule(e.id))},disabled:N,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50",children:"⏸ Pause Schedule"})),be&&t.jsx("button",{onClick:()=>ie(()=>ae.tasks.archive(e.id)),disabled:N,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:"Archive"}),rt&&t.jsx("button",{onClick:()=>{xt()},disabled:N,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary disabled:opacity-50",children:"Reopen"}),!rt&&e.status!=="pending_approval"&&t.jsx("button",{onClick:async()=>{const{count:xe}=await ae.tasks.getDependentCount(e.id);xe>0?C({dependentCount:xe}):ie(()=>ae.tasks.cancel(e.id))},disabled:N,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:"Cancel"})]})})]}),S&&t.jsx(sj,{title:`Delete subtask "${S.title}"?`,message:"This subtask will be permanently deleted.",confirmLabel:"Delete",onConfirm:()=>{We(S)},onCancel:()=>T(null)}),E&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>C(null),children:t.jsxs("div",{className:"bg-surface-default border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:xe=>xe.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:"Cancel Task"}),t.jsxs("p",{className:"text-sm text-fg-secondary mb-4",children:["This task has ",t.jsx("span",{className:"text-amber-600 font-medium",children:E.dependentCount})," dependent task",E.dependentCount>1?"s":""," that ",E.dependentCount>1?"are":"is"," currently blocked by it."]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("button",{onClick:()=>{C(null),ie(()=>ae.tasks.cancel(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-surface-elevated border border-border-default rounded-lg hover:bg-surface-overlay text-fg-primary text-left",children:[t.jsx("span",{className:"font-medium",children:"Cancel this task only"}),t.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:"Dependent tasks will start if they have no other blockers"})]}),t.jsxs("button",{onClick:()=>{C(null),ie(()=>ae.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[t.jsx("span",{className:"font-medium",children:"Cancel with all dependents"}),t.jsxs("span",{className:"block text-xs text-red-500/70 mt-0.5",children:["Also cancels ",E.dependentCount," blocked task",E.dependentCount>1?"s":""]})]}),t.jsx("button",{onClick:()=>C(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:"Keep task running"})]})]})}),q&&t.jsx(sL,{filePath:q,onClose:()=>F(null)})]})}function iL({project:e,tasks:r,requirements:s,agents:i,onDeleteProject:o,onUpdateProject:c,onRefresh:u}){const f=j.useMemo(()=>r.filter(b=>b.projectId===e.id),[r,e.id]),m=j.useMemo(()=>s.filter(b=>b.projectId===e.id),[s,e.id]),h=j.useMemo(()=>{const b={total:f.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:m.length,reqsDone:0};for(const p of f)p.status==="completed"||p.status==="accepted"?b.completed++:p.status==="in_progress"?b.inProgress++:p.status==="review"||p.status==="revision"?b.inReview++:p.status==="blocked"?b.blocked++:p.status==="failed"?b.failed++:b.pending++;for(const p of m)p.status==="completed"&&b.reqsDone++;return b},[f,m]),x=j.useMemo(()=>new Set(f.map(b=>b.assignedAgentId).filter(Boolean)),[f]),g=j.useMemo(()=>i.filter(b=>x.has(b.id)),[i,x]);return t.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[t.jsxs("div",{className:"flex items-start justify-between",children:[t.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[t.jsx(Zz,{value:e.description??"",onSave:async b=>{await c({description:b}),u()},className:"text-sm text-fg-secondary",placeholder:"Add a project description…"}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[t.jsx(mL,{status:e.status}),e.createdAt&&t.jsxs("span",{className:"text-fg-tertiary",children:["Created ",new Date(e.createdAt).toLocaleDateString()]})]})]}),t.jsx("button",{onClick:o,className:"text-xs text-red-500 hover:text-red-500 shrink-0 ml-4",children:"Delete Project"})]}),t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Task Overview"}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(zs,{label:"Total",value:h.total,color:"text-fg-primary"}),t.jsx(zs,{label:"Completed",value:h.completed,color:"text-green-600"}),t.jsx(zs,{label:"In Progress",value:h.inProgress,color:"text-brand-500"}),t.jsx(zs,{label:"In Review",value:h.inReview,color:"text-brand-500"}),t.jsx(zs,{label:"Blocked",value:h.blocked,color:"text-amber-600"}),t.jsx(zs,{label:"Failed",value:h.failed,color:"text-red-500"})]}),h.total>0&&t.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[h.completed>0&&t.jsx("div",{className:"bg-green-500",style:{width:`${h.completed/h.total*100}%`}}),h.inProgress>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${h.inProgress/h.total*100}%`}}),h.inReview>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${h.inReview/h.total*100}%`}}),h.blocked>0&&t.jsx("div",{className:"bg-amber-500",style:{width:`${h.blocked/h.total*100}%`}}),h.pending>0&&t.jsx("div",{className:"bg-blue-500/40",style:{width:`${h.pending/h.total*100}%`}}),h.failed>0&&t.jsx("div",{className:"bg-red-500",style:{width:`${h.failed/h.total*100}%`}})]})]}),t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Requirements"}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(zs,{label:"Total",value:h.reqs,color:"text-fg-primary"}),t.jsx(zs,{label:"Completed",value:h.reqsDone,color:"text-green-600"}),t.jsx(zs,{label:"Active",value:h.reqs-h.reqsDone,color:"text-brand-500"})]})]}),g.length>0&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsxs("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:["Agents (",g.length,")"]}),t.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(b=>{const p=f.filter(S=>S.assignedAgentId===b.id),w=p.filter(S=>!["completed","failed","cancelled","archived"].includes(S.status));return t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-elevated/60 rounded-lg",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${b.status==="working"?"bg-blue-500":b.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:b.name}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[w.length," active / ",p.length," total"]})]},b.id)})})]}),e.repositories&&e.repositories.length>0&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-2",children:"Repositories"}),e.repositories.map((b,p)=>t.jsxs("div",{className:"text-sm text-fg-secondary flex items-center gap-2",children:[t.jsx("span",{className:"text-fg-tertiary",children:"⎇"}),t.jsx("span",{children:b.url||b.localPath}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",b.defaultBranch,")"]})]},p))]})]})}function zs({label:e,value:r,color:s}){return t.jsxs("div",{className:"text-center py-2",children:[t.jsx("div",{className:`text-xl font-bold ${s}`,children:r}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const $u={draft:{label:"Draft",cls:"bg-gray-500/15 text-fg-secondary"},pending_review:{label:"Pending",cls:"bg-amber-500/15 text-amber-600"},approved:{label:"Approved",cls:"bg-green-500/15 text-green-600"},in_progress:{label:"Active",cls:"bg-brand-500/15 text-brand-500"},completed:{label:"Done",cls:"bg-green-500/15 text-green-600"},rejected:{label:"Rejected",cls:"bg-red-500/15 text-red-500"},cancelled:{label:"Cancelled",cls:"bg-gray-600/15 text-fg-tertiary"}},oN={draft:"todo",pending_review:"todo",approved:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed"},cN={failed:"rejected",todo:"approved",in_progress:"in_progress",review:"approved",done:"completed",closed:"cancelled"},lL={urgent:0,high:1,medium:2,low:3},Dv={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},oL={failed:"border-l-red-500 bg-red-500/5",todo:"border-l-blue-500 bg-blue-500/5",in_progress:"border-l-brand-500 bg-brand-500/5",review:"border-l-purple-500 bg-brand-500/5",done:"border-l-green-500 bg-green-500/5",closed:"border-l-gray-500 bg-gray-500/5"},cL={failed:"border-l-red-500 text-red-500",todo:"border-l-blue-500 text-blue-600",in_progress:"border-l-brand-500 text-brand-500",review:"border-l-purple-500 text-brand-500",done:"border-l-green-500 text-green-600",closed:"border-l-gray-500 text-fg-tertiary"},uN=["draft","pending_review","approved","in_progress","completed","rejected","cancelled"];function uL(e){for(const r of To)if(r.statuses.includes(e))return r.id;return"closed"}function dL(e){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Ov({row:e,idx:r,dragIdx:s,agentMap:i,projMap:o,onTaskClick:c,onReqClick:u,onRowDragStart:f,onRowDragEnd:m,handleStatusChange:h,handlePriorityChange:x}){const g=e.data.status,b=e.data.priority,p=e.kind==="task"?i.get(e.data.assignedAgentId??""):void 0,w=o.get((e.kind==="task",e.data.projectId??""));return t.jsxs("div",{draggable:!0,onDragStart:S=>f(S,r),onDragEnd:m,onClick:()=>e.kind==="task"?c(e.data):u(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer hover:bg-surface-elevated/50 transition-colors border-l-2 ${oL[e.group]??"border-l-gray-700"} ${s===r?"opacity-40":""}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:e.kind==="req"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:"REQ"}):e.data.taskType==="scheduled"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600 inline-flex items-center gap-0.5",title:"Scheduled task",children:"SCHED"}):t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:"TASK"})}),t.jsx("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate",children:e.data.title}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:S=>S.stopPropagation(),children:t.jsx("select",{value:g,onChange:S=>{h(e,S.target.value)},className:"w-full px-1.5 py-1 bg-surface-elevated/80 border border-border-default/50 rounded text-[11px] text-fg-secondary outline-none focus:border-brand-500 cursor-pointer",children:e.kind==="task"?Qz.map(S=>t.jsx("option",{value:S,children:Kz[S]??S},S)):uN.map(S=>t.jsx("option",{value:S,children:$u[S]?.label??S},S))})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:S=>S.stopPropagation(),children:t.jsxs("select",{value:b,onChange:S=>{x(e,S.target.value)},className:"w-full px-1.5 py-1 bg-surface-elevated/80 border border-border-default/50 rounded text-[11px] text-fg-secondary outline-none focus:border-brand-500 cursor-pointer",children:[t.jsx("option",{value:"low",children:"Low"}),t.jsx("option",{value:"medium",children:"Medium"}),t.jsx("option",{value:"high",children:"High"}),t.jsx("option",{value:"urgent",children:"Urgent"})]})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] text-fg-secondary truncate",children:p?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${lN[p.status]??"bg-gray-500"}`}),p.name]}):t.jsx("span",{className:"text-fg-tertiary",children:"—"})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] text-fg-tertiary truncate",children:w?.name??t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-tertiary text-right",children:dL(e.data.updatedAt??"")})]})}function fL({tasks:e,requirements:r,agents:s,projects:i,onTaskClick:o,onReqClick:c,onRefresh:u}){const[f,m]=j.useState("status"),[h,x]=j.useState(null),[g,b]=j.useState(null),p=j.useMemo(()=>{const q=[];for(const F of e){const D=uL(F.status);q.push({kind:"task",data:F,group:D,groupOrder:Dv[D]??5})}for(const F of r){const D=oN[F.status]??"todo";q.push({kind:"req",data:F,group:D,groupOrder:Dv[D]??5})}if(f==="status")q.sort((F,D)=>{if(F.groupOrder!==D.groupOrder)return F.groupOrder-D.groupOrder;const _=new Date(F.data.updatedAt??0).getTime();return new Date(D.data.updatedAt??0).getTime()-_});else{const F=D=>lL[D.data.priority]??2;q.sort((D,_)=>{const I=F(D),A=F(_);return I!==A?I-A:new Date(_.data.updatedAt??0).getTime()-new Date(D.data.updatedAt??0).getTime()})}return q},[e,r,f]),w=async(q,F)=>{try{q.kind==="task"?await ae.tasks.updateStatus(q.data.id,F):await ae.requirements.updateStatus(q.data.id,F),u()}catch{}},S=async(q,F)=>{try{q.kind==="task"?await ae.tasks.update(q.data.id,{priority:F}):await ae.requirements.update(q.data.id,{priority:F}),u()}catch{}},T=(q,F)=>{x(F),q.dataTransfer.effectAllowed="move",q.dataTransfer.setData("text/plain",String(F)),q.currentTarget.style.opacity="0.4"},E=q=>{q.currentTarget.style.opacity="1",x(null),b(null)},C=(q,F)=>{q.preventDefault(),q.dataTransfer.dropEffect="move",g!==F&&b(F)},N=async(q,F)=>{if(q.preventDefault(),b(null),h==null)return;const D=p[h];if(!D||D.group===F)return;const _=To.find(I=>I.id===F);if(_){try{if(D.kind==="task"){if(D.data.status==="pending_approval")return;await ae.tasks.updateStatus(D.data.id,_.dropStatus)}else{const I=cN[F];I&&await ae.requirements.updateStatus(D.data.id,I)}u()}catch{}x(null)}},k=j.useMemo(()=>new Map(s.map(q=>[q.id,q])),[s]),H=j.useMemo(()=>new Map(i.map(q=>[q.id,q])),[i]),M=["todo","in_progress","review","done"],Y=j.useMemo(()=>{const q={};for(const F of p)q[F.group]=(q[F.group]??0)+1;return q},[p]),{rowsByGroup:$,rowIndexMap:X}=j.useMemo(()=>{const q=new Map,F=new Map;for(let D=0;D<p.length;D++){const _=p[D];F.set(_,D);const I=q.get(_.group)??[];I.push(_),q.set(_.group,I)}return{rowsByGroup:q,rowIndexMap:F}},[p]),P=j.useMemo(()=>{if(f!=="status")return null;const q=new Set(p.map(_=>_.group)),F=[],D=new Set;q.has("failed")&&(F.push("failed"),D.add("failed"));for(const _ of M)F.push(_),D.add(_);for(const _ of p)D.has(_.group)||(F.push(_.group),D.add(_.group));return F},[p,f]);return t.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:t.jsxs("div",{className:"min-w-[850px] h-full flex flex-col",children:[t.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider shrink-0 bg-surface-secondary/80",children:[t.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:p.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:"Title"}),t.jsxs("button",{onClick:()=>m("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:["Status ",f==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>m("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:["Priority ",f==="priority"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsx("div",{className:"w-[120px] shrink-0",children:"Assignee"}),t.jsx("div",{className:"w-[120px] shrink-0",children:"Project"}),t.jsx("div",{className:"w-[90px] shrink-0 text-right",children:"Updated"})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[f==="status"&&P?P.map(q=>{const F=To.find(_=>_.id===q),D=$.get(q)??[];return t.jsxs("div",{children:[t.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-secondary/60 sticky top-0 z-10 ${cL[q]??""} ${g===q?"ring-1 ring-brand-500/40":""}`,onDragOver:_=>C(_,q),onDragLeave:()=>b(null),onDrop:_=>{N(_,q)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:F?.label??q}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Y[q]??0})]}),D.map(_=>t.jsx(Ov,{row:_,idx:X.get(_)??0,dragIdx:h,agentMap:k,projMap:H,onTaskClick:o,onReqClick:c,onRowDragStart:T,onRowDragEnd:E,handleStatusChange:w,handlePriorityChange:S},`${_.kind}-${_.data.id}`))]},q)}):p.map((q,F)=>t.jsx(Ov,{row:q,idx:F,dragIdx:h,agentMap:k,projMap:H,onTaskClick:o,onReqClick:c,onRowDragStart:T,onRowDragEnd:E,handleStatusChange:w,handlePriorityChange:S},`${q.kind}-${q.data.id}`)),p.length===0&&t.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-fg-tertiary",children:"No items"})]})]})})}function Rv({authUser:e}){const r=gs(),[s,i]=j.useState([]),[o,c]=j.useState("all"),[u,f]=j.useState(null),[m,h]=j.useState({}),[x,g]=j.useState([]),[b,p]=j.useState([]),[w,S]=j.useState([]),[T,E]=j.useState(!0),[C,N]=j.useState(""),[k,H]=j.useState(!1),M=j.useCallback(()=>{Se(u??""),Ht(!0)},[u]),[Y,$]=j.useState(!1),[X,P]=j.useState(!1),[q,F]=j.useState(""),[D,_]=j.useState(""),[I,A]=j.useState("medium"),[G,U]=j.useState(""),[K,B]=j.useState(""),[L,W]=j.useState(""),[R,z]=j.useState(""),[V,Q]=j.useState([]),[te,Z]=j.useState("standard"),[ee,ie]=j.useState("4h"),[je,ke]=j.useState(null),[De,Ie]=j.useState(null),[ze,Ze]=j.useState(new Set),[Ae,We]=j.useState(new Set),xt=j.useRef(new Set),Lt=j.useRef(new Set),[le,_e]=j.useState(null),[ht,Ct]=j.useState("backlog"),[Ft,be]=j.useState(!1),[Me,Ve]=j.useState(!1),Xe=j.useRef(null),rt=j.useRef(null),[It,Ht]=j.useState(!1),[_t,wt]=j.useState(""),[xe,Be]=j.useState(""),[gt,pt]=j.useState("medium"),[ue,Se]=j.useState(""),[Ke,At]=j.useState(null),[rn,vn]=j.useState(""),Mt=ne=>{N(ne),setTimeout(()=>N(""),3e3)},oe=s.find(ne=>ne.id===u)??null;j.useEffect(()=>{Lt.current=Ae},[Ae]);const Le=j.useCallback(async()=>{try{const{projects:ne}=await ae.projects.list();i(ne)}catch{}},[]),$e=j.useCallback(async()=>{const ne={};o==="project"&&u&&(ne.projectId=u);try{const{board:Oe}=await ae.tasks.board(ne);h(Oe)}catch{}},[o,u]),st=j.useCallback(async()=>{try{const{agents:ne}=await ae.agents.list();g(ne)}catch{}},[]),at=j.useCallback(async()=>{try{const{users:ne}=await ae.users.list(e?.orgId);p(ne)}catch{}},[e?.orgId]),Ue=j.useCallback(async()=>{try{const{requirements:ne}=await ae.requirements.list({});S(ne)}catch{}},[]),jn=j.useCallback(async()=>{await Promise.all([Le(),$e(),st(),at(),Ue()]),E(!1)},[Le,$e,st,at,Ue]);j.useEffect(()=>{jn()},[jn]);const gn=j.useRef(je);gn.current=je,j.useEffect(()=>{const Oe=setInterval(()=>{$e(),st(),Ue()},je?6e4:15e3),Pe=En.on("task:update",et=>{gn.current||($e(),Ue());const re=et?.payload;re?.taskId&&ke(pe=>{if(!pe||pe.id!==re.taskId)return pe;const Ne={};return typeof re.status=="string"&&(Ne.status=re.status),Array.isArray(re.deliverables)&&(Ne.deliverables=re.deliverables),Array.isArray(re.notes)&&(Ne.notes=re.notes),re.result!==void 0&&(Ne.result=re.result),{...pe,...Ne}})});return()=>{clearInterval(Oe),Pe()}},[$e,st,Ue,je]);const Dt=j.useRef(m);Dt.current=m,j.useEffect(()=>{const ne=localStorage.getItem("markus_nav_openTask");if(!ne)return;const Pe=Object.values(m).flat().find(et=>et.id===ne);Pe&&(ke(Pe),localStorage.removeItem("markus_nav_openTask"))},[m]),j.useEffect(()=>{const ne=window.location.hash.slice(1).split("/");if(ne[0]==="projects"&&ne[1])Dn(ne[1]);else{const Oe=localStorage.getItem("markus_nav_projectId");Oe&&(localStorage.removeItem("markus_nav_projectId"),Dn(Oe))}},[]),j.useEffect(()=>{const ne=()=>{const Pe=window.location.hash.slice(1).split("/");Pe[0]==="projects"&&Pe[1]?Dn(Pe[1]):Pe[0]==="projects"&&Un()},Oe=Pe=>{const et=Pe.detail;if(et.page==="tasks"||et.page==="projects"){if(et.params?.openTask){const pe=Object.values(Dt.current).flat().find(Ne=>Ne.id===et.params.openTask);pe&&ke(pe)}et.params?.projectId&&Dn(et.params.projectId),!et.params?.projectId&&!et.params?.openTask&&Un()}};return window.addEventListener("markus:navigate",Oe),window.addEventListener("hashchange",ne),()=>{window.removeEventListener("markus:navigate",Oe),window.removeEventListener("hashchange",ne)}},[]);const Dn=ne=>{Lt.current.size>0&&(xt.current=new Set(Lt.current)),We(new Set),f(ne),c("project"),H(!1),history.replaceState(null,"","#projects/"+ne)},Un=()=>{We(xt.current),f(null),c("all"),H(!1),history.replaceState(null,"","#projects")},On=()=>{$(!1),Mt("Project created"),Le()},on=async ne=>{if(confirm("Delete this project and unlink all its tasks?"))try{await ae.projects.delete(ne),u===ne&&Un(),Mt("Project deleted"),Le(),$e()}catch(Oe){Mt(`Error: ${Oe}`)}},cn=async()=>{if(!q||!G||!K)return;if(G===K){Mt("Assigned agent and reviewer must be different");return}const ne=L||void 0,Oe=R||void 0;try{await ae.tasks.create(q,D,G,K,I,ne,V.length>0?V:void 0,Oe,te!=="standard"?te:void 0,te==="scheduled"?{every:ee}:void 0),F(""),_(""),Q([]),z(""),Z("standard"),ie("4h"),P(!1),$e()}catch(Pe){Mt(`Error creating task: ${Pe}`)}},wn=()=>{$e(),je&&setTimeout(()=>{const ne={};o==="project"&&u&&(ne.projectId=u),ae.tasks.board(ne).then(Oe=>{const et=Object.values(Oe.board).flat().find(re=>re.id===je.id);ke(et||null)}).catch(()=>{})},150)},qn=async()=>{if(_t.trim()){if(!ue){Mt("Please select a project for this requirement");return}try{await ae.requirements.create({title:_t,description:xe,priority:gt,projectId:ue}),Mt("Requirement created"),wt(""),Be(""),Ht(!1),Ue()}catch(ne){Mt(`Error: ${ne}`)}}},ve=async ne=>{try{await ae.requirements.approve(ne),Mt("Requirement approved"),Ue(),$e()}catch(Oe){Mt(`Error: ${Oe}`)}},Qe=async()=>{if(Ke)try{await ae.requirements.reject(Ke,rn),Mt("Requirement rejected"),At(null),vn(""),Ue()}catch(ne){Mt(`Error: ${ne}`)}},Nt=async ne=>{try{await ae.requirements.delete(ne),Mt("Requirement cancelled"),Ue()}catch(Oe){Mt(`Error: ${Oe}`)}},Et=(ne,Oe)=>{Xe.current=Oe,rt.current=null,ne.dataTransfer.effectAllowed="move",ne.dataTransfer.setData("text/plain",`task:${Oe.id}`),ne.currentTarget.style.opacity="0.4"},Nn=(ne,Oe)=>{rt.current=Oe,Xe.current=null,ne.dataTransfer.effectAllowed="move",ne.dataTransfer.setData("text/plain",`req:${Oe.id}`),ne.currentTarget.style.opacity="0.4"},ar=ne=>{ne.currentTarget.style.opacity="1",Xe.current=null,rt.current=null,_e(null)},ir=(ne,Oe)=>{ne.preventDefault(),ne.dataTransfer.dropEffect="move",le!==Oe&&_e(Oe)},Or=(ne,Oe)=>{const Pe=ne.currentTarget.getBoundingClientRect(),{clientX:et,clientY:re}=ne;(et<Pe.left||et>Pe.right||re<Pe.top||re>Pe.bottom)&&le===Oe&&_e(null)},Rr=async(ne,Oe)=>{ne.preventDefault(),_e(null);const Pe=Xe.current,et=rt.current;if(Pe){const re=To.find(Ne=>Ne.id===Oe);if(!re)return;const pe=re.dropStatus;if(Pe.status===pe||Pe.status==="pending_approval")return;try{await ae.tasks.updateStatus(Pe.id,pe),$e()}catch{}}else if(et){const re=cN[Oe];if(!re||et.status===re)return;try{await ae.requirements.updateStatus(et.id,re),Ue()}catch{}}},vr=ne=>{Ze(Oe=>{const Pe=new Set(Oe);return Pe.has(ne)?Pe.delete(ne):Pe.add(ne),Pe})},un=ne=>{We(Oe=>{const Pe=new Set(Oe);return Pe.has(ne)?Pe.delete(ne):Pe.add(ne),Pe})},zr=1440*60*1e3,Ps=Date.now(),lr=ne=>ne.status==="completed"&&ne.updatedAt&&Ps-new Date(ne.updatedAt).getTime()>zr,or=(ne,Oe=!1)=>{let Pe=ne.filter(et=>Ft||Oe||!lr(et));return o==="project"&&u&&(Pe=Pe.filter(et=>et.projectId===u)),Ae.size>0&&(Pe=Pe.filter(et=>et.projectId&&Ae.has(et.projectId))),ze.size>0&&(Pe=Pe.filter(et=>et.assignedAgentId&&ze.has(et.assignedAgentId))),Pe},Us=ne=>ne.statuses.flatMap(Oe=>or(m[Oe]??[])),Tn=j.useMemo(()=>{let ne=w;return o==="project"&&u&&(ne=ne.filter(Oe=>Oe.projectId===u)),Ae.size>0&&(ne=ne.filter(Oe=>Oe.projectId&&Ae.has(Oe.projectId))),ze.size>0&&(ne=ne.filter(Oe=>ze.has(Oe.createdBy))),ne},[w,o,u,Ae,ze]),Gr=j.useCallback(ne=>Tn.filter(Oe=>oN[Oe.status]===ne.id),[Tn]),Sa=To.filter(ne=>{if(ne.id==="failed"||ne.id==="closed"){const Oe=Us(ne),Pe=Gr(ne);return Oe.length+Pe.length>0}return!0}),cr=Object.values(m).flat().filter(ne=>lr(ne)).length,Lr=j.useMemo(()=>{const ne=new Set(["completed","failed","cancelled","archived"]),Oe=Object.values(m).flat(),Pe=new Set;for(const et of Oe)et.assignedAgentId&&!ne.has(et.status)&&(!u||et.projectId===u)&&Pe.add(et.assignedAgentId);return[...x].sort((et,re)=>{const pe=Pe.has(et.id)?0:1,Ne=Pe.has(re.id)?0:1;return pe-Ne})},[x,m,u]),Yn=j.useMemo(()=>{const ne=new Set(["completed","failed","cancelled","archived"]),Oe=Object.values(m).flat(),Pe=new Set;for(const et of Oe)et.projectId&&!ne.has(et.status)&&Pe.add(et.projectId);return[...s].sort((et,re)=>{const pe=Pe.has(et.id)?0:1,Ne=Pe.has(re.id)?0:1;return pe-Ne})},[s,m]),kn=j.useMemo(()=>{const ne={};for(const Oe of Object.values(m))for(const Pe of Oe){const et=Pe.projectId??"__none__";ne[et]=(ne[et]??0)+1}return ne},[m]),jr=Object.values(kn).reduce((ne,Oe)=>ne+Oe,0);return T?t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:"Loading…"}):t.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[C&&t.jsx("div",{className:"mx-6 mt-2 px-3 py-1.5 bg-green-500/15 text-green-600 text-xs rounded-lg",children:C}),r?t.jsxs("div",{className:"border-b border-border-default bg-surface-secondary/80 shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[oe?t.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[t.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:oe.name}),t.jsx("button",{onClick:()=>H(!k),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${k?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:s.length===1?s[0].name:`${s.length} Projects`}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>$(!0),className:"px-2 py-1 text-[11px] border border-border-default text-fg-secondary rounded-md",children:"+ Project"}),t.jsx("button",{onClick:M,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:"+ Req"}),t.jsx("button",{onClick:()=>{W(u??""),P(!0)},className:"px-2 py-1 text-[11px] border border-border-default text-fg-secondary rounded-md",children:"+ Task"})]})]}),t.jsxs("div",{className:"flex items-center gap-2 px-3 h-9 border-t border-border-default/40",children:[t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(ne=>t.jsx("button",{onClick:()=>Ct(ne),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${ht===ne?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:ne==="backlog"?"Backlog":ne==="kanban"?"Kanban":"DAG"},ne))}),cr>0&&t.jsx("button",{onClick:()=>be(ne=>!ne),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ft?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Ft?"Hide archived":`${cr} archived`}),t.jsx("div",{className:"flex-1"}),(Ae.size>0||ze.size>0||s.length>1||x.length>0)&&t.jsxs("button",{onClick:()=>Ve(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${Ae.size>0||ze.size>0?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),"Filter",Ae.size+ze.size>0?` (${Ae.size+ze.size})`:""]})]})]}):t.jsxs("div",{className:"flex items-center gap-3 px-6 h-14 border-b border-border-default bg-surface-secondary/80 shrink-0",children:[oe?t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(Xz,{value:oe.name,onSave:async ne=>{await ae.projects.update(oe.id,{name:ne}),Le()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:()=>H(!k),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${k?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:"Project settings",children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:s.length===1?s[0].name:`${s.length} Projects`}),cr>0&&t.jsx("button",{onClick:()=>be(ne=>!ne),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ft?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Ft?`Hide ${cr} archived`:`${cr} archived`}),t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(ne=>t.jsx("button",{onClick:()=>Ct(ne),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${ht===ne?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:ne==="backlog"?"Backlog":ne==="kanban"?"Kanban":"DAG"},ne))}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:M,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:"+ Requirement"}),t.jsx("button",{onClick:()=>{W(u??""),P(!0)},className:"px-3 py-1.5 border border-border-default hover:bg-surface-elevated text-fg-secondary text-xs rounded-lg font-medium transition-colors",children:"+ Task"})]}),t.jsx("div",{className:"flex-1"})]}),!r&&s.length>1&&!u&&!k&&(jr>0||w.length>0)&&t.jsxs("div",{className:"px-6 py-1.5 border-b border-border-default/60 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[t.jsx("button",{onClick:()=>We(new Set),className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${Ae.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),Yn.map(ne=>{const Oe=Ae.has(ne.id),Pe=kn[ne.id]??0;return t.jsxs("button",{onClick:()=>un(ne.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Oe?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${Oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:ne.name[0]?.toUpperCase()}),ne.name,Pe>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:Pe})]},ne.id)})]}),!r&&x.length>0&&!k&&(jr>0||w.length>0)&&t.jsxs("div",{className:"px-6 py-1.5 border-b border-border-default/60 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[t.jsx("button",{onClick:()=>Ze(new Set),className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${ze.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),Lr.map(ne=>{const Oe=ze.has(ne.id);return t.jsxs("button",{onClick:()=>vr(ne.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Oe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:ne.name[0]?.toUpperCase()}),ne.name]},ne.id)})]}),k&&oe?t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsx(iL,{project:oe,tasks:Object.values(m).flat(),requirements:w,agents:x,onDeleteProject:()=>on(oe.id),onUpdateProject:async ne=>{await ae.projects.update(oe.id,ne)},onRefresh:()=>{Le()}})}):jr===0&&Tn.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[t.jsx("div",{className:"w-10 h-10 mx-auto rounded-lg bg-surface-elevated flex items-center justify-center",children:t.jsx("span",{className:"text-fg-tertiary text-lg",children:"☐"})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:"No items yet"}),t.jsxs("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:["Create a requirement to tell agents what you need.",t.jsx("br",{}),"Once approved, tasks will appear here automatically."]}),t.jsx("button",{onClick:M,className:"text-xs text-brand-500 hover:text-brand-500 font-medium",children:"+ Create a requirement"})]})}):ht==="backlog"?t.jsx(fL,{tasks:or(Object.values(m).flat()),requirements:Tn,agents:x,projects:s,onTaskClick:ne=>ke(ne),onReqClick:ne=>Ie(ne),onRefresh:()=>{$e(),Ue()}}):ht==="dag"?t.jsx(Gz,{tasks:or(Object.values(m).flat(),!0),requirements:Tn,agents:x,showArchived:Ft,onShowArchivedChange:be,onTaskClick:ne=>ke(ne),onReqClick:ne=>Ie(ne),onDependencyChange:$e}):t.jsx("div",{className:"flex-1 min-h-0 overflow-x-auto overflow-y-hidden p-6",children:t.jsx("div",{className:"flex gap-4 h-full",children:Sa.map(ne=>{const Oe=Us(ne),Pe=Gr(ne),et=Oe.length+Pe.length,re=le===ne.id;return t.jsxs("div",{className:`w-72 shrink-0 rounded-xl p-3.5 border-t-2 transition-colors flex flex-col h-full ${ne.accent} ${re?"bg-surface-elevated/80 ring-1 ring-brand-500/40":"bg-surface-secondary"}`,onDragOver:pe=>ir(pe,ne.id),onDragLeave:pe=>Or(pe,ne.id),onDrop:pe=>{Rr(pe,ne.id)},children:[t.jsxs("div",{className:"flex justify-between items-center mb-3 shrink-0",children:[t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:ne.label}),t.jsx("span",{className:"text-xs bg-surface-elevated px-2 py-0.5 rounded-full",children:et})]}),t.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin",children:(()=>{const pe=[...Pe.map(Ne=>({kind:"req",data:Ne,time:new Date(Ne.updatedAt??Ne.createdAt).getTime()})),...Oe.map(Ne=>({kind:"task",data:Ne,time:new Date(Ne.updatedAt??Ne.createdAt??0).getTime()}))];return pe.sort((Ne,ye)=>ye.time-Ne.time),pe.map(Ne=>{if(Ne.kind==="req"){const ye=Ne.data,dt=$u[ye.status]??{label:ye.status,cls:"bg-gray-500/15 text-fg-secondary"},Fe=ye.source==="agent"&&(ye.status==="draft"||ye.status==="pending_review"),bt=o==="all"&&ye.projectId?s.find(tt=>tt.id===ye.projectId):null,it=el(ye.createdBy,x,b)??ye.createdBy.slice(0,10);return t.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:tt=>Nn(tt,ye),onDragEnd:ar,onClick:()=>Ie(ye),onKeyDown:tt=>tt.key==="Enter"&&Ie(ye),className:`bg-brand-500/[0.06] border rounded-lg p-3 border-l-[3px] border-l-purple-500 transition-colors cursor-grab active:cursor-grabbing ${Fe?"border-amber-500/40 ring-1 ring-amber-500/20":"border-brand-500/20"} hover:border-brand-400/50`,children:[t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx("span",{className:"text-[9px] font-bold text-brand-500 bg-brand-500/15 px-1.5 py-0.5 rounded shrink-0",children:"REQ"}),t.jsx("span",{className:"text-sm font-medium leading-snug truncate",children:ye.title})]}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${dt.cls}`,children:dt.label})]}),ye.description&&t.jsx("div",{className:"text-xs text-fg-tertiary mt-1 line-clamp-2",children:ye.description}),bt&&t.jsx("div",{className:"mt-1.5",children:t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[120px]",title:bt.name,children:bt.name})}),t.jsxs("div",{className:"flex items-center justify-between mt-2",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs text-fg-tertiary",children:ye.priority}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["by ",it]})]}),t.jsx("div",{className:"flex items-center gap-1.5",children:ye.taskIds.length>0&&t.jsxs("span",{className:"text-[10px] text-brand-500/60 bg-brand-500/10 px-1.5 py-0.5 rounded",children:[ye.taskIds.length," tasks"]})})]}),Fe&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-brand-500/10",children:[t.jsx("button",{onClick:tt=>{tt.stopPropagation(),ve(ye.id)},className:"px-2.5 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:"Approve"}),t.jsx("button",{onClick:tt=>{tt.stopPropagation(),At(ye.id)},className:"px-2.5 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:"Reject"})]})]},`req-${ye.id}`)}else{const ye=Ne.data,dt=ye.subtasks?.length??0,He=iN[ye.status],Fe=ye.status==="pending_approval",bt=ye.taskType==="scheduled"&&!!ye.scheduleConfig,it=bt?ye.scheduleConfig.every?`Every ${ye.scheduleConfig.every}`:ye.scheduleConfig.cron?"Cron":"Scheduled":null,tt=o==="all"&&ye.projectId?s.find(hn=>hn.id===ye.projectId)?.name:null,Xt=ye.requirementId?w.find(hn=>hn.id===ye.requirementId)?.title:null,Zt=ye.createdBy?el(ye.createdBy,x,b)??ye.createdBy:null;return t.jsxs("div",{role:"button",tabIndex:0,"aria-label":ye.title,draggable:!Fe,onDragStart:hn=>!Fe&&Et(hn,ye),onDragEnd:ar,onClick:()=>ke(ye),onKeyDown:hn=>hn.key==="Enter"&&ke(ye),className:`border rounded-lg p-3 border-l-[3px] transition-colors ${Fe?"bg-amber-500/[0.04] border-amber-500/30 border-l-amber-500 cursor-pointer":bt?`bg-blue-500/[0.03] border-blue-500/20 ${_m[ye.priority]??""} hover:border-blue-500/40 cursor-pointer`:`bg-surface-elevated border-border-default ${_m[ye.priority]??""} hover:border-brand-500/50 cursor-grab active:cursor-grabbing`}`,children:[t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[bt&&t.jsx("span",{className:"text-blue-600 shrink-0",title:it??"Scheduled",children:t.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})}),t.jsx("div",{className:"text-sm font-medium leading-snug truncate",children:ye.title})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[bt&&it&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-600 whitespace-nowrap",children:it}),He&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${He.cls}`,children:He.label})]})]}),ye.description&&t.jsx("div",{className:"text-xs text-fg-tertiary mt-1 line-clamp-2",children:ye.description}),(tt||Xt)&&t.jsxs("div",{className:"mt-1.5 flex flex-wrap gap-1",children:[tt&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[100px]",title:tt,children:tt}),Xt&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-brand-500/10 text-brand-500 rounded truncate max-w-[120px]",title:Xt,children:["# ",Xt]})]}),ye.blockedBy&&ye.blockedBy.length>0&&t.jsx("div",{className:"mt-1.5 flex items-center gap-1",children:t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded",children:["⏳ ",ye.blockedBy.length," dep",ye.blockedBy.length>1?"s":""]})}),t.jsxs("div",{className:"flex items-center justify-between mt-2",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs text-fg-tertiary",children:ye.priority}),Zt&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",title:`Created by ${Zt}`,children:["by ",Zt]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[dt>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary bg-surface-overlay/50 px-1.5 py-0.5 rounded",children:["⋮ ",dt]}),ye.notes&&ye.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",ye.notes.length]}),ye.assignedAgentId&&t.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/10 px-1.5 py-0.5 rounded flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${lN[x.find(hn=>hn.id===ye.assignedAgentId)?.status??""]??"bg-gray-500"}`}),x.find(hn=>hn.id===ye.assignedAgentId)?.name??ye.assignedAgentId.slice(0,8)]})]})]})]},ye.id)}})})()}),re&&t.jsx("div",{className:"mt-2 border-2 border-dashed border-brand-500/30 rounded-lg h-12 flex items-center justify-center shrink-0",children:t.jsx("span",{className:"text-xs text-brand-500/60",children:"Drop here"})})]},ne.id)})})})]}),Y&&t.jsx(aN,{orgId:e?.orgId,onCreated:On,onClose:()=>$(!1)}),X&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>P(!1),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${r?"w-full":"w-[28rem]"}`,onClick:ne=>ne.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:"New Task"}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Project"}),t.jsxs("select",{value:L,onChange:ne=>W(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"No Project"}),s.map(ne=>t.jsx("option",{value:ne.id,children:ne.name},ne.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Requirement"}),t.jsxs("select",{value:R,onChange:ne=>z(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select a requirement…"}),w.filter(ne=>ne.status==="approved"&&(!L||ne.projectId===L)).map(ne=>t.jsx("option",{value:ne.id,children:ne.title},ne.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{autoFocus:!r,value:q,onChange:ne=>F(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&cn()},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:D,onChange:ne=>_(ne.target.value),rows:2,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Priority"}),t.jsxs("select",{value:I,onChange:ne=>A(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:"Low"}),t.jsx("option",{value:"medium",children:"Medium"}),t.jsx("option",{value:"high",children:"High"}),t.jsx("option",{value:"urgent",children:"Urgent"})]})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:["Assign to ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsxs("select",{value:G,onChange:ne=>U(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select agent…"}),x.map(ne=>t.jsx("option",{value:ne.id,children:ne.name},ne.id))]})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:["Reviewer ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsxs("select",{value:K,onChange:ne=>B(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select reviewer…"}),x.filter(ne=>ne.id!==G).map(ne=>t.jsx("option",{value:ne.id,children:ne.name},ne.id))]})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Task Type"}),t.jsxs("select",{value:te,onChange:ne=>Z(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"standard",children:"Standard"}),t.jsx("option",{value:"scheduled",children:"Scheduled (recurring)"})]})]}),te==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Frequency"}),t.jsxs("select",{value:ee,onChange:ne=>ie(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"30m",children:"Every 30 min"}),t.jsx("option",{value:"1h",children:"Every 1 hour"}),t.jsx("option",{value:"2h",children:"Every 2 hours"}),t.jsx("option",{value:"4h",children:"Every 4 hours"}),t.jsx("option",{value:"8h",children:"Every 8 hours"}),t.jsx("option",{value:"12h",children:"Every 12 hours"}),t.jsx("option",{value:"1d",children:"Every day"}),t.jsx("option",{value:"1w",children:"Every week"})]})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Blocked By (dependencies)"}),t.jsxs("select",{value:"",onChange:ne=>{const Oe=ne.target.value;Oe&&!V.includes(Oe)&&Q([...V,Oe])},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select a task to depend on…"}),Object.values(m).flat().filter(ne=>ne.status!=="completed"&&ne.status!=="cancelled"&&!V.includes(ne.id)).map(ne=>t.jsx("option",{value:ne.id,children:ne.title},ne.id))]}),V.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:V.map(ne=>{const Oe=Object.values(m).flat().find(Pe=>Pe.id===ne);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:["⏳ ",Oe?Oe.title.slice(0,30):ne.slice(-8),t.jsx("button",{onClick:()=>Q(V.filter(Pe=>Pe!==ne)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},ne)})})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>P(!1),className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{onClick:()=>{cn()},disabled:!G||!K,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Create"})]})]})}),je&&t.jsx(aL,{task:je,agents:x,projects:s,requirements:w,allTasks:Object.values(m).flat(),users:b,onClose:()=>ke(null),onRefresh:wn,authUser:e}),It&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ht(!1),wt(""),Be("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${r?"w-full":"w-[28rem]"}`,onClick:ne=>ne.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:"New Requirement"}),t.jsx("p",{className:"text-xs text-fg-tertiary -mt-2",children:"Describe what you need. Agents will break approved requirements into tasks."}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Project"}),t.jsxs("select",{value:ue,onChange:ne=>Se(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select a project…"}),s.map(ne=>t.jsx("option",{value:ne.id,children:ne.name},ne.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{value:_t,onChange:ne=>wt(ne.target.value),placeholder:"e.g. Add user authentication",className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!r,onKeyDown:ne=>{ne.key==="Enter"&&_t.trim()&&qn()}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:xe,onChange:ne=>Be(ne.target.value),placeholder:"What is needed and why...",rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Priority"}),t.jsxs("select",{value:gt,onChange:ne=>pt(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:"Low"}),t.jsx("option",{value:"medium",children:"Medium"}),t.jsx("option",{value:"high",children:"High"}),t.jsx("option",{value:"urgent",children:"Urgent"})]})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{Ht(!1),wt(""),Be("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{onClick:()=>{qn()},className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Create"})]})]})}),Ke&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>At(null),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${r?"w-full":"w-96"}`,onClick:ne=>ne.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:"Reject Requirement"}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Reason"}),t.jsx("textarea",{value:rn,onChange:ne=>vn(ne.target.value),placeholder:"Why is this being rejected...",rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!r})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>At(null),className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{onClick:()=>{Qe()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:"Reject"})]})]})}),De&&t.jsx(hL,{req:De,agents:x,projects:s,allTasks:Object.values(m).flat(),users:b,onClose:()=>Ie(null),onApprove:ne=>{ve(ne),Ie(null)},onReject:ne=>{At(ne),Ie(null)},onCancel:ne=>{Nt(ne),Ie(null)},onStatusChange:async(ne,Oe)=>{try{await ae.requirements.updateStatus(ne,Oe),Mt(`Requirement status → ${Oe}`),Ue(),$e()}catch(Pe){Mt(`Error: ${Pe}`)}}}),Me&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Ve(!1),children:[t.jsx("div",{className:"absolute inset-0 bg-black/50"}),t.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:ne=>ne.stopPropagation(),children:[t.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:"Filters"}),t.jsxs("div",{className:"flex items-center gap-2",children:[(Ae.size>0||ze.size>0)&&t.jsx("button",{onClick:()=>{We(new Set),Ze(new Set)},className:"text-[11px] text-brand-500 font-medium",children:"Clear all"}),t.jsx("button",{onClick:()=>Ve(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),s.length>1&&t.jsxs("div",{className:"px-4 py-3",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:"Projects"}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Yn.map(ne=>{const Oe=Ae.has(ne.id),Pe=kn[ne.id]??0;return t.jsxs("button",{onClick:()=>un(ne.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Oe?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${Oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:ne.name[0]?.toUpperCase()}),ne.name,Pe>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Pe})]},ne.id)})})]}),x.length>0&&t.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:"Agents"}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Lr.map(ne=>{const Oe=ze.has(ne.id);return t.jsxs("button",{onClick:()=>vr(ne.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Oe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:ne.name[0]?.toUpperCase()}),ne.name]},ne.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function hL({req:e,agents:r,projects:s,allTasks:i,users:o,onClose:c,onApprove:u,onReject:f,onCancel:m,onStatusChange:h}){const x=gs(),g=$u[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},b=e.source==="agent",p=b&&(e.status==="draft"||e.status==="pending_review"),w=e.status==="draft"||e.status==="approved",S=e.status==="completed"||e.status==="rejected"||e.status==="cancelled",T=e.projectId?s.find(N=>N.id===e.projectId):null,E=el(e.createdBy,r,o)??e.createdBy.slice(0,12),C=i.filter(N=>e.taskIds.includes(N.id));return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:c,children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl max-h-[85dvh] flex flex-col ${x?"w-full":"w-[36rem]"}`,onClick:N=>N.stopPropagation(),children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded",children:"REQ"}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${g.cls}`,children:g.label}),e.priority==="high"||e.priority==="urgent"?t.jsx("span",{className:`text-[10px] font-medium ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:e.priority}):t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:e.priority})]}),t.jsx("h2",{className:"text-lg font-semibold text-fg-primary leading-snug",children:e.title})]}),t.jsx("button",{onClick:c,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-4",children:[e.description&&t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:"Description"}),t.jsx(er,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:"Created by"}),t.jsx("span",{className:"text-fg-secondary",children:E}),b&&t.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:"(Agent)"})]}),t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:"Created"}),t.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),T&&t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:"Project"}),t.jsx("span",{className:"text-fg-secondary",children:T.name})]}),e.approvedBy&&t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:"Approved by"}),t.jsx("span",{className:"text-fg-secondary",children:el(e.approvedBy,r,o)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:"Rejection Reason"}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.tags&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(N=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",N]},N))}),C.length>0&&t.jsxs("div",{children:[t.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:["Linked Tasks (",C.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:C.map(N=>{const k=iN[N.status];return t.jsxs("div",{className:"flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${_m[N.priority]?.replace("border-l-","bg-")??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:N.title}),k&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${k.cls}`,children:k.label})]},N.id)})})]})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[p&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>u(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:"Approve"}),t.jsx("button",{onClick:()=>f(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:"Reject"})]}),!p&&h&&!S&&t.jsx("select",{value:e.status,onChange:N=>{N.target.value!==e.status&&h(e.id,N.target.value)},className:"px-2 py-1.5 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-secondary cursor-pointer hover:border-gray-500 transition-colors",children:uN.map(N=>{const k=$u[N];return t.jsx("option",{value:N,children:k?.label??N},N)})}),S&&h&&t.jsx("button",{onClick:()=>h(e.id,"approved"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:"Reopen"}),t.jsx("div",{className:"flex-1"}),w&&!p&&t.jsx("button",{onClick:()=>m(e.id),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:"Cancel Requirement"})]})]})})}function mL({status:e}){const r={active:"bg-green-500/10 text-green-600",planning:"bg-blue-500/10 text-blue-600",review:"bg-amber-500/10 text-amber-600",completed:"bg-surface-overlay text-fg-secondary",archived:"bg-surface-elevated text-fg-tertiary",paused:"bg-amber-500/10 text-amber-600"};return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${r[e]??"bg-surface-overlay text-fg-secondary"}`,children:e})}function os(e){return Array.isArray(e)?e.map(r=>String(r).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(r=>r.trim()).filter(Boolean):[]}function xL(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function Fa({label:e,value:r}){return r?t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:r})]}):null}function Li({label:e,value:r,color:s}){if(!r)return null;const i={purple:"bg-brand-500/15 text-brand-500",cyan:"bg-blue-500/15 text-blue-600",indigo:"bg-brand-500/15 text-brand-500",gray:"bg-gray-500/15 text-fg-secondary",emerald:"bg-green-500/15 text-green-600"};return t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${i[s]??i.gray} capitalize inline-block`,children:r})]})}function Gh({files:e}){const[r,s]=j.useState(Object.keys(e)[0]??""),i=Object.keys(e);return i.length===0?null:t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Files (",i.length,")"]}),t.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[t.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:i.map(o=>t.jsx("button",{onClick:()=>s(o),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${r===o?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:o},o))}),r&&e[r]!=null&&t.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[r]})]})]})}function gL({artifact:e,mode:r}){const s=xL(e),i=e.agent,o=e.team,c=e.dependencies,u=e.displayName??e.name;if(r==="agent"){const f=i?.roleName,m=i?.agentRole,h=i?.llmProvider,x=i?.llmModel,g=os(c?.env),b=os(c?.skills);return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Fa,{label:"Name",value:u}),t.jsx(Fa,{label:"Description",value:e.description}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(Li,{label:"Role Template",value:f,color:"indigo"}),t.jsx(Li,{label:"Agent Role",value:m,color:m==="manager"?"purple":"cyan"})]}),os(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:os(e.tags).map(p=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:p},p))}),(h||x)&&t.jsxs("div",{className:"flex gap-2",children:[h&&t.jsx(Li,{label:"LLM Provider",value:h,color:"gray"}),x&&t.jsx(Li,{label:"LLM Model",value:x,color:"gray"})]}),g.length>0&&t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:"Required Env"}),t.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:g.map(p=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/10 text-amber-600 rounded font-mono",children:p},p))})]}),b.length>0&&t.jsx(Fa,{label:"Skills",value:b.join(", ")}),s&&t.jsx(Gh,{files:s})]})}if(r==="team"){const m=o?.members??[];return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Fa,{label:"Name",value:u}),t.jsx(Fa,{label:"Description",value:e.description}),t.jsx("div",{className:"flex flex-wrap gap-2",children:t.jsx(Li,{label:"Category",value:e.category,color:"indigo"})}),os(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:os(e.tags).map(h=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:h},h))}),s&&t.jsx(Gh,{files:s}),t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Members (",m.length,")"]}),t.jsx("div",{className:"mt-1.5 space-y-1.5",children:m.map((h,x)=>t.jsxs("div",{className:"bg-surface-elevated/30 rounded-lg px-2 py-1.5 border border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-5 h-5 rounded flex items-center justify-center text-[10px] font-bold ${h.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:h.role==="manager"?"★":x+1}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:h.name}),typeof h.roleName=="string"&&h.roleName&&t.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:h.roleName}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(h.count??1)]})]}),os(h.skills).length>0&&t.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:os(h.skills).map(g=>t.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:g},g))})]},x))})]})]})}return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Fa,{label:"Name",value:u}),t.jsx(Fa,{label:"Description",value:e.description}),t.jsx("div",{className:"flex gap-2",children:t.jsx(Li,{label:"Category",value:e.category,color:"indigo"})}),s&&t.jsx(Gh,{files:s}),os(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:os(e.tags).map(f=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:f},f))})]})}const to={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},zv={active:{label:"Active",color:"text-green-600 bg-green-500/10"},verified:{label:"Verified",color:"text-blue-600 bg-blue-500/10"},outdated:{label:"Outdated",color:"text-red-500 bg-red-500/10"}},Lv=["file","directory"],cs={agent:{icon:"✦",label:"Agent",color:"bg-brand-500/10 text-brand-500"},team:{icon:"◈",label:"Team",color:"bg-blue-500/10 text-blue-600"},skill:{icon:"⬡",label:"Skill",color:"bg-amber-500/10 text-amber-600"}};function Iv(){const e=gs(),r=ex({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[s,i]=j.useState(!1),o=j.useRef(s);o.current=s,j.useEffect(()=>{if(!e)return;const ve=()=>{o.current&&i(!1)};return window.addEventListener("popstate",ve),()=>window.removeEventListener("popstate",ve)},[e]);const c=100,[u,f]=j.useState([]),[m,h]=j.useState(0),[x,g]=j.useState(!1),[b,p]=j.useState([]),[w,S]=j.useState([]),[T,E]=j.useState(!0),[C,N]=j.useState(""),[k,H]=j.useState(""),[M,Y]=j.useState(""),[$,X]=j.useState(""),[P,q]=j.useState(""),[F,D]=j.useState(""),[_,I]=j.useState(""),[A,G]=j.useState("date"),[U,K]=j.useState(null),[B,L]=j.useState(null),[W,R]=j.useState(""),[z,V]=j.useState(!1),[Q,te]=j.useState(!1),[Z,ee]=j.useState(new Set),ie=j.useRef(null),[je,ke]=j.useState("file"),[De,Ie]=j.useState(""),[ze,Ze]=j.useState(""),[Ae,We]=j.useState(""),[xt,Lt]=j.useState(""),[le,_e]=j.useState(""),[ht,Ct]=j.useState(null),[Ft,be]=j.useState(null),[Me,Ve]=j.useState(!1),[Xe,rt]=j.useState(!1),[It,Ht]=j.useState(!1),[_t,wt]=j.useState(!1),xe=j.useRef(null),Be=j.useRef(null),[gt,pt]=j.useState(""),ue=j.useRef(void 0),Se=(ve,Qe)=>{L({type:ve,text:Qe}),setTimeout(()=>L(null),3e3)},Ke=async ve=>{try{return await navigator.clipboard.writeText(ve),!0}catch{try{const Qe=document.createElement("textarea");Qe.value=ve,Qe.style.cssText="position:fixed;left:-9999px;top:-9999px;opacity:0",document.body.appendChild(Qe),Qe.select();const Nt=document.execCommand("copy");return document.body.removeChild(Qe),Nt}catch{return!1}}},At=async ve=>{await Ke(ve)?(wt(!0),setTimeout(()=>wt(!1),1500)):Se("error","Copy failed — try long-pressing to copy manually")},rn=j.useMemo(()=>new Map(w.map(ve=>[ve.id,ve])),[w]),vn=j.useMemo(()=>new Map(b.map(ve=>[ve.id,ve])),[b]);j.useEffect(()=>{ae.projects.list().then(ve=>p(ve.projects)).catch(()=>{}),ae.agents.list().then(ve=>S(ve.agents??[])).catch(()=>{}),ae.system.storage().then(ve=>pt(ve.dataDir+"/shared")).catch(()=>{})},[]),j.useEffect(()=>(ue.current=setTimeout(()=>H(C),300),()=>clearTimeout(ue.current)),[C]);const Mt=j.useMemo(()=>({q:k||void 0,projectId:$||void 0,agentId:P||void 0,type:M||void 0,status:F||void 0,artifactType:_||void 0}),[k,$,P,M,F,_]),oe=j.useCallback(async()=>{E(!0);try{const{results:ve,total:Qe}=await ae.deliverables.search({...Mt,offset:0,limit:c});f(ve),h(Qe)}catch{f([]),h(0)}E(!1)},[Mt]),Le=j.useCallback(async()=>{if(!(x||u.length>=m)){g(!0);try{const{results:ve,total:Qe}=await ae.deliverables.search({...Mt,offset:u.length,limit:c});f(Nt=>[...Nt,...ve]),h(Qe)}catch{}g(!1)}},[Mt,u.length,m,x]);j.useEffect(()=>{oe()},[oe]),j.useEffect(()=>En.on("deliverable:created",()=>oe()),[oe]);const $e=j.useCallback(()=>{const ve=ie.current;!ve||T||x||u.length>=m||ve.scrollHeight<=ve.clientHeight+100&&Le()},[T,x,u.length,m,Le]);j.useEffect(()=>{const ve=ie.current;if(!ve)return;const Qe=()=>{ve.scrollTop+ve.clientHeight>=ve.scrollHeight-100&&Le()};return ve.addEventListener("scroll",Qe,{passive:!0}),()=>ve.removeEventListener("scroll",Qe)},[Le]),j.useEffect(()=>{$e()},[$e,Z]);const st=j.useMemo(()=>{const ve=new Map;for(const Nt of u){let Et,Nn;if(A==="project")Et=Nt.projectId??"_none",Nn=Nt.projectId?vn.get(Nt.projectId)?.name??Nt.projectId:"No Project";else if(A==="agent")Et=Nt.agentId??"_none",Nn=Nt.agentId?rn.get(Nt.agentId)?.name??Nt.agentId:"Unknown";else if(A==="type")Et=Nt.type,Nn=Nt.type.charAt(0).toUpperCase()+Nt.type.slice(1);else{const ar=new Date(Nt.updatedAt);Et=`${ar.getFullYear()}-${String(ar.getMonth()+1).padStart(2,"0")}-${String(ar.getDate()).padStart(2,"0")}`,Nn=Et}ve.has(Et)||ve.set(Et,{label:Nn,items:[]}),ve.get(Et).items.push(Nt)}const Qe=[...ve.entries()];return A==="date"?Qe.sort((Nt,Et)=>Et[0].localeCompare(Nt[0])):Qe.sort((Nt,Et)=>Nt[1].label.localeCompare(Et[1].label)),Qe},[u,A,vn,rn]),at=async()=>{if(!(!De.trim()||!ze.trim())){te(!0);try{await ae.deliverables.create({type:je,title:De,summary:ze,reference:Ae,projectId:xt||void 0,tags:le.split(",").map(ve=>ve.trim()).filter(Boolean)}),V(!1),Se("success","Deliverable created"),oe()}catch(ve){Se("error",`Error: ${ve}`)}te(!1)}},Ue=async ve=>{R("verify");try{await ae.deliverables.verify(ve.id),Se("success","Verified"),K({...ve,status:"verified"}),oe()}catch(Qe){Se("error",`Error: ${Qe}`)}R("")},jn=async ve=>{R("flag");try{await ae.deliverables.update(ve.id,{status:"outdated"}),Se("success","Flagged as outdated"),K({...ve,status:"outdated"}),oe()}catch(Qe){Se("error",`Error: ${Qe}`)}R("")},gn=async ve=>{R("remove");try{await ae.deliverables.remove(ve.id),Se("success","Removed"),K(null),oe()}catch(Qe){Se("error",`Error: ${Qe}`)}R("")},Dt=()=>{Ut.navigate("builder")},Dn=async ve=>{if(ve.reference){if(ve.type==="directory"){rt(!0);return}Ve(!0);try{const Qe=await ae.files.preview(ve.reference);Qe.type==="image"&&Qe.mimeType?be({src:`data:${Qe.mimeType};base64,${Qe.content}`,name:Qe.name}):Ct(Qe.content)}catch{Ct(null),ve.type==="file"&&rt(!0)}Ve(!1)}};j.useEffect(()=>{Ct(null),be(null),rt(!1),Ht(!1),U&&Dn(U)},[U?.id]),j.useEffect(()=>{if(!It)return;const ve=Qe=>{Be.current&&!Be.current.contains(Qe.target)&&Ht(!1)};return document.addEventListener("mousedown",ve),()=>document.removeEventListener("mousedown",ve)},[It]);const Un=async(ve,Qe)=>{const Nt=xe.current?.firstElementChild;if(!Nt)return;const Et=pL(Nt,ve);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([Et],{type:"text/html"}),"text/plain":new Blob([Qe],{type:"text/plain"})})]),Se("success",ve==="light"?"HTML (light) copied":"HTML (dark) copied")}catch{const Nn=await Ke(Qe);Se(Nn?"success":"error",Nn?"Text copied (HTML not supported)":"Copy failed")}Ht(!1)},On=ve=>t.jsxs("div",{className:"relative group/preview",children:[t.jsxs("div",{className:"absolute -top-1 -right-1 z-10",ref:Be,children:[t.jsx("button",{onClick:()=>Ht(Qe=>!Qe),className:"p-1.5 rounded-lg bg-surface-elevated/80 hover:bg-surface-overlay text-fg-secondary hover:text-fg-primary backdrop-blur-sm border border-border-default/50 transition-all",title:"Copy content",children:t.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),It&&t.jsxs("div",{className:"absolute right-0 top-full mt-1 bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 min-w-[180px]",children:[t.jsxs("button",{onClick:async()=>{const Qe=await Ke(ve);Se(Qe?"success":"error",Qe?"Markdown source copied":"Copy failed"),Ht(!1)},className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[t.jsx("span",{className:"w-4 text-center text-fg-tertiary shrink-0 font-mono text-[10px]",children:"Md"}),"Copy Markdown Source"]}),t.jsxs("button",{onClick:()=>Un("light",ve),className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[t.jsx("span",{className:"w-4 text-center shrink-0",children:"☀️"}),"Copy HTML (Light)"]}),t.jsxs("button",{onClick:()=>Un("dark",ve),className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[t.jsx("span",{className:"w-4 text-center shrink-0",children:"🌙"}),"Copy HTML (Dark)"]})]})]}),t.jsx("div",{ref:xe,children:t.jsx(er,{content:ve,className:"text-fg-secondary text-sm"})})]}),on=j.useCallback(ve=>{ee(Qe=>{const Nt=new Set(Qe);return Nt.has(ve)?Nt.delete(ve):Nt.add(ve),Nt})},[]),cn=j.useCallback(()=>{Z.size===st.length?ee(new Set):ee(new Set(st.map(([ve])=>ve)))},[Z.size,st]),wn=()=>{Ie(""),Ze(""),We(""),_e(""),ke("file"),b.length>0&&Lt(b[0].id),V(!0)},qn=ve=>{K(ve),e&&(i(!0),history.pushState({mobileDetail:"deliverables"},"",window.location.hash))};return t.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[(!e||!s)&&t.jsxs("div",{className:`${e?"flex-1 min-w-0":"shrink-0"} border-r border-border-default flex flex-col bg-surface-primary`,style:e?void 0:{width:r.width},children:[t.jsxs("div",{className:"p-4 border-b border-border-default space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary",children:["Deliverables",m>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",m,")"]})]}),t.jsx("button",{onClick:wn,className:"text-xs px-2.5 py-1 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create"})]}),t.jsx("input",{value:C,onChange:ve=>N(ve.target.value),placeholder:"Search deliverables...",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors"}),gt&&t.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 bg-surface-elevated/50 border border-border-default rounded-lg text-[10px] text-fg-tertiary",children:[t.jsx("span",{className:"truncate font-mono",children:gt}),t.jsx("button",{onClick:()=>{ae.system.openPath(gt)},className:"shrink-0 underline hover:text-fg-secondary transition-colors",children:"Open"})]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(ba,{label:"All types",value:"",current:M||_||"",onClick:()=>{Y(""),I("")}}),Lv.map(ve=>t.jsx(ba,{label:`${to[ve]?.icon??""} ${ve}`,value:ve,current:M,onClick:Qe=>{Y(Qe),I("")}},ve)),["agent","team","skill"].map(ve=>t.jsx(ba,{label:`${cs[ve].icon} ${cs[ve].label}`,value:ve,current:_,onClick:Qe=>{I(Qe),Y("")}},ve))]}),b.length>0&&t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(ba,{label:"All projects",value:"",current:$,onClick:X}),b.map(ve=>t.jsx(ba,{label:ve.name,value:ve.id,current:$,onClick:X},ve.id))]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(ba,{label:"Active",value:"",current:F,onClick:D}),t.jsx(ba,{label:"Verified",value:"verified",current:F,onClick:D}),t.jsx(ba,{label:"Outdated",value:"outdated",current:F,onClick:D})]}),t.jsxs("div",{className:"flex gap-1.5 items-center",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"Group:"}),["date","project","agent","type"].map(ve=>t.jsx("button",{onClick:()=>{G(ve),ee(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${A===ve?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:ve.charAt(0).toUpperCase()+ve.slice(1)},ve)),st.length>1&&t.jsx("button",{onClick:cn,className:"ml-auto px-1.5 py-1 rounded text-[10px] text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:Z.size===st.length?"Expand all":"Collapse all",children:Z.size===st.length?"▶ Expand":"▼ Collapse"})]})]}),B&&t.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${B.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:B.text}),t.jsxs("div",{ref:ie,className:"flex-1 overflow-y-auto p-2 space-y-1",children:[T?t.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(ve=>t.jsxs("div",{className:"animate-pulse space-y-2",children:[t.jsx("div",{className:"h-4 bg-surface-elevated rounded w-3/4"}),t.jsx("div",{className:"h-3 bg-surface-elevated rounded w-1/2"})]},ve))}):u.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[t.jsx("svg",{className:"w-12 h-12 text-fg-muted mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),t.jsx("p",{className:"text-sm text-fg-secondary",children:"No deliverables yet"}),t.jsx("p",{className:"text-xs text-fg-tertiary mt-1 mb-3",children:"Deliverables are created when tasks complete or manually"}),t.jsx("button",{onClick:wn,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create first"})]}):st.map(([ve,Qe])=>{const Nt=Z.has(ve);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>on(ve),className:"w-full flex items-center gap-1.5 px-2 py-1.5 rounded-md hover:bg-surface-elevated/50 transition-colors group/header",children:[t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform duration-200 shrink-0 ${Nt?"":"rotate-90"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),t.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider truncate",children:Qe.label}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Qe.items.length,")"]})]}),!Nt&&Qe.items.map(Et=>t.jsxs("button",{onClick:()=>qn(Et),className:`w-full text-left p-3 rounded-lg transition-colors ${U?.id===Et.id?"bg-brand-600/20 border border-brand-500/30":"hover:bg-surface-elevated/60 border border-transparent"}`,children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:Et.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[Et.artifactType&&cs[Et.artifactType]?t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${cs[Et.artifactType].color}`,children:[cs[Et.artifactType].icon," ",cs[Et.artifactType].label]}):t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium uppercase ${to[Et.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:Et.type}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${zv[Et.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:Et.status}),Et.agentId&&t.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:rn.get(Et.agentId)?.name??"Agent"})]})]},Et.id))]},ve)}),x&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[t.jsx(Xh,{})," ",t.jsx("span",{className:"text-[10px]",children:"Loading more..."})]}),!T&&u.length>0&&t.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:u.length<m?`${u.length} / ${m} deliverables`:`${m} deliverables`})]})]}),!e&&t.jsx("div",{className:"w-1 shrink-0 cursor-col-resize hover:bg-brand-500/30 active:bg-brand-500/50 transition-colors",onMouseDown:r.onResizeStart}),(!e||s)&&t.jsxs("div",{className:"flex-1 overflow-y-auto min-w-0",children:[e&&t.jsxs("div",{className:"sticky top-0 z-10 bg-surface-secondary border-b border-border-default px-4 py-2.5 flex items-center gap-2",children:[t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsx("span",{className:"text-sm font-medium truncate",children:U?.title??"Details"})]}),U?t.jsxs("div",{className:"p-6 space-y-5",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-xl font-semibold text-fg-primary",children:U.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[U.status!=="verified"&&t.jsx("button",{onClick:()=>Ue(U),disabled:!!W,className:"px-3 py-1.5 text-xs rounded-lg bg-green-600/20 text-green-600 hover:bg-green-600/30 disabled:opacity-50 transition-colors",children:W==="verify"?"Verifying...":"Verify"}),U.status!=="outdated"&&t.jsx("button",{onClick:()=>jn(U),disabled:!!W,className:"px-3 py-1.5 text-xs rounded-lg bg-amber-600/20 text-amber-600 hover:bg-amber-600/30 disabled:opacity-50 transition-colors",children:W==="flag"?"Flagging...":"Flag Outdated"}),t.jsx("button",{onClick:()=>gn(U),disabled:!!W,className:"px-3 py-1.5 text-xs rounded-lg bg-red-600/20 text-red-500 hover:bg-red-600/30 disabled:opacity-50 transition-colors",children:W==="remove"?"Removing...":"Remove"})]}),t.jsxs("div",{className:"flex items-center gap-3 mt-2 flex-wrap",children:[t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium uppercase ${to[U.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[to[U.type]?.icon??""," ",U.type]}),t.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${zv[U.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:U.status}),U.artifactType&&cs[U.artifactType]&&t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${cs[U.artifactType].color}`,children:[cs[U.artifactType].icon," Builder ",cs[U.artifactType].label]})]}),U.reference&&(U.type==="file"||U.type==="directory")&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 bg-surface-secondary/60 border border-border-default rounded-lg px-3 py-2",children:[t.jsx("button",{onClick:()=>{ae.files.reveal(U.reference).catch(()=>Se("error","Failed to open file browser"))},className:"text-xs font-mono text-brand-500 hover:text-brand-500 hover:underline truncate flex-1 text-left cursor-pointer",title:"Open in file browser",children:U.reference}),t.jsx("button",{onClick:()=>{ae.files.reveal(U.reference).catch(()=>Se("error","Failed to open file browser"))},className:"px-2 py-1 text-[10px] rounded bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",title:"Reveal in Finder",children:"Open"}),t.jsx("button",{onClick:()=>At(U.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${_t?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:"Copy path to clipboard",children:_t?"Copied!":"Copy"})]}),U.reference&&U.type!=="file"&&U.type!=="directory"&&t.jsx("div",{className:"mt-2",children:t.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:U.reference})})]}),U.artifactType&&U.artifactData?t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:t.jsx(gL,{artifact:U.artifactData,mode:U.artifactType})}),U.reference&&t.jsxs("div",{className:"px-3 py-2 bg-surface-secondary/50 border border-border-default rounded-lg",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider block mb-1",children:"Artifact Directory"}),t.jsx("span",{className:"text-xs text-fg-secondary font-mono break-all",children:U.reference})]}),t.jsx("div",{className:"flex gap-2",children:t.jsx("button",{onClick:Dt,className:"flex-1 px-4 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-colors",children:"Open in Builder"})}),U.summary&&t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:t.jsx(er,{content:U.summary,className:"text-fg-secondary text-sm"})})]}):t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:Me?t.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[t.jsx(Xh,{})," Loading preview..."]}):Ft?t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("img",{src:Ft.src,alt:Ft.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:Ft.name})]}):ht?On(ht):Xe?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("p",{className:"text-sm text-fg-secondary",children:["This ",U.type," cannot be previewed in the browser."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>{ae.files.reveal(U.reference).catch(()=>Se("error","Failed to open"))},className:"text-xs bg-surface-elevated px-3 py-2 rounded text-brand-500 hover:text-brand-500 hover:underline flex-1 truncate text-left cursor-pointer font-mono",title:"Open in file browser",children:U.reference}),t.jsx("button",{onClick:()=>{ae.files.reveal(U.reference).catch(()=>Se("error","Failed to open"))},className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",children:"Open"}),t.jsx("button",{onClick:()=>At(U.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${_t?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:_t?"Copied!":"Copy"})]})]}):U.summary?On(U.summary):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No content"})}),(U.diffStats||U.testResults)&&t.jsxs("div",{className:"flex gap-4 flex-wrap",children:[U.diffStats&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-lg px-4 py-3 text-xs space-y-1",children:[t.jsx("div",{className:"text-fg-tertiary font-medium",children:"Diff Stats"}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("span",{className:"text-fg-secondary",children:[U.diffStats.filesChanged," files"]}),t.jsxs("span",{className:"text-green-600",children:["+",U.diffStats.additions]}),t.jsxs("span",{className:"text-red-500",children:["-",U.diffStats.deletions]})]})]}),U.testResults&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-lg px-4 py-3 text-xs space-y-1",children:[t.jsx("div",{className:"text-fg-tertiary font-medium",children:"Tests"}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("span",{className:"text-green-600",children:[U.testResults.passed," passed"]}),t.jsxs("span",{className:"text-red-500",children:[U.testResults.failed," failed"]}),t.jsxs("span",{className:"text-fg-secondary",children:[U.testResults.skipped," skipped"]})]})]})]}),U.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5",children:U.tags.map(ve=>t.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:ve},ve))}),t.jsxs("div",{className:"border-t border-border-default pt-4 space-y-2",children:[t.jsx("div",{className:"text-xs text-fg-tertiary font-medium",children:"Links"}),t.jsxs("div",{className:"flex gap-3 flex-wrap",children:[U.taskId&&t.jsxs("button",{onClick:()=>Ut.navigate("projects",{openTask:U.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2.5 py-1 rounded",children:["Task: ",U.taskId.slice(0,12),"..."]}),U.agentId&&t.jsxs("button",{onClick:()=>Ut.navigate("team",{selectAgent:U.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Agent: ",rn.get(U.agentId)?.name??U.agentId.slice(0,12)]}),U.projectId&&t.jsxs("button",{onClick:()=>Ut.navigate("projects",{projectId:U.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Project: ",vn.get(U.projectId)?.name??U.projectId.slice(0,12)]})]})]}),t.jsxs("div",{className:"text-xs text-fg-tertiary space-y-1 border-t border-border-default pt-4",children:[t.jsxs("div",{className:"flex gap-6 flex-wrap",children:[t.jsxs("span",{children:["Created: ",t.jsx("span",{className:"text-fg-secondary",children:new Date(U.createdAt).toLocaleString()})]}),t.jsxs("span",{children:["Updated: ",t.jsx("span",{className:"text-fg-secondary",children:new Date(U.updatedAt).toLocaleString()})]}),t.jsxs("span",{children:["Accessed: ",t.jsxs("span",{className:"text-fg-secondary",children:[U.accessCount,"x"]})]})]}),t.jsxs("div",{className:"text-fg-muted select-all",children:["ID: ",U.id]})]})]}):t.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:t.jsxs("div",{className:"text-center text-fg-tertiary space-y-2",children:[t.jsx("svg",{className:"w-12 h-12 mx-auto text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),t.jsx("p",{className:"text-sm",children:"Select a deliverable to view details"})]})})]}),z&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!Q&&V(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:ve=>ve.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:"Create Deliverable"}),t.jsxs("div",{children:[t.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:"Type"}),t.jsx("select",{value:je,onChange:ve=>ke(ve.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:Lv.map(ve=>t.jsxs("option",{value:ve,children:[to[ve]?.icon??""," ",ve]},ve))})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:["Title ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("input",{value:De,onChange:ve=>Ie(ve.target.value),placeholder:"Clear, searchable title",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:["Reference ",t.jsx("span",{className:"text-fg-tertiary",children:"(file path, URL, branch name)"})]}),t.jsx("input",{value:Ae,onChange:ve=>We(ve.target.value),placeholder:"/path/to/file or https://...",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors font-mono"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:["Summary ",t.jsx("span",{className:"text-red-500",children:"*"})," ",t.jsx("span",{className:"text-fg-tertiary",children:"(Markdown)"})]}),t.jsx("textarea",{value:ze,onChange:ve=>Ze(ve.target.value),placeholder:"Describe the deliverable...",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary h-36 resize-none focus:border-brand-500 focus:outline-none transition-colors font-mono"})]}),t.jsxs("div",{className:"flex gap-4",children:[t.jsxs("div",{className:"flex-1",children:[t.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:["Tags ",t.jsx("span",{className:"text-fg-tertiary",children:"(comma separated)"})]}),t.jsx("input",{value:le,onChange:ve=>_e(ve.target.value),placeholder:"react, api, docs",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors"})]}),t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:"Project"}),t.jsxs("select",{value:xt,onChange:ve=>Lt(ve.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:[t.jsx("option",{value:"",children:"None"}),b.map(ve=>t.jsx("option",{value:ve.id,children:ve.name},ve.id))]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1 border-t border-border-default",children:[t.jsx("button",{onClick:()=>V(!1),disabled:Q,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:"Cancel"}),t.jsxs("button",{onClick:at,disabled:Q||!De.trim()||!ze.trim(),className:"bg-brand-600 hover:bg-brand-500 text-white text-sm px-4 py-2 rounded-lg disabled:opacity-50 flex items-center gap-2 transition-colors",children:[Q&&t.jsx(Xh,{}),Q?"Creating...":"Create"]})]})]})})]})}function pL(e,r){const s=e.cloneNode(!0),i=r==="light"?{bg:"#ffffff",text:"#24292f",heading:"#1f2328",strong:"#1f2328",link:"#0969da",codeBg:"#eff1f3",codeText:"#24292f",preBg:"#f6f8fa",preText:"#24292f",preBorder:"#d0d7de",border:"#d0d7de",blockquoteBorder:"#d0d7de",blockquoteText:"#656d76",tableBorder:"#d0d7de",tableHeaderBg:"#f6f8fa",tableHeaderText:"#24292f",hrColor:"#d8dee4"}:{bg:"#0d1117",text:"#e6edf3",heading:"#f0f6fc",strong:"#f0f6fc",link:"#58a6ff",codeBg:"#161b22",codeText:"#e6edf3",preBg:"#161b22",preText:"#e6edf3",preBorder:"#30363d",border:"#30363d",blockquoteBorder:"#3b82f6",blockquoteText:"#8b949e",tableBorder:"#30363d",tableHeaderBg:"#161b22",tableHeaderText:"#e6edf3",hrColor:"#21262d"},o={p:`margin:0 0 10px;color:${i.text};line-height:1.7;`,h1:`font-size:1.6em;font-weight:700;color:${i.heading};margin:20px 0 10px;line-height:1.3;border-bottom:1px solid ${i.border};padding-bottom:6px;`,h2:`font-size:1.35em;font-weight:700;color:${i.heading};margin:18px 0 8px;line-height:1.3;`,h3:`font-size:1.15em;font-weight:600;color:${i.heading};margin:14px 0 6px;line-height:1.3;`,h4:`font-size:1em;font-weight:600;color:${i.heading};margin:12px 0 4px;`,strong:`font-weight:600;color:${i.strong};`,em:"font-style:italic;",a:`color:${i.link};text-decoration:underline;`,ul:"padding-left:1.5em;margin:0 0 10px;",ol:"padding-left:1.5em;margin:0 0 10px;",li:`margin:3px 0;line-height:1.7;color:${i.text};`,blockquote:`border-left:3px solid ${i.blockquoteBorder};padding:2px 0 2px 14px;margin:10px 0;color:${i.blockquoteText};`,hr:`border:none;border-top:1px solid ${i.hrColor};margin:20px 0;`,table:"border-collapse:collapse;width:100%;margin:10px 0;",thead:`background:${i.tableHeaderBg};`,th:`border:1px solid ${i.tableBorder};padding:8px 12px;text-align:left;font-weight:600;color:${i.tableHeaderText};`,td:`border:1px solid ${i.tableBorder};padding:8px 12px;color:${i.text};`,img:"max-width:100%;height:auto;"};function c(u){u.removeAttribute("class");const f=u.tagName.toLowerCase();if(f==="pre"){u.setAttribute("style",`background:${i.preBg};color:${i.preText};padding:14px;border-radius:6px;overflow-x:auto;margin:10px 0;font-size:0.88em;line-height:1.5;border:1px solid ${i.preBorder};`);const m=u.querySelector("code");m&&(m.removeAttribute("class"),m.setAttribute("style","background:transparent;padding:0;border-radius:0;color:inherit;font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;font-size:inherit;"));return}f==="code"?u.setAttribute("style",`background:${i.codeBg};color:${i.codeText};padding:2px 6px;border-radius:4px;font-size:0.9em;font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;`):o[f]&&u.setAttribute("style",o[f]),Array.from(u.children).forEach(c)}return s.removeAttribute("class"),Array.from(s.children).forEach(u=>c(u)),`<div style="background:${i.bg};color:${i.text};padding:20px 24px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Noto Sans',Helvetica,Arial,sans-serif;font-size:15px;line-height:1.7;max-width:800px;">${s.innerHTML}</div>`}function ba({label:e,value:r,current:s,onClick:i}){return t.jsx("button",{onClick:()=>i(s===r?"":r),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${s===r?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function Xh(){return t.jsxs("svg",{className:"animate-spin h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function ya(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function pu(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function bL(e){return e>=1024*1024*1024?`${(e/(1024*1024*1024)).toFixed(1)} GB`:e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function dN(){const[e,r]=j.useState("weekly"),[s,i]=j.useState(null),[o,c]=j.useState(!0),[u,f]=j.useState(""),[m,h]=j.useState(null),[x,g]=j.useState([]),[b,p]=j.useState("totalTokens"),[w,S]=j.useState(!0),T=j.useCallback(async $=>{c(!0),f("");try{const{report:X}=await ae.reports.generate({period:$,scope:"org",orgId:"default"});i(X)}catch(X){f(String(X)),i(null)}c(!1)},[]),E=j.useCallback(()=>{ae.usage.summary().then($=>h($.usage)).catch(()=>{}),ae.usage.agents().then($=>g($.agents)).catch(()=>{})},[]);j.useEffect(()=>{T(e)},[e,T]),j.useEffect(()=>{E();const $=setInterval(E,3e4);return()=>clearInterval($)},[E]);const C=j.useMemo(()=>[...x].sort(($,X)=>{const P=$[b],q=X[b];return w?q-P:P-q}),[x,b,w]),N=x.reduce(($,X)=>$+X.estimatedCost,0),k=x.reduce(($,X)=>$+X.tokensUsedToday,0),H=Math.max(1,...x.map($=>$.totalTokens)),M=$=>{b===$?S(!w):(p($),S(!0))},Y={daily:"Today",weekly:"This Week",monthly:"This Month"};return t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsxs("div",{className:"max-w-5xl p-6 space-y-6",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h1",{className:"text-xl font-semibold text-fg-primary",children:"Reports"}),t.jsxs("select",{value:e,onChange:$=>r($.target.value),className:"bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary",children:[t.jsx("option",{value:"daily",children:"Daily"}),t.jsx("option",{value:"weekly",children:"Weekly"}),t.jsx("option",{value:"monthly",children:"Monthly"})]})]}),m&&t.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t.jsx(ou,{label:"LLM Tokens (this month)",value:ya(m.llmTokens),color:"text-brand-500"}),t.jsx(ou,{label:"Tool Calls (today)",value:ya(m.toolCalls),color:"text-blue-600"}),t.jsx(ou,{label:"Messages (today)",value:ya(m.messages),color:"text-green-600"}),t.jsx(ou,{label:"Storage",value:bL(m.storageBytes),color:"text-amber-600"})]}),o?t.jsx("div",{className:"flex items-center justify-center h-32 text-fg-tertiary text-sm",children:"Loading…"}):u?t.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:u}):s?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"text-xs text-fg-tertiary",children:[Y[e]," · ",new Date(s.periodStart).toLocaleDateString()," — ",new Date(s.periodEnd).toLocaleDateString()]}),s.metrics&&t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Task Metrics"}),t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[t.jsx(no,{label:"Completed",value:s.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(no,{label:"In Progress",value:s.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(no,{label:"Created",value:s.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(no,{label:"Blocked",value:s.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(no,{label:"Failed",value:s.metrics.tasksFailed,color:"text-red-500"})]})]}),t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Cost Overview"}),t.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:pu(N)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Est. Cost (all time)"})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:ya(k)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Tokens Today"})]}),s.costSummary&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:s.costSummary.totalTokens.toLocaleString()}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Tokens (",Y[e],")"]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:pu(s.costSummary.totalEstimatedCost)}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Cost (",Y[e],")"]})]})]})]})]}),s.taskSummary&&t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Task Summary"}),t.jsxs("div",{className:"space-y-4",children:[s.taskSummary.completed.length>0&&t.jsx(Zh,{title:`Completed (${s.taskSummary.completed.length})`,color:"emerald",items:s.taskSummary.completed.map($=>({label:$.title,sub:$.agent}))}),s.taskSummary.inProgress.length>0&&t.jsx(Zh,{title:`In Progress (${s.taskSummary.inProgress.length})`,color:"indigo",items:s.taskSummary.inProgress.map($=>({label:$.title,sub:$.agent}))}),s.taskSummary.blocked.length>0&&t.jsx(Zh,{title:`Blocked (${s.taskSummary.blocked.length})`,color:"amber",items:s.taskSummary.blocked.map($=>({label:$.title,sub:$.reason||$.agent}))}),s.taskSummary.completed.length===0&&s.taskSummary.inProgress.length===0&&s.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]})]}):null,t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden",children:[t.jsx("div",{className:"px-5 py-4 border-b border-border-default",children:t.jsx("h3",{className:"text-sm font-semibold text-fg-secondary",children:"Per-Agent Usage"})}),x.length===0?t.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:"No agent usage data yet."}):t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"border-b border-border-default text-xs text-fg-tertiary uppercase tracking-wider",children:[t.jsx("th",{className:"px-4 py-3 text-left font-medium",children:"Agent"}),t.jsx(ro,{label:"Total Tokens",col:"totalTokens",current:b,desc:w,onSort:M}),t.jsx(ro,{label:"Today",col:"tokensUsedToday",current:b,desc:w,onSort:M}),t.jsx(ro,{label:"Requests",col:"requestCount",current:b,desc:w,onSort:M}),t.jsx(ro,{label:"Tool Calls",col:"toolCalls",current:b,desc:w,onSort:M}),t.jsx(ro,{label:"Est. Cost",col:"estimatedCost",current:b,desc:w,onSort:M,align:"right"})]})}),t.jsx("tbody",{children:C.map($=>t.jsx(yL,{agent:$,maxTokens:H},$.agentId))}),t.jsx("tfoot",{children:t.jsxs("tr",{className:"border-t border-border-default bg-surface-elevated/30",children:[t.jsxs("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary",children:["Total (",x.length," agents)"]}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ya(x.reduce(($,X)=>$+X.totalTokens,0))}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ya(k)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:x.reduce(($,X)=>$+X.requestCount,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:x.reduce(($,X)=>$+X.toolCalls,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:pu(N)})]})})]})})]})]})})}function no({label:e,value:r,color:s}){return t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:`text-2xl font-bold ${s}`,children:r}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function Zh({title:e,color:r,items:s}){return t.jsxs("div",{children:[t.jsx("div",{className:`text-xs font-medium text-${r}-400 mb-1.5`,children:e}),t.jsx("div",{className:"space-y-1",children:s.map((i,o)=>t.jsxs("div",{className:"text-sm text-fg-secondary flex items-center gap-2",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${r}-500 shrink-0`}),t.jsx("span",{className:"truncate",children:i.label}),i.sub&&i.sub!=="unassigned"&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:i.sub})]},o))})]})}function ou({label:e,value:r,color:s}){return t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("div",{className:"text-sm text-fg-secondary mb-2",children:e}),t.jsx("div",{className:`text-2xl font-bold ${s}`,children:r})]})}function ro({label:e,col:r,current:s,desc:i,onSort:o,align:c}){const u=s===r?i?"↓":"↑":"↕",f=s===r?"text-brand-500":"text-fg-muted";return t.jsxs("th",{className:`px-4 py-3 ${c==="right"?"text-right":"text-left"} font-medium cursor-pointer select-none hover:text-fg-secondary`,onClick:()=>o(r),children:[e,t.jsx("span",{className:`ml-1 ${f}`,children:u})]})}function yL({agent:e,maxTokens:r}){const s=r>0?Math.min(100,e.totalTokens/r*100):0,i=e.status==="working"?"bg-blue-500":e.status==="idle"?"bg-green-500":e.status==="paused"?"bg-amber-500":e.status==="error"?"bg-red-500":"bg-gray-600";return t.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>Ut.navigate("team",{selectAgent:e.agentId}),children:[t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:`w-2 h-2 rounded-full ${i}`}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:t.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${s}%`}})}),t.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:ya(e.totalTokens)})]})}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:ya(e.tokensUsedToday)}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.requestCount}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.toolCalls}),t.jsx("td",{className:"px-4 py-3 text-sm text-right text-fg-secondary tabular-nums",children:pu(e.estimatedCost)})]})}function so({d:e,size:r=18}){return t.jsx("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:e})})}const ao={dashboard:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M9 22V12h6v10",projects:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z",chat:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",reports:"M18 20V10 M12 20V4 M6 20v-6",deliverables:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20 M4 19.5A2.5 2.5 0 0 0 6.5 22H20V2H6.5A2.5 2.5 0 0 0 4 4.5v15z",usage:"M21.21 15.89A10 10 0 1 1 8 2.83 M22 12A10 10 0 0 0 12 2v10z",builder:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",agents:"M8 3H5a2 2 0 0 0-2 2v3 M21 8V5a2 2 0 0 0-2-2h-3 M3 16v3a2 2 0 0 0 2 2h3 M16 21h3a2 2 0 0 0 2-2v-3 M9 9h6v6H9z",teams:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2 M9 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8z M23 21v-2a4 4 0 0 0-3-3.87 M16 3.13a4 4 0 0 1 0 7.75",skills:"M12 2L2 7l10 5 10-5-10-5z M2 17l10 5 10-5 M2 12l10 5 10-5",governance:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"},vL={active:"bg-green-500",paused:"bg-amber-500",completed:"bg-gray-500",archived:"bg-gray-600"},jL=[{id:"dashboard",label:"Overview",section:"workspace"},{id:"chat",label:"Chat",section:"workspace"},{id:"deliverables",label:"Deliverables",section:"workspace"},{id:"builder",label:"Builder",section:"build"},{id:"agents",label:"Agents",section:"build"},{id:"teams",label:"Teams",section:"build"},{id:"skills",label:"Skills",section:"build"},{id:"governance",label:"Governance",section:"system"},{id:"reports",label:"Reports",section:"system"},{id:"settings",label:"Settings",section:"system"}],wL=[{key:"workspace",label:"WORKSPACE"},{key:"build",label:"BUILD"},{key:"system",label:"SYSTEM"}],$v=5;function NL({currentPage:e,onNavigate:r,authUser:s,onLogout:i,collapsed:o,onToggleCollapse:c}){const[u,f]=j.useState([]),[m,h]=j.useState(!1),[x,g]=j.useState(null),[b,p]=j.useState(!1),w=j.useCallback(()=>{ae.projects.list().then(C=>f(C.projects)).catch(()=>{})},[]);j.useEffect(()=>{w();const C=setInterval(w,3e4);return()=>clearInterval(C)},[w]),j.useEffect(()=>{if(e!=="projects"){g(null);return}const N=window.location.hash.slice(1).split("/");N[0]==="projects"&&N[1]&&g(N[1])},[e]);const S=async()=>{try{await ae.auth.logout()}catch{}i?.()},T=m?u:u.slice(0,$v),E=u.length>$v;return t.jsxs("aside",{className:"h-dvh bg-surface-secondary flex flex-col shrink-0 overflow-hidden border-r border-border-subtle",children:[t.jsx("div",{className:`flex items-center ${o?"px-2 py-3.5 justify-center":"px-4 h-14 justify-between"}`,children:o?t.jsx("button",{onClick:c,title:"Expand sidebar",className:"group",children:t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg group-hover:ring-2 group-hover:ring-brand-500/40 transition-all"})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg shadow-md shadow-black/30 shrink-0"}),t.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]}),t.jsx("button",{onClick:c,className:"text-fg-tertiary hover:text-fg-secondary transition-colors p-1 rounded-md hover:bg-surface-overlay shrink-0",title:"Collapse sidebar",children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"11 17 6 12 11 7"}),t.jsx("polyline",{points:"18 17 13 12 18 7"})]})})]})}),t.jsx("nav",{className:`${o?"p-1.5":"p-3"} flex-1 overflow-y-auto`,children:wL.map((C,N)=>t.jsx("div",{children:t.jsxs("div",{className:"mb-3",children:[!o&&t.jsx("div",{className:"px-3 py-1.5 text-[11px] font-semibold text-fg-tertiary uppercase tracking-widest",children:C.label}),o&&N>0&&t.jsx("div",{className:"my-2 mx-1"}),jL.filter(k=>k.section===C.key&&!(C.key==="workspace"&&k.id==="deliverables")).map(k=>{const H=e===k.id;return t.jsxs("button",{onClick:()=>r(k.id),title:o?k.label:void 0,className:`w-full flex items-center ${o?"justify-center px-2 py-2":"gap-3 px-3 py-2"} rounded-lg text-sm mb-0.5 transition-all ${H?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":"text-fg-primary hover:bg-surface-overlay"}`,children:[t.jsx(so,{d:ao[k.id]??""}),!o&&k.label]},k.id)}),C.key==="workspace"&&o&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{g(null),r("projects")},title:"Projects",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-all ${e==="projects"&&!x?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":e==="projects"?"bg-brand-600/15 text-fg-primary":"text-fg-primary hover:bg-surface-overlay"}`,children:t.jsx(so,{d:ao.projects})}),t.jsx("button",{onClick:()=>r("deliverables"),title:"Deliverables",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e==="deliverables"?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:t.jsx(so,{d:ao.deliverables})})]}),C.key==="workspace"&&!o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center mb-0.5",children:[t.jsxs("button",{onClick:()=>{g(null),window.location.hash="projects",r("projects")},className:`flex-1 flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-colors ${e==="projects"&&!x?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(so,{d:ao.projects}),"Projects"]}),t.jsx("button",{onClick:()=>p(!0),className:"text-fg-tertiary hover:text-fg-secondary transition-colors p-1.5 rounded hover:bg-surface-elevated shrink-0",title:"New Project",children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),u.length===0&&t.jsxs("button",{onClick:()=>p(!0),className:"w-full flex items-center gap-2 pl-9 pr-3 py-1.5 text-xs text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50 rounded-lg transition-colors",children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Create your first project"]}),T.map(k=>{const H=e==="projects"&&x===k.id;return t.jsxs("button",{onClick:()=>{g(k.id),e!=="projects"&&r("projects"),window.location.hash="projects/"+k.id},className:`w-full flex items-center gap-2.5 pl-9 pr-3 py-1.5 rounded-lg text-sm mb-0.5 transition-colors ${H?"bg-brand-600 text-white":"text-fg-secondary hover:bg-surface-elevated"}`,children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${vL[k.status]??"bg-gray-600"}`}),t.jsx("span",{className:"truncate text-xs",children:k.name})]},k.id)}),E&&!m&&t.jsxs("button",{onClick:()=>h(!0),className:"w-full pl-9 pr-3 py-1 text-[11px] text-fg-tertiary hover:text-fg-secondary transition-colors text-left",children:["Show all ",u.length," projects..."]}),t.jsxs("button",{onClick:()=>r("deliverables"),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e==="deliverables"?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(so,{d:ao.deliverables}),"Deliverables"]})]})]})},C.key))}),t.jsxs("div",{className:`${o?"p-2 flex flex-col items-center gap-2":"px-4 py-3 space-y-2"}`,children:[s&&(o?t.jsx("button",{onClick:S,title:`${s.name??s.email} — Sign out`,className:"w-7 h-7 rounded-full bg-brand-600 flex items-center justify-center text-white text-xs font-bold shrink-0 hover:ring-2 hover:ring-brand-500/50 transition-all",children:s.name?.[0]?.toUpperCase()??"A"}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-600 flex items-center justify-center text-white text-xs font-bold shrink-0",children:s.name?.[0]?.toUpperCase()??"A"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-secondary truncate",children:s.name??s.email}),t.jsx("div",{className:"text-[11px] text-fg-tertiary truncate",children:s.email??s.role?.[0]?.toUpperCase()+s.role?.slice(1)})]}),t.jsx("button",{onClick:S,title:"Sign out",className:"text-fg-tertiary hover:text-fg-secondary transition-colors text-sm",children:"⇥"})]})),!o&&t.jsxs("div",{className:"text-[10px] text-fg-muted",children:["v","0.2.1"]})]}),b&&t.jsx(aN,{orgId:s?.orgId,onCreated:()=>{p(!1),w()},onClose:()=>p(!1)})]})}const kL={dashboard:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M9 22V12h6v10",chat:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",projects:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z",deliverables:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20 M4 19.5A2.5 2.5 0 0 0 6.5 22H20V2H6.5A2.5 2.5 0 0 0 4 4.5v15z",builder:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"},SL=[{id:"dashboard",label:"Home",iconKey:"dashboard",group:["dashboard"]},{id:"chat",label:"Chat",iconKey:"chat",group:["chat"]},{id:"projects",label:"Projects",iconKey:"projects",group:["projects"]},{id:"deliverables",label:"Deliverables",iconKey:"deliverables",group:["deliverables"]},{id:"builder",label:"Builder",iconKey:"builder",group:["builder","agents","teams","skills"]},{id:"settings",label:"Settings",iconKey:"settings",group:["settings","governance","reports"]}];function CL({currentPage:e,onNavigate:r}){return t.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-surface-secondary border-t border-border-default flex items-stretch h-14 safe-area-bottom",children:SL.map(s=>{const i=s.group.includes(e);return t.jsxs("button",{onClick:()=>r(s.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${i?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[t.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:i?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:kL[s.iconKey]})}),t.jsx("span",{className:`text-[10px] leading-tight ${i?"font-semibold":""}`,children:s.label})]},s.id)})})}const EL=50,TL=30;function fN(e,r,s){const i=j.useRef(0),o=j.useRef(0),c=j.useCallback(f=>{i.current=f.touches[0].clientX,o.current=f.touches[0].clientY},[]),u=j.useCallback(f=>{const m=f.changedTouches[0].clientX-i.current,h=f.changedTouches[0].clientY-o.current,x=Math.abs(m),g=Math.abs(h);if(x<EL||Math.atan2(g,x)*(180/Math.PI)>TL)return;const p=e.findIndex(w=>w.id===r);m<0&&p<e.length-1?s(e[p+1].id):m>0&&p>0&&s(e[p-1].id)},[e,r,s]);return{onTouchStart:c,onTouchEnd:u}}const Bv=[{id:"builder",label:"Builder"},{id:"agents",label:"Agents"},{id:"teams",label:"Teams"},{id:"skills",label:"Skills"}];function _L({authUser:e}){const[r,s]=j.useState("builder"),i=fN(Bv,r,s);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:i.onTouchStart,onTouchEnd:i.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:Bv.map(o=>t.jsx("button",{onClick:()=>s(o.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${r===o.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:o.label},o.id))}),t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[r==="builder"&&t.jsx(gj,{}),r==="agents"&&t.jsx(fj,{authUser:e}),r==="teams"&&t.jsx(xj,{}),r==="skills"&&t.jsx(cj,{})]})]})}const Hv=[{id:"settings",label:"Settings"},{id:"governance",label:"Governance"},{id:"reports",label:"Reports"}];function AL({theme:e,onThemeChange:r}){const[s,i]=j.useState("settings"),o=fN(Hv,s,i);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:o.onTouchStart,onTouchEnd:o.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:Hv.map(c=>t.jsx("button",{onClick:()=>i(c.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===c.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:c.label},c.id))}),t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="settings"&&t.jsx(lj,{theme:e,onThemeChange:r}),s==="governance"&&t.jsx(pj,{}),s==="reports"&&t.jsx(dN,{})]})]})}const Pv=2;function ML({onComplete:e,theme:r,onThemeChange:s}){const[i,o]=j.useState(0),[c,u]=j.useState(null),[f,m]=j.useState(!1),[h,x]=j.useState({}),[g,b]=j.useState(!1),[p,w]=j.useState(null),[S,T]=j.useState(!1),[E,C]=j.useState(!1),[N,k]=j.useState(null),H=j.useRef(!1),M=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});j.useEffect(()=>{fetch("/api/settings/llm").then(I=>I.ok?I.json():null).then(I=>{I?.providers&&Object.values(I.providers).some(A=>A.configured)&&C(!0)}).catch(()=>{})},[]),j.useEffect(()=>{i===Pv&&!H.current&&!E&&(H.current=!0,Y())},[i,E]);const Y=async()=>{m(!0);try{const I=await fetch("/api/settings/env-models",{headers:M()});if(I.ok){const A=await I.json();if(u(A),A.detected.length>0){const G={};for(const U of A.detected)G[U.provider]=!0;x(G)}}}catch{}finally{m(!1)}},$=async()=>{if(!c)return;const I=c.detected.filter(A=>h[A.provider]);if(I.length!==0){b(!0),k(null);try{const A=await fetch("/api/settings/env-models",{method:"POST",headers:M(),body:JSON.stringify({providers:I.map(G=>({provider:G.provider,model:G.model,baseUrl:G.baseUrl,enabled:!0}))})});if(A.ok){const G=await A.json();k({type:"ok",text:G.message}),C(!0)}else k({type:"err",text:"Failed to apply"})}catch{k({type:"err",text:"Network error"})}finally{b(!1)}}},X=async()=>{T(!0);try{const A=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:M(),body:JSON.stringify({preview:!0})})).json();"error"in A||w(A)}catch{}finally{T(!1)}},P=async()=>{T(!0),k(null);try{const A=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:M(),body:JSON.stringify({preview:!1})})).json();"error"in A?k({type:"err",text:A.error}):(k({type:"ok",text:`Imported ${A.appliedModels} model configs`}),C(!0))}catch{k({type:"err",text:"Import failed"})}finally{T(!1)}},q=[{value:"system",label:"System",icon:"💻",desc:"Follow your OS setting"},{value:"light",label:"Light",icon:"☀️",desc:"Always light background"},{value:"dark",label:"Dark",icon:"🌙",desc:"Always dark background"}],F=[{title:"Welcome to Markus",subtitle:"Your AI Digital Employee Platform",content:t.jsxs("div",{className:"space-y-4 text-fg-secondary text-sm leading-relaxed",children:[t.jsxs("p",{children:["Markus helps you build ",t.jsx("strong",{className:"text-fg-primary",children:"AI teams"})," — digital employees that work autonomously, collaborate with each other, and communicate with you naturally."]}),t.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[["Always Online","Agents work 24/7 autonomously"],["Team Collaboration","Agents communicate via A2A messaging"],["Smart Routing","Messages auto-route to the right agent"],["Tool Capable","Shell, files, web, git, browser tools"]].map(([I,A])=>t.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[t.jsx("div",{className:"font-medium text-fg-primary text-xs",children:I}),t.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:A})]},I))})]})},{title:"Choose Your Theme",subtitle:"You can change this anytime in Settings",content:t.jsx("div",{className:"grid grid-cols-3 gap-3",children:q.map(I=>t.jsxs("button",{onClick:()=>s(I.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${r===I.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[t.jsx("span",{className:"text-2xl",children:I.icon}),t.jsx("span",{className:"text-sm font-medium text-fg-primary",children:I.label}),t.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:I.desc})]},I.value))})},{title:"Configure LLM",subtitle:"Agents need an LLM to think and act",content:E?t.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[t.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium text-green-600",children:"LLM provider configured"}),t.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:"You can manage providers anytime in Settings."})]})]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:"From Environment Variables"}),f&&t.jsx("div",{className:"text-xs text-fg-tertiary animate-pulse",children:"Detecting API keys..."}),c&&c.detected.length>0&&t.jsxs("div",{className:"space-y-2",children:[c.detected.map(I=>t.jsxs("label",{className:"flex items-center gap-3 bg-surface-elevated/40 rounded-lg px-3 py-2.5 cursor-pointer hover:bg-surface-elevated/60 transition-colors",children:[t.jsx("input",{type:"checkbox",checked:h[I.provider]??!1,onChange:A=>x({...h,[I.provider]:A.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-sm text-fg-primary",children:I.displayName}),t.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:I.model})]}),t.jsx("code",{className:"text-[10px] text-fg-tertiary",children:I.apiKeyPreview})]},I.provider)),t.jsx("button",{onClick:()=>{$()},disabled:g||Object.values(h).filter(Boolean).length===0,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:g?"Applying...":`Apply ${Object.values(h).filter(Boolean).length} Provider(s)`})]}),c&&c.detected.length===0&&!f&&t.jsxs("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:["No API keys found. Set ",t.jsx("code",{className:"text-fg-secondary",children:"ANTHROPIC_API_KEY"}),", ",t.jsx("code",{className:"text-fg-secondary",children:"OPENAI_API_KEY"}),", etc. in your ",t.jsx("code",{className:"text-fg-secondary",children:".env"})," file and restart."]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 h-px bg-border-default"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:"or"}),t.jsx("div",{className:"flex-1 h-px bg-border-default"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:"From OpenClaw"}),p?p.found?t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"text-xs text-green-600",children:["Found: ",t.jsx("code",{className:"text-fg-secondary",children:p.summary.configPath}),p.summary.models&&t.jsxs("span",{className:"text-fg-tertiary ml-1",children:["(",p.summary.models.providerCount," providers)"]})]}),t.jsx("button",{onClick:()=>{P()},disabled:S,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:S?"Importing...":"Import Model Configs"})]}):t.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:"No OpenClaw config found."}):t.jsx("button",{onClick:()=>{X()},disabled:S,className:"px-4 py-2 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-secondary text-sm rounded-lg transition-colors w-full",children:S?"Detecting...":"Detect OpenClaw Config"})]}),N&&t.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${N.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:N.text})]})},{title:"You're All Set",subtitle:"Here's what you can do",content:t.jsx("div",{className:"space-y-2 text-fg-secondary text-sm",children:[["Chat","Talk to agents or use Smart Route to auto-pick the best one"],["Projects","Create tasks and track progress on kanban boards"],["Builder","Create and customize agents, teams, and prompts"],["Settings","Manage LLM providers, themes, and import configs"]].map(([I,A])=>t.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[t.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),t.jsxs("div",{children:[t.jsx("div",{className:"font-medium text-fg-primary text-xs",children:I}),t.jsx("div",{className:"text-fg-secondary text-xs",children:A})]})]},I))})}],D=()=>{i<F.length-1?o(i+1):e()},_=F[i];return t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:t.jsx("div",{className:"w-full max-w-lg",children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl p-8",children:[t.jsx("div",{className:"flex gap-1.5 mb-8",children:F.map((I,A)=>t.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${A<=i?"bg-brand-500":"bg-surface-elevated"}`},A))}),t.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:_.title}),t.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:_.subtitle}),_.content,t.jsxs("div",{className:"flex justify-between mt-8",children:[i>0?t.jsx("button",{onClick:()=>o(i-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:"Back"}):t.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip"}),t.jsxs("div",{className:"flex items-center gap-3",children:[i===Pv&&!E&&t.jsx("button",{onClick:D,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip for now"}),t.jsx("button",{onClick:D,className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-xl transition-colors",children:i===F.length-1?"Get Started":"Next"})]})]})]})})})}const DL="markus123";function OL({onLogin:e}){const[r,s]=j.useState("admin@markus.local"),[i,o]=j.useState(""),[c,u]=j.useState(""),[f,m]=j.useState(!1),h=async x=>{if(x.preventDefault(),!(!r.trim()||!i)){u(""),m(!0);try{const{user:g}=await ae.auth.login(r.trim(),i);e(g,i===DL)}catch{u("Invalid email or password")}finally{m(!1)}}};return t.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[t.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),t.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),t.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),t.jsx("div",{className:"text-sm text-fg-tertiary",children:"AI Digital Employee Platform"})]}),t.jsxs("form",{onSubmit:h,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[t.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:"Sign in"}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Email"}),t.jsx("input",{type:"email",value:r,onChange:x=>s(x.target.value),autoComplete:"email",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Password"}),t.jsx("input",{type:"password",value:i,onChange:x=>o(x.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),c&&t.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:c}),t.jsx("button",{type:"submit",disabled:f||!r||!i,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all shadow-md shadow-brand-900/40 hover:shadow-lg hover:shadow-brand-900/50",children:f?"Signing in…":"Sign in"}),t.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:"Default: admin@markus.local / markus123"})]})]})]})}function RL({onComplete:e,isFirstTime:r}){const[s,i]=j.useState(""),[o,c]=j.useState(""),[u,f]=j.useState(""),[m,h]=j.useState(""),[x,g]=j.useState(!1),b=async p=>{if(p.preventDefault(),h(""),o.length<6){h("Password must be at least 6 characters");return}if(o!==u){h("Passwords do not match");return}g(!0);try{await ae.auth.changePassword(s,o),e()}catch{h("Failed to change password. Check your current password.")}finally{g(!1)}};return t.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[t.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),t.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),t.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),t.jsx("div",{className:"text-sm text-fg-tertiary",children:"AI Digital Employee Platform"})]}),t.jsxs("form",{onSubmit:b,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:r?"Set Your Password":"Change Password"}),r&&t.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:"You're using the default password. Please set a new one before continuing."})]}),!r&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Current Password"}),t.jsx("input",{type:"password",value:s,onChange:p=>i(p.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"New Password"}),t.jsx("input",{type:"password",value:o,onChange:p=>c(p.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0,minLength:6})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Confirm New Password"}),t.jsx("input",{type:"password",value:u,onChange:p=>f(p.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),m&&t.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:m}),t.jsx("button",{type:"submit",disabled:x||!o||!u,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-colors",children:x?"Saving…":r?"Set Password & Continue":"Change Password"})]})]})]})}const hN="markus-theme";function Uv(e){const r=document.documentElement;r.classList.remove("light","dark"),e==="light"?r.classList.add("light"):e==="dark"&&r.classList.add("dark")}function zL(){try{const e=localStorage.getItem(hN);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function LL(){const[e,r]=j.useState(zL),s=j.useCallback(i=>{r(i);try{localStorage.setItem(hN,i)}catch{}Uv(i)},[]);return j.useEffect(()=>{Uv(e)},[e]),{mode:e,setMode:s}}const IL=["dashboard","tasks","chat","team","usage","skills","agents","teams","builder","prompts","settings","governance","projects","deliverables","reports"];function cu(){const e=window.location.hash.slice(1).split("/")[0];return e==="team"?"chat":e==="tasks"?"projects":e==="usage"?"reports":e==="prompts"?"builder":e==="templates"?"agents":e==="knowledge"?"deliverables":IL.includes(e)?e:"dashboard"}const Qh={};function $L(){const[e,r]=j.useState(cu),[s,i]=j.useState(()=>!localStorage.getItem("markus_onboarded")),[o,c]=j.useState(!0),u=gs(),f=LL(),m=ex({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[h,x]=j.useState(()=>new Set([cu()])),[g,b]=j.useState("loading"),[p,w]=j.useState(!1),[S,T]=j.useState(null),[E,C]=j.useState(!1),N=j.useCallback(Y=>{let $=Y==="tasks"?"projects":Y==="team"?"chat":Y==="usage"?"reports":Y==="prompts"?"builder":Y==="templates"?"agents":Y;u&&(($==="agents"||$==="teams"||$==="skills")&&($="builder"),($==="governance"||$==="reports")&&($="settings"));const X=cu(),P=window.location.hash.slice(1);P!==X?Qh[X]=P:delete Qh[X],r($),x(q=>q.has($)?q:new Set([...q,$])),window.location.hash=Qh[$]||$},[u]);j.useEffect(()=>{Ut.setHandler(Y=>N(Y))},[N]);const k=j.useCallback(()=>{fetch("/api/settings/llm").then(Y=>Y.ok?Y.json():null).then(Y=>{if(Y?.providers){const $=Object.values(Y.providers).some(X=>X.configured);T($)}}).catch(()=>{})},[]);j.useEffect(()=>{ae.auth.me().then(({user:$})=>{b($),k(),Va(pr.builderArtifacts,()=>ae.builder.artifacts.list()),Va(pr.builderAgents,()=>ae.agents.list()),Va(pr.builderHubMyItems,()=>Bn.myItems()),Va(pr.builderInstalled,()=>ae.builder.artifacts.installed()),Va(pr.hubAgents,()=>Bn.search({type:"agent",limit:50})),Va(pr.hubTeams,()=>Bn.search({type:"team",limit:50})),Va(pr.hubSkills,()=>Bn.search({type:"skill",limit:50}))}).catch(()=>b(null)),En.connect();const Y=()=>{const $=cu();r($),x(X=>X.has($)?X:new Set([...X,$]))};return window.addEventListener("hashchange",Y),()=>{En.disconnect(),window.removeEventListener("hashchange",Y)}},[]);const H=g!=="loading"&&g!==null?g:void 0,M=j.useMemo(()=>u?{dashboard:t.jsx(ob,{}),chat:t.jsx(hy,{authUser:H}),builder:t.jsx(_L,{authUser:H}),settings:t.jsx(AL,{theme:f.mode,onThemeChange:f.setMode}),projects:t.jsx(Rv,{authUser:H}),deliverables:t.jsx(Iv,{})}:{dashboard:t.jsx(ob,{}),chat:t.jsx(hy,{authUser:H}),settings:t.jsx(lj,{theme:f.mode,onThemeChange:f.setMode}),skills:t.jsx(cj,{}),agents:t.jsx(fj,{authUser:H}),teams:t.jsx(xj,{}),builder:t.jsx(gj,{}),governance:t.jsx(pj,{}),projects:t.jsx(Rv,{authUser:H}),deliverables:t.jsx(Iv,{}),reports:t.jsx(dN,{})},[H?.id,f.mode,u]);return g==="loading"?t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:t.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:"Loading…"})}):g===null?t.jsx(OL,{onLogin:(Y,$)=>{b(Y),$&&w(!0)}}):p?t.jsx(RL,{onComplete:()=>w(!1),isFirstTime:!0}):s?t.jsx(ML,{theme:f.mode,onThemeChange:f.setMode,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),i(!1),k()}}):t.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary ${u?"flex-col":""}`,children:[!u&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:t.jsx(NL,{currentPage:e,onNavigate:Y=>{N(Y),c(!1)},authUser:g,onLogout:()=>b(null),collapsed:m.collapsed,onToggleCollapse:m.toggle})}),!m.collapsed&&t.jsx("div",{className:"w-1 cursor-col-resize shrink-0 group relative z-10",onMouseDown:m.onResizeStart,children:t.jsx("div",{className:"absolute inset-y-0 -left-0.5 -right-0.5 group-hover:bg-brand-500/30 group-active:bg-brand-500/50 transition-colors"})})]}),t.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col min-w-0 ${u?"pb-14":""}`,children:[S===!1&&!E&&e!=="settings"&&t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-amber-500/10 border-b border-amber-500/30 text-amber-600 text-sm shrink-0",children:[t.jsx("span",{className:u?"text-xs":"",children:"No LLM provider configured — agents cannot process requests."}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:()=>{N("settings")},className:"px-3 py-1 bg-amber-700/50 hover:bg-amber-700/70 text-white text-xs rounded-lg transition-colors",children:"Go to Settings"}),t.jsx("button",{onClick:()=>C(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:"Dismiss"})]})]}),t.jsx("main",{className:"flex-1 overflow-hidden flex flex-col",children:Object.keys(M).map(Y=>h.has(Y)?t.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:Y===e?"flex":"none"},children:M[Y]},Y):null)})]}),u&&t.jsx(CL,{currentPage:e,onNavigate:N})]})}S2.createRoot(document.getElementById("root")).render(t.jsx(j.StrictMode,{children:t.jsx($L,{})}));
61
+ M${$.x},${$.y}h${$.width}v${$.height}h${-$.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}rN.displayName="MiniMap";const lz=j.memo(rN),oz=e=>r=>e?`${Math.max(1/r.transform[2],1)}`:void 0,cz={[Wi.Line]:"right",[Wi.Handle]:"bottom-right"};function uz({nodeId:e,position:r,variant:s=Wi.Handle,className:i,style:o=void 0,children:c,color:u,minWidth:f=10,minHeight:m=10,maxWidth:h=Number.MAX_VALUE,maxHeight:x=Number.MAX_VALUE,keepAspectRatio:g=!1,resizeDirection:b,autoScale:p=!0,shouldResize:w,onResizeStart:S,onResize:T,onResizeEnd:E}){const C=zw(),N=typeof e=="string"?e:C,k=yn(),H=j.useRef(null),M=s===Wi.Handle,Y=Vt(j.useCallback(oz(M&&p),[M,p]),bn),$=j.useRef(null),X=r??cz[s];j.useEffect(()=>{if(!(!H.current||!N))return $.current||($.current=zD({domNode:H.current,nodeId:N,getStoreItems:()=>{const{nodeLookup:q,transform:F,snapGrid:D,snapToGrid:_,nodeOrigin:I,domNode:A}=k.getState();return{nodeLookup:q,transform:F,snapGrid:D,snapToGrid:_,nodeOrigin:I,paneDomNode:A}},onChange:(q,F)=>{const{triggerNodeChanges:D,nodeLookup:_,parentLookup:I,nodeOrigin:A}=k.getState(),G=[],U={x:q.x,y:q.y},K=_.get(N);if(K&&K.expandParent&&K.parentId){const B=K.origin??A,L=q.width??K.measured.width??0,W=q.height??K.measured.height??0,R={id:K.id,parentId:K.parentId,rect:{width:L,height:W,...sw({x:q.x??K.position.x,y:q.y??K.position.y},{width:L,height:W},K.parentId,_,B)}},z=bx([R],_,I,A);G.push(...z),U.x=q.x?Math.max(B[0]*L,q.x):void 0,U.y=q.y?Math.max(B[1]*W,q.y):void 0}if(U.x!==void 0&&U.y!==void 0){const B={id:N,type:"position",position:{...U}};G.push(B)}if(q.width!==void 0&&q.height!==void 0){const L={id:N,type:"dimensions",resizing:!0,setAttributes:b?b==="horizontal"?"width":"height":!0,dimensions:{width:q.width,height:q.height}};G.push(L)}for(const B of F){const L={...B,type:"position"};G.push(L)}D(G)},onEnd:({width:q,height:F})=>{const D={id:N,type:"dimensions",resizing:!1,dimensions:{width:q,height:F}};k.getState().triggerNodeChanges([D])}})),$.current.update({controlPosition:X,boundaries:{minWidth:f,minHeight:m,maxWidth:h,maxHeight:x},keepAspectRatio:g,resizeDirection:b,onResizeStart:S,onResize:T,onResizeEnd:E,shouldResize:w}),()=>{$.current?.destroy()}},[X,f,m,h,x,g,S,T,E,w]);const P=X.split("-");return t.jsx("div",{className:Pn(["react-flow__resize-control","nodrag",...P,s,i]),ref:H,style:{...o,scale:Y,...u&&{[M?"backgroundColor":"borderColor"]:u}},children:c})}j.memo(uz);var Wt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),ns=Wt((e,r)=>{var s=Object.defineProperty,i=(D,_,I)=>_ in D?s(D,_,{enumerable:!0,configurable:!0,writable:!0,value:I}):D[_]=I,o=(D,_)=>()=>(_||D((_={exports:{}}).exports,_),_.exports),c=(D,_,I)=>i(D,typeof _!="symbol"?_+"":_,I),u=o((D,_)=>{var I="\0",A="\0",G="",U=class{constructor(z){c(this,"_isDirected",!0),c(this,"_isMultigraph",!1),c(this,"_isCompound",!1),c(this,"_label"),c(this,"_defaultNodeLabelFn",()=>{}),c(this,"_defaultEdgeLabelFn",()=>{}),c(this,"_nodes",{}),c(this,"_in",{}),c(this,"_preds",{}),c(this,"_out",{}),c(this,"_sucs",{}),c(this,"_edgeObjs",{}),c(this,"_edgeLabels",{}),c(this,"_nodeCount",0),c(this,"_edgeCount",0),c(this,"_parent"),c(this,"_children"),z&&(this._isDirected=Object.hasOwn(z,"directed")?z.directed:!0,this._isMultigraph=Object.hasOwn(z,"multigraph")?z.multigraph:!1,this._isCompound=Object.hasOwn(z,"compound")?z.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[A]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(z){return this._label=z,this}graph(){return this._label}setDefaultNodeLabel(z){return this._defaultNodeLabelFn=z,typeof z!="function"&&(this._defaultNodeLabelFn=()=>z),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var z=this;return this.nodes().filter(V=>Object.keys(z._in[V]).length===0)}sinks(){var z=this;return this.nodes().filter(V=>Object.keys(z._out[V]).length===0)}setNodes(z,V){var Q=arguments,te=this;return z.forEach(function(Z){Q.length>1?te.setNode(Z,V):te.setNode(Z)}),this}setNode(z,V){return Object.hasOwn(this._nodes,z)?(arguments.length>1&&(this._nodes[z]=V),this):(this._nodes[z]=arguments.length>1?V:this._defaultNodeLabelFn(z),this._isCompound&&(this._parent[z]=A,this._children[z]={},this._children[A][z]=!0),this._in[z]={},this._preds[z]={},this._out[z]={},this._sucs[z]={},++this._nodeCount,this)}node(z){return this._nodes[z]}hasNode(z){return Object.hasOwn(this._nodes,z)}removeNode(z){var V=this;if(Object.hasOwn(this._nodes,z)){var Q=te=>V.removeEdge(V._edgeObjs[te]);delete this._nodes[z],this._isCompound&&(this._removeFromParentsChildList(z),delete this._parent[z],this.children(z).forEach(function(te){V.setParent(te)}),delete this._children[z]),Object.keys(this._in[z]).forEach(Q),delete this._in[z],delete this._preds[z],Object.keys(this._out[z]).forEach(Q),delete this._out[z],delete this._sucs[z],--this._nodeCount}return this}setParent(z,V){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(V===void 0)V=A;else{V+="";for(var Q=V;Q!==void 0;Q=this.parent(Q))if(Q===z)throw new Error("Setting "+V+" as parent of "+z+" would create a cycle");this.setNode(V)}return this.setNode(z),this._removeFromParentsChildList(z),this._parent[z]=V,this._children[V][z]=!0,this}_removeFromParentsChildList(z){delete this._children[this._parent[z]][z]}parent(z){if(this._isCompound){var V=this._parent[z];if(V!==A)return V}}children(z=A){if(this._isCompound){var V=this._children[z];if(V)return Object.keys(V)}else{if(z===A)return this.nodes();if(this.hasNode(z))return[]}}predecessors(z){var V=this._preds[z];if(V)return Object.keys(V)}successors(z){var V=this._sucs[z];if(V)return Object.keys(V)}neighbors(z){var V=this.predecessors(z);if(V){let te=new Set(V);for(var Q of this.successors(z))te.add(Q);return Array.from(te.values())}}isLeaf(z){var V;return this.isDirected()?V=this.successors(z):V=this.neighbors(z),V.length===0}filterNodes(z){var V=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});V.setGraph(this.graph());var Q=this;Object.entries(this._nodes).forEach(function([ee,ie]){z(ee)&&V.setNode(ee,ie)}),Object.values(this._edgeObjs).forEach(function(ee){V.hasNode(ee.v)&&V.hasNode(ee.w)&&V.setEdge(ee,Q.edge(ee))});var te={};function Z(ee){var ie=Q.parent(ee);return ie===void 0||V.hasNode(ie)?(te[ee]=ie,ie):ie in te?te[ie]:Z(ie)}return this._isCompound&&V.nodes().forEach(ee=>V.setParent(ee,Z(ee))),V}setDefaultEdgeLabel(z){return this._defaultEdgeLabelFn=z,typeof z!="function"&&(this._defaultEdgeLabelFn=()=>z),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(z,V){var Q=this,te=arguments;return z.reduce(function(Z,ee){return te.length>1?Q.setEdge(Z,ee,V):Q.setEdge(Z,ee),ee}),this}setEdge(){var z,V,Q,te,Z=!1,ee=arguments[0];typeof ee=="object"&&ee!==null&&"v"in ee?(z=ee.v,V=ee.w,Q=ee.name,arguments.length===2&&(te=arguments[1],Z=!0)):(z=ee,V=arguments[1],Q=arguments[3],arguments.length>2&&(te=arguments[2],Z=!0)),z=""+z,V=""+V,Q!==void 0&&(Q=""+Q);var ie=L(this._isDirected,z,V,Q);if(Object.hasOwn(this._edgeLabels,ie))return Z&&(this._edgeLabels[ie]=te),this;if(Q!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(z),this.setNode(V),this._edgeLabels[ie]=Z?te:this._defaultEdgeLabelFn(z,V,Q);var je=W(this._isDirected,z,V,Q);return z=je.v,V=je.w,Object.freeze(je),this._edgeObjs[ie]=je,K(this._preds[V],z),K(this._sucs[z],V),this._in[V][ie]=je,this._out[z][ie]=je,this._edgeCount++,this}edge(z,V,Q){var te=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,Q);return this._edgeLabels[te]}edgeAsObj(){let z=this.edge(...arguments);return typeof z!="object"?{label:z}:z}hasEdge(z,V,Q){var te=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,Q);return Object.hasOwn(this._edgeLabels,te)}removeEdge(z,V,Q){var te=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,Q),Z=this._edgeObjs[te];return Z&&(z=Z.v,V=Z.w,delete this._edgeLabels[te],delete this._edgeObjs[te],B(this._preds[V],z),B(this._sucs[z],V),delete this._in[V][te],delete this._out[z][te],this._edgeCount--),this}inEdges(z,V){return this.isDirected()?this.filterEdges(this._in[z],z,V):this.nodeEdges(z,V)}outEdges(z,V){return this.isDirected()?this.filterEdges(this._out[z],z,V):this.nodeEdges(z,V)}nodeEdges(z,V){if(z in this._nodes)return this.filterEdges({...this._in[z],...this._out[z]},z,V)}filterEdges(z,V,Q){if(z){var te=Object.values(z);return Q?te.filter(function(Z){return Z.v===V&&Z.w===Q||Z.v===Q&&Z.w===V}):te}}};function K(z,V){z[V]?z[V]++:z[V]=1}function B(z,V){--z[V]||delete z[V]}function L(z,V,Q,te){var Z=""+V,ee=""+Q;if(!z&&Z>ee){var ie=Z;Z=ee,ee=ie}return Z+G+ee+G+(te===void 0?I:te)}function W(z,V,Q,te){var Z=""+V,ee=""+Q;if(!z&&Z>ee){var ie=Z;Z=ee,ee=ie}var je={v:Z,w:ee};return te&&(je.name=te),je}function R(z,V){return L(z,V.v,V.w,V.name)}_.exports=U}),f=o((D,_)=>{_.exports="3.0.2"}),m=o((D,_)=>{_.exports={Graph:u(),version:f()}}),h=o((D,_)=>{var I=u();_.exports={write:A,read:K};function A(B){var L={options:{directed:B.isDirected(),multigraph:B.isMultigraph(),compound:B.isCompound()},nodes:G(B),edges:U(B)};return B.graph()!==void 0&&(L.value=structuredClone(B.graph())),L}function G(B){return B.nodes().map(function(L){var W=B.node(L),R=B.parent(L),z={v:L};return W!==void 0&&(z.value=W),R!==void 0&&(z.parent=R),z})}function U(B){return B.edges().map(function(L){var W=B.edge(L),R={v:L.v,w:L.w};return L.name!==void 0&&(R.name=L.name),W!==void 0&&(R.value=W),R})}function K(B){var L=new I(B.options).setGraph(B.value);return B.nodes.forEach(function(W){L.setNode(W.v,W.value),W.parent&&L.setParent(W.v,W.parent)}),B.edges.forEach(function(W){L.setEdge({v:W.v,w:W.w,name:W.name},W.value)}),L}}),x=o((D,_)=>{_.exports=A;var I=()=>1;function A(U,K,B,L){return G(U,String(K),B||I,L||function(W){return U.outEdges(W)})}function G(U,K,B,L){var W={},R=!0,z=0,V=U.nodes(),Q=function(ie){var je=B(ie);W[ie.v].distance+je<W[ie.w].distance&&(W[ie.w]={distance:W[ie.v].distance+je,predecessor:ie.v},R=!0)},te=function(){V.forEach(function(ie){L(ie).forEach(function(je){var ke=je.v===ie?je.v:je.w,De=ke===je.v?je.w:je.v;Q({v:ke,w:De})})})};V.forEach(function(ie){var je=ie===K?0:Number.POSITIVE_INFINITY;W[ie]={distance:je}});for(var Z=V.length,ee=1;ee<Z&&(R=!1,z++,te(),!!R);ee++);if(z===Z-1&&(R=!1,te(),R))throw new Error("The graph contains a negative weight cycle");return W}}),g=o((D,_)=>{_.exports=I;function I(A){var G={},U=[],K;function B(L){Object.hasOwn(G,L)||(G[L]=!0,K.push(L),A.successors(L).forEach(B),A.predecessors(L).forEach(B))}return A.nodes().forEach(function(L){K=[],B(L),K.length&&U.push(K)}),U}}),b=o((D,_)=>{var I=class{constructor(){c(this,"_arr",[]),c(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(A){return A.key})}has(A){return Object.hasOwn(this._keyIndices,A)}priority(A){var G=this._keyIndices[A];if(G!==void 0)return this._arr[G].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(A,G){var U=this._keyIndices;if(A=String(A),!Object.hasOwn(U,A)){var K=this._arr,B=K.length;return U[A]=B,K.push({key:A,priority:G}),this._decrease(B),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var A=this._arr.pop();return delete this._keyIndices[A.key],this._heapify(0),A.key}decrease(A,G){var U=this._keyIndices[A];if(G>this._arr[U].priority)throw new Error("New priority is greater than current priority. Key: "+A+" Old: "+this._arr[U].priority+" New: "+G);this._arr[U].priority=G,this._decrease(U)}_heapify(A){var G=this._arr,U=2*A,K=U+1,B=A;U<G.length&&(B=G[U].priority<G[B].priority?U:B,K<G.length&&(B=G[K].priority<G[B].priority?K:B),B!==A&&(this._swap(A,B),this._heapify(B)))}_decrease(A){for(var G=this._arr,U=G[A].priority,K;A!==0&&(K=A>>1,!(G[K].priority<U));)this._swap(A,K),A=K}_swap(A,G){var U=this._arr,K=this._keyIndices,B=U[A],L=U[G];U[A]=L,U[G]=B,K[L.key]=A,K[B.key]=G}};_.exports=I}),p=o((D,_)=>{var I=b();_.exports=G;var A=()=>1;function G(K,B,L,W){var R=function(z){return K.outEdges(z)};return U(K,String(B),L||A,W||R)}function U(K,B,L,W){var R={},z=new I,V,Q,te=function(Z){var ee=Z.v!==V?Z.v:Z.w,ie=R[ee],je=L(Z),ke=Q.distance+je;if(je<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+Z+" Weight: "+je);ke<ie.distance&&(ie.distance=ke,ie.predecessor=V,z.decrease(ee,ke))};for(K.nodes().forEach(function(Z){var ee=Z===B?0:Number.POSITIVE_INFINITY;R[Z]={distance:ee},z.add(Z,ee)});z.size()>0&&(V=z.removeMin(),Q=R[V],Q.distance!==Number.POSITIVE_INFINITY);)W(V).forEach(te);return R}}),w=o((D,_)=>{var I=p();_.exports=A;function A(G,U,K){return G.nodes().reduce(function(B,L){return B[L]=I(G,L,U,K),B},{})}}),S=o((D,_)=>{_.exports=I;function I(G,U,K){if(G[U].predecessor!==void 0)throw new Error("Invalid source vertex");if(G[K].predecessor===void 0&&K!==U)throw new Error("Invalid destination vertex");return{weight:G[K].distance,path:A(G,U,K)}}function A(G,U,K){for(var B=[],L=K;L!==U;)B.push(L),L=G[L].predecessor;return B.push(U),B.reverse()}}),T=o((D,_)=>{_.exports=I;function I(A){var G=0,U=[],K={},B=[];function L(W){var R=K[W]={onStack:!0,lowlink:G,index:G++};if(U.push(W),A.successors(W).forEach(function(Q){Object.hasOwn(K,Q)?K[Q].onStack&&(R.lowlink=Math.min(R.lowlink,K[Q].index)):(L(Q),R.lowlink=Math.min(R.lowlink,K[Q].lowlink))}),R.lowlink===R.index){var z=[],V;do V=U.pop(),K[V].onStack=!1,z.push(V);while(W!==V);B.push(z)}}return A.nodes().forEach(function(W){Object.hasOwn(K,W)||L(W)}),B}}),E=o((D,_)=>{var I=T();_.exports=A;function A(G){return I(G).filter(function(U){return U.length>1||U.length===1&&G.hasEdge(U[0],U[0])})}}),C=o((D,_)=>{_.exports=A;var I=()=>1;function A(U,K,B){return G(U,K||I,B||function(L){return U.outEdges(L)})}function G(U,K,B){var L={},W=U.nodes();return W.forEach(function(R){L[R]={},L[R][R]={distance:0},W.forEach(function(z){R!==z&&(L[R][z]={distance:Number.POSITIVE_INFINITY})}),B(R).forEach(function(z){var V=z.v===R?z.w:z.v,Q=K(z);L[R][V]={distance:Q,predecessor:R}})}),W.forEach(function(R){var z=L[R];W.forEach(function(V){var Q=L[V];W.forEach(function(te){var Z=Q[R],ee=z[te],ie=Q[te],je=Z.distance+ee.distance;je<ie.distance&&(ie.distance=je,ie.predecessor=ee.predecessor)})})}),L}}),N=o((D,_)=>{function I(G){var U={},K={},B=[];function L(W){if(Object.hasOwn(K,W))throw new A;Object.hasOwn(U,W)||(K[W]=!0,U[W]=!0,G.predecessors(W).forEach(L),delete K[W],B.push(W))}if(G.sinks().forEach(L),Object.keys(U).length!==G.nodeCount())throw new A;return B}var A=class extends Error{constructor(){super(...arguments)}};_.exports=I,I.CycleException=A}),k=o((D,_)=>{var I=N();_.exports=A;function A(G){try{I(G)}catch(U){if(U instanceof I.CycleException)return!1;throw U}return!0}}),H=o((D,_)=>{_.exports=I;function I(G,U,K,B,L){Array.isArray(U)||(U=[U]);var W=(G.isDirected()?G.successors:G.neighbors).bind(G),R={};return U.forEach(function(z){if(!G.hasNode(z))throw new Error("Graph does not have node: "+z);L=A(G,z,K==="post",R,W,B,L)}),L}function A(G,U,K,B,L,W,R){return Object.hasOwn(B,U)||(B[U]=!0,K||(R=W(R,U)),L(U).forEach(function(z){R=A(G,z,K,B,L,W,R)}),K&&(R=W(R,U))),R}}),M=o((D,_)=>{var I=H();_.exports=A;function A(G,U,K){return I(G,U,K,function(B,L){return B.push(L),B},[])}}),Y=o((D,_)=>{var I=M();_.exports=A;function A(G,U){return I(G,U,"post")}}),$=o((D,_)=>{var I=M();_.exports=A;function A(G,U){return I(G,U,"pre")}}),X=o((D,_)=>{var I=u(),A=b();_.exports=G;function G(U,K){var B=new I,L={},W=new A,R;function z(Q){var te=Q.v===R?Q.w:Q.v,Z=W.priority(te);if(Z!==void 0){var ee=K(Q);ee<Z&&(L[te]=R,W.decrease(te,ee))}}if(U.nodeCount()===0)return B;U.nodes().forEach(function(Q){W.add(Q,Number.POSITIVE_INFINITY),B.setNode(Q)}),W.decrease(U.nodes()[0],0);for(var V=!1;W.size()>0;){if(R=W.removeMin(),Object.hasOwn(L,R))B.setEdge(R,L[R]);else{if(V)throw new Error("Input graph is not connected: "+U);V=!0}U.nodeEdges(R).forEach(z)}return B}}),P=o((D,_)=>{var I=p(),A=x();_.exports=G;function G(K,B,L,W){return U(K,B,L,W||function(R){return K.outEdges(R)})}function U(K,B,L,W){if(L===void 0)return I(K,B,L,W);for(var R=!1,z=K.nodes(),V=0;V<z.length;V++){for(var Q=W(z[V]),te=0;te<Q.length;te++){var Z=Q[te],ee=Z.v===z[V]?Z.v:Z.w,ie=ee===Z.v?Z.w:Z.v;L({v:ee,w:ie})<0&&(R=!0)}if(R)return A(K,B,L,W)}return I(K,B,L,W)}}),q=o((D,_)=>{_.exports={bellmanFord:x(),components:g(),dijkstra:p(),dijkstraAll:w(),extractPath:S(),findCycles:E(),floydWarshall:C(),isAcyclic:k(),postorder:Y(),preorder:$(),prim:X(),shortestPaths:P(),reduce:H(),tarjan:T(),topsort:N()}}),F=m();r.exports={Graph:F.Graph,json:h(),alg:q(),version:F.version}}),dz=Wt((e,r)=>{var s=class{constructor(){let c={};c._next=c._prev=c,this._sentinel=c}dequeue(){let c=this._sentinel,u=c._prev;if(u!==c)return i(u),u}enqueue(c){let u=this._sentinel;c._prev&&c._next&&i(c),c._next=u._next,u._next._prev=c,u._next=c,c._prev=u}toString(){let c=[],u=this._sentinel,f=u._prev;for(;f!==u;)c.push(JSON.stringify(f,o)),f=f._prev;return"["+c.join(", ")+"]"}};function i(c){c._prev._next=c._next,c._next._prev=c._prev,delete c._next,delete c._prev}function o(c,u){if(c!=="_next"&&c!=="_prev")return u}r.exports=s}),fz=Wt((e,r)=>{var s=ns().Graph,i=dz();r.exports=c;var o=()=>1;function c(g,b){if(g.nodeCount()<=1)return[];let p=m(g,b||o);return u(p.graph,p.buckets,p.zeroIdx).flatMap(w=>g.outEdges(w.v,w.w))}function u(g,b,p){let w=[],S=b[b.length-1],T=b[0],E;for(;g.nodeCount();){for(;E=T.dequeue();)f(g,b,p,E);for(;E=S.dequeue();)f(g,b,p,E);if(g.nodeCount()){for(let C=b.length-2;C>0;--C)if(E=b[C].dequeue(),E){w=w.concat(f(g,b,p,E,!0));break}}}return w}function f(g,b,p,w,S){let T=S?[]:void 0;return g.inEdges(w.v).forEach(E=>{let C=g.edge(E),N=g.node(E.v);S&&T.push({v:E.v,w:E.w}),N.out-=C,h(b,p,N)}),g.outEdges(w.v).forEach(E=>{let C=g.edge(E),N=E.w,k=g.node(N);k.in-=C,h(b,p,k)}),g.removeNode(w.v),T}function m(g,b){let p=new s,w=0,S=0;g.nodes().forEach(C=>{p.setNode(C,{v:C,in:0,out:0})}),g.edges().forEach(C=>{let N=p.edge(C.v,C.w)||0,k=b(C),H=N+k;p.setEdge(C.v,C.w,H),S=Math.max(S,p.node(C.v).out+=k),w=Math.max(w,p.node(C.w).in+=k)});let T=x(S+w+3).map(()=>new i),E=w+1;return p.nodes().forEach(C=>{h(T,E,p.node(C))}),{graph:p,buckets:T,zeroIdx:E}}function h(g,b,p){p.out?p.in?g[p.out-p.in+b].enqueue(p):g[g.length-1].enqueue(p):g[0].enqueue(p)}function x(g){let b=[];for(let p=0;p<g;p++)b.push(p);return b}}),Hn=Wt((e,r)=>{var s=ns().Graph;r.exports={addBorderNode:b,addDummyNode:i,applyWithChunking:S,asNonCompoundGraph:c,buildLayerMatrix:h,intersectRect:m,mapValues:$,maxRank:T,normalizeRanks:x,notime:N,partition:E,pick:Y,predecessorWeights:f,range:M,removeEmptyRanks:g,simplify:o,successorWeights:u,time:C,uniqueId:H,zipObject:X};function i(P,q,F,D){for(var _=D;P.hasNode(_);)_=H(D);return F.dummy=q,P.setNode(_,F),_}function o(P){let q=new s().setGraph(P.graph());return P.nodes().forEach(F=>q.setNode(F,P.node(F))),P.edges().forEach(F=>{let D=q.edge(F.v,F.w)||{weight:0,minlen:1},_=P.edge(F);q.setEdge(F.v,F.w,{weight:D.weight+_.weight,minlen:Math.max(D.minlen,_.minlen)})}),q}function c(P){let q=new s({multigraph:P.isMultigraph()}).setGraph(P.graph());return P.nodes().forEach(F=>{P.children(F).length||q.setNode(F,P.node(F))}),P.edges().forEach(F=>{q.setEdge(F,P.edge(F))}),q}function u(P){let q=P.nodes().map(F=>{let D={};return P.outEdges(F).forEach(_=>{D[_.w]=(D[_.w]||0)+P.edge(_).weight}),D});return X(P.nodes(),q)}function f(P){let q=P.nodes().map(F=>{let D={};return P.inEdges(F).forEach(_=>{D[_.v]=(D[_.v]||0)+P.edge(_).weight}),D});return X(P.nodes(),q)}function m(P,q){let F=P.x,D=P.y,_=q.x-F,I=q.y-D,A=P.width/2,G=P.height/2;if(!_&&!I)throw new Error("Not possible to find intersection inside of the rectangle");let U,K;return Math.abs(I)*A>Math.abs(_)*G?(I<0&&(G=-G),U=G*_/I,K=G):(_<0&&(A=-A),U=A,K=A*I/_),{x:F+U,y:D+K}}function h(P){let q=M(T(P)+1).map(()=>[]);return P.nodes().forEach(F=>{let D=P.node(F),_=D.rank;_!==void 0&&(q[_][D.order]=F)}),q}function x(P){let q=P.nodes().map(D=>{let _=P.node(D).rank;return _===void 0?Number.MAX_VALUE:_}),F=S(Math.min,q);P.nodes().forEach(D=>{let _=P.node(D);Object.hasOwn(_,"rank")&&(_.rank-=F)})}function g(P){let q=P.nodes().map(A=>P.node(A).rank).filter(A=>A!==void 0),F=S(Math.min,q),D=[];P.nodes().forEach(A=>{let G=P.node(A).rank-F;D[G]||(D[G]=[]),D[G].push(A)});let _=0,I=P.graph().nodeRankFactor;Array.from(D).forEach((A,G)=>{A===void 0&&G%I!==0?--_:A!==void 0&&_&&A.forEach(U=>P.node(U).rank+=_)})}function b(P,q,F,D){let _={width:0,height:0};return arguments.length>=4&&(_.rank=F,_.order=D),i(P,"border",_,q)}function p(P,q=w){let F=[];for(let D=0;D<P.length;D+=q){let _=P.slice(D,D+q);F.push(_)}return F}var w=65535;function S(P,q){if(q.length>w){let F=p(q);return P.apply(null,F.map(D=>P.apply(null,D)))}else return P.apply(null,q)}function T(P){let q=P.nodes().map(F=>{let D=P.node(F).rank;return D===void 0?Number.MIN_VALUE:D});return S(Math.max,q)}function E(P,q){let F={lhs:[],rhs:[]};return P.forEach(D=>{q(D)?F.lhs.push(D):F.rhs.push(D)}),F}function C(P,q){let F=Date.now();try{return q()}finally{console.log(P+" time: "+(Date.now()-F)+"ms")}}function N(P,q){return q()}var k=0;function H(P){var q=++k;return P+(""+q)}function M(P,q,F=1){q==null&&(q=P,P=0);let D=I=>I<q;F<0&&(D=I=>q<I);let _=[];for(let I=P;D(I);I+=F)_.push(I);return _}function Y(P,q){let F={};for(let D of q)P[D]!==void 0&&(F[D]=P[D]);return F}function $(P,q){let F=q;return typeof q=="string"&&(F=D=>D[q]),Object.entries(P).reduce((D,[_,I])=>(D[_]=F(I,_),D),{})}function X(P,q){return P.reduce((F,D,_)=>(F[D]=q[_],F),{})}}),hz=Wt((e,r)=>{var s=fz(),i=Hn().uniqueId;r.exports={run:o,undo:u};function o(f){(f.graph().acyclicer==="greedy"?s(f,m(f)):c(f)).forEach(h=>{let x=f.edge(h);f.removeEdge(h),x.forwardName=h.name,x.reversed=!0,f.setEdge(h.w,h.v,x,i("rev"))});function m(h){return x=>h.edge(x).weight}}function c(f){let m=[],h={},x={};function g(b){Object.hasOwn(x,b)||(x[b]=!0,h[b]=!0,f.outEdges(b).forEach(p=>{Object.hasOwn(h,p.w)?m.push(p):g(p.w)}),delete h[b])}return f.nodes().forEach(g),m}function u(f){f.edges().forEach(m=>{let h=f.edge(m);if(h.reversed){f.removeEdge(m);let x=h.forwardName;delete h.reversed,delete h.forwardName,f.setEdge(m.w,m.v,h,x)}})}}),mz=Wt((e,r)=>{var s=Hn();r.exports={run:i,undo:c};function i(u){u.graph().dummyChains=[],u.edges().forEach(f=>o(u,f))}function o(u,f){let m=f.v,h=u.node(m).rank,x=f.w,g=u.node(x).rank,b=f.name,p=u.edge(f),w=p.labelRank;if(g===h+1)return;u.removeEdge(f);let S,T,E;for(E=0,++h;h<g;++E,++h)p.points=[],T={width:0,height:0,edgeLabel:p,edgeObj:f,rank:h},S=s.addDummyNode(u,"edge",T,"_d"),h===w&&(T.width=p.width,T.height=p.height,T.dummy="edge-label",T.labelpos=p.labelpos),u.setEdge(m,S,{weight:p.weight},b),E===0&&u.graph().dummyChains.push(S),m=S;u.setEdge(m,x,{weight:p.weight},b)}function c(u){u.graph().dummyChains.forEach(f=>{let m=u.node(f),h=m.edgeLabel,x;for(u.setEdge(m.edgeObj,h);m.dummy;)x=u.successors(f)[0],u.removeNode(f),h.points.push({x:m.x,y:m.y}),m.dummy==="edge-label"&&(h.x=m.x,h.y=m.y,h.width=m.width,h.height=m.height),f=x,m=u.node(f)})}}),Iu=Wt((e,r)=>{var{applyWithChunking:s}=Hn();r.exports={longestPath:i,slack:o};function i(c){var u={};function f(m){var h=c.node(m);if(Object.hasOwn(u,m))return h.rank;u[m]=!0;let x=c.outEdges(m).map(b=>b==null?Number.POSITIVE_INFINITY:f(b.w)-c.edge(b).minlen);var g=s(Math.min,x);return g===Number.POSITIVE_INFINITY&&(g=0),h.rank=g}c.sources().forEach(f)}function o(c,u){return c.node(u.w).rank-c.node(u.v).rank-c.edge(u).minlen}}),sN=Wt((e,r)=>{var s=ns().Graph,i=Iu().slack;r.exports=o;function o(m){var h=new s({directed:!1}),x=m.nodes()[0],g=m.nodeCount();h.setNode(x,{});for(var b,p;c(h,m)<g;)b=u(h,m),p=h.hasNode(b.v)?i(m,b):-i(m,b),f(h,m,p);return h}function c(m,h){function x(g){h.nodeEdges(g).forEach(b=>{var p=b.v,w=g===p?b.w:p;!m.hasNode(w)&&!i(h,b)&&(m.setNode(w,{}),m.setEdge(g,w,{}),x(w))})}return m.nodes().forEach(x),m.nodeCount()}function u(m,h){return h.edges().reduce((x,g)=>{let b=Number.POSITIVE_INFINITY;return m.hasNode(g.v)!==m.hasNode(g.w)&&(b=i(h,g)),b<x[0]?[b,g]:x},[Number.POSITIVE_INFINITY,null])[1]}function f(m,h,x){m.nodes().forEach(g=>h.node(g).rank+=x)}}),xz=Wt((e,r)=>{var s=sN(),i=Iu().slack,o=Iu().longestPath,c=ns().alg.preorder,u=ns().alg.postorder,f=Hn().simplify;r.exports=m,m.initLowLimValues=b,m.initCutValues=h,m.calcCutValue=g,m.leaveEdge=w,m.enterEdge=S,m.exchangeEdges=T;function m(k){k=f(k),o(k);var H=s(k);b(H),h(H,k);for(var M,Y;M=w(H);)Y=S(H,k,M),T(H,k,M,Y)}function h(k,H){var M=u(k,k.nodes());M=M.slice(0,M.length-1),M.forEach(Y=>x(k,H,Y))}function x(k,H,M){var Y=k.node(M),$=Y.parent;k.edge(M,$).cutvalue=g(k,H,M)}function g(k,H,M){var Y=k.node(M),$=Y.parent,X=!0,P=H.edge(M,$),q=0;return P||(X=!1,P=H.edge($,M)),q=P.weight,H.nodeEdges(M).forEach(F=>{var D=F.v===M,_=D?F.w:F.v;if(_!==$){var I=D===X,A=H.edge(F).weight;if(q+=I?A:-A,C(k,M,_)){var G=k.edge(M,_).cutvalue;q+=I?-G:G}}}),q}function b(k,H){arguments.length<2&&(H=k.nodes()[0]),p(k,{},1,H)}function p(k,H,M,Y,$){var X=M,P=k.node(Y);return H[Y]=!0,k.neighbors(Y).forEach(q=>{Object.hasOwn(H,q)||(M=p(k,H,M,q,Y))}),P.low=X,P.lim=M++,$?P.parent=$:delete P.parent,M}function w(k){return k.edges().find(H=>k.edge(H).cutvalue<0)}function S(k,H,M){var Y=M.v,$=M.w;H.hasEdge(Y,$)||(Y=M.w,$=M.v);var X=k.node(Y),P=k.node($),q=X,F=!1;X.lim>P.lim&&(q=P,F=!0);var D=H.edges().filter(_=>F===N(k,k.node(_.v),q)&&F!==N(k,k.node(_.w),q));return D.reduce((_,I)=>i(H,I)<i(H,_)?I:_)}function T(k,H,M,Y){var $=M.v,X=M.w;k.removeEdge($,X),k.setEdge(Y.v,Y.w,{}),b(k),h(k,H),E(k,H)}function E(k,H){var M=k.nodes().find($=>!H.node($).parent),Y=c(k,M);Y=Y.slice(1),Y.forEach($=>{var X=k.node($).parent,P=H.edge($,X),q=!1;P||(P=H.edge(X,$),q=!0),H.node($).rank=H.node(X).rank+(q?P.minlen:-P.minlen)})}function C(k,H,M){return k.hasEdge(H,M)}function N(k,H,M){return M.low<=H.lim&&H.lim<=M.lim}}),gz=Wt((e,r)=>{var s=Iu(),i=s.longestPath,o=sN(),c=xz();r.exports=u;function u(x){var g=x.graph().ranker;if(g instanceof Function)return g(x);switch(x.graph().ranker){case"network-simplex":h(x);break;case"tight-tree":m(x);break;case"longest-path":f(x);break;case"none":break;default:h(x)}}var f=i;function m(x){i(x),o(x)}function h(x){c(x)}}),pz=Wt((e,r)=>{r.exports=s;function s(c){let u=o(c);c.graph().dummyChains.forEach(f=>{let m=c.node(f),h=m.edgeObj,x=i(c,u,h.v,h.w),g=x.path,b=x.lca,p=0,w=g[p],S=!0;for(;f!==h.w;){if(m=c.node(f),S){for(;(w=g[p])!==b&&c.node(w).maxRank<m.rank;)p++;w===b&&(S=!1)}if(!S){for(;p<g.length-1&&c.node(w=g[p+1]).minRank<=m.rank;)p++;w=g[p]}c.setParent(f,w),f=c.successors(f)[0]}})}function i(c,u,f,m){let h=[],x=[],g=Math.min(u[f].low,u[m].low),b=Math.max(u[f].lim,u[m].lim),p,w;p=f;do p=c.parent(p),h.push(p);while(p&&(u[p].low>g||b>u[p].lim));for(w=p,p=m;(p=c.parent(p))!==w;)x.push(p);return{path:h.concat(x.reverse()),lca:w}}function o(c){let u={},f=0;function m(h){let x=f;c.children(h).forEach(m),u[h]={low:x,lim:f++}}return c.children().forEach(m),u}}),bz=Wt((e,r)=>{var s=Hn();r.exports={run:i,cleanup:f};function i(m){let h=s.addDummyNode(m,"root",{},"_root"),x=c(m),g=Object.values(x),b=s.applyWithChunking(Math.max,g)-1,p=2*b+1;m.graph().nestingRoot=h,m.edges().forEach(S=>m.edge(S).minlen*=p);let w=u(m)+1;m.children().forEach(S=>o(m,h,p,w,b,x,S)),m.graph().nodeRankFactor=p}function o(m,h,x,g,b,p,w){let S=m.children(w);if(!S.length){w!==h&&m.setEdge(h,w,{weight:0,minlen:x});return}let T=s.addBorderNode(m,"_bt"),E=s.addBorderNode(m,"_bb"),C=m.node(w);m.setParent(T,w),C.borderTop=T,m.setParent(E,w),C.borderBottom=E,S.forEach(N=>{o(m,h,x,g,b,p,N);let k=m.node(N),H=k.borderTop?k.borderTop:N,M=k.borderBottom?k.borderBottom:N,Y=k.borderTop?g:2*g,$=H!==M?1:b-p[w]+1;m.setEdge(T,H,{weight:Y,minlen:$,nestingEdge:!0}),m.setEdge(M,E,{weight:Y,minlen:$,nestingEdge:!0})}),m.parent(w)||m.setEdge(h,T,{weight:0,minlen:b+p[w]})}function c(m){var h={};function x(g,b){var p=m.children(g);p&&p.length&&p.forEach(w=>x(w,b+1)),h[g]=b}return m.children().forEach(g=>x(g,1)),h}function u(m){return m.edges().reduce((h,x)=>h+m.edge(x).weight,0)}function f(m){var h=m.graph();m.removeNode(h.nestingRoot),delete h.nestingRoot,m.edges().forEach(x=>{var g=m.edge(x);g.nestingEdge&&m.removeEdge(x)})}}),yz=Wt((e,r)=>{var s=Hn();r.exports=i;function i(c){function u(f){let m=c.children(f),h=c.node(f);if(m.length&&m.forEach(u),Object.hasOwn(h,"minRank")){h.borderLeft=[],h.borderRight=[];for(let x=h.minRank,g=h.maxRank+1;x<g;++x)o(c,"borderLeft","_bl",f,h,x),o(c,"borderRight","_br",f,h,x)}}c.children().forEach(u)}function o(c,u,f,m,h,x){let g={width:0,height:0,rank:x,borderType:u},b=h[u][x-1],p=s.addDummyNode(c,"border",g,f);h[u][x]=p,c.setParent(p,m),b&&c.setEdge(b,p,{weight:1})}}),vz=Wt((e,r)=>{r.exports={adjust:s,undo:i};function s(x){let g=x.graph().rankdir.toLowerCase();(g==="lr"||g==="rl")&&o(x)}function i(x){let g=x.graph().rankdir.toLowerCase();(g==="bt"||g==="rl")&&u(x),(g==="lr"||g==="rl")&&(m(x),o(x))}function o(x){x.nodes().forEach(g=>c(x.node(g))),x.edges().forEach(g=>c(x.edge(g)))}function c(x){let g=x.width;x.width=x.height,x.height=g}function u(x){x.nodes().forEach(g=>f(x.node(g))),x.edges().forEach(g=>{let b=x.edge(g);b.points.forEach(f),Object.hasOwn(b,"y")&&f(b)})}function f(x){x.y=-x.y}function m(x){x.nodes().forEach(g=>h(x.node(g))),x.edges().forEach(g=>{let b=x.edge(g);b.points.forEach(h),Object.hasOwn(b,"x")&&h(b)})}function h(x){let g=x.x;x.x=x.y,x.y=g}}),jz=Wt((e,r)=>{var s=Hn();r.exports=i;function i(o){let c={},u=o.nodes().filter(g=>!o.children(g).length),f=u.map(g=>o.node(g).rank),m=s.applyWithChunking(Math.max,f),h=s.range(m+1).map(()=>[]);function x(g){if(c[g])return;c[g]=!0;let b=o.node(g);h[b.rank].push(g),o.successors(g).forEach(x)}return u.sort((g,b)=>o.node(g).rank-o.node(b).rank).forEach(x),h}}),wz=Wt((e,r)=>{var s=Hn().zipObject;r.exports=i;function i(c,u){let f=0;for(let m=1;m<u.length;++m)f+=o(c,u[m-1],u[m]);return f}function o(c,u,f){let m=s(f,f.map((w,S)=>S)),h=u.flatMap(w=>c.outEdges(w).map(S=>({pos:m[S.w],weight:c.edge(S).weight})).sort((S,T)=>S.pos-T.pos)),x=1;for(;x<f.length;)x<<=1;let g=2*x-1;x-=1;let b=new Array(g).fill(0),p=0;return h.forEach(w=>{let S=w.pos+x;b[S]+=w.weight;let T=0;for(;S>0;)S%2&&(T+=b[S+1]),S=S-1>>1,b[S]+=w.weight;p+=w.weight*T}),p}}),Nz=Wt((e,r)=>{r.exports=s;function s(i,o=[]){return o.map(c=>{let u=i.inEdges(c);if(u.length){let f=u.reduce((m,h)=>{let x=i.edge(h),g=i.node(h.v);return{sum:m.sum+x.weight*g.order,weight:m.weight+x.weight}},{sum:0,weight:0});return{v:c,barycenter:f.sum/f.weight,weight:f.weight}}else return{v:c}})}}),kz=Wt((e,r)=>{var s=Hn();r.exports=i;function i(u,f){let m={};u.forEach((x,g)=>{let b=m[x.v]={indegree:0,in:[],out:[],vs:[x.v],i:g};x.barycenter!==void 0&&(b.barycenter=x.barycenter,b.weight=x.weight)}),f.edges().forEach(x=>{let g=m[x.v],b=m[x.w];g!==void 0&&b!==void 0&&(b.indegree++,g.out.push(m[x.w]))});let h=Object.values(m).filter(x=>!x.indegree);return o(h)}function o(u){let f=[];function m(x){return g=>{g.merged||(g.barycenter===void 0||x.barycenter===void 0||g.barycenter>=x.barycenter)&&c(x,g)}}function h(x){return g=>{g.in.push(x),--g.indegree===0&&u.push(g)}}for(;u.length;){let x=u.pop();f.push(x),x.in.reverse().forEach(m(x)),x.out.forEach(h(x))}return f.filter(x=>!x.merged).map(x=>s.pick(x,["vs","i","barycenter","weight"]))}function c(u,f){let m=0,h=0;u.weight&&(m+=u.barycenter*u.weight,h+=u.weight),f.weight&&(m+=f.barycenter*f.weight,h+=f.weight),u.vs=f.vs.concat(u.vs),u.barycenter=m/h,u.weight=h,u.i=Math.min(f.i,u.i),f.merged=!0}}),Sz=Wt((e,r)=>{var s=Hn();r.exports=i;function i(u,f){let m=s.partition(u,T=>Object.hasOwn(T,"barycenter")),h=m.lhs,x=m.rhs.sort((T,E)=>E.i-T.i),g=[],b=0,p=0,w=0;h.sort(c(!!f)),w=o(g,x,w),h.forEach(T=>{w+=T.vs.length,g.push(T.vs),b+=T.barycenter*T.weight,p+=T.weight,w=o(g,x,w)});let S={vs:g.flat(!0)};return p&&(S.barycenter=b/p,S.weight=p),S}function o(u,f,m){let h;for(;f.length&&(h=f[f.length-1]).i<=m;)f.pop(),u.push(h.vs),m++;return m}function c(u){return(f,m)=>f.barycenter<m.barycenter?-1:f.barycenter>m.barycenter?1:u?m.i-f.i:f.i-m.i}}),Cz=Wt((e,r)=>{var s=Nz(),i=kz(),o=Sz();r.exports=c;function c(m,h,x,g){let b=m.children(h),p=m.node(h),w=p?p.borderLeft:void 0,S=p?p.borderRight:void 0,T={};w&&(b=b.filter(k=>k!==w&&k!==S));let E=s(m,b);E.forEach(k=>{if(m.children(k.v).length){let H=c(m,k.v,x,g);T[k.v]=H,Object.hasOwn(H,"barycenter")&&f(k,H)}});let C=i(E,x);u(C,T);let N=o(C,g);if(w&&(N.vs=[w,N.vs,S].flat(!0),m.predecessors(w).length)){let k=m.node(m.predecessors(w)[0]),H=m.node(m.predecessors(S)[0]);Object.hasOwn(N,"barycenter")||(N.barycenter=0,N.weight=0),N.barycenter=(N.barycenter*N.weight+k.order+H.order)/(N.weight+2),N.weight+=2}return N}function u(m,h){m.forEach(x=>{x.vs=x.vs.flatMap(g=>h[g]?h[g].vs:g)})}function f(m,h){m.barycenter!==void 0?(m.barycenter=(m.barycenter*m.weight+h.barycenter*h.weight)/(m.weight+h.weight),m.weight+=h.weight):(m.barycenter=h.barycenter,m.weight=h.weight)}}),Ez=Wt((e,r)=>{var s=ns().Graph,i=Hn();r.exports=o;function o(u,f,m,h){h||(h=u.nodes());let x=c(u),g=new s({compound:!0}).setGraph({root:x}).setDefaultNodeLabel(b=>u.node(b));return h.forEach(b=>{let p=u.node(b),w=u.parent(b);(p.rank===f||p.minRank<=f&&f<=p.maxRank)&&(g.setNode(b),g.setParent(b,w||x),u[m](b).forEach(S=>{let T=S.v===b?S.w:S.v,E=g.edge(T,b),C=E!==void 0?E.weight:0;g.setEdge(T,b,{weight:u.edge(S).weight+C})}),Object.hasOwn(p,"minRank")&&g.setNode(b,{borderLeft:p.borderLeft[f],borderRight:p.borderRight[f]}))}),g}function c(u){for(var f;u.hasNode(f=i.uniqueId("_root")););return f}}),Tz=Wt((e,r)=>{r.exports=s;function s(i,o,c){let u={},f;c.forEach(m=>{let h=i.parent(m),x,g;for(;h;){if(x=i.parent(h),x?(g=u[x],u[x]=h):(g=f,f=h),g&&g!==h){o.setEdge(g,h);return}h=x}})}}),_z=Wt((e,r)=>{var s=jz(),i=wz(),o=Cz(),c=Ez(),u=Tz(),f=ns().Graph,m=Hn();r.exports=h;function h(p,w={}){if(typeof w.customOrder=="function"){w.customOrder(p,h);return}let S=m.maxRank(p),T=x(p,m.range(1,S+1),"inEdges"),E=x(p,m.range(S-1,-1,-1),"outEdges"),C=s(p);if(b(p,C),w.disableOptimalOrderHeuristic)return;let N=Number.POSITIVE_INFINITY,k,H=w.constraints||[];for(let M=0,Y=0;Y<4;++M,++Y){g(M%2?T:E,M%4>=2,H),C=m.buildLayerMatrix(p);let $=i(p,C);$<N?(Y=0,k=Object.assign({},C),N=$):$===N&&(k=structuredClone(C))}b(p,k)}function x(p,w,S){let T=new Map,E=(C,N)=>{T.has(C)||T.set(C,[]),T.get(C).push(N)};for(let C of p.nodes()){let N=p.node(C);if(typeof N.rank=="number"&&E(N.rank,C),typeof N.minRank=="number"&&typeof N.maxRank=="number")for(let k=N.minRank;k<=N.maxRank;k++)k!==N.rank&&E(k,C)}return w.map(function(C){return c(p,C,S,T.get(C)||[])})}function g(p,w,S){let T=new f;p.forEach(function(E){S.forEach(k=>T.setEdge(k.left,k.right));let C=E.graph().root,N=o(E,C,T,w);N.vs.forEach((k,H)=>E.node(k).order=H),u(E,T,N.vs)})}function b(p,w){Object.values(w).forEach(S=>S.forEach((T,E)=>p.node(T).order=E))}}),Az=Wt((e,r)=>{var s=ns().Graph,i=Hn();r.exports={positionX:S,findType1Conflicts:o,findType2Conflicts:c,addConflict:f,hasConflict:m,verticalAlignment:h,horizontalCompaction:x,alignCoordinates:p,findSmallestWidthAlignment:b,balance:w};function o(C,N){let k={};function H(M,Y){let $=0,X=0,P=M.length,q=Y[Y.length-1];return Y.forEach((F,D)=>{let _=u(C,F),I=_?C.node(_).order:P;(_||F===q)&&(Y.slice(X,D+1).forEach(A=>{C.predecessors(A).forEach(G=>{let U=C.node(G),K=U.order;(K<$||I<K)&&!(U.dummy&&C.node(A).dummy)&&f(k,G,A)})}),X=D+1,$=I)}),Y}return N.length&&N.reduce(H),k}function c(C,N){let k={};function H(Y,$,X,P,q){let F;i.range($,X).forEach(D=>{F=Y[D],C.node(F).dummy&&C.predecessors(F).forEach(_=>{let I=C.node(_);I.dummy&&(I.order<P||I.order>q)&&f(k,_,F)})})}function M(Y,$){let X=-1,P,q=0;return $.forEach((F,D)=>{if(C.node(F).dummy==="border"){let _=C.predecessors(F);_.length&&(P=C.node(_[0]).order,H($,q,D,X,P),q=D,X=P)}H($,q,$.length,P,Y.length)}),$}return N.length&&N.reduce(M),k}function u(C,N){if(C.node(N).dummy)return C.predecessors(N).find(k=>C.node(k).dummy)}function f(C,N,k){if(N>k){let M=N;N=k,k=M}let H=C[N];H||(C[N]=H={}),H[k]=!0}function m(C,N,k){if(N>k){let H=N;N=k,k=H}return!!C[N]&&Object.hasOwn(C[N],k)}function h(C,N,k,H){let M={},Y={},$={};return N.forEach(X=>{X.forEach((P,q)=>{M[P]=P,Y[P]=P,$[P]=q})}),N.forEach(X=>{let P=-1;X.forEach(q=>{let F=H(q);if(F.length){F=F.sort((_,I)=>$[_]-$[I]);let D=(F.length-1)/2;for(let _=Math.floor(D),I=Math.ceil(D);_<=I;++_){let A=F[_];Y[q]===q&&P<$[A]&&!m(k,q,A)&&(Y[A]=q,Y[q]=M[q]=M[A],P=$[A])}}})}),{root:M,align:Y}}function x(C,N,k,H,M){let Y={},$=g(C,N,k,M),X=M?"borderLeft":"borderRight";function P(D,_){let I=$.nodes().slice(),A={},G=I.pop();for(;G;){if(A[G])D(G);else{A[G]=!0,I.push(G);for(let U of _(G))I.push(U)}G=I.pop()}}function q(D){Y[D]=$.inEdges(D).reduce((_,I)=>Math.max(_,Y[I.v]+$.edge(I)),0)}function F(D){let _=$.outEdges(D).reduce((A,G)=>Math.min(A,Y[G.w]-$.edge(G)),Number.POSITIVE_INFINITY),I=C.node(D);_!==Number.POSITIVE_INFINITY&&I.borderType!==X&&(Y[D]=Math.max(Y[D],_))}return P(q,$.predecessors.bind($)),P(F,$.successors.bind($)),Object.keys(H).forEach(D=>Y[D]=Y[k[D]]),Y}function g(C,N,k,H){let M=new s,Y=C.graph(),$=T(Y.nodesep,Y.edgesep,H);return N.forEach(X=>{let P;X.forEach(q=>{let F=k[q];if(M.setNode(F),P){var D=k[P],_=M.edge(D,F);M.setEdge(D,F,Math.max($(C,q,P),_||0))}P=q})}),M}function b(C,N){return Object.values(N).reduce((k,H)=>{let M=Number.NEGATIVE_INFINITY,Y=Number.POSITIVE_INFINITY;Object.entries(H).forEach(([X,P])=>{let q=E(C,X)/2;M=Math.max(P+q,M),Y=Math.min(P-q,Y)});let $=M-Y;return $<k[0]&&(k=[$,H]),k},[Number.POSITIVE_INFINITY,null])[1]}function p(C,N){let k=Object.values(N),H=i.applyWithChunking(Math.min,k),M=i.applyWithChunking(Math.max,k);["u","d"].forEach(Y=>{["l","r"].forEach($=>{let X=Y+$,P=C[X];if(P===N)return;let q=Object.values(P),F=H-i.applyWithChunking(Math.min,q);$!=="l"&&(F=M-i.applyWithChunking(Math.max,q)),F&&(C[X]=i.mapValues(P,D=>D+F))})})}function w(C,N){return i.mapValues(C.ul,(k,H)=>{if(N)return C[N.toLowerCase()][H];{let M=Object.values(C).map(Y=>Y[H]).sort((Y,$)=>Y-$);return(M[1]+M[2])/2}})}function S(C){let N=i.buildLayerMatrix(C),k=Object.assign(o(C,N),c(C,N)),H={},M;["u","d"].forEach($=>{M=$==="u"?N:Object.values(N).reverse(),["l","r"].forEach(X=>{X==="r"&&(M=M.map(D=>Object.values(D).reverse()));let P=($==="u"?C.predecessors:C.successors).bind(C),q=h(C,M,k,P),F=x(C,M,q.root,q.align,X==="r");X==="r"&&(F=i.mapValues(F,D=>-D)),H[$+X]=F})});let Y=b(C,H);return p(H,Y),w(H,C.graph().align)}function T(C,N,k){return(H,M,Y)=>{let $=H.node(M),X=H.node(Y),P=0,q;if(P+=$.width/2,Object.hasOwn($,"labelpos"))switch($.labelpos.toLowerCase()){case"l":q=-$.width/2;break;case"r":q=$.width/2;break}if(q&&(P+=k?q:-q),q=0,P+=($.dummy?N:C)/2,P+=(X.dummy?N:C)/2,P+=X.width/2,Object.hasOwn(X,"labelpos"))switch(X.labelpos.toLowerCase()){case"l":q=X.width/2;break;case"r":q=-X.width/2;break}return q&&(P+=k?q:-q),q=0,P}}function E(C,N){return C.node(N).width}}),Mz=Wt((e,r)=>{var s=Hn(),i=Az().positionX;r.exports=o;function o(u){u=s.asNonCompoundGraph(u),c(u),Object.entries(i(u)).forEach(([f,m])=>u.node(f).x=m)}function c(u){let f=s.buildLayerMatrix(u),m=u.graph().ranksep,h=u.graph().rankalign,x=0;f.forEach(g=>{let b=g.reduce((p,w)=>{let S=u.node(w).height;return p>S?p:S},0);g.forEach(p=>{let w=u.node(p);h==="top"?w.y=x+w.height/2:h==="bottom"?w.y=x+b-w.height/2:w.y=x+b/2}),x+=b+m})}}),Dz=Wt((e,r)=>{var s=hz(),i=mz(),o=gz(),c=Hn().normalizeRanks,u=pz(),f=Hn().removeEmptyRanks,m=bz(),h=yz(),x=vz(),g=_z(),b=Mz(),p=Hn(),w=ns().Graph;r.exports=S;function S(V,Q={}){let te=Q.debugTiming?p.time:p.notime;return te("layout",()=>{let Z=te(" buildLayoutGraph",()=>P(V));return te(" runLayout",()=>T(Z,te,Q)),te(" updateInputGraph",()=>E(V,Z)),Z})}function T(V,Q,te){Q(" makeSpaceForEdgeLabels",()=>q(V)),Q(" removeSelfEdges",()=>B(V)),Q(" acyclic",()=>s.run(V)),Q(" nestingGraph.run",()=>m.run(V)),Q(" rank",()=>o(p.asNonCompoundGraph(V))),Q(" injectEdgeLabelProxies",()=>F(V)),Q(" removeEmptyRanks",()=>f(V)),Q(" nestingGraph.cleanup",()=>m.cleanup(V)),Q(" normalizeRanks",()=>c(V)),Q(" assignRankMinMax",()=>D(V)),Q(" removeEdgeLabelProxies",()=>_(V)),Q(" normalize.run",()=>i.run(V)),Q(" parentDummyChains",()=>u(V)),Q(" addBorderSegments",()=>h(V)),Q(" order",()=>g(V,te)),Q(" insertSelfEdges",()=>L(V)),Q(" adjustCoordinateSystem",()=>x.adjust(V)),Q(" position",()=>b(V)),Q(" positionSelfEdges",()=>W(V)),Q(" removeBorderNodes",()=>K(V)),Q(" normalize.undo",()=>i.undo(V)),Q(" fixupEdgeLabelCoords",()=>G(V)),Q(" undoCoordinateSystem",()=>x.undo(V)),Q(" translateGraph",()=>I(V)),Q(" assignNodeIntersects",()=>A(V)),Q(" reversePoints",()=>U(V)),Q(" acyclic.undo",()=>s.undo(V))}function E(V,Q){V.nodes().forEach(te=>{let Z=V.node(te),ee=Q.node(te);Z&&(Z.x=ee.x,Z.y=ee.y,Z.order=ee.order,Z.rank=ee.rank,Q.children(te).length&&(Z.width=ee.width,Z.height=ee.height))}),V.edges().forEach(te=>{let Z=V.edge(te),ee=Q.edge(te);Z.points=ee.points,Object.hasOwn(ee,"x")&&(Z.x=ee.x,Z.y=ee.y)}),V.graph().width=Q.graph().width,V.graph().height=Q.graph().height}var C=["nodesep","edgesep","ranksep","marginx","marginy"],N={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},k=["acyclicer","ranker","rankdir","align","rankalign"],H=["width","height","rank"],M={width:0,height:0},Y=["minlen","weight","width","height","labeloffset"],$={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},X=["labelpos"];function P(V){let Q=new w({multigraph:!0,compound:!0}),te=z(V.graph());return Q.setGraph(Object.assign({},N,R(te,C),p.pick(te,k))),V.nodes().forEach(Z=>{let ee=z(V.node(Z)),ie=R(ee,H);Object.keys(M).forEach(je=>{ie[je]===void 0&&(ie[je]=M[je])}),Q.setNode(Z,ie),Q.setParent(Z,V.parent(Z))}),V.edges().forEach(Z=>{let ee=z(V.edge(Z));Q.setEdge(Z,Object.assign({},$,R(ee,Y),p.pick(ee,X)))}),Q}function q(V){let Q=V.graph();Q.ranksep/=2,V.edges().forEach(te=>{let Z=V.edge(te);Z.minlen*=2,Z.labelpos.toLowerCase()!=="c"&&(Q.rankdir==="TB"||Q.rankdir==="BT"?Z.width+=Z.labeloffset:Z.height+=Z.labeloffset)})}function F(V){V.edges().forEach(Q=>{let te=V.edge(Q);if(te.width&&te.height){let Z=V.node(Q.v),ee={rank:(V.node(Q.w).rank-Z.rank)/2+Z.rank,e:Q};p.addDummyNode(V,"edge-proxy",ee,"_ep")}})}function D(V){let Q=0;V.nodes().forEach(te=>{let Z=V.node(te);Z.borderTop&&(Z.minRank=V.node(Z.borderTop).rank,Z.maxRank=V.node(Z.borderBottom).rank,Q=Math.max(Q,Z.maxRank))}),V.graph().maxRank=Q}function _(V){V.nodes().forEach(Q=>{let te=V.node(Q);te.dummy==="edge-proxy"&&(V.edge(te.e).labelRank=te.rank,V.removeNode(Q))})}function I(V){let Q=Number.POSITIVE_INFINITY,te=0,Z=Number.POSITIVE_INFINITY,ee=0,ie=V.graph(),je=ie.marginx||0,ke=ie.marginy||0;function De(Ie){let ze=Ie.x,Ze=Ie.y,Ae=Ie.width,We=Ie.height;Q=Math.min(Q,ze-Ae/2),te=Math.max(te,ze+Ae/2),Z=Math.min(Z,Ze-We/2),ee=Math.max(ee,Ze+We/2)}V.nodes().forEach(Ie=>De(V.node(Ie))),V.edges().forEach(Ie=>{let ze=V.edge(Ie);Object.hasOwn(ze,"x")&&De(ze)}),Q-=je,Z-=ke,V.nodes().forEach(Ie=>{let ze=V.node(Ie);ze.x-=Q,ze.y-=Z}),V.edges().forEach(Ie=>{let ze=V.edge(Ie);ze.points.forEach(Ze=>{Ze.x-=Q,Ze.y-=Z}),Object.hasOwn(ze,"x")&&(ze.x-=Q),Object.hasOwn(ze,"y")&&(ze.y-=Z)}),ie.width=te-Q+je,ie.height=ee-Z+ke}function A(V){V.edges().forEach(Q=>{let te=V.edge(Q),Z=V.node(Q.v),ee=V.node(Q.w),ie,je;te.points?(ie=te.points[0],je=te.points[te.points.length-1]):(te.points=[],ie=ee,je=Z),te.points.unshift(p.intersectRect(Z,ie)),te.points.push(p.intersectRect(ee,je))})}function G(V){V.edges().forEach(Q=>{let te=V.edge(Q);if(Object.hasOwn(te,"x"))switch((te.labelpos==="l"||te.labelpos==="r")&&(te.width-=te.labeloffset),te.labelpos){case"l":te.x-=te.width/2+te.labeloffset;break;case"r":te.x+=te.width/2+te.labeloffset;break}})}function U(V){V.edges().forEach(Q=>{let te=V.edge(Q);te.reversed&&te.points.reverse()})}function K(V){V.nodes().forEach(Q=>{if(V.children(Q).length){let te=V.node(Q),Z=V.node(te.borderTop),ee=V.node(te.borderBottom),ie=V.node(te.borderLeft[te.borderLeft.length-1]),je=V.node(te.borderRight[te.borderRight.length-1]);te.width=Math.abs(je.x-ie.x),te.height=Math.abs(ee.y-Z.y),te.x=ie.x+te.width/2,te.y=Z.y+te.height/2}}),V.nodes().forEach(Q=>{V.node(Q).dummy==="border"&&V.removeNode(Q)})}function B(V){V.edges().forEach(Q=>{if(Q.v===Q.w){var te=V.node(Q.v);te.selfEdges||(te.selfEdges=[]),te.selfEdges.push({e:Q,label:V.edge(Q)}),V.removeEdge(Q)}})}function L(V){var Q=p.buildLayerMatrix(V);Q.forEach(te=>{var Z=0;te.forEach((ee,ie)=>{var je=V.node(ee);je.order=ie+Z,(je.selfEdges||[]).forEach(ke=>{p.addDummyNode(V,"selfedge",{width:ke.label.width,height:ke.label.height,rank:je.rank,order:ie+ ++Z,e:ke.e,label:ke.label},"_se")}),delete je.selfEdges})})}function W(V){V.nodes().forEach(Q=>{var te=V.node(Q);if(te.dummy==="selfedge"){var Z=V.node(te.e.v),ee=Z.x+Z.width/2,ie=Z.y,je=te.x-ee,ke=Z.height/2;V.setEdge(te.e,te.label),V.removeNode(Q),te.label.points=[{x:ee+2*je/3,y:ie-ke},{x:ee+5*je/6,y:ie-ke},{x:ee+je,y:ie},{x:ee+5*je/6,y:ie+ke},{x:ee+2*je/3,y:ie+ke}],te.label.x=te.x,te.label.y=te.y}})}function R(V,Q){return p.mapValues(p.pick(V,Q),Number)}function z(V){var Q={};return V&&Object.entries(V).forEach(([te,Z])=>{typeof te=="string"&&(te=te.toLowerCase()),Q[te]=Z}),Q}}),Oz=Wt((e,r)=>{var s=Hn(),i=ns().Graph;r.exports={debugOrdering:o};function o(c){let u=s.buildLayerMatrix(c),f=new i({compound:!0,multigraph:!0}).setGraph({});return c.nodes().forEach(m=>{f.setNode(m,{label:m}),f.setParent(m,"layer"+c.node(m).rank)}),c.edges().forEach(m=>f.setEdge(m.v,m.w,{},m.name)),u.forEach((m,h)=>{let x="layer"+h;f.setNode(x,{rank:"same"}),m.reduce((g,b)=>(f.setEdge(g,b,{style:"invis"}),b))}),f}}),Rz=Wt((e,r)=>{r.exports="2.0.4"}),zz=Wt((e,r)=>{r.exports={graphlib:ns(),layout:Dz(),debug:Oz(),util:{time:Hn().time,notime:Hn().notime},version:Rz()}});const kv=zz();const Sv={pending:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},pending_approval:{bg:"bg-blue-500/8",border:"border-blue-400/25",text:"text-blue-500"},assigned:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},in_progress:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},blocked:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},review:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},revision:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},accepted:{bg:"bg-green-500/8",border:"border-green-500/25",text:"text-green-600"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},failed:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"}},Lz={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function Iz({data:e}){const{task:r,agentName:s}=e,i=Sv[r.status]??Sv.pending,o=r.taskType==="scheduled"&&!!r.scheduleConfig,c=o?r.scheduleConfig.every?`Every ${r.scheduleConfig.every}`:r.scheduleConfig.cron?"Cron":"":"";return t.jsxs("div",{className:`rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${o?`${i.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${i.bg} ${i.border}`}`,children:[t.jsx(Na,{type:"target",position:nt.Top,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Lz[r.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${i.text}`,children:r.status.replace("_"," ")}),o&&t.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/15 text-blue-600 ml-auto whitespace-nowrap inline-flex items-center gap-0.5",children:[t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})}),c]})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:r.title}),s&&t.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:s}),r.blockedBy&&r.blockedBy.length>0&&t.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[r.blockedBy.length," dep",r.blockedBy.length>1?"s":""]}),t.jsx(Na,{type:"source",position:nt.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const Cv={draft:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-secondary"},pending_review:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},approved:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},in_progress:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},rejected:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"}},Ev={draft:"todo",pending_review:"todo",approved:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done"};function $z({data:e}){const{req:r}=e,s=Cv[r.status]??Cv.draft;return t.jsxs("div",{className:`rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${s.bg} ${s.border}`,children:[t.jsx(Na,{type:"target",position:nt.Top,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:"REQ"}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${s.text}`,children:r.status.replace("_"," ")})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:r.title}),r.taskIds.length>0&&t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[r.taskIds.length," task",r.taskIds.length>1?"s":""]}),t.jsx(Na,{type:"source",position:nt.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const Bz={task:Iz,requirement:$z},Hz=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&window.matchMedia("(prefers-color-scheme: light)").matches,Pz=e=>{const r=new MutationObserver(e);r.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const s=window.matchMedia("(prefers-color-scheme: light)");return s.addEventListener("change",e),()=>{r.disconnect(),s.removeEventListener("change",e)}};function Uz(){return j.useSyncExternalStore(Pz,Hz,()=>!1)}const Em=200,Tm=80;function Tv(e,r,s="TB"){const i=new kv.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:s,nodesep:40,ranksep:60});for(const o of e)i.setNode(o.id,{width:Em,height:Tm});for(const o of r)i.setEdge(o.source,o.target);return kv.layout(i),e.map(o=>{const c=i.node(o.id);return{...o,position:{x:(c?.x??0)-Em/2,y:(c?.y??0)-Tm/2}}})}function qz(e,r){const s=new Map,i=new Map;for(const u of e)i.set(u.id,u),s.set(u.id,new Set);for(const u of r)s.get(u.source)?.add(u.target),s.get(u.target)?.add(u.source);const o=new Set,c=[];for(const u of e){if(o.has(u.id))continue;const f=new Set,m=[u.id];for(;m.length>0;){const h=m.pop();if(!o.has(h)){o.add(h),f.add(h);for(const x of s.get(h)??[])o.has(x)||m.push(x)}}c.push({nodes:e.filter(h=>f.has(h.id)),edges:r.filter(h=>f.has(h.source)&&f.has(h.target))})}return c}function Vz(e,r){if(e.length===0)return[];const s=qz(e,r);if(s.length===1)return Tv(e,r);const i=s.map(g=>{const b=Tv(g.nodes,g.edges);let p=1/0,w=-1/0,S=1/0,T=-1/0;for(const E of b)p=Math.min(p,E.position.x),w=Math.max(w,E.position.x+Em),S=Math.min(S,E.position.y),T=Math.max(T,E.position.y+Tm);for(const E of b)E.position.x-=p,E.position.y-=S;return{nodes:b,w:w-p,h:T-S}});i.sort((g,b)=>b.h-g.h);const o=60,c=i.reduce((g,b)=>g+(b.w+o)*(b.h+o),0),u=Math.sqrt(c)*1.1,f=[];let m=0,h=0,x=0;for(const g of i){m>0&&m+g.w>u&&(m=0,h+=x+o,x=0);for(const b of g.nodes)f.push({...b,position:{x:b.position.x+m,y:b.position.y+h}});m+=g.w+o,x=Math.max(x,g.h)}return f}function Fz(e,r,s){const i=new Set,o=[r];for(;o.length>0;){const c=o.pop();if(c===s)return!0;if(i.has(c))continue;i.add(c);const u=e.get(c);if(u?.blockedBy)for(const f of u.blockedBy)o.push(f)}return!1}const oo=[{id:"todo",label:"To Do",statuses:new Set(["pending_approval","pending","assigned"]),color:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"}},{id:"in_progress",label:"In Progress",statuses:new Set(["in_progress","blocked"]),color:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"}},{id:"review",label:"In Review",statuses:new Set(["review","revision","accepted"]),color:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"}},{id:"done",label:"Done",statuses:new Set(["completed","failed","cancelled"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}],Yh=new Set(oo.map(e=>e.id)),Yz=1440*60*1e3,_v=e=>e.status==="completed"&&e.updatedAt&&Date.now()-new Date(e.updatedAt).getTime()>Yz;function Gz({tasks:e,requirements:r=[],agents:s,showArchived:i,onShowArchivedChange:o,onTaskClick:c,onReqClick:u,onDependencyChange:f}){const m=Uz(),[h,x]=j.useState(null),[g,b]=j.useState(null),[p,w]=j.useState(new Set(Yh)),[S,T]=j.useState(i??!1),E=i??S,C=j.useCallback(Z=>{const ee=typeof Z=="function"?Z(E):Z;T(ee),o?.(ee)},[E,o]);j.useEffect(()=>{i!==void 0&&T(i)},[i]);const N=j.useMemo(()=>e.filter(Z=>_v(Z)).length,[e]),k=j.useMemo(()=>{const Z=new Set;for(const ee of oo)if(p.has(ee.id))for(const ie of ee.statuses)Z.add(ie);return Z},[p]),H=j.useMemo(()=>{const Z=new Set;for(const ee of e)for(const ie of oo)if(ie.statuses.has(ee.status)){Z.add(ie.id);break}for(const ee of r){const ie=Ev[ee.status];ie&&Z.add(ie)}return oo.filter(ee=>Z.has(ee.id))},[e,r]),M=j.useCallback(Z=>{w(ee=>{const ie=new Set(ee);return ie.has(Z)?ie.delete(Z):ie.add(Z),ie})},[]),Y=j.useCallback((Z,ee="success")=>{x({msg:Z,type:ee}),setTimeout(()=>x(null),2500)},[]),$=j.useMemo(()=>{const Z=new Map;for(const ee of s)Z.set(ee.id,ee.name);return Z},[s]),X=j.useMemo(()=>{const Z=new Map;for(const ee of e)Z.set(ee.id,ee);return Z},[e]),P=j.useMemo(()=>{const Z=new Map;for(const ee of r)Z.set(ee.id,ee);return Z},[r]),q=m?"#94a3b8":"#6b7280",F=j.useCallback((Z,ee,ie)=>({id:`${Z}->${ee}`,source:Z,target:ee,animated:ie==="blocked",markerEnd:{type:Zi.ArrowClosed,width:14,height:14,color:ie==="blocked"?"#ef4444":q},style:{stroke:ie==="blocked"?"#ef4444":q,strokeWidth:1.5,cursor:"pointer"}}),[q]),{initialNodes:D,initialEdges:_}=j.useMemo(()=>{const Z=e.filter(Ae=>k.has(Ae.status)&&(E||!_v(Ae))),ee=Z.map(Ae=>({id:Ae.id,type:"task",data:{task:Ae,agentName:Ae.assignedAgentId?$.get(Ae.assignedAgentId):void 0},position:{x:0,y:0}})),ie=new Set(ee.map(Ae=>Ae.id)),je=new Set;for(const Ae of oo)p.has(Ae.id)&&je.add(Ae.id);const ke=r.filter(Ae=>{const We=Ev[Ae.status];return We&&je.has(We)});for(const Ae of ke){const We=`req-${Ae.id}`;ee.push({id:We,type:"requirement",data:{req:Ae},position:{x:0,y:0}}),ie.add(We)}const De=[];for(const Ae of Z)if(Ae.blockedBy)for(const We of Ae.blockedBy)ie.has(We)&&De.push(F(We,Ae.id,Ae.status));const Ie=new Set,ze=(Ae,We)=>{const xt=`${Ae}->${We}`;Ie.has(xt)||(Ie.add(xt),De.push({id:xt,source:Ae,target:We,markerEnd:{type:Zi.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ae of ke){const We=`req-${Ae.id}`;for(const xt of Ae.taskIds)ie.has(xt)&&ze(We,xt)}for(const Ae of Z)if(Ae.requirementId){const We=`req-${Ae.requirementId}`;ie.has(We)&&ze(We,Ae.id)}return{initialNodes:Vz(ee,De),initialEdges:De}},[e,r,$,X,F,k,p,E]),[I,A,G]=zR(D),[U,K,B]=LR(_),L=j.useRef(null);j.useEffect(()=>{A(D),K(_),requestAnimationFrame(()=>{L.current?.fitView({padding:.2,duration:300})})},[D,_,A,K]);const W=j.useCallback((Z,ee)=>{if(ee.id.startsWith("req-")){const ie=P.get(ee.id.slice(4));ie&&u&&u(ie)}else{const ie=X.get(ee.id);ie&&c&&c(ie)}},[X,P,c,u]),R=j.useCallback(async Z=>{const{source:ee,target:ie}=Z;if(!ee||!ie||ee===ie)return;const je=X.get(ie);if(!je)return;if(je.blockedBy?.includes(ee)){Y("Dependency already exists","error");return}if(Fz(X,ee,ie)){Y("Cannot add: would create a cycle","error");return}const ke=[...je.blockedBy??[],ee];try{await ae.tasks.update(ie,{blockedBy:ke}),Y("Dependency added"),f?.()}catch(De){Y(`Failed: ${De instanceof Error?De.message:String(De)}`,"error")}},[X,Y,f]),z=j.useCallback((Z,ee)=>{b(ee)},[]),V=j.useCallback(async()=>{if(!g)return;const Z=X.get(g.target);if(!Z){b(null);return}const ee=(Z.blockedBy??[]).filter(ie=>ie!==g.source);try{await ae.tasks.update(g.target,{blockedBy:ee}),Y("Dependency removed"),f?.()}catch(ie){Y(`Failed: ${ie instanceof Error?ie.message:String(ie)}`,"error")}b(null)},[g,X,Y,f]);if(e.length===0)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:"No tasks to display"});const Q=g?X.get(g.source):null,te=g?X.get(g.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(RR,{nodes:I,edges:U,onNodesChange:G,onEdgesChange:B,onNodeClick:W,onConnect:R,onEdgeClick:z,onInit:Z=>{L.current=Z},nodeTypes:Bz,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[t.jsx(PR,{color:m?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(XR,{showInteractive:!1,className:"!bg-surface-secondary !border-border-default !shadow-xl [&>button]:!bg-surface-elevated [&>button]:!border-border-default [&>button]:!text-fg-secondary [&>button:hover]:!bg-surface-overlay"}),t.jsx(lz,{nodeColor:Z=>{const ee=Z.data?.task,ie=ee?.status;return ee?.taskType==="scheduled"?"#06b6d4":ie==="completed"||ie==="accepted"?"#10b981":ie==="in_progress"?"#f59e0b":ie==="blocked"||ie==="failed"?"#ef4444":m?"#94a3b8":"#6b7280"},maskColor:m?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),t.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-surface-secondary/90 border border-border-default rounded-lg backdrop-blur-sm z-10 flex flex-col items-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[H.map(Z=>{const ee=p.has(Z.id);return t.jsx("button",{onClick:()=>M(Z.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${ee?`${Z.color.bg} ${Z.color.border} ${Z.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:Z.label},Z.id)}),N>0&&t.jsxs("button",{onClick:()=>C(Z=>!Z),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${E?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:["Archived ",N]}),p.size<Yh.size&&t.jsx("button",{onClick:()=>{w(new Set(Yh)),C(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:"Reset"})]}),t.jsx("div",{className:"text-[10px] text-fg-tertiary select-none",children:"Drag to add dependency · Click edge to remove"})]}),h&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${h.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:h.msg}),g&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>b(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:Z=>Z.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:"Remove dependency?"}),t.jsxs("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:[t.jsx("span",{className:"text-fg-secondary font-medium",children:te?.title??g.target.slice(-8)})," ","will no longer be blocked by"," ",t.jsx("span",{className:"text-fg-secondary font-medium",children:Q?.title??g.source.slice(-8)}),"."]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>b(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:"Cancel"}),t.jsx("button",{onClick:V,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:"Remove"})]})]})})]})}function aN({orgId:e,onCreated:r,onClose:s}){const[i,o]=j.useState(""),[c,u]=j.useState(""),[f,m]=j.useState(""),[h,x]=j.useState("main"),[g,b]=j.useState([]),[p,w]=j.useState([]),[S,T]=j.useState(!1),[E,C]=j.useState(""),[N,k]=j.useState(!1),H=gs();j.useEffect(()=>{ae.teams.list().then($=>w($.teams)).catch(()=>{})},[]);const M=j.useCallback(async $=>{if($?.preventDefault(),k(!0),!(!i.trim()||S)){T(!0),C("");try{const X=f.trim()?[{url:f.trim(),defaultBranch:h.trim()||"main"}]:[],P=await ae.projects.create({name:i.trim(),description:c.trim()||void 0,repositories:X.length>0?X:void 0,teamIds:g.length>0?g:void 0,orgId:e??"default"});r(P.project)}catch(X){C(X instanceof Error?X.message:"Failed to create project")}T(!1)}},[i,c,f,h,g,e,S,r]),Y=N&&!i.trim();return K1.createPortal(t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:s,children:t.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto ${H?"w-full":"w-[520px]"}`,onClick:$=>$.stopPropagation(),onSubmit:M,children:[t.jsx("h3",{className:"text-base font-semibold mb-5",children:"New Project"}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Project Name *"}),t.jsx("input",{value:i,onChange:$=>{o($.target.value),C("")},onBlur:()=>k(!0),placeholder:"e.g. Mobile App, Website Redesign",className:`input ${Y?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!H}),Y&&t.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:"Project name is required"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Description"}),t.jsx("textarea",{value:c,onChange:$=>u($.target.value),placeholder:"What is this project about?",className:"input",rows:3})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Assign Teams"}),p.length===0?t.jsx("div",{className:"text-[11px] text-fg-tertiary py-2",children:"No teams available"}):t.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:p.map($=>{const X=g.includes($.id);return t.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer hover:text-fg-primary py-0.5",children:[t.jsx("input",{type:"checkbox",checked:X,onChange:()=>b(P=>X?P.filter(q=>q!==$.id):[...P,$.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:$.name})]},$.id)})})]}),t.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Repository URL"}),t.jsx("input",{value:f,onChange:$=>m($.target.value),placeholder:"https://github.com/org/repo (optional)",className:"input"})]}),f.trim()&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Branch"}),t.jsx("input",{value:h,onChange:$=>x($.target.value),placeholder:"main",className:"input !w-24"})]})]}),E&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:E}),t.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{type:"submit",disabled:!i.trim()||S,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:S?"Creating...":"Create Project"})]})]})]})}),document.body)}function el(e,r,s){if(!e)return null;const i=r.find(c=>c.id===e);if(i)return i.name;const o=s.find(c=>c.id===e);return o?o.name:e==="anonymous"?"Admin":null}function Xz({value:e,onSave:r,className:s,placeholder:i}){const[o,c]=j.useState(!1),[u,f]=j.useState(e),m=j.useRef(null);j.useEffect(()=>{f(e)},[e]),j.useEffect(()=>{o&&m.current?.focus()},[o]);const h=async()=>{c(!1);const x=u.trim();if(x&&x!==e)try{await r(x)}catch{f(e)}else f(e)};return o?t.jsx("input",{ref:m,value:u,onChange:x=>f(x.target.value),onBlur:()=>{h()},onKeyDown:x=>{x.key==="Enter"&&h(),x.key==="Escape"&&(f(e),c(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${s??""}`,placeholder:i}):t.jsx("span",{onClick:()=>c(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${s??""}`,title:"Click to edit",children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:i??"Click to edit"})})}function Zz({value:e,onSave:r,className:s,placeholder:i}){const[o,c]=j.useState(!1),[u,f]=j.useState(e),m=j.useRef(null);j.useEffect(()=>{f(e)},[e]),j.useEffect(()=>{o&&m.current&&(m.current.focus(),m.current.style.height="auto",m.current.style.height=m.current.scrollHeight+"px")},[o]);const h=async()=>{c(!1);const x=u.trim();if(x!==e)try{await r(x)}catch{f(e)}else f(e)};return o?t.jsx("textarea",{ref:m,value:u,onChange:x=>{f(x.target.value),x.target.style.height="auto",x.target.style.height=x.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:x=>{x.key==="Escape"&&(f(e),c(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${s??""}`,placeholder:i,rows:2}):t.jsx("p",{onClick:()=>c(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${s??""}`,title:"Click to edit",children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:i??"Add a description…"})})}const Qz=["pending_approval","in_progress","blocked","review","completed","failed","cancelled","archived"],To=[{id:"failed",label:"Failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",label:"To Do",statuses:["pending_approval"],accent:"border-t-amber-500",dropStatus:"pending_approval"},{id:"in_progress",label:"In Progress",statuses:["in_progress","blocked"],accent:"border-t-brand-500",dropStatus:"in_progress"},{id:"review",label:"In Review",statuses:["review"],accent:"border-t-purple-500",dropStatus:"review"},{id:"done",label:"Done",statuses:["completed"],accent:"border-t-green-500",dropStatus:"completed"},{id:"closed",label:"Closed",statuses:["cancelled"],accent:"border-t-gray-500",dropStatus:"cancelled"}],Kz={pending_approval:"Awaiting Approval",in_progress:"In Progress",blocked:"Blocked",review:"In Review",completed:"Completed",failed:"Failed",cancelled:"Cancelled",archived:"Archived"},iN={pending_approval:{label:"Awaiting",cls:"bg-amber-500/15 text-amber-600"},blocked:{label:"Blocked",cls:"bg-amber-500/15 text-amber-600"},failed:{label:"Failed",cls:"bg-red-500/15 text-red-500"}},Jz={pending_approval:{label:"Pending Approval",cls:"bg-amber-500/15 text-amber-600"},in_progress:{label:"In Progress",cls:"bg-blue-500/15 text-blue-500"},blocked:{label:"Blocked",cls:"bg-orange-500/15 text-orange-500"},review:{label:"In Review",cls:"bg-purple-500/15 text-purple-500"},completed:{label:"Completed",cls:"bg-green-500/15 text-green-600"},failed:{label:"Failed",cls:"bg-red-500/15 text-red-500"},cancelled:{label:"Cancelled",cls:"bg-gray-500/15 text-fg-tertiary"},archived:{label:"Archived",cls:"bg-gray-500/15 text-fg-tertiary"}},_m={urgent:"border-l-red-500",high:"border-l-amber-500",medium:"border-l-blue-500",low:"border-l-gray-500"},lN={pending_approval:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},Av=j.memo(function({comment:r}){return t.jsxs("div",{className:"bg-blue-500/10 border border-blue-500/30 rounded-lg px-3 py-2.5 my-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("span",{className:"w-5 h-5 rounded-full bg-blue-600/30 flex items-center justify-center text-[10px] text-blue-600 font-bold shrink-0",children:r.authorType==="human"?"👤":"🤖"}),t.jsx("span",{className:"text-[11px] font-medium text-blue-600",children:r.authorName}),t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:new Date(r.createdAt).toLocaleString()})]}),t.jsx(er,{content:r.content,className:"text-sm text-fg-secondary"}),r.attachments?.map((s,i)=>s.type==="image"?t.jsx("img",{src:s.url,alt:s.name,className:"mt-2 max-w-full max-h-48 rounded-lg border border-border-default"},i):null)]})});function Wz(e){return e.kind==="log"?e.executionRound??1:0}function eL(e){const r=[];let s=null,i=[],o=1;for(const c of e){if(c.kind==="comment"){s?s.items.push(c):i.push(c);continue}const u=Wz(c);if(c.entry.type==="status"&&(c.entry.content==="started"||c.entry.content==="resumed")){(!s||u!==s.roundNumber)&&(s={id:o++,roundNumber:u,startTime:c.entry.timestamp??c.entry.time??"",status:"running",items:[],preComments:[...i]},i=[],r.push(s)),c.entry.content==="resumed"&&s.items.push(c);continue}if(c.entry.type==="status"&&["completed","failed","cancelled","execution_finished"].includes(c.entry.content)){if(s){const f=c.entry.content==="execution_finished"?"completed":c.entry.content;s.status=f,s.endTime=c.entry.timestamp??c.entry.time}continue}s&&s.items.push(c)}return s&&s.status==="running"&&(s.items.length>0||(s.status="interrupted")),i.length>0&&r.length>0&&r[r.length-1].items.push(...i),r.length===0&&e.length>0&&r.push({id:o++,roundNumber:1,startTime:e[0].kind==="log"?e[0].entry.timestamp??"":new Date(e[0].time).toISOString(),status:"running",items:[...i,...e],preComments:[]}),r}function tL(e,r){if(!r)return"";const s=new Date(r).getTime()-new Date(e).getTime();if(s<1e3)return"<1s";const i=Math.floor(s/1e3);if(i<60)return`${i}s`;const o=Math.floor(i/60);return o<60?`${o}m ${i%60}s`:`${Math.floor(o/60)}h ${o%60}m`}const Mv={running:{label:"Running",color:"text-blue-600",bg:"bg-blue-500/15"},completed:{label:"Completed",color:"text-green-600",bg:"bg-green-500/15"},failed:{label:"Failed",color:"text-red-500",bg:"bg-red-500/15"},cancelled:{label:"Cancelled",color:"text-fg-secondary",bg:"bg-gray-500/15"},interrupted:{label:"Interrupted",color:"text-amber-600",bg:"bg-amber-500/15"}},nL=j.memo(function({round:r,expanded:s,onToggle:i,isLive:o,streamingText:c,isExecuting:u,totalRounds:f}){const m=Mv[r.status]??Mv.running,h=tL(r.startTime,r.endTime),x=Jm(r.startTime),g=r.items.filter(p=>p.kind==="log"&&p.entry.type==="tool").length,b=r.items.filter(p=>p.kind==="log"&&p.entry.type==="error").length;return t.jsxs("div",{className:"border-b border-border-default/60 last:border-b-0",children:[r.preComments.length>0&&t.jsx("div",{className:"px-4 py-2",children:r.preComments.map((p,w)=>p.kind==="comment"?t.jsx(Av,{comment:p.entry},`pc-${p.entry.id}`):null)}),t.jsxs("button",{onClick:i,className:"w-full flex items-center gap-2 px-4 py-2.5 hover:bg-surface-elevated/40 transition-colors text-left min-w-0 overflow-hidden",children:[t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary shrink-0 transition-transform ${s?"rotate-90":""}`,viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M4 2l5 4-5 4V2z"})}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary shrink-0",children:f>1?`Round #${r.id}`:"Execution"}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${m.bg} ${m.color}`,children:m.label}),r.status==="running"&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 animate-pulse shrink-0"}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary ml-auto flex items-center gap-2 shrink-0 truncate",children:[g>0&&t.jsxs("span",{children:[g," tools"]}),b>0&&t.jsxs("span",{className:"text-red-500",children:[b," err"]}),h&&t.jsx("span",{children:h}),t.jsx("span",{children:x})]})]}),s&&t.jsxs("div",{className:"px-4 pb-3 space-y-0.5 overflow-x-hidden min-w-0",children:[r.items.map((p,w)=>p.kind==="comment"?t.jsx(Av,{comment:p.entry},`c-${p.entry.id}`):t.jsx(fT,{entry:p.entry,showTime:!0},`l-${(p.entry.type==="tool"?p.entry.key:void 0)??`${p.entry.timestamp}-${w}`}`)),o&&c&&t.jsx(ej,{content:c}),o&&u&&!c&&t.jsx(Nu,{label:"Thinking"})]})]})});function rL({taskId:e,isVisible:r,isRunning:s,authUser:i}){const[o,c]=j.useState([]),[u,f]=j.useState([]),[m,h]=j.useState(""),[x,g]=j.useState(s),[b,p]=j.useState(!0),[w,S]=j.useState(""),[T,E]=j.useState(!1),[C,N]=j.useState([]),[k,H]=j.useState(new Set),[M,Y]=j.useState(1),$=20,X=j.useRef(null),P=j.useRef(null),q=j.useRef(null),F=j.useRef(!0);j.useEffect(()=>{const z=q.current;if(!z)return;let V=z.parentElement;for(;V&&V.scrollHeight<=V.clientHeight;)V=V.parentElement;if(!V)return;const Q=V,te=()=>{F.current=Q.scrollHeight-Q.scrollTop-Q.clientHeight<80};return Q.addEventListener("scroll",te,{passive:!0}),()=>Q.removeEventListener("scroll",te)},[]),j.useEffect(()=>{g(s)},[s]),j.useEffect(()=>{p(!0),Promise.all([ae.tasks.getLogs(e).catch(()=>({logs:[]})),ae.tasks.getComments(e).catch(()=>({comments:[]}))]).then(([z,V])=>{c(z.logs),f(V.comments),p(!1)})},[e]),j.useEffect(()=>{const z=En.on("task:log",te=>{const Z=te.payload;if(Z.taskId!==e)return;const ee={id:Z.id,taskId:Z.taskId,agentId:Z.agentId,seq:Z.seq,type:Z.logType,content:Z.content,metadata:Z.metadata,executionRound:Z.executionRound,createdAt:Z.createdAt};c(ie=>ee.id&&ie.some(je=>je.id===ee.id)||!ee.id&&ie.some(je=>je.seq===ee.seq&&je.type===ee.type)?ie:[...ie,ee]),ee.type==="text"&&h(""),ee.type==="status"&&(ee.content==="started"||ee.content==="resumed"?g(!0):["completed","failed","cancelled","execution_finished"].includes(ee.content)&&g(!1)),ee.type==="error"&&g(!1)}),V=En.on("task:log:delta",te=>{const Z=te.payload;Z.taskId===e&&h(ee=>ee+Z.text)}),Q=En.on("task:comment",te=>{const Z=te.payload;if(Z.taskId!==e)return;const ee=Z.comment;f(ie=>ie.some(je=>je.id===ee.id)?ie:[...ie,ee])});return()=>{z(),V(),Q()}},[e]);const D=j.useMemo(()=>{const z=new Map;for(const V of o)V.executionRound&&z.set(V.seq,V.executionRound);return z},[o]),_=j.useMemo(()=>{const z=o.map(Z=>({log:Z,entry:Wm(Z)})).filter(Z=>Z.entry!=null),V=bo(z.map(Z=>Z.entry)),Q=new Set(V),te=[...z.filter(Z=>Q.has(Z.entry)).map(({log:Z,entry:ee})=>({kind:"log",entry:ee,time:new Date(ee.timestamp??ee.time??0).getTime(),executionRound:Z.executionRound??D.get(Z.seq)??1})),...u.map(Z=>({kind:"comment",entry:Z,time:new Date(Z.createdAt).getTime()}))];return te.sort((Z,ee)=>Z.time-ee.time),te},[o,u,D]),I=j.useMemo(()=>eL(_),[_]);j.useEffect(()=>{I.length>0&&H(z=>{const V=I[I.length-1].id;return z.has(V)?z:new Set([V])})},[I.length]),j.useEffect(()=>{r&&x&&P.current?.scrollIntoView({behavior:"smooth",block:"start"})},[I.length,r,x]);const A=j.useCallback(z=>{H(V=>{const Q=new Set(V);return Q.has(z)?Q.delete(z):Q.add(z),Q})},[]),G=z=>{const V=z.target.files;if(V){for(const Q of Array.from(V)){if(!Q.type.startsWith("image/"))continue;const te=new FileReader;te.onload=()=>{N(Z=>[...Z,{type:"image",url:te.result,name:Q.name}])},te.readAsDataURL(Q)}z.target.value=""}},U=async()=>{if(!(!w.trim()&&C.length===0)){E(!0);try{const z=await ae.tasks.addComment(e,w,i?.name,C.length>0?C:void 0,i?.id);z.comment&&f(V=>V.some(Q=>Q.id===z.comment.id)?V:[...V,z.comment]),S(""),N([])}catch{}E(!1)}},K=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-secondary z-10",children:[C.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:C.map((z,V)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:z.url,alt:z.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>N(Q=>Q.filter((te,Z)=>Z!==V)),className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-600 text-white text-[10px] flex items-center justify-center opacity-0 group-hover:opacity-100",children:"×"})]},V))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:w,onChange:z=>S(z.target.value),onKeyDown:z=>{z.key==="Enter"&&!z.shiftKey&&(z.preventDefault(),U())},placeholder:"Add a comment or instruction…",className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-blue-500 outline-none text-fg-primary placeholder-gray-600"}),t.jsx("input",{type:"file",ref:X,accept:"image/*",multiple:!0,onChange:G,className:"hidden"}),t.jsx("button",{onClick:()=>X.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:"Attach image",children:"📎"}),t.jsx("button",{onClick:()=>{U()},disabled:T||!w.trim()&&C.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:"Send"})]})]});if(b)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:"Loading logs…"});if(I.length===0&&!m)return t.jsxs("div",{className:"flex flex-col flex-1",children:[t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"text-center text-fg-tertiary",children:[t.jsx("div",{className:"text-2xl mb-2",children:"📋"}),t.jsxs("div",{className:"text-xs",children:["No execution logs yet.",t.jsx("br",{}),'Click "Run with Agent" to start.']})]})}),K]});const B=Math.ceil(I.length/$),L=M*$,W=(M-1)*$,R=I.slice(Math.max(0,I.length-L),I.length-W).slice().reverse();return t.jsxs("div",{children:[B>1&&t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-default",children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[I.length," rounds total"]}),t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:M<=1,onClick:()=>Y(z=>z-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"← Newer"}),t.jsxs("span",{children:[M,"/",B]}),t.jsx("button",{disabled:M>=B,onClick:()=>Y(z=>z+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"Older →"})]})]}),t.jsxs("div",{className:"py-1",children:[t.jsx("div",{ref:P}),R.map(z=>{const V=z.id===I[I.length-1]?.id;return t.jsx(nL,{round:z,expanded:k.has(z.id),onToggle:()=>A(z.id),isLive:V&&x,streamingText:V?m:void 0,isExecuting:V?x:!1,totalRounds:I.length},z.id)}),t.jsx("div",{ref:q})]}),K]})}function sL({filePath:e,onClose:r}){const[s,i]=j.useState(null),[o,c]=j.useState(null),[u,f]=j.useState(!0);j.useEffect(()=>{f(!0),c(null),ae.files.preview(e).then(h=>i(h)).catch(h=>c(String(h))).finally(()=>f(!1))},[e]);const m=e.split("/").pop()??e;return t.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",onClick:r,children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl w-[720px] max-w-[92vw] max-h-[85vh] flex flex-col shadow-2xl",onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),t.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),t.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:m})]}),t.jsx("button",{onClick:r,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0 ml-3",children:"×"})]}),t.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:e})}),t.jsxs("div",{className:"flex-1 overflow-auto min-h-0 p-5",children:[u&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:"Loading..."}),o&&t.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:o}),s&&s.type==="image"&&t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:`data:${s.mimeType};base64,${s.content}`,alt:s.name,className:"max-w-full max-h-[60vh] rounded-lg"})}),s&&s.type==="markdown"&&t.jsx(er,{content:s.content,className:"text-sm text-fg-secondary leading-relaxed"}),s&&s.type==="text"&&t.jsx("pre",{className:"text-xs text-fg-secondary font-mono whitespace-pre-wrap break-words bg-surface-primary/50 rounded-lg p-4 leading-relaxed",children:s.content})]})]})})}function aL({task:e,agents:r,projects:s,requirements:i,allTasks:o,users:c,onClose:u,onRefresh:f,authUser:m}){const[h,x]=j.useState([]),[g,b]=j.useState(""),[p,w]=j.useState(!1),[S,T]=j.useState(null),[E,C]=j.useState(null),[N,k]=j.useState(!1),[H,M]=j.useState("details"),[Y,$]=j.useState(!1),[X,P]=j.useState(null),[q,F]=j.useState(null),[D,_]=j.useState(!1),[I,A]=j.useState(e.description),[G,U]=j.useState(!1),[K,B]=j.useState(""),[L,W]=j.useState(1),[R,z]=j.useState(1),[V,Q]=j.useState(!1),te=gs(),Z=20,ee=j.useCallback(async()=>{try{const xe=await ae.tasks.listSubtasks(e.id);x(xe.subtasks)}catch{}},[e.id]);j.useEffect(()=>{ee()},[ee]);const ie=async xe=>{if(!N){k(!0);try{await xe(),f(),await ee()}catch(Be){P(String(Be).replace("Error: ",""))}finally{k(!1)}}},je=xe=>ie(()=>ae.tasks.update(e.id,{priority:xe})),ke=xe=>ie(()=>ae.tasks.assign(e.id,xe||null)),De=xe=>ie(()=>ae.tasks.update(e.id,{projectId:xe||null})),Ie=async()=>{if(!N){k(!0);try{await ae.tasks.pause(e.id),f()}finally{k(!1)}}},ze=async()=>{if(!Y){$(!0),P(null),M("logs");try{await ae.tasks.resume(e.id),f()}catch(xe){P(String(xe).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{$(!1)}}},Ze=async()=>{g.trim()&&(await ae.tasks.createSubtask(e.id,g.trim()),b(""),w(!1),ee(),f())},Ae=async xe=>{xe.status==="completed"?await ae.tasks.cancelSubtask(e.id,xe.id):await ae.tasks.completeSubtask(e.id,xe.id),ee(),f()},We=async xe=>{await ae.tasks.deleteSubtask(e.id,xe.id),T(null),ee(),f()},xt=async()=>{if(!N){k(!0);try{await ae.tasks.updateStatus(e.id,"pending_approval"),f()}finally{k(!1)}}},Lt=async()=>{if(!N){k(!0),P(null),M("logs");try{await ae.tasks.retry(e.id),f()}catch(xe){P(String(xe).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{k(!1)}}},le=async()=>{if(!Y){$(!0),P(null),M("logs");try{await ae.tasks.runNow(e.id),f()}catch(xe){P(String(xe).replace("Error: API error: 400","Server error").replace("Error: ","")),f()}finally{$(!1)}}};j.useEffect(()=>En.on("task:log:delta",Be=>{Be.payload.taskId===e.id&&M("logs")}),[e.id]);const _e=j.useRef(f);_e.current=f,j.useEffect(()=>En.on("task:update",Be=>{Be.payload.taskId===e.id&&(ee(),_e.current())}),[e.id,ee]);const ht=h.filter(xe=>xe.status==="completed").length,Ct=e.status==="in_progress",Ft=e.status==="blocked",be=e.status==="completed",Me=e.status==="failed",Ve=e.status==="cancelled",Xe=e.status==="archived",rt=be||Me||Ve||Xe,It=e.taskType==="scheduled"&&!!e.scheduleConfig,Ht=It&&!!e.scheduleConfig?.paused,_t=s.find(xe=>xe.id===e.projectId),wt=i.find(xe=>xe.id===e.requirementId);return r.find(xe=>xe.id===e.assignedAgentId),t.jsxs("div",{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3 ${te?"pb-[4.5rem]":""}`,onClick:u,children:[t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl flex flex-col shadow-2xl ${te?"w-full max-h-full":"w-[780px] max-w-[95vw] max-h-[88vh]"}`,onClick:xe=>xe.stopPropagation(),children:[t.jsxs("div",{className:"flex items-start justify-between px-6 pt-5 pb-3 border-b border-border-default shrink-0",children:[t.jsx("div",{className:"flex-1 min-w-0 pr-4",children:t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("h3",{className:"text-base font-semibold leading-snug",children:e.title}),(()=>{const xe=Jz[e.status];return xe?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap ${xe.cls}`,children:xe.label}):t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium bg-gray-500/15 text-fg-tertiary whitespace-nowrap",children:e.status.replace(/_/g," ")})})()]})}),t.jsx("button",{onClick:u,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:D?t.jsxs("div",{className:"space-y-2",children:[t.jsx("textarea",{value:I,onChange:xe=>A(xe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-y min-h-[80px]",rows:4,placeholder:"Add a description…"}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx("button",{onClick:()=>{_(!1),A(e.description)},className:"px-2.5 py-1 text-xs border border-border-default rounded-lg hover:bg-surface-elevated",children:"Cancel"}),t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.update(e.id,{description:I})),_(!1)},disabled:N,className:"px-2.5 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Save"})]})]}):t.jsxs("div",{className:"group relative",children:[e.description?t.jsxs("div",{children:[t.jsx("div",{className:te&&!V?"line-clamp-3":"",children:t.jsx(er,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),te&&e.description.length>150&&t.jsx("button",{onClick:()=>Q(!V),className:"text-[11px] text-brand-500 mt-1 font-medium",children:V?"Collapse":"Show more"})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No description"}),t.jsx("button",{onClick:()=>{A(e.description),_(!0)},className:"absolute top-0 right-0 text-[10px] text-fg-tertiary hover:text-brand-500 opacity-0 group-hover:opacity-100 transition-opacity",children:"Edit"})]})}),(_t||wt)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[_t&&t.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full",children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:"Project"}),_t.name]}),wt&&t.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full",children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:"Req"}),wt.title.length>40?wt.title.slice(0,40)+"…":wt.title]})]}),t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default",children:[t.jsx("div",{className:"flex items-center justify-between mb-1.5",children:t.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:"Dependencies"})}),e.blockedBy&&e.blockedBy.length>0?t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(xe=>{const Be=o.find(pt=>pt.id===xe),gt=Be&&(Be.status==="completed"||Be.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${gt?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:gt?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${gt?"line-through opacity-60":""}`,children:Be?Be.title.slice(0,30):xe.slice(-8)}),!rt&&t.jsx("button",{onClick:async()=>{const pt=(e.blockedBy??[]).filter(ue=>ue!==xe);await ae.tasks.update(e.id,{blockedBy:pt}),f()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:"Remove dependency",children:"×"})]},xe)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:"No dependencies"}),!rt&&t.jsxs("select",{value:"",onChange:async xe=>{const Be=xe.target.value;if(!Be)return;const gt=[...e.blockedBy??[],Be];await ae.tasks.update(e.id,{blockedBy:gt}),f()},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"+ Add dependency…"}),o.filter(xe=>xe.id!==e.id&&!(e.blockedBy??[]).includes(xe.id)).map(xe=>t.jsx("option",{value:xe.id,children:xe.title},xe.id))]})]}),t.jsxs("div",{className:"flex gap-1 px-6 pt-3 border-b border-border-default sticky top-0 z-10 bg-surface-secondary",children:[t.jsx("button",{onClick:()=>M("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${H==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:"Details"}),t.jsxs("button",{onClick:()=>M("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${H==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Execution Log",Ct&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsxs("button",{onClick:()=>M("notes"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${H==="notes"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Notes",e.notes&&e.notes.length>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary font-normal",children:e.notes.length})]}),t.jsxs("button",{onClick:()=>M("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${H==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Deliverables",(()=>{const xe=(e.deliverables??[]).filter(Be=>Be.type!=="branch"&&typeof Be.reference=="string"&&Be.reference.length>0).length;return xe>0?t.jsx("span",{className:"text-[10px] text-fg-tertiary font-normal",children:xe}):null})()]})]}),H==="logs"&&t.jsxs("div",{className:"overflow-x-hidden min-w-0",children:[X&&t.jsxs("div",{className:"mx-4 mt-3 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:[t.jsx("span",{className:"font-medium",children:"Failed to start:"})," ",X]}),t.jsx(rL,{taskId:e.id,isVisible:!0,isRunning:e.status==="in_progress",authUser:m})]}),H==="details"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Project"}),t.jsxs("select",{value:e.projectId??"",onChange:xe=>{De(xe.target.value)},disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"No Project"}),s.map(xe=>t.jsx("option",{value:xe.id,children:xe.name},xe.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Requirement"}),t.jsxs("select",{value:e.requirementId??"",onChange:xe=>ie(()=>ae.tasks.update(e.id,{requirementId:xe.target.value||null})),disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"No Requirement"}),i.filter(xe=>!e.projectId||xe.projectId===e.projectId).map(xe=>t.jsx("option",{value:xe.id,children:xe.title},xe.id))]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Assignee"}),t.jsxs("select",{value:e.assignedAgentId??"",onChange:xe=>{ke(xe.target.value)},disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"Unassigned"}),r.map(xe=>t.jsxs("option",{value:xe.id,children:[xe.name," (",xe.status,")"]},xe.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Reviewer"}),t.jsx("select",{value:e.reviewerAgentId??"",onChange:xe=>{xe.target.value&&xe.target.value!==e.reviewerAgentId&&ie(()=>ae.tasks.update(e.id,{reviewerAgentId:xe.target.value}))},disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:r.map(xe=>t.jsx("option",{value:xe.id,children:xe.name},xe.id))})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:"Priority"}),t.jsxs("select",{value:e.priority,onChange:xe=>{je(xe.target.value)},disabled:N,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"low",children:"Low"}),t.jsx("option",{value:"medium",children:"Medium"}),t.jsx("option",{value:"high",children:"High"}),t.jsx("option",{value:"urgent",children:"Urgent"})]})]})]})]}),t.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&t.jsxs("span",{children:["Created by ",t.jsx("span",{className:"text-fg-secondary",children:el(e.createdBy,r,c)??e.createdBy})]}),e.updatedBy&&t.jsxs("span",{children:["Updated by ",t.jsx("span",{className:"text-fg-secondary",children:el(e.updatedBy,r,c)??e.updatedBy})]}),e.createdAt&&t.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&t.jsxs("span",{children:["Started ",new Date(e.startedAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:["Updated ",new Date(e.updatedAt).toLocaleDateString()]}),e.projectId&&t.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&t.jsxs("span",{className:"text-amber-600",children:["Round ",e.executionRound]})]}),t.jsxs("div",{className:"px-6 py-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:["Subtasks ",h.length>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[ht,"/",h.length," done"]})]}),t.jsx("button",{onClick:()=>w(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:"+ Add subtask"})]}),h.length>0&&t.jsx("div",{className:"space-y-1.5 mb-3",children:h.map(xe=>t.jsxs("div",{className:"group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors",children:[t.jsx("button",{onClick:()=>{Ae(xe)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${xe.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:xe.status==="completed"&&t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),t.jsx("span",{className:`flex-1 text-sm ${xe.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:xe.title}),t.jsx("button",{onClick:()=>T(xe),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},xe.id))}),h.length===0&&!p&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:"No subtasks yet."}),p&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:g,onChange:xe=>b(xe.target.value),onKeyDown:xe=>{xe.key==="Enter"&&Ze(),xe.key==="Escape"&&(w(!1),b(""))},placeholder:"Subtask title...",className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{onClick:()=>{Ze()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:"Add"}),t.jsx("button",{onClick:()=>{w(!1),b("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:"Cancel"})]}),(()=>{const xe=(e.deliverables??[]).filter(pt=>pt.type!=="branch"&&typeof pt.reference=="string"&&pt.reference.length>0);if(xe.length===0)return null;const Be={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},gt=xe.slice(0,3);return t.jsxs("div",{className:"mt-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:["Deliverables ",t.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",xe.length,")"]})]}),xe.length>3&&t.jsx("button",{onClick:()=>M("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:"View all →"})]}),t.jsx("div",{className:"space-y-1.5",children:gt.map((pt,ue)=>{const Se=pt.reference.split("/").pop()??pt.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Be[pt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:pt.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>F(pt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:pt.reference,children:Se}),pt.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:pt.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:pt.reference})]})]},ue)})})]})})(),e.notes&&e.notes.length>0&&(()=>{const xe=[...e.notes].reverse().slice(0,3);return t.jsxs("div",{className:"mt-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:["Progress Notes ",t.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",e.notes.length,")"]})]}),e.notes.length>3&&t.jsx("button",{onClick:()=>M("notes"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:"View all →"})]}),t.jsx("div",{className:"space-y-1.5",children:xe.map((Be,gt)=>t.jsx("div",{className:"text-xs text-fg-secondary bg-surface-elevated/60 rounded px-2.5 py-1.5 leading-relaxed",children:t.jsx(er,{content:Be,className:"text-xs text-fg-secondary"})},gt))})]})})()]})]}),H==="notes"&&t.jsx("div",{className:"px-6 py-4",children:e.notes&&e.notes.length>0?(()=>{const xe=[...e.notes].reverse(),Be=Math.ceil(xe.length/Z),gt=xe.slice((R-1)*Z,R*Z);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:["Progress Notes ",t.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",e.notes.length,")"]})]}),Be>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:R<=1,onClick:()=>z(pt=>pt-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[R,"/",Be]}),t.jsx("button",{disabled:R>=Be,onClick:()=>z(pt=>pt+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),t.jsx("div",{className:"space-y-1.5",children:gt.map((pt,ue)=>t.jsx("div",{className:"text-xs text-fg-secondary bg-surface-elevated/60 rounded px-2.5 py-1.5 leading-relaxed",children:t.jsx(er,{content:pt,className:"text-xs text-fg-secondary"})},ue))})]})})():t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:"No progress notes yet."})}),H==="deliverables"&&t.jsx("div",{className:"px-6 py-4",children:(()=>{const xe=(e.deliverables??[]).filter(ue=>ue.type!=="branch"&&typeof ue.reference=="string"&&ue.reference.length>0);if(xe.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:"No deliverables yet."});const Be={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},gt=Math.ceil(xe.length/Z),pt=xe.slice((L-1)*Z,L*Z);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:["Deliverables ",t.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",xe.length,")"]})]}),gt>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:L<=1,onClick:()=>W(ue=>ue-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[L,"/",gt]}),t.jsx("button",{disabled:L>=gt,onClick:()=>W(ue=>ue+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),t.jsx("div",{className:"space-y-1.5",children:pt.map((ue,Se)=>{const Ke=ue.reference.split("/").pop()??ue.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Be[ue.type]??"bg-gray-500/15 text-fg-secondary"}`,children:ue.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>F(ue.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:ue.reference,children:Ke}),ue.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:ue.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:ue.reference})]})]},Se)})})]})})()})]}),It&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Ht?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:Ht?"text-amber-600":"text-brand-500",children:Ht?"⏸ Schedule Paused":t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3.5 h-3.5 inline -mt-0.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})," Scheduled"]})}),t.jsx("span",{className:"text-fg-tertiary",children:"·"}),t.jsx("span",{className:"text-fg-secondary",children:e.scheduleConfig.every?`Every ${e.scheduleConfig.every}`:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.runAt?"One-shot":"N/A"}),!Ht&&e.scheduleConfig.nextRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-fg-tertiary",children:"·"}),t.jsxs("span",{className:"text-fg-secondary",children:["Next: ",(()=>{const xe=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(xe<=0)return"due now";const Be=Math.floor(xe/6e4);if(Be<60)return`in ${Be}m`;const gt=Math.floor(Be/60);return gt<24?`in ${gt}h ${Be%60}m`:`in ${Math.floor(gt/24)}d ${gt%24}h`})()]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[t.jsxs("span",{children:["Runs: ",e.scheduleConfig.currentRuns??0,e.scheduleConfig.maxRuns!=null?` / ${e.scheduleConfig.maxRuns}`:""]}),e.scheduleConfig.lastRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsxs("span",{children:["Last: ",(()=>{const xe=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),Be=Math.floor(xe/6e4);if(Be<1)return"just now";if(Be<60)return`${Be}m ago`;const gt=Math.floor(Be/60);return gt<24?`${gt}h ${Be%60}m ago`:`${Math.floor(gt/24)}d ago`})()]})]})]})]}),t.jsx("div",{className:"px-6 py-4 border-t border-border-default flex items-center justify-between gap-2",children:t.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.status==="pending_approval"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>ie(()=>ae.tasks.approve(e.id)),disabled:N,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:"Approve"}),t.jsx("button",{onClick:()=>ie(()=>ae.tasks.reject(e.id)),disabled:N,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:"Reject"})]}),e.status==="review"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.accept(e.id,m?.id))},disabled:N,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:"✓ Approve"}),G?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:K,onChange:xe=>B(xe.target.value),onKeyDown:xe=>{xe.key==="Enter"&&K.trim()&&(ie(()=>ae.tasks.revision(e.id,K.trim(),m?.id)),U(!1),B(""))},placeholder:"Revision reason…",autoFocus:!0,className:"px-2 py-1 text-xs bg-surface-elevated border border-amber-500/40 rounded-lg text-fg-primary focus:border-amber-400 outline-none w-48"}),t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.revision(e.id,K.trim()||"Revisions needed",m?.id)),U(!1),B("")},disabled:N,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:"Send"}),t.jsx("button",{onClick:()=>{U(!1),B("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>U(!0),disabled:N,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:"↻ Request Revision"})]}),Ct&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{Ie()},disabled:N,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[t.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),t.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),"Pause"]}),t.jsxs("button",{onClick:()=>{Lt()},disabled:N,className:"px-3 py-1.5 text-xs border border-blue-500/30 text-blue-600 rounded-lg hover:bg-blue-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),"Retry"]})]}),Ft&&t.jsx("button",{onClick:()=>{ze()},disabled:Y,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:Y?t.jsx(t.Fragment,{children:"Resuming…"}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),"Resume"]})}),Me&&t.jsxs("button",{onClick:()=>{Lt()},disabled:N,className:"px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),"Retry"]}),It&&(be||Me)&&t.jsx("button",{onClick:()=>{le()},disabled:Y,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1.5",children:Y?t.jsx(t.Fragment,{children:"Running…"}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),"Run Now"]})}),It&&!Ct&&(Ht?t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.resumeSchedule(e.id))},disabled:N,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:"▶ Resume Schedule"}):t.jsx("button",{onClick:()=>{ie(()=>ae.tasks.pauseSchedule(e.id))},disabled:N,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50",children:"⏸ Pause Schedule"})),be&&t.jsx("button",{onClick:()=>ie(()=>ae.tasks.archive(e.id)),disabled:N,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:"Archive"}),rt&&t.jsx("button",{onClick:()=>{xt()},disabled:N,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary disabled:opacity-50",children:"Reopen"}),!rt&&e.status!=="pending_approval"&&t.jsx("button",{onClick:async()=>{const{count:xe}=await ae.tasks.getDependentCount(e.id);xe>0?C({dependentCount:xe}):ie(()=>ae.tasks.cancel(e.id))},disabled:N,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:"Cancel"})]})})]}),S&&t.jsx(sj,{title:`Delete subtask "${S.title}"?`,message:"This subtask will be permanently deleted.",confirmLabel:"Delete",onConfirm:()=>{We(S)},onCancel:()=>T(null)}),E&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>C(null),children:t.jsxs("div",{className:"bg-surface-default border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:xe=>xe.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:"Cancel Task"}),t.jsxs("p",{className:"text-sm text-fg-secondary mb-4",children:["This task has ",t.jsx("span",{className:"text-amber-600 font-medium",children:E.dependentCount})," dependent task",E.dependentCount>1?"s":""," that ",E.dependentCount>1?"are":"is"," currently blocked by it."]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("button",{onClick:()=>{C(null),ie(()=>ae.tasks.cancel(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-surface-elevated border border-border-default rounded-lg hover:bg-surface-overlay text-fg-primary text-left",children:[t.jsx("span",{className:"font-medium",children:"Cancel this task only"}),t.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:"Dependent tasks will start if they have no other blockers"})]}),t.jsxs("button",{onClick:()=>{C(null),ie(()=>ae.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[t.jsx("span",{className:"font-medium",children:"Cancel with all dependents"}),t.jsxs("span",{className:"block text-xs text-red-500/70 mt-0.5",children:["Also cancels ",E.dependentCount," blocked task",E.dependentCount>1?"s":""]})]}),t.jsx("button",{onClick:()=>C(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:"Keep task running"})]})]})}),q&&t.jsx(sL,{filePath:q,onClose:()=>F(null)})]})}function iL({project:e,tasks:r,requirements:s,agents:i,onDeleteProject:o,onUpdateProject:c,onRefresh:u}){const f=j.useMemo(()=>r.filter(b=>b.projectId===e.id),[r,e.id]),m=j.useMemo(()=>s.filter(b=>b.projectId===e.id),[s,e.id]),h=j.useMemo(()=>{const b={total:f.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:m.length,reqsDone:0};for(const p of f)p.status==="completed"||p.status==="accepted"?b.completed++:p.status==="in_progress"?b.inProgress++:p.status==="review"||p.status==="revision"?b.inReview++:p.status==="blocked"?b.blocked++:p.status==="failed"?b.failed++:b.pending++;for(const p of m)p.status==="completed"&&b.reqsDone++;return b},[f,m]),x=j.useMemo(()=>new Set(f.map(b=>b.assignedAgentId).filter(Boolean)),[f]),g=j.useMemo(()=>i.filter(b=>x.has(b.id)),[i,x]);return t.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[t.jsxs("div",{className:"flex items-start justify-between",children:[t.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[t.jsx(Zz,{value:e.description??"",onSave:async b=>{await c({description:b}),u()},className:"text-sm text-fg-secondary",placeholder:"Add a project description…"}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[t.jsx(mL,{status:e.status}),e.createdAt&&t.jsxs("span",{className:"text-fg-tertiary",children:["Created ",new Date(e.createdAt).toLocaleDateString()]})]})]}),t.jsx("button",{onClick:o,className:"text-xs text-red-500 hover:text-red-500 shrink-0 ml-4",children:"Delete Project"})]}),t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Task Overview"}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(zs,{label:"Total",value:h.total,color:"text-fg-primary"}),t.jsx(zs,{label:"Completed",value:h.completed,color:"text-green-600"}),t.jsx(zs,{label:"In Progress",value:h.inProgress,color:"text-brand-500"}),t.jsx(zs,{label:"In Review",value:h.inReview,color:"text-brand-500"}),t.jsx(zs,{label:"Blocked",value:h.blocked,color:"text-amber-600"}),t.jsx(zs,{label:"Failed",value:h.failed,color:"text-red-500"})]}),h.total>0&&t.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[h.completed>0&&t.jsx("div",{className:"bg-green-500",style:{width:`${h.completed/h.total*100}%`}}),h.inProgress>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${h.inProgress/h.total*100}%`}}),h.inReview>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${h.inReview/h.total*100}%`}}),h.blocked>0&&t.jsx("div",{className:"bg-amber-500",style:{width:`${h.blocked/h.total*100}%`}}),h.pending>0&&t.jsx("div",{className:"bg-blue-500/40",style:{width:`${h.pending/h.total*100}%`}}),h.failed>0&&t.jsx("div",{className:"bg-red-500",style:{width:`${h.failed/h.total*100}%`}})]})]}),t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Requirements"}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(zs,{label:"Total",value:h.reqs,color:"text-fg-primary"}),t.jsx(zs,{label:"Completed",value:h.reqsDone,color:"text-green-600"}),t.jsx(zs,{label:"Active",value:h.reqs-h.reqsDone,color:"text-brand-500"})]})]}),g.length>0&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsxs("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:["Agents (",g.length,")"]}),t.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(b=>{const p=f.filter(S=>S.assignedAgentId===b.id),w=p.filter(S=>!["completed","failed","cancelled","archived"].includes(S.status));return t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-elevated/60 rounded-lg",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${b.status==="working"?"bg-blue-500":b.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:b.name}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[w.length," active / ",p.length," total"]})]},b.id)})})]}),e.repositories&&e.repositories.length>0&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-2",children:"Repositories"}),e.repositories.map((b,p)=>t.jsxs("div",{className:"text-sm text-fg-secondary flex items-center gap-2",children:[t.jsx("span",{className:"text-fg-tertiary",children:"⎇"}),t.jsx("span",{children:b.url||b.localPath}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",b.defaultBranch,")"]})]},p))]})]})}function zs({label:e,value:r,color:s}){return t.jsxs("div",{className:"text-center py-2",children:[t.jsx("div",{className:`text-xl font-bold ${s}`,children:r}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const $u={draft:{label:"Draft",cls:"bg-gray-500/15 text-fg-secondary"},pending_review:{label:"Pending",cls:"bg-amber-500/15 text-amber-600"},approved:{label:"Approved",cls:"bg-green-500/15 text-green-600"},in_progress:{label:"Active",cls:"bg-brand-500/15 text-brand-500"},completed:{label:"Done",cls:"bg-green-500/15 text-green-600"},rejected:{label:"Rejected",cls:"bg-red-500/15 text-red-500"},cancelled:{label:"Cancelled",cls:"bg-gray-600/15 text-fg-tertiary"}},oN={draft:"todo",pending_review:"todo",approved:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed"},cN={failed:"rejected",todo:"approved",in_progress:"in_progress",review:"approved",done:"completed",closed:"cancelled"},lL={urgent:0,high:1,medium:2,low:3},Dv={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},oL={failed:"border-l-red-500 bg-red-500/5",todo:"border-l-blue-500 bg-blue-500/5",in_progress:"border-l-brand-500 bg-brand-500/5",review:"border-l-purple-500 bg-brand-500/5",done:"border-l-green-500 bg-green-500/5",closed:"border-l-gray-500 bg-gray-500/5"},cL={failed:"border-l-red-500 text-red-500",todo:"border-l-blue-500 text-blue-600",in_progress:"border-l-brand-500 text-brand-500",review:"border-l-purple-500 text-brand-500",done:"border-l-green-500 text-green-600",closed:"border-l-gray-500 text-fg-tertiary"},uN=["draft","pending_review","approved","in_progress","completed","rejected","cancelled"];function uL(e){for(const r of To)if(r.statuses.includes(e))return r.id;return"closed"}function dL(e){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Ov({row:e,idx:r,dragIdx:s,agentMap:i,projMap:o,onTaskClick:c,onReqClick:u,onRowDragStart:f,onRowDragEnd:m,handleStatusChange:h,handlePriorityChange:x}){const g=e.data.status,b=e.data.priority,p=e.kind==="task"?i.get(e.data.assignedAgentId??""):void 0,w=o.get((e.kind==="task",e.data.projectId??""));return t.jsxs("div",{draggable:!0,onDragStart:S=>f(S,r),onDragEnd:m,onClick:()=>e.kind==="task"?c(e.data):u(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer hover:bg-surface-elevated/50 transition-colors border-l-2 ${oL[e.group]??"border-l-gray-700"} ${s===r?"opacity-40":""}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:e.kind==="req"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:"REQ"}):e.data.taskType==="scheduled"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600 inline-flex items-center gap-0.5",title:"Scheduled task",children:"SCHED"}):t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:"TASK"})}),t.jsx("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate",children:e.data.title}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:S=>S.stopPropagation(),children:t.jsx("select",{value:g,onChange:S=>{h(e,S.target.value)},className:"w-full px-1.5 py-1 bg-surface-elevated/80 border border-border-default/50 rounded text-[11px] text-fg-secondary outline-none focus:border-brand-500 cursor-pointer",children:e.kind==="task"?Qz.map(S=>t.jsx("option",{value:S,children:Kz[S]??S},S)):uN.map(S=>t.jsx("option",{value:S,children:$u[S]?.label??S},S))})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:S=>S.stopPropagation(),children:t.jsxs("select",{value:b,onChange:S=>{x(e,S.target.value)},className:"w-full px-1.5 py-1 bg-surface-elevated/80 border border-border-default/50 rounded text-[11px] text-fg-secondary outline-none focus:border-brand-500 cursor-pointer",children:[t.jsx("option",{value:"low",children:"Low"}),t.jsx("option",{value:"medium",children:"Medium"}),t.jsx("option",{value:"high",children:"High"}),t.jsx("option",{value:"urgent",children:"Urgent"})]})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] text-fg-secondary truncate",children:p?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${lN[p.status]??"bg-gray-500"}`}),p.name]}):t.jsx("span",{className:"text-fg-tertiary",children:"—"})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] text-fg-tertiary truncate",children:w?.name??t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-tertiary text-right",children:dL(e.data.updatedAt??"")})]})}function fL({tasks:e,requirements:r,agents:s,projects:i,onTaskClick:o,onReqClick:c,onRefresh:u}){const[f,m]=j.useState("status"),[h,x]=j.useState(null),[g,b]=j.useState(null),p=j.useMemo(()=>{const q=[];for(const F of e){const D=uL(F.status);q.push({kind:"task",data:F,group:D,groupOrder:Dv[D]??5})}for(const F of r){const D=oN[F.status]??"todo";q.push({kind:"req",data:F,group:D,groupOrder:Dv[D]??5})}if(f==="status")q.sort((F,D)=>{if(F.groupOrder!==D.groupOrder)return F.groupOrder-D.groupOrder;const _=new Date(F.data.updatedAt??0).getTime();return new Date(D.data.updatedAt??0).getTime()-_});else{const F=D=>lL[D.data.priority]??2;q.sort((D,_)=>{const I=F(D),A=F(_);return I!==A?I-A:new Date(_.data.updatedAt??0).getTime()-new Date(D.data.updatedAt??0).getTime()})}return q},[e,r,f]),w=async(q,F)=>{try{q.kind==="task"?await ae.tasks.updateStatus(q.data.id,F):await ae.requirements.updateStatus(q.data.id,F),u()}catch{}},S=async(q,F)=>{try{q.kind==="task"?await ae.tasks.update(q.data.id,{priority:F}):await ae.requirements.update(q.data.id,{priority:F}),u()}catch{}},T=(q,F)=>{x(F),q.dataTransfer.effectAllowed="move",q.dataTransfer.setData("text/plain",String(F)),q.currentTarget.style.opacity="0.4"},E=q=>{q.currentTarget.style.opacity="1",x(null),b(null)},C=(q,F)=>{q.preventDefault(),q.dataTransfer.dropEffect="move",g!==F&&b(F)},N=async(q,F)=>{if(q.preventDefault(),b(null),h==null)return;const D=p[h];if(!D||D.group===F)return;const _=To.find(I=>I.id===F);if(_){try{if(D.kind==="task"){if(D.data.status==="pending_approval")return;await ae.tasks.updateStatus(D.data.id,_.dropStatus)}else{const I=cN[F];I&&await ae.requirements.updateStatus(D.data.id,I)}u()}catch{}x(null)}},k=j.useMemo(()=>new Map(s.map(q=>[q.id,q])),[s]),H=j.useMemo(()=>new Map(i.map(q=>[q.id,q])),[i]),M=["todo","in_progress","review","done"],Y=j.useMemo(()=>{const q={};for(const F of p)q[F.group]=(q[F.group]??0)+1;return q},[p]),{rowsByGroup:$,rowIndexMap:X}=j.useMemo(()=>{const q=new Map,F=new Map;for(let D=0;D<p.length;D++){const _=p[D];F.set(_,D);const I=q.get(_.group)??[];I.push(_),q.set(_.group,I)}return{rowsByGroup:q,rowIndexMap:F}},[p]),P=j.useMemo(()=>{if(f!=="status")return null;const q=new Set(p.map(_=>_.group)),F=[],D=new Set;q.has("failed")&&(F.push("failed"),D.add("failed"));for(const _ of M)F.push(_),D.add(_);for(const _ of p)D.has(_.group)||(F.push(_.group),D.add(_.group));return F},[p,f]);return t.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:t.jsxs("div",{className:"min-w-[850px] h-full flex flex-col",children:[t.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider shrink-0 bg-surface-secondary/80",children:[t.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:p.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:"Title"}),t.jsxs("button",{onClick:()=>m("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:["Status ",f==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>m("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:["Priority ",f==="priority"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsx("div",{className:"w-[120px] shrink-0",children:"Assignee"}),t.jsx("div",{className:"w-[120px] shrink-0",children:"Project"}),t.jsx("div",{className:"w-[90px] shrink-0 text-right",children:"Updated"})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[f==="status"&&P?P.map(q=>{const F=To.find(_=>_.id===q),D=$.get(q)??[];return t.jsxs("div",{children:[t.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-secondary/60 sticky top-0 z-10 ${cL[q]??""} ${g===q?"ring-1 ring-brand-500/40":""}`,onDragOver:_=>C(_,q),onDragLeave:()=>b(null),onDrop:_=>{N(_,q)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:F?.label??q}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Y[q]??0})]}),D.map(_=>t.jsx(Ov,{row:_,idx:X.get(_)??0,dragIdx:h,agentMap:k,projMap:H,onTaskClick:o,onReqClick:c,onRowDragStart:T,onRowDragEnd:E,handleStatusChange:w,handlePriorityChange:S},`${_.kind}-${_.data.id}`))]},q)}):p.map((q,F)=>t.jsx(Ov,{row:q,idx:F,dragIdx:h,agentMap:k,projMap:H,onTaskClick:o,onReqClick:c,onRowDragStart:T,onRowDragEnd:E,handleStatusChange:w,handlePriorityChange:S},`${q.kind}-${q.data.id}`)),p.length===0&&t.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-fg-tertiary",children:"No items"})]})]})})}function Rv({authUser:e}){const r=gs(),[s,i]=j.useState([]),[o,c]=j.useState("all"),[u,f]=j.useState(null),[m,h]=j.useState({}),[x,g]=j.useState([]),[b,p]=j.useState([]),[w,S]=j.useState([]),[T,E]=j.useState(!0),[C,N]=j.useState(""),[k,H]=j.useState(!1),M=j.useCallback(()=>{Se(u??""),Ht(!0)},[u]),[Y,$]=j.useState(!1),[X,P]=j.useState(!1),[q,F]=j.useState(""),[D,_]=j.useState(""),[I,A]=j.useState("medium"),[G,U]=j.useState(""),[K,B]=j.useState(""),[L,W]=j.useState(""),[R,z]=j.useState(""),[V,Q]=j.useState([]),[te,Z]=j.useState("standard"),[ee,ie]=j.useState("4h"),[je,ke]=j.useState(null),[De,Ie]=j.useState(null),[ze,Ze]=j.useState(new Set),[Ae,We]=j.useState(new Set),xt=j.useRef(new Set),Lt=j.useRef(new Set),[le,_e]=j.useState(null),[ht,Ct]=j.useState("backlog"),[Ft,be]=j.useState(!1),[Me,Ve]=j.useState(!1),Xe=j.useRef(null),rt=j.useRef(null),[It,Ht]=j.useState(!1),[_t,wt]=j.useState(""),[xe,Be]=j.useState(""),[gt,pt]=j.useState("medium"),[ue,Se]=j.useState(""),[Ke,At]=j.useState(null),[rn,vn]=j.useState(""),Mt=ne=>{N(ne),setTimeout(()=>N(""),3e3)},oe=s.find(ne=>ne.id===u)??null;j.useEffect(()=>{Lt.current=Ae},[Ae]);const Le=j.useCallback(async()=>{try{const{projects:ne}=await ae.projects.list();i(ne)}catch{}},[]),$e=j.useCallback(async()=>{const ne={};o==="project"&&u&&(ne.projectId=u);try{const{board:Oe}=await ae.tasks.board(ne);h(Oe)}catch{}},[o,u]),st=j.useCallback(async()=>{try{const{agents:ne}=await ae.agents.list();g(ne)}catch{}},[]),at=j.useCallback(async()=>{try{const{users:ne}=await ae.users.list(e?.orgId);p(ne)}catch{}},[e?.orgId]),Ue=j.useCallback(async()=>{try{const{requirements:ne}=await ae.requirements.list({});S(ne)}catch{}},[]),jn=j.useCallback(async()=>{await Promise.all([Le(),$e(),st(),at(),Ue()]),E(!1)},[Le,$e,st,at,Ue]);j.useEffect(()=>{jn()},[jn]);const gn=j.useRef(je);gn.current=je,j.useEffect(()=>{const Oe=setInterval(()=>{$e(),st(),Ue()},je?6e4:15e3),Pe=En.on("task:update",et=>{gn.current||($e(),Ue());const re=et?.payload;re?.taskId&&ke(pe=>{if(!pe||pe.id!==re.taskId)return pe;const Ne={};return typeof re.status=="string"&&(Ne.status=re.status),Array.isArray(re.deliverables)&&(Ne.deliverables=re.deliverables),Array.isArray(re.notes)&&(Ne.notes=re.notes),re.result!==void 0&&(Ne.result=re.result),{...pe,...Ne}})});return()=>{clearInterval(Oe),Pe()}},[$e,st,Ue,je]);const Dt=j.useRef(m);Dt.current=m,j.useEffect(()=>{const ne=localStorage.getItem("markus_nav_openTask");if(!ne)return;const Pe=Object.values(m).flat().find(et=>et.id===ne);Pe&&(ke(Pe),localStorage.removeItem("markus_nav_openTask"))},[m]),j.useEffect(()=>{const ne=window.location.hash.slice(1).split("/");if(ne[0]==="projects"&&ne[1])Dn(ne[1]);else{const Oe=localStorage.getItem("markus_nav_projectId");Oe&&(localStorage.removeItem("markus_nav_projectId"),Dn(Oe))}},[]),j.useEffect(()=>{const ne=()=>{const Pe=window.location.hash.slice(1).split("/");Pe[0]==="projects"&&Pe[1]?Dn(Pe[1]):Pe[0]==="projects"&&Un()},Oe=Pe=>{const et=Pe.detail;if(et.page==="tasks"||et.page==="projects"){if(et.params?.openTask){const pe=Object.values(Dt.current).flat().find(Ne=>Ne.id===et.params.openTask);pe&&ke(pe)}et.params?.projectId&&Dn(et.params.projectId),!et.params?.projectId&&!et.params?.openTask&&Un()}};return window.addEventListener("markus:navigate",Oe),window.addEventListener("hashchange",ne),()=>{window.removeEventListener("markus:navigate",Oe),window.removeEventListener("hashchange",ne)}},[]);const Dn=ne=>{Lt.current.size>0&&(xt.current=new Set(Lt.current)),We(new Set),f(ne),c("project"),H(!1),history.replaceState(null,"","#projects/"+ne)},Un=()=>{We(xt.current),f(null),c("all"),H(!1),history.replaceState(null,"","#projects")},On=()=>{$(!1),Mt("Project created"),Le()},on=async ne=>{if(confirm("Delete this project and unlink all its tasks?"))try{await ae.projects.delete(ne),u===ne&&Un(),Mt("Project deleted"),Le(),$e()}catch(Oe){Mt(`Error: ${Oe}`)}},cn=async()=>{if(!q||!G||!K)return;if(G===K){Mt("Assigned agent and reviewer must be different");return}const ne=L||void 0,Oe=R||void 0;try{await ae.tasks.create(q,D,G,K,I,ne,V.length>0?V:void 0,Oe,te!=="standard"?te:void 0,te==="scheduled"?{every:ee}:void 0),F(""),_(""),Q([]),z(""),Z("standard"),ie("4h"),P(!1),$e()}catch(Pe){Mt(`Error creating task: ${Pe}`)}},wn=()=>{$e(),je&&setTimeout(()=>{const ne={};o==="project"&&u&&(ne.projectId=u),ae.tasks.board(ne).then(Oe=>{const et=Object.values(Oe.board).flat().find(re=>re.id===je.id);ke(et||null)}).catch(()=>{})},150)},qn=async()=>{if(_t.trim()){if(!ue){Mt("Please select a project for this requirement");return}try{await ae.requirements.create({title:_t,description:xe,priority:gt,projectId:ue}),Mt("Requirement created"),wt(""),Be(""),Ht(!1),Ue()}catch(ne){Mt(`Error: ${ne}`)}}},ve=async ne=>{try{await ae.requirements.approve(ne),Mt("Requirement approved"),Ue(),$e()}catch(Oe){Mt(`Error: ${Oe}`)}},Qe=async()=>{if(Ke)try{await ae.requirements.reject(Ke,rn),Mt("Requirement rejected"),At(null),vn(""),Ue()}catch(ne){Mt(`Error: ${ne}`)}},Nt=async ne=>{try{await ae.requirements.delete(ne),Mt("Requirement cancelled"),Ue()}catch(Oe){Mt(`Error: ${Oe}`)}},Et=(ne,Oe)=>{Xe.current=Oe,rt.current=null,ne.dataTransfer.effectAllowed="move",ne.dataTransfer.setData("text/plain",`task:${Oe.id}`),ne.currentTarget.style.opacity="0.4"},Nn=(ne,Oe)=>{rt.current=Oe,Xe.current=null,ne.dataTransfer.effectAllowed="move",ne.dataTransfer.setData("text/plain",`req:${Oe.id}`),ne.currentTarget.style.opacity="0.4"},ar=ne=>{ne.currentTarget.style.opacity="1",Xe.current=null,rt.current=null,_e(null)},ir=(ne,Oe)=>{ne.preventDefault(),ne.dataTransfer.dropEffect="move",le!==Oe&&_e(Oe)},Or=(ne,Oe)=>{const Pe=ne.currentTarget.getBoundingClientRect(),{clientX:et,clientY:re}=ne;(et<Pe.left||et>Pe.right||re<Pe.top||re>Pe.bottom)&&le===Oe&&_e(null)},Rr=async(ne,Oe)=>{ne.preventDefault(),_e(null);const Pe=Xe.current,et=rt.current;if(Pe){const re=To.find(Ne=>Ne.id===Oe);if(!re)return;const pe=re.dropStatus;if(Pe.status===pe||Pe.status==="pending_approval")return;try{await ae.tasks.updateStatus(Pe.id,pe),$e()}catch{}}else if(et){const re=cN[Oe];if(!re||et.status===re)return;try{await ae.requirements.updateStatus(et.id,re),Ue()}catch{}}},vr=ne=>{Ze(Oe=>{const Pe=new Set(Oe);return Pe.has(ne)?Pe.delete(ne):Pe.add(ne),Pe})},un=ne=>{We(Oe=>{const Pe=new Set(Oe);return Pe.has(ne)?Pe.delete(ne):Pe.add(ne),Pe})},zr=1440*60*1e3,Ps=Date.now(),lr=ne=>ne.status==="completed"&&ne.updatedAt&&Ps-new Date(ne.updatedAt).getTime()>zr,or=(ne,Oe=!1)=>{let Pe=ne.filter(et=>Ft||Oe||!lr(et));return o==="project"&&u&&(Pe=Pe.filter(et=>et.projectId===u)),Ae.size>0&&(Pe=Pe.filter(et=>et.projectId&&Ae.has(et.projectId))),ze.size>0&&(Pe=Pe.filter(et=>et.assignedAgentId&&ze.has(et.assignedAgentId))),Pe},Us=ne=>ne.statuses.flatMap(Oe=>or(m[Oe]??[])),Tn=j.useMemo(()=>{let ne=w;return o==="project"&&u&&(ne=ne.filter(Oe=>Oe.projectId===u)),Ae.size>0&&(ne=ne.filter(Oe=>Oe.projectId&&Ae.has(Oe.projectId))),ze.size>0&&(ne=ne.filter(Oe=>ze.has(Oe.createdBy))),ne},[w,o,u,Ae,ze]),Gr=j.useCallback(ne=>Tn.filter(Oe=>oN[Oe.status]===ne.id),[Tn]),Sa=To.filter(ne=>{if(ne.id==="failed"||ne.id==="closed"){const Oe=Us(ne),Pe=Gr(ne);return Oe.length+Pe.length>0}return!0}),cr=Object.values(m).flat().filter(ne=>lr(ne)).length,Lr=j.useMemo(()=>{const ne=new Set(["completed","failed","cancelled","archived"]),Oe=Object.values(m).flat(),Pe=new Set;for(const et of Oe)et.assignedAgentId&&!ne.has(et.status)&&(!u||et.projectId===u)&&Pe.add(et.assignedAgentId);return[...x].sort((et,re)=>{const pe=Pe.has(et.id)?0:1,Ne=Pe.has(re.id)?0:1;return pe-Ne})},[x,m,u]),Yn=j.useMemo(()=>{const ne=new Set(["completed","failed","cancelled","archived"]),Oe=Object.values(m).flat(),Pe=new Set;for(const et of Oe)et.projectId&&!ne.has(et.status)&&Pe.add(et.projectId);return[...s].sort((et,re)=>{const pe=Pe.has(et.id)?0:1,Ne=Pe.has(re.id)?0:1;return pe-Ne})},[s,m]),kn=j.useMemo(()=>{const ne={};for(const Oe of Object.values(m))for(const Pe of Oe){const et=Pe.projectId??"__none__";ne[et]=(ne[et]??0)+1}return ne},[m]),jr=Object.values(kn).reduce((ne,Oe)=>ne+Oe,0);return T?t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:"Loading…"}):t.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[C&&t.jsx("div",{className:"mx-6 mt-2 px-3 py-1.5 bg-green-500/15 text-green-600 text-xs rounded-lg",children:C}),r?t.jsxs("div",{className:"border-b border-border-default bg-surface-secondary/80 shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[oe?t.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[t.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:oe.name}),t.jsx("button",{onClick:()=>H(!k),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${k?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:s.length===1?s[0].name:`${s.length} Projects`}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>$(!0),className:"px-2 py-1 text-[11px] border border-border-default text-fg-secondary rounded-md",children:"+ Project"}),t.jsx("button",{onClick:M,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:"+ Req"}),t.jsx("button",{onClick:()=>{W(u??""),P(!0)},className:"px-2 py-1 text-[11px] border border-border-default text-fg-secondary rounded-md",children:"+ Task"})]})]}),t.jsxs("div",{className:"flex items-center gap-2 px-3 h-9 border-t border-border-default/40",children:[t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(ne=>t.jsx("button",{onClick:()=>Ct(ne),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${ht===ne?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:ne==="backlog"?"Backlog":ne==="kanban"?"Kanban":"DAG"},ne))}),cr>0&&t.jsx("button",{onClick:()=>be(ne=>!ne),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ft?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Ft?"Hide archived":`${cr} archived`}),t.jsx("div",{className:"flex-1"}),(Ae.size>0||ze.size>0||s.length>1||x.length>0)&&t.jsxs("button",{onClick:()=>Ve(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${Ae.size>0||ze.size>0?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),"Filter",Ae.size+ze.size>0?` (${Ae.size+ze.size})`:""]})]})]}):t.jsxs("div",{className:"flex items-center gap-3 px-6 h-14 border-b border-border-default bg-surface-secondary/80 shrink-0",children:[oe?t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(Xz,{value:oe.name,onSave:async ne=>{await ae.projects.update(oe.id,{name:ne}),Le()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:()=>H(!k),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${k?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:"Project settings",children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:s.length===1?s[0].name:`${s.length} Projects`}),cr>0&&t.jsx("button",{onClick:()=>be(ne=>!ne),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ft?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Ft?`Hide ${cr} archived`:`${cr} archived`}),t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(ne=>t.jsx("button",{onClick:()=>Ct(ne),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${ht===ne?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:ne==="backlog"?"Backlog":ne==="kanban"?"Kanban":"DAG"},ne))}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:M,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:"+ Requirement"}),t.jsx("button",{onClick:()=>{W(u??""),P(!0)},className:"px-3 py-1.5 border border-border-default hover:bg-surface-elevated text-fg-secondary text-xs rounded-lg font-medium transition-colors",children:"+ Task"})]}),t.jsx("div",{className:"flex-1"})]}),!r&&s.length>1&&!u&&!k&&(jr>0||w.length>0)&&t.jsxs("div",{className:"px-6 py-1.5 border-b border-border-default/60 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[t.jsx("button",{onClick:()=>We(new Set),className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${Ae.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),Yn.map(ne=>{const Oe=Ae.has(ne.id),Pe=kn[ne.id]??0;return t.jsxs("button",{onClick:()=>un(ne.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Oe?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${Oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:ne.name[0]?.toUpperCase()}),ne.name,Pe>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:Pe})]},ne.id)})]}),!r&&x.length>0&&!k&&(jr>0||w.length>0)&&t.jsxs("div",{className:"px-6 py-1.5 border-b border-border-default/60 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[t.jsx("button",{onClick:()=>Ze(new Set),className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${ze.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),Lr.map(ne=>{const Oe=ze.has(ne.id);return t.jsxs("button",{onClick:()=>vr(ne.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Oe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:ne.name[0]?.toUpperCase()}),ne.name]},ne.id)})]}),k&&oe?t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsx(iL,{project:oe,tasks:Object.values(m).flat(),requirements:w,agents:x,onDeleteProject:()=>on(oe.id),onUpdateProject:async ne=>{await ae.projects.update(oe.id,ne)},onRefresh:()=>{Le()}})}):jr===0&&Tn.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[t.jsx("div",{className:"w-10 h-10 mx-auto rounded-lg bg-surface-elevated flex items-center justify-center",children:t.jsx("span",{className:"text-fg-tertiary text-lg",children:"☐"})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:"No items yet"}),t.jsxs("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:["Create a requirement to tell agents what you need.",t.jsx("br",{}),"Once approved, tasks will appear here automatically."]}),t.jsx("button",{onClick:M,className:"text-xs text-brand-500 hover:text-brand-500 font-medium",children:"+ Create a requirement"})]})}):ht==="backlog"?t.jsx(fL,{tasks:or(Object.values(m).flat()),requirements:Tn,agents:x,projects:s,onTaskClick:ne=>ke(ne),onReqClick:ne=>Ie(ne),onRefresh:()=>{$e(),Ue()}}):ht==="dag"?t.jsx(Gz,{tasks:or(Object.values(m).flat(),!0),requirements:Tn,agents:x,showArchived:Ft,onShowArchivedChange:be,onTaskClick:ne=>ke(ne),onReqClick:ne=>Ie(ne),onDependencyChange:$e}):t.jsx("div",{className:"flex-1 min-h-0 overflow-x-auto overflow-y-hidden p-6",children:t.jsx("div",{className:"flex gap-4 h-full",children:Sa.map(ne=>{const Oe=Us(ne),Pe=Gr(ne),et=Oe.length+Pe.length,re=le===ne.id;return t.jsxs("div",{className:`w-72 shrink-0 rounded-xl p-3.5 border-t-2 transition-colors flex flex-col h-full ${ne.accent} ${re?"bg-surface-elevated/80 ring-1 ring-brand-500/40":"bg-surface-secondary"}`,onDragOver:pe=>ir(pe,ne.id),onDragLeave:pe=>Or(pe,ne.id),onDrop:pe=>{Rr(pe,ne.id)},children:[t.jsxs("div",{className:"flex justify-between items-center mb-3 shrink-0",children:[t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:ne.label}),t.jsx("span",{className:"text-xs bg-surface-elevated px-2 py-0.5 rounded-full",children:et})]}),t.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin",children:(()=>{const pe=[...Pe.map(Ne=>({kind:"req",data:Ne,time:new Date(Ne.updatedAt??Ne.createdAt).getTime()})),...Oe.map(Ne=>({kind:"task",data:Ne,time:new Date(Ne.updatedAt??Ne.createdAt??0).getTime()}))];return pe.sort((Ne,ye)=>ye.time-Ne.time),pe.map(Ne=>{if(Ne.kind==="req"){const ye=Ne.data,dt=$u[ye.status]??{label:ye.status,cls:"bg-gray-500/15 text-fg-secondary"},Fe=ye.source==="agent"&&(ye.status==="draft"||ye.status==="pending_review"),bt=o==="all"&&ye.projectId?s.find(tt=>tt.id===ye.projectId):null,it=el(ye.createdBy,x,b)??ye.createdBy.slice(0,10);return t.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:tt=>Nn(tt,ye),onDragEnd:ar,onClick:()=>Ie(ye),onKeyDown:tt=>tt.key==="Enter"&&Ie(ye),className:`bg-brand-500/[0.06] border rounded-lg p-3 border-l-[3px] border-l-purple-500 transition-colors cursor-grab active:cursor-grabbing ${Fe?"border-amber-500/40 ring-1 ring-amber-500/20":"border-brand-500/20"} hover:border-brand-400/50`,children:[t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx("span",{className:"text-[9px] font-bold text-brand-500 bg-brand-500/15 px-1.5 py-0.5 rounded shrink-0",children:"REQ"}),t.jsx("span",{className:"text-sm font-medium leading-snug truncate",children:ye.title})]}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${dt.cls}`,children:dt.label})]}),ye.description&&t.jsx("div",{className:"text-xs text-fg-tertiary mt-1 line-clamp-2",children:ye.description}),bt&&t.jsx("div",{className:"mt-1.5",children:t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[120px]",title:bt.name,children:bt.name})}),t.jsxs("div",{className:"flex items-center justify-between mt-2",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs text-fg-tertiary",children:ye.priority}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["by ",it]})]}),t.jsx("div",{className:"flex items-center gap-1.5",children:ye.taskIds.length>0&&t.jsxs("span",{className:"text-[10px] text-brand-500/60 bg-brand-500/10 px-1.5 py-0.5 rounded",children:[ye.taskIds.length," tasks"]})})]}),Fe&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-brand-500/10",children:[t.jsx("button",{onClick:tt=>{tt.stopPropagation(),ve(ye.id)},className:"px-2.5 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:"Approve"}),t.jsx("button",{onClick:tt=>{tt.stopPropagation(),At(ye.id)},className:"px-2.5 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:"Reject"})]})]},`req-${ye.id}`)}else{const ye=Ne.data,dt=ye.subtasks?.length??0,He=iN[ye.status],Fe=ye.status==="pending_approval",bt=ye.taskType==="scheduled"&&!!ye.scheduleConfig,it=bt?ye.scheduleConfig.every?`Every ${ye.scheduleConfig.every}`:ye.scheduleConfig.cron?"Cron":"Scheduled":null,tt=o==="all"&&ye.projectId?s.find(hn=>hn.id===ye.projectId)?.name:null,Xt=ye.requirementId?w.find(hn=>hn.id===ye.requirementId)?.title:null,Zt=ye.createdBy?el(ye.createdBy,x,b)??ye.createdBy:null;return t.jsxs("div",{role:"button",tabIndex:0,"aria-label":ye.title,draggable:!Fe,onDragStart:hn=>!Fe&&Et(hn,ye),onDragEnd:ar,onClick:()=>ke(ye),onKeyDown:hn=>hn.key==="Enter"&&ke(ye),className:`border rounded-lg p-3 border-l-[3px] transition-colors ${Fe?"bg-amber-500/[0.04] border-amber-500/30 border-l-amber-500 cursor-pointer":bt?`bg-blue-500/[0.03] border-blue-500/20 ${_m[ye.priority]??""} hover:border-blue-500/40 cursor-pointer`:`bg-surface-elevated border-border-default ${_m[ye.priority]??""} hover:border-brand-500/50 cursor-grab active:cursor-grabbing`}`,children:[t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[bt&&t.jsx("span",{className:"text-blue-600 shrink-0",title:it??"Scheduled",children:t.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})}),t.jsx("div",{className:"text-sm font-medium leading-snug truncate",children:ye.title})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[bt&&it&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-600 whitespace-nowrap",children:it}),He&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${He.cls}`,children:He.label})]})]}),ye.description&&t.jsx("div",{className:"text-xs text-fg-tertiary mt-1 line-clamp-2",children:ye.description}),(tt||Xt)&&t.jsxs("div",{className:"mt-1.5 flex flex-wrap gap-1",children:[tt&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[100px]",title:tt,children:tt}),Xt&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-brand-500/10 text-brand-500 rounded truncate max-w-[120px]",title:Xt,children:["# ",Xt]})]}),ye.blockedBy&&ye.blockedBy.length>0&&t.jsx("div",{className:"mt-1.5 flex items-center gap-1",children:t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded",children:["⏳ ",ye.blockedBy.length," dep",ye.blockedBy.length>1?"s":""]})}),t.jsxs("div",{className:"flex items-center justify-between mt-2",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs text-fg-tertiary",children:ye.priority}),Zt&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",title:`Created by ${Zt}`,children:["by ",Zt]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[dt>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary bg-surface-overlay/50 px-1.5 py-0.5 rounded",children:["⋮ ",dt]}),ye.notes&&ye.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",ye.notes.length]}),ye.assignedAgentId&&t.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/10 px-1.5 py-0.5 rounded flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${lN[x.find(hn=>hn.id===ye.assignedAgentId)?.status??""]??"bg-gray-500"}`}),x.find(hn=>hn.id===ye.assignedAgentId)?.name??ye.assignedAgentId.slice(0,8)]})]})]})]},ye.id)}})})()}),re&&t.jsx("div",{className:"mt-2 border-2 border-dashed border-brand-500/30 rounded-lg h-12 flex items-center justify-center shrink-0",children:t.jsx("span",{className:"text-xs text-brand-500/60",children:"Drop here"})})]},ne.id)})})})]}),Y&&t.jsx(aN,{orgId:e?.orgId,onCreated:On,onClose:()=>$(!1)}),X&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>P(!1),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${r?"w-full":"w-[28rem]"}`,onClick:ne=>ne.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:"New Task"}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Project"}),t.jsxs("select",{value:L,onChange:ne=>W(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"No Project"}),s.map(ne=>t.jsx("option",{value:ne.id,children:ne.name},ne.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Requirement"}),t.jsxs("select",{value:R,onChange:ne=>z(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select a requirement…"}),w.filter(ne=>ne.status==="approved"&&(!L||ne.projectId===L)).map(ne=>t.jsx("option",{value:ne.id,children:ne.title},ne.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{autoFocus:!r,value:q,onChange:ne=>F(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&cn()},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:D,onChange:ne=>_(ne.target.value),rows:2,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Priority"}),t.jsxs("select",{value:I,onChange:ne=>A(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:"Low"}),t.jsx("option",{value:"medium",children:"Medium"}),t.jsx("option",{value:"high",children:"High"}),t.jsx("option",{value:"urgent",children:"Urgent"})]})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:["Assign to ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsxs("select",{value:G,onChange:ne=>U(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select agent…"}),x.map(ne=>t.jsx("option",{value:ne.id,children:ne.name},ne.id))]})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:["Reviewer ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsxs("select",{value:K,onChange:ne=>B(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select reviewer…"}),x.filter(ne=>ne.id!==G).map(ne=>t.jsx("option",{value:ne.id,children:ne.name},ne.id))]})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Task Type"}),t.jsxs("select",{value:te,onChange:ne=>Z(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"standard",children:"Standard"}),t.jsx("option",{value:"scheduled",children:"Scheduled (recurring)"})]})]}),te==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Frequency"}),t.jsxs("select",{value:ee,onChange:ne=>ie(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"30m",children:"Every 30 min"}),t.jsx("option",{value:"1h",children:"Every 1 hour"}),t.jsx("option",{value:"2h",children:"Every 2 hours"}),t.jsx("option",{value:"4h",children:"Every 4 hours"}),t.jsx("option",{value:"8h",children:"Every 8 hours"}),t.jsx("option",{value:"12h",children:"Every 12 hours"}),t.jsx("option",{value:"1d",children:"Every day"}),t.jsx("option",{value:"1w",children:"Every week"})]})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Blocked By (dependencies)"}),t.jsxs("select",{value:"",onChange:ne=>{const Oe=ne.target.value;Oe&&!V.includes(Oe)&&Q([...V,Oe])},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select a task to depend on…"}),Object.values(m).flat().filter(ne=>ne.status!=="completed"&&ne.status!=="cancelled"&&!V.includes(ne.id)).map(ne=>t.jsx("option",{value:ne.id,children:ne.title},ne.id))]}),V.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:V.map(ne=>{const Oe=Object.values(m).flat().find(Pe=>Pe.id===ne);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:["⏳ ",Oe?Oe.title.slice(0,30):ne.slice(-8),t.jsx("button",{onClick:()=>Q(V.filter(Pe=>Pe!==ne)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},ne)})})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>P(!1),className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{onClick:()=>{cn()},disabled:!G||!K,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Create"})]})]})}),je&&t.jsx(aL,{task:je,agents:x,projects:s,requirements:w,allTasks:Object.values(m).flat(),users:b,onClose:()=>ke(null),onRefresh:wn,authUser:e}),It&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ht(!1),wt(""),Be("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${r?"w-full":"w-[28rem]"}`,onClick:ne=>ne.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:"New Requirement"}),t.jsx("p",{className:"text-xs text-fg-tertiary -mt-2",children:"Describe what you need. Agents will break approved requirements into tasks."}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Project"}),t.jsxs("select",{value:ue,onChange:ne=>Se(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select a project…"}),s.map(ne=>t.jsx("option",{value:ne.id,children:ne.name},ne.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{value:_t,onChange:ne=>wt(ne.target.value),placeholder:"e.g. Add user authentication",className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!r,onKeyDown:ne=>{ne.key==="Enter"&&_t.trim()&&qn()}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:xe,onChange:ne=>Be(ne.target.value),placeholder:"What is needed and why...",rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Priority"}),t.jsxs("select",{value:gt,onChange:ne=>pt(ne.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:"Low"}),t.jsx("option",{value:"medium",children:"Medium"}),t.jsx("option",{value:"high",children:"High"}),t.jsx("option",{value:"urgent",children:"Urgent"})]})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{Ht(!1),wt(""),Be("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{onClick:()=>{qn()},className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Create"})]})]})}),Ke&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>At(null),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${r?"w-full":"w-96"}`,onClick:ne=>ne.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:"Reject Requirement"}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Reason"}),t.jsx("textarea",{value:rn,onChange:ne=>vn(ne.target.value),placeholder:"Why is this being rejected...",rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!r})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>At(null),className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{onClick:()=>{Qe()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:"Reject"})]})]})}),De&&t.jsx(hL,{req:De,agents:x,projects:s,allTasks:Object.values(m).flat(),users:b,onClose:()=>Ie(null),onApprove:ne=>{ve(ne),Ie(null)},onReject:ne=>{At(ne),Ie(null)},onCancel:ne=>{Nt(ne),Ie(null)},onStatusChange:async(ne,Oe)=>{try{await ae.requirements.updateStatus(ne,Oe),Mt(`Requirement status → ${Oe}`),Ue(),$e()}catch(Pe){Mt(`Error: ${Pe}`)}}}),Me&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Ve(!1),children:[t.jsx("div",{className:"absolute inset-0 bg-black/50"}),t.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:ne=>ne.stopPropagation(),children:[t.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:"Filters"}),t.jsxs("div",{className:"flex items-center gap-2",children:[(Ae.size>0||ze.size>0)&&t.jsx("button",{onClick:()=>{We(new Set),Ze(new Set)},className:"text-[11px] text-brand-500 font-medium",children:"Clear all"}),t.jsx("button",{onClick:()=>Ve(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),s.length>1&&t.jsxs("div",{className:"px-4 py-3",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:"Projects"}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Yn.map(ne=>{const Oe=Ae.has(ne.id),Pe=kn[ne.id]??0;return t.jsxs("button",{onClick:()=>un(ne.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Oe?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${Oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:ne.name[0]?.toUpperCase()}),ne.name,Pe>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Pe})]},ne.id)})})]}),x.length>0&&t.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:"Agents"}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Lr.map(ne=>{const Oe=ze.has(ne.id);return t.jsxs("button",{onClick:()=>vr(ne.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Oe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:ne.name[0]?.toUpperCase()}),ne.name]},ne.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function hL({req:e,agents:r,projects:s,allTasks:i,users:o,onClose:c,onApprove:u,onReject:f,onCancel:m,onStatusChange:h}){const x=gs(),g=$u[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},b=e.source==="agent",p=b&&(e.status==="draft"||e.status==="pending_review"),w=e.status==="draft"||e.status==="approved",S=e.status==="completed"||e.status==="rejected"||e.status==="cancelled",T=e.projectId?s.find(N=>N.id===e.projectId):null,E=el(e.createdBy,r,o)??e.createdBy.slice(0,12),C=i.filter(N=>e.taskIds.includes(N.id));return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:c,children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl max-h-[85dvh] flex flex-col ${x?"w-full":"w-[36rem]"}`,onClick:N=>N.stopPropagation(),children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded",children:"REQ"}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${g.cls}`,children:g.label}),e.priority==="high"||e.priority==="urgent"?t.jsx("span",{className:`text-[10px] font-medium ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:e.priority}):t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:e.priority})]}),t.jsx("h2",{className:"text-lg font-semibold text-fg-primary leading-snug",children:e.title})]}),t.jsx("button",{onClick:c,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-4",children:[e.description&&t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:"Description"}),t.jsx(er,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:"Created by"}),t.jsx("span",{className:"text-fg-secondary",children:E}),b&&t.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:"(Agent)"})]}),t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:"Created"}),t.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),T&&t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:"Project"}),t.jsx("span",{className:"text-fg-secondary",children:T.name})]}),e.approvedBy&&t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:"Approved by"}),t.jsx("span",{className:"text-fg-secondary",children:el(e.approvedBy,r,o)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:"Rejection Reason"}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.tags&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(N=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",N]},N))}),C.length>0&&t.jsxs("div",{children:[t.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:["Linked Tasks (",C.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:C.map(N=>{const k=iN[N.status];return t.jsxs("div",{className:"flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${_m[N.priority]?.replace("border-l-","bg-")??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:N.title}),k&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${k.cls}`,children:k.label})]},N.id)})})]})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[p&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>u(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:"Approve"}),t.jsx("button",{onClick:()=>f(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:"Reject"})]}),!p&&h&&!S&&t.jsx("select",{value:e.status,onChange:N=>{N.target.value!==e.status&&h(e.id,N.target.value)},className:"px-2 py-1.5 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-secondary cursor-pointer hover:border-gray-500 transition-colors",children:uN.map(N=>{const k=$u[N];return t.jsx("option",{value:N,children:k?.label??N},N)})}),S&&h&&t.jsx("button",{onClick:()=>h(e.id,"approved"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:"Reopen"}),t.jsx("div",{className:"flex-1"}),w&&!p&&t.jsx("button",{onClick:()=>m(e.id),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:"Cancel Requirement"})]})]})})}function mL({status:e}){const r={active:"bg-green-500/10 text-green-600",planning:"bg-blue-500/10 text-blue-600",review:"bg-amber-500/10 text-amber-600",completed:"bg-surface-overlay text-fg-secondary",archived:"bg-surface-elevated text-fg-tertiary",paused:"bg-amber-500/10 text-amber-600"};return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${r[e]??"bg-surface-overlay text-fg-secondary"}`,children:e})}function os(e){return Array.isArray(e)?e.map(r=>String(r).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(r=>r.trim()).filter(Boolean):[]}function xL(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function Fa({label:e,value:r}){return r?t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:r})]}):null}function Li({label:e,value:r,color:s}){if(!r)return null;const i={purple:"bg-brand-500/15 text-brand-500",cyan:"bg-blue-500/15 text-blue-600",indigo:"bg-brand-500/15 text-brand-500",gray:"bg-gray-500/15 text-fg-secondary",emerald:"bg-green-500/15 text-green-600"};return t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${i[s]??i.gray} capitalize inline-block`,children:r})]})}function Gh({files:e}){const[r,s]=j.useState(Object.keys(e)[0]??""),i=Object.keys(e);return i.length===0?null:t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Files (",i.length,")"]}),t.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[t.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:i.map(o=>t.jsx("button",{onClick:()=>s(o),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${r===o?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:o},o))}),r&&e[r]!=null&&t.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[r]})]})]})}function gL({artifact:e,mode:r}){const s=xL(e),i=e.agent,o=e.team,c=e.dependencies,u=e.displayName??e.name;if(r==="agent"){const f=i?.roleName,m=i?.agentRole,h=i?.llmProvider,x=i?.llmModel,g=os(c?.env),b=os(c?.skills);return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Fa,{label:"Name",value:u}),t.jsx(Fa,{label:"Description",value:e.description}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(Li,{label:"Role Template",value:f,color:"indigo"}),t.jsx(Li,{label:"Agent Role",value:m,color:m==="manager"?"purple":"cyan"})]}),os(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:os(e.tags).map(p=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:p},p))}),(h||x)&&t.jsxs("div",{className:"flex gap-2",children:[h&&t.jsx(Li,{label:"LLM Provider",value:h,color:"gray"}),x&&t.jsx(Li,{label:"LLM Model",value:x,color:"gray"})]}),g.length>0&&t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:"Required Env"}),t.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:g.map(p=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/10 text-amber-600 rounded font-mono",children:p},p))})]}),b.length>0&&t.jsx(Fa,{label:"Skills",value:b.join(", ")}),s&&t.jsx(Gh,{files:s})]})}if(r==="team"){const m=o?.members??[];return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Fa,{label:"Name",value:u}),t.jsx(Fa,{label:"Description",value:e.description}),t.jsx("div",{className:"flex flex-wrap gap-2",children:t.jsx(Li,{label:"Category",value:e.category,color:"indigo"})}),os(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:os(e.tags).map(h=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:h},h))}),s&&t.jsx(Gh,{files:s}),t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Members (",m.length,")"]}),t.jsx("div",{className:"mt-1.5 space-y-1.5",children:m.map((h,x)=>t.jsxs("div",{className:"bg-surface-elevated/30 rounded-lg px-2 py-1.5 border border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-5 h-5 rounded flex items-center justify-center text-[10px] font-bold ${h.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:h.role==="manager"?"★":x+1}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:h.name}),typeof h.roleName=="string"&&h.roleName&&t.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:h.roleName}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(h.count??1)]})]}),os(h.skills).length>0&&t.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:os(h.skills).map(g=>t.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:g},g))})]},x))})]})]})}return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Fa,{label:"Name",value:u}),t.jsx(Fa,{label:"Description",value:e.description}),t.jsx("div",{className:"flex gap-2",children:t.jsx(Li,{label:"Category",value:e.category,color:"indigo"})}),s&&t.jsx(Gh,{files:s}),os(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:os(e.tags).map(f=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:f},f))})]})}const to={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},zv={active:{label:"Active",color:"text-green-600 bg-green-500/10"},verified:{label:"Verified",color:"text-blue-600 bg-blue-500/10"},outdated:{label:"Outdated",color:"text-red-500 bg-red-500/10"}},Lv=["file","directory"],cs={agent:{icon:"✦",label:"Agent",color:"bg-brand-500/10 text-brand-500"},team:{icon:"◈",label:"Team",color:"bg-blue-500/10 text-blue-600"},skill:{icon:"⬡",label:"Skill",color:"bg-amber-500/10 text-amber-600"}};function Iv(){const e=gs(),r=ex({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[s,i]=j.useState(!1),o=j.useRef(s);o.current=s,j.useEffect(()=>{if(!e)return;const ve=()=>{o.current&&i(!1)};return window.addEventListener("popstate",ve),()=>window.removeEventListener("popstate",ve)},[e]);const c=100,[u,f]=j.useState([]),[m,h]=j.useState(0),[x,g]=j.useState(!1),[b,p]=j.useState([]),[w,S]=j.useState([]),[T,E]=j.useState(!0),[C,N]=j.useState(""),[k,H]=j.useState(""),[M,Y]=j.useState(""),[$,X]=j.useState(""),[P,q]=j.useState(""),[F,D]=j.useState(""),[_,I]=j.useState(""),[A,G]=j.useState("date"),[U,K]=j.useState(null),[B,L]=j.useState(null),[W,R]=j.useState(""),[z,V]=j.useState(!1),[Q,te]=j.useState(!1),[Z,ee]=j.useState(new Set),ie=j.useRef(null),[je,ke]=j.useState("file"),[De,Ie]=j.useState(""),[ze,Ze]=j.useState(""),[Ae,We]=j.useState(""),[xt,Lt]=j.useState(""),[le,_e]=j.useState(""),[ht,Ct]=j.useState(null),[Ft,be]=j.useState(null),[Me,Ve]=j.useState(!1),[Xe,rt]=j.useState(!1),[It,Ht]=j.useState(!1),[_t,wt]=j.useState(!1),xe=j.useRef(null),Be=j.useRef(null),[gt,pt]=j.useState(""),ue=j.useRef(void 0),Se=(ve,Qe)=>{L({type:ve,text:Qe}),setTimeout(()=>L(null),3e3)},Ke=async ve=>{try{return await navigator.clipboard.writeText(ve),!0}catch{try{const Qe=document.createElement("textarea");Qe.value=ve,Qe.style.cssText="position:fixed;left:-9999px;top:-9999px;opacity:0",document.body.appendChild(Qe),Qe.select();const Nt=document.execCommand("copy");return document.body.removeChild(Qe),Nt}catch{return!1}}},At=async ve=>{await Ke(ve)?(wt(!0),setTimeout(()=>wt(!1),1500)):Se("error","Copy failed — try long-pressing to copy manually")},rn=j.useMemo(()=>new Map(w.map(ve=>[ve.id,ve])),[w]),vn=j.useMemo(()=>new Map(b.map(ve=>[ve.id,ve])),[b]);j.useEffect(()=>{ae.projects.list().then(ve=>p(ve.projects)).catch(()=>{}),ae.agents.list().then(ve=>S(ve.agents??[])).catch(()=>{}),ae.system.storage().then(ve=>pt(ve.dataDir+"/shared")).catch(()=>{})},[]),j.useEffect(()=>(ue.current=setTimeout(()=>H(C),300),()=>clearTimeout(ue.current)),[C]);const Mt=j.useMemo(()=>({q:k||void 0,projectId:$||void 0,agentId:P||void 0,type:M||void 0,status:F||void 0,artifactType:_||void 0}),[k,$,P,M,F,_]),oe=j.useCallback(async()=>{E(!0);try{const{results:ve,total:Qe}=await ae.deliverables.search({...Mt,offset:0,limit:c});f(ve),h(Qe)}catch{f([]),h(0)}E(!1)},[Mt]),Le=j.useCallback(async()=>{if(!(x||u.length>=m)){g(!0);try{const{results:ve,total:Qe}=await ae.deliverables.search({...Mt,offset:u.length,limit:c});f(Nt=>[...Nt,...ve]),h(Qe)}catch{}g(!1)}},[Mt,u.length,m,x]);j.useEffect(()=>{oe()},[oe]),j.useEffect(()=>En.on("deliverable:created",()=>oe()),[oe]);const $e=j.useCallback(()=>{const ve=ie.current;!ve||T||x||u.length>=m||ve.scrollHeight<=ve.clientHeight+100&&Le()},[T,x,u.length,m,Le]);j.useEffect(()=>{const ve=ie.current;if(!ve)return;const Qe=()=>{ve.scrollTop+ve.clientHeight>=ve.scrollHeight-100&&Le()};return ve.addEventListener("scroll",Qe,{passive:!0}),()=>ve.removeEventListener("scroll",Qe)},[Le]),j.useEffect(()=>{$e()},[$e,Z]);const st=j.useMemo(()=>{const ve=new Map;for(const Nt of u){let Et,Nn;if(A==="project")Et=Nt.projectId??"_none",Nn=Nt.projectId?vn.get(Nt.projectId)?.name??Nt.projectId:"No Project";else if(A==="agent")Et=Nt.agentId??"_none",Nn=Nt.agentId?rn.get(Nt.agentId)?.name??Nt.agentId:"Unknown";else if(A==="type")Et=Nt.type,Nn=Nt.type.charAt(0).toUpperCase()+Nt.type.slice(1);else{const ar=new Date(Nt.updatedAt);Et=`${ar.getFullYear()}-${String(ar.getMonth()+1).padStart(2,"0")}-${String(ar.getDate()).padStart(2,"0")}`,Nn=Et}ve.has(Et)||ve.set(Et,{label:Nn,items:[]}),ve.get(Et).items.push(Nt)}const Qe=[...ve.entries()];return A==="date"?Qe.sort((Nt,Et)=>Et[0].localeCompare(Nt[0])):Qe.sort((Nt,Et)=>Nt[1].label.localeCompare(Et[1].label)),Qe},[u,A,vn,rn]),at=async()=>{if(!(!De.trim()||!ze.trim())){te(!0);try{await ae.deliverables.create({type:je,title:De,summary:ze,reference:Ae,projectId:xt||void 0,tags:le.split(",").map(ve=>ve.trim()).filter(Boolean)}),V(!1),Se("success","Deliverable created"),oe()}catch(ve){Se("error",`Error: ${ve}`)}te(!1)}},Ue=async ve=>{R("verify");try{await ae.deliverables.verify(ve.id),Se("success","Verified"),K({...ve,status:"verified"}),oe()}catch(Qe){Se("error",`Error: ${Qe}`)}R("")},jn=async ve=>{R("flag");try{await ae.deliverables.update(ve.id,{status:"outdated"}),Se("success","Flagged as outdated"),K({...ve,status:"outdated"}),oe()}catch(Qe){Se("error",`Error: ${Qe}`)}R("")},gn=async ve=>{R("remove");try{await ae.deliverables.remove(ve.id),Se("success","Removed"),K(null),oe()}catch(Qe){Se("error",`Error: ${Qe}`)}R("")},Dt=()=>{Ut.navigate("builder")},Dn=async ve=>{if(ve.reference){if(ve.type==="directory"){rt(!0);return}Ve(!0);try{const Qe=await ae.files.preview(ve.reference);Qe.type==="image"&&Qe.mimeType?be({src:`data:${Qe.mimeType};base64,${Qe.content}`,name:Qe.name}):Ct(Qe.content)}catch{Ct(null),ve.type==="file"&&rt(!0)}Ve(!1)}};j.useEffect(()=>{Ct(null),be(null),rt(!1),Ht(!1),U&&Dn(U)},[U?.id]),j.useEffect(()=>{if(!It)return;const ve=Qe=>{Be.current&&!Be.current.contains(Qe.target)&&Ht(!1)};return document.addEventListener("mousedown",ve),()=>document.removeEventListener("mousedown",ve)},[It]);const Un=async(ve,Qe)=>{const Nt=xe.current?.firstElementChild;if(!Nt)return;const Et=pL(Nt,ve);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([Et],{type:"text/html"}),"text/plain":new Blob([Qe],{type:"text/plain"})})]),Se("success",ve==="light"?"HTML (light) copied":"HTML (dark) copied")}catch{const Nn=await Ke(Qe);Se(Nn?"success":"error",Nn?"Text copied (HTML not supported)":"Copy failed")}Ht(!1)},On=ve=>t.jsxs("div",{className:"relative group/preview",children:[t.jsxs("div",{className:"absolute -top-1 -right-1 z-10",ref:Be,children:[t.jsx("button",{onClick:()=>Ht(Qe=>!Qe),className:"p-1.5 rounded-lg bg-surface-elevated/80 hover:bg-surface-overlay text-fg-secondary hover:text-fg-primary backdrop-blur-sm border border-border-default/50 transition-all",title:"Copy content",children:t.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),It&&t.jsxs("div",{className:"absolute right-0 top-full mt-1 bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 min-w-[180px]",children:[t.jsxs("button",{onClick:async()=>{const Qe=await Ke(ve);Se(Qe?"success":"error",Qe?"Markdown source copied":"Copy failed"),Ht(!1)},className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[t.jsx("span",{className:"w-4 text-center text-fg-tertiary shrink-0 font-mono text-[10px]",children:"Md"}),"Copy Markdown Source"]}),t.jsxs("button",{onClick:()=>Un("light",ve),className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[t.jsx("span",{className:"w-4 text-center shrink-0",children:"☀️"}),"Copy HTML (Light)"]}),t.jsxs("button",{onClick:()=>Un("dark",ve),className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[t.jsx("span",{className:"w-4 text-center shrink-0",children:"🌙"}),"Copy HTML (Dark)"]})]})]}),t.jsx("div",{ref:xe,children:t.jsx(er,{content:ve,className:"text-fg-secondary text-sm"})})]}),on=j.useCallback(ve=>{ee(Qe=>{const Nt=new Set(Qe);return Nt.has(ve)?Nt.delete(ve):Nt.add(ve),Nt})},[]),cn=j.useCallback(()=>{Z.size===st.length?ee(new Set):ee(new Set(st.map(([ve])=>ve)))},[Z.size,st]),wn=()=>{Ie(""),Ze(""),We(""),_e(""),ke("file"),b.length>0&&Lt(b[0].id),V(!0)},qn=ve=>{K(ve),e&&(i(!0),history.pushState({mobileDetail:"deliverables"},"",window.location.hash))};return t.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[(!e||!s)&&t.jsxs("div",{className:`${e?"flex-1 min-w-0":"shrink-0"} border-r border-border-default flex flex-col bg-surface-primary`,style:e?void 0:{width:r.width},children:[t.jsxs("div",{className:"p-4 border-b border-border-default space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary",children:["Deliverables",m>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",m,")"]})]}),t.jsx("button",{onClick:wn,className:"text-xs px-2.5 py-1 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create"})]}),t.jsx("input",{value:C,onChange:ve=>N(ve.target.value),placeholder:"Search deliverables...",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors"}),gt&&t.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 bg-surface-elevated/50 border border-border-default rounded-lg text-[10px] text-fg-tertiary",children:[t.jsx("span",{className:"truncate font-mono",children:gt}),t.jsx("button",{onClick:()=>{ae.system.openPath(gt)},className:"shrink-0 underline hover:text-fg-secondary transition-colors",children:"Open"})]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(ba,{label:"All types",value:"",current:M||_||"",onClick:()=>{Y(""),I("")}}),Lv.map(ve=>t.jsx(ba,{label:`${to[ve]?.icon??""} ${ve}`,value:ve,current:M,onClick:Qe=>{Y(Qe),I("")}},ve)),["agent","team","skill"].map(ve=>t.jsx(ba,{label:`${cs[ve].icon} ${cs[ve].label}`,value:ve,current:_,onClick:Qe=>{I(Qe),Y("")}},ve))]}),b.length>0&&t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(ba,{label:"All projects",value:"",current:$,onClick:X}),b.map(ve=>t.jsx(ba,{label:ve.name,value:ve.id,current:$,onClick:X},ve.id))]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(ba,{label:"Active",value:"",current:F,onClick:D}),t.jsx(ba,{label:"Verified",value:"verified",current:F,onClick:D}),t.jsx(ba,{label:"Outdated",value:"outdated",current:F,onClick:D})]}),t.jsxs("div",{className:"flex gap-1.5 items-center",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"Group:"}),["date","project","agent","type"].map(ve=>t.jsx("button",{onClick:()=>{G(ve),ee(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${A===ve?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:ve.charAt(0).toUpperCase()+ve.slice(1)},ve)),st.length>1&&t.jsx("button",{onClick:cn,className:"ml-auto px-1.5 py-1 rounded text-[10px] text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:Z.size===st.length?"Expand all":"Collapse all",children:Z.size===st.length?"▶ Expand":"▼ Collapse"})]})]}),B&&t.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${B.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:B.text}),t.jsxs("div",{ref:ie,className:"flex-1 overflow-y-auto p-2 space-y-1",children:[T?t.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(ve=>t.jsxs("div",{className:"animate-pulse space-y-2",children:[t.jsx("div",{className:"h-4 bg-surface-elevated rounded w-3/4"}),t.jsx("div",{className:"h-3 bg-surface-elevated rounded w-1/2"})]},ve))}):u.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[t.jsx("svg",{className:"w-12 h-12 text-fg-muted mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),t.jsx("p",{className:"text-sm text-fg-secondary",children:"No deliverables yet"}),t.jsx("p",{className:"text-xs text-fg-tertiary mt-1 mb-3",children:"Deliverables are created when tasks complete or manually"}),t.jsx("button",{onClick:wn,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create first"})]}):st.map(([ve,Qe])=>{const Nt=Z.has(ve);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>on(ve),className:"w-full flex items-center gap-1.5 px-2 py-1.5 rounded-md hover:bg-surface-elevated/50 transition-colors group/header",children:[t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform duration-200 shrink-0 ${Nt?"":"rotate-90"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),t.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider truncate",children:Qe.label}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Qe.items.length,")"]})]}),!Nt&&Qe.items.map(Et=>t.jsxs("button",{onClick:()=>qn(Et),className:`w-full text-left p-3 rounded-lg transition-colors ${U?.id===Et.id?"bg-brand-600/20 border border-brand-500/30":"hover:bg-surface-elevated/60 border border-transparent"}`,children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:Et.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[Et.artifactType&&cs[Et.artifactType]?t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${cs[Et.artifactType].color}`,children:[cs[Et.artifactType].icon," ",cs[Et.artifactType].label]}):t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium uppercase ${to[Et.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:Et.type}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${zv[Et.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:Et.status}),Et.agentId&&t.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:rn.get(Et.agentId)?.name??"Agent"})]})]},Et.id))]},ve)}),x&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[t.jsx(Xh,{})," ",t.jsx("span",{className:"text-[10px]",children:"Loading more..."})]}),!T&&u.length>0&&t.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:u.length<m?`${u.length} / ${m} deliverables`:`${m} deliverables`})]})]}),!e&&t.jsx("div",{className:"w-1 shrink-0 cursor-col-resize hover:bg-brand-500/30 active:bg-brand-500/50 transition-colors",onMouseDown:r.onResizeStart}),(!e||s)&&t.jsxs("div",{className:"flex-1 overflow-y-auto min-w-0",children:[e&&t.jsxs("div",{className:"sticky top-0 z-10 bg-surface-secondary border-b border-border-default px-4 py-2.5 flex items-center gap-2",children:[t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsx("span",{className:"text-sm font-medium truncate",children:U?.title??"Details"})]}),U?t.jsxs("div",{className:"p-6 space-y-5",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-xl font-semibold text-fg-primary",children:U.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[U.status!=="verified"&&t.jsx("button",{onClick:()=>Ue(U),disabled:!!W,className:"px-3 py-1.5 text-xs rounded-lg bg-green-600/20 text-green-600 hover:bg-green-600/30 disabled:opacity-50 transition-colors",children:W==="verify"?"Verifying...":"Verify"}),U.status!=="outdated"&&t.jsx("button",{onClick:()=>jn(U),disabled:!!W,className:"px-3 py-1.5 text-xs rounded-lg bg-amber-600/20 text-amber-600 hover:bg-amber-600/30 disabled:opacity-50 transition-colors",children:W==="flag"?"Flagging...":"Flag Outdated"}),t.jsx("button",{onClick:()=>gn(U),disabled:!!W,className:"px-3 py-1.5 text-xs rounded-lg bg-red-600/20 text-red-500 hover:bg-red-600/30 disabled:opacity-50 transition-colors",children:W==="remove"?"Removing...":"Remove"})]}),t.jsxs("div",{className:"flex items-center gap-3 mt-2 flex-wrap",children:[t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium uppercase ${to[U.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[to[U.type]?.icon??""," ",U.type]}),t.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${zv[U.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:U.status}),U.artifactType&&cs[U.artifactType]&&t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${cs[U.artifactType].color}`,children:[cs[U.artifactType].icon," Builder ",cs[U.artifactType].label]})]}),U.reference&&(U.type==="file"||U.type==="directory")&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 bg-surface-secondary/60 border border-border-default rounded-lg px-3 py-2",children:[t.jsx("button",{onClick:()=>{ae.files.reveal(U.reference).catch(()=>Se("error","Failed to open file browser"))},className:"text-xs font-mono text-brand-500 hover:text-brand-500 hover:underline truncate flex-1 text-left cursor-pointer",title:"Open in file browser",children:U.reference}),t.jsx("button",{onClick:()=>{ae.files.reveal(U.reference).catch(()=>Se("error","Failed to open file browser"))},className:"px-2 py-1 text-[10px] rounded bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",title:"Reveal in Finder",children:"Open"}),t.jsx("button",{onClick:()=>At(U.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${_t?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:"Copy path to clipboard",children:_t?"Copied!":"Copy"})]}),U.reference&&U.type!=="file"&&U.type!=="directory"&&t.jsx("div",{className:"mt-2",children:t.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:U.reference})})]}),U.artifactType&&U.artifactData?t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:t.jsx(gL,{artifact:U.artifactData,mode:U.artifactType})}),U.reference&&t.jsxs("div",{className:"px-3 py-2 bg-surface-secondary/50 border border-border-default rounded-lg",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider block mb-1",children:"Artifact Directory"}),t.jsx("span",{className:"text-xs text-fg-secondary font-mono break-all",children:U.reference})]}),t.jsx("div",{className:"flex gap-2",children:t.jsx("button",{onClick:Dt,className:"flex-1 px-4 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-colors",children:"Open in Builder"})}),U.summary&&t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:t.jsx(er,{content:U.summary,className:"text-fg-secondary text-sm"})})]}):t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:Me?t.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[t.jsx(Xh,{})," Loading preview..."]}):Ft?t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("img",{src:Ft.src,alt:Ft.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:Ft.name})]}):ht?On(ht):Xe?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("p",{className:"text-sm text-fg-secondary",children:["This ",U.type," cannot be previewed in the browser."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>{ae.files.reveal(U.reference).catch(()=>Se("error","Failed to open"))},className:"text-xs bg-surface-elevated px-3 py-2 rounded text-brand-500 hover:text-brand-500 hover:underline flex-1 truncate text-left cursor-pointer font-mono",title:"Open in file browser",children:U.reference}),t.jsx("button",{onClick:()=>{ae.files.reveal(U.reference).catch(()=>Se("error","Failed to open"))},className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",children:"Open"}),t.jsx("button",{onClick:()=>At(U.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${_t?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:_t?"Copied!":"Copy"})]})]}):U.summary?On(U.summary):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No content"})}),(U.diffStats||U.testResults)&&t.jsxs("div",{className:"flex gap-4 flex-wrap",children:[U.diffStats&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-lg px-4 py-3 text-xs space-y-1",children:[t.jsx("div",{className:"text-fg-tertiary font-medium",children:"Diff Stats"}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("span",{className:"text-fg-secondary",children:[U.diffStats.filesChanged," files"]}),t.jsxs("span",{className:"text-green-600",children:["+",U.diffStats.additions]}),t.jsxs("span",{className:"text-red-500",children:["-",U.diffStats.deletions]})]})]}),U.testResults&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-lg px-4 py-3 text-xs space-y-1",children:[t.jsx("div",{className:"text-fg-tertiary font-medium",children:"Tests"}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("span",{className:"text-green-600",children:[U.testResults.passed," passed"]}),t.jsxs("span",{className:"text-red-500",children:[U.testResults.failed," failed"]}),t.jsxs("span",{className:"text-fg-secondary",children:[U.testResults.skipped," skipped"]})]})]})]}),U.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5",children:U.tags.map(ve=>t.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:ve},ve))}),t.jsxs("div",{className:"border-t border-border-default pt-4 space-y-2",children:[t.jsx("div",{className:"text-xs text-fg-tertiary font-medium",children:"Links"}),t.jsxs("div",{className:"flex gap-3 flex-wrap",children:[U.taskId&&t.jsxs("button",{onClick:()=>Ut.navigate("projects",{openTask:U.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2.5 py-1 rounded",children:["Task: ",U.taskId.slice(0,12),"..."]}),U.agentId&&t.jsxs("button",{onClick:()=>Ut.navigate("team",{selectAgent:U.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Agent: ",rn.get(U.agentId)?.name??U.agentId.slice(0,12)]}),U.projectId&&t.jsxs("button",{onClick:()=>Ut.navigate("projects",{projectId:U.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Project: ",vn.get(U.projectId)?.name??U.projectId.slice(0,12)]})]})]}),t.jsxs("div",{className:"text-xs text-fg-tertiary space-y-1 border-t border-border-default pt-4",children:[t.jsxs("div",{className:"flex gap-6 flex-wrap",children:[t.jsxs("span",{children:["Created: ",t.jsx("span",{className:"text-fg-secondary",children:new Date(U.createdAt).toLocaleString()})]}),t.jsxs("span",{children:["Updated: ",t.jsx("span",{className:"text-fg-secondary",children:new Date(U.updatedAt).toLocaleString()})]}),t.jsxs("span",{children:["Accessed: ",t.jsxs("span",{className:"text-fg-secondary",children:[U.accessCount,"x"]})]})]}),t.jsxs("div",{className:"text-fg-muted select-all",children:["ID: ",U.id]})]})]}):t.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:t.jsxs("div",{className:"text-center text-fg-tertiary space-y-2",children:[t.jsx("svg",{className:"w-12 h-12 mx-auto text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),t.jsx("p",{className:"text-sm",children:"Select a deliverable to view details"})]})})]}),z&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!Q&&V(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:ve=>ve.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:"Create Deliverable"}),t.jsxs("div",{children:[t.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:"Type"}),t.jsx("select",{value:je,onChange:ve=>ke(ve.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:Lv.map(ve=>t.jsxs("option",{value:ve,children:[to[ve]?.icon??""," ",ve]},ve))})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:["Title ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("input",{value:De,onChange:ve=>Ie(ve.target.value),placeholder:"Clear, searchable title",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:["Reference ",t.jsx("span",{className:"text-fg-tertiary",children:"(file path, URL, branch name)"})]}),t.jsx("input",{value:Ae,onChange:ve=>We(ve.target.value),placeholder:"/path/to/file or https://...",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors font-mono"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:["Summary ",t.jsx("span",{className:"text-red-500",children:"*"})," ",t.jsx("span",{className:"text-fg-tertiary",children:"(Markdown)"})]}),t.jsx("textarea",{value:ze,onChange:ve=>Ze(ve.target.value),placeholder:"Describe the deliverable...",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary h-36 resize-none focus:border-brand-500 focus:outline-none transition-colors font-mono"})]}),t.jsxs("div",{className:"flex gap-4",children:[t.jsxs("div",{className:"flex-1",children:[t.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:["Tags ",t.jsx("span",{className:"text-fg-tertiary",children:"(comma separated)"})]}),t.jsx("input",{value:le,onChange:ve=>_e(ve.target.value),placeholder:"react, api, docs",className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors"})]}),t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:"Project"}),t.jsxs("select",{value:xt,onChange:ve=>Lt(ve.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:[t.jsx("option",{value:"",children:"None"}),b.map(ve=>t.jsx("option",{value:ve.id,children:ve.name},ve.id))]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1 border-t border-border-default",children:[t.jsx("button",{onClick:()=>V(!1),disabled:Q,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:"Cancel"}),t.jsxs("button",{onClick:at,disabled:Q||!De.trim()||!ze.trim(),className:"bg-brand-600 hover:bg-brand-500 text-white text-sm px-4 py-2 rounded-lg disabled:opacity-50 flex items-center gap-2 transition-colors",children:[Q&&t.jsx(Xh,{}),Q?"Creating...":"Create"]})]})]})})]})}function pL(e,r){const s=e.cloneNode(!0),i=r==="light"?{bg:"#ffffff",text:"#24292f",heading:"#1f2328",strong:"#1f2328",link:"#0969da",codeBg:"#eff1f3",codeText:"#24292f",preBg:"#f6f8fa",preText:"#24292f",preBorder:"#d0d7de",border:"#d0d7de",blockquoteBorder:"#d0d7de",blockquoteText:"#656d76",tableBorder:"#d0d7de",tableHeaderBg:"#f6f8fa",tableHeaderText:"#24292f",hrColor:"#d8dee4"}:{bg:"#0d1117",text:"#e6edf3",heading:"#f0f6fc",strong:"#f0f6fc",link:"#58a6ff",codeBg:"#161b22",codeText:"#e6edf3",preBg:"#161b22",preText:"#e6edf3",preBorder:"#30363d",border:"#30363d",blockquoteBorder:"#3b82f6",blockquoteText:"#8b949e",tableBorder:"#30363d",tableHeaderBg:"#161b22",tableHeaderText:"#e6edf3",hrColor:"#21262d"},o={p:`margin:0 0 10px;color:${i.text};line-height:1.7;`,h1:`font-size:1.6em;font-weight:700;color:${i.heading};margin:20px 0 10px;line-height:1.3;border-bottom:1px solid ${i.border};padding-bottom:6px;`,h2:`font-size:1.35em;font-weight:700;color:${i.heading};margin:18px 0 8px;line-height:1.3;`,h3:`font-size:1.15em;font-weight:600;color:${i.heading};margin:14px 0 6px;line-height:1.3;`,h4:`font-size:1em;font-weight:600;color:${i.heading};margin:12px 0 4px;`,strong:`font-weight:600;color:${i.strong};`,em:"font-style:italic;",a:`color:${i.link};text-decoration:underline;`,ul:"padding-left:1.5em;margin:0 0 10px;",ol:"padding-left:1.5em;margin:0 0 10px;",li:`margin:3px 0;line-height:1.7;color:${i.text};`,blockquote:`border-left:3px solid ${i.blockquoteBorder};padding:2px 0 2px 14px;margin:10px 0;color:${i.blockquoteText};`,hr:`border:none;border-top:1px solid ${i.hrColor};margin:20px 0;`,table:"border-collapse:collapse;width:100%;margin:10px 0;",thead:`background:${i.tableHeaderBg};`,th:`border:1px solid ${i.tableBorder};padding:8px 12px;text-align:left;font-weight:600;color:${i.tableHeaderText};`,td:`border:1px solid ${i.tableBorder};padding:8px 12px;color:${i.text};`,img:"max-width:100%;height:auto;"};function c(u){u.removeAttribute("class");const f=u.tagName.toLowerCase();if(f==="pre"){u.setAttribute("style",`background:${i.preBg};color:${i.preText};padding:14px;border-radius:6px;overflow-x:auto;margin:10px 0;font-size:0.88em;line-height:1.5;border:1px solid ${i.preBorder};`);const m=u.querySelector("code");m&&(m.removeAttribute("class"),m.setAttribute("style","background:transparent;padding:0;border-radius:0;color:inherit;font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;font-size:inherit;"));return}f==="code"?u.setAttribute("style",`background:${i.codeBg};color:${i.codeText};padding:2px 6px;border-radius:4px;font-size:0.9em;font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;`):o[f]&&u.setAttribute("style",o[f]),Array.from(u.children).forEach(c)}return s.removeAttribute("class"),Array.from(s.children).forEach(u=>c(u)),`<div style="background:${i.bg};color:${i.text};padding:20px 24px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Noto Sans',Helvetica,Arial,sans-serif;font-size:15px;line-height:1.7;max-width:800px;">${s.innerHTML}</div>`}function ba({label:e,value:r,current:s,onClick:i}){return t.jsx("button",{onClick:()=>i(s===r?"":r),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${s===r?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function Xh(){return t.jsxs("svg",{className:"animate-spin h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function ya(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function pu(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function bL(e){return e>=1024*1024*1024?`${(e/(1024*1024*1024)).toFixed(1)} GB`:e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function dN(){const[e,r]=j.useState("weekly"),[s,i]=j.useState(null),[o,c]=j.useState(!0),[u,f]=j.useState(""),[m,h]=j.useState(null),[x,g]=j.useState([]),[b,p]=j.useState("totalTokens"),[w,S]=j.useState(!0),T=j.useCallback(async $=>{c(!0),f("");try{const{report:X}=await ae.reports.generate({period:$,scope:"org",orgId:"default"});i(X)}catch(X){f(String(X)),i(null)}c(!1)},[]),E=j.useCallback(()=>{ae.usage.summary().then($=>h($.usage)).catch(()=>{}),ae.usage.agents().then($=>g($.agents)).catch(()=>{})},[]);j.useEffect(()=>{T(e)},[e,T]),j.useEffect(()=>{E();const $=setInterval(E,3e4);return()=>clearInterval($)},[E]);const C=j.useMemo(()=>[...x].sort(($,X)=>{const P=$[b],q=X[b];return w?q-P:P-q}),[x,b,w]),N=x.reduce(($,X)=>$+X.estimatedCost,0),k=x.reduce(($,X)=>$+X.tokensUsedToday,0),H=Math.max(1,...x.map($=>$.totalTokens)),M=$=>{b===$?S(!w):(p($),S(!0))},Y={daily:"Today",weekly:"This Week",monthly:"This Month"};return t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsxs("div",{className:"max-w-5xl p-6 space-y-6",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h1",{className:"text-xl font-semibold text-fg-primary",children:"Reports"}),t.jsxs("select",{value:e,onChange:$=>r($.target.value),className:"bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary",children:[t.jsx("option",{value:"daily",children:"Daily"}),t.jsx("option",{value:"weekly",children:"Weekly"}),t.jsx("option",{value:"monthly",children:"Monthly"})]})]}),m&&t.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t.jsx(ou,{label:"LLM Tokens (this month)",value:ya(m.llmTokens),color:"text-brand-500"}),t.jsx(ou,{label:"Tool Calls (today)",value:ya(m.toolCalls),color:"text-blue-600"}),t.jsx(ou,{label:"Messages (today)",value:ya(m.messages),color:"text-green-600"}),t.jsx(ou,{label:"Storage",value:bL(m.storageBytes),color:"text-amber-600"})]}),o?t.jsx("div",{className:"flex items-center justify-center h-32 text-fg-tertiary text-sm",children:"Loading…"}):u?t.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:u}):s?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"text-xs text-fg-tertiary",children:[Y[e]," · ",new Date(s.periodStart).toLocaleDateString()," — ",new Date(s.periodEnd).toLocaleDateString()]}),s.metrics&&t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Task Metrics"}),t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[t.jsx(no,{label:"Completed",value:s.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(no,{label:"In Progress",value:s.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(no,{label:"Created",value:s.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(no,{label:"Blocked",value:s.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(no,{label:"Failed",value:s.metrics.tasksFailed,color:"text-red-500"})]})]}),t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Cost Overview"}),t.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:pu(N)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Est. Cost (all time)"})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:ya(k)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Tokens Today"})]}),s.costSummary&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:s.costSummary.totalTokens.toLocaleString()}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Tokens (",Y[e],")"]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:pu(s.costSummary.totalEstimatedCost)}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Cost (",Y[e],")"]})]})]})]})]}),s.taskSummary&&t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Task Summary"}),t.jsxs("div",{className:"space-y-4",children:[s.taskSummary.completed.length>0&&t.jsx(Zh,{title:`Completed (${s.taskSummary.completed.length})`,color:"emerald",items:s.taskSummary.completed.map($=>({label:$.title,sub:$.agent}))}),s.taskSummary.inProgress.length>0&&t.jsx(Zh,{title:`In Progress (${s.taskSummary.inProgress.length})`,color:"indigo",items:s.taskSummary.inProgress.map($=>({label:$.title,sub:$.agent}))}),s.taskSummary.blocked.length>0&&t.jsx(Zh,{title:`Blocked (${s.taskSummary.blocked.length})`,color:"amber",items:s.taskSummary.blocked.map($=>({label:$.title,sub:$.reason||$.agent}))}),s.taskSummary.completed.length===0&&s.taskSummary.inProgress.length===0&&s.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]})]}):null,t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden",children:[t.jsx("div",{className:"px-5 py-4 border-b border-border-default",children:t.jsx("h3",{className:"text-sm font-semibold text-fg-secondary",children:"Per-Agent Usage"})}),x.length===0?t.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:"No agent usage data yet."}):t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"border-b border-border-default text-xs text-fg-tertiary uppercase tracking-wider",children:[t.jsx("th",{className:"px-4 py-3 text-left font-medium",children:"Agent"}),t.jsx(ro,{label:"Total Tokens",col:"totalTokens",current:b,desc:w,onSort:M}),t.jsx(ro,{label:"Today",col:"tokensUsedToday",current:b,desc:w,onSort:M}),t.jsx(ro,{label:"Requests",col:"requestCount",current:b,desc:w,onSort:M}),t.jsx(ro,{label:"Tool Calls",col:"toolCalls",current:b,desc:w,onSort:M}),t.jsx(ro,{label:"Est. Cost",col:"estimatedCost",current:b,desc:w,onSort:M,align:"right"})]})}),t.jsx("tbody",{children:C.map($=>t.jsx(yL,{agent:$,maxTokens:H},$.agentId))}),t.jsx("tfoot",{children:t.jsxs("tr",{className:"border-t border-border-default bg-surface-elevated/30",children:[t.jsxs("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary",children:["Total (",x.length," agents)"]}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ya(x.reduce(($,X)=>$+X.totalTokens,0))}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ya(k)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:x.reduce(($,X)=>$+X.requestCount,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:x.reduce(($,X)=>$+X.toolCalls,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:pu(N)})]})})]})})]})]})})}function no({label:e,value:r,color:s}){return t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:`text-2xl font-bold ${s}`,children:r}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function Zh({title:e,color:r,items:s}){return t.jsxs("div",{children:[t.jsx("div",{className:`text-xs font-medium text-${r}-400 mb-1.5`,children:e}),t.jsx("div",{className:"space-y-1",children:s.map((i,o)=>t.jsxs("div",{className:"text-sm text-fg-secondary flex items-center gap-2",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${r}-500 shrink-0`}),t.jsx("span",{className:"truncate",children:i.label}),i.sub&&i.sub!=="unassigned"&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:i.sub})]},o))})]})}function ou({label:e,value:r,color:s}){return t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("div",{className:"text-sm text-fg-secondary mb-2",children:e}),t.jsx("div",{className:`text-2xl font-bold ${s}`,children:r})]})}function ro({label:e,col:r,current:s,desc:i,onSort:o,align:c}){const u=s===r?i?"↓":"↑":"↕",f=s===r?"text-brand-500":"text-fg-muted";return t.jsxs("th",{className:`px-4 py-3 ${c==="right"?"text-right":"text-left"} font-medium cursor-pointer select-none hover:text-fg-secondary`,onClick:()=>o(r),children:[e,t.jsx("span",{className:`ml-1 ${f}`,children:u})]})}function yL({agent:e,maxTokens:r}){const s=r>0?Math.min(100,e.totalTokens/r*100):0,i=e.status==="working"?"bg-blue-500":e.status==="idle"?"bg-green-500":e.status==="paused"?"bg-amber-500":e.status==="error"?"bg-red-500":"bg-gray-600";return t.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>Ut.navigate("team",{selectAgent:e.agentId}),children:[t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:`w-2 h-2 rounded-full ${i}`}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:t.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${s}%`}})}),t.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:ya(e.totalTokens)})]})}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:ya(e.tokensUsedToday)}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.requestCount}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.toolCalls}),t.jsx("td",{className:"px-4 py-3 text-sm text-right text-fg-secondary tabular-nums",children:pu(e.estimatedCost)})]})}function so({d:e,size:r=18}){return t.jsx("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:e})})}const ao={dashboard:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M9 22V12h6v10",projects:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z",chat:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",reports:"M18 20V10 M12 20V4 M6 20v-6",deliverables:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20 M4 19.5A2.5 2.5 0 0 0 6.5 22H20V2H6.5A2.5 2.5 0 0 0 4 4.5v15z",usage:"M21.21 15.89A10 10 0 1 1 8 2.83 M22 12A10 10 0 0 0 12 2v10z",builder:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",agents:"M8 3H5a2 2 0 0 0-2 2v3 M21 8V5a2 2 0 0 0-2-2h-3 M3 16v3a2 2 0 0 0 2 2h3 M16 21h3a2 2 0 0 0 2-2v-3 M9 9h6v6H9z",teams:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2 M9 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8z M23 21v-2a4 4 0 0 0-3-3.87 M16 3.13a4 4 0 0 1 0 7.75",skills:"M12 2L2 7l10 5 10-5-10-5z M2 17l10 5 10-5 M2 12l10 5 10-5",governance:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"},vL={active:"bg-green-500",paused:"bg-amber-500",completed:"bg-gray-500",archived:"bg-gray-600"},jL=[{id:"dashboard",label:"Overview",section:"workspace"},{id:"chat",label:"Chat",section:"workspace"},{id:"deliverables",label:"Deliverables",section:"workspace"},{id:"builder",label:"Builder",section:"build"},{id:"agents",label:"Agents",section:"build"},{id:"teams",label:"Teams",section:"build"},{id:"skills",label:"Skills",section:"build"},{id:"governance",label:"Governance",section:"system"},{id:"reports",label:"Reports",section:"system"},{id:"settings",label:"Settings",section:"system"}],wL=[{key:"workspace",label:"WORKSPACE"},{key:"build",label:"BUILD"},{key:"system",label:"SYSTEM"}],$v=5;function NL({currentPage:e,onNavigate:r,authUser:s,onLogout:i,collapsed:o,onToggleCollapse:c}){const[u,f]=j.useState([]),[m,h]=j.useState(!1),[x,g]=j.useState(null),[b,p]=j.useState(!1),w=j.useCallback(()=>{ae.projects.list().then(C=>f(C.projects)).catch(()=>{})},[]);j.useEffect(()=>{w();const C=setInterval(w,3e4);return()=>clearInterval(C)},[w]),j.useEffect(()=>{if(e!=="projects"){g(null);return}const N=window.location.hash.slice(1).split("/");N[0]==="projects"&&N[1]&&g(N[1])},[e]);const S=async()=>{try{await ae.auth.logout()}catch{}i?.()},T=m?u:u.slice(0,$v),E=u.length>$v;return t.jsxs("aside",{className:"h-dvh bg-surface-secondary flex flex-col shrink-0 overflow-hidden border-r border-border-subtle",children:[t.jsx("div",{className:`flex items-center ${o?"px-2 py-3.5 justify-center":"px-4 h-14 justify-between"}`,children:o?t.jsx("button",{onClick:c,title:"Expand sidebar",className:"group",children:t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg group-hover:ring-2 group-hover:ring-brand-500/40 transition-all"})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg shadow-md shadow-black/30 shrink-0"}),t.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]}),t.jsx("button",{onClick:c,className:"text-fg-tertiary hover:text-fg-secondary transition-colors p-1 rounded-md hover:bg-surface-overlay shrink-0",title:"Collapse sidebar",children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"11 17 6 12 11 7"}),t.jsx("polyline",{points:"18 17 13 12 18 7"})]})})]})}),t.jsx("nav",{className:`${o?"p-1.5":"p-3"} flex-1 overflow-y-auto`,children:wL.map((C,N)=>t.jsx("div",{children:t.jsxs("div",{className:"mb-3",children:[!o&&t.jsx("div",{className:"px-3 py-1.5 text-[11px] font-semibold text-fg-tertiary uppercase tracking-widest",children:C.label}),o&&N>0&&t.jsx("div",{className:"my-2 mx-1"}),jL.filter(k=>k.section===C.key&&!(C.key==="workspace"&&k.id==="deliverables")).map(k=>{const H=e===k.id;return t.jsxs("button",{onClick:()=>r(k.id),title:o?k.label:void 0,className:`w-full flex items-center ${o?"justify-center px-2 py-2":"gap-3 px-3 py-2"} rounded-lg text-sm mb-0.5 transition-all ${H?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":"text-fg-primary hover:bg-surface-overlay"}`,children:[t.jsx(so,{d:ao[k.id]??""}),!o&&k.label]},k.id)}),C.key==="workspace"&&o&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{g(null),r("projects")},title:"Projects",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-all ${e==="projects"&&!x?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":e==="projects"?"bg-brand-600/15 text-fg-primary":"text-fg-primary hover:bg-surface-overlay"}`,children:t.jsx(so,{d:ao.projects})}),t.jsx("button",{onClick:()=>r("deliverables"),title:"Deliverables",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e==="deliverables"?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:t.jsx(so,{d:ao.deliverables})})]}),C.key==="workspace"&&!o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center mb-0.5",children:[t.jsxs("button",{onClick:()=>{g(null),window.location.hash="projects",r("projects")},className:`flex-1 flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-colors ${e==="projects"&&!x?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(so,{d:ao.projects}),"Projects"]}),t.jsx("button",{onClick:()=>p(!0),className:"text-fg-tertiary hover:text-fg-secondary transition-colors p-1.5 rounded hover:bg-surface-elevated shrink-0",title:"New Project",children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),u.length===0&&t.jsxs("button",{onClick:()=>p(!0),className:"w-full flex items-center gap-2 pl-9 pr-3 py-1.5 text-xs text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50 rounded-lg transition-colors",children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Create your first project"]}),T.map(k=>{const H=e==="projects"&&x===k.id;return t.jsxs("button",{onClick:()=>{g(k.id),e!=="projects"&&r("projects"),window.location.hash="projects/"+k.id},className:`w-full flex items-center gap-2.5 pl-9 pr-3 py-1.5 rounded-lg text-sm mb-0.5 transition-colors ${H?"bg-brand-600 text-white":"text-fg-secondary hover:bg-surface-elevated"}`,children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${vL[k.status]??"bg-gray-600"}`}),t.jsx("span",{className:"truncate text-xs",children:k.name})]},k.id)}),E&&!m&&t.jsxs("button",{onClick:()=>h(!0),className:"w-full pl-9 pr-3 py-1 text-[11px] text-fg-tertiary hover:text-fg-secondary transition-colors text-left",children:["Show all ",u.length," projects..."]}),t.jsxs("button",{onClick:()=>r("deliverables"),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e==="deliverables"?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(so,{d:ao.deliverables}),"Deliverables"]})]})]})},C.key))}),t.jsxs("div",{className:`${o?"p-2 flex flex-col items-center gap-2":"px-4 py-3 space-y-2"}`,children:[s&&(o?t.jsx("button",{onClick:S,title:`${s.name??s.email} — Sign out`,className:"w-7 h-7 rounded-full bg-brand-600 flex items-center justify-center text-white text-xs font-bold shrink-0 hover:ring-2 hover:ring-brand-500/50 transition-all",children:s.name?.[0]?.toUpperCase()??"A"}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-600 flex items-center justify-center text-white text-xs font-bold shrink-0",children:s.name?.[0]?.toUpperCase()??"A"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-secondary truncate",children:s.name??s.email}),t.jsx("div",{className:"text-[11px] text-fg-tertiary truncate",children:s.email??s.role?.[0]?.toUpperCase()+s.role?.slice(1)})]}),t.jsx("button",{onClick:S,title:"Sign out",className:"text-fg-tertiary hover:text-fg-secondary transition-colors text-sm",children:"⇥"})]})),!o&&t.jsxs("div",{className:"text-[10px] text-fg-muted",children:["v","0.2.3"]})]}),b&&t.jsx(aN,{orgId:s?.orgId,onCreated:()=>{p(!1),w()},onClose:()=>p(!1)})]})}const kL={dashboard:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M9 22V12h6v10",chat:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",projects:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z",deliverables:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20 M4 19.5A2.5 2.5 0 0 0 6.5 22H20V2H6.5A2.5 2.5 0 0 0 4 4.5v15z",builder:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"},SL=[{id:"dashboard",label:"Home",iconKey:"dashboard",group:["dashboard"]},{id:"chat",label:"Chat",iconKey:"chat",group:["chat"]},{id:"projects",label:"Projects",iconKey:"projects",group:["projects"]},{id:"deliverables",label:"Deliverables",iconKey:"deliverables",group:["deliverables"]},{id:"builder",label:"Builder",iconKey:"builder",group:["builder","agents","teams","skills"]},{id:"settings",label:"Settings",iconKey:"settings",group:["settings","governance","reports"]}];function CL({currentPage:e,onNavigate:r}){return t.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-surface-secondary border-t border-border-default flex items-stretch h-14 safe-area-bottom",children:SL.map(s=>{const i=s.group.includes(e);return t.jsxs("button",{onClick:()=>r(s.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${i?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[t.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:i?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:kL[s.iconKey]})}),t.jsx("span",{className:`text-[10px] leading-tight ${i?"font-semibold":""}`,children:s.label})]},s.id)})})}const EL=50,TL=30;function fN(e,r,s){const i=j.useRef(0),o=j.useRef(0),c=j.useCallback(f=>{i.current=f.touches[0].clientX,o.current=f.touches[0].clientY},[]),u=j.useCallback(f=>{const m=f.changedTouches[0].clientX-i.current,h=f.changedTouches[0].clientY-o.current,x=Math.abs(m),g=Math.abs(h);if(x<EL||Math.atan2(g,x)*(180/Math.PI)>TL)return;const p=e.findIndex(w=>w.id===r);m<0&&p<e.length-1?s(e[p+1].id):m>0&&p>0&&s(e[p-1].id)},[e,r,s]);return{onTouchStart:c,onTouchEnd:u}}const Bv=[{id:"builder",label:"Builder"},{id:"agents",label:"Agents"},{id:"teams",label:"Teams"},{id:"skills",label:"Skills"}];function _L({authUser:e}){const[r,s]=j.useState("builder"),i=fN(Bv,r,s);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:i.onTouchStart,onTouchEnd:i.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:Bv.map(o=>t.jsx("button",{onClick:()=>s(o.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${r===o.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:o.label},o.id))}),t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[r==="builder"&&t.jsx(gj,{}),r==="agents"&&t.jsx(fj,{authUser:e}),r==="teams"&&t.jsx(xj,{}),r==="skills"&&t.jsx(cj,{})]})]})}const Hv=[{id:"settings",label:"Settings"},{id:"governance",label:"Governance"},{id:"reports",label:"Reports"}];function AL({theme:e,onThemeChange:r}){const[s,i]=j.useState("settings"),o=fN(Hv,s,i);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:o.onTouchStart,onTouchEnd:o.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:Hv.map(c=>t.jsx("button",{onClick:()=>i(c.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===c.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:c.label},c.id))}),t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="settings"&&t.jsx(lj,{theme:e,onThemeChange:r}),s==="governance"&&t.jsx(pj,{}),s==="reports"&&t.jsx(dN,{})]})]})}const Pv=2;function ML({onComplete:e,theme:r,onThemeChange:s}){const[i,o]=j.useState(0),[c,u]=j.useState(null),[f,m]=j.useState(!1),[h,x]=j.useState({}),[g,b]=j.useState(!1),[p,w]=j.useState(null),[S,T]=j.useState(!1),[E,C]=j.useState(!1),[N,k]=j.useState(null),H=j.useRef(!1),M=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});j.useEffect(()=>{fetch("/api/settings/llm").then(I=>I.ok?I.json():null).then(I=>{I?.providers&&Object.values(I.providers).some(A=>A.configured)&&C(!0)}).catch(()=>{})},[]),j.useEffect(()=>{i===Pv&&!H.current&&!E&&(H.current=!0,Y())},[i,E]);const Y=async()=>{m(!0);try{const I=await fetch("/api/settings/env-models",{headers:M()});if(I.ok){const A=await I.json();if(u(A),A.detected.length>0){const G={};for(const U of A.detected)G[U.provider]=!0;x(G)}}}catch{}finally{m(!1)}},$=async()=>{if(!c)return;const I=c.detected.filter(A=>h[A.provider]);if(I.length!==0){b(!0),k(null);try{const A=await fetch("/api/settings/env-models",{method:"POST",headers:M(),body:JSON.stringify({providers:I.map(G=>({provider:G.provider,model:G.model,baseUrl:G.baseUrl,enabled:!0}))})});if(A.ok){const G=await A.json();k({type:"ok",text:G.message}),C(!0)}else k({type:"err",text:"Failed to apply"})}catch{k({type:"err",text:"Network error"})}finally{b(!1)}}},X=async()=>{T(!0);try{const A=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:M(),body:JSON.stringify({preview:!0})})).json();"error"in A||w(A)}catch{}finally{T(!1)}},P=async()=>{T(!0),k(null);try{const A=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:M(),body:JSON.stringify({preview:!1})})).json();"error"in A?k({type:"err",text:A.error}):(k({type:"ok",text:`Imported ${A.appliedModels} model configs`}),C(!0))}catch{k({type:"err",text:"Import failed"})}finally{T(!1)}},q=[{value:"system",label:"System",icon:"💻",desc:"Follow your OS setting"},{value:"light",label:"Light",icon:"☀️",desc:"Always light background"},{value:"dark",label:"Dark",icon:"🌙",desc:"Always dark background"}],F=[{title:"Welcome to Markus",subtitle:"Your AI Digital Employee Platform",content:t.jsxs("div",{className:"space-y-4 text-fg-secondary text-sm leading-relaxed",children:[t.jsxs("p",{children:["Markus helps you build ",t.jsx("strong",{className:"text-fg-primary",children:"AI teams"})," — digital employees that work autonomously, collaborate with each other, and communicate with you naturally."]}),t.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[["Always Online","Agents work 24/7 autonomously"],["Team Collaboration","Agents communicate via A2A messaging"],["Smart Routing","Messages auto-route to the right agent"],["Tool Capable","Shell, files, web, git, browser tools"]].map(([I,A])=>t.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[t.jsx("div",{className:"font-medium text-fg-primary text-xs",children:I}),t.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:A})]},I))})]})},{title:"Choose Your Theme",subtitle:"You can change this anytime in Settings",content:t.jsx("div",{className:"grid grid-cols-3 gap-3",children:q.map(I=>t.jsxs("button",{onClick:()=>s(I.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${r===I.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[t.jsx("span",{className:"text-2xl",children:I.icon}),t.jsx("span",{className:"text-sm font-medium text-fg-primary",children:I.label}),t.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:I.desc})]},I.value))})},{title:"Configure LLM",subtitle:"Agents need an LLM to think and act",content:E?t.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[t.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium text-green-600",children:"LLM provider configured"}),t.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:"You can manage providers anytime in Settings."})]})]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:"From Environment Variables"}),f&&t.jsx("div",{className:"text-xs text-fg-tertiary animate-pulse",children:"Detecting API keys..."}),c&&c.detected.length>0&&t.jsxs("div",{className:"space-y-2",children:[c.detected.map(I=>t.jsxs("label",{className:"flex items-center gap-3 bg-surface-elevated/40 rounded-lg px-3 py-2.5 cursor-pointer hover:bg-surface-elevated/60 transition-colors",children:[t.jsx("input",{type:"checkbox",checked:h[I.provider]??!1,onChange:A=>x({...h,[I.provider]:A.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-sm text-fg-primary",children:I.displayName}),t.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:I.model})]}),t.jsx("code",{className:"text-[10px] text-fg-tertiary",children:I.apiKeyPreview})]},I.provider)),t.jsx("button",{onClick:()=>{$()},disabled:g||Object.values(h).filter(Boolean).length===0,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:g?"Applying...":`Apply ${Object.values(h).filter(Boolean).length} Provider(s)`})]}),c&&c.detected.length===0&&!f&&t.jsxs("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:["No API keys found. Set ",t.jsx("code",{className:"text-fg-secondary",children:"ANTHROPIC_API_KEY"}),", ",t.jsx("code",{className:"text-fg-secondary",children:"OPENAI_API_KEY"}),", etc. in your ",t.jsx("code",{className:"text-fg-secondary",children:".env"})," file and restart."]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 h-px bg-border-default"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:"or"}),t.jsx("div",{className:"flex-1 h-px bg-border-default"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:"From OpenClaw"}),p?p.found?t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"text-xs text-green-600",children:["Found: ",t.jsx("code",{className:"text-fg-secondary",children:p.summary.configPath}),p.summary.models&&t.jsxs("span",{className:"text-fg-tertiary ml-1",children:["(",p.summary.models.providerCount," providers)"]})]}),t.jsx("button",{onClick:()=>{P()},disabled:S,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:S?"Importing...":"Import Model Configs"})]}):t.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:"No OpenClaw config found."}):t.jsx("button",{onClick:()=>{X()},disabled:S,className:"px-4 py-2 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-secondary text-sm rounded-lg transition-colors w-full",children:S?"Detecting...":"Detect OpenClaw Config"})]}),N&&t.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${N.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:N.text})]})},{title:"You're All Set",subtitle:"Here's what you can do",content:t.jsx("div",{className:"space-y-2 text-fg-secondary text-sm",children:[["Chat","Talk to agents or use Smart Route to auto-pick the best one"],["Projects","Create tasks and track progress on kanban boards"],["Builder","Create and customize agents, teams, and prompts"],["Settings","Manage LLM providers, themes, and import configs"]].map(([I,A])=>t.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[t.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),t.jsxs("div",{children:[t.jsx("div",{className:"font-medium text-fg-primary text-xs",children:I}),t.jsx("div",{className:"text-fg-secondary text-xs",children:A})]})]},I))})}],D=()=>{i<F.length-1?o(i+1):e()},_=F[i];return t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:t.jsx("div",{className:"w-full max-w-lg",children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl p-8",children:[t.jsx("div",{className:"flex gap-1.5 mb-8",children:F.map((I,A)=>t.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${A<=i?"bg-brand-500":"bg-surface-elevated"}`},A))}),t.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:_.title}),t.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:_.subtitle}),_.content,t.jsxs("div",{className:"flex justify-between mt-8",children:[i>0?t.jsx("button",{onClick:()=>o(i-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:"Back"}):t.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip"}),t.jsxs("div",{className:"flex items-center gap-3",children:[i===Pv&&!E&&t.jsx("button",{onClick:D,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip for now"}),t.jsx("button",{onClick:D,className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-xl transition-colors",children:i===F.length-1?"Get Started":"Next"})]})]})]})})})}const DL="markus123";function OL({onLogin:e}){const[r,s]=j.useState("admin@markus.local"),[i,o]=j.useState(""),[c,u]=j.useState(""),[f,m]=j.useState(!1),h=async x=>{if(x.preventDefault(),!(!r.trim()||!i)){u(""),m(!0);try{const{user:g}=await ae.auth.login(r.trim(),i);e(g,i===DL)}catch{u("Invalid email or password")}finally{m(!1)}}};return t.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[t.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),t.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),t.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),t.jsx("div",{className:"text-sm text-fg-tertiary",children:"AI Digital Employee Platform"})]}),t.jsxs("form",{onSubmit:h,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[t.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:"Sign in"}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Email"}),t.jsx("input",{type:"email",value:r,onChange:x=>s(x.target.value),autoComplete:"email",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Password"}),t.jsx("input",{type:"password",value:i,onChange:x=>o(x.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),c&&t.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:c}),t.jsx("button",{type:"submit",disabled:f||!r||!i,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all shadow-md shadow-brand-900/40 hover:shadow-lg hover:shadow-brand-900/50",children:f?"Signing in…":"Sign in"}),t.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:"Default: admin@markus.local / markus123"})]})]})]})}function RL({onComplete:e,isFirstTime:r}){const[s,i]=j.useState(""),[o,c]=j.useState(""),[u,f]=j.useState(""),[m,h]=j.useState(""),[x,g]=j.useState(!1),b=async p=>{if(p.preventDefault(),h(""),o.length<6){h("Password must be at least 6 characters");return}if(o!==u){h("Passwords do not match");return}g(!0);try{await ae.auth.changePassword(s,o),e()}catch{h("Failed to change password. Check your current password.")}finally{g(!1)}};return t.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[t.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),t.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),t.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),t.jsx("div",{className:"text-sm text-fg-tertiary",children:"AI Digital Employee Platform"})]}),t.jsxs("form",{onSubmit:b,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:r?"Set Your Password":"Change Password"}),r&&t.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:"You're using the default password. Please set a new one before continuing."})]}),!r&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Current Password"}),t.jsx("input",{type:"password",value:s,onChange:p=>i(p.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"New Password"}),t.jsx("input",{type:"password",value:o,onChange:p=>c(p.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0,minLength:6})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Confirm New Password"}),t.jsx("input",{type:"password",value:u,onChange:p=>f(p.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),m&&t.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:m}),t.jsx("button",{type:"submit",disabled:x||!o||!u,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-colors",children:x?"Saving…":r?"Set Password & Continue":"Change Password"})]})]})]})}const hN="markus-theme";function Uv(e){const r=document.documentElement;r.classList.remove("light","dark"),e==="light"?r.classList.add("light"):e==="dark"&&r.classList.add("dark")}function zL(){try{const e=localStorage.getItem(hN);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function LL(){const[e,r]=j.useState(zL),s=j.useCallback(i=>{r(i);try{localStorage.setItem(hN,i)}catch{}Uv(i)},[]);return j.useEffect(()=>{Uv(e)},[e]),{mode:e,setMode:s}}const IL=["dashboard","tasks","chat","team","usage","skills","agents","teams","builder","prompts","settings","governance","projects","deliverables","reports"];function cu(){const e=window.location.hash.slice(1).split("/")[0];return e==="team"?"chat":e==="tasks"?"projects":e==="usage"?"reports":e==="prompts"?"builder":e==="templates"?"agents":e==="knowledge"?"deliverables":IL.includes(e)?e:"dashboard"}const Qh={};function $L(){const[e,r]=j.useState(cu),[s,i]=j.useState(()=>!localStorage.getItem("markus_onboarded")),[o,c]=j.useState(!0),u=gs(),f=LL(),m=ex({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[h,x]=j.useState(()=>new Set([cu()])),[g,b]=j.useState("loading"),[p,w]=j.useState(!1),[S,T]=j.useState(null),[E,C]=j.useState(!1),N=j.useCallback(Y=>{let $=Y==="tasks"?"projects":Y==="team"?"chat":Y==="usage"?"reports":Y==="prompts"?"builder":Y==="templates"?"agents":Y;u&&(($==="agents"||$==="teams"||$==="skills")&&($="builder"),($==="governance"||$==="reports")&&($="settings"));const X=cu(),P=window.location.hash.slice(1);P!==X?Qh[X]=P:delete Qh[X],r($),x(q=>q.has($)?q:new Set([...q,$])),window.location.hash=Qh[$]||$},[u]);j.useEffect(()=>{Ut.setHandler(Y=>N(Y))},[N]);const k=j.useCallback(()=>{fetch("/api/settings/llm").then(Y=>Y.ok?Y.json():null).then(Y=>{if(Y?.providers){const $=Object.values(Y.providers).some(X=>X.configured);T($)}}).catch(()=>{})},[]);j.useEffect(()=>{ae.auth.me().then(({user:$})=>{b($),k(),Va(pr.builderArtifacts,()=>ae.builder.artifacts.list()),Va(pr.builderAgents,()=>ae.agents.list()),Va(pr.builderHubMyItems,()=>Bn.myItems()),Va(pr.builderInstalled,()=>ae.builder.artifacts.installed()),Va(pr.hubAgents,()=>Bn.search({type:"agent",limit:50})),Va(pr.hubTeams,()=>Bn.search({type:"team",limit:50})),Va(pr.hubSkills,()=>Bn.search({type:"skill",limit:50}))}).catch(()=>b(null)),En.connect();const Y=()=>{const $=cu();r($),x(X=>X.has($)?X:new Set([...X,$]))};return window.addEventListener("hashchange",Y),()=>{En.disconnect(),window.removeEventListener("hashchange",Y)}},[]);const H=g!=="loading"&&g!==null?g:void 0,M=j.useMemo(()=>u?{dashboard:t.jsx(ob,{}),chat:t.jsx(hy,{authUser:H}),builder:t.jsx(_L,{authUser:H}),settings:t.jsx(AL,{theme:f.mode,onThemeChange:f.setMode}),projects:t.jsx(Rv,{authUser:H}),deliverables:t.jsx(Iv,{})}:{dashboard:t.jsx(ob,{}),chat:t.jsx(hy,{authUser:H}),settings:t.jsx(lj,{theme:f.mode,onThemeChange:f.setMode}),skills:t.jsx(cj,{}),agents:t.jsx(fj,{authUser:H}),teams:t.jsx(xj,{}),builder:t.jsx(gj,{}),governance:t.jsx(pj,{}),projects:t.jsx(Rv,{authUser:H}),deliverables:t.jsx(Iv,{}),reports:t.jsx(dN,{})},[H?.id,f.mode,u]);return g==="loading"?t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:t.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:"Loading…"})}):g===null?t.jsx(OL,{onLogin:(Y,$)=>{b(Y),$&&w(!0)}}):p?t.jsx(RL,{onComplete:()=>w(!1),isFirstTime:!0}):s?t.jsx(ML,{theme:f.mode,onThemeChange:f.setMode,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),i(!1),k()}}):t.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary ${u?"flex-col":""}`,children:[!u&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:t.jsx(NL,{currentPage:e,onNavigate:Y=>{N(Y),c(!1)},authUser:g,onLogout:()=>b(null),collapsed:m.collapsed,onToggleCollapse:m.toggle})}),!m.collapsed&&t.jsx("div",{className:"w-1 cursor-col-resize shrink-0 group relative z-10",onMouseDown:m.onResizeStart,children:t.jsx("div",{className:"absolute inset-y-0 -left-0.5 -right-0.5 group-hover:bg-brand-500/30 group-active:bg-brand-500/50 transition-colors"})})]}),t.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col min-w-0 ${u?"pb-14":""}`,children:[S===!1&&!E&&e!=="settings"&&t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-amber-500/10 border-b border-amber-500/30 text-amber-600 text-sm shrink-0",children:[t.jsx("span",{className:u?"text-xs":"",children:"No LLM provider configured — agents cannot process requests."}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:()=>{N("settings")},className:"px-3 py-1 bg-amber-700/50 hover:bg-amber-700/70 text-white text-xs rounded-lg transition-colors",children:"Go to Settings"}),t.jsx("button",{onClick:()=>C(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:"Dismiss"})]})]}),t.jsx("main",{className:"flex-1 overflow-hidden flex flex-col",children:Object.keys(M).map(Y=>h.has(Y)?t.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:Y===e?"flex":"none"},children:M[Y]},Y):null)})]}),u&&t.jsx(CL,{currentPage:e,onNavigate:N})]})}S2.createRoot(document.getElementById("root")).render(t.jsx(j.StrictMode,{children:t.jsx($L,{})}));