@markus-global/cli 0.4.9 → 0.4.11

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((g,p)=>g.concat(...p),[]);return[f,x]}return[[],[]]},[e]);return v.useEffect(()=>{const m=r?.target??gv,f=r?.actInsideInputWithModifier??!0;if(e!==null){const x=y=>{if(o.current=y.ctrlKey||y.metaKey||y.shiftKey||y.altKey,(!o.current||o.current&&!f)&&Nw(y))return!1;const N=bv(y.code,h);if(d.current.add(y[N]),pv(c,d.current,!1)){const E=y.composedPath?.()?.[0]||y.target,A=E?.nodeName==="BUTTON"||E?.nodeName==="A";r.preventDefault!==!1&&(o.current||!A)&&y.preventDefault(),l(!0)}},g=y=>{const w=bv(y.code,h);pv(c,d.current,!0)?(l(!1),d.current.clear()):d.current.delete(y[w]),y.key==="Meta"&&d.current.clear(),o.current=!1},p=()=>{d.current.clear(),l(!1)};return m?.addEventListener("keydown",x),m?.addEventListener("keyup",g),window.addEventListener("blur",p),window.addEventListener("contextmenu",p),()=>{m?.removeEventListener("keydown",x),m?.removeEventListener("keyup",g),window.removeEventListener("blur",p),window.removeEventListener("contextmenu",p)}}},[e,l]),s}function pv(e,r,s){return e.filter(l=>s||l.length===r.size).some(l=>l.every(o=>r.has(o)))}function bv(e,r){return r.includes(e)?"code":"key"}const DO=()=>{const e=Cn();return v.useMemo(()=>({zoomIn:r=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1.2,{duration:r?.duration}):Promise.resolve(!1)},zoomOut:r=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1/1.2,{duration:r?.duration}):Promise.resolve(!1)},zoomTo:(r,s)=>{const{panZoom:l}=e.getState();return l?l.scaleTo(r,{duration:s?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(r,s)=>{const{transform:[l,o,d],panZoom:c}=e.getState();return c?(await c.setViewport({x:r.x??l,y:r.y??o,zoom:r.zoom??d},s),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[r,s,l]=e.getState().transform;return{x:r,y:s,zoom:l}},setCenter:async(r,s,l)=>e.getState().setCenter(r,s,l),fitBounds:async(r,s)=>{const{width:l,height:o,minZoom:d,maxZoom:c,panZoom:h}=e.getState(),m=yx(r,l,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:(r,s={})=>{const{transform:l,snapGrid:o,snapToGrid:d,domNode:c}=e.getState();if(!c)return r;const{x:h,y:m}=c.getBoundingClientRect(),f={x:r.x-h,y:r.y-m},x=s.snapGrid??o,g=s.snapToGrid??d;return qo(f,l,g,x)},flowToScreenPosition:r=>{const{transform:s,domNode:l}=e.getState();if(!l)return r;const{x:o,y:d}=l.getBoundingClientRect(),c=Pd(r,s);return{x:c.x+o,y:c.y+d}}}),[])};function Vw(e,r){const s=[],l=new Map,o=[];for(const d of e)if(d.type==="add"){o.push(d);continue}else if(d.type==="remove"||d.type==="replace")l.set(d.id,[d]);else{const c=l.get(d.id);c?c.push(d):l.set(d.id,[d])}for(const d of r){const c=l.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)OO(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 OO(e,r){switch(e.type){case"select":{r.selected=e.selected;break}case"position":{typeof e.position<"u"&&(r.position=e.position),typeof e.dragging<"u"&&(r.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(r.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(r.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(r.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(r.resizing=e.resizing);break}}}function Yw(e,r){return Vw(e,r)}function Gw(e,r){return Vw(e,r)}function Ja(e,r){return{id:e,type:"select",selected:r}}function Xl(e,r=new Set,s=!1){const l=[];for(const[o,d]of e){const c=r.has(o);!(d.selected===void 0&&!c)&&d.selected!==c&&(s&&(d.selected=c),l.push(Ja(d.id,c)))}return l}function yv({items:e=[],lookup:r}){const s=[],l=new Map(e.map(o=>[o.id,o]));for(const[o,d]of e.entries()){const c=r.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 r)l.get(o)===void 0&&s.push({id:o,type:"remove"});return s}function vv(e){return{id:e.id,type:"remove"}}const jv=e=>rD(e),RO=e=>xw(e);function Xw(e){return v.forwardRef(e)}const LO=typeof window<"u"?v.useLayoutEffect:v.useEffect;function wv(e){const[r,s]=v.useState(BigInt(0)),[l]=v.useState(()=>zO(()=>s(o=>o+BigInt(1))));return LO(()=>{const o=l.get();o.length&&(e(o),l.reset())},[r]),l}function zO(e){let r=[];return{get:()=>r,reset:()=>{r=[]},push:s=>{r.push(s),e()}}}const Zw=v.createContext(null);function IO({children:e}){const r=Cn(),s=v.useCallback(h=>{const{nodes:m=[],setNodes:f,hasDefaultNodes:x,onNodesChange:g,nodeLookup:p,fitViewQueued:y,onNodesChangeMiddlewareMap:w}=r.getState();let N=m;for(const A of h)N=typeof A=="function"?A(N):A;let E=yv({items:N,lookup:p});for(const A of w.values())E=A(E);x&&f(N),E.length>0?g?.(E):y&&window.requestAnimationFrame(()=>{const{fitViewQueued:A,nodes:C,setNodes:k}=r.getState();A&&k(C)})},[]),l=wv(s),o=v.useCallback(h=>{const{edges:m=[],setEdges:f,hasDefaultEdges:x,onEdgesChange:g,edgeLookup:p}=r.getState();let y=m;for(const w of h)y=typeof w=="function"?w(y):w;x?f(y):g&&g(yv({items:y,lookup:p}))},[]),d=wv(o),c=v.useMemo(()=>({nodeQueue:l,edgeQueue:d}),[]);return t.jsx(Zw.Provider,{value:c,children:e})}function $O(){const e=v.useContext(Zw);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const BO=e=>!!e.panZoom;function Cx(){const e=DO(),r=Cn(),s=$O(),l=Vt(BO),o=v.useMemo(()=>{const d=g=>r.getState().nodeLookup.get(g),c=g=>{s.nodeQueue.push(g)},h=g=>{s.edgeQueue.push(g)},m=g=>{const{nodeLookup:p,nodeOrigin:y}=r.getState(),w=jv(g)?g:p.get(g.id),N=w.parentId?jw(w.position,w.measured,w.parentId,p,y):w.position,E={...w,position:N,width:w.measured?.width??w.width,height:w.measured?.height??w.height};return si(E)},f=(g,p,y={replace:!1})=>{c(w=>w.map(N=>{if(N.id===g){const E=typeof p=="function"?p(N):p;return y.replace&&jv(E)?E:{...N,...E}}return N}))},x=(g,p,y={replace:!1})=>{h(w=>w.map(N=>{if(N.id===g){const E=typeof p=="function"?p(N):p;return y.replace&&RO(E)?E:{...N,...E}}return N}))};return{getNodes:()=>r.getState().nodes.map(g=>({...g})),getNode:g=>d(g)?.internals.userNode,getInternalNode:d,getEdges:()=>{const{edges:g=[]}=r.getState();return g.map(p=>({...p}))},getEdge:g=>r.getState().edgeLookup.get(g),setNodes:c,setEdges:h,addNodes:g=>{const p=Array.isArray(g)?g:[g];s.nodeQueue.push(y=>[...y,...p])},addEdges:g=>{const p=Array.isArray(g)?g:[g];s.edgeQueue.push(y=>[...y,...p])},toObject:()=>{const{nodes:g=[],edges:p=[],transform:y}=r.getState(),[w,N,E]=y;return{nodes:g.map(A=>({...A})),edges:p.map(A=>({...A})),viewport:{x:w,y:N,zoom:E}}},deleteElements:async({nodes:g=[],edges:p=[]})=>{const{nodes:y,edges:w,onNodesDelete:N,onEdgesDelete:E,triggerNodeChanges:A,triggerEdgeChanges:C,onDelete:k,onBeforeDelete:S}=r.getState(),{nodes:O,edges:R}=await oD({nodesToRemove:g,edgesToRemove:p,nodes:y,edges:w,onBeforeDelete:S}),G=R.length>0,I=O.length>0;if(G){const Q=R.map(vv);E?.(R),C(Q)}if(I){const Q=O.map(vv);N?.(O),A(Q)}return(I||G)&&k?.({nodes:O,edges:R}),{deletedNodes:O,deletedEdges:R}},getIntersectingNodes:(g,p=!0,y)=>{const w=Gy(g),N=w?g:m(g),E=y!==void 0;return N?(y||r.getState().nodes).filter(A=>{const C=r.getState().nodeLookup.get(A.id);if(C&&!w&&(A.id===g.id||!C.internals.positionAbsolute))return!1;const k=si(E?A:C),S=Ao(k,N);return p&&S>0||S>=k.width*k.height||S>=N.width*N.height}):[]},isNodeIntersecting:(g,p,y=!0)=>{const N=Gy(g)?g:m(g);if(!N)return!1;const E=Ao(N,p);return y&&E>0||E>=p.width*p.height||E>=N.width*N.height},updateNode:f,updateNodeData:(g,p,y={replace:!1})=>{f(g,w=>{const N=typeof p=="function"?p(w):p;return y.replace?{...w,data:N}:{...w,data:{...w.data,...N}}},y)},updateEdge:x,updateEdgeData:(g,p,y={replace:!1})=>{x(g,w=>{const N=typeof p=="function"?p(w):p;return y.replace?{...w,data:N}:{...w,data:{...w.data,...N}}},y)},getNodesBounds:g=>{const{nodeLookup:p,nodeOrigin:y}=r.getState();return sD(g,{nodeLookup:p,nodeOrigin:y})},getHandleConnections:({type:g,id:p,nodeId:y})=>Array.from(r.getState().connectionLookup.get(`${y}-${g}${p?`-${p}`:""}`)?.values()??[]),getNodeConnections:({type:g,handleId:p,nodeId:y})=>Array.from(r.getState().connectionLookup.get(`${y}${g?p?`-${g}-${p}`:`-${g}`:""}`)?.values()??[]),fitView:async g=>{const p=r.getState().fitViewResolver??fD();return r.setState({fitViewQueued:!0,fitViewOptions:g,fitViewResolver:p}),s.nodeQueue.push(y=>[...y]),p.promise}}},[]);return v.useMemo(()=>({...o,...e,viewportInitialized:l}),[l])}const Nv=e=>e.selected,HO=typeof window<"u"?window:void 0;function PO({deleteKeyCode:e,multiSelectionKeyCode:r}){const s=Cn(),{deleteElements:l}=Cx(),o=Mo(e,{actInsideInputWithModifier:!1}),d=Mo(r,{target:HO});v.useEffect(()=>{if(o){const{edges:c,nodes:h}=s.getState();l({nodes:h.filter(Nv),edges:c.filter(Nv)}),s.setState({nodesSelectionActive:!1})}},[o]),v.useEffect(()=>{s.setState({multiSelectionActive:d})},[d])}function UO(e){const r=Cn();v.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const l=vx(e.current);(l.height===0||l.width===0)&&r.getState().onError?.("004",ws.error004()),r.setState({width:l.width||500,height:l.height||500})};if(e.current){s(),window.addEventListener("resize",s);const l=new ResizeObserver(()=>s());return l.observe(e.current),()=>{window.removeEventListener("resize",s),l&&e.current&&l.unobserve(e.current)}}},[])}const du={position:"absolute",width:"100%",height:"100%",top:0,left:0},qO=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function FO({onPaneContextMenu:e,zoomOnScroll:r=!0,zoomOnPinch:s=!0,panOnScroll:l=!1,panOnScrollSpeed:o=.5,panOnScrollMode:d=nl.Free,zoomOnDoubleClick:c=!0,panOnDrag:h=!0,defaultViewport:m,translateExtent:f,minZoom:x,maxZoom:g,zoomActivationKeyCode:p,preventScrolling:y=!0,children:w,noWheelClassName:N,noPanClassName:E,onViewportChange:A,isControlledViewport:C,paneClickDistance:k,selectionOnDrag:S}){const O=Cn(),R=v.useRef(null),{userSelectionActive:G,lib:I,connectionInProgress:Q}=Vt(qO,Sn),$=Mo(p),F=v.useRef();UO(R);const B=v.useCallback(T=>{A?.({x:T[0],y:T[1],zoom:T[2]}),C||O.setState({transform:T})},[A,C]);return v.useEffect(()=>{if(R.current){F.current=ZD({domNode:R.current,minZoom:x,maxZoom:g,translateExtent:f,viewport:m,onDraggingChange:_=>O.setState(Y=>Y.paneDragging===_?Y:{paneDragging:_}),onPanZoomStart:(_,Y)=>{const{onViewportChangeStart:V,onMoveStart:J}=O.getState();J?.(_,Y),V?.(Y)},onPanZoom:(_,Y)=>{const{onViewportChange:V,onMove:J}=O.getState();J?.(_,Y),V?.(Y)},onPanZoomEnd:(_,Y)=>{const{onViewportChangeEnd:V,onMoveEnd:J}=O.getState();J?.(_,Y),V?.(Y)}});const{x:T,y:D,zoom:z}=F.current.getViewport();return O.setState({panZoom:F.current,transform:[T,D,z],domNode:R.current.closest(".react-flow")}),()=>{F.current?.destroy()}}},[]),v.useEffect(()=>{F.current?.update({onPaneContextMenu:e,zoomOnScroll:r,zoomOnPinch:s,panOnScroll:l,panOnScrollSpeed:o,panOnScrollMode:d,zoomOnDoubleClick:c,panOnDrag:h,zoomActivationKeyPressed:$,preventScrolling:y,noPanClassName:E,userSelectionActive:G,noWheelClassName:N,lib:I,onTransformChange:B,connectionInProgress:Q,selectionOnDrag:S,paneClickDistance:k})},[e,r,s,l,o,d,c,h,$,y,E,G,N,I,B,Q,S,k]),t.jsx("div",{className:"react-flow__renderer",ref:R,style:du,children:w})}const VO=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function YO(){const{userSelectionActive:e,userSelectionRect:r}=Vt(VO,Sn);return e&&r?t.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:r.width,height:r.height,transform:`translate(${r.x}px, ${r.y}px)`}}):null}const Jh=(e,r)=>s=>{s.target===r.current&&e?.(s)},GO=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function XO({isSelecting:e,selectionKeyPressed:r,selectionMode:s=To.Full,panOnDrag:l,paneClickDistance:o,selectionOnDrag:d,onSelectionStart:c,onSelectionEnd:h,onPaneClick:m,onPaneContextMenu:f,onPaneScroll:x,onPaneMouseEnter:g,onPaneMouseMove:p,onPaneMouseLeave:y,children:w}){const N=Cn(),{userSelectionActive:E,elementsSelectable:A,dragging:C,connectionInProgress:k}=Vt(GO,Sn),S=A&&(e||E),O=v.useRef(null),R=v.useRef(),G=v.useRef(new Set),I=v.useRef(new Set),Q=v.useRef(!1),$=V=>{if(Q.current||k){Q.current=!1;return}m?.(V),N.getState().resetSelectedElements(),N.setState({nodesSelectionActive:!1})},F=V=>{if(Array.isArray(l)&&l?.includes(2)){V.preventDefault();return}f?.(V)},B=x?V=>x(V):void 0,T=V=>{Q.current&&(V.stopPropagation(),Q.current=!1)},D=V=>{const{domNode:J}=N.getState();if(R.current=J?.getBoundingClientRect(),!R.current)return;const U=V.target===O.current;if(!U&&!!V.target.closest(".nokey")||!e||!(d&&U||r)||V.button!==0||!V.isPrimary)return;V.target?.setPointerCapture?.(V.pointerId),Q.current=!1;const{x:L,y:M}=ss(V.nativeEvent,R.current);N.setState({userSelectionRect:{width:0,height:0,startX:L,startY:M,x:L,y:M}}),U||(V.stopPropagation(),V.preventDefault())},z=V=>{const{userSelectionRect:J,transform:U,nodeLookup:H,edgeLookup:X,connectionLookup:L,triggerNodeChanges:M,triggerEdgeChanges:q,defaultEdgeOptions:K,resetSelectedElements:ee}=N.getState();if(!R.current||!J)return;const{x:te,y:se}=ss(V.nativeEvent,R.current),{startX:xe,startY:ke}=J;if(!Q.current){const ze=r?0:o;if(Math.hypot(te-xe,se-ke)<=ze)return;ee(),c?.(V)}Q.current=!0;const De={startX:xe,startY:ke,x:te<xe?te:xe,y:se<ke?se:ke,width:Math.abs(te-xe),height:Math.abs(se-ke)},ge=G.current,ye=I.current;G.current=new Set(bx(H,De,U,s===To.Partial,!0).map(ze=>ze.id)),I.current=new Set;const Ce=K?.selectable??!0;for(const ze of G.current){const tt=L.get(ze);if(tt)for(const{edgeId:Xe}of tt.values()){const dt=X.get(Xe);dt&&(dt.selectable??Ce)&&I.current.add(Xe)}}if(!Xy(ge,G.current)){const ze=Xl(H,G.current,!0);M(ze)}if(!Xy(ye,I.current)){const ze=Xl(X,I.current);q(ze)}N.setState({userSelectionRect:De,userSelectionActive:!0,nodesSelectionActive:!1})},_=V=>{V.button===0&&(V.target?.releasePointerCapture?.(V.pointerId),!E&&V.target===O.current&&N.getState().userSelectionRect&&$?.(V),N.setState({userSelectionActive:!1,userSelectionRect:null}),Q.current&&(h?.(V),N.setState({nodesSelectionActive:G.current.size>0})))},Y=l===!0||Array.isArray(l)&&l.includes(0);return t.jsxs("div",{className:Fn(["react-flow__pane",{draggable:Y,dragging:C,selection:e}]),onClick:S?void 0:Jh($,O),onContextMenu:Jh(F,O),onWheel:Jh(B,O),onPointerEnter:S?void 0:g,onPointerMove:S?z:p,onPointerUp:S?_:void 0,onPointerDownCapture:S?D:void 0,onClickCapture:S?T:void 0,onPointerLeave:y,ref:O,style:du,children:[w,t.jsx(YO,{})]})}function zm({id:e,store:r,unselect:s=!1,nodeRef:l}){const{addSelectedNodes:o,unselectNodesAndEdges:d,multiSelectionActive:c,nodeLookup:h,onError:m}=r.getState(),f=h.get(e);if(!f){m?.("012",ws.error012(e));return}r.setState({nodesSelectionActive:!1}),f.selected?(s||f.selected&&c)&&(d({nodes:[f],edges:[]}),requestAnimationFrame(()=>l?.current?.blur())):o([e])}function Qw({nodeRef:e,disabled:r=!1,noDragClassName:s,handleSelector:l,nodeId:o,isSelectable:d,nodeClickDistance:c}){const h=Cn(),[m,f]=v.useState(!1),x=v.useRef();return v.useEffect(()=>{x.current=LD({getStoreItems:()=>h.getState(),onNodeMouseDown:g=>{zm({id:g,store:h,nodeRef:e})},onDragStart:()=>{f(!0)},onDragStop:()=>{f(!1)}})},[]),v.useEffect(()=>{if(!(r||!e.current||!x.current))return x.current.update({noDragClassName:s,handleSelector:l,domNode:e.current,isSelectable:d,nodeId:o,nodeClickDistance:c}),()=>{x.current?.destroy()}},[s,l,r,d,e,o,c]),m}const ZO=e=>r=>r.selected&&(r.draggable||e&&typeof r.draggable>"u");function Kw(){const e=Cn();return v.useCallback(s=>{const{nodeExtent:l,snapToGrid:o,snapGrid:d,nodesDraggable:c,onError:h,updateNodePositions:m,nodeLookup:f,nodeOrigin:x}=e.getState(),g=new Map,p=ZO(c),y=o?d[0]:5,w=o?d[1]:5,N=s.direction.x*y*s.factor,E=s.direction.y*w*s.factor;for(const[,A]of f){if(!p(A))continue;let C={x:A.internals.positionAbsolute.x+N,y:A.internals.positionAbsolute.y+E};o&&(C=Uo(C,d));const{position:k,positionAbsolute:S}=gw({nodeId:A.id,nextPosition:C,nodeLookup:f,nodeExtent:l,nodeOrigin:x,onError:h});A.position=k,A.internals.positionAbsolute=S,g.set(A.id,A)}m(g)},[])}const Ex=v.createContext(null),QO=Ex.Provider;Ex.Consumer;const Jw=()=>v.useContext(Ex),KO=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),JO=(e,r,s)=>l=>{const{connectionClickStartHandle:o,connectionMode:d,connection:c}=l,{fromHandle:h,toHandle:m,isValid:f}=c,x=m?.nodeId===e&&m?.id===r&&m?.type===s;return{connectingFrom:h?.nodeId===e&&h?.id===r&&h?.type===s,connectingTo:x,clickConnecting:o?.nodeId===e&&o?.id===r&&o?.type===s,isPossibleEndHandle:d===ti.Strict?h?.type!==s:e!==h?.nodeId||r!==h?.id,connectionInProcess:!!h,clickConnectionInProcess:!!o,valid:x&&f}};function WO({type:e="source",position:r=lt.Top,isValidConnection:s,isConnectable:l=!0,isConnectableStart:o=!0,isConnectableEnd:d=!0,id:c,onConnect:h,children:m,className:f,onMouseDown:x,onTouchStart:g,...p},y){const w=c||null,N=e==="target",E=Cn(),A=Jw(),{connectOnClick:C,noPanClassName:k,rfId:S}=Vt(KO,Sn),{connectingFrom:O,connectingTo:R,clickConnecting:G,isPossibleEndHandle:I,connectionInProcess:Q,clickConnectionInProcess:$,valid:F}=Vt(JO(A,w,e),Sn);A||E.getState().onError?.("010",ws.error010());const B=z=>{const{defaultEdgeOptions:_,onConnect:Y,hasDefaultEdges:V}=E.getState(),J={..._,...z};if(V){const{edges:U,setEdges:H}=E.getState();H(yD(J,U))}Y?.(J),h?.(J)},T=z=>{if(!A)return;const _=kw(z.nativeEvent);if(o&&(_&&z.button===0||!_)){const Y=E.getState();Lm.onPointerDown(z.nativeEvent,{handleDomNode:z.currentTarget,autoPanOnConnect:Y.autoPanOnConnect,connectionMode:Y.connectionMode,connectionRadius:Y.connectionRadius,domNode:Y.domNode,nodeLookup:Y.nodeLookup,lib:Y.lib,isTarget:N,handleId:w,nodeId:A,flowId:Y.rfId,panBy:Y.panBy,cancelConnection:Y.cancelConnection,onConnectStart:Y.onConnectStart,onConnectEnd:(...V)=>E.getState().onConnectEnd?.(...V),updateConnection:Y.updateConnection,onConnect:B,isValidConnection:s||((...V)=>E.getState().isValidConnection?.(...V)??!0),getTransform:()=>E.getState().transform,getFromHandle:()=>E.getState().connection.fromHandle,autoPanSpeed:Y.autoPanSpeed,dragThreshold:Y.connectionDragThreshold})}_?x?.(z):g?.(z)},D=z=>{const{onClickConnectStart:_,onClickConnectEnd:Y,connectionClickStartHandle:V,connectionMode:J,isValidConnection:U,lib:H,rfId:X,nodeLookup:L,connection:M}=E.getState();if(!A||!V&&!o)return;if(!V){_?.(z.nativeEvent,{nodeId:A,handleId:w,handleType:e}),E.setState({connectionClickStartHandle:{nodeId:A,type:e,id:w}});return}const q=ww(z.target),K=s||U,{connection:ee,isValid:te}=Lm.isValid(z.nativeEvent,{handle:{nodeId:A,id:w,type:e},connectionMode:J,fromNodeId:V.nodeId,fromHandleId:V.id||null,fromType:V.type,isValidConnection:K,flowId:X,doc:q,lib:H,nodeLookup:L});te&&ee&&B(ee);const se=structuredClone(M);delete se.inProgress,se.toPosition=se.toHandle?se.toHandle.position:null,Y?.(z,se),E.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":w,"data-nodeid":A,"data-handlepos":r,"data-id":`${S}-${A}-${w}-${e}`,className:Fn(["react-flow__handle",`react-flow__handle-${r}`,"nodrag",k,f,{source:!N,target:N,connectable:l,connectablestart:o,connectableend:d,clickconnecting:G,connectingfrom:O,connectingto:R,valid:F,connectionindicator:l&&(!Q||I)&&(Q||$?d:o)}]),onMouseDown:T,onTouchStart:T,onClick:C?D:void 0,ref:y,...p,children:m})}const Ma=v.memo(Xw(WO));function eR({data:e,isConnectable:r,sourcePosition:s=lt.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(Ma,{type:"source",position:s,isConnectable:r})]})}function tR({data:e,isConnectable:r,targetPosition:s=lt.Top,sourcePosition:l=lt.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(Ma,{type:"target",position:s,isConnectable:r}),e?.label,t.jsx(Ma,{type:"source",position:l,isConnectable:r})]})}function nR(){return null}function rR({data:e,isConnectable:r,targetPosition:s=lt.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(Ma,{type:"target",position:s,isConnectable:r}),e?.label]})}const Ud={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},kv={input:eR,default:tR,output:rR,group:nR};function sR(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 aR=e=>{const{width:r,height:s,x:l,y:o}=Po(e.nodeLookup,{filter:d=>!!d.selected});return{width:rs(r)?r:null,height:rs(s)?s:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${l}px,${o}px)`}};function lR({onSelectionContextMenu:e,noPanClassName:r,disableKeyboardA11y:s}){const l=Cn(),{width:o,height:d,transformString:c,userSelectionActive:h}=Vt(aR,Sn),m=Kw(),f=v.useRef(null);v.useEffect(()=>{s||f.current?.focus({preventScroll:!0})},[s]);const x=!h&&o!==null&&d!==null;if(Qw({nodeRef:f,disabled:!x}),!x)return null;const g=e?y=>{const w=l.getState().nodes.filter(N=>N.selected);e(y,w)}:void 0,p=y=>{Object.prototype.hasOwnProperty.call(Ud,y.key)&&(y.preventDefault(),m({direction:Ud[y.key],factor:y.shiftKey?4:1}))};return t.jsx("div",{className:Fn(["react-flow__nodesselection","react-flow__container",r]),style:{transform:c},children:t.jsx("div",{ref:f,className:"react-flow__nodesselection-rect",onContextMenu:g,tabIndex:s?void 0:-1,onKeyDown:s?void 0:p,style:{width:o,height:d}})})}const Sv=typeof window<"u"?window:void 0,iR=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Ww({children:e,onPaneClick:r,onPaneMouseEnter:s,onPaneMouseMove:l,onPaneMouseLeave:o,onPaneContextMenu:d,onPaneScroll:c,paneClickDistance:h,deleteKeyCode:m,selectionKeyCode:f,selectionOnDrag:x,selectionMode:g,onSelectionStart:p,onSelectionEnd:y,multiSelectionKeyCode:w,panActivationKeyCode:N,zoomActivationKeyCode:E,elementsSelectable:A,zoomOnScroll:C,zoomOnPinch:k,panOnScroll:S,panOnScrollSpeed:O,panOnScrollMode:R,zoomOnDoubleClick:G,panOnDrag:I,defaultViewport:Q,translateExtent:$,minZoom:F,maxZoom:B,preventScrolling:T,onSelectionContextMenu:D,noWheelClassName:z,noPanClassName:_,disableKeyboardA11y:Y,onViewportChange:V,isControlledViewport:J}){const{nodesSelectionActive:U,userSelectionActive:H}=Vt(iR,Sn),X=Mo(f,{target:Sv}),L=Mo(N,{target:Sv}),M=L||I,q=L||S,K=x&&M!==!0,ee=X||H||K;return PO({deleteKeyCode:m,multiSelectionKeyCode:w}),t.jsx(FO,{onPaneContextMenu:d,elementsSelectable:A,zoomOnScroll:C,zoomOnPinch:k,panOnScroll:q,panOnScrollSpeed:O,panOnScrollMode:R,zoomOnDoubleClick:G,panOnDrag:!X&&M,defaultViewport:Q,translateExtent:$,minZoom:F,maxZoom:B,zoomActivationKeyCode:E,preventScrolling:T,noWheelClassName:z,noPanClassName:_,onViewportChange:V,isControlledViewport:J,paneClickDistance:h,selectionOnDrag:K,children:t.jsxs(XO,{onSelectionStart:p,onSelectionEnd:y,onPaneClick:r,onPaneMouseEnter:s,onPaneMouseMove:l,onPaneMouseLeave:o,onPaneContextMenu:d,onPaneScroll:c,panOnDrag:M,isSelecting:!!ee,selectionMode:g,selectionKeyPressed:X,paneClickDistance:h,selectionOnDrag:K,children:[e,U&&t.jsx(lR,{onSelectionContextMenu:D,noPanClassName:_,disableKeyboardA11y:Y})]})})}Ww.displayName="FlowRenderer";const oR=v.memo(Ww),cR=e=>r=>e?bx(r.nodeLookup,{x:0,y:0,width:r.width,height:r.height},r.transform,!0).map(s=>s.id):Array.from(r.nodeLookup.keys());function dR(e){return Vt(v.useCallback(cR(e),[e]),Sn)}const uR=e=>e.updateNodeInternals;function fR(){const e=Vt(uR),[r]=v.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const l=new Map;s.forEach(o=>{const d=o.target.getAttribute("data-id");l.set(d,{id:d,nodeElement:o.target,force:!0})}),e(l)}));return v.useEffect(()=>()=>{r?.disconnect()},[r]),r}function hR({node:e,nodeType:r,hasDimensions:s,resizeObserver:l}){const o=Cn(),d=v.useRef(null),c=v.useRef(null),h=v.useRef(e.sourcePosition),m=v.useRef(e.targetPosition),f=v.useRef(r),x=s&&!!e.internals.handleBounds;return v.useEffect(()=>{d.current&&!e.hidden&&(!x||c.current!==d.current)&&(c.current&&l?.unobserve(c.current),l?.observe(d.current),c.current=d.current)},[x,e.hidden]),v.useEffect(()=>()=>{c.current&&(l?.unobserve(c.current),c.current=null)},[]),v.useEffect(()=>{if(d.current){const g=f.current!==r,p=h.current!==e.sourcePosition,y=m.current!==e.targetPosition;(g||p||y)&&(f.current=r,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,r,e.sourcePosition,e.targetPosition]),d}function mR({id:e,onClick:r,onMouseEnter:s,onMouseMove:l,onMouseLeave:o,onContextMenu:d,onDoubleClick:c,nodesDraggable:h,elementsSelectable:m,nodesConnectable:f,nodesFocusable:x,resizeObserver:g,noDragClassName:p,noPanClassName:y,disableKeyboardA11y:w,rfId:N,nodeTypes:E,nodeClickDistance:A,onError:C}){const{node:k,internals:S,isParent:O}=Vt(te=>{const se=te.nodeLookup.get(e),xe=te.parentLookup.has(e);return{node:se,internals:se.internals,isParent:xe}},Sn);let R=k.type||"default",G=E?.[R]||kv[R];G===void 0&&(C?.("003",ws.error003(R)),R="default",G=E?.default||kv.default);const I=!!(k.draggable||h&&typeof k.draggable>"u"),Q=!!(k.selectable||m&&typeof k.selectable>"u"),$=!!(k.connectable||f&&typeof k.connectable>"u"),F=!!(k.focusable||x&&typeof k.focusable>"u"),B=Cn(),T=vw(k),D=hR({node:k,nodeType:R,hasDimensions:T,resizeObserver:g}),z=Qw({nodeRef:D,disabled:k.hidden||!I,noDragClassName:p,handleSelector:k.dragHandle,nodeId:e,isSelectable:Q,nodeClickDistance:A}),_=Kw();if(k.hidden)return null;const Y=Ks(k),V=sR(k),J=Q||I||r||s||l||o,U=s?te=>s(te,{...S.userNode}):void 0,H=l?te=>l(te,{...S.userNode}):void 0,X=o?te=>o(te,{...S.userNode}):void 0,L=d?te=>d(te,{...S.userNode}):void 0,M=c?te=>c(te,{...S.userNode}):void 0,q=te=>{const{selectNodesOnDrag:se,nodeDragThreshold:xe}=B.getState();Q&&(!se||!I||xe>0)&&zm({id:e,store:B,nodeRef:D}),r&&r(te,{...S.userNode})},K=te=>{if(!(Nw(te.nativeEvent)||w)){if(uw.includes(te.key)&&Q){const se=te.key==="Escape";zm({id:e,store:B,unselect:se,nodeRef:D})}else if(I&&k.selected&&Object.prototype.hasOwnProperty.call(Ud,te.key)){te.preventDefault();const{ariaLabelConfig:se}=B.getState();B.setState({ariaLiveMessage:se["node.a11yDescription.ariaLiveMessage"]({direction:te.key.replace("Arrow","").toLowerCase(),x:~~S.positionAbsolute.x,y:~~S.positionAbsolute.y})}),_({direction:Ud[te.key],factor:te.shiftKey?4:1})}}},ee=()=>{if(w||!D.current?.matches(":focus-visible"))return;const{transform:te,width:se,height:xe,autoPanOnNodeFocus:ke,setCenter:De}=B.getState();if(!ke)return;bx(new Map([[e,k]]),{x:0,y:0,width:se,height:xe},te,!0).length>0||De(k.position.x+Y.width/2,k.position.y+Y.height/2,{zoom:te[2]})};return t.jsx("div",{className:Fn(["react-flow__node",`react-flow__node-${R}`,{[y]:I},k.className,{selected:k.selected,selectable:Q,parent:O,draggable:I,dragging:z}]),ref:D,style:{zIndex:S.z,transform:`translate(${S.positionAbsolute.x}px,${S.positionAbsolute.y}px)`,pointerEvents:J?"all":"none",visibility:T?"visible":"hidden",...k.style,...V},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:U,onMouseMove:H,onMouseLeave:X,onContextMenu:L,onClick:q,onDoubleClick:M,onKeyDown:F?K:void 0,tabIndex:F?0:void 0,onFocus:F?ee:void 0,role:k.ariaRole??(F?"group":void 0),"aria-roledescription":"node","aria-describedby":w?void 0:`${Uw}-${N}`,"aria-label":k.ariaLabel,...k.domAttributes,children:t.jsx(QO,{value:e,children:t.jsx(G,{id:e,data:k.data,type:R,positionAbsoluteX:S.positionAbsolute.x,positionAbsoluteY:S.positionAbsolute.y,selected:k.selected??!1,selectable:Q,draggable:I,deletable:k.deletable??!0,isConnectable:$,sourcePosition:k.sourcePosition,targetPosition:k.targetPosition,dragging:z,dragHandle:k.dragHandle,zIndex:S.z,parentId:k.parentId,...Y})})})}var xR=v.memo(mR);const gR=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function eN(e){const{nodesDraggable:r,nodesConnectable:s,nodesFocusable:l,elementsSelectable:o,onError:d}=Vt(gR,Sn),c=dR(e.onlyRenderVisibleElements),h=fR();return t.jsx("div",{className:"react-flow__nodes",style:du,children:c.map(m=>t.jsx(xR,{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:r,nodesConnectable:s,nodesFocusable:l,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:d},m))})}eN.displayName="NodeRenderer";const pR=v.memo(eN);function bR(e){return Vt(v.useCallback(s=>{if(!e)return s.edges.map(o=>o.id);const l=[];if(s.width&&s.height)for(const o of s.edges){const d=s.nodeLookup.get(o.source),c=s.nodeLookup.get(o.target);d&&c&&gD({sourceNode:d,targetNode:c,width:s.width,height:s.height,transform:s.transform})&&l.push(o.id)}return l},[e]),Sn)}const yR=({color:e="none",strokeWidth:r=1})=>{const s={strokeWidth:r,...e&&{stroke:e}};return t.jsx("polyline",{className:"arrow",style:s,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},vR=({color:e="none",strokeWidth:r=1})=>{const s={strokeWidth:r,...e&&{stroke:e,fill:e}};return t.jsx("polyline",{className:"arrowclosed",style:s,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Cv={[ni.Arrow]:yR,[ni.ArrowClosed]:vR};function jR(e){const r=Cn();return v.useMemo(()=>Object.prototype.hasOwnProperty.call(Cv,e)?Cv[e]:(r.getState().onError?.("009",ws.error009(e)),null),[e])}const wR=({id:e,type:r,color:s,width:l=12.5,height:o=12.5,markerUnits:d="strokeWidth",strokeWidth:c,orient:h="auto-start-reverse"})=>{const m=jR(r);return m?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${l}`,markerHeight:`${o}`,viewBox:"-10 -10 20 20",markerUnits:d,orient:h,refX:"0",refY:"0",children:t.jsx(m,{color:s,strokeWidth:c})}):null},tN=({defaultColor:e,rfId:r})=>{const s=Vt(d=>d.edges),l=Vt(d=>d.defaultEdgeOptions),o=v.useMemo(()=>kD(s,{id:r,defaultColor:e,defaultMarkerStart:l?.markerStart,defaultMarkerEnd:l?.markerEnd}),[s,l,r,e]);return o.length?t.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:t.jsx("defs",{children:o.map(d=>t.jsx(wR,{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};tN.displayName="MarkerDefinitions";var NR=v.memo(tN);function nN({x:e,y:r,label:s,labelStyle:l,labelShowBg:o=!0,labelBgStyle:d,labelBgPadding:c=[2,4],labelBgBorderRadius:h=2,children:m,className:f,...x}){const[g,p]=v.useState({x:1,y:0,width:0,height:0}),y=Fn(["react-flow__edge-textwrapper",f]),w=v.useRef(null);return v.useEffect(()=>{if(w.current){const N=w.current.getBBox();p({x:N.x,y:N.y,width:N.width,height:N.height})}},[s]),s?t.jsxs("g",{transform:`translate(${e-g.width/2} ${r-g.height/2})`,className:y,visibility:g.width?"visible":"hidden",...x,children:[o&&t.jsx("rect",{width:g.width+2*c[0],x:-c[0],y:-c[1],height:g.height+2*c[1],className:"react-flow__edge-textbg",style:d,rx:h,ry:h}),t.jsx("text",{className:"react-flow__edge-text",y:g.height/2,dy:"0.3em",ref:w,style:l,children:s}),m]}):null}nN.displayName="EdgeText";const kR=v.memo(nN);function uu({path:e,labelX:r,labelY:s,label:l,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:Fn(["react-flow__edge-path",x.className])}),f?t.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}):null,l&&rs(r)&&rs(s)?t.jsx(kR,{x:r,y:s,label:l,labelStyle:o,labelShowBg:d,labelBgStyle:c,labelBgPadding:h,labelBgBorderRadius:m}):null]})}function Ev({pos:e,x1:r,y1:s,x2:l,y2:o}){return e===lt.Left||e===lt.Right?[.5*(r+l),s]:[r,.5*(s+o)]}function rN({sourceX:e,sourceY:r,sourcePosition:s=lt.Bottom,targetX:l,targetY:o,targetPosition:d=lt.Top}){const[c,h]=Ev({pos:s,x1:e,y1:r,x2:l,y2:o}),[m,f]=Ev({pos:d,x1:l,y1:o,x2:e,y2:r}),[x,g,p,y]=Sw({sourceX:e,sourceY:r,targetX:l,targetY:o,sourceControlX:c,sourceControlY:h,targetControlX:m,targetControlY:f});return[`M${e},${r} C${c},${h} ${m},${f} ${l},${o}`,x,g,p,y]}function sN(e){return v.memo(({id:r,sourceX:s,sourceY:l,targetX:o,targetY:d,sourcePosition:c,targetPosition:h,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:g,labelBgPadding:p,labelBgBorderRadius:y,style:w,markerEnd:N,markerStart:E,interactionWidth:A})=>{const[C,k,S]=rN({sourceX:s,sourceY:l,sourcePosition:c,targetX:o,targetY:d,targetPosition:h}),O=e.isInternal?void 0:r;return t.jsx(uu,{id:O,path:C,labelX:k,labelY:S,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:g,labelBgPadding:p,labelBgBorderRadius:y,style:w,markerEnd:N,markerStart:E,interactionWidth:A})})}const SR=sN({isInternal:!1}),aN=sN({isInternal:!0});SR.displayName="SimpleBezierEdge";aN.displayName="SimpleBezierEdgeInternal";function lN(e){return v.memo(({id:r,sourceX:s,sourceY:l,targetX:o,targetY:d,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:g,style:p,sourcePosition:y=lt.Bottom,targetPosition:w=lt.Top,markerEnd:N,markerStart:E,pathOptions:A,interactionWidth:C})=>{const[k,S,O]=Dm({sourceX:s,sourceY:l,sourcePosition:y,targetX:o,targetY:d,targetPosition:w,borderRadius:A?.borderRadius,offset:A?.offset,stepPosition:A?.stepPosition}),R=e.isInternal?void 0:r;return t.jsx(uu,{id:R,path:k,labelX:S,labelY:O,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:g,style:p,markerEnd:N,markerStart:E,interactionWidth:C})})}const iN=lN({isInternal:!1}),oN=lN({isInternal:!0});iN.displayName="SmoothStepEdge";oN.displayName="SmoothStepEdgeInternal";function cN(e){return v.memo(({id:r,...s})=>{const l=e.isInternal?void 0:r;return t.jsx(iN,{...s,id:l,pathOptions:v.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const CR=cN({isInternal:!1}),dN=cN({isInternal:!0});CR.displayName="StepEdge";dN.displayName="StepEdgeInternal";function uN(e){return v.memo(({id:r,sourceX:s,sourceY:l,targetX:o,targetY:d,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:g,style:p,markerEnd:y,markerStart:w,interactionWidth:N})=>{const[E,A,C]=Tw({sourceX:s,sourceY:l,targetX:o,targetY:d}),k=e.isInternal?void 0:r;return t.jsx(uu,{id:k,path:E,labelX:A,labelY:C,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:g,style:p,markerEnd:y,markerStart:w,interactionWidth:N})})}const ER=uN({isInternal:!1}),fN=uN({isInternal:!0});ER.displayName="StraightEdge";fN.displayName="StraightEdgeInternal";function hN(e){return v.memo(({id:r,sourceX:s,sourceY:l,targetX:o,targetY:d,sourcePosition:c=lt.Bottom,targetPosition:h=lt.Top,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:g,labelBgPadding:p,labelBgBorderRadius:y,style:w,markerEnd:N,markerStart:E,pathOptions:A,interactionWidth:C})=>{const[k,S,O]=Cw({sourceX:s,sourceY:l,sourcePosition:c,targetX:o,targetY:d,targetPosition:h,curvature:A?.curvature}),R=e.isInternal?void 0:r;return t.jsx(uu,{id:R,path:k,labelX:S,labelY:O,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:g,labelBgPadding:p,labelBgBorderRadius:y,style:w,markerEnd:N,markerStart:E,interactionWidth:C})})}const TR=hN({isInternal:!1}),mN=hN({isInternal:!0});TR.displayName="BezierEdge";mN.displayName="BezierEdgeInternal";const Tv={default:mN,straight:fN,step:dN,smoothstep:oN,simplebezier:aN},Av={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},AR=(e,r,s)=>s===lt.Left?e-r:s===lt.Right?e+r:e,_R=(e,r,s)=>s===lt.Top?e-r:s===lt.Bottom?e+r:e,_v="react-flow__edgeupdater";function Mv({position:e,centerX:r,centerY:s,radius:l=10,onMouseDown:o,onMouseEnter:d,onMouseOut:c,type:h}){return t.jsx("circle",{onMouseDown:o,onMouseEnter:d,onMouseOut:c,className:Fn([_v,`${_v}-${h}`]),cx:AR(r,l,e),cy:_R(s,l,e),r:l,stroke:"transparent",fill:"transparent"})}function MR({isReconnectable:e,reconnectRadius:r,edge:s,sourceX:l,sourceY:o,targetX:d,targetY:c,sourcePosition:h,targetPosition:m,onReconnect:f,onReconnectStart:x,onReconnectEnd:g,setReconnecting:p,setUpdateHover:y}){const w=Cn(),N=(S,O)=>{if(S.button!==0)return;const{autoPanOnConnect:R,domNode:G,connectionMode:I,connectionRadius:Q,lib:$,onConnectStart:F,cancelConnection:B,nodeLookup:T,rfId:D,panBy:z,updateConnection:_}=w.getState(),Y=O.type==="target",V=(H,X)=>{p(!1),g?.(H,s,O.type,X)},J=H=>f?.(s,H),U=(H,X)=>{p(!0),x?.(S,s,O.type),F?.(H,X)};Lm.onPointerDown(S.nativeEvent,{autoPanOnConnect:R,connectionMode:I,connectionRadius:Q,domNode:G,handleId:O.id,nodeId:O.nodeId,nodeLookup:T,isTarget:Y,edgeUpdaterType:O.type,lib:$,flowId:D,cancelConnection:B,panBy:z,isValidConnection:(...H)=>w.getState().isValidConnection?.(...H)??!0,onConnect:J,onConnectStart:U,onConnectEnd:(...H)=>w.getState().onConnectEnd?.(...H),onReconnectEnd:V,updateConnection:_,getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,dragThreshold:w.getState().connectionDragThreshold,handleDomNode:S.currentTarget})},E=S=>N(S,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),A=S=>N(S,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),C=()=>y(!0),k=()=>y(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(Mv,{position:h,centerX:l,centerY:o,radius:r,onMouseDown:E,onMouseEnter:C,onMouseOut:k,type:"source"}),(e===!0||e==="target")&&t.jsx(Mv,{position:m,centerX:d,centerY:c,radius:r,onMouseDown:A,onMouseEnter:C,onMouseOut:k,type:"target"})]})}function DR({id:e,edgesFocusable:r,edgesReconnectable:s,elementsSelectable:l,onClick:o,onDoubleClick:d,onContextMenu:c,onMouseEnter:h,onMouseMove:m,onMouseLeave:f,reconnectRadius:x,onReconnect:g,onReconnectStart:p,onReconnectEnd:y,rfId:w,edgeTypes:N,noPanClassName:E,onError:A,disableKeyboardA11y:C}){let k=Vt(De=>De.edgeLookup.get(e));const S=Vt(De=>De.defaultEdgeOptions);k=S?{...S,...k}:k;let O=k.type||"default",R=N?.[O]||Tv[O];R===void 0&&(A?.("011",ws.error011(O)),O="default",R=N?.default||Tv.default);const G=!!(k.focusable||r&&typeof k.focusable>"u"),I=typeof g<"u"&&(k.reconnectable||s&&typeof k.reconnectable>"u"),Q=!!(k.selectable||l&&typeof k.selectable>"u"),$=v.useRef(null),[F,B]=v.useState(!1),[T,D]=v.useState(!1),z=Cn(),{zIndex:_,sourceX:Y,sourceY:V,targetX:J,targetY:U,sourcePosition:H,targetPosition:X}=Vt(v.useCallback(De=>{const ge=De.nodeLookup.get(k.source),ye=De.nodeLookup.get(k.target);if(!ge||!ye)return{zIndex:k.zIndex,...Av};const Ce=ND({id:e,sourceNode:ge,targetNode:ye,sourceHandle:k.sourceHandle||null,targetHandle:k.targetHandle||null,connectionMode:De.connectionMode,onError:A});return{zIndex:xD({selected:k.selected,zIndex:k.zIndex,sourceNode:ge,targetNode:ye,elevateOnSelect:De.elevateEdgesOnSelect,zIndexMode:De.zIndexMode}),...Ce||Av}},[k.source,k.target,k.sourceHandle,k.targetHandle,k.selected,k.zIndex]),Sn),L=v.useMemo(()=>k.markerStart?`url('#${Om(k.markerStart,w)}')`:void 0,[k.markerStart,w]),M=v.useMemo(()=>k.markerEnd?`url('#${Om(k.markerEnd,w)}')`:void 0,[k.markerEnd,w]);if(k.hidden||Y===null||V===null||J===null||U===null)return null;const q=De=>{const{addSelectedEdges:ge,unselectNodesAndEdges:ye,multiSelectionActive:Ce}=z.getState();Q&&(z.setState({nodesSelectionActive:!1}),k.selected&&Ce?(ye({nodes:[],edges:[k]}),$.current?.blur()):ge([e])),o&&o(De,k)},K=d?De=>{d(De,{...k})}:void 0,ee=c?De=>{c(De,{...k})}:void 0,te=h?De=>{h(De,{...k})}:void 0,se=m?De=>{m(De,{...k})}:void 0,xe=f?De=>{f(De,{...k})}:void 0,ke=De=>{if(!C&&uw.includes(De.key)&&Q){const{unselectNodesAndEdges:ge,addSelectedEdges:ye}=z.getState();De.key==="Escape"?($.current?.blur(),ge({edges:[k]})):ye([e])}};return t.jsx("svg",{style:{zIndex:_},children:t.jsxs("g",{className:Fn(["react-flow__edge",`react-flow__edge-${O}`,k.className,E,{selected:k.selected,animated:k.animated,inactive:!Q&&!o,updating:F,selectable:Q}]),onClick:q,onDoubleClick:K,onContextMenu:ee,onMouseEnter:te,onMouseMove:se,onMouseLeave:xe,onKeyDown:G?ke:void 0,tabIndex:G?0:void 0,role:k.ariaRole??(G?"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":G?`${qw}-${w}`:void 0,ref:$,...k.domAttributes,children:[!T&&t.jsx(R,{id:e,source:k.source,target:k.target,type:k.type,selected:k.selected,animated:k.animated,selectable:Q,deletable:k.deletable??!0,label:k.label,labelStyle:k.labelStyle,labelShowBg:k.labelShowBg,labelBgStyle:k.labelBgStyle,labelBgPadding:k.labelBgPadding,labelBgBorderRadius:k.labelBgBorderRadius,sourceX:Y,sourceY:V,targetX:J,targetY:U,sourcePosition:H,targetPosition:X,data:k.data,style:k.style,sourceHandleId:k.sourceHandle,targetHandleId:k.targetHandle,markerStart:L,markerEnd:M,pathOptions:"pathOptions"in k?k.pathOptions:void 0,interactionWidth:k.interactionWidth}),I&&t.jsx(MR,{edge:k,isReconnectable:I,reconnectRadius:x,onReconnect:g,onReconnectStart:p,onReconnectEnd:y,sourceX:Y,sourceY:V,targetX:J,targetY:U,sourcePosition:H,targetPosition:X,setUpdateHover:B,setReconnecting:D})]})})}var OR=v.memo(DR);const RR=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function xN({defaultMarkerColor:e,onlyRenderVisibleElements:r,rfId:s,edgeTypes:l,noPanClassName:o,onReconnect:d,onEdgeContextMenu:c,onEdgeMouseEnter:h,onEdgeMouseMove:m,onEdgeMouseLeave:f,onEdgeClick:x,reconnectRadius:g,onEdgeDoubleClick:p,onReconnectStart:y,onReconnectEnd:w,disableKeyboardA11y:N}){const{edgesFocusable:E,edgesReconnectable:A,elementsSelectable:C,onError:k}=Vt(RR,Sn),S=bR(r);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(NR,{defaultColor:e,rfId:s}),S.map(O=>t.jsx(OR,{id:O,edgesFocusable:E,edgesReconnectable:A,elementsSelectable:C,noPanClassName:o,onReconnect:d,onContextMenu:c,onMouseEnter:h,onMouseMove:m,onMouseLeave:f,onClick:x,reconnectRadius:g,onDoubleClick:p,onReconnectStart:y,onReconnectEnd:w,rfId:s,onError:k,edgeTypes:l,disableKeyboardA11y:N},O))]})}xN.displayName="EdgeRenderer";const LR=v.memo(xN),zR=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function IR({children:e}){const r=Vt(zR);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:r},children:e})}function $R(e){const r=Cx(),s=v.useRef(!1);v.useEffect(()=>{!s.current&&r.viewportInitialized&&e&&(setTimeout(()=>e(r),1),s.current=!0)},[e,r.viewportInitialized])}const BR=e=>e.panZoom?.syncViewport;function HR(e){const r=Vt(BR),s=Cn();return v.useEffect(()=>{e&&(r?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,r]),null}function PR(e){return e.connection.inProgress?{...e.connection,to:qo(e.connection.to,e.transform)}:{...e.connection}}function UR(e){return PR}function qR(e){const r=UR();return Vt(r,Sn)}const FR=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function VR({containerStyle:e,style:r,type:s,component:l}){const{nodesConnectable:o,width:d,height:c,isValid:h,inProgress:m}=Vt(FR,Sn);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:Fn(["react-flow__connection",mw(h)]),children:t.jsx(gN,{style:r,type:s,CustomComponent:l,isValid:h})})})}const gN=({style:e,type:r=Aa.Bezier,CustomComponent:s,isValid:l})=>{const{inProgress:o,from:d,fromNode:c,fromHandle:h,fromPosition:m,to:f,toNode:x,toHandle:g,toPosition:p,pointer:y}=qR();if(!o)return;if(s)return t.jsx(s,{connectionLineType:r,connectionLineStyle:e,fromNode:c,fromHandle:h,fromX:d.x,fromY:d.y,toX:f.x,toY:f.y,fromPosition:m,toPosition:p,connectionStatus:mw(l),toNode:x,toHandle:g,pointer:y});let w="";const N={sourceX:d.x,sourceY:d.y,sourcePosition:m,targetX:f.x,targetY:f.y,targetPosition:p};switch(r){case Aa.Bezier:[w]=Cw(N);break;case Aa.SimpleBezier:[w]=rN(N);break;case Aa.Step:[w]=Dm({...N,borderRadius:0});break;case Aa.SmoothStep:[w]=Dm(N);break;default:[w]=Tw(N)}return t.jsx("path",{d:w,fill:"none",className:"react-flow__connection-path",style:e})};gN.displayName="ConnectionLine";const YR={};function Dv(e=YR){v.useRef(e),Cn(),v.useEffect(()=>{},[e])}function GR(){Cn(),v.useRef(!1),v.useEffect(()=>{},[])}function pN({nodeTypes:e,edgeTypes:r,onInit:s,onNodeClick:l,onEdgeClick:o,onNodeDoubleClick:d,onEdgeDoubleClick:c,onNodeMouseEnter:h,onNodeMouseMove:m,onNodeMouseLeave:f,onNodeContextMenu:x,onSelectionContextMenu:g,onSelectionStart:p,onSelectionEnd:y,connectionLineType:w,connectionLineStyle:N,connectionLineComponent:E,connectionLineContainerStyle:A,selectionKeyCode:C,selectionOnDrag:k,selectionMode:S,multiSelectionKeyCode:O,panActivationKeyCode:R,zoomActivationKeyCode:G,deleteKeyCode:I,onlyRenderVisibleElements:Q,elementsSelectable:$,defaultViewport:F,translateExtent:B,minZoom:T,maxZoom:D,preventScrolling:z,defaultMarkerColor:_,zoomOnScroll:Y,zoomOnPinch:V,panOnScroll:J,panOnScrollSpeed:U,panOnScrollMode:H,zoomOnDoubleClick:X,panOnDrag:L,onPaneClick:M,onPaneMouseEnter:q,onPaneMouseMove:K,onPaneMouseLeave:ee,onPaneScroll:te,onPaneContextMenu:se,paneClickDistance:xe,nodeClickDistance:ke,onEdgeContextMenu:De,onEdgeMouseEnter:ge,onEdgeMouseMove:ye,onEdgeMouseLeave:Ce,reconnectRadius:ze,onReconnect:tt,onReconnectStart:Xe,onReconnectEnd:dt,noDragClassName:wt,noWheelClassName:ae,noPanClassName:Te,disableKeyboardA11y:Ze,nodeExtent:xt,rfId:dn,viewport:we,onViewportChange:Re}){return Dv(e),Dv(r),GR(),$R(s),HR(we),t.jsx(oR,{onPaneClick:M,onPaneMouseEnter:q,onPaneMouseMove:K,onPaneMouseLeave:ee,onPaneContextMenu:se,onPaneScroll:te,paneClickDistance:xe,deleteKeyCode:I,selectionKeyCode:C,selectionOnDrag:k,selectionMode:S,onSelectionStart:p,onSelectionEnd:y,multiSelectionKeyCode:O,panActivationKeyCode:R,zoomActivationKeyCode:G,elementsSelectable:$,zoomOnScroll:Y,zoomOnPinch:V,zoomOnDoubleClick:X,panOnScroll:J,panOnScrollSpeed:U,panOnScrollMode:H,panOnDrag:L,defaultViewport:F,translateExtent:B,minZoom:T,maxZoom:D,onSelectionContextMenu:g,preventScrolling:z,noDragClassName:wt,noWheelClassName:ae,noPanClassName:Te,disableKeyboardA11y:Ze,onViewportChange:Re,isControlledViewport:!!we,children:t.jsxs(IR,{children:[t.jsx(LR,{edgeTypes:r,onEdgeClick:o,onEdgeDoubleClick:c,onReconnect:tt,onReconnectStart:Xe,onReconnectEnd:dt,onlyRenderVisibleElements:Q,onEdgeContextMenu:De,onEdgeMouseEnter:ge,onEdgeMouseMove:ye,onEdgeMouseLeave:Ce,reconnectRadius:ze,defaultMarkerColor:_,noPanClassName:Te,disableKeyboardA11y:Ze,rfId:dn}),t.jsx(VR,{style:N,type:w,component:E,containerStyle:A}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(pR,{nodeTypes:e,onNodeClick:l,onNodeDoubleClick:d,onNodeMouseEnter:h,onNodeMouseMove:m,onNodeMouseLeave:f,onNodeContextMenu:x,nodeClickDistance:ke,onlyRenderVisibleElements:Q,noPanClassName:Te,noDragClassName:wt,disableKeyboardA11y:Ze,nodeExtent:xt,rfId:dn}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}pN.displayName="GraphView";const XR=v.memo(pN),Ov=({nodes:e,edges:r,defaultNodes:s,defaultEdges:l,width:o,height:d,fitView:c,fitViewOptions:h,minZoom:m=.5,maxZoom:f=2,nodeOrigin:x,nodeExtent:g,zIndexMode:p="basic"}={})=>{const y=new Map,w=new Map,N=new Map,E=new Map,A=l??r??[],C=s??e??[],k=x??[0,0],S=g??Eo;Mw(N,E,A);const O=Rm(C,y,w,{nodeOrigin:k,nodeExtent:S,zIndexMode:p});let R=[0,0,1];if(c&&o&&d){const G=Po(y,{filter:F=>!!((F.width||F.initialWidth)&&(F.height||F.initialHeight))}),{x:I,y:Q,zoom:$}=yx(G,o,d,m,f,h?.padding??.1);R=[I,Q,$]}return{rfId:"1",width:o??0,height:d??0,transform:R,nodes:C,nodesInitialized:O,nodeLookup:y,parentLookup:w,edges:A,edgeLookup:E,connectionLookup:N,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:l!==void 0,panZoom:null,minZoom:m,maxZoom:f,translateExtent:Eo,nodeExtent:S,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:ti.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:{...hw},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:cD,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:fw,zIndexMode:p,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},ZR=({nodes:e,edges:r,defaultNodes:s,defaultEdges:l,width:o,height:d,fitView:c,fitViewOptions:h,minZoom:m,maxZoom:f,nodeOrigin:x,nodeExtent:g,zIndexMode:p})=>hO((y,w)=>{async function N(){const{nodeLookup:E,panZoom:A,fitViewOptions:C,fitViewResolver:k,width:S,height:O,minZoom:R,maxZoom:G}=w();A&&(await iD({nodes:E,width:S,height:O,panZoom:A,minZoom:R,maxZoom:G},C),k?.resolve(!0),y({fitViewResolver:null}))}return{...Ov({nodes:e,edges:r,width:o,height:d,fitView:c,fitViewOptions:h,minZoom:m,maxZoom:f,nodeOrigin:x,nodeExtent:g,defaultNodes:s,defaultEdges:l,zIndexMode:p}),setNodes:E=>{const{nodeLookup:A,parentLookup:C,nodeOrigin:k,elevateNodesOnSelect:S,fitViewQueued:O,zIndexMode:R}=w(),G=Rm(E,A,C,{nodeOrigin:k,nodeExtent:g,elevateNodesOnSelect:S,checkEquality:!0,zIndexMode:R});O&&G?(N(),y({nodes:E,nodesInitialized:G,fitViewQueued:!1,fitViewOptions:void 0})):y({nodes:E,nodesInitialized:G})},setEdges:E=>{const{connectionLookup:A,edgeLookup:C}=w();Mw(A,C,E),y({edges:E})},setDefaultNodesAndEdges:(E,A)=>{if(E){const{setNodes:C}=w();C(E),y({hasDefaultNodes:!0})}if(A){const{setEdges:C}=w();C(A),y({hasDefaultEdges:!0})}},updateNodeInternals:E=>{const{triggerNodeChanges:A,nodeLookup:C,parentLookup:k,domNode:S,nodeOrigin:O,nodeExtent:R,debug:G,fitViewQueued:I,zIndexMode:Q}=w(),{changes:$,updatedInternals:F}=MD(E,C,k,S,O,R,Q);F&&(ED(C,k,{nodeOrigin:O,nodeExtent:R,zIndexMode:Q}),I?(N(),y({fitViewQueued:!1,fitViewOptions:void 0})):y({}),$?.length>0&&(G&&console.log("React Flow: trigger node changes",$),A?.($)))},updateNodePositions:(E,A=!1)=>{const C=[];let k=[];const{nodeLookup:S,triggerNodeChanges:O,connection:R,updateConnection:G,onNodesChangeMiddlewareMap:I}=w();for(const[Q,$]of E){const F=S.get(Q),B=!!(F?.expandParent&&F?.parentId&&$?.position),T={id:Q,type:"position",position:B?{x:Math.max(0,$.position.x),y:Math.max(0,$.position.y)}:$.position,dragging:A};if(F&&R.inProgress&&R.fromNode.id===F.id){const D=ol(F,R.fromHandle,lt.Left,!0);G({...R,from:D})}B&&F.parentId&&C.push({id:Q,parentId:F.parentId,rect:{...$.internals.positionAbsolute,width:$.measured.width??0,height:$.measured.height??0}}),k.push(T)}if(C.length>0){const{parentLookup:Q,nodeOrigin:$}=w(),F=Sx(C,S,Q,$);k.push(...F)}for(const Q of I.values())k=Q(k);O(k)},triggerNodeChanges:E=>{const{onNodesChange:A,setNodes:C,nodes:k,hasDefaultNodes:S,debug:O}=w();if(E?.length){if(S){const R=Yw(E,k);C(R)}O&&console.log("React Flow: trigger node changes",E),A?.(E)}},triggerEdgeChanges:E=>{const{onEdgesChange:A,setEdges:C,edges:k,hasDefaultEdges:S,debug:O}=w();if(E?.length){if(S){const R=Gw(E,k);C(R)}O&&console.log("React Flow: trigger edge changes",E),A?.(E)}},addSelectedNodes:E=>{const{multiSelectionActive:A,edgeLookup:C,nodeLookup:k,triggerNodeChanges:S,triggerEdgeChanges:O}=w();if(A){const R=E.map(G=>Ja(G,!0));S(R);return}S(Xl(k,new Set([...E]),!0)),O(Xl(C))},addSelectedEdges:E=>{const{multiSelectionActive:A,edgeLookup:C,nodeLookup:k,triggerNodeChanges:S,triggerEdgeChanges:O}=w();if(A){const R=E.map(G=>Ja(G,!0));O(R);return}O(Xl(C,new Set([...E]))),S(Xl(k,new Set,!0))},unselectNodesAndEdges:({nodes:E,edges:A}={})=>{const{edges:C,nodes:k,nodeLookup:S,triggerNodeChanges:O,triggerEdgeChanges:R}=w(),G=E||k,I=A||C,Q=[];for(const F of G){if(!F.selected)continue;const B=S.get(F.id);B&&(B.selected=!1),Q.push(Ja(F.id,!1))}const $=[];for(const F of I)F.selected&&$.push(Ja(F.id,!1));O(Q),R($)},setMinZoom:E=>{const{panZoom:A,maxZoom:C}=w();A?.setScaleExtent([E,C]),y({minZoom:E})},setMaxZoom:E=>{const{panZoom:A,minZoom:C}=w();A?.setScaleExtent([C,E]),y({maxZoom:E})},setTranslateExtent:E=>{w().panZoom?.setTranslateExtent(E),y({translateExtent:E})},resetSelectedElements:()=>{const{edges:E,nodes:A,triggerNodeChanges:C,triggerEdgeChanges:k,elementsSelectable:S}=w();if(!S)return;const O=A.reduce((G,I)=>I.selected?[...G,Ja(I.id,!1)]:G,[]),R=E.reduce((G,I)=>I.selected?[...G,Ja(I.id,!1)]:G,[]);C(O),k(R)},setNodeExtent:E=>{const{nodes:A,nodeLookup:C,parentLookup:k,nodeOrigin:S,elevateNodesOnSelect:O,nodeExtent:R,zIndexMode:G}=w();E[0][0]===R[0][0]&&E[0][1]===R[0][1]&&E[1][0]===R[1][0]&&E[1][1]===R[1][1]||(Rm(A,C,k,{nodeOrigin:S,nodeExtent:E,elevateNodesOnSelect:O,checkEquality:!1,zIndexMode:G}),y({nodeExtent:E}))},panBy:E=>{const{transform:A,width:C,height:k,panZoom:S,translateExtent:O}=w();return DD({delta:E,panZoom:S,transform:A,translateExtent:O,width:C,height:k})},setCenter:async(E,A,C)=>{const{width:k,height:S,maxZoom:O,panZoom:R}=w();if(!R)return Promise.resolve(!1);const G=typeof C?.zoom<"u"?C.zoom:O;return await R.setViewport({x:k/2-E*G,y:S/2-A*G,zoom:G},{duration:C?.duration,ease:C?.ease,interpolate:C?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{y({connection:{...hw}})},updateConnection:E=>{y({connection:E})},reset:()=>y({...Ov()})}},Object.is);function QR({initialNodes:e,initialEdges:r,defaultNodes:s,defaultEdges:l,initialWidth:o,initialHeight:d,initialMinZoom:c,initialMaxZoom:h,initialFitViewOptions:m,fitView:f,nodeOrigin:x,nodeExtent:g,zIndexMode:p,children:y}){const[w]=v.useState(()=>ZR({nodes:e,edges:r,defaultNodes:s,defaultEdges:l,width:o,height:d,fitView:f,minZoom:c,maxZoom:h,fitViewOptions:m,nodeOrigin:x,nodeExtent:g,zIndexMode:p}));return t.jsx(mO,{value:w,children:t.jsx(IO,{children:y})})}function KR({children:e,nodes:r,edges:s,defaultNodes:l,defaultEdges:o,width:d,height:c,fitView:h,fitViewOptions:m,minZoom:f,maxZoom:x,nodeOrigin:g,nodeExtent:p,zIndexMode:y}){return v.useContext(ou)?t.jsx(t.Fragment,{children:e}):t.jsx(QR,{initialNodes:r,initialEdges:s,defaultNodes:l,defaultEdges:o,initialWidth:d,initialHeight:c,fitView:h,initialFitViewOptions:m,initialMinZoom:f,initialMaxZoom:x,nodeOrigin:g,nodeExtent:p,zIndexMode:y,children:e})}const JR={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function WR({nodes:e,edges:r,defaultNodes:s,defaultEdges:l,className:o,nodeTypes:d,edgeTypes:c,onNodeClick:h,onEdgeClick:m,onInit:f,onMove:x,onMoveStart:g,onMoveEnd:p,onConnect:y,onConnectStart:w,onConnectEnd:N,onClickConnectStart:E,onClickConnectEnd:A,onNodeMouseEnter:C,onNodeMouseMove:k,onNodeMouseLeave:S,onNodeContextMenu:O,onNodeDoubleClick:R,onNodeDragStart:G,onNodeDrag:I,onNodeDragStop:Q,onNodesDelete:$,onEdgesDelete:F,onDelete:B,onSelectionChange:T,onSelectionDragStart:D,onSelectionDrag:z,onSelectionDragStop:_,onSelectionContextMenu:Y,onSelectionStart:V,onSelectionEnd:J,onBeforeDelete:U,connectionMode:H,connectionLineType:X=Aa.Bezier,connectionLineStyle:L,connectionLineComponent:M,connectionLineContainerStyle:q,deleteKeyCode:K="Backspace",selectionKeyCode:ee="Shift",selectionOnDrag:te=!1,selectionMode:se=To.Full,panActivationKeyCode:xe="Space",multiSelectionKeyCode:ke=_o()?"Meta":"Control",zoomActivationKeyCode:De=_o()?"Meta":"Control",snapToGrid:ge,snapGrid:ye,onlyRenderVisibleElements:Ce=!1,selectNodesOnDrag:ze,nodesDraggable:tt,autoPanOnNodeFocus:Xe,nodesConnectable:dt,nodesFocusable:wt,nodeOrigin:ae=Fw,edgesFocusable:Te,edgesReconnectable:Ze,elementsSelectable:xt=!0,defaultViewport:dn=EO,minZoom:we=.5,maxZoom:Re=2,translateExtent:qe=Eo,preventScrolling:et=!0,nodeExtent:nt,defaultMarkerColor:zt="#b1b1b7",zoomOnScroll:Yt=!0,zoomOnPinch:Lt=!0,panOnScroll:Tt=!1,panOnScrollSpeed:qt=.5,panOnScrollMode:yt=nl.Free,zoomOnDoubleClick:sn=!0,panOnDrag:Xt=!0,onPaneClick:je,onPaneMouseEnter:Pe,onPaneMouseMove:vt,onPaneMouseLeave:Nt,onPaneScroll:ut,onPaneContextMenu:Wt,paneClickDistance:en=1,nodeClickDistance:Ct=0,children:de,onReconnect:Be,onReconnectStart:Le,onReconnectEnd:ot,onEdgeContextMenu:Qe,onEdgeDoubleClick:ft,onEdgeMouseEnter:Zt,onEdgeMouseMove:it,onEdgeMouseLeave:gt,reconnectRadius:wn=10,onNodesChange:an,onEdgesChange:Qt,noDragClassName:At="nodrag",noWheelClassName:un="nowheel",noPanClassName:En="nopan",fitView:fe,fitViewOptions:Fe,connectOnClick:kt,attributionPosition:St,proOptions:Tn,defaultEdgeOptions:Qn,elevateNodesOnSelect:hr=!0,elevateEdgesOnSelect:or=!1,disableKeyboardA11y:tr=!1,autoPanOnConnect:cr,autoPanOnNodeDrag:fn,autoPanSpeed:os,connectionRadius:Sr,isValidConnection:nr,onError:rr,style:Cs,id:ie,nodeDragThreshold:Se,connectionDragThreshold:He,viewport:Mt,onViewportChange:Gn,width:On,height:tn,colorMode:Hr="light",debug:Js,onScroll:mr,ariaLabelConfig:dr,zIndexMode:Cr="basic",...Er},An){const Tr=ie||"1",cs=MO(Hr),Kr=v.useCallback(ne=>{ne.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),mr?.(ne)},[mr]);return t.jsx("div",{"data-testid":"rf__wrapper",...Er,onScroll:Kr,style:{...Cs,...JR},ref:An,className:Fn(["react-flow",o,cs]),id:ie,role:"application",children:t.jsxs(KR,{nodes:e,edges:r,width:On,height:tn,fitView:fe,fitViewOptions:Fe,minZoom:we,maxZoom:Re,nodeOrigin:ae,nodeExtent:nt,zIndexMode:Cr,children:[t.jsx(XR,{onInit:f,onNodeClick:h,onEdgeClick:m,onNodeMouseEnter:C,onNodeMouseMove:k,onNodeMouseLeave:S,onNodeContextMenu:O,onNodeDoubleClick:R,nodeTypes:d,edgeTypes:c,connectionLineType:X,connectionLineStyle:L,connectionLineComponent:M,connectionLineContainerStyle:q,selectionKeyCode:ee,selectionOnDrag:te,selectionMode:se,deleteKeyCode:K,multiSelectionKeyCode:ke,panActivationKeyCode:xe,zoomActivationKeyCode:De,onlyRenderVisibleElements:Ce,defaultViewport:dn,translateExtent:qe,minZoom:we,maxZoom:Re,preventScrolling:et,zoomOnScroll:Yt,zoomOnPinch:Lt,zoomOnDoubleClick:sn,panOnScroll:Tt,panOnScrollSpeed:qt,panOnScrollMode:yt,panOnDrag:Xt,onPaneClick:je,onPaneMouseEnter:Pe,onPaneMouseMove:vt,onPaneMouseLeave:Nt,onPaneScroll:ut,onPaneContextMenu:Wt,paneClickDistance:en,nodeClickDistance:Ct,onSelectionContextMenu:Y,onSelectionStart:V,onSelectionEnd:J,onReconnect:Be,onReconnectStart:Le,onReconnectEnd:ot,onEdgeContextMenu:Qe,onEdgeDoubleClick:ft,onEdgeMouseEnter:Zt,onEdgeMouseMove:it,onEdgeMouseLeave:gt,reconnectRadius:wn,defaultMarkerColor:zt,noDragClassName:At,noWheelClassName:un,noPanClassName:En,rfId:Tr,disableKeyboardA11y:tr,nodeExtent:nt,viewport:Mt,onViewportChange:Gn}),t.jsx(_O,{nodes:e,edges:r,defaultNodes:s,defaultEdges:l,onConnect:y,onConnectStart:w,onConnectEnd:N,onClickConnectStart:E,onClickConnectEnd:A,nodesDraggable:tt,autoPanOnNodeFocus:Xe,nodesConnectable:dt,nodesFocusable:wt,edgesFocusable:Te,edgesReconnectable:Ze,elementsSelectable:xt,elevateNodesOnSelect:hr,elevateEdgesOnSelect:or,minZoom:we,maxZoom:Re,nodeExtent:nt,onNodesChange:an,onEdgesChange:Qt,snapToGrid:ge,snapGrid:ye,connectionMode:H,translateExtent:qe,connectOnClick:kt,defaultEdgeOptions:Qn,fitView:fe,fitViewOptions:Fe,onNodesDelete:$,onEdgesDelete:F,onDelete:B,onNodeDragStart:G,onNodeDrag:I,onNodeDragStop:Q,onSelectionDrag:z,onSelectionDragStart:D,onSelectionDragStop:_,onMove:x,onMoveStart:g,onMoveEnd:p,noPanClassName:En,nodeOrigin:ae,rfId:Tr,autoPanOnConnect:cr,autoPanOnNodeDrag:fn,autoPanSpeed:os,onError:rr,connectionRadius:Sr,isValidConnection:nr,selectNodesOnDrag:ze,nodeDragThreshold:Se,connectionDragThreshold:He,onBeforeDelete:U,debug:Js,ariaLabelConfig:dr,zIndexMode:Cr}),t.jsx(CO,{onSelectionChange:T}),de,t.jsx(jO,{proOptions:Tn,position:St}),t.jsx(vO,{rfId:Tr,disableKeyboardA11y:tr})]})})}var eL=Xw(WR);function tL(e){const[r,s]=v.useState(e),l=v.useCallback(o=>s(d=>Yw(o,d)),[]);return[r,s,l]}function nL(e){const[r,s]=v.useState(e),l=v.useCallback(o=>s(d=>Gw(o,d)),[]);return[r,s,l]}function rL({dimensions:e,lineWidth:r,variant:s,className:l}){return t.jsx("path",{strokeWidth:r,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Fn(["react-flow__background-pattern",s,l])})}function sL({radius:e,className:r}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Fn(["react-flow__background-pattern","dots",r])})}var _a;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(_a||(_a={}));const aL={[_a.Dots]:1,[_a.Lines]:1,[_a.Cross]:6},lL=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function bN({id:e,variant:r=_a.Dots,gap:s=20,size:l,lineWidth:o=1,offset:d=0,color:c,bgColor:h,style:m,className:f,patternClassName:x}){const g=v.useRef(null),{transform:p,patternId:y}=Vt(lL,Sn),w=l||aL[r],N=r===_a.Dots,E=r===_a.Cross,A=Array.isArray(s)?s:[s,s],C=[A[0]*p[2]||1,A[1]*p[2]||1],k=w*p[2],S=Array.isArray(d)?d:[d,d],O=E?[k,k]:C,R=[S[0]*p[2]||1+O[0]/2,S[1]*p[2]||1+O[1]/2],G=`${y}${e||""}`;return t.jsxs("svg",{className:Fn(["react-flow__background",f]),style:{...m,...du,"--xy-background-color-props":h,"--xy-background-pattern-color-props":c},ref:g,"data-testid":"rf__background",children:[t.jsx("pattern",{id:G,x:p[0]%C[0],y:p[1]%C[1],width:C[0],height:C[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${R[0]},-${R[1]})`,children:N?t.jsx(sL,{radius:k/2,className:x}):t.jsx(rL,{dimensions:O,lineWidth:o,variant:r,className:x})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${G})`})]})}bN.displayName="Background";const iL=v.memo(bN);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 cL(){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 dL(){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 uL(){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 fL(){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 ud({children:e,className:r,...s}){return t.jsx("button",{type:"button",className:Fn(["react-flow__controls-button",r]),...s,children:e})}const hL=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function yN({style:e,showZoom:r=!0,showFitView:s=!0,showInteractive:l=!0,fitViewOptions:o,onZoomIn:d,onZoomOut:c,onFitView:h,onInteractiveChange:m,className:f,children:x,position:g="bottom-left",orientation:p="vertical","aria-label":y}){const w=Cn(),{isInteractive:N,minZoomReached:E,maxZoomReached:A,ariaLabelConfig:C}=Vt(hL,Sn),{zoomIn:k,zoomOut:S,fitView:O}=Cx(),R=()=>{k(),d?.()},G=()=>{S(),c?.()},I=()=>{O(o),h?.()},Q=()=>{w.setState({nodesDraggable:!N,nodesConnectable:!N,elementsSelectable:!N}),m?.(!N)},$=p==="horizontal"?"horizontal":"vertical";return t.jsxs(cu,{className:Fn(["react-flow__controls",$,f]),position:g,style:e,"data-testid":"rf__controls","aria-label":y??C["controls.ariaLabel"],children:[r&&t.jsxs(t.Fragment,{children:[t.jsx(ud,{onClick:R,className:"react-flow__controls-zoomin",title:C["controls.zoomIn.ariaLabel"],"aria-label":C["controls.zoomIn.ariaLabel"],disabled:A,children:t.jsx(oL,{})}),t.jsx(ud,{onClick:G,className:"react-flow__controls-zoomout",title:C["controls.zoomOut.ariaLabel"],"aria-label":C["controls.zoomOut.ariaLabel"],disabled:E,children:t.jsx(cL,{})})]}),s&&t.jsx(ud,{className:"react-flow__controls-fitview",onClick:I,title:C["controls.fitView.ariaLabel"],"aria-label":C["controls.fitView.ariaLabel"],children:t.jsx(dL,{})}),l&&t.jsx(ud,{className:"react-flow__controls-interactive",onClick:Q,title:C["controls.interactive.ariaLabel"],"aria-label":C["controls.interactive.ariaLabel"],children:N?t.jsx(fL,{}):t.jsx(uL,{})}),x]})}yN.displayName="Controls";const mL=v.memo(yN);function xL({id:e,x:r,y:s,width:l,height:o,style:d,color:c,strokeColor:h,strokeWidth:m,className:f,borderRadius:x,shapeRendering:g,selected:p,onClick:y}){const{background:w,backgroundColor:N}=d||{},E=c||w||N;return t.jsx("rect",{className:Fn(["react-flow__minimap-node",{selected:p},f]),x:r,y:s,rx:x,ry:x,width:l,height:o,style:{fill:E,stroke:h,strokeWidth:m},shapeRendering:g,onClick:y?A=>y(A,e):void 0})}const gL=v.memo(xL),pL=e=>e.nodes.map(r=>r.id),Wh=e=>e instanceof Function?e:()=>e;function bL({nodeStrokeColor:e,nodeColor:r,nodeClassName:s="",nodeBorderRadius:l=5,nodeStrokeWidth:o,nodeComponent:d=gL,onClick:c}){const h=Vt(pL,Sn),m=Wh(r),f=Wh(e),x=Wh(s),g=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:h.map(p=>t.jsx(vL,{id:p,nodeColorFunc:m,nodeStrokeColorFunc:f,nodeClassNameFunc:x,nodeBorderRadius:l,nodeStrokeWidth:o,NodeComponent:d,onClick:c,shapeRendering:g},p))})}function yL({id:e,nodeColorFunc:r,nodeStrokeColorFunc:s,nodeClassNameFunc:l,nodeBorderRadius:o,nodeStrokeWidth:d,shapeRendering:c,NodeComponent:h,onClick:m}){const{node:f,x,y:g,width:p,height:y}=Vt(w=>{const N=w.nodeLookup.get(e);if(!N)return{node:void 0,x:0,y:0,width:0,height:0};const E=N.internals.userNode,{x:A,y:C}=N.internals.positionAbsolute,{width:k,height:S}=Ks(E);return{node:E,x:A,y:C,width:k,height:S}},Sn);return!f||f.hidden||!vw(f)?null:t.jsx(h,{x,y:g,width:p,height:y,style:f.style,selected:!!f.selected,className:l(f),color:r(f),borderRadius:o,strokeColor:s(f),strokeWidth:d,shapeRendering:c,onClick:m,id:f.id})}const vL=v.memo(yL);var jL=v.memo(bL);const wL=200,NL=150,kL=e=>!e.hidden,SL=e=>{const r={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:r,boundingRect:e.nodeLookup.size>0?yw(Po(e.nodeLookup,{filter:kL}),r):r,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},CL="react-flow__minimap-desc";function vN({style:e,className:r,nodeStrokeColor:s,nodeColor:l,nodeClassName:o="",nodeBorderRadius:d=5,nodeStrokeWidth:c,nodeComponent:h,bgColor:m,maskColor:f,maskStrokeColor:x,maskStrokeWidth:g,position:p="bottom-right",onClick:y,onNodeClick:w,pannable:N=!1,zoomable:E=!1,ariaLabel:A,inversePan:C,zoomStep:k=1,offsetScale:S=5}){const O=Cn(),R=v.useRef(null),{boundingRect:G,viewBB:I,rfId:Q,panZoom:$,translateExtent:F,flowWidth:B,flowHeight:T,ariaLabelConfig:D}=Vt(SL,Sn),z=e?.width??wL,_=e?.height??NL,Y=G.width/z,V=G.height/_,J=Math.max(Y,V),U=J*z,H=J*_,X=S*J,L=G.x-(U-G.width)/2-X,M=G.y-(H-G.height)/2-X,q=U+X*2,K=H+X*2,ee=`${CL}-${Q}`,te=v.useRef(0),se=v.useRef();te.current=J,v.useEffect(()=>{if(R.current&&$)return se.current=PD({domNode:R.current,panZoom:$,getTransform:()=>O.getState().transform,getViewScale:()=>te.current}),()=>{se.current?.destroy()}},[$]),v.useEffect(()=>{se.current?.update({translateExtent:F,width:B,height:T,inversePan:C,pannable:N,zoomStep:k,zoomable:E})},[N,E,C,k,F,B,T]);const xe=y?ge=>{const[ye,Ce]=se.current?.pointer(ge)||[0,0];y(ge,{x:ye,y:Ce})}:void 0,ke=w?v.useCallback((ge,ye)=>{const Ce=O.getState().nodeLookup.get(ye).internals.userNode;w(ge,Ce)},[]):void 0,De=A??D["minimap.ariaLabel"];return t.jsx(cu,{position:p,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 g=="number"?g*J:void 0,"--xy-minimap-node-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-node-stroke-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-width-props":typeof c=="number"?c:void 0},className:Fn(["react-flow__minimap",r]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:z,height:_,viewBox:`${L} ${M} ${q} ${K}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":ee,ref:R,onClick:xe,children:[De&&t.jsx("title",{id:ee,children:De}),t.jsx(jL,{onClick:ke,nodeColor:l,nodeStrokeColor:s,nodeBorderRadius:d,nodeClassName:o,nodeStrokeWidth:c,nodeComponent:h}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${L-X},${M-X}h${q+X*2}v${K+X*2}h${-q-X*2}z
61
61
  M${I.x},${I.y}h${I.width}v${I.height}h${-I.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}vN.displayName="MiniMap";const EL=v.memo(vN),TL=e=>r=>e?`${Math.max(1/r.transform[2],1)}`:void 0,AL={[li.Line]:"right",[li.Handle]:"bottom-right"};function _L({nodeId:e,position:r,variant:s=li.Handle,className:l,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:g=!1,resizeDirection:p,autoScale:y=!0,shouldResize:w,onResizeStart:N,onResize:E,onResizeEnd:A}){const C=Jw(),k=typeof e=="string"?e:C,S=Cn(),O=v.useRef(null),R=s===li.Handle,G=Vt(v.useCallback(TL(R&&y),[R,y]),Sn),I=v.useRef(null),Q=r??AL[s];v.useEffect(()=>{if(!(!O.current||!k))return I.current||(I.current=tO({domNode:O.current,nodeId:k,getStoreItems:()=>{const{nodeLookup:F,transform:B,snapGrid:T,snapToGrid:D,nodeOrigin:z,domNode:_}=S.getState();return{nodeLookup:F,transform:B,snapGrid:T,snapToGrid:D,nodeOrigin:z,paneDomNode:_}},onChange:(F,B)=>{const{triggerNodeChanges:T,nodeLookup:D,parentLookup:z,nodeOrigin:_}=S.getState(),Y=[],V={x:F.x,y:F.y},J=D.get(k);if(J&&J.expandParent&&J.parentId){const U=J.origin??_,H=F.width??J.measured.width??0,X=F.height??J.measured.height??0,L={id:J.id,parentId:J.parentId,rect:{width:H,height:X,...jw({x:F.x??J.position.x,y:F.y??J.position.y},{width:H,height:X},J.parentId,D,U)}},M=Sx([L],D,z,_);Y.push(...M),V.x=F.x?Math.max(U[0]*H,F.x):void 0,V.y=F.y?Math.max(U[1]*X,F.y):void 0}if(V.x!==void 0&&V.y!==void 0){const U={id:k,type:"position",position:{...V}};Y.push(U)}if(F.width!==void 0&&F.height!==void 0){const H={id:k,type:"dimensions",resizing:!0,setAttributes:p?p==="horizontal"?"width":"height":!0,dimensions:{width:F.width,height:F.height}};Y.push(H)}for(const U of B){const H={...U,type:"position"};Y.push(H)}T(Y)},onEnd:({width:F,height:B})=>{const T={id:k,type:"dimensions",resizing:!1,dimensions:{width:F,height:B}};S.getState().triggerNodeChanges([T])}})),I.current.update({controlPosition:Q,boundaries:{minWidth:h,minHeight:m,maxWidth:f,maxHeight:x},keepAspectRatio:g,resizeDirection:p,onResizeStart:N,onResize:E,onResizeEnd:A,shouldResize:w}),()=>{I.current?.destroy()}},[Q,h,m,f,x,g,N,E,A,w]);const $=Q.split("-");return t.jsx("div",{className:Fn(["react-flow__resize-control","nodrag",...$,s,l]),ref:O,style:{...o,scale:G,...c&&{[R?"backgroundColor":"borderColor"]:c}},children:d})}v.memo(_L);var cn=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),ls=cn((e,r)=>{var s=Object.defineProperty,l=(T,D,z)=>D in T?s(T,D,{enumerable:!0,configurable:!0,writable:!0,value:z}):T[D]=z,o=(T,D)=>()=>(D||T((D={exports:{}}).exports,D),D.exports),d=(T,D,z)=>l(T,typeof D!="symbol"?D+"":D,z),c=o((T,D)=>{var z="\0",_="\0",Y="",V=class{constructor(M){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"),M&&(this._isDirected=Object.hasOwn(M,"directed")?M.directed:!0,this._isMultigraph=Object.hasOwn(M,"multigraph")?M.multigraph:!1,this._isCompound=Object.hasOwn(M,"compound")?M.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[_]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(M){return this._label=M,this}graph(){return this._label}setDefaultNodeLabel(M){return this._defaultNodeLabelFn=M,typeof M!="function"&&(this._defaultNodeLabelFn=()=>M),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var M=this;return this.nodes().filter(q=>Object.keys(M._in[q]).length===0)}sinks(){var M=this;return this.nodes().filter(q=>Object.keys(M._out[q]).length===0)}setNodes(M,q){var K=arguments,ee=this;return M.forEach(function(te){K.length>1?ee.setNode(te,q):ee.setNode(te)}),this}setNode(M,q){return Object.hasOwn(this._nodes,M)?(arguments.length>1&&(this._nodes[M]=q),this):(this._nodes[M]=arguments.length>1?q:this._defaultNodeLabelFn(M),this._isCompound&&(this._parent[M]=_,this._children[M]={},this._children[_][M]=!0),this._in[M]={},this._preds[M]={},this._out[M]={},this._sucs[M]={},++this._nodeCount,this)}node(M){return this._nodes[M]}hasNode(M){return Object.hasOwn(this._nodes,M)}removeNode(M){var q=this;if(Object.hasOwn(this._nodes,M)){var K=ee=>q.removeEdge(q._edgeObjs[ee]);delete this._nodes[M],this._isCompound&&(this._removeFromParentsChildList(M),delete this._parent[M],this.children(M).forEach(function(ee){q.setParent(ee)}),delete this._children[M]),Object.keys(this._in[M]).forEach(K),delete this._in[M],delete this._preds[M],Object.keys(this._out[M]).forEach(K),delete this._out[M],delete this._sucs[M],--this._nodeCount}return this}setParent(M,q){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(q===void 0)q=_;else{q+="";for(var K=q;K!==void 0;K=this.parent(K))if(K===M)throw new Error("Setting "+q+" as parent of "+M+" would create a cycle");this.setNode(q)}return this.setNode(M),this._removeFromParentsChildList(M),this._parent[M]=q,this._children[q][M]=!0,this}_removeFromParentsChildList(M){delete this._children[this._parent[M]][M]}parent(M){if(this._isCompound){var q=this._parent[M];if(q!==_)return q}}children(M=_){if(this._isCompound){var q=this._children[M];if(q)return Object.keys(q)}else{if(M===_)return this.nodes();if(this.hasNode(M))return[]}}predecessors(M){var q=this._preds[M];if(q)return Object.keys(q)}successors(M){var q=this._sucs[M];if(q)return Object.keys(q)}neighbors(M){var q=this.predecessors(M);if(q){let ee=new Set(q);for(var K of this.successors(M))ee.add(K);return Array.from(ee.values())}}isLeaf(M){var q;return this.isDirected()?q=this.successors(M):q=this.neighbors(M),q.length===0}filterNodes(M){var q=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});q.setGraph(this.graph());var K=this;Object.entries(this._nodes).forEach(function([se,xe]){M(se)&&q.setNode(se,xe)}),Object.values(this._edgeObjs).forEach(function(se){q.hasNode(se.v)&&q.hasNode(se.w)&&q.setEdge(se,K.edge(se))});var ee={};function te(se){var xe=K.parent(se);return xe===void 0||q.hasNode(xe)?(ee[se]=xe,xe):xe in ee?ee[xe]:te(xe)}return this._isCompound&&q.nodes().forEach(se=>q.setParent(se,te(se))),q}setDefaultEdgeLabel(M){return this._defaultEdgeLabelFn=M,typeof M!="function"&&(this._defaultEdgeLabelFn=()=>M),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(M,q){var K=this,ee=arguments;return M.reduce(function(te,se){return ee.length>1?K.setEdge(te,se,q):K.setEdge(te,se),se}),this}setEdge(){var M,q,K,ee,te=!1,se=arguments[0];typeof se=="object"&&se!==null&&"v"in se?(M=se.v,q=se.w,K=se.name,arguments.length===2&&(ee=arguments[1],te=!0)):(M=se,q=arguments[1],K=arguments[3],arguments.length>2&&(ee=arguments[2],te=!0)),M=""+M,q=""+q,K!==void 0&&(K=""+K);var xe=H(this._isDirected,M,q,K);if(Object.hasOwn(this._edgeLabels,xe))return te&&(this._edgeLabels[xe]=ee),this;if(K!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(M),this.setNode(q),this._edgeLabels[xe]=te?ee:this._defaultEdgeLabelFn(M,q,K);var ke=X(this._isDirected,M,q,K);return M=ke.v,q=ke.w,Object.freeze(ke),this._edgeObjs[xe]=ke,J(this._preds[q],M),J(this._sucs[M],q),this._in[q][xe]=ke,this._out[M][xe]=ke,this._edgeCount++,this}edge(M,q,K){var ee=arguments.length===1?L(this._isDirected,arguments[0]):H(this._isDirected,M,q,K);return this._edgeLabels[ee]}edgeAsObj(){let M=this.edge(...arguments);return typeof M!="object"?{label:M}:M}hasEdge(M,q,K){var ee=arguments.length===1?L(this._isDirected,arguments[0]):H(this._isDirected,M,q,K);return Object.hasOwn(this._edgeLabels,ee)}removeEdge(M,q,K){var ee=arguments.length===1?L(this._isDirected,arguments[0]):H(this._isDirected,M,q,K),te=this._edgeObjs[ee];return te&&(M=te.v,q=te.w,delete this._edgeLabels[ee],delete this._edgeObjs[ee],U(this._preds[q],M),U(this._sucs[M],q),delete this._in[q][ee],delete this._out[M][ee],this._edgeCount--),this}inEdges(M,q){return this.isDirected()?this.filterEdges(this._in[M],M,q):this.nodeEdges(M,q)}outEdges(M,q){return this.isDirected()?this.filterEdges(this._out[M],M,q):this.nodeEdges(M,q)}nodeEdges(M,q){if(M in this._nodes)return this.filterEdges({...this._in[M],...this._out[M]},M,q)}filterEdges(M,q,K){if(M){var ee=Object.values(M);return K?ee.filter(function(te){return te.v===q&&te.w===K||te.v===K&&te.w===q}):ee}}};function J(M,q){M[q]?M[q]++:M[q]=1}function U(M,q){--M[q]||delete M[q]}function H(M,q,K,ee){var te=""+q,se=""+K;if(!M&&te>se){var xe=te;te=se,se=xe}return te+Y+se+Y+(ee===void 0?z:ee)}function X(M,q,K,ee){var te=""+q,se=""+K;if(!M&&te>se){var xe=te;te=se,se=xe}var ke={v:te,w:se};return ee&&(ke.name=ee),ke}function L(M,q){return H(M,q.v,q.w,q.name)}D.exports=V}),h=o((T,D)=>{D.exports="3.0.2"}),m=o((T,D)=>{D.exports={Graph:c(),version:h()}}),f=o((T,D)=>{var z=c();D.exports={write:_,read:J};function _(U){var H={options:{directed:U.isDirected(),multigraph:U.isMultigraph(),compound:U.isCompound()},nodes:Y(U),edges:V(U)};return U.graph()!==void 0&&(H.value=structuredClone(U.graph())),H}function Y(U){return U.nodes().map(function(H){var X=U.node(H),L=U.parent(H),M={v:H};return X!==void 0&&(M.value=X),L!==void 0&&(M.parent=L),M})}function V(U){return U.edges().map(function(H){var X=U.edge(H),L={v:H.v,w:H.w};return H.name!==void 0&&(L.name=H.name),X!==void 0&&(L.value=X),L})}function J(U){var H=new z(U.options).setGraph(U.value);return U.nodes.forEach(function(X){H.setNode(X.v,X.value),X.parent&&H.setParent(X.v,X.parent)}),U.edges.forEach(function(X){H.setEdge({v:X.v,w:X.w,name:X.name},X.value)}),H}}),x=o((T,D)=>{D.exports=_;var z=()=>1;function _(V,J,U,H){return Y(V,String(J),U||z,H||function(X){return V.outEdges(X)})}function Y(V,J,U,H){var X={},L=!0,M=0,q=V.nodes(),K=function(xe){var ke=U(xe);X[xe.v].distance+ke<X[xe.w].distance&&(X[xe.w]={distance:X[xe.v].distance+ke,predecessor:xe.v},L=!0)},ee=function(){q.forEach(function(xe){H(xe).forEach(function(ke){var De=ke.v===xe?ke.v:ke.w,ge=De===ke.v?ke.w:ke.v;K({v:De,w:ge})})})};q.forEach(function(xe){var ke=xe===J?0:Number.POSITIVE_INFINITY;X[xe]={distance:ke}});for(var te=q.length,se=1;se<te&&(L=!1,M++,ee(),!!L);se++);if(M===te-1&&(L=!1,ee(),L))throw new Error("The graph contains a negative weight cycle");return X}}),g=o((T,D)=>{D.exports=z;function z(_){var Y={},V=[],J;function U(H){Object.hasOwn(Y,H)||(Y[H]=!0,J.push(H),_.successors(H).forEach(U),_.predecessors(H).forEach(U))}return _.nodes().forEach(function(H){J=[],U(H),J.length&&V.push(J)}),V}}),p=o((T,D)=>{var z=class{constructor(){d(this,"_arr",[]),d(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(_){return _.key})}has(_){return Object.hasOwn(this._keyIndices,_)}priority(_){var Y=this._keyIndices[_];if(Y!==void 0)return this._arr[Y].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(_,Y){var V=this._keyIndices;if(_=String(_),!Object.hasOwn(V,_)){var J=this._arr,U=J.length;return V[_]=U,J.push({key:_,priority:Y}),this._decrease(U),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var _=this._arr.pop();return delete this._keyIndices[_.key],this._heapify(0),_.key}decrease(_,Y){var V=this._keyIndices[_];if(Y>this._arr[V].priority)throw new Error("New priority is greater than current priority. Key: "+_+" Old: "+this._arr[V].priority+" New: "+Y);this._arr[V].priority=Y,this._decrease(V)}_heapify(_){var Y=this._arr,V=2*_,J=V+1,U=_;V<Y.length&&(U=Y[V].priority<Y[U].priority?V:U,J<Y.length&&(U=Y[J].priority<Y[U].priority?J:U),U!==_&&(this._swap(_,U),this._heapify(U)))}_decrease(_){for(var Y=this._arr,V=Y[_].priority,J;_!==0&&(J=_>>1,!(Y[J].priority<V));)this._swap(_,J),_=J}_swap(_,Y){var V=this._arr,J=this._keyIndices,U=V[_],H=V[Y];V[_]=H,V[Y]=U,J[H.key]=_,J[U.key]=Y}};D.exports=z}),y=o((T,D)=>{var z=p();D.exports=Y;var _=()=>1;function Y(J,U,H,X){var L=function(M){return J.outEdges(M)};return V(J,String(U),H||_,X||L)}function V(J,U,H,X){var L={},M=new z,q,K,ee=function(te){var se=te.v!==q?te.v:te.w,xe=L[se],ke=H(te),De=K.distance+ke;if(ke<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+te+" Weight: "+ke);De<xe.distance&&(xe.distance=De,xe.predecessor=q,M.decrease(se,De))};for(J.nodes().forEach(function(te){var se=te===U?0:Number.POSITIVE_INFINITY;L[te]={distance:se},M.add(te,se)});M.size()>0&&(q=M.removeMin(),K=L[q],K.distance!==Number.POSITIVE_INFINITY);)X(q).forEach(ee);return L}}),w=o((T,D)=>{var z=y();D.exports=_;function _(Y,V,J){return Y.nodes().reduce(function(U,H){return U[H]=z(Y,H,V,J),U},{})}}),N=o((T,D)=>{D.exports=z;function z(Y,V,J){if(Y[V].predecessor!==void 0)throw new Error("Invalid source vertex");if(Y[J].predecessor===void 0&&J!==V)throw new Error("Invalid destination vertex");return{weight:Y[J].distance,path:_(Y,V,J)}}function _(Y,V,J){for(var U=[],H=J;H!==V;)U.push(H),H=Y[H].predecessor;return U.push(V),U.reverse()}}),E=o((T,D)=>{D.exports=z;function z(_){var Y=0,V=[],J={},U=[];function H(X){var L=J[X]={onStack:!0,lowlink:Y,index:Y++};if(V.push(X),_.successors(X).forEach(function(K){Object.hasOwn(J,K)?J[K].onStack&&(L.lowlink=Math.min(L.lowlink,J[K].index)):(H(K),L.lowlink=Math.min(L.lowlink,J[K].lowlink))}),L.lowlink===L.index){var M=[],q;do q=V.pop(),J[q].onStack=!1,M.push(q);while(X!==q);U.push(M)}}return _.nodes().forEach(function(X){Object.hasOwn(J,X)||H(X)}),U}}),A=o((T,D)=>{var z=E();D.exports=_;function _(Y){return z(Y).filter(function(V){return V.length>1||V.length===1&&Y.hasEdge(V[0],V[0])})}}),C=o((T,D)=>{D.exports=_;var z=()=>1;function _(V,J,U){return Y(V,J||z,U||function(H){return V.outEdges(H)})}function Y(V,J,U){var H={},X=V.nodes();return X.forEach(function(L){H[L]={},H[L][L]={distance:0},X.forEach(function(M){L!==M&&(H[L][M]={distance:Number.POSITIVE_INFINITY})}),U(L).forEach(function(M){var q=M.v===L?M.w:M.v,K=J(M);H[L][q]={distance:K,predecessor:L}})}),X.forEach(function(L){var M=H[L];X.forEach(function(q){var K=H[q];X.forEach(function(ee){var te=K[L],se=M[ee],xe=K[ee],ke=te.distance+se.distance;ke<xe.distance&&(xe.distance=ke,xe.predecessor=se.predecessor)})})}),H}}),k=o((T,D)=>{function z(Y){var V={},J={},U=[];function H(X){if(Object.hasOwn(J,X))throw new _;Object.hasOwn(V,X)||(J[X]=!0,V[X]=!0,Y.predecessors(X).forEach(H),delete J[X],U.push(X))}if(Y.sinks().forEach(H),Object.keys(V).length!==Y.nodeCount())throw new _;return U}var _=class extends Error{constructor(){super(...arguments)}};D.exports=z,z.CycleException=_}),S=o((T,D)=>{var z=k();D.exports=_;function _(Y){try{z(Y)}catch(V){if(V instanceof z.CycleException)return!1;throw V}return!0}}),O=o((T,D)=>{D.exports=z;function z(Y,V,J,U,H){Array.isArray(V)||(V=[V]);var X=(Y.isDirected()?Y.successors:Y.neighbors).bind(Y),L={};return V.forEach(function(M){if(!Y.hasNode(M))throw new Error("Graph does not have node: "+M);H=_(Y,M,J==="post",L,X,U,H)}),H}function _(Y,V,J,U,H,X,L){return Object.hasOwn(U,V)||(U[V]=!0,J||(L=X(L,V)),H(V).forEach(function(M){L=_(Y,M,J,U,H,X,L)}),J&&(L=X(L,V))),L}}),R=o((T,D)=>{var z=O();D.exports=_;function _(Y,V,J){return z(Y,V,J,function(U,H){return U.push(H),U},[])}}),G=o((T,D)=>{var z=R();D.exports=_;function _(Y,V){return z(Y,V,"post")}}),I=o((T,D)=>{var z=R();D.exports=_;function _(Y,V){return z(Y,V,"pre")}}),Q=o((T,D)=>{var z=c(),_=p();D.exports=Y;function Y(V,J){var U=new z,H={},X=new _,L;function M(K){var ee=K.v===L?K.w:K.v,te=X.priority(ee);if(te!==void 0){var se=J(K);se<te&&(H[ee]=L,X.decrease(ee,se))}}if(V.nodeCount()===0)return U;V.nodes().forEach(function(K){X.add(K,Number.POSITIVE_INFINITY),U.setNode(K)}),X.decrease(V.nodes()[0],0);for(var q=!1;X.size()>0;){if(L=X.removeMin(),Object.hasOwn(H,L))U.setEdge(L,H[L]);else{if(q)throw new Error("Input graph is not connected: "+V);q=!0}V.nodeEdges(L).forEach(M)}return U}}),$=o((T,D)=>{var z=y(),_=x();D.exports=Y;function Y(J,U,H,X){return V(J,U,H,X||function(L){return J.outEdges(L)})}function V(J,U,H,X){if(H===void 0)return z(J,U,H,X);for(var L=!1,M=J.nodes(),q=0;q<M.length;q++){for(var K=X(M[q]),ee=0;ee<K.length;ee++){var te=K[ee],se=te.v===M[q]?te.v:te.w,xe=se===te.v?te.w:te.v;H({v:se,w:xe})<0&&(L=!0)}if(L)return _(J,U,H,X)}return z(J,U,H,X)}}),F=o((T,D)=>{D.exports={bellmanFord:x(),components:g(),dijkstra:y(),dijkstraAll:w(),extractPath:N(),findCycles:A(),floydWarshall:C(),isAcyclic:S(),postorder:G(),preorder:I(),prim:Q(),shortestPaths:$(),reduce:O(),tarjan:E(),topsort:k()}}),B=m();r.exports={Graph:B.Graph,json:f(),alg:F(),version:B.version}}),ML=cn((e,r)=>{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 l(c),c}enqueue(d){let c=this._sentinel;d._prev&&d._next&&l(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 l(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}r.exports=s}),DL=cn((e,r)=>{var s=ls().Graph,l=ML();r.exports=d;var o=()=>1;function d(g,p){if(g.nodeCount()<=1)return[];let y=m(g,p||o);return c(y.graph,y.buckets,y.zeroIdx).flatMap(w=>g.outEdges(w.v,w.w))}function c(g,p,y){let w=[],N=p[p.length-1],E=p[0],A;for(;g.nodeCount();){for(;A=E.dequeue();)h(g,p,y,A);for(;A=N.dequeue();)h(g,p,y,A);if(g.nodeCount()){for(let C=p.length-2;C>0;--C)if(A=p[C].dequeue(),A){w=w.concat(h(g,p,y,A,!0));break}}}return w}function h(g,p,y,w,N){let E=N?[]:void 0;return g.inEdges(w.v).forEach(A=>{let C=g.edge(A),k=g.node(A.v);N&&E.push({v:A.v,w:A.w}),k.out-=C,f(p,y,k)}),g.outEdges(w.v).forEach(A=>{let C=g.edge(A),k=A.w,S=g.node(k);S.in-=C,f(p,y,S)}),g.removeNode(w.v),E}function m(g,p){let y=new s,w=0,N=0;g.nodes().forEach(C=>{y.setNode(C,{v:C,in:0,out:0})}),g.edges().forEach(C=>{let k=y.edge(C.v,C.w)||0,S=p(C),O=k+S;y.setEdge(C.v,C.w,O),N=Math.max(N,y.node(C.v).out+=S),w=Math.max(w,y.node(C.w).in+=S)});let E=x(N+w+3).map(()=>new l),A=w+1;return y.nodes().forEach(C=>{f(E,A,y.node(C))}),{graph:y,buckets:E,zeroIdx:A}}function f(g,p,y){y.out?y.in?g[y.out-y.in+p].enqueue(y):g[g.length-1].enqueue(y):g[0].enqueue(y)}function x(g){let p=[];for(let y=0;y<g;y++)p.push(y);return p}}),qn=cn((e,r)=>{var s=ls().Graph;r.exports={addBorderNode:p,addDummyNode:l,applyWithChunking:N,asNonCompoundGraph:d,buildLayerMatrix:f,intersectRect:m,mapValues:I,maxRank:E,normalizeRanks:x,notime:k,partition:A,pick:G,predecessorWeights:h,range:R,removeEmptyRanks:g,simplify:o,successorWeights:c,time:C,uniqueId:O,zipObject:Q};function l($,F,B,T){for(var D=T;$.hasNode(D);)D=O(T);return B.dummy=F,$.setNode(D,B),D}function o($){let F=new s().setGraph($.graph());return $.nodes().forEach(B=>F.setNode(B,$.node(B))),$.edges().forEach(B=>{let T=F.edge(B.v,B.w)||{weight:0,minlen:1},D=$.edge(B);F.setEdge(B.v,B.w,{weight:T.weight+D.weight,minlen:Math.max(T.minlen,D.minlen)})}),F}function d($){let F=new s({multigraph:$.isMultigraph()}).setGraph($.graph());return $.nodes().forEach(B=>{$.children(B).length||F.setNode(B,$.node(B))}),$.edges().forEach(B=>{F.setEdge(B,$.edge(B))}),F}function c($){let F=$.nodes().map(B=>{let T={};return $.outEdges(B).forEach(D=>{T[D.w]=(T[D.w]||0)+$.edge(D).weight}),T});return Q($.nodes(),F)}function h($){let F=$.nodes().map(B=>{let T={};return $.inEdges(B).forEach(D=>{T[D.v]=(T[D.v]||0)+$.edge(D).weight}),T});return Q($.nodes(),F)}function m($,F){let B=$.x,T=$.y,D=F.x-B,z=F.y-T,_=$.width/2,Y=$.height/2;if(!D&&!z)throw new Error("Not possible to find intersection inside of the rectangle");let V,J;return Math.abs(z)*_>Math.abs(D)*Y?(z<0&&(Y=-Y),V=Y*D/z,J=Y):(D<0&&(_=-_),V=_,J=_*z/D),{x:B+V,y:T+J}}function f($){let F=R(E($)+1).map(()=>[]);return $.nodes().forEach(B=>{let T=$.node(B),D=T.rank;D!==void 0&&(F[D][T.order]=B)}),F}function x($){let F=$.nodes().map(T=>{let D=$.node(T).rank;return D===void 0?Number.MAX_VALUE:D}),B=N(Math.min,F);$.nodes().forEach(T=>{let D=$.node(T);Object.hasOwn(D,"rank")&&(D.rank-=B)})}function g($){let F=$.nodes().map(_=>$.node(_).rank).filter(_=>_!==void 0),B=N(Math.min,F),T=[];$.nodes().forEach(_=>{let Y=$.node(_).rank-B;T[Y]||(T[Y]=[]),T[Y].push(_)});let D=0,z=$.graph().nodeRankFactor;Array.from(T).forEach((_,Y)=>{_===void 0&&Y%z!==0?--D:_!==void 0&&D&&_.forEach(V=>$.node(V).rank+=D)})}function p($,F,B,T){let D={width:0,height:0};return arguments.length>=4&&(D.rank=B,D.order=T),l($,"border",D,F)}function y($,F=w){let B=[];for(let T=0;T<$.length;T+=F){let D=$.slice(T,T+F);B.push(D)}return B}var w=65535;function N($,F){if(F.length>w){let B=y(F);return $.apply(null,B.map(T=>$.apply(null,T)))}else return $.apply(null,F)}function E($){let F=$.nodes().map(B=>{let T=$.node(B).rank;return T===void 0?Number.MIN_VALUE:T});return N(Math.max,F)}function A($,F){let B={lhs:[],rhs:[]};return $.forEach(T=>{F(T)?B.lhs.push(T):B.rhs.push(T)}),B}function C($,F){let B=Date.now();try{return F()}finally{console.log($+" time: "+(Date.now()-B)+"ms")}}function k($,F){return F()}var S=0;function O($){var F=++S;return $+(""+F)}function R($,F,B=1){F==null&&(F=$,$=0);let T=z=>z<F;B<0&&(T=z=>F<z);let D=[];for(let z=$;T(z);z+=B)D.push(z);return D}function G($,F){let B={};for(let T of F)$[T]!==void 0&&(B[T]=$[T]);return B}function I($,F){let B=F;return typeof F=="string"&&(B=T=>T[F]),Object.entries($).reduce((T,[D,z])=>(T[D]=B(z,D),T),{})}function Q($,F){return $.reduce((B,T,D)=>(B[T]=F[D],B),{})}}),OL=cn((e,r)=>{var s=DL(),l=qn().uniqueId;r.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,l("rev"))});function m(f){return x=>f.edge(x).weight}}function d(h){let m=[],f={},x={};function g(p){Object.hasOwn(x,p)||(x[p]=!0,f[p]=!0,h.outEdges(p).forEach(y=>{Object.hasOwn(f,y.w)?m.push(y):g(y.w)}),delete f[p])}return h.nodes().forEach(g),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)}})}}),RL=cn((e,r)=>{var s=qn();r.exports={run:l,undo:d};function l(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,g=c.node(x).rank,p=h.name,y=c.edge(h),w=y.labelRank;if(g===f+1)return;c.removeEdge(h);let N,E,A;for(A=0,++f;f<g;++A,++f)y.points=[],E={width:0,height:0,edgeLabel:y,edgeObj:h,rank:f},N=s.addDummyNode(c,"edge",E,"_d"),f===w&&(E.width=y.width,E.height=y.height,E.dummy="edge-label",E.labelpos=y.labelpos),c.setEdge(m,N,{weight:y.weight},p),A===0&&c.graph().dummyChains.push(N),m=N;c.setEdge(m,x,{weight:y.weight},p)}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)})}}),qd=cn((e,r)=>{var{applyWithChunking:s}=qn();r.exports={longestPath:l,slack:o};function l(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(p=>p==null?Number.POSITIVE_INFINITY:h(p.w)-d.edge(p).minlen);var g=s(Math.min,x);return g===Number.POSITIVE_INFINITY&&(g=0),f.rank=g}d.sources().forEach(h)}function o(d,c){return d.node(c.w).rank-d.node(c.v).rank-d.edge(c).minlen}}),jN=cn((e,r)=>{var s=ls().Graph,l=qd().slack;r.exports=o;function o(m){var f=new s({directed:!1}),x=m.nodes()[0],g=m.nodeCount();f.setNode(x,{});for(var p,y;d(f,m)<g;)p=c(f,m),y=f.hasNode(p.v)?l(m,p):-l(m,p),h(f,m,y);return f}function d(m,f){function x(g){f.nodeEdges(g).forEach(p=>{var y=p.v,w=g===y?p.w:y;!m.hasNode(w)&&!l(f,p)&&(m.setNode(w,{}),m.setEdge(g,w,{}),x(w))})}return m.nodes().forEach(x),m.nodeCount()}function c(m,f){return f.edges().reduce((x,g)=>{let p=Number.POSITIVE_INFINITY;return m.hasNode(g.v)!==m.hasNode(g.w)&&(p=l(f,g)),p<x[0]?[p,g]:x},[Number.POSITIVE_INFINITY,null])[1]}function h(m,f,x){m.nodes().forEach(g=>f.node(g).rank+=x)}}),LL=cn((e,r)=>{var s=jN(),l=qd().slack,o=qd().longestPath,d=ls().alg.preorder,c=ls().alg.postorder,h=qn().simplify;r.exports=m,m.initLowLimValues=p,m.initCutValues=f,m.calcCutValue=g,m.leaveEdge=w,m.enterEdge=N,m.exchangeEdges=E;function m(S){S=h(S),o(S);var O=s(S);p(O),f(O,S);for(var R,G;R=w(O);)G=N(O,S,R),E(O,S,R,G)}function f(S,O){var R=c(S,S.nodes());R=R.slice(0,R.length-1),R.forEach(G=>x(S,O,G))}function x(S,O,R){var G=S.node(R),I=G.parent;S.edge(R,I).cutvalue=g(S,O,R)}function g(S,O,R){var G=S.node(R),I=G.parent,Q=!0,$=O.edge(R,I),F=0;return $||(Q=!1,$=O.edge(I,R)),F=$.weight,O.nodeEdges(R).forEach(B=>{var T=B.v===R,D=T?B.w:B.v;if(D!==I){var z=T===Q,_=O.edge(B).weight;if(F+=z?_:-_,C(S,R,D)){var Y=S.edge(R,D).cutvalue;F+=z?-Y:Y}}}),F}function p(S,O){arguments.length<2&&(O=S.nodes()[0]),y(S,{},1,O)}function y(S,O,R,G,I){var Q=R,$=S.node(G);return O[G]=!0,S.neighbors(G).forEach(F=>{Object.hasOwn(O,F)||(R=y(S,O,R,F,G))}),$.low=Q,$.lim=R++,I?$.parent=I:delete $.parent,R}function w(S){return S.edges().find(O=>S.edge(O).cutvalue<0)}function N(S,O,R){var G=R.v,I=R.w;O.hasEdge(G,I)||(G=R.w,I=R.v);var Q=S.node(G),$=S.node(I),F=Q,B=!1;Q.lim>$.lim&&(F=$,B=!0);var T=O.edges().filter(D=>B===k(S,S.node(D.v),F)&&B!==k(S,S.node(D.w),F));return T.reduce((D,z)=>l(O,z)<l(O,D)?z:D)}function E(S,O,R,G){var I=R.v,Q=R.w;S.removeEdge(I,Q),S.setEdge(G.v,G.w,{}),p(S),f(S,O),A(S,O)}function A(S,O){var R=S.nodes().find(I=>!O.node(I).parent),G=d(S,R);G=G.slice(1),G.forEach(I=>{var Q=S.node(I).parent,$=O.edge(I,Q),F=!1;$||($=O.edge(Q,I),F=!0),O.node(I).rank=O.node(Q).rank+(F?$.minlen:-$.minlen)})}function C(S,O,R){return S.hasEdge(O,R)}function k(S,O,R){return R.low<=O.lim&&O.lim<=R.lim}}),zL=cn((e,r)=>{var s=qd(),l=s.longestPath,o=jN(),d=LL();r.exports=c;function c(x){var g=x.graph().ranker;if(g instanceof Function)return g(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=l;function m(x){l(x),o(x)}function f(x){d(x)}}),IL=cn((e,r)=>{r.exports=s;function s(d){let c=o(d);d.graph().dummyChains.forEach(h=>{let m=d.node(h),f=m.edgeObj,x=l(d,c,f.v,f.w),g=x.path,p=x.lca,y=0,w=g[y],N=!0;for(;h!==f.w;){if(m=d.node(h),N){for(;(w=g[y])!==p&&d.node(w).maxRank<m.rank;)y++;w===p&&(N=!1)}if(!N){for(;y<g.length-1&&d.node(w=g[y+1]).minRank<=m.rank;)y++;w=g[y]}d.setParent(h,w),h=d.successors(h)[0]}})}function l(d,c,h,m){let f=[],x=[],g=Math.min(c[h].low,c[m].low),p=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>g||p>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}}),$L=cn((e,r)=>{var s=qn();r.exports={run:l,cleanup:h};function l(m){let f=s.addDummyNode(m,"root",{},"_root"),x=d(m),g=Object.values(x),p=s.applyWithChunking(Math.max,g)-1,y=2*p+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,p,x,N)),m.graph().nodeRankFactor=y}function o(m,f,x,g,p,y,w){let N=m.children(w);if(!N.length){w!==f&&m.setEdge(f,w,{weight:0,minlen:x});return}let E=s.addBorderNode(m,"_bt"),A=s.addBorderNode(m,"_bb"),C=m.node(w);m.setParent(E,w),C.borderTop=E,m.setParent(A,w),C.borderBottom=A,N.forEach(k=>{o(m,f,x,g,p,y,k);let S=m.node(k),O=S.borderTop?S.borderTop:k,R=S.borderBottom?S.borderBottom:k,G=S.borderTop?g:2*g,I=O!==R?1:p-y[w]+1;m.setEdge(E,O,{weight:G,minlen:I,nestingEdge:!0}),m.setEdge(R,A,{weight:G,minlen:I,nestingEdge:!0})}),m.parent(w)||m.setEdge(f,E,{weight:0,minlen:p+y[w]})}function d(m){var f={};function x(g,p){var y=m.children(g);y&&y.length&&y.forEach(w=>x(w,p+1)),f[g]=p}return m.children().forEach(g=>x(g,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 g=m.edge(x);g.nestingEdge&&m.removeEdge(x)})}}),BL=cn((e,r)=>{var s=qn();r.exports=l;function l(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,g=f.maxRank+1;x<g;++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 g={width:0,height:0,rank:x,borderType:c},p=f[c][x-1],y=s.addDummyNode(d,"border",g,h);f[c][x]=y,d.setParent(y,m),p&&d.setEdge(p,y,{weight:1})}}),HL=cn((e,r)=>{r.exports={adjust:s,undo:l};function s(x){let g=x.graph().rankdir.toLowerCase();(g==="lr"||g==="rl")&&o(x)}function l(x){let g=x.graph().rankdir.toLowerCase();(g==="bt"||g==="rl")&&c(x),(g==="lr"||g==="rl")&&(m(x),o(x))}function o(x){x.nodes().forEach(g=>d(x.node(g))),x.edges().forEach(g=>d(x.edge(g)))}function d(x){let g=x.width;x.width=x.height,x.height=g}function c(x){x.nodes().forEach(g=>h(x.node(g))),x.edges().forEach(g=>{let p=x.edge(g);p.points.forEach(h),Object.hasOwn(p,"y")&&h(p)})}function h(x){x.y=-x.y}function m(x){x.nodes().forEach(g=>f(x.node(g))),x.edges().forEach(g=>{let p=x.edge(g);p.points.forEach(f),Object.hasOwn(p,"x")&&f(p)})}function f(x){let g=x.x;x.x=x.y,x.y=g}}),PL=cn((e,r)=>{var s=qn();r.exports=l;function l(o){let d={},c=o.nodes().filter(g=>!o.children(g).length),h=c.map(g=>o.node(g).rank),m=s.applyWithChunking(Math.max,h),f=s.range(m+1).map(()=>[]);function x(g){if(d[g])return;d[g]=!0;let p=o.node(g);f[p.rank].push(g),o.successors(g).forEach(x)}return c.sort((g,p)=>o.node(g).rank-o.node(p).rank).forEach(x),f}}),UL=cn((e,r)=>{var s=qn().zipObject;r.exports=l;function l(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,E)=>N.pos-E.pos)),x=1;for(;x<h.length;)x<<=1;let g=2*x-1;x-=1;let p=new Array(g).fill(0),y=0;return f.forEach(w=>{let N=w.pos+x;p[N]+=w.weight;let E=0;for(;N>0;)N%2&&(E+=p[N+1]),N=N-1>>1,p[N]+=w.weight;y+=w.weight*E}),y}}),qL=cn((e,r)=>{r.exports=s;function s(l,o=[]){return o.map(d=>{let c=l.inEdges(d);if(c.length){let h=c.reduce((m,f)=>{let x=l.edge(f),g=l.node(f.v);return{sum:m.sum+x.weight*g.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}})}}),FL=cn((e,r)=>{var s=qn();r.exports=l;function l(c,h){let m={};c.forEach((x,g)=>{let p=m[x.v]={indegree:0,in:[],out:[],vs:[x.v],i:g};x.barycenter!==void 0&&(p.barycenter=x.barycenter,p.weight=x.weight)}),h.edges().forEach(x=>{let g=m[x.v],p=m[x.w];g!==void 0&&p!==void 0&&(p.indegree++,g.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 g=>{g.merged||(g.barycenter===void 0||x.barycenter===void 0||g.barycenter>=x.barycenter)&&d(x,g)}}function f(x){return g=>{g.in.push(x),--g.indegree===0&&c.push(g)}}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}}),VL=cn((e,r)=>{var s=qn();r.exports=l;function l(c,h){let m=s.partition(c,E=>Object.hasOwn(E,"barycenter")),f=m.lhs,x=m.rhs.sort((E,A)=>A.i-E.i),g=[],p=0,y=0,w=0;f.sort(d(!!h)),w=o(g,x,w),f.forEach(E=>{w+=E.vs.length,g.push(E.vs),p+=E.barycenter*E.weight,y+=E.weight,w=o(g,x,w)});let N={vs:g.flat(!0)};return y&&(N.barycenter=p/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}}),YL=cn((e,r)=>{var s=qL(),l=FL(),o=VL();r.exports=d;function d(m,f,x,g){let p=m.children(f),y=m.node(f),w=y?y.borderLeft:void 0,N=y?y.borderRight:void 0,E={};w&&(p=p.filter(S=>S!==w&&S!==N));let A=s(m,p);A.forEach(S=>{if(m.children(S.v).length){let O=d(m,S.v,x,g);E[S.v]=O,Object.hasOwn(O,"barycenter")&&h(S,O)}});let C=l(A,x);c(C,E);let k=o(C,g);if(w&&(k.vs=[w,k.vs,N].flat(!0),m.predecessors(w).length)){let S=m.node(m.predecessors(w)[0]),O=m.node(m.predecessors(N)[0]);Object.hasOwn(k,"barycenter")||(k.barycenter=0,k.weight=0),k.barycenter=(k.barycenter*k.weight+S.order+O.order)/(k.weight+2),k.weight+=2}return k}function c(m,f){m.forEach(x=>{x.vs=x.vs.flatMap(g=>f[g]?f[g].vs:g)})}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)}}),GL=cn((e,r)=>{var s=ls().Graph,l=qn();r.exports=o;function o(c,h,m,f){f||(f=c.nodes());let x=d(c),g=new s({compound:!0}).setGraph({root:x}).setDefaultNodeLabel(p=>c.node(p));return f.forEach(p=>{let y=c.node(p),w=c.parent(p);(y.rank===h||y.minRank<=h&&h<=y.maxRank)&&(g.setNode(p),g.setParent(p,w||x),c[m](p).forEach(N=>{let E=N.v===p?N.w:N.v,A=g.edge(E,p),C=A!==void 0?A.weight:0;g.setEdge(E,p,{weight:c.edge(N).weight+C})}),Object.hasOwn(y,"minRank")&&g.setNode(p,{borderLeft:y.borderLeft[h],borderRight:y.borderRight[h]}))}),g}function d(c){for(var h;c.hasNode(h=l.uniqueId("_root")););return h}}),XL=cn((e,r)=>{r.exports=s;function s(l,o,d){let c={},h;d.forEach(m=>{let f=l.parent(m),x,g;for(;f;){if(x=l.parent(f),x?(g=c[x],c[x]=f):(g=h,h=f),g&&g!==f){o.setEdge(g,f);return}f=x}})}}),ZL=cn((e,r)=>{var s=PL(),l=UL(),o=YL(),d=GL(),c=XL(),h=ls().Graph,m=qn();r.exports=f;function f(y,w={}){if(typeof w.customOrder=="function"){w.customOrder(y,f);return}let N=m.maxRank(y),E=x(y,m.range(1,N+1),"inEdges"),A=x(y,m.range(N-1,-1,-1),"outEdges"),C=s(y);if(p(y,C),w.disableOptimalOrderHeuristic)return;let k=Number.POSITIVE_INFINITY,S,O=w.constraints||[];for(let R=0,G=0;G<4;++R,++G){g(R%2?E:A,R%4>=2,O),C=m.buildLayerMatrix(y);let I=l(y,C);I<k?(G=0,S=Object.assign({},C),k=I):I===k&&(S=structuredClone(C))}p(y,S)}function x(y,w,N){let E=new Map,A=(C,k)=>{E.has(C)||E.set(C,[]),E.get(C).push(k)};for(let C of y.nodes()){let k=y.node(C);if(typeof k.rank=="number"&&A(k.rank,C),typeof k.minRank=="number"&&typeof k.maxRank=="number")for(let S=k.minRank;S<=k.maxRank;S++)S!==k.rank&&A(S,C)}return w.map(function(C){return d(y,C,N,E.get(C)||[])})}function g(y,w,N){let E=new h;y.forEach(function(A){N.forEach(S=>E.setEdge(S.left,S.right));let C=A.graph().root,k=o(A,C,E,w);k.vs.forEach((S,O)=>A.node(S).order=O),c(A,E,k.vs)})}function p(y,w){Object.values(w).forEach(N=>N.forEach((E,A)=>y.node(E).order=A))}}),QL=cn((e,r)=>{var s=ls().Graph,l=qn();r.exports={positionX:N,findType1Conflicts:o,findType2Conflicts:d,addConflict:h,hasConflict:m,verticalAlignment:f,horizontalCompaction:x,alignCoordinates:y,findSmallestWidthAlignment:p,balance:w};function o(C,k){let S={};function O(R,G){let I=0,Q=0,$=R.length,F=G[G.length-1];return G.forEach((B,T)=>{let D=c(C,B),z=D?C.node(D).order:$;(D||B===F)&&(G.slice(Q,T+1).forEach(_=>{C.predecessors(_).forEach(Y=>{let V=C.node(Y),J=V.order;(J<I||z<J)&&!(V.dummy&&C.node(_).dummy)&&h(S,Y,_)})}),Q=T+1,I=z)}),G}return k.length&&k.reduce(O),S}function d(C,k){let S={};function O(G,I,Q,$,F){let B;l.range(I,Q).forEach(T=>{B=G[T],C.node(B).dummy&&C.predecessors(B).forEach(D=>{let z=C.node(D);z.dummy&&(z.order<$||z.order>F)&&h(S,D,B)})})}function R(G,I){let Q=-1,$,F=0;return I.forEach((B,T)=>{if(C.node(B).dummy==="border"){let D=C.predecessors(B);D.length&&($=C.node(D[0]).order,O(I,F,T,Q,$),F=T,Q=$)}O(I,F,I.length,$,G.length)}),I}return k.length&&k.reduce(R),S}function c(C,k){if(C.node(k).dummy)return C.predecessors(k).find(S=>C.node(S).dummy)}function h(C,k,S){if(k>S){let R=k;k=S,S=R}let O=C[k];O||(C[k]=O={}),O[S]=!0}function m(C,k,S){if(k>S){let O=k;k=S,S=O}return!!C[k]&&Object.hasOwn(C[k],S)}function f(C,k,S,O){let R={},G={},I={};return k.forEach(Q=>{Q.forEach(($,F)=>{R[$]=$,G[$]=$,I[$]=F})}),k.forEach(Q=>{let $=-1;Q.forEach(F=>{let B=O(F);if(B.length){B=B.sort((D,z)=>I[D]-I[z]);let T=(B.length-1)/2;for(let D=Math.floor(T),z=Math.ceil(T);D<=z;++D){let _=B[D];G[F]===F&&$<I[_]&&!m(S,F,_)&&(G[_]=F,G[F]=R[F]=R[_],$=I[_])}}})}),{root:R,align:G}}function x(C,k,S,O,R){let G={},I=g(C,k,S,R),Q=R?"borderLeft":"borderRight";function $(T,D){let z=I.nodes().slice(),_={},Y=z.pop();for(;Y;){if(_[Y])T(Y);else{_[Y]=!0,z.push(Y);for(let V of D(Y))z.push(V)}Y=z.pop()}}function F(T){G[T]=I.inEdges(T).reduce((D,z)=>Math.max(D,G[z.v]+I.edge(z)),0)}function B(T){let D=I.outEdges(T).reduce((_,Y)=>Math.min(_,G[Y.w]-I.edge(Y)),Number.POSITIVE_INFINITY),z=C.node(T);D!==Number.POSITIVE_INFINITY&&z.borderType!==Q&&(G[T]=Math.max(G[T],D))}return $(F,I.predecessors.bind(I)),$(B,I.successors.bind(I)),Object.keys(O).forEach(T=>G[T]=G[S[T]]),G}function g(C,k,S,O){let R=new s,G=C.graph(),I=E(G.nodesep,G.edgesep,O);return k.forEach(Q=>{let $;Q.forEach(F=>{let B=S[F];if(R.setNode(B),$){var T=S[$],D=R.edge(T,B);R.setEdge(T,B,Math.max(I(C,F,$),D||0))}$=F})}),R}function p(C,k){return Object.values(k).reduce((S,O)=>{let R=Number.NEGATIVE_INFINITY,G=Number.POSITIVE_INFINITY;Object.entries(O).forEach(([Q,$])=>{let F=A(C,Q)/2;R=Math.max($+F,R),G=Math.min($-F,G)});let I=R-G;return I<S[0]&&(S=[I,O]),S},[Number.POSITIVE_INFINITY,null])[1]}function y(C,k){let S=Object.values(k),O=l.applyWithChunking(Math.min,S),R=l.applyWithChunking(Math.max,S);["u","d"].forEach(G=>{["l","r"].forEach(I=>{let Q=G+I,$=C[Q];if($===k)return;let F=Object.values($),B=O-l.applyWithChunking(Math.min,F);I!=="l"&&(B=R-l.applyWithChunking(Math.max,F)),B&&(C[Q]=l.mapValues($,T=>T+B))})})}function w(C,k){return l.mapValues(C.ul,(S,O)=>{if(k)return C[k.toLowerCase()][O];{let R=Object.values(C).map(G=>G[O]).sort((G,I)=>G-I);return(R[1]+R[2])/2}})}function N(C){let k=l.buildLayerMatrix(C),S=Object.assign(o(C,k),d(C,k)),O={},R;["u","d"].forEach(I=>{R=I==="u"?k:Object.values(k).reverse(),["l","r"].forEach(Q=>{Q==="r"&&(R=R.map(T=>Object.values(T).reverse()));let $=(I==="u"?C.predecessors:C.successors).bind(C),F=f(C,R,S,$),B=x(C,R,F.root,F.align,Q==="r");Q==="r"&&(B=l.mapValues(B,T=>-T)),O[I+Q]=B})});let G=p(C,O);return y(O,G),w(O,C.graph().align)}function E(C,k,S){return(O,R,G)=>{let I=O.node(R),Q=O.node(G),$=0,F;if($+=I.width/2,Object.hasOwn(I,"labelpos"))switch(I.labelpos.toLowerCase()){case"l":F=-I.width/2;break;case"r":F=I.width/2;break}if(F&&($+=S?F:-F),F=0,$+=(I.dummy?k:C)/2,$+=(Q.dummy?k:C)/2,$+=Q.width/2,Object.hasOwn(Q,"labelpos"))switch(Q.labelpos.toLowerCase()){case"l":F=Q.width/2;break;case"r":F=-Q.width/2;break}return F&&($+=S?F:-F),F=0,$}}function A(C,k){return C.node(k).width}}),KL=cn((e,r)=>{var s=qn(),l=QL().positionX;r.exports=o;function o(c){c=s.asNonCompoundGraph(c),d(c),Object.entries(l(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(g=>{let p=g.reduce((y,w)=>{let N=c.node(w).height;return y>N?y:N},0);g.forEach(y=>{let w=c.node(y);f==="top"?w.y=x+w.height/2:f==="bottom"?w.y=x+p-w.height/2:w.y=x+p/2}),x+=p+m})}}),JL=cn((e,r)=>{var s=OL(),l=RL(),o=zL(),d=qn().normalizeRanks,c=IL(),h=qn().removeEmptyRanks,m=$L(),f=BL(),x=HL(),g=ZL(),p=KL(),y=qn(),w=ls().Graph;r.exports=N;function N(q,K={}){let ee=K.debugTiming?y.time:y.notime;return ee("layout",()=>{let te=ee(" buildLayoutGraph",()=>$(q));return ee(" runLayout",()=>E(te,ee,K)),ee(" updateInputGraph",()=>A(q,te)),te})}function E(q,K,ee){K(" makeSpaceForEdgeLabels",()=>F(q)),K(" removeSelfEdges",()=>U(q)),K(" acyclic",()=>s.run(q)),K(" nestingGraph.run",()=>m.run(q)),K(" rank",()=>o(y.asNonCompoundGraph(q))),K(" injectEdgeLabelProxies",()=>B(q)),K(" removeEmptyRanks",()=>h(q)),K(" nestingGraph.cleanup",()=>m.cleanup(q)),K(" normalizeRanks",()=>d(q)),K(" assignRankMinMax",()=>T(q)),K(" removeEdgeLabelProxies",()=>D(q)),K(" normalize.run",()=>l.run(q)),K(" parentDummyChains",()=>c(q)),K(" addBorderSegments",()=>f(q)),K(" order",()=>g(q,ee)),K(" insertSelfEdges",()=>H(q)),K(" adjustCoordinateSystem",()=>x.adjust(q)),K(" position",()=>p(q)),K(" positionSelfEdges",()=>X(q)),K(" removeBorderNodes",()=>J(q)),K(" normalize.undo",()=>l.undo(q)),K(" fixupEdgeLabelCoords",()=>Y(q)),K(" undoCoordinateSystem",()=>x.undo(q)),K(" translateGraph",()=>z(q)),K(" assignNodeIntersects",()=>_(q)),K(" reversePoints",()=>V(q)),K(" acyclic.undo",()=>s.undo(q))}function A(q,K){q.nodes().forEach(ee=>{let te=q.node(ee),se=K.node(ee);te&&(te.x=se.x,te.y=se.y,te.order=se.order,te.rank=se.rank,K.children(ee).length&&(te.width=se.width,te.height=se.height))}),q.edges().forEach(ee=>{let te=q.edge(ee),se=K.edge(ee);te.points=se.points,Object.hasOwn(se,"x")&&(te.x=se.x,te.y=se.y)}),q.graph().width=K.graph().width,q.graph().height=K.graph().height}var C=["nodesep","edgesep","ranksep","marginx","marginy"],k={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},S=["acyclicer","ranker","rankdir","align","rankalign"],O=["width","height","rank"],R={width:0,height:0},G=["minlen","weight","width","height","labeloffset"],I={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Q=["labelpos"];function $(q){let K=new w({multigraph:!0,compound:!0}),ee=M(q.graph());return K.setGraph(Object.assign({},k,L(ee,C),y.pick(ee,S))),q.nodes().forEach(te=>{let se=M(q.node(te)),xe=L(se,O);Object.keys(R).forEach(ke=>{xe[ke]===void 0&&(xe[ke]=R[ke])}),K.setNode(te,xe),K.setParent(te,q.parent(te))}),q.edges().forEach(te=>{let se=M(q.edge(te));K.setEdge(te,Object.assign({},I,L(se,G),y.pick(se,Q)))}),K}function F(q){let K=q.graph();K.ranksep/=2,q.edges().forEach(ee=>{let te=q.edge(ee);te.minlen*=2,te.labelpos.toLowerCase()!=="c"&&(K.rankdir==="TB"||K.rankdir==="BT"?te.width+=te.labeloffset:te.height+=te.labeloffset)})}function B(q){q.edges().forEach(K=>{let ee=q.edge(K);if(ee.width&&ee.height){let te=q.node(K.v),se={rank:(q.node(K.w).rank-te.rank)/2+te.rank,e:K};y.addDummyNode(q,"edge-proxy",se,"_ep")}})}function T(q){let K=0;q.nodes().forEach(ee=>{let te=q.node(ee);te.borderTop&&(te.minRank=q.node(te.borderTop).rank,te.maxRank=q.node(te.borderBottom).rank,K=Math.max(K,te.maxRank))}),q.graph().maxRank=K}function D(q){q.nodes().forEach(K=>{let ee=q.node(K);ee.dummy==="edge-proxy"&&(q.edge(ee.e).labelRank=ee.rank,q.removeNode(K))})}function z(q){let K=Number.POSITIVE_INFINITY,ee=0,te=Number.POSITIVE_INFINITY,se=0,xe=q.graph(),ke=xe.marginx||0,De=xe.marginy||0;function ge(ye){let Ce=ye.x,ze=ye.y,tt=ye.width,Xe=ye.height;K=Math.min(K,Ce-tt/2),ee=Math.max(ee,Ce+tt/2),te=Math.min(te,ze-Xe/2),se=Math.max(se,ze+Xe/2)}q.nodes().forEach(ye=>ge(q.node(ye))),q.edges().forEach(ye=>{let Ce=q.edge(ye);Object.hasOwn(Ce,"x")&&ge(Ce)}),K-=ke,te-=De,q.nodes().forEach(ye=>{let Ce=q.node(ye);Ce.x-=K,Ce.y-=te}),q.edges().forEach(ye=>{let Ce=q.edge(ye);Ce.points.forEach(ze=>{ze.x-=K,ze.y-=te}),Object.hasOwn(Ce,"x")&&(Ce.x-=K),Object.hasOwn(Ce,"y")&&(Ce.y-=te)}),xe.width=ee-K+ke,xe.height=se-te+De}function _(q){q.edges().forEach(K=>{let ee=q.edge(K),te=q.node(K.v),se=q.node(K.w),xe,ke;ee.points?(xe=ee.points[0],ke=ee.points[ee.points.length-1]):(ee.points=[],xe=se,ke=te),ee.points.unshift(y.intersectRect(te,xe)),ee.points.push(y.intersectRect(se,ke))})}function Y(q){q.edges().forEach(K=>{let ee=q.edge(K);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(q){q.edges().forEach(K=>{let ee=q.edge(K);ee.reversed&&ee.points.reverse()})}function J(q){q.nodes().forEach(K=>{if(q.children(K).length){let ee=q.node(K),te=q.node(ee.borderTop),se=q.node(ee.borderBottom),xe=q.node(ee.borderLeft[ee.borderLeft.length-1]),ke=q.node(ee.borderRight[ee.borderRight.length-1]);ee.width=Math.abs(ke.x-xe.x),ee.height=Math.abs(se.y-te.y),ee.x=xe.x+ee.width/2,ee.y=te.y+ee.height/2}}),q.nodes().forEach(K=>{q.node(K).dummy==="border"&&q.removeNode(K)})}function U(q){q.edges().forEach(K=>{if(K.v===K.w){var ee=q.node(K.v);ee.selfEdges||(ee.selfEdges=[]),ee.selfEdges.push({e:K,label:q.edge(K)}),q.removeEdge(K)}})}function H(q){var K=y.buildLayerMatrix(q);K.forEach(ee=>{var te=0;ee.forEach((se,xe)=>{var ke=q.node(se);ke.order=xe+te,(ke.selfEdges||[]).forEach(De=>{y.addDummyNode(q,"selfedge",{width:De.label.width,height:De.label.height,rank:ke.rank,order:xe+ ++te,e:De.e,label:De.label},"_se")}),delete ke.selfEdges})})}function X(q){q.nodes().forEach(K=>{var ee=q.node(K);if(ee.dummy==="selfedge"){var te=q.node(ee.e.v),se=te.x+te.width/2,xe=te.y,ke=ee.x-se,De=te.height/2;q.setEdge(ee.e,ee.label),q.removeNode(K),ee.label.points=[{x:se+2*ke/3,y:xe-De},{x:se+5*ke/6,y:xe-De},{x:se+ke,y:xe},{x:se+5*ke/6,y:xe+De},{x:se+2*ke/3,y:xe+De}],ee.label.x=ee.x,ee.label.y=ee.y}})}function L(q,K){return y.mapValues(y.pick(q,K),Number)}function M(q){var K={};return q&&Object.entries(q).forEach(([ee,te])=>{typeof ee=="string"&&(ee=ee.toLowerCase()),K[ee]=te}),K}}),WL=cn((e,r)=>{var s=qn(),l=ls().Graph;r.exports={debugOrdering:o};function o(d){let c=s.buildLayerMatrix(d),h=new l({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((g,p)=>(h.setEdge(g,p,{style:"invis"}),p))}),h}}),ez=cn((e,r)=>{r.exports="2.0.4"}),tz=cn((e,r)=>{r.exports={graphlib:ls(),layout:JL(),debug:WL(),util:{time:qn().time,notime:qn().notime},version:ez()}});const Rv=tz();const Lv={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"}},nz={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function rz({data:e}){const{task:r,agentName:s,selected:l}=e,o=Lv[r.status]??Lv.pending,d=r.taskType==="scheduled"&&!!r.scheduleConfig,c=d?r.scheduleConfig.every?`Every ${r.scheduleConfig.every}`:r.scheduleConfig.cron?"Cron":"":"";return t.jsxs("div",{className:`rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${d?`${o.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${o.bg} ${o.border}`} ${l?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[t.jsx(Ma,{type:"target",position:lt.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 ${nz[r.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${o.text}`,children:r.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:r.title}),s&&t.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:s}),r.blockedBy&&r.blockedBy.length>0&&t.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[r.blockedBy.length," dep",r.blockedBy.length>1?"s":""]}),t.jsx(Ma,{type:"source",position:lt.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"}},Iv={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done"};function sz({data:e}){const{req:r,selected:s}=e,l=zv[r.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 ${l.bg} ${l.border} ${s?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[t.jsx(Ma,{type:"target",position:lt.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 ${l.text}`,children:r.status.replace("_"," ")})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:r.title}),r.taskIds.length>0&&t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[r.taskIds.length," task",r.taskIds.length>1?"s":""]}),t.jsx(Ma,{type:"source",position:lt.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const az={task:rz,requirement:sz},lz=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&window.matchMedia("(prefers-color-scheme: light)").matches,iz=e=>{const r=new MutationObserver(e);r.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const s=window.matchMedia("(prefers-color-scheme: light)");return s.addEventListener("change",e),()=>{r.disconnect(),s.removeEventListener("change",e)}};function oz(){return v.useSyncExternalStore(iz,lz,()=>!1)}const Im=200,$m=80;function $v(e,r,s="TB"){const l=new Rv.graphlib.Graph;l.setDefaultEdgeLabel(()=>({})),l.setGraph({rankdir:s,nodesep:40,ranksep:60});for(const o of e)l.setNode(o.id,{width:Im,height:$m});for(const o of r)l.setEdge(o.source,o.target);return Rv.layout(l),e.map(o=>{const d=l.node(o.id);return{...o,position:{x:(d?.x??0)-Im/2,y:(d?.y??0)-$m/2}}})}function cz(e,r){const s=new Map,l=new Map;for(const c of e)l.set(c.id,c),s.set(c.id,new Set);for(const c of r)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:r.filter(f=>h.has(f.source)&&h.has(f.target))})}return d}function dz(e,r){if(e.length===0)return[];const s=cz(e,r);if(s.length===1)return $v(e,r);const l=s.map(g=>{const p=$v(g.nodes,g.edges);let y=1/0,w=-1/0,N=1/0,E=-1/0;for(const A of p)y=Math.min(y,A.position.x),w=Math.max(w,A.position.x+Im),N=Math.min(N,A.position.y),E=Math.max(E,A.position.y+$m);for(const A of p)A.position.x-=y,A.position.y-=N;return{nodes:p,w:w-y,h:E-N}});l.sort((g,p)=>p.h-g.h);const o=60,d=l.reduce((g,p)=>g+(p.w+o)*(p.h+o),0),c=Math.sqrt(d)*1.1,h=[];let m=0,f=0,x=0;for(const g of l){m>0&&m+g.w>c&&(m=0,f+=x+o,x=0);for(const p of g.nodes)h.push({...p,position:{x:p.position.x+m,y:p.position.y+f}});m+=g.w+o,x=Math.max(x,g.h)}return h}function uz(e,r,s){const l=new Set,o=[r];for(;o.length>0;){const d=o.pop();if(d===s)return!0;if(l.has(d))continue;l.add(d);const c=e.get(d);if(c?.blockedBy)for(const h of c.blockedBy)o.push(h)}return!1}const ho=[{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"}}],em=new Set(ho.map(e=>e.id)),fz=1440*60*1e3,Bv=e=>e.status==="completed"&&e.updatedAt&&Date.now()-new Date(e.updatedAt).getTime()>fz;function hz({tasks:e,requirements:r=[],agents:s,showArchived:l,onShowArchivedChange:o,onTaskClick:d,onReqClick:c,onDependencyChange:h,selectedTaskId:m,selectedReqId:f}){const x=oz(),[g,p]=v.useState(null),[y,w]=v.useState(null),[N,E]=v.useState(new Set(em)),[A,C]=v.useState(l??!1),k=l??A,S=v.useCallback(ge=>{const ye=typeof ge=="function"?ge(k):ge;C(ye),o?.(ye)},[k,o]);v.useEffect(()=>{l!==void 0&&C(l)},[l]);const O=v.useMemo(()=>e.filter(ge=>Bv(ge)).length,[e]),R=v.useMemo(()=>{const ge=new Set;for(const ye of ho)if(N.has(ye.id))for(const Ce of ye.statuses)ge.add(Ce);return ge},[N]),G=v.useMemo(()=>{const ge=new Set;for(const ye of e)for(const Ce of ho)if(Ce.statuses.has(ye.status)){ge.add(Ce.id);break}for(const ye of r){const Ce=Iv[ye.status];Ce&&ge.add(Ce)}return ho.filter(ye=>ge.has(ye.id))},[e,r]),I=v.useCallback(ge=>{E(ye=>{const Ce=new Set(ye);return Ce.has(ge)?Ce.delete(ge):Ce.add(ge),Ce})},[]),Q=v.useCallback((ge,ye="success")=>{p({msg:ge,type:ye}),setTimeout(()=>p(null),2500)},[]),$=v.useMemo(()=>{const ge=new Map;for(const ye of s)ge.set(ye.id,ye.name);return ge},[s]),F=v.useMemo(()=>{const ge=new Map;for(const ye of e)ge.set(ye.id,ye);return ge},[e]),B=v.useMemo(()=>{const ge=new Map;for(const ye of r)ge.set(ye.id,ye);return ge},[r]),T=x?"#94a3b8":"#6b7280",D=v.useCallback((ge,ye,Ce)=>({id:`${ge}->${ye}`,source:ge,target:ye,animated:Ce==="blocked",markerEnd:{type:ni.ArrowClosed,width:14,height:14,color:Ce==="blocked"?"#ef4444":T},style:{stroke:Ce==="blocked"?"#ef4444":T,strokeWidth:1.5,cursor:"pointer"}}),[T]),{initialNodes:z,initialEdges:_}=v.useMemo(()=>{const ge=e.filter(Te=>R.has(Te.status)&&(k||!Bv(Te))),ye=ge.map(Te=>({id:Te.id,type:"task",data:{task:Te,agentName:Te.assignedAgentId?$.get(Te.assignedAgentId):void 0,selected:Te.id===m},position:{x:0,y:0}})),Ce=new Set(ye.map(Te=>Te.id)),ze=new Set;for(const Te of ho)N.has(Te.id)&&ze.add(Te.id);const tt=r.filter(Te=>{const Ze=Iv[Te.status];return Ze&&ze.has(Ze)});for(const Te of tt){const Ze=`req-${Te.id}`;ye.push({id:Ze,type:"requirement",data:{req:Te,selected:Te.id===f},position:{x:0,y:0}}),Ce.add(Ze)}const Xe=[];for(const Te of ge)if(Te.blockedBy)for(const Ze of Te.blockedBy)Ce.has(Ze)&&Xe.push(D(Ze,Te.id,Te.status));const dt=new Set,wt=(Te,Ze)=>{const xt=`${Te}->${Ze}`;dt.has(xt)||(dt.add(xt),Xe.push({id:xt,source:Te,target:Ze,markerEnd:{type:ni.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Te of tt){const Ze=`req-${Te.id}`;for(const xt of Te.taskIds)Ce.has(xt)&&wt(Ze,xt)}for(const Te of ge)if(Te.requirementId){const Ze=`req-${Te.requirementId}`;Ce.has(Ze)&&wt(Ze,Te.id)}return{initialNodes:dz(ye,Xe),initialEdges:Xe}},[e,r,$,F,D,R,N,k,m,f]),[Y,V,J]=tL(z),[U,H,X]=nL(_),L=v.useRef(null),M=v.useRef(!1),q=v.useRef({groupFilter:N,showArchived:k});v.useEffect(()=>{const ge=q.current;(ge.groupFilter!==N||ge.showArchived!==k)&&(M.current=!1,q.current={groupFilter:N,showArchived:k})},[N,k]),v.useEffect(()=>{V(z),H(_),M.current||requestAnimationFrame(()=>{L.current?.fitView({padding:.2,duration:300})})},[z,_,V,H]);const K=v.useCallback(ge=>{ge&&(M.current=!0)},[]),ee=v.useCallback((ge,ye)=>{if(ye.id.startsWith("req-")){const Ce=B.get(ye.id.slice(4));Ce&&c&&c(Ce)}else{const Ce=F.get(ye.id);Ce&&d&&d(Ce)}},[F,B,d,c]),te=v.useCallback(async ge=>{const{source:ye,target:Ce}=ge;if(!ye||!Ce||ye===Ce)return;const ze=F.get(Ce);if(!ze)return;if(ze.blockedBy?.includes(ye)){Q("Dependency already exists","error");return}if(uz(F,ye,Ce)){Q("Cannot add: would create a cycle","error");return}const tt=[...ze.blockedBy??[],ye];try{await re.tasks.update(Ce,{blockedBy:tt}),Q("Dependency added"),h?.()}catch(Xe){Q(`Failed: ${Xe instanceof Error?Xe.message:String(Xe)}`,"error")}},[F,Q,h]),se=v.useCallback((ge,ye)=>{w(ye)},[]),xe=v.useCallback(async()=>{if(!y)return;const ge=F.get(y.target);if(!ge){w(null);return}const ye=(ge.blockedBy??[]).filter(Ce=>Ce!==y.source);try{await re.tasks.update(y.target,{blockedBy:ye}),Q("Dependency removed"),h?.()}catch(Ce){Q(`Failed: ${Ce instanceof Error?Ce.message:String(Ce)}`,"error")}w(null)},[y,F,Q,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 ke=y?F.get(y.source):null,De=y?F.get(y.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(eL,{nodes:Y,edges:U,onNodesChange:J,onEdgesChange:X,onNodeClick:ee,onConnect:te,onEdgeClick:se,onMoveEnd:K,onInit:ge=>{L.current=ge},nodeTypes:az,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[t.jsx(iL,{color:x?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(mL,{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(EL,{nodeColor:ge=>{const ye=ge.data?.task,Ce=ye?.status;return ye?.taskType==="scheduled"?"#06b6d4":Ce==="completed"||Ce==="accepted"?"#10b981":Ce==="in_progress"?"#f59e0b":Ce==="blocked"||Ce==="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:[G.map(ge=>{const ye=N.has(ge.id);return t.jsx("button",{onClick:()=>I(ge.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${ye?`${ge.color.bg} ${ge.color.border} ${ge.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:ge.label},ge.id)}),O>0&&t.jsxs("button",{onClick:()=>S(ge=>!ge),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 ",O]}),N.size<em.size&&t.jsx("button",{onClick:()=>{E(new Set(em)),S(!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"})]}),g&&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 ${g.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:g.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:ge=>ge.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:De?.title??y.target.slice(-8)})," ","will no longer be blocked by"," ",t.jsx("span",{className:"text-fg-secondary font-medium",children:ke?.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:xe,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 wN({orgId:e,onCreated:r,onClose:s}){const[l,o]=v.useState(""),[d,c]=v.useState(""),[h,m]=v.useState(""),[f,x]=v.useState("main"),[g,p]=v.useState([]),[y,w]=v.useState([]),[N,E]=v.useState(!1),[A,C]=v.useState(""),[k,S]=v.useState(!1),O=ks();v.useEffect(()=>{re.teams.list().then(I=>w(I.teams)).catch(()=>{})},[]);const R=v.useCallback(async I=>{if(I?.preventDefault(),S(!0),!(!l.trim()||N)){E(!0),C("");try{const Q=h.trim()?[{url:h.trim(),defaultBranch:f.trim()||"main"}]:[],$=await re.projects.create({name:l.trim(),description:d.trim()||void 0,repositories:Q.length>0?Q:void 0,teamIds:g.length>0?g:void 0,orgId:e??"default"});r($.project)}catch(Q){C(Q instanceof Error?Q.message:"Failed to create project")}E(!1)}},[l,d,h,f,g,e,N,r]),G=k&&!l.trim();return ix.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 ${O?"w-full":"w-[520px]"}`,onClick:I=>I.stopPropagation(),onSubmit:R,children:[t.jsx("h3",{className:"text-base font-semibold mb-5",children:"New Project"}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:"Project Name *"}),t.jsx("input",{value:l,onChange:I=>{o(I.target.value),C("")},onBlur:()=>S(!0),placeholder:"e.g. Mobile App, Website Redesign",className:`input ${G?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!O}),G&&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:I=>c(I.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(I=>{const Q=g.includes(I.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:Q,onChange:()=>p($=>Q?$.filter(F=>F!==I.id):[...$,I.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:I.name})]},I.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:I=>m(I.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:I=>x(I.target.value),placeholder:"main",className:"input !w-24"})]})]}),A&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:A}),t.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:"Cancel"}),t.jsx("button",{type:"submit",disabled:!l.trim()||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 ii(e,r,s){if(!e)return null;const l=r.find(d=>d.id===e);if(l)return l.name;const o=s.find(d=>d.id===e);return o?o.name:e==="anonymous"?"Admin":null}function mz({value:e,onSave:r,className:s,placeholder:l}){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 r(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:l}):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:l??"Click to edit"})})}function xz({value:e,onSave:r,className:s,placeholder:l}){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 r(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:l,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:l??"Add a description…"})})}const gz=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function NN(e){const r=e.match(gz);return r?{timestamp:r[1].trim(),author:r[2]?.trim()??"System",content:r[3].trim()}:{timestamp:"",author:"",content:e}}function pz(e){if(!e)return"";const r=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!r)return e;const s=new Date,l=+r[1],o=+r[2]-1,d=+r[3],c=+r[4],h=+r[5],m=new Date(l,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`:`${l}-${String(o+1).padStart(2,"0")}-${String(d).padStart(2,"0")}`}const Hv=[{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 bz(e){let r=0;for(let s=0;s<e.length;s++)r=(r<<5)-r+e.charCodeAt(s)|0;return Hv[Math.abs(r)%Hv.length]}function yz({note:e,compact:r}){const s=NN(e),l=bz(s.author||"System"),o=s.author?s.author.split(/[\s_-]+/).map(h=>h[0]).join("").slice(0,2).toUpperCase():"SY",d=pz(s.timestamp),c=!s.author||s.author==="System";return r?t.jsxs("div",{className:"flex gap-2.5 group",children:[t.jsx("div",{className:`w-6 h-6 rounded-full ${l.bg} flex items-center justify-center text-[9px] font-bold ${l.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":l.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(Zn,{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 ${l.bg} flex items-center justify-center text-[10px] font-bold ${l.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 ${l.border} rounded-lg overflow-hidden`,children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${l.bg} border-b ${l.border}`,children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-secondary":l.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(Zn,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const Do=[{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"}],kN={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"}},Bm={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"}},vz={urgent:"border-l-red-500",high:"border-l-amber-500",medium:"border-l-blue-500",low:"border-l-gray-500"},Pv={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"}},jz=["low","medium","high","urgent"],wz=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],Nz=["pending","in_progress","completed","rejected","cancelled"],SN={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"};function kz({agent:e,anchorRect:r,onClose:s}){const l=v.useRef(null);v.useEffect(()=>{const c=h=>{l.current&&!l.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:l,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:r.top+4,left:r.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(),jt.navigate("chat",{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 yo({comment:e,agents:r}){const s=e.authorType==="agent"||e.authorType==="system",l=new Date(e.createdAt),o=l.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),d=l.toLocaleDateString([],{month:"short",day:"numeric"}),[c,h]=v.useState(null),m=v.useCallback((f,x)=>{const g=r.find(p=>p.name.toLowerCase()===f.toLowerCase());if(g){const p=x.target.getBoundingClientRect();h({agent:g,top:p.bottom,left:p.left})}},[r]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",children:[t.jsx("div",{className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 ${s?"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 ${s?"text-indigo-400":"text-blue-400"}`,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[d," ",o]})]}),t.jsx(Zn,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:m}),e.attachments?.map((f,x)=>f.type==="image"?t.jsx("img",{src:f.url,alt:f.name,className:"mt-1 max-w-[200px] rounded"},x):null)]}),c&&t.jsx(kz,{agent:c.agent,anchorRect:{top:c.top,left:c.left},onClose:()=>h(null)})]})}function Sz({task:e,agents:r,users:s,authUser:l}){const[o,d]=v.useState([]);v.useEffect(()=>{re.tasks.getComments(e.id).then(m=>d(m.comments)).catch(()=>{})},[e.id]),v.useEffect(()=>kn.on("task:comment",f=>{f.payload?.taskId===e.id&&f.payload.comment&&d(x=>x.some(g=>g.id===f.payload.comment.id)?x:[...x,f.payload.comment])}),[e.id]);const c=v.useMemo(()=>{const m=[];for(const f of e.notes??[]){const x=NN(f);let g;if(x.timestamp){const p=x.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);g=p?new Date(+p[1],+p[2]-1,+p[3],+p[4],+p[5],+(p[6]??0)):new Date(0)}else g=new Date(0);m.push({type:"note",note:f,ts:g})}for(const f of o)m.push({type:"comment",comment:f,ts:new Date(f.createdAt)});return m.sort((f,x)=>f.ts.getTime()-x.ts.getTime()),m},[e.notes,o]),h=async(m,f)=>{await re.tasks.addComment(e.id,m,l?.name,void 0,l?.id,f.length>0?f:void 0)};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((m,f)=>m.type==="note"?t.jsx(yz,{note:m.note,compact:!0},`n-${f}`):t.jsx(yo,{comment:m.comment,agents:r},`c-${m.comment.id}`))]}),t.jsx(yj,{agents:r,onSubmit:h})]})}function Cz({taskId:e,isRunning:r,authUser:s,agents:l}){const[o,d]=v.useState([]),[c,h]=v.useState(new Map),[m,f]=v.useState(new Set),[x,g]=v.useState([]),[p,y]=v.useState(""),[w,N]=v.useState(r),[E,A]=v.useState(!0),[C,k]=v.useState(new Set),[S,O]=v.useState(""),[R,G]=v.useState(!1),[I,Q]=v.useState([]),$=v.useRef(null),F=v.useRef(null);v.useEffect(()=>{N(r)},[r]),v.useEffect(()=>{A(!0),Promise.all([re.tasks.getLogsSummary(e).catch(()=>({rounds:[]})),re.tasks.getComments(e).catch(()=>({comments:[]}))]).then(([X,L])=>{const M=X.rounds;if(d(M),g(L.comments),M.length===0){A(!1);return}const q=M[M.length-1].round;k(new Set([q])),re.tasks.getLogs(e,q).catch(()=>({logs:[]})).then(K=>{h(new Map([[q,K.logs]])),A(!1)})})},[e]);const B=v.useCallback(X=>{c.has(X)||m.has(X)||(f(L=>new Set(L).add(X)),re.tasks.getLogs(e,X).catch(()=>({logs:[]})).then(L=>{h(M=>new Map(M).set(X,L.logs)),f(M=>{const q=new Set(M);return q.delete(X),q})}))},[e,c,m]),T=v.useCallback(X=>{k(L=>{const M=new Set(L);return M.has(X)?M.delete(X):(M.add(X),c.has(X)||B(X)),M})},[c,B]);v.useEffect(()=>{const X=kn.on("task:log",q=>{const K=q.payload;if(K.taskId!==e)return;const ee={id:K.id,taskId:K.taskId,agentId:K.agentId,seq:K.seq,type:K.logType,content:K.content,metadata:K.metadata,executionRound:K.executionRound,createdAt:K.createdAt},te=ee.executionRound??1;d(se=>se.find(ke=>ke.round===te)?se:[...se,{round:te,logCount:0,toolCount:0,firstAt:ee.createdAt,lastAt:ee.createdAt,status:"running"}]),k(se=>se.has(te)?se:new Set(se).add(te)),h(se=>{const xe=se.get(te)??[];return ee.id&&xe.some(ke=>ke.id===ee.id)?se:new Map(se).set(te,[...xe,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(se=>se.map(xe=>xe.round===te?{...xe,status:ee.content}:xe)))),ee.type==="error"&&N(!1)}),L=kn.on("task:log:delta",q=>{const K=q.payload;K.taskId===e&&y(ee=>ee+K.text)}),M=kn.on("task:comment",q=>{const K=q.payload;if(K.taskId!==e)return;const ee=K.comment;g(te=>te.some(se=>se.id===ee.id)?te:[...te,ee])});return()=>{X(),L(),M()}},[e]);const D=v.useMemo(()=>{const X=[];for(const[,L]of c)X.push(...L);return X.sort((L,M)=>L.seq-M.seq),X},[c]),z=v.useMemo(()=>D.map(X=>jd(X)),[D]),_=o.length>1,Y=X=>{const L=X.target.files;if(L){for(const M of Array.from(L)){if(!M.type.startsWith("image/"))continue;const q=new FileReader;q.onload=()=>{Q(K=>[...K,{type:"image",url:q.result,name:M.name}])},q.readAsDataURL(M)}X.target.value=""}},V=async()=>{if(!(!S.trim()&&I.length===0)){G(!0);try{const X=await re.tasks.addComment(e,S,s?.name,I.length>0?I:void 0,s?.id);X.comment&&g(L=>L.some(M=>M.id===X.comment.id)?L:[...L,X.comment]),O(""),Q([])}catch{}G(!1)}},J=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-secondary z-10",children:[I.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:I.map((X,L)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:X.url,alt:X.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>Q(M=>M.filter((q,K)=>K!==L)),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:"×"})]},L))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:S,onChange:X=>O(X.target.value),onKeyDown:X=>{X.key==="Enter"&&!X.shiftKey&&(X.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:$,accept:"image/*",multiple:!0,onChange:Y,className:"hidden"}),t.jsx("button",{onClick:()=>$.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:R||!S.trim()&&I.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(E)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:"Loading logs…"});if(o.length===0&&!p)return t.jsxs("div",{className:"flex flex-col flex-1",children:[t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"text-center text-fg-tertiary",children:[t.jsx("div",{className:"text-2xl mb-2",children:"📋"}),t.jsxs("div",{className:"text-xs",children:["No execution logs yet.",t.jsx("br",{}),'Click "Run with Agent" to start.']})]})}),J]});if(!_){const X=z.map(q=>Ed(q)).filter(q=>q!==null),L=Cd(X),M=[...L.map(q=>({kind:"entry",entry:q,ts:q.timestamp?new Date(q.timestamp).getTime():0})),...x.map(q=>({kind:"comment",comment:q,ts:new Date(q.createdAt).getTime()}))];return M.sort((q,K)=>q.ts-K.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:[M.map((q,K)=>q.kind==="comment"?t.jsx(yo,{comment:q.comment,agents:l},`c-${q.comment.id}`):t.jsx(Td,{entry:q.entry,showTime:!0,isLast:K===M.length-1},`e-${K}`)),w&&p&&t.jsx(jm,{content:p}),w&&!p&&L.length>0&&t.jsx(vm,{})]}),J]})}const U=(X,L)=>{const M=X.firstAt?new Date(X.firstAt).getTime():0,q=L?.firstAt?new Date(L.firstAt).getTime():1/0;return x.filter(K=>{const ee=new Date(K.createdAt).getTime();return ee>=M&&ee<q})},H=o.length>0?x.filter(X=>new Date(X.createdAt).getTime()<new Date(o[0].firstAt).getTime()):[];return t.jsxs("div",{className:"flex flex-col flex-1",children:[t.jsx("div",{ref:F}),t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[H.length>0&&t.jsx("div",{className:"space-y-0.5",children:H.map(X=>t.jsx(yo,{comment:X,agents:l},X.id))}),o.map((X,L)=>{const M=C.has(X.round),q=X.round===o[o.length-1].round,K=c.get(X.round),ee=m.has(X.round),te=U(X,o[L+1]),se=X.status==="completed"||X.status==="execution_finished"?"✅":X.status==="failed"?"❌":X.status==="cancelled"?"⏹":"🔄",xe=X.lastAt&&X.firstAt?Math.max(0,new Date(X.lastAt).getTime()-new Date(X.firstAt).getTime()):0,ke=xe>=6e4?`${Math.floor(xe/6e4)}m ${Math.floor(xe%6e4/1e3)}s`:xe>=1e3?`${Math.floor(xe/1e3)}s`:"";return t.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[t.jsxs("button",{onClick:()=>T(X.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:se}),t.jsxs("span",{className:"text-xs text-fg-secondary font-medium",children:["Round #",X.round]}),te.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",te.length]}),q&&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:[X.toolCount," tool",X.toolCount!==1?"s":""]}),ke&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:ke}),t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${M?"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"})})]})]}),M&&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 #",X.round,"…"]}),K&&(()=>{const ge=K.map(ze=>jd(ze)).map(ze=>Ed(ze)).filter(ze=>ze!==null),Ce=[...Cd(ge).map(ze=>({kind:"entry",entry:ze,ts:ze.timestamp?new Date(ze.timestamp).getTime():0})),...te.map(ze=>({kind:"comment",comment:ze,ts:new Date(ze.createdAt).getTime()}))];return Ce.sort((ze,tt)=>ze.ts-tt.ts),Ce.map((ze,tt)=>ze.kind==="comment"?t.jsx(yo,{comment:ze.comment,agents:l},`c-${ze.comment.id}`):t.jsx(Td,{entry:ze.entry,showTime:!0,isLast:tt===Ce.length-1},`e-${tt}`))})(),q&&w&&p&&t.jsx(jm,{content:p}),q&&w&&!p&&!ee&&t.jsx(vm,{})]})]},X.round)})]}),J]})}function Ez({filePath:e,onClose:r}){const[s,l]=v.useState(null),[o,d]=v.useState(null),[c,h]=v.useState(!0);v.useEffect(()=>{h(!0),d(null),re.files.preview(e).then(f=>l(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:r,children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl w-[720px] max-w-[92vw] max-h-[85vh] flex flex-col shadow-2xl",onClick: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:r,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0 ml-3",children:"×"})]}),t.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:e})}),t.jsxs("div",{className:"flex-1 overflow-auto min-h-0 p-5",children:[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(Zn,{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 Tz({task:e,agents:r,projects:s,requirements:l,allTasks:o,users:d,onClose:c,onRefresh:h,authUser:m}){const[f,x]=v.useState([]),[g,p]=v.useState(""),[y,w]=v.useState(!1),[N,E]=v.useState(!1),[A,C]=v.useState(null),[k,S]=v.useState(null),[O,R]=v.useState(!1),[G,I]=v.useState("details"),Q=v.useRef(null),[$,F]=v.useState("none"),B=v.useCallback(je=>{I(je),requestAnimationFrame(()=>{Q.current?.scrollTo({top:0,behavior:"instant"})})},[]);v.useEffect(()=>{const je=Q.current;if(!je)return;const Pe=()=>{const{scrollTop:Nt,scrollHeight:ut,clientHeight:Wt}=je;if(!(ut>Wt+50)){F("none");return}const Ct=Nt<30,de=Nt+Wt>=ut-30;F(Ct?"top":de?"bottom":"middle")};Pe(),je.addEventListener("scroll",Pe,{passive:!0});const vt=new ResizeObserver(Pe);return vt.observe(je),()=>{je.removeEventListener("scroll",Pe),vt.disconnect()}},[G]);const[T,D]=v.useState(!1),[z,_]=v.useState(null),[Y,V]=v.useState(null),[J,U]=v.useState(!1),[H,X]=v.useState(e.description),[L,M]=v.useState(!1),[q,K]=v.useState(""),[ee,te]=v.useState(1),[se,xe]=v.useState(!1),ke=ks(),De=20,ge=v.useCallback(async()=>{try{const je=await re.tasks.listSubtasks(e.id);x(je.subtasks)}catch{}},[e.id]);v.useEffect(()=>{ge()},[ge]);const ye=async je=>{if(!O){R(!0);try{await je(),h(),await ge()}catch(Pe){_(String(Pe).replace("Error: ",""))}finally{R(!1)}}},Ce=je=>ye(()=>re.tasks.update(e.id,{priority:je})),ze=je=>ye(()=>re.tasks.assign(e.id,je||null)),tt=je=>ye(()=>re.tasks.update(e.id,{projectId:je||null})),Xe=async()=>{if(!O){R(!0);try{await re.tasks.pause(e.id),h()}finally{R(!1)}}},dt=async()=>{if(!T){D(!0),_(null),B("logs");try{await re.tasks.resume(e.id),h()}catch(je){_(String(je).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{D(!1)}}},wt=async()=>{g.trim()&&(await re.tasks.createSubtask(e.id,g.trim()),p(""),w(!1),ge(),h())},ae=async je=>{je.status==="completed"?await re.tasks.cancelSubtask(e.id,je.id):await re.tasks.completeSubtask(e.id,je.id),ge(),h()},Te=async je=>{await re.tasks.deleteSubtask(e.id,je.id),C(null),ge(),h()},Ze=async()=>{if(!O){R(!0);try{await re.tasks.updateStatus(e.id,"pending"),h()}finally{R(!1)}}},xt=async()=>{if(!O){R(!0),_(null),B("logs");try{await re.tasks.retry(e.id),h()}catch(je){_(String(je).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{R(!1)}}},dn=async()=>{if(!T){D(!0),_(null),B("logs");try{await re.tasks.runNow(e.id),h()}catch(je){_(String(je).replace("Error: API error: 400","Server error").replace("Error: ","")),h()}finally{D(!1)}}},we=v.useRef(h);we.current=h,v.useEffect(()=>kn.on("task:update",Pe=>{Pe.payload.taskId===e.id&&(ge(),we.current())}),[e.id,ge]);const Re=f.filter(je=>je.status==="completed").length,qe=e.status==="in_progress",et=e.status==="blocked",nt=e.status==="completed",zt=e.status==="failed",Yt=e.status==="cancelled",Lt=e.status==="archived",Tt=nt||zt||Yt||Lt,qt=e.taskType==="scheduled"&&!!e.scheduleConfig,yt=qt&&!!e.scheduleConfig?.paused,sn=s.find(je=>je.id===e.projectId),Xt=l.find(je=>je.id===e.requirementId);return r.find(je=>je.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:[ke&&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 je=Bm[e.status];return je?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap ${je.cls}`,children:je.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," ")})})()]})]}),!ke&&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:()=>B("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${G==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:"Details"}),t.jsxs("button",{onClick:()=>B("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${G==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Execution Log",qe&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsxs("button",{onClick:()=>B("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${G==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Deliverables",(()=>{const je=(e.deliverables??[]).filter(Pe=>Pe.type!=="branch"&&typeof Pe.reference=="string"&&Pe.reference.length>0).length;return je>0?t.jsx("span",{className:"text-[10px] text-fg-tertiary font-normal",children:je}):null})()]})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:Q,className:"h-full overflow-y-auto",children:[G==="logs"&&t.jsxs("div",{className:"overflow-x-hidden min-w-0",children:[z&&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:"})," ",z]}),t.jsx(Cz,{taskId:e.id,isRunning:e.status==="in_progress",authUser:m,agents:r})]}),G==="details"&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:J?t.jsxs("div",{className:"space-y-2",children:[t.jsx("textarea",{value:H,onChange:je=>X(je.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:()=>{U(!1),X(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:()=>{ye(()=>re.tasks.update(e.id,{description:H})),U(!1)},disabled:O,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:ke&&!se?"line-clamp-3":"",children:t.jsx(Zn,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),ke&&e.description.length>150&&t.jsx("button",{onClick:()=>xe(!se),className:"text-[11px] text-brand-500 mt-1 font-medium",children:se?"Collapse":"Show more"})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No description"}),t.jsx("button",{onClick:()=>{X(e.description),U(!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"})]})}),(sn||Xt)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[sn&&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"}),sn.name]}),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:"Req"}),Xt.title.length>40?Xt.title.slice(0,40)+"…":Xt.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(je=>{const Pe=o.find(Nt=>Nt.id===je),vt=Pe&&(Pe.status==="completed"||Pe.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${vt?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:vt?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${vt?"line-through opacity-60":""}`,children:Pe?Pe.title.slice(0,30):je.slice(-8)}),!Tt&&t.jsx("button",{onClick:async()=>{const Nt=(e.blockedBy??[]).filter(ut=>ut!==je);await re.tasks.update(e.id,{blockedBy:Nt}),h()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:"Remove dependency",children:"×"})]},je)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:"No dependencies"}),!Tt&&t.jsxs("select",{value:"",onChange:async je=>{const Pe=je.target.value;if(!Pe)return;const vt=[...e.blockedBy??[],Pe];await re.tasks.update(e.id,{blockedBy:vt}),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(je=>je.id!==e.id&&!(e.blockedBy??[]).includes(je.id)).map(je=>t.jsx("option",{value:je.id,children:je.title},je.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:je=>{tt(je.target.value)},disabled:O,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(je=>t.jsx("option",{value:je.id,children:je.name},je.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:je=>ye(()=>re.tasks.update(e.id,{requirementId:je.target.value||null})),disabled:O,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"No Requirement"}),l.filter(je=>!e.projectId||je.projectId===e.projectId).map(je=>t.jsx("option",{value:je.id,children:je.title},je.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:je=>{ze(je.target.value)},disabled:O,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:"Unassigned"}),r.map(je=>t.jsxs("option",{value:je.id,children:[je.name," (",je.status,")"]},je.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:je=>{je.target.value&&je.target.value!==e.reviewerAgentId&&ye(()=>re.tasks.update(e.id,{reviewerAgentId:je.target.value}))},disabled:O,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:r.map(je=>t.jsx("option",{value:je.id,children:je.name},je.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:je=>{Ce(je.target.value)},disabled:O,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:ii(e.createdBy,r,d)??e.createdBy})]}),e.updatedBy&&t.jsxs("span",{children:["Updated by ",t.jsx("span",{className:"text-fg-secondary",children:ii(e.updatedBy,r,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:[Re,"/",f.length," done"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[Re>0&&t.jsx("button",{onClick:()=>E(je=>!je),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 (${Re})`}),t.jsx("button",{onClick:()=>w(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:"+ Add subtask"})]})]}),(()=>{const je=N?f:f.filter(Pe=>Pe.status!=="completed");return je.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:je.map(Pe=>t.jsxs("div",{className:"group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors",children:[t.jsx("button",{onClick:()=>{ae(Pe)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${Pe.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:Pe.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 ${Pe.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:Pe.title}),t.jsx("button",{onClick:()=>C(Pe),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},Pe.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:g,onChange:je=>p(je.target.value),onKeyDown:je=>{je.key==="Enter"&&wt(),je.key==="Escape"&&(w(!1),p(""))},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:()=>{wt()},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),p("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:"Cancel"})]}),(()=>{const je=(e.deliverables??[]).filter(Nt=>Nt.type!=="branch"&&typeof Nt.reference=="string"&&Nt.reference.length>0);if(je.length===0)return null;const Pe={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"},vt=je.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:["(",je.length,")"]})]}),je.length>3&&t.jsx("button",{onClick:()=>B("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:"View all →"})]}),t.jsx("div",{className:"space-y-1.5",children:vt.map((Nt,ut)=>{const Wt=Nt.reference.split("/").pop()??Nt.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 ${Pe[Nt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Nt.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>V(Nt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Nt.reference,children:Wt}),Nt.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Nt.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Nt.reference})]})]},ut)})})]})})(),t.jsx(Sz,{task:e,agents:r,users:d,authUser:m})]})]}),G==="deliverables"&&t.jsx("div",{className:"px-6 py-4",children:(()=>{const je=(e.deliverables??[]).filter(ut=>ut.type!=="branch"&&typeof ut.reference=="string"&&ut.reference.length>0);if(je.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:"No deliverables yet."});const Pe={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"},vt=Math.ceil(je.length/De),Nt=je.slice((ee-1)*De,ee*De);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:["(",je.length,")"]})]}),vt>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:ee<=1,onClick:()=>te(ut=>ut-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,"/",vt]}),t.jsx("button",{disabled:ee>=vt,onClick:()=>te(ut=>ut+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:Nt.map((ut,Wt)=>{const en=ut.reference.split("/").pop()??ut.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 ${Pe[ut.type]??"bg-gray-500/15 text-fg-secondary"}`,children:ut.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("button",{onClick:()=>V(ut.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:ut.reference,children:en}),ut.summary&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:ut.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:ut.reference})]})]},Wt)})})]})})()})]}),$!=="none"&&t.jsxs("div",{className:"absolute bottom-3 right-3 flex flex-col gap-1.5 z-10",children:[$!=="top"&&t.jsx("button",{onClick:()=>Q.current?.scrollTo({top:0,behavior:"smooth"}),className:"w-8 h-8 rounded-full bg-surface-overlay/90 border border-border-default shadow-lg flex items-center justify-center text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated transition-colors backdrop-blur-sm",title:"Scroll to top",children:t.jsx("svg",{className:"w-4 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"})})}),$!=="bottom"&&t.jsx("button",{onClick:()=>{const je=Q.current;je&&je.scrollTo({top:je.scrollHeight,behavior:"smooth"})},className:"w-8 h-8 rounded-full bg-surface-overlay/90 border border-border-default shadow-lg flex items-center justify-center text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated transition-colors backdrop-blur-sm",title:"Scroll to bottom",children:t.jsx("svg",{className:"w-4 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"})})})]})]}),qt&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${yt?"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:yt?"text-amber-600":"text-brand-500",children:yt?"⏸ 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"}),!yt&&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 je=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(je<=0)return"due now";const Pe=Math.floor(je/6e4);if(Pe<60)return`in ${Pe}m`;const vt=Math.floor(Pe/60);return vt<24?`in ${vt}h ${Pe%60}m`:`in ${Math.floor(vt/24)}d ${vt%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 je=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),Pe=Math.floor(je/6e4);if(Pe<1)return"just now";if(Pe<60)return`${Pe}m ago`;const vt=Math.floor(Pe/60);return vt<24?`${vt}h ${Pe%60}m ago`:`${Math.floor(vt/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:()=>ye(()=>re.tasks.approve(e.id)),disabled:O,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:()=>ye(()=>re.tasks.reject(e.id)),disabled:O,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:()=>{ye(()=>re.tasks.accept(e.id,m?.id))},disabled:O,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:"✓ Approve"}),L?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:q,onChange:je=>K(je.target.value),onKeyDown:je=>{je.key==="Enter"&&q.trim()&&(ye(()=>re.tasks.revision(e.id,q.trim(),m?.id)),M(!1),K(""))},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:()=>{ye(()=>re.tasks.revision(e.id,q.trim()||"Revisions needed",m?.id)),M(!1),K("")},disabled:O,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:()=>{M(!1),K("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>M(!0),disabled:O,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"})]}),qe&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{Xe()},disabled:O,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:()=>{xt()},disabled:O,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"]})]}),et&&t.jsx("button",{onClick:()=>{dt()},disabled:T,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:T?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:()=>{xt()},disabled:O,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"]}),qt&&(nt||zt)&&t.jsx("button",{onClick:()=>{dn()},disabled:T,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:T?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"]})}),qt&&!qe&&(yt?t.jsx("button",{onClick:()=>{ye(()=>re.tasks.resumeSchedule(e.id))},disabled:O,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:()=>{ye(()=>re.tasks.pauseSchedule(e.id))},disabled:O,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"})),nt&&t.jsx("button",{onClick:()=>ye(()=>re.tasks.archive(e.id)),disabled:O,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:"Archive"}),Tt&&t.jsx("button",{onClick:()=>{Ze()},disabled:O,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary disabled:opacity-50",children:"Reopen"}),!Tt&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:je}=await re.tasks.getDependentCount(e.id);je>0?S({dependentCount:je}):ye(()=>re.tasks.cancel(e.id))},disabled:O,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"})]})}),A&&t.jsx(jj,{title:`Delete subtask "${A.title}"?`,message:"This subtask will be permanently deleted.",confirmLabel:"Delete",onConfirm:()=>{Te(A)},onCancel:()=>C(null)}),k&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>S(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:je=>je.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:()=>{S(null),ye(()=>re.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:()=>{S(null),ye(()=>re.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:()=>S(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:"Keep task running"})]})]})}),Y&&t.jsx(Ez,{filePath:Y,onClose:()=>V(null)})]})}function Az({project:e,tasks:r,requirements:s,agents:l,onDeleteProject:o,onUpdateProject:d,onRefresh:c}){const h=v.useMemo(()=>r.filter(I=>I.projectId===e.id),[r,e.id]),m=v.useMemo(()=>s.filter(I=>I.projectId===e.id),[s,e.id]),f=v.useMemo(()=>{const I={total:h.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:m.length,reqsDone:0};for(const Q of h)Q.status==="completed"||Q.status==="accepted"?I.completed++:Q.status==="in_progress"?I.inProgress++:Q.status==="review"||Q.status==="revision"?I.inReview++:Q.status==="blocked"?I.blocked++:Q.status==="failed"?I.failed++:I.pending++;for(const Q of m)Q.status==="completed"&&I.reqsDone++;return I},[h,m]),x=v.useMemo(()=>new Set(h.map(I=>I.assignedAgentId).filter(Boolean)),[h]),g=v.useMemo(()=>l.filter(I=>x.has(I.id)),[l,x]),[p,y]=v.useState(!1),[w,N]=v.useState(""),[E,A]=v.useState("main"),[C,k]=v.useState(!1),S=[{value:"active",label:"Active",desc:"Work is ongoing"},{value:"paused",label:"Paused",desc:"Temporarily on hold"},{value:"archived",label:"Archived",desc:"No longer active"}],O=async I=>{if(I!==e.status){k(!0);try{await d({status:I}),c()}finally{k(!1)}}},R=async()=>{const I=w.trim();if(!I)return;const Q=[...e.repositories??[],{url:"",localPath:I,defaultBranch:E||"main"}];await d({repositories:Q}),N(""),A("main"),y(!1),c()},G=async I=>{const Q=(e.repositories??[]).filter(($,F)=>F!==I);await d({repositories:Q}),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(xz,{value:e.description??"",onSave:async I=>{await d({description:I}),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:S.map(I=>t.jsxs("button",{disabled:C,onClick:()=>O(I.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===I.value?I.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":I.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"} ${C?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:I.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:I.desc})]},I.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(Vs,{label:"Total",value:f.total,color:"text-fg-primary"}),t.jsx(Vs,{label:"Completed",value:f.completed,color:"text-green-600"}),t.jsx(Vs,{label:"In Progress",value:f.inProgress,color:"text-brand-500"}),t.jsx(Vs,{label:"In Review",value:f.inReview,color:"text-brand-500"}),t.jsx(Vs,{label:"Blocked",value:f.blocked,color:"text-amber-600"}),t.jsx(Vs,{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(Vs,{label:"Total",value:f.reqs,color:"text-fg-primary"}),t.jsx(Vs,{label:"Completed",value:f.reqsDone,color:"text-green-600"}),t.jsx(Vs,{label:"Active",value:f.reqs-f.reqsDone,color:"text-brand-500"})]})]}),g.length>0&&t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[t.jsxs("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:["Agents (",g.length,")"]}),t.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(I=>{const Q=h.filter(F=>F.assignedAgentId===I.id),$=Q.filter(F=>!["completed","failed","cancelled","archived"].includes(F.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 ${I.status==="working"?"bg-blue-500":I.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:I.name}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[$.length," active / ",Q.length," total"]})]},I.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(!p),className:"text-[10px] text-brand-500 hover:text-brand-500",children:p?"Cancel":"+ Add"})]}),(e.repositories??[]).length===0&&!p&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:"No repositories linked."}),(e.repositories??[]).map((I,Q)=>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:I.url||I.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:I.defaultBranch}),t.jsx("button",{onClick:()=>G(Q),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"})]})})]},Q)),p&&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:I=>N(I.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:E,onChange:I=>A(I.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:R,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 Vs({label:e,value:r,color:s}){return t.jsxs("div",{className:"text-center py-2",children:[t.jsx("div",{className:`text-xl font-bold ${s}`,children:r}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const Oo={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"}},CN={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed"},EN={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},_z={urgent:0,high:1,medium:2,low:3},Uv={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Mz={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"},Dz={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"},Oz=["pending","in_progress","completed","rejected","cancelled"];function Rz(e){for(const r of Do)if(r.statuses.includes(e))return r.id;return"closed"}function Lz(e){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const l=Math.floor(s/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function qv({value:e,options:r,onSelect:s}){const[l,o]=v.useState(!1),d=v.useRef(null),c=v.useRef(null),h=r.find(m=>m.value===e);return v.useEffect(()=>{if(!l)return;const m=f=>{c.current&&!c.current.contains(f.target)&&d.current&&!d.current.contains(f.target)&&o(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[l]),t.jsxs("div",{className:"relative",children:[t.jsx("button",{ref:d,onClick:()=>o(m=>!m),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${h?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:h?.label??e}),l&&t.jsx("div",{ref:c,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:r.map(m=>t.jsxs("button",{onClick:()=>{m.value!==e&&s(m.value),o(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${m.value===e?"bg-surface-elevated":"hover:bg-surface-elevated/60"}`,children:[t.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 ${m.cls.split(" ")[0]}`}),t.jsx("span",{className:`font-medium ${m.value===e?"text-fg-primary":"text-fg-secondary"}`,children:m.label}),m.value===e&&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"})})]},m.value))})]})}function Fv({row:e,idx:r,dragIdx:s,agentMap:l,projMap:o,onTaskClick:d,onReqClick:c,onRowDragStart:h,onRowDragEnd:m,handleStatusChange:f,handlePriorityChange:x,selected:g}){const p=e.data.status,y=e.data.priority,w=e.kind==="task"?l.get(e.data.assignedAgentId??""):void 0,N=o.get((e.kind==="task",e.data.projectId??""));return t.jsxs("div",{draggable:!0,onDragStart:E=>h(E,r),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 ${Mz[e.group]??"border-l-gray-700"} ${s===r?"opacity-40":""} ${g?"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:e.kind==="req"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:"REQ"}):e.data.taskType==="scheduled"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600 inline-flex items-center gap-0.5",title:"Scheduled task",children:"SCHED"}):t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:"TASK"})}),t.jsx("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate",children:e.data.title}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:E=>E.stopPropagation(),children:t.jsx(qv,{value:p,options:e.kind==="task"?wz.map(E=>({value:E,label:Bm[E]?.label??E,cls:Bm[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Nz.map(E=>({value:E,label:Oo[E]?.label??E,cls:Oo[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:E=>{f(e,E)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:E=>E.stopPropagation(),children:t.jsx(qv,{value:y,options:jz.map(E=>({value:E,label:Pv[E]?.label??E,cls:Pv[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:E=>{x(e,E)}})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] text-fg-secondary truncate",children:w?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${SN[w.status]??"bg-gray-500"}`}),w.name]}):t.jsx("span",{className:"text-fg-tertiary",children:"—"})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] text-fg-tertiary truncate",children:N?.name??t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-tertiary text-right",children:Lz(e.data.updatedAt??"")})]})}function zz({tasks:e,requirements:r,agents:s,projects:l,onTaskClick:o,onReqClick:d,onRefresh:c,selectedTaskId:h,selectedReqId:m}){const[f,x]=v.useState("status"),[g,p]=v.useState(null),[y,w]=v.useState(null),N=v.useMemo(()=>{const T=[];for(const D of e){const z=Rz(D.status);T.push({kind:"task",data:D,group:z,groupOrder:Uv[z]??5})}for(const D of r){const z=CN[D.status]??"todo";T.push({kind:"req",data:D,group:z,groupOrder:Uv[z]??5})}if(f==="status")T.sort((D,z)=>{if(D.groupOrder!==z.groupOrder)return D.groupOrder-z.groupOrder;const _=new Date(D.data.updatedAt??0).getTime();return new Date(z.data.updatedAt??0).getTime()-_});else{const D=z=>_z[z.data.priority]??2;T.sort((z,_)=>{const Y=D(z),V=D(_);return Y!==V?Y-V:new Date(_.data.updatedAt??0).getTime()-new Date(z.data.updatedAt??0).getTime()})}return T},[e,r,f]),E=async(T,D)=>{try{T.kind==="task"?await re.tasks.updateStatus(T.data.id,D):await re.requirements.updateStatus(T.data.id,D),c()}catch{}},A=async(T,D)=>{try{T.kind==="task"?await re.tasks.update(T.data.id,{priority:D}):await re.requirements.update(T.data.id,{priority:D}),c()}catch{}},C=(T,D)=>{p(D),T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",String(D)),T.currentTarget.style.opacity="0.4"},k=T=>{T.currentTarget.style.opacity="1",p(null),w(null)},S=(T,D)=>{T.preventDefault(),T.dataTransfer.dropEffect="move",y!==D&&w(D)},O=async(T,D)=>{if(T.preventDefault(),w(null),g==null)return;const z=N[g];if(!z||z.group===D)return;const _=Do.find(Y=>Y.id===D);if(_){try{if(z.kind==="task"){if(z.data.status==="pending")return;await re.tasks.updateStatus(z.data.id,_.dropStatus)}else{const Y=EN[D];Y&&await re.requirements.updateStatus(z.data.id,Y)}c()}catch{}p(null)}},R=v.useMemo(()=>new Map(s.map(T=>[T.id,T])),[s]),G=v.useMemo(()=>new Map(l.map(T=>[T.id,T])),[l]),I=["todo","in_progress","review","done"],Q=v.useMemo(()=>{const T={};for(const D of N)T[D.group]=(T[D.group]??0)+1;return T},[N]),{rowsByGroup:$,rowIndexMap:F}=v.useMemo(()=>{const T=new Map,D=new Map;for(let z=0;z<N.length;z++){const _=N[z];D.set(_,z);const Y=T.get(_.group)??[];Y.push(_),T.set(_.group,Y)}return{rowsByGroup:T,rowIndexMap:D}},[N]),B=v.useMemo(()=>{if(f!=="status")return null;const T=new Set(N.map(_=>_.group)),D=[],z=new Set;T.has("failed")&&(D.push("failed"),z.add("failed"));for(const _ of I)D.push(_),z.add(_);for(const _ of N)z.has(_.group)||(D.push(_.group),z.add(_.group));return D},[N,f]);return t.jsx("div",{className:"flex-1 min-h-0 overflow-auto bg-surface-secondary",children:t.jsxs("div",{className:"w-fit min-w-full",children:[t.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider 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:N.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:"Title"}),t.jsxs("button",{onClick:()=>x("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:["Status ",f==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>x("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:["Priority ",f==="priority"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsx("div",{className:"w-[120px] shrink-0",children:"Assignee"}),t.jsx("div",{className:"w-[120px] shrink-0",children:"Project"}),t.jsx("div",{className:"w-[90px] shrink-0 text-right",children:"Updated"})]}),t.jsxs("div",{children:[f==="status"&&B?B.map(T=>{const D=Do.find(_=>_.id===T),z=$.get(T)??[];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 ${Dz[T]??""} ${y===T?"ring-1 ring-brand-500/40":""}`,onDragOver:_=>S(_,T),onDragLeave:()=>w(null),onDrop:_=>{O(_,T)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:D?.label??T}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Q[T]??0})]}),z.map(_=>t.jsx(Fv,{row:_,idx:F.get(_)??0,dragIdx:g,agentMap:R,projMap:G,onTaskClick:o,onReqClick:d,onRowDragStart:C,onRowDragEnd:k,handleStatusChange:E,handlePriorityChange:A,selected:_.kind==="task"?_.data.id===h:_.data.id===m},`${_.kind}-${_.data.id}`))]},T)}):N.map((T,D)=>t.jsx(Fv,{row:T,idx:D,dragIdx:g,agentMap:R,projMap:G,onTaskClick:o,onReqClick:d,onRowDragStart:C,onRowDragEnd:k,handleStatusChange:E,handlePriorityChange:A,selected:T.kind==="task"?T.data.id===h:T.data.id===m},`${T.kind}-${T.data.id}`)),N.length===0&&t.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-fg-tertiary",children:"No items"})]})]})})}function Vv({authUser:e}){const r=ks(),s=Wd({side:"right",defaultWidth:Math.round(window.innerWidth*2/3),minWidth:380,maxWidth:Math.round(window.innerWidth*.8),storageKey:"markus_projects_detail_v3"}),[l,o]=v.useState(!1),d=v.useRef(l);d.current=l;const[c,h]=v.useState([]),[m,f]=v.useState("all"),[x,g]=v.useState(null),[p,y]=v.useState({}),[w,N]=v.useState([]),[E,A]=v.useState([]),[C,k]=v.useState([]),[S,O]=v.useState(!0),[R,G]=v.useState(""),[I,Q]=v.useState(!1),$=v.useCallback(()=>{Wt(x??""),yt(!0)},[x]),[F,B]=v.useState(!1),[T,D]=v.useState(!1),[z,_]=v.useState(""),[Y,V]=v.useState(""),[J,U]=v.useState("medium"),[H,X]=v.useState(""),[L,M]=v.useState(""),[q,K]=v.useState(""),[ee,te]=v.useState(""),[se,xe]=v.useState([]),[ke,De]=v.useState("standard"),[ge,ye]=v.useState("4h"),[Ce,ze]=v.useState(null),[tt,Xe]=v.useState(null),[dt,wt]=v.useState(new Set),[ae,Te]=v.useState(new Set),Ze=v.useRef(new Set),xt=v.useRef(new Set),[dn,we]=v.useState(null),[Re,qe]=v.useState("backlog"),[et,nt]=v.useState(!1),[zt,Yt]=v.useState(!1),Lt=v.useRef(null),Tt=v.useRef(null),[qt,yt]=v.useState(!1),[sn,Xt]=v.useState(""),[je,Pe]=v.useState(""),[vt,Nt]=v.useState("medium"),[ut,Wt]=v.useState(""),[en,Ct]=v.useState(null),[de,Be]=v.useState(""),Le=Z=>{G(Z),setTimeout(()=>G(""),3e3)},ot=c.find(Z=>Z.id===x)??null;v.useEffect(()=>{xt.current=ae},[ae]);const Qe=v.useCallback(async()=>{try{const{projects:Z}=await re.projects.list();h(Z)}catch{}},[]),ft=v.useCallback(async()=>{const Z={};m==="project"&&x&&(Z.projectId=x);try{const{board:oe}=await re.tasks.board(Z);y(oe)}catch{}},[m,x]),Zt=v.useCallback(async()=>{try{const{agents:Z}=await re.agents.list();N(Z)}catch{}},[]),it=v.useCallback(async()=>{try{const{users:Z}=await re.users.list(e?.orgId);A(Z)}catch{}},[e?.orgId]),gt=v.useCallback(async()=>{try{const{requirements:Z}=await re.requirements.list({});k(Z)}catch{}},[]),wn=v.useCallback(async()=>{await Promise.all([Qe(),ft(),Zt(),it(),gt()]),O(!1)},[Qe,ft,Zt,it,gt]);v.useEffect(()=>{wn()},[wn]);const an=v.useCallback(Z=>{ze(oe=>oe?.id===Z.id?(r&&d.current&&o(!1),null):(r&&(o(!0),history.pushState({mobileDetail:"projects"},"",window.location.hash)),Z)),Xe(null)},[r]),Qt=v.useCallback(Z=>{Xe(oe=>oe?.id===Z.id?(r&&d.current&&o(!1),null):(r&&(o(!0),history.pushState({mobileDetail:"projects"},"",window.location.hash)),Z)),ze(null)},[r]),At=v.useCallback(()=>{ze(null),Xe(null),r&&d.current&&o(!1)},[r]);v.useEffect(()=>{if(!r)return;const Z=()=>{d.current&&(o(!1),ze(null),Xe(null))};return window.addEventListener("popstate",Z),()=>window.removeEventListener("popstate",Z)},[r]);const un=v.useRef(Ce);un.current=Ce,v.useEffect(()=>{const oe=setInterval(()=>{ft(),Zt(),gt()},Ce?6e4:15e3),me=kn.on("task:update",Ie=>{un.current||(ft(),gt());const Me=Ie?.payload;Me?.taskId&&ze(Ue=>{if(!Ue||Ue.id!==Me.taskId)return Ue;const Ve={};return typeof Me.status=="string"&&(Ve.status=Me.status),Array.isArray(Me.deliverables)&&(Ve.deliverables=Me.deliverables),Array.isArray(Me.notes)&&(Ve.notes=Me.notes),Me.result!==void 0&&(Ve.result=Me.result),{...Ue,...Ve}})});return()=>{clearInterval(oe),me()}},[ft,Zt,gt,Ce]);const En=v.useRef(p);En.current=p;const fe=v.useCallback(Z=>{if(!Z)return;const oe=xt.current;oe.size>0&&!oe.has(Z)&&Te(me=>new Set([...me,Z]))},[]);v.useEffect(()=>{const Z=localStorage.getItem("markus_nav_openTask");if(!Z)return;const me=Object.values(p).flat().find(Ie=>Ie.id===Z);me&&(fe(me.projectId),an(me),localStorage.removeItem("markus_nav_openTask"))},[p,an,fe]),v.useEffect(()=>{const Z=window.location.hash.slice(1).split("/");if(Z[0]==="projects"&&Z[1])Fe(Z[1]);else{const oe=localStorage.getItem("markus_nav_projectId");oe&&(localStorage.removeItem("markus_nav_projectId"),Fe(oe))}},[]),v.useEffect(()=>{const Z=()=>{const me=window.location.hash.slice(1).split("/");me[0]==="projects"&&me[1]?Fe(me[1]):me[0]==="projects"&&kt()},oe=me=>{const Ie=me.detail;if(Ie.page==="tasks"||Ie.page==="projects"){if(Ie.params?.openTask){const Ue=Object.values(En.current).flat().find(Ve=>Ve.id===Ie.params.openTask);Ue&&(fe(Ue.projectId),an(Ue),localStorage.removeItem("markus_nav_openTask"))}Ie.params?.projectId&&Fe(Ie.params.projectId),!Ie.params?.projectId&&!Ie.params?.openTask&&kt()}};return window.addEventListener("markus:navigate",oe),window.addEventListener("hashchange",Z),()=>{window.removeEventListener("markus:navigate",oe),window.removeEventListener("hashchange",Z)}},[]);const Fe=Z=>{xt.current.size>0&&(Ze.current=new Set(xt.current)),Te(new Set),g(Z),f("project"),Q(!1),history.replaceState(null,"","#projects/"+Z)},kt=()=>{Te(Ze.current),g(null),f("all"),Q(!1),history.replaceState(null,"","#projects")},St=()=>{B(!1),Le("Project created"),Qe()},Tn=async Z=>{if(confirm("Delete this project and unlink all its tasks?"))try{await re.projects.delete(Z),x===Z&&kt(),Le("Project deleted"),Qe(),ft()}catch(oe){Le(`Error: ${oe}`)}},Qn=async()=>{if(!z||!H||!L)return;if(H===L){Le("Assigned agent and reviewer must be different");return}const Z=q||void 0,oe=ee||void 0;try{await re.tasks.create(z,Y,H,L,J,Z,se.length>0?se:void 0,oe,ke!=="standard"?ke:void 0,ke==="scheduled"?{every:ge}:void 0),_(""),V(""),xe([]),te(""),De("standard"),ye("4h"),D(!1),ft()}catch(me){Le(`Error creating task: ${me}`)}},hr=()=>{ft(),Ce&&setTimeout(()=>{const Z={};m==="project"&&x&&(Z.projectId=x),re.tasks.board(Z).then(oe=>{const Ie=Object.values(oe.board).flat().find(Me=>Me.id===Ce.id);ze(Ie||null)}).catch(()=>{})},150)},or=async()=>{if(!sn.trim()){Le("Please enter a title for this requirement");return}if(!je.trim()){Le("Please enter a description for this requirement");return}if(!ut){Le("Please select a project for this requirement");return}try{await re.requirements.create({title:sn.trim(),description:je.trim(),priority:vt,projectId:ut}),Le("Requirement created"),Xt(""),Pe(""),yt(!1),gt()}catch(Z){Le(`Error: ${Z}`)}},tr=async Z=>{try{await re.requirements.approve(Z),Le("Requirement approved"),gt(),ft()}catch(oe){Le(`Error: ${oe}`)}},cr=async()=>{if(en)try{await re.requirements.reject(en,de),Le("Requirement rejected"),Ct(null),Be(""),gt()}catch(Z){Le(`Error: ${Z}`)}},fn=async Z=>{try{await re.requirements.cancel(Z),Le("Requirement cancelled"),gt()}catch(oe){Le(`Error: ${oe}`)}},os=(Z,oe)=>{Lt.current=oe,Tt.current=null,Z.dataTransfer.effectAllowed="move",Z.dataTransfer.setData("text/plain",`task:${oe.id}`),Z.currentTarget.style.opacity="0.4"},Sr=(Z,oe)=>{Tt.current=oe,Lt.current=null,Z.dataTransfer.effectAllowed="move",Z.dataTransfer.setData("text/plain",`req:${oe.id}`),Z.currentTarget.style.opacity="0.4"},nr=Z=>{Z.currentTarget.style.opacity="1",Lt.current=null,Tt.current=null,we(null)},rr=(Z,oe)=>{Z.preventDefault(),Z.dataTransfer.dropEffect="move",dn!==oe&&we(oe)},Cs=(Z,oe)=>{const me=Z.currentTarget.getBoundingClientRect(),{clientX:Ie,clientY:Me}=Z;(Ie<me.left||Ie>me.right||Me<me.top||Me>me.bottom)&&dn===oe&&we(null)},ie=async(Z,oe)=>{Z.preventDefault(),we(null);const me=Lt.current,Ie=Tt.current;if(me){const Me=Do.find(Ve=>Ve.id===oe);if(!Me)return;const Ue=Me.dropStatus;if(me.status===Ue||me.status==="pending")return;try{await re.tasks.updateStatus(me.id,Ue),ft()}catch{}}else if(Ie){const Me=EN[oe];if(!Me||Ie.status===Me)return;try{await re.requirements.updateStatus(Ie.id,Me),gt()}catch{}}},Se=Z=>{wt(oe=>{const me=new Set(oe);return me.has(Z)?me.delete(Z):me.add(Z),me})},He=Z=>{Te(oe=>{const me=new Set(oe);return me.has(Z)?me.delete(Z):me.add(Z),me})},Mt=1440*60*1e3,Gn=Date.now(),On=Z=>Z.updatedAt&&Gn-new Date(Z.updatedAt).getTime()>Mt,tn=Z=>(Z.status==="completed"||Z.status==="cancelled")&&On(Z),Hr=(Z,oe=!1)=>{let me=Z.filter(Ie=>et||oe||!tn(Ie));return m==="project"&&x&&(me=me.filter(Ie=>Ie.projectId===x)),ae.size>0&&(me=me.filter(Ie=>Ie.projectId&&ae.has(Ie.projectId))),dt.size>0&&(me=me.filter(Ie=>Ie.assignedAgentId&&dt.has(Ie.assignedAgentId))),me},Js=Z=>Z.statuses.flatMap(oe=>Hr(p[oe]??[])),mr=v.useMemo(()=>{let Z=C;return et||(Z=Z.filter(oe=>!tn(oe))),m==="project"&&x&&(Z=Z.filter(oe=>oe.projectId===x)),ae.size>0&&(Z=Z.filter(oe=>oe.projectId&&ae.has(oe.projectId))),dt.size>0&&(Z=Z.filter(oe=>dt.has(oe.createdBy))),Z},[C,et,m,x,ae,dt]),dr=v.useCallback(Z=>mr.filter(oe=>CN[oe.status]===Z.id),[mr]),Cr=Do.filter(Z=>{if(Z.id==="failed"||Z.id==="closed"){const oe=Js(Z),me=dr(Z);return oe.length+me.length>0}return!0}),Er=Object.values(p).flat().filter(Z=>tn(Z)).length+C.filter(Z=>tn(Z)).length,An=v.useMemo(()=>{const Z=new Set(["completed","failed","cancelled","archived"]),oe=Object.values(p).flat(),me=new Set;for(const Ie of oe)Ie.assignedAgentId&&!Z.has(Ie.status)&&(!x||Ie.projectId===x)&&me.add(Ie.assignedAgentId);return[...w].sort((Ie,Me)=>{const Ue=me.has(Ie.id)?0:1,Ve=me.has(Me.id)?0:1;return Ue-Ve})},[w,p,x]),Tr=v.useMemo(()=>{const Z=new Set(["completed","failed","cancelled","archived"]),oe=Object.values(p).flat(),me=new Set;for(const Ie of oe)Ie.projectId&&!Z.has(Ie.status)&&me.add(Ie.projectId);return[...c].sort((Ie,Me)=>{const Ue=me.has(Ie.id)?0:1,Ve=me.has(Me.id)?0:1;return Ue-Ve})},[c,p]),cs=v.useMemo(()=>{const Z={};for(const oe of Object.values(p))for(const me of oe){const Ie=me.projectId??"__none__";Z[Ie]=(Z[Ie]??0)+1}return Z},[p]),Kr=Object.values(cs).reduce((Z,oe)=>Z+oe,0);if(S)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:"Loading…"});const ne=!!(Ce||tt);return t.jsxs("div",{className:"flex-1 overflow-hidden flex bg-surface-secondary",children:[t.jsxs("div",{className:`${r?"flex-1 min-w-0":ne?"shrink-0":"flex-1"} overflow-hidden flex flex-col bg-surface-secondary`,style:r?l?{display:"none"}:void 0:ne?{width:`calc(100% - ${s.width}px - 4px)`}:void 0,children:[R&&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:R}),r?t.jsxs("div",{className:"border-b border-border-default bg-surface-secondary/80 shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[ot?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:ot.name}),t.jsx("button",{onClick:()=>Q(!I),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${I?"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:()=>B(!0),className:"px-2 py-1 text-[11px] border border-border-default text-fg-secondary rounded-md",children:"+ Project"}),t.jsx("button",{onClick:$,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:"+ Req"}),t.jsx("button",{onClick:()=>{K(x??""),D(!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(Z=>t.jsx("button",{onClick:()=>qe(Z),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${Re===Z?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:Z==="backlog"?"Backlog":Z==="kanban"?"Kanban":"DAG"},Z))}),Er>0&&t.jsx("button",{onClick:()=>nt(Z=>!Z),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${et?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:et?"Hide archived":`${Er} archived`}),t.jsx("div",{className:"flex-1"}),(ae.size>0||dt.size>0||c.length>1||w.length>0)&&t.jsxs("button",{onClick:()=>Yt(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${ae.size>0||dt.size>0?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),"Filter",ae.size+dt.size>0?` (${ae.size+dt.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:[ot?t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(mz,{value:ot.name,onSave:async Z=>{await re.projects.update(ot.id,{name:Z}),Qe()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:()=>Q(!I),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${I?"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`}),Er>0&&t.jsx("button",{onClick:()=>nt(Z=>!Z),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${et?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:et?`Hide ${Er} archived`:`${Er} archived`}),t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(Z=>t.jsx("button",{onClick:()=>qe(Z),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Re===Z?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:Z==="backlog"?"Backlog":Z==="kanban"?"Kanban":"DAG"},Z))}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:$,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:()=>{K(x??""),D(!0)},className:"px-3 py-1.5 border border-border-default hover:bg-surface-elevated text-fg-secondary text-xs rounded-lg font-medium transition-colors",children:"+ Task"})]}),t.jsx("div",{className:"flex-1"})]}),!r&&c.length>1&&!x&&!I&&(Kr>0||C.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 ${ae.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),Tr.map(Z=>{const oe=ae.has(Z.id),me=cs[Z.id]??0;return t.jsxs("button",{onClick:()=>He(Z.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:Z.name[0]?.toUpperCase()}),Z.name,me>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:me})]},Z.id)})]}),!r&&w.length>0&&!I&&(Kr>0||C.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:()=>wt(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 ${dt.size>0?"visible opacity-100":"invisible opacity-0"}`,children:"Clear"}),An.map(Z=>{const oe=dt.has(Z.id);return t.jsxs("button",{onClick:()=>Se(Z.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:Z.name[0]?.toUpperCase()}),Z.name]},Z.id)})]}),I&&ot?t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsx(Az,{project:ot,tasks:Object.values(p).flat(),requirements:C,agents:w,onDeleteProject:()=>Tn(ot.id),onUpdateProject:async Z=>{await re.projects.update(ot.id,Z)},onRefresh:()=>{Qe()}})}):Kr===0&&mr.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:$,className:"text-xs text-brand-500 hover:text-brand-500 font-medium",children:"+ Create a requirement"})]})}):Re==="backlog"?t.jsx(zz,{tasks:Hr(Object.values(p).flat()),requirements:mr,agents:w,projects:c,onTaskClick:Z=>an(Z),onReqClick:Z=>Qt(Z),onRefresh:()=>{ft(),gt()},selectedTaskId:Ce?.id,selectedReqId:tt?.id}):Re==="dag"?t.jsx(hz,{tasks:Hr(Object.values(p).flat(),!0),requirements:mr,agents:w,showArchived:et,onShowArchivedChange:nt,onTaskClick:Z=>an(Z),onReqClick:Z=>Qt(Z),onDependencyChange:ft,selectedTaskId:Ce?.id,selectedReqId:tt?.id}):t.jsx("div",{className:"flex-1 min-h-0 overflow-x-auto overflow-y-hidden px-4 py-5",children:t.jsx("div",{className:"flex gap-3 h-full",children:Cr.map(Z=>{const oe=Js(Z),me=dr(Z),Ie=oe.length+me.length,Me=dn===Z.id;return t.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col h-full transition-colors ${Me?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:Ue=>rr(Ue,Z.id),onDragLeave:Ue=>Cs(Ue,Z.id),onDrop:Ue=>{ie(Ue,Z.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 ${Z.accent.replace("border-t-","bg-")}`}),t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:Z.label})]}),t.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:Ie})]}),t.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin px-2 py-2",children:(()=>{const Ue=[...me.map(Ve=>({kind:"req",data:Ve,time:new Date(Ve.updatedAt??Ve.createdAt).getTime()})),...oe.map(Ve=>({kind:"task",data:Ve,time:new Date(Ve.updatedAt??Ve.createdAt??0).getTime()}))];return Ue.sort((Ve,Oe)=>Oe.time-Ve.time),Ue.map(Ve=>{if(Ve.kind==="req"){const Oe=Ve.data,bt=Oo[Oe.status]??{label:Oe.status,cls:"bg-gray-500/15 text-fg-secondary"},Dt=Oe.source==="agent"&&Oe.status==="pending",_n=m==="all"&&Oe.projectId?c.find(Ye=>Ye.id===Oe.projectId):null,at=ii(Oe.createdBy,w,E)??Oe.createdBy.slice(0,10),ht=tt?.id===Oe.id;return t.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:Ye=>Sr(Ye,Oe),onDragEnd:nr,onClick:()=>Qt(Oe),onKeyDown:Ye=>Ye.key==="Enter"&&Qt(Oe),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
62
62
  ${Dt?"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
- ${ht?"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 ${bt.cls}`,children:bt.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Oe.title}),Oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Oe.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:[_n&&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:_n.name,children:_n.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Oe.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",at]})]}),t.jsx("div",{className:"flex items-center gap-1",children:Oe.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:["📋 ",Oe.taskIds.length]})})]}),Dt&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:Ye=>{Ye.stopPropagation(),tr(Oe.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:Ye=>{Ye.stopPropagation(),Ct(Oe.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-${Oe.id}`)}else{const Oe=Ve.data,bt=Oe.subtasks?.length??0,Gt=kN[Oe.status],Dt=Oe.status==="pending",_n=Oe.taskType==="scheduled"&&!!Oe.scheduleConfig,at=_n?Oe.scheduleConfig.every?`Every ${Oe.scheduleConfig.every}`:Oe.scheduleConfig.cron?"Cron":"Scheduled":null,ht=m==="all"&&Oe.projectId?c.find(Ge=>Ge.id===Oe.projectId)?.name:null,Ye=Oe.requirementId?C.find(Ge=>Ge.id===Oe.requirementId)?.title:null,Ke=Oe.createdBy?ii(Oe.createdBy,w,E)??Oe.createdBy:null,Je=Ce?.id===Oe.id,st={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":Oe.title,draggable:!Dt,onDragStart:Ge=>!Dt&&os(Ge,Oe),onDragEnd:nr,onClick:()=>an(Oe),onKeyDown:Ge=>Ge.key==="Enter"&&an(Oe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Dt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":_n?"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"} ${Je?"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 ${st[Oe.priority]??"bg-gray-400"}`,title:Oe.priority}),_n&&t.jsx("span",{className:"text-blue-500 shrink-0",title:at??"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"})})}),_n&&at&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:at}),Gt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Gt.cls}`,children:Gt.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Oe.title}),Oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Oe.description}),(ht||Ye||Oe.blockedBy&&Oe.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[ht&&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:ht,children:ht}),Ye&&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:Ye,children:["# ",Ye]}),Oe.blockedBy&&Oe.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:["⏳ ",Oe.blockedBy.length," dep",Oe.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:Ke&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Ke}`,children:["by ",Ke]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[bt>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",bt]}),Oe.notes&&Oe.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",Oe.notes.length]}),Oe.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 ${SN[w.find(Ge=>Ge.id===Oe.assignedAgentId)?.status??""]??"bg-gray-500"}`}),w.find(Ge=>Ge.id===Oe.assignedAgentId)?.name??Oe.assignedAgentId.slice(0,8)]})]})]})]},Oe.id)}})})()}),Me&&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"})})]},Z.id)})})})]}),!r&&ne&&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}),(!r||l)&&ne&&t.jsx("div",{className:`${r?"flex-1":"shrink-0"} overflow-hidden min-w-0 border-l border-border-default`,style:r?void 0:{width:s.width},children:Ce?t.jsx(Tz,{task:Ce,agents:w,projects:c,requirements:C,allTasks:Object.values(p).flat(),users:E,onClose:At,onRefresh:hr,authUser:e}):tt?t.jsx($z,{req:tt,agents:w,projects:c,allTasks:Object.values(p).flat(),users:E,onClose:At,onApprove:Z=>{tr(Z),At()},onReject:Z=>{Ct(Z),At()},onCancel:Z=>{fn(Z),At()},onStatusChange:async(Z,oe)=>{try{await re.requirements.updateStatus(Z,oe),Le(`Requirement status → ${oe}`),gt(),ft()}catch(me){Le(`Error: ${me}`)}},onRefresh:gt,authUser:e}):null}),F&&t.jsx(wN,{orgId:e?.orgId,onCreated:St,onClose:()=>B(!1)}),T&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>D(!1),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${r?"w-full":"w-[28rem]"}`,onClick:Z=>Z.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:q,onChange:Z=>K(Z.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(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.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:Z=>te(Z.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…"}),C.filter(Z=>Z.status==="in_progress"&&(!q||Z.projectId===q)).map(Z=>t.jsx("option",{value:Z.id,children:Z.title},Z.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{autoFocus:!r,value:z,onChange:Z=>_(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"&&Qn()},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:Y,onChange:Z=>V(Z.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:J,onChange:Z=>U(Z.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:H,onChange:Z=>X(Z.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(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.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:L,onChange:Z=>M(Z.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(Z=>Z.id!==H).map(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.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:ke,onChange:Z=>De(Z.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)"})]})]}),ke==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Frequency"}),t.jsxs("select",{value:ge,onChange:Z=>ye(Z.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:Z=>{const oe=Z.target.value;oe&&!se.includes(oe)&&xe([...se,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(p).flat().filter(Z=>Z.status!=="completed"&&Z.status!=="cancelled"&&!se.includes(Z.id)).map(Z=>t.jsx("option",{value:Z.id,children:Z.title},Z.id))]}),se.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:se.map(Z=>{const oe=Object.values(p).flat().find(me=>me.id===Z);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):Z.slice(-8),t.jsx("button",{onClick:()=>xe(se.filter(me=>me!==Z)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},Z)})})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>D(!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:()=>{Qn()},disabled:!H||!L,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Create"})]})]})}),qt&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{yt(!1),Xt(""),Pe("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${r?"w-full":"w-[28rem]"}`,onClick:Z=>Z.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:ut,onChange:Z=>Wt(Z.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(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{value:sn,onChange:Z=>Xt(Z.target.value),placeholder:"e.g. Add user authentication",className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!r,onKeyDown:Z=>{Z.key==="Enter"&&sn.trim()&&or()}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:je,onChange:Z=>Pe(Z.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:vt,onChange:Z=>Nt(Z.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:()=>{yt(!1),Xt(""),Pe("")},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:()=>{or()},disabled:!sn.trim()||!je.trim()||!ut,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"})]})]})}),en&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>Ct(null),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${r?"w-full":"w-96"}`,onClick:Z=>Z.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:de,onChange:Z=>Be(Z.target.value),placeholder:"Why is this being rejected...",rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!r})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>Ct(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:()=>{cr()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:"Reject"})]})]})}),zt&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Yt(!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:Z=>Z.stopPropagation(),children:[t.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:"Filters"}),t.jsxs("div",{className:"flex items-center gap-2",children:[(ae.size>0||dt.size>0)&&t.jsx("button",{onClick:()=>{Te(new Set),wt(new Set)},className:"text-[11px] text-brand-500 font-medium",children:"Clear all"}),t.jsx("button",{onClick:()=>Yt(!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:Tr.map(Z=>{const oe=ae.has(Z.id),me=cs[Z.id]??0;return t.jsxs("button",{onClick:()=>He(Z.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:Z.name[0]?.toUpperCase()}),Z.name,me>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:me})]},Z.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:An.map(Z=>{const oe=dt.has(Z.id);return t.jsxs("button",{onClick:()=>Se(Z.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:Z.name[0]?.toUpperCase()}),Z.name]},Z.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Iz({requirementId:e,agents:r,authUser:s}){const[l,o]=v.useState([]);v.useEffect(()=>{re.requirements.getComments(e).then(c=>o(c.comments)).catch(()=>{})},[e]),v.useEffect(()=>kn.on("requirement:comment",h=>{h.payload?.requirementId===e&&h.payload.comment&&o(m=>m.some(f=>f.id===h.payload.comment.id)?m:[...m,h.payload.comment])}),[e]);const d=async(c,h)=>{await re.requirements.addComment(e,c,s?.name,s?.id,h.length>0?h:void 0)};return t.jsxs("div",{children:[t.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:["Comments ",l.length>0&&t.jsxs("span",{className:"font-normal",children:["(",l.length,")"]})]}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[l.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:"No comments yet."}),l.map(c=>t.jsx(yo,{comment:c,agents:r},c.id))]}),t.jsx(yj,{agents:r,onSubmit:d})]})}function $z({req:e,agents:r,projects:s,allTasks:l,users:o,onClose:d,onApprove:c,onReject:h,onCancel:m,onStatusChange:f,onRefresh:x,authUser:g}){const p=ks(),[y,w]=v.useState(!1),[N,E]=v.useState(e.description),[A,C]=v.useState(!1),k=Oo[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},S=e.source==="agent",O=S&&e.status==="pending",R=e.status==="pending"||e.status==="in_progress",G=e.status==="completed"||e.status==="rejected"||e.status==="cancelled",I=e.projectId?s.find(F=>F.id===e.projectId):null,Q=ii(e.createdBy,r,o)??e.createdBy.slice(0,12),$=l.filter(F=>e.taskIds.includes(F.id));return v.useEffect(()=>{E(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:[p&&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})]})]}),!p&&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:F=>E(F.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),E(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()=>{C(!0);try{await re.requirements.update(e.id,{description:N}),w(!1),x?.()}catch{}finally{C(!1)}},disabled:A,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(Zn,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No description"}),!G&&t.jsx("button",{onClick:()=>{E(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:Q}),S&&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()})]}),I&&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:I.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:ii(e.approvedBy,r,o)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:"Rejection Reason"}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(F=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",F]},F))}),$.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 (",$.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:$.map(F=>{const B=kN[F.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 ${vz[F.priority]?.replace("border-l-","bg-")??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:F.title}),B&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${B.cls}`,children:B.label})]},F.id)})})]}),t.jsx(Iz,{requirementId:e.id,agents:r,authUser:g})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[O&&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"})]}),!O&&f&&!G&&t.jsx("select",{value:e.status,onChange:F=>{F.target.value!==e.status&&f(e.id,F.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:Oz.map(F=>{const B=Oo[F];return t.jsx("option",{value:F,children:B?.label??F},F)})}),G&&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"}),R&&!O&&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 xs(e){return Array.isArray(e)?e.map(r=>String(r).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(r=>r.trim()).filter(Boolean):[]}function Bz(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function Ka({label:e,value:r}){return r?t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:r})]}):null}function Ul({label:e,value:r,color:s}){if(!r)return null;const l={purple:"bg-brand-500/15 text-brand-500",cyan:"bg-blue-500/15 text-blue-600",indigo:"bg-brand-500/15 text-brand-500",gray:"bg-gray-500/15 text-fg-secondary",emerald:"bg-green-500/15 text-green-600"};return t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${l[s]??l.gray} capitalize inline-block`,children:r})]})}function tm({files:e}){const[r,s]=v.useState(Object.keys(e)[0]??""),l=Object.keys(e);return l.length===0?null:t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Files (",l.length,")"]}),t.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[t.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:l.map(o=>t.jsx("button",{onClick:()=>s(o),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${r===o?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:o},o))}),r&&e[r]!=null&&t.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[r]})]})]})}function Hz({artifact:e,mode:r}){const s=Bz(e),l=e.agent,o=e.team,d=e.dependencies,c=e.displayName??e.name;if(r==="agent"){const h=l?.roleName,m=l?.agentRole,f=l?.llmProvider,x=l?.llmModel,g=xs(d?.env),p=xs(d?.skills);return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Ka,{label:"Name",value:c}),t.jsx(Ka,{label:"Description",value:e.description}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(Ul,{label:"Role Template",value:h,color:"indigo"}),t.jsx(Ul,{label:"Agent Role",value:m,color:m==="manager"?"purple":"cyan"})]}),xs(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:xs(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(Ul,{label:"LLM Provider",value:f,color:"gray"}),x&&t.jsx(Ul,{label:"LLM Model",value:x,color:"gray"})]}),g.length>0&&t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:"Required Env"}),t.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:g.map(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))})]}),p.length>0&&t.jsx(Ka,{label:"Skills",value:p.join(", ")}),s&&t.jsx(tm,{files:s})]})}if(r==="team"){const m=o?.members??[];return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Ka,{label:"Name",value:c}),t.jsx(Ka,{label:"Description",value:e.description}),t.jsx("div",{className:"flex flex-wrap gap-2",children:t.jsx(Ul,{label:"Category",value:e.category,color:"indigo"})}),xs(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:xs(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(tm,{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)]})]}),xs(f.skills).length>0&&t.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:xs(f.skills).map(g=>t.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:g},g))})]},x))})]})]})}return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Ka,{label:"Name",value:c}),t.jsx(Ka,{label:"Description",value:e.description}),t.jsx("div",{className:"flex gap-2",children:t.jsx(Ul,{label:"Category",value:e.category,color:"indigo"})}),s&&t.jsx(tm,{files:s}),xs(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:xs(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 lo={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},Yv={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"}},Gv=["file","directory"],gs={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 Xv(){const e=ks(),r=Wd({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[s,l]=v.useState(!1),o=v.useRef(s);o.current=s,v.useEffect(()=>{if(!e)return;const fe=()=>{o.current&&l(!1)};return window.addEventListener("popstate",fe),()=>window.removeEventListener("popstate",fe)},[e]);const d=100,[c,h]=v.useState([]),[m,f]=v.useState(0),[x,g]=v.useState(!1),[p,y]=v.useState([]),[w,N]=v.useState([]),[E,A]=v.useState(!0),[C,k]=v.useState(""),[S,O]=v.useState(""),[R,G]=v.useState(""),[I,Q]=v.useState(""),[$,F]=v.useState(""),[B,T]=v.useState(""),[D,z]=v.useState(""),[_,Y]=v.useState("date"),[V,J]=v.useState(null),[U,H]=v.useState(null),[X,L]=v.useState(""),[M,q]=v.useState(!1),[K,ee]=v.useState(!1),[te,se]=v.useState(new Set),xe=v.useRef(null),[ke,De]=v.useState("file"),[ge,ye]=v.useState(""),[Ce,ze]=v.useState(""),[tt,Xe]=v.useState(""),[dt,wt]=v.useState(""),[ae,Te]=v.useState(""),[Ze,xt]=v.useState(null),[dn,we]=v.useState(null),[Re,qe]=v.useState(!1),[et,nt]=v.useState(!1),[zt,Yt]=v.useState(!1),[Lt,Tt]=v.useState(!1),qt=v.useRef(null),yt=v.useRef(null),[sn,Xt]=v.useState(""),je=v.useRef(void 0),Pe=(fe,Fe)=>{H({type:fe,text:Fe}),setTimeout(()=>H(null),3e3)},vt=async fe=>{try{return await navigator.clipboard.writeText(fe),!0}catch{try{const Fe=document.createElement("textarea");Fe.value=fe,Fe.style.cssText="position:fixed;left:-9999px;top:-9999px;opacity:0",document.body.appendChild(Fe),Fe.select();const kt=document.execCommand("copy");return document.body.removeChild(Fe),kt}catch{return!1}}},Nt=async fe=>{await vt(fe)?(Tt(!0),setTimeout(()=>Tt(!1),1500)):Pe("error","Copy failed — try long-pressing to copy manually")},ut=v.useMemo(()=>new Map(w.map(fe=>[fe.id,fe])),[w]),Wt=v.useMemo(()=>new Map(p.map(fe=>[fe.id,fe])),[p]);v.useEffect(()=>{re.projects.list().then(fe=>y(fe.projects)).catch(()=>{}),re.agents.list().then(fe=>N(fe.agents??[])).catch(()=>{}),re.system.storage().then(fe=>Xt(fe.dataDir+"/shared")).catch(()=>{})},[]),v.useEffect(()=>(je.current=setTimeout(()=>O(C),300),()=>clearTimeout(je.current)),[C]);const en=v.useMemo(()=>({q:S||void 0,projectId:I||void 0,agentId:$||void 0,type:R||void 0,status:B||void 0,artifactType:D||void 0}),[S,I,$,R,B,D]),Ct=v.useCallback(async()=>{A(!0);try{const{results:fe,total:Fe}=await re.deliverables.search({...en,offset:0,limit:d});h(fe),f(Fe)}catch{h([]),f(0)}A(!1)},[en]),de=v.useCallback(async()=>{if(!(x||c.length>=m)){g(!0);try{const{results:fe,total:Fe}=await re.deliverables.search({...en,offset:c.length,limit:d});h(kt=>[...kt,...fe]),f(Fe)}catch{}g(!1)}},[en,c.length,m,x]);v.useEffect(()=>{Ct()},[Ct]),v.useEffect(()=>kn.on("deliverable:created",()=>Ct()),[Ct]);const Be=v.useCallback(()=>{const fe=xe.current;!fe||E||x||c.length>=m||fe.scrollHeight<=fe.clientHeight+100&&de()},[E,x,c.length,m,de]);v.useEffect(()=>{const fe=xe.current;if(!fe)return;const Fe=()=>{fe.scrollTop+fe.clientHeight>=fe.scrollHeight-100&&de()};return fe.addEventListener("scroll",Fe,{passive:!0}),()=>fe.removeEventListener("scroll",Fe)},[de]),v.useEffect(()=>{Be()},[Be,te]);const Le=v.useMemo(()=>{const fe=new Map;for(const kt of c){let St,Tn;if(_==="project")St=kt.projectId??"_none",Tn=kt.projectId?Wt.get(kt.projectId)?.name??kt.projectId:"No Project";else if(_==="agent")St=kt.agentId??"_none",Tn=kt.agentId?ut.get(kt.agentId)?.name??kt.agentId:"Unknown";else if(_==="type")St=kt.type,Tn=kt.type.charAt(0).toUpperCase()+kt.type.slice(1);else{const Qn=new Date(kt.updatedAt);St=`${Qn.getFullYear()}-${String(Qn.getMonth()+1).padStart(2,"0")}-${String(Qn.getDate()).padStart(2,"0")}`,Tn=St}fe.has(St)||fe.set(St,{label:Tn,items:[]}),fe.get(St).items.push(kt)}const Fe=[...fe.entries()];return _==="date"?Fe.sort((kt,St)=>St[0].localeCompare(kt[0])):Fe.sort((kt,St)=>kt[1].label.localeCompare(St[1].label)),Fe},[c,_,Wt,ut]),ot=async()=>{if(!(!ge.trim()||!Ce.trim())){ee(!0);try{await re.deliverables.create({type:ke,title:ge,summary:Ce,reference:tt,projectId:dt||void 0,tags:ae.split(",").map(fe=>fe.trim()).filter(Boolean)}),q(!1),Pe("success","Deliverable created"),Ct()}catch(fe){Pe("error",`Error: ${fe}`)}ee(!1)}},Qe=async fe=>{L("verify");try{await re.deliverables.verify(fe.id),Pe("success","Verified"),J({...fe,status:"verified"}),Ct()}catch(Fe){Pe("error",`Error: ${Fe}`)}L("")},ft=async fe=>{L("flag");try{await re.deliverables.update(fe.id,{status:"outdated"}),Pe("success","Flagged as outdated"),J({...fe,status:"outdated"}),Ct()}catch(Fe){Pe("error",`Error: ${Fe}`)}L("")},Zt=async fe=>{L("remove");try{await re.deliverables.remove(fe.id),Pe("success","Removed"),J(null),Ct()}catch(Fe){Pe("error",`Error: ${Fe}`)}L("")},it=()=>{jt.navigate("builder")},gt=async fe=>{if(fe.reference){if(fe.type==="directory"){nt(!0);return}qe(!0);try{const Fe=await re.files.preview(fe.reference);Fe.type==="image"&&Fe.mimeType?we({src:`data:${Fe.mimeType};base64,${Fe.content}`,name:Fe.name}):xt(Fe.content)}catch{xt(null),fe.type==="file"&&nt(!0)}qe(!1)}};v.useEffect(()=>{xt(null),we(null),nt(!1),Yt(!1),V&&gt(V)},[V?.id]),v.useEffect(()=>{if(!zt)return;const fe=Fe=>{yt.current&&!yt.current.contains(Fe.target)&&Yt(!1)};return document.addEventListener("mousedown",fe),()=>document.removeEventListener("mousedown",fe)},[zt]);const wn=async(fe,Fe)=>{const kt=qt.current?.firstElementChild;if(!kt)return;const St=Pz(kt,fe);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([St],{type:"text/html"}),"text/plain":new Blob([Fe],{type:"text/plain"})})]),Pe("success",fe==="light"?"HTML (light) copied":"HTML (dark) copied")}catch{const Tn=await vt(Fe);Pe(Tn?"success":"error",Tn?"Text copied (HTML not supported)":"Copy failed")}Yt(!1)},an=fe=>t.jsxs("div",{className:"relative group/preview",children:[t.jsxs("div",{className:"absolute -top-1 -right-1 z-10",ref:yt,children:[t.jsx("button",{onClick:()=>Yt(Fe=>!Fe),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"})})}),zt&&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 Fe=await vt(fe);Pe(Fe?"success":"error",Fe?"Markdown source copied":"Copy failed"),Yt(!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:()=>wn("light",fe),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:()=>wn("dark",fe),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:qt,children:t.jsx(Zn,{content:fe,className:"text-fg-secondary text-sm"})})]}),Qt=v.useCallback(fe=>{se(Fe=>{const kt=new Set(Fe);return kt.has(fe)?kt.delete(fe):kt.add(fe),kt})},[]),At=v.useCallback(()=>{te.size===Le.length?se(new Set):se(new Set(Le.map(([fe])=>fe)))},[te.size,Le]),un=()=>{ye(""),ze(""),Xe(""),Te(""),De("file"),p.length>0&&wt(p[0].id),q(!0)},En=fe=>{J(fe),e&&(l(!0),history.pushState({mobileDetail:"deliverables"},"",window.location.hash))};return t.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[t.jsxs("div",{className:`${e?"flex-1 min-w-0":"shrink-0"} border-r border-border-default flex flex-col bg-surface-primary`,style:e?s?{display:"none"}:void 0:{width:r.width},children:[t.jsxs("div",{className:"p-4 border-b border-border-default space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary",children:["Deliverables",m>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",m,")"]})]}),t.jsx("button",{onClick:un,className:"text-xs px-2.5 py-1 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create"})]}),t.jsx("input",{value:C,onChange:fe=>k(fe.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"}),sn&&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:sn}),t.jsx("button",{onClick:()=>{re.system.openPath(sn)},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(Ea,{label:"All types",value:"",current:R||D||"",onClick:()=>{G(""),z("")}}),Gv.map(fe=>t.jsx(Ea,{label:`${lo[fe]?.icon??""} ${fe}`,value:fe,current:R,onClick:Fe=>{G(Fe),z("")}},fe)),["agent","team","skill"].map(fe=>t.jsx(Ea,{label:`${gs[fe].icon} ${gs[fe].label}`,value:fe,current:D,onClick:Fe=>{z(Fe),G("")}},fe))]}),p.length>0&&t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(Ea,{label:"All projects",value:"",current:I,onClick:Q}),p.map(fe=>t.jsx(Ea,{label:fe.name,value:fe.id,current:I,onClick:Q},fe.id))]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(Ea,{label:"Active",value:"",current:B,onClick:T}),t.jsx(Ea,{label:"Verified",value:"verified",current:B,onClick:T}),t.jsx(Ea,{label:"Outdated",value:"outdated",current:B,onClick:T})]}),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(fe=>t.jsx("button",{onClick:()=>{Y(fe),se(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${_===fe?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:fe.charAt(0).toUpperCase()+fe.slice(1)},fe)),Le.length>1&&t.jsx("button",{onClick:At,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:te.size===Le.length?"Expand all":"Collapse all",children:te.size===Le.length?"▶ Expand":"▼ Collapse"})]})]}),U&&t.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${U.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:U.text}),t.jsxs("div",{ref:xe,className:"flex-1 overflow-y-auto p-2 space-y-1",children:[E?t.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(fe=>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"})]},fe))}):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:un,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create first"})]}):Le.map(([fe,Fe])=>{const kt=te.has(fe);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>Qt(fe),className:"w-full flex items-center gap-1.5 px-2 py-1.5 rounded-md hover:bg-surface-elevated/50 transition-colors group/header",children:[t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform duration-200 shrink-0 ${kt?"":"rotate-90"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),t.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider truncate",children:Fe.label}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Fe.items.length,")"]})]}),!kt&&Fe.items.map(St=>t.jsxs("button",{onClick:()=>En(St),className:`w-full text-left p-3 rounded-lg transition-colors ${V?.id===St.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:St.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[St.artifactType&&gs[St.artifactType]?t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${gs[St.artifactType].color}`,children:[gs[St.artifactType].icon," ",gs[St.artifactType].label]}):t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium uppercase ${lo[St.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:St.type}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${Yv[St.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:St.status}),St.agentId&&t.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:ut.get(St.agentId)?.name??"Agent"})]})]},St.id))]},fe)}),x&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[t.jsx(nm,{})," ",t.jsx("span",{className:"text-[10px]",children:"Loading more..."})]}),!E&&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:r.onResizeStart}),(!e||s)&&t.jsxs("div",{className:"flex-1 overflow-y-auto min-w-0",children:[e&&t.jsxs("div",{className:"sticky top-0 z-10 bg-surface-secondary border-b border-border-default px-4 py-2.5 flex items-center gap-2",children:[t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsx("span",{className:"text-sm font-medium truncate",children: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:()=>Qe(V),disabled:!!X,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:X==="verify"?"Verifying...":"Verify"}),V.status!=="outdated"&&t.jsx("button",{onClick:()=>ft(V),disabled:!!X,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:X==="flag"?"Flagging...":"Flag Outdated"}),t.jsx("button",{onClick:()=>Zt(V),disabled:!!X,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:X==="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 ${lo[V.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[lo[V.type]?.icon??""," ",V.type]}),t.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${Yv[V.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:V.status}),V.artifactType&&gs[V.artifactType]&&t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${gs[V.artifactType].color}`,children:[gs[V.artifactType].icon," Builder ",gs[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:()=>{re.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:()=>{re.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:()=>Nt(V.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Lt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:"Copy path to clipboard",children:Lt?"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(Hz,{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:it,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(Zn,{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:Re?t.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[t.jsx(nm,{})," Loading preview..."]}):dn?t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("img",{src:dn.src,alt:dn.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:dn.name})]}):Ze?an(Ze):et?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:()=>{re.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:()=>{re.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:()=>Nt(V.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Lt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:Lt?"Copied!":"Copy"})]})]}):V.summary?an(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(fe=>t.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:fe},fe))}),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:()=>jt.navigate("projects",{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:()=>jt.navigate("team",{selectAgent:V.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Agent: ",ut.get(V.agentId)?.name??V.agentId.slice(0,12)]}),V.projectId&&t.jsxs("button",{onClick:()=>jt.navigate("projects",{projectId:V.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Project: ",Wt.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"})]})})]}),M&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!K&&q(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:fe=>fe.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:ke,onChange:fe=>De(fe.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:Gv.map(fe=>t.jsxs("option",{value:fe,children:[lo[fe]?.icon??""," ",fe]},fe))})]}),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:ge,onChange:fe=>ye(fe.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:tt,onChange:fe=>Xe(fe.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:Ce,onChange:fe=>ze(fe.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:ae,onChange:fe=>Te(fe.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:dt,onChange:fe=>wt(fe.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"}),p.map(fe=>t.jsx("option",{value:fe.id,children:fe.name},fe.id))]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1 border-t border-border-default",children:[t.jsx("button",{onClick:()=>q(!1),disabled:K,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:"Cancel"}),t.jsxs("button",{onClick:ot,disabled:K||!ge.trim()||!Ce.trim(),className:"bg-brand-600 hover:bg-brand-500 text-white text-sm px-4 py-2 rounded-lg disabled:opacity-50 flex items-center gap-2 transition-colors",children:[K&&t.jsx(nm,{}),K?"Creating...":"Create"]})]})]})})]})}function Pz(e,r){const s=e.cloneNode(!0),l=r==="light"?{bg:"#ffffff",text:"#24292f",heading:"#1f2328",strong:"#1f2328",link:"#0969da",codeBg:"#eff1f3",codeText:"#24292f",preBg:"#f6f8fa",preText:"#24292f",preBorder:"#d0d7de",border:"#d0d7de",blockquoteBorder:"#d0d7de",blockquoteText:"#656d76",tableBorder:"#d0d7de",tableHeaderBg:"#f6f8fa",tableHeaderText:"#24292f",hrColor:"#d8dee4"}:{bg:"#0d1117",text:"#e6edf3",heading:"#f0f6fc",strong:"#f0f6fc",link:"#58a6ff",codeBg:"#161b22",codeText:"#e6edf3",preBg:"#161b22",preText:"#e6edf3",preBorder:"#30363d",border:"#30363d",blockquoteBorder:"#3b82f6",blockquoteText:"#8b949e",tableBorder:"#30363d",tableHeaderBg:"#161b22",tableHeaderText:"#e6edf3",hrColor:"#21262d"},o={p:`margin:0 0 10px;color:${l.text};line-height:1.7;`,h1:`font-size:1.6em;font-weight:700;color:${l.heading};margin:20px 0 10px;line-height:1.3;border-bottom:1px solid ${l.border};padding-bottom:6px;`,h2:`font-size:1.35em;font-weight:700;color:${l.heading};margin:18px 0 8px;line-height:1.3;`,h3:`font-size:1.15em;font-weight:600;color:${l.heading};margin:14px 0 6px;line-height:1.3;`,h4:`font-size:1em;font-weight:600;color:${l.heading};margin:12px 0 4px;`,strong:`font-weight:600;color:${l.strong};`,em:"font-style:italic;",a:`color:${l.link};text-decoration:underline;`,ul:"padding-left:1.5em;margin:0 0 10px;",ol:"padding-left:1.5em;margin:0 0 10px;",li:`margin:3px 0;line-height:1.7;color:${l.text};`,blockquote:`border-left:3px solid ${l.blockquoteBorder};padding:2px 0 2px 14px;margin:10px 0;color:${l.blockquoteText};`,hr:`border:none;border-top:1px solid ${l.hrColor};margin:20px 0;`,table:"border-collapse:collapse;width:100%;margin:10px 0;",thead:`background:${l.tableHeaderBg};`,th:`border:1px solid ${l.tableBorder};padding:8px 12px;text-align:left;font-weight:600;color:${l.tableHeaderText};`,td:`border:1px solid ${l.tableBorder};padding:8px 12px;color:${l.text};`,img:"max-width:100%;height:auto;"};function d(c){c.removeAttribute("class");const h=c.tagName.toLowerCase();if(h==="pre"){c.setAttribute("style",`background:${l.preBg};color:${l.preText};padding:14px;border-radius:6px;overflow-x:auto;margin:10px 0;font-size:0.88em;line-height:1.5;border:1px solid ${l.preBorder};`);const m=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:${l.codeBg};color:${l.codeText};padding:2px 6px;border-radius:4px;font-size:0.9em;font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;`):o[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:${l.bg};color:${l.text};padding:20px 24px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Noto Sans',Helvetica,Arial,sans-serif;font-size:15px;line-height:1.7;max-width:800px;">${s.innerHTML}</div>`}function Ea({label:e,value:r,current:s,onClick:l}){return t.jsx("button",{onClick:()=>l(s===r?"":r),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${s===r?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function nm(){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 Ys(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Vl(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Uz(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 TN({authUser:e}){const[r,s]=v.useState("weekly"),[l,o]=v.useState(null),[d,c]=v.useState(!0),[h,m]=v.useState(""),[f,x]=v.useState(null),[g,p]=v.useState([]),[y,w]=v.useState("totalTokens"),[N,E]=v.useState(!0),[A,C]=v.useState("generate"),[k,S]=v.useState([]),[O,R]=v.useState(null),[G,I]=v.useState([]),[Q,$]=v.useState(""),[F,B]=v.useState(""),T=M=>{B(M),setTimeout(()=>B(""),3e3)},D=v.useCallback(async M=>{c(!0),m("");try{const{report:q}=await re.reports.generate({period:M,scope:"org",orgId:"default"});o(q)}catch(q){m(String(q)),o(null)}c(!1)},[]),z=v.useCallback(()=>{re.usage.summary().then(M=>x(M.usage)).catch(()=>{}),re.usage.agents().then(M=>p(M.agents)).catch(()=>{})},[]),_=v.useCallback(async()=>{try{const{reports:M}=await re.reports.list();S(M)}catch{}},[]),Y=v.useCallback(async M=>{R(M);try{const{feedback:q}=await re.reports.getFeedback(M.id);I(q)}catch{I([])}},[]);v.useEffect(()=>{D(r)},[r,D]),v.useEffect(()=>{z();const M=setInterval(z,3e4);return()=>clearInterval(M)},[z]),v.useEffect(()=>{A==="history"&&_()},[A,_]);const V=v.useMemo(()=>[...g].sort((M,q)=>{const K=M[y],ee=q[y];return N?ee-K:K-ee}),[g,y,N]),J=g.reduce((M,q)=>M+q.estimatedCost,0),U=g.reduce((M,q)=>M+q.tokensUsedToday,0),H=Math.max(1,...g.map(M=>M.totalTokens)),X=M=>{y===M?E(!N):(w(M),E(!0))},L={daily:"Today",weekly:"This Week",monthly:"This Month"};return t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsxs("div",{className:"max-w-5xl p-6 space-y-6",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-4",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:()=>C("generate"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${A==="generate"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:"Generate"}),t.jsxs("button",{onClick:()=>C("history"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${A==="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",children:[F&&t.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:F}),A==="generate"&&t.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(M=>t.jsx("button",{onClick:()=>s(M),className:`px-3 py-1.5 text-xs rounded-md transition-colors capitalize ${r===M?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:M},M))})]})]}),A==="history"&&!O&&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(M=>t.jsxs("button",{onClick:()=>Y(M),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:[M.type," Report"]}),t.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(M.periodStart).toLocaleDateString()," — ",new Date(M.periodEnd).toLocaleDateString()]})]}),M.plan&&t.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${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==="pending"?"Plan pending":`Plan ${M.plan.status}`}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(M.generatedAt).toLocaleDateString()})]},M.id))})}),A==="history"&&O&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:()=>{R(null),I([])},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:[O.type," Report"]}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(O.periodStart).toLocaleDateString()," — ",new Date(O.periodEnd).toLocaleDateString()]})]}),O.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(ps,{label:"Completed",value:O.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(ps,{label:"In Progress",value:O.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(ps,{label:"Created",value:O.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(ps,{label:"Blocked",value:O.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(ps,{label:"Failed",value:O.metrics.tasksFailed,color:"text-red-500"})]})]}),O.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:O.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:Vl(O.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 ${O.costSummary.trend==="decreasing"?"text-green-600":O.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[O.costSummary.trend==="decreasing"?"↓":O.costSummary.trend==="increasing"?"↑":"→"," ",O.costSummary.trend]}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Trend"})]})]}),O.costSummary.byAgent&&O.costSummary.byAgent.length>0&&t.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:O.costSummary.byAgent.map((M,q)=>t.jsxs("div",{className:"flex items-center justify-between text-xs",children:[t.jsx("span",{className:"text-fg-secondary",children:M.agentId}),t.jsxs("span",{className:"text-fg-tertiary tabular-nums",children:[Ys(M.tokens)," tokens · ",Vl(M.cost)]})]},q))})]}),O.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:[O.taskSummary.completed.length>0&&t.jsx(ql,{title:`Completed (${O.taskSummary.completed.length})`,color:"emerald",items:O.taskSummary.completed.map(M=>({id:M.id,label:M.title,sub:M.agent}))}),O.taskSummary.inProgress.length>0&&t.jsx(ql,{title:`In Progress (${O.taskSummary.inProgress.length})`,color:"indigo",items:O.taskSummary.inProgress.map(M=>({id:M.id,label:M.title,sub:M.agent}))}),O.taskSummary.blocked.length>0&&t.jsx(ql,{title:`Blocked (${O.taskSummary.blocked.length})`,color:"amber",items:O.taskSummary.blocked.map(M=>({id:M.id,label:M.title,sub:M.reason||M.agent}))}),O.taskSummary.completed.length===0&&O.taskSummary.inProgress.length===0&&O.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]}),O.highlights&&O.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:O.highlights.map((M,q)=>t.jsx("li",{children:M},q))})]}),O.blockers&&O.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:O.blockers.map((M,q)=>t.jsx("li",{children:M},q))})]}),O.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 ${O.plan.status==="approved"?"bg-green-500/10 text-green-600":O.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:O.plan.status})]}),O.plan.status==="pending"&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{onClick:async()=>{try{const{report:M}=await re.reports.approvePlan(O.id,{approvedBy:e?.id??"admin"});R(M),T("Plan approved"),_()}catch(M){T(`Error: ${M}`)}},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 M=prompt("Rejection reason:");if(M)try{const{report:q}=await re.reports.rejectPlan(O.id,{rejectedBy:e?.id??"admin",reason:M});R(q),T("Plan rejected"),_()}catch(q){T(`Error: ${q}`)}},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"})]})]}),O.plan.items&&O.plan.items.length>0&&t.jsx("div",{className:"space-y-1.5",children:O.plan.items.map((M,q)=>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 ${M.priority==="high"?"bg-red-500/10 text-red-500":M.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:M.priority}),t.jsx("span",{children:M.title}),M.assignee&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:M.assignee})]},q))})]}),!O.metrics&&!O.taskSummary&&!O.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 (",G.length,")"]}),G.length>0&&t.jsx("div",{className:"space-y-2 mb-4",children:G.map(M=>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:M.authorName}),t.jsx("span",{children:M.type}),t.jsx("span",{children:new Date(M.createdAt).toLocaleDateString()})]}),t.jsx("p",{className:"text-xs text-fg-secondary",children:M.content})]},M.id))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:Q,onChange:M=>$(M.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:M=>{M.key==="Enter"&&Q.trim()&&re.reports.addFeedback(O.id,{author:e?.id??"admin",type:"comment",content:Q.trim()}).then(({feedback:q})=>{I(K=>[...K,q]),$(""),T("Feedback added")}).catch(q=>T(`Error: ${q}`))}}),t.jsx("button",{onClick:()=>{Q.trim()&&re.reports.addFeedback(O.id,{author:e?.id??"admin",type:"comment",content:Q.trim()}).then(({feedback:M})=>{I(q=>[...q,M]),$(""),T("Feedback added")}).catch(M=>T(`Error: ${M}`))},disabled:!Q.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"})]})]})]}),A==="generate"&&f&&t.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t.jsx(fd,{label:"LLM Tokens (this month)",value:Ys(f.llmTokens),color:"text-brand-500"}),t.jsx(fd,{label:"Tool Calls (today)",value:Ys(f.toolCalls),color:"text-blue-600"}),t.jsx(fd,{label:"Messages (today)",value:Ys(f.messages),color:"text-green-600"}),t.jsx(fd,{label:"Storage",value:Uz(f.storageBytes),color:"text-amber-600"})]}),A==="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}):l?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"text-xs text-fg-tertiary",children:[L[r]," · ",new Date(l.periodStart).toLocaleDateString()," — ",new Date(l.periodEnd).toLocaleDateString()]}),l.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(ps,{label:"Completed",value:l.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(ps,{label:"In Progress",value:l.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(ps,{label:"Created",value:l.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(ps,{label:"Blocked",value:l.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(ps,{label:"Failed",value:l.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:Vl(J)}),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:Ys(U)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Tokens Today"})]}),l.costSummary&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:l.costSummary.totalTokens.toLocaleString()}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Tokens (",L[r],")"]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:Vl(l.costSummary.totalEstimatedCost)}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Cost (",L[r],")"]})]})]})]})]}),l.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:[l.taskSummary.completed.length>0&&t.jsx(ql,{title:`Completed (${l.taskSummary.completed.length})`,color:"emerald",items:l.taskSummary.completed.map(M=>({id:M.id,label:M.title,sub:M.agent}))}),l.taskSummary.inProgress.length>0&&t.jsx(ql,{title:`In Progress (${l.taskSummary.inProgress.length})`,color:"indigo",items:l.taskSummary.inProgress.map(M=>({id:M.id,label:M.title,sub:M.agent}))}),l.taskSummary.blocked.length>0&&t.jsx(ql,{title:`Blocked (${l.taskSummary.blocked.length})`,color:"amber",items:l.taskSummary.blocked.map(M=>({id:M.id,label:M.title,sub:M.reason||M.agent}))}),l.taskSummary.completed.length===0&&l.taskSummary.inProgress.length===0&&l.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]})]}):null),A==="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"})}),g.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(io,{label:"Total Tokens",col:"totalTokens",current:y,desc:N,onSort:X}),t.jsx(io,{label:"Today",col:"tokensUsedToday",current:y,desc:N,onSort:X}),t.jsx(io,{label:"Requests",col:"requestCount",current:y,desc:N,onSort:X}),t.jsx(io,{label:"Tool Calls",col:"toolCalls",current:y,desc:N,onSort:X}),t.jsx(io,{label:"Est. Cost",col:"estimatedCost",current:y,desc:N,onSort:X,align:"right"})]})}),t.jsx("tbody",{children:V.map(M=>t.jsx(qz,{agent:M,maxTokens:H},M.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 (",g.length," agents)"]}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Ys(g.reduce((M,q)=>M+q.totalTokens,0))}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Ys(U)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:g.reduce((M,q)=>M+q.requestCount,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:g.reduce((M,q)=>M+q.toolCalls,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:Vl(J)})]})})]})})]})]})})}function ps({label:e,value:r,color:s}){return t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:`text-2xl font-bold ${s}`,children:r}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function ql({title:e,color:r,items:s}){return t.jsxs("div",{children:[t.jsx("div",{className:`text-xs font-medium text-${r}-400 mb-1.5`,children:e}),t.jsx("div",{className:"space-y-1",children:s.map((l,o)=>t.jsxs("div",{className:`text-sm text-fg-secondary flex items-center gap-2 ${l.id?"cursor-pointer hover:text-fg-primary group":""}`,onClick:l.id?()=>jt.navigate("projects",{openTask:l.id}):void 0,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${r}-500 shrink-0`}),t.jsx("span",{className:`truncate ${l.id?"group-hover:text-brand-500 transition-colors":""}`,children:l.label}),l.sub&&l.sub!=="unassigned"&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:l.sub})]},l.id??o))})]})}function fd({label:e,value:r,color:s}){return t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("div",{className:"text-sm text-fg-secondary mb-2",children:e}),t.jsx("div",{className:`text-2xl font-bold ${s}`,children:r})]})}function io({label:e,col:r,current:s,desc:l,onSort:o,align:d}){const c=s===r?l?"↓":"↑":"↕",h=s===r?"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(r),children:[e,t.jsx("span",{className:`ml-1 ${h}`,children:c})]})}function qz({agent:e,maxTokens:r}){const s=r>0?Math.min(100,e.totalTokens/r*100):0,l=e.status==="working"?"bg-blue-500":e.status==="idle"?"bg-green-500":e.status==="paused"?"bg-amber-500":e.status==="error"?"bg-red-500":"bg-gray-600";return t.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>jt.navigate("team",{selectAgent:e.agentId}),children:[t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:`w-2 h-2 rounded-full ${l}`}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:t.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${s}%`}})}),t.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:Ys(e.totalTokens)})]})}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:Ys(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:Vl(e.estimatedCost)})]})}const Zv={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},rm={approval_request:"M9 12l2 2 4-4 M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z",task_completed:"M22 11.08V12a10 10 0 1 1-5.93-9.14 M22 4L12 14.01l-3-3",agent_alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z M12 9v4 M12 17h.01",bounty_posted:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z M19 10v2a7 7 0 0 1-14 0v-2",system:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"};function Qv(e){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return"now";if(s<60)return`${s}m`;const l=Math.floor(s/60);return l<24?`${l}h`:`${Math.floor(l/24)}d`}function Kv({collapsed:e,userId:r}){const[s,l]=v.useState(!1),[o,d]=v.useState("approvals"),[c,h]=v.useState([]),[m,f]=v.useState([]),[x,g]=v.useState(null),p=v.useRef(null),y=v.useRef(null),[w,N]=v.useState({top:0,left:0}),E=v.useCallback(async()=>{try{const[B,T]=await Promise.all([re.notifications.list(r,!1),re.approvals.list()]);h(B.notifications),f(T.approvals)}catch{}},[r]);v.useEffect(()=>{E();const B=setInterval(E,15e3),T=()=>E();return window.addEventListener("markus:notifications-changed",T),()=>{clearInterval(B),window.removeEventListener("markus:notifications-changed",T)}},[E]),v.useLayoutEffect(()=>{if(!s||!p.current)return;const B=p.current.getBoundingClientRect();N({top:B.top,left:B.right+8})},[s]),v.useEffect(()=>{if(!s)return;const B=T=>{p.current?.contains(T.target)||y.current?.contains(T.target)||l(!1)};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[s]);const A=new Set(m.map(B=>B.id)),C=c.filter(B=>!(B.type==="approval_request"&&B.metadata?.approvalId&&A.has(B.metadata.approvalId))),k=C.filter(B=>!B.read).length,S=m.filter(B=>B.status==="pending").length,O=k+S,R=async B=>{await re.notifications.markRead(B),h(T=>T.map(D=>D.id===B?{...D,read:!0}:D))},G=B=>{const T=B.metadata??{};switch(B.type){case"approval_request":{const D=T.approvalId,_=(D?m.find(Y=>Y.id===D):void 0)?.details?.taskId??T.taskId;_?jt.navigate("projects",{openTask:_}):jt.navigate("projects");break}case"task_completed":T.taskId?jt.navigate("projects",{openTask:T.taskId}):jt.navigate("projects");break;case"agent_alert":T.agentId?jt.navigate("team",{selectAgent:T.agentId}):jt.navigate("team");break;case"bounty_posted":jt.navigate("governance");break;default:T.taskId?jt.navigate("projects",{openTask:T.taskId}):T.projectId?jt.navigate("projects",{projectId:T.projectId}):T.agentId&&jt.navigate("team",{selectAgent:T.agentId});break}},I=async B=>{B.read||R(B.id),G(B),l(!1)},Q=async(B,T)=>{g(B);try{const{approval:D}=await re.approvals.respond(B,T,r);f(_=>_.map(Y=>Y.id===B?D:Y));const z=c.find(_=>_.type==="approval_request"&&_.metadata?.approvalId===B);z&&!z.read&&(re.notifications.markRead(z.id),h(_=>_.map(Y=>Y.id===z.id?{...Y,read:!0}:Y))),window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}catch{}g(null)},$=async()=>{const B=C.filter(T=>!T.read);await Promise.all(B.map(T=>re.notifications.markRead(T.id))),h(T=>T.map(D=>({...D,read:!0})))},F=B=>{const T=B.details?.taskId;T?jt.navigate("projects",{openTask:T}):jt.navigate("projects"),l(!1)};return t.jsxs(t.Fragment,{children:[t.jsxs("button",{ref:p,onClick:()=>{l(!s),s||E()},className:`relative flex items-center justify-center rounded-md transition-colors ${e?"w-8 h-8":"w-7 h-7"} ${s?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"}`,title:"Notifications",children:[t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),t.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),O>0&&t.jsx("span",{className:"absolute -top-0.5 -right-0.5 min-w-[16px] h-4 px-1 rounded-full bg-red-500 text-white text-[10px] font-bold flex items-center justify-center leading-none",children:O>99?"99+":O})]}),s&&ix.createPortal(t.jsxs("div",{ref:y,className:"fixed w-80 max-h-[28rem] bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:w.top,left:w.left},children:[t.jsxs("div",{className:"flex border-b border-border-default shrink-0",children:[t.jsxs("button",{onClick:()=>d("approvals"),className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${o==="approvals"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Approvals",S>0?` (${S})`:""]}),t.jsxs("button",{onClick:()=>d("notifications"),className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${o==="notifications"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Notifications",k>0?` (${k})`:""]})]}),o==="notifications"&&k>0&&t.jsx("div",{className:"flex justify-end px-3 py-1.5 border-b border-border-default/50 shrink-0",children:t.jsx("button",{onClick:$,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:"Mark all read"})}),t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o==="approvals"&&(m.length===0?t.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:"No approval requests"}):t.jsxs("div",{className:"divide-y divide-border-default/50",children:[m.filter(B=>B.status==="pending").map(B=>t.jsxs("div",{className:"px-3 py-3 space-y-2",children:[t.jsxs("button",{onClick:()=>F(B),className:"w-full text-left flex items-start gap-2 hover:bg-surface-overlay rounded transition-colors",children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 mt-0.5 shrink-0",children:t.jsx("path",{d:rm.approval_request})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary font-medium",children:B.title}),t.jsxs("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:[B.agentName," · ",Qv(B.requestedAt)]}),t.jsx("p",{className:"text-[11px] text-fg-secondary mt-1 line-clamp-3",children:B.description})]})]}),t.jsxs("div",{className:"flex gap-2 pl-5",children:[t.jsx("button",{disabled:x===B.id,onClick:()=>Q(B.id,!0),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors",children:"Approve"}),t.jsx("button",{disabled:x===B.id,onClick:()=>Q(B.id,!1),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay disabled:opacity-50 transition-colors",children:"Reject"})]})]},B.id)),m.filter(B=>B.status!=="pending").slice(0,20).map(B=>t.jsx("button",{onClick:()=>F(B),className:"w-full text-left px-3 py-2.5 opacity-50 hover:opacity-70 transition-colors",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${B.status==="approved"?"bg-green-500":"bg-red-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:B.title}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:B.status})]})},B.id))]})),o==="notifications"&&(C.length===0?t.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:"No notifications"}):t.jsx("div",{className:"divide-y divide-border-default/50",children:C.slice(0,50).map(B=>t.jsxs("button",{onClick:()=>I(B),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${B.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[t.jsx("div",{className:"shrink-0 mt-0.5",children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:t.jsx("path",{d:rm[B.type]??rm.system})})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[!B.read&&t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Zv[B.priority]??Zv.normal}`}),t.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:B.title})]}),t.jsx("p",{className:"text-[11px] text-fg-tertiary line-clamp-2 mt-0.5",children:B.body}),t.jsx("span",{className:"text-[10px] text-fg-muted mt-0.5",children:Qv(B.createdAt)})]}),t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-muted shrink-0 mt-1 opacity-0 group-hover:opacity-100",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})]},B.id))}))]})]}),document.body)]})}function oo({d:e,size:r=18}){return t.jsx("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:e})})}const co={dashboard:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M9 22V12h6v10",projects:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z",chat:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",reports:"M18 20V10 M12 20V4 M6 20v-6",deliverables:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20 M4 19.5A2.5 2.5 0 0 0 6.5 22H20V2H6.5A2.5 2.5 0 0 0 4 4.5v15z",usage:"M21.21 15.89A10 10 0 1 1 8 2.83 M22 12A10 10 0 0 0 12 2v10z",builder:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",agents:"M8 3H5a2 2 0 0 0-2 2v3 M21 8V5a2 2 0 0 0-2-2h-3 M3 16v3a2 2 0 0 0 2 2h3 M16 21h3a2 2 0 0 0 2-2v-3 M9 9h6v6H9z",teams:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2 M9 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8z M23 21v-2a4 4 0 0 0-3-3.87 M16 3.13a4 4 0 0 1 0 7.75",skills:"M12 2L2 7l10 5 10-5-10-5z M2 17l10 5 10-5 M2 12l10 5 10-5",governance:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"},Fz={active:"bg-green-500",paused:"bg-amber-500",completed:"bg-gray-500",archived:"bg-gray-600"},Vz=[{id:"dashboard",label:"Overview",section:"workspace"},{id:"chat",label:"Chat",section:"workspace"},{id:"deliverables",label:"Deliverables",section:"workspace"},{id:"builder",label:"Builder",section:"build"},{id:"agents",label:"Agents",section:"build"},{id:"teams",label:"Teams",section:"build"},{id:"skills",label:"Skills",section:"build"},{id:"governance",label:"Governance",section:"system"},{id:"reports",label:"Reports",section:"system"},{id:"settings",label:"Settings",section:"system"}],Yz=[{key:"workspace",label:"WORKSPACE"},{key:"build",label:"BUILD"},{key:"system",label:"SYSTEM"}],Jv=5;function Gz({currentPage:e,onNavigate:r,authUser:s,onLogout:l,collapsed:o,onToggleCollapse:d}){const[c,h]=v.useState([]),[m,f]=v.useState(!1),[x,g]=v.useState(null),[p,y]=v.useState(!1),w=v.useCallback(()=>{re.projects.list().then(C=>h(C.projects)).catch(()=>{})},[]);v.useEffect(()=>{w();const C=setInterval(w,3e4);return()=>clearInterval(C)},[w]),v.useEffect(()=>{if(e!=="projects"){g(null);return}const k=window.location.hash.slice(1).split("/");k[0]==="projects"&&k[1]&&g(k[1])},[e]);const N=async()=>{try{await re.auth.logout()}catch{}l?.()},E=m?c:c.slice(0,Jv),A=c.length>Jv;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(Kv,{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(Kv,{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:Yz.map((C,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:C.label}),o&&k>0&&t.jsx("div",{className:"my-2 mx-1"}),Vz.filter(S=>S.section===C.key&&!(C.key==="workspace"&&S.id==="deliverables")).map(S=>{const O=e===S.id;return t.jsxs("button",{onClick:()=>r(S.id),title:o?S.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 ${O?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":"text-fg-primary hover:bg-surface-overlay"}`,children:[t.jsx(oo,{d:co[S.id]??""}),!o&&S.label]},S.id)}),C.key==="workspace"&&o&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{g(null),r("projects")},title:"Projects",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-all ${e==="projects"&&!x?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":e==="projects"?"bg-brand-600/15 text-fg-primary":"text-fg-primary hover:bg-surface-overlay"}`,children:t.jsx(oo,{d:co.projects})}),t.jsx("button",{onClick:()=>r("deliverables"),title:"Deliverables",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e==="deliverables"?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:t.jsx(oo,{d:co.deliverables})})]}),C.key==="workspace"&&!o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center mb-0.5",children:[t.jsxs("button",{onClick:()=>{g(null),window.location.hash="projects",r("projects")},className:`flex-1 flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-colors ${e==="projects"&&!x?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(oo,{d:co.projects}),"Projects"]}),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"]}),E.map(S=>{const O=e==="projects"&&x===S.id;return t.jsxs("button",{onClick:()=>{g(S.id),e!=="projects"&&r("projects"),window.location.hash="projects/"+S.id},className:`w-full flex items-center gap-2.5 pl-9 pr-3 py-1.5 rounded-lg text-sm mb-0.5 transition-colors ${O?"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 ${Fz[S.status]??"bg-gray-600"}`}),t.jsx("span",{className:"truncate text-xs",children:S.name})]},S.id)}),A&&!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:()=>r("deliverables"),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e==="deliverables"?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(oo,{d:co.deliverables}),"Deliverables"]})]})]})},C.key))}),t.jsxs("div",{className:`${o?"p-2 flex flex-col items-center gap-2":"px-4 py-3 space-y-2"}`,children:[s&&(o?t.jsx("button",{onClick: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.9"]})]}),p&&t.jsx(wN,{orgId:s?.orgId,onCreated:()=>{y(!1),w()},onClose:()=>y(!1)})]})}const Xz={dashboard:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M9 22V12h6v10",chat:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",projects:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z",deliverables:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20 M4 19.5A2.5 2.5 0 0 0 6.5 22H20V2H6.5A2.5 2.5 0 0 0 4 4.5v15z",builder:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"},Zz=[{id:"dashboard",label:"Home",iconKey:"dashboard",group:["dashboard"]},{id:"chat",label:"Chat",iconKey:"chat",group:["chat"]},{id:"projects",label:"Projects",iconKey:"projects",group:["projects"]},{id:"deliverables",label:"Deliverables",iconKey:"deliverables",group:["deliverables"]},{id:"builder",label:"Builder",iconKey:"builder",group:["builder","agents","teams","skills"]},{id:"settings",label:"Settings",iconKey:"settings",group:["settings","governance","reports"]}];function Qz({currentPage:e,onNavigate:r}){return t.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-surface-secondary border-t border-border-default flex items-stretch h-14 safe-area-bottom",children:Zz.map(s=>{const l=s.group.includes(e);return t.jsxs("button",{onClick:()=>r(s.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${l?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[t.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:l?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:Xz[s.iconKey]})}),t.jsx("span",{className:`text-[10px] leading-tight ${l?"font-semibold":""}`,children:s.label})]},s.id)})})}const Kz=50,Jz=30;function AN(e,r,s){const l=v.useRef(0),o=v.useRef(0),d=v.useCallback(h=>{l.current=h.touches[0].clientX,o.current=h.touches[0].clientY},[]),c=v.useCallback(h=>{const m=h.changedTouches[0].clientX-l.current,f=h.changedTouches[0].clientY-o.current,x=Math.abs(m),g=Math.abs(f);if(x<Kz||Math.atan2(g,x)*(180/Math.PI)>Jz)return;const y=e.findIndex(w=>w.id===r);m<0&&y<e.length-1?s(e[y+1].id):m>0&&y>0&&s(e[y-1].id)},[e,r,s]);return{onTouchStart:d,onTouchEnd:c}}const Wv=[{id:"builder",label:"Builder"},{id:"agents",label:"Agents"},{id:"teams",label:"Teams"},{id:"skills",label:"Skills"}];function Wz({authUser:e}){const[r,s]=v.useState("builder"),l=AN(Wv,r,s);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:l.onTouchStart,onTouchEnd:l.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:Wv.map(o=>t.jsx("button",{onClick:()=>s(o.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${r===o.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:o.label},o.id))}),t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[r==="builder"&&t.jsx(Oj,{}),r==="agents"&&t.jsx(Aj,{authUser:e}),r==="teams"&&t.jsx(Dj,{}),r==="skills"&&t.jsx(Cj,{})]})]})}const e1=[{id:"settings",label:"Settings"},{id:"governance",label:"Governance"},{id:"reports",label:"Reports"}];function eI({theme:e,onThemeChange:r}){const[s,l]=v.useState("settings"),o=AN(e1,s,l);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:o.onTouchStart,onTouchEnd:o.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:e1.map(d=>t.jsx("button",{onClick:()=>l(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(kj,{theme:e,onThemeChange:r}),s==="governance"&&t.jsx(Rj,{}),s==="reports"&&t.jsx(TN,{})]})]})}const t1=2;function tI({onComplete:e,theme:r,onThemeChange:s}){const[l,o]=v.useState(0),[d,c]=v.useState(null),[h,m]=v.useState(!1),[f,x]=v.useState({}),[g,p]=v.useState(!1),[y,w]=v.useState(null),[N,E]=v.useState(!1),[A,C]=v.useState(!1),[k,S]=v.useState(null),O=v.useRef(!1),R=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});v.useEffect(()=>{fetch("/api/settings/llm").then(z=>z.ok?z.json():null).then(z=>{z?.providers&&Object.values(z.providers).some(_=>_.configured)&&C(!0)}).catch(()=>{})},[]),v.useEffect(()=>{l===t1&&!O.current&&!A&&(O.current=!0,G())},[l,A]);const G=async()=>{m(!0);try{const z=await fetch("/api/settings/env-models",{headers:R()});if(z.ok){const _=await z.json();if(c(_),_.detected.length>0){const Y={};for(const V of _.detected)Y[V.provider]=!0;x(Y)}}}catch{}finally{m(!1)}},I=async()=>{if(!d)return;const z=d.detected.filter(_=>f[_.provider]);if(z.length!==0){p(!0),S(null);try{const _=await fetch("/api/settings/env-models",{method:"POST",headers:R(),body:JSON.stringify({providers:z.map(Y=>({provider:Y.provider,model:Y.model,baseUrl:Y.baseUrl,enabled:!0}))})});if(_.ok){const Y=await _.json();S({type:"ok",text:Y.message}),C(!0)}else S({type:"err",text:"Failed to apply"})}catch{S({type:"err",text:"Network error"})}finally{p(!1)}}},Q=async()=>{E(!0);try{const _=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:R(),body:JSON.stringify({preview:!0})})).json();"error"in _||w(_)}catch{}finally{E(!1)}},$=async()=>{E(!0),S(null);try{const _=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:R(),body:JSON.stringify({preview:!1})})).json();"error"in _?S({type:"err",text:_.error}):(S({type:"ok",text:`Imported ${_.appliedModels} model configs`}),C(!0))}catch{S({type:"err",text:"Import failed"})}finally{E(!1)}},F=[{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"}],B=[{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(([z,_])=>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:z}),t.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:_})]},z))})]})},{title:"Choose Your Theme",subtitle:"You can change this anytime in Settings",content:t.jsx("div",{className:"grid grid-cols-3 gap-3",children:F.map(z=>t.jsxs("button",{onClick:()=>s(z.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${r===z.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:z.icon}),t.jsx("span",{className:"text-sm font-medium text-fg-primary",children:z.label}),t.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:z.desc})]},z.value))})},{title:"Configure LLM",subtitle:"Agents need an LLM to think and act",content:A?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(z=>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[z.provider]??!1,onChange:_=>x({...f,[z.provider]:_.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-sm text-fg-primary",children:z.displayName}),t.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:z.model})]}),t.jsx("code",{className:"text-[10px] text-fg-tertiary",children:z.apiKeyPreview})]},z.provider)),t.jsx("button",{onClick:()=>{I()},disabled:g||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:g?"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:()=>{$()},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:()=>{Q()},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(([z,_])=>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:z}),t.jsx("div",{className:"text-fg-secondary text-xs",children:_})]})]},z))})}],T=()=>{l<B.length-1?o(l+1):e()},D=B[l];return t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:t.jsx("div",{className:"w-full max-w-lg",children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl p-8",children:[t.jsx("div",{className:"flex gap-1.5 mb-8",children:B.map((z,_)=>t.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${_<=l?"bg-brand-500":"bg-surface-elevated"}`},_))}),t.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:D.title}),t.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:D.subtitle}),D.content,t.jsxs("div",{className:"flex justify-between mt-8",children:[l>0?t.jsx("button",{onClick:()=>o(l-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:"Back"}):t.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip"}),t.jsxs("div",{className:"flex items-center gap-3",children:[l===t1&&!A&&t.jsx("button",{onClick:T,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip for now"}),t.jsx("button",{onClick:T,className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-xl transition-colors",children:l===B.length-1?"Get Started":"Next"})]})]})]})})})}const nI="markus123";function rI({onLogin:e}){const[r,s]=v.useState("admin@markus.local"),[l,o]=v.useState(""),[d,c]=v.useState(""),[h,m]=v.useState(!1),f=async x=>{if(x.preventDefault(),!(!r.trim()||!l)){c(""),m(!0);try{const{user:g}=await re.auth.login(r.trim(),l);e(g,l===nI)}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:r,onChange:x=>s(x.target.value),autoComplete:"email",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Password"}),t.jsx("input",{type:"password",value:l,onChange:x=>o(x.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),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||!r||!l,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all shadow-md shadow-brand-900/40 hover:shadow-lg hover:shadow-brand-900/50",children:h?"Signing in…":"Sign in"}),t.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:"Default: admin@markus.local / markus123"})]})]})]})}function sI({onComplete:e,isFirstTime:r}){const[s,l]=v.useState(""),[o,d]=v.useState(""),[c,h]=v.useState(""),[m,f]=v.useState(""),[x,g]=v.useState(!1),p=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}g(!0);try{await re.auth.changePassword(s,o),e()}catch{f("Failed to change password. Check your current password.")}finally{g(!1)}};return t.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[t.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),t.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),t.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),t.jsx("div",{className:"text-sm text-fg-tertiary",children:"AI Digital Employee Platform"})]}),t.jsxs("form",{onSubmit:p,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:r?"Set Your Password":"Change Password"}),r&&t.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:"You're using the default password. Please set a new one before continuing."})]}),!r&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Current Password"}),t.jsx("input",{type:"password",value:s,onChange:y=>l(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…":r?"Set Password & Continue":"Change Password"})]})]})]})}const _N="markus-theme";function n1(e){const r=document.documentElement;r.classList.remove("light","dark"),e==="light"?r.classList.add("light"):e==="dark"&&r.classList.add("dark")}function aI(){try{const e=localStorage.getItem(_N);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function lI(){const[e,r]=v.useState(aI),s=v.useCallback(l=>{r(l);try{localStorage.setItem(_N,l)}catch{}n1(l)},[]);return v.useEffect(()=>{n1(e)},[e]),{mode:e,setMode:s}}const iI=["dashboard","tasks","chat","team","usage","skills","agents","teams","builder","prompts","settings","governance","projects","deliverables","reports"];function hd(){const e=window.location.hash.slice(1).split("/")[0];return e==="team"?"chat":e==="tasks"?"projects":e==="usage"?"reports":e==="prompts"?"builder":e==="templates"?"agents":e==="knowledge"?"deliverables":iI.includes(e)?e:"dashboard"}const sm={};function oI(){const[e,r]=v.useState(hd),[s,l]=v.useState(()=>!localStorage.getItem("markus_onboarded")),[o,d]=v.useState(!0),c=ks(),h=lI(),m=Wd({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[f,x]=v.useState(()=>new Set([hd()])),[g,p]=v.useState("loading"),[y,w]=v.useState(!1),[N,E]=v.useState(null),[A,C]=v.useState(!1),k=v.useCallback(G=>{let I=G==="tasks"?"projects":G==="team"?"chat":G==="usage"?"reports":G==="prompts"?"builder":G==="templates"?"agents":G;c&&((I==="agents"||I==="teams"||I==="skills")&&(I="builder"),(I==="governance"||I==="reports")&&(I="settings"));const Q=hd(),$=window.location.hash.slice(1);$!==Q?sm[Q]=$:delete sm[Q];const F=sm[I];F&&F!==I?(history.pushState(null,"","#"+I),history.pushState(null,"","#"+F)):history.pushState(null,"","#"+I),window.dispatchEvent(new HashChangeEvent("hashchange")),r(I),x(B=>B.has(I)?B:new Set([...B,I]))},[c]);v.useEffect(()=>{jt.setHandler(G=>k(G))},[k]);const S=v.useCallback(()=>{fetch("/api/settings/llm").then(G=>G.ok?G.json():null).then(G=>{if(G?.providers){const I=Object.values(G.providers).some(Q=>Q.configured);E(I)}}).catch(()=>{})},[]);v.useEffect(()=>{re.auth.me().then(({user:I})=>{p(I),S(),Qa(wr.builderArtifacts,()=>re.builder.artifacts.list()),Qa(wr.builderAgents,()=>re.agents.list()),Qa(wr.builderHubMyItems,()=>Un.myItems()),Qa(wr.builderInstalled,()=>re.builder.artifacts.installed()),Qa(wr.hubAgents,()=>Un.search({type:"agent",limit:50})),Qa(wr.hubTeams,()=>Un.search({type:"team",limit:50})),Qa(wr.hubSkills,()=>Un.search({type:"skill",limit:50}))}).catch(()=>p(null)),kn.connect();const G=()=>{const I=hd();r(I),x(Q=>Q.has(I)?Q:new Set([...Q,I]))};return window.addEventListener("hashchange",G),()=>{kn.disconnect(),window.removeEventListener("hashchange",G)}},[]);const O=g!=="loading"&&g!==null?g:void 0,R=v.useMemo(()=>c?{dashboard:t.jsx(xb,{}),chat:t.jsx(wy,{authUser:O}),builder:t.jsx(Wz,{authUser:O}),settings:t.jsx(eI,{theme:h.mode,onThemeChange:h.setMode}),projects:t.jsx(Vv,{authUser:O}),deliverables:t.jsx(Xv,{})}:{dashboard:t.jsx(xb,{}),chat:t.jsx(wy,{authUser:O}),settings:t.jsx(kj,{theme:h.mode,onThemeChange:h.setMode}),skills:t.jsx(Cj,{}),agents:t.jsx(Aj,{authUser:O}),teams:t.jsx(Dj,{}),builder:t.jsx(Oj,{}),governance:t.jsx(Rj,{}),projects:t.jsx(Vv,{authUser:O}),deliverables:t.jsx(Xv,{}),reports:t.jsx(TN,{authUser:O})},[O?.id,h.mode,c]);return g==="loading"?t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:t.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:"Loading…"})}):g===null?t.jsx(rI,{onLogin:(G,I)=>{p(G),I&&w(!0)}}):y?t.jsx(sI,{onComplete:()=>w(!1),isFirstTime:!0}):s?t.jsx(tI,{theme:h.mode,onThemeChange:h.setMode,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),l(!1),S()}}):t.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary ${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(Gz,{currentPage:e,onNavigate:G=>{k(G),d(!1)},authUser:g,onLogout:()=>p(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&&!A&&e!=="settings"&&t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-amber-500/10 border-b border-amber-500/30 text-amber-600 text-sm shrink-0",children:[t.jsx("span",{className: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("settings")},className:"px-3 py-1 bg-amber-700/50 hover:bg-amber-700/70 text-white text-xs rounded-lg transition-colors",children:"Go to Settings"}),t.jsx("button",{onClick:()=>C(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:"Dismiss"})]})]}),t.jsx("main",{className:"flex-1 overflow-hidden flex flex-col",children:Object.keys(R).map(G=>f.has(G)?t.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:G===e?"flex":"none"},children:R[G]},G):null)})]}),c&&t.jsx(Qz,{currentPage:e,onNavigate:k})]})}U2.createRoot(document.getElementById("root")).render(t.jsx(v.StrictMode,{children:t.jsx(oI,{})}));
63
+ ${ht?"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 ${bt.cls}`,children:bt.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Oe.title}),Oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Oe.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:[_n&&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:_n.name,children:_n.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Oe.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",at]})]}),t.jsx("div",{className:"flex items-center gap-1",children:Oe.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:["📋 ",Oe.taskIds.length]})})]}),Dt&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:Ye=>{Ye.stopPropagation(),tr(Oe.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:Ye=>{Ye.stopPropagation(),Ct(Oe.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-${Oe.id}`)}else{const Oe=Ve.data,bt=Oe.subtasks?.length??0,Gt=kN[Oe.status],Dt=Oe.status==="pending",_n=Oe.taskType==="scheduled"&&!!Oe.scheduleConfig,at=_n?Oe.scheduleConfig.every?`Every ${Oe.scheduleConfig.every}`:Oe.scheduleConfig.cron?"Cron":"Scheduled":null,ht=m==="all"&&Oe.projectId?c.find(Ge=>Ge.id===Oe.projectId)?.name:null,Ye=Oe.requirementId?C.find(Ge=>Ge.id===Oe.requirementId)?.title:null,Ke=Oe.createdBy?ii(Oe.createdBy,w,E)??Oe.createdBy:null,Je=Ce?.id===Oe.id,st={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":Oe.title,draggable:!Dt,onDragStart:Ge=>!Dt&&os(Ge,Oe),onDragEnd:nr,onClick:()=>an(Oe),onKeyDown:Ge=>Ge.key==="Enter"&&an(Oe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Dt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":_n?"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"} ${Je?"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 ${st[Oe.priority]??"bg-gray-400"}`,title:Oe.priority}),_n&&t.jsx("span",{className:"text-blue-500 shrink-0",title:at??"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"})})}),_n&&at&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:at}),Gt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Gt.cls}`,children:Gt.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Oe.title}),Oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Oe.description}),(ht||Ye||Oe.blockedBy&&Oe.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[ht&&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:ht,children:ht}),Ye&&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:Ye,children:["# ",Ye]}),Oe.blockedBy&&Oe.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:["⏳ ",Oe.blockedBy.length," dep",Oe.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:Ke&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Ke}`,children:["by ",Ke]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[bt>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",bt]}),Oe.notes&&Oe.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",Oe.notes.length]}),Oe.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 ${SN[w.find(Ge=>Ge.id===Oe.assignedAgentId)?.status??""]??"bg-gray-500"}`}),w.find(Ge=>Ge.id===Oe.assignedAgentId)?.name??Oe.assignedAgentId.slice(0,8)]})]})]})]},Oe.id)}})})()}),Me&&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"})})]},Z.id)})})})]}),!r&&ne&&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}),(!r||l)&&ne&&t.jsx("div",{className:`${r?"flex-1":"shrink-0"} overflow-hidden min-w-0 border-l border-border-default`,style:r?void 0:{width:s.width},children:Ce?t.jsx(Tz,{task:Ce,agents:w,projects:c,requirements:C,allTasks:Object.values(p).flat(),users:E,onClose:At,onRefresh:hr,authUser:e}):tt?t.jsx($z,{req:tt,agents:w,projects:c,allTasks:Object.values(p).flat(),users:E,onClose:At,onApprove:Z=>{tr(Z),At()},onReject:Z=>{Ct(Z),At()},onCancel:Z=>{fn(Z),At()},onStatusChange:async(Z,oe)=>{try{await re.requirements.updateStatus(Z,oe),Le(`Requirement status → ${oe}`),gt(),ft()}catch(me){Le(`Error: ${me}`)}},onRefresh:gt,authUser:e}):null}),F&&t.jsx(wN,{orgId:e?.orgId,onCreated:St,onClose:()=>B(!1)}),T&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>D(!1),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${r?"w-full":"w-[28rem]"}`,onClick:Z=>Z.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:q,onChange:Z=>K(Z.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(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.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:Z=>te(Z.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…"}),C.filter(Z=>Z.status==="in_progress"&&(!q||Z.projectId===q)).map(Z=>t.jsx("option",{value:Z.id,children:Z.title},Z.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{autoFocus:!r,value:z,onChange:Z=>_(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"&&Qn()},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:Y,onChange:Z=>V(Z.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:J,onChange:Z=>U(Z.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:H,onChange:Z=>X(Z.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(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.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:L,onChange:Z=>M(Z.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(Z=>Z.id!==H).map(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.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:ke,onChange:Z=>De(Z.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)"})]})]}),ke==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Frequency"}),t.jsxs("select",{value:ge,onChange:Z=>ye(Z.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:Z=>{const oe=Z.target.value;oe&&!se.includes(oe)&&xe([...se,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(p).flat().filter(Z=>Z.status!=="completed"&&Z.status!=="cancelled"&&!se.includes(Z.id)).map(Z=>t.jsx("option",{value:Z.id,children:Z.title},Z.id))]}),se.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:se.map(Z=>{const oe=Object.values(p).flat().find(me=>me.id===Z);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):Z.slice(-8),t.jsx("button",{onClick:()=>xe(se.filter(me=>me!==Z)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},Z)})})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>D(!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:()=>{Qn()},disabled:!H||!L,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:"Create"})]})]})}),qt&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{yt(!1),Xt(""),Pe("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${r?"w-full":"w-[28rem]"}`,onClick:Z=>Z.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:ut,onChange:Z=>Wt(Z.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(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Title"}),t.jsx("input",{value:sn,onChange:Z=>Xt(Z.target.value),placeholder:"e.g. Add user authentication",className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!r,onKeyDown:Z=>{Z.key==="Enter"&&sn.trim()&&or()}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:"Description"}),t.jsx("textarea",{value:je,onChange:Z=>Pe(Z.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:vt,onChange:Z=>Nt(Z.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:()=>{yt(!1),Xt(""),Pe("")},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:()=>{or()},disabled:!sn.trim()||!je.trim()||!ut,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"})]})]})}),en&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>Ct(null),children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${r?"w-full":"w-96"}`,onClick:Z=>Z.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:de,onChange:Z=>Be(Z.target.value),placeholder:"Why is this being rejected...",rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!r})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>Ct(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:()=>{cr()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:"Reject"})]})]})}),zt&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Yt(!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:Z=>Z.stopPropagation(),children:[t.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:"Filters"}),t.jsxs("div",{className:"flex items-center gap-2",children:[(ae.size>0||dt.size>0)&&t.jsx("button",{onClick:()=>{Te(new Set),wt(new Set)},className:"text-[11px] text-brand-500 font-medium",children:"Clear all"}),t.jsx("button",{onClick:()=>Yt(!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:Tr.map(Z=>{const oe=ae.has(Z.id),me=cs[Z.id]??0;return t.jsxs("button",{onClick:()=>He(Z.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:Z.name[0]?.toUpperCase()}),Z.name,me>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:me})]},Z.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:An.map(Z=>{const oe=dt.has(Z.id);return t.jsxs("button",{onClick:()=>Se(Z.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:Z.name[0]?.toUpperCase()}),Z.name]},Z.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Iz({requirementId:e,agents:r,authUser:s}){const[l,o]=v.useState([]);v.useEffect(()=>{re.requirements.getComments(e).then(c=>o(c.comments)).catch(()=>{})},[e]),v.useEffect(()=>kn.on("requirement:comment",h=>{h.payload?.requirementId===e&&h.payload.comment&&o(m=>m.some(f=>f.id===h.payload.comment.id)?m:[...m,h.payload.comment])}),[e]);const d=async(c,h)=>{await re.requirements.addComment(e,c,s?.name,s?.id,h.length>0?h:void 0)};return t.jsxs("div",{children:[t.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:["Comments ",l.length>0&&t.jsxs("span",{className:"font-normal",children:["(",l.length,")"]})]}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[l.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:"No comments yet."}),l.map(c=>t.jsx(yo,{comment:c,agents:r},c.id))]}),t.jsx(yj,{agents:r,onSubmit:d})]})}function $z({req:e,agents:r,projects:s,allTasks:l,users:o,onClose:d,onApprove:c,onReject:h,onCancel:m,onStatusChange:f,onRefresh:x,authUser:g}){const p=ks(),[y,w]=v.useState(!1),[N,E]=v.useState(e.description),[A,C]=v.useState(!1),k=Oo[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},S=e.source==="agent",O=S&&e.status==="pending",R=e.status==="pending"||e.status==="in_progress",G=e.status==="completed"||e.status==="rejected"||e.status==="cancelled",I=e.projectId?s.find(F=>F.id===e.projectId):null,Q=ii(e.createdBy,r,o)??e.createdBy.slice(0,12),$=l.filter(F=>e.taskIds.includes(F.id));return v.useEffect(()=>{E(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:[p&&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})]})]}),!p&&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:F=>E(F.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),E(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()=>{C(!0);try{await re.requirements.update(e.id,{description:N}),w(!1),x?.()}catch{}finally{C(!1)}},disabled:A,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(Zn,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:"No description"}),!G&&t.jsx("button",{onClick:()=>{E(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:Q}),S&&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()})]}),I&&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:I.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:ii(e.approvedBy,r,o)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:"Rejection Reason"}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(F=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",F]},F))}),$.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 (",$.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:$.map(F=>{const B=kN[F.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 ${vz[F.priority]?.replace("border-l-","bg-")??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:F.title}),B&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${B.cls}`,children:B.label})]},F.id)})})]}),t.jsx(Iz,{requirementId:e.id,agents:r,authUser:g})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[O&&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"})]}),!O&&f&&!G&&t.jsx("select",{value:e.status,onChange:F=>{F.target.value!==e.status&&f(e.id,F.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:Oz.map(F=>{const B=Oo[F];return t.jsx("option",{value:F,children:B?.label??F},F)})}),G&&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"}),R&&!O&&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 xs(e){return Array.isArray(e)?e.map(r=>String(r).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(r=>r.trim()).filter(Boolean):[]}function Bz(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function Ka({label:e,value:r}){return r?t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:r})]}):null}function Ul({label:e,value:r,color:s}){if(!r)return null;const l={purple:"bg-brand-500/15 text-brand-500",cyan:"bg-blue-500/15 text-blue-600",indigo:"bg-brand-500/15 text-brand-500",gray:"bg-gray-500/15 text-fg-secondary",emerald:"bg-green-500/15 text-green-600"};return t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),t.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${l[s]??l.gray} capitalize inline-block`,children:r})]})}function tm({files:e}){const[r,s]=v.useState(Object.keys(e)[0]??""),l=Object.keys(e);return l.length===0?null:t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:["Files (",l.length,")"]}),t.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[t.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:l.map(o=>t.jsx("button",{onClick:()=>s(o),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${r===o?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:o},o))}),r&&e[r]!=null&&t.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[r]})]})]})}function Hz({artifact:e,mode:r}){const s=Bz(e),l=e.agent,o=e.team,d=e.dependencies,c=e.displayName??e.name;if(r==="agent"){const h=l?.roleName,m=l?.agentRole,f=l?.llmProvider,x=l?.llmModel,g=xs(d?.env),p=xs(d?.skills);return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Ka,{label:"Name",value:c}),t.jsx(Ka,{label:"Description",value:e.description}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(Ul,{label:"Role Template",value:h,color:"indigo"}),t.jsx(Ul,{label:"Agent Role",value:m,color:m==="manager"?"purple":"cyan"})]}),xs(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:xs(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(Ul,{label:"LLM Provider",value:f,color:"gray"}),x&&t.jsx(Ul,{label:"LLM Model",value:x,color:"gray"})]}),g.length>0&&t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:"Required Env"}),t.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:g.map(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))})]}),p.length>0&&t.jsx(Ka,{label:"Skills",value:p.join(", ")}),s&&t.jsx(tm,{files:s})]})}if(r==="team"){const m=o?.members??[];return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Ka,{label:"Name",value:c}),t.jsx(Ka,{label:"Description",value:e.description}),t.jsx("div",{className:"flex flex-wrap gap-2",children:t.jsx(Ul,{label:"Category",value:e.category,color:"indigo"})}),xs(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:xs(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(tm,{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)]})]}),xs(f.skills).length>0&&t.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:xs(f.skills).map(g=>t.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:g},g))})]},x))})]})]})}return t.jsxs("div",{className:"space-y-3 text-sm",children:[t.jsx(Ka,{label:"Name",value:c}),t.jsx(Ka,{label:"Description",value:e.description}),t.jsx("div",{className:"flex gap-2",children:t.jsx(Ul,{label:"Category",value:e.category,color:"indigo"})}),s&&t.jsx(tm,{files:s}),xs(e.tags).length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:xs(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 lo={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},Yv={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"}},Gv=["file","directory"],gs={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 Xv(){const e=ks(),r=Wd({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[s,l]=v.useState(!1),o=v.useRef(s);o.current=s,v.useEffect(()=>{if(!e)return;const fe=()=>{o.current&&l(!1)};return window.addEventListener("popstate",fe),()=>window.removeEventListener("popstate",fe)},[e]);const d=100,[c,h]=v.useState([]),[m,f]=v.useState(0),[x,g]=v.useState(!1),[p,y]=v.useState([]),[w,N]=v.useState([]),[E,A]=v.useState(!0),[C,k]=v.useState(""),[S,O]=v.useState(""),[R,G]=v.useState(""),[I,Q]=v.useState(""),[$,F]=v.useState(""),[B,T]=v.useState(""),[D,z]=v.useState(""),[_,Y]=v.useState("date"),[V,J]=v.useState(null),[U,H]=v.useState(null),[X,L]=v.useState(""),[M,q]=v.useState(!1),[K,ee]=v.useState(!1),[te,se]=v.useState(new Set),xe=v.useRef(null),[ke,De]=v.useState("file"),[ge,ye]=v.useState(""),[Ce,ze]=v.useState(""),[tt,Xe]=v.useState(""),[dt,wt]=v.useState(""),[ae,Te]=v.useState(""),[Ze,xt]=v.useState(null),[dn,we]=v.useState(null),[Re,qe]=v.useState(!1),[et,nt]=v.useState(!1),[zt,Yt]=v.useState(!1),[Lt,Tt]=v.useState(!1),qt=v.useRef(null),yt=v.useRef(null),[sn,Xt]=v.useState(""),je=v.useRef(void 0),Pe=(fe,Fe)=>{H({type:fe,text:Fe}),setTimeout(()=>H(null),3e3)},vt=async fe=>{try{return await navigator.clipboard.writeText(fe),!0}catch{try{const Fe=document.createElement("textarea");Fe.value=fe,Fe.style.cssText="position:fixed;left:-9999px;top:-9999px;opacity:0",document.body.appendChild(Fe),Fe.select();const kt=document.execCommand("copy");return document.body.removeChild(Fe),kt}catch{return!1}}},Nt=async fe=>{await vt(fe)?(Tt(!0),setTimeout(()=>Tt(!1),1500)):Pe("error","Copy failed — try long-pressing to copy manually")},ut=v.useMemo(()=>new Map(w.map(fe=>[fe.id,fe])),[w]),Wt=v.useMemo(()=>new Map(p.map(fe=>[fe.id,fe])),[p]);v.useEffect(()=>{re.projects.list().then(fe=>y(fe.projects)).catch(()=>{}),re.agents.list().then(fe=>N(fe.agents??[])).catch(()=>{}),re.system.storage().then(fe=>Xt(fe.dataDir+"/shared")).catch(()=>{})},[]),v.useEffect(()=>(je.current=setTimeout(()=>O(C),300),()=>clearTimeout(je.current)),[C]);const en=v.useMemo(()=>({q:S||void 0,projectId:I||void 0,agentId:$||void 0,type:R||void 0,status:B||void 0,artifactType:D||void 0}),[S,I,$,R,B,D]),Ct=v.useCallback(async()=>{A(!0);try{const{results:fe,total:Fe}=await re.deliverables.search({...en,offset:0,limit:d});h(fe),f(Fe)}catch{h([]),f(0)}A(!1)},[en]),de=v.useCallback(async()=>{if(!(x||c.length>=m)){g(!0);try{const{results:fe,total:Fe}=await re.deliverables.search({...en,offset:c.length,limit:d});h(kt=>[...kt,...fe]),f(Fe)}catch{}g(!1)}},[en,c.length,m,x]);v.useEffect(()=>{Ct()},[Ct]),v.useEffect(()=>kn.on("deliverable:created",()=>Ct()),[Ct]);const Be=v.useCallback(()=>{const fe=xe.current;!fe||E||x||c.length>=m||fe.scrollHeight<=fe.clientHeight+100&&de()},[E,x,c.length,m,de]);v.useEffect(()=>{const fe=xe.current;if(!fe)return;const Fe=()=>{fe.scrollTop+fe.clientHeight>=fe.scrollHeight-100&&de()};return fe.addEventListener("scroll",Fe,{passive:!0}),()=>fe.removeEventListener("scroll",Fe)},[de]),v.useEffect(()=>{Be()},[Be,te]);const Le=v.useMemo(()=>{const fe=new Map;for(const kt of c){let St,Tn;if(_==="project")St=kt.projectId??"_none",Tn=kt.projectId?Wt.get(kt.projectId)?.name??kt.projectId:"No Project";else if(_==="agent")St=kt.agentId??"_none",Tn=kt.agentId?ut.get(kt.agentId)?.name??kt.agentId:"Unknown";else if(_==="type")St=kt.type,Tn=kt.type.charAt(0).toUpperCase()+kt.type.slice(1);else{const Qn=new Date(kt.updatedAt);St=`${Qn.getFullYear()}-${String(Qn.getMonth()+1).padStart(2,"0")}-${String(Qn.getDate()).padStart(2,"0")}`,Tn=St}fe.has(St)||fe.set(St,{label:Tn,items:[]}),fe.get(St).items.push(kt)}const Fe=[...fe.entries()];return _==="date"?Fe.sort((kt,St)=>St[0].localeCompare(kt[0])):Fe.sort((kt,St)=>kt[1].label.localeCompare(St[1].label)),Fe},[c,_,Wt,ut]),ot=async()=>{if(!(!ge.trim()||!Ce.trim())){ee(!0);try{await re.deliverables.create({type:ke,title:ge,summary:Ce,reference:tt,projectId:dt||void 0,tags:ae.split(",").map(fe=>fe.trim()).filter(Boolean)}),q(!1),Pe("success","Deliverable created"),Ct()}catch(fe){Pe("error",`Error: ${fe}`)}ee(!1)}},Qe=async fe=>{L("verify");try{await re.deliverables.verify(fe.id),Pe("success","Verified"),J({...fe,status:"verified"}),Ct()}catch(Fe){Pe("error",`Error: ${Fe}`)}L("")},ft=async fe=>{L("flag");try{await re.deliverables.update(fe.id,{status:"outdated"}),Pe("success","Flagged as outdated"),J({...fe,status:"outdated"}),Ct()}catch(Fe){Pe("error",`Error: ${Fe}`)}L("")},Zt=async fe=>{L("remove");try{await re.deliverables.remove(fe.id),Pe("success","Removed"),J(null),Ct()}catch(Fe){Pe("error",`Error: ${Fe}`)}L("")},it=()=>{jt.navigate("builder")},gt=async fe=>{if(fe.reference){if(fe.type==="directory"){nt(!0);return}qe(!0);try{const Fe=await re.files.preview(fe.reference);Fe.type==="image"&&Fe.mimeType?we({src:`data:${Fe.mimeType};base64,${Fe.content}`,name:Fe.name}):xt(Fe.content)}catch{xt(null),fe.type==="file"&&nt(!0)}qe(!1)}};v.useEffect(()=>{xt(null),we(null),nt(!1),Yt(!1),V&&gt(V)},[V?.id]),v.useEffect(()=>{if(!zt)return;const fe=Fe=>{yt.current&&!yt.current.contains(Fe.target)&&Yt(!1)};return document.addEventListener("mousedown",fe),()=>document.removeEventListener("mousedown",fe)},[zt]);const wn=async(fe,Fe)=>{const kt=qt.current?.firstElementChild;if(!kt)return;const St=Pz(kt,fe);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([St],{type:"text/html"}),"text/plain":new Blob([Fe],{type:"text/plain"})})]),Pe("success",fe==="light"?"HTML (light) copied":"HTML (dark) copied")}catch{const Tn=await vt(Fe);Pe(Tn?"success":"error",Tn?"Text copied (HTML not supported)":"Copy failed")}Yt(!1)},an=fe=>t.jsxs("div",{className:"relative group/preview",children:[t.jsxs("div",{className:"absolute -top-1 -right-1 z-10",ref:yt,children:[t.jsx("button",{onClick:()=>Yt(Fe=>!Fe),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"})})}),zt&&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 Fe=await vt(fe);Pe(Fe?"success":"error",Fe?"Markdown source copied":"Copy failed"),Yt(!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:()=>wn("light",fe),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:()=>wn("dark",fe),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:qt,children:t.jsx(Zn,{content:fe,className:"text-fg-secondary text-sm"})})]}),Qt=v.useCallback(fe=>{se(Fe=>{const kt=new Set(Fe);return kt.has(fe)?kt.delete(fe):kt.add(fe),kt})},[]),At=v.useCallback(()=>{te.size===Le.length?se(new Set):se(new Set(Le.map(([fe])=>fe)))},[te.size,Le]),un=()=>{ye(""),ze(""),Xe(""),Te(""),De("file"),p.length>0&&wt(p[0].id),q(!0)},En=fe=>{J(fe),e&&(l(!0),history.pushState({mobileDetail:"deliverables"},"",window.location.hash))};return t.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[t.jsxs("div",{className:`${e?"flex-1 min-w-0":"shrink-0"} border-r border-border-default flex flex-col bg-surface-primary`,style:e?s?{display:"none"}:void 0:{width:r.width},children:[t.jsxs("div",{className:"p-4 border-b border-border-default space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary",children:["Deliverables",m>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",m,")"]})]}),t.jsx("button",{onClick:un,className:"text-xs px-2.5 py-1 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create"})]}),t.jsx("input",{value:C,onChange:fe=>k(fe.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"}),sn&&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:sn}),t.jsx("button",{onClick:()=>{re.system.openPath(sn)},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(Ea,{label:"All types",value:"",current:R||D||"",onClick:()=>{G(""),z("")}}),Gv.map(fe=>t.jsx(Ea,{label:`${lo[fe]?.icon??""} ${fe}`,value:fe,current:R,onClick:Fe=>{G(Fe),z("")}},fe)),["agent","team","skill"].map(fe=>t.jsx(Ea,{label:`${gs[fe].icon} ${gs[fe].label}`,value:fe,current:D,onClick:Fe=>{z(Fe),G("")}},fe))]}),p.length>0&&t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(Ea,{label:"All projects",value:"",current:I,onClick:Q}),p.map(fe=>t.jsx(Ea,{label:fe.name,value:fe.id,current:I,onClick:Q},fe.id))]}),t.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[t.jsx(Ea,{label:"Active",value:"",current:B,onClick:T}),t.jsx(Ea,{label:"Verified",value:"verified",current:B,onClick:T}),t.jsx(Ea,{label:"Outdated",value:"outdated",current:B,onClick:T})]}),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(fe=>t.jsx("button",{onClick:()=>{Y(fe),se(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${_===fe?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:fe.charAt(0).toUpperCase()+fe.slice(1)},fe)),Le.length>1&&t.jsx("button",{onClick:At,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:te.size===Le.length?"Expand all":"Collapse all",children:te.size===Le.length?"▶ Expand":"▼ Collapse"})]})]}),U&&t.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${U.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:U.text}),t.jsxs("div",{ref:xe,className:"flex-1 overflow-y-auto p-2 space-y-1",children:[E?t.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(fe=>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"})]},fe))}):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:un,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"+ Create first"})]}):Le.map(([fe,Fe])=>{const kt=te.has(fe);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>Qt(fe),className:"w-full flex items-center gap-1.5 px-2 py-1.5 rounded-md hover:bg-surface-elevated/50 transition-colors group/header",children:[t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform duration-200 shrink-0 ${kt?"":"rotate-90"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),t.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider truncate",children:Fe.label}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Fe.items.length,")"]})]}),!kt&&Fe.items.map(St=>t.jsxs("button",{onClick:()=>En(St),className:`w-full text-left p-3 rounded-lg transition-colors ${V?.id===St.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:St.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[St.artifactType&&gs[St.artifactType]?t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${gs[St.artifactType].color}`,children:[gs[St.artifactType].icon," ",gs[St.artifactType].label]}):t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium uppercase ${lo[St.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:St.type}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${Yv[St.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:St.status}),St.agentId&&t.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:ut.get(St.agentId)?.name??"Agent"})]})]},St.id))]},fe)}),x&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[t.jsx(nm,{})," ",t.jsx("span",{className:"text-[10px]",children:"Loading more..."})]}),!E&&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:r.onResizeStart}),(!e||s)&&t.jsxs("div",{className:"flex-1 overflow-y-auto min-w-0",children:[e&&t.jsxs("div",{className:"sticky top-0 z-10 bg-surface-secondary border-b border-border-default px-4 py-2.5 flex items-center gap-2",children:[t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsx("span",{className:"text-sm font-medium truncate",children: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:()=>Qe(V),disabled:!!X,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:X==="verify"?"Verifying...":"Verify"}),V.status!=="outdated"&&t.jsx("button",{onClick:()=>ft(V),disabled:!!X,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:X==="flag"?"Flagging...":"Flag Outdated"}),t.jsx("button",{onClick:()=>Zt(V),disabled:!!X,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:X==="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 ${lo[V.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[lo[V.type]?.icon??""," ",V.type]}),t.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${Yv[V.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:V.status}),V.artifactType&&gs[V.artifactType]&&t.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${gs[V.artifactType].color}`,children:[gs[V.artifactType].icon," Builder ",gs[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:()=>{re.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:()=>{re.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:()=>Nt(V.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Lt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:"Copy path to clipboard",children:Lt?"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(Hz,{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:it,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(Zn,{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:Re?t.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[t.jsx(nm,{})," Loading preview..."]}):dn?t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("img",{src:dn.src,alt:dn.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),t.jsx("span",{className:"text-xs text-fg-tertiary",children:dn.name})]}):Ze?an(Ze):et?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:()=>{re.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:()=>{re.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:()=>Nt(V.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Lt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:Lt?"Copied!":"Copy"})]})]}):V.summary?an(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(fe=>t.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:fe},fe))}),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:()=>jt.navigate("projects",{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:()=>jt.navigate("team",{selectAgent:V.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Agent: ",ut.get(V.agentId)?.name??V.agentId.slice(0,12)]}),V.projectId&&t.jsxs("button",{onClick:()=>jt.navigate("projects",{projectId:V.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:["Project: ",Wt.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"})]})})]}),M&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!K&&q(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:fe=>fe.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:ke,onChange:fe=>De(fe.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:Gv.map(fe=>t.jsxs("option",{value:fe,children:[lo[fe]?.icon??""," ",fe]},fe))})]}),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:ge,onChange:fe=>ye(fe.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:tt,onChange:fe=>Xe(fe.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:Ce,onChange:fe=>ze(fe.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:ae,onChange:fe=>Te(fe.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:dt,onChange:fe=>wt(fe.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"}),p.map(fe=>t.jsx("option",{value:fe.id,children:fe.name},fe.id))]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1 border-t border-border-default",children:[t.jsx("button",{onClick:()=>q(!1),disabled:K,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:"Cancel"}),t.jsxs("button",{onClick:ot,disabled:K||!ge.trim()||!Ce.trim(),className:"bg-brand-600 hover:bg-brand-500 text-white text-sm px-4 py-2 rounded-lg disabled:opacity-50 flex items-center gap-2 transition-colors",children:[K&&t.jsx(nm,{}),K?"Creating...":"Create"]})]})]})})]})}function Pz(e,r){const s=e.cloneNode(!0),l=r==="light"?{bg:"#ffffff",text:"#24292f",heading:"#1f2328",strong:"#1f2328",link:"#0969da",codeBg:"#eff1f3",codeText:"#24292f",preBg:"#f6f8fa",preText:"#24292f",preBorder:"#d0d7de",border:"#d0d7de",blockquoteBorder:"#d0d7de",blockquoteText:"#656d76",tableBorder:"#d0d7de",tableHeaderBg:"#f6f8fa",tableHeaderText:"#24292f",hrColor:"#d8dee4"}:{bg:"#0d1117",text:"#e6edf3",heading:"#f0f6fc",strong:"#f0f6fc",link:"#58a6ff",codeBg:"#161b22",codeText:"#e6edf3",preBg:"#161b22",preText:"#e6edf3",preBorder:"#30363d",border:"#30363d",blockquoteBorder:"#3b82f6",blockquoteText:"#8b949e",tableBorder:"#30363d",tableHeaderBg:"#161b22",tableHeaderText:"#e6edf3",hrColor:"#21262d"},o={p:`margin:0 0 10px;color:${l.text};line-height:1.7;`,h1:`font-size:1.6em;font-weight:700;color:${l.heading};margin:20px 0 10px;line-height:1.3;border-bottom:1px solid ${l.border};padding-bottom:6px;`,h2:`font-size:1.35em;font-weight:700;color:${l.heading};margin:18px 0 8px;line-height:1.3;`,h3:`font-size:1.15em;font-weight:600;color:${l.heading};margin:14px 0 6px;line-height:1.3;`,h4:`font-size:1em;font-weight:600;color:${l.heading};margin:12px 0 4px;`,strong:`font-weight:600;color:${l.strong};`,em:"font-style:italic;",a:`color:${l.link};text-decoration:underline;`,ul:"padding-left:1.5em;margin:0 0 10px;",ol:"padding-left:1.5em;margin:0 0 10px;",li:`margin:3px 0;line-height:1.7;color:${l.text};`,blockquote:`border-left:3px solid ${l.blockquoteBorder};padding:2px 0 2px 14px;margin:10px 0;color:${l.blockquoteText};`,hr:`border:none;border-top:1px solid ${l.hrColor};margin:20px 0;`,table:"border-collapse:collapse;width:100%;margin:10px 0;",thead:`background:${l.tableHeaderBg};`,th:`border:1px solid ${l.tableBorder};padding:8px 12px;text-align:left;font-weight:600;color:${l.tableHeaderText};`,td:`border:1px solid ${l.tableBorder};padding:8px 12px;color:${l.text};`,img:"max-width:100%;height:auto;"};function d(c){c.removeAttribute("class");const h=c.tagName.toLowerCase();if(h==="pre"){c.setAttribute("style",`background:${l.preBg};color:${l.preText};padding:14px;border-radius:6px;overflow-x:auto;margin:10px 0;font-size:0.88em;line-height:1.5;border:1px solid ${l.preBorder};`);const m=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:${l.codeBg};color:${l.codeText};padding:2px 6px;border-radius:4px;font-size:0.9em;font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;`):o[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:${l.bg};color:${l.text};padding:20px 24px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Noto Sans',Helvetica,Arial,sans-serif;font-size:15px;line-height:1.7;max-width:800px;">${s.innerHTML}</div>`}function Ea({label:e,value:r,current:s,onClick:l}){return t.jsx("button",{onClick:()=>l(s===r?"":r),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${s===r?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function nm(){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 Ys(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Vl(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Uz(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 TN({authUser:e}){const[r,s]=v.useState("weekly"),[l,o]=v.useState(null),[d,c]=v.useState(!0),[h,m]=v.useState(""),[f,x]=v.useState(null),[g,p]=v.useState([]),[y,w]=v.useState("totalTokens"),[N,E]=v.useState(!0),[A,C]=v.useState("generate"),[k,S]=v.useState([]),[O,R]=v.useState(null),[G,I]=v.useState([]),[Q,$]=v.useState(""),[F,B]=v.useState(""),T=M=>{B(M),setTimeout(()=>B(""),3e3)},D=v.useCallback(async M=>{c(!0),m("");try{const{report:q}=await re.reports.generate({period:M,scope:"org",orgId:"default"});o(q)}catch(q){m(String(q)),o(null)}c(!1)},[]),z=v.useCallback(()=>{re.usage.summary().then(M=>x(M.usage)).catch(()=>{}),re.usage.agents().then(M=>p(M.agents)).catch(()=>{})},[]),_=v.useCallback(async()=>{try{const{reports:M}=await re.reports.list();S(M)}catch{}},[]),Y=v.useCallback(async M=>{R(M);try{const{feedback:q}=await re.reports.getFeedback(M.id);I(q)}catch{I([])}},[]);v.useEffect(()=>{D(r)},[r,D]),v.useEffect(()=>{z();const M=setInterval(z,3e4);return()=>clearInterval(M)},[z]),v.useEffect(()=>{A==="history"&&_()},[A,_]);const V=v.useMemo(()=>[...g].sort((M,q)=>{const K=M[y],ee=q[y];return N?ee-K:K-ee}),[g,y,N]),J=g.reduce((M,q)=>M+q.estimatedCost,0),U=g.reduce((M,q)=>M+q.tokensUsedToday,0),H=Math.max(1,...g.map(M=>M.totalTokens)),X=M=>{y===M?E(!N):(w(M),E(!0))},L={daily:"Today",weekly:"This Week",monthly:"This Month"};return t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsxs("div",{className:"max-w-5xl p-6 space-y-6",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-4",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:()=>C("generate"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${A==="generate"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:"Generate"}),t.jsxs("button",{onClick:()=>C("history"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${A==="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",children:[F&&t.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:F}),A==="generate"&&t.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(M=>t.jsx("button",{onClick:()=>s(M),className:`px-3 py-1.5 text-xs rounded-md transition-colors capitalize ${r===M?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:M},M))})]})]}),A==="history"&&!O&&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(M=>t.jsxs("button",{onClick:()=>Y(M),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:[M.type," Report"]}),t.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(M.periodStart).toLocaleDateString()," — ",new Date(M.periodEnd).toLocaleDateString()]})]}),M.plan&&t.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${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==="pending"?"Plan pending":`Plan ${M.plan.status}`}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(M.generatedAt).toLocaleDateString()})]},M.id))})}),A==="history"&&O&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:()=>{R(null),I([])},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:[O.type," Report"]}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(O.periodStart).toLocaleDateString()," — ",new Date(O.periodEnd).toLocaleDateString()]})]}),O.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(ps,{label:"Completed",value:O.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(ps,{label:"In Progress",value:O.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(ps,{label:"Created",value:O.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(ps,{label:"Blocked",value:O.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(ps,{label:"Failed",value:O.metrics.tasksFailed,color:"text-red-500"})]})]}),O.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:O.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:Vl(O.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 ${O.costSummary.trend==="decreasing"?"text-green-600":O.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[O.costSummary.trend==="decreasing"?"↓":O.costSummary.trend==="increasing"?"↑":"→"," ",O.costSummary.trend]}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Trend"})]})]}),O.costSummary.byAgent&&O.costSummary.byAgent.length>0&&t.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:O.costSummary.byAgent.map((M,q)=>t.jsxs("div",{className:"flex items-center justify-between text-xs",children:[t.jsx("span",{className:"text-fg-secondary",children:M.agentId}),t.jsxs("span",{className:"text-fg-tertiary tabular-nums",children:[Ys(M.tokens)," tokens · ",Vl(M.cost)]})]},q))})]}),O.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:[O.taskSummary.completed.length>0&&t.jsx(ql,{title:`Completed (${O.taskSummary.completed.length})`,color:"emerald",items:O.taskSummary.completed.map(M=>({id:M.id,label:M.title,sub:M.agent}))}),O.taskSummary.inProgress.length>0&&t.jsx(ql,{title:`In Progress (${O.taskSummary.inProgress.length})`,color:"indigo",items:O.taskSummary.inProgress.map(M=>({id:M.id,label:M.title,sub:M.agent}))}),O.taskSummary.blocked.length>0&&t.jsx(ql,{title:`Blocked (${O.taskSummary.blocked.length})`,color:"amber",items:O.taskSummary.blocked.map(M=>({id:M.id,label:M.title,sub:M.reason||M.agent}))}),O.taskSummary.completed.length===0&&O.taskSummary.inProgress.length===0&&O.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]}),O.highlights&&O.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:O.highlights.map((M,q)=>t.jsx("li",{children:M},q))})]}),O.blockers&&O.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:O.blockers.map((M,q)=>t.jsx("li",{children:M},q))})]}),O.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 ${O.plan.status==="approved"?"bg-green-500/10 text-green-600":O.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:O.plan.status})]}),O.plan.status==="pending"&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{onClick:async()=>{try{const{report:M}=await re.reports.approvePlan(O.id,{approvedBy:e?.id??"admin"});R(M),T("Plan approved"),_()}catch(M){T(`Error: ${M}`)}},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 M=prompt("Rejection reason:");if(M)try{const{report:q}=await re.reports.rejectPlan(O.id,{rejectedBy:e?.id??"admin",reason:M});R(q),T("Plan rejected"),_()}catch(q){T(`Error: ${q}`)}},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"})]})]}),O.plan.items&&O.plan.items.length>0&&t.jsx("div",{className:"space-y-1.5",children:O.plan.items.map((M,q)=>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 ${M.priority==="high"?"bg-red-500/10 text-red-500":M.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:M.priority}),t.jsx("span",{children:M.title}),M.assignee&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:M.assignee})]},q))})]}),!O.metrics&&!O.taskSummary&&!O.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 (",G.length,")"]}),G.length>0&&t.jsx("div",{className:"space-y-2 mb-4",children:G.map(M=>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:M.authorName}),t.jsx("span",{children:M.type}),t.jsx("span",{children:new Date(M.createdAt).toLocaleDateString()})]}),t.jsx("p",{className:"text-xs text-fg-secondary",children:M.content})]},M.id))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:Q,onChange:M=>$(M.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:M=>{M.key==="Enter"&&Q.trim()&&re.reports.addFeedback(O.id,{author:e?.id??"admin",type:"comment",content:Q.trim()}).then(({feedback:q})=>{I(K=>[...K,q]),$(""),T("Feedback added")}).catch(q=>T(`Error: ${q}`))}}),t.jsx("button",{onClick:()=>{Q.trim()&&re.reports.addFeedback(O.id,{author:e?.id??"admin",type:"comment",content:Q.trim()}).then(({feedback:M})=>{I(q=>[...q,M]),$(""),T("Feedback added")}).catch(M=>T(`Error: ${M}`))},disabled:!Q.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"})]})]})]}),A==="generate"&&f&&t.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t.jsx(fd,{label:"LLM Tokens (this month)",value:Ys(f.llmTokens),color:"text-brand-500"}),t.jsx(fd,{label:"Tool Calls (today)",value:Ys(f.toolCalls),color:"text-blue-600"}),t.jsx(fd,{label:"Messages (today)",value:Ys(f.messages),color:"text-green-600"}),t.jsx(fd,{label:"Storage",value:Uz(f.storageBytes),color:"text-amber-600"})]}),A==="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}):l?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"text-xs text-fg-tertiary",children:[L[r]," · ",new Date(l.periodStart).toLocaleDateString()," — ",new Date(l.periodEnd).toLocaleDateString()]}),l.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(ps,{label:"Completed",value:l.metrics.tasksCompleted,color:"text-green-600"}),t.jsx(ps,{label:"In Progress",value:l.metrics.tasksInProgress,color:"text-brand-500"}),t.jsx(ps,{label:"Created",value:l.metrics.tasksCreated,color:"text-blue-600"}),t.jsx(ps,{label:"Blocked",value:l.metrics.tasksBlocked,color:"text-amber-600"}),t.jsx(ps,{label:"Failed",value:l.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:Vl(J)}),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:Ys(U)}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:"Tokens Today"})]}),l.costSummary&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:l.costSummary.totalTokens.toLocaleString()}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Tokens (",L[r],")"]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:Vl(l.costSummary.totalEstimatedCost)}),t.jsxs("div",{className:"text-xs text-fg-tertiary",children:["Cost (",L[r],")"]})]})]})]})]}),l.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:[l.taskSummary.completed.length>0&&t.jsx(ql,{title:`Completed (${l.taskSummary.completed.length})`,color:"emerald",items:l.taskSummary.completed.map(M=>({id:M.id,label:M.title,sub:M.agent}))}),l.taskSummary.inProgress.length>0&&t.jsx(ql,{title:`In Progress (${l.taskSummary.inProgress.length})`,color:"indigo",items:l.taskSummary.inProgress.map(M=>({id:M.id,label:M.title,sub:M.agent}))}),l.taskSummary.blocked.length>0&&t.jsx(ql,{title:`Blocked (${l.taskSummary.blocked.length})`,color:"amber",items:l.taskSummary.blocked.map(M=>({id:M.id,label:M.title,sub:M.reason||M.agent}))}),l.taskSummary.completed.length===0&&l.taskSummary.inProgress.length===0&&l.taskSummary.blocked.length===0&&t.jsx("p",{className:"text-sm text-fg-tertiary",children:"No tasks in this period."})]})]})]}):null),A==="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"})}),g.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(io,{label:"Total Tokens",col:"totalTokens",current:y,desc:N,onSort:X}),t.jsx(io,{label:"Today",col:"tokensUsedToday",current:y,desc:N,onSort:X}),t.jsx(io,{label:"Requests",col:"requestCount",current:y,desc:N,onSort:X}),t.jsx(io,{label:"Tool Calls",col:"toolCalls",current:y,desc:N,onSort:X}),t.jsx(io,{label:"Est. Cost",col:"estimatedCost",current:y,desc:N,onSort:X,align:"right"})]})}),t.jsx("tbody",{children:V.map(M=>t.jsx(qz,{agent:M,maxTokens:H},M.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 (",g.length," agents)"]}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Ys(g.reduce((M,q)=>M+q.totalTokens,0))}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Ys(U)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:g.reduce((M,q)=>M+q.requestCount,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:g.reduce((M,q)=>M+q.toolCalls,0)}),t.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:Vl(J)})]})})]})})]})]})})}function ps({label:e,value:r,color:s}){return t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:`text-2xl font-bold ${s}`,children:r}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function ql({title:e,color:r,items:s}){return t.jsxs("div",{children:[t.jsx("div",{className:`text-xs font-medium text-${r}-400 mb-1.5`,children:e}),t.jsx("div",{className:"space-y-1",children:s.map((l,o)=>t.jsxs("div",{className:`text-sm text-fg-secondary flex items-center gap-2 ${l.id?"cursor-pointer hover:text-fg-primary group":""}`,onClick:l.id?()=>jt.navigate("projects",{openTask:l.id}):void 0,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${r}-500 shrink-0`}),t.jsx("span",{className:`truncate ${l.id?"group-hover:text-brand-500 transition-colors":""}`,children:l.label}),l.sub&&l.sub!=="unassigned"&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:l.sub})]},l.id??o))})]})}function fd({label:e,value:r,color:s}){return t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[t.jsx("div",{className:"text-sm text-fg-secondary mb-2",children:e}),t.jsx("div",{className:`text-2xl font-bold ${s}`,children:r})]})}function io({label:e,col:r,current:s,desc:l,onSort:o,align:d}){const c=s===r?l?"↓":"↑":"↕",h=s===r?"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(r),children:[e,t.jsx("span",{className:`ml-1 ${h}`,children:c})]})}function qz({agent:e,maxTokens:r}){const s=r>0?Math.min(100,e.totalTokens/r*100):0,l=e.status==="working"?"bg-blue-500":e.status==="idle"?"bg-green-500":e.status==="paused"?"bg-amber-500":e.status==="error"?"bg-red-500":"bg-gray-600";return t.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>jt.navigate("team",{selectAgent:e.agentId}),children:[t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:`w-2 h-2 rounded-full ${l}`}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),t.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:t.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${s}%`}})}),t.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:Ys(e.totalTokens)})]})}),t.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:Ys(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:Vl(e.estimatedCost)})]})}const Zv={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},rm={approval_request:"M9 12l2 2 4-4 M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z",task_completed:"M22 11.08V12a10 10 0 1 1-5.93-9.14 M22 4L12 14.01l-3-3",agent_alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z M12 9v4 M12 17h.01",bounty_posted:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z M19 10v2a7 7 0 0 1-14 0v-2",system:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"};function Qv(e){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return"now";if(s<60)return`${s}m`;const l=Math.floor(s/60);return l<24?`${l}h`:`${Math.floor(l/24)}d`}function Kv({collapsed:e,userId:r}){const[s,l]=v.useState(!1),[o,d]=v.useState("approvals"),[c,h]=v.useState([]),[m,f]=v.useState([]),[x,g]=v.useState(null),p=v.useRef(null),y=v.useRef(null),[w,N]=v.useState({top:0,left:0}),E=v.useCallback(async()=>{try{const[B,T]=await Promise.all([re.notifications.list(r,!1),re.approvals.list()]);h(B.notifications),f(T.approvals)}catch{}},[r]);v.useEffect(()=>{E();const B=setInterval(E,15e3),T=()=>E();return window.addEventListener("markus:notifications-changed",T),()=>{clearInterval(B),window.removeEventListener("markus:notifications-changed",T)}},[E]),v.useLayoutEffect(()=>{if(!s||!p.current)return;const B=p.current.getBoundingClientRect();N({top:B.top,left:B.right+8})},[s]),v.useEffect(()=>{if(!s)return;const B=T=>{p.current?.contains(T.target)||y.current?.contains(T.target)||l(!1)};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[s]);const A=new Set(m.map(B=>B.id)),C=c.filter(B=>!(B.type==="approval_request"&&B.metadata?.approvalId&&A.has(B.metadata.approvalId))),k=C.filter(B=>!B.read).length,S=m.filter(B=>B.status==="pending").length,O=k+S,R=async B=>{await re.notifications.markRead(B),h(T=>T.map(D=>D.id===B?{...D,read:!0}:D))},G=B=>{const T=B.metadata??{};switch(B.type){case"approval_request":{const D=T.approvalId,_=(D?m.find(Y=>Y.id===D):void 0)?.details?.taskId??T.taskId;_?jt.navigate("projects",{openTask:_}):jt.navigate("projects");break}case"task_completed":T.taskId?jt.navigate("projects",{openTask:T.taskId}):jt.navigate("projects");break;case"agent_alert":T.agentId?jt.navigate("team",{selectAgent:T.agentId}):jt.navigate("team");break;case"bounty_posted":jt.navigate("governance");break;default:T.taskId?jt.navigate("projects",{openTask:T.taskId}):T.projectId?jt.navigate("projects",{projectId:T.projectId}):T.agentId&&jt.navigate("team",{selectAgent:T.agentId});break}},I=async B=>{B.read||R(B.id),G(B),l(!1)},Q=async(B,T)=>{g(B);try{const{approval:D}=await re.approvals.respond(B,T,r);f(_=>_.map(Y=>Y.id===B?D:Y));const z=c.find(_=>_.type==="approval_request"&&_.metadata?.approvalId===B);z&&!z.read&&(re.notifications.markRead(z.id),h(_=>_.map(Y=>Y.id===z.id?{...Y,read:!0}:Y))),window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}catch{}g(null)},$=async()=>{const B=C.filter(T=>!T.read);await Promise.all(B.map(T=>re.notifications.markRead(T.id))),h(T=>T.map(D=>({...D,read:!0})))},F=B=>{const T=B.details?.taskId;T?jt.navigate("projects",{openTask:T}):jt.navigate("projects"),l(!1)};return t.jsxs(t.Fragment,{children:[t.jsxs("button",{ref:p,onClick:()=>{l(!s),s||E()},className:`relative flex items-center justify-center rounded-md transition-colors ${e?"w-8 h-8":"w-7 h-7"} ${s?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"}`,title:"Notifications",children:[t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),t.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),O>0&&t.jsx("span",{className:"absolute -top-0.5 -right-0.5 min-w-[16px] h-4 px-1 rounded-full bg-red-500 text-white text-[10px] font-bold flex items-center justify-center leading-none",children:O>99?"99+":O})]}),s&&ix.createPortal(t.jsxs("div",{ref:y,className:"fixed w-80 max-h-[28rem] bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:w.top,left:w.left},children:[t.jsxs("div",{className:"flex border-b border-border-default shrink-0",children:[t.jsxs("button",{onClick:()=>d("approvals"),className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${o==="approvals"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Approvals",S>0?` (${S})`:""]}),t.jsxs("button",{onClick:()=>d("notifications"),className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${o==="notifications"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:["Notifications",k>0?` (${k})`:""]})]}),o==="notifications"&&k>0&&t.jsx("div",{className:"flex justify-end px-3 py-1.5 border-b border-border-default/50 shrink-0",children:t.jsx("button",{onClick:$,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:"Mark all read"})}),t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o==="approvals"&&(m.length===0?t.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:"No approval requests"}):t.jsxs("div",{className:"divide-y divide-border-default/50",children:[m.filter(B=>B.status==="pending").map(B=>t.jsxs("div",{className:"px-3 py-3 space-y-2",children:[t.jsxs("button",{onClick:()=>F(B),className:"w-full text-left flex items-start gap-2 hover:bg-surface-overlay rounded transition-colors",children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 mt-0.5 shrink-0",children:t.jsx("path",{d:rm.approval_request})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary font-medium",children:B.title}),t.jsxs("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:[B.agentName," · ",Qv(B.requestedAt)]}),t.jsx("p",{className:"text-[11px] text-fg-secondary mt-1 line-clamp-3",children:B.description})]})]}),t.jsxs("div",{className:"flex gap-2 pl-5",children:[t.jsx("button",{disabled:x===B.id,onClick:()=>Q(B.id,!0),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors",children:"Approve"}),t.jsx("button",{disabled:x===B.id,onClick:()=>Q(B.id,!1),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay disabled:opacity-50 transition-colors",children:"Reject"})]})]},B.id)),m.filter(B=>B.status!=="pending").slice(0,20).map(B=>t.jsx("button",{onClick:()=>F(B),className:"w-full text-left px-3 py-2.5 opacity-50 hover:opacity-70 transition-colors",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${B.status==="approved"?"bg-green-500":"bg-red-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:B.title}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:B.status})]})},B.id))]})),o==="notifications"&&(C.length===0?t.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:"No notifications"}):t.jsx("div",{className:"divide-y divide-border-default/50",children:C.slice(0,50).map(B=>t.jsxs("button",{onClick:()=>I(B),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${B.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[t.jsx("div",{className:"shrink-0 mt-0.5",children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:t.jsx("path",{d:rm[B.type]??rm.system})})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[!B.read&&t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Zv[B.priority]??Zv.normal}`}),t.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:B.title})]}),t.jsx("p",{className:"text-[11px] text-fg-tertiary line-clamp-2 mt-0.5",children:B.body}),t.jsx("span",{className:"text-[10px] text-fg-muted mt-0.5",children:Qv(B.createdAt)})]}),t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-muted shrink-0 mt-1 opacity-0 group-hover:opacity-100",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})]},B.id))}))]})]}),document.body)]})}function oo({d:e,size:r=18}){return t.jsx("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:e})})}const co={dashboard:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M9 22V12h6v10",projects:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z",chat:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",reports:"M18 20V10 M12 20V4 M6 20v-6",deliverables:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20 M4 19.5A2.5 2.5 0 0 0 6.5 22H20V2H6.5A2.5 2.5 0 0 0 4 4.5v15z",usage:"M21.21 15.89A10 10 0 1 1 8 2.83 M22 12A10 10 0 0 0 12 2v10z",builder:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",agents:"M8 3H5a2 2 0 0 0-2 2v3 M21 8V5a2 2 0 0 0-2-2h-3 M3 16v3a2 2 0 0 0 2 2h3 M16 21h3a2 2 0 0 0 2-2v-3 M9 9h6v6H9z",teams:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2 M9 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8z M23 21v-2a4 4 0 0 0-3-3.87 M16 3.13a4 4 0 0 1 0 7.75",skills:"M12 2L2 7l10 5 10-5-10-5z M2 17l10 5 10-5 M2 12l10 5 10-5",governance:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"},Fz={active:"bg-green-500",paused:"bg-amber-500",completed:"bg-gray-500",archived:"bg-gray-600"},Vz=[{id:"dashboard",label:"Overview",section:"workspace"},{id:"chat",label:"Chat",section:"workspace"},{id:"deliverables",label:"Deliverables",section:"workspace"},{id:"builder",label:"Builder",section:"build"},{id:"agents",label:"Agents",section:"build"},{id:"teams",label:"Teams",section:"build"},{id:"skills",label:"Skills",section:"build"},{id:"governance",label:"Governance",section:"system"},{id:"reports",label:"Reports",section:"system"},{id:"settings",label:"Settings",section:"system"}],Yz=[{key:"workspace",label:"WORKSPACE"},{key:"build",label:"BUILD"},{key:"system",label:"SYSTEM"}],Jv=5;function Gz({currentPage:e,onNavigate:r,authUser:s,onLogout:l,collapsed:o,onToggleCollapse:d}){const[c,h]=v.useState([]),[m,f]=v.useState(!1),[x,g]=v.useState(null),[p,y]=v.useState(!1),w=v.useCallback(()=>{re.projects.list().then(C=>h(C.projects)).catch(()=>{})},[]);v.useEffect(()=>{w();const C=setInterval(w,3e4);return()=>clearInterval(C)},[w]),v.useEffect(()=>{if(e!=="projects"){g(null);return}const k=window.location.hash.slice(1).split("/");k[0]==="projects"&&k[1]&&g(k[1])},[e]);const N=async()=>{try{await re.auth.logout()}catch{}l?.()},E=m?c:c.slice(0,Jv),A=c.length>Jv;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(Kv,{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(Kv,{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:Yz.map((C,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:C.label}),o&&k>0&&t.jsx("div",{className:"my-2 mx-1"}),Vz.filter(S=>S.section===C.key&&!(C.key==="workspace"&&S.id==="deliverables")).map(S=>{const O=e===S.id;return t.jsxs("button",{onClick:()=>r(S.id),title:o?S.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 ${O?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":"text-fg-primary hover:bg-surface-overlay"}`,children:[t.jsx(oo,{d:co[S.id]??""}),!o&&S.label]},S.id)}),C.key==="workspace"&&o&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{g(null),r("projects")},title:"Projects",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-all ${e==="projects"&&!x?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":e==="projects"?"bg-brand-600/15 text-fg-primary":"text-fg-primary hover:bg-surface-overlay"}`,children:t.jsx(oo,{d:co.projects})}),t.jsx("button",{onClick:()=>r("deliverables"),title:"Deliverables",className:`w-full flex items-center justify-center px-2 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e==="deliverables"?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:t.jsx(oo,{d:co.deliverables})})]}),C.key==="workspace"&&!o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center mb-0.5",children:[t.jsxs("button",{onClick:()=>{g(null),window.location.hash="projects",r("projects")},className:`flex-1 flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-colors ${e==="projects"&&!x?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(oo,{d:co.projects}),"Projects"]}),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"]}),E.map(S=>{const O=e==="projects"&&x===S.id;return t.jsxs("button",{onClick:()=>{g(S.id),e!=="projects"&&r("projects"),window.location.hash="projects/"+S.id},className:`w-full flex items-center gap-2.5 pl-9 pr-3 py-1.5 rounded-lg text-sm mb-0.5 transition-colors ${O?"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 ${Fz[S.status]??"bg-gray-600"}`}),t.jsx("span",{className:"truncate text-xs",children:S.name})]},S.id)}),A&&!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:()=>r("deliverables"),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-sm mb-0.5 transition-colors ${e==="deliverables"?"bg-brand-600 text-white":"text-fg-primary hover:bg-surface-elevated"}`,children:[t.jsx(oo,{d:co.deliverables}),"Deliverables"]})]})]})},C.key))}),t.jsxs("div",{className:`${o?"p-2 flex flex-col items-center gap-2":"px-4 py-3 space-y-2"}`,children:[s&&(o?t.jsx("button",{onClick: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.11"]})]}),p&&t.jsx(wN,{orgId:s?.orgId,onCreated:()=>{y(!1),w()},onClose:()=>y(!1)})]})}const Xz={dashboard:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M9 22V12h6v10",chat:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",projects:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z",deliverables:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20 M4 19.5A2.5 2.5 0 0 0 6.5 22H20V2H6.5A2.5 2.5 0 0 0 4 4.5v15z",builder:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"},Zz=[{id:"dashboard",label:"Home",iconKey:"dashboard",group:["dashboard"]},{id:"chat",label:"Chat",iconKey:"chat",group:["chat"]},{id:"projects",label:"Projects",iconKey:"projects",group:["projects"]},{id:"deliverables",label:"Deliverables",iconKey:"deliverables",group:["deliverables"]},{id:"builder",label:"Builder",iconKey:"builder",group:["builder","agents","teams","skills"]},{id:"settings",label:"Settings",iconKey:"settings",group:["settings","governance","reports"]}];function Qz({currentPage:e,onNavigate:r}){return t.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-surface-secondary border-t border-border-default flex items-stretch h-14 safe-area-bottom",children:Zz.map(s=>{const l=s.group.includes(e);return t.jsxs("button",{onClick:()=>r(s.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${l?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[t.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:l?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("path",{d:Xz[s.iconKey]})}),t.jsx("span",{className:`text-[10px] leading-tight ${l?"font-semibold":""}`,children:s.label})]},s.id)})})}const Kz=50,Jz=30;function AN(e,r,s){const l=v.useRef(0),o=v.useRef(0),d=v.useCallback(h=>{l.current=h.touches[0].clientX,o.current=h.touches[0].clientY},[]),c=v.useCallback(h=>{const m=h.changedTouches[0].clientX-l.current,f=h.changedTouches[0].clientY-o.current,x=Math.abs(m),g=Math.abs(f);if(x<Kz||Math.atan2(g,x)*(180/Math.PI)>Jz)return;const y=e.findIndex(w=>w.id===r);m<0&&y<e.length-1?s(e[y+1].id):m>0&&y>0&&s(e[y-1].id)},[e,r,s]);return{onTouchStart:d,onTouchEnd:c}}const Wv=[{id:"builder",label:"Builder"},{id:"agents",label:"Agents"},{id:"teams",label:"Teams"},{id:"skills",label:"Skills"}];function Wz({authUser:e}){const[r,s]=v.useState("builder"),l=AN(Wv,r,s);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:l.onTouchStart,onTouchEnd:l.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:Wv.map(o=>t.jsx("button",{onClick:()=>s(o.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${r===o.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:o.label},o.id))}),t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[r==="builder"&&t.jsx(Oj,{}),r==="agents"&&t.jsx(Aj,{authUser:e}),r==="teams"&&t.jsx(Dj,{}),r==="skills"&&t.jsx(Cj,{})]})]})}const e1=[{id:"settings",label:"Settings"},{id:"governance",label:"Governance"},{id:"reports",label:"Reports"}];function eI({theme:e,onThemeChange:r}){const[s,l]=v.useState("settings"),o=AN(e1,s,l);return t.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:o.onTouchStart,onTouchEnd:o.onTouchEnd,children:[t.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:e1.map(d=>t.jsx("button",{onClick:()=>l(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(kj,{theme:e,onThemeChange:r}),s==="governance"&&t.jsx(Rj,{}),s==="reports"&&t.jsx(TN,{})]})]})}const t1=2;function tI({onComplete:e,theme:r,onThemeChange:s}){const[l,o]=v.useState(0),[d,c]=v.useState(null),[h,m]=v.useState(!1),[f,x]=v.useState({}),[g,p]=v.useState(!1),[y,w]=v.useState(null),[N,E]=v.useState(!1),[A,C]=v.useState(!1),[k,S]=v.useState(null),O=v.useRef(!1),R=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});v.useEffect(()=>{fetch("/api/settings/llm").then(z=>z.ok?z.json():null).then(z=>{z?.providers&&Object.values(z.providers).some(_=>_.configured)&&C(!0)}).catch(()=>{})},[]),v.useEffect(()=>{l===t1&&!O.current&&!A&&(O.current=!0,G())},[l,A]);const G=async()=>{m(!0);try{const z=await fetch("/api/settings/env-models",{headers:R()});if(z.ok){const _=await z.json();if(c(_),_.detected.length>0){const Y={};for(const V of _.detected)Y[V.provider]=!0;x(Y)}}}catch{}finally{m(!1)}},I=async()=>{if(!d)return;const z=d.detected.filter(_=>f[_.provider]);if(z.length!==0){p(!0),S(null);try{const _=await fetch("/api/settings/env-models",{method:"POST",headers:R(),body:JSON.stringify({providers:z.map(Y=>({provider:Y.provider,model:Y.model,baseUrl:Y.baseUrl,enabled:!0}))})});if(_.ok){const Y=await _.json();S({type:"ok",text:Y.message}),C(!0)}else S({type:"err",text:"Failed to apply"})}catch{S({type:"err",text:"Network error"})}finally{p(!1)}}},Q=async()=>{E(!0);try{const _=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:R(),body:JSON.stringify({preview:!0})})).json();"error"in _||w(_)}catch{}finally{E(!1)}},$=async()=>{E(!0),S(null);try{const _=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:R(),body:JSON.stringify({preview:!1})})).json();"error"in _?S({type:"err",text:_.error}):(S({type:"ok",text:`Imported ${_.appliedModels} model configs`}),C(!0))}catch{S({type:"err",text:"Import failed"})}finally{E(!1)}},F=[{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"}],B=[{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(([z,_])=>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:z}),t.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:_})]},z))})]})},{title:"Choose Your Theme",subtitle:"You can change this anytime in Settings",content:t.jsx("div",{className:"grid grid-cols-3 gap-3",children:F.map(z=>t.jsxs("button",{onClick:()=>s(z.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${r===z.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:z.icon}),t.jsx("span",{className:"text-sm font-medium text-fg-primary",children:z.label}),t.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:z.desc})]},z.value))})},{title:"Configure LLM",subtitle:"Agents need an LLM to think and act",content:A?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(z=>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[z.provider]??!1,onChange:_=>x({...f,[z.provider]:_.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-sm text-fg-primary",children:z.displayName}),t.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:z.model})]}),t.jsx("code",{className:"text-[10px] text-fg-tertiary",children:z.apiKeyPreview})]},z.provider)),t.jsx("button",{onClick:()=>{I()},disabled:g||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:g?"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:()=>{$()},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:()=>{Q()},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(([z,_])=>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:z}),t.jsx("div",{className:"text-fg-secondary text-xs",children:_})]})]},z))})}],T=()=>{l<B.length-1?o(l+1):e()},D=B[l];return t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:t.jsx("div",{className:"w-full max-w-lg",children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl p-8",children:[t.jsx("div",{className:"flex gap-1.5 mb-8",children:B.map((z,_)=>t.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${_<=l?"bg-brand-500":"bg-surface-elevated"}`},_))}),t.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:D.title}),t.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:D.subtitle}),D.content,t.jsxs("div",{className:"flex justify-between mt-8",children:[l>0?t.jsx("button",{onClick:()=>o(l-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:"Back"}):t.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip"}),t.jsxs("div",{className:"flex items-center gap-3",children:[l===t1&&!A&&t.jsx("button",{onClick:T,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:"Skip for now"}),t.jsx("button",{onClick:T,className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-xl transition-colors",children:l===B.length-1?"Get Started":"Next"})]})]})]})})})}const nI="markus123";function rI({onLogin:e}){const[r,s]=v.useState("admin@markus.local"),[l,o]=v.useState(""),[d,c]=v.useState(""),[h,m]=v.useState(!1),f=async x=>{if(x.preventDefault(),!(!r.trim()||!l)){c(""),m(!0);try{const{user:g}=await re.auth.login(r.trim(),l);e(g,l===nI)}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:r,onChange:x=>s(x.target.value),autoComplete:"email",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Password"}),t.jsx("input",{type:"password",value:l,onChange:x=>o(x.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),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||!r||!l,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all shadow-md shadow-brand-900/40 hover:shadow-lg hover:shadow-brand-900/50",children:h?"Signing in…":"Sign in"}),t.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:"Default: admin@markus.local / markus123"})]})]})]})}function sI({onComplete:e,isFirstTime:r}){const[s,l]=v.useState(""),[o,d]=v.useState(""),[c,h]=v.useState(""),[m,f]=v.useState(""),[x,g]=v.useState(!1),p=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}g(!0);try{await re.auth.changePassword(s,o),e()}catch{f("Failed to change password. Check your current password.")}finally{g(!1)}};return t.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[t.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),t.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),t.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),t.jsx("div",{className:"text-sm text-fg-tertiary",children:"AI Digital Employee Platform"})]}),t.jsxs("form",{onSubmit:p,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:r?"Set Your Password":"Change Password"}),r&&t.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:"You're using the default password. Please set a new one before continuing."})]}),!r&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:"Current Password"}),t.jsx("input",{type:"password",value:s,onChange:y=>l(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…":r?"Set Password & Continue":"Change Password"})]})]})]})}const _N="markus-theme";function n1(e){const r=document.documentElement;r.classList.remove("light","dark"),e==="light"?r.classList.add("light"):e==="dark"&&r.classList.add("dark")}function aI(){try{const e=localStorage.getItem(_N);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function lI(){const[e,r]=v.useState(aI),s=v.useCallback(l=>{r(l);try{localStorage.setItem(_N,l)}catch{}n1(l)},[]);return v.useEffect(()=>{n1(e)},[e]),{mode:e,setMode:s}}const iI=["dashboard","tasks","chat","team","usage","skills","agents","teams","builder","prompts","settings","governance","projects","deliverables","reports"];function hd(){const e=window.location.hash.slice(1).split("/")[0];return e==="team"?"chat":e==="tasks"?"projects":e==="usage"?"reports":e==="prompts"?"builder":e==="templates"?"agents":e==="knowledge"?"deliverables":iI.includes(e)?e:"dashboard"}const sm={};function oI(){const[e,r]=v.useState(hd),[s,l]=v.useState(()=>!localStorage.getItem("markus_onboarded")),[o,d]=v.useState(!0),c=ks(),h=lI(),m=Wd({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[f,x]=v.useState(()=>new Set([hd()])),[g,p]=v.useState("loading"),[y,w]=v.useState(!1),[N,E]=v.useState(null),[A,C]=v.useState(!1),k=v.useCallback(G=>{let I=G==="tasks"?"projects":G==="team"?"chat":G==="usage"?"reports":G==="prompts"?"builder":G==="templates"?"agents":G;c&&((I==="agents"||I==="teams"||I==="skills")&&(I="builder"),(I==="governance"||I==="reports")&&(I="settings"));const Q=hd(),$=window.location.hash.slice(1);$!==Q?sm[Q]=$:delete sm[Q];const F=sm[I];F&&F!==I?(history.pushState(null,"","#"+I),history.pushState(null,"","#"+F)):history.pushState(null,"","#"+I),window.dispatchEvent(new HashChangeEvent("hashchange")),r(I),x(B=>B.has(I)?B:new Set([...B,I]))},[c]);v.useEffect(()=>{jt.setHandler(G=>k(G))},[k]);const S=v.useCallback(()=>{fetch("/api/settings/llm").then(G=>G.ok?G.json():null).then(G=>{if(G?.providers){const I=Object.values(G.providers).some(Q=>Q.configured);E(I)}}).catch(()=>{})},[]);v.useEffect(()=>{re.auth.me().then(({user:I})=>{p(I),S(),Qa(wr.builderArtifacts,()=>re.builder.artifacts.list()),Qa(wr.builderAgents,()=>re.agents.list()),Qa(wr.builderHubMyItems,()=>Un.myItems()),Qa(wr.builderInstalled,()=>re.builder.artifacts.installed()),Qa(wr.hubAgents,()=>Un.search({type:"agent",limit:50})),Qa(wr.hubTeams,()=>Un.search({type:"team",limit:50})),Qa(wr.hubSkills,()=>Un.search({type:"skill",limit:50}))}).catch(()=>p(null)),kn.connect();const G=()=>{const I=hd();r(I),x(Q=>Q.has(I)?Q:new Set([...Q,I]))};return window.addEventListener("hashchange",G),()=>{kn.disconnect(),window.removeEventListener("hashchange",G)}},[]);const O=g!=="loading"&&g!==null?g:void 0,R=v.useMemo(()=>c?{dashboard:t.jsx(xb,{}),chat:t.jsx(wy,{authUser:O}),builder:t.jsx(Wz,{authUser:O}),settings:t.jsx(eI,{theme:h.mode,onThemeChange:h.setMode}),projects:t.jsx(Vv,{authUser:O}),deliverables:t.jsx(Xv,{})}:{dashboard:t.jsx(xb,{}),chat:t.jsx(wy,{authUser:O}),settings:t.jsx(kj,{theme:h.mode,onThemeChange:h.setMode}),skills:t.jsx(Cj,{}),agents:t.jsx(Aj,{authUser:O}),teams:t.jsx(Dj,{}),builder:t.jsx(Oj,{}),governance:t.jsx(Rj,{}),projects:t.jsx(Vv,{authUser:O}),deliverables:t.jsx(Xv,{}),reports:t.jsx(TN,{authUser:O})},[O?.id,h.mode,c]);return g==="loading"?t.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:t.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:"Loading…"})}):g===null?t.jsx(rI,{onLogin:(G,I)=>{p(G),I&&w(!0)}}):y?t.jsx(sI,{onComplete:()=>w(!1),isFirstTime:!0}):s?t.jsx(tI,{theme:h.mode,onThemeChange:h.setMode,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),l(!1),S()}}):t.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary ${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(Gz,{currentPage:e,onNavigate:G=>{k(G),d(!1)},authUser:g,onLogout:()=>p(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&&!A&&e!=="settings"&&t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-amber-500/10 border-b border-amber-500/30 text-amber-600 text-sm shrink-0",children:[t.jsx("span",{className: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("settings")},className:"px-3 py-1 bg-amber-700/50 hover:bg-amber-700/70 text-white text-xs rounded-lg transition-colors",children:"Go to Settings"}),t.jsx("button",{onClick:()=>C(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:"Dismiss"})]})]}),t.jsx("main",{className:"flex-1 overflow-hidden flex flex-col",children:Object.keys(R).map(G=>f.has(G)?t.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:G===e?"flex":"none"},children:R[G]},G):null)})]}),c&&t.jsx(Qz,{currentPage:e,onNavigate:k})]})}U2.createRoot(document.getElementById("root")).render(t.jsx(v.StrictMode,{children:t.jsx(oI,{})}));