@markus-global/cli 0.4.17 → 0.4.18

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.
@@ -60,4 +60,4 @@ Step 3: Accept and execute tasks, report progress, and communicate with teammate
60
60
  `)),x=f.reduce((p,g)=>p.concat(...g),[]);return[f,x]}return[[],[]]},[e]);return v.useEffect(()=>{const m=n?.target??Rv,f=n?.actInsideInputWithModifier??!0;if(e!==null){const x=y=>{if(o.current=y.ctrlKey||y.metaKey||y.shiftKey||y.altKey,(!o.current||o.current&&!f)&&Iw(y))return!1;const N=Dv(y.code,h);if(d.current.add(y[N]),Ov(c,d.current,!1)){const T=y.composedPath?.()?.[0]||y.target,_=T?.nodeName==="BUTTON"||T?.nodeName==="A";n.preventDefault!==!1&&(o.current||!_)&&y.preventDefault(),i(!0)}},p=y=>{const w=Dv(y.code,h);Ov(c,d.current,!0)?(i(!1),d.current.clear()):d.current.delete(y[w]),y.key==="Meta"&&d.current.clear(),o.current=!1},g=()=>{d.current.clear(),i(!1)};return m?.addEventListener("keydown",x),m?.addEventListener("keyup",p),window.addEventListener("blur",g),window.addEventListener("contextmenu",g),()=>{m?.removeEventListener("keydown",x),m?.removeEventListener("keyup",p),window.removeEventListener("blur",g),window.removeEventListener("contextmenu",g)}}},[e,i]),s}function Ov(e,n,s){return e.filter(i=>s||i.length===n.size).some(i=>i.every(o=>n.has(o)))}function Dv(e,n){return n.includes(e)?"code":"key"}const rD=()=>{const e=An();return v.useMemo(()=>({zoomIn:n=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1.2,{duration:n?.duration}):Promise.resolve(!1)},zoomOut:n=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1/1.2,{duration:n?.duration}):Promise.resolve(!1)},zoomTo:(n,s)=>{const{panZoom:i}=e.getState();return i?i.scaleTo(n,{duration:s?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(n,s)=>{const{transform:[i,o,d],panZoom:c}=e.getState();return c?(await c.setViewport({x:n.x??i,y:n.y??o,zoom:n.zoom??d},s),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[n,s,i]=e.getState().transform;return{x:n,y:s,zoom:i}},setCenter:async(n,s,i)=>e.getState().setCenter(n,s,i),fitBounds:async(n,s)=>{const{width:i,height:o,minZoom:d,maxZoom:c,panZoom:h}=e.getState(),m=Mx(n,i,o,d,c,s?.padding??.1);return h?(await h.setViewport(m,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(n,s={})=>{const{transform:i,snapGrid:o,snapToGrid:d,domNode:c}=e.getState();if(!c)return n;const{x:h,y:m}=c.getBoundingClientRect(),f={x:n.x-h,y:n.y-m},x=s.snapGrid??o,p=s.snapToGrid??d;return nc(f,i,p,x)},flowToScreenPosition:n=>{const{transform:s,domNode:i}=e.getState();if(!i)return n;const{x:o,y:d}=i.getBoundingClientRect(),c=Xd(n,s);return{x:c.x+o,y:c.y+d}}}),[])};function sN(e,n){const s=[],i=new Map,o=[];for(const d of e)if(d.type==="add"){o.push(d);continue}else if(d.type==="remove"||d.type==="replace")i.set(d.id,[d]);else{const c=i.get(d.id);c?c.push(d):i.set(d.id,[d])}for(const d of n){const c=i.get(d.id);if(!c){s.push(d);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){s.push({...c[0].item});continue}const h={...d};for(const m of c)sD(m,h);s.push(h)}return o.length&&o.forEach(d=>{d.index!==void 0?s.splice(d.index,0,{...d.item}):s.push({...d.item})}),s}function sD(e,n){switch(e.type){case"select":{n.selected=e.selected;break}case"position":{typeof e.position<"u"&&(n.position=e.position),typeof e.dragging<"u"&&(n.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(n.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(n.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(n.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(n.resizing=e.resizing);break}}}function aN(e,n){return sN(e,n)}function iN(e,n){return sN(e,n)}function li(e,n){return{id:e,type:"select",selected:n}}function il(e,n=new Set,s=!1){const i=[];for(const[o,d]of e){const c=n.has(o);!(d.selected===void 0&&!c)&&d.selected!==c&&(s&&(d.selected=c),i.push(li(d.id,c)))}return i}function Lv({items:e=[],lookup:n}){const s=[],i=new Map(e.map(o=>[o.id,o]));for(const[o,d]of e.entries()){const c=n.get(d.id),h=c?.internals?.userNode??c;h!==void 0&&h!==d&&s.push({id:d.id,item:d,type:"replace"}),h===void 0&&s.push({item:d,type:"add",index:o})}for(const[o]of n)i.get(o)===void 0&&s.push({id:o,type:"remove"});return s}function Iv(e){return{id:e.id,type:"remove"}}const zv=e=>TR(e),aD=e=>Tw(e);function lN(e){return v.forwardRef(e)}const iD=typeof window<"u"?v.useLayoutEffect:v.useEffect;function $v(e){const[n,s]=v.useState(BigInt(0)),[i]=v.useState(()=>lD(()=>s(o=>o+BigInt(1))));return iD(()=>{const o=i.get();o.length&&(e(o),i.reset())},[n]),i}function lD(e){let n=[];return{get:()=>n,reset:()=>{n=[]},push:s=>{n.push(s),e()}}}const oN=v.createContext(null);function oD({children:e}){const n=An(),s=v.useCallback(h=>{const{nodes:m=[],setNodes:f,hasDefaultNodes:x,onNodesChange:p,nodeLookup:g,fitViewQueued:y,onNodesChangeMiddlewareMap:w}=n.getState();let N=m;for(const _ of h)N=typeof _=="function"?_(N):_;let T=Lv({items:N,lookup:g});for(const _ of w.values())T=_(T);x&&f(N),T.length>0?p?.(T):y&&window.requestAnimationFrame(()=>{const{fitViewQueued:_,nodes:S,setNodes:k}=n.getState();_&&k(S)})},[]),i=$v(s),o=v.useCallback(h=>{const{edges:m=[],setEdges:f,hasDefaultEdges:x,onEdgesChange:p,edgeLookup:g}=n.getState();let y=m;for(const w of h)y=typeof w=="function"?w(y):w;x?f(y):p&&p(Lv({items:y,lookup:g}))},[]),d=$v(o),c=v.useMemo(()=>({nodeQueue:i,edgeQueue:d}),[]);return t.jsx(oN.Provider,{value:c,children:e})}function cD(){const e=v.useContext(oN);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const dD=e=>!!e.panZoom;function $x(){const e=rD(),n=An(),s=cD(),i=Zt(dD),o=v.useMemo(()=>{const d=p=>n.getState().nodeLookup.get(p),c=p=>{s.nodeQueue.push(p)},h=p=>{s.edgeQueue.push(p)},m=p=>{const{nodeLookup:g,nodeOrigin:y}=n.getState(),w=zv(p)?p:g.get(p.id),N=w.parentId?Dw(w.position,w.measured,w.parentId,g,y):w.position,T={...w,position:N,width:w.measured?.width??w.width,height:w.measured?.height??w.height};return pl(T)},f=(p,g,y={replace:!1})=>{c(w=>w.map(N=>{if(N.id===p){const T=typeof g=="function"?g(N):g;return y.replace&&zv(T)?T:{...N,...T}}return N}))},x=(p,g,y={replace:!1})=>{h(w=>w.map(N=>{if(N.id===p){const T=typeof g=="function"?g(N):g;return y.replace&&aD(T)?T:{...N,...T}}return N}))};return{getNodes:()=>n.getState().nodes.map(p=>({...p})),getNode:p=>d(p)?.internals.userNode,getInternalNode:d,getEdges:()=>{const{edges:p=[]}=n.getState();return p.map(g=>({...g}))},getEdge:p=>n.getState().edgeLookup.get(p),setNodes:c,setEdges:h,addNodes:p=>{const g=Array.isArray(p)?p:[p];s.nodeQueue.push(y=>[...y,...g])},addEdges:p=>{const g=Array.isArray(p)?p:[p];s.edgeQueue.push(y=>[...y,...g])},toObject:()=>{const{nodes:p=[],edges:g=[],transform:y}=n.getState(),[w,N,T]=y;return{nodes:p.map(_=>({..._})),edges:g.map(_=>({..._})),viewport:{x:w,y:N,zoom:T}}},deleteElements:async({nodes:p=[],edges:g=[]})=>{const{nodes:y,edges:w,onNodesDelete:N,onEdgesDelete:T,triggerNodeChanges:_,triggerEdgeChanges:S,onDelete:k,onBeforeDelete:C}=n.getState(),{nodes:M,edges:L}=await OR({nodesToRemove:p,edgesToRemove:g,nodes:y,edges:w,onBeforeDelete:C}),P=L.length>0,G=M.length>0;if(P){const W=L.map(Iv);T?.(L),S(W)}if(G){const W=M.map(Iv);N?.(M),_(W)}return(G||P)&&k?.({nodes:M,edges:L}),{deletedNodes:M,deletedEdges:L}},getIntersectingNodes:(p,g=!0,y)=>{const w=cv(p),N=w?p:m(p),T=y!==void 0;return N?(y||n.getState().nodes).filter(_=>{const S=n.getState().nodeLookup.get(_.id);if(S&&!w&&(_.id===p.id||!S.internals.positionAbsolute))return!1;const k=pl(T?_:S),C=qo(k,N);return g&&C>0||C>=k.width*k.height||C>=N.width*N.height}):[]},isNodeIntersecting:(p,g,y=!0)=>{const N=cv(p)?p:m(p);if(!N)return!1;const T=qo(N,g);return y&&T>0||T>=g.width*g.height||T>=N.width*N.height},updateNode:f,updateNodeData:(p,g,y={replace:!1})=>{f(p,w=>{const N=typeof g=="function"?g(w):g;return y.replace?{...w,data:N}:{...w,data:{...w.data,...N}}},y)},updateEdge:x,updateEdgeData:(p,g,y={replace:!1})=>{x(p,w=>{const N=typeof g=="function"?g(w):g;return y.replace?{...w,data:N}:{...w,data:{...w.data,...N}}},y)},getNodesBounds:p=>{const{nodeLookup:g,nodeOrigin:y}=n.getState();return _R(p,{nodeLookup:g,nodeOrigin:y})},getHandleConnections:({type:p,id:g,nodeId:y})=>Array.from(n.getState().connectionLookup.get(`${y}-${p}${g?`-${g}`:""}`)?.values()??[]),getNodeConnections:({type:p,handleId:g,nodeId:y})=>Array.from(n.getState().connectionLookup.get(`${y}${p?g?`-${p}-${g}`:`-${p}`:""}`)?.values()??[]),fitView:async p=>{const g=n.getState().fitViewResolver??zR();return n.setState({fitViewQueued:!0,fitViewOptions:p,fitViewResolver:g}),s.nodeQueue.push(y=>[...y]),g.promise}}},[]);return v.useMemo(()=>({...o,...e,viewportInitialized:i}),[i])}const Bv=e=>e.selected,uD=typeof window<"u"?window:void 0;function fD({deleteKeyCode:e,multiSelectionKeyCode:n}){const s=An(),{deleteElements:i}=$x(),o=Fo(e,{actInsideInputWithModifier:!1}),d=Fo(n,{target:uD});v.useEffect(()=>{if(o){const{edges:c,nodes:h}=s.getState();i({nodes:h.filter(Bv),edges:c.filter(Bv)}),s.setState({nodesSelectionActive:!1})}},[o]),v.useEffect(()=>{s.setState({multiSelectionActive:d})},[d])}function hD(e){const n=An();v.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const i=Rx(e.current);(i.height===0||i.width===0)&&n.getState().onError?.("004",Cs.error004()),n.setState({width:i.width||500,height:i.height||500})};if(e.current){s(),window.addEventListener("resize",s);const i=new ResizeObserver(()=>s());return i.observe(e.current),()=>{window.removeEventListener("resize",s),i&&e.current&&i.unobserve(e.current)}}},[])}const pu={position:"absolute",width:"100%",height:"100%",top:0,left:0},mD=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function xD({onPaneContextMenu:e,zoomOnScroll:n=!0,zoomOnPinch:s=!0,panOnScroll:i=!1,panOnScrollSpeed:o=.5,panOnScrollMode:d=fi.Free,zoomOnDoubleClick:c=!0,panOnDrag:h=!0,defaultViewport:m,translateExtent:f,minZoom:x,maxZoom:p,zoomActivationKeyCode:g,preventScrolling:y=!0,children:w,noWheelClassName:N,noPanClassName:T,onViewportChange:_,isControlledViewport:S,paneClickDistance:k,selectionOnDrag:C}){const M=An(),L=v.useRef(null),{userSelectionActive:P,lib:G,connectionInProgress:W}=Zt(mD,_n),z=Fo(g),q=v.useRef();hD(L);const Y=v.useCallback($=>{_?.({x:$[0],y:$[1],zoom:$[2]}),S||M.setState({transform:$})},[_,S]);return v.useEffect(()=>{if(L.current){q.current=vO({domNode:L.current,minZoom:x,maxZoom:p,translateExtent:f,viewport:m,onDraggingChange:A=>M.setState(F=>F.paneDragging===A?F:{paneDragging:A}),onPanZoomStart:(A,F)=>{const{onViewportChangeStart:V,onMoveStart:X}=M.getState();X?.(A,F),V?.(F)},onPanZoom:(A,F)=>{const{onViewportChange:V,onMove:X}=M.getState();X?.(A,F),V?.(F)},onPanZoomEnd:(A,F)=>{const{onViewportChangeEnd:V,onMoveEnd:X}=M.getState();X?.(A,F),V?.(F)}});const{x:$,y:R,zoom:I}=q.current.getViewport();return M.setState({panZoom:q.current,transform:[$,R,I],domNode:L.current.closest(".react-flow")}),()=>{q.current?.destroy()}}},[]),v.useEffect(()=>{q.current?.update({onPaneContextMenu:e,zoomOnScroll:n,zoomOnPinch:s,panOnScroll:i,panOnScrollSpeed:o,panOnScrollMode:d,zoomOnDoubleClick:c,panOnDrag:h,zoomActivationKeyPressed:z,preventScrolling:y,noPanClassName:T,userSelectionActive:P,noWheelClassName:N,lib:G,onTransformChange:Y,connectionInProgress:W,selectionOnDrag:C,paneClickDistance:k})},[e,n,s,i,o,d,c,h,z,y,T,P,N,G,Y,W,C,k]),t.jsx("div",{className:"react-flow__renderer",ref:L,style:pu,children:w})}const pD=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function gD(){const{userSelectionActive:e,userSelectionRect:n}=Zt(pD,_n);return e&&n?t.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:n.width,height:n.height,transform:`translate(${n.x}px, ${n.y}px)`}}):null}const am=(e,n)=>s=>{s.target===n.current&&e?.(s)},bD=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function yD({isSelecting:e,selectionKeyPressed:n,selectionMode:s=Uo.Full,panOnDrag:i,paneClickDistance:o,selectionOnDrag:d,onSelectionStart:c,onSelectionEnd:h,onPaneClick:m,onPaneContextMenu:f,onPaneScroll:x,onPaneMouseEnter:p,onPaneMouseMove:g,onPaneMouseLeave:y,children:w}){const N=An(),{userSelectionActive:T,elementsSelectable:_,dragging:S,connectionInProgress:k}=Zt(bD,_n),C=_&&(e||T),M=v.useRef(null),L=v.useRef(),P=v.useRef(new Set),G=v.useRef(new Set),W=v.useRef(!1),z=V=>{if(W.current||k){W.current=!1;return}m?.(V),N.getState().resetSelectedElements(),N.setState({nodesSelectionActive:!1})},q=V=>{if(Array.isArray(i)&&i?.includes(2)){V.preventDefault();return}f?.(V)},Y=x?V=>x(V):void 0,$=V=>{W.current&&(V.stopPropagation(),W.current=!1)},R=V=>{const{domNode:X}=N.getState();if(L.current=X?.getBoundingClientRect(),!L.current)return;const O=V.target===M.current;if(!O&&!!V.target.closest(".nokey")||!e||!(d&&O||n)||V.button!==0||!V.isPrimary)return;V.target?.setPointerCapture?.(V.pointerId),W.current=!1;const{x:D,y:E}=us(V.nativeEvent,L.current);N.setState({userSelectionRect:{width:0,height:0,startX:D,startY:E,x:D,y:E}}),O||(V.stopPropagation(),V.preventDefault())},I=V=>{const{userSelectionRect:X,transform:O,nodeLookup:U,edgeLookup:K,connectionLookup:D,triggerNodeChanges:E,triggerEdgeChanges:H,defaultEdgeOptions:Z,resetSelectedElements:ee}=N.getState();if(!L.current||!X)return;const{x:ne,y:ae}=us(V.nativeEvent,L.current),{startX:he,startY:Se}=X;if(!W.current){const Be=n?0:o;if(Math.hypot(ne-he,ae-Se)<=Be)return;ee(),c?.(V)}W.current=!0;const Ie={startX:he,startY:Se,x:ne<he?ne:he,y:ae<Se?ae:Se,width:Math.abs(ne-he),height:Math.abs(ae-Se)},xe=P.current,we=G.current;P.current=new Set(Ax(U,Ie,O,s===Uo.Partial,!0).map(Be=>Be.id)),G.current=new Set;const Me=Z?.selectable??!0;for(const Be of P.current){const et=D.get(Be);if(et)for(const{edgeId:lt}of et.values()){const ft=K.get(lt);ft&&(ft.selectable??Me)&&G.current.add(lt)}}if(!dv(xe,P.current)){const Be=il(U,P.current,!0);E(Be)}if(!dv(we,G.current)){const Be=il(K,G.current);H(Be)}N.setState({userSelectionRect:Ie,userSelectionActive:!0,nodesSelectionActive:!1})},A=V=>{V.button===0&&(V.target?.releasePointerCapture?.(V.pointerId),!T&&V.target===M.current&&N.getState().userSelectionRect&&z?.(V),N.setState({userSelectionActive:!1,userSelectionRect:null}),W.current&&(h?.(V),N.setState({nodesSelectionActive:P.current.size>0})))},F=i===!0||Array.isArray(i)&&i.includes(0);return t.jsxs("div",{className:Xn(["react-flow__pane",{draggable:F,dragging:S,selection:e}]),onClick:C?void 0:am(z,M),onContextMenu:am(q,M),onWheel:am(Y,M),onPointerEnter:C?void 0:p,onPointerMove:C?I:g,onPointerUp:C?A:void 0,onPointerDownCapture:C?R:void 0,onClickCapture:C?$:void 0,onPointerLeave:y,ref:M,style:pu,children:[w,t.jsx(gD,{})]})}function Xm({id:e,store:n,unselect:s=!1,nodeRef:i}){const{addSelectedNodes:o,unselectNodesAndEdges:d,multiSelectionActive:c,nodeLookup:h,onError:m}=n.getState(),f=h.get(e);if(!f){m?.("012",Cs.error012(e));return}n.setState({nodesSelectionActive:!1}),f.selected?(s||f.selected&&c)&&(d({nodes:[f],edges:[]}),requestAnimationFrame(()=>i?.current?.blur())):o([e])}function cN({nodeRef:e,disabled:n=!1,noDragClassName:s,handleSelector:i,nodeId:o,isSelectable:d,nodeClickDistance:c}){const h=An(),[m,f]=v.useState(!1),x=v.useRef();return v.useEffect(()=>{x.current=iO({getStoreItems:()=>h.getState(),onNodeMouseDown:p=>{Xm({id:p,store:h,nodeRef:e})},onDragStart:()=>{f(!0)},onDragStop:()=>{f(!1)}})},[]),v.useEffect(()=>{if(!(n||!e.current||!x.current))return x.current.update({noDragClassName:s,handleSelector:i,domNode:e.current,isSelectable:d,nodeId:o,nodeClickDistance:c}),()=>{x.current?.destroy()}},[s,i,n,d,e,o,c]),m}const vD=e=>n=>n.selected&&(n.draggable||e&&typeof n.draggable>"u");function dN(){const e=An();return v.useCallback(s=>{const{nodeExtent:i,snapToGrid:o,snapGrid:d,nodesDraggable:c,onError:h,updateNodePositions:m,nodeLookup:f,nodeOrigin:x}=e.getState(),p=new Map,g=vD(c),y=o?d[0]:5,w=o?d[1]:5,N=s.direction.x*y*s.factor,T=s.direction.y*w*s.factor;for(const[,_]of f){if(!g(_))continue;let S={x:_.internals.positionAbsolute.x+N,y:_.internals.positionAbsolute.y+T};o&&(S=tc(S,d));const{position:k,positionAbsolute:C}=_w({nodeId:_.id,nextPosition:S,nodeLookup:f,nodeExtent:i,nodeOrigin:x,onError:h});_.position=k,_.internals.positionAbsolute=C,p.set(_.id,_)}m(p)},[])}const Bx=v.createContext(null),jD=Bx.Provider;Bx.Consumer;const uN=()=>v.useContext(Bx),wD=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),ND=(e,n,s)=>i=>{const{connectionClickStartHandle:o,connectionMode:d,connection:c}=i,{fromHandle:h,toHandle:m,isValid:f}=c,x=m?.nodeId===e&&m?.id===n&&m?.type===s;return{connectingFrom:h?.nodeId===e&&h?.id===n&&h?.type===s,connectingTo:x,clickConnecting:o?.nodeId===e&&o?.id===n&&o?.type===s,isPossibleEndHandle:d===hl.Strict?h?.type!==s:e!==h?.nodeId||n!==h?.id,connectionInProcess:!!h,clickConnectionInProcess:!!o,valid:x&&f}};function kD({type:e="source",position:n=ut.Top,isValidConnection:s,isConnectable:i=!0,isConnectableStart:o=!0,isConnectableEnd:d=!0,id:c,onConnect:h,children:m,className:f,onMouseDown:x,onTouchStart:p,...g},y){const w=c||null,N=e==="target",T=An(),_=uN(),{connectOnClick:S,noPanClassName:k,rfId:C}=Zt(wD,_n),{connectingFrom:M,connectingTo:L,clickConnecting:P,isPossibleEndHandle:G,connectionInProcess:W,clickConnectionInProcess:z,valid:q}=Zt(ND(_,w,e),_n);_||T.getState().onError?.("010",Cs.error010());const Y=I=>{const{defaultEdgeOptions:A,onConnect:F,hasDefaultEdges:V}=T.getState(),X={...A,...I};if(V){const{edges:O,setEdges:U}=T.getState();U(VR(X,O))}F?.(X),h?.(X)},$=I=>{if(!_)return;const A=zw(I.nativeEvent);if(o&&(A&&I.button===0||!A)){const F=T.getState();Gm.onPointerDown(I.nativeEvent,{handleDomNode:I.currentTarget,autoPanOnConnect:F.autoPanOnConnect,connectionMode:F.connectionMode,connectionRadius:F.connectionRadius,domNode:F.domNode,nodeLookup:F.nodeLookup,lib:F.lib,isTarget:N,handleId:w,nodeId:_,flowId:F.rfId,panBy:F.panBy,cancelConnection:F.cancelConnection,onConnectStart:F.onConnectStart,onConnectEnd:(...V)=>T.getState().onConnectEnd?.(...V),updateConnection:F.updateConnection,onConnect:Y,isValidConnection:s||((...V)=>T.getState().isValidConnection?.(...V)??!0),getTransform:()=>T.getState().transform,getFromHandle:()=>T.getState().connection.fromHandle,autoPanSpeed:F.autoPanSpeed,dragThreshold:F.connectionDragThreshold})}A?x?.(I):p?.(I)},R=I=>{const{onClickConnectStart:A,onClickConnectEnd:F,connectionClickStartHandle:V,connectionMode:X,isValidConnection:O,lib:U,rfId:K,nodeLookup:D,connection:E}=T.getState();if(!_||!V&&!o)return;if(!V){A?.(I.nativeEvent,{nodeId:_,handleId:w,handleType:e}),T.setState({connectionClickStartHandle:{nodeId:_,type:e,id:w}});return}const H=Lw(I.target),Z=s||O,{connection:ee,isValid:ne}=Gm.isValid(I.nativeEvent,{handle:{nodeId:_,id:w,type:e},connectionMode:X,fromNodeId:V.nodeId,fromHandleId:V.id||null,fromType:V.type,isValidConnection:Z,flowId:K,doc:H,lib:U,nodeLookup:D});ne&&ee&&Y(ee);const ae=structuredClone(E);delete ae.inProgress,ae.toPosition=ae.toHandle?ae.toHandle.position:null,F?.(I,ae),T.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":w,"data-nodeid":_,"data-handlepos":n,"data-id":`${C}-${_}-${w}-${e}`,className:Xn(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",k,f,{source:!N,target:N,connectable:i,connectablestart:o,connectableend:d,clickconnecting:P,connectingfrom:M,connectingto:L,valid:q,connectionindicator:i&&(!W||G)&&(W||z?d:o)}]),onMouseDown:$,onTouchStart:$,onClick:S?R:void 0,ref:y,...g,children:m})}const $a=v.memo(lN(kD));function SD({data:e,isConnectable:n,sourcePosition:s=ut.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx($a,{type:"source",position:s,isConnectable:n})]})}function CD({data:e,isConnectable:n,targetPosition:s=ut.Top,sourcePosition:i=ut.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx($a,{type:"target",position:s,isConnectable:n}),e?.label,t.jsx($a,{type:"source",position:i,isConnectable:n})]})}function ED(){return null}function TD({data:e,isConnectable:n,targetPosition:s=ut.Top}){return t.jsxs(t.Fragment,{children:[t.jsx($a,{type:"target",position:s,isConnectable:n}),e?.label]})}const Kd={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Hv={input:SD,default:CD,output:TD,group:ED};function _D(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 AD=e=>{const{width:n,height:s,x:i,y:o}=ec(e.nodeLookup,{filter:d=>!!d.selected});return{width:ds(n)?n:null,height:ds(s)?s:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${i}px,${o}px)`}};function MD({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:s}){const i=An(),{width:o,height:d,transformString:c,userSelectionActive:h}=Zt(AD,_n),m=dN(),f=v.useRef(null);v.useEffect(()=>{s||f.current?.focus({preventScroll:!0})},[s]);const x=!h&&o!==null&&d!==null;if(cN({nodeRef:f,disabled:!x}),!x)return null;const p=e?y=>{const w=i.getState().nodes.filter(N=>N.selected);e(y,w)}:void 0,g=y=>{Object.prototype.hasOwnProperty.call(Kd,y.key)&&(y.preventDefault(),m({direction:Kd[y.key],factor:y.shiftKey?4:1}))};return t.jsx("div",{className:Xn(["react-flow__nodesselection","react-flow__container",n]),style:{transform:c},children:t.jsx("div",{ref:f,className:"react-flow__nodesselection-rect",onContextMenu:p,tabIndex:s?void 0:-1,onKeyDown:s?void 0:g,style:{width:o,height:d}})})}const Pv=typeof window<"u"?window:void 0,RD=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function fN({children:e,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:i,onPaneMouseLeave:o,onPaneContextMenu:d,onPaneScroll:c,paneClickDistance:h,deleteKeyCode:m,selectionKeyCode:f,selectionOnDrag:x,selectionMode:p,onSelectionStart:g,onSelectionEnd:y,multiSelectionKeyCode:w,panActivationKeyCode:N,zoomActivationKeyCode:T,elementsSelectable:_,zoomOnScroll:S,zoomOnPinch:k,panOnScroll:C,panOnScrollSpeed:M,panOnScrollMode:L,zoomOnDoubleClick:P,panOnDrag:G,defaultViewport:W,translateExtent:z,minZoom:q,maxZoom:Y,preventScrolling:$,onSelectionContextMenu:R,noWheelClassName:I,noPanClassName:A,disableKeyboardA11y:F,onViewportChange:V,isControlledViewport:X}){const{nodesSelectionActive:O,userSelectionActive:U}=Zt(RD,_n),K=Fo(f,{target:Pv}),D=Fo(N,{target:Pv}),E=D||G,H=D||C,Z=x&&E!==!0,ee=K||U||Z;return fD({deleteKeyCode:m,multiSelectionKeyCode:w}),t.jsx(xD,{onPaneContextMenu:d,elementsSelectable:_,zoomOnScroll:S,zoomOnPinch:k,panOnScroll:H,panOnScrollSpeed:M,panOnScrollMode:L,zoomOnDoubleClick:P,panOnDrag:!K&&E,defaultViewport:W,translateExtent:z,minZoom:q,maxZoom:Y,zoomActivationKeyCode:T,preventScrolling:$,noWheelClassName:I,noPanClassName:A,onViewportChange:V,isControlledViewport:X,paneClickDistance:h,selectionOnDrag:Z,children:t.jsxs(yD,{onSelectionStart:g,onSelectionEnd:y,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:i,onPaneMouseLeave:o,onPaneContextMenu:d,onPaneScroll:c,panOnDrag:E,isSelecting:!!ee,selectionMode:p,selectionKeyPressed:K,paneClickDistance:h,selectionOnDrag:Z,children:[e,O&&t.jsx(MD,{onSelectionContextMenu:R,noPanClassName:A,disableKeyboardA11y:F})]})})}fN.displayName="FlowRenderer";const OD=v.memo(fN),DD=e=>n=>e?Ax(n.nodeLookup,{x:0,y:0,width:n.width,height:n.height},n.transform,!0).map(s=>s.id):Array.from(n.nodeLookup.keys());function LD(e){return Zt(v.useCallback(DD(e),[e]),_n)}const ID=e=>e.updateNodeInternals;function zD(){const e=Zt(ID),[n]=v.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const i=new Map;s.forEach(o=>{const d=o.target.getAttribute("data-id");i.set(d,{id:d,nodeElement:o.target,force:!0})}),e(i)}));return v.useEffect(()=>()=>{n?.disconnect()},[n]),n}function $D({node:e,nodeType:n,hasDimensions:s,resizeObserver:i}){const o=An(),d=v.useRef(null),c=v.useRef(null),h=v.useRef(e.sourcePosition),m=v.useRef(e.targetPosition),f=v.useRef(n),x=s&&!!e.internals.handleBounds;return v.useEffect(()=>{d.current&&!e.hidden&&(!x||c.current!==d.current)&&(c.current&&i?.unobserve(c.current),i?.observe(d.current),c.current=d.current)},[x,e.hidden]),v.useEffect(()=>()=>{c.current&&(i?.unobserve(c.current),c.current=null)},[]),v.useEffect(()=>{if(d.current){const p=f.current!==n,g=h.current!==e.sourcePosition,y=m.current!==e.targetPosition;(p||g||y)&&(f.current=n,h.current=e.sourcePosition,m.current=e.targetPosition,o.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:d.current,force:!0}]])))}},[e.id,n,e.sourcePosition,e.targetPosition]),d}function BD({id:e,onClick:n,onMouseEnter:s,onMouseMove:i,onMouseLeave:o,onContextMenu:d,onDoubleClick:c,nodesDraggable:h,elementsSelectable:m,nodesConnectable:f,nodesFocusable:x,resizeObserver:p,noDragClassName:g,noPanClassName:y,disableKeyboardA11y:w,rfId:N,nodeTypes:T,nodeClickDistance:_,onError:S}){const{node:k,internals:C,isParent:M}=Zt(ne=>{const ae=ne.nodeLookup.get(e),he=ne.parentLookup.has(e);return{node:ae,internals:ae.internals,isParent:he}},_n);let L=k.type||"default",P=T?.[L]||Hv[L];P===void 0&&(S?.("003",Cs.error003(L)),L="default",P=T?.default||Hv.default);const G=!!(k.draggable||h&&typeof k.draggable>"u"),W=!!(k.selectable||m&&typeof k.selectable>"u"),z=!!(k.connectable||f&&typeof k.connectable>"u"),q=!!(k.focusable||x&&typeof k.focusable>"u"),Y=An(),$=Ow(k),R=$D({node:k,nodeType:L,hasDimensions:$,resizeObserver:p}),I=cN({nodeRef:R,disabled:k.hidden||!G,noDragClassName:g,handleSelector:k.dragHandle,nodeId:e,isSelectable:W,nodeClickDistance:_}),A=dN();if(k.hidden)return null;const F=na(k),V=_D(k),X=W||G||n||s||i||o,O=s?ne=>s(ne,{...C.userNode}):void 0,U=i?ne=>i(ne,{...C.userNode}):void 0,K=o?ne=>o(ne,{...C.userNode}):void 0,D=d?ne=>d(ne,{...C.userNode}):void 0,E=c?ne=>c(ne,{...C.userNode}):void 0,H=ne=>{const{selectNodesOnDrag:ae,nodeDragThreshold:he}=Y.getState();W&&(!ae||!G||he>0)&&Xm({id:e,store:Y,nodeRef:R}),n&&n(ne,{...C.userNode})},Z=ne=>{if(!(Iw(ne.nativeEvent)||w)){if(kw.includes(ne.key)&&W){const ae=ne.key==="Escape";Xm({id:e,store:Y,unselect:ae,nodeRef:R})}else if(G&&k.selected&&Object.prototype.hasOwnProperty.call(Kd,ne.key)){ne.preventDefault();const{ariaLabelConfig:ae}=Y.getState();Y.setState({ariaLiveMessage:ae["node.a11yDescription.ariaLiveMessage"]({direction:ne.key.replace("Arrow","").toLowerCase(),x:~~C.positionAbsolute.x,y:~~C.positionAbsolute.y})}),A({direction:Kd[ne.key],factor:ne.shiftKey?4:1})}}},ee=()=>{if(w||!R.current?.matches(":focus-visible"))return;const{transform:ne,width:ae,height:he,autoPanOnNodeFocus:Se,setCenter:Ie}=Y.getState();if(!Se)return;Ax(new Map([[e,k]]),{x:0,y:0,width:ae,height:he},ne,!0).length>0||Ie(k.position.x+F.width/2,k.position.y+F.height/2,{zoom:ne[2]})};return t.jsx("div",{className:Xn(["react-flow__node",`react-flow__node-${L}`,{[y]:G},k.className,{selected:k.selected,selectable:W,parent:M,draggable:G,dragging:I}]),ref:R,style:{zIndex:C.z,transform:`translate(${C.positionAbsolute.x}px,${C.positionAbsolute.y}px)`,pointerEvents:X?"all":"none",visibility:$?"visible":"hidden",...k.style,...V},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:O,onMouseMove:U,onMouseLeave:K,onContextMenu:D,onClick:H,onDoubleClick:E,onKeyDown:q?Z:void 0,tabIndex:q?0:void 0,onFocus:q?ee:void 0,role:k.ariaRole??(q?"group":void 0),"aria-roledescription":"node","aria-describedby":w?void 0:`${tN}-${N}`,"aria-label":k.ariaLabel,...k.domAttributes,children:t.jsx(jD,{value:e,children:t.jsx(P,{id:e,data:k.data,type:L,positionAbsoluteX:C.positionAbsolute.x,positionAbsoluteY:C.positionAbsolute.y,selected:k.selected??!1,selectable:W,draggable:G,deletable:k.deletable??!0,isConnectable:z,sourcePosition:k.sourcePosition,targetPosition:k.targetPosition,dragging:I,dragHandle:k.dragHandle,zIndex:C.z,parentId:k.parentId,...F})})})}var HD=v.memo(BD);const PD=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function hN(e){const{nodesDraggable:n,nodesConnectable:s,nodesFocusable:i,elementsSelectable:o,onError:d}=Zt(PD,_n),c=LD(e.onlyRenderVisibleElements),h=zD();return t.jsx("div",{className:"react-flow__nodes",style:pu,children:c.map(m=>t.jsx(HD,{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:h,nodesDraggable:n,nodesConnectable:s,nodesFocusable:i,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:d},m))})}hN.displayName="NodeRenderer";const UD=v.memo(hN);function qD(e){return Zt(v.useCallback(s=>{if(!e)return s.edges.map(o=>o.id);const i=[];if(s.width&&s.height)for(const o of s.edges){const d=s.nodeLookup.get(o.source),c=s.nodeLookup.get(o.target);d&&c&&PR({sourceNode:d,targetNode:c,width:s.width,height:s.height,transform:s.transform})&&i.push(o.id)}return i},[e]),_n)}const VD=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...e&&{stroke:e}};return t.jsx("polyline",{className:"arrow",style:s,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},FD=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...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"})},Uv={[ml.Arrow]:VD,[ml.ArrowClosed]:FD};function YD(e){const n=An();return v.useMemo(()=>Object.prototype.hasOwnProperty.call(Uv,e)?Uv[e]:(n.getState().onError?.("009",Cs.error009(e)),null),[e])}const GD=({id:e,type:n,color:s,width:i=12.5,height:o=12.5,markerUnits:d="strokeWidth",strokeWidth:c,orient:h="auto-start-reverse"})=>{const m=YD(n);return m?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${i}`,markerHeight:`${o}`,viewBox:"-10 -10 20 20",markerUnits:d,orient:h,refX:"0",refY:"0",children:t.jsx(m,{color:s,strokeWidth:c})}):null},mN=({defaultColor:e,rfId:n})=>{const s=Zt(d=>d.edges),i=Zt(d=>d.defaultEdgeOptions),o=v.useMemo(()=>KR(s,{id:n,defaultColor:e,defaultMarkerStart:i?.markerStart,defaultMarkerEnd:i?.markerEnd}),[s,i,n,e]);return o.length?t.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:t.jsx("defs",{children:o.map(d=>t.jsx(GD,{id:d.id,type:d.type,color:d.color,width:d.width,height:d.height,markerUnits:d.markerUnits,strokeWidth:d.strokeWidth,orient:d.orient},d.id))})}):null};mN.displayName="MarkerDefinitions";var XD=v.memo(mN);function xN({x:e,y:n,label:s,labelStyle:i,labelShowBg:o=!0,labelBgStyle:d,labelBgPadding:c=[2,4],labelBgBorderRadius:h=2,children:m,className:f,...x}){const[p,g]=v.useState({x:1,y:0,width:0,height:0}),y=Xn(["react-flow__edge-textwrapper",f]),w=v.useRef(null);return v.useEffect(()=>{if(w.current){const N=w.current.getBBox();g({x:N.x,y:N.y,width:N.width,height:N.height})}},[s]),s?t.jsxs("g",{transform:`translate(${e-p.width/2} ${n-p.height/2})`,className:y,visibility:p.width?"visible":"hidden",...x,children:[o&&t.jsx("rect",{width:p.width+2*c[0],x:-c[0],y:-c[1],height:p.height+2*c[1],className:"react-flow__edge-textbg",style:d,rx:h,ry:h}),t.jsx("text",{className:"react-flow__edge-text",y:p.height/2,dy:"0.3em",ref:w,style:i,children:s}),m]}):null}xN.displayName="EdgeText";const KD=v.memo(xN);function gu({path:e,labelX:n,labelY:s,label:i,labelStyle:o,labelShowBg:d,labelBgStyle:c,labelBgPadding:h,labelBgBorderRadius:m,interactionWidth:f=20,...x}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...x,d:e,fill:"none",className:Xn(["react-flow__edge-path",x.className])}),f?t.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}):null,i&&ds(n)&&ds(s)?t.jsx(KD,{x:n,y:s,label:i,labelStyle:o,labelShowBg:d,labelBgStyle:c,labelBgPadding:h,labelBgBorderRadius:m}):null]})}function qv({pos:e,x1:n,y1:s,x2:i,y2:o}){return e===ut.Left||e===ut.Right?[.5*(n+i),s]:[n,.5*(s+o)]}function pN({sourceX:e,sourceY:n,sourcePosition:s=ut.Bottom,targetX:i,targetY:o,targetPosition:d=ut.Top}){const[c,h]=qv({pos:s,x1:e,y1:n,x2:i,y2:o}),[m,f]=qv({pos:d,x1:i,y1:o,x2:e,y2:n}),[x,p,g,y]=$w({sourceX:e,sourceY:n,targetX:i,targetY:o,sourceControlX:c,sourceControlY:h,targetControlX:m,targetControlY:f});return[`M${e},${n} C${c},${h} ${m},${f} ${i},${o}`,x,p,g,y]}function gN(e){return v.memo(({id:n,sourceX:s,sourceY:i,targetX:o,targetY:d,sourcePosition:c,targetPosition:h,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:p,labelBgPadding:g,labelBgBorderRadius:y,style:w,markerEnd:N,markerStart:T,interactionWidth:_})=>{const[S,k,C]=pN({sourceX:s,sourceY:i,sourcePosition:c,targetX:o,targetY:d,targetPosition:h}),M=e.isInternal?void 0:n;return t.jsx(gu,{id:M,path:S,labelX:k,labelY:C,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:p,labelBgPadding:g,labelBgBorderRadius:y,style:w,markerEnd:N,markerStart:T,interactionWidth:_})})}const WD=gN({isInternal:!1}),bN=gN({isInternal:!0});WD.displayName="SimpleBezierEdge";bN.displayName="SimpleBezierEdgeInternal";function yN(e){return v.memo(({id:n,sourceX:s,sourceY:i,targetX:o,targetY:d,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:p,style:g,sourcePosition:y=ut.Bottom,targetPosition:w=ut.Top,markerEnd:N,markerStart:T,pathOptions:_,interactionWidth:S})=>{const[k,C,M]=Vm({sourceX:s,sourceY:i,sourcePosition:y,targetX:o,targetY:d,targetPosition:w,borderRadius:_?.borderRadius,offset:_?.offset,stepPosition:_?.stepPosition}),L=e.isInternal?void 0:n;return t.jsx(gu,{id:L,path:k,labelX:C,labelY:M,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:p,style:g,markerEnd:N,markerStart:T,interactionWidth:S})})}const vN=yN({isInternal:!1}),jN=yN({isInternal:!0});vN.displayName="SmoothStepEdge";jN.displayName="SmoothStepEdgeInternal";function wN(e){return v.memo(({id:n,...s})=>{const i=e.isInternal?void 0:n;return t.jsx(vN,{...s,id:i,pathOptions:v.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const QD=wN({isInternal:!1}),NN=wN({isInternal:!0});QD.displayName="StepEdge";NN.displayName="StepEdgeInternal";function kN(e){return v.memo(({id:n,sourceX:s,sourceY:i,targetX:o,targetY:d,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:p,style:g,markerEnd:y,markerStart:w,interactionWidth:N})=>{const[T,_,S]=Pw({sourceX:s,sourceY:i,targetX:o,targetY:d}),k=e.isInternal?void 0:n;return t.jsx(gu,{id:k,path:T,labelX:_,labelY:S,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:p,style:g,markerEnd:y,markerStart:w,interactionWidth:N})})}const ZD=kN({isInternal:!1}),SN=kN({isInternal:!0});ZD.displayName="StraightEdge";SN.displayName="StraightEdgeInternal";function CN(e){return v.memo(({id:n,sourceX:s,sourceY:i,targetX:o,targetY:d,sourcePosition:c=ut.Bottom,targetPosition:h=ut.Top,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:p,labelBgPadding:g,labelBgBorderRadius:y,style:w,markerEnd:N,markerStart:T,pathOptions:_,interactionWidth:S})=>{const[k,C,M]=Bw({sourceX:s,sourceY:i,sourcePosition:c,targetX:o,targetY:d,targetPosition:h,curvature:_?.curvature}),L=e.isInternal?void 0:n;return t.jsx(gu,{id:L,path:k,labelX:C,labelY:M,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:p,labelBgPadding:g,labelBgBorderRadius:y,style:w,markerEnd:N,markerStart:T,interactionWidth:S})})}const JD=CN({isInternal:!1}),EN=CN({isInternal:!0});JD.displayName="BezierEdge";EN.displayName="BezierEdgeInternal";const Vv={default:EN,straight:SN,step:NN,smoothstep:jN,simplebezier:bN},Fv={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},eL=(e,n,s)=>s===ut.Left?e-n:s===ut.Right?e+n:e,tL=(e,n,s)=>s===ut.Top?e-n:s===ut.Bottom?e+n:e,Yv="react-flow__edgeupdater";function Gv({position:e,centerX:n,centerY:s,radius:i=10,onMouseDown:o,onMouseEnter:d,onMouseOut:c,type:h}){return t.jsx("circle",{onMouseDown:o,onMouseEnter:d,onMouseOut:c,className:Xn([Yv,`${Yv}-${h}`]),cx:eL(n,i,e),cy:tL(s,i,e),r:i,stroke:"transparent",fill:"transparent"})}function nL({isReconnectable:e,reconnectRadius:n,edge:s,sourceX:i,sourceY:o,targetX:d,targetY:c,sourcePosition:h,targetPosition:m,onReconnect:f,onReconnectStart:x,onReconnectEnd:p,setReconnecting:g,setUpdateHover:y}){const w=An(),N=(C,M)=>{if(C.button!==0)return;const{autoPanOnConnect:L,domNode:P,connectionMode:G,connectionRadius:W,lib:z,onConnectStart:q,cancelConnection:Y,nodeLookup:$,rfId:R,panBy:I,updateConnection:A}=w.getState(),F=M.type==="target",V=(U,K)=>{g(!1),p?.(U,s,M.type,K)},X=U=>f?.(s,U),O=(U,K)=>{g(!0),x?.(C,s,M.type),q?.(U,K)};Gm.onPointerDown(C.nativeEvent,{autoPanOnConnect:L,connectionMode:G,connectionRadius:W,domNode:P,handleId:M.id,nodeId:M.nodeId,nodeLookup:$,isTarget:F,edgeUpdaterType:M.type,lib:z,flowId:R,cancelConnection:Y,panBy:I,isValidConnection:(...U)=>w.getState().isValidConnection?.(...U)??!0,onConnect:X,onConnectStart:O,onConnectEnd:(...U)=>w.getState().onConnectEnd?.(...U),onReconnectEnd:V,updateConnection:A,getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,dragThreshold:w.getState().connectionDragThreshold,handleDomNode:C.currentTarget})},T=C=>N(C,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),_=C=>N(C,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),S=()=>y(!0),k=()=>y(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(Gv,{position:h,centerX:i,centerY:o,radius:n,onMouseDown:T,onMouseEnter:S,onMouseOut:k,type:"source"}),(e===!0||e==="target")&&t.jsx(Gv,{position:m,centerX:d,centerY:c,radius:n,onMouseDown:_,onMouseEnter:S,onMouseOut:k,type:"target"})]})}function rL({id:e,edgesFocusable:n,edgesReconnectable:s,elementsSelectable:i,onClick:o,onDoubleClick:d,onContextMenu:c,onMouseEnter:h,onMouseMove:m,onMouseLeave:f,reconnectRadius:x,onReconnect:p,onReconnectStart:g,onReconnectEnd:y,rfId:w,edgeTypes:N,noPanClassName:T,onError:_,disableKeyboardA11y:S}){let k=Zt(Ie=>Ie.edgeLookup.get(e));const C=Zt(Ie=>Ie.defaultEdgeOptions);k=C?{...C,...k}:k;let M=k.type||"default",L=N?.[M]||Vv[M];L===void 0&&(_?.("011",Cs.error011(M)),M="default",L=N?.default||Vv.default);const P=!!(k.focusable||n&&typeof k.focusable>"u"),G=typeof p<"u"&&(k.reconnectable||s&&typeof k.reconnectable>"u"),W=!!(k.selectable||i&&typeof k.selectable>"u"),z=v.useRef(null),[q,Y]=v.useState(!1),[$,R]=v.useState(!1),I=An(),{zIndex:A,sourceX:F,sourceY:V,targetX:X,targetY:O,sourcePosition:U,targetPosition:K}=Zt(v.useCallback(Ie=>{const xe=Ie.nodeLookup.get(k.source),we=Ie.nodeLookup.get(k.target);if(!xe||!we)return{zIndex:k.zIndex,...Fv};const Me=XR({id:e,sourceNode:xe,targetNode:we,sourceHandle:k.sourceHandle||null,targetHandle:k.targetHandle||null,connectionMode:Ie.connectionMode,onError:_});return{zIndex:HR({selected:k.selected,zIndex:k.zIndex,sourceNode:xe,targetNode:we,elevateOnSelect:Ie.elevateEdgesOnSelect,zIndexMode:Ie.zIndexMode}),...Me||Fv}},[k.source,k.target,k.sourceHandle,k.targetHandle,k.selected,k.zIndex]),_n),D=v.useMemo(()=>k.markerStart?`url('#${Fm(k.markerStart,w)}')`:void 0,[k.markerStart,w]),E=v.useMemo(()=>k.markerEnd?`url('#${Fm(k.markerEnd,w)}')`:void 0,[k.markerEnd,w]);if(k.hidden||F===null||V===null||X===null||O===null)return null;const H=Ie=>{const{addSelectedEdges:xe,unselectNodesAndEdges:we,multiSelectionActive:Me}=I.getState();W&&(I.setState({nodesSelectionActive:!1}),k.selected&&Me?(we({nodes:[],edges:[k]}),z.current?.blur()):xe([e])),o&&o(Ie,k)},Z=d?Ie=>{d(Ie,{...k})}:void 0,ee=c?Ie=>{c(Ie,{...k})}:void 0,ne=h?Ie=>{h(Ie,{...k})}:void 0,ae=m?Ie=>{m(Ie,{...k})}:void 0,he=f?Ie=>{f(Ie,{...k})}:void 0,Se=Ie=>{if(!S&&kw.includes(Ie.key)&&W){const{unselectNodesAndEdges:xe,addSelectedEdges:we}=I.getState();Ie.key==="Escape"?(z.current?.blur(),xe({edges:[k]})):we([e])}};return t.jsx("svg",{style:{zIndex:A},children:t.jsxs("g",{className:Xn(["react-flow__edge",`react-flow__edge-${M}`,k.className,T,{selected:k.selected,animated:k.animated,inactive:!W&&!o,updating:q,selectable:W}]),onClick:H,onDoubleClick:Z,onContextMenu:ee,onMouseEnter:ne,onMouseMove:ae,onMouseLeave:he,onKeyDown:P?Se:void 0,tabIndex:P?0:void 0,role:k.ariaRole??(P?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":k.ariaLabel===null?void 0:k.ariaLabel||`Edge from ${k.source} to ${k.target}`,"aria-describedby":P?`${nN}-${w}`:void 0,ref:z,...k.domAttributes,children:[!$&&t.jsx(L,{id:e,source:k.source,target:k.target,type:k.type,selected:k.selected,animated:k.animated,selectable:W,deletable:k.deletable??!0,label:k.label,labelStyle:k.labelStyle,labelShowBg:k.labelShowBg,labelBgStyle:k.labelBgStyle,labelBgPadding:k.labelBgPadding,labelBgBorderRadius:k.labelBgBorderRadius,sourceX:F,sourceY:V,targetX:X,targetY:O,sourcePosition:U,targetPosition:K,data:k.data,style:k.style,sourceHandleId:k.sourceHandle,targetHandleId:k.targetHandle,markerStart:D,markerEnd:E,pathOptions:"pathOptions"in k?k.pathOptions:void 0,interactionWidth:k.interactionWidth}),G&&t.jsx(nL,{edge:k,isReconnectable:G,reconnectRadius:x,onReconnect:p,onReconnectStart:g,onReconnectEnd:y,sourceX:F,sourceY:V,targetX:X,targetY:O,sourcePosition:U,targetPosition:K,setUpdateHover:Y,setReconnecting:R})]})})}var sL=v.memo(rL);const aL=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function TN({defaultMarkerColor:e,onlyRenderVisibleElements:n,rfId:s,edgeTypes:i,noPanClassName:o,onReconnect:d,onEdgeContextMenu:c,onEdgeMouseEnter:h,onEdgeMouseMove:m,onEdgeMouseLeave:f,onEdgeClick:x,reconnectRadius:p,onEdgeDoubleClick:g,onReconnectStart:y,onReconnectEnd:w,disableKeyboardA11y:N}){const{edgesFocusable:T,edgesReconnectable:_,elementsSelectable:S,onError:k}=Zt(aL,_n),C=qD(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(XD,{defaultColor:e,rfId:s}),C.map(M=>t.jsx(sL,{id:M,edgesFocusable:T,edgesReconnectable:_,elementsSelectable:S,noPanClassName:o,onReconnect:d,onContextMenu:c,onMouseEnter:h,onMouseMove:m,onMouseLeave:f,onClick:x,reconnectRadius:p,onDoubleClick:g,onReconnectStart:y,onReconnectEnd:w,rfId:s,onError:k,edgeTypes:i,disableKeyboardA11y:N},M))]})}TN.displayName="EdgeRenderer";const iL=v.memo(TN),lL=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function oL({children:e}){const n=Zt(lL);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function cL(e){const n=$x(),s=v.useRef(!1);v.useEffect(()=>{!s.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),s.current=!0)},[e,n.viewportInitialized])}const dL=e=>e.panZoom?.syncViewport;function uL(e){const n=Zt(dL),s=An();return v.useEffect(()=>{e&&(n?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,n]),null}function fL(e){return e.connection.inProgress?{...e.connection,to:nc(e.connection.to,e.transform)}:{...e.connection}}function hL(e){return fL}function mL(e){const n=hL();return Zt(n,_n)}const xL=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function pL({containerStyle:e,style:n,type:s,component:i}){const{nodesConnectable:o,width:d,height:c,isValid:h,inProgress:m}=Zt(xL,_n);return!(d&&o&&m)?null:t.jsx("svg",{style:e,width:d,height:c,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:Xn(["react-flow__connection",Ew(h)]),children:t.jsx(_N,{style:n,type:s,CustomComponent:i,isValid:h})})})}const _N=({style:e,type:n=Ia.Bezier,CustomComponent:s,isValid:i})=>{const{inProgress:o,from:d,fromNode:c,fromHandle:h,fromPosition:m,to:f,toNode:x,toHandle:p,toPosition:g,pointer:y}=mL();if(!o)return;if(s)return t.jsx(s,{connectionLineType:n,connectionLineStyle:e,fromNode:c,fromHandle:h,fromX:d.x,fromY:d.y,toX:f.x,toY:f.y,fromPosition:m,toPosition:g,connectionStatus:Ew(i),toNode:x,toHandle:p,pointer:y});let w="";const N={sourceX:d.x,sourceY:d.y,sourcePosition:m,targetX:f.x,targetY:f.y,targetPosition:g};switch(n){case Ia.Bezier:[w]=Bw(N);break;case Ia.SimpleBezier:[w]=pN(N);break;case Ia.Step:[w]=Vm({...N,borderRadius:0});break;case Ia.SmoothStep:[w]=Vm(N);break;default:[w]=Pw(N)}return t.jsx("path",{d:w,fill:"none",className:"react-flow__connection-path",style:e})};_N.displayName="ConnectionLine";const gL={};function Xv(e=gL){v.useRef(e),An(),v.useEffect(()=>{},[e])}function bL(){An(),v.useRef(!1),v.useEffect(()=>{},[])}function AN({nodeTypes:e,edgeTypes:n,onInit:s,onNodeClick:i,onEdgeClick:o,onNodeDoubleClick:d,onEdgeDoubleClick:c,onNodeMouseEnter:h,onNodeMouseMove:m,onNodeMouseLeave:f,onNodeContextMenu:x,onSelectionContextMenu:p,onSelectionStart:g,onSelectionEnd:y,connectionLineType:w,connectionLineStyle:N,connectionLineComponent:T,connectionLineContainerStyle:_,selectionKeyCode:S,selectionOnDrag:k,selectionMode:C,multiSelectionKeyCode:M,panActivationKeyCode:L,zoomActivationKeyCode:P,deleteKeyCode:G,onlyRenderVisibleElements:W,elementsSelectable:z,defaultViewport:q,translateExtent:Y,minZoom:$,maxZoom:R,preventScrolling:I,defaultMarkerColor:A,zoomOnScroll:F,zoomOnPinch:V,panOnScroll:X,panOnScrollSpeed:O,panOnScrollMode:U,zoomOnDoubleClick:K,panOnDrag:D,onPaneClick:E,onPaneMouseEnter:H,onPaneMouseMove:Z,onPaneMouseLeave:ee,onPaneScroll:ne,onPaneContextMenu:ae,paneClickDistance:he,nodeClickDistance:Se,onEdgeContextMenu:Ie,onEdgeMouseEnter:xe,onEdgeMouseMove:we,onEdgeMouseLeave:Me,reconnectRadius:Be,onReconnect:et,onReconnectStart:lt,onReconnectEnd:ft,noDragClassName:yt,noWheelClassName:re,noPanClassName:Te,disableKeyboardA11y:rt,nodeExtent:wt,rfId:Lt,viewport:je,onViewportChange:De}){return Xv(e),Xv(n),bL(),cL(s),uL(je),t.jsx(OD,{onPaneClick:E,onPaneMouseEnter:H,onPaneMouseMove:Z,onPaneMouseLeave:ee,onPaneContextMenu:ae,onPaneScroll:ne,paneClickDistance:he,deleteKeyCode:G,selectionKeyCode:S,selectionOnDrag:k,selectionMode:C,onSelectionStart:g,onSelectionEnd:y,multiSelectionKeyCode:M,panActivationKeyCode:L,zoomActivationKeyCode:P,elementsSelectable:z,zoomOnScroll:F,zoomOnPinch:V,zoomOnDoubleClick:K,panOnScroll:X,panOnScrollSpeed:O,panOnScrollMode:U,panOnDrag:D,defaultViewport:q,translateExtent:Y,minZoom:$,maxZoom:R,onSelectionContextMenu:p,preventScrolling:I,noDragClassName:yt,noWheelClassName:re,noPanClassName:Te,disableKeyboardA11y:rt,onViewportChange:De,isControlledViewport:!!je,children:t.jsxs(oL,{children:[t.jsx(iL,{edgeTypes:n,onEdgeClick:o,onEdgeDoubleClick:c,onReconnect:et,onReconnectStart:lt,onReconnectEnd:ft,onlyRenderVisibleElements:W,onEdgeContextMenu:Ie,onEdgeMouseEnter:xe,onEdgeMouseMove:we,onEdgeMouseLeave:Me,reconnectRadius:Be,defaultMarkerColor:A,noPanClassName:Te,disableKeyboardA11y:rt,rfId:Lt}),t.jsx(pL,{style:N,type:w,component:T,containerStyle:_}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(UD,{nodeTypes:e,onNodeClick:i,onNodeDoubleClick:d,onNodeMouseEnter:h,onNodeMouseMove:m,onNodeMouseLeave:f,onNodeContextMenu:x,nodeClickDistance:Se,onlyRenderVisibleElements:W,noPanClassName:Te,noDragClassName:yt,disableKeyboardA11y:rt,nodeExtent:wt,rfId:Lt}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}AN.displayName="GraphView";const yL=v.memo(AN),Kv=({nodes:e,edges:n,defaultNodes:s,defaultEdges:i,width:o,height:d,fitView:c,fitViewOptions:h,minZoom:m=.5,maxZoom:f=2,nodeOrigin:x,nodeExtent:p,zIndexMode:g="basic"}={})=>{const y=new Map,w=new Map,N=new Map,T=new Map,_=i??n??[],S=s??e??[],k=x??[0,0],C=p??Po;Vw(N,T,_);const M=Ym(S,y,w,{nodeOrigin:k,nodeExtent:C,zIndexMode:g});let L=[0,0,1];if(c&&o&&d){const P=ec(y,{filter:q=>!!((q.width||q.initialWidth)&&(q.height||q.initialHeight))}),{x:G,y:W,zoom:z}=Mx(P,o,d,m,f,h?.padding??.1);L=[G,W,z]}return{rfId:"1",width:o??0,height:d??0,transform:L,nodes:S,nodesInitialized:M,nodeLookup:y,parentLookup:w,edges:_,edgeLookup:T,connectionLookup:N,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:i!==void 0,panZoom:null,minZoom:m,maxZoom:f,translateExtent:Po,nodeExtent:C,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:hl.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:k,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:c??!1,fitViewOptions:h,fitViewResolver:null,connection:{...Cw},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:DR,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Sw,zIndexMode:g,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},vL=({nodes:e,edges:n,defaultNodes:s,defaultEdges:i,width:o,height:d,fitView:c,fitViewOptions:h,minZoom:m,maxZoom:f,nodeOrigin:x,nodeExtent:p,zIndexMode:g})=>$O((y,w)=>{async function N(){const{nodeLookup:T,panZoom:_,fitViewOptions:S,fitViewResolver:k,width:C,height:M,minZoom:L,maxZoom:P}=w();_&&(await RR({nodes:T,width:C,height:M,panZoom:_,minZoom:L,maxZoom:P},S),k?.resolve(!0),y({fitViewResolver:null}))}return{...Kv({nodes:e,edges:n,width:o,height:d,fitView:c,fitViewOptions:h,minZoom:m,maxZoom:f,nodeOrigin:x,nodeExtent:p,defaultNodes:s,defaultEdges:i,zIndexMode:g}),setNodes:T=>{const{nodeLookup:_,parentLookup:S,nodeOrigin:k,elevateNodesOnSelect:C,fitViewQueued:M,zIndexMode:L}=w(),P=Ym(T,_,S,{nodeOrigin:k,nodeExtent:p,elevateNodesOnSelect:C,checkEquality:!0,zIndexMode:L});M&&P?(N(),y({nodes:T,nodesInitialized:P,fitViewQueued:!1,fitViewOptions:void 0})):y({nodes:T,nodesInitialized:P})},setEdges:T=>{const{connectionLookup:_,edgeLookup:S}=w();Vw(_,S,T),y({edges:T})},setDefaultNodesAndEdges:(T,_)=>{if(T){const{setNodes:S}=w();S(T),y({hasDefaultNodes:!0})}if(_){const{setEdges:S}=w();S(_),y({hasDefaultEdges:!0})}},updateNodeInternals:T=>{const{triggerNodeChanges:_,nodeLookup:S,parentLookup:k,domNode:C,nodeOrigin:M,nodeExtent:L,debug:P,fitViewQueued:G,zIndexMode:W}=w(),{changes:z,updatedInternals:q}=nO(T,S,k,C,M,L,W);q&&(ZR(S,k,{nodeOrigin:M,nodeExtent:L,zIndexMode:W}),G?(N(),y({fitViewQueued:!1,fitViewOptions:void 0})):y({}),z?.length>0&&(P&&console.log("React Flow: trigger node changes",z),_?.(z)))},updateNodePositions:(T,_=!1)=>{const S=[];let k=[];const{nodeLookup:C,triggerNodeChanges:M,connection:L,updateConnection:P,onNodesChangeMiddlewareMap:G}=w();for(const[W,z]of T){const q=C.get(W),Y=!!(q?.expandParent&&q?.parentId&&z?.position),$={id:W,type:"position",position:Y?{x:Math.max(0,z.position.x),y:Math.max(0,z.position.y)}:z.position,dragging:_};if(q&&L.inProgress&&L.fromNode.id===q.id){const R=bi(q,L.fromHandle,ut.Left,!0);P({...L,from:R})}Y&&q.parentId&&S.push({id:W,parentId:q.parentId,rect:{...z.internals.positionAbsolute,width:z.measured.width??0,height:z.measured.height??0}}),k.push($)}if(S.length>0){const{parentLookup:W,nodeOrigin:z}=w(),q=zx(S,C,W,z);k.push(...q)}for(const W of G.values())k=W(k);M(k)},triggerNodeChanges:T=>{const{onNodesChange:_,setNodes:S,nodes:k,hasDefaultNodes:C,debug:M}=w();if(T?.length){if(C){const L=aN(T,k);S(L)}M&&console.log("React Flow: trigger node changes",T),_?.(T)}},triggerEdgeChanges:T=>{const{onEdgesChange:_,setEdges:S,edges:k,hasDefaultEdges:C,debug:M}=w();if(T?.length){if(C){const L=iN(T,k);S(L)}M&&console.log("React Flow: trigger edge changes",T),_?.(T)}},addSelectedNodes:T=>{const{multiSelectionActive:_,edgeLookup:S,nodeLookup:k,triggerNodeChanges:C,triggerEdgeChanges:M}=w();if(_){const L=T.map(P=>li(P,!0));C(L);return}C(il(k,new Set([...T]),!0)),M(il(S))},addSelectedEdges:T=>{const{multiSelectionActive:_,edgeLookup:S,nodeLookup:k,triggerNodeChanges:C,triggerEdgeChanges:M}=w();if(_){const L=T.map(P=>li(P,!0));M(L);return}M(il(S,new Set([...T]))),C(il(k,new Set,!0))},unselectNodesAndEdges:({nodes:T,edges:_}={})=>{const{edges:S,nodes:k,nodeLookup:C,triggerNodeChanges:M,triggerEdgeChanges:L}=w(),P=T||k,G=_||S,W=[];for(const q of P){if(!q.selected)continue;const Y=C.get(q.id);Y&&(Y.selected=!1),W.push(li(q.id,!1))}const z=[];for(const q of G)q.selected&&z.push(li(q.id,!1));M(W),L(z)},setMinZoom:T=>{const{panZoom:_,maxZoom:S}=w();_?.setScaleExtent([T,S]),y({minZoom:T})},setMaxZoom:T=>{const{panZoom:_,minZoom:S}=w();_?.setScaleExtent([S,T]),y({maxZoom:T})},setTranslateExtent:T=>{w().panZoom?.setTranslateExtent(T),y({translateExtent:T})},resetSelectedElements:()=>{const{edges:T,nodes:_,triggerNodeChanges:S,triggerEdgeChanges:k,elementsSelectable:C}=w();if(!C)return;const M=_.reduce((P,G)=>G.selected?[...P,li(G.id,!1)]:P,[]),L=T.reduce((P,G)=>G.selected?[...P,li(G.id,!1)]:P,[]);S(M),k(L)},setNodeExtent:T=>{const{nodes:_,nodeLookup:S,parentLookup:k,nodeOrigin:C,elevateNodesOnSelect:M,nodeExtent:L,zIndexMode:P}=w();T[0][0]===L[0][0]&&T[0][1]===L[0][1]&&T[1][0]===L[1][0]&&T[1][1]===L[1][1]||(Ym(_,S,k,{nodeOrigin:C,nodeExtent:T,elevateNodesOnSelect:M,checkEquality:!1,zIndexMode:P}),y({nodeExtent:T}))},panBy:T=>{const{transform:_,width:S,height:k,panZoom:C,translateExtent:M}=w();return rO({delta:T,panZoom:C,transform:_,translateExtent:M,width:S,height:k})},setCenter:async(T,_,S)=>{const{width:k,height:C,maxZoom:M,panZoom:L}=w();if(!L)return Promise.resolve(!1);const P=typeof S?.zoom<"u"?S.zoom:M;return await L.setViewport({x:k/2-T*P,y:C/2-_*P,zoom:P},{duration:S?.duration,ease:S?.ease,interpolate:S?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{y({connection:{...Cw}})},updateConnection:T=>{y({connection:T})},reset:()=>y({...Kv()})}},Object.is);function jL({initialNodes:e,initialEdges:n,defaultNodes:s,defaultEdges:i,initialWidth:o,initialHeight:d,initialMinZoom:c,initialMaxZoom:h,initialFitViewOptions:m,fitView:f,nodeOrigin:x,nodeExtent:p,zIndexMode:g,children:y}){const[w]=v.useState(()=>vL({nodes:e,edges:n,defaultNodes:s,defaultEdges:i,width:o,height:d,fitView:f,minZoom:c,maxZoom:h,fitViewOptions:m,nodeOrigin:x,nodeExtent:p,zIndexMode:g}));return t.jsx(BO,{value:w,children:t.jsx(oD,{children:y})})}function wL({children:e,nodes:n,edges:s,defaultNodes:i,defaultEdges:o,width:d,height:c,fitView:h,fitViewOptions:m,minZoom:f,maxZoom:x,nodeOrigin:p,nodeExtent:g,zIndexMode:y}){return v.useContext(mu)?t.jsx(t.Fragment,{children:e}):t.jsx(jL,{initialNodes:n,initialEdges:s,defaultNodes:i,defaultEdges:o,initialWidth:d,initialHeight:c,fitView:h,initialFitViewOptions:m,initialMinZoom:f,initialMaxZoom:x,nodeOrigin:p,nodeExtent:g,zIndexMode:y,children:e})}const NL={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function kL({nodes:e,edges:n,defaultNodes:s,defaultEdges:i,className:o,nodeTypes:d,edgeTypes:c,onNodeClick:h,onEdgeClick:m,onInit:f,onMove:x,onMoveStart:p,onMoveEnd:g,onConnect:y,onConnectStart:w,onConnectEnd:N,onClickConnectStart:T,onClickConnectEnd:_,onNodeMouseEnter:S,onNodeMouseMove:k,onNodeMouseLeave:C,onNodeContextMenu:M,onNodeDoubleClick:L,onNodeDragStart:P,onNodeDrag:G,onNodeDragStop:W,onNodesDelete:z,onEdgesDelete:q,onDelete:Y,onSelectionChange:$,onSelectionDragStart:R,onSelectionDrag:I,onSelectionDragStop:A,onSelectionContextMenu:F,onSelectionStart:V,onSelectionEnd:X,onBeforeDelete:O,connectionMode:U,connectionLineType:K=Ia.Bezier,connectionLineStyle:D,connectionLineComponent:E,connectionLineContainerStyle:H,deleteKeyCode:Z="Backspace",selectionKeyCode:ee="Shift",selectionOnDrag:ne=!1,selectionMode:ae=Uo.Full,panActivationKeyCode:he="Space",multiSelectionKeyCode:Se=Vo()?"Meta":"Control",zoomActivationKeyCode:Ie=Vo()?"Meta":"Control",snapToGrid:xe,snapGrid:we,onlyRenderVisibleElements:Me=!1,selectNodesOnDrag:Be,nodesDraggable:et,autoPanOnNodeFocus:lt,nodesConnectable:ft,nodesFocusable:yt,nodeOrigin:re=rN,edgesFocusable:Te,edgesReconnectable:rt,elementsSelectable:wt=!0,defaultViewport:Lt=ZO,minZoom:je=.5,maxZoom:De=2,translateExtent:Ve=Po,preventScrolling:dt=!0,nodeExtent:st,defaultMarkerColor:zt="#b1b1b7",zoomOnScroll:fn=!0,zoomOnPinch:Mt=!0,panOnScroll:_t=!1,panOnScrollSpeed:$t=.5,panOnScrollMode:Tt=fi.Free,zoomOnDoubleClick:Bt=!0,panOnDrag:Xt=!0,onPaneClick:hn,onPaneMouseEnter:ve,onPaneMouseMove:tt,onPaneMouseLeave:Et,onPaneScroll:Pe,onPaneContextMenu:vt,paneClickDistance:mn=1,nodeClickDistance:Rn=0,children:kn,onReconnect:Jt,onReconnectStart:sn,onReconnectEnd:On,onEdgeContextMenu:Nt,onEdgeDoubleClick:en,onEdgeMouseEnter:Bn,onEdgeMouseMove:le,onEdgeMouseLeave:ze,reconnectRadius:Fe=10,onNodesChange:Qe,onEdgesChange:Xe,noDragClassName:Ye="nodrag",noWheelClassName:nt="nowheel",noPanClassName:pt="nopan",fitView:an,fitViewOptions:It,connectOnClick:xn,attributionPosition:be,proOptions:Ge,defaultEdgeOptions:St,elevateNodesOnSelect:Ct=!0,elevateEdgesOnSelect:pn=!1,disableKeyboardA11y:Zn=!1,autoPanOnConnect:ir,autoPanOnNodeDrag:on,autoPanSpeed:ur,connectionRadius:ns,isValidConnection:de,onError:Ae,style:Ue,id:Ht,nodeDragThreshold:xr,connectionDragThreshold:Tr,viewport:Pr,onViewportChange:Ur,width:fr,height:Hn,colorMode:ra="light",debug:sa,onScroll:pr,ariaLabelConfig:_s,zIndexMode:qr="basic",...Ha},Jn){const Kn=Ht||"1",_r=nD(ra),rs=v.useCallback(gr=>{gr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),pr?.(gr)},[pr]);return t.jsx("div",{"data-testid":"rf__wrapper",...Ha,onScroll:rs,style:{...Ue,...NL},ref:Jn,className:Xn(["react-flow",o,_r]),id:Ht,role:"application",children:t.jsxs(wL,{nodes:e,edges:n,width:fr,height:Hn,fitView:an,fitViewOptions:It,minZoom:je,maxZoom:De,nodeOrigin:re,nodeExtent:st,zIndexMode:qr,children:[t.jsx(yL,{onInit:f,onNodeClick:h,onEdgeClick:m,onNodeMouseEnter:S,onNodeMouseMove:k,onNodeMouseLeave:C,onNodeContextMenu:M,onNodeDoubleClick:L,nodeTypes:d,edgeTypes:c,connectionLineType:K,connectionLineStyle:D,connectionLineComponent:E,connectionLineContainerStyle:H,selectionKeyCode:ee,selectionOnDrag:ne,selectionMode:ae,deleteKeyCode:Z,multiSelectionKeyCode:Se,panActivationKeyCode:he,zoomActivationKeyCode:Ie,onlyRenderVisibleElements:Me,defaultViewport:Lt,translateExtent:Ve,minZoom:je,maxZoom:De,preventScrolling:dt,zoomOnScroll:fn,zoomOnPinch:Mt,zoomOnDoubleClick:Bt,panOnScroll:_t,panOnScrollSpeed:$t,panOnScrollMode:Tt,panOnDrag:Xt,onPaneClick:hn,onPaneMouseEnter:ve,onPaneMouseMove:tt,onPaneMouseLeave:Et,onPaneScroll:Pe,onPaneContextMenu:vt,paneClickDistance:mn,nodeClickDistance:Rn,onSelectionContextMenu:F,onSelectionStart:V,onSelectionEnd:X,onReconnect:Jt,onReconnectStart:sn,onReconnectEnd:On,onEdgeContextMenu:Nt,onEdgeDoubleClick:en,onEdgeMouseEnter:Bn,onEdgeMouseMove:le,onEdgeMouseLeave:ze,reconnectRadius:Fe,defaultMarkerColor:zt,noDragClassName:Ye,noWheelClassName:nt,noPanClassName:pt,rfId:Kn,disableKeyboardA11y:Zn,nodeExtent:st,viewport:Pr,onViewportChange:Ur}),t.jsx(tD,{nodes:e,edges:n,defaultNodes:s,defaultEdges:i,onConnect:y,onConnectStart:w,onConnectEnd:N,onClickConnectStart:T,onClickConnectEnd:_,nodesDraggable:et,autoPanOnNodeFocus:lt,nodesConnectable:ft,nodesFocusable:yt,edgesFocusable:Te,edgesReconnectable:rt,elementsSelectable:wt,elevateNodesOnSelect:Ct,elevateEdgesOnSelect:pn,minZoom:je,maxZoom:De,nodeExtent:st,onNodesChange:Qe,onEdgesChange:Xe,snapToGrid:xe,snapGrid:we,connectionMode:U,translateExtent:Ve,connectOnClick:xn,defaultEdgeOptions:St,fitView:an,fitViewOptions:It,onNodesDelete:z,onEdgesDelete:q,onDelete:Y,onNodeDragStart:P,onNodeDrag:G,onNodeDragStop:W,onSelectionDrag:I,onSelectionDragStart:R,onSelectionDragStop:A,onMove:x,onMoveStart:p,onMoveEnd:g,noPanClassName:pt,nodeOrigin:re,rfId:Kn,autoPanOnConnect:ir,autoPanOnNodeDrag:on,autoPanSpeed:ur,onError:Ae,connectionRadius:ns,isValidConnection:de,selectNodesOnDrag:Be,nodeDragThreshold:xr,connectionDragThreshold:Tr,onBeforeDelete:O,debug:sa,ariaLabelConfig:_s,zIndexMode:qr}),t.jsx(QO,{onSelectionChange:$}),kn,t.jsx(YO,{proOptions:Ge,position:be}),t.jsx(FO,{rfId:Kn,disableKeyboardA11y:Zn})]})})}var SL=lN(kL);function CL(e){const[n,s]=v.useState(e),i=v.useCallback(o=>s(d=>aN(o,d)),[]);return[n,s,i]}function EL(e){const[n,s]=v.useState(e),i=v.useCallback(o=>s(d=>iN(o,d)),[]);return[n,s,i]}function TL({dimensions:e,lineWidth:n,variant:s,className:i}){return t.jsx("path",{strokeWidth:n,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Xn(["react-flow__background-pattern",s,i])})}function _L({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Xn(["react-flow__background-pattern","dots",n])})}var za;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(za||(za={}));const AL={[za.Dots]:1,[za.Lines]:1,[za.Cross]:6},ML=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function MN({id:e,variant:n=za.Dots,gap:s=20,size:i,lineWidth:o=1,offset:d=0,color:c,bgColor:h,style:m,className:f,patternClassName:x}){const p=v.useRef(null),{transform:g,patternId:y}=Zt(ML,_n),w=i||AL[n],N=n===za.Dots,T=n===za.Cross,_=Array.isArray(s)?s:[s,s],S=[_[0]*g[2]||1,_[1]*g[2]||1],k=w*g[2],C=Array.isArray(d)?d:[d,d],M=T?[k,k]:S,L=[C[0]*g[2]||1+M[0]/2,C[1]*g[2]||1+M[1]/2],P=`${y}${e||""}`;return t.jsxs("svg",{className:Xn(["react-flow__background",f]),style:{...m,...pu,"--xy-background-color-props":h,"--xy-background-pattern-color-props":c},ref:p,"data-testid":"rf__background",children:[t.jsx("pattern",{id:P,x:g[0]%S[0],y:g[1]%S[1],width:S[0],height:S[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${L[0]},-${L[1]})`,children:N?t.jsx(_L,{radius:k/2,className:x}):t.jsx(TL,{dimensions:M,lineWidth:o,variant:n,className:x})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${P})`})]})}MN.displayName="Background";const RL=v.memo(MN);function OL(){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 DL(){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 LL(){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 IL(){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 zL(){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 jd({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:Xn(["react-flow__controls-button",n]),...s,children:e})}const $L=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function RN({style:e,showZoom:n=!0,showFitView:s=!0,showInteractive:i=!0,fitViewOptions:o,onZoomIn:d,onZoomOut:c,onFitView:h,onInteractiveChange:m,className:f,children:x,position:p="bottom-left",orientation:g="vertical","aria-label":y}){const w=An(),{isInteractive:N,minZoomReached:T,maxZoomReached:_,ariaLabelConfig:S}=Zt($L,_n),{zoomIn:k,zoomOut:C,fitView:M}=$x(),L=()=>{k(),d?.()},P=()=>{C(),c?.()},G=()=>{M(o),h?.()},W=()=>{w.setState({nodesDraggable:!N,nodesConnectable:!N,elementsSelectable:!N}),m?.(!N)},z=g==="horizontal"?"horizontal":"vertical";return t.jsxs(xu,{className:Xn(["react-flow__controls",z,f]),position:p,style:e,"data-testid":"rf__controls","aria-label":y??S["controls.ariaLabel"],children:[n&&t.jsxs(t.Fragment,{children:[t.jsx(jd,{onClick:L,className:"react-flow__controls-zoomin",title:S["controls.zoomIn.ariaLabel"],"aria-label":S["controls.zoomIn.ariaLabel"],disabled:_,children:t.jsx(OL,{})}),t.jsx(jd,{onClick:P,className:"react-flow__controls-zoomout",title:S["controls.zoomOut.ariaLabel"],"aria-label":S["controls.zoomOut.ariaLabel"],disabled:T,children:t.jsx(DL,{})})]}),s&&t.jsx(jd,{className:"react-flow__controls-fitview",onClick:G,title:S["controls.fitView.ariaLabel"],"aria-label":S["controls.fitView.ariaLabel"],children:t.jsx(LL,{})}),i&&t.jsx(jd,{className:"react-flow__controls-interactive",onClick:W,title:S["controls.interactive.ariaLabel"],"aria-label":S["controls.interactive.ariaLabel"],children:N?t.jsx(zL,{}):t.jsx(IL,{})}),x]})}RN.displayName="Controls";const BL=v.memo(RN);function HL({id:e,x:n,y:s,width:i,height:o,style:d,color:c,strokeColor:h,strokeWidth:m,className:f,borderRadius:x,shapeRendering:p,selected:g,onClick:y}){const{background:w,backgroundColor:N}=d||{},T=c||w||N;return t.jsx("rect",{className:Xn(["react-flow__minimap-node",{selected:g},f]),x:n,y:s,rx:x,ry:x,width:i,height:o,style:{fill:T,stroke:h,strokeWidth:m},shapeRendering:p,onClick:y?_=>y(_,e):void 0})}const PL=v.memo(HL),UL=e=>e.nodes.map(n=>n.id),im=e=>e instanceof Function?e:()=>e;function qL({nodeStrokeColor:e,nodeColor:n,nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o,nodeComponent:d=PL,onClick:c}){const h=Zt(UL,_n),m=im(n),f=im(e),x=im(s),p=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:h.map(g=>t.jsx(FL,{id:g,nodeColorFunc:m,nodeStrokeColorFunc:f,nodeClassNameFunc:x,nodeBorderRadius:i,nodeStrokeWidth:o,NodeComponent:d,onClick:c,shapeRendering:p},g))})}function VL({id:e,nodeColorFunc:n,nodeStrokeColorFunc:s,nodeClassNameFunc:i,nodeBorderRadius:o,nodeStrokeWidth:d,shapeRendering:c,NodeComponent:h,onClick:m}){const{node:f,x,y:p,width:g,height:y}=Zt(w=>{const N=w.nodeLookup.get(e);if(!N)return{node:void 0,x:0,y:0,width:0,height:0};const T=N.internals.userNode,{x:_,y:S}=N.internals.positionAbsolute,{width:k,height:C}=na(T);return{node:T,x:_,y:S,width:k,height:C}},_n);return!f||f.hidden||!Ow(f)?null:t.jsx(h,{x,y:p,width:g,height:y,style:f.style,selected:!!f.selected,className:i(f),color:n(f),borderRadius:o,strokeColor:s(f),strokeWidth:d,shapeRendering:c,onClick:m,id:f.id})}const FL=v.memo(VL);var YL=v.memo(qL);const GL=200,XL=150,KL=e=>!e.hidden,WL=e=>{const n={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:n,boundingRect:e.nodeLookup.size>0?Rw(ec(e.nodeLookup,{filter:KL}),n):n,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},QL="react-flow__minimap-desc";function ON({style:e,className:n,nodeStrokeColor:s,nodeColor:i,nodeClassName:o="",nodeBorderRadius:d=5,nodeStrokeWidth:c,nodeComponent:h,bgColor:m,maskColor:f,maskStrokeColor:x,maskStrokeWidth:p,position:g="bottom-right",onClick:y,onNodeClick:w,pannable:N=!1,zoomable:T=!1,ariaLabel:_,inversePan:S,zoomStep:k=1,offsetScale:C=5}){const M=An(),L=v.useRef(null),{boundingRect:P,viewBB:G,rfId:W,panZoom:z,translateExtent:q,flowWidth:Y,flowHeight:$,ariaLabelConfig:R}=Zt(WL,_n),I=e?.width??GL,A=e?.height??XL,F=P.width/I,V=P.height/A,X=Math.max(F,V),O=X*I,U=X*A,K=C*X,D=P.x-(O-P.width)/2-K,E=P.y-(U-P.height)/2-K,H=O+K*2,Z=U+K*2,ee=`${QL}-${W}`,ne=v.useRef(0),ae=v.useRef();ne.current=X,v.useEffect(()=>{if(L.current&&z)return ae.current=fO({domNode:L.current,panZoom:z,getTransform:()=>M.getState().transform,getViewScale:()=>ne.current}),()=>{ae.current?.destroy()}},[z]),v.useEffect(()=>{ae.current?.update({translateExtent:q,width:Y,height:$,inversePan:S,pannable:N,zoomStep:k,zoomable:T})},[N,T,S,k,q,Y,$]);const he=y?xe=>{const[we,Me]=ae.current?.pointer(xe)||[0,0];y(xe,{x:we,y:Me})}:void 0,Se=w?v.useCallback((xe,we)=>{const Me=M.getState().nodeLookup.get(we).internals.userNode;w(xe,Me)},[]):void 0,Ie=_??R["minimap.ariaLabel"];return t.jsx(xu,{position:g,style:{...e,"--xy-minimap-background-color-props":typeof m=="string"?m:void 0,"--xy-minimap-mask-background-color-props":typeof f=="string"?f:void 0,"--xy-minimap-mask-stroke-color-props":typeof x=="string"?x:void 0,"--xy-minimap-mask-stroke-width-props":typeof p=="number"?p*X:void 0,"--xy-minimap-node-background-color-props":typeof i=="string"?i:void 0,"--xy-minimap-node-stroke-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-width-props":typeof c=="number"?c:void 0},className:Xn(["react-flow__minimap",n]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:I,height:A,viewBox:`${D} ${E} ${H} ${Z}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":ee,ref:L,onClick:he,children:[Ie&&t.jsx("title",{id:ee,children:Ie}),t.jsx(YL,{onClick:Se,nodeColor:i,nodeStrokeColor:s,nodeBorderRadius:d,nodeClassName:o,nodeStrokeWidth:c,nodeComponent:h}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${D-K},${E-K}h${H+K*2}v${Z+K*2}h${-H-K*2}z
61
61
  M${G.x},${G.y}h${G.width}v${G.height}h${-G.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}ON.displayName="MiniMap";const ZL=v.memo(ON),JL=e=>n=>e?`${Math.max(1/n.transform[2],1)}`:void 0,eI={[bl.Line]:"right",[bl.Handle]:"bottom-right"};function tI({nodeId:e,position:n,variant:s=bl.Handle,className:i,style:o=void 0,children:d,color:c,minWidth:h=10,minHeight:m=10,maxWidth:f=Number.MAX_VALUE,maxHeight:x=Number.MAX_VALUE,keepAspectRatio:p=!1,resizeDirection:g,autoScale:y=!0,shouldResize:w,onResizeStart:N,onResize:T,onResizeEnd:_}){const S=uN(),k=typeof e=="string"?e:S,C=An(),M=v.useRef(null),L=s===bl.Handle,P=Zt(v.useCallback(JL(L&&y),[L,y]),_n),G=v.useRef(null),W=n??eI[s];v.useEffect(()=>{if(!(!M.current||!k))return G.current||(G.current=CO({domNode:M.current,nodeId:k,getStoreItems:()=>{const{nodeLookup:q,transform:Y,snapGrid:$,snapToGrid:R,nodeOrigin:I,domNode:A}=C.getState();return{nodeLookup:q,transform:Y,snapGrid:$,snapToGrid:R,nodeOrigin:I,paneDomNode:A}},onChange:(q,Y)=>{const{triggerNodeChanges:$,nodeLookup:R,parentLookup:I,nodeOrigin:A}=C.getState(),F=[],V={x:q.x,y:q.y},X=R.get(k);if(X&&X.expandParent&&X.parentId){const O=X.origin??A,U=q.width??X.measured.width??0,K=q.height??X.measured.height??0,D={id:X.id,parentId:X.parentId,rect:{width:U,height:K,...Dw({x:q.x??X.position.x,y:q.y??X.position.y},{width:U,height:K},X.parentId,R,O)}},E=zx([D],R,I,A);F.push(...E),V.x=q.x?Math.max(O[0]*U,q.x):void 0,V.y=q.y?Math.max(O[1]*K,q.y):void 0}if(V.x!==void 0&&V.y!==void 0){const O={id:k,type:"position",position:{...V}};F.push(O)}if(q.width!==void 0&&q.height!==void 0){const U={id:k,type:"dimensions",resizing:!0,setAttributes:g?g==="horizontal"?"width":"height":!0,dimensions:{width:q.width,height:q.height}};F.push(U)}for(const O of Y){const U={...O,type:"position"};F.push(U)}$(F)},onEnd:({width:q,height:Y})=>{const $={id:k,type:"dimensions",resizing:!1,dimensions:{width:q,height:Y}};C.getState().triggerNodeChanges([$])}})),G.current.update({controlPosition:W,boundaries:{minWidth:h,minHeight:m,maxWidth:f,maxHeight:x},keepAspectRatio:p,resizeDirection:g,onResizeStart:N,onResize:T,onResizeEnd:_,shouldResize:w}),()=>{G.current?.destroy()}},[W,h,m,f,x,p,N,T,_,w]);const z=W.split("-");return t.jsx("div",{className:Xn(["react-flow__resize-control","nodrag",...z,s,i]),ref:M,style:{...o,scale:P,...c&&{[L?"backgroundColor":"borderColor"]:c}},children:d})}v.memo(tI);var un=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),hs=un((e,n)=>{var s=Object.defineProperty,i=($,R,I)=>R in $?s($,R,{enumerable:!0,configurable:!0,writable:!0,value:I}):$[R]=I,o=($,R)=>()=>(R||$((R={exports:{}}).exports,R),R.exports),d=($,R,I)=>i($,typeof R!="symbol"?R+"":R,I),c=o(($,R)=>{var I="\0",A="\0",F="",V=class{constructor(E){d(this,"_isDirected",!0),d(this,"_isMultigraph",!1),d(this,"_isCompound",!1),d(this,"_label"),d(this,"_defaultNodeLabelFn",()=>{}),d(this,"_defaultEdgeLabelFn",()=>{}),d(this,"_nodes",{}),d(this,"_in",{}),d(this,"_preds",{}),d(this,"_out",{}),d(this,"_sucs",{}),d(this,"_edgeObjs",{}),d(this,"_edgeLabels",{}),d(this,"_nodeCount",0),d(this,"_edgeCount",0),d(this,"_parent"),d(this,"_children"),E&&(this._isDirected=Object.hasOwn(E,"directed")?E.directed:!0,this._isMultigraph=Object.hasOwn(E,"multigraph")?E.multigraph:!1,this._isCompound=Object.hasOwn(E,"compound")?E.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[A]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(E){return this._label=E,this}graph(){return this._label}setDefaultNodeLabel(E){return this._defaultNodeLabelFn=E,typeof E!="function"&&(this._defaultNodeLabelFn=()=>E),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var E=this;return this.nodes().filter(H=>Object.keys(E._in[H]).length===0)}sinks(){var E=this;return this.nodes().filter(H=>Object.keys(E._out[H]).length===0)}setNodes(E,H){var Z=arguments,ee=this;return E.forEach(function(ne){Z.length>1?ee.setNode(ne,H):ee.setNode(ne)}),this}setNode(E,H){return Object.hasOwn(this._nodes,E)?(arguments.length>1&&(this._nodes[E]=H),this):(this._nodes[E]=arguments.length>1?H:this._defaultNodeLabelFn(E),this._isCompound&&(this._parent[E]=A,this._children[E]={},this._children[A][E]=!0),this._in[E]={},this._preds[E]={},this._out[E]={},this._sucs[E]={},++this._nodeCount,this)}node(E){return this._nodes[E]}hasNode(E){return Object.hasOwn(this._nodes,E)}removeNode(E){var H=this;if(Object.hasOwn(this._nodes,E)){var Z=ee=>H.removeEdge(H._edgeObjs[ee]);delete this._nodes[E],this._isCompound&&(this._removeFromParentsChildList(E),delete this._parent[E],this.children(E).forEach(function(ee){H.setParent(ee)}),delete this._children[E]),Object.keys(this._in[E]).forEach(Z),delete this._in[E],delete this._preds[E],Object.keys(this._out[E]).forEach(Z),delete this._out[E],delete this._sucs[E],--this._nodeCount}return this}setParent(E,H){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(H===void 0)H=A;else{H+="";for(var Z=H;Z!==void 0;Z=this.parent(Z))if(Z===E)throw new Error("Setting "+H+" as parent of "+E+" would create a cycle");this.setNode(H)}return this.setNode(E),this._removeFromParentsChildList(E),this._parent[E]=H,this._children[H][E]=!0,this}_removeFromParentsChildList(E){delete this._children[this._parent[E]][E]}parent(E){if(this._isCompound){var H=this._parent[E];if(H!==A)return H}}children(E=A){if(this._isCompound){var H=this._children[E];if(H)return Object.keys(H)}else{if(E===A)return this.nodes();if(this.hasNode(E))return[]}}predecessors(E){var H=this._preds[E];if(H)return Object.keys(H)}successors(E){var H=this._sucs[E];if(H)return Object.keys(H)}neighbors(E){var H=this.predecessors(E);if(H){let ee=new Set(H);for(var Z of this.successors(E))ee.add(Z);return Array.from(ee.values())}}isLeaf(E){var H;return this.isDirected()?H=this.successors(E):H=this.neighbors(E),H.length===0}filterNodes(E){var H=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});H.setGraph(this.graph());var Z=this;Object.entries(this._nodes).forEach(function([ae,he]){E(ae)&&H.setNode(ae,he)}),Object.values(this._edgeObjs).forEach(function(ae){H.hasNode(ae.v)&&H.hasNode(ae.w)&&H.setEdge(ae,Z.edge(ae))});var ee={};function ne(ae){var he=Z.parent(ae);return he===void 0||H.hasNode(he)?(ee[ae]=he,he):he in ee?ee[he]:ne(he)}return this._isCompound&&H.nodes().forEach(ae=>H.setParent(ae,ne(ae))),H}setDefaultEdgeLabel(E){return this._defaultEdgeLabelFn=E,typeof E!="function"&&(this._defaultEdgeLabelFn=()=>E),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(E,H){var Z=this,ee=arguments;return E.reduce(function(ne,ae){return ee.length>1?Z.setEdge(ne,ae,H):Z.setEdge(ne,ae),ae}),this}setEdge(){var E,H,Z,ee,ne=!1,ae=arguments[0];typeof ae=="object"&&ae!==null&&"v"in ae?(E=ae.v,H=ae.w,Z=ae.name,arguments.length===2&&(ee=arguments[1],ne=!0)):(E=ae,H=arguments[1],Z=arguments[3],arguments.length>2&&(ee=arguments[2],ne=!0)),E=""+E,H=""+H,Z!==void 0&&(Z=""+Z);var he=U(this._isDirected,E,H,Z);if(Object.hasOwn(this._edgeLabels,he))return ne&&(this._edgeLabels[he]=ee),this;if(Z!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(E),this.setNode(H),this._edgeLabels[he]=ne?ee:this._defaultEdgeLabelFn(E,H,Z);var Se=K(this._isDirected,E,H,Z);return E=Se.v,H=Se.w,Object.freeze(Se),this._edgeObjs[he]=Se,X(this._preds[H],E),X(this._sucs[E],H),this._in[H][he]=Se,this._out[E][he]=Se,this._edgeCount++,this}edge(E,H,Z){var ee=arguments.length===1?D(this._isDirected,arguments[0]):U(this._isDirected,E,H,Z);return this._edgeLabels[ee]}edgeAsObj(){let E=this.edge(...arguments);return typeof E!="object"?{label:E}:E}hasEdge(E,H,Z){var ee=arguments.length===1?D(this._isDirected,arguments[0]):U(this._isDirected,E,H,Z);return Object.hasOwn(this._edgeLabels,ee)}removeEdge(E,H,Z){var ee=arguments.length===1?D(this._isDirected,arguments[0]):U(this._isDirected,E,H,Z),ne=this._edgeObjs[ee];return ne&&(E=ne.v,H=ne.w,delete this._edgeLabels[ee],delete this._edgeObjs[ee],O(this._preds[H],E),O(this._sucs[E],H),delete this._in[H][ee],delete this._out[E][ee],this._edgeCount--),this}inEdges(E,H){return this.isDirected()?this.filterEdges(this._in[E],E,H):this.nodeEdges(E,H)}outEdges(E,H){return this.isDirected()?this.filterEdges(this._out[E],E,H):this.nodeEdges(E,H)}nodeEdges(E,H){if(E in this._nodes)return this.filterEdges({...this._in[E],...this._out[E]},E,H)}filterEdges(E,H,Z){if(E){var ee=Object.values(E);return Z?ee.filter(function(ne){return ne.v===H&&ne.w===Z||ne.v===Z&&ne.w===H}):ee}}};function X(E,H){E[H]?E[H]++:E[H]=1}function O(E,H){--E[H]||delete E[H]}function U(E,H,Z,ee){var ne=""+H,ae=""+Z;if(!E&&ne>ae){var he=ne;ne=ae,ae=he}return ne+F+ae+F+(ee===void 0?I:ee)}function K(E,H,Z,ee){var ne=""+H,ae=""+Z;if(!E&&ne>ae){var he=ne;ne=ae,ae=he}var Se={v:ne,w:ae};return ee&&(Se.name=ee),Se}function D(E,H){return U(E,H.v,H.w,H.name)}R.exports=V}),h=o(($,R)=>{R.exports="3.0.2"}),m=o(($,R)=>{R.exports={Graph:c(),version:h()}}),f=o(($,R)=>{var I=c();R.exports={write:A,read:X};function A(O){var U={options:{directed:O.isDirected(),multigraph:O.isMultigraph(),compound:O.isCompound()},nodes:F(O),edges:V(O)};return O.graph()!==void 0&&(U.value=structuredClone(O.graph())),U}function F(O){return O.nodes().map(function(U){var K=O.node(U),D=O.parent(U),E={v:U};return K!==void 0&&(E.value=K),D!==void 0&&(E.parent=D),E})}function V(O){return O.edges().map(function(U){var K=O.edge(U),D={v:U.v,w:U.w};return U.name!==void 0&&(D.name=U.name),K!==void 0&&(D.value=K),D})}function X(O){var U=new I(O.options).setGraph(O.value);return O.nodes.forEach(function(K){U.setNode(K.v,K.value),K.parent&&U.setParent(K.v,K.parent)}),O.edges.forEach(function(K){U.setEdge({v:K.v,w:K.w,name:K.name},K.value)}),U}}),x=o(($,R)=>{R.exports=A;var I=()=>1;function A(V,X,O,U){return F(V,String(X),O||I,U||function(K){return V.outEdges(K)})}function F(V,X,O,U){var K={},D=!0,E=0,H=V.nodes(),Z=function(he){var Se=O(he);K[he.v].distance+Se<K[he.w].distance&&(K[he.w]={distance:K[he.v].distance+Se,predecessor:he.v},D=!0)},ee=function(){H.forEach(function(he){U(he).forEach(function(Se){var Ie=Se.v===he?Se.v:Se.w,xe=Ie===Se.v?Se.w:Se.v;Z({v:Ie,w:xe})})})};H.forEach(function(he){var Se=he===X?0:Number.POSITIVE_INFINITY;K[he]={distance:Se}});for(var ne=H.length,ae=1;ae<ne&&(D=!1,E++,ee(),!!D);ae++);if(E===ne-1&&(D=!1,ee(),D))throw new Error("The graph contains a negative weight cycle");return K}}),p=o(($,R)=>{R.exports=I;function I(A){var F={},V=[],X;function O(U){Object.hasOwn(F,U)||(F[U]=!0,X.push(U),A.successors(U).forEach(O),A.predecessors(U).forEach(O))}return A.nodes().forEach(function(U){X=[],O(U),X.length&&V.push(X)}),V}}),g=o(($,R)=>{var I=class{constructor(){d(this,"_arr",[]),d(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(A){return A.key})}has(A){return Object.hasOwn(this._keyIndices,A)}priority(A){var F=this._keyIndices[A];if(F!==void 0)return this._arr[F].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(A,F){var V=this._keyIndices;if(A=String(A),!Object.hasOwn(V,A)){var X=this._arr,O=X.length;return V[A]=O,X.push({key:A,priority:F}),this._decrease(O),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var A=this._arr.pop();return delete this._keyIndices[A.key],this._heapify(0),A.key}decrease(A,F){var V=this._keyIndices[A];if(F>this._arr[V].priority)throw new Error("New priority is greater than current priority. Key: "+A+" Old: "+this._arr[V].priority+" New: "+F);this._arr[V].priority=F,this._decrease(V)}_heapify(A){var F=this._arr,V=2*A,X=V+1,O=A;V<F.length&&(O=F[V].priority<F[O].priority?V:O,X<F.length&&(O=F[X].priority<F[O].priority?X:O),O!==A&&(this._swap(A,O),this._heapify(O)))}_decrease(A){for(var F=this._arr,V=F[A].priority,X;A!==0&&(X=A>>1,!(F[X].priority<V));)this._swap(A,X),A=X}_swap(A,F){var V=this._arr,X=this._keyIndices,O=V[A],U=V[F];V[A]=U,V[F]=O,X[U.key]=A,X[O.key]=F}};R.exports=I}),y=o(($,R)=>{var I=g();R.exports=F;var A=()=>1;function F(X,O,U,K){var D=function(E){return X.outEdges(E)};return V(X,String(O),U||A,K||D)}function V(X,O,U,K){var D={},E=new I,H,Z,ee=function(ne){var ae=ne.v!==H?ne.v:ne.w,he=D[ae],Se=U(ne),Ie=Z.distance+Se;if(Se<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+ne+" Weight: "+Se);Ie<he.distance&&(he.distance=Ie,he.predecessor=H,E.decrease(ae,Ie))};for(X.nodes().forEach(function(ne){var ae=ne===O?0:Number.POSITIVE_INFINITY;D[ne]={distance:ae},E.add(ne,ae)});E.size()>0&&(H=E.removeMin(),Z=D[H],Z.distance!==Number.POSITIVE_INFINITY);)K(H).forEach(ee);return D}}),w=o(($,R)=>{var I=y();R.exports=A;function A(F,V,X){return F.nodes().reduce(function(O,U){return O[U]=I(F,U,V,X),O},{})}}),N=o(($,R)=>{R.exports=I;function I(F,V,X){if(F[V].predecessor!==void 0)throw new Error("Invalid source vertex");if(F[X].predecessor===void 0&&X!==V)throw new Error("Invalid destination vertex");return{weight:F[X].distance,path:A(F,V,X)}}function A(F,V,X){for(var O=[],U=X;U!==V;)O.push(U),U=F[U].predecessor;return O.push(V),O.reverse()}}),T=o(($,R)=>{R.exports=I;function I(A){var F=0,V=[],X={},O=[];function U(K){var D=X[K]={onStack:!0,lowlink:F,index:F++};if(V.push(K),A.successors(K).forEach(function(Z){Object.hasOwn(X,Z)?X[Z].onStack&&(D.lowlink=Math.min(D.lowlink,X[Z].index)):(U(Z),D.lowlink=Math.min(D.lowlink,X[Z].lowlink))}),D.lowlink===D.index){var E=[],H;do H=V.pop(),X[H].onStack=!1,E.push(H);while(K!==H);O.push(E)}}return A.nodes().forEach(function(K){Object.hasOwn(X,K)||U(K)}),O}}),_=o(($,R)=>{var I=T();R.exports=A;function A(F){return I(F).filter(function(V){return V.length>1||V.length===1&&F.hasEdge(V[0],V[0])})}}),S=o(($,R)=>{R.exports=A;var I=()=>1;function A(V,X,O){return F(V,X||I,O||function(U){return V.outEdges(U)})}function F(V,X,O){var U={},K=V.nodes();return K.forEach(function(D){U[D]={},U[D][D]={distance:0},K.forEach(function(E){D!==E&&(U[D][E]={distance:Number.POSITIVE_INFINITY})}),O(D).forEach(function(E){var H=E.v===D?E.w:E.v,Z=X(E);U[D][H]={distance:Z,predecessor:D}})}),K.forEach(function(D){var E=U[D];K.forEach(function(H){var Z=U[H];K.forEach(function(ee){var ne=Z[D],ae=E[ee],he=Z[ee],Se=ne.distance+ae.distance;Se<he.distance&&(he.distance=Se,he.predecessor=ae.predecessor)})})}),U}}),k=o(($,R)=>{function I(F){var V={},X={},O=[];function U(K){if(Object.hasOwn(X,K))throw new A;Object.hasOwn(V,K)||(X[K]=!0,V[K]=!0,F.predecessors(K).forEach(U),delete X[K],O.push(K))}if(F.sinks().forEach(U),Object.keys(V).length!==F.nodeCount())throw new A;return O}var A=class extends Error{constructor(){super(...arguments)}};R.exports=I,I.CycleException=A}),C=o(($,R)=>{var I=k();R.exports=A;function A(F){try{I(F)}catch(V){if(V instanceof I.CycleException)return!1;throw V}return!0}}),M=o(($,R)=>{R.exports=I;function I(F,V,X,O,U){Array.isArray(V)||(V=[V]);var K=(F.isDirected()?F.successors:F.neighbors).bind(F),D={};return V.forEach(function(E){if(!F.hasNode(E))throw new Error("Graph does not have node: "+E);U=A(F,E,X==="post",D,K,O,U)}),U}function A(F,V,X,O,U,K,D){return Object.hasOwn(O,V)||(O[V]=!0,X||(D=K(D,V)),U(V).forEach(function(E){D=A(F,E,X,O,U,K,D)}),X&&(D=K(D,V))),D}}),L=o(($,R)=>{var I=M();R.exports=A;function A(F,V,X){return I(F,V,X,function(O,U){return O.push(U),O},[])}}),P=o(($,R)=>{var I=L();R.exports=A;function A(F,V){return I(F,V,"post")}}),G=o(($,R)=>{var I=L();R.exports=A;function A(F,V){return I(F,V,"pre")}}),W=o(($,R)=>{var I=c(),A=g();R.exports=F;function F(V,X){var O=new I,U={},K=new A,D;function E(Z){var ee=Z.v===D?Z.w:Z.v,ne=K.priority(ee);if(ne!==void 0){var ae=X(Z);ae<ne&&(U[ee]=D,K.decrease(ee,ae))}}if(V.nodeCount()===0)return O;V.nodes().forEach(function(Z){K.add(Z,Number.POSITIVE_INFINITY),O.setNode(Z)}),K.decrease(V.nodes()[0],0);for(var H=!1;K.size()>0;){if(D=K.removeMin(),Object.hasOwn(U,D))O.setEdge(D,U[D]);else{if(H)throw new Error("Input graph is not connected: "+V);H=!0}V.nodeEdges(D).forEach(E)}return O}}),z=o(($,R)=>{var I=y(),A=x();R.exports=F;function F(X,O,U,K){return V(X,O,U,K||function(D){return X.outEdges(D)})}function V(X,O,U,K){if(U===void 0)return I(X,O,U,K);for(var D=!1,E=X.nodes(),H=0;H<E.length;H++){for(var Z=K(E[H]),ee=0;ee<Z.length;ee++){var ne=Z[ee],ae=ne.v===E[H]?ne.v:ne.w,he=ae===ne.v?ne.w:ne.v;U({v:ae,w:he})<0&&(D=!0)}if(D)return A(X,O,U,K)}return I(X,O,U,K)}}),q=o(($,R)=>{R.exports={bellmanFord:x(),components:p(),dijkstra:y(),dijkstraAll:w(),extractPath:N(),findCycles:_(),floydWarshall:S(),isAcyclic:C(),postorder:P(),preorder:G(),prim:W(),shortestPaths:z(),reduce:M(),tarjan:T(),topsort:k()}}),Y=m();n.exports={Graph:Y.Graph,json:f(),alg:q(),version:Y.version}}),nI=un((e,n)=>{var s=class{constructor(){let d={};d._next=d._prev=d,this._sentinel=d}dequeue(){let d=this._sentinel,c=d._prev;if(c!==d)return i(c),c}enqueue(d){let c=this._sentinel;d._prev&&d._next&&i(d),d._next=c._next,c._next._prev=d,c._next=d,d._prev=c}toString(){let d=[],c=this._sentinel,h=c._prev;for(;h!==c;)d.push(JSON.stringify(h,o)),h=h._prev;return"["+d.join(", ")+"]"}};function i(d){d._prev._next=d._next,d._next._prev=d._prev,delete d._next,delete d._prev}function o(d,c){if(d!=="_next"&&d!=="_prev")return c}n.exports=s}),rI=un((e,n)=>{var s=hs().Graph,i=nI();n.exports=d;var o=()=>1;function d(p,g){if(p.nodeCount()<=1)return[];let y=m(p,g||o);return c(y.graph,y.buckets,y.zeroIdx).flatMap(w=>p.outEdges(w.v,w.w))}function c(p,g,y){let w=[],N=g[g.length-1],T=g[0],_;for(;p.nodeCount();){for(;_=T.dequeue();)h(p,g,y,_);for(;_=N.dequeue();)h(p,g,y,_);if(p.nodeCount()){for(let S=g.length-2;S>0;--S)if(_=g[S].dequeue(),_){w=w.concat(h(p,g,y,_,!0));break}}}return w}function h(p,g,y,w,N){let T=N?[]:void 0;return p.inEdges(w.v).forEach(_=>{let S=p.edge(_),k=p.node(_.v);N&&T.push({v:_.v,w:_.w}),k.out-=S,f(g,y,k)}),p.outEdges(w.v).forEach(_=>{let S=p.edge(_),k=_.w,C=p.node(k);C.in-=S,f(g,y,C)}),p.removeNode(w.v),T}function m(p,g){let y=new s,w=0,N=0;p.nodes().forEach(S=>{y.setNode(S,{v:S,in:0,out:0})}),p.edges().forEach(S=>{let k=y.edge(S.v,S.w)||0,C=g(S),M=k+C;y.setEdge(S.v,S.w,M),N=Math.max(N,y.node(S.v).out+=C),w=Math.max(w,y.node(S.w).in+=C)});let T=x(N+w+3).map(()=>new i),_=w+1;return y.nodes().forEach(S=>{f(T,_,y.node(S))}),{graph:y,buckets:T,zeroIdx:_}}function f(p,g,y){y.out?y.in?p[y.out-y.in+g].enqueue(y):p[p.length-1].enqueue(y):p[0].enqueue(y)}function x(p){let g=[];for(let y=0;y<p;y++)g.push(y);return g}}),Gn=un((e,n)=>{var s=hs().Graph;n.exports={addBorderNode:g,addDummyNode:i,applyWithChunking:N,asNonCompoundGraph:d,buildLayerMatrix:f,intersectRect:m,mapValues:G,maxRank:T,normalizeRanks:x,notime:k,partition:_,pick:P,predecessorWeights:h,range:L,removeEmptyRanks:p,simplify:o,successorWeights:c,time:S,uniqueId:M,zipObject:W};function i(z,q,Y,$){for(var R=$;z.hasNode(R);)R=M($);return Y.dummy=q,z.setNode(R,Y),R}function o(z){let q=new s().setGraph(z.graph());return z.nodes().forEach(Y=>q.setNode(Y,z.node(Y))),z.edges().forEach(Y=>{let $=q.edge(Y.v,Y.w)||{weight:0,minlen:1},R=z.edge(Y);q.setEdge(Y.v,Y.w,{weight:$.weight+R.weight,minlen:Math.max($.minlen,R.minlen)})}),q}function d(z){let q=new s({multigraph:z.isMultigraph()}).setGraph(z.graph());return z.nodes().forEach(Y=>{z.children(Y).length||q.setNode(Y,z.node(Y))}),z.edges().forEach(Y=>{q.setEdge(Y,z.edge(Y))}),q}function c(z){let q=z.nodes().map(Y=>{let $={};return z.outEdges(Y).forEach(R=>{$[R.w]=($[R.w]||0)+z.edge(R).weight}),$});return W(z.nodes(),q)}function h(z){let q=z.nodes().map(Y=>{let $={};return z.inEdges(Y).forEach(R=>{$[R.v]=($[R.v]||0)+z.edge(R).weight}),$});return W(z.nodes(),q)}function m(z,q){let Y=z.x,$=z.y,R=q.x-Y,I=q.y-$,A=z.width/2,F=z.height/2;if(!R&&!I)throw new Error("Not possible to find intersection inside of the rectangle");let V,X;return Math.abs(I)*A>Math.abs(R)*F?(I<0&&(F=-F),V=F*R/I,X=F):(R<0&&(A=-A),V=A,X=A*I/R),{x:Y+V,y:$+X}}function f(z){let q=L(T(z)+1).map(()=>[]);return z.nodes().forEach(Y=>{let $=z.node(Y),R=$.rank;R!==void 0&&(q[R][$.order]=Y)}),q}function x(z){let q=z.nodes().map($=>{let R=z.node($).rank;return R===void 0?Number.MAX_VALUE:R}),Y=N(Math.min,q);z.nodes().forEach($=>{let R=z.node($);Object.hasOwn(R,"rank")&&(R.rank-=Y)})}function p(z){let q=z.nodes().map(A=>z.node(A).rank).filter(A=>A!==void 0),Y=N(Math.min,q),$=[];z.nodes().forEach(A=>{let F=z.node(A).rank-Y;$[F]||($[F]=[]),$[F].push(A)});let R=0,I=z.graph().nodeRankFactor;Array.from($).forEach((A,F)=>{A===void 0&&F%I!==0?--R:A!==void 0&&R&&A.forEach(V=>z.node(V).rank+=R)})}function g(z,q,Y,$){let R={width:0,height:0};return arguments.length>=4&&(R.rank=Y,R.order=$),i(z,"border",R,q)}function y(z,q=w){let Y=[];for(let $=0;$<z.length;$+=q){let R=z.slice($,$+q);Y.push(R)}return Y}var w=65535;function N(z,q){if(q.length>w){let Y=y(q);return z.apply(null,Y.map($=>z.apply(null,$)))}else return z.apply(null,q)}function T(z){let q=z.nodes().map(Y=>{let $=z.node(Y).rank;return $===void 0?Number.MIN_VALUE:$});return N(Math.max,q)}function _(z,q){let Y={lhs:[],rhs:[]};return z.forEach($=>{q($)?Y.lhs.push($):Y.rhs.push($)}),Y}function S(z,q){let Y=Date.now();try{return q()}finally{console.log(z+" time: "+(Date.now()-Y)+"ms")}}function k(z,q){return q()}var C=0;function M(z){var q=++C;return z+(""+q)}function L(z,q,Y=1){q==null&&(q=z,z=0);let $=I=>I<q;Y<0&&($=I=>q<I);let R=[];for(let I=z;$(I);I+=Y)R.push(I);return R}function P(z,q){let Y={};for(let $ of q)z[$]!==void 0&&(Y[$]=z[$]);return Y}function G(z,q){let Y=q;return typeof q=="string"&&(Y=$=>$[q]),Object.entries(z).reduce(($,[R,I])=>($[R]=Y(I,R),$),{})}function W(z,q){return z.reduce((Y,$,R)=>(Y[$]=q[R],Y),{})}}),sI=un((e,n)=>{var s=rI(),i=Gn().uniqueId;n.exports={run:o,undo:c};function o(h){(h.graph().acyclicer==="greedy"?s(h,m(h)):d(h)).forEach(f=>{let x=h.edge(f);h.removeEdge(f),x.forwardName=f.name,x.reversed=!0,h.setEdge(f.w,f.v,x,i("rev"))});function m(f){return x=>f.edge(x).weight}}function d(h){let m=[],f={},x={};function p(g){Object.hasOwn(x,g)||(x[g]=!0,f[g]=!0,h.outEdges(g).forEach(y=>{Object.hasOwn(f,y.w)?m.push(y):p(y.w)}),delete f[g])}return h.nodes().forEach(p),m}function c(h){h.edges().forEach(m=>{let f=h.edge(m);if(f.reversed){h.removeEdge(m);let x=f.forwardName;delete f.reversed,delete f.forwardName,h.setEdge(m.w,m.v,f,x)}})}}),aI=un((e,n)=>{var s=Gn();n.exports={run:i,undo:d};function i(c){c.graph().dummyChains=[],c.edges().forEach(h=>o(c,h))}function o(c,h){let m=h.v,f=c.node(m).rank,x=h.w,p=c.node(x).rank,g=h.name,y=c.edge(h),w=y.labelRank;if(p===f+1)return;c.removeEdge(h);let N,T,_;for(_=0,++f;f<p;++_,++f)y.points=[],T={width:0,height:0,edgeLabel:y,edgeObj:h,rank:f},N=s.addDummyNode(c,"edge",T,"_d"),f===w&&(T.width=y.width,T.height=y.height,T.dummy="edge-label",T.labelpos=y.labelpos),c.setEdge(m,N,{weight:y.weight},g),_===0&&c.graph().dummyChains.push(N),m=N;c.setEdge(m,x,{weight:y.weight},g)}function d(c){c.graph().dummyChains.forEach(h=>{let m=c.node(h),f=m.edgeLabel,x;for(c.setEdge(m.edgeObj,f);m.dummy;)x=c.successors(h)[0],c.removeNode(h),f.points.push({x:m.x,y:m.y}),m.dummy==="edge-label"&&(f.x=m.x,f.y=m.y,f.width=m.width,f.height=m.height),h=x,m=c.node(h)})}}),Wd=un((e,n)=>{var{applyWithChunking:s}=Gn();n.exports={longestPath:i,slack:o};function i(d){var c={};function h(m){var f=d.node(m);if(Object.hasOwn(c,m))return f.rank;c[m]=!0;let x=d.outEdges(m).map(g=>g==null?Number.POSITIVE_INFINITY:h(g.w)-d.edge(g).minlen);var p=s(Math.min,x);return p===Number.POSITIVE_INFINITY&&(p=0),f.rank=p}d.sources().forEach(h)}function o(d,c){return d.node(c.w).rank-d.node(c.v).rank-d.edge(c).minlen}}),DN=un((e,n)=>{var s=hs().Graph,i=Wd().slack;n.exports=o;function o(m){var f=new s({directed:!1}),x=m.nodes()[0],p=m.nodeCount();f.setNode(x,{});for(var g,y;d(f,m)<p;)g=c(f,m),y=f.hasNode(g.v)?i(m,g):-i(m,g),h(f,m,y);return f}function d(m,f){function x(p){f.nodeEdges(p).forEach(g=>{var y=g.v,w=p===y?g.w:y;!m.hasNode(w)&&!i(f,g)&&(m.setNode(w,{}),m.setEdge(p,w,{}),x(w))})}return m.nodes().forEach(x),m.nodeCount()}function c(m,f){return f.edges().reduce((x,p)=>{let g=Number.POSITIVE_INFINITY;return m.hasNode(p.v)!==m.hasNode(p.w)&&(g=i(f,p)),g<x[0]?[g,p]:x},[Number.POSITIVE_INFINITY,null])[1]}function h(m,f,x){m.nodes().forEach(p=>f.node(p).rank+=x)}}),iI=un((e,n)=>{var s=DN(),i=Wd().slack,o=Wd().longestPath,d=hs().alg.preorder,c=hs().alg.postorder,h=Gn().simplify;n.exports=m,m.initLowLimValues=g,m.initCutValues=f,m.calcCutValue=p,m.leaveEdge=w,m.enterEdge=N,m.exchangeEdges=T;function m(C){C=h(C),o(C);var M=s(C);g(M),f(M,C);for(var L,P;L=w(M);)P=N(M,C,L),T(M,C,L,P)}function f(C,M){var L=c(C,C.nodes());L=L.slice(0,L.length-1),L.forEach(P=>x(C,M,P))}function x(C,M,L){var P=C.node(L),G=P.parent;C.edge(L,G).cutvalue=p(C,M,L)}function p(C,M,L){var P=C.node(L),G=P.parent,W=!0,z=M.edge(L,G),q=0;return z||(W=!1,z=M.edge(G,L)),q=z.weight,M.nodeEdges(L).forEach(Y=>{var $=Y.v===L,R=$?Y.w:Y.v;if(R!==G){var I=$===W,A=M.edge(Y).weight;if(q+=I?A:-A,S(C,L,R)){var F=C.edge(L,R).cutvalue;q+=I?-F:F}}}),q}function g(C,M){arguments.length<2&&(M=C.nodes()[0]),y(C,{},1,M)}function y(C,M,L,P,G){var W=L,z=C.node(P);return M[P]=!0,C.neighbors(P).forEach(q=>{Object.hasOwn(M,q)||(L=y(C,M,L,q,P))}),z.low=W,z.lim=L++,G?z.parent=G:delete z.parent,L}function w(C){return C.edges().find(M=>C.edge(M).cutvalue<0)}function N(C,M,L){var P=L.v,G=L.w;M.hasEdge(P,G)||(P=L.w,G=L.v);var W=C.node(P),z=C.node(G),q=W,Y=!1;W.lim>z.lim&&(q=z,Y=!0);var $=M.edges().filter(R=>Y===k(C,C.node(R.v),q)&&Y!==k(C,C.node(R.w),q));return $.reduce((R,I)=>i(M,I)<i(M,R)?I:R)}function T(C,M,L,P){var G=L.v,W=L.w;C.removeEdge(G,W),C.setEdge(P.v,P.w,{}),g(C),f(C,M),_(C,M)}function _(C,M){var L=C.nodes().find(G=>!M.node(G).parent),P=d(C,L);P=P.slice(1),P.forEach(G=>{var W=C.node(G).parent,z=M.edge(G,W),q=!1;z||(z=M.edge(W,G),q=!0),M.node(G).rank=M.node(W).rank+(q?z.minlen:-z.minlen)})}function S(C,M,L){return C.hasEdge(M,L)}function k(C,M,L){return L.low<=M.lim&&M.lim<=L.lim}}),lI=un((e,n)=>{var s=Wd(),i=s.longestPath,o=DN(),d=iI();n.exports=c;function c(x){var p=x.graph().ranker;if(p instanceof Function)return p(x);switch(x.graph().ranker){case"network-simplex":f(x);break;case"tight-tree":m(x);break;case"longest-path":h(x);break;case"none":break;default:f(x)}}var h=i;function m(x){i(x),o(x)}function f(x){d(x)}}),oI=un((e,n)=>{n.exports=s;function s(d){let c=o(d);d.graph().dummyChains.forEach(h=>{let m=d.node(h),f=m.edgeObj,x=i(d,c,f.v,f.w),p=x.path,g=x.lca,y=0,w=p[y],N=!0;for(;h!==f.w;){if(m=d.node(h),N){for(;(w=p[y])!==g&&d.node(w).maxRank<m.rank;)y++;w===g&&(N=!1)}if(!N){for(;y<p.length-1&&d.node(w=p[y+1]).minRank<=m.rank;)y++;w=p[y]}d.setParent(h,w),h=d.successors(h)[0]}})}function i(d,c,h,m){let f=[],x=[],p=Math.min(c[h].low,c[m].low),g=Math.max(c[h].lim,c[m].lim),y,w;y=h;do y=d.parent(y),f.push(y);while(y&&(c[y].low>p||g>c[y].lim));for(w=y,y=m;(y=d.parent(y))!==w;)x.push(y);return{path:f.concat(x.reverse()),lca:w}}function o(d){let c={},h=0;function m(f){let x=h;d.children(f).forEach(m),c[f]={low:x,lim:h++}}return d.children().forEach(m),c}}),cI=un((e,n)=>{var s=Gn();n.exports={run:i,cleanup:h};function i(m){let f=s.addDummyNode(m,"root",{},"_root"),x=d(m),p=Object.values(x),g=s.applyWithChunking(Math.max,p)-1,y=2*g+1;m.graph().nestingRoot=f,m.edges().forEach(N=>m.edge(N).minlen*=y);let w=c(m)+1;m.children().forEach(N=>o(m,f,y,w,g,x,N)),m.graph().nodeRankFactor=y}function o(m,f,x,p,g,y,w){let N=m.children(w);if(!N.length){w!==f&&m.setEdge(f,w,{weight:0,minlen:x});return}let T=s.addBorderNode(m,"_bt"),_=s.addBorderNode(m,"_bb"),S=m.node(w);m.setParent(T,w),S.borderTop=T,m.setParent(_,w),S.borderBottom=_,N.forEach(k=>{o(m,f,x,p,g,y,k);let C=m.node(k),M=C.borderTop?C.borderTop:k,L=C.borderBottom?C.borderBottom:k,P=C.borderTop?p:2*p,G=M!==L?1:g-y[w]+1;m.setEdge(T,M,{weight:P,minlen:G,nestingEdge:!0}),m.setEdge(L,_,{weight:P,minlen:G,nestingEdge:!0})}),m.parent(w)||m.setEdge(f,T,{weight:0,minlen:g+y[w]})}function d(m){var f={};function x(p,g){var y=m.children(p);y&&y.length&&y.forEach(w=>x(w,g+1)),f[p]=g}return m.children().forEach(p=>x(p,1)),f}function c(m){return m.edges().reduce((f,x)=>f+m.edge(x).weight,0)}function h(m){var f=m.graph();m.removeNode(f.nestingRoot),delete f.nestingRoot,m.edges().forEach(x=>{var p=m.edge(x);p.nestingEdge&&m.removeEdge(x)})}}),dI=un((e,n)=>{var s=Gn();n.exports=i;function i(d){function c(h){let m=d.children(h),f=d.node(h);if(m.length&&m.forEach(c),Object.hasOwn(f,"minRank")){f.borderLeft=[],f.borderRight=[];for(let x=f.minRank,p=f.maxRank+1;x<p;++x)o(d,"borderLeft","_bl",h,f,x),o(d,"borderRight","_br",h,f,x)}}d.children().forEach(c)}function o(d,c,h,m,f,x){let p={width:0,height:0,rank:x,borderType:c},g=f[c][x-1],y=s.addDummyNode(d,"border",p,h);f[c][x]=y,d.setParent(y,m),g&&d.setEdge(g,y,{weight:1})}}),uI=un((e,n)=>{n.exports={adjust:s,undo:i};function s(x){let p=x.graph().rankdir.toLowerCase();(p==="lr"||p==="rl")&&o(x)}function i(x){let p=x.graph().rankdir.toLowerCase();(p==="bt"||p==="rl")&&c(x),(p==="lr"||p==="rl")&&(m(x),o(x))}function o(x){x.nodes().forEach(p=>d(x.node(p))),x.edges().forEach(p=>d(x.edge(p)))}function d(x){let p=x.width;x.width=x.height,x.height=p}function c(x){x.nodes().forEach(p=>h(x.node(p))),x.edges().forEach(p=>{let g=x.edge(p);g.points.forEach(h),Object.hasOwn(g,"y")&&h(g)})}function h(x){x.y=-x.y}function m(x){x.nodes().forEach(p=>f(x.node(p))),x.edges().forEach(p=>{let g=x.edge(p);g.points.forEach(f),Object.hasOwn(g,"x")&&f(g)})}function f(x){let p=x.x;x.x=x.y,x.y=p}}),fI=un((e,n)=>{var s=Gn();n.exports=i;function i(o){let d={},c=o.nodes().filter(p=>!o.children(p).length),h=c.map(p=>o.node(p).rank),m=s.applyWithChunking(Math.max,h),f=s.range(m+1).map(()=>[]);function x(p){if(d[p])return;d[p]=!0;let g=o.node(p);f[g.rank].push(p),o.successors(p).forEach(x)}return c.sort((p,g)=>o.node(p).rank-o.node(g).rank).forEach(x),f}}),hI=un((e,n)=>{var s=Gn().zipObject;n.exports=i;function i(d,c){let h=0;for(let m=1;m<c.length;++m)h+=o(d,c[m-1],c[m]);return h}function o(d,c,h){let m=s(h,h.map((w,N)=>N)),f=c.flatMap(w=>d.outEdges(w).map(N=>({pos:m[N.w],weight:d.edge(N).weight})).sort((N,T)=>N.pos-T.pos)),x=1;for(;x<h.length;)x<<=1;let p=2*x-1;x-=1;let g=new Array(p).fill(0),y=0;return f.forEach(w=>{let N=w.pos+x;g[N]+=w.weight;let T=0;for(;N>0;)N%2&&(T+=g[N+1]),N=N-1>>1,g[N]+=w.weight;y+=w.weight*T}),y}}),mI=un((e,n)=>{n.exports=s;function s(i,o=[]){return o.map(d=>{let c=i.inEdges(d);if(c.length){let h=c.reduce((m,f)=>{let x=i.edge(f),p=i.node(f.v);return{sum:m.sum+x.weight*p.order,weight:m.weight+x.weight}},{sum:0,weight:0});return{v:d,barycenter:h.sum/h.weight,weight:h.weight}}else return{v:d}})}}),xI=un((e,n)=>{var s=Gn();n.exports=i;function i(c,h){let m={};c.forEach((x,p)=>{let g=m[x.v]={indegree:0,in:[],out:[],vs:[x.v],i:p};x.barycenter!==void 0&&(g.barycenter=x.barycenter,g.weight=x.weight)}),h.edges().forEach(x=>{let p=m[x.v],g=m[x.w];p!==void 0&&g!==void 0&&(g.indegree++,p.out.push(m[x.w]))});let f=Object.values(m).filter(x=>!x.indegree);return o(f)}function o(c){let h=[];function m(x){return p=>{p.merged||(p.barycenter===void 0||x.barycenter===void 0||p.barycenter>=x.barycenter)&&d(x,p)}}function f(x){return p=>{p.in.push(x),--p.indegree===0&&c.push(p)}}for(;c.length;){let x=c.pop();h.push(x),x.in.reverse().forEach(m(x)),x.out.forEach(f(x))}return h.filter(x=>!x.merged).map(x=>s.pick(x,["vs","i","barycenter","weight"]))}function d(c,h){let m=0,f=0;c.weight&&(m+=c.barycenter*c.weight,f+=c.weight),h.weight&&(m+=h.barycenter*h.weight,f+=h.weight),c.vs=h.vs.concat(c.vs),c.barycenter=m/f,c.weight=f,c.i=Math.min(h.i,c.i),h.merged=!0}}),pI=un((e,n)=>{var s=Gn();n.exports=i;function i(c,h){let m=s.partition(c,T=>Object.hasOwn(T,"barycenter")),f=m.lhs,x=m.rhs.sort((T,_)=>_.i-T.i),p=[],g=0,y=0,w=0;f.sort(d(!!h)),w=o(p,x,w),f.forEach(T=>{w+=T.vs.length,p.push(T.vs),g+=T.barycenter*T.weight,y+=T.weight,w=o(p,x,w)});let N={vs:p.flat(!0)};return y&&(N.barycenter=g/y,N.weight=y),N}function o(c,h,m){let f;for(;h.length&&(f=h[h.length-1]).i<=m;)h.pop(),c.push(f.vs),m++;return m}function d(c){return(h,m)=>h.barycenter<m.barycenter?-1:h.barycenter>m.barycenter?1:c?m.i-h.i:h.i-m.i}}),gI=un((e,n)=>{var s=mI(),i=xI(),o=pI();n.exports=d;function d(m,f,x,p){let g=m.children(f),y=m.node(f),w=y?y.borderLeft:void 0,N=y?y.borderRight:void 0,T={};w&&(g=g.filter(C=>C!==w&&C!==N));let _=s(m,g);_.forEach(C=>{if(m.children(C.v).length){let M=d(m,C.v,x,p);T[C.v]=M,Object.hasOwn(M,"barycenter")&&h(C,M)}});let S=i(_,x);c(S,T);let k=o(S,p);if(w&&(k.vs=[w,k.vs,N].flat(!0),m.predecessors(w).length)){let C=m.node(m.predecessors(w)[0]),M=m.node(m.predecessors(N)[0]);Object.hasOwn(k,"barycenter")||(k.barycenter=0,k.weight=0),k.barycenter=(k.barycenter*k.weight+C.order+M.order)/(k.weight+2),k.weight+=2}return k}function c(m,f){m.forEach(x=>{x.vs=x.vs.flatMap(p=>f[p]?f[p].vs:p)})}function h(m,f){m.barycenter!==void 0?(m.barycenter=(m.barycenter*m.weight+f.barycenter*f.weight)/(m.weight+f.weight),m.weight+=f.weight):(m.barycenter=f.barycenter,m.weight=f.weight)}}),bI=un((e,n)=>{var s=hs().Graph,i=Gn();n.exports=o;function o(c,h,m,f){f||(f=c.nodes());let x=d(c),p=new s({compound:!0}).setGraph({root:x}).setDefaultNodeLabel(g=>c.node(g));return f.forEach(g=>{let y=c.node(g),w=c.parent(g);(y.rank===h||y.minRank<=h&&h<=y.maxRank)&&(p.setNode(g),p.setParent(g,w||x),c[m](g).forEach(N=>{let T=N.v===g?N.w:N.v,_=p.edge(T,g),S=_!==void 0?_.weight:0;p.setEdge(T,g,{weight:c.edge(N).weight+S})}),Object.hasOwn(y,"minRank")&&p.setNode(g,{borderLeft:y.borderLeft[h],borderRight:y.borderRight[h]}))}),p}function d(c){for(var h;c.hasNode(h=i.uniqueId("_root")););return h}}),yI=un((e,n)=>{n.exports=s;function s(i,o,d){let c={},h;d.forEach(m=>{let f=i.parent(m),x,p;for(;f;){if(x=i.parent(f),x?(p=c[x],c[x]=f):(p=h,h=f),p&&p!==f){o.setEdge(p,f);return}f=x}})}}),vI=un((e,n)=>{var s=fI(),i=hI(),o=gI(),d=bI(),c=yI(),h=hs().Graph,m=Gn();n.exports=f;function f(y,w={}){if(typeof w.customOrder=="function"){w.customOrder(y,f);return}let N=m.maxRank(y),T=x(y,m.range(1,N+1),"inEdges"),_=x(y,m.range(N-1,-1,-1),"outEdges"),S=s(y);if(g(y,S),w.disableOptimalOrderHeuristic)return;let k=Number.POSITIVE_INFINITY,C,M=w.constraints||[];for(let L=0,P=0;P<4;++L,++P){p(L%2?T:_,L%4>=2,M),S=m.buildLayerMatrix(y);let G=i(y,S);G<k?(P=0,C=Object.assign({},S),k=G):G===k&&(C=structuredClone(S))}g(y,C)}function x(y,w,N){let T=new Map,_=(S,k)=>{T.has(S)||T.set(S,[]),T.get(S).push(k)};for(let S of y.nodes()){let k=y.node(S);if(typeof k.rank=="number"&&_(k.rank,S),typeof k.minRank=="number"&&typeof k.maxRank=="number")for(let C=k.minRank;C<=k.maxRank;C++)C!==k.rank&&_(C,S)}return w.map(function(S){return d(y,S,N,T.get(S)||[])})}function p(y,w,N){let T=new h;y.forEach(function(_){N.forEach(C=>T.setEdge(C.left,C.right));let S=_.graph().root,k=o(_,S,T,w);k.vs.forEach((C,M)=>_.node(C).order=M),c(_,T,k.vs)})}function g(y,w){Object.values(w).forEach(N=>N.forEach((T,_)=>y.node(T).order=_))}}),jI=un((e,n)=>{var s=hs().Graph,i=Gn();n.exports={positionX:N,findType1Conflicts:o,findType2Conflicts:d,addConflict:h,hasConflict:m,verticalAlignment:f,horizontalCompaction:x,alignCoordinates:y,findSmallestWidthAlignment:g,balance:w};function o(S,k){let C={};function M(L,P){let G=0,W=0,z=L.length,q=P[P.length-1];return P.forEach((Y,$)=>{let R=c(S,Y),I=R?S.node(R).order:z;(R||Y===q)&&(P.slice(W,$+1).forEach(A=>{S.predecessors(A).forEach(F=>{let V=S.node(F),X=V.order;(X<G||I<X)&&!(V.dummy&&S.node(A).dummy)&&h(C,F,A)})}),W=$+1,G=I)}),P}return k.length&&k.reduce(M),C}function d(S,k){let C={};function M(P,G,W,z,q){let Y;i.range(G,W).forEach($=>{Y=P[$],S.node(Y).dummy&&S.predecessors(Y).forEach(R=>{let I=S.node(R);I.dummy&&(I.order<z||I.order>q)&&h(C,R,Y)})})}function L(P,G){let W=-1,z,q=0;return G.forEach((Y,$)=>{if(S.node(Y).dummy==="border"){let R=S.predecessors(Y);R.length&&(z=S.node(R[0]).order,M(G,q,$,W,z),q=$,W=z)}M(G,q,G.length,z,P.length)}),G}return k.length&&k.reduce(L),C}function c(S,k){if(S.node(k).dummy)return S.predecessors(k).find(C=>S.node(C).dummy)}function h(S,k,C){if(k>C){let L=k;k=C,C=L}let M=S[k];M||(S[k]=M={}),M[C]=!0}function m(S,k,C){if(k>C){let M=k;k=C,C=M}return!!S[k]&&Object.hasOwn(S[k],C)}function f(S,k,C,M){let L={},P={},G={};return k.forEach(W=>{W.forEach((z,q)=>{L[z]=z,P[z]=z,G[z]=q})}),k.forEach(W=>{let z=-1;W.forEach(q=>{let Y=M(q);if(Y.length){Y=Y.sort((R,I)=>G[R]-G[I]);let $=(Y.length-1)/2;for(let R=Math.floor($),I=Math.ceil($);R<=I;++R){let A=Y[R];P[q]===q&&z<G[A]&&!m(C,q,A)&&(P[A]=q,P[q]=L[q]=L[A],z=G[A])}}})}),{root:L,align:P}}function x(S,k,C,M,L){let P={},G=p(S,k,C,L),W=L?"borderLeft":"borderRight";function z($,R){let I=G.nodes().slice(),A={},F=I.pop();for(;F;){if(A[F])$(F);else{A[F]=!0,I.push(F);for(let V of R(F))I.push(V)}F=I.pop()}}function q($){P[$]=G.inEdges($).reduce((R,I)=>Math.max(R,P[I.v]+G.edge(I)),0)}function Y($){let R=G.outEdges($).reduce((A,F)=>Math.min(A,P[F.w]-G.edge(F)),Number.POSITIVE_INFINITY),I=S.node($);R!==Number.POSITIVE_INFINITY&&I.borderType!==W&&(P[$]=Math.max(P[$],R))}return z(q,G.predecessors.bind(G)),z(Y,G.successors.bind(G)),Object.keys(M).forEach($=>P[$]=P[C[$]]),P}function p(S,k,C,M){let L=new s,P=S.graph(),G=T(P.nodesep,P.edgesep,M);return k.forEach(W=>{let z;W.forEach(q=>{let Y=C[q];if(L.setNode(Y),z){var $=C[z],R=L.edge($,Y);L.setEdge($,Y,Math.max(G(S,q,z),R||0))}z=q})}),L}function g(S,k){return Object.values(k).reduce((C,M)=>{let L=Number.NEGATIVE_INFINITY,P=Number.POSITIVE_INFINITY;Object.entries(M).forEach(([W,z])=>{let q=_(S,W)/2;L=Math.max(z+q,L),P=Math.min(z-q,P)});let G=L-P;return G<C[0]&&(C=[G,M]),C},[Number.POSITIVE_INFINITY,null])[1]}function y(S,k){let C=Object.values(k),M=i.applyWithChunking(Math.min,C),L=i.applyWithChunking(Math.max,C);["u","d"].forEach(P=>{["l","r"].forEach(G=>{let W=P+G,z=S[W];if(z===k)return;let q=Object.values(z),Y=M-i.applyWithChunking(Math.min,q);G!=="l"&&(Y=L-i.applyWithChunking(Math.max,q)),Y&&(S[W]=i.mapValues(z,$=>$+Y))})})}function w(S,k){return i.mapValues(S.ul,(C,M)=>{if(k)return S[k.toLowerCase()][M];{let L=Object.values(S).map(P=>P[M]).sort((P,G)=>P-G);return(L[1]+L[2])/2}})}function N(S){let k=i.buildLayerMatrix(S),C=Object.assign(o(S,k),d(S,k)),M={},L;["u","d"].forEach(G=>{L=G==="u"?k:Object.values(k).reverse(),["l","r"].forEach(W=>{W==="r"&&(L=L.map($=>Object.values($).reverse()));let z=(G==="u"?S.predecessors:S.successors).bind(S),q=f(S,L,C,z),Y=x(S,L,q.root,q.align,W==="r");W==="r"&&(Y=i.mapValues(Y,$=>-$)),M[G+W]=Y})});let P=g(S,M);return y(M,P),w(M,S.graph().align)}function T(S,k,C){return(M,L,P)=>{let G=M.node(L),W=M.node(P),z=0,q;if(z+=G.width/2,Object.hasOwn(G,"labelpos"))switch(G.labelpos.toLowerCase()){case"l":q=-G.width/2;break;case"r":q=G.width/2;break}if(q&&(z+=C?q:-q),q=0,z+=(G.dummy?k:S)/2,z+=(W.dummy?k:S)/2,z+=W.width/2,Object.hasOwn(W,"labelpos"))switch(W.labelpos.toLowerCase()){case"l":q=W.width/2;break;case"r":q=-W.width/2;break}return q&&(z+=C?q:-q),q=0,z}}function _(S,k){return S.node(k).width}}),wI=un((e,n)=>{var s=Gn(),i=jI().positionX;n.exports=o;function o(c){c=s.asNonCompoundGraph(c),d(c),Object.entries(i(c)).forEach(([h,m])=>c.node(h).x=m)}function d(c){let h=s.buildLayerMatrix(c),m=c.graph().ranksep,f=c.graph().rankalign,x=0;h.forEach(p=>{let g=p.reduce((y,w)=>{let N=c.node(w).height;return y>N?y:N},0);p.forEach(y=>{let w=c.node(y);f==="top"?w.y=x+w.height/2:f==="bottom"?w.y=x+g-w.height/2:w.y=x+g/2}),x+=g+m})}}),NI=un((e,n)=>{var s=sI(),i=aI(),o=lI(),d=Gn().normalizeRanks,c=oI(),h=Gn().removeEmptyRanks,m=cI(),f=dI(),x=uI(),p=vI(),g=wI(),y=Gn(),w=hs().Graph;n.exports=N;function N(H,Z={}){let ee=Z.debugTiming?y.time:y.notime;return ee("layout",()=>{let ne=ee(" buildLayoutGraph",()=>z(H));return ee(" runLayout",()=>T(ne,ee,Z)),ee(" updateInputGraph",()=>_(H,ne)),ne})}function T(H,Z,ee){Z(" makeSpaceForEdgeLabels",()=>q(H)),Z(" removeSelfEdges",()=>O(H)),Z(" acyclic",()=>s.run(H)),Z(" nestingGraph.run",()=>m.run(H)),Z(" rank",()=>o(y.asNonCompoundGraph(H))),Z(" injectEdgeLabelProxies",()=>Y(H)),Z(" removeEmptyRanks",()=>h(H)),Z(" nestingGraph.cleanup",()=>m.cleanup(H)),Z(" normalizeRanks",()=>d(H)),Z(" assignRankMinMax",()=>$(H)),Z(" removeEdgeLabelProxies",()=>R(H)),Z(" normalize.run",()=>i.run(H)),Z(" parentDummyChains",()=>c(H)),Z(" addBorderSegments",()=>f(H)),Z(" order",()=>p(H,ee)),Z(" insertSelfEdges",()=>U(H)),Z(" adjustCoordinateSystem",()=>x.adjust(H)),Z(" position",()=>g(H)),Z(" positionSelfEdges",()=>K(H)),Z(" removeBorderNodes",()=>X(H)),Z(" normalize.undo",()=>i.undo(H)),Z(" fixupEdgeLabelCoords",()=>F(H)),Z(" undoCoordinateSystem",()=>x.undo(H)),Z(" translateGraph",()=>I(H)),Z(" assignNodeIntersects",()=>A(H)),Z(" reversePoints",()=>V(H)),Z(" acyclic.undo",()=>s.undo(H))}function _(H,Z){H.nodes().forEach(ee=>{let ne=H.node(ee),ae=Z.node(ee);ne&&(ne.x=ae.x,ne.y=ae.y,ne.order=ae.order,ne.rank=ae.rank,Z.children(ee).length&&(ne.width=ae.width,ne.height=ae.height))}),H.edges().forEach(ee=>{let ne=H.edge(ee),ae=Z.edge(ee);ne.points=ae.points,Object.hasOwn(ae,"x")&&(ne.x=ae.x,ne.y=ae.y)}),H.graph().width=Z.graph().width,H.graph().height=Z.graph().height}var S=["nodesep","edgesep","ranksep","marginx","marginy"],k={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},C=["acyclicer","ranker","rankdir","align","rankalign"],M=["width","height","rank"],L={width:0,height:0},P=["minlen","weight","width","height","labeloffset"],G={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},W=["labelpos"];function z(H){let Z=new w({multigraph:!0,compound:!0}),ee=E(H.graph());return Z.setGraph(Object.assign({},k,D(ee,S),y.pick(ee,C))),H.nodes().forEach(ne=>{let ae=E(H.node(ne)),he=D(ae,M);Object.keys(L).forEach(Se=>{he[Se]===void 0&&(he[Se]=L[Se])}),Z.setNode(ne,he),Z.setParent(ne,H.parent(ne))}),H.edges().forEach(ne=>{let ae=E(H.edge(ne));Z.setEdge(ne,Object.assign({},G,D(ae,P),y.pick(ae,W)))}),Z}function q(H){let Z=H.graph();Z.ranksep/=2,H.edges().forEach(ee=>{let ne=H.edge(ee);ne.minlen*=2,ne.labelpos.toLowerCase()!=="c"&&(Z.rankdir==="TB"||Z.rankdir==="BT"?ne.width+=ne.labeloffset:ne.height+=ne.labeloffset)})}function Y(H){H.edges().forEach(Z=>{let ee=H.edge(Z);if(ee.width&&ee.height){let ne=H.node(Z.v),ae={rank:(H.node(Z.w).rank-ne.rank)/2+ne.rank,e:Z};y.addDummyNode(H,"edge-proxy",ae,"_ep")}})}function $(H){let Z=0;H.nodes().forEach(ee=>{let ne=H.node(ee);ne.borderTop&&(ne.minRank=H.node(ne.borderTop).rank,ne.maxRank=H.node(ne.borderBottom).rank,Z=Math.max(Z,ne.maxRank))}),H.graph().maxRank=Z}function R(H){H.nodes().forEach(Z=>{let ee=H.node(Z);ee.dummy==="edge-proxy"&&(H.edge(ee.e).labelRank=ee.rank,H.removeNode(Z))})}function I(H){let Z=Number.POSITIVE_INFINITY,ee=0,ne=Number.POSITIVE_INFINITY,ae=0,he=H.graph(),Se=he.marginx||0,Ie=he.marginy||0;function xe(we){let Me=we.x,Be=we.y,et=we.width,lt=we.height;Z=Math.min(Z,Me-et/2),ee=Math.max(ee,Me+et/2),ne=Math.min(ne,Be-lt/2),ae=Math.max(ae,Be+lt/2)}H.nodes().forEach(we=>xe(H.node(we))),H.edges().forEach(we=>{let Me=H.edge(we);Object.hasOwn(Me,"x")&&xe(Me)}),Z-=Se,ne-=Ie,H.nodes().forEach(we=>{let Me=H.node(we);Me.x-=Z,Me.y-=ne}),H.edges().forEach(we=>{let Me=H.edge(we);Me.points.forEach(Be=>{Be.x-=Z,Be.y-=ne}),Object.hasOwn(Me,"x")&&(Me.x-=Z),Object.hasOwn(Me,"y")&&(Me.y-=ne)}),he.width=ee-Z+Se,he.height=ae-ne+Ie}function A(H){H.edges().forEach(Z=>{let ee=H.edge(Z),ne=H.node(Z.v),ae=H.node(Z.w),he,Se;ee.points?(he=ee.points[0],Se=ee.points[ee.points.length-1]):(ee.points=[],he=ae,Se=ne),ee.points.unshift(y.intersectRect(ne,he)),ee.points.push(y.intersectRect(ae,Se))})}function F(H){H.edges().forEach(Z=>{let ee=H.edge(Z);if(Object.hasOwn(ee,"x"))switch((ee.labelpos==="l"||ee.labelpos==="r")&&(ee.width-=ee.labeloffset),ee.labelpos){case"l":ee.x-=ee.width/2+ee.labeloffset;break;case"r":ee.x+=ee.width/2+ee.labeloffset;break}})}function V(H){H.edges().forEach(Z=>{let ee=H.edge(Z);ee.reversed&&ee.points.reverse()})}function X(H){H.nodes().forEach(Z=>{if(H.children(Z).length){let ee=H.node(Z),ne=H.node(ee.borderTop),ae=H.node(ee.borderBottom),he=H.node(ee.borderLeft[ee.borderLeft.length-1]),Se=H.node(ee.borderRight[ee.borderRight.length-1]);ee.width=Math.abs(Se.x-he.x),ee.height=Math.abs(ae.y-ne.y),ee.x=he.x+ee.width/2,ee.y=ne.y+ee.height/2}}),H.nodes().forEach(Z=>{H.node(Z).dummy==="border"&&H.removeNode(Z)})}function O(H){H.edges().forEach(Z=>{if(Z.v===Z.w){var ee=H.node(Z.v);ee.selfEdges||(ee.selfEdges=[]),ee.selfEdges.push({e:Z,label:H.edge(Z)}),H.removeEdge(Z)}})}function U(H){var Z=y.buildLayerMatrix(H);Z.forEach(ee=>{var ne=0;ee.forEach((ae,he)=>{var Se=H.node(ae);Se.order=he+ne,(Se.selfEdges||[]).forEach(Ie=>{y.addDummyNode(H,"selfedge",{width:Ie.label.width,height:Ie.label.height,rank:Se.rank,order:he+ ++ne,e:Ie.e,label:Ie.label},"_se")}),delete Se.selfEdges})})}function K(H){H.nodes().forEach(Z=>{var ee=H.node(Z);if(ee.dummy==="selfedge"){var ne=H.node(ee.e.v),ae=ne.x+ne.width/2,he=ne.y,Se=ee.x-ae,Ie=ne.height/2;H.setEdge(ee.e,ee.label),H.removeNode(Z),ee.label.points=[{x:ae+2*Se/3,y:he-Ie},{x:ae+5*Se/6,y:he-Ie},{x:ae+Se,y:he},{x:ae+5*Se/6,y:he+Ie},{x:ae+2*Se/3,y:he+Ie}],ee.label.x=ee.x,ee.label.y=ee.y}})}function D(H,Z){return y.mapValues(y.pick(H,Z),Number)}function E(H){var Z={};return H&&Object.entries(H).forEach(([ee,ne])=>{typeof ee=="string"&&(ee=ee.toLowerCase()),Z[ee]=ne}),Z}}),kI=un((e,n)=>{var s=Gn(),i=hs().Graph;n.exports={debugOrdering:o};function o(d){let c=s.buildLayerMatrix(d),h=new i({compound:!0,multigraph:!0}).setGraph({});return d.nodes().forEach(m=>{h.setNode(m,{label:m}),h.setParent(m,"layer"+d.node(m).rank)}),d.edges().forEach(m=>h.setEdge(m.v,m.w,{},m.name)),c.forEach((m,f)=>{let x="layer"+f;h.setNode(x,{rank:"same"}),m.reduce((p,g)=>(h.setEdge(p,g,{style:"invis"}),g))}),h}}),SI=un((e,n)=>{n.exports="2.0.4"}),CI=un((e,n)=>{n.exports={graphlib:hs(),layout:NI(),debug:kI(),util:{time:Gn().time,notime:Gn().notime},version:SI()}});const Wv=CI();const Qv={pending:{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"},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"},rejected:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"},archived:{bg:"bg-gray-500/5",border:"border-gray-500/15",text:"text-fg-tertiary"}},EI={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function TI({data:e}){const{task:n,agentName:s,selected:i}=e,o=Qv[n.status]??Qv.pending,d=n.taskType==="scheduled"&&!!n.scheduleConfig,c=d?n.scheduleConfig.every?`Every ${n.scheduleConfig.every}`:n.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 ${d?`${o.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${o.bg} ${o.border}`} ${i?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[t.jsx($a,{type:"target",position:ut.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 ${EI[n.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${o.text}`,children:n.status.replace("_"," ")}),d&&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:n.title}),s&&t.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:s}),n.blockedBy&&n.blockedBy.length>0&&t.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[n.blockedBy.length," dep",n.blockedBy.length>1?"s":""]}),t.jsx($a,{type:"source",position:ut.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const Zv={pending:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},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"}},Jv={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done"};function _I({data:e}){const{req:n,selected:s}=e,i=Zv[n.status]??Zv.pending;return t.jsxs("div",{className:`rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${i.bg} ${i.border} ${s?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[t.jsx($a,{type:"target",position:ut.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 ${i.text}`,children:n.status.replace("_"," ")})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:n.title}),n.taskIds.length>0&&t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[n.taskIds.length," task",n.taskIds.length>1?"s":""]}),t.jsx($a,{type:"source",position:ut.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const AI={task:TI,requirement:_I},MI=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&window.matchMedia("(prefers-color-scheme: light)").matches,RI=e=>{const n=new MutationObserver(e);n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const s=window.matchMedia("(prefers-color-scheme: light)");return s.addEventListener("change",e),()=>{n.disconnect(),s.removeEventListener("change",e)}};function OI(){return v.useSyncExternalStore(RI,MI,()=>!1)}const Km=200,Wm=80;function e1(e,n,s="TB"){const i=new Wv.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:s,nodesep:40,ranksep:60});for(const o of e)i.setNode(o.id,{width:Km,height:Wm});for(const o of n)i.setEdge(o.source,o.target);return Wv.layout(i),e.map(o=>{const d=i.node(o.id);return{...o,position:{x:(d?.x??0)-Km/2,y:(d?.y??0)-Wm/2}}})}function DI(e,n){const s=new Map,i=new Map;for(const c of e)i.set(c.id,c),s.set(c.id,new Set);for(const c of n)s.get(c.source)?.add(c.target),s.get(c.target)?.add(c.source);const o=new Set,d=[];for(const c of e){if(o.has(c.id))continue;const h=new Set,m=[c.id];for(;m.length>0;){const f=m.pop();if(!o.has(f)){o.add(f),h.add(f);for(const x of s.get(f)??[])o.has(x)||m.push(x)}}d.push({nodes:e.filter(f=>h.has(f.id)),edges:n.filter(f=>h.has(f.source)&&h.has(f.target))})}return d}function LI(e,n){if(e.length===0)return[];const s=DI(e,n);if(s.length===1)return e1(e,n);const i=s.map(p=>{const g=e1(p.nodes,p.edges);let y=1/0,w=-1/0,N=1/0,T=-1/0;for(const _ of g)y=Math.min(y,_.position.x),w=Math.max(w,_.position.x+Km),N=Math.min(N,_.position.y),T=Math.max(T,_.position.y+Wm);for(const _ of g)_.position.x-=y,_.position.y-=N;return{nodes:g,w:w-y,h:T-N}});i.sort((p,g)=>g.h-p.h);const o=60,d=i.reduce((p,g)=>p+(g.w+o)*(g.h+o),0),c=Math.sqrt(d)*1.1,h=[];let m=0,f=0,x=0;for(const p of i){m>0&&m+p.w>c&&(m=0,f+=x+o,x=0);for(const g of p.nodes)h.push({...g,position:{x:g.position.x+m,y:g.position.y+f}});m+=p.w+o,x=Math.max(x,p.h)}return h}function II(e,n,s){const i=new Set,o=[n];for(;o.length>0;){const d=o.pop();if(d===s)return!0;if(i.has(d))continue;i.add(d);const c=e.get(d);if(c?.blockedBy)for(const h of c.blockedBy)o.push(h)}return!1}const ko=[{id:"todo",label:"To Do",statuses:new Set(["pending"]),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"]),color:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"}},{id:"done",label:"Done",statuses:new Set(["completed","failed","rejected","cancelled"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}],lm=new Set(ko.map(e=>e.id)),zI=1440*60*1e3,t1=e=>e.status==="completed"&&e.updatedAt&&Date.now()-new Date(e.updatedAt).getTime()>zI;function $I({tasks:e,requirements:n=[],agents:s,showArchived:i,onShowArchivedChange:o,onTaskClick:d,onReqClick:c,onDependencyChange:h,selectedTaskId:m,selectedReqId:f}){const x=OI(),[p,g]=v.useState(null),[y,w]=v.useState(null),[N,T]=v.useState(new Set(lm)),[_,S]=v.useState(i??!1),k=i??_,C=v.useCallback(xe=>{const we=typeof xe=="function"?xe(k):xe;S(we),o?.(we)},[k,o]);v.useEffect(()=>{i!==void 0&&S(i)},[i]);const M=v.useMemo(()=>e.filter(xe=>t1(xe)).length,[e]),L=v.useMemo(()=>{const xe=new Set;for(const we of ko)if(N.has(we.id))for(const Me of we.statuses)xe.add(Me);return xe},[N]),P=v.useMemo(()=>{const xe=new Set;for(const we of e)for(const Me of ko)if(Me.statuses.has(we.status)){xe.add(Me.id);break}for(const we of n){const Me=Jv[we.status];Me&&xe.add(Me)}return ko.filter(we=>xe.has(we.id))},[e,n]),G=v.useCallback(xe=>{T(we=>{const Me=new Set(we);return Me.has(xe)?Me.delete(xe):Me.add(xe),Me})},[]),W=v.useCallback((xe,we="success")=>{g({msg:xe,type:we}),setTimeout(()=>g(null),2500)},[]),z=v.useMemo(()=>{const xe=new Map;for(const we of s)xe.set(we.id,we.name);return xe},[s]),q=v.useMemo(()=>{const xe=new Map;for(const we of e)xe.set(we.id,we);return xe},[e]),Y=v.useMemo(()=>{const xe=new Map;for(const we of n)xe.set(we.id,we);return xe},[n]),$=x?"#94a3b8":"#6b7280",R=v.useCallback((xe,we,Me)=>({id:`${xe}->${we}`,source:xe,target:we,animated:Me==="blocked",markerEnd:{type:ml.ArrowClosed,width:14,height:14,color:Me==="blocked"?"#ef4444":$},style:{stroke:Me==="blocked"?"#ef4444":$,strokeWidth:1.5,cursor:"pointer"}}),[$]),{initialNodes:I,initialEdges:A}=v.useMemo(()=>{const xe=e.filter(Te=>L.has(Te.status)&&(k||!t1(Te))),we=xe.map(Te=>({id:Te.id,type:"task",data:{task:Te,agentName:Te.assignedAgentId?z.get(Te.assignedAgentId):void 0,selected:Te.id===m},position:{x:0,y:0}})),Me=new Set(we.map(Te=>Te.id)),Be=new Set;for(const Te of ko)N.has(Te.id)&&Be.add(Te.id);const et=n.filter(Te=>{const rt=Jv[Te.status];return rt&&Be.has(rt)});for(const Te of et){const rt=`req-${Te.id}`;we.push({id:rt,type:"requirement",data:{req:Te,selected:Te.id===f},position:{x:0,y:0}}),Me.add(rt)}const lt=[];for(const Te of xe)if(Te.blockedBy)for(const rt of Te.blockedBy)Me.has(rt)&&lt.push(R(rt,Te.id,Te.status));const ft=new Set,yt=(Te,rt)=>{const wt=`${Te}->${rt}`;ft.has(wt)||(ft.add(wt),lt.push({id:wt,source:Te,target:rt,markerEnd:{type:ml.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Te of et){const rt=`req-${Te.id}`;for(const wt of Te.taskIds)Me.has(wt)&&yt(rt,wt)}for(const Te of xe)if(Te.requirementId){const rt=`req-${Te.requirementId}`;Me.has(rt)&&yt(rt,Te.id)}return{initialNodes:LI(we,lt),initialEdges:lt}},[e,n,z,q,R,L,N,k,m,f]),[F,V,X]=CL(I),[O,U,K]=EL(A),D=v.useRef(null),E=v.useRef(!1),H=v.useRef({groupFilter:N,showArchived:k});v.useEffect(()=>{const xe=H.current;(xe.groupFilter!==N||xe.showArchived!==k)&&(E.current=!1,H.current={groupFilter:N,showArchived:k})},[N,k]),v.useEffect(()=>{V(I),U(A),E.current||requestAnimationFrame(()=>{D.current?.fitView({padding:.2,duration:300})})},[I,A,V,U]);const Z=v.useCallback(xe=>{xe&&(E.current=!0)},[]),ee=v.useCallback((xe,we)=>{if(we.id.startsWith("req-")){const Me=Y.get(we.id.slice(4));Me&&c&&c(Me)}else{const Me=q.get(we.id);Me&&d&&d(Me)}},[q,Y,d,c]),ne=v.useCallback(async xe=>{const{source:we,target:Me}=xe;if(!we||!Me||we===Me)return;const Be=q.get(Me);if(!Be)return;if(Be.blockedBy?.includes(we)){W("Dependency already exists","error");return}if(II(q,we,Me)){W("Cannot add: would create a cycle","error");return}const et=[...Be.blockedBy??[],we];try{await se.tasks.update(Me,{blockedBy:et}),W("Dependency added"),h?.()}catch(lt){W(`Failed: ${lt instanceof Error?lt.message:String(lt)}`,"error")}},[q,W,h]),ae=v.useCallback((xe,we)=>{w(we)},[]),he=v.useCallback(async()=>{if(!y)return;const xe=q.get(y.target);if(!xe){w(null);return}const we=(xe.blockedBy??[]).filter(Me=>Me!==y.source);try{await se.tasks.update(y.target,{blockedBy:we}),W("Dependency removed"),h?.()}catch(Me){W(`Failed: ${Me instanceof Error?Me.message:String(Me)}`,"error")}w(null)},[y,q,W,h]);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 Se=y?q.get(y.source):null,Ie=y?q.get(y.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(SL,{nodes:F,edges:O,onNodesChange:X,onEdgesChange:K,onNodeClick:ee,onConnect:ne,onEdgeClick:ae,onMoveEnd:Z,onInit:xe=>{D.current=xe},nodeTypes:AI,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[t.jsx(RL,{color:x?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(BL,{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(ZL,{nodeColor:xe=>{const we=xe.data?.task,Me=we?.status;return we?.taskType==="scheduled"?"#06b6d4":Me==="completed"||Me==="accepted"?"#10b981":Me==="in_progress"?"#f59e0b":Me==="blocked"||Me==="failed"?"#ef4444":x?"#94a3b8":"#6b7280"},maskColor:x?"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:[P.map(xe=>{const we=N.has(xe.id);return t.jsx("button",{onClick:()=>G(xe.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${we?`${xe.color.bg} ${xe.color.border} ${xe.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:xe.label},xe.id)}),M>0&&t.jsxs("button",{onClick:()=>C(xe=>!xe),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${k?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:["Archived ",M]}),N.size<lm.size&&t.jsx("button",{onClick:()=>{T(new Set(lm)),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"})]}),p&&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 ${p.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:p.msg}),y&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>w(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:xe=>xe.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:Ie?.title??y.target.slice(-8)})," ","will no longer be blocked by"," ",t.jsx("span",{className:"text-fg-secondary font-medium",children:Se?.title??y.source.slice(-8)}),"."]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>w(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:he,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 LN({orgId:e,onCreated:n,onClose:s}){const[i,o]=v.useState(""),[d,c]=v.useState(""),[h,m]=v.useState(""),[f,x]=v.useState("main"),[p,g]=v.useState([]),[y,w]=v.useState([]),[N,T]=v.useState(!1),[_,S]=v.useState(""),[k,C]=v.useState(!1),M=Cr();v.useEffect(()=>{se.teams.list().then(G=>w(G.teams)).catch(()=>{})},[]);const L=v.useCallback(async G=>{if(G?.preventDefault(),C(!0),!(!i.trim()||N)){T(!0),S("");try{const W=h.trim()?[{url:h.trim(),defaultBranch:f.trim()||"main"}]:[],z=await se.projects.create({name:i.trim(),description:d.trim()||void 0,repositories:W.length>0?W:void 0,teamIds:p.length>0?p:void 0,orgId:e??"default"});n(z.project)}catch(W){S(W instanceof Error?W.message:"Failed to create project")}T(!1)}},[i,d,h,f,p,e,N,n]),P=k&&!i.trim();return tx.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 ${M?"w-full":"w-[520px]"}`,onClick:G=>G.stopPropagation(),onSubmit:L,children:[t.jsx("h3",{className:"text-base font-semibold mb-5",children:"New Project"}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Project Name *"}),t.jsx("input",{value:i,onChange:G=>{o(G.target.value),S("")},onBlur:()=>C(!0),placeholder:"e.g. Mobile App, Website Redesign",className:`input ${P?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!M}),P&&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:d,onChange:G=>c(G.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"}),y.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:y.map(G=>{const W=p.includes(G.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:W,onChange:()=>g(z=>W?z.filter(q=>q!==G.id):[...z,G.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:G.name})]},G.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:h,onChange:G=>m(G.target.value),placeholder:"https://github.com/org/repo (optional)",className:"input"})]}),h.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:f,onChange:G=>x(G.target.value),placeholder:"main",className:"input !w-24"})]})]}),_&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:_}),t.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{type:"submit",disabled:!i.trim()||N,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:N?"Creating...":"Create Project"})]})]})]})}),document.body)}function yl(e,n,s){if(!e)return null;const i=n.find(d=>d.id===e);if(i)return i.name;const o=s.find(d=>d.id===e);return o?o.name:e==="anonymous"?"Admin":null}function BI({value:e,onSave:n,className:s,placeholder:i}){const[o,d]=v.useState(!1),[c,h]=v.useState(e),m=v.useRef(null);v.useEffect(()=>{h(e)},[e]),v.useEffect(()=>{o&&m.current?.focus()},[o]);const f=async()=>{d(!1);const x=c.trim();if(x&&x!==e)try{await n(x)}catch{h(e)}else h(e)};return o?t.jsx("input",{ref:m,value:c,onChange:x=>h(x.target.value),onBlur:()=>{f()},onKeyDown:x=>{x.key==="Enter"&&f(),x.key==="Escape"&&(h(e),d(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${s??""}`,placeholder:i}):t.jsx("span",{onClick:()=>d(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${s??""}`,title:"Click to edit",children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:i??"Click to edit"})})}function HI({value:e,onSave:n,className:s,placeholder:i}){const[o,d]=v.useState(!1),[c,h]=v.useState(e),m=v.useRef(null);v.useEffect(()=>{h(e)},[e]),v.useEffect(()=>{o&&m.current&&(m.current.focus(),m.current.style.height="auto",m.current.style.height=m.current.scrollHeight+"px")},[o]);const f=async()=>{d(!1);const x=c.trim();if(x!==e)try{await n(x)}catch{h(e)}else h(e)};return o?t.jsx("textarea",{ref:m,value:c,onChange:x=>{h(x.target.value),x.target.style.height="auto",x.target.style.height=x.target.scrollHeight+"px"},onBlur:()=>{f()},onKeyDown:x=>{x.key==="Escape"&&(h(e),d(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${s??""}`,placeholder:i,rows:2}):t.jsx("p",{onClick:()=>d(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${s??""}`,title:"Click to edit",children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:i??"Add a description…"})})}const PI=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function IN(e){const n=e.match(PI);return n?{timestamp:n[1].trim(),author:n[2]?.trim()??"System",content:n[3].trim()}:{timestamp:"",author:"",content:e}}function UI(e){if(!e)return"";const n=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!n)return e;const s=new Date,i=+n[1],o=+n[2]-1,d=+n[3],c=+n[4],h=+n[5],m=new Date(i,o,d,c,h),f=s.getTime()-m.getTime();return f<6e4?"just now":f<36e5?`${Math.floor(f/6e4)}m ago`:f<864e5?`${Math.floor(f/36e5)}h ago`:f<6048e5?`${Math.floor(f/864e5)}d ago`:`${i}-${String(o+1).padStart(2,"0")}-${String(d).padStart(2,"0")}`}const n1=[{bg:"bg-brand-600/30",text:"text-brand-500",border:"border-brand-500/30"},{bg:"bg-blue-600/30",text:"text-blue-400",border:"border-blue-500/30"},{bg:"bg-green-600/30",text:"text-green-400",border:"border-green-500/30"},{bg:"bg-amber-600/30",text:"text-amber-400",border:"border-amber-500/30"},{bg:"bg-purple-600/30",text:"text-purple-400",border:"border-purple-500/30"},{bg:"bg-pink-600/30",text:"text-pink-400",border:"border-pink-500/30"}];function qI(e){let n=0;for(let s=0;s<e.length;s++)n=(n<<5)-n+e.charCodeAt(s)|0;return n1[Math.abs(n)%n1.length]}function VI({note:e,compact:n}){const s=IN(e),i=qI(s.author||"System"),o=s.author?s.author.split(/[\s_-]+/).map(h=>h[0]).join("").slice(0,2).toUpperCase():"SY",d=UI(s.timestamp),c=!s.author||s.author==="System";return n?t.jsxs("div",{className:"flex gap-2.5 group",children:[t.jsx("div",{className:`w-6 h-6 rounded-full ${i.bg} flex items-center justify-center text-[9px] font-bold ${i.text} shrink-0 mt-0.5`,children:o}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-tertiary":i.text}`,children:s.author||"System"}),d&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d})]}),t.jsx("div",{className:"text-xs text-fg-secondary",children:t.jsx(tr,{content:s.content,className:"text-xs text-fg-secondary"})})]})]}):t.jsxs("div",{className:"flex gap-3 group",children:[t.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[t.jsx("div",{className:`w-7 h-7 rounded-full ${i.bg} flex items-center justify-center text-[10px] font-bold ${i.text}`,children:o}),t.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),t.jsx("div",{className:"flex-1 min-w-0 pb-4",children:t.jsxs("div",{className:`border ${i.border} rounded-lg overflow-hidden`,children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${i.bg} border-b ${i.border}`,children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-secondary":i.text}`,children:s.author||"System"}),d&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d})]}),t.jsx("div",{className:"px-3 py-2.5",children:t.jsx(tr,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const Yo=[{id:"failed",label:"Failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",label:"To Do",statuses:["pending"],accent:"border-t-amber-500",dropStatus:"pending"},{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:["rejected","cancelled"],accent:"border-t-gray-500",dropStatus:"cancelled"}],zN={pending:{label:"Pending",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"},rejected:{label:"Rejected",cls:"bg-red-500/15 text-red-500"}},So={pending:{label:"Pending",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"},rejected:{label:"Rejected",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"}},FI={urgent:"border-l-red-500",high:"border-l-amber-500",medium:"border-l-blue-500",low:"border-l-gray-500"},wd={low:{label:"Low",cls:"bg-gray-500/15 text-fg-tertiary"},medium:{label:"Medium",cls:"bg-blue-500/15 text-blue-500"},high:{label:"High",cls:"bg-amber-500/15 text-amber-600"},urgent:{label:"Urgent",cls:"bg-red-500/15 text-red-500"}},r1=["low","medium","high","urgent"],s1=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],a1=["pending","in_progress","completed","rejected","cancelled"],i1={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived"]),archived:new Set([])},Qm={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},Zm={idle:"bg-green-400",working:"bg-blue-400",error:"bg-red-400",paused:"bg-amber-400",offline:"bg-gray-600",pending:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",rejected:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},l1={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function YI({agent:e,anchorRect:n,onClose:s}){const i=v.useRef(null);v.useEffect(()=>{const c=h=>{i.current&&!i.current.contains(h.target)&&s()};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s]);const o=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",d=e.status==="idle"?"Online":e.status==="working"?"Working":e.status==="error"?"Error":e.status==="paused"?"Paused":"Offline";return t.jsxs("div",{ref:i,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:n.top+4,left:n.left},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[10px] font-bold text-brand-600 shrink-0",children:e.name.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),t.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o}`}),t.jsx("span",{className:"text-[10px] text-fg-secondary",children:d})]})]})]}),t.jsx("button",{onClick:()=>{s(),xt.navigate(me.TEAM,{selectAgent:e.id})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1 transition-colors",children:"View Profile →"})]})}function Mo({comment:e,agents:n,onReply:s}){const i=e.authorType==="agent"||e.authorType==="system",o=new Date(e.createdAt),d=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),c=o.toLocaleDateString([],{month:"short",day:"numeric"}),[h,m]=v.useState(null),[f,x]=v.useState(!1),[p,g]=v.useState([]),[y,w]=v.useState(!1),N=v.useCallback((k,C)=>{const M=n.find(L=>L.name.toLowerCase()===k.toLowerCase());if(M){const L=C.target.getBoundingClientRect();m({agent:M,top:L.bottom,left:L.left})}},[n]),T=v.useCallback(k=>{const C=n.find(M=>M.name.toLowerCase()===e.authorName.toLowerCase());if(C){const M=k.currentTarget.getBoundingClientRect();m({agent:C,top:M.bottom,left:M.left})}},[n,e.authorName]),_=v.useCallback(async()=>{if(f){x(!1);return}const k=e.activityId;if(k&&(x(!0),!(p.length>0))){w(!0);try{const{logs:C}=await se.agents.getActivityLogs(e.authorId,k),M=C.map(L=>w1(L,k,e.authorId)).filter(L=>L!==null).map(L=>({...L,ts:new Date(L.createdAt).getTime()}));g(M)}catch{}w(!1)}},[f,p.length,e]),S=v.useMemo(()=>Lo(p.map(Io).filter(k=>k!==null)),[p]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[t.jsx("div",{onClick:T,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${i?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${i?"text-indigo-400":"text-blue-400"}`,onClick:T,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[c," ",d]}),s&&t.jsx("button",{onClick:()=>s(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:"Reply"}),e.activityId&&i&&t.jsx("button",{onClick:_,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:f?"Hide log":"View log"})]}),e.replyTo&&e.replyToAuthor&&t.jsxs("button",{onClick:()=>{const k=document.getElementById(`comment-${e.replyTo}`);k&&(k.scrollIntoView({behavior:"smooth",block:"center"}),k.classList.add("bg-brand-500/10"),setTimeout(()=>k.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[t.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),t.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),t.jsx(tr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:N}),e.attachments?.map((k,C)=>k.type==="image"?t.jsx("img",{src:k.url,alt:k.name,className:"mt-1 max-w-[200px] rounded"},C):null),f&&t.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:y?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:"Loading execution log..."}):S.length===0?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:"No execution log available."}):t.jsx(ru,{entries:p,isActive:!1,onCollapse:()=>x(!1),embedded:!0})})]}),h&&t.jsx(YI,{agent:h.agent,anchorRect:{top:h.top,left:h.left},onClose:()=>m(null)})]})}function GI({task:e,agents:n,users:s,authUser:i}){const[o,d]=v.useState([]);v.useEffect(()=>{se.tasks.getComments(e.id).then(p=>d(p.comments)).catch(()=>{})},[e.id]),v.useEffect(()=>ln.on("task:comment",g=>{g.payload?.taskId===e.id&&g.payload.comment&&d(y=>y.some(w=>w.id===g.payload.comment.id)?y:[...y,g.payload.comment])}),[e.id]);const c=v.useMemo(()=>{const p=[];for(const g of e.notes??[]){const y=IN(g);let w;if(y.timestamp){const N=y.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);w=N?new Date(+N[1],+N[2]-1,+N[3],+N[4],+N[5],+(N[6]??0)):new Date(0)}else w=new Date(0);p.push({type:"note",note:g,ts:w})}for(const g of o)p.push({type:"comment",comment:g,ts:new Date(g.createdAt)});return p.sort((g,y)=>g.ts.getTime()-y.ts.getTime()),p},[e.notes,o]),[h,m]=v.useState(null),f=async(p,g,y)=>{await se.tasks.addComment(e.id,p,i?.name,void 0,i?.id,g.length>0?g:void 0,y)},x=v.useCallback(p=>{m({id:p.id,authorName:p.authorName,content:p.content.slice(0,100)})},[]);return t.jsxs("div",{className:"mt-5",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:"Activity & Comments"}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[c.length===0&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:"No activity yet. Post the first comment below."}),c.map((p,g)=>p.type==="note"?t.jsx(VI,{note:p.note,compact:!0},`n-${g}`):t.jsx(Mo,{comment:p.comment,agents:n,onReply:x},`c-${p.comment.id}`))]}),t.jsx(zj,{agents:n,onSubmit:f,replyTo:h,onCancelReply:()=>m(null)})]})}function XI({taskId:e,isRunning:n,authUser:s,agents:i}){const[o,d]=v.useState([]),[c,h]=v.useState(new Map),[m,f]=v.useState(new Set),[x,p]=v.useState([]),[g,y]=v.useState(""),[w,N]=v.useState(n),[T,_]=v.useState(!0),[S,k]=v.useState(new Set),[C,M]=v.useState(""),[L,P]=v.useState(!1),[G,W]=v.useState([]),z=v.useRef(null),q=v.useRef(null);v.useEffect(()=>{N(n)},[n]),v.useEffect(()=>{_(!0),Promise.all([se.tasks.getLogsSummary(e).catch(()=>({rounds:[]})),se.tasks.getComments(e).catch(()=>({comments:[]}))]).then(([K,D])=>{const E=K.rounds;if(d(E),p(D.comments),E.length===0){_(!1);return}const H=E[E.length-1].round;k(new Set([H])),se.tasks.getLogs(e,H).catch(()=>({logs:[]})).then(Z=>{h(new Map([[H,Z.logs]])),_(!1)})})},[e]);const Y=v.useCallback(K=>{c.has(K)||m.has(K)||(f(D=>new Set(D).add(K)),se.tasks.getLogs(e,K).catch(()=>({logs:[]})).then(D=>{h(E=>new Map(E).set(K,D.logs)),f(E=>{const H=new Set(E);return H.delete(K),H})}))},[e,c,m]),$=v.useCallback(K=>{k(D=>{const E=new Set(D);return E.has(K)?E.delete(K):(E.add(K),c.has(K)||Y(K)),E})},[c,Y]);v.useEffect(()=>{const K=ln.on("task:log",H=>{const Z=H.payload;if(Z.taskId!==e)return;const ee={id:Z.id,taskId:Z.taskId,agentId:Z.agentId,seq:Z.seq,type:Z.logType,content:Z.content,metadata:Z.metadata,executionRound:Z.executionRound,createdAt:Z.createdAt},ne=ee.executionRound??1;d(ae=>ae.find(Se=>Se.round===ne)?ae:[...ae,{round:ne,logCount:0,toolCount:0,firstAt:ee.createdAt,lastAt:ee.createdAt,status:"running"}]),k(ae=>ae.has(ne)?ae:new Set(ae).add(ne)),h(ae=>{const he=ae.get(ne)??[];return ee.id&&he.some(Se=>Se.id===ee.id)?ae:new Map(ae).set(ne,[...he,ee])}),ee.type==="text"&&y(""),ee.type==="status"&&(ee.content==="started"||ee.content==="resumed"?N(!0):["completed","failed","cancelled","execution_finished"].includes(ee.content)&&(N(!1),d(ae=>ae.map(he=>he.round===ne?{...he,status:ee.content}:he)))),ee.type==="error"&&N(!1)}),D=ln.on("task:log:delta",H=>{const Z=H.payload;Z.taskId===e&&y(ee=>ee+Z.text)}),E=ln.on("task:comment",H=>{const Z=H.payload;if(Z.taskId!==e)return;const ee=Z.comment;p(ne=>ne.some(ae=>ae.id===ee.id)?ne:[...ne,ee])});return()=>{K(),D(),E()}},[e]);const R=v.useMemo(()=>{const K=[];for(const[,D]of c)K.push(...D);return K.sort((D,E)=>D.seq-E.seq),K},[c]),I=v.useMemo(()=>R.map(K=>fm(K)),[R]),A=o.length>1,F=K=>{const D=K.target.files;if(D){for(const E of Array.from(D)){if(!E.type.startsWith("image/"))continue;const H=new FileReader;H.onload=()=>{W(Z=>[...Z,{type:"image",url:H.result,name:E.name}])},H.readAsDataURL(E)}K.target.value=""}},V=async()=>{if(!(!C.trim()&&G.length===0)){P(!0);try{const K=await se.tasks.addComment(e,C,s?.name,G.length>0?G:void 0,s?.id);K.comment&&p(D=>D.some(E=>E.id===K.comment.id)?D:[...D,K.comment]),M(""),W([])}catch{}P(!1)}},X=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-secondary z-10",children:[G.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:G.map((K,D)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:K.url,alt:K.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>W(E=>E.filter((H,Z)=>Z!==D)),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:"×"})]},D))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:C,onChange:K=>M(K.target.value),onKeyDown:K=>{K.key==="Enter"&&!K.shiftKey&&(K.preventDefault(),V())},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:z,accept:"image/*",multiple:!0,onChange:F,className:"hidden"}),t.jsx("button",{onClick:()=>z.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:()=>{V()},disabled:L||!C.trim()&&G.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(T)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:"Loading logs…"});if(o.length===0&&!g)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.']})]})}),X]});if(!A){const K=I.map(H=>Io(H)).filter(H=>H!==null),D=Ny(R,Lo(K)),E=[...D.map(H=>({kind:"entry",entry:H,ts:H.timestamp?new Date(H.timestamp).getTime():0})),...x.map(H=>({kind:"comment",comment:H,ts:new Date(H.createdAt).getTime()}))];return E.sort((H,Z)=>H.ts-Z.ts),t.jsxs("div",{className:"flex flex-col flex-1",children:[t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-0.5",children:[E.map((H,Z)=>H.kind==="comment"?t.jsx(Mo,{comment:H.comment,agents:i},`c-${H.comment.id}`):t.jsx(Id,{entry:H.entry,showTime:!0,isLast:Z===E.length-1},`e-${Z}`)),w&&g&&t.jsx(Am,{content:g}),w&&!g&&D.length>0&&t.jsx(_m,{})]}),X]})}const O=(K,D)=>{const E=K.firstAt?new Date(K.firstAt).getTime():0,H=D?.firstAt?new Date(D.firstAt).getTime():1/0;return x.filter(Z=>{const ee=new Date(Z.createdAt).getTime();return ee>=E&&ee<H})},U=o.length>0?x.filter(K=>new Date(K.createdAt).getTime()<new Date(o[0].firstAt).getTime()):[];return t.jsxs("div",{className:"flex flex-col flex-1",children:[t.jsx("div",{ref:q}),t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[U.length>0&&t.jsx("div",{className:"space-y-0.5",children:U.map(K=>t.jsx(Mo,{comment:K,agents:i},K.id))}),o.map((K,D)=>{const E=S.has(K.round),H=K.round===o[o.length-1].round,Z=c.get(K.round),ee=m.has(K.round),ne=O(K,o[D+1]),ae=K.status==="completed"||K.status==="execution_finished"?"✅":K.status==="failed"?"❌":K.status==="cancelled"?"⏹":"🔄",he=K.lastAt&&K.firstAt?Math.max(0,new Date(K.lastAt).getTime()-new Date(K.firstAt).getTime()):0,Se=he>=6e4?`${Math.floor(he/6e4)}m ${Math.floor(he%6e4/1e3)}s`:he>=1e3?`${Math.floor(he/1e3)}s`:"";return t.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[t.jsxs("button",{onClick:()=>$(K.round),className:"w-full flex items-center justify-between px-3 py-2 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm",children:ae}),t.jsxs("span",{className:"text-xs text-fg-secondary font-medium",children:["Round #",K.round]}),ne.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",ne.length]}),H&&w&&t.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",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"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[K.toolCount," tool",K.toolCount!==1?"s":""]}),Se&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:Se}),t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${E?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})]}),E&&t.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[ee&&t.jsxs("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:["Loading round #",K.round,"…"]}),Z&&(()=>{const xe=Z.map(Be=>fm(Be)).map(Be=>Io(Be)).filter(Be=>Be!==null),Me=[...Ny(Z,Lo(xe)).map(Be=>({kind:"entry",entry:Be,ts:Be.timestamp?new Date(Be.timestamp).getTime():0})),...ne.map(Be=>({kind:"comment",comment:Be,ts:new Date(Be.createdAt).getTime()}))];return Me.sort((Be,et)=>Be.ts-et.ts),Me.map((Be,et)=>Be.kind==="comment"?t.jsx(Mo,{comment:Be.comment,agents:i},`c-${Be.comment.id}`):t.jsx(Id,{entry:Be.entry,showTime:!0,isLast:et===Me.length-1},`e-${et}`))})(),H&&w&&g&&t.jsx(Am,{content:g}),H&&w&&!g&&!ee&&t.jsx(_m,{})]})]},K.round)})]}),X]})}function KI({filePath:e,onClose:n}){const[s,i]=v.useState(null),[o,d]=v.useState(null),[c,h]=v.useState(!0);v.useEffect(()=>{h(!0),d(null),se.files.preview(e).then(f=>i(f)).catch(f=>d(String(f))).finally(()=>h(!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:n,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:f=>f.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:n,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:[c&&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(tr,{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 WI({task:e,agents:n,projects:s,requirements:i,allTasks:o,users:d,onClose:c,onRefresh:h,authUser:m}){const[f,x]=v.useState([]),[p,g]=v.useState(""),[y,w]=v.useState(!1),[N,T]=v.useState(!1),[_,S]=v.useState(null),[k,C]=v.useState(null),[M,L]=v.useState(!1),[P,G]=v.useState("details"),W=v.useRef(null),[z,q]=v.useState("none"),Y=v.useCallback(ve=>{G(ve),requestAnimationFrame(()=>{W.current?.scrollTo({top:0,behavior:"instant"})})},[]),$=v.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"}],[]),R=Js($,P,Y);v.useEffect(()=>{const ve=W.current;if(!ve)return;const tt=()=>{const{scrollTop:Pe,scrollHeight:vt,clientHeight:mn}=ve;if(!(vt>mn+50)){q("none");return}const kn=Pe<30,Jt=Pe+mn>=vt-30;q(kn?"top":Jt?"bottom":"middle")};tt(),ve.addEventListener("scroll",tt,{passive:!0});const Et=new ResizeObserver(tt);return Et.observe(ve),()=>{ve.removeEventListener("scroll",tt),Et.disconnect()}},[P]);const[I,A]=v.useState(null),[F,V]=v.useState(null),[X,O]=v.useState(!1),[U,K]=v.useState(e.description),[D,E]=v.useState(!1),[H,Z]=v.useState(""),[ee,ne]=v.useState(1),[ae,he]=v.useState(!1),Se=Cr(),Ie=20,xe=v.useCallback(async()=>{try{const ve=await se.tasks.listSubtasks(e.id);x(ve.subtasks)}catch{}},[e.id]);v.useEffect(()=>{xe()},[xe]);const we=async ve=>{if(!M){L(!0);try{await ve(),h(),await xe()}catch(tt){A(String(tt).replace("Error: ",""))}finally{L(!1)}}},Me=ve=>we(()=>se.tasks.update(e.id,{priority:ve})),Be=ve=>we(()=>se.tasks.assign(e.id,ve||null)),et=ve=>we(()=>se.tasks.update(e.id,{projectId:ve||null})),lt=async()=>{if(!M){L(!0);try{await se.tasks.pause(e.id),h()}finally{L(!1)}}},ft=async()=>{if(!M){L(!0),A(null),Y("logs");try{await se.tasks.resume(e.id),h()}catch(ve){A(String(ve).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{L(!1)}}},yt=async()=>{p.trim()&&(await se.tasks.createSubtask(e.id,p.trim()),g(""),w(!1),xe(),h())},re=async ve=>{ve.status==="completed"?await se.tasks.cancelSubtask(e.id,ve.id):await se.tasks.completeSubtask(e.id,ve.id),xe(),h()},Te=async ve=>{await se.tasks.deleteSubtask(e.id,ve.id),S(null),xe(),h()},rt=async()=>{if(!M){L(!0);try{await se.tasks.updateStatus(e.id,"in_progress"),h()}finally{L(!1)}}},wt=async()=>{if(!M){L(!0),A(null),Y("logs");try{await se.tasks.retry(e.id),h()}catch(ve){A(String(ve).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{L(!1)}}},Lt=async()=>{if(!M){L(!0),A(null),Y("logs");try{await se.tasks.runNow(e.id),h()}catch(ve){A(String(ve).replace("Error: API error: 400","Server error").replace("Error: ","")),h()}finally{L(!1)}}},je=v.useRef(h);je.current=h,v.useEffect(()=>ln.on("task:update",tt=>{tt.payload.taskId===e.id&&(xe(),je.current())}),[e.id,xe]);const De=f.filter(ve=>ve.status==="completed").length,Ve=e.status==="in_progress",dt=e.status==="blocked",st=e.status==="completed",zt=e.status==="failed",fn=e.status==="rejected",Mt=e.status==="cancelled",_t=e.status==="archived",$t=st||zt||fn||Mt||_t,Tt=e.taskType==="scheduled"&&!!e.scheduleConfig,Bt=Tt&&!!e.scheduleConfig?.paused,Xt=s.find(ve=>ve.id===e.projectId),hn=i.find(ve=>ve.id===e.requirementId);return n.find(ve=>ve.id===e.assignedAgentId),t.jsxs("div",{className:"flex flex-col h-full overflow-hidden bg-surface-secondary",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.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1 pr-4",children:[Se&&t.jsx("button",{onClick:c,className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",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.jsxs("div",{className:"flex items-center gap-2 flex-wrap flex-1 min-w-0",children:[t.jsx("h3",{className:"text-base font-semibold leading-snug truncate",children:e.title}),(()=>{const ve=So[e.status];return ve?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap ${ve.cls}`,children:ve.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," ")})})()]})]}),!Se&&t.jsx("button",{onClick:c,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]}),t.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 border-b border-border-default shrink-0 bg-surface-secondary",children:[t.jsx("button",{onClick:()=>Y("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${P==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:"Details"}),t.jsxs("button",{onClick:()=>Y("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${P==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Execution Log",Ve&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsxs("button",{onClick:()=>Y("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${P==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Deliverables",(()=>{const ve=(e.deliverables??[]).filter(tt=>tt.type!=="branch"&&typeof tt.reference=="string"&&tt.reference.length>0).length;return ve>0?t.jsx("span",{className:"text-[10px] text-fg-tertiary font-normal",children:ve}):null})()]})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:W,className:"h-full overflow-y-auto",onTouchStart:R.onTouchStart,onTouchEnd:R.onTouchEnd,children:[P==="logs"&&t.jsxs("div",{className:"overflow-x-hidden min-w-0",children:[I&&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:"})," ",I]}),t.jsx(XI,{taskId:e.id,isRunning:e.status==="in_progress",authUser:m,agents:n})]}),P==="details"&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:X?t.jsxs("div",{className:"space-y-2",children:[t.jsx("textarea",{value:U,onChange:ve=>K(ve.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:()=>{O(!1),K(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:()=>{we(()=>se.tasks.update(e.id,{description:U})),O(!1)},disabled:M,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:Se&&!ae?"line-clamp-3":"",children:t.jsx(tr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),Se&&e.description.length>150&&t.jsx("button",{onClick:()=>he(!ae),className:"text-[11px] text-brand-500 mt-1 font-medium",children:ae?"Collapse":"Show more"})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No description"}),t.jsx("button",{onClick:()=>{K(e.description),O(!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"})]})}),(Xt||hn)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Xt&&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"}),Xt.name]}),hn&&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"}),hn.title.length>40?hn.title.slice(0,40)+"…":hn.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(ve=>{const tt=o.find(Pe=>Pe.id===ve),Et=tt&&(tt.status==="completed"||tt.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Et?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:Et?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${Et?"line-through opacity-60":""}`,children:tt?tt.title.slice(0,30):ve.slice(-8)}),!$t&&t.jsx("button",{onClick:async()=>{const Pe=(e.blockedBy??[]).filter(vt=>vt!==ve);await se.tasks.update(e.id,{blockedBy:Pe}),h()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:"Remove dependency",children:"×"})]},ve)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:"No dependencies"}),!$t&&t.jsxs("select",{value:"",onChange:async ve=>{const tt=ve.target.value;if(!tt)return;const Et=[...e.blockedBy??[],tt];await se.tasks.update(e.id,{blockedBy:Et}),h()},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(ve=>ve.id!==e.id&&!(e.blockedBy??[]).includes(ve.id)).map(ve=>t.jsx("option",{value:ve.id,children:ve.title},ve.id))]})]}),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:ve=>{et(ve.target.value)},disabled:M,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(ve=>t.jsx("option",{value:ve.id,children:ve.name},ve.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:ve=>we(()=>se.tasks.update(e.id,{requirementId:ve.target.value||null})),disabled:M,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"No Requirement"}),i.filter(ve=>!e.projectId||ve.projectId===e.projectId).map(ve=>t.jsx("option",{value:ve.id,children:ve.title},ve.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:ve=>{Be(ve.target.value)},disabled:M,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"}),n.map(ve=>t.jsxs("option",{value:ve.id,children:[ve.name," (",ve.status,")"]},ve.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:ve=>{ve.target.value&&ve.target.value!==e.reviewerAgentId&&we(()=>se.tasks.update(e.id,{reviewerAgentId:ve.target.value}))},disabled:M,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:n.map(ve=>t.jsx("option",{value:ve.id,children:ve.name},ve.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:ve=>{Me(ve.target.value)},disabled:M,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:yl(e.createdBy,n,d)??e.createdBy})]}),e.updatedBy&&t.jsxs("span",{children:["Updated by ",t.jsx("span",{className:"text-fg-secondary",children:yl(e.updatedBy,n,d)??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 ",f.length>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[De,"/",f.length," done"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[De>0&&t.jsx("button",{onClick:()=>T(ve=>!ve),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${N?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:N?"Hide completed":`Show completed (${De})`}),t.jsx("button",{onClick:()=>w(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:"+ Add subtask"})]})]}),(()=>{const ve=N?f:f.filter(tt=>tt.status!=="completed");return ve.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:ve.map(tt=>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:()=>{re(tt)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${tt.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:tt.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 ${tt.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:tt.title}),t.jsx("button",{onClick:()=>S(tt),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},tt.id))}):null})(),f.length===0&&!y&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:"No subtasks yet."}),y&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:p,onChange:ve=>g(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&yt(),ve.key==="Escape"&&(w(!1),g(""))},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:()=>{yt()},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),g("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:"Cancel"})]}),(()=>{const ve=(e.deliverables??[]).filter(Pe=>Pe.type!=="branch"&&typeof Pe.reference=="string"&&Pe.reference.length>0);if(ve.length===0)return null;const tt={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"},Et=ve.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:["(",ve.length,")"]})]}),ve.length>3&&t.jsx("button",{onClick:()=>Y("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:"View all →"})]}),t.jsx("div",{className:"space-y-1.5",children:Et.map((Pe,vt)=>{const mn=Pe.reference.split("/").pop()??Pe.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 ${tt[Pe.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Pe.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>V(Pe.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Pe.reference,children:mn}),Pe.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Pe.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Pe.reference})]})]},vt)})})]})})(),t.jsx(GI,{task:e,agents:n,users:d,authUser:m})]})]}),P==="deliverables"&&t.jsx("div",{className:"px-6 py-4",children:(()=>{const ve=(e.deliverables??[]).filter(vt=>vt.type!=="branch"&&typeof vt.reference=="string"&&vt.reference.length>0);if(ve.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:"No deliverables yet."});const tt={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"},Et=Math.ceil(ve.length/Ie),Pe=ve.slice((ee-1)*Ie,ee*Ie);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:["(",ve.length,")"]})]}),Et>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:ee<=1,onClick:()=>ne(vt=>vt-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[ee,"/",Et]}),t.jsx("button",{disabled:ee>=Et,onClick:()=>ne(vt=>vt+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:Pe.map((vt,mn)=>{const Rn=vt.reference.split("/").pop()??vt.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 ${tt[vt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:vt.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>V(vt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:vt.reference,children:Rn}),vt.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:vt.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:vt.reference})]})]},mn)})})]})})()})]}),z!=="none"&&z!=="top"&&t.jsx("button",{onClick:()=>W.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:"Scroll to top",children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),z!=="none"&&z!=="bottom"&&t.jsx("button",{onClick:()=>{const ve=W.current;ve&&ve.scrollTo({top:ve.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:"Scroll to bottom",children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),Tt&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Bt?"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:Bt?"text-amber-600":"text-brand-500",children:Bt?"⏸ 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"}),!Bt&&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 ve=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(ve<=0)return"due now";const tt=Math.floor(ve/6e4);if(tt<60)return`in ${tt}m`;const Et=Math.floor(tt/60);return Et<24?`in ${Et}h ${tt%60}m`:`in ${Math.floor(Et/24)}d ${Et%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 ve=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),tt=Math.floor(ve/6e4);if(tt<1)return"just now";if(tt<60)return`${tt}m ago`;const Et=Math.floor(tt/60);return Et<24?`${Et}h ${tt%60}m ago`:`${Math.floor(Et/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"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>we(()=>se.tasks.approve(e.id)),disabled:M,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:()=>we(()=>se.tasks.reject(e.id)),disabled:M,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:()=>{we(()=>se.tasks.accept(e.id,m?.id))},disabled:M,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:"✓ Approve"}),D?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:H,onChange:ve=>Z(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&H.trim()&&(we(()=>se.tasks.revision(e.id,H.trim(),m?.id)),E(!1),Z(""))},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:()=>{we(()=>se.tasks.revision(e.id,H.trim()||"Revisions needed",m?.id)),E(!1),Z("")},disabled:M,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:()=>{E(!1),Z("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>E(!0),disabled:M,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"})]}),Ve&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{lt()},disabled:M,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:()=>{wt()},disabled:M,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"]})]}),dt&&t.jsx("button",{onClick:()=>{ft()},disabled:M,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:M?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"]})}),zt&&t.jsxs("button",{onClick:()=>{wt()},disabled:M,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"]}),Tt&&(st||zt)&&t.jsx("button",{onClick:()=>{Lt()},disabled:M,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:M?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"]})}),Tt&&!Ve&&(Bt?t.jsx("button",{onClick:()=>{we(()=>se.tasks.resumeSchedule(e.id))},disabled:M,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:()=>{we(()=>se.tasks.pauseSchedule(e.id))},disabled:M,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"})),(st||zt||fn||Mt)&&t.jsx("button",{onClick:()=>we(()=>se.tasks.archive(e.id)),disabled:M,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:"Archive"}),(st||zt)&&t.jsx("button",{onClick:()=>{rt()},disabled:M,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"}),!$t&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:ve}=await se.tasks.getDependentCount(e.id);ve>0?C({dependentCount:ve}):we(()=>se.tasks.cancel(e.id))},disabled:M,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"})]})}),_&&t.jsx($j,{title:`Delete subtask "${_.title}"?`,message:"This subtask will be permanently deleted.",confirmLabel:"Delete",onConfirm:()=>{Te(_)},onCancel:()=>S(null)}),k&&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:ve=>ve.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:k.dependentCount})," dependent task",k.dependentCount>1?"s":""," that ",k.dependentCount>1?"are":"is"," currently blocked by it."]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("button",{onClick:()=>{C(null),we(()=>se.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),we(()=>se.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 ",k.dependentCount," blocked task",k.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"})]})]})}),F&&t.jsx(KI,{filePath:F,onClose:()=>V(null)})]})}function QI({project:e,tasks:n,requirements:s,agents:i,onDeleteProject:o,onUpdateProject:d,onRefresh:c}){const h=v.useMemo(()=>n.filter(G=>G.projectId===e.id),[n,e.id]),m=v.useMemo(()=>s.filter(G=>G.projectId===e.id),[s,e.id]),f=v.useMemo(()=>{const G={total:h.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:m.length,reqsDone:0};for(const W of h)W.status==="completed"||W.status==="accepted"?G.completed++:W.status==="in_progress"?G.inProgress++:W.status==="review"||W.status==="revision"?G.inReview++:W.status==="blocked"?G.blocked++:W.status==="failed"?G.failed++:G.pending++;for(const W of m)W.status==="completed"&&G.reqsDone++;return G},[h,m]),x=v.useMemo(()=>new Set(h.map(G=>G.assignedAgentId).filter(Boolean)),[h]),p=v.useMemo(()=>i.filter(G=>x.has(G.id)),[i,x]),[g,y]=v.useState(!1),[w,N]=v.useState(""),[T,_]=v.useState("main"),[S,k]=v.useState(!1),C=[{value:"active",label:"Active",desc:"Work is ongoing"},{value:"paused",label:"Paused",desc:"Temporarily on hold"},{value:"archived",label:"Archived",desc:"No longer active"}],M=async G=>{if(G!==e.status){k(!0);try{await d({status:G}),c()}finally{k(!1)}}},L=async()=>{const G=w.trim();if(!G)return;const W=[...e.repositories??[],{url:"",localPath:G,defaultBranch:T||"main"}];await d({repositories:W}),N(""),_("main"),y(!1),c()},P=async G=>{const W=(e.repositories??[]).filter((z,q)=>q!==G);await d({repositories:W}),c()};return t.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx(HI,{value:e.description??"",onSave:async G=>{await d({description:G}),c()},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:[e.createdAt&&t.jsxs("span",{children:["Created ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:["Updated ",new Date(e.updatedAt).toLocaleDateString()]})]})]}),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:"Project Status"}),t.jsx("div",{className:"flex gap-2",children:C.map(G=>t.jsxs("button",{disabled:S,onClick:()=>M(G.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===G.value?G.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":G.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${S?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:G.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:G.desc})]},G.value))})]}),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(Xs,{label:"Total",value:f.total,color:"text-fg-primary"}),t.jsx(Xs,{label:"Completed",value:f.completed,color:"text-green-600"}),t.jsx(Xs,{label:"In Progress",value:f.inProgress,color:"text-brand-500"}),t.jsx(Xs,{label:"In Review",value:f.inReview,color:"text-brand-500"}),t.jsx(Xs,{label:"Blocked",value:f.blocked,color:"text-amber-600"}),t.jsx(Xs,{label:"Failed",value:f.failed,color:"text-red-500"})]}),f.total>0&&t.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[f.completed>0&&t.jsx("div",{className:"bg-green-500",style:{width:`${f.completed/f.total*100}%`}}),f.inProgress>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${f.inProgress/f.total*100}%`}}),f.inReview>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${f.inReview/f.total*100}%`}}),f.blocked>0&&t.jsx("div",{className:"bg-amber-500",style:{width:`${f.blocked/f.total*100}%`}}),f.pending>0&&t.jsx("div",{className:"bg-blue-500/40",style:{width:`${f.pending/f.total*100}%`}}),f.failed>0&&t.jsx("div",{className:"bg-red-500",style:{width:`${f.failed/f.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(Xs,{label:"Total",value:f.reqs,color:"text-fg-primary"}),t.jsx(Xs,{label:"Completed",value:f.reqsDone,color:"text-green-600"}),t.jsx(Xs,{label:"Active",value:f.reqs-f.reqsDone,color:"text-brand-500"})]})]}),p.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 (",p.length,")"]}),t.jsx("div",{className:"flex flex-wrap gap-2",children:p.map(G=>{const W=h.filter(q=>q.assignedAgentId===G.id),z=W.filter(q=>!["completed","failed","cancelled","archived"].includes(q.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 ${G.status==="working"?"bg-blue-500":G.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:G.name}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[z.length," active / ",W.length," total"]})]},G.id)})})]}),t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:"Repositories"}),t.jsx("button",{onClick:()=>y(!g),className:"text-[10px] text-brand-500 hover:text-brand-500",children:g?"Cancel":"+ Add"})]}),(e.repositories??[]).length===0&&!g&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:"No repositories linked."}),(e.repositories??[]).map((G,W)=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:[t.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),t.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate",children:G.url||G.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:G.defaultBranch}),t.jsx("button",{onClick:()=>P(W),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:"Remove repository",children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},W)),g&&t.jsxs("div",{className:"mt-2 space-y-2 p-3 bg-surface-elevated rounded-lg border border-border-default",children:[t.jsx("input",{value:w,onChange:G=>N(G.target.value),placeholder:"Local path (e.g. /Users/me/project)",className:"w-full px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:T,onChange:G=>_(G.target.value),placeholder:"Branch (default: main)",className:"flex-1 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsx("button",{onClick:L,disabled:!w.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:"Add"})]})]})]}),t.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:"Danger Zone"}),t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:"Deleting a project is permanent and cannot be undone. Tasks and requirements will be unlinked."}),t.jsx("button",{onClick:o,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 hover:bg-red-500/10 rounded-lg transition-colors",children:"Delete Project"})]})]})}function Xs({label:e,value:n,color:s}){return t.jsxs("div",{className:"text-center py-2",children:[t.jsx("div",{className:`text-xl font-bold ${s}`,children:n}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const di={pending:{label:"Pending",cls:"bg-amber-500/15 text-amber-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"}},$N={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed"},BN={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},ZI={urgent:0,high:1,medium:2,low:3},o1={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},c1={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"},JI={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"},ez=["pending","in_progress","completed","rejected","cancelled"];function tz(e){for(const n of Yo)if(n.statuses.includes(e))return n.id;return"closed"}function d1(e){const n=Date.now()-new Date(e).getTime(),s=Math.floor(n/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const i=Math.floor(s/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Nd({value:e,options:n,onSelect:s,allowedValues:i}){const[o,d]=v.useState(!1),c=v.useRef(null),h=v.useRef(null),m=n.find(f=>f.value===e);return v.useEffect(()=>{if(!o)return;const f=x=>{h.current&&!h.current.contains(x.target)&&c.current&&!c.current.contains(x.target)&&d(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[o]),t.jsxs("div",{className:"relative",children:[t.jsx("button",{ref:c,onClick:()=>d(f=>!f),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${m?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:m?.label??e}),o&&t.jsx("div",{ref:h,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:n.map(f=>{const x=f.value===e,p=x||!i||i.has(f.value);return t.jsxs("button",{disabled:!p,onClick:()=>{!x&&p&&s(f.value),d(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${x?"bg-surface-elevated":p?"hover:bg-surface-elevated/60":"opacity-35 cursor-not-allowed"}`,children:[t.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 ${p?f.cls.split(" ")[0]:"bg-gray-600"}`}),t.jsx("span",{className:`font-medium ${x?"text-fg-primary":p?"text-fg-secondary":"text-fg-muted"}`,children:f.label}),x&&t.jsx("svg",{className:"w-3 h-3 ml-auto text-brand-500",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"})})]},f.value)})})]})}function u1({row:e,idx:n,dragIdx:s,agentMap:i,projMap:o,onTaskClick:d,onReqClick:c,onRowDragStart:h,onRowDragEnd:m,handleStatusChange:f,handlePriorityChange:x,selected:p,isMobile:g}){const y=e.data.status,w=e.data.priority,N=e.kind==="task"?i.get(e.data.assignedAgentId??""):void 0,T=o.get((e.kind==="task",e.data.projectId??"")),_=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",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"});return g?t.jsxs("div",{onClick:()=>e.kind==="task"?d(e.data):c(e.data),className:`px-3 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${c1[e.group]??"border-l-gray-700"} ${p?"bg-brand-500/10 border-l-brand-500":"active:bg-surface-elevated/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[_,t.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsx("div",{onClick:S=>S.stopPropagation(),children:t.jsx(Nd,{value:y,options:e.kind==="task"?s1.map(S=>({value:S,label:So[S]?.label??S,cls:So[S]?.cls??"bg-gray-500/15 text-fg-tertiary"})):a1.map(S=>({value:S,label:di[S]?.label??S,cls:di[S]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?i1[y]:Qm[y],onSelect:S=>{f(e,S)}})}),t.jsx("div",{onClick:S=>S.stopPropagation(),children:t.jsx(Nd,{value:w,options:r1.map(S=>({value:S,label:wd[S]?.label??S,cls:wd[S]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:S=>{x(e,S)}})}),N&&t.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Zm[N.status]??"bg-gray-500"}`}),t.jsx("span",{className:`${l1[N.status]??"text-fg-secondary"}`,children:N.name})]}),T?.name&&t.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:T.name}),t.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:d1(e.data.updatedAt??"")})]})]}):t.jsxs("div",{draggable:!0,onDragStart:S=>h(S,n),onDragEnd:m,onClick:()=>e.kind==="task"?d(e.data):c(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${c1[e.group]??"border-l-gray-700"} ${s===n?"opacity-40":""} ${p?"bg-brand-500/10 border-l-brand-500 hover:bg-brand-500/15":"hover:bg-surface-elevated/50"}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:_}),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(Nd,{value:y,options:e.kind==="task"?s1.map(S=>({value:S,label:So[S]?.label??S,cls:So[S]?.cls??"bg-gray-500/15 text-fg-tertiary"})):a1.map(S=>({value:S,label:di[S]?.label??S,cls:di[S]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?i1[y]:Qm[y],onSelect:S=>{f(e,S)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:S=>S.stopPropagation(),children:t.jsx(Nd,{value:w,options:r1.map(S=>({value:S,label:wd[S]?.label??S,cls:wd[S]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:S=>{x(e,S)}})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:N?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Zm[N.status]??"bg-gray-500"}`}),t.jsx("span",{className:`font-medium ${l1[N.status]??"text-fg-secondary"}`,children:N.name})]}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:T?.name?t.jsx("span",{className:"text-brand-400/70",children:T.name}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-muted text-right",children:d1(e.data.updatedAt??"")})]})}function nz({tasks:e,requirements:n,agents:s,projects:i,onTaskClick:o,onReqClick:d,onRefresh:c,selectedTaskId:h,selectedReqId:m}){const f=Cr(),[x,p]=v.useState("status"),[g,y]=v.useState(null),[w,N]=v.useState(null),T=v.useMemo(()=>{const R=[];for(const I of e){const A=tz(I.status);R.push({kind:"task",data:I,group:A,groupOrder:o1[A]??5})}for(const I of n){const A=$N[I.status]??"todo";R.push({kind:"req",data:I,group:A,groupOrder:o1[A]??5})}if(x==="status")R.sort((I,A)=>{if(I.groupOrder!==A.groupOrder)return I.groupOrder-A.groupOrder;const F=new Date(I.data.updatedAt??0).getTime();return new Date(A.data.updatedAt??0).getTime()-F});else{const I=A=>ZI[A.data.priority]??2;R.sort((A,F)=>{const V=I(A),X=I(F);return V!==X?V-X:new Date(F.data.updatedAt??0).getTime()-new Date(A.data.updatedAt??0).getTime()})}return R},[e,n,x]),_=async(R,I)=>{try{R.kind==="task"?await se.tasks.updateStatus(R.data.id,I):await se.requirements.updateStatus(R.data.id,I),c()}catch{}},S=async(R,I)=>{try{R.kind==="task"?await se.tasks.update(R.data.id,{priority:I}):await se.requirements.update(R.data.id,{priority:I}),c()}catch{}},k=(R,I)=>{y(I),R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("text/plain",String(I)),R.currentTarget.style.opacity="0.4"},C=R=>{R.currentTarget.style.opacity="1",y(null),N(null)},M=(R,I)=>{R.preventDefault(),R.dataTransfer.dropEffect="move",w!==I&&N(I)},L=async(R,I)=>{if(R.preventDefault(),N(null),g==null)return;const A=T[g];if(!A||A.group===I)return;const F=Yo.find(V=>V.id===I);if(F){try{if(A.kind==="task"){if(A.data.status==="pending")return;await se.tasks.updateStatus(A.data.id,F.dropStatus)}else{const V=BN[I];V&&await se.requirements.updateStatus(A.data.id,V)}c()}catch{}y(null)}},P=v.useMemo(()=>new Map(s.map(R=>[R.id,R])),[s]),G=v.useMemo(()=>new Map(i.map(R=>[R.id,R])),[i]),W=["todo","in_progress","review","done"],z=v.useMemo(()=>{const R={};for(const I of T)R[I.group]=(R[I.group]??0)+1;return R},[T]),{rowsByGroup:q,rowIndexMap:Y}=v.useMemo(()=>{const R=new Map,I=new Map;for(let A=0;A<T.length;A++){const F=T[A];I.set(F,A);const V=R.get(F.group)??[];V.push(F),R.set(F.group,V)}return{rowsByGroup:R,rowIndexMap:I}},[T]),$=v.useMemo(()=>{if(x!=="status")return null;const R=new Set(T.map(F=>F.group)),I=[],A=new Set;R.has("failed")&&(I.push("failed"),A.add("failed"));for(const F of W)I.push(F),A.add(F);for(const F of T)A.has(F.group)||(I.push(F.group),A.add(F.group));return I},[T,x]);return t.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-secondary ${f?"overflow-x-hidden w-full":""}`,children:t.jsxs("div",{className:f?"w-full":"w-fit min-w-full",children:[!f&&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 sticky top-0 z-20 bg-surface-secondary",children:[t.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:T.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:"Title"}),t.jsxs("button",{onClick:()=>p("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${x==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:["Status ",x==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>p("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${x==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:["Priority ",x==="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",{children:[x==="status"&&$?$.map(R=>{const I=Yo.find(F=>F.id===R),A=q.get(R)??[];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 ${JI[R]??""} ${w===R?"ring-1 ring-brand-500/40":""}`,onDragOver:F=>M(F,R),onDragLeave:()=>N(null),onDrop:F=>{L(F,R)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:I?.label??R}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:z[R]??0})]}),A.map(F=>t.jsx(u1,{row:F,idx:Y.get(F)??0,dragIdx:g,agentMap:P,projMap:G,onTaskClick:o,onReqClick:d,onRowDragStart:k,onRowDragEnd:C,handleStatusChange:_,handlePriorityChange:S,selected:F.kind==="task"?F.data.id===h:F.data.id===m,isMobile:f},`${F.kind}-${F.data.id}`))]},R)}):T.map((R,I)=>t.jsx(u1,{row:R,idx:I,dragIdx:g,agentMap:P,projMap:G,onTaskClick:o,onReqClick:d,onRowDragStart:k,onRowDragEnd:C,handleStatusChange:_,handlePriorityChange:S,selected:R.kind==="task"?R.data.id===h:R.data.id===m,isMobile:f},`${R.kind}-${R.data.id}`)),T.length===0&&t.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-fg-tertiary",children:"No items"})]})]})})}function f1({authUser:e}){const n=Cr(),s=au({side:"right",defaultWidth:Math.round(window.innerWidth*2/3),minWidth:380,maxWidth:Math.round(window.innerWidth*.8),storageKey:"markus_projects_detail_v3"}),[i,o]=v.useState(!1),d=v.useRef(i);d.current=i;const[c,h]=v.useState([]),[m,f]=v.useState("all"),[x,p]=v.useState(null),[g,y]=v.useState({}),[w,N]=v.useState([]),[T,_]=v.useState([]),[S,k]=v.useState([]),[C,M]=v.useState(!0),[L,P]=v.useState(""),[G,W]=v.useState(!1),z=v.useCallback(()=>{sn(x??""),tt(!0)},[x]),[q,Y]=v.useState(!1),[$,R]=v.useState(!1),[I,A]=v.useState(""),[F,V]=v.useState(""),[X,O]=v.useState("medium"),[U,K]=v.useState(""),[D,E]=v.useState(""),[H,Z]=v.useState(""),[ee,ne]=v.useState(""),[ae,he]=v.useState([]),[Se,Ie]=v.useState("standard"),[xe,we]=v.useState("4h"),[Me,Be]=v.useState(null),[et,lt]=v.useState(null),[ft,yt]=v.useState(new Set),[re,Te]=v.useState(new Set),rt=v.useRef(new Set),wt=v.useRef(new Set),[Lt,je]=v.useState(null),[De,Ve]=v.useState("backlog"),dt=v.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"}],[]),st=Js(dt,De,Ve),zt=v.useRef(null),fn=v.useMemo(()=>({scrollContainerRef:zt}),[]),Mt=Js(dt,De,Ve,fn),[_t,$t]=v.useState(!1),[Tt,Bt]=v.useState(!1),Xt=v.useRef(null),hn=v.useRef(null),[ve,tt]=v.useState(!1),[Et,Pe]=v.useState(""),[vt,mn]=v.useState(""),[Rn,kn]=v.useState("medium"),[Jt,sn]=v.useState(""),[On,Nt]=v.useState(null),[en,Bn]=v.useState(""),le=Q=>{P(Q),setTimeout(()=>P(""),3e3)},ze=c.find(Q=>Q.id===x)??null;v.useEffect(()=>{wt.current=re},[re]);const Fe=v.useCallback(async()=>{try{const{projects:Q}=await se.projects.list();h(Q)}catch{}},[]),Qe=v.useCallback(async()=>{const Q={};m==="project"&&x&&(Q.projectId=x);try{const{board:oe}=await se.tasks.board(Q);y(oe)}catch{}},[m,x]),Xe=v.useCallback(async()=>{try{const{agents:Q}=await se.agents.list();N(Q)}catch{}},[]),Ye=v.useCallback(async()=>{try{const{users:Q}=await se.users.list(e?.orgId);_(Q)}catch{}},[e?.orgId]),nt=v.useCallback(async()=>{try{const{requirements:Q}=await se.requirements.list({});k(Q)}catch{}},[]),pt=v.useCallback(async()=>{await Promise.all([Fe(),Qe(),Xe(),Ye(),nt()]),M(!1)},[Fe,Qe,Xe,Ye,nt]);v.useEffect(()=>{pt()},[pt]);const an=v.useCallback(Q=>{Be(oe=>oe?.id===Q.id?(n&&d.current&&o(!1),null):(n&&(o(!0),history.pushState({mobileDetail:me.WORK},"",window.location.hash)),Q)),lt(null)},[n]),It=v.useCallback(Q=>{lt(oe=>oe?.id===Q.id?(n&&d.current&&o(!1),null):(n&&(o(!0),history.pushState({mobileDetail:me.WORK},"",window.location.hash)),Q)),Be(null)},[n]),xn=v.useCallback(()=>{Be(null),lt(null),n&&d.current&&o(!1)},[n]);v.useEffect(()=>{if(!n)return;const Q=()=>{d.current&&(o(!1),Be(null),lt(null))};return window.addEventListener("popstate",Q),()=>window.removeEventListener("popstate",Q)},[n]);const be=v.useRef(Me);be.current=Me,v.useEffect(()=>{const Q=be.current?6e4:15e3,oe=setInterval(()=>{Qe(),Xe(),nt()},Q),ke=ln.on("task:update",qe=>{Qe();const Ee=qe?.payload;Ee?.taskId&&Be(ht=>{if(!ht||ht.id!==Ee.taskId)return ht;const Pt={};return typeof Ee.status=="string"&&(Pt.status=Ee.status),Array.isArray(Ee.deliverables)&&(Pt.deliverables=Ee.deliverables),Array.isArray(Ee.notes)&&(Pt.notes=Ee.notes),Ee.result!==void 0&&(Pt.result=Ee.result),{...ht,...Pt}})}),Re=ln.on("task:create",()=>{Qe()}),Ke=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(qe=>ln.on(qe,()=>{nt()}));return()=>{clearInterval(oe),ke(),Re(),Ke.forEach(qe=>qe())}},[Qe,Xe,nt]);const Ge=v.useRef(g);Ge.current=g;const St=v.useRef(S);St.current=S;const Ct=v.useCallback(Q=>{if(!Q)return;const oe=wt.current;oe.size>0&&!oe.has(Q)&&Te(ke=>new Set([...ke,Q]))},[]),pn=v.useCallback(Q=>{Be(Q),lt(null),n&&(o(!0),history.pushState({mobileDetail:me.WORK},"",window.location.hash))},[n]),Zn=v.useCallback(Q=>{lt(Q),Be(null),n&&(o(!0),history.pushState({mobileDetail:me.WORK},"",window.location.hash))},[n]);v.useEffect(()=>{const Q=localStorage.getItem("markus_nav_openTask");if(!Q)return;const ke=Object.values(g).flat().find(Re=>Re.id===Q);ke&&(Ct(ke.projectId),pn(ke),localStorage.removeItem("markus_nav_openTask"))},[g,pn,Ct]),v.useEffect(()=>{const Q=window.location.hash.slice(1).split("/");if(Qs(Q[0])===me.WORK&&Q[1])on(Q[1]);else{const oe=localStorage.getItem("markus_nav_projectId");oe&&(localStorage.removeItem("markus_nav_projectId"),on(oe))}},[]);const ir=v.useRef(Qs(window.location.hash.slice(1).split("/")[0]));v.useEffect(()=>{const Q=()=>{const ke=window.location.hash.slice(1).split("/"),Re=Qs(ke[0]),$e=ir.current===me.WORK;ir.current=Re,Re===me.WORK&&(Re===me.WORK&&ke[1]?on(ke[1]):$e&&ur())},oe=ke=>{const Re=ke.detail;if(Qs(Re.page)===me.WORK){if(Re.params?.openTask){const Ke=Object.values(Ge.current).flat().find(qe=>qe.id===Re.params.openTask);Ke&&(Ct(Ke.projectId),pn(Ke),localStorage.removeItem("markus_nav_openTask"))}if(Re.params?.openRequirement){const $e=St.current.find(Ke=>Ke.id===Re.params.openRequirement);$e&&(Ct($e.projectId),Zn($e))}Re.params?.projectId&&on(Re.params.projectId)}};return window.addEventListener("markus:navigate",oe),window.addEventListener("hashchange",Q),()=>{window.removeEventListener("markus:navigate",oe),window.removeEventListener("hashchange",Q)}},[]);const on=Q=>{wt.current.size>0&&(rt.current=new Set(wt.current)),Te(new Set),p(Q),f("project"),W(!1),history.replaceState(null,"",um(me.WORK,Q))},ur=()=>{Te(rt.current),p(null),f("all"),W(!1),history.replaceState(null,"",um(me.WORK))},ns=()=>{Y(!1),le("Project created"),Fe()},de=async Q=>{if(confirm("Delete this project and unlink all its tasks?"))try{await se.projects.delete(Q),x===Q&&ur(),le("Project deleted"),Fe(),Qe()}catch(oe){le(`Error: ${oe}`)}},Ae=async()=>{if(!I||!U||!D)return;if(U===D){le("Assigned agent and reviewer must be different");return}const Q=H||void 0,oe=ee||void 0;try{await se.tasks.create(I,F,U,D,X,Q,ae.length>0?ae:void 0,oe,Se!=="standard"?Se:void 0,Se==="scheduled"?{every:xe}:void 0),A(""),V(""),he([]),ne(""),Ie("standard"),we("4h"),R(!1),Qe()}catch(ke){le(`Error creating task: ${ke}`)}},Ue=()=>{Qe(),Me&&setTimeout(()=>{const Q={};m==="project"&&x&&(Q.projectId=x),se.tasks.board(Q).then(oe=>{const Re=Object.values(oe.board).flat().find($e=>$e.id===Me.id);Be(Re||null)}).catch(()=>{})},150)},Ht=async()=>{if(!Et.trim()){le("Please enter a title for this requirement");return}if(!vt.trim()){le("Please enter a description for this requirement");return}if(!Jt){le("Please select a project for this requirement");return}try{await se.requirements.create({title:Et.trim(),description:vt.trim(),priority:Rn,projectId:Jt}),le("Requirement created"),Pe(""),mn(""),tt(!1),nt()}catch(Q){le(`Error: ${Q}`)}},xr=async Q=>{try{await se.requirements.approve(Q),le("Requirement approved"),nt(),Qe()}catch(oe){le(`Error: ${oe}`)}},Tr=async()=>{if(On)try{await se.requirements.reject(On,en),le("Requirement rejected"),Nt(null),Bn(""),nt()}catch(Q){le(`Error: ${Q}`)}},Pr=async Q=>{try{await se.requirements.cancel(Q),le("Requirement cancelled"),nt()}catch(oe){le(`Error: ${oe}`)}},Ur=(Q,oe)=>{Xt.current=oe,hn.current=null,Q.dataTransfer.effectAllowed="move",Q.dataTransfer.setData("text/plain",`task:${oe.id}`),Q.currentTarget.style.opacity="0.4"},fr=(Q,oe)=>{hn.current=oe,Xt.current=null,Q.dataTransfer.effectAllowed="move",Q.dataTransfer.setData("text/plain",`req:${oe.id}`),Q.currentTarget.style.opacity="0.4"},Hn=Q=>{Q.currentTarget.style.opacity="1",Xt.current=null,hn.current=null,je(null)},ra=(Q,oe)=>{Q.preventDefault(),Q.dataTransfer.dropEffect="move",Lt!==oe&&je(oe)},sa=(Q,oe)=>{const ke=Q.currentTarget.getBoundingClientRect(),{clientX:Re,clientY:$e}=Q;(Re<ke.left||Re>ke.right||$e<ke.top||$e>ke.bottom)&&Lt===oe&&je(null)},pr=async(Q,oe)=>{Q.preventDefault(),je(null);const ke=Xt.current,Re=hn.current;if(ke){const $e=Yo.find(qe=>qe.id===oe);if(!$e)return;const Ke=$e.dropStatus;if(ke.status===Ke||ke.status==="pending")return;try{await se.tasks.updateStatus(ke.id,Ke),Qe()}catch{}}else if(Re){const $e=BN[oe];if(!$e||Re.status===$e)return;try{await se.requirements.updateStatus(Re.id,$e),nt()}catch{}}},_s=Q=>{yt(oe=>{const ke=new Set(oe);return ke.has(Q)?ke.delete(Q):ke.add(Q),ke})},qr=Q=>{Te(oe=>{const ke=new Set(oe);return ke.has(Q)?ke.delete(Q):ke.add(Q),ke})},Ha=1440*60*1e3,Jn=Date.now(),Kn=Q=>Q.updatedAt&&Jn-new Date(Q.updatedAt).getTime()>Ha,_r=Q=>(Q.status==="completed"||Q.status==="cancelled")&&Kn(Q),rs=(Q,oe=!1)=>{let ke=Q.filter(Re=>_t||oe||!_r(Re));return m==="project"&&x&&(ke=ke.filter(Re=>Re.projectId===x)),re.size>0&&(ke=ke.filter(Re=>Re.projectId&&re.has(Re.projectId))),ft.size>0&&(ke=ke.filter(Re=>Re.assignedAgentId&&ft.has(Re.assignedAgentId))),ke},gr=Q=>Q.statuses.flatMap(oe=>rs(g[oe]??[])),lr=v.useMemo(()=>{let Q=S;return _t||(Q=Q.filter(oe=>!_r(oe))),m==="project"&&x&&(Q=Q.filter(oe=>oe.projectId===x)),re.size>0&&(Q=Q.filter(oe=>oe.projectId&&re.has(oe.projectId))),ft.size>0&&(Q=Q.filter(oe=>ft.has(oe.createdBy))),Q},[S,_t,m,x,re,ft]),As=v.useCallback(Q=>lr.filter(oe=>$N[oe.status]===Q.id),[lr]),Vr=Yo.filter(Q=>{if(Q.id==="failed"||Q.id==="closed"){const oe=gr(Q),ke=As(Q);return oe.length+ke.length>0}return!0}),Fr=Object.values(g).flat().filter(Q=>_r(Q)).length+S.filter(Q=>_r(Q)).length,aa=v.useMemo(()=>{const Q=new Set(["completed","failed","cancelled","archived"]),oe=Object.values(g).flat(),ke=new Set;for(const Re of oe)Re.assignedAgentId&&!Q.has(Re.status)&&(!x||Re.projectId===x)&&ke.add(Re.assignedAgentId);return[...w].sort((Re,$e)=>{const Ke=ke.has(Re.id)?0:1,qe=ke.has($e.id)?0:1;return Ke-qe})},[w,g,x]),Pa=v.useMemo(()=>{const Q=new Set(["completed","failed","cancelled","archived"]),oe=Object.values(g).flat(),ke=new Set;for(const Re of oe)Re.projectId&&!Q.has(Re.status)&&ke.add(Re.projectId);return[...c].sort((Re,$e)=>{const Ke=ke.has(Re.id)?0:1,qe=ke.has($e.id)?0:1;return Ke-qe})},[c,g]),Ms=v.useMemo(()=>{const Q={};for(const oe of Object.values(g))for(const ke of oe){const Re=ke.projectId??"__none__";Q[Re]=(Q[Re]??0)+1}return Q},[g]),te=Object.values(Ms).reduce((Q,oe)=>Q+oe,0);if(C)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:"Loading…"});const Ce=!!(Me||et);return t.jsxs("div",{className:"flex-1 overflow-hidden flex bg-surface-secondary",children:[t.jsxs("div",{className:`${n?"flex-1 min-w-0":Ce?"shrink-0":"flex-1"} overflow-hidden flex flex-col bg-surface-secondary`,style:n?i?{display:"none"}:void 0:Ce?{width:`calc(100% - ${s.width}px - 4px)`}:void 0,children:[L&&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:L}),n?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:[ze?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:ze.name}),t.jsx("button",{onClick:()=>W(!G),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${G?"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:c.length===1?c[0].name:`${c.length} Projects`}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>Y(!0),className:"px-2 py-1 text-[11px] border border-border-default text-fg-secondary rounded-md",children:"+ Project"}),t.jsx("button",{onClick:z,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:"+ Req"}),t.jsx("button",{onClick:()=>{Z(x??""),R(!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(Q=>t.jsx("button",{onClick:()=>Ve(Q),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${De===Q?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:Q==="backlog"?"Backlog":Q==="kanban"?"Kanban":"DAG"},Q))}),Fr>0&&t.jsx("button",{onClick:()=>$t(Q=>!Q),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${_t?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:_t?"Hide archived":`${Fr} archived`}),t.jsx("div",{className:"flex-1"}),(re.size>0||ft.size>0||c.length>1||w.length>0)&&t.jsxs("button",{onClick:()=>Bt(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${re.size>0||ft.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",re.size+ft.size>0?` (${re.size+ft.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:[ze?t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(BI,{value:ze.name,onSave:async Q=>{await se.projects.update(ze.id,{name:Q}),Fe()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:()=>W(!G),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${G?"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:c.length===1?c[0].name:`${c.length} Projects`}),Fr>0&&t.jsx("button",{onClick:()=>$t(Q=>!Q),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${_t?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:_t?`Hide ${Fr} archived`:`${Fr} archived`}),t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(Q=>t.jsx("button",{onClick:()=>Ve(Q),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${De===Q?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:Q==="backlog"?"Backlog":Q==="kanban"?"Kanban":"DAG"},Q))}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:z,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:()=>{Z(x??""),R(!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"})]}),!n&&c.length>1&&!x&&!G&&(te>0||S.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:()=>Te(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 ${re.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),Pa.map(Q=>{const oe=re.has(Q.id),ke=Ms[Q.id]??0;return t.jsxs("button",{onClick:()=>qr(Q.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${oe?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:Q.name[0]?.toUpperCase()}),Q.name,ke>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:ke})]},Q.id)})]}),!n&&w.length>0&&!G&&(te>0||S.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:()=>yt(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 ${ft.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),aa.map(Q=>{const oe=ft.has(Q.id);return t.jsxs("button",{onClick:()=>_s(Q.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${oe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:Q.name[0]?.toUpperCase()}),Q.name]},Q.id)})]}),G&&ze?t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsx(QI,{project:ze,tasks:Object.values(g).flat(),requirements:S,agents:w,onDeleteProject:()=>de(ze.id),onUpdateProject:async Q=>{await se.projects.update(ze.id,Q)},onRefresh:()=>{Fe()}})}):te===0&&lr.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:z,className:"text-xs text-brand-500 hover:text-brand-500 font-medium",children:"+ Create a requirement"})]})}):De==="backlog"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:n?st.onTouchStart:void 0,onTouchEnd:n?st.onTouchEnd:void 0,children:t.jsx(nz,{tasks:rs(Object.values(g).flat()),requirements:lr,agents:w,projects:c,onTaskClick:Q=>an(Q),onReqClick:Q=>It(Q),onRefresh:()=>{Qe(),nt()},selectedTaskId:Me?.id,selectedReqId:et?.id})}):De==="dag"?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:n?st.onTouchStart:void 0,onTouchEnd:n?st.onTouchEnd:void 0,children:[t.jsx($I,{tasks:rs(Object.values(g).flat(),!0),requirements:lr,agents:w,showArchived:_t,onShowArchivedChange:$t,onTaskClick:Q=>an(Q),onReqClick:Q=>It(Q),onDependencyChange:Qe,selectedTaskId:Me?.id,selectedReqId:et?.id}),n&&t.jsx("button",{onClick:()=>Ve("kanban"),className:"absolute left-3 top-1/2 -translate-y-1/2 w-11 h-11 rounded-full bg-brand-500 border border-brand-400/60 shadow-xl shadow-brand-500/30 flex items-center justify-center text-white active:bg-brand-400 backdrop-blur-sm z-10",title:"Back to Kanban",children:t.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})})})]}):t.jsx("div",{ref:zt,className:"flex-1 min-h-0 overflow-x-auto overflow-y-hidden px-4 py-5",onTouchStart:n?Mt.onTouchStart:void 0,onTouchEnd:n?Mt.onTouchEnd:void 0,children:t.jsx("div",{className:"flex gap-3 h-full",children:Vr.map(Q=>{const oe=gr(Q),ke=As(Q),Re=oe.length+ke.length,$e=Lt===Q.id;return t.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col h-full transition-colors ${$e?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:Ke=>ra(Ke,Q.id),onDragLeave:Ke=>sa(Ke,Q.id),onDrop:Ke=>{pr(Ke,Q.id)},children:[t.jsxs("div",{className:"flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${Q.accent.replace("border-t-","bg-")}`}),t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:Q.label})]}),t.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:Re})]}),t.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin px-2 py-2",children:(()=>{const Ke=[...ke.map(qe=>({kind:"req",data:qe,time:new Date(qe.updatedAt??qe.createdAt).getTime()})),...oe.map(qe=>({kind:"task",data:qe,time:new Date(qe.updatedAt??qe.createdAt??0).getTime()}))];return Ke.sort((qe,Ee)=>Ee.time-qe.time),Ke.map(qe=>{if(qe.kind==="req"){const Ee=qe.data,ht=di[Ee.status]??{label:Ee.status,cls:"bg-gray-500/15 text-fg-secondary"},Ut=Ee.source==="agent"&&Ee.status==="pending",Kt=m==="all"&&Ee.projectId?c.find(Ze=>Ze.id===Ee.projectId):null,mt=yl(Ee.createdBy,w,T)??Ee.createdBy.slice(0,10),bt=et?.id===Ee.id;return t.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:Ze=>fr(Ze,Ee),onDragEnd:Hn,onClick:()=>It(Ee),onKeyDown:Ze=>Ze.key==="Enter"&&It(Ee),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
62
62
  ${Ut?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40"}
63
- ${bt?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),t.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:"REQ"}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${ht.cls}`,children:ht.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Ee.title}),Ee.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Ee.description}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[Kt&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:Kt.name,children:Kt.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Ee.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",mt]})]}),t.jsx("div",{className:"flex items-center gap-1",children:Ee.taskIds.length>0&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",Ee.taskIds.length]})})]}),Ut&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:Ze=>{Ze.stopPropagation(),xr(Ee.id)},className:"flex-1 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:Ze=>{Ze.stopPropagation(),Nt(Ee.id)},className:"flex-1 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-${Ee.id}`)}else{const Ee=qe.data,ht=Ee.subtasks?.length??0,Pt=zN[Ee.status],Ut=Ee.status==="pending",Kt=Ee.taskType==="scheduled"&&!!Ee.scheduleConfig,mt=Kt?Ee.scheduleConfig.every?`Every ${Ee.scheduleConfig.every}`:Ee.scheduleConfig.cron?"Cron":"Scheduled":null,bt=m==="all"&&Ee.projectId?c.find(We=>We.id===Ee.projectId)?.name:null,Ze=Ee.requirementId?S.find(We=>We.id===Ee.requirementId)?.title:null,Je=Ee.createdBy?yl(Ee.createdBy,w,T)??Ee.createdBy:null,at=Me?.id===Ee.id,ot={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"};return t.jsxs("div",{role:"button",tabIndex:0,"aria-label":Ee.title,draggable:!Ut,onDragStart:We=>!Ut&&Ur(We,Ee),onDragEnd:Hn,onClick:()=>an(Ee),onKeyDown:We=>We.key==="Enter"&&an(Ee),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Ut?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Kt?"bg-blue-500/[0.04] border-blue-500/20 hover:border-blue-400/40 cursor-pointer":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40 cursor-grab active:cursor-grabbing"} ${at?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${ot[Ee.priority]??"bg-gray-400"}`,title:Ee.priority}),Kt&&t.jsx("span",{className:"text-blue-500 shrink-0",title:mt??"Scheduled",children:t.jsx("svg",{className:"w-3 h-3",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"})})}),Kt&&mt&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:mt}),Pt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Pt.cls}`,children:Pt.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Ee.title}),Ee.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Ee.description}),(bt||Ze||Ee.blockedBy&&Ee.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[bt&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded-md truncate max-w-[100px]",title:bt,children:bt}),Ze&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-brand-500/8 text-brand-500 rounded-md truncate max-w-[110px]",title:Ze,children:["# ",Ze]}),Ee.blockedBy&&Ee.blockedBy.length>0&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",Ee.blockedBy.length," dep",Ee.blockedBy.length>1?"s":""]})]}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:Je&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Je}`,children:["by ",Je]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[ht>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",ht]}),Ee.notes&&Ee.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",Ee.notes.length]}),Ee.assignedAgentId&&t.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Zm[w.find(We=>We.id===Ee.assignedAgentId)?.status??""]??"bg-gray-500"}`}),w.find(We=>We.id===Ee.assignedAgentId)?.name??Ee.assignedAgentId.slice(0,8)]})]})]})]},Ee.id)}})})()}),$e&&t.jsx("div",{className:"mx-2 mb-2 border-2 border-dashed border-brand-500/25 rounded-lg h-10 flex items-center justify-center shrink-0",children:t.jsx("span",{className:"text-[11px] text-brand-500/50",children:"Drop here"})})]},Q.id)})})})]}),!n&&Ce&&t.jsx("div",{className:"w-1 shrink-0 cursor-col-resize bg-border-default/40 hover:bg-brand-500/30 active:bg-brand-500/50 transition-colors",onMouseDown:s.onResizeStart}),(!n||i)&&Ce&&t.jsx("div",{className:`${n?"flex-1":"shrink-0"} overflow-hidden min-w-0 border-l border-border-default`,style:n?void 0:{width:s.width},children:Me?t.jsx(WI,{task:Me,agents:w,projects:c,requirements:S,allTasks:Object.values(g).flat(),users:T,onClose:xn,onRefresh:Ue,authUser:e}):et?t.jsx(sz,{req:et,agents:w,projects:c,allTasks:Object.values(g).flat(),users:T,onClose:xn,onApprove:Q=>{xr(Q),xn()},onReject:Q=>{Nt(Q),xn()},onCancel:Q=>{Pr(Q),xn()},onStatusChange:async(Q,oe)=>{try{await se.requirements.updateStatus(Q,oe),le(`Requirement status → ${oe}`),nt(),Qe()}catch(ke){le(`Error: ${ke}`)}},onRefresh:nt,authUser:e}):null}),q&&t.jsx(LN,{orgId:e?.orgId,onCreated:ns,onClose:()=>Y(!1)}),$&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>R(!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 ${n?"w-full":"w-[28rem]"}`,onClick:Q=>Q.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:H,onChange:Q=>Z(Q.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"}),c.map(Q=>t.jsx("option",{value:Q.id,children:Q.name},Q.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Requirement"}),t.jsxs("select",{value:ee,onChange:Q=>ne(Q.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…"}),S.filter(Q=>Q.status==="in_progress"&&(!H||Q.projectId===H)).map(Q=>t.jsx("option",{value:Q.id,children:Q.title},Q.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{autoFocus:!n,value:I,onChange:Q=>A(Q.target.value),onKeyDown:Q=>{Q.key==="Enter"&&Ae()},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:F,onChange:Q=>V(Q.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:X,onChange:Q=>O(Q.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:U,onChange:Q=>K(Q.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…"}),w.map(Q=>t.jsx("option",{value:Q.id,children:Q.name},Q.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:D,onChange:Q=>E(Q.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…"}),w.filter(Q=>Q.id!==U).map(Q=>t.jsx("option",{value:Q.id,children:Q.name},Q.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:Se,onChange:Q=>Ie(Q.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)"})]})]}),Se==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Frequency"}),t.jsxs("select",{value:xe,onChange:Q=>we(Q.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:Q=>{const oe=Q.target.value;oe&&!ae.includes(oe)&&he([...ae,oe])},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select a task to depend on…"}),Object.values(g).flat().filter(Q=>Q.status!=="completed"&&Q.status!=="cancelled"&&!ae.includes(Q.id)).map(Q=>t.jsx("option",{value:Q.id,children:Q.title},Q.id))]}),ae.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ae.map(Q=>{const oe=Object.values(g).flat().find(ke=>ke.id===Q);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:["⏳ ",oe?oe.title.slice(0,30):Q.slice(-8),t.jsx("button",{onClick:()=>he(ae.filter(ke=>ke!==Q)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},Q)})})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>R(!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:()=>{Ae()},disabled:!U||!D,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Create"})]})]})}),ve&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{tt(!1),Pe(""),mn("")},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 ${n?"w-full":"w-[28rem]"}`,onClick:Q=>Q.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:Jt,onChange:Q=>sn(Q.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…"}),c.map(Q=>t.jsx("option",{value:Q.id,children:Q.name},Q.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{value:Et,onChange:Q=>Pe(Q.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:!n,onKeyDown:Q=>{Q.key==="Enter"&&Et.trim()&&Ht()}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:vt,onChange:Q=>mn(Q.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:Rn,onChange:Q=>kn(Q.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:()=>{tt(!1),Pe(""),mn("")},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:()=>{Ht()},disabled:!Et.trim()||!vt.trim()||!Jt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40 disabled:cursor-not-allowed",children:"Create"})]})]})}),On&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>Nt(null),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${n?"w-full":"w-96"}`,onClick:Q=>Q.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:en,onChange:Q=>Bn(Q.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:!n})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>Nt(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:()=>{Tr()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:"Reject"})]})]})}),Tt&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Bt(!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:Q=>Q.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:[(re.size>0||ft.size>0)&&t.jsx("button",{onClick:()=>{Te(new Set),yt(new Set)},className:"text-[11px] text-brand-500 font-medium",children:"Clear all"}),t.jsx("button",{onClick:()=>Bt(!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"})]})})]})]}),c.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:Pa.map(Q=>{const oe=re.has(Q.id),ke=Ms[Q.id]??0;return t.jsxs("button",{onClick:()=>qr(Q.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${oe?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:Q.name[0]?.toUpperCase()}),Q.name,ke>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:ke})]},Q.id)})})]}),w.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:aa.map(Q=>{const oe=ft.has(Q.id);return t.jsxs("button",{onClick:()=>_s(Q.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${oe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:Q.name[0]?.toUpperCase()}),Q.name]},Q.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function rz({requirementId:e,agents:n,authUser:s}){const[i,o]=v.useState([]);v.useEffect(()=>{se.requirements.getComments(e).then(f=>o(f.comments)).catch(()=>{})},[e]),v.useEffect(()=>ln.on("requirement:comment",x=>{x.payload?.requirementId===e&&x.payload.comment&&o(p=>p.some(g=>g.id===x.payload.comment.id)?p:[...p,x.payload.comment])}),[e]);const[d,c]=v.useState(null),h=async(f,x,p)=>{await se.requirements.addComment(e,f,s?.name,s?.id,x.length>0?x:void 0,p)},m=v.useCallback(f=>{c({id:f.id,authorName:f.authorName,content:f.content.slice(0,100)})},[]);return t.jsxs("div",{children:[t.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:["Comments ",i.length>0&&t.jsxs("span",{className:"font-normal",children:["(",i.length,")"]})]}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[i.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:"No comments yet."}),i.map(f=>t.jsx(Mo,{comment:f,agents:n,onReply:m},f.id))]}),t.jsx(zj,{agents:n,onSubmit:h,replyTo:d,onCancelReply:()=>c(null)})]})}function sz({req:e,agents:n,projects:s,allTasks:i,users:o,onClose:d,onApprove:c,onReject:h,onCancel:m,onStatusChange:f,onRefresh:x,authUser:p}){const g=Cr(),[y,w]=v.useState(!1),[N,T]=v.useState(e.description),[_,S]=v.useState(!1),k=di[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},C=e.source==="agent",M=C&&e.status==="pending",L=e.status==="pending"||e.status==="in_progress",P=e.status==="completed"||e.status==="rejected"||e.status==="cancelled",G=e.projectId?s.find(q=>q.id===e.projectId):null,W=yl(e.createdBy,n,o)??e.createdBy.slice(0,12),z=i.filter(q=>e.taskIds.includes(q.id));return v.useEffect(()=>{T(e.description),w(!1)},[e.id,e.description]),t.jsxs("div",{className:"flex flex-col h-full overflow-hidden bg-surface-secondary",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[g&&t.jsx("button",{onClick:d,className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",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.jsxs("div",{className:"flex-1 min-w-0 pb-4",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 ${k.cls}`,children:k.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})]})]}),!g&&t.jsx("button",{onClick:d,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:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:"Description"}),y?t.jsxs("div",{className:"space-y-2",children:[t.jsx("textarea",{value:N,onChange:q=>T(q.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,autoFocus:!0}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx("button",{onClick:()=>{w(!1),T(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:async()=>{S(!0);try{await se.requirements.update(e.id,{description:N}),w(!1),x?.()}catch{}finally{S(!1)}},disabled:_,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.jsx(tr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No description"}),!P&&t.jsx("button",{onClick:()=>{T(e.description),w(!0)},className:"absolute top-0 right-0 text-[10px] text-fg-tertiary hover:text-brand-500 opacity-0 group-hover:opacity-100 transition-opacity",children:"Edit"})]})]}),t.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:W}),C&&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()})]}),G&&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:G.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:yl(e.approvedBy,n,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})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(q=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",q]},q))}),z.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 (",z.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:z.map(q=>{const Y=zN[q.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 ${FI[q.priority]?.replace("border-l-","bg-")??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:q.title}),Y&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Y.cls}`,children:Y.label})]},q.id)})})]}),t.jsx(rz,{requirementId:e.id,agents:n,authUser:p})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[M&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>c(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:()=>h(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"})]}),!M&&f&&!P&&t.jsx("select",{value:e.status,onChange:q=>{q.target.value!==e.status&&f(e.id,q.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:ez.map(q=>{const Y=di[q],$=q===e.status||(Qm[e.status]?.has(q)??!1);return t.jsx("option",{value:q,disabled:!$,children:Y?.label??q},q)})}),P&&f&&t.jsx("button",{onClick:()=>f(e.id,"in_progress"),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"}),L&&!M&&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 ys(e){return Array.isArray(e)?e.map(n=>String(n).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(n=>n.trim()).filter(Boolean):[]}function az(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function ii({label:e,value:n}){return n?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:n})]}):null}function Ji({label:e,value:n,color:s}){if(!n)return null;const i={purple:"bg-brand-500/15 text-brand-500",cyan:"bg-blue-500/15 text-blue-600",indigo:"bg-brand-500/15 text-brand-500",gray:"bg-gray-500/15 text-fg-secondary",emerald:"bg-green-500/15 text-green-600"};return t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${i[s]??i.gray} capitalize inline-block`,children:n})]})}function om({files:e}){const[n,s]=v.useState(Object.keys(e)[0]??""),i=Object.keys(e);return i.length===0?null:t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Files (",i.length,")"]}),t.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[t.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:i.map(o=>t.jsx("button",{onClick:()=>s(o),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${n===o?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:o},o))}),n&&e[n]!=null&&t.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[n]})]})]})}function iz({artifact:e,mode:n}){const s=az(e),i=e.agent,o=e.team,d=e.dependencies,c=e.displayName??e.name;if(n==="agent"){const h=i?.roleName,m=i?.agentRole,f=i?.llmProvider,x=i?.llmModel,p=ys(d?.env),g=ys(d?.skills);return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(ii,{label:"Name",value:c}),t.jsx(ii,{label:"Description",value:e.description}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(Ji,{label:"Role Template",value:h,color:"indigo"}),t.jsx(Ji,{label:"Agent Role",value:m,color:m==="manager"?"purple":"cyan"})]}),ys(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:ys(e.tags).map(y=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:y},y))}),(f||x)&&t.jsxs("div",{className:"flex gap-2",children:[f&&t.jsx(Ji,{label:"LLM Provider",value:f,color:"gray"}),x&&t.jsx(Ji,{label:"LLM Model",value:x,color:"gray"})]}),p.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:p.map(y=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/10 text-amber-600 rounded font-mono",children:y},y))})]}),g.length>0&&t.jsx(ii,{label:"Skills",value:g.join(", ")}),s&&t.jsx(om,{files:s})]})}if(n==="team"){const m=o?.members??[];return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(ii,{label:"Name",value:c}),t.jsx(ii,{label:"Description",value:e.description}),t.jsx("div",{className:"flex flex-wrap gap-2",children:t.jsx(Ji,{label:"Category",value:e.category,color:"indigo"})}),ys(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:ys(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))}),s&&t.jsx(om,{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((f,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 ${f.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:f.role==="manager"?"★":x+1}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:f.name}),typeof f.roleName=="string"&&f.roleName&&t.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:f.roleName}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(f.count??1)]})]}),ys(f.skills).length>0&&t.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:ys(f.skills).map(p=>t.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:p},p))})]},x))})]})]})}return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(ii,{label:"Name",value:c}),t.jsx(ii,{label:"Description",value:e.description}),t.jsx("div",{className:"flex gap-2",children:t.jsx(Ji,{label:"Category",value:e.category,color:"indigo"})}),s&&t.jsx(om,{files:s}),ys(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:ys(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))})]})}const yo={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},h1={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"}},m1=["file","directory"],vs={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 x1(){const e=Cr(),n=au({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[s,i]=v.useState(!1),o=v.useRef(s);o.current=s,v.useEffect(()=>{if(!e)return;const be=()=>{o.current&&i(!1)};return window.addEventListener("popstate",be),()=>window.removeEventListener("popstate",be)},[e]);const d=100,[c,h]=v.useState([]),[m,f]=v.useState(0),[x,p]=v.useState(!1),[g,y]=v.useState([]),[w,N]=v.useState([]),[T,_]=v.useState(!0),[S,k]=v.useState(""),[C,M]=v.useState(""),[L,P]=v.useState(""),[G,W]=v.useState(""),[z,q]=v.useState(""),[Y,$]=v.useState(""),[R,I]=v.useState(""),[A,F]=v.useState("date"),[V,X]=v.useState(null),[O,U]=v.useState(null),[K,D]=v.useState(""),[E,H]=v.useState(!1),[Z,ee]=v.useState(!1),[ne,ae]=v.useState(new Set),he=v.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),Se=v.useCallback(be=>{F(be),ae(new Set)},[]),Ie=Js(he,A,Se),xe=v.useRef(null),[we,Me]=v.useState("file"),[Be,et]=v.useState(""),[lt,ft]=v.useState(""),[yt,re]=v.useState(""),[Te,rt]=v.useState(""),[wt,Lt]=v.useState(""),[je,De]=v.useState(null),[Ve,dt]=v.useState(null),[st,zt]=v.useState(!1),[fn,Mt]=v.useState(!1),[_t,$t]=v.useState(!1),[Tt,Bt]=v.useState(!1),Xt=v.useRef(null),hn=v.useRef(null),[ve,tt]=v.useState(""),Et=v.useRef(void 0),Pe=(be,Ge)=>{U({type:be,text:Ge}),setTimeout(()=>U(null),3e3)},vt=async be=>{try{return await navigator.clipboard.writeText(be),!0}catch{try{const Ge=document.createElement("textarea");Ge.value=be,Ge.style.cssText="position:fixed;left:-9999px;top:-9999px;opacity:0",document.body.appendChild(Ge),Ge.select();const St=document.execCommand("copy");return document.body.removeChild(Ge),St}catch{return!1}}},mn=async be=>{await vt(be)?(Bt(!0),setTimeout(()=>Bt(!1),1500)):Pe("error","Copy failed — try long-pressing to copy manually")},Rn=v.useMemo(()=>new Map(w.map(be=>[be.id,be])),[w]),kn=v.useMemo(()=>new Map(g.map(be=>[be.id,be])),[g]);v.useEffect(()=>{se.projects.list().then(be=>y(be.projects)).catch(()=>{}),se.agents.list().then(be=>N(be.agents??[])).catch(()=>{}),se.system.storage().then(be=>tt(be.dataDir+"/shared")).catch(()=>{})},[]),v.useEffect(()=>(Et.current=setTimeout(()=>M(S),300),()=>clearTimeout(Et.current)),[S]);const Jt=v.useMemo(()=>({q:C||void 0,projectId:G||void 0,agentId:z||void 0,type:L||void 0,status:Y||void 0,artifactType:R||void 0}),[C,G,z,L,Y,R]),sn=v.useCallback(async()=>{_(!0);try{const{results:be,total:Ge}=await se.deliverables.search({...Jt,offset:0,limit:d});h(be),f(Ge)}catch{h([]),f(0)}_(!1)},[Jt]),On=v.useCallback(async()=>{if(!(x||c.length>=m)){p(!0);try{const{results:be,total:Ge}=await se.deliverables.search({...Jt,offset:c.length,limit:d});h(St=>[...St,...be]),f(Ge)}catch{}p(!1)}},[Jt,c.length,m,x]);v.useEffect(()=>{sn()},[sn]),v.useEffect(()=>ln.on("deliverable:created",()=>sn()),[sn]);const Nt=v.useCallback(()=>{const be=xe.current;!be||T||x||c.length>=m||be.scrollHeight<=be.clientHeight+100&&On()},[T,x,c.length,m,On]);v.useEffect(()=>{const be=xe.current;if(!be)return;const Ge=()=>{be.scrollTop+be.clientHeight>=be.scrollHeight-100&&On()};return be.addEventListener("scroll",Ge,{passive:!0}),()=>be.removeEventListener("scroll",Ge)},[On]),v.useEffect(()=>{Nt()},[Nt,ne]);const en=v.useMemo(()=>{const be=new Map;for(const St of c){let Ct,pn;if(A==="project")Ct=St.projectId??"_none",pn=St.projectId?kn.get(St.projectId)?.name??St.projectId:"No Project";else if(A==="agent")Ct=St.agentId??"_none",pn=St.agentId?Rn.get(St.agentId)?.name??St.agentId:"Unknown";else if(A==="type")Ct=St.type,pn=St.type.charAt(0).toUpperCase()+St.type.slice(1);else{const Zn=new Date(St.updatedAt);Ct=`${Zn.getFullYear()}-${String(Zn.getMonth()+1).padStart(2,"0")}-${String(Zn.getDate()).padStart(2,"0")}`,pn=Ct}be.has(Ct)||be.set(Ct,{label:pn,items:[]}),be.get(Ct).items.push(St)}const Ge=[...be.entries()];return A==="date"?Ge.sort((St,Ct)=>Ct[0].localeCompare(St[0])):Ge.sort((St,Ct)=>St[1].label.localeCompare(Ct[1].label)),Ge},[c,A,kn,Rn]),Bn=async()=>{if(!(!Be.trim()||!lt.trim())){ee(!0);try{await se.deliverables.create({type:we,title:Be,summary:lt,reference:yt,projectId:Te||void 0,tags:wt.split(",").map(be=>be.trim()).filter(Boolean)}),H(!1),Pe("success","Deliverable created"),sn()}catch(be){Pe("error",`Error: ${be}`)}ee(!1)}},le=async be=>{D("verify");try{await se.deliverables.verify(be.id),Pe("success","Verified"),X({...be,status:"verified"}),sn()}catch(Ge){Pe("error",`Error: ${Ge}`)}D("")},ze=async be=>{D("flag");try{await se.deliverables.update(be.id,{status:"outdated"}),Pe("success","Flagged as outdated"),X({...be,status:"outdated"}),sn()}catch(Ge){Pe("error",`Error: ${Ge}`)}D("")},Fe=async be=>{D("remove");try{await se.deliverables.remove(be.id),Pe("success","Removed"),X(null),sn()}catch(Ge){Pe("error",`Error: ${Ge}`)}D("")},Qe=()=>{xt.navigate(me.BUILDER)},Xe=async be=>{if(be.reference){if(be.type==="directory"){Mt(!0);return}zt(!0);try{const Ge=await se.files.preview(be.reference);Ge.type==="image"&&Ge.mimeType?dt({src:`data:${Ge.mimeType};base64,${Ge.content}`,name:Ge.name}):De(Ge.content)}catch{De(null),be.type==="file"&&Mt(!0)}zt(!1)}};v.useEffect(()=>{De(null),dt(null),Mt(!1),$t(!1),V&&Xe(V)},[V?.id]),v.useEffect(()=>{if(!_t)return;const be=Ge=>{hn.current&&!hn.current.contains(Ge.target)&&$t(!1)};return document.addEventListener("mousedown",be),()=>document.removeEventListener("mousedown",be)},[_t]);const Ye=async(be,Ge)=>{const St=Xt.current?.firstElementChild;if(!St)return;const Ct=lz(St,be);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([Ct],{type:"text/html"}),"text/plain":new Blob([Ge],{type:"text/plain"})})]),Pe("success",be==="light"?"HTML (light) copied":"HTML (dark) copied")}catch{const pn=await vt(Ge);Pe(pn?"success":"error",pn?"Text copied (HTML not supported)":"Copy failed")}$t(!1)},nt=be=>t.jsxs("div",{className:"relative group/preview",children:[t.jsxs("div",{className:"absolute -top-1 -right-1 z-10",ref:hn,children:[t.jsx("button",{onClick:()=>$t(Ge=>!Ge),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"})})}),_t&&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 Ge=await vt(be);Pe(Ge?"success":"error",Ge?"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:()=>Ye("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:()=>Ye("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:Xt,children:t.jsx(tr,{content:be,className:"text-fg-secondary text-sm"})})]}),pt=v.useCallback(be=>{ae(Ge=>{const St=new Set(Ge);return St.has(be)?St.delete(be):St.add(be),St})},[]),an=v.useCallback(()=>{ne.size===en.length?ae(new Set):ae(new Set(en.map(([be])=>be)))},[ne.size,en]),It=()=>{et(""),ft(""),re(""),Lt(""),Me("file"),g.length>0&&rt(g[0].id),H(!0)},xn=be=>{X(be),e&&(i(!0),history.pushState({mobileDetail:me.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:n.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:It,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:S,onChange:be=>k(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"}),ve&&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:ve}),t.jsx("button",{onClick:()=>{se.system.openPath(ve)},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(Da,{label:"All types",value:"",current:L||R||"",onClick:()=>{P(""),I("")}}),m1.map(be=>t.jsx(Da,{label:`${yo[be]?.icon??""} ${be}`,value:be,current:L,onClick:Ge=>{P(Ge),I("")}},be)),["agent","team","skill"].map(be=>t.jsx(Da,{label:`${vs[be].icon} ${vs[be].label}`,value:be,current:R,onClick:Ge=>{I(Ge),P("")}},be))]}),g.length>0&&t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(Da,{label:"All projects",value:"",current:G,onClick:W}),g.map(be=>t.jsx(Da,{label:be.name,value:be.id,current:G,onClick:W},be.id))]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(Da,{label:"Active",value:"",current:Y,onClick:$}),t.jsx(Da,{label:"Verified",value:"verified",current:Y,onClick:$}),t.jsx(Da,{label:"Outdated",value:"outdated",current:Y,onClick:$})]}),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:()=>{F(be),ae(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${A===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)),en.length>1&&t.jsx("button",{onClick:an,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:ne.size===en.length?"Expand all":"Collapse all",children:ne.size===en.length?"▶ Expand":"▼ Collapse"})]})]}),O&&t.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${O.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:O.text}),t.jsxs("div",{ref:xe,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:e?Ie.onTouchStart:void 0,onTouchEnd:e?Ie.onTouchEnd:void 0,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))}):c.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:It,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create first"})]}):en.map(([be,Ge])=>{const St=ne.has(be);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>pt(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 ${St?"":"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:Ge.label}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Ge.items.length,")"]})]}),!St&&Ge.items.map(Ct=>t.jsxs("button",{onClick:()=>xn(Ct),className:`w-full text-left p-3 rounded-lg transition-colors ${V?.id===Ct.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:Ct.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[Ct.artifactType&&vs[Ct.artifactType]?t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${vs[Ct.artifactType].color}`,children:[vs[Ct.artifactType].icon," ",vs[Ct.artifactType].label]}):t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium uppercase ${yo[Ct.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:Ct.type}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${h1[Ct.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:Ct.status}),Ct.agentId&&t.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:Rn.get(Ct.agentId)?.name??"Agent"})]})]},Ct.id))]},be)}),x&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[t.jsx(cm,{})," ",t.jsx("span",{className:"text-[10px]",children:"Loading more..."})]}),!T&&c.length>0&&t.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:c.length<m?`${c.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:n.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:V?.title??"Details"})]}),V?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:V.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[V.status!=="verified"&&t.jsx("button",{onClick:()=>le(V),disabled:!!K,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:K==="verify"?"Verifying...":"Verify"}),V.status!=="outdated"&&t.jsx("button",{onClick:()=>ze(V),disabled:!!K,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:K==="flag"?"Flagging...":"Flag Outdated"}),t.jsx("button",{onClick:()=>Fe(V),disabled:!!K,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:K==="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 ${yo[V.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[yo[V.type]?.icon??""," ",V.type]}),t.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${h1[V.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:V.status}),V.artifactType&&vs[V.artifactType]&&t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${vs[V.artifactType].color}`,children:[vs[V.artifactType].icon," Builder ",vs[V.artifactType].label]})]}),V.reference&&(V.type==="file"||V.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:()=>{se.files.reveal(V.reference).catch(()=>Pe("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:V.reference}),t.jsx("button",{onClick:()=>{se.files.reveal(V.reference).catch(()=>Pe("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:()=>mn(V.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Tt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:"Copy path to clipboard",children:Tt?"Copied!":"Copy"})]}),V.reference&&V.type!=="file"&&V.type!=="directory"&&t.jsx("div",{className:"mt-2",children:t.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:V.reference})})]}),V.artifactType&&V.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(iz,{artifact:V.artifactData,mode:V.artifactType})}),V.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:V.reference})]}),t.jsx("div",{className:"flex gap-2",children:t.jsx("button",{onClick:Qe,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"})}),V.summary&&t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:t.jsx(tr,{content:V.summary,className:"text-fg-secondary text-sm"})})]}):t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:st?t.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[t.jsx(cm,{})," Loading preview..."]}):Ve?t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("img",{src:Ve.src,alt:Ve.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:Ve.name})]}):je?nt(je):fn?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("p",{className:"text-sm text-fg-secondary",children:["This ",V.type," cannot be previewed in the browser."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>{se.files.reveal(V.reference).catch(()=>Pe("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:V.reference}),t.jsx("button",{onClick:()=>{se.files.reveal(V.reference).catch(()=>Pe("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:()=>mn(V.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Tt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:Tt?"Copied!":"Copy"})]})]}):V.summary?nt(V.summary):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No content"})}),(V.diffStats||V.testResults)&&t.jsxs("div",{className:"flex gap-4 flex-wrap",children:[V.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:[V.diffStats.filesChanged," files"]}),t.jsxs("span",{className:"text-green-600",children:["+",V.diffStats.additions]}),t.jsxs("span",{className:"text-red-500",children:["-",V.diffStats.deletions]})]})]}),V.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:[V.testResults.passed," passed"]}),t.jsxs("span",{className:"text-red-500",children:[V.testResults.failed," failed"]}),t.jsxs("span",{className:"text-fg-secondary",children:[V.testResults.skipped," skipped"]})]})]})]}),V.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5",children:V.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:[V.taskId&&t.jsxs("button",{onClick:()=>xt.navigate(me.WORK,{openTask:V.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2.5 py-1 rounded",children:["Task: ",V.taskId.slice(0,12),"..."]}),V.agentId&&t.jsxs("button",{onClick:()=>xt.navigate(me.TEAM,{selectAgent:V.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Agent: ",Rn.get(V.agentId)?.name??V.agentId.slice(0,12)]}),V.projectId&&t.jsxs("button",{onClick:()=>xt.navigate(me.WORK,{projectId:V.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Project: ",kn.get(V.projectId)?.name??V.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(V.createdAt).toLocaleString()})]}),t.jsxs("span",{children:["Updated: ",t.jsx("span",{className:"text-fg-secondary",children:new Date(V.updatedAt).toLocaleString()})]}),t.jsxs("span",{children:["Accessed: ",t.jsxs("span",{className:"text-fg-secondary",children:[V.accessCount,"x"]})]})]}),t.jsxs("div",{className:"text-fg-muted select-all",children:["ID: ",V.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"})]})})]}),E&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!Z&&H(!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:we,onChange:be=>Me(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:m1.map(be=>t.jsxs("option",{value:be,children:[yo[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:Be,onChange:be=>et(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:yt,onChange:be=>re(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:lt,onChange:be=>ft(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:wt,onChange:be=>Lt(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:Te,onChange:be=>rt(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"}),g.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:()=>H(!1),disabled:Z,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:"Cancel"}),t.jsxs("button",{onClick:Bn,disabled:Z||!Be.trim()||!lt.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:[Z&&t.jsx(cm,{}),Z?"Creating...":"Create"]})]})]})})]})}function lz(e,n){const s=e.cloneNode(!0),i=n==="light"?{bg:"#ffffff",text:"#24292f",heading:"#1f2328",strong:"#1f2328",link:"#0969da",codeBg:"#eff1f3",codeText:"#24292f",preBg:"#f6f8fa",preText:"#24292f",preBorder:"#d0d7de",border:"#d0d7de",blockquoteBorder:"#d0d7de",blockquoteText:"#656d76",tableBorder:"#d0d7de",tableHeaderBg:"#f6f8fa",tableHeaderText:"#24292f",hrColor:"#d8dee4"}:{bg:"#0d1117",text:"#e6edf3",heading:"#f0f6fc",strong:"#f0f6fc",link:"#58a6ff",codeBg:"#161b22",codeText:"#e6edf3",preBg:"#161b22",preText:"#e6edf3",preBorder:"#30363d",border:"#30363d",blockquoteBorder:"#3b82f6",blockquoteText:"#8b949e",tableBorder:"#30363d",tableHeaderBg:"#161b22",tableHeaderText:"#e6edf3",hrColor:"#21262d"},o={p:`margin:0 0 10px;color:${i.text};line-height:1.7;`,h1:`font-size:1.6em;font-weight:700;color:${i.heading};margin:20px 0 10px;line-height:1.3;border-bottom:1px solid ${i.border};padding-bottom:6px;`,h2:`font-size:1.35em;font-weight:700;color:${i.heading};margin:18px 0 8px;line-height:1.3;`,h3:`font-size:1.15em;font-weight:600;color:${i.heading};margin:14px 0 6px;line-height:1.3;`,h4:`font-size:1em;font-weight:600;color:${i.heading};margin:12px 0 4px;`,strong:`font-weight:600;color:${i.strong};`,em:"font-style:italic;",a:`color:${i.link};text-decoration:underline;`,ul:"padding-left:1.5em;margin:0 0 10px;",ol:"padding-left:1.5em;margin:0 0 10px;",li:`margin:3px 0;line-height:1.7;color:${i.text};`,blockquote:`border-left:3px solid ${i.blockquoteBorder};padding:2px 0 2px 14px;margin:10px 0;color:${i.blockquoteText};`,hr:`border:none;border-top:1px solid ${i.hrColor};margin:20px 0;`,table:"border-collapse:collapse;width:100%;margin:10px 0;",thead:`background:${i.tableHeaderBg};`,th:`border:1px solid ${i.tableBorder};padding:8px 12px;text-align:left;font-weight:600;color:${i.tableHeaderText};`,td:`border:1px solid ${i.tableBorder};padding:8px 12px;color:${i.text};`,img:"max-width:100%;height:auto;"};function d(c){c.removeAttribute("class");const h=c.tagName.toLowerCase();if(h==="pre"){c.setAttribute("style",`background:${i.preBg};color:${i.preText};padding:14px;border-radius:6px;overflow-x:auto;margin:10px 0;font-size:0.88em;line-height:1.5;border:1px solid ${i.preBorder};`);const m=c.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}h==="code"?c.setAttribute("style",`background:${i.codeBg};color:${i.codeText};padding:2px 6px;border-radius:4px;font-size:0.9em;font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;`):o[h]&&c.setAttribute("style",o[h]),Array.from(c.children).forEach(d)}return s.removeAttribute("class"),Array.from(s.children).forEach(c=>d(c)),`<div style="background:${i.bg};color:${i.text};padding:20px 24px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Noto Sans',Helvetica,Arial,sans-serif;font-size:15px;line-height:1.7;max-width:800px;">${s.innerHTML}</div>`}function Da({label:e,value:n,current:s,onClick:i}){return t.jsx("button",{onClick:()=>i(s===n?"":n),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${s===n?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function cm(){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 Ks(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function rl(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function oz(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 HN({authUser:e}){const[n,s]=v.useState("weekly"),[i,o]=v.useState(null),[d,c]=v.useState(!0),[h,m]=v.useState(""),[f,x]=v.useState(null),[p,g]=v.useState([]),[y,w]=v.useState("totalTokens"),[N,T]=v.useState(!0),[_,S]=v.useState("generate"),[k,C]=v.useState([]),[M,L]=v.useState(null),[P,G]=v.useState([]),[W,z]=v.useState(""),[q,Y]=v.useState(""),$=E=>{Y(E),setTimeout(()=>Y(""),3e3)},R=v.useCallback(async E=>{c(!0),m("");try{const{report:H}=await se.reports.generate({period:E,scope:"org",orgId:"default"});o(H)}catch(H){m(String(H)),o(null)}c(!1)},[]),I=v.useCallback(()=>{se.usage.summary().then(E=>x(E.usage)).catch(()=>{}),se.usage.agents().then(E=>g(E.agents)).catch(()=>{})},[]),A=v.useCallback(async()=>{try{const{reports:E}=await se.reports.list();C(E)}catch{}},[]),F=v.useCallback(async E=>{L(E);try{const{feedback:H}=await se.reports.getFeedback(E.id);G(H)}catch{G([])}},[]);v.useEffect(()=>{R(n)},[n,R]),v.useEffect(()=>{I();const E=setInterval(I,3e4);return()=>clearInterval(E)},[I]),v.useEffect(()=>{_==="history"&&A()},[_,A]);const V=v.useMemo(()=>[...p].sort((E,H)=>{const Z=E[y],ee=H[y];return N?ee-Z:Z-ee}),[p,y,N]),X=p.reduce((E,H)=>E+H.estimatedCost,0),O=p.reduce((E,H)=>E+H.tokensUsedToday,0),U=Math.max(1,...p.map(E=>E.totalTokens)),K=E=>{y===E?T(!N):(w(E),T(!0))},D={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 flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[t.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[t.jsx("h1",{className:"text-xl font-semibold text-fg-primary",children:"Reports"}),t.jsxs("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:[t.jsx("button",{onClick:()=>S("generate"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${_==="generate"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:"Generate"}),t.jsxs("button",{onClick:()=>S("history"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${_==="history"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:["History",k.length>0?` (${k.length})`:""]})]})]}),t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[q&&t.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:q}),_==="generate"&&t.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(E=>t.jsx("button",{onClick:()=>s(E),className:`px-3 py-1.5 text-xs rounded-md transition-colors capitalize ${n===E?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:E},E))})]})]}),_==="history"&&!M&&t.jsx("section",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden",children:k.length===0?t.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:"No reports generated yet. Use the Generate tab to create one."}):t.jsx("div",{className:"divide-y divide-border-default/50",children:k.map(E=>t.jsxs("button",{onClick:()=>F(E),className:"w-full text-left px-5 py-3 flex items-center gap-4 hover:bg-surface-elevated/30 transition-colors",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"text-sm font-medium text-fg-primary",children:[E.type," Report"]}),t.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(E.periodStart).toLocaleDateString()," — ",new Date(E.periodEnd).toLocaleDateString()]})]}),E.plan&&t.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${E.plan.status==="approved"?"bg-green-500/10 text-green-600":E.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:E.plan.status==="pending"?"Plan pending":`Plan ${E.plan.status}`}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(E.generatedAt).toLocaleDateString()})]},E.id))})}),_==="history"&&M&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:()=>{L(null),G([])},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"← Back to list"}),t.jsxs("span",{className:"text-sm font-medium text-fg-primary",children:[M.type," Report"]}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(M.periodStart).toLocaleDateString()," — ",new Date(M.periodEnd).toLocaleDateString()]})]}),M.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(js,{label:"Completed",value:M.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(js,{label:"In Progress",value:M.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(js,{label:"Created",value:M.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(js,{label:"Blocked",value:M.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(js,{label:"Failed",value:M.metrics.tasksFailed,color:"text-red-500"})]})]}),M.costSummary&&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-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:M.costSummary.totalTokens.toLocaleString()}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Total Tokens"})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:rl(M.costSummary.totalEstimatedCost)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Estimated Cost"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:`text-2xl font-bold ${M.costSummary.trend==="decreasing"?"text-green-600":M.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[M.costSummary.trend==="decreasing"?"↓":M.costSummary.trend==="increasing"?"↑":"→"," ",M.costSummary.trend]}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Trend"})]})]}),M.costSummary.byAgent&&M.costSummary.byAgent.length>0&&t.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:M.costSummary.byAgent.map((E,H)=>t.jsxs("div",{className:"flex items-center justify-between text-xs",children:[t.jsx("span",{className:"text-fg-secondary",children:E.agentId}),t.jsxs("span",{className:"text-fg-tertiary tabular-nums",children:[Ks(E.tokens)," tokens · ",rl(E.cost)]})]},H))})]}),M.taskSummary&&t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 overflow-hidden",children:[t.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Task Summary"}),t.jsxs("div",{className:"space-y-4 min-w-0",children:[M.taskSummary.completed.length>0&&t.jsx(el,{title:`Completed (${M.taskSummary.completed.length})`,color:"emerald",items:M.taskSummary.completed.map(E=>({id:E.id,label:E.title,sub:E.agent}))}),M.taskSummary.inProgress.length>0&&t.jsx(el,{title:`In Progress (${M.taskSummary.inProgress.length})`,color:"indigo",items:M.taskSummary.inProgress.map(E=>({id:E.id,label:E.title,sub:E.agent}))}),M.taskSummary.blocked.length>0&&t.jsx(el,{title:`Blocked (${M.taskSummary.blocked.length})`,color:"amber",items:M.taskSummary.blocked.map(E=>({id:E.id,label:E.title,sub:E.reason||E.agent}))}),M.taskSummary.completed.length===0&&M.taskSummary.inProgress.length===0&&M.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]}),M.highlights&&M.highlights.length>0&&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-2",children:"Highlights"}),t.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:M.highlights.map((E,H)=>t.jsx("li",{children:E},H))})]}),M.blockers&&M.blockers.length>0&&t.jsxs("section",{className:"bg-surface-secondary border border-amber-500/20 rounded-xl p-5",children:[t.jsx("h3",{className:"text-xs font-semibold text-amber-600 mb-2",children:"Blockers"}),t.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:M.blockers.map((E,H)=>t.jsx("li",{children:E},H))})]}),M.plan&&t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("h3",{className:"text-xs font-semibold text-fg-secondary",children:["Upcoming Plan",t.jsx("span",{className:`ml-2 px-1.5 py-0.5 rounded text-[10px] font-medium ${M.plan.status==="approved"?"bg-green-500/10 text-green-600":M.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:M.plan.status})]}),M.plan.status==="pending"&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{onClick:async()=>{try{const{report:E}=await se.reports.approvePlan(M.id,{approvedBy:e?.id??"admin"});L(E),$("Plan approved"),A()}catch(E){$(`Error: ${E}`)}},className:"px-3 py-1.5 text-xs font-medium bg-green-600 text-white rounded-lg hover:bg-green-500 transition-colors",children:"Approve Plan"}),t.jsx("button",{onClick:async()=>{const E=prompt("Rejection reason:");if(E)try{const{report:H}=await se.reports.rejectPlan(M.id,{rejectedBy:e?.id??"admin",reason:E});L(H),$("Plan rejected"),A()}catch(H){$(`Error: ${H}`)}},className:"px-3 py-1.5 text-xs font-medium border border-border-default text-fg-secondary rounded-lg hover:bg-surface-overlay transition-colors",children:"Reject Plan"})]})]}),M.plan.items&&M.plan.items.length>0&&t.jsx("div",{className:"space-y-1.5",children:M.plan.items.map((E,H)=>t.jsxs("div",{className:"flex items-center gap-2 text-sm text-fg-secondary",children:[t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${E.priority==="high"?"bg-red-500/10 text-red-500":E.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:E.priority}),t.jsx("span",{children:E.title}),E.assignee&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:E.assignee})]},H))})]}),!M.metrics&&!M.taskSummary&&!M.costSummary&&t.jsx("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-8 text-center",children:t.jsx("p",{className:"text-sm text-fg-tertiary",children:"This report does not contain detailed metrics data."})}),t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsxs("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:["Feedback (",P.length,")"]}),P.length>0&&t.jsx("div",{className:"space-y-2 mb-4",children:P.map(E=>t.jsxs("div",{className:"p-3 bg-surface-elevated/50 rounded-lg",children:[t.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary mb-1",children:[t.jsx("span",{className:"font-medium text-fg-secondary",children:E.authorName}),t.jsx("span",{children:E.type}),t.jsx("span",{children:new Date(E.createdAt).toLocaleDateString()})]}),t.jsx("p",{className:"text-xs text-fg-secondary",children:E.content})]},E.id))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:W,onChange:E=>z(E.target.value),placeholder:"Add feedback or instructions…",className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-tertiary",onKeyDown:E=>{E.key==="Enter"&&W.trim()&&se.reports.addFeedback(M.id,{author:e?.id??"admin",type:"comment",content:W.trim()}).then(({feedback:H})=>{G(Z=>[...Z,H]),z(""),$("Feedback added")}).catch(H=>$(`Error: ${H}`))}}),t.jsx("button",{onClick:()=>{W.trim()&&se.reports.addFeedback(M.id,{author:e?.id??"admin",type:"comment",content:W.trim()}).then(({feedback:E})=>{G(H=>[...H,E]),z(""),$("Feedback added")}).catch(E=>$(`Error: ${E}`))},disabled:!W.trim(),className:"px-3 py-2 text-xs bg-brand-600 text-white rounded-lg hover:bg-brand-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:"Send"})]})]})]}),_==="generate"&&f&&t.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t.jsx(kd,{label:"LLM Tokens (this month)",value:Ks(f.llmTokens),color:"text-brand-500"}),t.jsx(kd,{label:"Tool Calls (today)",value:Ks(f.toolCalls),color:"text-blue-600"}),t.jsx(kd,{label:"Messages (today)",value:Ks(f.messages),color:"text-green-600"}),t.jsx(kd,{label:"Storage",value:oz(f.storageBytes),color:"text-amber-600"})]}),_==="generate"&&(d?t.jsx("div",{className:"flex items-center justify-center h-32 text-fg-tertiary text-sm",children:"Loading…"}):h?t.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:h}):i?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"text-xs text-fg-tertiary",children:[D[n]," · ",new Date(i.periodStart).toLocaleDateString()," — ",new Date(i.periodEnd).toLocaleDateString()]}),i.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(js,{label:"Completed",value:i.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(js,{label:"In Progress",value:i.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(js,{label:"Created",value:i.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(js,{label:"Blocked",value:i.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(js,{label:"Failed",value:i.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:rl(X)}),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:Ks(O)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Tokens Today"})]}),i.costSummary&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:i.costSummary.totalTokens.toLocaleString()}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Tokens (",D[n],")"]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:rl(i.costSummary.totalEstimatedCost)}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Cost (",D[n],")"]})]})]})]})]}),i.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:[i.taskSummary.completed.length>0&&t.jsx(el,{title:`Completed (${i.taskSummary.completed.length})`,color:"emerald",items:i.taskSummary.completed.map(E=>({id:E.id,label:E.title,sub:E.agent}))}),i.taskSummary.inProgress.length>0&&t.jsx(el,{title:`In Progress (${i.taskSummary.inProgress.length})`,color:"indigo",items:i.taskSummary.inProgress.map(E=>({id:E.id,label:E.title,sub:E.agent}))}),i.taskSummary.blocked.length>0&&t.jsx(el,{title:`Blocked (${i.taskSummary.blocked.length})`,color:"amber",items:i.taskSummary.blocked.map(E=>({id:E.id,label:E.title,sub:E.reason||E.agent}))}),i.taskSummary.completed.length===0&&i.taskSummary.inProgress.length===0&&i.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]})]}):null),_==="generate"&&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"})}),p.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(vo,{label:"Total Tokens",col:"totalTokens",current:y,desc:N,onSort:K}),t.jsx(vo,{label:"Today",col:"tokensUsedToday",current:y,desc:N,onSort:K}),t.jsx(vo,{label:"Requests",col:"requestCount",current:y,desc:N,onSort:K}),t.jsx(vo,{label:"Tool Calls",col:"toolCalls",current:y,desc:N,onSort:K}),t.jsx(vo,{label:"Est. Cost",col:"estimatedCost",current:y,desc:N,onSort:K,align:"right"})]})}),t.jsx("tbody",{children:V.map(E=>t.jsx(cz,{agent:E,maxTokens:U},E.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 (",p.length," agents)"]}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Ks(p.reduce((E,H)=>E+H.totalTokens,0))}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Ks(O)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:p.reduce((E,H)=>E+H.requestCount,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:p.reduce((E,H)=>E+H.toolCalls,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:rl(X)})]})})]})})]})]})})}function js({label:e,value:n,color:s}){return t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:`text-2xl font-bold ${s}`,children:n}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function el({title:e,color:n,items:s}){return t.jsxs("div",{className:"min-w-0 overflow-hidden",children:[t.jsx("div",{className:`text-xs font-medium text-${n}-400 mb-1.5`,children:e}),t.jsx("div",{className:"space-y-1.5",children:s.map((i,o)=>t.jsxs("div",{className:`text-sm text-fg-secondary min-w-0 ${i.id?"cursor-pointer hover:text-fg-primary group":""}`,onClick:i.id?()=>xt.navigate(me.WORK,{openTask:i.id}):void 0,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${n}-500 shrink-0`}),t.jsx("span",{className:`truncate min-w-0 ${i.id?"group-hover:text-brand-500 transition-colors":""}`,children:i.label})]}),i.sub&&i.sub!=="unassigned"&&t.jsx("div",{className:"text-[10px] text-fg-tertiary ml-3.5 mt-0.5 break-all line-clamp-2",children:i.sub})]},i.id??o))})]})}function kd({label:e,value:n,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:n})]})}function vo({label:e,col:n,current:s,desc:i,onSort:o,align:d}){const c=s===n?i?"↓":"↑":"↕",h=s===n?"text-brand-500":"text-fg-muted";return t.jsxs("th",{className:`px-4 py-3 ${d==="right"?"text-right":"text-left"} font-medium cursor-pointer select-none hover:text-fg-secondary`,onClick:()=>o(n),children:[e,t.jsx("span",{className:`ml-1 ${h}`,children:c})]})}function cz({agent:e,maxTokens:n}){const s=n>0?Math.min(100,e.totalTokens/n*100):0,i=e.status==="working"?"bg-blue-500":e.status==="idle"?"bg-green-500":e.status==="paused"?"bg-amber-500":e.status==="error"?"bg-red-500":"bg-gray-600";return t.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>xt.navigate(me.TEAM,{selectAgent:e.agentId}),children:[t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:`w-2 h-2 rounded-full ${i}`}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:t.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${s}%`}})}),t.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:Ks(e.totalTokens)})]})}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:Ks(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:rl(e.estimatedCost)})]})}function jo({d:e,size:n=18}){return t.jsx("svg",{width:n,height:n,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 dz={active:"bg-green-500",paused:"bg-amber-500",completed:"bg-gray-500",archived:"bg-gray-600"},p1=5;function uz({currentPage:e,onNavigate:n,authUser:s,onLogout:i,collapsed:o,onToggleCollapse:d}){const[c,h]=v.useState([]),[m,f]=v.useState(!1),[x,p]=v.useState(null),[g,y]=v.useState(!1),w=v.useCallback(()=>{se.projects.list().then(S=>h(S.projects)).catch(()=>{})},[]);v.useEffect(()=>{w();const S=setInterval(w,3e4);return()=>clearInterval(S)},[w]),v.useEffect(()=>{if(e!==me.WORK){p(null);return}const k=window.location.hash.slice(1).split("/");Qs(k[0])===me.WORK&&k[1]&&p(k[1])},[e]);const N=async()=>{try{await se.auth.logout()}catch{}i?.()},T=m?c:c.slice(0,p1),_=c.length>p1;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.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("button",{onClick:d,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.jsx(mm,{collapsed:!0,userId:s?.id})]}):t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:d,className:"flex items-center gap-2.5 min-w-0 group",title:"Collapse sidebar",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg shadow-md shadow-black/30 shrink-0 group-hover:ring-2 group-hover:ring-brand-500/40 transition-all"}),t.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(mm,{userId:s?.id}),t.jsx("button",{onClick:d,className:"text-fg-tertiary hover:text-fg-secondary transition-colors p-1 rounded-md hover:bg-surface-overlay",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:nk.map((S,k)=>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:S.label}),o&&k>0&&t.jsx("div",{className:"my-2 mx-1"}),rk.filter(C=>C.section===S.key&&!(S.key==="workspace"&&C.id===me.DELIVERABLES)).map(C=>{const M=e===C.id;return t.jsxs("button",{onClick:()=>n(C.id),title:o?C.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 ${M?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":"text-fg-primary hover:bg-surface-overlay"}`,children:[t.jsx(jo,{d:tl[C.id]??""}),!o&&C.label]},C.id)}),S.key==="workspace"&&o&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{p(null),n(me.WORK)},title:"Work",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-all ${e===me.WORK&&!x?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":e===me.WORK?"bg-brand-600/15 text-fg-primary":"text-fg-primary hover:bg-surface-overlay"}`,children:t.jsx(jo,{d:tl[me.WORK]})}),t.jsx("button",{onClick:()=>n(me.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===me.DELIVERABLES?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:t.jsx(jo,{d:tl[me.DELIVERABLES]})})]}),S.key==="workspace"&&!o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center mb-0.5",children:[t.jsxs("button",{onClick:()=>{p(null),n(me.WORK)},className:`flex-1 flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-colors ${e===me.WORK&&!x?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(jo,{d:tl[me.WORK]}),"Work"]}),t.jsx("button",{onClick:()=>y(!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"})]})})]}),c.length===0&&t.jsxs("button",{onClick:()=>y(!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(C=>{const M=e===me.WORK&&x===C.id;return t.jsxs("button",{onClick:()=>{p(C.id),e!==me.WORK&&n(me.WORK),window.location.hash=um(me.WORK,C.id).slice(1)},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 ${M?"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 ${dz[C.status]??"bg-gray-600"}`}),t.jsx("span",{className:"truncate text-xs",children:C.name})]},C.id)}),_&&!m&&t.jsxs("button",{onClick:()=>f(!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 ",c.length," projects..."]}),t.jsxs("button",{onClick:()=>n(me.DELIVERABLES),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e===me.DELIVERABLES?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(jo,{d:tl[me.DELIVERABLES]}),"Deliverables"]})]})]})},S.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:N,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:N,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.4.17"]})]}),g&&t.jsx(LN,{orgId:s?.orgId,onCreated:()=>{y(!1),w()},onClose:()=>y(!1)})]})}function fz({currentPage:e,onNavigate:n}){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:sk.map(s=>{const i=s.group.includes(e);return t.jsxs("button",{onClick:()=>n(s.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${i?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[t.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:i?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:tl[s.id]})}),t.jsx("span",{className:`text-[10px] leading-tight ${i?"font-semibold":""}`,children:s.label})]},s.id)})})}const g1=[{id:"builder",label:"Builder"},{id:"agents",label:"Agents"},{id:"teams",label:"Teams"},{id:"skills",label:"Skills"}];function hz({authUser:e}){const[n,s]=v.useState("builder"),i=Js(g1,n,s);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:i.onTouchStart,onTouchEnd:i.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:g1.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 ${n===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:[n==="builder"&&t.jsx(Gj,{}),n==="agents"&&t.jsx(Rm,{authUser:e}),n==="teams"&&t.jsx(Om,{}),n==="skills"&&t.jsx(Dm,{})]})]})}const b1=[{id:"settings",label:"Settings"},{id:"reports",label:"Reports"}];function mz({theme:e,onThemeChange:n}){const[s,i]=v.useState("settings"),o=Js(b1,s,i);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:o.onTouchStart,onTouchEnd:o.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:b1.map(d=>t.jsx("button",{onClick:()=>i(d.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===d.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:d.label},d.id))}),t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="settings"&&t.jsx(Uj,{theme:e,onThemeChange:n}),s==="reports"&&t.jsx(HN,{})]})]})}const y1=2;function xz({onComplete:e,theme:n,onThemeChange:s}){const[i,o]=v.useState(0),[d,c]=v.useState(null),[h,m]=v.useState(!1),[f,x]=v.useState({}),[p,g]=v.useState(!1),[y,w]=v.useState(null),[N,T]=v.useState(!1),[_,S]=v.useState(!1),[k,C]=v.useState(null),M=v.useRef(!1),L=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});v.useEffect(()=>{fetch("/api/settings/llm").then(I=>I.ok?I.json():null).then(I=>{I?.providers&&Object.values(I.providers).some(A=>A.configured)&&S(!0)}).catch(()=>{})},[]),v.useEffect(()=>{i===y1&&!M.current&&!_&&(M.current=!0,P())},[i,_]);const P=async()=>{m(!0);try{const I=await fetch("/api/settings/env-models",{headers:L()});if(I.ok){const A=await I.json();if(c(A),A.detected.length>0){const F={};for(const V of A.detected)F[V.provider]=!0;x(F)}}}catch{}finally{m(!1)}},G=async()=>{if(!d)return;const I=d.detected.filter(A=>f[A.provider]);if(I.length!==0){g(!0),C(null);try{const A=await fetch("/api/settings/env-models",{method:"POST",headers:L(),body:JSON.stringify({providers:I.map(F=>({provider:F.provider,model:F.model,baseUrl:F.baseUrl,enabled:!0}))})});if(A.ok){const F=await A.json();C({type:"ok",text:F.message}),S(!0)}else C({type:"err",text:"Failed to apply"})}catch{C({type:"err",text:"Network error"})}finally{g(!1)}}},W=async()=>{T(!0);try{const A=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:L(),body:JSON.stringify({preview:!0})})).json();"error"in A||w(A)}catch{}finally{T(!1)}},z=async()=>{T(!0),C(null);try{const A=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:L(),body:JSON.stringify({preview:!1})})).json();"error"in A?C({type:"err",text:A.error}):(C({type:"ok",text:`Imported ${A.appliedModels} model configs`}),S(!0))}catch{C({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"},{value:"cyberpunk",label:"Cyberpunk",icon:"🔮",desc:"Neon pink, dark violet"},{value:"midnight",label:"Midnight",icon:"🌊",desc:"Deep ocean, teal accents"}],Y=[{title:"Welcome to Markus",subtitle:"Your AI workforce, ready in minutes",content:t.jsxs("div",{className:"space-y-4 text-fg-secondary text-sm leading-relaxed",children:[t.jsxs("p",{children:["Markus runs ",t.jsx("strong",{className:"text-fg-primary",children:"complete AI teams"})," — developers, researchers, writers, analysts that work autonomously, collaborate with each other, and deliver results around the clock."]}),t.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[["24/7 Operation","Agents work while you sleep via heartbeat"],["Team Collaboration","Agents delegate, review, and coordinate"],["Persistent Memory","Five memory layers survive restarts"],["Any LLM Provider","Anthropic, OpenAI, Google, Ollama & more"]].map(([I,A])=>t.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[t.jsx("div",{className:"font-medium text-fg-primary text-xs",children:I}),t.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:A})]},I))})]})},{title:"Choose Your Theme",subtitle:"You can change this anytime in Settings",content:t.jsx("div",{className:"grid grid-cols-3 gap-3",children:q.map(I=>t.jsxs("button",{onClick:()=>s(I.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${n===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:_?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"}),h&&t.jsx("div",{className:"text-xs text-fg-tertiary animate-pulse",children:"Detecting API keys..."}),d&&d.detected.length>0&&t.jsxs("div",{className:"space-y-2",children:[d.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:f[I.provider]??!1,onChange:A=>x({...f,[I.provider]:A.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-sm text-fg-primary",children:I.displayName}),t.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:I.model})]}),t.jsx("code",{className:"text-[10px] text-fg-tertiary",children:I.apiKeyPreview})]},I.provider)),t.jsx("button",{onClick:()=>{G()},disabled:p||Object.values(f).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:p?"Applying...":`Apply ${Object.values(f).filter(Boolean).length} Provider(s)`})]}),d&&d.detected.length===0&&!h&&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"}),y?y.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:y.summary.configPath}),y.summary.models&&t.jsxs("span",{className:"text-fg-tertiary ml-1",children:["(",y.summary.models.providerCount," providers)"]})]}),t.jsx("button",{onClick:()=>{z()},disabled:N,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:N?"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:()=>{W()},disabled:N,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:N?"Detecting...":"Detect OpenClaw Config"})]}),k&&t.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${k.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:k.text})]})},{title:"You're All Set",subtitle:"Start building your AI workforce",content:t.jsx("div",{className:"space-y-2 text-fg-secondary text-sm",children:[["Chat","Talk to agents or use Smart Route to auto-delegate tasks"],["Projects","Create projects with requirements, tasks, and deliverables"],["Builder","Hire new agents from templates or build custom roles"],["Settings","Manage LLM providers, integrations, and governance"]].map(([I,A])=>t.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[t.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),t.jsxs("div",{children:[t.jsx("div",{className:"font-medium text-fg-primary text-xs",children:I}),t.jsx("div",{className:"text-fg-secondary text-xs",children:A})]})]},I))})}],$=()=>{i<Y.length-1?o(i+1):e()},R=Y[i];return t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:t.jsx("div",{className:"w-full max-w-lg",children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl p-8",children:[t.jsx("div",{className:"flex gap-1.5 mb-8",children:Y.map((I,A)=>t.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${A<=i?"bg-brand-500":"bg-surface-elevated"}`},A))}),t.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:R.title}),t.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:R.subtitle}),R.content,t.jsxs("div",{className:"flex justify-between mt-8",children:[i>0?t.jsx("button",{onClick:()=>o(i-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:"Back"}):t.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip"}),t.jsxs("div",{className:"flex items-center gap-3",children:[i===y1&&!_&&t.jsx("button",{onClick:$,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip for now"}),t.jsx("button",{onClick:$,className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-xl transition-colors",children:i===Y.length-1?"Get Started":"Next"})]})]})]})})})}const pz="markus123";function gz({onLogin:e}){const[n,s]=v.useState("admin@markus.local"),[i,o]=v.useState(""),[d,c]=v.useState(""),[h,m]=v.useState(!1),f=async x=>{if(x.preventDefault(),!(!n.trim()||!i)){c(""),m(!0);try{const{user:p}=await se.auth.login(n.trim(),i);e(p,i===pz)}catch{c("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:f,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:n,onChange:x=>s(x.target.value),autoComplete:"email",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Password"}),t.jsx("input",{type:"password",value:i,onChange:x=>o(x.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),d&&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:d}),t.jsx("button",{type:"submit",disabled:h||!n||!i,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all shadow-md shadow-brand-900/40 hover:shadow-lg hover:shadow-brand-900/50",children:h?"Signing in…":"Sign in"}),t.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:"Default: admin@markus.local / markus123"})]})]})]})}function bz({onComplete:e,isFirstTime:n}){const[s,i]=v.useState(""),[o,d]=v.useState(""),[c,h]=v.useState(""),[m,f]=v.useState(""),[x,p]=v.useState(!1),g=async y=>{if(y.preventDefault(),f(""),o.length<6){f("Password must be at least 6 characters");return}if(o!==c){f("Passwords do not match");return}p(!0);try{await se.auth.changePassword(s,o),e()}catch{f("Failed to change password. Check your current password.")}finally{p(!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:g,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:n?"Set Your Password":"Change Password"}),n&&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."})]}),!n&&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:y=>i(y.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:y=>d(y.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:c,onChange:y=>h(y.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||!c,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…":n?"Set Password & Continue":"Change Password"})]})]})]})}const dm={};function yz(){const[e,n]=v.useState(ld),[s,i]=v.useState(()=>!localStorage.getItem("markus_onboarded")),[o,d]=v.useState(!0),c=Cr(),h=D_(),m=au({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[f,x]=v.useState(()=>new Set([ld()])),[p,g]=v.useState("loading"),[y,w]=v.useState(!1),[N,T]=v.useState(null),[_,S]=v.useState(!1),k=v.useCallback(P=>{let G=Qs(P);c&&(G=tk[G]??G);const W=ld(),z=window.location.hash.slice(1);z!==W?dm[W]=z:delete dm[W];const q=G!==me.WORK?dm[G]:void 0;q&&q!==G?(history.pushState(null,"","#"+G),history.pushState(null,"","#"+q)):history.pushState(null,"","#"+G),window.dispatchEvent(new HashChangeEvent("hashchange")),n(G),x(Y=>Y.has(G)?Y:new Set([...Y,G]))},[c]);v.useEffect(()=>{xt.setHandler(P=>k(P))},[k]);const C=v.useCallback(()=>{fetch("/api/settings/llm").then(P=>P.ok?P.json():null).then(P=>{if(P?.providers){const G=Object.values(P.providers).some(W=>W.configured);T(G)}}).catch(()=>{})},[]);v.useEffect(()=>{se.auth.me().then(({user:W})=>{g(W),C(),ai(kr.builderArtifacts,()=>se.builder.artifacts.list()),ai(kr.builderAgents,()=>se.agents.list()),ai(kr.builderHubMyItems,()=>Yn.myItems()),ai(kr.builderInstalled,()=>se.builder.artifacts.installed()),ai(kr.hubAgents,()=>Yn.search({type:"agent",limit:50})),ai(kr.hubTeams,()=>Yn.search({type:"team",limit:50})),ai(kr.hubSkills,()=>Yn.search({type:"skill",limit:50}))}).catch(()=>g(null)),ln.connect();const P=ln.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),G=()=>{const W=ld();n(W),x(z=>z.has(W)?z:new Set([...z,W]))};return window.addEventListener("hashchange",G),()=>{P(),ln.disconnect(),window.removeEventListener("hashchange",G)}},[]);const M=p!=="loading"&&p!==null?p:void 0,L=v.useMemo(()=>c?{[me.HOME]:t.jsx(Tb,{authUser:M}),[me.TEAM]:t.jsx(By,{authUser:M}),[me.BUILDER]:t.jsx(hz,{authUser:M}),[me.SETTINGS]:t.jsx(mz,{theme:h.mode,onThemeChange:h.setMode}),[me.WORK]:t.jsx(f1,{authUser:M}),[me.DELIVERABLES]:t.jsx(x1,{})}:{[me.HOME]:t.jsx(Tb,{}),[me.TEAM]:t.jsx(By,{authUser:M}),[me.SETTINGS]:t.jsx(Uj,{theme:h.mode,onThemeChange:h.setMode}),[me.STORE]:t.jsx(Y_,{authUser:M}),[me.BUILDER]:t.jsx(Gj,{}),[me.WORK]:t.jsx(f1,{authUser:M}),[me.DELIVERABLES]:t.jsx(x1,{}),[me.REPORTS]:t.jsx(HN,{authUser:M})},[M?.id,h.mode,c]);return p==="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…"})}):p===null?t.jsx(gz,{onLogin:(P,G)=>{g(P),G&&w(!0)}}):y?t.jsx(bz,{onComplete:()=>w(!1),isFirstTime:!0}):s?t.jsx(xz,{theme:h.mode,onThemeChange:h.setMode,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),i(!1),C()}}):t.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${c?"flex-col":""}`,children:[!c&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:t.jsx(uz,{currentPage:e,onNavigate:P=>{k(P),d(!1)},authUser:p,onLogout:()=>g(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 ${c?"pb-14":""}`,children:[N===!1&&!_&&e!==me.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:c?"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:()=>{k(me.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:()=>S(!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(L).map(P=>f.has(P)?t.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:P===e?"flex":"none"},children:L[P]},P):null)})]}),c&&t.jsx(fz,{currentPage:e,onNavigate:k})]})}Z2.createRoot(document.getElementById("root")).render(t.jsx(v.StrictMode,{children:t.jsx(yz,{})}));
63
+ ${bt?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),t.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:"REQ"}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${ht.cls}`,children:ht.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Ee.title}),Ee.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Ee.description}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[Kt&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:Kt.name,children:Kt.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Ee.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",mt]})]}),t.jsx("div",{className:"flex items-center gap-1",children:Ee.taskIds.length>0&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",Ee.taskIds.length]})})]}),Ut&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:Ze=>{Ze.stopPropagation(),xr(Ee.id)},className:"flex-1 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:Ze=>{Ze.stopPropagation(),Nt(Ee.id)},className:"flex-1 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-${Ee.id}`)}else{const Ee=qe.data,ht=Ee.subtasks?.length??0,Pt=zN[Ee.status],Ut=Ee.status==="pending",Kt=Ee.taskType==="scheduled"&&!!Ee.scheduleConfig,mt=Kt?Ee.scheduleConfig.every?`Every ${Ee.scheduleConfig.every}`:Ee.scheduleConfig.cron?"Cron":"Scheduled":null,bt=m==="all"&&Ee.projectId?c.find(We=>We.id===Ee.projectId)?.name:null,Ze=Ee.requirementId?S.find(We=>We.id===Ee.requirementId)?.title:null,Je=Ee.createdBy?yl(Ee.createdBy,w,T)??Ee.createdBy:null,at=Me?.id===Ee.id,ot={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"};return t.jsxs("div",{role:"button",tabIndex:0,"aria-label":Ee.title,draggable:!Ut,onDragStart:We=>!Ut&&Ur(We,Ee),onDragEnd:Hn,onClick:()=>an(Ee),onKeyDown:We=>We.key==="Enter"&&an(Ee),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Ut?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Kt?"bg-blue-500/[0.04] border-blue-500/20 hover:border-blue-400/40 cursor-pointer":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40 cursor-grab active:cursor-grabbing"} ${at?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${ot[Ee.priority]??"bg-gray-400"}`,title:Ee.priority}),Kt&&t.jsx("span",{className:"text-blue-500 shrink-0",title:mt??"Scheduled",children:t.jsx("svg",{className:"w-3 h-3",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"})})}),Kt&&mt&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:mt}),Pt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Pt.cls}`,children:Pt.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Ee.title}),Ee.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Ee.description}),(bt||Ze||Ee.blockedBy&&Ee.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[bt&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded-md truncate max-w-[100px]",title:bt,children:bt}),Ze&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-brand-500/8 text-brand-500 rounded-md truncate max-w-[110px]",title:Ze,children:["# ",Ze]}),Ee.blockedBy&&Ee.blockedBy.length>0&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",Ee.blockedBy.length," dep",Ee.blockedBy.length>1?"s":""]})]}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:Je&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Je}`,children:["by ",Je]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[ht>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",ht]}),Ee.notes&&Ee.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",Ee.notes.length]}),Ee.assignedAgentId&&t.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Zm[w.find(We=>We.id===Ee.assignedAgentId)?.status??""]??"bg-gray-500"}`}),w.find(We=>We.id===Ee.assignedAgentId)?.name??Ee.assignedAgentId.slice(0,8)]})]})]})]},Ee.id)}})})()}),$e&&t.jsx("div",{className:"mx-2 mb-2 border-2 border-dashed border-brand-500/25 rounded-lg h-10 flex items-center justify-center shrink-0",children:t.jsx("span",{className:"text-[11px] text-brand-500/50",children:"Drop here"})})]},Q.id)})})})]}),!n&&Ce&&t.jsx("div",{className:"w-1 shrink-0 cursor-col-resize bg-border-default/40 hover:bg-brand-500/30 active:bg-brand-500/50 transition-colors",onMouseDown:s.onResizeStart}),(!n||i)&&Ce&&t.jsx("div",{className:`${n?"flex-1":"shrink-0"} overflow-hidden min-w-0 border-l border-border-default`,style:n?void 0:{width:s.width},children:Me?t.jsx(WI,{task:Me,agents:w,projects:c,requirements:S,allTasks:Object.values(g).flat(),users:T,onClose:xn,onRefresh:Ue,authUser:e}):et?t.jsx(sz,{req:et,agents:w,projects:c,allTasks:Object.values(g).flat(),users:T,onClose:xn,onApprove:Q=>{xr(Q),xn()},onReject:Q=>{Nt(Q),xn()},onCancel:Q=>{Pr(Q),xn()},onStatusChange:async(Q,oe)=>{try{await se.requirements.updateStatus(Q,oe),le(`Requirement status → ${oe}`),nt(),Qe()}catch(ke){le(`Error: ${ke}`)}},onRefresh:nt,authUser:e}):null}),q&&t.jsx(LN,{orgId:e?.orgId,onCreated:ns,onClose:()=>Y(!1)}),$&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>R(!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 ${n?"w-full":"w-[28rem]"}`,onClick:Q=>Q.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:H,onChange:Q=>Z(Q.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"}),c.map(Q=>t.jsx("option",{value:Q.id,children:Q.name},Q.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Requirement"}),t.jsxs("select",{value:ee,onChange:Q=>ne(Q.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…"}),S.filter(Q=>Q.status==="in_progress"&&(!H||Q.projectId===H)).map(Q=>t.jsx("option",{value:Q.id,children:Q.title},Q.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{autoFocus:!n,value:I,onChange:Q=>A(Q.target.value),onKeyDown:Q=>{Q.key==="Enter"&&Ae()},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:F,onChange:Q=>V(Q.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:X,onChange:Q=>O(Q.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:U,onChange:Q=>K(Q.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…"}),w.map(Q=>t.jsx("option",{value:Q.id,children:Q.name},Q.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:D,onChange:Q=>E(Q.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…"}),w.filter(Q=>Q.id!==U).map(Q=>t.jsx("option",{value:Q.id,children:Q.name},Q.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:Se,onChange:Q=>Ie(Q.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)"})]})]}),Se==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Frequency"}),t.jsxs("select",{value:xe,onChange:Q=>we(Q.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:Q=>{const oe=Q.target.value;oe&&!ae.includes(oe)&&he([...ae,oe])},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:"Select a task to depend on…"}),Object.values(g).flat().filter(Q=>Q.status!=="completed"&&Q.status!=="cancelled"&&!ae.includes(Q.id)).map(Q=>t.jsx("option",{value:Q.id,children:Q.title},Q.id))]}),ae.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ae.map(Q=>{const oe=Object.values(g).flat().find(ke=>ke.id===Q);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:["⏳ ",oe?oe.title.slice(0,30):Q.slice(-8),t.jsx("button",{onClick:()=>he(ae.filter(ke=>ke!==Q)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},Q)})})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>R(!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:()=>{Ae()},disabled:!U||!D,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Create"})]})]})}),ve&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{tt(!1),Pe(""),mn("")},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 ${n?"w-full":"w-[28rem]"}`,onClick:Q=>Q.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:Jt,onChange:Q=>sn(Q.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…"}),c.map(Q=>t.jsx("option",{value:Q.id,children:Q.name},Q.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{value:Et,onChange:Q=>Pe(Q.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:!n,onKeyDown:Q=>{Q.key==="Enter"&&Et.trim()&&Ht()}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:vt,onChange:Q=>mn(Q.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:Rn,onChange:Q=>kn(Q.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:()=>{tt(!1),Pe(""),mn("")},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:()=>{Ht()},disabled:!Et.trim()||!vt.trim()||!Jt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40 disabled:cursor-not-allowed",children:"Create"})]})]})}),On&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>Nt(null),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${n?"w-full":"w-96"}`,onClick:Q=>Q.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:en,onChange:Q=>Bn(Q.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:!n})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>Nt(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:()=>{Tr()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:"Reject"})]})]})}),Tt&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Bt(!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:Q=>Q.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:[(re.size>0||ft.size>0)&&t.jsx("button",{onClick:()=>{Te(new Set),yt(new Set)},className:"text-[11px] text-brand-500 font-medium",children:"Clear all"}),t.jsx("button",{onClick:()=>Bt(!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"})]})})]})]}),c.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:Pa.map(Q=>{const oe=re.has(Q.id),ke=Ms[Q.id]??0;return t.jsxs("button",{onClick:()=>qr(Q.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${oe?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:Q.name[0]?.toUpperCase()}),Q.name,ke>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:ke})]},Q.id)})})]}),w.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:aa.map(Q=>{const oe=ft.has(Q.id);return t.jsxs("button",{onClick:()=>_s(Q.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${oe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${oe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:Q.name[0]?.toUpperCase()}),Q.name]},Q.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function rz({requirementId:e,agents:n,authUser:s}){const[i,o]=v.useState([]);v.useEffect(()=>{se.requirements.getComments(e).then(f=>o(f.comments)).catch(()=>{})},[e]),v.useEffect(()=>ln.on("requirement:comment",x=>{x.payload?.requirementId===e&&x.payload.comment&&o(p=>p.some(g=>g.id===x.payload.comment.id)?p:[...p,x.payload.comment])}),[e]);const[d,c]=v.useState(null),h=async(f,x,p)=>{await se.requirements.addComment(e,f,s?.name,s?.id,x.length>0?x:void 0,p)},m=v.useCallback(f=>{c({id:f.id,authorName:f.authorName,content:f.content.slice(0,100)})},[]);return t.jsxs("div",{children:[t.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:["Comments ",i.length>0&&t.jsxs("span",{className:"font-normal",children:["(",i.length,")"]})]}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[i.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:"No comments yet."}),i.map(f=>t.jsx(Mo,{comment:f,agents:n,onReply:m},f.id))]}),t.jsx(zj,{agents:n,onSubmit:h,replyTo:d,onCancelReply:()=>c(null)})]})}function sz({req:e,agents:n,projects:s,allTasks:i,users:o,onClose:d,onApprove:c,onReject:h,onCancel:m,onStatusChange:f,onRefresh:x,authUser:p}){const g=Cr(),[y,w]=v.useState(!1),[N,T]=v.useState(e.description),[_,S]=v.useState(!1),k=di[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},C=e.source==="agent",M=C&&e.status==="pending",L=e.status==="pending"||e.status==="in_progress",P=e.status==="completed"||e.status==="rejected"||e.status==="cancelled",G=e.projectId?s.find(q=>q.id===e.projectId):null,W=yl(e.createdBy,n,o)??e.createdBy.slice(0,12),z=i.filter(q=>e.taskIds.includes(q.id));return v.useEffect(()=>{T(e.description),w(!1)},[e.id,e.description]),t.jsxs("div",{className:"flex flex-col h-full overflow-hidden bg-surface-secondary",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[g&&t.jsx("button",{onClick:d,className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",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.jsxs("div",{className:"flex-1 min-w-0 pb-4",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 ${k.cls}`,children:k.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})]})]}),!g&&t.jsx("button",{onClick:d,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:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:"Description"}),y?t.jsxs("div",{className:"space-y-2",children:[t.jsx("textarea",{value:N,onChange:q=>T(q.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,autoFocus:!0}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx("button",{onClick:()=>{w(!1),T(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:async()=>{S(!0);try{await se.requirements.update(e.id,{description:N}),w(!1),x?.()}catch{}finally{S(!1)}},disabled:_,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.jsx(tr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No description"}),!P&&t.jsx("button",{onClick:()=>{T(e.description),w(!0)},className:"absolute top-0 right-0 text-[10px] text-fg-tertiary hover:text-brand-500 opacity-0 group-hover:opacity-100 transition-opacity",children:"Edit"})]})]}),t.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:W}),C&&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()})]}),G&&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:G.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:yl(e.approvedBy,n,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})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(q=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",q]},q))}),z.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 (",z.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:z.map(q=>{const Y=zN[q.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 ${FI[q.priority]?.replace("border-l-","bg-")??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:q.title}),Y&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Y.cls}`,children:Y.label})]},q.id)})})]}),t.jsx(rz,{requirementId:e.id,agents:n,authUser:p})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[M&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>c(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:()=>h(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"})]}),!M&&f&&!P&&t.jsx("select",{value:e.status,onChange:q=>{q.target.value!==e.status&&f(e.id,q.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:ez.map(q=>{const Y=di[q],$=q===e.status||(Qm[e.status]?.has(q)??!1);return t.jsx("option",{value:q,disabled:!$,children:Y?.label??q},q)})}),P&&f&&t.jsx("button",{onClick:()=>f(e.id,"in_progress"),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"}),L&&!M&&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 ys(e){return Array.isArray(e)?e.map(n=>String(n).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(n=>n.trim()).filter(Boolean):[]}function az(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function ii({label:e,value:n}){return n?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:n})]}):null}function Ji({label:e,value:n,color:s}){if(!n)return null;const i={purple:"bg-brand-500/15 text-brand-500",cyan:"bg-blue-500/15 text-blue-600",indigo:"bg-brand-500/15 text-brand-500",gray:"bg-gray-500/15 text-fg-secondary",emerald:"bg-green-500/15 text-green-600"};return t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${i[s]??i.gray} capitalize inline-block`,children:n})]})}function om({files:e}){const[n,s]=v.useState(Object.keys(e)[0]??""),i=Object.keys(e);return i.length===0?null:t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Files (",i.length,")"]}),t.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[t.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:i.map(o=>t.jsx("button",{onClick:()=>s(o),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${n===o?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:o},o))}),n&&e[n]!=null&&t.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[n]})]})]})}function iz({artifact:e,mode:n}){const s=az(e),i=e.agent,o=e.team,d=e.dependencies,c=e.displayName??e.name;if(n==="agent"){const h=i?.roleName,m=i?.agentRole,f=i?.llmProvider,x=i?.llmModel,p=ys(d?.env),g=ys(d?.skills);return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(ii,{label:"Name",value:c}),t.jsx(ii,{label:"Description",value:e.description}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(Ji,{label:"Role Template",value:h,color:"indigo"}),t.jsx(Ji,{label:"Agent Role",value:m,color:m==="manager"?"purple":"cyan"})]}),ys(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:ys(e.tags).map(y=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:y},y))}),(f||x)&&t.jsxs("div",{className:"flex gap-2",children:[f&&t.jsx(Ji,{label:"LLM Provider",value:f,color:"gray"}),x&&t.jsx(Ji,{label:"LLM Model",value:x,color:"gray"})]}),p.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:p.map(y=>t.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/10 text-amber-600 rounded font-mono",children:y},y))})]}),g.length>0&&t.jsx(ii,{label:"Skills",value:g.join(", ")}),s&&t.jsx(om,{files:s})]})}if(n==="team"){const m=o?.members??[];return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(ii,{label:"Name",value:c}),t.jsx(ii,{label:"Description",value:e.description}),t.jsx("div",{className:"flex flex-wrap gap-2",children:t.jsx(Ji,{label:"Category",value:e.category,color:"indigo"})}),ys(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:ys(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))}),s&&t.jsx(om,{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((f,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 ${f.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:f.role==="manager"?"★":x+1}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:f.name}),typeof f.roleName=="string"&&f.roleName&&t.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:f.roleName}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(f.count??1)]})]}),ys(f.skills).length>0&&t.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:ys(f.skills).map(p=>t.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:p},p))})]},x))})]})]})}return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(ii,{label:"Name",value:c}),t.jsx(ii,{label:"Description",value:e.description}),t.jsx("div",{className:"flex gap-2",children:t.jsx(Ji,{label:"Category",value:e.category,color:"indigo"})}),s&&t.jsx(om,{files:s}),ys(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:ys(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))})]})}const yo={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},h1={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"}},m1=["file","directory"],vs={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 x1(){const e=Cr(),n=au({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[s,i]=v.useState(!1),o=v.useRef(s);o.current=s,v.useEffect(()=>{if(!e)return;const be=()=>{o.current&&i(!1)};return window.addEventListener("popstate",be),()=>window.removeEventListener("popstate",be)},[e]);const d=100,[c,h]=v.useState([]),[m,f]=v.useState(0),[x,p]=v.useState(!1),[g,y]=v.useState([]),[w,N]=v.useState([]),[T,_]=v.useState(!0),[S,k]=v.useState(""),[C,M]=v.useState(""),[L,P]=v.useState(""),[G,W]=v.useState(""),[z,q]=v.useState(""),[Y,$]=v.useState(""),[R,I]=v.useState(""),[A,F]=v.useState("date"),[V,X]=v.useState(null),[O,U]=v.useState(null),[K,D]=v.useState(""),[E,H]=v.useState(!1),[Z,ee]=v.useState(!1),[ne,ae]=v.useState(new Set),he=v.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),Se=v.useCallback(be=>{F(be),ae(new Set)},[]),Ie=Js(he,A,Se),xe=v.useRef(null),[we,Me]=v.useState("file"),[Be,et]=v.useState(""),[lt,ft]=v.useState(""),[yt,re]=v.useState(""),[Te,rt]=v.useState(""),[wt,Lt]=v.useState(""),[je,De]=v.useState(null),[Ve,dt]=v.useState(null),[st,zt]=v.useState(!1),[fn,Mt]=v.useState(!1),[_t,$t]=v.useState(!1),[Tt,Bt]=v.useState(!1),Xt=v.useRef(null),hn=v.useRef(null),[ve,tt]=v.useState(""),Et=v.useRef(void 0),Pe=(be,Ge)=>{U({type:be,text:Ge}),setTimeout(()=>U(null),3e3)},vt=async be=>{try{return await navigator.clipboard.writeText(be),!0}catch{try{const Ge=document.createElement("textarea");Ge.value=be,Ge.style.cssText="position:fixed;left:-9999px;top:-9999px;opacity:0",document.body.appendChild(Ge),Ge.select();const St=document.execCommand("copy");return document.body.removeChild(Ge),St}catch{return!1}}},mn=async be=>{await vt(be)?(Bt(!0),setTimeout(()=>Bt(!1),1500)):Pe("error","Copy failed — try long-pressing to copy manually")},Rn=v.useMemo(()=>new Map(w.map(be=>[be.id,be])),[w]),kn=v.useMemo(()=>new Map(g.map(be=>[be.id,be])),[g]);v.useEffect(()=>{se.projects.list().then(be=>y(be.projects)).catch(()=>{}),se.agents.list().then(be=>N(be.agents??[])).catch(()=>{}),se.system.storage().then(be=>tt(be.dataDir+"/shared")).catch(()=>{})},[]),v.useEffect(()=>(Et.current=setTimeout(()=>M(S),300),()=>clearTimeout(Et.current)),[S]);const Jt=v.useMemo(()=>({q:C||void 0,projectId:G||void 0,agentId:z||void 0,type:L||void 0,status:Y||void 0,artifactType:R||void 0}),[C,G,z,L,Y,R]),sn=v.useCallback(async()=>{_(!0);try{const{results:be,total:Ge}=await se.deliverables.search({...Jt,offset:0,limit:d});h(be),f(Ge)}catch{h([]),f(0)}_(!1)},[Jt]),On=v.useCallback(async()=>{if(!(x||c.length>=m)){p(!0);try{const{results:be,total:Ge}=await se.deliverables.search({...Jt,offset:c.length,limit:d});h(St=>[...St,...be]),f(Ge)}catch{}p(!1)}},[Jt,c.length,m,x]);v.useEffect(()=>{sn()},[sn]),v.useEffect(()=>ln.on("deliverable:created",()=>sn()),[sn]);const Nt=v.useCallback(()=>{const be=xe.current;!be||T||x||c.length>=m||be.scrollHeight<=be.clientHeight+100&&On()},[T,x,c.length,m,On]);v.useEffect(()=>{const be=xe.current;if(!be)return;const Ge=()=>{be.scrollTop+be.clientHeight>=be.scrollHeight-100&&On()};return be.addEventListener("scroll",Ge,{passive:!0}),()=>be.removeEventListener("scroll",Ge)},[On]),v.useEffect(()=>{Nt()},[Nt,ne]);const en=v.useMemo(()=>{const be=new Map;for(const St of c){let Ct,pn;if(A==="project")Ct=St.projectId??"_none",pn=St.projectId?kn.get(St.projectId)?.name??St.projectId:"No Project";else if(A==="agent")Ct=St.agentId??"_none",pn=St.agentId?Rn.get(St.agentId)?.name??St.agentId:"Unknown";else if(A==="type")Ct=St.type,pn=St.type.charAt(0).toUpperCase()+St.type.slice(1);else{const Zn=new Date(St.updatedAt);Ct=`${Zn.getFullYear()}-${String(Zn.getMonth()+1).padStart(2,"0")}-${String(Zn.getDate()).padStart(2,"0")}`,pn=Ct}be.has(Ct)||be.set(Ct,{label:pn,items:[]}),be.get(Ct).items.push(St)}const Ge=[...be.entries()];return A==="date"?Ge.sort((St,Ct)=>Ct[0].localeCompare(St[0])):Ge.sort((St,Ct)=>St[1].label.localeCompare(Ct[1].label)),Ge},[c,A,kn,Rn]),Bn=async()=>{if(!(!Be.trim()||!lt.trim())){ee(!0);try{await se.deliverables.create({type:we,title:Be,summary:lt,reference:yt,projectId:Te||void 0,tags:wt.split(",").map(be=>be.trim()).filter(Boolean)}),H(!1),Pe("success","Deliverable created"),sn()}catch(be){Pe("error",`Error: ${be}`)}ee(!1)}},le=async be=>{D("verify");try{await se.deliverables.verify(be.id),Pe("success","Verified"),X({...be,status:"verified"}),sn()}catch(Ge){Pe("error",`Error: ${Ge}`)}D("")},ze=async be=>{D("flag");try{await se.deliverables.update(be.id,{status:"outdated"}),Pe("success","Flagged as outdated"),X({...be,status:"outdated"}),sn()}catch(Ge){Pe("error",`Error: ${Ge}`)}D("")},Fe=async be=>{D("remove");try{await se.deliverables.remove(be.id),Pe("success","Removed"),X(null),sn()}catch(Ge){Pe("error",`Error: ${Ge}`)}D("")},Qe=()=>{xt.navigate(me.BUILDER)},Xe=async be=>{if(be.reference){if(be.type==="directory"){Mt(!0);return}zt(!0);try{const Ge=await se.files.preview(be.reference);Ge.type==="image"&&Ge.mimeType?dt({src:`data:${Ge.mimeType};base64,${Ge.content}`,name:Ge.name}):De(Ge.content)}catch{De(null),be.type==="file"&&Mt(!0)}zt(!1)}};v.useEffect(()=>{De(null),dt(null),Mt(!1),$t(!1),V&&Xe(V)},[V?.id]),v.useEffect(()=>{if(!_t)return;const be=Ge=>{hn.current&&!hn.current.contains(Ge.target)&&$t(!1)};return document.addEventListener("mousedown",be),()=>document.removeEventListener("mousedown",be)},[_t]);const Ye=async(be,Ge)=>{const St=Xt.current?.firstElementChild;if(!St)return;const Ct=lz(St,be);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([Ct],{type:"text/html"}),"text/plain":new Blob([Ge],{type:"text/plain"})})]),Pe("success",be==="light"?"HTML (light) copied":"HTML (dark) copied")}catch{const pn=await vt(Ge);Pe(pn?"success":"error",pn?"Text copied (HTML not supported)":"Copy failed")}$t(!1)},nt=be=>t.jsxs("div",{className:"relative group/preview",children:[t.jsxs("div",{className:"absolute -top-1 -right-1 z-10",ref:hn,children:[t.jsx("button",{onClick:()=>$t(Ge=>!Ge),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"})})}),_t&&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 Ge=await vt(be);Pe(Ge?"success":"error",Ge?"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:()=>Ye("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:()=>Ye("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:Xt,children:t.jsx(tr,{content:be,className:"text-fg-secondary text-sm"})})]}),pt=v.useCallback(be=>{ae(Ge=>{const St=new Set(Ge);return St.has(be)?St.delete(be):St.add(be),St})},[]),an=v.useCallback(()=>{ne.size===en.length?ae(new Set):ae(new Set(en.map(([be])=>be)))},[ne.size,en]),It=()=>{et(""),ft(""),re(""),Lt(""),Me("file"),g.length>0&&rt(g[0].id),H(!0)},xn=be=>{X(be),e&&(i(!0),history.pushState({mobileDetail:me.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:n.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:It,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:S,onChange:be=>k(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"}),ve&&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:ve}),t.jsx("button",{onClick:()=>{se.system.openPath(ve)},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(Da,{label:"All types",value:"",current:L||R||"",onClick:()=>{P(""),I("")}}),m1.map(be=>t.jsx(Da,{label:`${yo[be]?.icon??""} ${be}`,value:be,current:L,onClick:Ge=>{P(Ge),I("")}},be)),["agent","team","skill"].map(be=>t.jsx(Da,{label:`${vs[be].icon} ${vs[be].label}`,value:be,current:R,onClick:Ge=>{I(Ge),P("")}},be))]}),g.length>0&&t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(Da,{label:"All projects",value:"",current:G,onClick:W}),g.map(be=>t.jsx(Da,{label:be.name,value:be.id,current:G,onClick:W},be.id))]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(Da,{label:"Active",value:"",current:Y,onClick:$}),t.jsx(Da,{label:"Verified",value:"verified",current:Y,onClick:$}),t.jsx(Da,{label:"Outdated",value:"outdated",current:Y,onClick:$})]}),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:()=>{F(be),ae(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${A===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)),en.length>1&&t.jsx("button",{onClick:an,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:ne.size===en.length?"Expand all":"Collapse all",children:ne.size===en.length?"▶ Expand":"▼ Collapse"})]})]}),O&&t.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${O.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:O.text}),t.jsxs("div",{ref:xe,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:e?Ie.onTouchStart:void 0,onTouchEnd:e?Ie.onTouchEnd:void 0,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))}):c.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:It,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create first"})]}):en.map(([be,Ge])=>{const St=ne.has(be);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>pt(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 ${St?"":"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:Ge.label}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Ge.items.length,")"]})]}),!St&&Ge.items.map(Ct=>t.jsxs("button",{onClick:()=>xn(Ct),className:`w-full text-left p-3 rounded-lg transition-colors ${V?.id===Ct.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:Ct.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[Ct.artifactType&&vs[Ct.artifactType]?t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${vs[Ct.artifactType].color}`,children:[vs[Ct.artifactType].icon," ",vs[Ct.artifactType].label]}):t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium uppercase ${yo[Ct.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:Ct.type}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${h1[Ct.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:Ct.status}),Ct.agentId&&t.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:Rn.get(Ct.agentId)?.name??"Agent"})]})]},Ct.id))]},be)}),x&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[t.jsx(cm,{})," ",t.jsx("span",{className:"text-[10px]",children:"Loading more..."})]}),!T&&c.length>0&&t.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:c.length<m?`${c.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:n.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:V?.title??"Details"})]}),V?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:V.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[V.status!=="verified"&&t.jsx("button",{onClick:()=>le(V),disabled:!!K,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:K==="verify"?"Verifying...":"Verify"}),V.status!=="outdated"&&t.jsx("button",{onClick:()=>ze(V),disabled:!!K,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:K==="flag"?"Flagging...":"Flag Outdated"}),t.jsx("button",{onClick:()=>Fe(V),disabled:!!K,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:K==="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 ${yo[V.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[yo[V.type]?.icon??""," ",V.type]}),t.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${h1[V.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:V.status}),V.artifactType&&vs[V.artifactType]&&t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${vs[V.artifactType].color}`,children:[vs[V.artifactType].icon," Builder ",vs[V.artifactType].label]})]}),V.reference&&(V.type==="file"||V.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:()=>{se.files.reveal(V.reference).catch(()=>Pe("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:V.reference}),t.jsx("button",{onClick:()=>{se.files.reveal(V.reference).catch(()=>Pe("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:()=>mn(V.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Tt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:"Copy path to clipboard",children:Tt?"Copied!":"Copy"})]}),V.reference&&V.type!=="file"&&V.type!=="directory"&&t.jsx("div",{className:"mt-2",children:t.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:V.reference})})]}),V.artifactType&&V.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(iz,{artifact:V.artifactData,mode:V.artifactType})}),V.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:V.reference})]}),t.jsx("div",{className:"flex gap-2",children:t.jsx("button",{onClick:Qe,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"})}),V.summary&&t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:t.jsx(tr,{content:V.summary,className:"text-fg-secondary text-sm"})})]}):t.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:st?t.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[t.jsx(cm,{})," Loading preview..."]}):Ve?t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("img",{src:Ve.src,alt:Ve.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:Ve.name})]}):je?nt(je):fn?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("p",{className:"text-sm text-fg-secondary",children:["This ",V.type," cannot be previewed in the browser."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>{se.files.reveal(V.reference).catch(()=>Pe("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:V.reference}),t.jsx("button",{onClick:()=>{se.files.reveal(V.reference).catch(()=>Pe("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:()=>mn(V.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Tt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:Tt?"Copied!":"Copy"})]})]}):V.summary?nt(V.summary):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No content"})}),(V.diffStats||V.testResults)&&t.jsxs("div",{className:"flex gap-4 flex-wrap",children:[V.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:[V.diffStats.filesChanged," files"]}),t.jsxs("span",{className:"text-green-600",children:["+",V.diffStats.additions]}),t.jsxs("span",{className:"text-red-500",children:["-",V.diffStats.deletions]})]})]}),V.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:[V.testResults.passed," passed"]}),t.jsxs("span",{className:"text-red-500",children:[V.testResults.failed," failed"]}),t.jsxs("span",{className:"text-fg-secondary",children:[V.testResults.skipped," skipped"]})]})]})]}),V.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5",children:V.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:[V.taskId&&t.jsxs("button",{onClick:()=>xt.navigate(me.WORK,{openTask:V.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2.5 py-1 rounded",children:["Task: ",V.taskId.slice(0,12),"..."]}),V.agentId&&t.jsxs("button",{onClick:()=>xt.navigate(me.TEAM,{selectAgent:V.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Agent: ",Rn.get(V.agentId)?.name??V.agentId.slice(0,12)]}),V.projectId&&t.jsxs("button",{onClick:()=>xt.navigate(me.WORK,{projectId:V.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Project: ",kn.get(V.projectId)?.name??V.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(V.createdAt).toLocaleString()})]}),t.jsxs("span",{children:["Updated: ",t.jsx("span",{className:"text-fg-secondary",children:new Date(V.updatedAt).toLocaleString()})]}),t.jsxs("span",{children:["Accessed: ",t.jsxs("span",{className:"text-fg-secondary",children:[V.accessCount,"x"]})]})]}),t.jsxs("div",{className:"text-fg-muted select-all",children:["ID: ",V.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"})]})})]}),E&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!Z&&H(!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:we,onChange:be=>Me(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:m1.map(be=>t.jsxs("option",{value:be,children:[yo[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:Be,onChange:be=>et(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:yt,onChange:be=>re(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:lt,onChange:be=>ft(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:wt,onChange:be=>Lt(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:Te,onChange:be=>rt(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"}),g.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:()=>H(!1),disabled:Z,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:"Cancel"}),t.jsxs("button",{onClick:Bn,disabled:Z||!Be.trim()||!lt.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:[Z&&t.jsx(cm,{}),Z?"Creating...":"Create"]})]})]})})]})}function lz(e,n){const s=e.cloneNode(!0),i=n==="light"?{bg:"#ffffff",text:"#24292f",heading:"#1f2328",strong:"#1f2328",link:"#0969da",codeBg:"#eff1f3",codeText:"#24292f",preBg:"#f6f8fa",preText:"#24292f",preBorder:"#d0d7de",border:"#d0d7de",blockquoteBorder:"#d0d7de",blockquoteText:"#656d76",tableBorder:"#d0d7de",tableHeaderBg:"#f6f8fa",tableHeaderText:"#24292f",hrColor:"#d8dee4"}:{bg:"#0d1117",text:"#e6edf3",heading:"#f0f6fc",strong:"#f0f6fc",link:"#58a6ff",codeBg:"#161b22",codeText:"#e6edf3",preBg:"#161b22",preText:"#e6edf3",preBorder:"#30363d",border:"#30363d",blockquoteBorder:"#3b82f6",blockquoteText:"#8b949e",tableBorder:"#30363d",tableHeaderBg:"#161b22",tableHeaderText:"#e6edf3",hrColor:"#21262d"},o={p:`margin:0 0 10px;color:${i.text};line-height:1.7;`,h1:`font-size:1.6em;font-weight:700;color:${i.heading};margin:20px 0 10px;line-height:1.3;border-bottom:1px solid ${i.border};padding-bottom:6px;`,h2:`font-size:1.35em;font-weight:700;color:${i.heading};margin:18px 0 8px;line-height:1.3;`,h3:`font-size:1.15em;font-weight:600;color:${i.heading};margin:14px 0 6px;line-height:1.3;`,h4:`font-size:1em;font-weight:600;color:${i.heading};margin:12px 0 4px;`,strong:`font-weight:600;color:${i.strong};`,em:"font-style:italic;",a:`color:${i.link};text-decoration:underline;`,ul:"padding-left:1.5em;margin:0 0 10px;",ol:"padding-left:1.5em;margin:0 0 10px;",li:`margin:3px 0;line-height:1.7;color:${i.text};`,blockquote:`border-left:3px solid ${i.blockquoteBorder};padding:2px 0 2px 14px;margin:10px 0;color:${i.blockquoteText};`,hr:`border:none;border-top:1px solid ${i.hrColor};margin:20px 0;`,table:"border-collapse:collapse;width:100%;margin:10px 0;",thead:`background:${i.tableHeaderBg};`,th:`border:1px solid ${i.tableBorder};padding:8px 12px;text-align:left;font-weight:600;color:${i.tableHeaderText};`,td:`border:1px solid ${i.tableBorder};padding:8px 12px;color:${i.text};`,img:"max-width:100%;height:auto;"};function d(c){c.removeAttribute("class");const h=c.tagName.toLowerCase();if(h==="pre"){c.setAttribute("style",`background:${i.preBg};color:${i.preText};padding:14px;border-radius:6px;overflow-x:auto;margin:10px 0;font-size:0.88em;line-height:1.5;border:1px solid ${i.preBorder};`);const m=c.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}h==="code"?c.setAttribute("style",`background:${i.codeBg};color:${i.codeText};padding:2px 6px;border-radius:4px;font-size:0.9em;font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;`):o[h]&&c.setAttribute("style",o[h]),Array.from(c.children).forEach(d)}return s.removeAttribute("class"),Array.from(s.children).forEach(c=>d(c)),`<div style="background:${i.bg};color:${i.text};padding:20px 24px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Noto Sans',Helvetica,Arial,sans-serif;font-size:15px;line-height:1.7;max-width:800px;">${s.innerHTML}</div>`}function Da({label:e,value:n,current:s,onClick:i}){return t.jsx("button",{onClick:()=>i(s===n?"":n),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${s===n?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function cm(){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 Ks(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function rl(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function oz(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 HN({authUser:e}){const[n,s]=v.useState("weekly"),[i,o]=v.useState(null),[d,c]=v.useState(!0),[h,m]=v.useState(""),[f,x]=v.useState(null),[p,g]=v.useState([]),[y,w]=v.useState("totalTokens"),[N,T]=v.useState(!0),[_,S]=v.useState("generate"),[k,C]=v.useState([]),[M,L]=v.useState(null),[P,G]=v.useState([]),[W,z]=v.useState(""),[q,Y]=v.useState(""),$=E=>{Y(E),setTimeout(()=>Y(""),3e3)},R=v.useCallback(async E=>{c(!0),m("");try{const{report:H}=await se.reports.generate({period:E,scope:"org",orgId:"default"});o(H)}catch(H){m(String(H)),o(null)}c(!1)},[]),I=v.useCallback(()=>{se.usage.summary().then(E=>x(E.usage)).catch(()=>{}),se.usage.agents().then(E=>g(E.agents)).catch(()=>{})},[]),A=v.useCallback(async()=>{try{const{reports:E}=await se.reports.list();C(E)}catch{}},[]),F=v.useCallback(async E=>{L(E);try{const{feedback:H}=await se.reports.getFeedback(E.id);G(H)}catch{G([])}},[]);v.useEffect(()=>{R(n)},[n,R]),v.useEffect(()=>{I();const E=setInterval(I,3e4);return()=>clearInterval(E)},[I]),v.useEffect(()=>{_==="history"&&A()},[_,A]);const V=v.useMemo(()=>[...p].sort((E,H)=>{const Z=E[y],ee=H[y];return N?ee-Z:Z-ee}),[p,y,N]),X=p.reduce((E,H)=>E+H.estimatedCost,0),O=p.reduce((E,H)=>E+H.tokensUsedToday,0),U=Math.max(1,...p.map(E=>E.totalTokens)),K=E=>{y===E?T(!N):(w(E),T(!0))},D={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 flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[t.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[t.jsx("h1",{className:"text-xl font-semibold text-fg-primary",children:"Reports"}),t.jsxs("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:[t.jsx("button",{onClick:()=>S("generate"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${_==="generate"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:"Generate"}),t.jsxs("button",{onClick:()=>S("history"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${_==="history"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:["History",k.length>0?` (${k.length})`:""]})]})]}),t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[q&&t.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:q}),_==="generate"&&t.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(E=>t.jsx("button",{onClick:()=>s(E),className:`px-3 py-1.5 text-xs rounded-md transition-colors capitalize ${n===E?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:E},E))})]})]}),_==="history"&&!M&&t.jsx("section",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden",children:k.length===0?t.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:"No reports generated yet. Use the Generate tab to create one."}):t.jsx("div",{className:"divide-y divide-border-default/50",children:k.map(E=>t.jsxs("button",{onClick:()=>F(E),className:"w-full text-left px-5 py-3 flex items-center gap-4 hover:bg-surface-elevated/30 transition-colors",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"text-sm font-medium text-fg-primary",children:[E.type," Report"]}),t.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(E.periodStart).toLocaleDateString()," — ",new Date(E.periodEnd).toLocaleDateString()]})]}),E.plan&&t.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${E.plan.status==="approved"?"bg-green-500/10 text-green-600":E.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:E.plan.status==="pending"?"Plan pending":`Plan ${E.plan.status}`}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(E.generatedAt).toLocaleDateString()})]},E.id))})}),_==="history"&&M&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:()=>{L(null),G([])},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"← Back to list"}),t.jsxs("span",{className:"text-sm font-medium text-fg-primary",children:[M.type," Report"]}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(M.periodStart).toLocaleDateString()," — ",new Date(M.periodEnd).toLocaleDateString()]})]}),M.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(js,{label:"Completed",value:M.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(js,{label:"In Progress",value:M.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(js,{label:"Created",value:M.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(js,{label:"Blocked",value:M.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(js,{label:"Failed",value:M.metrics.tasksFailed,color:"text-red-500"})]})]}),M.costSummary&&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-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:M.costSummary.totalTokens.toLocaleString()}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Total Tokens"})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:rl(M.costSummary.totalEstimatedCost)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Estimated Cost"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:`text-2xl font-bold ${M.costSummary.trend==="decreasing"?"text-green-600":M.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[M.costSummary.trend==="decreasing"?"↓":M.costSummary.trend==="increasing"?"↑":"→"," ",M.costSummary.trend]}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Trend"})]})]}),M.costSummary.byAgent&&M.costSummary.byAgent.length>0&&t.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:M.costSummary.byAgent.map((E,H)=>t.jsxs("div",{className:"flex items-center justify-between text-xs",children:[t.jsx("span",{className:"text-fg-secondary",children:E.agentId}),t.jsxs("span",{className:"text-fg-tertiary tabular-nums",children:[Ks(E.tokens)," tokens · ",rl(E.cost)]})]},H))})]}),M.taskSummary&&t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 overflow-hidden",children:[t.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:"Task Summary"}),t.jsxs("div",{className:"space-y-4 min-w-0",children:[M.taskSummary.completed.length>0&&t.jsx(el,{title:`Completed (${M.taskSummary.completed.length})`,color:"emerald",items:M.taskSummary.completed.map(E=>({id:E.id,label:E.title,sub:E.agent}))}),M.taskSummary.inProgress.length>0&&t.jsx(el,{title:`In Progress (${M.taskSummary.inProgress.length})`,color:"indigo",items:M.taskSummary.inProgress.map(E=>({id:E.id,label:E.title,sub:E.agent}))}),M.taskSummary.blocked.length>0&&t.jsx(el,{title:`Blocked (${M.taskSummary.blocked.length})`,color:"amber",items:M.taskSummary.blocked.map(E=>({id:E.id,label:E.title,sub:E.reason||E.agent}))}),M.taskSummary.completed.length===0&&M.taskSummary.inProgress.length===0&&M.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]}),M.highlights&&M.highlights.length>0&&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-2",children:"Highlights"}),t.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:M.highlights.map((E,H)=>t.jsx("li",{children:E},H))})]}),M.blockers&&M.blockers.length>0&&t.jsxs("section",{className:"bg-surface-secondary border border-amber-500/20 rounded-xl p-5",children:[t.jsx("h3",{className:"text-xs font-semibold text-amber-600 mb-2",children:"Blockers"}),t.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:M.blockers.map((E,H)=>t.jsx("li",{children:E},H))})]}),M.plan&&t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("h3",{className:"text-xs font-semibold text-fg-secondary",children:["Upcoming Plan",t.jsx("span",{className:`ml-2 px-1.5 py-0.5 rounded text-[10px] font-medium ${M.plan.status==="approved"?"bg-green-500/10 text-green-600":M.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:M.plan.status})]}),M.plan.status==="pending"&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{onClick:async()=>{try{const{report:E}=await se.reports.approvePlan(M.id,{approvedBy:e?.id??"admin"});L(E),$("Plan approved"),A()}catch(E){$(`Error: ${E}`)}},className:"px-3 py-1.5 text-xs font-medium bg-green-600 text-white rounded-lg hover:bg-green-500 transition-colors",children:"Approve Plan"}),t.jsx("button",{onClick:async()=>{const E=prompt("Rejection reason:");if(E)try{const{report:H}=await se.reports.rejectPlan(M.id,{rejectedBy:e?.id??"admin",reason:E});L(H),$("Plan rejected"),A()}catch(H){$(`Error: ${H}`)}},className:"px-3 py-1.5 text-xs font-medium border border-border-default text-fg-secondary rounded-lg hover:bg-surface-overlay transition-colors",children:"Reject Plan"})]})]}),M.plan.items&&M.plan.items.length>0&&t.jsx("div",{className:"space-y-1.5",children:M.plan.items.map((E,H)=>t.jsxs("div",{className:"flex items-center gap-2 text-sm text-fg-secondary",children:[t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${E.priority==="high"?"bg-red-500/10 text-red-500":E.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:E.priority}),t.jsx("span",{children:E.title}),E.assignee&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:E.assignee})]},H))})]}),!M.metrics&&!M.taskSummary&&!M.costSummary&&t.jsx("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-8 text-center",children:t.jsx("p",{className:"text-sm text-fg-tertiary",children:"This report does not contain detailed metrics data."})}),t.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsxs("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:["Feedback (",P.length,")"]}),P.length>0&&t.jsx("div",{className:"space-y-2 mb-4",children:P.map(E=>t.jsxs("div",{className:"p-3 bg-surface-elevated/50 rounded-lg",children:[t.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary mb-1",children:[t.jsx("span",{className:"font-medium text-fg-secondary",children:E.authorName}),t.jsx("span",{children:E.type}),t.jsx("span",{children:new Date(E.createdAt).toLocaleDateString()})]}),t.jsx("p",{className:"text-xs text-fg-secondary",children:E.content})]},E.id))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:W,onChange:E=>z(E.target.value),placeholder:"Add feedback or instructions…",className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-tertiary",onKeyDown:E=>{E.key==="Enter"&&W.trim()&&se.reports.addFeedback(M.id,{author:e?.id??"admin",type:"comment",content:W.trim()}).then(({feedback:H})=>{G(Z=>[...Z,H]),z(""),$("Feedback added")}).catch(H=>$(`Error: ${H}`))}}),t.jsx("button",{onClick:()=>{W.trim()&&se.reports.addFeedback(M.id,{author:e?.id??"admin",type:"comment",content:W.trim()}).then(({feedback:E})=>{G(H=>[...H,E]),z(""),$("Feedback added")}).catch(E=>$(`Error: ${E}`))},disabled:!W.trim(),className:"px-3 py-2 text-xs bg-brand-600 text-white rounded-lg hover:bg-brand-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:"Send"})]})]})]}),_==="generate"&&f&&t.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t.jsx(kd,{label:"LLM Tokens (this month)",value:Ks(f.llmTokens),color:"text-brand-500"}),t.jsx(kd,{label:"Tool Calls (today)",value:Ks(f.toolCalls),color:"text-blue-600"}),t.jsx(kd,{label:"Messages (today)",value:Ks(f.messages),color:"text-green-600"}),t.jsx(kd,{label:"Storage",value:oz(f.storageBytes),color:"text-amber-600"})]}),_==="generate"&&(d?t.jsx("div",{className:"flex items-center justify-center h-32 text-fg-tertiary text-sm",children:"Loading…"}):h?t.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:h}):i?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"text-xs text-fg-tertiary",children:[D[n]," · ",new Date(i.periodStart).toLocaleDateString()," — ",new Date(i.periodEnd).toLocaleDateString()]}),i.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(js,{label:"Completed",value:i.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(js,{label:"In Progress",value:i.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(js,{label:"Created",value:i.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(js,{label:"Blocked",value:i.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(js,{label:"Failed",value:i.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:rl(X)}),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:Ks(O)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Tokens Today"})]}),i.costSummary&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:i.costSummary.totalTokens.toLocaleString()}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Tokens (",D[n],")"]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:rl(i.costSummary.totalEstimatedCost)}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Cost (",D[n],")"]})]})]})]})]}),i.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:[i.taskSummary.completed.length>0&&t.jsx(el,{title:`Completed (${i.taskSummary.completed.length})`,color:"emerald",items:i.taskSummary.completed.map(E=>({id:E.id,label:E.title,sub:E.agent}))}),i.taskSummary.inProgress.length>0&&t.jsx(el,{title:`In Progress (${i.taskSummary.inProgress.length})`,color:"indigo",items:i.taskSummary.inProgress.map(E=>({id:E.id,label:E.title,sub:E.agent}))}),i.taskSummary.blocked.length>0&&t.jsx(el,{title:`Blocked (${i.taskSummary.blocked.length})`,color:"amber",items:i.taskSummary.blocked.map(E=>({id:E.id,label:E.title,sub:E.reason||E.agent}))}),i.taskSummary.completed.length===0&&i.taskSummary.inProgress.length===0&&i.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]})]}):null),_==="generate"&&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"})}),p.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(vo,{label:"Total Tokens",col:"totalTokens",current:y,desc:N,onSort:K}),t.jsx(vo,{label:"Today",col:"tokensUsedToday",current:y,desc:N,onSort:K}),t.jsx(vo,{label:"Requests",col:"requestCount",current:y,desc:N,onSort:K}),t.jsx(vo,{label:"Tool Calls",col:"toolCalls",current:y,desc:N,onSort:K}),t.jsx(vo,{label:"Est. Cost",col:"estimatedCost",current:y,desc:N,onSort:K,align:"right"})]})}),t.jsx("tbody",{children:V.map(E=>t.jsx(cz,{agent:E,maxTokens:U},E.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 (",p.length," agents)"]}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Ks(p.reduce((E,H)=>E+H.totalTokens,0))}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Ks(O)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:p.reduce((E,H)=>E+H.requestCount,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:p.reduce((E,H)=>E+H.toolCalls,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:rl(X)})]})})]})})]})]})})}function js({label:e,value:n,color:s}){return t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:`text-2xl font-bold ${s}`,children:n}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function el({title:e,color:n,items:s}){return t.jsxs("div",{className:"min-w-0 overflow-hidden",children:[t.jsx("div",{className:`text-xs font-medium text-${n}-400 mb-1.5`,children:e}),t.jsx("div",{className:"space-y-1.5",children:s.map((i,o)=>t.jsxs("div",{className:`text-sm text-fg-secondary min-w-0 ${i.id?"cursor-pointer hover:text-fg-primary group":""}`,onClick:i.id?()=>xt.navigate(me.WORK,{openTask:i.id}):void 0,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${n}-500 shrink-0`}),t.jsx("span",{className:`truncate min-w-0 ${i.id?"group-hover:text-brand-500 transition-colors":""}`,children:i.label})]}),i.sub&&i.sub!=="unassigned"&&t.jsx("div",{className:"text-[10px] text-fg-tertiary ml-3.5 mt-0.5 break-all line-clamp-2",children:i.sub})]},i.id??o))})]})}function kd({label:e,value:n,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:n})]})}function vo({label:e,col:n,current:s,desc:i,onSort:o,align:d}){const c=s===n?i?"↓":"↑":"↕",h=s===n?"text-brand-500":"text-fg-muted";return t.jsxs("th",{className:`px-4 py-3 ${d==="right"?"text-right":"text-left"} font-medium cursor-pointer select-none hover:text-fg-secondary`,onClick:()=>o(n),children:[e,t.jsx("span",{className:`ml-1 ${h}`,children:c})]})}function cz({agent:e,maxTokens:n}){const s=n>0?Math.min(100,e.totalTokens/n*100):0,i=e.status==="working"?"bg-blue-500":e.status==="idle"?"bg-green-500":e.status==="paused"?"bg-amber-500":e.status==="error"?"bg-red-500":"bg-gray-600";return t.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>xt.navigate(me.TEAM,{selectAgent:e.agentId}),children:[t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:`w-2 h-2 rounded-full ${i}`}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:t.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${s}%`}})}),t.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:Ks(e.totalTokens)})]})}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:Ks(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:rl(e.estimatedCost)})]})}function jo({d:e,size:n=18}){return t.jsx("svg",{width:n,height:n,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 dz={active:"bg-green-500",paused:"bg-amber-500",completed:"bg-gray-500",archived:"bg-gray-600"},p1=5;function uz({currentPage:e,onNavigate:n,authUser:s,onLogout:i,collapsed:o,onToggleCollapse:d}){const[c,h]=v.useState([]),[m,f]=v.useState(!1),[x,p]=v.useState(null),[g,y]=v.useState(!1),w=v.useCallback(()=>{se.projects.list().then(S=>h(S.projects)).catch(()=>{})},[]);v.useEffect(()=>{w();const S=setInterval(w,3e4);return()=>clearInterval(S)},[w]),v.useEffect(()=>{if(e!==me.WORK){p(null);return}const k=window.location.hash.slice(1).split("/");Qs(k[0])===me.WORK&&k[1]&&p(k[1])},[e]);const N=async()=>{try{await se.auth.logout()}catch{}i?.()},T=m?c:c.slice(0,p1),_=c.length>p1;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.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("button",{onClick:d,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.jsx(mm,{collapsed:!0,userId:s?.id})]}):t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:d,className:"flex items-center gap-2.5 min-w-0 group",title:"Collapse sidebar",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg shadow-md shadow-black/30 shrink-0 group-hover:ring-2 group-hover:ring-brand-500/40 transition-all"}),t.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(mm,{userId:s?.id}),t.jsx("button",{onClick:d,className:"text-fg-tertiary hover:text-fg-secondary transition-colors p-1 rounded-md hover:bg-surface-overlay",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:nk.map((S,k)=>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:S.label}),o&&k>0&&t.jsx("div",{className:"my-2 mx-1"}),rk.filter(C=>C.section===S.key&&!(S.key==="workspace"&&C.id===me.DELIVERABLES)).map(C=>{const M=e===C.id;return t.jsxs("button",{onClick:()=>n(C.id),title:o?C.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 ${M?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":"text-fg-primary hover:bg-surface-overlay"}`,children:[t.jsx(jo,{d:tl[C.id]??""}),!o&&C.label]},C.id)}),S.key==="workspace"&&o&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{p(null),n(me.WORK)},title:"Work",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-all ${e===me.WORK&&!x?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":e===me.WORK?"bg-brand-600/15 text-fg-primary":"text-fg-primary hover:bg-surface-overlay"}`,children:t.jsx(jo,{d:tl[me.WORK]})}),t.jsx("button",{onClick:()=>n(me.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===me.DELIVERABLES?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:t.jsx(jo,{d:tl[me.DELIVERABLES]})})]}),S.key==="workspace"&&!o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center mb-0.5",children:[t.jsxs("button",{onClick:()=>{p(null),n(me.WORK)},className:`flex-1 flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-colors ${e===me.WORK&&!x?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(jo,{d:tl[me.WORK]}),"Work"]}),t.jsx("button",{onClick:()=>y(!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"})]})})]}),c.length===0&&t.jsxs("button",{onClick:()=>y(!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(C=>{const M=e===me.WORK&&x===C.id;return t.jsxs("button",{onClick:()=>{p(C.id),e!==me.WORK&&n(me.WORK),window.location.hash=um(me.WORK,C.id).slice(1)},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 ${M?"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 ${dz[C.status]??"bg-gray-600"}`}),t.jsx("span",{className:"truncate text-xs",children:C.name})]},C.id)}),_&&!m&&t.jsxs("button",{onClick:()=>f(!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 ",c.length," projects..."]}),t.jsxs("button",{onClick:()=>n(me.DELIVERABLES),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e===me.DELIVERABLES?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(jo,{d:tl[me.DELIVERABLES]}),"Deliverables"]})]})]})},S.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:N,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:N,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.4.18"]})]}),g&&t.jsx(LN,{orgId:s?.orgId,onCreated:()=>{y(!1),w()},onClose:()=>y(!1)})]})}function fz({currentPage:e,onNavigate:n}){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:sk.map(s=>{const i=s.group.includes(e);return t.jsxs("button",{onClick:()=>n(s.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${i?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[t.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:i?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:tl[s.id]})}),t.jsx("span",{className:`text-[10px] leading-tight ${i?"font-semibold":""}`,children:s.label})]},s.id)})})}const g1=[{id:"builder",label:"Builder"},{id:"agents",label:"Agents"},{id:"teams",label:"Teams"},{id:"skills",label:"Skills"}];function hz({authUser:e}){const[n,s]=v.useState("builder"),i=Js(g1,n,s);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:i.onTouchStart,onTouchEnd:i.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:g1.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 ${n===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:[n==="builder"&&t.jsx(Gj,{}),n==="agents"&&t.jsx(Rm,{authUser:e}),n==="teams"&&t.jsx(Om,{}),n==="skills"&&t.jsx(Dm,{})]})]})}const b1=[{id:"settings",label:"Settings"},{id:"reports",label:"Reports"}];function mz({theme:e,onThemeChange:n}){const[s,i]=v.useState("settings"),o=Js(b1,s,i);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:o.onTouchStart,onTouchEnd:o.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:b1.map(d=>t.jsx("button",{onClick:()=>i(d.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===d.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:d.label},d.id))}),t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="settings"&&t.jsx(Uj,{theme:e,onThemeChange:n}),s==="reports"&&t.jsx(HN,{})]})]})}const y1=2;function xz({onComplete:e,theme:n,onThemeChange:s}){const[i,o]=v.useState(0),[d,c]=v.useState(null),[h,m]=v.useState(!1),[f,x]=v.useState({}),[p,g]=v.useState(!1),[y,w]=v.useState(null),[N,T]=v.useState(!1),[_,S]=v.useState(!1),[k,C]=v.useState(null),M=v.useRef(!1),L=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});v.useEffect(()=>{fetch("/api/settings/llm").then(I=>I.ok?I.json():null).then(I=>{I?.providers&&Object.values(I.providers).some(A=>A.configured)&&S(!0)}).catch(()=>{})},[]),v.useEffect(()=>{i===y1&&!M.current&&!_&&(M.current=!0,P())},[i,_]);const P=async()=>{m(!0);try{const I=await fetch("/api/settings/env-models",{headers:L()});if(I.ok){const A=await I.json();if(c(A),A.detected.length>0){const F={};for(const V of A.detected)F[V.provider]=!0;x(F)}}}catch{}finally{m(!1)}},G=async()=>{if(!d)return;const I=d.detected.filter(A=>f[A.provider]);if(I.length!==0){g(!0),C(null);try{const A=await fetch("/api/settings/env-models",{method:"POST",headers:L(),body:JSON.stringify({providers:I.map(F=>({provider:F.provider,model:F.model,baseUrl:F.baseUrl,enabled:!0}))})});if(A.ok){const F=await A.json();C({type:"ok",text:F.message}),S(!0)}else C({type:"err",text:"Failed to apply"})}catch{C({type:"err",text:"Network error"})}finally{g(!1)}}},W=async()=>{T(!0);try{const A=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:L(),body:JSON.stringify({preview:!0})})).json();"error"in A||w(A)}catch{}finally{T(!1)}},z=async()=>{T(!0),C(null);try{const A=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:L(),body:JSON.stringify({preview:!1})})).json();"error"in A?C({type:"err",text:A.error}):(C({type:"ok",text:`Imported ${A.appliedModels} model configs`}),S(!0))}catch{C({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"},{value:"cyberpunk",label:"Cyberpunk",icon:"🔮",desc:"Neon pink, dark violet"},{value:"midnight",label:"Midnight",icon:"🌊",desc:"Deep ocean, teal accents"}],Y=[{title:"Welcome to Markus",subtitle:"Your AI workforce, ready in minutes",content:t.jsxs("div",{className:"space-y-4 text-fg-secondary text-sm leading-relaxed",children:[t.jsxs("p",{children:["Markus runs ",t.jsx("strong",{className:"text-fg-primary",children:"complete AI teams"})," — developers, researchers, writers, analysts that work autonomously, collaborate with each other, and deliver results around the clock."]}),t.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[["24/7 Operation","Agents work while you sleep via heartbeat"],["Team Collaboration","Agents delegate, review, and coordinate"],["Persistent Memory","Five memory layers survive restarts"],["Any LLM Provider","Anthropic, OpenAI, Google, Ollama & more"]].map(([I,A])=>t.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[t.jsx("div",{className:"font-medium text-fg-primary text-xs",children:I}),t.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:A})]},I))})]})},{title:"Choose Your Theme",subtitle:"You can change this anytime in Settings",content:t.jsx("div",{className:"grid grid-cols-3 gap-3",children:q.map(I=>t.jsxs("button",{onClick:()=>s(I.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${n===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:_?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"}),h&&t.jsx("div",{className:"text-xs text-fg-tertiary animate-pulse",children:"Detecting API keys..."}),d&&d.detected.length>0&&t.jsxs("div",{className:"space-y-2",children:[d.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:f[I.provider]??!1,onChange:A=>x({...f,[I.provider]:A.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-sm text-fg-primary",children:I.displayName}),t.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:I.model})]}),t.jsx("code",{className:"text-[10px] text-fg-tertiary",children:I.apiKeyPreview})]},I.provider)),t.jsx("button",{onClick:()=>{G()},disabled:p||Object.values(f).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:p?"Applying...":`Apply ${Object.values(f).filter(Boolean).length} Provider(s)`})]}),d&&d.detected.length===0&&!h&&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"}),y?y.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:y.summary.configPath}),y.summary.models&&t.jsxs("span",{className:"text-fg-tertiary ml-1",children:["(",y.summary.models.providerCount," providers)"]})]}),t.jsx("button",{onClick:()=>{z()},disabled:N,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:N?"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:()=>{W()},disabled:N,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:N?"Detecting...":"Detect OpenClaw Config"})]}),k&&t.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${k.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:k.text})]})},{title:"You're All Set",subtitle:"Start building your AI workforce",content:t.jsx("div",{className:"space-y-2 text-fg-secondary text-sm",children:[["Chat","Talk to agents or use Smart Route to auto-delegate tasks"],["Projects","Create projects with requirements, tasks, and deliverables"],["Builder","Hire new agents from templates or build custom roles"],["Settings","Manage LLM providers, integrations, and governance"]].map(([I,A])=>t.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[t.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),t.jsxs("div",{children:[t.jsx("div",{className:"font-medium text-fg-primary text-xs",children:I}),t.jsx("div",{className:"text-fg-secondary text-xs",children:A})]})]},I))})}],$=()=>{i<Y.length-1?o(i+1):e()},R=Y[i];return t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:t.jsx("div",{className:"w-full max-w-lg",children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl p-8",children:[t.jsx("div",{className:"flex gap-1.5 mb-8",children:Y.map((I,A)=>t.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${A<=i?"bg-brand-500":"bg-surface-elevated"}`},A))}),t.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:R.title}),t.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:R.subtitle}),R.content,t.jsxs("div",{className:"flex justify-between mt-8",children:[i>0?t.jsx("button",{onClick:()=>o(i-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:"Back"}):t.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip"}),t.jsxs("div",{className:"flex items-center gap-3",children:[i===y1&&!_&&t.jsx("button",{onClick:$,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip for now"}),t.jsx("button",{onClick:$,className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-xl transition-colors",children:i===Y.length-1?"Get Started":"Next"})]})]})]})})})}const pz="markus123";function gz({onLogin:e}){const[n,s]=v.useState("admin@markus.local"),[i,o]=v.useState(""),[d,c]=v.useState(""),[h,m]=v.useState(!1),f=async x=>{if(x.preventDefault(),!(!n.trim()||!i)){c(""),m(!0);try{const{user:p}=await se.auth.login(n.trim(),i);e(p,i===pz)}catch{c("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:f,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:n,onChange:x=>s(x.target.value),autoComplete:"email",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Password"}),t.jsx("input",{type:"password",value:i,onChange:x=>o(x.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),d&&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:d}),t.jsx("button",{type:"submit",disabled:h||!n||!i,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all shadow-md shadow-brand-900/40 hover:shadow-lg hover:shadow-brand-900/50",children:h?"Signing in…":"Sign in"}),t.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:"Default: admin@markus.local / markus123"})]})]})]})}function bz({onComplete:e,isFirstTime:n}){const[s,i]=v.useState(""),[o,d]=v.useState(""),[c,h]=v.useState(""),[m,f]=v.useState(""),[x,p]=v.useState(!1),g=async y=>{if(y.preventDefault(),f(""),o.length<6){f("Password must be at least 6 characters");return}if(o!==c){f("Passwords do not match");return}p(!0);try{await se.auth.changePassword(s,o),e()}catch{f("Failed to change password. Check your current password.")}finally{p(!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:g,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:n?"Set Your Password":"Change Password"}),n&&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."})]}),!n&&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:y=>i(y.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:y=>d(y.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:c,onChange:y=>h(y.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||!c,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…":n?"Set Password & Continue":"Change Password"})]})]})]})}const dm={};function yz(){const[e,n]=v.useState(ld),[s,i]=v.useState(()=>!localStorage.getItem("markus_onboarded")),[o,d]=v.useState(!0),c=Cr(),h=D_(),m=au({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[f,x]=v.useState(()=>new Set([ld()])),[p,g]=v.useState("loading"),[y,w]=v.useState(!1),[N,T]=v.useState(null),[_,S]=v.useState(!1),k=v.useCallback(P=>{let G=Qs(P);c&&(G=tk[G]??G);const W=ld(),z=window.location.hash.slice(1);z!==W?dm[W]=z:delete dm[W];const q=G!==me.WORK?dm[G]:void 0;q&&q!==G?(history.pushState(null,"","#"+G),history.pushState(null,"","#"+q)):history.pushState(null,"","#"+G),window.dispatchEvent(new HashChangeEvent("hashchange")),n(G),x(Y=>Y.has(G)?Y:new Set([...Y,G]))},[c]);v.useEffect(()=>{xt.setHandler(P=>k(P))},[k]);const C=v.useCallback(()=>{fetch("/api/settings/llm").then(P=>P.ok?P.json():null).then(P=>{if(P?.providers){const G=Object.values(P.providers).some(W=>W.configured);T(G)}}).catch(()=>{})},[]);v.useEffect(()=>{se.auth.me().then(({user:W})=>{g(W),C(),ai(kr.builderArtifacts,()=>se.builder.artifacts.list()),ai(kr.builderAgents,()=>se.agents.list()),ai(kr.builderHubMyItems,()=>Yn.myItems()),ai(kr.builderInstalled,()=>se.builder.artifacts.installed()),ai(kr.hubAgents,()=>Yn.search({type:"agent",limit:50})),ai(kr.hubTeams,()=>Yn.search({type:"team",limit:50})),ai(kr.hubSkills,()=>Yn.search({type:"skill",limit:50}))}).catch(()=>g(null)),ln.connect();const P=ln.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),G=()=>{const W=ld();n(W),x(z=>z.has(W)?z:new Set([...z,W]))};return window.addEventListener("hashchange",G),()=>{P(),ln.disconnect(),window.removeEventListener("hashchange",G)}},[]);const M=p!=="loading"&&p!==null?p:void 0,L=v.useMemo(()=>c?{[me.HOME]:t.jsx(Tb,{authUser:M}),[me.TEAM]:t.jsx(By,{authUser:M}),[me.BUILDER]:t.jsx(hz,{authUser:M}),[me.SETTINGS]:t.jsx(mz,{theme:h.mode,onThemeChange:h.setMode}),[me.WORK]:t.jsx(f1,{authUser:M}),[me.DELIVERABLES]:t.jsx(x1,{})}:{[me.HOME]:t.jsx(Tb,{}),[me.TEAM]:t.jsx(By,{authUser:M}),[me.SETTINGS]:t.jsx(Uj,{theme:h.mode,onThemeChange:h.setMode}),[me.STORE]:t.jsx(Y_,{authUser:M}),[me.BUILDER]:t.jsx(Gj,{}),[me.WORK]:t.jsx(f1,{authUser:M}),[me.DELIVERABLES]:t.jsx(x1,{}),[me.REPORTS]:t.jsx(HN,{authUser:M})},[M?.id,h.mode,c]);return p==="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…"})}):p===null?t.jsx(gz,{onLogin:(P,G)=>{g(P),G&&w(!0)}}):y?t.jsx(bz,{onComplete:()=>w(!1),isFirstTime:!0}):s?t.jsx(xz,{theme:h.mode,onThemeChange:h.setMode,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),i(!1),C()}}):t.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${c?"flex-col":""}`,children:[!c&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:t.jsx(uz,{currentPage:e,onNavigate:P=>{k(P),d(!1)},authUser:p,onLogout:()=>g(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 ${c?"pb-14":""}`,children:[N===!1&&!_&&e!==me.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:c?"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:()=>{k(me.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:()=>S(!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(L).map(P=>f.has(P)?t.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:P===e?"flex":"none"},children:L[P]},P):null)})]}),c&&t.jsx(fz,{currentPage:e,onNavigate:k})]})}Z2.createRoot(document.getElementById("root")).render(t.jsx(v.StrictMode,{children:t.jsx(yz,{})}));