@markus-global/cli 0.3.0 → 0.3.2

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??lv,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)&&lw(p))return!1;const S=ov(p.code,f);if(c.current.add(p[S]),iv(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(),l(!0)}},g=p=>{const w=ov(p.code,f);iv(u,c.current,!0)?(l(!1),c.current.clear()):c.current.delete(p[w]),p.key==="Meta"&&c.current.clear(),o.current=!1},b=()=>{c.current.clear(),l(!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,l]),s}function iv(e,r,s){return e.filter(l=>s||l.length===r.size).some(l=>l.every(o=>r.has(o)))}function ov(e,r){return r.includes(e)?"code":"key"}const fO=()=>{const e=pn();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:l}=e.getState();return l?l.scaleTo(r,{duration:s?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(r,s)=>{const{transform:[l,o,c],panZoom:u}=e.getState();return u?(await u.setViewport({x:r.x??l,y:r.y??o,zoom:r.zoom??c},s),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[r,s,l]=e.getState().transform;return{x:r,y:s,zoom:l}},setCenter:async(r,s,l)=>e.getState().setCenter(r,s,l),fitBounds:async(r,s)=>{const{width:l,height:o,minZoom:c,maxZoom:u,panZoom:f}=e.getState(),m=dx(r,l,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:l,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,l,g,x)},flowToScreenPosition:r=>{const{transform:s,domNode:l}=e.getState();if(!l)return r;const{x:o,y:c}=l.getBoundingClientRect(),u=Ru(r,s);return{x:u.x+o,y:u.y+c}}}),[])};function Tw(e,r){const s=[],l=new Map,o=[];for(const c of e)if(c.type==="add"){o.push(c);continue}else if(c.type==="remove"||c.type==="replace")l.set(c.id,[c]);else{const u=l.get(c.id);u?u.push(c):l.set(c.id,[c])}for(const c of r){const u=l.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 Aw(e,r){return Tw(e,r)}function _w(e,r){return Tw(e,r)}function Fa(e,r){return{id:e,type:"select",selected:r}}function Bl(e,r=new Set,s=!1){const l=[];for(const[o,c]of e){const u=r.has(o);!(c.selected===void 0&&!u)&&c.selected!==u&&(s&&(c.selected=u),l.push(Fa(c.id,u)))}return l}function cv({items:e=[],lookup:r}){const s=[],l=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)l.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)),[l]=j.useState(()=>gO(()=>s(o=>o+BigInt(1))));return xO(()=>{const o=l.get();o.length&&(e(o),l.reset())},[r]),l}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=pn(),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)})},[]),l=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:l,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 bx(){const e=fO(),r=pn(),s=bO(),l=Ut(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 Ql(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=Ql(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:l}),[l])}const hv=e=>e.selected,vO=typeof window<"u"?window:void 0;function jO({deleteKeyCode:e,multiSelectionKeyCode:r}){const s=pn(),{deleteElements:l}=bx(),o=Eo(e,{actInsideInputWithModifier:!1}),c=Eo(r,{target:vO});j.useEffect(()=>{if(o){const{edges:u,nodes:f}=s.getState();l({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=pn();j.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const l=fx(e.current);(l.height===0||l.width===0)&&r.getState().onError?.("004",hs.error004()),r.setState({width:l.width||500,height:l.height||500})};if(e.current){s(),window.addEventListener("resize",s);const l=new ResizeObserver(()=>s());return l.observe(e.current),()=>{window.removeEventListener("resize",s),l&&e.current&&l.unobserve(e.current)}}},[])}const td={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:l=!1,panOnScrollSpeed:o=.5,panOnScrollMode:c=Za.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=pn(),M=j.useRef(null),{userSelectionActive:Y,lib:$,connectionInProgress:X}=Ut(NO,gn),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=AD({domNode:M.current,minZoom:x,maxZoom:g,translateExtent:h,viewport:m,onDraggingChange:_=>H.setState(G=>G.paneDragging===_?G:{paneDragging:_}),onPanZoomStart:(_,G)=>{const{onViewportChangeStart:U,onMoveStart:J}=H.getState();J?.(_,G),U?.(G)},onPanZoom:(_,G)=>{const{onViewportChange:U,onMove:J}=H.getState();J?.(_,G),U?.(G)},onPanZoomEnd:(_,G)=>{const{onViewportChangeEnd:U,onMoveEnd:J}=H.getState();J?.(_,G),U?.(G)}});const{x:D,y:A,zoom:I}=q.current.getViewport();return H.setState({panZoom:q.current,transform:[D,A,I],domNode:M.current.closest(".react-flow")}),()=>{q.current?.destroy()}}},[]),j.useEffect(()=>{q.current?.update({onPaneContextMenu:e,zoomOnScroll:r,zoomOnPinch:s,panOnScroll:l,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,l,o,c,u,f,P,p,T,Y,S,$,F,X,k,N]),t.jsx("div",{className:"react-flow__renderer",ref:M,style:td,children:w})}const SO=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function CO(){const{userSelectionActive:e,userSelectionRect:r}=Ut(SO,gn);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 qh=(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:l,paneClickDistance:o,selectionOnDrag:c,onSelectionStart:u,onSelectionEnd:f,onPaneClick:m,onPaneContextMenu:h,onPaneScroll:x,onPaneMouseEnter:g,onPaneMouseMove:b,onPaneMouseLeave:p,children:w}){const S=pn(),{userSelectionActive:T,elementsSelectable:E,dragging:C,connectionInProgress:N}=Ut(EO,gn),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(l)&&l?.includes(2)){U.preventDefault();return}h?.(U)},F=x?U=>x(U):void 0,D=U=>{X.current&&(U.stopPropagation(),X.current=!1)},A=U=>{const{domNode:J}=S.getState();if(M.current=J?.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}=Wr(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:J,transform:B,nodeLookup:L,edgeLookup:ee,connectionLookup:R,triggerNodeChanges:z,triggerEdgeChanges:V,defaultEdgeOptions:K,resetSelectedElements:ne}=S.getState();if(!M.current||!J)return;const{x:Z,y:te}=Wr(U.nativeEvent,M.current),{startX:ie,startY:ye}=J;if(!X.current){const Qe=r?0:o;if(Math.hypot(Z-ie,te-ye)<=Qe)return;ne(),u?.(U)}X.current=!0;const ke={startX:ie,startY:ye,x:Z<ie?Z:ie,y:te<ye?te:ye,width:Math.abs(Z-ie),height:Math.abs(te-ye)},Me=Y.current,Ie=$.current;Y.current=new Set(ux(L,ke,B,s===ko.Partial,!0).map(Qe=>Qe.id)),$.current=new Set;const Le=K?.selectable??!0;for(const Qe of Y.current){const Ae=R.get(Qe);if(Ae)for(const{edgeId:Ge}of Ae.values()){const ut=ee.get(Ge);ut&&(ut.selectable??Le)&&$.current.add(Ge)}}if(!$y(Me,Y.current)){const Qe=Bl(L,Y.current,!0);z(Qe)}if(!$y(Ie,$.current)){const Qe=Bl(ee,$.current);V(Qe)}S.setState({userSelectionRect:ke,userSelectionActive:!0,nodesSelectionActive:!1})},_=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=l===!0||Array.isArray(l)&&l.includes(0);return t.jsxs("div",{className:Bn(["react-flow__pane",{draggable:G,dragging:C,selection:e}]),onClick:k?void 0:qh(P,H),onContextMenu:qh(q,H),onWheel:qh(F,H),onPointerEnter:k?void 0:g,onPointerMove:k?I:b,onPointerUp:k?_:void 0,onPointerDownCapture:k?A:void 0,onClickCapture:k?D:void 0,onPointerLeave:p,ref:H,style:td,children:[w,t.jsx(CO,{})]})}function Sm({id:e,store:r,unselect:s=!1,nodeRef:l}){const{addSelectedNodes:o,unselectNodesAndEdges:c,multiSelectionActive:u,nodeLookup:f,onError:m}=r.getState(),h=f.get(e);if(!h){m?.("012",hs.error012(e));return}r.setState({nodesSelectionActive:!1}),h.selected?(s||h.selected&&u)&&(c({nodes:[h],edges:[]}),requestAnimationFrame(()=>l?.current?.blur())):o([e])}function Ow({nodeRef:e,disabled:r=!1,noDragClassName:s,handleSelector:l,nodeId:o,isSelectable:c,nodeClickDistance:u}){const f=pn(),[m,h]=j.useState(!1),x=j.useRef();return j.useEffect(()=>{x.current=xD({getStoreItems:()=>f.getState(),onNodeMouseDown:g=>{Sm({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:l,domNode:e.current,isSelectable:c,nodeId:o,nodeClickDistance:u}),()=>{x.current?.destroy()}},[s,l,r,c,e,o,u]),m}const AO=e=>r=>r.selected&&(r.draggable||e&&typeof r.draggable>"u");function Rw(){const e=pn();return j.useCallback(s=>{const{nodeExtent:l,snapToGrid:o,snapGrid:c,nodesDraggable:u,onError:f,updateNodePositions:m,nodeLookup:h,nodeOrigin:x}=e.getState(),g=new Map,b=AO(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:l,nodeOrigin:x,onError:f});E.position=N,E.internals.positionAbsolute=k,g.set(E.id,E)}m(g)},[])}const yx=j.createContext(null),_O=yx.Provider;yx.Consumer;const zw=()=>j.useContext(yx),MO=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),DO=(e,r,s)=>l=>{const{connectionClickStartHandle:o,connectionMode:c,connection:u}=l,{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===Gl.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:l=!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=pn(),E=zw(),{connectOnClick:C,noPanClassName:N,rfId:k}=Ut(MO,gn),{connectingFrom:H,connectingTo:M,clickConnecting:Y,isPossibleEndHandle:$,connectionInProcess:X,clickConnectionInProcess:P,valid:q}=Ut(DO(E,w,e),gn);E||T.getState().onError?.("010",hs.error010());const F=I=>{const{defaultEdgeOptions:_,onConnect:G,hasDefaultEdges:U}=T.getState(),J={..._,...I};if(U){const{edges:B,setEdges:L}=T.getState();L(WM(J,B))}G?.(J),f?.(J)},D=I=>{if(!E)return;const _=iw(I.nativeEvent);if(o&&(_&&I.button===0||!_)){const G=T.getState();km.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})}_?x?.(I):g?.(I)},A=I=>{const{onClickConnectStart:_,onClickConnectEnd:G,connectionClickStartHandle:U,connectionMode:J,isValidConnection:B,lib:L,rfId:ee,nodeLookup:R,connection:z}=T.getState();if(!E||!U&&!o)return;if(!U){_?.(I.nativeEvent,{nodeId:E,handleId:w,handleType:e}),T.setState({connectionClickStartHandle:{nodeId:E,type:e,id:w}});return}const V=aw(I.target),K=s||B,{connection:ne,isValid:Z}=km.isValid(I.nativeEvent,{handle:{nodeId:E,id:w,type:e},connectionMode:J,fromNodeId:U.nodeId,fromHandleId:U.id||null,fromType:U.type,isValidConnection:K,flowId:ee,doc:V,lib:L,nodeLookup:R});Z&&ne&&F(ne);const te=structuredClone(z);delete te.inProgress,te.toPosition=te.toHandle?te.toHandle.position:null,G?.(I,te),T.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":w,"data-nodeid":E,"data-handlepos":r,"data-id":`${k}-${E}-${w}-${e}`,className:Bn(["react-flow__handle",`react-flow__handle-${r}`,"nodrag",N,h,{source:!S,target:S,connectable:l,connectablestart:o,connectableend:c,clickconnecting:Y,connectingfrom:H,connectingto:M,valid:q,connectionindicator:l&&(!X||$)&&(X||P?c:o)}]),onMouseDown:D,onTouchStart:D,onClick:C?A:void 0,ref:p,...b,children:m})}const wa=j.memo(Mw(OO));function RO({data:e,isConnectable:r,sourcePosition:s=nt.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(wa,{type:"source",position:s,isConnectable:r})]})}function zO({data:e,isConnectable:r,targetPosition:s=nt.Top,sourcePosition:l=nt.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(wa,{type:"target",position:s,isConnectable:r}),e?.label,t.jsx(wa,{type:"source",position:l,isConnectable:r})]})}function LO(){return null}function IO({data:e,isConnectable:r,targetPosition:s=nt.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(wa,{type:"target",position:s,isConnectable:r}),e?.label]})}const zu={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:l,y:o}=Lo(e.nodeLookup,{filter:c=>!!c.selected});return{width:Jr(r)?r:null,height:Jr(s)?s:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${l}px,${o}px)`}};function HO({onSelectionContextMenu:e,noPanClassName:r,disableKeyboardA11y:s}){const l=pn(),{width:o,height:c,transformString:u,userSelectionActive:f}=Ut(BO,gn),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=l.getState().nodes.filter(S=>S.selected);e(p,w)}:void 0,b=p=>{Object.prototype.hasOwnProperty.call(zu,p.key)&&(p.preventDefault(),m({direction:zu[p.key],factor:p.shiftKey?4:1}))};return t.jsx("div",{className:Bn(["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:l,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:A,noWheelClassName:I,noPanClassName:_,disableKeyboardA11y:G,onViewportChange:U,isControlledViewport:J}){const{nodesSelectionActive:B,userSelectionActive:L}=Ut(PO,gn),ee=Eo(h,{target:xv}),R=Eo(S,{target:xv}),z=R||$,V=R||k,K=x&&z!==!0,ne=ee||L||K;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:!ee&&z,defaultViewport:X,translateExtent:P,minZoom:q,maxZoom:F,zoomActivationKeyCode:T,preventScrolling:D,noWheelClassName:I,noPanClassName:_,onViewportChange:U,isControlledViewport:J,paneClickDistance:f,selectionOnDrag:K,children:t.jsxs(TO,{onSelectionStart:b,onSelectionEnd:p,onPaneClick:r,onPaneMouseEnter:s,onPaneMouseMove:l,onPaneMouseLeave:o,onPaneContextMenu:c,onPaneScroll:u,panOnDrag:z,isSelecting:!!ne,selectionMode:g,selectionKeyPressed:ee,paneClickDistance:f,selectionOnDrag:K,children:[e,B&&t.jsx(HO,{onSelectionContextMenu:A,noPanClassName:_,disableKeyboardA11y:G})]})})}Lw.displayName="FlowRenderer";const UO=j.memo(Lw),qO=e=>r=>e?ux(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 Ut(j.useCallback(qO(e),[e]),gn)}const FO=e=>e.updateNodeInternals;function YO(){const e=Ut(FO),[r]=j.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const l=new Map;s.forEach(o=>{const c=o.target.getAttribute("data-id");l.set(c,{id:c,nodeElement:o.target,force:!0})}),e(l)}));return j.useEffect(()=>()=>{r?.disconnect()},[r]),r}function GO({node:e,nodeType:r,hasDimensions:s,resizeObserver:l}){const o=pn(),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&&l?.unobserve(u.current),l?.observe(c.current),u.current=c.current)},[x,e.hidden]),j.useEffect(()=>()=>{u.current&&(l?.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:l,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}=Ut(Z=>{const te=Z.nodeLookup.get(e),ie=Z.parentLookup.has(e);return{node:te,internals:te.internals,isParent:ie}},gn);let M=N.type||"default",Y=T?.[M]||mv[M];Y===void 0&&(C?.("003",hs.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=pn(),D=rw(N),A=GO({node:N,nodeType:M,hasDimensions:D,resizeObserver:g}),I=Ow({nodeRef:A,disabled:N.hidden||!$,noDragClassName:b,handleSelector:N.dragHandle,nodeId:e,isSelectable:X,nodeClickDistance:E}),_=Rw();if(N.hidden)return null;const G=Hs(N),U=$O(N),J=X||$||r||s||l||o,B=s?Z=>s(Z,{...k.userNode}):void 0,L=l?Z=>l(Z,{...k.userNode}):void 0,ee=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:te,nodeDragThreshold:ie}=F.getState();X&&(!te||!$||ie>0)&&Sm({id:e,store:F,nodeRef:A}),r&&r(Z,{...k.userNode})},K=Z=>{if(!(lw(Z.nativeEvent)||w)){if(Xj.includes(Z.key)&&X){const te=Z.key==="Escape";Sm({id:e,store:F,unselect:te,nodeRef:A})}else if($&&N.selected&&Object.prototype.hasOwnProperty.call(zu,Z.key)){Z.preventDefault();const{ariaLabelConfig:te}=F.getState();F.setState({ariaLiveMessage:te["node.a11yDescription.ariaLiveMessage"]({direction:Z.key.replace("Arrow","").toLowerCase(),x:~~k.positionAbsolute.x,y:~~k.positionAbsolute.y})}),_({direction:zu[Z.key],factor:Z.shiftKey?4:1})}}},ne=()=>{if(w||!A.current?.matches(":focus-visible"))return;const{transform:Z,width:te,height:ie,autoPanOnNodeFocus:ye,setCenter:ke}=F.getState();if(!ye)return;ux(new Map([[e,N]]),{x:0,y:0,width:te,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:Bn(["react-flow__node",`react-flow__node-${M}`,{[p]:$},N.className,{selected:N.selected,selectable:X,parent:H,draggable:$,dragging:I}]),ref:A,style:{zIndex:k.z,transform:`translate(${k.positionAbsolute.x}px,${k.positionAbsolute.y}px)`,pointerEvents:J?"all":"none",visibility:D?"visible":"hidden",...N.style,...U},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:B,onMouseMove:L,onMouseLeave:ee,onContextMenu:R,onClick:V,onDoubleClick:z,onKeyDown:q?K:void 0,tabIndex:q?0:void 0,onFocus:q?ne: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(_O,{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:l,elementsSelectable:o,onError:c}=Ut(QO,gn),u=VO(e.onlyRenderVisibleElements),f=YO();return t.jsx("div",{className:"react-flow__nodes",style:td,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:l,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:c},m))})}Iw.displayName="NodeRenderer";const KO=j.memo(Iw);function JO(e){return Ut(j.useCallback(s=>{if(!e)return s.edges.map(o=>o.id);const l=[];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})&&l.push(o.id)}return l},[e]),gn)}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={[Xl.Arrow]:WO,[Xl.ArrowClosed]:eR};function tR(e){const r=pn();return j.useMemo(()=>Object.prototype.hasOwnProperty.call(gv,e)?gv[e]:(r.getState().onError?.("009",hs.error009(e)),null),[e])}const nR=({id:e,type:r,color:s,width:l=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:`${l}`,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=Ut(c=>c.edges),l=Ut(c=>c.defaultEdgeOptions),o=j.useMemo(()=>sD(s,{id:r,defaultColor:e,defaultMarkerStart:l?.markerStart,defaultMarkerEnd:l?.markerEnd}),[s,l,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:l,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=Bn(["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:l,children:s}),m]}):null}Bw.displayName="EdgeText";const sR=j.memo(Bw);function nd({path:e,labelX:r,labelY:s,label:l,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:Bn(["react-flow__edge-path",x.className])}),h?t.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:h,className:"react-flow__edge-interaction"}):null,l&&Jr(r)&&Jr(s)?t.jsx(sR,{x:r,y:s,label:l,labelStyle:o,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m}):null]})}function pv({pos:e,x1:r,y1:s,x2:l,y2:o}){return e===nt.Left||e===nt.Right?[.5*(r+l),s]:[r,.5*(s+o)]}function Hw({sourceX:e,sourceY:r,sourcePosition:s=nt.Bottom,targetX:l,targetY:o,targetPosition:c=nt.Top}){const[u,f]=pv({pos:s,x1:e,y1:r,x2:l,y2:o}),[m,h]=pv({pos:c,x1:l,y1:o,x2:e,y2:r}),[x,g,b,p]=ow({sourceX:e,sourceY:r,targetX:l,targetY:o,sourceControlX:u,sourceControlY:f,targetControlX:m,targetControlY:h});return[`M${e},${r} C${u},${f} ${m},${h} ${l},${o}`,x,g,b,p]}function Pw(e){return j.memo(({id:r,sourceX:s,sourceY:l,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:l,sourcePosition:u,targetX:o,targetY:c,targetPosition:f}),H=e.isInternal?void 0:r;return t.jsx(nd,{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:l,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]=jm({sourceX:s,sourceY:l,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(nd,{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 l=e.isInternal?void 0:r;return t.jsx(Vw,{...s,id:l,pathOptions:j.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const lR=Yw({isInternal:!1}),Gw=Yw({isInternal:!0});lR.displayName="StepEdge";Gw.displayName="StepEdgeInternal";function Xw(e){return j.memo(({id:r,sourceX:s,sourceY:l,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:l,targetX:o,targetY:c}),N=e.isInternal?void 0:r;return t.jsx(nd,{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 iR=Xw({isInternal:!1}),Zw=Xw({isInternal:!0});iR.displayName="StraightEdge";Zw.displayName="StraightEdgeInternal";function Qw(e){return j.memo(({id:r,sourceX:s,sourceY:l,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:l,sourcePosition:u,targetX:o,targetY:c,targetPosition:f,curvature:E?.curvature}),M=e.isInternal?void 0:r;return t.jsx(nd,{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:l=10,onMouseDown:o,onMouseEnter:c,onMouseOut:u,type:f}){return t.jsx("circle",{onMouseDown:o,onMouseEnter:c,onMouseOut:u,className:Bn([vv,`${vv}-${f}`]),cx:cR(r,l,e),cy:uR(s,l,e),r:l,stroke:"transparent",fill:"transparent"})}function dR({isReconnectable:e,reconnectRadius:r,edge:s,sourceX:l,sourceY:o,targetX:c,targetY:u,sourcePosition:f,targetPosition:m,onReconnect:h,onReconnectStart:x,onReconnectEnd:g,setReconnecting:b,setUpdateHover:p}){const w=pn(),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:A,panBy:I,updateConnection:_}=w.getState(),G=H.type==="target",U=(L,ee)=>{b(!1),g?.(L,s,H.type,ee)},J=L=>h?.(s,L),B=(L,ee)=>{b(!0),x?.(k,s,H.type),q?.(L,ee)};km.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:A,cancelConnection:F,panBy:I,isValidConnection:(...L)=>w.getState().isValidConnection?.(...L)??!0,onConnect:J,onConnectStart:B,onConnectEnd:(...L)=>w.getState().onConnectEnd?.(...L),onReconnectEnd:U,updateConnection:_,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:l,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:l,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=Ut(ke=>ke.edgeLookup.get(e));const k=Ut(ke=>ke.defaultEdgeOptions);N=k?{...k,...N}:N;let H=N.type||"default",M=S?.[H]||bv[H];M===void 0&&(E?.("011",hs.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||l&&typeof N.selectable>"u"),P=j.useRef(null),[q,F]=j.useState(!1),[D,A]=j.useState(!1),I=pn(),{zIndex:_,sourceX:G,sourceY:U,targetX:J,targetY:B,sourcePosition:L,targetPosition:ee}=Ut(j.useCallback(ke=>{const Me=ke.nodeLookup.get(N.source),Ie=ke.nodeLookup.get(N.target);if(!Me||!Ie)return{zIndex:N.zIndex,...yv};const Le=rD({id:e,sourceNode:Me,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:Me,targetNode:Ie,elevateOnSelect:ke.elevateEdgesOnSelect,zIndexMode:ke.zIndexMode}),...Le||yv}},[N.source,N.target,N.sourceHandle,N.targetHandle,N.selected,N.zIndex]),gn),R=j.useMemo(()=>N.markerStart?`url('#${wm(N.markerStart,w)}')`:void 0,[N.markerStart,w]),z=j.useMemo(()=>N.markerEnd?`url('#${wm(N.markerEnd,w)}')`:void 0,[N.markerEnd,w]);if(N.hidden||G===null||U===null||J===null||B===null)return null;const V=ke=>{const{addSelectedEdges:Me,unselectNodesAndEdges:Ie,multiSelectionActive:Le}=I.getState();X&&(I.setState({nodesSelectionActive:!1}),N.selected&&Le?(Ie({nodes:[],edges:[N]}),P.current?.blur()):Me([e])),o&&o(ke,N)},K=c?ke=>{c(ke,{...N})}:void 0,ne=u?ke=>{u(ke,{...N})}:void 0,Z=f?ke=>{f(ke,{...N})}:void 0,te=m?ke=>{m(ke,{...N})}:void 0,ie=h?ke=>{h(ke,{...N})}:void 0,ye=ke=>{if(!C&&Xj.includes(ke.key)&&X){const{unselectNodesAndEdges:Me,addSelectedEdges:Ie}=I.getState();ke.key==="Escape"?(P.current?.blur(),Me({edges:[N]})):Ie([e])}};return t.jsx("svg",{style:{zIndex:_},children:t.jsxs("g",{className:Bn(["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:K,onContextMenu:ne,onMouseEnter:Z,onMouseMove:te,onMouseLeave:ie,onKeyDown:Y?ye: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:J,targetY:B,sourcePosition:L,targetPosition:ee,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:J,targetY:B,sourcePosition:L,targetPosition:ee,setUpdateHover:F,setReconnecting:A})]})})}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:l,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}=Ut(mR,gn),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:l,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=Ut(gR);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:r},children:e})}function bR(e){const r=bx(),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=Ut(yR),s=pn();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 Ut(r,gn)}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:l}){const{nodesConnectable:o,width:c,height:u,isValid:f,inProgress:m}=Ut(kR,gn);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:Bn(["react-flow__connection",Kj(f)]),children:t.jsx(Ww,{style:r,type:s,CustomComponent:l,isValid:f})})})}const Ww=({style:e,type:r=va.Bezier,CustomComponent:s,isValid:l})=>{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(l),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 va.Bezier:[w]=cw(S);break;case va.SimpleBezier:[w]=Hw(S);break;case va.Step:[w]=jm({...S,borderRadius:0});break;case va.SmoothStep:[w]=jm(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),pn(),j.useEffect(()=>{},[e])}function ER(){pn(),j.useRef(!1),j.useEffect(()=>{},[])}function eN({nodeTypes:e,edgeTypes:r,onInit:s,onNodeClick:l,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:A,preventScrolling:I,defaultMarkerColor:_,zoomOnScroll:G,zoomOnPinch:U,panOnScroll:J,panOnScrollSpeed:B,panOnScrollMode:L,zoomOnDoubleClick:ee,panOnDrag:R,onPaneClick:z,onPaneMouseEnter:V,onPaneMouseMove:K,onPaneMouseLeave:ne,onPaneScroll:Z,onPaneContextMenu:te,paneClickDistance:ie,nodeClickDistance:ye,onEdgeContextMenu:ke,onEdgeMouseEnter:Me,onEdgeMouseMove:Ie,onEdgeMouseLeave:Le,reconnectRadius:Qe,onReconnect:Ae,onReconnectStart:Ge,onReconnectEnd:ut,noDragClassName:_t,noWheelClassName:oe,noPanClassName:Oe,disableKeyboardA11y:xt,nodeExtent:vt,rfId:Gt,viewport:ve,onViewportChange:De}){return wv(e),wv(r),ER(),bR(s),vR(ve),t.jsx(UO,{onPaneClick:z,onPaneMouseEnter:V,onPaneMouseMove:K,onPaneMouseLeave:ne,onPaneContextMenu:te,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:ee,panOnScroll:J,panOnScrollSpeed:B,panOnScrollMode:L,panOnDrag:R,defaultViewport:q,translateExtent:F,minZoom:D,maxZoom:A,onSelectionContextMenu:g,preventScrolling:I,noDragClassName:_t,noWheelClassName:oe,noPanClassName:Oe,disableKeyboardA11y:xt,onViewportChange:De,isControlledViewport:!!ve,children:t.jsxs(pR,{children:[t.jsx(xR,{edgeTypes:r,onEdgeClick:o,onEdgeDoubleClick:u,onReconnect:Ae,onReconnectStart:Ge,onReconnectEnd:ut,onlyRenderVisibleElements:X,onEdgeContextMenu:ke,onEdgeMouseEnter:Me,onEdgeMouseMove:Ie,onEdgeMouseLeave:Le,reconnectRadius:Qe,defaultMarkerColor:_,noPanClassName:Oe,disableKeyboardA11y:xt,rfId:Gt}),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:l,onNodeDoubleClick:c,onNodeMouseEnter:f,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:x,nodeClickDistance:ye,onlyRenderVisibleElements:X,noPanClassName:Oe,noDragClassName:_t,disableKeyboardA11y:xt,nodeExtent:vt,rfId:Gt}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}eN.displayName="GraphView";const TR=j.memo(eN),Nv=({nodes:e,edges:r,defaultNodes:s,defaultEdges:l,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=l??r??[],C=s??e??[],N=x??[0,0],k=g??No;mw(S,T,E);const H=Nm(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}=dx(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:l!==void 0,panZoom:null,minZoom:m,maxZoom:h,translateExtent:No,nodeExtent:k,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Gl.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}},AR=({nodes:e,edges:r,defaultNodes:s,defaultEdges:l,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:l,zIndexMode:b}),setNodes:T=>{const{nodeLookup:E,parentLookup:C,nodeOrigin:N,elevateNodesOnSelect:k,fitViewQueued:H,zIndexMode:M}=w(),Y=Nm(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&&(iD(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 A=el(q,M.fromHandle,nt.Left,!0);Y({...M,from:A})}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=px(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=Aw(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=_w(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=>Fa(Y,!0));k(M);return}k(Bl(N,new Set([...T]),!0)),H(Bl(C))},addSelectedEdges:T=>{const{multiSelectionActive:E,edgeLookup:C,nodeLookup:N,triggerNodeChanges:k,triggerEdgeChanges:H}=w();if(E){const M=T.map(Y=>Fa(Y,!0));H(M);return}H(Bl(C,new Set([...T]))),k(Bl(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(Fa(q.id,!1))}const P=[];for(const q of $)q.selected&&P.push(Fa(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,Fa($.id,!1)]:Y,[]),M=T.reduce((Y,$)=>$.selected?[...Y,Fa($.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]||(Nm(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 _R({initialNodes:e,initialEdges:r,defaultNodes:s,defaultEdges:l,initialWidth:o,initialHeight:c,initialMinZoom:u,initialMaxZoom:f,initialFitViewOptions:m,fitView:h,nodeOrigin:x,nodeExtent:g,zIndexMode:b,children:p}){const[w]=j.useState(()=>AR({nodes:e,edges:r,defaultNodes:s,defaultEdges:l,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:l,defaultEdges:o,width:c,height:u,fitView:f,fitViewOptions:m,minZoom:h,maxZoom:x,nodeOrigin:g,nodeExtent:b,zIndexMode:p}){return j.useContext(Wu)?t.jsx(t.Fragment,{children:e}):t.jsx(_R,{initialNodes:r,initialEdges:s,defaultNodes:l,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:l,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:A,onSelectionDrag:I,onSelectionDragStop:_,onSelectionContextMenu:G,onSelectionStart:U,onSelectionEnd:J,onBeforeDelete:B,connectionMode:L,connectionLineType:ee=va.Bezier,connectionLineStyle:R,connectionLineComponent:z,connectionLineContainerStyle:V,deleteKeyCode:K="Backspace",selectionKeyCode:ne="Shift",selectionOnDrag:Z=!1,selectionMode:te=ko.Full,panActivationKeyCode:ie="Space",multiSelectionKeyCode:ye=Co()?"Meta":"Control",zoomActivationKeyCode:ke=Co()?"Meta":"Control",snapToGrid:Me,snapGrid:Ie,onlyRenderVisibleElements:Le=!1,selectNodesOnDrag:Qe,nodesDraggable:Ae,autoPanOnNodeFocus:Ge,nodesConnectable:ut,nodesFocusable:_t,nodeOrigin:oe=Ew,edgesFocusable:Oe,edgesReconnectable:xt,elementsSelectable:vt=!0,defaultViewport:Gt=iO,minZoom:ve=.5,maxZoom:De=2,translateExtent:He=No,preventScrolling:Ye=!0,nodeExtent:tt,defaultMarkerColor:Dt="#b1b1b7",zoomOnScroll:$t=!0,zoomOnPinch:bt=!0,panOnScroll:yt=!1,panOnScrollSpeed:he=.5,panOnScrollMode:$e=Za.Free,zoomOnDoubleClick:ht=!0,panOnDrag:dt=!0,onPaneClick:gt,onPaneMouseEnter:jt,onPaneMouseMove:en,onPaneMouseLeave:hn,onPaneScroll:sn,onPaneContextMenu:bn,paneClickDistance:Nt=1,nodeClickDistance:Q=0,children:ue,onReconnect:Se,onReconnectStart:qe,onReconnectEnd:et,onEdgeContextMenu:Ue,onEdgeDoubleClick:yn,onEdgeMouseEnter:mn,onEdgeMouseMove:Mt,onEdgeMouseLeave:_n,reconnectRadius:Hn=10,onNodesChange:Mn,onEdgesChange:an,noDragClassName:ln="nodrag",noWheelClassName:vn="nowheel",noPanClassName:Pn="nopan",fitView:be,fitViewOptions:Ke,connectOnClick:kt,attributionPosition:Et,proOptions:jn,defaultEdgeOptions:sr,elevateNodesOnSelect:ar=!0,elevateEdgesOnSelect:Dr=!1,disableKeyboardA11y:Or=!1,autoPanOnConnect:yr,autoPanOnNodeDrag:on,autoPanSpeed:Rr,connectionRadius:Ps,isValidConnection:lr,onError:ir,style:Us,id:Cn,nodeDragThreshold:Yr,connectionDragThreshold:ka,viewport:or,onViewportChange:zr,width:Fn,height:wn,colorMode:vr="light",debug:se,onScroll:Re,ariaLabelConfig:Pe,zIndexMode:re="basic",...pe},we){const Ee=Cn||"1",_e=dO(vr),Be=j.useCallback(Ve=>{Ve.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Re?.(Ve)},[Re]);return t.jsx("div",{"data-testid":"rf__wrapper",...pe,onScroll:Be,style:{...Us,...DR},ref:we,className:Bn(["react-flow",o,_e]),id:Cn,role:"application",children:t.jsxs(MR,{nodes:e,edges:r,width:Fn,height:wn,fitView:be,fitViewOptions:Ke,minZoom:ve,maxZoom:De,nodeOrigin:oe,nodeExtent:tt,zIndexMode:re,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:ee,connectionLineStyle:R,connectionLineComponent:z,connectionLineContainerStyle:V,selectionKeyCode:ne,selectionOnDrag:Z,selectionMode:te,deleteKeyCode:K,multiSelectionKeyCode:ye,panActivationKeyCode:ie,zoomActivationKeyCode:ke,onlyRenderVisibleElements:Le,defaultViewport:Gt,translateExtent:He,minZoom:ve,maxZoom:De,preventScrolling:Ye,zoomOnScroll:$t,zoomOnPinch:bt,zoomOnDoubleClick:ht,panOnScroll:yt,panOnScrollSpeed:he,panOnScrollMode:$e,panOnDrag:dt,onPaneClick:gt,onPaneMouseEnter:jt,onPaneMouseMove:en,onPaneMouseLeave:hn,onPaneScroll:sn,onPaneContextMenu:bn,paneClickDistance:Nt,nodeClickDistance:Q,onSelectionContextMenu:G,onSelectionStart:U,onSelectionEnd:J,onReconnect:Se,onReconnectStart:qe,onReconnectEnd:et,onEdgeContextMenu:Ue,onEdgeDoubleClick:yn,onEdgeMouseEnter:mn,onEdgeMouseMove:Mt,onEdgeMouseLeave:_n,reconnectRadius:Hn,defaultMarkerColor:Dt,noDragClassName:ln,noWheelClassName:vn,noPanClassName:Pn,rfId:Ee,disableKeyboardA11y:Or,nodeExtent:tt,viewport:or,onViewportChange:zr}),t.jsx(uO,{nodes:e,edges:r,defaultNodes:s,defaultEdges:l,onConnect:p,onConnectStart:w,onConnectEnd:S,onClickConnectStart:T,onClickConnectEnd:E,nodesDraggable:Ae,autoPanOnNodeFocus:Ge,nodesConnectable:ut,nodesFocusable:_t,edgesFocusable:Oe,edgesReconnectable:xt,elementsSelectable:vt,elevateNodesOnSelect:ar,elevateEdgesOnSelect:Dr,minZoom:ve,maxZoom:De,nodeExtent:tt,onNodesChange:Mn,onEdgesChange:an,snapToGrid:Me,snapGrid:Ie,connectionMode:L,translateExtent:He,connectOnClick:kt,defaultEdgeOptions:sr,fitView:be,fitViewOptions:Ke,onNodesDelete:P,onEdgesDelete:q,onDelete:F,onNodeDragStart:Y,onNodeDrag:$,onNodeDragStop:X,onSelectionDrag:I,onSelectionDragStart:A,onSelectionDragStop:_,onMove:x,onMoveStart:g,onMoveEnd:b,noPanClassName:Pn,nodeOrigin:oe,rfId:Ee,autoPanOnConnect:yr,autoPanOnNodeDrag:on,autoPanSpeed:Rr,onError:ir,connectionRadius:Ps,isValidConnection:lr,selectNodesOnDrag:Qe,nodeDragThreshold:Yr,connectionDragThreshold:ka,onBeforeDelete:B,debug:se,ariaLabelConfig:Pe,zIndexMode:re}),t.jsx(lO,{onSelectionChange:D}),ue,t.jsx(tO,{proOptions:jn,position:Et}),t.jsx(eO,{rfId:Ee,disableKeyboardA11y:Or})]})})}var RR=Mw(OR);function zR(e){const[r,s]=j.useState(e),l=j.useCallback(o=>s(c=>Aw(o,c)),[]);return[r,s,l]}function LR(e){const[r,s]=j.useState(e),l=j.useCallback(o=>s(c=>_w(o,c)),[]);return[r,s,l]}function IR({dimensions:e,lineWidth:r,variant:s,className:l}){return t.jsx("path",{strokeWidth:r,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Bn(["react-flow__background-pattern",s,l])})}function $R({radius:e,className:r}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Bn(["react-flow__background-pattern","dots",r])})}var ja;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(ja||(ja={}));const BR={[ja.Dots]:1,[ja.Lines]:1,[ja.Cross]:6},HR=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function tN({id:e,variant:r=ja.Dots,gap:s=20,size:l,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}=Ut(HR,gn),w=l||BR[r],S=r===ja.Dots,T=r===ja.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:Bn(["react-flow__background",h]),style:{...m,...td,"--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:Bn(["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:l=!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=pn(),{isInteractive:S,minZoomReached:T,maxZoomReached:E,ariaLabelConfig:C}=Ut(GR,gn),{zoomIn:N,zoomOut:k,fitView:H}=bx(),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(ed,{className:Bn(["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,{})}),l&&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:l,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:Bn(["react-flow__minimap-node",{selected:b},h]),x:r,y:s,rx:x,ry:x,width:l,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),Vh=e=>e instanceof Function?e:()=>e;function JR({nodeStrokeColor:e,nodeColor:r,nodeClassName:s="",nodeBorderRadius:l=5,nodeStrokeWidth:o,nodeComponent:c=QR,onClick:u}){const f=Ut(KR,gn),m=Vh(r),h=Vh(e),x=Vh(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:l,nodeStrokeWidth:o,NodeComponent:c,onClick:u,shapeRendering:g},b))})}function WR({id:e,nodeColorFunc:r,nodeStrokeColorFunc:s,nodeClassNameFunc:l,nodeBorderRadius:o,nodeStrokeWidth:c,shapeRendering:u,NodeComponent:f,onClick:m}){const{node:h,x,y:g,width:b,height:p}=Ut(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}},gn);return!h||h.hidden||!rw(h)?null:t.jsx(f,{x,y:g,width:b,height:p,style:h.style,selected:!!h.selected,className:l(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}},lz="react-flow__minimap-desc";function rN({style:e,className:r,nodeStrokeColor:s,nodeColor:l,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=pn(),M=j.useRef(null),{boundingRect:Y,viewBB:$,rfId:X,panZoom:P,translateExtent:q,flowWidth:F,flowHeight:D,ariaLabelConfig:A}=Ut(az,gn),I=e?.width??nz,_=e?.height??rz,G=Y.width/I,U=Y.height/_,J=Math.max(G,U),B=J*I,L=J*_,ee=k*J,R=Y.x-(B-Y.width)/2-ee,z=Y.y-(L-Y.height)/2-ee,V=B+ee*2,K=L+ee*2,ne=`${lz}-${X}`,Z=j.useRef(0),te=j.useRef();Z.current=J,j.useEffect(()=>{if(M.current&&P)return te.current=jD({domNode:M.current,panZoom:P,getTransform:()=>H.getState().transform,getViewScale:()=>Z.current}),()=>{te.current?.destroy()}},[P]),j.useEffect(()=>{te.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?Me=>{const[Ie,Le]=te.current?.pointer(Me)||[0,0];p(Me,{x:Ie,y:Le})}:void 0,ye=w?j.useCallback((Me,Ie)=>{const Le=H.getState().nodeLookup.get(Ie).internals.userNode;w(Me,Le)},[]):void 0,ke=E??A["minimap.ariaLabel"];return t.jsx(ed,{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*J:void 0,"--xy-minimap-node-background-color-props":typeof l=="string"?l: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:Bn(["react-flow__minimap",r]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:I,height:_,viewBox:`${R} ${z} ${V} ${K}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":ne,ref:M,onClick:ie,children:[ke&&t.jsx("title",{id:ne,children:ke}),t.jsx(tz,{onClick:ye,nodeColor:l,nodeStrokeColor:s,nodeBorderRadius:c,nodeClassName:o,nodeStrokeWidth:u,nodeComponent:f}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${R-ee},${z-ee}h${V+ee*2}v${K+ee*2}h${-V-ee*2}z
61
- M${$.x},${$.y}h${$.width}v${$.height}h${-$.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}rN.displayName="MiniMap";const iz=j.memo(rN),oz=e=>r=>e?`${Math.max(1/r.transform[2],1)}`:void 0,cz={[Jl.Line]:"right",[Jl.Handle]:"bottom-right"};function uz({nodeId:e,position:r,variant:s=Jl.Handle,className:l,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=pn(),H=j.useRef(null),M=s===Jl.Handle,Y=Ut(j.useCallback(oz(M&&p),[M,p]),gn),$=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:A,nodeOrigin:I,domNode:_}=k.getState();return{nodeLookup:q,transform:F,snapGrid:D,snapToGrid:A,nodeOrigin:I,paneDomNode:_}},onChange:(q,F)=>{const{triggerNodeChanges:D,nodeLookup:A,parentLookup:I,nodeOrigin:_}=k.getState(),G=[],U={x:q.x,y:q.y},J=A.get(N);if(J&&J.expandParent&&J.parentId){const B=J.origin??_,L=q.width??J.measured.width??0,ee=q.height??J.measured.height??0,R={id:J.id,parentId:J.parentId,rect:{width:L,height:ee,...sw({x:q.x??J.position.x,y:q.y??J.position.y},{width:L,height:ee},J.parentId,A,B)}},z=px([R],A,I,_);G.push(...z),U.x=q.x?Math.max(B[0]*L,q.x):void 0,U.y=q.y?Math.max(B[1]*ee,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:Bn(["react-flow__resize-control","nodrag",...P,s,l]),ref:H,style:{...o,scale:Y,...u&&{[M?"backgroundColor":"borderColor"]:u}},children:c})}j.memo(uz);var Qt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),ts=Qt((e,r)=>{var s=Object.defineProperty,l=(D,A,I)=>A in D?s(D,A,{enumerable:!0,configurable:!0,writable:!0,value:I}):D[A]=I,o=(D,A)=>()=>(A||D((A={exports:{}}).exports,A),A.exports),c=(D,A,I)=>l(D,typeof A!="symbol"?A+"":A,I),u=o((D,A)=>{var I="\0",_="\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[_]={})}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 K=arguments,ne=this;return z.forEach(function(Z){K.length>1?ne.setNode(Z,V):ne.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]=_,this._children[z]={},this._children[_][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 K=ne=>V.removeEdge(V._edgeObjs[ne]);delete this._nodes[z],this._isCompound&&(this._removeFromParentsChildList(z),delete this._parent[z],this.children(z).forEach(function(ne){V.setParent(ne)}),delete this._children[z]),Object.keys(this._in[z]).forEach(K),delete this._in[z],delete this._preds[z],Object.keys(this._out[z]).forEach(K),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=_;else{V+="";for(var K=V;K!==void 0;K=this.parent(K))if(K===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!==_)return V}}children(z=_){if(this._isCompound){var V=this._children[z];if(V)return Object.keys(V)}else{if(z===_)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 ne=new Set(V);for(var K of this.successors(z))ne.add(K);return Array.from(ne.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 K=this;Object.entries(this._nodes).forEach(function([te,ie]){z(te)&&V.setNode(te,ie)}),Object.values(this._edgeObjs).forEach(function(te){V.hasNode(te.v)&&V.hasNode(te.w)&&V.setEdge(te,K.edge(te))});var ne={};function Z(te){var ie=K.parent(te);return ie===void 0||V.hasNode(ie)?(ne[te]=ie,ie):ie in ne?ne[ie]:Z(ie)}return this._isCompound&&V.nodes().forEach(te=>V.setParent(te,Z(te))),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 K=this,ne=arguments;return z.reduce(function(Z,te){return ne.length>1?K.setEdge(Z,te,V):K.setEdge(Z,te),te}),this}setEdge(){var z,V,K,ne,Z=!1,te=arguments[0];typeof te=="object"&&te!==null&&"v"in te?(z=te.v,V=te.w,K=te.name,arguments.length===2&&(ne=arguments[1],Z=!0)):(z=te,V=arguments[1],K=arguments[3],arguments.length>2&&(ne=arguments[2],Z=!0)),z=""+z,V=""+V,K!==void 0&&(K=""+K);var ie=L(this._isDirected,z,V,K);if(Object.hasOwn(this._edgeLabels,ie))return Z&&(this._edgeLabels[ie]=ne),this;if(K!==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?ne:this._defaultEdgeLabelFn(z,V,K);var ye=ee(this._isDirected,z,V,K);return z=ye.v,V=ye.w,Object.freeze(ye),this._edgeObjs[ie]=ye,J(this._preds[V],z),J(this._sucs[z],V),this._in[V][ie]=ye,this._out[z][ie]=ye,this._edgeCount++,this}edge(z,V,K){var ne=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,K);return this._edgeLabels[ne]}edgeAsObj(){let z=this.edge(...arguments);return typeof z!="object"?{label:z}:z}hasEdge(z,V,K){var ne=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,K);return Object.hasOwn(this._edgeLabels,ne)}removeEdge(z,V,K){var ne=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,K),Z=this._edgeObjs[ne];return Z&&(z=Z.v,V=Z.w,delete this._edgeLabels[ne],delete this._edgeObjs[ne],B(this._preds[V],z),B(this._sucs[z],V),delete this._in[V][ne],delete this._out[z][ne],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,K){if(z){var ne=Object.values(z);return K?ne.filter(function(Z){return Z.v===V&&Z.w===K||Z.v===K&&Z.w===V}):ne}}};function J(z,V){z[V]?z[V]++:z[V]=1}function B(z,V){--z[V]||delete z[V]}function L(z,V,K,ne){var Z=""+V,te=""+K;if(!z&&Z>te){var ie=Z;Z=te,te=ie}return Z+G+te+G+(ne===void 0?I:ne)}function ee(z,V,K,ne){var Z=""+V,te=""+K;if(!z&&Z>te){var ie=Z;Z=te,te=ie}var ye={v:Z,w:te};return ne&&(ye.name=ne),ye}function R(z,V){return L(z,V.v,V.w,V.name)}A.exports=U}),f=o((D,A)=>{A.exports="3.0.2"}),m=o((D,A)=>{A.exports={Graph:u(),version:f()}}),h=o((D,A)=>{var I=u();A.exports={write:_,read:J};function _(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 ee=B.node(L),R=B.parent(L),z={v:L};return ee!==void 0&&(z.value=ee),R!==void 0&&(z.parent=R),z})}function U(B){return B.edges().map(function(L){var ee=B.edge(L),R={v:L.v,w:L.w};return L.name!==void 0&&(R.name=L.name),ee!==void 0&&(R.value=ee),R})}function J(B){var L=new I(B.options).setGraph(B.value);return B.nodes.forEach(function(ee){L.setNode(ee.v,ee.value),ee.parent&&L.setParent(ee.v,ee.parent)}),B.edges.forEach(function(ee){L.setEdge({v:ee.v,w:ee.w,name:ee.name},ee.value)}),L}}),x=o((D,A)=>{A.exports=_;var I=()=>1;function _(U,J,B,L){return G(U,String(J),B||I,L||function(ee){return U.outEdges(ee)})}function G(U,J,B,L){var ee={},R=!0,z=0,V=U.nodes(),K=function(ie){var ye=B(ie);ee[ie.v].distance+ye<ee[ie.w].distance&&(ee[ie.w]={distance:ee[ie.v].distance+ye,predecessor:ie.v},R=!0)},ne=function(){V.forEach(function(ie){L(ie).forEach(function(ye){var ke=ye.v===ie?ye.v:ye.w,Me=ke===ye.v?ye.w:ye.v;K({v:ke,w:Me})})})};V.forEach(function(ie){var ye=ie===J?0:Number.POSITIVE_INFINITY;ee[ie]={distance:ye}});for(var Z=V.length,te=1;te<Z&&(R=!1,z++,ne(),!!R);te++);if(z===Z-1&&(R=!1,ne(),R))throw new Error("The graph contains a negative weight cycle");return ee}}),g=o((D,A)=>{A.exports=I;function I(_){var G={},U=[],J;function B(L){Object.hasOwn(G,L)||(G[L]=!0,J.push(L),_.successors(L).forEach(B),_.predecessors(L).forEach(B))}return _.nodes().forEach(function(L){J=[],B(L),J.length&&U.push(J)}),U}}),b=o((D,A)=>{var I=class{constructor(){c(this,"_arr",[]),c(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(_){return _.key})}has(_){return Object.hasOwn(this._keyIndices,_)}priority(_){var G=this._keyIndices[_];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(_,G){var U=this._keyIndices;if(_=String(_),!Object.hasOwn(U,_)){var J=this._arr,B=J.length;return U[_]=B,J.push({key:_,priority:G}),this._decrease(B),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var _=this._arr.pop();return delete this._keyIndices[_.key],this._heapify(0),_.key}decrease(_,G){var U=this._keyIndices[_];if(G>this._arr[U].priority)throw new Error("New priority is greater than current priority. Key: "+_+" Old: "+this._arr[U].priority+" New: "+G);this._arr[U].priority=G,this._decrease(U)}_heapify(_){var G=this._arr,U=2*_,J=U+1,B=_;U<G.length&&(B=G[U].priority<G[B].priority?U:B,J<G.length&&(B=G[J].priority<G[B].priority?J:B),B!==_&&(this._swap(_,B),this._heapify(B)))}_decrease(_){for(var G=this._arr,U=G[_].priority,J;_!==0&&(J=_>>1,!(G[J].priority<U));)this._swap(_,J),_=J}_swap(_,G){var U=this._arr,J=this._keyIndices,B=U[_],L=U[G];U[_]=L,U[G]=B,J[L.key]=_,J[B.key]=G}};A.exports=I}),p=o((D,A)=>{var I=b();A.exports=G;var _=()=>1;function G(J,B,L,ee){var R=function(z){return J.outEdges(z)};return U(J,String(B),L||_,ee||R)}function U(J,B,L,ee){var R={},z=new I,V,K,ne=function(Z){var te=Z.v!==V?Z.v:Z.w,ie=R[te],ye=L(Z),ke=K.distance+ye;if(ye<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+Z+" Weight: "+ye);ke<ie.distance&&(ie.distance=ke,ie.predecessor=V,z.decrease(te,ke))};for(J.nodes().forEach(function(Z){var te=Z===B?0:Number.POSITIVE_INFINITY;R[Z]={distance:te},z.add(Z,te)});z.size()>0&&(V=z.removeMin(),K=R[V],K.distance!==Number.POSITIVE_INFINITY);)ee(V).forEach(ne);return R}}),w=o((D,A)=>{var I=p();A.exports=_;function _(G,U,J){return G.nodes().reduce(function(B,L){return B[L]=I(G,L,U,J),B},{})}}),S=o((D,A)=>{A.exports=I;function I(G,U,J){if(G[U].predecessor!==void 0)throw new Error("Invalid source vertex");if(G[J].predecessor===void 0&&J!==U)throw new Error("Invalid destination vertex");return{weight:G[J].distance,path:_(G,U,J)}}function _(G,U,J){for(var B=[],L=J;L!==U;)B.push(L),L=G[L].predecessor;return B.push(U),B.reverse()}}),T=o((D,A)=>{A.exports=I;function I(_){var G=0,U=[],J={},B=[];function L(ee){var R=J[ee]={onStack:!0,lowlink:G,index:G++};if(U.push(ee),_.successors(ee).forEach(function(K){Object.hasOwn(J,K)?J[K].onStack&&(R.lowlink=Math.min(R.lowlink,J[K].index)):(L(K),R.lowlink=Math.min(R.lowlink,J[K].lowlink))}),R.lowlink===R.index){var z=[],V;do V=U.pop(),J[V].onStack=!1,z.push(V);while(ee!==V);B.push(z)}}return _.nodes().forEach(function(ee){Object.hasOwn(J,ee)||L(ee)}),B}}),E=o((D,A)=>{var I=T();A.exports=_;function _(G){return I(G).filter(function(U){return U.length>1||U.length===1&&G.hasEdge(U[0],U[0])})}}),C=o((D,A)=>{A.exports=_;var I=()=>1;function _(U,J,B){return G(U,J||I,B||function(L){return U.outEdges(L)})}function G(U,J,B){var L={},ee=U.nodes();return ee.forEach(function(R){L[R]={},L[R][R]={distance:0},ee.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,K=J(z);L[R][V]={distance:K,predecessor:R}})}),ee.forEach(function(R){var z=L[R];ee.forEach(function(V){var K=L[V];ee.forEach(function(ne){var Z=K[R],te=z[ne],ie=K[ne],ye=Z.distance+te.distance;ye<ie.distance&&(ie.distance=ye,ie.predecessor=te.predecessor)})})}),L}}),N=o((D,A)=>{function I(G){var U={},J={},B=[];function L(ee){if(Object.hasOwn(J,ee))throw new _;Object.hasOwn(U,ee)||(J[ee]=!0,U[ee]=!0,G.predecessors(ee).forEach(L),delete J[ee],B.push(ee))}if(G.sinks().forEach(L),Object.keys(U).length!==G.nodeCount())throw new _;return B}var _=class extends Error{constructor(){super(...arguments)}};A.exports=I,I.CycleException=_}),k=o((D,A)=>{var I=N();A.exports=_;function _(G){try{I(G)}catch(U){if(U instanceof I.CycleException)return!1;throw U}return!0}}),H=o((D,A)=>{A.exports=I;function I(G,U,J,B,L){Array.isArray(U)||(U=[U]);var ee=(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=_(G,z,J==="post",R,ee,B,L)}),L}function _(G,U,J,B,L,ee,R){return Object.hasOwn(B,U)||(B[U]=!0,J||(R=ee(R,U)),L(U).forEach(function(z){R=_(G,z,J,B,L,ee,R)}),J&&(R=ee(R,U))),R}}),M=o((D,A)=>{var I=H();A.exports=_;function _(G,U,J){return I(G,U,J,function(B,L){return B.push(L),B},[])}}),Y=o((D,A)=>{var I=M();A.exports=_;function _(G,U){return I(G,U,"post")}}),$=o((D,A)=>{var I=M();A.exports=_;function _(G,U){return I(G,U,"pre")}}),X=o((D,A)=>{var I=u(),_=b();A.exports=G;function G(U,J){var B=new I,L={},ee=new _,R;function z(K){var ne=K.v===R?K.w:K.v,Z=ee.priority(ne);if(Z!==void 0){var te=J(K);te<Z&&(L[ne]=R,ee.decrease(ne,te))}}if(U.nodeCount()===0)return B;U.nodes().forEach(function(K){ee.add(K,Number.POSITIVE_INFINITY),B.setNode(K)}),ee.decrease(U.nodes()[0],0);for(var V=!1;ee.size()>0;){if(R=ee.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,A)=>{var I=p(),_=x();A.exports=G;function G(J,B,L,ee){return U(J,B,L,ee||function(R){return J.outEdges(R)})}function U(J,B,L,ee){if(L===void 0)return I(J,B,L,ee);for(var R=!1,z=J.nodes(),V=0;V<z.length;V++){for(var K=ee(z[V]),ne=0;ne<K.length;ne++){var Z=K[ne],te=Z.v===z[V]?Z.v:Z.w,ie=te===Z.v?Z.w:Z.v;L({v:te,w:ie})<0&&(R=!0)}if(R)return _(J,B,L,ee)}return I(J,B,L,ee)}}),q=o((D,A)=>{A.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=Qt((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 l(u),u}enqueue(c){let u=this._sentinel;c._prev&&c._next&&l(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 l(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=Qt((e,r)=>{var s=ts().Graph,l=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 l),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}}),$n=Qt((e,r)=>{var s=ts().Graph;r.exports={addBorderNode:b,addDummyNode:l,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 l(P,q,F,D){for(var A=D;P.hasNode(A);)A=H(D);return F.dummy=q,P.setNode(A,F),A}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},A=P.edge(F);q.setEdge(F.v,F.w,{weight:D.weight+A.weight,minlen:Math.max(D.minlen,A.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(A=>{D[A.w]=(D[A.w]||0)+P.edge(A).weight}),D});return X(P.nodes(),q)}function f(P){let q=P.nodes().map(F=>{let D={};return P.inEdges(F).forEach(A=>{D[A.v]=(D[A.v]||0)+P.edge(A).weight}),D});return X(P.nodes(),q)}function m(P,q){let F=P.x,D=P.y,A=q.x-F,I=q.y-D,_=P.width/2,G=P.height/2;if(!A&&!I)throw new Error("Not possible to find intersection inside of the rectangle");let U,J;return Math.abs(I)*_>Math.abs(A)*G?(I<0&&(G=-G),U=G*A/I,J=G):(A<0&&(_=-_),U=_,J=_*I/A),{x:F+U,y:D+J}}function h(P){let q=M(T(P)+1).map(()=>[]);return P.nodes().forEach(F=>{let D=P.node(F),A=D.rank;A!==void 0&&(q[A][D.order]=F)}),q}function x(P){let q=P.nodes().map(D=>{let A=P.node(D).rank;return A===void 0?Number.MAX_VALUE:A}),F=S(Math.min,q);P.nodes().forEach(D=>{let A=P.node(D);Object.hasOwn(A,"rank")&&(A.rank-=F)})}function g(P){let q=P.nodes().map(_=>P.node(_).rank).filter(_=>_!==void 0),F=S(Math.min,q),D=[];P.nodes().forEach(_=>{let G=P.node(_).rank-F;D[G]||(D[G]=[]),D[G].push(_)});let A=0,I=P.graph().nodeRankFactor;Array.from(D).forEach((_,G)=>{_===void 0&&G%I!==0?--A:_!==void 0&&A&&_.forEach(U=>P.node(U).rank+=A)})}function b(P,q,F,D){let A={width:0,height:0};return arguments.length>=4&&(A.rank=F,A.order=D),l(P,"border",A,q)}function p(P,q=w){let F=[];for(let D=0;D<P.length;D+=q){let A=P.slice(D,D+q);F.push(A)}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 A=[];for(let I=P;D(I);I+=F)A.push(I);return A}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,[A,I])=>(D[A]=F(I,A),D),{})}function X(P,q){return P.reduce((F,D,A)=>(F[D]=q[A],F),{})}}),hz=Qt((e,r)=>{var s=fz(),l=$n().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,l("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=Qt((e,r)=>{var s=$n();r.exports={run:l,undo:c};function l(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)})}}),Lu=Qt((e,r)=>{var{applyWithChunking:s}=$n();r.exports={longestPath:l,slack:o};function l(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=Qt((e,r)=>{var s=ts().Graph,l=Lu().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)?l(m,b):-l(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)&&!l(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=l(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=Qt((e,r)=>{var s=sN(),l=Lu().slack,o=Lu().longestPath,c=ts().alg.preorder,u=ts().alg.postorder,f=$n().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,A=D?F.w:F.v;if(A!==$){var I=D===X,_=H.edge(F).weight;if(q+=I?_:-_,C(k,M,A)){var G=k.edge(M,A).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(A=>F===N(k,k.node(A.v),q)&&F!==N(k,k.node(A.w),q));return D.reduce((A,I)=>l(H,I)<l(H,A)?I:A)}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=Qt((e,r)=>{var s=Lu(),l=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=l;function m(x){l(x),o(x)}function h(x){c(x)}}),pz=Qt((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=l(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 l(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=Qt((e,r)=>{var s=$n();r.exports={run:l,cleanup:f};function l(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=Qt((e,r)=>{var s=$n();r.exports=l;function l(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=Qt((e,r)=>{r.exports={adjust:s,undo:l};function s(x){let g=x.graph().rankdir.toLowerCase();(g==="lr"||g==="rl")&&o(x)}function l(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=Qt((e,r)=>{var s=$n();r.exports=l;function l(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=Qt((e,r)=>{var s=$n().zipObject;r.exports=l;function l(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=Qt((e,r)=>{r.exports=s;function s(l,o=[]){return o.map(c=>{let u=l.inEdges(c);if(u.length){let f=u.reduce((m,h)=>{let x=l.edge(h),g=l.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=Qt((e,r)=>{var s=$n();r.exports=l;function l(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=Qt((e,r)=>{var s=$n();r.exports=l;function l(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=Qt((e,r)=>{var s=Nz(),l=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=l(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=Qt((e,r)=>{var s=ts().Graph,l=$n();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=l.uniqueId("_root")););return f}}),Tz=Qt((e,r)=>{r.exports=s;function s(l,o,c){let u={},f;c.forEach(m=>{let h=l.parent(m),x,g;for(;h;){if(x=l.parent(h),x?(g=u[x],u[x]=h):(g=f,f=h),g&&g!==h){o.setEdge(g,h);return}h=x}})}}),Az=Qt((e,r)=>{var s=jz(),l=wz(),o=Cz(),c=Ez(),u=Tz(),f=ts().Graph,m=$n();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 $=l(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))}}),_z=Qt((e,r)=>{var s=ts().Graph,l=$n();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 A=u(C,F),I=A?C.node(A).order:P;(A||F===q)&&(Y.slice(X,D+1).forEach(_=>{C.predecessors(_).forEach(G=>{let U=C.node(G),J=U.order;(J<$||I<J)&&!(U.dummy&&C.node(_).dummy)&&f(k,G,_)})}),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;l.range($,X).forEach(D=>{F=Y[D],C.node(F).dummy&&C.predecessors(F).forEach(A=>{let I=C.node(A);I.dummy&&(I.order<P||I.order>q)&&f(k,A,F)})})}function M(Y,$){let X=-1,P,q=0;return $.forEach((F,D)=>{if(C.node(F).dummy==="border"){let A=C.predecessors(F);A.length&&(P=C.node(A[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((A,I)=>$[A]-$[I]);let D=(F.length-1)/2;for(let A=Math.floor(D),I=Math.ceil(D);A<=I;++A){let _=F[A];Y[q]===q&&P<$[_]&&!m(k,q,_)&&(Y[_]=q,Y[q]=M[q]=M[_],P=$[_])}}})}),{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,A){let I=$.nodes().slice(),_={},G=I.pop();for(;G;){if(_[G])D(G);else{_[G]=!0,I.push(G);for(let U of A(G))I.push(U)}G=I.pop()}}function q(D){Y[D]=$.inEdges(D).reduce((A,I)=>Math.max(A,Y[I.v]+$.edge(I)),0)}function F(D){let A=$.outEdges(D).reduce((_,G)=>Math.min(_,Y[G.w]-$.edge(G)),Number.POSITIVE_INFINITY),I=C.node(D);A!==Number.POSITIVE_INFINITY&&I.borderType!==X&&(Y[D]=Math.max(Y[D],A))}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],A=M.edge(D,F);M.setEdge(D,F,Math.max($(C,q,P),A||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=l.applyWithChunking(Math.min,k),M=l.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-l.applyWithChunking(Math.min,q);$!=="l"&&(F=M-l.applyWithChunking(Math.max,q)),F&&(C[X]=l.mapValues(P,D=>D+F))})})}function w(C,N){return l.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=l.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=l.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=Qt((e,r)=>{var s=$n(),l=_z().positionX;r.exports=o;function o(u){u=s.asNonCompoundGraph(u),c(u),Object.entries(l(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=Qt((e,r)=>{var s=hz(),l=mz(),o=gz(),c=$n().normalizeRanks,u=pz(),f=$n().removeEmptyRanks,m=bz(),h=yz(),x=vz(),g=Az(),b=Mz(),p=$n(),w=ts().Graph;r.exports=S;function S(V,K={}){let ne=K.debugTiming?p.time:p.notime;return ne("layout",()=>{let Z=ne(" buildLayoutGraph",()=>P(V));return ne(" runLayout",()=>T(Z,ne,K)),ne(" updateInputGraph",()=>E(V,Z)),Z})}function T(V,K,ne){K(" makeSpaceForEdgeLabels",()=>q(V)),K(" removeSelfEdges",()=>B(V)),K(" acyclic",()=>s.run(V)),K(" nestingGraph.run",()=>m.run(V)),K(" rank",()=>o(p.asNonCompoundGraph(V))),K(" injectEdgeLabelProxies",()=>F(V)),K(" removeEmptyRanks",()=>f(V)),K(" nestingGraph.cleanup",()=>m.cleanup(V)),K(" normalizeRanks",()=>c(V)),K(" assignRankMinMax",()=>D(V)),K(" removeEdgeLabelProxies",()=>A(V)),K(" normalize.run",()=>l.run(V)),K(" parentDummyChains",()=>u(V)),K(" addBorderSegments",()=>h(V)),K(" order",()=>g(V,ne)),K(" insertSelfEdges",()=>L(V)),K(" adjustCoordinateSystem",()=>x.adjust(V)),K(" position",()=>b(V)),K(" positionSelfEdges",()=>ee(V)),K(" removeBorderNodes",()=>J(V)),K(" normalize.undo",()=>l.undo(V)),K(" fixupEdgeLabelCoords",()=>G(V)),K(" undoCoordinateSystem",()=>x.undo(V)),K(" translateGraph",()=>I(V)),K(" assignNodeIntersects",()=>_(V)),K(" reversePoints",()=>U(V)),K(" acyclic.undo",()=>s.undo(V))}function E(V,K){V.nodes().forEach(ne=>{let Z=V.node(ne),te=K.node(ne);Z&&(Z.x=te.x,Z.y=te.y,Z.order=te.order,Z.rank=te.rank,K.children(ne).length&&(Z.width=te.width,Z.height=te.height))}),V.edges().forEach(ne=>{let Z=V.edge(ne),te=K.edge(ne);Z.points=te.points,Object.hasOwn(te,"x")&&(Z.x=te.x,Z.y=te.y)}),V.graph().width=K.graph().width,V.graph().height=K.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 K=new w({multigraph:!0,compound:!0}),ne=z(V.graph());return K.setGraph(Object.assign({},N,R(ne,C),p.pick(ne,k))),V.nodes().forEach(Z=>{let te=z(V.node(Z)),ie=R(te,H);Object.keys(M).forEach(ye=>{ie[ye]===void 0&&(ie[ye]=M[ye])}),K.setNode(Z,ie),K.setParent(Z,V.parent(Z))}),V.edges().forEach(Z=>{let te=z(V.edge(Z));K.setEdge(Z,Object.assign({},$,R(te,Y),p.pick(te,X)))}),K}function q(V){let K=V.graph();K.ranksep/=2,V.edges().forEach(ne=>{let Z=V.edge(ne);Z.minlen*=2,Z.labelpos.toLowerCase()!=="c"&&(K.rankdir==="TB"||K.rankdir==="BT"?Z.width+=Z.labeloffset:Z.height+=Z.labeloffset)})}function F(V){V.edges().forEach(K=>{let ne=V.edge(K);if(ne.width&&ne.height){let Z=V.node(K.v),te={rank:(V.node(K.w).rank-Z.rank)/2+Z.rank,e:K};p.addDummyNode(V,"edge-proxy",te,"_ep")}})}function D(V){let K=0;V.nodes().forEach(ne=>{let Z=V.node(ne);Z.borderTop&&(Z.minRank=V.node(Z.borderTop).rank,Z.maxRank=V.node(Z.borderBottom).rank,K=Math.max(K,Z.maxRank))}),V.graph().maxRank=K}function A(V){V.nodes().forEach(K=>{let ne=V.node(K);ne.dummy==="edge-proxy"&&(V.edge(ne.e).labelRank=ne.rank,V.removeNode(K))})}function I(V){let K=Number.POSITIVE_INFINITY,ne=0,Z=Number.POSITIVE_INFINITY,te=0,ie=V.graph(),ye=ie.marginx||0,ke=ie.marginy||0;function Me(Ie){let Le=Ie.x,Qe=Ie.y,Ae=Ie.width,Ge=Ie.height;K=Math.min(K,Le-Ae/2),ne=Math.max(ne,Le+Ae/2),Z=Math.min(Z,Qe-Ge/2),te=Math.max(te,Qe+Ge/2)}V.nodes().forEach(Ie=>Me(V.node(Ie))),V.edges().forEach(Ie=>{let Le=V.edge(Ie);Object.hasOwn(Le,"x")&&Me(Le)}),K-=ye,Z-=ke,V.nodes().forEach(Ie=>{let Le=V.node(Ie);Le.x-=K,Le.y-=Z}),V.edges().forEach(Ie=>{let Le=V.edge(Ie);Le.points.forEach(Qe=>{Qe.x-=K,Qe.y-=Z}),Object.hasOwn(Le,"x")&&(Le.x-=K),Object.hasOwn(Le,"y")&&(Le.y-=Z)}),ie.width=ne-K+ye,ie.height=te-Z+ke}function _(V){V.edges().forEach(K=>{let ne=V.edge(K),Z=V.node(K.v),te=V.node(K.w),ie,ye;ne.points?(ie=ne.points[0],ye=ne.points[ne.points.length-1]):(ne.points=[],ie=te,ye=Z),ne.points.unshift(p.intersectRect(Z,ie)),ne.points.push(p.intersectRect(te,ye))})}function G(V){V.edges().forEach(K=>{let ne=V.edge(K);if(Object.hasOwn(ne,"x"))switch((ne.labelpos==="l"||ne.labelpos==="r")&&(ne.width-=ne.labeloffset),ne.labelpos){case"l":ne.x-=ne.width/2+ne.labeloffset;break;case"r":ne.x+=ne.width/2+ne.labeloffset;break}})}function U(V){V.edges().forEach(K=>{let ne=V.edge(K);ne.reversed&&ne.points.reverse()})}function J(V){V.nodes().forEach(K=>{if(V.children(K).length){let ne=V.node(K),Z=V.node(ne.borderTop),te=V.node(ne.borderBottom),ie=V.node(ne.borderLeft[ne.borderLeft.length-1]),ye=V.node(ne.borderRight[ne.borderRight.length-1]);ne.width=Math.abs(ye.x-ie.x),ne.height=Math.abs(te.y-Z.y),ne.x=ie.x+ne.width/2,ne.y=Z.y+ne.height/2}}),V.nodes().forEach(K=>{V.node(K).dummy==="border"&&V.removeNode(K)})}function B(V){V.edges().forEach(K=>{if(K.v===K.w){var ne=V.node(K.v);ne.selfEdges||(ne.selfEdges=[]),ne.selfEdges.push({e:K,label:V.edge(K)}),V.removeEdge(K)}})}function L(V){var K=p.buildLayerMatrix(V);K.forEach(ne=>{var Z=0;ne.forEach((te,ie)=>{var ye=V.node(te);ye.order=ie+Z,(ye.selfEdges||[]).forEach(ke=>{p.addDummyNode(V,"selfedge",{width:ke.label.width,height:ke.label.height,rank:ye.rank,order:ie+ ++Z,e:ke.e,label:ke.label},"_se")}),delete ye.selfEdges})})}function ee(V){V.nodes().forEach(K=>{var ne=V.node(K);if(ne.dummy==="selfedge"){var Z=V.node(ne.e.v),te=Z.x+Z.width/2,ie=Z.y,ye=ne.x-te,ke=Z.height/2;V.setEdge(ne.e,ne.label),V.removeNode(K),ne.label.points=[{x:te+2*ye/3,y:ie-ke},{x:te+5*ye/6,y:ie-ke},{x:te+ye,y:ie},{x:te+5*ye/6,y:ie+ke},{x:te+2*ye/3,y:ie+ke}],ne.label.x=ne.x,ne.label.y=ne.y}})}function R(V,K){return p.mapValues(p.pick(V,K),Number)}function z(V){var K={};return V&&Object.entries(V).forEach(([ne,Z])=>{typeof ne=="string"&&(ne=ne.toLowerCase()),K[ne]=Z}),K}}),Oz=Qt((e,r)=>{var s=$n(),l=ts().Graph;r.exports={debugOrdering:o};function o(c){let u=s.buildLayerMatrix(c),f=new l({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=Qt((e,r)=>{r.exports="2.0.4"}),zz=Qt((e,r)=>{r.exports={graphlib:ts(),layout:Dz(),debug:Oz(),util:{time:$n().time,notime:$n().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,l=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?`${l.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${l.bg} ${l.border}`}`,children:[t.jsx(wa,{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 ${l.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(wa,{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(wa,{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(wa,{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 Cm=200,Em=80;function Tv(e,r,s="TB"){const l=new kv.graphlib.Graph;l.setDefaultEdgeLabel(()=>({})),l.setGraph({rankdir:s,nodesep:40,ranksep:60});for(const o of e)l.setNode(o.id,{width:Cm,height:Em});for(const o of r)l.setEdge(o.source,o.target);return kv.layout(l),e.map(o=>{const c=l.node(o.id);return{...o,position:{x:(c?.x??0)-Cm/2,y:(c?.y??0)-Em/2}}})}function qz(e,r){const s=new Map,l=new Map;for(const u of e)l.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 l=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+Cm),S=Math.min(S,E.position.y),T=Math.max(T,E.position.y+Em);for(const E of b)E.position.x-=p,E.position.y-=S;return{nodes:b,w:w-p,h:T-S}});l.sort((g,b)=>b.h-g.h);const o=60,c=l.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 l){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 l=new Set,o=[r];for(;o.length>0;){const c=o.pop();if(c===s)return!0;if(l.has(c))continue;l.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"}}],Fh=new Set(oo.map(e=>e.id)),Yz=1440*60*1e3,Av=e=>e.status==="completed"&&e.updatedAt&&Date.now()-new Date(e.updatedAt).getTime()>Yz;function Gz({tasks:e,requirements:r=[],agents:s,showArchived:l,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(Fh)),[S,T]=j.useState(l??!1),E=l??S,C=j.useCallback(Z=>{const te=typeof Z=="function"?Z(E):Z;T(te),o?.(te)},[E,o]);j.useEffect(()=>{l!==void 0&&T(l)},[l]);const N=j.useMemo(()=>e.filter(Z=>Av(Z)).length,[e]),k=j.useMemo(()=>{const Z=new Set;for(const te of oo)if(p.has(te.id))for(const ie of te.statuses)Z.add(ie);return Z},[p]),H=j.useMemo(()=>{const Z=new Set;for(const te of e)for(const ie of oo)if(ie.statuses.has(te.status)){Z.add(ie.id);break}for(const te of r){const ie=Ev[te.status];ie&&Z.add(ie)}return oo.filter(te=>Z.has(te.id))},[e,r]),M=j.useCallback(Z=>{w(te=>{const ie=new Set(te);return ie.has(Z)?ie.delete(Z):ie.add(Z),ie})},[]),Y=j.useCallback((Z,te="success")=>{x({msg:Z,type:te}),setTimeout(()=>x(null),2500)},[]),$=j.useMemo(()=>{const Z=new Map;for(const te of s)Z.set(te.id,te.name);return Z},[s]),X=j.useMemo(()=>{const Z=new Map;for(const te of e)Z.set(te.id,te);return Z},[e]),P=j.useMemo(()=>{const Z=new Map;for(const te of r)Z.set(te.id,te);return Z},[r]),q=m?"#94a3b8":"#6b7280",F=j.useCallback((Z,te,ie)=>({id:`${Z}->${te}`,source:Z,target:te,animated:ie==="blocked",markerEnd:{type:Xl.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:A}=j.useMemo(()=>{const Z=e.filter(Ae=>k.has(Ae.status)&&(E||!Av(Ae))),te=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(te.map(Ae=>Ae.id)),ye=new Set;for(const Ae of oo)p.has(Ae.id)&&ye.add(Ae.id);const ke=r.filter(Ae=>{const Ge=Ev[Ae.status];return Ge&&ye.has(Ge)});for(const Ae of ke){const Ge=`req-${Ae.id}`;te.push({id:Ge,type:"requirement",data:{req:Ae},position:{x:0,y:0}}),ie.add(Ge)}const Me=[];for(const Ae of Z)if(Ae.blockedBy)for(const Ge of Ae.blockedBy)ie.has(Ge)&&Me.push(F(Ge,Ae.id,Ae.status));const Ie=new Set,Le=(Ae,Ge)=>{const ut=`${Ae}->${Ge}`;Ie.has(ut)||(Ie.add(ut),Me.push({id:ut,source:Ae,target:Ge,markerEnd:{type:Xl.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ae of ke){const Ge=`req-${Ae.id}`;for(const ut of Ae.taskIds)ie.has(ut)&&Le(Ge,ut)}for(const Ae of Z)if(Ae.requirementId){const Ge=`req-${Ae.requirementId}`;ie.has(Ge)&&Le(Ge,Ae.id)}return{initialNodes:Vz(te,Me),initialEdges:Me}},[e,r,$,X,F,k,p,E]),[I,_,G]=zR(D),[U,J,B]=LR(A),L=j.useRef(null);j.useEffect(()=>{_(D),J(A),requestAnimationFrame(()=>{L.current?.fitView({padding:.2,duration:300})})},[D,A,_,J]);const ee=j.useCallback((Z,te)=>{if(te.id.startsWith("req-")){const ie=P.get(te.id.slice(4));ie&&u&&u(ie)}else{const ie=X.get(te.id);ie&&c&&c(ie)}},[X,P,c,u]),R=j.useCallback(async Z=>{const{source:te,target:ie}=Z;if(!te||!ie||te===ie)return;const ye=X.get(ie);if(!ye)return;if(ye.blockedBy?.includes(te)){Y("Dependency already exists","error");return}if(Fz(X,te,ie)){Y("Cannot add: would create a cycle","error");return}const ke=[...ye.blockedBy??[],te];try{await le.tasks.update(ie,{blockedBy:ke}),Y("Dependency added"),f?.()}catch(Me){Y(`Failed: ${Me instanceof Error?Me.message:String(Me)}`,"error")}},[X,Y,f]),z=j.useCallback((Z,te)=>{b(te)},[]),V=j.useCallback(async()=>{if(!g)return;const Z=X.get(g.target);if(!Z){b(null);return}const te=(Z.blockedBy??[]).filter(ie=>ie!==g.source);try{await le.tasks.update(g.target,{blockedBy:te}),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 K=g?X.get(g.source):null,ne=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:ee,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(iz,{nodeColor:Z=>{const te=Z.data?.task,ie=te?.status;return te?.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 te=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 ${te?`${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<Fh.size&&t.jsx("button",{onClick:()=>{w(new Set(Fh)),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:ne?.title??g.target.slice(-8)})," ","will no longer be blocked by"," ",t.jsx("span",{className:"text-fg-secondary font-medium",children:K?.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[l,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=xs();j.useEffect(()=>{le.teams.list().then($=>w($.teams)).catch(()=>{})},[]);const M=j.useCallback(async $=>{if($?.preventDefault(),k(!0),!(!l.trim()||S)){T(!0),C("");try{const X=f.trim()?[{url:f.trim(),defaultBranch:h.trim()||"main"}]:[],P=await le.projects.create({name:l.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)}},[l,c,f,h,g,e,S,r]),Y=N&&!l.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:l,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:!l.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 Wl(e,r,s){if(!e)return null;const l=r.find(c=>c.id===e);if(l)return l.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:l}){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:l}):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:l??"Click to edit"})})}function Zz({value:e,onSave:r,className:s,placeholder:l}){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:l,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:l??"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"},lN={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"}},Tm={urgent:"border-l-red-500",high:"border-l-amber-500",medium:"border-l-blue-500",low:"border-l-gray-500"},iN={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"},_v=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,l)=>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"},l):null)]})});function Wz(e){return e.kind==="log"?e.executionRound??1:0}function eL(e){const r=[];let s=null,l=[],o=1;for(const c of e){if(c.kind==="comment"){s?s.items.push(c):l.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:[...l]},l=[],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")),l.length>0&&r.length>0&&r[r.length-1].items.push(...l),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:[...l,...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 l=Math.floor(s/1e3);if(l<60)return`${l}s`;const o=Math.floor(l/60);return o<60?`${o}m ${l%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:l,isLive:o,streamingText:c,isExecuting:u,totalRounds:f}){const m=Mv[r.status]??Mv.running,h=tL(r.startTime,r.endTime),x=Km(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(_v,{comment:p.entry},`pc-${p.entry.id}`):null)}),t.jsxs("button",{onClick:l,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(_v,{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(wu,{label:"Thinking"})]})]})});function rL({taskId:e,isVisible:r,isRunning:s,authUser:l}){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 K=V,ne=()=>{F.current=K.scrollHeight-K.scrollTop-K.clientHeight<80};return K.addEventListener("scroll",ne,{passive:!0}),()=>K.removeEventListener("scroll",ne)},[]),j.useEffect(()=>{g(s)},[s]),j.useEffect(()=>{p(!0),Promise.all([le.tasks.getLogs(e).catch(()=>({logs:[]})),le.tasks.getComments(e).catch(()=>({comments:[]}))]).then(([z,V])=>{c(z.logs),f(V.comments),p(!1)})},[e]),j.useEffect(()=>{const z=Sn.on("task:log",ne=>{const Z=ne.payload;if(Z.taskId!==e)return;const te={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=>te.id&&ie.some(ye=>ye.id===te.id)||!te.id&&ie.some(ye=>ye.seq===te.seq&&ye.type===te.type)?ie:[...ie,te]),te.type==="text"&&h(""),te.type==="status"&&(te.content==="started"||te.content==="resumed"?g(!0):["completed","failed","cancelled","execution_finished"].includes(te.content)&&g(!1)),te.type==="error"&&g(!1)}),V=Sn.on("task:log:delta",ne=>{const Z=ne.payload;Z.taskId===e&&h(te=>te+Z.text)}),K=Sn.on("task:comment",ne=>{const Z=ne.payload;if(Z.taskId!==e)return;const te=Z.comment;f(ie=>ie.some(ye=>ye.id===te.id)?ie:[...ie,te])});return()=>{z(),V(),K()}},[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]),A=j.useMemo(()=>{const z=o.map(Z=>({log:Z,entry:Jm(Z)})).filter(Z=>Z.entry!=null),V=bo(z.map(Z=>Z.entry)),K=new Set(V),ne=[...z.filter(Z=>K.has(Z.entry)).map(({log:Z,entry:te})=>({kind:"log",entry:te,time:new Date(te.timestamp??te.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 ne.sort((Z,te)=>Z.time-te.time),ne},[o,u,D]),I=j.useMemo(()=>eL(A),[A]);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 _=j.useCallback(z=>{H(V=>{const K=new Set(V);return K.has(z)?K.delete(z):K.add(z),K})},[]),G=z=>{const V=z.target.files;if(V){for(const K of Array.from(V)){if(!K.type.startsWith("image/"))continue;const ne=new FileReader;ne.onload=()=>{N(Z=>[...Z,{type:"image",url:ne.result,name:K.name}])},ne.readAsDataURL(K)}z.target.value=""}},U=async()=>{if(!(!w.trim()&&C.length===0)){E(!0);try{const z=await le.tasks.addComment(e,w,l?.name,C.length>0?C:void 0,l?.id);z.comment&&f(V=>V.some(K=>K.id===z.comment.id)?V:[...V,z.comment]),S(""),N([])}catch{}E(!1)}},J=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(K=>K.filter((ne,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.']})]})}),J]});const B=Math.ceil(I.length/$),L=M*$,ee=(M-1)*$,R=I.slice(Math.max(0,I.length-L),I.length-ee).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:()=>_(z.id),isLive:V&&x,streamingText:V?m:void 0,isExecuting:V?x:!1,totalRounds:I.length},z.id)}),t.jsx("div",{ref:q})]}),J]})}function sL({filePath:e,onClose:r}){const[s,l]=j.useState(null),[o,c]=j.useState(null),[u,f]=j.useState(!0);j.useEffect(()=>{f(!0),c(null),le.files.preview(e).then(h=>l(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:l,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,A]=j.useState(!1),[I,_]=j.useState(e.description),[G,U]=j.useState(!1),[J,B]=j.useState(""),[L,ee]=j.useState(1),[R,z]=j.useState(1),[V,K]=j.useState(!1),ne=xs(),Z=20,te=j.useCallback(async()=>{try{const he=await le.tasks.listSubtasks(e.id);x(he.subtasks)}catch{}},[e.id]);j.useEffect(()=>{te()},[te]);const ie=async he=>{if(!N){k(!0);try{await he(),f(),await te()}catch($e){P(String($e).replace("Error: ",""))}finally{k(!1)}}},ye=he=>ie(()=>le.tasks.update(e.id,{priority:he})),ke=he=>ie(()=>le.tasks.assign(e.id,he||null)),Me=he=>ie(()=>le.tasks.update(e.id,{projectId:he||null})),Ie=async()=>{if(!N){k(!0);try{await le.tasks.pause(e.id),f()}finally{k(!1)}}},Le=async()=>{if(!Y){$(!0),P(null),M("logs");try{await le.tasks.resume(e.id),f()}catch(he){P(String(he).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{$(!1)}}},Qe=async()=>{g.trim()&&(await le.tasks.createSubtask(e.id,g.trim()),b(""),w(!1),te(),f())},Ae=async he=>{he.status==="completed"?await le.tasks.cancelSubtask(e.id,he.id):await le.tasks.completeSubtask(e.id,he.id),te(),f()},Ge=async he=>{await le.tasks.deleteSubtask(e.id,he.id),T(null),te(),f()},ut=async()=>{if(!N){k(!0);try{await le.tasks.updateStatus(e.id,"pending_approval"),f()}finally{k(!1)}}},_t=async()=>{if(!N){k(!0),P(null),M("logs");try{await le.tasks.retry(e.id),f()}catch(he){P(String(he).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{k(!1)}}},oe=async()=>{if(!Y){$(!0),P(null),M("logs");try{await le.tasks.runNow(e.id),f()}catch(he){P(String(he).replace("Error: API error: 400","Server error").replace("Error: ","")),f()}finally{$(!1)}}};j.useEffect(()=>Sn.on("task:log:delta",$e=>{$e.payload.taskId===e.id&&M("logs")}),[e.id]);const Oe=j.useRef(f);Oe.current=f,j.useEffect(()=>Sn.on("task:update",$e=>{$e.payload.taskId===e.id&&(te(),Oe.current())}),[e.id,te]);const xt=h.filter(he=>he.status==="completed").length,vt=e.status==="in_progress",Gt=e.status==="blocked",ve=e.status==="completed",De=e.status==="failed",He=e.status==="cancelled",Ye=e.status==="archived",tt=ve||De||He||Ye,Dt=e.taskType==="scheduled"&&!!e.scheduleConfig,$t=Dt&&!!e.scheduleConfig?.paused,bt=s.find(he=>he.id===e.projectId),yt=l.find(he=>he.id===e.requirementId);return r.find(he=>he.id===e.assignedAgentId),t.jsxs("div",{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3 ${ne?"pb-[4.5rem]":""}`,onClick:u,children:[t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl flex flex-col shadow-2xl ${ne?"w-full max-h-full":"w-[780px] max-w-[95vw] max-h-[88vh]"}`,onClick:he=>he.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 he=Jz[e.status];return he?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap ${he.cls}`,children:he.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:he=>_(he.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:()=>{A(!1),_(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(()=>le.tasks.update(e.id,{description:I})),A(!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:ne&&!V?"line-clamp-3":"",children:t.jsx(er,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),ne&&e.description.length>150&&t.jsx("button",{onClick:()=>K(!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:()=>{_(e.description),A(!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"})]})}),(bt||yt)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[bt&&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"}),bt.name]}),yt&&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"}),yt.title.length>40?yt.title.slice(0,40)+"…":yt.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(he=>{const $e=o.find(dt=>dt.id===he),ht=$e&&($e.status==="completed"||$e.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${ht?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:ht?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${ht?"line-through opacity-60":""}`,children:$e?$e.title.slice(0,30):he.slice(-8)}),!tt&&t.jsx("button",{onClick:async()=>{const dt=(e.blockedBy??[]).filter(gt=>gt!==he);await le.tasks.update(e.id,{blockedBy:dt}),f()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:"Remove dependency",children:"×"})]},he)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:"No dependencies"}),!tt&&t.jsxs("select",{value:"",onChange:async he=>{const $e=he.target.value;if(!$e)return;const ht=[...e.blockedBy??[],$e];await le.tasks.update(e.id,{blockedBy:ht}),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(he=>he.id!==e.id&&!(e.blockedBy??[]).includes(he.id)).map(he=>t.jsx("option",{value:he.id,children:he.title},he.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",vt&&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 he=(e.deliverables??[]).filter($e=>$e.type!=="branch"&&typeof $e.reference=="string"&&$e.reference.length>0).length;return he>0?t.jsx("span",{className:"text-[10px] text-fg-tertiary font-normal",children:he}):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:he=>{Me(he.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(he=>t.jsx("option",{value:he.id,children:he.name},he.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:he=>ie(()=>le.tasks.update(e.id,{requirementId:he.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"}),l.filter(he=>!e.projectId||he.projectId===e.projectId).map(he=>t.jsx("option",{value:he.id,children:he.title},he.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:he=>{ke(he.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(he=>t.jsxs("option",{value:he.id,children:[he.name," (",he.status,")"]},he.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:he=>{he.target.value&&he.target.value!==e.reviewerAgentId&&ie(()=>le.tasks.update(e.id,{reviewerAgentId:he.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(he=>t.jsx("option",{value:he.id,children:he.name},he.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:he=>{ye(he.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:Wl(e.createdBy,r,c)??e.createdBy})]}),e.updatedBy&&t.jsxs("span",{children:["Updated by ",t.jsx("span",{className:"text-fg-secondary",children:Wl(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:[xt,"/",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(he=>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(he)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${he.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:he.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 ${he.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:he.title}),t.jsx("button",{onClick:()=>T(he),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},he.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:he=>b(he.target.value),onKeyDown:he=>{he.key==="Enter"&&Qe(),he.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:()=>{Qe()},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 he=(e.deliverables??[]).filter(dt=>dt.type!=="branch"&&typeof dt.reference=="string"&&dt.reference.length>0);if(he.length===0)return null;const $e={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"},ht=he.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:["(",he.length,")"]})]}),he.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:ht.map((dt,gt)=>{const jt=dt.reference.split("/").pop()??dt.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 ${$e[dt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:dt.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>F(dt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:dt.reference,children:jt}),dt.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:dt.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:dt.reference})]})]},gt)})})]})})(),e.notes&&e.notes.length>0&&(()=>{const he=[...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:he.map(($e,ht)=>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:$e,className:"text-xs text-fg-secondary"})},ht))})]})})()]})]}),H==="notes"&&t.jsx("div",{className:"px-6 py-4",children:e.notes&&e.notes.length>0?(()=>{const he=[...e.notes].reverse(),$e=Math.ceil(he.length/Z),ht=he.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,")"]})]}),$e>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(dt=>dt-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,"/",$e]}),t.jsx("button",{disabled:R>=$e,onClick:()=>z(dt=>dt+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:ht.map((dt,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:dt,className:"text-xs text-fg-secondary"})},gt))})]})})():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 he=(e.deliverables??[]).filter(gt=>gt.type!=="branch"&&typeof gt.reference=="string"&&gt.reference.length>0);if(he.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:"No deliverables yet."});const $e={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"},ht=Math.ceil(he.length/Z),dt=he.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:["(",he.length,")"]})]}),ht>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:L<=1,onClick:()=>ee(gt=>gt-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,"/",ht]}),t.jsx("button",{disabled:L>=ht,onClick:()=>ee(gt=>gt+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:dt.map((gt,jt)=>{const en=gt.reference.split("/").pop()??gt.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 ${$e[gt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:gt.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>F(gt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:gt.reference,children:en}),gt.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:gt.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:gt.reference})]})]},jt)})})]})})()})]}),Dt&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${$t?"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:$t?"text-amber-600":"text-brand-500",children:$t?"⏸ 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"}),!$t&&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 he=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(he<=0)return"due now";const $e=Math.floor(he/6e4);if($e<60)return`in ${$e}m`;const ht=Math.floor($e/60);return ht<24?`in ${ht}h ${$e%60}m`:`in ${Math.floor(ht/24)}d ${ht%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 he=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),$e=Math.floor(he/6e4);if($e<1)return"just now";if($e<60)return`${$e}m ago`;const ht=Math.floor($e/60);return ht<24?`${ht}h ${$e%60}m ago`:`${Math.floor(ht/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(()=>le.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(()=>le.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(()=>le.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:J,onChange:he=>B(he.target.value),onKeyDown:he=>{he.key==="Enter"&&J.trim()&&(ie(()=>le.tasks.revision(e.id,J.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(()=>le.tasks.revision(e.id,J.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"})]}),vt&&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:()=>{_t()},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"]})]}),Gt&&t.jsx("button",{onClick:()=>{Le()},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"]})}),De&&t.jsxs("button",{onClick:()=>{_t()},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"]}),Dt&&(ve||De)&&t.jsx("button",{onClick:()=>{oe()},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"]})}),Dt&&!vt&&($t?t.jsx("button",{onClick:()=>{ie(()=>le.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(()=>le.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"})),ve&&t.jsx("button",{onClick:()=>ie(()=>le.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"}),tt&&t.jsx("button",{onClick:()=>{ut()},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"}),!tt&&e.status!=="pending_approval"&&t.jsx("button",{onClick:async()=>{const{count:he}=await le.tasks.getDependentCount(e.id);he>0?C({dependentCount:he}):ie(()=>le.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:()=>{Ge(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:he=>he.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(()=>le.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(()=>le.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 lL({project:e,tasks:r,requirements:s,agents:l,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(()=>l.filter(b=>x.has(b.id)),[l,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 Iu={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"},iL={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 l=Math.floor(s/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function Ov({row:e,idx:r,dragIdx:s,agentMap:l,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"?l.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:Iu[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 ${iN[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:l,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 A=new Date(F.data.updatedAt??0).getTime();return new Date(D.data.updatedAt??0).getTime()-A});else{const F=D=>iL[D.data.priority]??2;q.sort((D,A)=>{const I=F(D),_=F(A);return I!==_?I-_:new Date(A.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 le.tasks.updateStatus(q.data.id,F):await le.requirements.updateStatus(q.data.id,F),u()}catch{}},S=async(q,F)=>{try{q.kind==="task"?await le.tasks.update(q.data.id,{priority:F}):await le.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 A=To.find(I=>I.id===F);if(A){try{if(D.kind==="task"){if(D.data.status==="pending_approval")return;await le.tasks.updateStatus(D.data.id,A.dropStatus)}else{const I=cN[F];I&&await le.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(l.map(q=>[q.id,q])),[l]),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 A=p[D];F.set(A,D);const I=q.get(A.group)??[];I.push(A),q.set(A.group,I)}return{rowsByGroup:q,rowIndexMap:F}},[p]),P=j.useMemo(()=>{if(f!=="status")return null;const q=new Set(p.map(A=>A.group)),F=[],D=new Set;q.has("failed")&&(F.push("failed"),D.add("failed"));for(const A of M)F.push(A),D.add(A);for(const A of p)D.has(A.group)||(F.push(A.group),D.add(A.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(A=>A.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:A=>C(A,q),onDragLeave:()=>b(null),onDrop:A=>{N(A,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(A=>t.jsx(Ov,{row:A,idx:X.get(A)??0,dragIdx:h,agentMap:k,projMap:H,onTaskClick:o,onReqClick:c,onRowDragStart:T,onRowDragEnd:E,handleStatusChange:w,handlePriorityChange:S},`${A.kind}-${A.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=xs(),[s,l]=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(()=>{jt(u??""),$t(!0)},[u]),[Y,$]=j.useState(!1),[X,P]=j.useState(!1),[q,F]=j.useState(""),[D,A]=j.useState(""),[I,_]=j.useState("medium"),[G,U]=j.useState(""),[J,B]=j.useState(""),[L,ee]=j.useState(""),[R,z]=j.useState(""),[V,K]=j.useState([]),[ne,Z]=j.useState("standard"),[te,ie]=j.useState("4h"),[ye,ke]=j.useState(null),[Me,Ie]=j.useState(null),[Le,Qe]=j.useState(new Set),[Ae,Ge]=j.useState(new Set),ut=j.useRef(new Set),_t=j.useRef(new Set),[oe,Oe]=j.useState(null),[xt,vt]=j.useState("backlog"),[Gt,ve]=j.useState(!1),[De,He]=j.useState(!1),Ye=j.useRef(null),tt=j.useRef(null),[Dt,$t]=j.useState(!1),[bt,yt]=j.useState(""),[he,$e]=j.useState(""),[ht,dt]=j.useState("medium"),[gt,jt]=j.useState(""),[en,hn]=j.useState(null),[sn,bn]=j.useState(""),Nt=se=>{N(se),setTimeout(()=>N(""),3e3)},Q=s.find(se=>se.id===u)??null;j.useEffect(()=>{_t.current=Ae},[Ae]);const ue=j.useCallback(async()=>{try{const{projects:se}=await le.projects.list();l(se)}catch{}},[]),Se=j.useCallback(async()=>{const se={};o==="project"&&u&&(se.projectId=u);try{const{board:Re}=await le.tasks.board(se);h(Re)}catch{}},[o,u]),qe=j.useCallback(async()=>{try{const{agents:se}=await le.agents.list();g(se)}catch{}},[]),et=j.useCallback(async()=>{try{const{users:se}=await le.users.list(e?.orgId);p(se)}catch{}},[e?.orgId]),Ue=j.useCallback(async()=>{try{const{requirements:se}=await le.requirements.list({});S(se)}catch{}},[]),yn=j.useCallback(async()=>{await Promise.all([ue(),Se(),qe(),et(),Ue()]),E(!1)},[ue,Se,qe,et,Ue]);j.useEffect(()=>{yn()},[yn]);const mn=j.useRef(ye);mn.current=ye,j.useEffect(()=>{const Re=setInterval(()=>{Se(),qe(),Ue()},ye?6e4:15e3),Pe=Sn.on("task:update",re=>{mn.current||(Se(),Ue());const pe=re?.payload;pe?.taskId&&ke(we=>{if(!we||we.id!==pe.taskId)return we;const Ee={};return typeof pe.status=="string"&&(Ee.status=pe.status),Array.isArray(pe.deliverables)&&(Ee.deliverables=pe.deliverables),Array.isArray(pe.notes)&&(Ee.notes=pe.notes),pe.result!==void 0&&(Ee.result=pe.result),{...we,...Ee}})});return()=>{clearInterval(Re),Pe()}},[Se,qe,Ue,ye]);const Mt=j.useRef(m);Mt.current=m,j.useEffect(()=>{const se=localStorage.getItem("markus_nav_openTask");if(!se)return;const Pe=Object.values(m).flat().find(re=>re.id===se);Pe&&(ke(Pe),localStorage.removeItem("markus_nav_openTask"))},[m]),j.useEffect(()=>{const se=window.location.hash.slice(1).split("/");if(se[0]==="projects"&&se[1])_n(se[1]);else{const Re=localStorage.getItem("markus_nav_projectId");Re&&(localStorage.removeItem("markus_nav_projectId"),_n(Re))}},[]),j.useEffect(()=>{const se=()=>{const Pe=window.location.hash.slice(1).split("/");Pe[0]==="projects"&&Pe[1]?_n(Pe[1]):Pe[0]==="projects"&&Hn()},Re=Pe=>{const re=Pe.detail;if(re.page==="tasks"||re.page==="projects"){if(re.params?.openTask){const we=Object.values(Mt.current).flat().find(Ee=>Ee.id===re.params.openTask);we&&ke(we)}re.params?.projectId&&_n(re.params.projectId),!re.params?.projectId&&!re.params?.openTask&&Hn()}};return window.addEventListener("markus:navigate",Re),window.addEventListener("hashchange",se),()=>{window.removeEventListener("markus:navigate",Re),window.removeEventListener("hashchange",se)}},[]);const _n=se=>{_t.current.size>0&&(ut.current=new Set(_t.current)),Ge(new Set),f(se),c("project"),H(!1),history.replaceState(null,"","#projects/"+se)},Hn=()=>{Ge(ut.current),f(null),c("all"),H(!1),history.replaceState(null,"","#projects")},Mn=()=>{$(!1),Nt("Project created"),ue()},an=async se=>{if(confirm("Delete this project and unlink all its tasks?"))try{await le.projects.delete(se),u===se&&Hn(),Nt("Project deleted"),ue(),Se()}catch(Re){Nt(`Error: ${Re}`)}},ln=async()=>{if(!q||!G||!J)return;if(G===J){Nt("Assigned agent and reviewer must be different");return}const se=L||void 0,Re=R||void 0;try{await le.tasks.create(q,D,G,J,I,se,V.length>0?V:void 0,Re,ne!=="standard"?ne:void 0,ne==="scheduled"?{every:te}:void 0),F(""),A(""),K([]),z(""),Z("standard"),ie("4h"),P(!1),Se()}catch(Pe){Nt(`Error creating task: ${Pe}`)}},vn=()=>{Se(),ye&&setTimeout(()=>{const se={};o==="project"&&u&&(se.projectId=u),le.tasks.board(se).then(Re=>{const re=Object.values(Re.board).flat().find(pe=>pe.id===ye.id);ke(re||null)}).catch(()=>{})},150)},Pn=async()=>{if(bt.trim()){if(!gt){Nt("Please select a project for this requirement");return}try{await le.requirements.create({title:bt,description:he,priority:ht,projectId:gt}),Nt("Requirement created"),yt(""),$e(""),$t(!1),Ue()}catch(se){Nt(`Error: ${se}`)}}},be=async se=>{try{await le.requirements.approve(se),Nt("Requirement approved"),Ue(),Se()}catch(Re){Nt(`Error: ${Re}`)}},Ke=async()=>{if(en)try{await le.requirements.reject(en,sn),Nt("Requirement rejected"),hn(null),bn(""),Ue()}catch(se){Nt(`Error: ${se}`)}},kt=async se=>{try{await le.requirements.delete(se),Nt("Requirement cancelled"),Ue()}catch(Re){Nt(`Error: ${Re}`)}},Et=(se,Re)=>{Ye.current=Re,tt.current=null,se.dataTransfer.effectAllowed="move",se.dataTransfer.setData("text/plain",`task:${Re.id}`),se.currentTarget.style.opacity="0.4"},jn=(se,Re)=>{tt.current=Re,Ye.current=null,se.dataTransfer.effectAllowed="move",se.dataTransfer.setData("text/plain",`req:${Re.id}`),se.currentTarget.style.opacity="0.4"},sr=se=>{se.currentTarget.style.opacity="1",Ye.current=null,tt.current=null,Oe(null)},ar=(se,Re)=>{se.preventDefault(),se.dataTransfer.dropEffect="move",oe!==Re&&Oe(Re)},Dr=(se,Re)=>{const Pe=se.currentTarget.getBoundingClientRect(),{clientX:re,clientY:pe}=se;(re<Pe.left||re>Pe.right||pe<Pe.top||pe>Pe.bottom)&&oe===Re&&Oe(null)},Or=async(se,Re)=>{se.preventDefault(),Oe(null);const Pe=Ye.current,re=tt.current;if(Pe){const pe=To.find(Ee=>Ee.id===Re);if(!pe)return;const we=pe.dropStatus;if(Pe.status===we||Pe.status==="pending_approval")return;try{await le.tasks.updateStatus(Pe.id,we),Se()}catch{}}else if(re){const pe=cN[Re];if(!pe||re.status===pe)return;try{await le.requirements.updateStatus(re.id,pe),Ue()}catch{}}},yr=se=>{Qe(Re=>{const Pe=new Set(Re);return Pe.has(se)?Pe.delete(se):Pe.add(se),Pe})},on=se=>{Ge(Re=>{const Pe=new Set(Re);return Pe.has(se)?Pe.delete(se):Pe.add(se),Pe})},Rr=1440*60*1e3,Ps=Date.now(),lr=se=>se.status==="completed"&&se.updatedAt&&Ps-new Date(se.updatedAt).getTime()>Rr,ir=(se,Re=!1)=>{let Pe=se.filter(re=>Gt||Re||!lr(re));return o==="project"&&u&&(Pe=Pe.filter(re=>re.projectId===u)),Ae.size>0&&(Pe=Pe.filter(re=>re.projectId&&Ae.has(re.projectId))),Le.size>0&&(Pe=Pe.filter(re=>re.assignedAgentId&&Le.has(re.assignedAgentId))),Pe},Us=se=>se.statuses.flatMap(Re=>ir(m[Re]??[])),Cn=j.useMemo(()=>{let se=w;return o==="project"&&u&&(se=se.filter(Re=>Re.projectId===u)),Ae.size>0&&(se=se.filter(Re=>Re.projectId&&Ae.has(Re.projectId))),Le.size>0&&(se=se.filter(Re=>Le.has(Re.createdBy))),se},[w,o,u,Ae,Le]),Yr=j.useCallback(se=>Cn.filter(Re=>oN[Re.status]===se.id),[Cn]),ka=To.filter(se=>{if(se.id==="failed"||se.id==="closed"){const Re=Us(se),Pe=Yr(se);return Re.length+Pe.length>0}return!0}),or=Object.values(m).flat().filter(se=>lr(se)).length,zr=j.useMemo(()=>{const se=new Set(["completed","failed","cancelled","archived"]),Re=Object.values(m).flat(),Pe=new Set;for(const re of Re)re.assignedAgentId&&!se.has(re.status)&&(!u||re.projectId===u)&&Pe.add(re.assignedAgentId);return[...x].sort((re,pe)=>{const we=Pe.has(re.id)?0:1,Ee=Pe.has(pe.id)?0:1;return we-Ee})},[x,m,u]),Fn=j.useMemo(()=>{const se=new Set(["completed","failed","cancelled","archived"]),Re=Object.values(m).flat(),Pe=new Set;for(const re of Re)re.projectId&&!se.has(re.status)&&Pe.add(re.projectId);return[...s].sort((re,pe)=>{const we=Pe.has(re.id)?0:1,Ee=Pe.has(pe.id)?0:1;return we-Ee})},[s,m]),wn=j.useMemo(()=>{const se={};for(const Re of Object.values(m))for(const Pe of Re){const re=Pe.projectId??"__none__";se[re]=(se[re]??0)+1}return se},[m]),vr=Object.values(wn).reduce((se,Re)=>se+Re,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:[Q?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:Q.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:()=>{ee(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(se=>t.jsx("button",{onClick:()=>vt(se),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${xt===se?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:se==="backlog"?"Backlog":se==="kanban"?"Kanban":"DAG"},se))}),or>0&&t.jsx("button",{onClick:()=>ve(se=>!se),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Gt?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Gt?"Hide archived":`${or} archived`}),t.jsx("div",{className:"flex-1"}),(Ae.size>0||Le.size>0||s.length>1||x.length>0)&&t.jsxs("button",{onClick:()=>He(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${Ae.size>0||Le.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+Le.size>0?` (${Ae.size+Le.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:[Q?t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(Xz,{value:Q.name,onSave:async se=>{await le.projects.update(Q.id,{name:se}),ue()},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`}),or>0&&t.jsx("button",{onClick:()=>ve(se=>!se),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Gt?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Gt?`Hide ${or} archived`:`${or} archived`}),t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(se=>t.jsx("button",{onClick:()=>vt(se),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${xt===se?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:se==="backlog"?"Backlog":se==="kanban"?"Kanban":"DAG"},se))}),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:()=>{ee(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&&(vr>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:()=>Ge(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"}),Fn.map(se=>{const Re=Ae.has(se.id),Pe=wn[se.id]??0;return t.jsxs("button",{onClick:()=>on(se.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Re?"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 ${Re?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:se.name[0]?.toUpperCase()}),se.name,Pe>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:Pe})]},se.id)})]}),!r&&x.length>0&&!k&&(vr>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:()=>Qe(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 ${Le.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),zr.map(se=>{const Re=Le.has(se.id);return t.jsxs("button",{onClick:()=>yr(se.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Re?"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 ${Re?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:se.name[0]?.toUpperCase()}),se.name]},se.id)})]}),k&&Q?t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsx(lL,{project:Q,tasks:Object.values(m).flat(),requirements:w,agents:x,onDeleteProject:()=>an(Q.id),onUpdateProject:async se=>{await le.projects.update(Q.id,se)},onRefresh:()=>{ue()}})}):vr===0&&Cn.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"})]})}):xt==="backlog"?t.jsx(fL,{tasks:ir(Object.values(m).flat()),requirements:Cn,agents:x,projects:s,onTaskClick:se=>ke(se),onReqClick:se=>Ie(se),onRefresh:()=>{Se(),Ue()}}):xt==="dag"?t.jsx(Gz,{tasks:ir(Object.values(m).flat(),!0),requirements:Cn,agents:x,showArchived:Gt,onShowArchivedChange:ve,onTaskClick:se=>ke(se),onReqClick:se=>Ie(se),onDependencyChange:Se}):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:ka.map(se=>{const Re=Us(se),Pe=Yr(se),re=Re.length+Pe.length,pe=oe===se.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 ${se.accent} ${pe?"bg-surface-elevated/80 ring-1 ring-brand-500/40":"bg-surface-secondary"}`,onDragOver:we=>ar(we,se.id),onDragLeave:we=>Dr(we,se.id),onDrop:we=>{Or(we,se.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:se.label}),t.jsx("span",{className:"text-xs bg-surface-elevated px-2 py-0.5 rounded-full",children:re})]}),t.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin",children:(()=>{const we=[...Pe.map(Ee=>({kind:"req",data:Ee,time:new Date(Ee.updatedAt??Ee.createdAt).getTime()})),...Re.map(Ee=>({kind:"task",data:Ee,time:new Date(Ee.updatedAt??Ee.createdAt??0).getTime()}))];return we.sort((Ee,_e)=>_e.time-Ee.time),we.map(Ee=>{if(Ee.kind==="req"){const _e=Ee.data,Be=Iu[_e.status]??{label:_e.status,cls:"bg-gray-500/15 text-fg-secondary"},mt=_e.source==="agent"&&(_e.status==="draft"||_e.status==="pending_review"),at=o==="all"&&_e.projectId?s.find(Tt=>Tt.id===_e.projectId):null,rt=Wl(_e.createdBy,x,b)??_e.createdBy.slice(0,10);return t.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:Tt=>jn(Tt,_e),onDragEnd:sr,onClick:()=>Ie(_e),onKeyDown:Tt=>Tt.key==="Enter"&&Ie(_e),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 ${mt?"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:_e.title})]}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Be.cls}`,children:Be.label})]}),_e.description&&t.jsx("div",{className:"text-xs text-fg-tertiary mt-1 line-clamp-2",children:_e.description}),at&&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:at.name,children:at.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:_e.priority}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["by ",rt]})]}),t.jsx("div",{className:"flex items-center gap-1.5",children:_e.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:[_e.taskIds.length," tasks"]})})]}),mt&&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(),be(_e.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(),hn(_e.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-${_e.id}`)}else{const _e=Ee.data,Be=_e.subtasks?.length??0,Ve=lN[_e.status],mt=_e.status==="pending_approval",at=_e.taskType==="scheduled"&&!!_e.scheduleConfig,rt=at?_e.scheduleConfig.every?`Every ${_e.scheduleConfig.every}`:_e.scheduleConfig.cron?"Cron":"Scheduled":null,Tt=o==="all"&&_e.projectId?s.find(Je=>Je.id===_e.projectId)?.name:null,qt=_e.requirementId?w.find(Je=>Je.id===_e.requirementId)?.title:null,Kn=_e.createdBy?Wl(_e.createdBy,x,b)??_e.createdBy:null;return t.jsxs("div",{role:"button",tabIndex:0,"aria-label":_e.title,draggable:!mt,onDragStart:Je=>!mt&&Et(Je,_e),onDragEnd:sr,onClick:()=>ke(_e),onKeyDown:Je=>Je.key==="Enter"&&ke(_e),className:`border rounded-lg p-3 border-l-[3px] transition-colors ${mt?"bg-amber-500/[0.04] border-amber-500/30 border-l-amber-500 cursor-pointer":at?`bg-blue-500/[0.03] border-blue-500/20 ${Tm[_e.priority]??""} hover:border-blue-500/40 cursor-pointer`:`bg-surface-elevated border-border-default ${Tm[_e.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:[at&&t.jsx("span",{className:"text-blue-600 shrink-0",title:rt??"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:_e.title})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[at&&rt&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-600 whitespace-nowrap",children:rt}),Ve&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${Ve.cls}`,children:Ve.label})]})]}),_e.description&&t.jsx("div",{className:"text-xs text-fg-tertiary mt-1 line-clamp-2",children:_e.description}),(Tt||qt)&&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}),qt&&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:qt,children:["# ",qt]})]}),_e.blockedBy&&_e.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:["⏳ ",_e.blockedBy.length," dep",_e.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:_e.priority}),Kn&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",title:`Created by ${Kn}`,children:["by ",Kn]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[Be>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary bg-surface-overlay/50 px-1.5 py-0.5 rounded",children:["⋮ ",Be]}),_e.notes&&_e.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",_e.notes.length]}),_e.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 ${iN[x.find(Je=>Je.id===_e.assignedAgentId)?.status??""]??"bg-gray-500"}`}),x.find(Je=>Je.id===_e.assignedAgentId)?.name??_e.assignedAgentId.slice(0,8)]})]})]})]},_e.id)}})})()}),pe&&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"})})]},se.id)})})})]}),Y&&t.jsx(aN,{orgId:e?.orgId,onCreated:Mn,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:se=>se.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:se=>ee(se.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(se=>t.jsx("option",{value:se.id,children:se.name},se.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:se=>z(se.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(se=>se.status==="approved"&&(!L||se.projectId===L)).map(se=>t.jsx("option",{value:se.id,children:se.title},se.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:se=>F(se.target.value),onKeyDown:se=>{se.key==="Enter"&&ln()},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:se=>A(se.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:se=>_(se.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:se=>U(se.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(se=>t.jsx("option",{value:se.id,children:se.name},se.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:J,onChange:se=>B(se.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(se=>se.id!==G).map(se=>t.jsx("option",{value:se.id,children:se.name},se.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:ne,onChange:se=>Z(se.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)"})]})]}),ne==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Frequency"}),t.jsxs("select",{value:te,onChange:se=>ie(se.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:se=>{const Re=se.target.value;Re&&!V.includes(Re)&&K([...V,Re])},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(se=>se.status!=="completed"&&se.status!=="cancelled"&&!V.includes(se.id)).map(se=>t.jsx("option",{value:se.id,children:se.title},se.id))]}),V.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:V.map(se=>{const Re=Object.values(m).flat().find(Pe=>Pe.id===se);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:["⏳ ",Re?Re.title.slice(0,30):se.slice(-8),t.jsx("button",{onClick:()=>K(V.filter(Pe=>Pe!==se)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},se)})})]}),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:()=>{ln()},disabled:!G||!J,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Create"})]})]})}),ye&&t.jsx(aL,{task:ye,agents:x,projects:s,requirements:w,allTasks:Object.values(m).flat(),users:b,onClose:()=>ke(null),onRefresh:vn,authUser:e}),Dt&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{$t(!1),yt(""),$e("")},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:se=>se.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:gt,onChange:se=>jt(se.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(se=>t.jsx("option",{value:se.id,children:se.name},se.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{value:bt,onChange:se=>yt(se.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:se=>{se.key==="Enter"&&bt.trim()&&Pn()}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:he,onChange:se=>$e(se.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:ht,onChange:se=>dt(se.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:()=>{$t(!1),yt(""),$e("")},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:()=>{Pn()},className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Create"})]})]})}),en&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>hn(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:se=>se.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:sn,onChange:se=>bn(se.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:()=>hn(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:()=>{Ke()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:"Reject"})]})]})}),Me&&t.jsx(hL,{req:Me,agents:x,projects:s,allTasks:Object.values(m).flat(),users:b,onClose:()=>Ie(null),onApprove:se=>{be(se),Ie(null)},onReject:se=>{hn(se),Ie(null)},onCancel:se=>{kt(se),Ie(null)},onStatusChange:async(se,Re)=>{try{await le.requirements.updateStatus(se,Re),Nt(`Requirement status → ${Re}`),Ue(),Se()}catch(Pe){Nt(`Error: ${Pe}`)}}}),De&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>He(!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:se=>se.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||Le.size>0)&&t.jsx("button",{onClick:()=>{Ge(new Set),Qe(new Set)},className:"text-[11px] text-brand-500 font-medium",children:"Clear all"}),t.jsx("button",{onClick:()=>He(!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:Fn.map(se=>{const Re=Ae.has(se.id),Pe=wn[se.id]??0;return t.jsxs("button",{onClick:()=>on(se.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Re?"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 ${Re?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:se.name[0]?.toUpperCase()}),se.name,Pe>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Pe})]},se.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:zr.map(se=>{const Re=Le.has(se.id);return t.jsxs("button",{onClick:()=>yr(se.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Re?"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 ${Re?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:se.name[0]?.toUpperCase()}),se.name]},se.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function hL({req:e,agents:r,projects:s,allTasks:l,users:o,onClose:c,onApprove:u,onReject:f,onCancel:m,onStatusChange:h}){const x=xs(),g=Iu[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=Wl(e.createdBy,r,o)??e.createdBy.slice(0,12),C=l.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:Wl(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=lN[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 ${Tm[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=Iu[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 is(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 Va({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 zl({label:e,value:r,color:s}){if(!r)return null;const l={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 ${l[s]??l.gray} capitalize inline-block`,children:r})]})}function Yh({files:e}){const[r,s]=j.useState(Object.keys(e)[0]??""),l=Object.keys(e);return l.length===0?null:t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Files (",l.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:l.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),l=e.agent,o=e.team,c=e.dependencies,u=e.displayName??e.name;if(r==="agent"){const f=l?.roleName,m=l?.agentRole,h=l?.llmProvider,x=l?.llmModel,g=is(c?.env),b=is(c?.skills);return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Va,{label:"Name",value:u}),t.jsx(Va,{label:"Description",value:e.description}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(zl,{label:"Role Template",value:f,color:"indigo"}),t.jsx(zl,{label:"Agent Role",value:m,color:m==="manager"?"purple":"cyan"})]}),is(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:is(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(zl,{label:"LLM Provider",value:h,color:"gray"}),x&&t.jsx(zl,{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(Va,{label:"Skills",value:b.join(", ")}),s&&t.jsx(Yh,{files:s})]})}if(r==="team"){const m=o?.members??[];return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Va,{label:"Name",value:u}),t.jsx(Va,{label:"Description",value:e.description}),t.jsx("div",{className:"flex flex-wrap gap-2",children:t.jsx(zl,{label:"Category",value:e.category,color:"indigo"})}),is(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:is(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(Yh,{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)]})]}),is(h.skills).length>0&&t.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:is(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(Va,{label:"Name",value:u}),t.jsx(Va,{label:"Description",value:e.description}),t.jsx("div",{className:"flex gap-2",children:t.jsx(zl,{label:"Category",value:e.category,color:"indigo"})}),s&&t.jsx(Yh,{files:s}),is(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:is(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"],os={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=xs(),r=Wm({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[s,l]=j.useState(!1),o=j.useRef(s);o.current=s,j.useEffect(()=>{if(!e)return;const be=()=>{o.current&&l(!1)};return window.addEventListener("popstate",be),()=>window.removeEventListener("popstate",be)},[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(""),[A,I]=j.useState(""),[_,G]=j.useState("date"),[U,J]=j.useState(null),[B,L]=j.useState(null),[ee,R]=j.useState(""),[z,V]=j.useState(!1),[K,ne]=j.useState(!1),[Z,te]=j.useState(new Set),ie=j.useRef(null),[ye,ke]=j.useState("file"),[Me,Ie]=j.useState(""),[Le,Qe]=j.useState(""),[Ae,Ge]=j.useState(""),[ut,_t]=j.useState(""),[oe,Oe]=j.useState(""),[xt,vt]=j.useState(null),[Gt,ve]=j.useState(null),[De,He]=j.useState(!1),[Ye,tt]=j.useState(!1),[Dt,$t]=j.useState(!1),[bt,yt]=j.useState(!1),he=j.useRef(null),$e=j.useRef(null),[ht,dt]=j.useState(""),gt=j.useRef(void 0),jt=(be,Ke)=>{L({type:be,text:Ke}),setTimeout(()=>L(null),3e3)},en=async be=>{try{return await navigator.clipboard.writeText(be),!0}catch{try{const Ke=document.createElement("textarea");Ke.value=be,Ke.style.cssText="position:fixed;left:-9999px;top:-9999px;opacity:0",document.body.appendChild(Ke),Ke.select();const kt=document.execCommand("copy");return document.body.removeChild(Ke),kt}catch{return!1}}},hn=async be=>{await en(be)?(yt(!0),setTimeout(()=>yt(!1),1500)):jt("error","Copy failed — try long-pressing to copy manually")},sn=j.useMemo(()=>new Map(w.map(be=>[be.id,be])),[w]),bn=j.useMemo(()=>new Map(b.map(be=>[be.id,be])),[b]);j.useEffect(()=>{le.projects.list().then(be=>p(be.projects)).catch(()=>{}),le.agents.list().then(be=>S(be.agents??[])).catch(()=>{}),le.system.storage().then(be=>dt(be.dataDir+"/shared")).catch(()=>{})},[]),j.useEffect(()=>(gt.current=setTimeout(()=>H(C),300),()=>clearTimeout(gt.current)),[C]);const Nt=j.useMemo(()=>({q:k||void 0,projectId:$||void 0,agentId:P||void 0,type:M||void 0,status:F||void 0,artifactType:A||void 0}),[k,$,P,M,F,A]),Q=j.useCallback(async()=>{E(!0);try{const{results:be,total:Ke}=await le.deliverables.search({...Nt,offset:0,limit:c});f(be),h(Ke)}catch{f([]),h(0)}E(!1)},[Nt]),ue=j.useCallback(async()=>{if(!(x||u.length>=m)){g(!0);try{const{results:be,total:Ke}=await le.deliverables.search({...Nt,offset:u.length,limit:c});f(kt=>[...kt,...be]),h(Ke)}catch{}g(!1)}},[Nt,u.length,m,x]);j.useEffect(()=>{Q()},[Q]),j.useEffect(()=>Sn.on("deliverable:created",()=>Q()),[Q]);const Se=j.useCallback(()=>{const be=ie.current;!be||T||x||u.length>=m||be.scrollHeight<=be.clientHeight+100&&ue()},[T,x,u.length,m,ue]);j.useEffect(()=>{const be=ie.current;if(!be)return;const Ke=()=>{be.scrollTop+be.clientHeight>=be.scrollHeight-100&&ue()};return be.addEventListener("scroll",Ke,{passive:!0}),()=>be.removeEventListener("scroll",Ke)},[ue]),j.useEffect(()=>{Se()},[Se,Z]);const qe=j.useMemo(()=>{const be=new Map;for(const kt of u){let Et,jn;if(_==="project")Et=kt.projectId??"_none",jn=kt.projectId?bn.get(kt.projectId)?.name??kt.projectId:"No Project";else if(_==="agent")Et=kt.agentId??"_none",jn=kt.agentId?sn.get(kt.agentId)?.name??kt.agentId:"Unknown";else if(_==="type")Et=kt.type,jn=kt.type.charAt(0).toUpperCase()+kt.type.slice(1);else{const sr=new Date(kt.updatedAt);Et=`${sr.getFullYear()}-${String(sr.getMonth()+1).padStart(2,"0")}-${String(sr.getDate()).padStart(2,"0")}`,jn=Et}be.has(Et)||be.set(Et,{label:jn,items:[]}),be.get(Et).items.push(kt)}const Ke=[...be.entries()];return _==="date"?Ke.sort((kt,Et)=>Et[0].localeCompare(kt[0])):Ke.sort((kt,Et)=>kt[1].label.localeCompare(Et[1].label)),Ke},[u,_,bn,sn]),et=async()=>{if(!(!Me.trim()||!Le.trim())){ne(!0);try{await le.deliverables.create({type:ye,title:Me,summary:Le,reference:Ae,projectId:ut||void 0,tags:oe.split(",").map(be=>be.trim()).filter(Boolean)}),V(!1),jt("success","Deliverable created"),Q()}catch(be){jt("error",`Error: ${be}`)}ne(!1)}},Ue=async be=>{R("verify");try{await le.deliverables.verify(be.id),jt("success","Verified"),J({...be,status:"verified"}),Q()}catch(Ke){jt("error",`Error: ${Ke}`)}R("")},yn=async be=>{R("flag");try{await le.deliverables.update(be.id,{status:"outdated"}),jt("success","Flagged as outdated"),J({...be,status:"outdated"}),Q()}catch(Ke){jt("error",`Error: ${Ke}`)}R("")},mn=async be=>{R("remove");try{await le.deliverables.remove(be.id),jt("success","Removed"),J(null),Q()}catch(Ke){jt("error",`Error: ${Ke}`)}R("")},Mt=()=>{Ht.navigate("builder")},_n=async be=>{if(be.reference){if(be.type==="directory"){tt(!0);return}He(!0);try{const Ke=await le.files.preview(be.reference);Ke.type==="image"&&Ke.mimeType?ve({src:`data:${Ke.mimeType};base64,${Ke.content}`,name:Ke.name}):vt(Ke.content)}catch{vt(null),be.type==="file"&&tt(!0)}He(!1)}};j.useEffect(()=>{vt(null),ve(null),tt(!1),$t(!1),U&&_n(U)},[U?.id]),j.useEffect(()=>{if(!Dt)return;const be=Ke=>{$e.current&&!$e.current.contains(Ke.target)&&$t(!1)};return document.addEventListener("mousedown",be),()=>document.removeEventListener("mousedown",be)},[Dt]);const Hn=async(be,Ke)=>{const kt=he.current?.firstElementChild;if(!kt)return;const Et=pL(kt,be);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([Et],{type:"text/html"}),"text/plain":new Blob([Ke],{type:"text/plain"})})]),jt("success",be==="light"?"HTML (light) copied":"HTML (dark) copied")}catch{const jn=await en(Ke);jt(jn?"success":"error",jn?"Text copied (HTML not supported)":"Copy failed")}$t(!1)},Mn=be=>t.jsxs("div",{className:"relative group/preview",children:[t.jsxs("div",{className:"absolute -top-1 -right-1 z-10",ref:$e,children:[t.jsx("button",{onClick:()=>$t(Ke=>!Ke),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"})})}),Dt&&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 Ke=await en(be);jt(Ke?"success":"error",Ke?"Markdown source copied":"Copy failed"),$t(!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:()=>Hn("light",be),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:()=>Hn("dark",be),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:he,children:t.jsx(er,{content:be,className:"text-fg-secondary text-sm"})})]}),an=j.useCallback(be=>{te(Ke=>{const kt=new Set(Ke);return kt.has(be)?kt.delete(be):kt.add(be),kt})},[]),ln=j.useCallback(()=>{Z.size===qe.length?te(new Set):te(new Set(qe.map(([be])=>be)))},[Z.size,qe]),vn=()=>{Ie(""),Qe(""),Ge(""),Oe(""),ke("file"),b.length>0&&_t(b[0].id),V(!0)},Pn=be=>{J(be),e&&(l(!0),history.pushState({mobileDetail:"deliverables"},"",window.location.hash))};return t.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[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?s?{display:"none"}: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:vn,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:be=>N(be.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"}),ht&&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:ht}),t.jsx("button",{onClick:()=>{le.system.openPath(ht)},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(pa,{label:"All types",value:"",current:M||A||"",onClick:()=>{Y(""),I("")}}),Lv.map(be=>t.jsx(pa,{label:`${to[be]?.icon??""} ${be}`,value:be,current:M,onClick:Ke=>{Y(Ke),I("")}},be)),["agent","team","skill"].map(be=>t.jsx(pa,{label:`${os[be].icon} ${os[be].label}`,value:be,current:A,onClick:Ke=>{I(Ke),Y("")}},be))]}),b.length>0&&t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(pa,{label:"All projects",value:"",current:$,onClick:X}),b.map(be=>t.jsx(pa,{label:be.name,value:be.id,current:$,onClick:X},be.id))]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(pa,{label:"Active",value:"",current:F,onClick:D}),t.jsx(pa,{label:"Verified",value:"verified",current:F,onClick:D}),t.jsx(pa,{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(be=>t.jsx("button",{onClick:()=>{G(be),te(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${_===be?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:be.charAt(0).toUpperCase()+be.slice(1)},be)),qe.length>1&&t.jsx("button",{onClick:ln,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===qe.length?"Expand all":"Collapse all",children:Z.size===qe.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(be=>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"})]},be))}):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:vn,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create first"})]}):qe.map(([be,Ke])=>{const kt=Z.has(be);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>an(be),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 ${kt?"":"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:Ke.label}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Ke.items.length,")"]})]}),!kt&&Ke.items.map(Et=>t.jsxs("button",{onClick:()=>Pn(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&&os[Et.artifactType]?t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${os[Et.artifactType].color}`,children:[os[Et.artifactType].icon," ",os[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:sn.get(Et.agentId)?.name??"Agent"})]})]},Et.id))]},be)}),x&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[t.jsx(Gh,{})," ",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:!!ee,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:ee==="verify"?"Verifying...":"Verify"}),U.status!=="outdated"&&t.jsx("button",{onClick:()=>yn(U),disabled:!!ee,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:ee==="flag"?"Flagging...":"Flag Outdated"}),t.jsx("button",{onClick:()=>mn(U),disabled:!!ee,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:ee==="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&&os[U.artifactType]&&t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${os[U.artifactType].color}`,children:[os[U.artifactType].icon," Builder ",os[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:()=>{le.files.reveal(U.reference).catch(()=>jt("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:()=>{le.files.reveal(U.reference).catch(()=>jt("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:()=>hn(U.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${bt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:"Copy path to clipboard",children:bt?"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:Mt,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:De?t.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[t.jsx(Gh,{})," Loading preview..."]}):Gt?t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("img",{src:Gt.src,alt:Gt.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:Gt.name})]}):xt?Mn(xt):Ye?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:()=>{le.files.reveal(U.reference).catch(()=>jt("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:()=>{le.files.reveal(U.reference).catch(()=>jt("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:()=>hn(U.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${bt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:bt?"Copied!":"Copy"})]})]}):U.summary?Mn(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(be=>t.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:be},be))}),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:()=>Ht.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:()=>Ht.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: ",sn.get(U.agentId)?.name??U.agentId.slice(0,12)]}),U.projectId&&t.jsxs("button",{onClick:()=>Ht.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: ",bn.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:()=>!K&&V(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:be=>be.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:ye,onChange:be=>ke(be.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(be=>t.jsxs("option",{value:be,children:[to[be]?.icon??""," ",be]},be))})]}),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:Me,onChange:be=>Ie(be.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:be=>Ge(be.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:Le,onChange:be=>Qe(be.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:oe,onChange:be=>Oe(be.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:ut,onChange:be=>_t(be.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(be=>t.jsx("option",{value:be.id,children:be.name},be.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:K,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:"Cancel"}),t.jsxs("button",{onClick:et,disabled:K||!Me.trim()||!Le.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:[K&&t.jsx(Gh,{}),K?"Creating...":"Create"]})]})]})})]})}function pL(e,r){const s=e.cloneNode(!0),l=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:${l.text};line-height:1.7;`,h1:`font-size:1.6em;font-weight:700;color:${l.heading};margin:20px 0 10px;line-height:1.3;border-bottom:1px solid ${l.border};padding-bottom:6px;`,h2:`font-size:1.35em;font-weight:700;color:${l.heading};margin:18px 0 8px;line-height:1.3;`,h3:`font-size:1.15em;font-weight:600;color:${l.heading};margin:14px 0 6px;line-height:1.3;`,h4:`font-size:1em;font-weight:600;color:${l.heading};margin:12px 0 4px;`,strong:`font-weight:600;color:${l.strong};`,em:"font-style:italic;",a:`color:${l.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:${l.text};`,blockquote:`border-left:3px solid ${l.blockquoteBorder};padding:2px 0 2px 14px;margin:10px 0;color:${l.blockquoteText};`,hr:`border:none;border-top:1px solid ${l.hrColor};margin:20px 0;`,table:"border-collapse:collapse;width:100%;margin:10px 0;",thead:`background:${l.tableHeaderBg};`,th:`border:1px solid ${l.tableBorder};padding:8px 12px;text-align:left;font-weight:600;color:${l.tableHeaderText};`,td:`border:1px solid ${l.tableBorder};padding:8px 12px;color:${l.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:${l.preBg};color:${l.preText};padding:14px;border-radius:6px;overflow-x:auto;margin:10px 0;font-size:0.88em;line-height:1.5;border:1px solid ${l.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:${l.codeBg};color:${l.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:${l.bg};color:${l.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 pa({label:e,value:r,current:s,onClick:l}){return t.jsx("button",{onClick:()=>l(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 Gh(){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 ba(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function gu(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,l]=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 le.reports.generate({period:$,scope:"org",orgId:"default"});l(X)}catch(X){f(String(X)),l(null)}c(!1)},[]),E=j.useCallback(()=>{le.usage.summary().then($=>h($.usage)).catch(()=>{}),le.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(iu,{label:"LLM Tokens (this month)",value:ba(m.llmTokens),color:"text-brand-500"}),t.jsx(iu,{label:"Tool Calls (today)",value:ba(m.toolCalls),color:"text-blue-600"}),t.jsx(iu,{label:"Messages (today)",value:ba(m.messages),color:"text-green-600"}),t.jsx(iu,{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:gu(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:ba(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:gu(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(Xh,{title:`Completed (${s.taskSummary.completed.length})`,color:"emerald",items:s.taskSummary.completed.map($=>({label:$.title,sub:$.agent}))}),s.taskSummary.inProgress.length>0&&t.jsx(Xh,{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(Xh,{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:ba(x.reduce(($,X)=>$+X.totalTokens,0))}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ba(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:gu(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 Xh({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((l,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:l.label}),l.sub&&l.sub!=="unassigned"&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:l.sub})]},o))})]})}function iu({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:l,onSort:o,align:c}){const u=s===r?l?"↓":"↑":"↕",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,l=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:()=>Ht.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 ${l}`}),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:ba(e.totalTokens)})]})}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:ba(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:gu(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:l,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(()=>{le.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 le.auth.logout()}catch{}l?.()},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.3.0"]})]}),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 l=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 ${l?"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:l?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 ${l?"font-semibold":""}`,children:s.label})]},s.id)})})}const EL=50,TL=30;function fN(e,r,s){const l=j.useRef(0),o=j.useRef(0),c=j.useCallback(f=>{l.current=f.touches[0].clientX,o.current=f.touches[0].clientY},[]),u=j.useCallback(f=>{const m=f.changedTouches[0].clientX-l.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 AL({authUser:e}){const[r,s]=j.useState("builder"),l=fN(Bv,r,s);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:l.onTouchStart,onTouchEnd:l.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 _L({theme:e,onThemeChange:r}){const[s,l]=j.useState("settings"),o=fN(Hv,s,l);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:()=>l(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(ij,{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[l,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(_=>_.configured)&&C(!0)}).catch(()=>{})},[]),j.useEffect(()=>{l===Pv&&!H.current&&!E&&(H.current=!0,Y())},[l,E]);const Y=async()=>{m(!0);try{const I=await fetch("/api/settings/env-models",{headers:M()});if(I.ok){const _=await I.json();if(u(_),_.detected.length>0){const G={};for(const U of _.detected)G[U.provider]=!0;x(G)}}}catch{}finally{m(!1)}},$=async()=>{if(!c)return;const I=c.detected.filter(_=>h[_.provider]);if(I.length!==0){b(!0),k(null);try{const _=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(_.ok){const G=await _.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 _=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:M(),body:JSON.stringify({preview:!0})})).json();"error"in _||w(_)}catch{}finally{T(!1)}},P=async()=>{T(!0),k(null);try{const _=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:M(),body:JSON.stringify({preview:!1})})).json();"error"in _?k({type:"err",text:_.error}):(k({type:"ok",text:`Imported ${_.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,_])=>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:_})]},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:_=>x({...h,[I.provider]:_.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,_])=>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:_})]})]},I))})}],D=()=>{l<F.length-1?o(l+1):e()},A=F[l];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,_)=>t.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${_<=l?"bg-brand-500":"bg-surface-elevated"}`},_))}),t.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:A.title}),t.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:A.subtitle}),A.content,t.jsxs("div",{className:"flex justify-between mt-8",children:[l>0?t.jsx("button",{onClick:()=>o(l-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:[l===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:l===F.length-1?"Get Started":"Next"})]})]})]})})})}const DL="markus123";function OL({onLogin:e}){const[r,s]=j.useState("admin@markus.local"),[l,o]=j.useState(""),[c,u]=j.useState(""),[f,m]=j.useState(!1),h=async x=>{if(x.preventDefault(),!(!r.trim()||!l)){u(""),m(!0);try{const{user:g}=await le.auth.login(r.trim(),l);e(g,l===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:l,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||!l,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,l]=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 le.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=>l(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(l=>{r(l);try{localStorage.setItem(hN,l)}catch{}Uv(l)},[]);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 ou(){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 Zh={};function $L(){const[e,r]=j.useState(ou),[s,l]=j.useState(()=>!localStorage.getItem("markus_onboarded")),[o,c]=j.useState(!0),u=xs(),f=LL(),m=Wm({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[h,x]=j.useState(()=>new Set([ou()])),[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=ou(),P=window.location.hash.slice(1);P!==X?Zh[X]=P:delete Zh[X],r($),x(q=>q.has($)?q:new Set([...q,$])),window.location.hash=Zh[$]||$},[u]);j.useEffect(()=>{Ht.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(()=>{le.auth.me().then(({user:$})=>{b($),k(),qa(gr.builderArtifacts,()=>le.builder.artifacts.list()),qa(gr.builderAgents,()=>le.agents.list()),qa(gr.builderHubMyItems,()=>In.myItems()),qa(gr.builderInstalled,()=>le.builder.artifacts.installed()),qa(gr.hubAgents,()=>In.search({type:"agent",limit:50})),qa(gr.hubTeams,()=>In.search({type:"team",limit:50})),qa(gr.hubSkills,()=>In.search({type:"skill",limit:50}))}).catch(()=>b(null)),Sn.connect();const Y=()=>{const $=ou();r($),x(X=>X.has($)?X:new Set([...X,$]))};return window.addEventListener("hashchange",Y),()=>{Sn.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(AL,{authUser:H}),settings:t.jsx(_L,{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(ij,{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"),l(!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 iz=j.memo(rN),oz=e=>r=>e?`${Math.max(1/r.transform[2],1)}`:void 0,cz={[Jl.Line]:"right",[Jl.Handle]:"bottom-right"};function uz({nodeId:e,position:r,variant:s=Jl.Handle,className:l,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=pn(),H=j.useRef(null),M=s===Jl.Handle,Y=Ut(j.useCallback(oz(M&&p),[M,p]),gn),$=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:A,nodeOrigin:I,domNode:_}=k.getState();return{nodeLookup:q,transform:F,snapGrid:D,snapToGrid:A,nodeOrigin:I,paneDomNode:_}},onChange:(q,F)=>{const{triggerNodeChanges:D,nodeLookup:A,parentLookup:I,nodeOrigin:_}=k.getState(),G=[],U={x:q.x,y:q.y},J=A.get(N);if(J&&J.expandParent&&J.parentId){const B=J.origin??_,L=q.width??J.measured.width??0,ee=q.height??J.measured.height??0,R={id:J.id,parentId:J.parentId,rect:{width:L,height:ee,...sw({x:q.x??J.position.x,y:q.y??J.position.y},{width:L,height:ee},J.parentId,A,B)}},z=px([R],A,I,_);G.push(...z),U.x=q.x?Math.max(B[0]*L,q.x):void 0,U.y=q.y?Math.max(B[1]*ee,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:Bn(["react-flow__resize-control","nodrag",...P,s,l]),ref:H,style:{...o,scale:Y,...u&&{[M?"backgroundColor":"borderColor"]:u}},children:c})}j.memo(uz);var Qt=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),ts=Qt((e,r)=>{var s=Object.defineProperty,l=(D,A,I)=>A in D?s(D,A,{enumerable:!0,configurable:!0,writable:!0,value:I}):D[A]=I,o=(D,A)=>()=>(A||D((A={exports:{}}).exports,A),A.exports),c=(D,A,I)=>l(D,typeof A!="symbol"?A+"":A,I),u=o((D,A)=>{var I="\0",_="\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[_]={})}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 K=arguments,ne=this;return z.forEach(function(Z){K.length>1?ne.setNode(Z,V):ne.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]=_,this._children[z]={},this._children[_][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 K=ne=>V.removeEdge(V._edgeObjs[ne]);delete this._nodes[z],this._isCompound&&(this._removeFromParentsChildList(z),delete this._parent[z],this.children(z).forEach(function(ne){V.setParent(ne)}),delete this._children[z]),Object.keys(this._in[z]).forEach(K),delete this._in[z],delete this._preds[z],Object.keys(this._out[z]).forEach(K),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=_;else{V+="";for(var K=V;K!==void 0;K=this.parent(K))if(K===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!==_)return V}}children(z=_){if(this._isCompound){var V=this._children[z];if(V)return Object.keys(V)}else{if(z===_)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 ne=new Set(V);for(var K of this.successors(z))ne.add(K);return Array.from(ne.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 K=this;Object.entries(this._nodes).forEach(function([te,ie]){z(te)&&V.setNode(te,ie)}),Object.values(this._edgeObjs).forEach(function(te){V.hasNode(te.v)&&V.hasNode(te.w)&&V.setEdge(te,K.edge(te))});var ne={};function Z(te){var ie=K.parent(te);return ie===void 0||V.hasNode(ie)?(ne[te]=ie,ie):ie in ne?ne[ie]:Z(ie)}return this._isCompound&&V.nodes().forEach(te=>V.setParent(te,Z(te))),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 K=this,ne=arguments;return z.reduce(function(Z,te){return ne.length>1?K.setEdge(Z,te,V):K.setEdge(Z,te),te}),this}setEdge(){var z,V,K,ne,Z=!1,te=arguments[0];typeof te=="object"&&te!==null&&"v"in te?(z=te.v,V=te.w,K=te.name,arguments.length===2&&(ne=arguments[1],Z=!0)):(z=te,V=arguments[1],K=arguments[3],arguments.length>2&&(ne=arguments[2],Z=!0)),z=""+z,V=""+V,K!==void 0&&(K=""+K);var ie=L(this._isDirected,z,V,K);if(Object.hasOwn(this._edgeLabels,ie))return Z&&(this._edgeLabels[ie]=ne),this;if(K!==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?ne:this._defaultEdgeLabelFn(z,V,K);var ye=ee(this._isDirected,z,V,K);return z=ye.v,V=ye.w,Object.freeze(ye),this._edgeObjs[ie]=ye,J(this._preds[V],z),J(this._sucs[z],V),this._in[V][ie]=ye,this._out[z][ie]=ye,this._edgeCount++,this}edge(z,V,K){var ne=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,K);return this._edgeLabels[ne]}edgeAsObj(){let z=this.edge(...arguments);return typeof z!="object"?{label:z}:z}hasEdge(z,V,K){var ne=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,K);return Object.hasOwn(this._edgeLabels,ne)}removeEdge(z,V,K){var ne=arguments.length===1?R(this._isDirected,arguments[0]):L(this._isDirected,z,V,K),Z=this._edgeObjs[ne];return Z&&(z=Z.v,V=Z.w,delete this._edgeLabels[ne],delete this._edgeObjs[ne],B(this._preds[V],z),B(this._sucs[z],V),delete this._in[V][ne],delete this._out[z][ne],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,K){if(z){var ne=Object.values(z);return K?ne.filter(function(Z){return Z.v===V&&Z.w===K||Z.v===K&&Z.w===V}):ne}}};function J(z,V){z[V]?z[V]++:z[V]=1}function B(z,V){--z[V]||delete z[V]}function L(z,V,K,ne){var Z=""+V,te=""+K;if(!z&&Z>te){var ie=Z;Z=te,te=ie}return Z+G+te+G+(ne===void 0?I:ne)}function ee(z,V,K,ne){var Z=""+V,te=""+K;if(!z&&Z>te){var ie=Z;Z=te,te=ie}var ye={v:Z,w:te};return ne&&(ye.name=ne),ye}function R(z,V){return L(z,V.v,V.w,V.name)}A.exports=U}),f=o((D,A)=>{A.exports="3.0.2"}),m=o((D,A)=>{A.exports={Graph:u(),version:f()}}),h=o((D,A)=>{var I=u();A.exports={write:_,read:J};function _(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 ee=B.node(L),R=B.parent(L),z={v:L};return ee!==void 0&&(z.value=ee),R!==void 0&&(z.parent=R),z})}function U(B){return B.edges().map(function(L){var ee=B.edge(L),R={v:L.v,w:L.w};return L.name!==void 0&&(R.name=L.name),ee!==void 0&&(R.value=ee),R})}function J(B){var L=new I(B.options).setGraph(B.value);return B.nodes.forEach(function(ee){L.setNode(ee.v,ee.value),ee.parent&&L.setParent(ee.v,ee.parent)}),B.edges.forEach(function(ee){L.setEdge({v:ee.v,w:ee.w,name:ee.name},ee.value)}),L}}),x=o((D,A)=>{A.exports=_;var I=()=>1;function _(U,J,B,L){return G(U,String(J),B||I,L||function(ee){return U.outEdges(ee)})}function G(U,J,B,L){var ee={},R=!0,z=0,V=U.nodes(),K=function(ie){var ye=B(ie);ee[ie.v].distance+ye<ee[ie.w].distance&&(ee[ie.w]={distance:ee[ie.v].distance+ye,predecessor:ie.v},R=!0)},ne=function(){V.forEach(function(ie){L(ie).forEach(function(ye){var ke=ye.v===ie?ye.v:ye.w,Me=ke===ye.v?ye.w:ye.v;K({v:ke,w:Me})})})};V.forEach(function(ie){var ye=ie===J?0:Number.POSITIVE_INFINITY;ee[ie]={distance:ye}});for(var Z=V.length,te=1;te<Z&&(R=!1,z++,ne(),!!R);te++);if(z===Z-1&&(R=!1,ne(),R))throw new Error("The graph contains a negative weight cycle");return ee}}),g=o((D,A)=>{A.exports=I;function I(_){var G={},U=[],J;function B(L){Object.hasOwn(G,L)||(G[L]=!0,J.push(L),_.successors(L).forEach(B),_.predecessors(L).forEach(B))}return _.nodes().forEach(function(L){J=[],B(L),J.length&&U.push(J)}),U}}),b=o((D,A)=>{var I=class{constructor(){c(this,"_arr",[]),c(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(_){return _.key})}has(_){return Object.hasOwn(this._keyIndices,_)}priority(_){var G=this._keyIndices[_];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(_,G){var U=this._keyIndices;if(_=String(_),!Object.hasOwn(U,_)){var J=this._arr,B=J.length;return U[_]=B,J.push({key:_,priority:G}),this._decrease(B),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var _=this._arr.pop();return delete this._keyIndices[_.key],this._heapify(0),_.key}decrease(_,G){var U=this._keyIndices[_];if(G>this._arr[U].priority)throw new Error("New priority is greater than current priority. Key: "+_+" Old: "+this._arr[U].priority+" New: "+G);this._arr[U].priority=G,this._decrease(U)}_heapify(_){var G=this._arr,U=2*_,J=U+1,B=_;U<G.length&&(B=G[U].priority<G[B].priority?U:B,J<G.length&&(B=G[J].priority<G[B].priority?J:B),B!==_&&(this._swap(_,B),this._heapify(B)))}_decrease(_){for(var G=this._arr,U=G[_].priority,J;_!==0&&(J=_>>1,!(G[J].priority<U));)this._swap(_,J),_=J}_swap(_,G){var U=this._arr,J=this._keyIndices,B=U[_],L=U[G];U[_]=L,U[G]=B,J[L.key]=_,J[B.key]=G}};A.exports=I}),p=o((D,A)=>{var I=b();A.exports=G;var _=()=>1;function G(J,B,L,ee){var R=function(z){return J.outEdges(z)};return U(J,String(B),L||_,ee||R)}function U(J,B,L,ee){var R={},z=new I,V,K,ne=function(Z){var te=Z.v!==V?Z.v:Z.w,ie=R[te],ye=L(Z),ke=K.distance+ye;if(ye<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+Z+" Weight: "+ye);ke<ie.distance&&(ie.distance=ke,ie.predecessor=V,z.decrease(te,ke))};for(J.nodes().forEach(function(Z){var te=Z===B?0:Number.POSITIVE_INFINITY;R[Z]={distance:te},z.add(Z,te)});z.size()>0&&(V=z.removeMin(),K=R[V],K.distance!==Number.POSITIVE_INFINITY);)ee(V).forEach(ne);return R}}),w=o((D,A)=>{var I=p();A.exports=_;function _(G,U,J){return G.nodes().reduce(function(B,L){return B[L]=I(G,L,U,J),B},{})}}),S=o((D,A)=>{A.exports=I;function I(G,U,J){if(G[U].predecessor!==void 0)throw new Error("Invalid source vertex");if(G[J].predecessor===void 0&&J!==U)throw new Error("Invalid destination vertex");return{weight:G[J].distance,path:_(G,U,J)}}function _(G,U,J){for(var B=[],L=J;L!==U;)B.push(L),L=G[L].predecessor;return B.push(U),B.reverse()}}),T=o((D,A)=>{A.exports=I;function I(_){var G=0,U=[],J={},B=[];function L(ee){var R=J[ee]={onStack:!0,lowlink:G,index:G++};if(U.push(ee),_.successors(ee).forEach(function(K){Object.hasOwn(J,K)?J[K].onStack&&(R.lowlink=Math.min(R.lowlink,J[K].index)):(L(K),R.lowlink=Math.min(R.lowlink,J[K].lowlink))}),R.lowlink===R.index){var z=[],V;do V=U.pop(),J[V].onStack=!1,z.push(V);while(ee!==V);B.push(z)}}return _.nodes().forEach(function(ee){Object.hasOwn(J,ee)||L(ee)}),B}}),E=o((D,A)=>{var I=T();A.exports=_;function _(G){return I(G).filter(function(U){return U.length>1||U.length===1&&G.hasEdge(U[0],U[0])})}}),C=o((D,A)=>{A.exports=_;var I=()=>1;function _(U,J,B){return G(U,J||I,B||function(L){return U.outEdges(L)})}function G(U,J,B){var L={},ee=U.nodes();return ee.forEach(function(R){L[R]={},L[R][R]={distance:0},ee.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,K=J(z);L[R][V]={distance:K,predecessor:R}})}),ee.forEach(function(R){var z=L[R];ee.forEach(function(V){var K=L[V];ee.forEach(function(ne){var Z=K[R],te=z[ne],ie=K[ne],ye=Z.distance+te.distance;ye<ie.distance&&(ie.distance=ye,ie.predecessor=te.predecessor)})})}),L}}),N=o((D,A)=>{function I(G){var U={},J={},B=[];function L(ee){if(Object.hasOwn(J,ee))throw new _;Object.hasOwn(U,ee)||(J[ee]=!0,U[ee]=!0,G.predecessors(ee).forEach(L),delete J[ee],B.push(ee))}if(G.sinks().forEach(L),Object.keys(U).length!==G.nodeCount())throw new _;return B}var _=class extends Error{constructor(){super(...arguments)}};A.exports=I,I.CycleException=_}),k=o((D,A)=>{var I=N();A.exports=_;function _(G){try{I(G)}catch(U){if(U instanceof I.CycleException)return!1;throw U}return!0}}),H=o((D,A)=>{A.exports=I;function I(G,U,J,B,L){Array.isArray(U)||(U=[U]);var ee=(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=_(G,z,J==="post",R,ee,B,L)}),L}function _(G,U,J,B,L,ee,R){return Object.hasOwn(B,U)||(B[U]=!0,J||(R=ee(R,U)),L(U).forEach(function(z){R=_(G,z,J,B,L,ee,R)}),J&&(R=ee(R,U))),R}}),M=o((D,A)=>{var I=H();A.exports=_;function _(G,U,J){return I(G,U,J,function(B,L){return B.push(L),B},[])}}),Y=o((D,A)=>{var I=M();A.exports=_;function _(G,U){return I(G,U,"post")}}),$=o((D,A)=>{var I=M();A.exports=_;function _(G,U){return I(G,U,"pre")}}),X=o((D,A)=>{var I=u(),_=b();A.exports=G;function G(U,J){var B=new I,L={},ee=new _,R;function z(K){var ne=K.v===R?K.w:K.v,Z=ee.priority(ne);if(Z!==void 0){var te=J(K);te<Z&&(L[ne]=R,ee.decrease(ne,te))}}if(U.nodeCount()===0)return B;U.nodes().forEach(function(K){ee.add(K,Number.POSITIVE_INFINITY),B.setNode(K)}),ee.decrease(U.nodes()[0],0);for(var V=!1;ee.size()>0;){if(R=ee.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,A)=>{var I=p(),_=x();A.exports=G;function G(J,B,L,ee){return U(J,B,L,ee||function(R){return J.outEdges(R)})}function U(J,B,L,ee){if(L===void 0)return I(J,B,L,ee);for(var R=!1,z=J.nodes(),V=0;V<z.length;V++){for(var K=ee(z[V]),ne=0;ne<K.length;ne++){var Z=K[ne],te=Z.v===z[V]?Z.v:Z.w,ie=te===Z.v?Z.w:Z.v;L({v:te,w:ie})<0&&(R=!0)}if(R)return _(J,B,L,ee)}return I(J,B,L,ee)}}),q=o((D,A)=>{A.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=Qt((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 l(u),u}enqueue(c){let u=this._sentinel;c._prev&&c._next&&l(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 l(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=Qt((e,r)=>{var s=ts().Graph,l=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 l),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}}),$n=Qt((e,r)=>{var s=ts().Graph;r.exports={addBorderNode:b,addDummyNode:l,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 l(P,q,F,D){for(var A=D;P.hasNode(A);)A=H(D);return F.dummy=q,P.setNode(A,F),A}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},A=P.edge(F);q.setEdge(F.v,F.w,{weight:D.weight+A.weight,minlen:Math.max(D.minlen,A.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(A=>{D[A.w]=(D[A.w]||0)+P.edge(A).weight}),D});return X(P.nodes(),q)}function f(P){let q=P.nodes().map(F=>{let D={};return P.inEdges(F).forEach(A=>{D[A.v]=(D[A.v]||0)+P.edge(A).weight}),D});return X(P.nodes(),q)}function m(P,q){let F=P.x,D=P.y,A=q.x-F,I=q.y-D,_=P.width/2,G=P.height/2;if(!A&&!I)throw new Error("Not possible to find intersection inside of the rectangle");let U,J;return Math.abs(I)*_>Math.abs(A)*G?(I<0&&(G=-G),U=G*A/I,J=G):(A<0&&(_=-_),U=_,J=_*I/A),{x:F+U,y:D+J}}function h(P){let q=M(T(P)+1).map(()=>[]);return P.nodes().forEach(F=>{let D=P.node(F),A=D.rank;A!==void 0&&(q[A][D.order]=F)}),q}function x(P){let q=P.nodes().map(D=>{let A=P.node(D).rank;return A===void 0?Number.MAX_VALUE:A}),F=S(Math.min,q);P.nodes().forEach(D=>{let A=P.node(D);Object.hasOwn(A,"rank")&&(A.rank-=F)})}function g(P){let q=P.nodes().map(_=>P.node(_).rank).filter(_=>_!==void 0),F=S(Math.min,q),D=[];P.nodes().forEach(_=>{let G=P.node(_).rank-F;D[G]||(D[G]=[]),D[G].push(_)});let A=0,I=P.graph().nodeRankFactor;Array.from(D).forEach((_,G)=>{_===void 0&&G%I!==0?--A:_!==void 0&&A&&_.forEach(U=>P.node(U).rank+=A)})}function b(P,q,F,D){let A={width:0,height:0};return arguments.length>=4&&(A.rank=F,A.order=D),l(P,"border",A,q)}function p(P,q=w){let F=[];for(let D=0;D<P.length;D+=q){let A=P.slice(D,D+q);F.push(A)}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 A=[];for(let I=P;D(I);I+=F)A.push(I);return A}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,[A,I])=>(D[A]=F(I,A),D),{})}function X(P,q){return P.reduce((F,D,A)=>(F[D]=q[A],F),{})}}),hz=Qt((e,r)=>{var s=fz(),l=$n().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,l("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=Qt((e,r)=>{var s=$n();r.exports={run:l,undo:c};function l(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)})}}),Lu=Qt((e,r)=>{var{applyWithChunking:s}=$n();r.exports={longestPath:l,slack:o};function l(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=Qt((e,r)=>{var s=ts().Graph,l=Lu().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)?l(m,b):-l(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)&&!l(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=l(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=Qt((e,r)=>{var s=sN(),l=Lu().slack,o=Lu().longestPath,c=ts().alg.preorder,u=ts().alg.postorder,f=$n().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,A=D?F.w:F.v;if(A!==$){var I=D===X,_=H.edge(F).weight;if(q+=I?_:-_,C(k,M,A)){var G=k.edge(M,A).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(A=>F===N(k,k.node(A.v),q)&&F!==N(k,k.node(A.w),q));return D.reduce((A,I)=>l(H,I)<l(H,A)?I:A)}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=Qt((e,r)=>{var s=Lu(),l=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=l;function m(x){l(x),o(x)}function h(x){c(x)}}),pz=Qt((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=l(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 l(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=Qt((e,r)=>{var s=$n();r.exports={run:l,cleanup:f};function l(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=Qt((e,r)=>{var s=$n();r.exports=l;function l(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=Qt((e,r)=>{r.exports={adjust:s,undo:l};function s(x){let g=x.graph().rankdir.toLowerCase();(g==="lr"||g==="rl")&&o(x)}function l(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=Qt((e,r)=>{var s=$n();r.exports=l;function l(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=Qt((e,r)=>{var s=$n().zipObject;r.exports=l;function l(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=Qt((e,r)=>{r.exports=s;function s(l,o=[]){return o.map(c=>{let u=l.inEdges(c);if(u.length){let f=u.reduce((m,h)=>{let x=l.edge(h),g=l.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=Qt((e,r)=>{var s=$n();r.exports=l;function l(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=Qt((e,r)=>{var s=$n();r.exports=l;function l(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=Qt((e,r)=>{var s=Nz(),l=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=l(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=Qt((e,r)=>{var s=ts().Graph,l=$n();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=l.uniqueId("_root")););return f}}),Tz=Qt((e,r)=>{r.exports=s;function s(l,o,c){let u={},f;c.forEach(m=>{let h=l.parent(m),x,g;for(;h;){if(x=l.parent(h),x?(g=u[x],u[x]=h):(g=f,f=h),g&&g!==h){o.setEdge(g,h);return}h=x}})}}),Az=Qt((e,r)=>{var s=jz(),l=wz(),o=Cz(),c=Ez(),u=Tz(),f=ts().Graph,m=$n();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 $=l(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))}}),_z=Qt((e,r)=>{var s=ts().Graph,l=$n();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 A=u(C,F),I=A?C.node(A).order:P;(A||F===q)&&(Y.slice(X,D+1).forEach(_=>{C.predecessors(_).forEach(G=>{let U=C.node(G),J=U.order;(J<$||I<J)&&!(U.dummy&&C.node(_).dummy)&&f(k,G,_)})}),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;l.range($,X).forEach(D=>{F=Y[D],C.node(F).dummy&&C.predecessors(F).forEach(A=>{let I=C.node(A);I.dummy&&(I.order<P||I.order>q)&&f(k,A,F)})})}function M(Y,$){let X=-1,P,q=0;return $.forEach((F,D)=>{if(C.node(F).dummy==="border"){let A=C.predecessors(F);A.length&&(P=C.node(A[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((A,I)=>$[A]-$[I]);let D=(F.length-1)/2;for(let A=Math.floor(D),I=Math.ceil(D);A<=I;++A){let _=F[A];Y[q]===q&&P<$[_]&&!m(k,q,_)&&(Y[_]=q,Y[q]=M[q]=M[_],P=$[_])}}})}),{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,A){let I=$.nodes().slice(),_={},G=I.pop();for(;G;){if(_[G])D(G);else{_[G]=!0,I.push(G);for(let U of A(G))I.push(U)}G=I.pop()}}function q(D){Y[D]=$.inEdges(D).reduce((A,I)=>Math.max(A,Y[I.v]+$.edge(I)),0)}function F(D){let A=$.outEdges(D).reduce((_,G)=>Math.min(_,Y[G.w]-$.edge(G)),Number.POSITIVE_INFINITY),I=C.node(D);A!==Number.POSITIVE_INFINITY&&I.borderType!==X&&(Y[D]=Math.max(Y[D],A))}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],A=M.edge(D,F);M.setEdge(D,F,Math.max($(C,q,P),A||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=l.applyWithChunking(Math.min,k),M=l.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-l.applyWithChunking(Math.min,q);$!=="l"&&(F=M-l.applyWithChunking(Math.max,q)),F&&(C[X]=l.mapValues(P,D=>D+F))})})}function w(C,N){return l.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=l.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=l.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=Qt((e,r)=>{var s=$n(),l=_z().positionX;r.exports=o;function o(u){u=s.asNonCompoundGraph(u),c(u),Object.entries(l(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=Qt((e,r)=>{var s=hz(),l=mz(),o=gz(),c=$n().normalizeRanks,u=pz(),f=$n().removeEmptyRanks,m=bz(),h=yz(),x=vz(),g=Az(),b=Mz(),p=$n(),w=ts().Graph;r.exports=S;function S(V,K={}){let ne=K.debugTiming?p.time:p.notime;return ne("layout",()=>{let Z=ne(" buildLayoutGraph",()=>P(V));return ne(" runLayout",()=>T(Z,ne,K)),ne(" updateInputGraph",()=>E(V,Z)),Z})}function T(V,K,ne){K(" makeSpaceForEdgeLabels",()=>q(V)),K(" removeSelfEdges",()=>B(V)),K(" acyclic",()=>s.run(V)),K(" nestingGraph.run",()=>m.run(V)),K(" rank",()=>o(p.asNonCompoundGraph(V))),K(" injectEdgeLabelProxies",()=>F(V)),K(" removeEmptyRanks",()=>f(V)),K(" nestingGraph.cleanup",()=>m.cleanup(V)),K(" normalizeRanks",()=>c(V)),K(" assignRankMinMax",()=>D(V)),K(" removeEdgeLabelProxies",()=>A(V)),K(" normalize.run",()=>l.run(V)),K(" parentDummyChains",()=>u(V)),K(" addBorderSegments",()=>h(V)),K(" order",()=>g(V,ne)),K(" insertSelfEdges",()=>L(V)),K(" adjustCoordinateSystem",()=>x.adjust(V)),K(" position",()=>b(V)),K(" positionSelfEdges",()=>ee(V)),K(" removeBorderNodes",()=>J(V)),K(" normalize.undo",()=>l.undo(V)),K(" fixupEdgeLabelCoords",()=>G(V)),K(" undoCoordinateSystem",()=>x.undo(V)),K(" translateGraph",()=>I(V)),K(" assignNodeIntersects",()=>_(V)),K(" reversePoints",()=>U(V)),K(" acyclic.undo",()=>s.undo(V))}function E(V,K){V.nodes().forEach(ne=>{let Z=V.node(ne),te=K.node(ne);Z&&(Z.x=te.x,Z.y=te.y,Z.order=te.order,Z.rank=te.rank,K.children(ne).length&&(Z.width=te.width,Z.height=te.height))}),V.edges().forEach(ne=>{let Z=V.edge(ne),te=K.edge(ne);Z.points=te.points,Object.hasOwn(te,"x")&&(Z.x=te.x,Z.y=te.y)}),V.graph().width=K.graph().width,V.graph().height=K.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 K=new w({multigraph:!0,compound:!0}),ne=z(V.graph());return K.setGraph(Object.assign({},N,R(ne,C),p.pick(ne,k))),V.nodes().forEach(Z=>{let te=z(V.node(Z)),ie=R(te,H);Object.keys(M).forEach(ye=>{ie[ye]===void 0&&(ie[ye]=M[ye])}),K.setNode(Z,ie),K.setParent(Z,V.parent(Z))}),V.edges().forEach(Z=>{let te=z(V.edge(Z));K.setEdge(Z,Object.assign({},$,R(te,Y),p.pick(te,X)))}),K}function q(V){let K=V.graph();K.ranksep/=2,V.edges().forEach(ne=>{let Z=V.edge(ne);Z.minlen*=2,Z.labelpos.toLowerCase()!=="c"&&(K.rankdir==="TB"||K.rankdir==="BT"?Z.width+=Z.labeloffset:Z.height+=Z.labeloffset)})}function F(V){V.edges().forEach(K=>{let ne=V.edge(K);if(ne.width&&ne.height){let Z=V.node(K.v),te={rank:(V.node(K.w).rank-Z.rank)/2+Z.rank,e:K};p.addDummyNode(V,"edge-proxy",te,"_ep")}})}function D(V){let K=0;V.nodes().forEach(ne=>{let Z=V.node(ne);Z.borderTop&&(Z.minRank=V.node(Z.borderTop).rank,Z.maxRank=V.node(Z.borderBottom).rank,K=Math.max(K,Z.maxRank))}),V.graph().maxRank=K}function A(V){V.nodes().forEach(K=>{let ne=V.node(K);ne.dummy==="edge-proxy"&&(V.edge(ne.e).labelRank=ne.rank,V.removeNode(K))})}function I(V){let K=Number.POSITIVE_INFINITY,ne=0,Z=Number.POSITIVE_INFINITY,te=0,ie=V.graph(),ye=ie.marginx||0,ke=ie.marginy||0;function Me(Ie){let Le=Ie.x,Qe=Ie.y,Ae=Ie.width,Ge=Ie.height;K=Math.min(K,Le-Ae/2),ne=Math.max(ne,Le+Ae/2),Z=Math.min(Z,Qe-Ge/2),te=Math.max(te,Qe+Ge/2)}V.nodes().forEach(Ie=>Me(V.node(Ie))),V.edges().forEach(Ie=>{let Le=V.edge(Ie);Object.hasOwn(Le,"x")&&Me(Le)}),K-=ye,Z-=ke,V.nodes().forEach(Ie=>{let Le=V.node(Ie);Le.x-=K,Le.y-=Z}),V.edges().forEach(Ie=>{let Le=V.edge(Ie);Le.points.forEach(Qe=>{Qe.x-=K,Qe.y-=Z}),Object.hasOwn(Le,"x")&&(Le.x-=K),Object.hasOwn(Le,"y")&&(Le.y-=Z)}),ie.width=ne-K+ye,ie.height=te-Z+ke}function _(V){V.edges().forEach(K=>{let ne=V.edge(K),Z=V.node(K.v),te=V.node(K.w),ie,ye;ne.points?(ie=ne.points[0],ye=ne.points[ne.points.length-1]):(ne.points=[],ie=te,ye=Z),ne.points.unshift(p.intersectRect(Z,ie)),ne.points.push(p.intersectRect(te,ye))})}function G(V){V.edges().forEach(K=>{let ne=V.edge(K);if(Object.hasOwn(ne,"x"))switch((ne.labelpos==="l"||ne.labelpos==="r")&&(ne.width-=ne.labeloffset),ne.labelpos){case"l":ne.x-=ne.width/2+ne.labeloffset;break;case"r":ne.x+=ne.width/2+ne.labeloffset;break}})}function U(V){V.edges().forEach(K=>{let ne=V.edge(K);ne.reversed&&ne.points.reverse()})}function J(V){V.nodes().forEach(K=>{if(V.children(K).length){let ne=V.node(K),Z=V.node(ne.borderTop),te=V.node(ne.borderBottom),ie=V.node(ne.borderLeft[ne.borderLeft.length-1]),ye=V.node(ne.borderRight[ne.borderRight.length-1]);ne.width=Math.abs(ye.x-ie.x),ne.height=Math.abs(te.y-Z.y),ne.x=ie.x+ne.width/2,ne.y=Z.y+ne.height/2}}),V.nodes().forEach(K=>{V.node(K).dummy==="border"&&V.removeNode(K)})}function B(V){V.edges().forEach(K=>{if(K.v===K.w){var ne=V.node(K.v);ne.selfEdges||(ne.selfEdges=[]),ne.selfEdges.push({e:K,label:V.edge(K)}),V.removeEdge(K)}})}function L(V){var K=p.buildLayerMatrix(V);K.forEach(ne=>{var Z=0;ne.forEach((te,ie)=>{var ye=V.node(te);ye.order=ie+Z,(ye.selfEdges||[]).forEach(ke=>{p.addDummyNode(V,"selfedge",{width:ke.label.width,height:ke.label.height,rank:ye.rank,order:ie+ ++Z,e:ke.e,label:ke.label},"_se")}),delete ye.selfEdges})})}function ee(V){V.nodes().forEach(K=>{var ne=V.node(K);if(ne.dummy==="selfedge"){var Z=V.node(ne.e.v),te=Z.x+Z.width/2,ie=Z.y,ye=ne.x-te,ke=Z.height/2;V.setEdge(ne.e,ne.label),V.removeNode(K),ne.label.points=[{x:te+2*ye/3,y:ie-ke},{x:te+5*ye/6,y:ie-ke},{x:te+ye,y:ie},{x:te+5*ye/6,y:ie+ke},{x:te+2*ye/3,y:ie+ke}],ne.label.x=ne.x,ne.label.y=ne.y}})}function R(V,K){return p.mapValues(p.pick(V,K),Number)}function z(V){var K={};return V&&Object.entries(V).forEach(([ne,Z])=>{typeof ne=="string"&&(ne=ne.toLowerCase()),K[ne]=Z}),K}}),Oz=Qt((e,r)=>{var s=$n(),l=ts().Graph;r.exports={debugOrdering:o};function o(c){let u=s.buildLayerMatrix(c),f=new l({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=Qt((e,r)=>{r.exports="2.0.4"}),zz=Qt((e,r)=>{r.exports={graphlib:ts(),layout:Dz(),debug:Oz(),util:{time:$n().time,notime:$n().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,l=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?`${l.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${l.bg} ${l.border}`}`,children:[t.jsx(wa,{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 ${l.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(wa,{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(wa,{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(wa,{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 Cm=200,Em=80;function Tv(e,r,s="TB"){const l=new kv.graphlib.Graph;l.setDefaultEdgeLabel(()=>({})),l.setGraph({rankdir:s,nodesep:40,ranksep:60});for(const o of e)l.setNode(o.id,{width:Cm,height:Em});for(const o of r)l.setEdge(o.source,o.target);return kv.layout(l),e.map(o=>{const c=l.node(o.id);return{...o,position:{x:(c?.x??0)-Cm/2,y:(c?.y??0)-Em/2}}})}function qz(e,r){const s=new Map,l=new Map;for(const u of e)l.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 l=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+Cm),S=Math.min(S,E.position.y),T=Math.max(T,E.position.y+Em);for(const E of b)E.position.x-=p,E.position.y-=S;return{nodes:b,w:w-p,h:T-S}});l.sort((g,b)=>b.h-g.h);const o=60,c=l.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 l){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 l=new Set,o=[r];for(;o.length>0;){const c=o.pop();if(c===s)return!0;if(l.has(c))continue;l.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"}}],Fh=new Set(oo.map(e=>e.id)),Yz=1440*60*1e3,Av=e=>e.status==="completed"&&e.updatedAt&&Date.now()-new Date(e.updatedAt).getTime()>Yz;function Gz({tasks:e,requirements:r=[],agents:s,showArchived:l,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(Fh)),[S,T]=j.useState(l??!1),E=l??S,C=j.useCallback(Z=>{const te=typeof Z=="function"?Z(E):Z;T(te),o?.(te)},[E,o]);j.useEffect(()=>{l!==void 0&&T(l)},[l]);const N=j.useMemo(()=>e.filter(Z=>Av(Z)).length,[e]),k=j.useMemo(()=>{const Z=new Set;for(const te of oo)if(p.has(te.id))for(const ie of te.statuses)Z.add(ie);return Z},[p]),H=j.useMemo(()=>{const Z=new Set;for(const te of e)for(const ie of oo)if(ie.statuses.has(te.status)){Z.add(ie.id);break}for(const te of r){const ie=Ev[te.status];ie&&Z.add(ie)}return oo.filter(te=>Z.has(te.id))},[e,r]),M=j.useCallback(Z=>{w(te=>{const ie=new Set(te);return ie.has(Z)?ie.delete(Z):ie.add(Z),ie})},[]),Y=j.useCallback((Z,te="success")=>{x({msg:Z,type:te}),setTimeout(()=>x(null),2500)},[]),$=j.useMemo(()=>{const Z=new Map;for(const te of s)Z.set(te.id,te.name);return Z},[s]),X=j.useMemo(()=>{const Z=new Map;for(const te of e)Z.set(te.id,te);return Z},[e]),P=j.useMemo(()=>{const Z=new Map;for(const te of r)Z.set(te.id,te);return Z},[r]),q=m?"#94a3b8":"#6b7280",F=j.useCallback((Z,te,ie)=>({id:`${Z}->${te}`,source:Z,target:te,animated:ie==="blocked",markerEnd:{type:Xl.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:A}=j.useMemo(()=>{const Z=e.filter(Ae=>k.has(Ae.status)&&(E||!Av(Ae))),te=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(te.map(Ae=>Ae.id)),ye=new Set;for(const Ae of oo)p.has(Ae.id)&&ye.add(Ae.id);const ke=r.filter(Ae=>{const Ge=Ev[Ae.status];return Ge&&ye.has(Ge)});for(const Ae of ke){const Ge=`req-${Ae.id}`;te.push({id:Ge,type:"requirement",data:{req:Ae},position:{x:0,y:0}}),ie.add(Ge)}const Me=[];for(const Ae of Z)if(Ae.blockedBy)for(const Ge of Ae.blockedBy)ie.has(Ge)&&Me.push(F(Ge,Ae.id,Ae.status));const Ie=new Set,Le=(Ae,Ge)=>{const ut=`${Ae}->${Ge}`;Ie.has(ut)||(Ie.add(ut),Me.push({id:ut,source:Ae,target:Ge,markerEnd:{type:Xl.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ae of ke){const Ge=`req-${Ae.id}`;for(const ut of Ae.taskIds)ie.has(ut)&&Le(Ge,ut)}for(const Ae of Z)if(Ae.requirementId){const Ge=`req-${Ae.requirementId}`;ie.has(Ge)&&Le(Ge,Ae.id)}return{initialNodes:Vz(te,Me),initialEdges:Me}},[e,r,$,X,F,k,p,E]),[I,_,G]=zR(D),[U,J,B]=LR(A),L=j.useRef(null);j.useEffect(()=>{_(D),J(A),requestAnimationFrame(()=>{L.current?.fitView({padding:.2,duration:300})})},[D,A,_,J]);const ee=j.useCallback((Z,te)=>{if(te.id.startsWith("req-")){const ie=P.get(te.id.slice(4));ie&&u&&u(ie)}else{const ie=X.get(te.id);ie&&c&&c(ie)}},[X,P,c,u]),R=j.useCallback(async Z=>{const{source:te,target:ie}=Z;if(!te||!ie||te===ie)return;const ye=X.get(ie);if(!ye)return;if(ye.blockedBy?.includes(te)){Y("Dependency already exists","error");return}if(Fz(X,te,ie)){Y("Cannot add: would create a cycle","error");return}const ke=[...ye.blockedBy??[],te];try{await le.tasks.update(ie,{blockedBy:ke}),Y("Dependency added"),f?.()}catch(Me){Y(`Failed: ${Me instanceof Error?Me.message:String(Me)}`,"error")}},[X,Y,f]),z=j.useCallback((Z,te)=>{b(te)},[]),V=j.useCallback(async()=>{if(!g)return;const Z=X.get(g.target);if(!Z){b(null);return}const te=(Z.blockedBy??[]).filter(ie=>ie!==g.source);try{await le.tasks.update(g.target,{blockedBy:te}),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 K=g?X.get(g.source):null,ne=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:ee,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(iz,{nodeColor:Z=>{const te=Z.data?.task,ie=te?.status;return te?.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 te=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 ${te?`${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<Fh.size&&t.jsx("button",{onClick:()=>{w(new Set(Fh)),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:ne?.title??g.target.slice(-8)})," ","will no longer be blocked by"," ",t.jsx("span",{className:"text-fg-secondary font-medium",children:K?.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[l,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=xs();j.useEffect(()=>{le.teams.list().then($=>w($.teams)).catch(()=>{})},[]);const M=j.useCallback(async $=>{if($?.preventDefault(),k(!0),!(!l.trim()||S)){T(!0),C("");try{const X=f.trim()?[{url:f.trim(),defaultBranch:h.trim()||"main"}]:[],P=await le.projects.create({name:l.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)}},[l,c,f,h,g,e,S,r]),Y=N&&!l.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:l,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:!l.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 Wl(e,r,s){if(!e)return null;const l=r.find(c=>c.id===e);if(l)return l.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:l}){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:l}):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:l??"Click to edit"})})}function Zz({value:e,onSave:r,className:s,placeholder:l}){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:l,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:l??"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"},lN={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"}},Tm={urgent:"border-l-red-500",high:"border-l-amber-500",medium:"border-l-blue-500",low:"border-l-gray-500"},iN={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"},_v=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,l)=>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"},l):null)]})});function Wz(e){return e.kind==="log"?e.executionRound??1:0}function eL(e){const r=[];let s=null,l=[],o=1;for(const c of e){if(c.kind==="comment"){s?s.items.push(c):l.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:[...l]},l=[],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")),l.length>0&&r.length>0&&r[r.length-1].items.push(...l),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:[...l,...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 l=Math.floor(s/1e3);if(l<60)return`${l}s`;const o=Math.floor(l/60);return o<60?`${o}m ${l%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:l,isLive:o,streamingText:c,isExecuting:u,totalRounds:f}){const m=Mv[r.status]??Mv.running,h=tL(r.startTime,r.endTime),x=Km(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(_v,{comment:p.entry},`pc-${p.entry.id}`):null)}),t.jsxs("button",{onClick:l,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(_v,{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(wu,{label:"Thinking"})]})]})});function rL({taskId:e,isVisible:r,isRunning:s,authUser:l}){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 K=V,ne=()=>{F.current=K.scrollHeight-K.scrollTop-K.clientHeight<80};return K.addEventListener("scroll",ne,{passive:!0}),()=>K.removeEventListener("scroll",ne)},[]),j.useEffect(()=>{g(s)},[s]),j.useEffect(()=>{p(!0),Promise.all([le.tasks.getLogs(e).catch(()=>({logs:[]})),le.tasks.getComments(e).catch(()=>({comments:[]}))]).then(([z,V])=>{c(z.logs),f(V.comments),p(!1)})},[e]),j.useEffect(()=>{const z=Sn.on("task:log",ne=>{const Z=ne.payload;if(Z.taskId!==e)return;const te={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=>te.id&&ie.some(ye=>ye.id===te.id)||!te.id&&ie.some(ye=>ye.seq===te.seq&&ye.type===te.type)?ie:[...ie,te]),te.type==="text"&&h(""),te.type==="status"&&(te.content==="started"||te.content==="resumed"?g(!0):["completed","failed","cancelled","execution_finished"].includes(te.content)&&g(!1)),te.type==="error"&&g(!1)}),V=Sn.on("task:log:delta",ne=>{const Z=ne.payload;Z.taskId===e&&h(te=>te+Z.text)}),K=Sn.on("task:comment",ne=>{const Z=ne.payload;if(Z.taskId!==e)return;const te=Z.comment;f(ie=>ie.some(ye=>ye.id===te.id)?ie:[...ie,te])});return()=>{z(),V(),K()}},[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]),A=j.useMemo(()=>{const z=o.map(Z=>({log:Z,entry:Jm(Z)})).filter(Z=>Z.entry!=null),V=bo(z.map(Z=>Z.entry)),K=new Set(V),ne=[...z.filter(Z=>K.has(Z.entry)).map(({log:Z,entry:te})=>({kind:"log",entry:te,time:new Date(te.timestamp??te.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 ne.sort((Z,te)=>Z.time-te.time),ne},[o,u,D]),I=j.useMemo(()=>eL(A),[A]);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 _=j.useCallback(z=>{H(V=>{const K=new Set(V);return K.has(z)?K.delete(z):K.add(z),K})},[]),G=z=>{const V=z.target.files;if(V){for(const K of Array.from(V)){if(!K.type.startsWith("image/"))continue;const ne=new FileReader;ne.onload=()=>{N(Z=>[...Z,{type:"image",url:ne.result,name:K.name}])},ne.readAsDataURL(K)}z.target.value=""}},U=async()=>{if(!(!w.trim()&&C.length===0)){E(!0);try{const z=await le.tasks.addComment(e,w,l?.name,C.length>0?C:void 0,l?.id);z.comment&&f(V=>V.some(K=>K.id===z.comment.id)?V:[...V,z.comment]),S(""),N([])}catch{}E(!1)}},J=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(K=>K.filter((ne,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.']})]})}),J]});const B=Math.ceil(I.length/$),L=M*$,ee=(M-1)*$,R=I.slice(Math.max(0,I.length-L),I.length-ee).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:()=>_(z.id),isLive:V&&x,streamingText:V?m:void 0,isExecuting:V?x:!1,totalRounds:I.length},z.id)}),t.jsx("div",{ref:q})]}),J]})}function sL({filePath:e,onClose:r}){const[s,l]=j.useState(null),[o,c]=j.useState(null),[u,f]=j.useState(!0);j.useEffect(()=>{f(!0),c(null),le.files.preview(e).then(h=>l(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:l,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,A]=j.useState(!1),[I,_]=j.useState(e.description),[G,U]=j.useState(!1),[J,B]=j.useState(""),[L,ee]=j.useState(1),[R,z]=j.useState(1),[V,K]=j.useState(!1),ne=xs(),Z=20,te=j.useCallback(async()=>{try{const he=await le.tasks.listSubtasks(e.id);x(he.subtasks)}catch{}},[e.id]);j.useEffect(()=>{te()},[te]);const ie=async he=>{if(!N){k(!0);try{await he(),f(),await te()}catch($e){P(String($e).replace("Error: ",""))}finally{k(!1)}}},ye=he=>ie(()=>le.tasks.update(e.id,{priority:he})),ke=he=>ie(()=>le.tasks.assign(e.id,he||null)),Me=he=>ie(()=>le.tasks.update(e.id,{projectId:he||null})),Ie=async()=>{if(!N){k(!0);try{await le.tasks.pause(e.id),f()}finally{k(!1)}}},Le=async()=>{if(!Y){$(!0),P(null),M("logs");try{await le.tasks.resume(e.id),f()}catch(he){P(String(he).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{$(!1)}}},Qe=async()=>{g.trim()&&(await le.tasks.createSubtask(e.id,g.trim()),b(""),w(!1),te(),f())},Ae=async he=>{he.status==="completed"?await le.tasks.cancelSubtask(e.id,he.id):await le.tasks.completeSubtask(e.id,he.id),te(),f()},Ge=async he=>{await le.tasks.deleteSubtask(e.id,he.id),T(null),te(),f()},ut=async()=>{if(!N){k(!0);try{await le.tasks.updateStatus(e.id,"pending_approval"),f()}finally{k(!1)}}},_t=async()=>{if(!N){k(!0),P(null),M("logs");try{await le.tasks.retry(e.id),f()}catch(he){P(String(he).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{k(!1)}}},oe=async()=>{if(!Y){$(!0),P(null),M("logs");try{await le.tasks.runNow(e.id),f()}catch(he){P(String(he).replace("Error: API error: 400","Server error").replace("Error: ","")),f()}finally{$(!1)}}};j.useEffect(()=>Sn.on("task:log:delta",$e=>{$e.payload.taskId===e.id&&M("logs")}),[e.id]);const Oe=j.useRef(f);Oe.current=f,j.useEffect(()=>Sn.on("task:update",$e=>{$e.payload.taskId===e.id&&(te(),Oe.current())}),[e.id,te]);const xt=h.filter(he=>he.status==="completed").length,vt=e.status==="in_progress",Gt=e.status==="blocked",ve=e.status==="completed",De=e.status==="failed",He=e.status==="cancelled",Ye=e.status==="archived",tt=ve||De||He||Ye,Dt=e.taskType==="scheduled"&&!!e.scheduleConfig,$t=Dt&&!!e.scheduleConfig?.paused,bt=s.find(he=>he.id===e.projectId),yt=l.find(he=>he.id===e.requirementId);return r.find(he=>he.id===e.assignedAgentId),t.jsxs("div",{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3 ${ne?"pb-[4.5rem]":""}`,onClick:u,children:[t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl flex flex-col shadow-2xl ${ne?"w-full max-h-full":"w-[780px] max-w-[95vw] max-h-[88vh]"}`,onClick:he=>he.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 he=Jz[e.status];return he?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap ${he.cls}`,children:he.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:he=>_(he.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:()=>{A(!1),_(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(()=>le.tasks.update(e.id,{description:I})),A(!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:ne&&!V?"line-clamp-3":"",children:t.jsx(er,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),ne&&e.description.length>150&&t.jsx("button",{onClick:()=>K(!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:()=>{_(e.description),A(!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"})]})}),(bt||yt)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[bt&&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"}),bt.name]}),yt&&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"}),yt.title.length>40?yt.title.slice(0,40)+"…":yt.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(he=>{const $e=o.find(dt=>dt.id===he),ht=$e&&($e.status==="completed"||$e.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${ht?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:ht?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${ht?"line-through opacity-60":""}`,children:$e?$e.title.slice(0,30):he.slice(-8)}),!tt&&t.jsx("button",{onClick:async()=>{const dt=(e.blockedBy??[]).filter(gt=>gt!==he);await le.tasks.update(e.id,{blockedBy:dt}),f()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:"Remove dependency",children:"×"})]},he)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:"No dependencies"}),!tt&&t.jsxs("select",{value:"",onChange:async he=>{const $e=he.target.value;if(!$e)return;const ht=[...e.blockedBy??[],$e];await le.tasks.update(e.id,{blockedBy:ht}),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(he=>he.id!==e.id&&!(e.blockedBy??[]).includes(he.id)).map(he=>t.jsx("option",{value:he.id,children:he.title},he.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",vt&&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 he=(e.deliverables??[]).filter($e=>$e.type!=="branch"&&typeof $e.reference=="string"&&$e.reference.length>0).length;return he>0?t.jsx("span",{className:"text-[10px] text-fg-tertiary font-normal",children:he}):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:he=>{Me(he.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(he=>t.jsx("option",{value:he.id,children:he.name},he.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:he=>ie(()=>le.tasks.update(e.id,{requirementId:he.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"}),l.filter(he=>!e.projectId||he.projectId===e.projectId).map(he=>t.jsx("option",{value:he.id,children:he.title},he.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:he=>{ke(he.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(he=>t.jsxs("option",{value:he.id,children:[he.name," (",he.status,")"]},he.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:he=>{he.target.value&&he.target.value!==e.reviewerAgentId&&ie(()=>le.tasks.update(e.id,{reviewerAgentId:he.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(he=>t.jsx("option",{value:he.id,children:he.name},he.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:he=>{ye(he.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:Wl(e.createdBy,r,c)??e.createdBy})]}),e.updatedBy&&t.jsxs("span",{children:["Updated by ",t.jsx("span",{className:"text-fg-secondary",children:Wl(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:[xt,"/",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(he=>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(he)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${he.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:he.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 ${he.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:he.title}),t.jsx("button",{onClick:()=>T(he),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},he.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:he=>b(he.target.value),onKeyDown:he=>{he.key==="Enter"&&Qe(),he.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:()=>{Qe()},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 he=(e.deliverables??[]).filter(dt=>dt.type!=="branch"&&typeof dt.reference=="string"&&dt.reference.length>0);if(he.length===0)return null;const $e={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"},ht=he.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:["(",he.length,")"]})]}),he.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:ht.map((dt,gt)=>{const jt=dt.reference.split("/").pop()??dt.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 ${$e[dt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:dt.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>F(dt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:dt.reference,children:jt}),dt.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:dt.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:dt.reference})]})]},gt)})})]})})(),e.notes&&e.notes.length>0&&(()=>{const he=[...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:he.map(($e,ht)=>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:$e,className:"text-xs text-fg-secondary"})},ht))})]})})()]})]}),H==="notes"&&t.jsx("div",{className:"px-6 py-4",children:e.notes&&e.notes.length>0?(()=>{const he=[...e.notes].reverse(),$e=Math.ceil(he.length/Z),ht=he.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,")"]})]}),$e>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(dt=>dt-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,"/",$e]}),t.jsx("button",{disabled:R>=$e,onClick:()=>z(dt=>dt+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:ht.map((dt,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:dt,className:"text-xs text-fg-secondary"})},gt))})]})})():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 he=(e.deliverables??[]).filter(gt=>gt.type!=="branch"&&typeof gt.reference=="string"&&gt.reference.length>0);if(he.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:"No deliverables yet."});const $e={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"},ht=Math.ceil(he.length/Z),dt=he.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:["(",he.length,")"]})]}),ht>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:L<=1,onClick:()=>ee(gt=>gt-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,"/",ht]}),t.jsx("button",{disabled:L>=ht,onClick:()=>ee(gt=>gt+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:dt.map((gt,jt)=>{const en=gt.reference.split("/").pop()??gt.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 ${$e[gt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:gt.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>F(gt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:gt.reference,children:en}),gt.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:gt.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:gt.reference})]})]},jt)})})]})})()})]}),Dt&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${$t?"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:$t?"text-amber-600":"text-brand-500",children:$t?"⏸ 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"}),!$t&&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 he=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(he<=0)return"due now";const $e=Math.floor(he/6e4);if($e<60)return`in ${$e}m`;const ht=Math.floor($e/60);return ht<24?`in ${ht}h ${$e%60}m`:`in ${Math.floor(ht/24)}d ${ht%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 he=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),$e=Math.floor(he/6e4);if($e<1)return"just now";if($e<60)return`${$e}m ago`;const ht=Math.floor($e/60);return ht<24?`${ht}h ${$e%60}m ago`:`${Math.floor(ht/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(()=>le.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(()=>le.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(()=>le.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:J,onChange:he=>B(he.target.value),onKeyDown:he=>{he.key==="Enter"&&J.trim()&&(ie(()=>le.tasks.revision(e.id,J.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(()=>le.tasks.revision(e.id,J.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"})]}),vt&&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:()=>{_t()},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"]})]}),Gt&&t.jsx("button",{onClick:()=>{Le()},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"]})}),De&&t.jsxs("button",{onClick:()=>{_t()},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"]}),Dt&&(ve||De)&&t.jsx("button",{onClick:()=>{oe()},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"]})}),Dt&&!vt&&($t?t.jsx("button",{onClick:()=>{ie(()=>le.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(()=>le.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"})),ve&&t.jsx("button",{onClick:()=>ie(()=>le.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"}),tt&&t.jsx("button",{onClick:()=>{ut()},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"}),!tt&&e.status!=="pending_approval"&&t.jsx("button",{onClick:async()=>{const{count:he}=await le.tasks.getDependentCount(e.id);he>0?C({dependentCount:he}):ie(()=>le.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:()=>{Ge(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:he=>he.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(()=>le.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(()=>le.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 lL({project:e,tasks:r,requirements:s,agents:l,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(()=>l.filter(b=>x.has(b.id)),[l,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 Iu={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"},iL={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 l=Math.floor(s/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function Ov({row:e,idx:r,dragIdx:s,agentMap:l,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"?l.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:Iu[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 ${iN[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:l,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 A=new Date(F.data.updatedAt??0).getTime();return new Date(D.data.updatedAt??0).getTime()-A});else{const F=D=>iL[D.data.priority]??2;q.sort((D,A)=>{const I=F(D),_=F(A);return I!==_?I-_:new Date(A.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 le.tasks.updateStatus(q.data.id,F):await le.requirements.updateStatus(q.data.id,F),u()}catch{}},S=async(q,F)=>{try{q.kind==="task"?await le.tasks.update(q.data.id,{priority:F}):await le.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 A=To.find(I=>I.id===F);if(A){try{if(D.kind==="task"){if(D.data.status==="pending_approval")return;await le.tasks.updateStatus(D.data.id,A.dropStatus)}else{const I=cN[F];I&&await le.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(l.map(q=>[q.id,q])),[l]),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 A=p[D];F.set(A,D);const I=q.get(A.group)??[];I.push(A),q.set(A.group,I)}return{rowsByGroup:q,rowIndexMap:F}},[p]),P=j.useMemo(()=>{if(f!=="status")return null;const q=new Set(p.map(A=>A.group)),F=[],D=new Set;q.has("failed")&&(F.push("failed"),D.add("failed"));for(const A of M)F.push(A),D.add(A);for(const A of p)D.has(A.group)||(F.push(A.group),D.add(A.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(A=>A.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:A=>C(A,q),onDragLeave:()=>b(null),onDrop:A=>{N(A,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(A=>t.jsx(Ov,{row:A,idx:X.get(A)??0,dragIdx:h,agentMap:k,projMap:H,onTaskClick:o,onReqClick:c,onRowDragStart:T,onRowDragEnd:E,handleStatusChange:w,handlePriorityChange:S},`${A.kind}-${A.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=xs(),[s,l]=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(()=>{jt(u??""),$t(!0)},[u]),[Y,$]=j.useState(!1),[X,P]=j.useState(!1),[q,F]=j.useState(""),[D,A]=j.useState(""),[I,_]=j.useState("medium"),[G,U]=j.useState(""),[J,B]=j.useState(""),[L,ee]=j.useState(""),[R,z]=j.useState(""),[V,K]=j.useState([]),[ne,Z]=j.useState("standard"),[te,ie]=j.useState("4h"),[ye,ke]=j.useState(null),[Me,Ie]=j.useState(null),[Le,Qe]=j.useState(new Set),[Ae,Ge]=j.useState(new Set),ut=j.useRef(new Set),_t=j.useRef(new Set),[oe,Oe]=j.useState(null),[xt,vt]=j.useState("backlog"),[Gt,ve]=j.useState(!1),[De,He]=j.useState(!1),Ye=j.useRef(null),tt=j.useRef(null),[Dt,$t]=j.useState(!1),[bt,yt]=j.useState(""),[he,$e]=j.useState(""),[ht,dt]=j.useState("medium"),[gt,jt]=j.useState(""),[en,hn]=j.useState(null),[sn,bn]=j.useState(""),Nt=se=>{N(se),setTimeout(()=>N(""),3e3)},Q=s.find(se=>se.id===u)??null;j.useEffect(()=>{_t.current=Ae},[Ae]);const ue=j.useCallback(async()=>{try{const{projects:se}=await le.projects.list();l(se)}catch{}},[]),Se=j.useCallback(async()=>{const se={};o==="project"&&u&&(se.projectId=u);try{const{board:Re}=await le.tasks.board(se);h(Re)}catch{}},[o,u]),qe=j.useCallback(async()=>{try{const{agents:se}=await le.agents.list();g(se)}catch{}},[]),et=j.useCallback(async()=>{try{const{users:se}=await le.users.list(e?.orgId);p(se)}catch{}},[e?.orgId]),Ue=j.useCallback(async()=>{try{const{requirements:se}=await le.requirements.list({});S(se)}catch{}},[]),yn=j.useCallback(async()=>{await Promise.all([ue(),Se(),qe(),et(),Ue()]),E(!1)},[ue,Se,qe,et,Ue]);j.useEffect(()=>{yn()},[yn]);const mn=j.useRef(ye);mn.current=ye,j.useEffect(()=>{const Re=setInterval(()=>{Se(),qe(),Ue()},ye?6e4:15e3),Pe=Sn.on("task:update",re=>{mn.current||(Se(),Ue());const pe=re?.payload;pe?.taskId&&ke(we=>{if(!we||we.id!==pe.taskId)return we;const Ee={};return typeof pe.status=="string"&&(Ee.status=pe.status),Array.isArray(pe.deliverables)&&(Ee.deliverables=pe.deliverables),Array.isArray(pe.notes)&&(Ee.notes=pe.notes),pe.result!==void 0&&(Ee.result=pe.result),{...we,...Ee}})});return()=>{clearInterval(Re),Pe()}},[Se,qe,Ue,ye]);const Mt=j.useRef(m);Mt.current=m,j.useEffect(()=>{const se=localStorage.getItem("markus_nav_openTask");if(!se)return;const Pe=Object.values(m).flat().find(re=>re.id===se);Pe&&(ke(Pe),localStorage.removeItem("markus_nav_openTask"))},[m]),j.useEffect(()=>{const se=window.location.hash.slice(1).split("/");if(se[0]==="projects"&&se[1])_n(se[1]);else{const Re=localStorage.getItem("markus_nav_projectId");Re&&(localStorage.removeItem("markus_nav_projectId"),_n(Re))}},[]),j.useEffect(()=>{const se=()=>{const Pe=window.location.hash.slice(1).split("/");Pe[0]==="projects"&&Pe[1]?_n(Pe[1]):Pe[0]==="projects"&&Hn()},Re=Pe=>{const re=Pe.detail;if(re.page==="tasks"||re.page==="projects"){if(re.params?.openTask){const we=Object.values(Mt.current).flat().find(Ee=>Ee.id===re.params.openTask);we&&ke(we)}re.params?.projectId&&_n(re.params.projectId),!re.params?.projectId&&!re.params?.openTask&&Hn()}};return window.addEventListener("markus:navigate",Re),window.addEventListener("hashchange",se),()=>{window.removeEventListener("markus:navigate",Re),window.removeEventListener("hashchange",se)}},[]);const _n=se=>{_t.current.size>0&&(ut.current=new Set(_t.current)),Ge(new Set),f(se),c("project"),H(!1),history.replaceState(null,"","#projects/"+se)},Hn=()=>{Ge(ut.current),f(null),c("all"),H(!1),history.replaceState(null,"","#projects")},Mn=()=>{$(!1),Nt("Project created"),ue()},an=async se=>{if(confirm("Delete this project and unlink all its tasks?"))try{await le.projects.delete(se),u===se&&Hn(),Nt("Project deleted"),ue(),Se()}catch(Re){Nt(`Error: ${Re}`)}},ln=async()=>{if(!q||!G||!J)return;if(G===J){Nt("Assigned agent and reviewer must be different");return}const se=L||void 0,Re=R||void 0;try{await le.tasks.create(q,D,G,J,I,se,V.length>0?V:void 0,Re,ne!=="standard"?ne:void 0,ne==="scheduled"?{every:te}:void 0),F(""),A(""),K([]),z(""),Z("standard"),ie("4h"),P(!1),Se()}catch(Pe){Nt(`Error creating task: ${Pe}`)}},vn=()=>{Se(),ye&&setTimeout(()=>{const se={};o==="project"&&u&&(se.projectId=u),le.tasks.board(se).then(Re=>{const re=Object.values(Re.board).flat().find(pe=>pe.id===ye.id);ke(re||null)}).catch(()=>{})},150)},Pn=async()=>{if(bt.trim()){if(!gt){Nt("Please select a project for this requirement");return}try{await le.requirements.create({title:bt,description:he,priority:ht,projectId:gt}),Nt("Requirement created"),yt(""),$e(""),$t(!1),Ue()}catch(se){Nt(`Error: ${se}`)}}},be=async se=>{try{await le.requirements.approve(se),Nt("Requirement approved"),Ue(),Se()}catch(Re){Nt(`Error: ${Re}`)}},Ke=async()=>{if(en)try{await le.requirements.reject(en,sn),Nt("Requirement rejected"),hn(null),bn(""),Ue()}catch(se){Nt(`Error: ${se}`)}},kt=async se=>{try{await le.requirements.delete(se),Nt("Requirement cancelled"),Ue()}catch(Re){Nt(`Error: ${Re}`)}},Et=(se,Re)=>{Ye.current=Re,tt.current=null,se.dataTransfer.effectAllowed="move",se.dataTransfer.setData("text/plain",`task:${Re.id}`),se.currentTarget.style.opacity="0.4"},jn=(se,Re)=>{tt.current=Re,Ye.current=null,se.dataTransfer.effectAllowed="move",se.dataTransfer.setData("text/plain",`req:${Re.id}`),se.currentTarget.style.opacity="0.4"},sr=se=>{se.currentTarget.style.opacity="1",Ye.current=null,tt.current=null,Oe(null)},ar=(se,Re)=>{se.preventDefault(),se.dataTransfer.dropEffect="move",oe!==Re&&Oe(Re)},Dr=(se,Re)=>{const Pe=se.currentTarget.getBoundingClientRect(),{clientX:re,clientY:pe}=se;(re<Pe.left||re>Pe.right||pe<Pe.top||pe>Pe.bottom)&&oe===Re&&Oe(null)},Or=async(se,Re)=>{se.preventDefault(),Oe(null);const Pe=Ye.current,re=tt.current;if(Pe){const pe=To.find(Ee=>Ee.id===Re);if(!pe)return;const we=pe.dropStatus;if(Pe.status===we||Pe.status==="pending_approval")return;try{await le.tasks.updateStatus(Pe.id,we),Se()}catch{}}else if(re){const pe=cN[Re];if(!pe||re.status===pe)return;try{await le.requirements.updateStatus(re.id,pe),Ue()}catch{}}},yr=se=>{Qe(Re=>{const Pe=new Set(Re);return Pe.has(se)?Pe.delete(se):Pe.add(se),Pe})},on=se=>{Ge(Re=>{const Pe=new Set(Re);return Pe.has(se)?Pe.delete(se):Pe.add(se),Pe})},Rr=1440*60*1e3,Ps=Date.now(),lr=se=>se.status==="completed"&&se.updatedAt&&Ps-new Date(se.updatedAt).getTime()>Rr,ir=(se,Re=!1)=>{let Pe=se.filter(re=>Gt||Re||!lr(re));return o==="project"&&u&&(Pe=Pe.filter(re=>re.projectId===u)),Ae.size>0&&(Pe=Pe.filter(re=>re.projectId&&Ae.has(re.projectId))),Le.size>0&&(Pe=Pe.filter(re=>re.assignedAgentId&&Le.has(re.assignedAgentId))),Pe},Us=se=>se.statuses.flatMap(Re=>ir(m[Re]??[])),Cn=j.useMemo(()=>{let se=w;return o==="project"&&u&&(se=se.filter(Re=>Re.projectId===u)),Ae.size>0&&(se=se.filter(Re=>Re.projectId&&Ae.has(Re.projectId))),Le.size>0&&(se=se.filter(Re=>Le.has(Re.createdBy))),se},[w,o,u,Ae,Le]),Yr=j.useCallback(se=>Cn.filter(Re=>oN[Re.status]===se.id),[Cn]),ka=To.filter(se=>{if(se.id==="failed"||se.id==="closed"){const Re=Us(se),Pe=Yr(se);return Re.length+Pe.length>0}return!0}),or=Object.values(m).flat().filter(se=>lr(se)).length,zr=j.useMemo(()=>{const se=new Set(["completed","failed","cancelled","archived"]),Re=Object.values(m).flat(),Pe=new Set;for(const re of Re)re.assignedAgentId&&!se.has(re.status)&&(!u||re.projectId===u)&&Pe.add(re.assignedAgentId);return[...x].sort((re,pe)=>{const we=Pe.has(re.id)?0:1,Ee=Pe.has(pe.id)?0:1;return we-Ee})},[x,m,u]),Fn=j.useMemo(()=>{const se=new Set(["completed","failed","cancelled","archived"]),Re=Object.values(m).flat(),Pe=new Set;for(const re of Re)re.projectId&&!se.has(re.status)&&Pe.add(re.projectId);return[...s].sort((re,pe)=>{const we=Pe.has(re.id)?0:1,Ee=Pe.has(pe.id)?0:1;return we-Ee})},[s,m]),wn=j.useMemo(()=>{const se={};for(const Re of Object.values(m))for(const Pe of Re){const re=Pe.projectId??"__none__";se[re]=(se[re]??0)+1}return se},[m]),vr=Object.values(wn).reduce((se,Re)=>se+Re,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:[Q?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:Q.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:()=>{ee(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(se=>t.jsx("button",{onClick:()=>vt(se),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${xt===se?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:se==="backlog"?"Backlog":se==="kanban"?"Kanban":"DAG"},se))}),or>0&&t.jsx("button",{onClick:()=>ve(se=>!se),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Gt?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Gt?"Hide archived":`${or} archived`}),t.jsx("div",{className:"flex-1"}),(Ae.size>0||Le.size>0||s.length>1||x.length>0)&&t.jsxs("button",{onClick:()=>He(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${Ae.size>0||Le.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+Le.size>0?` (${Ae.size+Le.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:[Q?t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(Xz,{value:Q.name,onSave:async se=>{await le.projects.update(Q.id,{name:se}),ue()},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`}),or>0&&t.jsx("button",{onClick:()=>ve(se=>!se),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Gt?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Gt?`Hide ${or} archived`:`${or} archived`}),t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(se=>t.jsx("button",{onClick:()=>vt(se),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${xt===se?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:se==="backlog"?"Backlog":se==="kanban"?"Kanban":"DAG"},se))}),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:()=>{ee(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&&(vr>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:()=>Ge(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"}),Fn.map(se=>{const Re=Ae.has(se.id),Pe=wn[se.id]??0;return t.jsxs("button",{onClick:()=>on(se.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Re?"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 ${Re?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:se.name[0]?.toUpperCase()}),se.name,Pe>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:Pe})]},se.id)})]}),!r&&x.length>0&&!k&&(vr>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:()=>Qe(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 ${Le.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),zr.map(se=>{const Re=Le.has(se.id);return t.jsxs("button",{onClick:()=>yr(se.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Re?"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 ${Re?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:se.name[0]?.toUpperCase()}),se.name]},se.id)})]}),k&&Q?t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsx(lL,{project:Q,tasks:Object.values(m).flat(),requirements:w,agents:x,onDeleteProject:()=>an(Q.id),onUpdateProject:async se=>{await le.projects.update(Q.id,se)},onRefresh:()=>{ue()}})}):vr===0&&Cn.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"})]})}):xt==="backlog"?t.jsx(fL,{tasks:ir(Object.values(m).flat()),requirements:Cn,agents:x,projects:s,onTaskClick:se=>ke(se),onReqClick:se=>Ie(se),onRefresh:()=>{Se(),Ue()}}):xt==="dag"?t.jsx(Gz,{tasks:ir(Object.values(m).flat(),!0),requirements:Cn,agents:x,showArchived:Gt,onShowArchivedChange:ve,onTaskClick:se=>ke(se),onReqClick:se=>Ie(se),onDependencyChange:Se}):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:ka.map(se=>{const Re=Us(se),Pe=Yr(se),re=Re.length+Pe.length,pe=oe===se.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 ${se.accent} ${pe?"bg-surface-elevated/80 ring-1 ring-brand-500/40":"bg-surface-secondary"}`,onDragOver:we=>ar(we,se.id),onDragLeave:we=>Dr(we,se.id),onDrop:we=>{Or(we,se.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:se.label}),t.jsx("span",{className:"text-xs bg-surface-elevated px-2 py-0.5 rounded-full",children:re})]}),t.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin",children:(()=>{const we=[...Pe.map(Ee=>({kind:"req",data:Ee,time:new Date(Ee.updatedAt??Ee.createdAt).getTime()})),...Re.map(Ee=>({kind:"task",data:Ee,time:new Date(Ee.updatedAt??Ee.createdAt??0).getTime()}))];return we.sort((Ee,_e)=>_e.time-Ee.time),we.map(Ee=>{if(Ee.kind==="req"){const _e=Ee.data,Be=Iu[_e.status]??{label:_e.status,cls:"bg-gray-500/15 text-fg-secondary"},mt=_e.source==="agent"&&(_e.status==="draft"||_e.status==="pending_review"),at=o==="all"&&_e.projectId?s.find(Tt=>Tt.id===_e.projectId):null,rt=Wl(_e.createdBy,x,b)??_e.createdBy.slice(0,10);return t.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:Tt=>jn(Tt,_e),onDragEnd:sr,onClick:()=>Ie(_e),onKeyDown:Tt=>Tt.key==="Enter"&&Ie(_e),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 ${mt?"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:_e.title})]}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Be.cls}`,children:Be.label})]}),_e.description&&t.jsx("div",{className:"text-xs text-fg-tertiary mt-1 line-clamp-2",children:_e.description}),at&&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:at.name,children:at.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:_e.priority}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["by ",rt]})]}),t.jsx("div",{className:"flex items-center gap-1.5",children:_e.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:[_e.taskIds.length," tasks"]})})]}),mt&&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(),be(_e.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(),hn(_e.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-${_e.id}`)}else{const _e=Ee.data,Be=_e.subtasks?.length??0,Ve=lN[_e.status],mt=_e.status==="pending_approval",at=_e.taskType==="scheduled"&&!!_e.scheduleConfig,rt=at?_e.scheduleConfig.every?`Every ${_e.scheduleConfig.every}`:_e.scheduleConfig.cron?"Cron":"Scheduled":null,Tt=o==="all"&&_e.projectId?s.find(Je=>Je.id===_e.projectId)?.name:null,qt=_e.requirementId?w.find(Je=>Je.id===_e.requirementId)?.title:null,Kn=_e.createdBy?Wl(_e.createdBy,x,b)??_e.createdBy:null;return t.jsxs("div",{role:"button",tabIndex:0,"aria-label":_e.title,draggable:!mt,onDragStart:Je=>!mt&&Et(Je,_e),onDragEnd:sr,onClick:()=>ke(_e),onKeyDown:Je=>Je.key==="Enter"&&ke(_e),className:`border rounded-lg p-3 border-l-[3px] transition-colors ${mt?"bg-amber-500/[0.04] border-amber-500/30 border-l-amber-500 cursor-pointer":at?`bg-blue-500/[0.03] border-blue-500/20 ${Tm[_e.priority]??""} hover:border-blue-500/40 cursor-pointer`:`bg-surface-elevated border-border-default ${Tm[_e.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:[at&&t.jsx("span",{className:"text-blue-600 shrink-0",title:rt??"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:_e.title})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[at&&rt&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-600 whitespace-nowrap",children:rt}),Ve&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${Ve.cls}`,children:Ve.label})]})]}),_e.description&&t.jsx("div",{className:"text-xs text-fg-tertiary mt-1 line-clamp-2",children:_e.description}),(Tt||qt)&&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}),qt&&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:qt,children:["# ",qt]})]}),_e.blockedBy&&_e.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:["⏳ ",_e.blockedBy.length," dep",_e.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:_e.priority}),Kn&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",title:`Created by ${Kn}`,children:["by ",Kn]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[Be>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary bg-surface-overlay/50 px-1.5 py-0.5 rounded",children:["⋮ ",Be]}),_e.notes&&_e.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",_e.notes.length]}),_e.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 ${iN[x.find(Je=>Je.id===_e.assignedAgentId)?.status??""]??"bg-gray-500"}`}),x.find(Je=>Je.id===_e.assignedAgentId)?.name??_e.assignedAgentId.slice(0,8)]})]})]})]},_e.id)}})})()}),pe&&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"})})]},se.id)})})})]}),Y&&t.jsx(aN,{orgId:e?.orgId,onCreated:Mn,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:se=>se.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:se=>ee(se.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(se=>t.jsx("option",{value:se.id,children:se.name},se.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:se=>z(se.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(se=>se.status==="approved"&&(!L||se.projectId===L)).map(se=>t.jsx("option",{value:se.id,children:se.title},se.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:se=>F(se.target.value),onKeyDown:se=>{se.key==="Enter"&&ln()},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:se=>A(se.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:se=>_(se.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:se=>U(se.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(se=>t.jsx("option",{value:se.id,children:se.name},se.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:J,onChange:se=>B(se.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(se=>se.id!==G).map(se=>t.jsx("option",{value:se.id,children:se.name},se.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:ne,onChange:se=>Z(se.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)"})]})]}),ne==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Frequency"}),t.jsxs("select",{value:te,onChange:se=>ie(se.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:se=>{const Re=se.target.value;Re&&!V.includes(Re)&&K([...V,Re])},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(se=>se.status!=="completed"&&se.status!=="cancelled"&&!V.includes(se.id)).map(se=>t.jsx("option",{value:se.id,children:se.title},se.id))]}),V.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:V.map(se=>{const Re=Object.values(m).flat().find(Pe=>Pe.id===se);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:["⏳ ",Re?Re.title.slice(0,30):se.slice(-8),t.jsx("button",{onClick:()=>K(V.filter(Pe=>Pe!==se)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},se)})})]}),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:()=>{ln()},disabled:!G||!J,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Create"})]})]})}),ye&&t.jsx(aL,{task:ye,agents:x,projects:s,requirements:w,allTasks:Object.values(m).flat(),users:b,onClose:()=>ke(null),onRefresh:vn,authUser:e}),Dt&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{$t(!1),yt(""),$e("")},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:se=>se.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:gt,onChange:se=>jt(se.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(se=>t.jsx("option",{value:se.id,children:se.name},se.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{value:bt,onChange:se=>yt(se.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:se=>{se.key==="Enter"&&bt.trim()&&Pn()}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:he,onChange:se=>$e(se.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:ht,onChange:se=>dt(se.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:()=>{$t(!1),yt(""),$e("")},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:()=>{Pn()},className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Create"})]})]})}),en&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>hn(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:se=>se.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:sn,onChange:se=>bn(se.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:()=>hn(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:()=>{Ke()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:"Reject"})]})]})}),Me&&t.jsx(hL,{req:Me,agents:x,projects:s,allTasks:Object.values(m).flat(),users:b,onClose:()=>Ie(null),onApprove:se=>{be(se),Ie(null)},onReject:se=>{hn(se),Ie(null)},onCancel:se=>{kt(se),Ie(null)},onStatusChange:async(se,Re)=>{try{await le.requirements.updateStatus(se,Re),Nt(`Requirement status → ${Re}`),Ue(),Se()}catch(Pe){Nt(`Error: ${Pe}`)}}}),De&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>He(!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:se=>se.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||Le.size>0)&&t.jsx("button",{onClick:()=>{Ge(new Set),Qe(new Set)},className:"text-[11px] text-brand-500 font-medium",children:"Clear all"}),t.jsx("button",{onClick:()=>He(!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:Fn.map(se=>{const Re=Ae.has(se.id),Pe=wn[se.id]??0;return t.jsxs("button",{onClick:()=>on(se.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Re?"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 ${Re?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:se.name[0]?.toUpperCase()}),se.name,Pe>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Pe})]},se.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:zr.map(se=>{const Re=Le.has(se.id);return t.jsxs("button",{onClick:()=>yr(se.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Re?"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 ${Re?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:se.name[0]?.toUpperCase()}),se.name]},se.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function hL({req:e,agents:r,projects:s,allTasks:l,users:o,onClose:c,onApprove:u,onReject:f,onCancel:m,onStatusChange:h}){const x=xs(),g=Iu[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=Wl(e.createdBy,r,o)??e.createdBy.slice(0,12),C=l.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:Wl(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=lN[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 ${Tm[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=Iu[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 is(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 Va({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 zl({label:e,value:r,color:s}){if(!r)return null;const l={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 ${l[s]??l.gray} capitalize inline-block`,children:r})]})}function Yh({files:e}){const[r,s]=j.useState(Object.keys(e)[0]??""),l=Object.keys(e);return l.length===0?null:t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Files (",l.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:l.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),l=e.agent,o=e.team,c=e.dependencies,u=e.displayName??e.name;if(r==="agent"){const f=l?.roleName,m=l?.agentRole,h=l?.llmProvider,x=l?.llmModel,g=is(c?.env),b=is(c?.skills);return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Va,{label:"Name",value:u}),t.jsx(Va,{label:"Description",value:e.description}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(zl,{label:"Role Template",value:f,color:"indigo"}),t.jsx(zl,{label:"Agent Role",value:m,color:m==="manager"?"purple":"cyan"})]}),is(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:is(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(zl,{label:"LLM Provider",value:h,color:"gray"}),x&&t.jsx(zl,{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(Va,{label:"Skills",value:b.join(", ")}),s&&t.jsx(Yh,{files:s})]})}if(r==="team"){const m=o?.members??[];return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Va,{label:"Name",value:u}),t.jsx(Va,{label:"Description",value:e.description}),t.jsx("div",{className:"flex flex-wrap gap-2",children:t.jsx(zl,{label:"Category",value:e.category,color:"indigo"})}),is(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:is(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(Yh,{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)]})]}),is(h.skills).length>0&&t.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:is(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(Va,{label:"Name",value:u}),t.jsx(Va,{label:"Description",value:e.description}),t.jsx("div",{className:"flex gap-2",children:t.jsx(zl,{label:"Category",value:e.category,color:"indigo"})}),s&&t.jsx(Yh,{files:s}),is(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:is(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"],os={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=xs(),r=Wm({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[s,l]=j.useState(!1),o=j.useRef(s);o.current=s,j.useEffect(()=>{if(!e)return;const be=()=>{o.current&&l(!1)};return window.addEventListener("popstate",be),()=>window.removeEventListener("popstate",be)},[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(""),[A,I]=j.useState(""),[_,G]=j.useState("date"),[U,J]=j.useState(null),[B,L]=j.useState(null),[ee,R]=j.useState(""),[z,V]=j.useState(!1),[K,ne]=j.useState(!1),[Z,te]=j.useState(new Set),ie=j.useRef(null),[ye,ke]=j.useState("file"),[Me,Ie]=j.useState(""),[Le,Qe]=j.useState(""),[Ae,Ge]=j.useState(""),[ut,_t]=j.useState(""),[oe,Oe]=j.useState(""),[xt,vt]=j.useState(null),[Gt,ve]=j.useState(null),[De,He]=j.useState(!1),[Ye,tt]=j.useState(!1),[Dt,$t]=j.useState(!1),[bt,yt]=j.useState(!1),he=j.useRef(null),$e=j.useRef(null),[ht,dt]=j.useState(""),gt=j.useRef(void 0),jt=(be,Ke)=>{L({type:be,text:Ke}),setTimeout(()=>L(null),3e3)},en=async be=>{try{return await navigator.clipboard.writeText(be),!0}catch{try{const Ke=document.createElement("textarea");Ke.value=be,Ke.style.cssText="position:fixed;left:-9999px;top:-9999px;opacity:0",document.body.appendChild(Ke),Ke.select();const kt=document.execCommand("copy");return document.body.removeChild(Ke),kt}catch{return!1}}},hn=async be=>{await en(be)?(yt(!0),setTimeout(()=>yt(!1),1500)):jt("error","Copy failed — try long-pressing to copy manually")},sn=j.useMemo(()=>new Map(w.map(be=>[be.id,be])),[w]),bn=j.useMemo(()=>new Map(b.map(be=>[be.id,be])),[b]);j.useEffect(()=>{le.projects.list().then(be=>p(be.projects)).catch(()=>{}),le.agents.list().then(be=>S(be.agents??[])).catch(()=>{}),le.system.storage().then(be=>dt(be.dataDir+"/shared")).catch(()=>{})},[]),j.useEffect(()=>(gt.current=setTimeout(()=>H(C),300),()=>clearTimeout(gt.current)),[C]);const Nt=j.useMemo(()=>({q:k||void 0,projectId:$||void 0,agentId:P||void 0,type:M||void 0,status:F||void 0,artifactType:A||void 0}),[k,$,P,M,F,A]),Q=j.useCallback(async()=>{E(!0);try{const{results:be,total:Ke}=await le.deliverables.search({...Nt,offset:0,limit:c});f(be),h(Ke)}catch{f([]),h(0)}E(!1)},[Nt]),ue=j.useCallback(async()=>{if(!(x||u.length>=m)){g(!0);try{const{results:be,total:Ke}=await le.deliverables.search({...Nt,offset:u.length,limit:c});f(kt=>[...kt,...be]),h(Ke)}catch{}g(!1)}},[Nt,u.length,m,x]);j.useEffect(()=>{Q()},[Q]),j.useEffect(()=>Sn.on("deliverable:created",()=>Q()),[Q]);const Se=j.useCallback(()=>{const be=ie.current;!be||T||x||u.length>=m||be.scrollHeight<=be.clientHeight+100&&ue()},[T,x,u.length,m,ue]);j.useEffect(()=>{const be=ie.current;if(!be)return;const Ke=()=>{be.scrollTop+be.clientHeight>=be.scrollHeight-100&&ue()};return be.addEventListener("scroll",Ke,{passive:!0}),()=>be.removeEventListener("scroll",Ke)},[ue]),j.useEffect(()=>{Se()},[Se,Z]);const qe=j.useMemo(()=>{const be=new Map;for(const kt of u){let Et,jn;if(_==="project")Et=kt.projectId??"_none",jn=kt.projectId?bn.get(kt.projectId)?.name??kt.projectId:"No Project";else if(_==="agent")Et=kt.agentId??"_none",jn=kt.agentId?sn.get(kt.agentId)?.name??kt.agentId:"Unknown";else if(_==="type")Et=kt.type,jn=kt.type.charAt(0).toUpperCase()+kt.type.slice(1);else{const sr=new Date(kt.updatedAt);Et=`${sr.getFullYear()}-${String(sr.getMonth()+1).padStart(2,"0")}-${String(sr.getDate()).padStart(2,"0")}`,jn=Et}be.has(Et)||be.set(Et,{label:jn,items:[]}),be.get(Et).items.push(kt)}const Ke=[...be.entries()];return _==="date"?Ke.sort((kt,Et)=>Et[0].localeCompare(kt[0])):Ke.sort((kt,Et)=>kt[1].label.localeCompare(Et[1].label)),Ke},[u,_,bn,sn]),et=async()=>{if(!(!Me.trim()||!Le.trim())){ne(!0);try{await le.deliverables.create({type:ye,title:Me,summary:Le,reference:Ae,projectId:ut||void 0,tags:oe.split(",").map(be=>be.trim()).filter(Boolean)}),V(!1),jt("success","Deliverable created"),Q()}catch(be){jt("error",`Error: ${be}`)}ne(!1)}},Ue=async be=>{R("verify");try{await le.deliverables.verify(be.id),jt("success","Verified"),J({...be,status:"verified"}),Q()}catch(Ke){jt("error",`Error: ${Ke}`)}R("")},yn=async be=>{R("flag");try{await le.deliverables.update(be.id,{status:"outdated"}),jt("success","Flagged as outdated"),J({...be,status:"outdated"}),Q()}catch(Ke){jt("error",`Error: ${Ke}`)}R("")},mn=async be=>{R("remove");try{await le.deliverables.remove(be.id),jt("success","Removed"),J(null),Q()}catch(Ke){jt("error",`Error: ${Ke}`)}R("")},Mt=()=>{Ht.navigate("builder")},_n=async be=>{if(be.reference){if(be.type==="directory"){tt(!0);return}He(!0);try{const Ke=await le.files.preview(be.reference);Ke.type==="image"&&Ke.mimeType?ve({src:`data:${Ke.mimeType};base64,${Ke.content}`,name:Ke.name}):vt(Ke.content)}catch{vt(null),be.type==="file"&&tt(!0)}He(!1)}};j.useEffect(()=>{vt(null),ve(null),tt(!1),$t(!1),U&&_n(U)},[U?.id]),j.useEffect(()=>{if(!Dt)return;const be=Ke=>{$e.current&&!$e.current.contains(Ke.target)&&$t(!1)};return document.addEventListener("mousedown",be),()=>document.removeEventListener("mousedown",be)},[Dt]);const Hn=async(be,Ke)=>{const kt=he.current?.firstElementChild;if(!kt)return;const Et=pL(kt,be);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([Et],{type:"text/html"}),"text/plain":new Blob([Ke],{type:"text/plain"})})]),jt("success",be==="light"?"HTML (light) copied":"HTML (dark) copied")}catch{const jn=await en(Ke);jt(jn?"success":"error",jn?"Text copied (HTML not supported)":"Copy failed")}$t(!1)},Mn=be=>t.jsxs("div",{className:"relative group/preview",children:[t.jsxs("div",{className:"absolute -top-1 -right-1 z-10",ref:$e,children:[t.jsx("button",{onClick:()=>$t(Ke=>!Ke),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"})})}),Dt&&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 Ke=await en(be);jt(Ke?"success":"error",Ke?"Markdown source copied":"Copy failed"),$t(!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:()=>Hn("light",be),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:()=>Hn("dark",be),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:he,children:t.jsx(er,{content:be,className:"text-fg-secondary text-sm"})})]}),an=j.useCallback(be=>{te(Ke=>{const kt=new Set(Ke);return kt.has(be)?kt.delete(be):kt.add(be),kt})},[]),ln=j.useCallback(()=>{Z.size===qe.length?te(new Set):te(new Set(qe.map(([be])=>be)))},[Z.size,qe]),vn=()=>{Ie(""),Qe(""),Ge(""),Oe(""),ke("file"),b.length>0&&_t(b[0].id),V(!0)},Pn=be=>{J(be),e&&(l(!0),history.pushState({mobileDetail:"deliverables"},"",window.location.hash))};return t.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[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?s?{display:"none"}: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:vn,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:be=>N(be.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"}),ht&&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:ht}),t.jsx("button",{onClick:()=>{le.system.openPath(ht)},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(pa,{label:"All types",value:"",current:M||A||"",onClick:()=>{Y(""),I("")}}),Lv.map(be=>t.jsx(pa,{label:`${to[be]?.icon??""} ${be}`,value:be,current:M,onClick:Ke=>{Y(Ke),I("")}},be)),["agent","team","skill"].map(be=>t.jsx(pa,{label:`${os[be].icon} ${os[be].label}`,value:be,current:A,onClick:Ke=>{I(Ke),Y("")}},be))]}),b.length>0&&t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(pa,{label:"All projects",value:"",current:$,onClick:X}),b.map(be=>t.jsx(pa,{label:be.name,value:be.id,current:$,onClick:X},be.id))]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(pa,{label:"Active",value:"",current:F,onClick:D}),t.jsx(pa,{label:"Verified",value:"verified",current:F,onClick:D}),t.jsx(pa,{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(be=>t.jsx("button",{onClick:()=>{G(be),te(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${_===be?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:be.charAt(0).toUpperCase()+be.slice(1)},be)),qe.length>1&&t.jsx("button",{onClick:ln,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===qe.length?"Expand all":"Collapse all",children:Z.size===qe.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(be=>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"})]},be))}):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:vn,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create first"})]}):qe.map(([be,Ke])=>{const kt=Z.has(be);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>an(be),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 ${kt?"":"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:Ke.label}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Ke.items.length,")"]})]}),!kt&&Ke.items.map(Et=>t.jsxs("button",{onClick:()=>Pn(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&&os[Et.artifactType]?t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${os[Et.artifactType].color}`,children:[os[Et.artifactType].icon," ",os[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:sn.get(Et.agentId)?.name??"Agent"})]})]},Et.id))]},be)}),x&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[t.jsx(Gh,{})," ",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:!!ee,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:ee==="verify"?"Verifying...":"Verify"}),U.status!=="outdated"&&t.jsx("button",{onClick:()=>yn(U),disabled:!!ee,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:ee==="flag"?"Flagging...":"Flag Outdated"}),t.jsx("button",{onClick:()=>mn(U),disabled:!!ee,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:ee==="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&&os[U.artifactType]&&t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${os[U.artifactType].color}`,children:[os[U.artifactType].icon," Builder ",os[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:()=>{le.files.reveal(U.reference).catch(()=>jt("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:()=>{le.files.reveal(U.reference).catch(()=>jt("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:()=>hn(U.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${bt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:"Copy path to clipboard",children:bt?"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:Mt,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:De?t.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[t.jsx(Gh,{})," Loading preview..."]}):Gt?t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("img",{src:Gt.src,alt:Gt.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:Gt.name})]}):xt?Mn(xt):Ye?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:()=>{le.files.reveal(U.reference).catch(()=>jt("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:()=>{le.files.reveal(U.reference).catch(()=>jt("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:()=>hn(U.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${bt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:bt?"Copied!":"Copy"})]})]}):U.summary?Mn(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(be=>t.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:be},be))}),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:()=>Ht.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:()=>Ht.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: ",sn.get(U.agentId)?.name??U.agentId.slice(0,12)]}),U.projectId&&t.jsxs("button",{onClick:()=>Ht.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: ",bn.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:()=>!K&&V(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:be=>be.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:ye,onChange:be=>ke(be.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(be=>t.jsxs("option",{value:be,children:[to[be]?.icon??""," ",be]},be))})]}),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:Me,onChange:be=>Ie(be.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:be=>Ge(be.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:Le,onChange:be=>Qe(be.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:oe,onChange:be=>Oe(be.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:ut,onChange:be=>_t(be.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(be=>t.jsx("option",{value:be.id,children:be.name},be.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:K,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:"Cancel"}),t.jsxs("button",{onClick:et,disabled:K||!Me.trim()||!Le.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:[K&&t.jsx(Gh,{}),K?"Creating...":"Create"]})]})]})})]})}function pL(e,r){const s=e.cloneNode(!0),l=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:${l.text};line-height:1.7;`,h1:`font-size:1.6em;font-weight:700;color:${l.heading};margin:20px 0 10px;line-height:1.3;border-bottom:1px solid ${l.border};padding-bottom:6px;`,h2:`font-size:1.35em;font-weight:700;color:${l.heading};margin:18px 0 8px;line-height:1.3;`,h3:`font-size:1.15em;font-weight:600;color:${l.heading};margin:14px 0 6px;line-height:1.3;`,h4:`font-size:1em;font-weight:600;color:${l.heading};margin:12px 0 4px;`,strong:`font-weight:600;color:${l.strong};`,em:"font-style:italic;",a:`color:${l.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:${l.text};`,blockquote:`border-left:3px solid ${l.blockquoteBorder};padding:2px 0 2px 14px;margin:10px 0;color:${l.blockquoteText};`,hr:`border:none;border-top:1px solid ${l.hrColor};margin:20px 0;`,table:"border-collapse:collapse;width:100%;margin:10px 0;",thead:`background:${l.tableHeaderBg};`,th:`border:1px solid ${l.tableBorder};padding:8px 12px;text-align:left;font-weight:600;color:${l.tableHeaderText};`,td:`border:1px solid ${l.tableBorder};padding:8px 12px;color:${l.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:${l.preBg};color:${l.preText};padding:14px;border-radius:6px;overflow-x:auto;margin:10px 0;font-size:0.88em;line-height:1.5;border:1px solid ${l.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:${l.codeBg};color:${l.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:${l.bg};color:${l.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 pa({label:e,value:r,current:s,onClick:l}){return t.jsx("button",{onClick:()=>l(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 Gh(){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 ba(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function gu(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,l]=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 le.reports.generate({period:$,scope:"org",orgId:"default"});l(X)}catch(X){f(String(X)),l(null)}c(!1)},[]),E=j.useCallback(()=>{le.usage.summary().then($=>h($.usage)).catch(()=>{}),le.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(iu,{label:"LLM Tokens (this month)",value:ba(m.llmTokens),color:"text-brand-500"}),t.jsx(iu,{label:"Tool Calls (today)",value:ba(m.toolCalls),color:"text-blue-600"}),t.jsx(iu,{label:"Messages (today)",value:ba(m.messages),color:"text-green-600"}),t.jsx(iu,{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:gu(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:ba(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:gu(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(Xh,{title:`Completed (${s.taskSummary.completed.length})`,color:"emerald",items:s.taskSummary.completed.map($=>({label:$.title,sub:$.agent}))}),s.taskSummary.inProgress.length>0&&t.jsx(Xh,{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(Xh,{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:ba(x.reduce(($,X)=>$+X.totalTokens,0))}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ba(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:gu(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 Xh({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((l,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:l.label}),l.sub&&l.sub!=="unassigned"&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:l.sub})]},o))})]})}function iu({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:l,onSort:o,align:c}){const u=s===r?l?"↓":"↑":"↕",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,l=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:()=>Ht.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 ${l}`}),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:ba(e.totalTokens)})]})}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:ba(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:gu(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:l,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(()=>{le.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 le.auth.logout()}catch{}l?.()},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.3.2"]})]}),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 l=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 ${l?"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:l?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 ${l?"font-semibold":""}`,children:s.label})]},s.id)})})}const EL=50,TL=30;function fN(e,r,s){const l=j.useRef(0),o=j.useRef(0),c=j.useCallback(f=>{l.current=f.touches[0].clientX,o.current=f.touches[0].clientY},[]),u=j.useCallback(f=>{const m=f.changedTouches[0].clientX-l.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 AL({authUser:e}){const[r,s]=j.useState("builder"),l=fN(Bv,r,s);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:l.onTouchStart,onTouchEnd:l.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 _L({theme:e,onThemeChange:r}){const[s,l]=j.useState("settings"),o=fN(Hv,s,l);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:()=>l(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(ij,{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[l,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(_=>_.configured)&&C(!0)}).catch(()=>{})},[]),j.useEffect(()=>{l===Pv&&!H.current&&!E&&(H.current=!0,Y())},[l,E]);const Y=async()=>{m(!0);try{const I=await fetch("/api/settings/env-models",{headers:M()});if(I.ok){const _=await I.json();if(u(_),_.detected.length>0){const G={};for(const U of _.detected)G[U.provider]=!0;x(G)}}}catch{}finally{m(!1)}},$=async()=>{if(!c)return;const I=c.detected.filter(_=>h[_.provider]);if(I.length!==0){b(!0),k(null);try{const _=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(_.ok){const G=await _.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 _=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:M(),body:JSON.stringify({preview:!0})})).json();"error"in _||w(_)}catch{}finally{T(!1)}},P=async()=>{T(!0),k(null);try{const _=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:M(),body:JSON.stringify({preview:!1})})).json();"error"in _?k({type:"err",text:_.error}):(k({type:"ok",text:`Imported ${_.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,_])=>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:_})]},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:_=>x({...h,[I.provider]:_.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,_])=>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:_})]})]},I))})}],D=()=>{l<F.length-1?o(l+1):e()},A=F[l];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,_)=>t.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${_<=l?"bg-brand-500":"bg-surface-elevated"}`},_))}),t.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:A.title}),t.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:A.subtitle}),A.content,t.jsxs("div",{className:"flex justify-between mt-8",children:[l>0?t.jsx("button",{onClick:()=>o(l-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:[l===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:l===F.length-1?"Get Started":"Next"})]})]})]})})})}const DL="markus123";function OL({onLogin:e}){const[r,s]=j.useState("admin@markus.local"),[l,o]=j.useState(""),[c,u]=j.useState(""),[f,m]=j.useState(!1),h=async x=>{if(x.preventDefault(),!(!r.trim()||!l)){u(""),m(!0);try{const{user:g}=await le.auth.login(r.trim(),l);e(g,l===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:l,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||!l,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,l]=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 le.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=>l(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(l=>{r(l);try{localStorage.setItem(hN,l)}catch{}Uv(l)},[]);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 ou(){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 Zh={};function $L(){const[e,r]=j.useState(ou),[s,l]=j.useState(()=>!localStorage.getItem("markus_onboarded")),[o,c]=j.useState(!0),u=xs(),f=LL(),m=Wm({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[h,x]=j.useState(()=>new Set([ou()])),[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=ou(),P=window.location.hash.slice(1);P!==X?Zh[X]=P:delete Zh[X],r($),x(q=>q.has($)?q:new Set([...q,$])),window.location.hash=Zh[$]||$},[u]);j.useEffect(()=>{Ht.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(()=>{le.auth.me().then(({user:$})=>{b($),k(),qa(gr.builderArtifacts,()=>le.builder.artifacts.list()),qa(gr.builderAgents,()=>le.agents.list()),qa(gr.builderHubMyItems,()=>In.myItems()),qa(gr.builderInstalled,()=>le.builder.artifacts.installed()),qa(gr.hubAgents,()=>In.search({type:"agent",limit:50})),qa(gr.hubTeams,()=>In.search({type:"team",limit:50})),qa(gr.hubSkills,()=>In.search({type:"skill",limit:50}))}).catch(()=>b(null)),Sn.connect();const Y=()=>{const $=ou();r($),x(X=>X.has($)?X:new Set([...X,$]))};return window.addEventListener("hashchange",Y),()=>{Sn.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(AL,{authUser:H}),settings:t.jsx(_L,{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(ij,{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"),l(!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,{})}));