@markus-global/cli 0.5.10 → 0.6.0

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.
@@ -348,4 +348,4 @@ l0,-`+(n+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
348
348
  `)),h=f.reduce((p,x)=>p.concat(...x),[]);return[f,h]}return[[],[]]},[e]);return v.useEffect(()=>{const u=t?.target??L3,f=t?.actInsideInputWithModifier??!0;if(e!==null){const h=b=>{if(a.current=b.ctrlKey||b.metaKey||b.shiftKey||b.altKey,(!a.current||a.current&&!f)&&oS(b))return!1;const k=_3(b.code,d);if(o.current.add(b[k]),O3(c,o.current,!1)){const j=b.composedPath?.()?.[0]||b.target,S=j?.nodeName==="BUTTON"||j?.nodeName==="A";t.preventDefault!==!1&&(a.current||!S)&&b.preventDefault(),s(!0)}},p=b=>{const y=_3(b.code,d);O3(c,o.current,!0)?(s(!1),o.current.clear()):o.current.delete(b[y]),b.key==="Meta"&&o.current.clear(),a.current=!1},x=()=>{o.current.clear(),s(!1)};return u?.addEventListener("keydown",h),u?.addEventListener("keyup",p),window.addEventListener("blur",x),window.addEventListener("contextmenu",x),()=>{u?.removeEventListener("keydown",h),u?.removeEventListener("keyup",p),window.removeEventListener("blur",x),window.removeEventListener("contextmenu",x)}}},[e,s]),n}function O3(e,t,n){return e.filter(s=>n||s.length===t.size).some(s=>s.every(a=>t.has(a)))}function _3(e,t){return t.includes(e)?"code":"key"}const ZX=()=>{const e=kr();return v.useMemo(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,{duration:t?.duration}):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,{duration:t?.duration}):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:s}=e.getState();return s?s.scaleTo(t,{duration:n?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[s,a,o],panZoom:c}=e.getState();return c?(await c.setViewport({x:t.x??s,y:t.y??a,zoom:t.zoom??o},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,s]=e.getState().transform;return{x:t,y:n,zoom:s}},setCenter:async(t,n,s)=>e.getState().setCenter(t,n,s),fitBounds:async(t,n)=>{const{width:s,height:a,minZoom:o,maxZoom:c,panZoom:d}=e.getState(),u=r1(t,s,a,o,c,n?.padding??.1);return d?(await d.setViewport(u,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:s,snapGrid:a,snapToGrid:o,domNode:c}=e.getState();if(!c)return t;const{x:d,y:u}=c.getBoundingClientRect(),f={x:t.x-d,y:t.y-u},h=n.snapGrid??a,p=n.snapToGrid??o;return Mu(f,s,p,h)},flowToScreenPosition:t=>{const{transform:n,domNode:s}=e.getState();if(!s)return t;const{x:a,y:o}=s.getBoundingClientRect(),c=Zf(t,n);return{x:c.x+a,y:c.y+o}}}),[])};function ES(e,t){const n=[],s=new Map,a=[];for(const o of e)if(o.type==="add"){a.push(o);continue}else if(o.type==="remove"||o.type==="replace")s.set(o.id,[o]);else{const c=s.get(o.id);c?c.push(o):s.set(o.id,[o])}for(const o of t){const c=s.get(o.id);if(!c){n.push(o);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){n.push({...c[0].item});continue}const d={...o};for(const u of c)QX(u,d);n.push(d)}return a.length&&a.forEach(o=>{o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item})}),n}function QX(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function MS(e,t){return ES(e,t)}function DS(e,t){return ES(e,t)}function rl(e,t){return{id:e,type:"select",selected:t}}function fc(e,t=new Set,n=!1){const s=[];for(const[a,o]of e){const c=t.has(a);!(o.selected===void 0&&!c)&&o.selected!==c&&(n&&(o.selected=c),s.push(rl(o.id,c)))}return s}function I3({items:e=[],lookup:t}){const n=[],s=new Map(e.map(a=>[a.id,a]));for(const[a,o]of e.entries()){const c=t.get(o.id),d=c?.internals?.userNode??c;d!==void 0&&d!==o&&n.push({id:o.id,item:o,type:"replace"}),d===void 0&&n.push({item:o,type:"add",index:a})}for(const[a]of t)s.get(a)===void 0&&n.push({id:a,type:"remove"});return n}function P3(e){return{id:e.id,type:"remove"}}const z3=e=>NK(e),JX=e=>JN(e);function RS(e){return v.forwardRef(e)}const eZ=typeof window<"u"?v.useLayoutEffect:v.useEffect;function $3(e){const[t,n]=v.useState(BigInt(0)),[s]=v.useState(()=>tZ(()=>n(a=>a+BigInt(1))));return eZ(()=>{const a=s.get();a.length&&(e(a),s.reset())},[t]),s}function tZ(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const LS=v.createContext(null);function nZ({children:e}){const t=kr(),n=v.useCallback(d=>{const{nodes:u=[],setNodes:f,hasDefaultNodes:h,onNodesChange:p,nodeLookup:x,fitViewQueued:b,onNodesChangeMiddlewareMap:y}=t.getState();let k=u;for(const S of d)k=typeof S=="function"?S(k):S;let j=I3({items:k,lookup:x});for(const S of y.values())j=S(j);h&&f(k),j.length>0?p?.(j):b&&window.requestAnimationFrame(()=>{const{fitViewQueued:S,nodes:T,setNodes:N}=t.getState();S&&N(T)})},[]),s=$3(n),a=v.useCallback(d=>{const{edges:u=[],setEdges:f,hasDefaultEdges:h,onEdgesChange:p,edgeLookup:x}=t.getState();let b=u;for(const y of d)b=typeof y=="function"?y(b):y;h?f(b):p&&p(I3({items:b,lookup:x}))},[]),o=$3(a),c=v.useMemo(()=>({nodeQueue:s,edgeQueue:o}),[]);return r.jsx(LS.Provider,{value:c,children:e})}function rZ(){const e=v.useContext(LS);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const sZ=e=>!!e.panZoom;function d1(){const e=ZX(),t=kr(),n=rZ(),s=Ln(sZ),a=v.useMemo(()=>{const o=p=>t.getState().nodeLookup.get(p),c=p=>{n.nodeQueue.push(p)},d=p=>{n.edgeQueue.push(p)},u=p=>{const{nodeLookup:x,nodeOrigin:b}=t.getState(),y=z3(p)?p:x.get(p.id),k=y.parentId?aS(y.position,y.measured,y.parentId,x,b):y.position,j={...y,position:k,width:y.measured?.width??y.width,height:y.measured?.height??y.height};return Tc(j)},f=(p,x,b={replace:!1})=>{c(y=>y.map(k=>{if(k.id===p){const j=typeof x=="function"?x(k):x;return b.replace&&z3(j)?j:{...k,...j}}return k}))},h=(p,x,b={replace:!1})=>{d(y=>y.map(k=>{if(k.id===p){const j=typeof x=="function"?x(k):x;return b.replace&&JX(j)?j:{...k,...j}}return k}))};return{getNodes:()=>t.getState().nodes.map(p=>({...p})),getNode:p=>o(p)?.internals.userNode,getInternalNode:o,getEdges:()=>{const{edges:p=[]}=t.getState();return p.map(x=>({...x}))},getEdge:p=>t.getState().edgeLookup.get(p),setNodes:c,setEdges:d,addNodes:p=>{const x=Array.isArray(p)?p:[p];n.nodeQueue.push(b=>[...b,...x])},addEdges:p=>{const x=Array.isArray(p)?p:[p];n.edgeQueue.push(b=>[...b,...x])},toObject:()=>{const{nodes:p=[],edges:x=[],transform:b}=t.getState(),[y,k,j]=b;return{nodes:p.map(S=>({...S})),edges:x.map(S=>({...S})),viewport:{x:y,y:k,zoom:j}}},deleteElements:async({nodes:p=[],edges:x=[]})=>{const{nodes:b,edges:y,onNodesDelete:k,onEdgesDelete:j,triggerNodeChanges:S,triggerEdgeChanges:T,onDelete:N,onBeforeDelete:E}=t.getState(),{nodes:B,edges:A}=await EK({nodesToRemove:p,edgesToRemove:x,nodes:b,edges:y,onBeforeDelete:E}),H=A.length>0,O=B.length>0;if(H){const z=A.map(P3);j?.(A),T(z)}if(O){const z=B.map(P3);k?.(B),S(z)}return(O||H)&&N?.({nodes:B,edges:A}),{deletedNodes:B,deletedEdges:A}},getIntersectingNodes:(p,x=!0,b)=>{const y=f3(p),k=y?p:u(p),j=b!==void 0;return k?(b||t.getState().nodes).filter(S=>{const T=t.getState().nodeLookup.get(S.id);if(T&&!y&&(S.id===p.id||!T.internals.positionAbsolute))return!1;const N=Tc(j?S:T),E=mu(N,k);return x&&E>0||E>=N.width*N.height||E>=k.width*k.height}):[]},isNodeIntersecting:(p,x,b=!0)=>{const k=f3(p)?p:u(p);if(!k)return!1;const j=mu(k,x);return b&&j>0||j>=x.width*x.height||j>=k.width*k.height},updateNode:f,updateNodeData:(p,x,b={replace:!1})=>{f(p,y=>{const k=typeof x=="function"?x(y):x;return b.replace?{...y,data:k}:{...y,data:{...y.data,...k}}},b)},updateEdge:h,updateEdgeData:(p,x,b={replace:!1})=>{h(p,y=>{const k=typeof x=="function"?x(y):x;return b.replace?{...y,data:k}:{...y,data:{...y.data,...k}}},b)},getNodesBounds:p=>{const{nodeLookup:x,nodeOrigin:b}=t.getState();return SK(p,{nodeLookup:x,nodeOrigin:b})},getHandleConnections:({type:p,id:x,nodeId:b})=>Array.from(t.getState().connectionLookup.get(`${b}-${p}${x?`-${x}`:""}`)?.values()??[]),getNodeConnections:({type:p,handleId:x,nodeId:b})=>Array.from(t.getState().connectionLookup.get(`${b}${p?x?`-${p}-${x}`:`-${p}`:""}`)?.values()??[]),fitView:async p=>{const x=t.getState().fitViewResolver??LK();return t.setState({fitViewQueued:!0,fitViewOptions:p,fitViewResolver:x}),n.nodeQueue.push(b=>[...b]),x.promise}}},[]);return v.useMemo(()=>({...a,...e,viewportInitialized:s}),[s])}const B3=e=>e.selected,aZ=typeof window<"u"?window:void 0;function iZ({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=kr(),{deleteElements:s}=d1(),a=pu(e,{actInsideInputWithModifier:!1}),o=pu(t,{target:aZ});v.useEffect(()=>{if(a){const{edges:c,nodes:d}=n.getState();s({nodes:d.filter(B3),edges:c.filter(B3)}),n.setState({nodesSelectionActive:!1})}},[a]),v.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])}function oZ(e){const t=kr();v.useEffect(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const s=s1(e.current);(s.height===0||s.width===0)&&t.getState().onError?.("004",li.error004()),t.setState({width:s.width||500,height:s.height||500})};if(e.current){n(),window.addEventListener("resize",n);const s=new ResizeObserver(()=>n());return s.observe(e.current),()=>{window.removeEventListener("resize",n),s&&e.current&&s.unobserve(e.current)}}},[])}const Dm={position:"absolute",width:"100%",height:"100%",top:0,left:0},lZ=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function cZ({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:s=!1,panOnScrollSpeed:a=.5,panOnScrollMode:o=cl.Free,zoomOnDoubleClick:c=!0,panOnDrag:d=!0,defaultViewport:u,translateExtent:f,minZoom:h,maxZoom:p,zoomActivationKeyCode:x,preventScrolling:b=!0,children:y,noWheelClassName:k,noPanClassName:j,onViewportChange:S,isControlledViewport:T,paneClickDistance:N,selectionOnDrag:E}){const B=kr(),A=v.useRef(null),{userSelectionActive:H,lib:O,connectionInProgress:z}=Ln(lZ,vr),I=pu(x),_=v.useRef();oZ(A);const X=v.useCallback(G=>{S?.({x:G[0],y:G[1],zoom:G[2]}),T||B.setState({transform:G})},[S,T]);return v.useEffect(()=>{if(A.current){_.current=gX({domNode:A.current,minZoom:h,maxZoom:p,translateExtent:f,viewport:u,onDraggingChange:L=>B.setState(F=>F.paneDragging===L?F:{paneDragging:L}),onPanZoomStart:(L,F)=>{const{onViewportChangeStart:Z,onMoveStart:Y}=B.getState();Y?.(L,F),Z?.(F)},onPanZoom:(L,F)=>{const{onViewportChange:Z,onMove:Y}=B.getState();Y?.(L,F),Z?.(F)},onPanZoomEnd:(L,F)=>{const{onViewportChangeEnd:Z,onMoveEnd:Y}=B.getState();Y?.(L,F),Z?.(F)}});const{x:G,y:M,zoom:U}=_.current.getViewport();return B.setState({panZoom:_.current,transform:[G,M,U],domNode:A.current.closest(".react-flow")}),()=>{_.current?.destroy()}}},[]),v.useEffect(()=>{_.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:s,panOnScrollSpeed:a,panOnScrollMode:o,zoomOnDoubleClick:c,panOnDrag:d,zoomActivationKeyPressed:I,preventScrolling:b,noPanClassName:j,userSelectionActive:H,noWheelClassName:k,lib:O,onTransformChange:X,connectionInProgress:z,selectionOnDrag:E,paneClickDistance:N})},[e,t,n,s,a,o,c,d,I,b,j,H,k,O,X,z,E,N]),r.jsx("div",{className:"react-flow__renderer",ref:A,style:Dm,children:y})}const dZ=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function uZ(){const{userSelectionActive:e,userSelectionRect:t}=Ln(dZ,vr);return e&&t?r.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const Bg=(e,t)=>n=>{n.target===t.current&&e?.(n)},fZ=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function mZ({isSelecting:e,selectionKeyPressed:t,selectionMode:n=fu.Full,panOnDrag:s,paneClickDistance:a,selectionOnDrag:o,onSelectionStart:c,onSelectionEnd:d,onPaneClick:u,onPaneContextMenu:f,onPaneScroll:h,onPaneMouseEnter:p,onPaneMouseMove:x,onPaneMouseLeave:b,children:y}){const k=kr(),{userSelectionActive:j,elementsSelectable:S,dragging:T,connectionInProgress:N}=Ln(fZ,vr),E=S&&(e||j),B=v.useRef(null),A=v.useRef(),H=v.useRef(new Set),O=v.useRef(new Set),z=v.useRef(!1),I=Z=>{if(z.current||N){z.current=!1;return}u?.(Z),k.getState().resetSelectedElements(),k.setState({nodesSelectionActive:!1})},_=Z=>{if(Array.isArray(s)&&s?.includes(2)){Z.preventDefault();return}f?.(Z)},X=h?Z=>h(Z):void 0,G=Z=>{z.current&&(Z.stopPropagation(),z.current=!1)},M=Z=>{const{domNode:Y}=k.getState();if(A.current=Y?.getBoundingClientRect(),!A.current)return;const D=Z.target===B.current;if(!D&&!!Z.target.closest(".nokey")||!e||!(o&&D||t)||Z.button!==0||!Z.isPrimary)return;Z.target?.setPointerCapture?.(Z.pointerId),z.current=!1;const{x:$,y:Q}=Ba(Z.nativeEvent,A.current);k.setState({userSelectionRect:{width:0,height:0,startX:$,startY:Q,x:$,y:Q}}),D||(Z.stopPropagation(),Z.preventDefault())},U=Z=>{const{userSelectionRect:Y,transform:D,nodeLookup:P,edgeLookup:ee,connectionLookup:$,triggerNodeChanges:Q,triggerEdgeChanges:q,defaultEdgeOptions:J,resetSelectedElements:K}=k.getState();if(!A.current||!Y)return;const{x:re,y:de}=Ba(Z.nativeEvent,A.current),{startX:pe,startY:te}=Y;if(!z.current){const Be=t?0:a;if(Math.hypot(re-pe,de-te)<=Be)return;K(),c?.(Z)}z.current=!0;const we={startX:pe,startY:te,x:re<pe?re:pe,y:de<te?de:te,width:Math.abs(re-pe),height:Math.abs(de-te)},ce=H.current,ge=O.current;H.current=new Set(n1(P,we,D,n===fu.Partial,!0).map(Be=>Be.id)),O.current=new Set;const Ce=J?.selectable??!0;for(const Be of H.current){const Qe=$.get(Be);if(Qe)for(const{edgeId:We}of Qe.values()){const wt=ee.get(We);wt&&(wt.selectable??Ce)&&O.current.add(We)}}if(!m3(ce,H.current)){const Be=fc(P,H.current,!0);Q(Be)}if(!m3(ge,O.current)){const Be=fc(ee,O.current);q(Be)}k.setState({userSelectionRect:we,userSelectionActive:!0,nodesSelectionActive:!1})},L=Z=>{Z.button===0&&(Z.target?.releasePointerCapture?.(Z.pointerId),!j&&Z.target===B.current&&k.getState().userSelectionRect&&I?.(Z),k.setState({userSelectionActive:!1,userSelectionRect:null}),z.current&&(d?.(Z),k.setState({nodesSelectionActive:H.current.size>0})))},F=s===!0||Array.isArray(s)&&s.includes(0);return r.jsxs("div",{className:Kr(["react-flow__pane",{draggable:F,dragging:T,selection:e}]),onClick:E?void 0:Bg(I,B),onContextMenu:Bg(_,B),onWheel:Bg(X,B),onPointerEnter:E?void 0:p,onPointerMove:E?U:x,onPointerUp:E?L:void 0,onPointerDownCapture:E?M:void 0,onClickCapture:E?G:void 0,onPointerLeave:b,ref:B,style:Dm,children:[y,r.jsx(uZ,{})]})}function Xx({id:e,store:t,unselect:n=!1,nodeRef:s}){const{addSelectedNodes:a,unselectNodesAndEdges:o,multiSelectionActive:c,nodeLookup:d,onError:u}=t.getState(),f=d.get(e);if(!f){u?.("012",li.error012(e));return}t.setState({nodesSelectionActive:!1}),f.selected?(n||f.selected&&c)&&(o({nodes:[f],edges:[]}),requestAnimationFrame(()=>s?.current?.blur())):a([e])}function OS({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:s,nodeId:a,isSelectable:o,nodeClickDistance:c}){const d=kr(),[u,f]=v.useState(!1),h=v.useRef();return v.useEffect(()=>{h.current=nX({getStoreItems:()=>d.getState(),onNodeMouseDown:p=>{Xx({id:p,store:d,nodeRef:e})},onDragStart:()=>{f(!0)},onDragStop:()=>{f(!1)}})},[]),v.useEffect(()=>{if(!(t||!e.current||!h.current))return h.current.update({noDragClassName:n,handleSelector:s,domNode:e.current,isSelectable:o,nodeId:a,nodeClickDistance:c}),()=>{h.current?.destroy()}},[n,s,t,o,e,a,c]),u}const hZ=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function _S(){const e=kr();return v.useCallback(n=>{const{nodeExtent:s,snapToGrid:a,snapGrid:o,nodesDraggable:c,onError:d,updateNodePositions:u,nodeLookup:f,nodeOrigin:h}=e.getState(),p=new Map,x=hZ(c),b=a?o[0]:5,y=a?o[1]:5,k=n.direction.x*b*n.factor,j=n.direction.y*y*n.factor;for(const[,S]of f){if(!x(S))continue;let T={x:S.internals.positionAbsolute.x+k,y:S.internals.positionAbsolute.y+j};a&&(T=Eu(T,o));const{position:N,positionAbsolute:E}=eS({nodeId:S.id,nextPosition:T,nodeLookup:f,nodeExtent:s,nodeOrigin:h,onError:d});S.position=N,S.internals.positionAbsolute=E,p.set(S.id,S)}u(p)},[])}const u1=v.createContext(null),pZ=u1.Provider;u1.Consumer;const IS=()=>v.useContext(u1),gZ=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),xZ=(e,t,n)=>s=>{const{connectionClickStartHandle:a,connectionMode:o,connection:c}=s,{fromHandle:d,toHandle:u,isValid:f}=c,h=u?.nodeId===e&&u?.id===t&&u?.type===n;return{connectingFrom:d?.nodeId===e&&d?.id===t&&d?.type===n,connectingTo:h,clickConnecting:a?.nodeId===e&&a?.id===t&&a?.type===n,isPossibleEndHandle:o===Nc.Strict?d?.type!==n:e!==d?.nodeId||t!==d?.id,connectionInProcess:!!d,clickConnectionInProcess:!!a,valid:h&&f}};function bZ({type:e="source",position:t=_t.Top,isValidConnection:n,isConnectable:s=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,id:c,onConnect:d,children:u,className:f,onMouseDown:h,onTouchStart:p,...x},b){const y=c||null,k=e==="target",j=kr(),S=IS(),{connectOnClick:T,noPanClassName:N,rfId:E}=Ln(gZ,vr),{connectingFrom:B,connectingTo:A,clickConnecting:H,isPossibleEndHandle:O,connectionInProcess:z,clickConnectionInProcess:I,valid:_}=Ln(xZ(S,y,e),vr);S||j.getState().onError?.("010",li.error010());const X=U=>{const{defaultEdgeOptions:L,onConnect:F,hasDefaultEdges:Z}=j.getState(),Y={...L,...U};if(Z){const{edges:D,setEdges:P}=j.getState();P(BK(Y,D))}F?.(Y),d?.(Y)},G=U=>{if(!S)return;const L=lS(U.nativeEvent);if(a&&(L&&U.button===0||!L)){const F=j.getState();Kx.onPointerDown(U.nativeEvent,{handleDomNode:U.currentTarget,autoPanOnConnect:F.autoPanOnConnect,connectionMode:F.connectionMode,connectionRadius:F.connectionRadius,domNode:F.domNode,nodeLookup:F.nodeLookup,lib:F.lib,isTarget:k,handleId:y,nodeId:S,flowId:F.rfId,panBy:F.panBy,cancelConnection:F.cancelConnection,onConnectStart:F.onConnectStart,onConnectEnd:(...Z)=>j.getState().onConnectEnd?.(...Z),updateConnection:F.updateConnection,onConnect:X,isValidConnection:n||((...Z)=>j.getState().isValidConnection?.(...Z)??!0),getTransform:()=>j.getState().transform,getFromHandle:()=>j.getState().connection.fromHandle,autoPanSpeed:F.autoPanSpeed,dragThreshold:F.connectionDragThreshold})}L?h?.(U):p?.(U)},M=U=>{const{onClickConnectStart:L,onClickConnectEnd:F,connectionClickStartHandle:Z,connectionMode:Y,isValidConnection:D,lib:P,rfId:ee,nodeLookup:$,connection:Q}=j.getState();if(!S||!Z&&!a)return;if(!Z){L?.(U.nativeEvent,{nodeId:S,handleId:y,handleType:e}),j.setState({connectionClickStartHandle:{nodeId:S,type:e,id:y}});return}const q=iS(U.target),J=n||D,{connection:K,isValid:re}=Kx.isValid(U.nativeEvent,{handle:{nodeId:S,id:y,type:e},connectionMode:Y,fromNodeId:Z.nodeId,fromHandleId:Z.id||null,fromType:Z.type,isValidConnection:J,flowId:ee,doc:q,lib:P,nodeLookup:$});re&&K&&X(K);const de=structuredClone(Q);delete de.inProgress,de.toPosition=de.toHandle?de.toHandle.position:null,F?.(U,de),j.setState({connectionClickStartHandle:null})};return r.jsx("div",{"data-handleid":y,"data-nodeid":S,"data-handlepos":t,"data-id":`${E}-${S}-${y}-${e}`,className:Kr(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",N,f,{source:!k,target:k,connectable:s,connectablestart:a,connectableend:o,clickconnecting:H,connectingfrom:B,connectingto:A,valid:_,connectionindicator:s&&(!z||O)&&(z||I?o:a)}]),onMouseDown:G,onTouchStart:G,onClick:T?M:void 0,ref:b,...x,children:u})}const Ro=v.memo(RS(bZ));function yZ({data:e,isConnectable:t,sourcePosition:n=_t.Bottom}){return r.jsxs(r.Fragment,{children:[e?.label,r.jsx(Ro,{type:"source",position:n,isConnectable:t})]})}function vZ({data:e,isConnectable:t,targetPosition:n=_t.Top,sourcePosition:s=_t.Bottom}){return r.jsxs(r.Fragment,{children:[r.jsx(Ro,{type:"target",position:n,isConnectable:t}),e?.label,r.jsx(Ro,{type:"source",position:s,isConnectable:t})]})}function wZ(){return null}function kZ({data:e,isConnectable:t,targetPosition:n=_t.Top}){return r.jsxs(r.Fragment,{children:[r.jsx(Ro,{type:"target",position:n,isConnectable:t}),e?.label]})}const Qf={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},H3={input:yZ,default:vZ,output:kZ,group:wZ};function jZ(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 NZ=e=>{const{width:t,height:n,x:s,y:a}=Au(e.nodeLookup,{filter:o=>!!o.selected});return{width:$a(t)?t:null,height:$a(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${s}px,${a}px)`}};function SZ({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const s=kr(),{width:a,height:o,transformString:c,userSelectionActive:d}=Ln(NZ,vr),u=_S(),f=v.useRef(null);v.useEffect(()=>{n||f.current?.focus({preventScroll:!0})},[n]);const h=!d&&a!==null&&o!==null;if(OS({nodeRef:f,disabled:!h}),!h)return null;const p=e?b=>{const y=s.getState().nodes.filter(k=>k.selected);e(b,y)}:void 0,x=b=>{Object.prototype.hasOwnProperty.call(Qf,b.key)&&(b.preventDefault(),u({direction:Qf[b.key],factor:b.shiftKey?4:1}))};return r.jsx("div",{className:Kr(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c},children:r.jsx("div",{ref:f,className:"react-flow__nodesselection-rect",onContextMenu:p,tabIndex:n?void 0:-1,onKeyDown:n?void 0:x,style:{width:a,height:o}})})}const q3=typeof window<"u"?window:void 0,CZ=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function PS({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:a,onPaneContextMenu:o,onPaneScroll:c,paneClickDistance:d,deleteKeyCode:u,selectionKeyCode:f,selectionOnDrag:h,selectionMode:p,onSelectionStart:x,onSelectionEnd:b,multiSelectionKeyCode:y,panActivationKeyCode:k,zoomActivationKeyCode:j,elementsSelectable:S,zoomOnScroll:T,zoomOnPinch:N,panOnScroll:E,panOnScrollSpeed:B,panOnScrollMode:A,zoomOnDoubleClick:H,panOnDrag:O,defaultViewport:z,translateExtent:I,minZoom:_,maxZoom:X,preventScrolling:G,onSelectionContextMenu:M,noWheelClassName:U,noPanClassName:L,disableKeyboardA11y:F,onViewportChange:Z,isControlledViewport:Y}){const{nodesSelectionActive:D,userSelectionActive:P}=Ln(CZ,vr),ee=pu(f,{target:q3}),$=pu(k,{target:q3}),Q=$||O,q=$||E,J=h&&Q!==!0,K=ee||P||J;return iZ({deleteKeyCode:u,multiSelectionKeyCode:y}),r.jsx(cZ,{onPaneContextMenu:o,elementsSelectable:S,zoomOnScroll:T,zoomOnPinch:N,panOnScroll:q,panOnScrollSpeed:B,panOnScrollMode:A,zoomOnDoubleClick:H,panOnDrag:!ee&&Q,defaultViewport:z,translateExtent:I,minZoom:_,maxZoom:X,zoomActivationKeyCode:j,preventScrolling:G,noWheelClassName:U,noPanClassName:L,onViewportChange:Z,isControlledViewport:Y,paneClickDistance:d,selectionOnDrag:J,children:r.jsxs(mZ,{onSelectionStart:x,onSelectionEnd:b,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:a,onPaneContextMenu:o,onPaneScroll:c,panOnDrag:Q,isSelecting:!!K,selectionMode:p,selectionKeyPressed:ee,paneClickDistance:d,selectionOnDrag:J,children:[e,D&&r.jsx(SZ,{onSelectionContextMenu:M,noPanClassName:L,disableKeyboardA11y:F})]})})}PS.displayName="FlowRenderer";const TZ=v.memo(PS),AZ=e=>t=>e?n1(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function EZ(e){return Ln(v.useCallback(AZ(e),[e]),vr)}const MZ=e=>e.updateNodeInternals;function DZ(){const e=Ln(MZ),[t]=v.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const s=new Map;n.forEach(a=>{const o=a.target.getAttribute("data-id");s.set(o,{id:o,nodeElement:a.target,force:!0})}),e(s)}));return v.useEffect(()=>()=>{t?.disconnect()},[t]),t}function RZ({node:e,nodeType:t,hasDimensions:n,resizeObserver:s}){const a=kr(),o=v.useRef(null),c=v.useRef(null),d=v.useRef(e.sourcePosition),u=v.useRef(e.targetPosition),f=v.useRef(t),h=n&&!!e.internals.handleBounds;return v.useEffect(()=>{o.current&&!e.hidden&&(!h||c.current!==o.current)&&(c.current&&s?.unobserve(c.current),s?.observe(o.current),c.current=o.current)},[h,e.hidden]),v.useEffect(()=>()=>{c.current&&(s?.unobserve(c.current),c.current=null)},[]),v.useEffect(()=>{if(o.current){const p=f.current!==t,x=d.current!==e.sourcePosition,b=u.current!==e.targetPosition;(p||x||b)&&(f.current=t,d.current=e.sourcePosition,u.current=e.targetPosition,a.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:o.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),o}function LZ({id:e,onClick:t,onMouseEnter:n,onMouseMove:s,onMouseLeave:a,onContextMenu:o,onDoubleClick:c,nodesDraggable:d,elementsSelectable:u,nodesConnectable:f,nodesFocusable:h,resizeObserver:p,noDragClassName:x,noPanClassName:b,disableKeyboardA11y:y,rfId:k,nodeTypes:j,nodeClickDistance:S,onError:T}){const{node:N,internals:E,isParent:B}=Ln(re=>{const de=re.nodeLookup.get(e),pe=re.parentLookup.has(e);return{node:de,internals:de.internals,isParent:pe}},vr);let A=N.type||"default",H=j?.[A]||H3[A];H===void 0&&(T?.("003",li.error003(A)),A="default",H=j?.default||H3.default);const O=!!(N.draggable||d&&typeof N.draggable>"u"),z=!!(N.selectable||u&&typeof N.selectable>"u"),I=!!(N.connectable||f&&typeof N.connectable>"u"),_=!!(N.focusable||h&&typeof N.focusable>"u"),X=kr(),G=sS(N),M=RZ({node:N,nodeType:A,hasDimensions:G,resizeObserver:p}),U=OS({nodeRef:M,disabled:N.hidden||!O,noDragClassName:x,handleSelector:N.dragHandle,nodeId:e,isSelectable:z,nodeClickDistance:S}),L=_S();if(N.hidden)return null;const F=Yi(N),Z=jZ(N),Y=z||O||t||n||s||a,D=n?re=>n(re,{...E.userNode}):void 0,P=s?re=>s(re,{...E.userNode}):void 0,ee=a?re=>a(re,{...E.userNode}):void 0,$=o?re=>o(re,{...E.userNode}):void 0,Q=c?re=>c(re,{...E.userNode}):void 0,q=re=>{const{selectNodesOnDrag:de,nodeDragThreshold:pe}=X.getState();z&&(!de||!O||pe>0)&&Xx({id:e,store:X,nodeRef:M}),t&&t(re,{...E.userNode})},J=re=>{if(!(oS(re.nativeEvent)||y)){if(KN.includes(re.key)&&z){const de=re.key==="Escape";Xx({id:e,store:X,unselect:de,nodeRef:M})}else if(O&&N.selected&&Object.prototype.hasOwnProperty.call(Qf,re.key)){re.preventDefault();const{ariaLabelConfig:de}=X.getState();X.setState({ariaLiveMessage:de["node.a11yDescription.ariaLiveMessage"]({direction:re.key.replace("Arrow","").toLowerCase(),x:~~E.positionAbsolute.x,y:~~E.positionAbsolute.y})}),L({direction:Qf[re.key],factor:re.shiftKey?4:1})}}},K=()=>{if(y||!M.current?.matches(":focus-visible"))return;const{transform:re,width:de,height:pe,autoPanOnNodeFocus:te,setCenter:we}=X.getState();if(!te)return;n1(new Map([[e,N]]),{x:0,y:0,width:de,height:pe},re,!0).length>0||we(N.position.x+F.width/2,N.position.y+F.height/2,{zoom:re[2]})};return r.jsx("div",{className:Kr(["react-flow__node",`react-flow__node-${A}`,{[b]:O},N.className,{selected:N.selected,selectable:z,parent:B,draggable:O,dragging:U}]),ref:M,style:{zIndex:E.z,transform:`translate(${E.positionAbsolute.x}px,${E.positionAbsolute.y}px)`,pointerEvents:Y?"all":"none",visibility:G?"visible":"hidden",...N.style,...Z},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:D,onMouseMove:P,onMouseLeave:ee,onContextMenu:$,onClick:q,onDoubleClick:Q,onKeyDown:_?J:void 0,tabIndex:_?0:void 0,onFocus:_?K:void 0,role:N.ariaRole??(_?"group":void 0),"aria-roledescription":"node","aria-describedby":y?void 0:`${CS}-${k}`,"aria-label":N.ariaLabel,...N.domAttributes,children:r.jsx(pZ,{value:e,children:r.jsx(H,{id:e,data:N.data,type:A,positionAbsoluteX:E.positionAbsolute.x,positionAbsoluteY:E.positionAbsolute.y,selected:N.selected??!1,selectable:z,draggable:O,deletable:N.deletable??!0,isConnectable:I,sourcePosition:N.sourcePosition,targetPosition:N.targetPosition,dragging:U,dragHandle:N.dragHandle,zIndex:E.z,parentId:N.parentId,...F})})})}var OZ=v.memo(LZ);const _Z=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function zS(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:s,elementsSelectable:a,onError:o}=Ln(_Z,vr),c=EZ(e.onlyRenderVisibleElements),d=DZ();return r.jsx("div",{className:"react-flow__nodes",style:Dm,children:c.map(u=>r.jsx(OZ,{id:u,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:d,nodesDraggable:t,nodesConnectable:n,nodesFocusable:s,elementsSelectable:a,nodeClickDistance:e.nodeClickDistance,onError:o},u))})}zS.displayName="NodeRenderer";const IZ=v.memo(zS);function PZ(e){return Ln(v.useCallback(n=>{if(!e)return n.edges.map(a=>a.id);const s=[];if(n.width&&n.height)for(const a of n.edges){const o=n.nodeLookup.get(a.source),c=n.nodeLookup.get(a.target);o&&c&&PK({sourceNode:o,targetNode:c,width:n.width,height:n.height,transform:n.transform})&&s.push(a.id)}return s},[e]),vr)}const zZ=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return r.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},$Z=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return r.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},F3={[Sc.Arrow]:zZ,[Sc.ArrowClosed]:$Z};function BZ(e){const t=kr();return v.useMemo(()=>Object.prototype.hasOwnProperty.call(F3,e)?F3[e]:(t.getState().onError?.("009",li.error009(e)),null),[e])}const HZ=({id:e,type:t,color:n,width:s=12.5,height:a=12.5,markerUnits:o="strokeWidth",strokeWidth:c,orient:d="auto-start-reverse"})=>{const u=BZ(t);return u?r.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${s}`,markerHeight:`${a}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:d,refX:"0",refY:"0",children:r.jsx(u,{color:n,strokeWidth:c})}):null},$S=({defaultColor:e,rfId:t})=>{const n=Ln(o=>o.edges),s=Ln(o=>o.defaultEdgeOptions),a=v.useMemo(()=>VK(n,{id:t,defaultColor:e,defaultMarkerStart:s?.markerStart,defaultMarkerEnd:s?.markerEnd}),[n,s,t,e]);return a.length?r.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:r.jsx("defs",{children:a.map(o=>r.jsx(HZ,{id:o.id,type:o.type,color:o.color,width:o.width,height:o.height,markerUnits:o.markerUnits,strokeWidth:o.strokeWidth,orient:o.orient},o.id))})}):null};$S.displayName="MarkerDefinitions";var qZ=v.memo($S);function BS({x:e,y:t,label:n,labelStyle:s,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:d=2,children:u,className:f,...h}){const[p,x]=v.useState({x:1,y:0,width:0,height:0}),b=Kr(["react-flow__edge-textwrapper",f]),y=v.useRef(null);return v.useEffect(()=>{if(y.current){const k=y.current.getBBox();x({x:k.x,y:k.y,width:k.width,height:k.height})}},[n]),n?r.jsxs("g",{transform:`translate(${e-p.width/2} ${t-p.height/2})`,className:b,visibility:p.width?"visible":"hidden",...h,children:[a&&r.jsx("rect",{width:p.width+2*c[0],x:-c[0],y:-c[1],height:p.height+2*c[1],className:"react-flow__edge-textbg",style:o,rx:d,ry:d}),r.jsx("text",{className:"react-flow__edge-text",y:p.height/2,dy:"0.3em",ref:y,style:s,children:n}),u]}):null}BS.displayName="EdgeText";const FZ=v.memo(BS);function Rm({path:e,labelX:t,labelY:n,label:s,labelStyle:a,labelShowBg:o,labelBgStyle:c,labelBgPadding:d,labelBgBorderRadius:u,interactionWidth:f=20,...h}){return r.jsxs(r.Fragment,{children:[r.jsx("path",{...h,d:e,fill:"none",className:Kr(["react-flow__edge-path",h.className])}),f?r.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}):null,s&&$a(t)&&$a(n)?r.jsx(FZ,{x:t,y:n,label:s,labelStyle:a,labelShowBg:o,labelBgStyle:c,labelBgPadding:d,labelBgBorderRadius:u}):null]})}function U3({pos:e,x1:t,y1:n,x2:s,y2:a}){return e===_t.Left||e===_t.Right?[.5*(t+s),n]:[t,.5*(n+a)]}function HS({sourceX:e,sourceY:t,sourcePosition:n=_t.Bottom,targetX:s,targetY:a,targetPosition:o=_t.Top}){const[c,d]=U3({pos:n,x1:e,y1:t,x2:s,y2:a}),[u,f]=U3({pos:o,x1:s,y1:a,x2:e,y2:t}),[h,p,x,b]=cS({sourceX:e,sourceY:t,targetX:s,targetY:a,sourceControlX:c,sourceControlY:d,targetControlX:u,targetControlY:f});return[`M${e},${t} C${c},${d} ${u},${f} ${s},${a}`,h,p,x,b]}function qS(e){return v.memo(({id:t,sourceX:n,sourceY:s,targetX:a,targetY:o,sourcePosition:c,targetPosition:d,label:u,labelStyle:f,labelShowBg:h,labelBgStyle:p,labelBgPadding:x,labelBgBorderRadius:b,style:y,markerEnd:k,markerStart:j,interactionWidth:S})=>{const[T,N,E]=HS({sourceX:n,sourceY:s,sourcePosition:c,targetX:a,targetY:o,targetPosition:d}),B=e.isInternal?void 0:t;return r.jsx(Rm,{id:B,path:T,labelX:N,labelY:E,label:u,labelStyle:f,labelShowBg:h,labelBgStyle:p,labelBgPadding:x,labelBgBorderRadius:b,style:y,markerEnd:k,markerStart:j,interactionWidth:S})})}const UZ=qS({isInternal:!1}),FS=qS({isInternal:!0});UZ.displayName="SimpleBezierEdge";FS.displayName="SimpleBezierEdgeInternal";function US(e){return v.memo(({id:t,sourceX:n,sourceY:s,targetX:a,targetY:o,label:c,labelStyle:d,labelShowBg:u,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,sourcePosition:b=_t.Bottom,targetPosition:y=_t.Top,markerEnd:k,markerStart:j,pathOptions:S,interactionWidth:T})=>{const[N,E,B]=Gx({sourceX:n,sourceY:s,sourcePosition:b,targetX:a,targetY:o,targetPosition:y,borderRadius:S?.borderRadius,offset:S?.offset,stepPosition:S?.stepPosition}),A=e.isInternal?void 0:t;return r.jsx(Rm,{id:A,path:N,labelX:E,labelY:B,label:c,labelStyle:d,labelShowBg:u,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:k,markerStart:j,interactionWidth:T})})}const VS=US({isInternal:!1}),GS=US({isInternal:!0});VS.displayName="SmoothStepEdge";GS.displayName="SmoothStepEdgeInternal";function YS(e){return v.memo(({id:t,...n})=>{const s=e.isInternal?void 0:t;return r.jsx(VS,{...n,id:s,pathOptions:v.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const VZ=YS({isInternal:!1}),WS=YS({isInternal:!0});VZ.displayName="StepEdge";WS.displayName="StepEdgeInternal";function KS(e){return v.memo(({id:t,sourceX:n,sourceY:s,targetX:a,targetY:o,label:c,labelStyle:d,labelShowBg:u,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:b,markerStart:y,interactionWidth:k})=>{const[j,S,T]=fS({sourceX:n,sourceY:s,targetX:a,targetY:o}),N=e.isInternal?void 0:t;return r.jsx(Rm,{id:N,path:j,labelX:S,labelY:T,label:c,labelStyle:d,labelShowBg:u,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:b,markerStart:y,interactionWidth:k})})}const GZ=KS({isInternal:!1}),XS=KS({isInternal:!0});GZ.displayName="StraightEdge";XS.displayName="StraightEdgeInternal";function ZS(e){return v.memo(({id:t,sourceX:n,sourceY:s,targetX:a,targetY:o,sourcePosition:c=_t.Bottom,targetPosition:d=_t.Top,label:u,labelStyle:f,labelShowBg:h,labelBgStyle:p,labelBgPadding:x,labelBgBorderRadius:b,style:y,markerEnd:k,markerStart:j,pathOptions:S,interactionWidth:T})=>{const[N,E,B]=dS({sourceX:n,sourceY:s,sourcePosition:c,targetX:a,targetY:o,targetPosition:d,curvature:S?.curvature}),A=e.isInternal?void 0:t;return r.jsx(Rm,{id:A,path:N,labelX:E,labelY:B,label:u,labelStyle:f,labelShowBg:h,labelBgStyle:p,labelBgPadding:x,labelBgBorderRadius:b,style:y,markerEnd:k,markerStart:j,interactionWidth:T})})}const YZ=ZS({isInternal:!1}),QS=ZS({isInternal:!0});YZ.displayName="BezierEdge";QS.displayName="BezierEdgeInternal";const V3={default:QS,straight:XS,step:WS,smoothstep:GS,simplebezier:FS},G3={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},WZ=(e,t,n)=>n===_t.Left?e-t:n===_t.Right?e+t:e,KZ=(e,t,n)=>n===_t.Top?e-t:n===_t.Bottom?e+t:e,Y3="react-flow__edgeupdater";function W3({position:e,centerX:t,centerY:n,radius:s=10,onMouseDown:a,onMouseEnter:o,onMouseOut:c,type:d}){return r.jsx("circle",{onMouseDown:a,onMouseEnter:o,onMouseOut:c,className:Kr([Y3,`${Y3}-${d}`]),cx:WZ(t,s,e),cy:KZ(n,s,e),r:s,stroke:"transparent",fill:"transparent"})}function XZ({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:s,sourceY:a,targetX:o,targetY:c,sourcePosition:d,targetPosition:u,onReconnect:f,onReconnectStart:h,onReconnectEnd:p,setReconnecting:x,setUpdateHover:b}){const y=kr(),k=(E,B)=>{if(E.button!==0)return;const{autoPanOnConnect:A,domNode:H,connectionMode:O,connectionRadius:z,lib:I,onConnectStart:_,cancelConnection:X,nodeLookup:G,rfId:M,panBy:U,updateConnection:L}=y.getState(),F=B.type==="target",Z=(P,ee)=>{x(!1),p?.(P,n,B.type,ee)},Y=P=>f?.(n,P),D=(P,ee)=>{x(!0),h?.(E,n,B.type),_?.(P,ee)};Kx.onPointerDown(E.nativeEvent,{autoPanOnConnect:A,connectionMode:O,connectionRadius:z,domNode:H,handleId:B.id,nodeId:B.nodeId,nodeLookup:G,isTarget:F,edgeUpdaterType:B.type,lib:I,flowId:M,cancelConnection:X,panBy:U,isValidConnection:(...P)=>y.getState().isValidConnection?.(...P)??!0,onConnect:Y,onConnectStart:D,onConnectEnd:(...P)=>y.getState().onConnectEnd?.(...P),onReconnectEnd:Z,updateConnection:L,getTransform:()=>y.getState().transform,getFromHandle:()=>y.getState().connection.fromHandle,dragThreshold:y.getState().connectionDragThreshold,handleDomNode:E.currentTarget})},j=E=>k(E,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),S=E=>k(E,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),T=()=>b(!0),N=()=>b(!1);return r.jsxs(r.Fragment,{children:[(e===!0||e==="source")&&r.jsx(W3,{position:d,centerX:s,centerY:a,radius:t,onMouseDown:j,onMouseEnter:T,onMouseOut:N,type:"source"}),(e===!0||e==="target")&&r.jsx(W3,{position:u,centerX:o,centerY:c,radius:t,onMouseDown:S,onMouseEnter:T,onMouseOut:N,type:"target"})]})}function ZZ({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:s,onClick:a,onDoubleClick:o,onContextMenu:c,onMouseEnter:d,onMouseMove:u,onMouseLeave:f,reconnectRadius:h,onReconnect:p,onReconnectStart:x,onReconnectEnd:b,rfId:y,edgeTypes:k,noPanClassName:j,onError:S,disableKeyboardA11y:T}){let N=Ln(we=>we.edgeLookup.get(e));const E=Ln(we=>we.defaultEdgeOptions);N=E?{...E,...N}:N;let B=N.type||"default",A=k?.[B]||V3[B];A===void 0&&(S?.("011",li.error011(B)),B="default",A=k?.default||V3.default);const H=!!(N.focusable||t&&typeof N.focusable>"u"),O=typeof p<"u"&&(N.reconnectable||n&&typeof N.reconnectable>"u"),z=!!(N.selectable||s&&typeof N.selectable>"u"),I=v.useRef(null),[_,X]=v.useState(!1),[G,M]=v.useState(!1),U=kr(),{zIndex:L,sourceX:F,sourceY:Z,targetX:Y,targetY:D,sourcePosition:P,targetPosition:ee}=Ln(v.useCallback(we=>{const ce=we.nodeLookup.get(N.source),ge=we.nodeLookup.get(N.target);if(!ce||!ge)return{zIndex:N.zIndex,...G3};const Ce=UK({id:e,sourceNode:ce,targetNode:ge,sourceHandle:N.sourceHandle||null,targetHandle:N.targetHandle||null,connectionMode:we.connectionMode,onError:S});return{zIndex:IK({selected:N.selected,zIndex:N.zIndex,sourceNode:ce,targetNode:ge,elevateOnSelect:we.elevateEdgesOnSelect,zIndexMode:we.zIndexMode}),...Ce||G3}},[N.source,N.target,N.sourceHandle,N.targetHandle,N.selected,N.zIndex]),vr),$=v.useMemo(()=>N.markerStart?`url('#${Yx(N.markerStart,y)}')`:void 0,[N.markerStart,y]),Q=v.useMemo(()=>N.markerEnd?`url('#${Yx(N.markerEnd,y)}')`:void 0,[N.markerEnd,y]);if(N.hidden||F===null||Z===null||Y===null||D===null)return null;const q=we=>{const{addSelectedEdges:ce,unselectNodesAndEdges:ge,multiSelectionActive:Ce}=U.getState();z&&(U.setState({nodesSelectionActive:!1}),N.selected&&Ce?(ge({nodes:[],edges:[N]}),I.current?.blur()):ce([e])),a&&a(we,N)},J=o?we=>{o(we,{...N})}:void 0,K=c?we=>{c(we,{...N})}:void 0,re=d?we=>{d(we,{...N})}:void 0,de=u?we=>{u(we,{...N})}:void 0,pe=f?we=>{f(we,{...N})}:void 0,te=we=>{if(!T&&KN.includes(we.key)&&z){const{unselectNodesAndEdges:ce,addSelectedEdges:ge}=U.getState();we.key==="Escape"?(I.current?.blur(),ce({edges:[N]})):ge([e])}};return r.jsx("svg",{style:{zIndex:L},children:r.jsxs("g",{className:Kr(["react-flow__edge",`react-flow__edge-${B}`,N.className,j,{selected:N.selected,animated:N.animated,inactive:!z&&!a,updating:_,selectable:z}]),onClick:q,onDoubleClick:J,onContextMenu:K,onMouseEnter:re,onMouseMove:de,onMouseLeave:pe,onKeyDown:H?te:void 0,tabIndex:H?0:void 0,role:N.ariaRole??(H?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":N.ariaLabel===null?void 0:N.ariaLabel||`Edge from ${N.source} to ${N.target}`,"aria-describedby":H?`${TS}-${y}`:void 0,ref:I,...N.domAttributes,children:[!G&&r.jsx(A,{id:e,source:N.source,target:N.target,type:N.type,selected:N.selected,animated:N.animated,selectable:z,deletable:N.deletable??!0,label:N.label,labelStyle:N.labelStyle,labelShowBg:N.labelShowBg,labelBgStyle:N.labelBgStyle,labelBgPadding:N.labelBgPadding,labelBgBorderRadius:N.labelBgBorderRadius,sourceX:F,sourceY:Z,targetX:Y,targetY:D,sourcePosition:P,targetPosition:ee,data:N.data,style:N.style,sourceHandleId:N.sourceHandle,targetHandleId:N.targetHandle,markerStart:$,markerEnd:Q,pathOptions:"pathOptions"in N?N.pathOptions:void 0,interactionWidth:N.interactionWidth}),O&&r.jsx(XZ,{edge:N,isReconnectable:O,reconnectRadius:h,onReconnect:p,onReconnectStart:x,onReconnectEnd:b,sourceX:F,sourceY:Z,targetX:Y,targetY:D,sourcePosition:P,targetPosition:ee,setUpdateHover:X,setReconnecting:M})]})})}var QZ=v.memo(ZZ);const JZ=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function JS({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:s,noPanClassName:a,onReconnect:o,onEdgeContextMenu:c,onEdgeMouseEnter:d,onEdgeMouseMove:u,onEdgeMouseLeave:f,onEdgeClick:h,reconnectRadius:p,onEdgeDoubleClick:x,onReconnectStart:b,onReconnectEnd:y,disableKeyboardA11y:k}){const{edgesFocusable:j,edgesReconnectable:S,elementsSelectable:T,onError:N}=Ln(JZ,vr),E=PZ(t);return r.jsxs("div",{className:"react-flow__edges",children:[r.jsx(qZ,{defaultColor:e,rfId:n}),E.map(B=>r.jsx(QZ,{id:B,edgesFocusable:j,edgesReconnectable:S,elementsSelectable:T,noPanClassName:a,onReconnect:o,onContextMenu:c,onMouseEnter:d,onMouseMove:u,onMouseLeave:f,onClick:h,reconnectRadius:p,onDoubleClick:x,onReconnectStart:b,onReconnectEnd:y,rfId:n,onError:N,edgeTypes:s,disableKeyboardA11y:k},B))]})}JS.displayName="EdgeRenderer";const eQ=v.memo(JS),tQ=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function nQ({children:e}){const t=Ln(tQ);return r.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function rQ(e){const t=d1(),n=v.useRef(!1);v.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const sQ=e=>e.panZoom?.syncViewport;function aQ(e){const t=Ln(sQ),n=kr();return v.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function iQ(e){return e.connection.inProgress?{...e.connection,to:Mu(e.connection.to,e.transform)}:{...e.connection}}function oQ(e){return iQ}function lQ(e){const t=oQ();return Ln(t,vr)}const cQ=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function dQ({containerStyle:e,style:t,type:n,component:s}){const{nodesConnectable:a,width:o,height:c,isValid:d,inProgress:u}=Ln(cQ,vr);return!(o&&a&&u)?null:r.jsx("svg",{style:e,width:o,height:c,className:"react-flow__connectionline react-flow__container",children:r.jsx("g",{className:Kr(["react-flow__connection",QN(d)]),children:r.jsx(e7,{style:t,type:n,CustomComponent:s,isValid:d})})})}const e7=({style:e,type:t=No.Bezier,CustomComponent:n,isValid:s})=>{const{inProgress:a,from:o,fromNode:c,fromHandle:d,fromPosition:u,to:f,toNode:h,toHandle:p,toPosition:x,pointer:b}=lQ();if(!a)return;if(n)return r.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:c,fromHandle:d,fromX:o.x,fromY:o.y,toX:f.x,toY:f.y,fromPosition:u,toPosition:x,connectionStatus:QN(s),toNode:h,toHandle:p,pointer:b});let y="";const k={sourceX:o.x,sourceY:o.y,sourcePosition:u,targetX:f.x,targetY:f.y,targetPosition:x};switch(t){case No.Bezier:[y]=dS(k);break;case No.SimpleBezier:[y]=HS(k);break;case No.Step:[y]=Gx({...k,borderRadius:0});break;case No.SmoothStep:[y]=Gx(k);break;default:[y]=fS(k)}return r.jsx("path",{d:y,fill:"none",className:"react-flow__connection-path",style:e})};e7.displayName="ConnectionLine";const uQ={};function K3(e=uQ){v.useRef(e),kr(),v.useEffect(()=>{},[e])}function fQ(){kr(),v.useRef(!1),v.useEffect(()=>{},[])}function t7({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:s,onEdgeClick:a,onNodeDoubleClick:o,onEdgeDoubleClick:c,onNodeMouseEnter:d,onNodeMouseMove:u,onNodeMouseLeave:f,onNodeContextMenu:h,onSelectionContextMenu:p,onSelectionStart:x,onSelectionEnd:b,connectionLineType:y,connectionLineStyle:k,connectionLineComponent:j,connectionLineContainerStyle:S,selectionKeyCode:T,selectionOnDrag:N,selectionMode:E,multiSelectionKeyCode:B,panActivationKeyCode:A,zoomActivationKeyCode:H,deleteKeyCode:O,onlyRenderVisibleElements:z,elementsSelectable:I,defaultViewport:_,translateExtent:X,minZoom:G,maxZoom:M,preventScrolling:U,defaultMarkerColor:L,zoomOnScroll:F,zoomOnPinch:Z,panOnScroll:Y,panOnScrollSpeed:D,panOnScrollMode:P,zoomOnDoubleClick:ee,panOnDrag:$,onPaneClick:Q,onPaneMouseEnter:q,onPaneMouseMove:J,onPaneMouseLeave:K,onPaneScroll:re,onPaneContextMenu:de,paneClickDistance:pe,nodeClickDistance:te,onEdgeContextMenu:we,onEdgeMouseEnter:ce,onEdgeMouseMove:ge,onEdgeMouseLeave:Ce,reconnectRadius:Be,onReconnect:Qe,onReconnectStart:We,onReconnectEnd:wt,noDragClassName:bt,noWheelClassName:$t,noPanClassName:dt,disableKeyboardA11y:me,nodeExtent:ve,rfId:Re,viewport:ke,onViewportChange:Pe}){return K3(e),K3(t),fQ(),rQ(n),aQ(ke),r.jsx(TZ,{onPaneClick:Q,onPaneMouseEnter:q,onPaneMouseMove:J,onPaneMouseLeave:K,onPaneContextMenu:de,onPaneScroll:re,paneClickDistance:pe,deleteKeyCode:O,selectionKeyCode:T,selectionOnDrag:N,selectionMode:E,onSelectionStart:x,onSelectionEnd:b,multiSelectionKeyCode:B,panActivationKeyCode:A,zoomActivationKeyCode:H,elementsSelectable:I,zoomOnScroll:F,zoomOnPinch:Z,zoomOnDoubleClick:ee,panOnScroll:Y,panOnScrollSpeed:D,panOnScrollMode:P,panOnDrag:$,defaultViewport:_,translateExtent:X,minZoom:G,maxZoom:M,onSelectionContextMenu:p,preventScrolling:U,noDragClassName:bt,noWheelClassName:$t,noPanClassName:dt,disableKeyboardA11y:me,onViewportChange:Pe,isControlledViewport:!!ke,children:r.jsxs(nQ,{children:[r.jsx(eQ,{edgeTypes:t,onEdgeClick:a,onEdgeDoubleClick:c,onReconnect:Qe,onReconnectStart:We,onReconnectEnd:wt,onlyRenderVisibleElements:z,onEdgeContextMenu:we,onEdgeMouseEnter:ce,onEdgeMouseMove:ge,onEdgeMouseLeave:Ce,reconnectRadius:Be,defaultMarkerColor:L,noPanClassName:dt,disableKeyboardA11y:me,rfId:Re}),r.jsx(dQ,{style:k,type:y,component:j,containerStyle:S}),r.jsx("div",{className:"react-flow__edgelabel-renderer"}),r.jsx(IZ,{nodeTypes:e,onNodeClick:s,onNodeDoubleClick:o,onNodeMouseEnter:d,onNodeMouseMove:u,onNodeMouseLeave:f,onNodeContextMenu:h,nodeClickDistance:te,onlyRenderVisibleElements:z,noPanClassName:dt,noDragClassName:bt,disableKeyboardA11y:me,nodeExtent:ve,rfId:Re}),r.jsx("div",{className:"react-flow__viewport-portal"})]})})}t7.displayName="GraphView";const mQ=v.memo(t7),X3=({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:a,height:o,fitView:c,fitViewOptions:d,minZoom:u=.5,maxZoom:f=2,nodeOrigin:h,nodeExtent:p,zIndexMode:x="basic"}={})=>{const b=new Map,y=new Map,k=new Map,j=new Map,S=s??t??[],T=n??e??[],N=h??[0,0],E=p??uu;pS(k,j,S);const B=Wx(T,b,y,{nodeOrigin:N,nodeExtent:E,zIndexMode:x});let A=[0,0,1];if(c&&a&&o){const H=Au(b,{filter:_=>!!((_.width||_.initialWidth)&&(_.height||_.initialHeight))}),{x:O,y:z,zoom:I}=r1(H,a,o,u,f,d?.padding??.1);A=[O,z,I]}return{rfId:"1",width:a??0,height:o??0,transform:A,nodes:T,nodesInitialized:B,nodeLookup:b,parentLookup:y,edges:S,edgeLookup:j,connectionLookup:k,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:s!==void 0,panZoom:null,minZoom:u,maxZoom:f,translateExtent:uu,nodeExtent:E,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Nc.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:N,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:c??!1,fitViewOptions:d,fitViewResolver:null,connection:{...ZN},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:MK,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:XN,zIndexMode:x,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},hQ=({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:a,height:o,fitView:c,fitViewOptions:d,minZoom:u,maxZoom:f,nodeOrigin:h,nodeExtent:p,zIndexMode:x})=>RX((b,y)=>{async function k(){const{nodeLookup:j,panZoom:S,fitViewOptions:T,fitViewResolver:N,width:E,height:B,minZoom:A,maxZoom:H}=y();S&&(await AK({nodes:j,width:E,height:B,panZoom:S,minZoom:A,maxZoom:H},T),N?.resolve(!0),b({fitViewResolver:null}))}return{...X3({nodes:e,edges:t,width:a,height:o,fitView:c,fitViewOptions:d,minZoom:u,maxZoom:f,nodeOrigin:h,nodeExtent:p,defaultNodes:n,defaultEdges:s,zIndexMode:x}),setNodes:j=>{const{nodeLookup:S,parentLookup:T,nodeOrigin:N,elevateNodesOnSelect:E,fitViewQueued:B,zIndexMode:A}=y(),H=Wx(j,S,T,{nodeOrigin:N,nodeExtent:p,elevateNodesOnSelect:E,checkEquality:!0,zIndexMode:A});B&&H?(k(),b({nodes:j,nodesInitialized:H,fitViewQueued:!1,fitViewOptions:void 0})):b({nodes:j,nodesInitialized:H})},setEdges:j=>{const{connectionLookup:S,edgeLookup:T}=y();pS(S,T,j),b({edges:j})},setDefaultNodesAndEdges:(j,S)=>{if(j){const{setNodes:T}=y();T(j),b({hasDefaultNodes:!0})}if(S){const{setEdges:T}=y();T(S),b({hasDefaultEdges:!0})}},updateNodeInternals:j=>{const{triggerNodeChanges:S,nodeLookup:T,parentLookup:N,domNode:E,nodeOrigin:B,nodeExtent:A,debug:H,fitViewQueued:O,zIndexMode:z}=y(),{changes:I,updatedInternals:_}=QK(j,T,N,E,B,A,z);_&&(WK(T,N,{nodeOrigin:B,nodeExtent:A,zIndexMode:z}),O?(k(),b({fitViewQueued:!1,fitViewOptions:void 0})):b({}),I?.length>0&&(H&&console.log("React Flow: trigger node changes",I),S?.(I)))},updateNodePositions:(j,S=!1)=>{const T=[];let N=[];const{nodeLookup:E,triggerNodeChanges:B,connection:A,updateConnection:H,onNodesChangeMiddlewareMap:O}=y();for(const[z,I]of j){const _=E.get(z),X=!!(_?.expandParent&&_?.parentId&&I?.position),G={id:z,type:"position",position:X?{x:Math.max(0,I.position.x),y:Math.max(0,I.position.y)}:I.position,dragging:S};if(_&&A.inProgress&&A.fromNode.id===_.id){const M=gl(_,A.fromHandle,_t.Left,!0);H({...A,from:M})}X&&_.parentId&&T.push({id:z,parentId:_.parentId,rect:{...I.internals.positionAbsolute,width:I.measured.width??0,height:I.measured.height??0}}),N.push(G)}if(T.length>0){const{parentLookup:z,nodeOrigin:I}=y(),_=c1(T,E,z,I);N.push(..._)}for(const z of O.values())N=z(N);B(N)},triggerNodeChanges:j=>{const{onNodesChange:S,setNodes:T,nodes:N,hasDefaultNodes:E,debug:B}=y();if(j?.length){if(E){const A=MS(j,N);T(A)}B&&console.log("React Flow: trigger node changes",j),S?.(j)}},triggerEdgeChanges:j=>{const{onEdgesChange:S,setEdges:T,edges:N,hasDefaultEdges:E,debug:B}=y();if(j?.length){if(E){const A=DS(j,N);T(A)}B&&console.log("React Flow: trigger edge changes",j),S?.(j)}},addSelectedNodes:j=>{const{multiSelectionActive:S,edgeLookup:T,nodeLookup:N,triggerNodeChanges:E,triggerEdgeChanges:B}=y();if(S){const A=j.map(H=>rl(H,!0));E(A);return}E(fc(N,new Set([...j]),!0)),B(fc(T))},addSelectedEdges:j=>{const{multiSelectionActive:S,edgeLookup:T,nodeLookup:N,triggerNodeChanges:E,triggerEdgeChanges:B}=y();if(S){const A=j.map(H=>rl(H,!0));B(A);return}B(fc(T,new Set([...j]))),E(fc(N,new Set,!0))},unselectNodesAndEdges:({nodes:j,edges:S}={})=>{const{edges:T,nodes:N,nodeLookup:E,triggerNodeChanges:B,triggerEdgeChanges:A}=y(),H=j||N,O=S||T,z=[];for(const _ of H){if(!_.selected)continue;const X=E.get(_.id);X&&(X.selected=!1),z.push(rl(_.id,!1))}const I=[];for(const _ of O)_.selected&&I.push(rl(_.id,!1));B(z),A(I)},setMinZoom:j=>{const{panZoom:S,maxZoom:T}=y();S?.setScaleExtent([j,T]),b({minZoom:j})},setMaxZoom:j=>{const{panZoom:S,minZoom:T}=y();S?.setScaleExtent([T,j]),b({maxZoom:j})},setTranslateExtent:j=>{y().panZoom?.setTranslateExtent(j),b({translateExtent:j})},resetSelectedElements:()=>{const{edges:j,nodes:S,triggerNodeChanges:T,triggerEdgeChanges:N,elementsSelectable:E}=y();if(!E)return;const B=S.reduce((H,O)=>O.selected?[...H,rl(O.id,!1)]:H,[]),A=j.reduce((H,O)=>O.selected?[...H,rl(O.id,!1)]:H,[]);T(B),N(A)},setNodeExtent:j=>{const{nodes:S,nodeLookup:T,parentLookup:N,nodeOrigin:E,elevateNodesOnSelect:B,nodeExtent:A,zIndexMode:H}=y();j[0][0]===A[0][0]&&j[0][1]===A[0][1]&&j[1][0]===A[1][0]&&j[1][1]===A[1][1]||(Wx(S,T,N,{nodeOrigin:E,nodeExtent:j,elevateNodesOnSelect:B,checkEquality:!1,zIndexMode:H}),b({nodeExtent:j}))},panBy:j=>{const{transform:S,width:T,height:N,panZoom:E,translateExtent:B}=y();return JK({delta:j,panZoom:E,transform:S,translateExtent:B,width:T,height:N})},setCenter:async(j,S,T)=>{const{width:N,height:E,maxZoom:B,panZoom:A}=y();if(!A)return Promise.resolve(!1);const H=typeof T?.zoom<"u"?T.zoom:B;return await A.setViewport({x:N/2-j*H,y:E/2-S*H,zoom:H},{duration:T?.duration,ease:T?.ease,interpolate:T?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{b({connection:{...ZN}})},updateConnection:j=>{b({connection:j})},reset:()=>b({...X3()})}},Object.is);function pQ({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:s,initialWidth:a,initialHeight:o,initialMinZoom:c,initialMaxZoom:d,initialFitViewOptions:u,fitView:f,nodeOrigin:h,nodeExtent:p,zIndexMode:x,children:b}){const[y]=v.useState(()=>hQ({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:a,height:o,fitView:f,minZoom:c,maxZoom:d,fitViewOptions:u,nodeOrigin:h,nodeExtent:p,zIndexMode:x}));return r.jsx(LX,{value:y,children:r.jsx(nZ,{children:b})})}function gQ({children:e,nodes:t,edges:n,defaultNodes:s,defaultEdges:a,width:o,height:c,fitView:d,fitViewOptions:u,minZoom:f,maxZoom:h,nodeOrigin:p,nodeExtent:x,zIndexMode:b}){return v.useContext(Em)?r.jsx(r.Fragment,{children:e}):r.jsx(pQ,{initialNodes:t,initialEdges:n,defaultNodes:s,defaultEdges:a,initialWidth:o,initialHeight:c,fitView:d,initialFitViewOptions:u,initialMinZoom:f,initialMaxZoom:h,nodeOrigin:p,nodeExtent:x,zIndexMode:b,children:e})}const xQ={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function bQ({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,className:a,nodeTypes:o,edgeTypes:c,onNodeClick:d,onEdgeClick:u,onInit:f,onMove:h,onMoveStart:p,onMoveEnd:x,onConnect:b,onConnectStart:y,onConnectEnd:k,onClickConnectStart:j,onClickConnectEnd:S,onNodeMouseEnter:T,onNodeMouseMove:N,onNodeMouseLeave:E,onNodeContextMenu:B,onNodeDoubleClick:A,onNodeDragStart:H,onNodeDrag:O,onNodeDragStop:z,onNodesDelete:I,onEdgesDelete:_,onDelete:X,onSelectionChange:G,onSelectionDragStart:M,onSelectionDrag:U,onSelectionDragStop:L,onSelectionContextMenu:F,onSelectionStart:Z,onSelectionEnd:Y,onBeforeDelete:D,connectionMode:P,connectionLineType:ee=No.Bezier,connectionLineStyle:$,connectionLineComponent:Q,connectionLineContainerStyle:q,deleteKeyCode:J="Backspace",selectionKeyCode:K="Shift",selectionOnDrag:re=!1,selectionMode:de=fu.Full,panActivationKeyCode:pe="Space",multiSelectionKeyCode:te=hu()?"Meta":"Control",zoomActivationKeyCode:we=hu()?"Meta":"Control",snapToGrid:ce,snapGrid:ge,onlyRenderVisibleElements:Ce=!1,selectNodesOnDrag:Be,nodesDraggable:Qe,autoPanOnNodeFocus:We,nodesConnectable:wt,nodesFocusable:bt,nodeOrigin:$t=AS,edgesFocusable:dt,edgesReconnectable:me,elementsSelectable:ve=!0,defaultViewport:Re=GX,minZoom:ke=.5,maxZoom:Pe=2,translateExtent:lt=uu,preventScrolling:at=!0,nodeExtent:gt,defaultMarkerColor:Ft="#b1b1b7",zoomOnScroll:Bt=!0,zoomOnPinch:tn=!0,panOnScroll:It=!1,panOnScrollSpeed:Pt=.5,panOnScrollMode:Nt=cl.Free,zoomOnDoubleClick:cn=!0,panOnDrag:Xt=!0,onPaneClick:pn,onPaneMouseEnter:On,onPaneMouseMove:rn,onPaneMouseLeave:xn,onPaneScroll:Gn,onPaneContextMenu:wn,paneClickDistance:An=1,nodeClickDistance:sn=0,children:Pn,onReconnect:Dn,onReconnectStart:Zt,onReconnectEnd:Sr,onEdgeContextMenu:Bn,onEdgeDoubleClick:zr,onEdgeMouseEnter:gr,onEdgeMouseMove:sr,onEdgeMouseLeave:fr,reconnectRadius:Cr=10,onNodesChange:$r,onEdgesChange:Ee,noDragClassName:Ke="nodrag",noWheelClassName:Ae="nowheel",noPanClassName:ot="nopan",fitView:ut,fitViewOptions:jt,connectOnClick:er,attributionPosition:Hn,proOptions:Tr,defaultEdgeOptions:Ar,elevateNodesOnSelect:fe=!0,elevateEdgesOnSelect:Fe=!1,disableKeyboardA11y:Xe=!1,autoPanOnConnect:ft,autoPanOnNodeDrag:pt,autoPanSpeed:Vt,connectionRadius:bn,isValidConnection:Wn,onError:yn,style:At,id:Ot,nodeDragThreshold:ns,connectionDragThreshold:Xr,viewport:Kn,onViewportChange:ar,width:Or,height:Xn,colorMode:un="light",debug:rs,onScroll:os,ariaLabelConfig:Ms,zIndexMode:ls="basic",...Ua},xr){const ps=Ot||"1",Zr=XX(un),Ks=v.useCallback(Er=>{Er.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),os?.(Er)},[os]);return r.jsx("div",{"data-testid":"rf__wrapper",...Ua,onScroll:Ks,style:{...At,...xQ},ref:xr,className:Kr(["react-flow",a,Zr]),id:Ot,role:"application",children:r.jsxs(gQ,{nodes:e,edges:t,width:Or,height:Xn,fitView:ut,fitViewOptions:jt,minZoom:ke,maxZoom:Pe,nodeOrigin:$t,nodeExtent:gt,zIndexMode:ls,children:[r.jsx(mQ,{onInit:f,onNodeClick:d,onEdgeClick:u,onNodeMouseEnter:T,onNodeMouseMove:N,onNodeMouseLeave:E,onNodeContextMenu:B,onNodeDoubleClick:A,nodeTypes:o,edgeTypes:c,connectionLineType:ee,connectionLineStyle:$,connectionLineComponent:Q,connectionLineContainerStyle:q,selectionKeyCode:K,selectionOnDrag:re,selectionMode:de,deleteKeyCode:J,multiSelectionKeyCode:te,panActivationKeyCode:pe,zoomActivationKeyCode:we,onlyRenderVisibleElements:Ce,defaultViewport:Re,translateExtent:lt,minZoom:ke,maxZoom:Pe,preventScrolling:at,zoomOnScroll:Bt,zoomOnPinch:tn,zoomOnDoubleClick:cn,panOnScroll:It,panOnScrollSpeed:Pt,panOnScrollMode:Nt,panOnDrag:Xt,onPaneClick:pn,onPaneMouseEnter:On,onPaneMouseMove:rn,onPaneMouseLeave:xn,onPaneScroll:Gn,onPaneContextMenu:wn,paneClickDistance:An,nodeClickDistance:sn,onSelectionContextMenu:F,onSelectionStart:Z,onSelectionEnd:Y,onReconnect:Dn,onReconnectStart:Zt,onReconnectEnd:Sr,onEdgeContextMenu:Bn,onEdgeDoubleClick:zr,onEdgeMouseEnter:gr,onEdgeMouseMove:sr,onEdgeMouseLeave:fr,reconnectRadius:Cr,defaultMarkerColor:Ft,noDragClassName:Ke,noWheelClassName:Ae,noPanClassName:ot,rfId:ps,disableKeyboardA11y:Xe,nodeExtent:gt,viewport:Kn,onViewportChange:ar}),r.jsx(KX,{nodes:e,edges:t,defaultNodes:n,defaultEdges:s,onConnect:b,onConnectStart:y,onConnectEnd:k,onClickConnectStart:j,onClickConnectEnd:S,nodesDraggable:Qe,autoPanOnNodeFocus:We,nodesConnectable:wt,nodesFocusable:bt,edgesFocusable:dt,edgesReconnectable:me,elementsSelectable:ve,elevateNodesOnSelect:fe,elevateEdgesOnSelect:Fe,minZoom:ke,maxZoom:Pe,nodeExtent:gt,onNodesChange:$r,onEdgesChange:Ee,snapToGrid:ce,snapGrid:ge,connectionMode:P,translateExtent:lt,connectOnClick:er,defaultEdgeOptions:Ar,fitView:ut,fitViewOptions:jt,onNodesDelete:I,onEdgesDelete:_,onDelete:X,onNodeDragStart:H,onNodeDrag:O,onNodeDragStop:z,onSelectionDrag:U,onSelectionDragStart:M,onSelectionDragStop:L,onMove:h,onMoveStart:p,onMoveEnd:x,noPanClassName:ot,nodeOrigin:$t,rfId:ps,autoPanOnConnect:ft,autoPanOnNodeDrag:pt,autoPanSpeed:Vt,onError:yn,connectionRadius:bn,isValidConnection:Wn,selectNodesOnDrag:Be,nodeDragThreshold:ns,connectionDragThreshold:Xr,onBeforeDelete:D,debug:rs,ariaLabelConfig:Ms,zIndexMode:ls}),r.jsx(VX,{onSelectionChange:G}),Pn,r.jsx(BX,{proOptions:Tr,position:Hn}),r.jsx($X,{rfId:ps,disableKeyboardA11y:Xe})]})})}var yQ=RS(bQ);function vQ(e){const[t,n]=v.useState(e),s=v.useCallback(a=>n(o=>MS(a,o)),[]);return[t,n,s]}function wQ(e){const[t,n]=v.useState(e),s=v.useCallback(a=>n(o=>DS(a,o)),[]);return[t,n,s]}function kQ({dimensions:e,lineWidth:t,variant:n,className:s}){return r.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Kr(["react-flow__background-pattern",n,s])})}function jQ({radius:e,className:t}){return r.jsx("circle",{cx:e,cy:e,r:e,className:Kr(["react-flow__background-pattern","dots",t])})}var To;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(To||(To={}));const NQ={[To.Dots]:1,[To.Lines]:1,[To.Cross]:6},SQ=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function n7({id:e,variant:t=To.Dots,gap:n=20,size:s,lineWidth:a=1,offset:o=0,color:c,bgColor:d,style:u,className:f,patternClassName:h}){const p=v.useRef(null),{transform:x,patternId:b}=Ln(SQ,vr),y=s||NQ[t],k=t===To.Dots,j=t===To.Cross,S=Array.isArray(n)?n:[n,n],T=[S[0]*x[2]||1,S[1]*x[2]||1],N=y*x[2],E=Array.isArray(o)?o:[o,o],B=j?[N,N]:T,A=[E[0]*x[2]||1+B[0]/2,E[1]*x[2]||1+B[1]/2],H=`${b}${e||""}`;return r.jsxs("svg",{className:Kr(["react-flow__background",f]),style:{...u,...Dm,"--xy-background-color-props":d,"--xy-background-pattern-color-props":c},ref:p,"data-testid":"rf__background",children:[r.jsx("pattern",{id:H,x:x[0]%T[0],y:x[1]%T[1],width:T[0],height:T[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${A[0]},-${A[1]})`,children:k?r.jsx(jQ,{radius:N/2,className:h}):r.jsx(kQ,{dimensions:B,lineWidth:a,variant:t,className:h})}),r.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${H})`})]})}n7.displayName="Background";const CQ=v.memo(n7);function TQ(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:r.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function AQ(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:r.jsx("path",{d:"M0 0h32v4.2H0z"})})}function EQ(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:r.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 MQ(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:r.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 DQ(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:r.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 af({children:e,className:t,...n}){return r.jsx("button",{type:"button",className:Kr(["react-flow__controls-button",t]),...n,children:e})}const RQ=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function r7({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:s=!0,fitViewOptions:a,onZoomIn:o,onZoomOut:c,onFitView:d,onInteractiveChange:u,className:f,children:h,position:p="bottom-left",orientation:x="vertical","aria-label":b}){const y=kr(),{isInteractive:k,minZoomReached:j,maxZoomReached:S,ariaLabelConfig:T}=Ln(RQ,vr),{zoomIn:N,zoomOut:E,fitView:B}=d1(),A=()=>{N(),o?.()},H=()=>{E(),c?.()},O=()=>{B(a),d?.()},z=()=>{y.setState({nodesDraggable:!k,nodesConnectable:!k,elementsSelectable:!k}),u?.(!k)},I=x==="horizontal"?"horizontal":"vertical";return r.jsxs(Mm,{className:Kr(["react-flow__controls",I,f]),position:p,style:e,"data-testid":"rf__controls","aria-label":b??T["controls.ariaLabel"],children:[t&&r.jsxs(r.Fragment,{children:[r.jsx(af,{onClick:A,className:"react-flow__controls-zoomin",title:T["controls.zoomIn.ariaLabel"],"aria-label":T["controls.zoomIn.ariaLabel"],disabled:S,children:r.jsx(TQ,{})}),r.jsx(af,{onClick:H,className:"react-flow__controls-zoomout",title:T["controls.zoomOut.ariaLabel"],"aria-label":T["controls.zoomOut.ariaLabel"],disabled:j,children:r.jsx(AQ,{})})]}),n&&r.jsx(af,{className:"react-flow__controls-fitview",onClick:O,title:T["controls.fitView.ariaLabel"],"aria-label":T["controls.fitView.ariaLabel"],children:r.jsx(EQ,{})}),s&&r.jsx(af,{className:"react-flow__controls-interactive",onClick:z,title:T["controls.interactive.ariaLabel"],"aria-label":T["controls.interactive.ariaLabel"],children:k?r.jsx(DQ,{}):r.jsx(MQ,{})}),h]})}r7.displayName="Controls";const LQ=v.memo(r7);function OQ({id:e,x:t,y:n,width:s,height:a,style:o,color:c,strokeColor:d,strokeWidth:u,className:f,borderRadius:h,shapeRendering:p,selected:x,onClick:b}){const{background:y,backgroundColor:k}=o||{},j=c||y||k;return r.jsx("rect",{className:Kr(["react-flow__minimap-node",{selected:x},f]),x:t,y:n,rx:h,ry:h,width:s,height:a,style:{fill:j,stroke:d,strokeWidth:u},shapeRendering:p,onClick:b?S=>b(S,e):void 0})}const _Q=v.memo(OQ),IQ=e=>e.nodes.map(t=>t.id),Hg=e=>e instanceof Function?e:()=>e;function PQ({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:s=5,nodeStrokeWidth:a,nodeComponent:o=_Q,onClick:c}){const d=Ln(IQ,vr),u=Hg(t),f=Hg(e),h=Hg(n),p=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return r.jsx(r.Fragment,{children:d.map(x=>r.jsx($Q,{id:x,nodeColorFunc:u,nodeStrokeColorFunc:f,nodeClassNameFunc:h,nodeBorderRadius:s,nodeStrokeWidth:a,NodeComponent:o,onClick:c,shapeRendering:p},x))})}function zQ({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:s,nodeBorderRadius:a,nodeStrokeWidth:o,shapeRendering:c,NodeComponent:d,onClick:u}){const{node:f,x:h,y:p,width:x,height:b}=Ln(y=>{const k=y.nodeLookup.get(e);if(!k)return{node:void 0,x:0,y:0,width:0,height:0};const j=k.internals.userNode,{x:S,y:T}=k.internals.positionAbsolute,{width:N,height:E}=Yi(j);return{node:j,x:S,y:T,width:N,height:E}},vr);return!f||f.hidden||!sS(f)?null:r.jsx(d,{x:h,y:p,width:x,height:b,style:f.style,selected:!!f.selected,className:s(f),color:t(f),borderRadius:a,strokeColor:n(f),strokeWidth:o,shapeRendering:c,onClick:u,id:f.id})}const $Q=v.memo(zQ);var BQ=v.memo(PQ);const HQ=200,qQ=150,FQ=e=>!e.hidden,UQ=e=>{const t={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:t,boundingRect:e.nodeLookup.size>0?rS(Au(e.nodeLookup,{filter:FQ}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},VQ="react-flow__minimap-desc";function s7({style:e,className:t,nodeStrokeColor:n,nodeColor:s,nodeClassName:a="",nodeBorderRadius:o=5,nodeStrokeWidth:c,nodeComponent:d,bgColor:u,maskColor:f,maskStrokeColor:h,maskStrokeWidth:p,position:x="bottom-right",onClick:b,onNodeClick:y,pannable:k=!1,zoomable:j=!1,ariaLabel:S,inversePan:T,zoomStep:N=1,offsetScale:E=5}){const B=kr(),A=v.useRef(null),{boundingRect:H,viewBB:O,rfId:z,panZoom:I,translateExtent:_,flowWidth:X,flowHeight:G,ariaLabelConfig:M}=Ln(UQ,vr),U=e?.width??HQ,L=e?.height??qQ,F=H.width/U,Z=H.height/L,Y=Math.max(F,Z),D=Y*U,P=Y*L,ee=E*Y,$=H.x-(D-H.width)/2-ee,Q=H.y-(P-H.height)/2-ee,q=D+ee*2,J=P+ee*2,K=`${VQ}-${z}`,re=v.useRef(0),de=v.useRef();re.current=Y,v.useEffect(()=>{if(A.current&&I)return de.current=lX({domNode:A.current,panZoom:I,getTransform:()=>B.getState().transform,getViewScale:()=>re.current}),()=>{de.current?.destroy()}},[I]),v.useEffect(()=>{de.current?.update({translateExtent:_,width:X,height:G,inversePan:T,pannable:k,zoomStep:N,zoomable:j})},[k,j,T,N,_,X,G]);const pe=b?ce=>{const[ge,Ce]=de.current?.pointer(ce)||[0,0];b(ce,{x:ge,y:Ce})}:void 0,te=y?v.useCallback((ce,ge)=>{const Ce=B.getState().nodeLookup.get(ge).internals.userNode;y(ce,Ce)},[]):void 0,we=S??M["minimap.ariaLabel"];return r.jsx(Mm,{position:x,style:{...e,"--xy-minimap-background-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-background-color-props":typeof f=="string"?f:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof p=="number"?p*Y:void 0,"--xy-minimap-node-background-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof c=="number"?c:void 0},className:Kr(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:r.jsxs("svg",{width:U,height:L,viewBox:`${$} ${Q} ${q} ${J}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":K,ref:A,onClick:pe,children:[we&&r.jsx("title",{id:K,children:we}),r.jsx(BQ,{onClick:te,nodeColor:s,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:a,nodeStrokeWidth:c,nodeComponent:d}),r.jsx("path",{className:"react-flow__minimap-mask",d:`M${$-ee},${Q-ee}h${q+ee*2}v${J+ee*2}h${-q-ee*2}z
349
349
  M${O.x},${O.y}h${O.width}v${O.height}h${-O.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}s7.displayName="MiniMap";const GQ=v.memo(s7),YQ=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,WQ={[Ec.Line]:"right",[Ec.Handle]:"bottom-right"};function KQ({nodeId:e,position:t,variant:n=Ec.Handle,className:s,style:a=void 0,children:o,color:c,minWidth:d=10,minHeight:u=10,maxWidth:f=Number.MAX_VALUE,maxHeight:h=Number.MAX_VALUE,keepAspectRatio:p=!1,resizeDirection:x,autoScale:b=!0,shouldResize:y,onResizeStart:k,onResize:j,onResizeEnd:S}){const T=IS(),N=typeof e=="string"?e:T,E=kr(),B=v.useRef(null),A=n===Ec.Handle,H=Ln(v.useCallback(YQ(A&&b),[A,b]),vr),O=v.useRef(null),z=t??WQ[n];v.useEffect(()=>{if(!(!B.current||!N))return O.current||(O.current=kX({domNode:B.current,nodeId:N,getStoreItems:()=>{const{nodeLookup:_,transform:X,snapGrid:G,snapToGrid:M,nodeOrigin:U,domNode:L}=E.getState();return{nodeLookup:_,transform:X,snapGrid:G,snapToGrid:M,nodeOrigin:U,paneDomNode:L}},onChange:(_,X)=>{const{triggerNodeChanges:G,nodeLookup:M,parentLookup:U,nodeOrigin:L}=E.getState(),F=[],Z={x:_.x,y:_.y},Y=M.get(N);if(Y&&Y.expandParent&&Y.parentId){const D=Y.origin??L,P=_.width??Y.measured.width??0,ee=_.height??Y.measured.height??0,$={id:Y.id,parentId:Y.parentId,rect:{width:P,height:ee,...aS({x:_.x??Y.position.x,y:_.y??Y.position.y},{width:P,height:ee},Y.parentId,M,D)}},Q=c1([$],M,U,L);F.push(...Q),Z.x=_.x?Math.max(D[0]*P,_.x):void 0,Z.y=_.y?Math.max(D[1]*ee,_.y):void 0}if(Z.x!==void 0&&Z.y!==void 0){const D={id:N,type:"position",position:{...Z}};F.push(D)}if(_.width!==void 0&&_.height!==void 0){const P={id:N,type:"dimensions",resizing:!0,setAttributes:x?x==="horizontal"?"width":"height":!0,dimensions:{width:_.width,height:_.height}};F.push(P)}for(const D of X){const P={...D,type:"position"};F.push(P)}G(F)},onEnd:({width:_,height:X})=>{const G={id:N,type:"dimensions",resizing:!1,dimensions:{width:_,height:X}};E.getState().triggerNodeChanges([G])}})),O.current.update({controlPosition:z,boundaries:{minWidth:d,minHeight:u,maxWidth:f,maxHeight:h},keepAspectRatio:p,resizeDirection:x,onResizeStart:k,onResize:j,onResizeEnd:S,shouldResize:y}),()=>{O.current?.destroy()}},[z,d,u,f,h,p,k,j,S,y]);const I=z.split("-");return r.jsx("div",{className:Kr(["react-flow__resize-control","nodrag",...I,n,s]),ref:B,style:{...a,scale:H,...c&&{[A?"backgroundColor":"borderColor"]:c}},children:o})}v.memo(KQ);var Jn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),qa=Jn((e,t)=>{var n=Object.defineProperty,s=(G,M,U)=>M in G?n(G,M,{enumerable:!0,configurable:!0,writable:!0,value:U}):G[M]=U,a=(G,M)=>()=>(M||G((M={exports:{}}).exports,M),M.exports),o=(G,M,U)=>s(G,typeof M!="symbol"?M+"":M,U),c=a((G,M)=>{var U="\0",L="\0",F="",Z=class{constructor(Q){o(this,"_isDirected",!0),o(this,"_isMultigraph",!1),o(this,"_isCompound",!1),o(this,"_label"),o(this,"_defaultNodeLabelFn",()=>{}),o(this,"_defaultEdgeLabelFn",()=>{}),o(this,"_nodes",{}),o(this,"_in",{}),o(this,"_preds",{}),o(this,"_out",{}),o(this,"_sucs",{}),o(this,"_edgeObjs",{}),o(this,"_edgeLabels",{}),o(this,"_nodeCount",0),o(this,"_edgeCount",0),o(this,"_parent"),o(this,"_children"),Q&&(this._isDirected=Object.hasOwn(Q,"directed")?Q.directed:!0,this._isMultigraph=Object.hasOwn(Q,"multigraph")?Q.multigraph:!1,this._isCompound=Object.hasOwn(Q,"compound")?Q.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[L]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(Q){return this._label=Q,this}graph(){return this._label}setDefaultNodeLabel(Q){return this._defaultNodeLabelFn=Q,typeof Q!="function"&&(this._defaultNodeLabelFn=()=>Q),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var Q=this;return this.nodes().filter(q=>Object.keys(Q._in[q]).length===0)}sinks(){var Q=this;return this.nodes().filter(q=>Object.keys(Q._out[q]).length===0)}setNodes(Q,q){var J=arguments,K=this;return Q.forEach(function(re){J.length>1?K.setNode(re,q):K.setNode(re)}),this}setNode(Q,q){return Object.hasOwn(this._nodes,Q)?(arguments.length>1&&(this._nodes[Q]=q),this):(this._nodes[Q]=arguments.length>1?q:this._defaultNodeLabelFn(Q),this._isCompound&&(this._parent[Q]=L,this._children[Q]={},this._children[L][Q]=!0),this._in[Q]={},this._preds[Q]={},this._out[Q]={},this._sucs[Q]={},++this._nodeCount,this)}node(Q){return this._nodes[Q]}hasNode(Q){return Object.hasOwn(this._nodes,Q)}removeNode(Q){var q=this;if(Object.hasOwn(this._nodes,Q)){var J=K=>q.removeEdge(q._edgeObjs[K]);delete this._nodes[Q],this._isCompound&&(this._removeFromParentsChildList(Q),delete this._parent[Q],this.children(Q).forEach(function(K){q.setParent(K)}),delete this._children[Q]),Object.keys(this._in[Q]).forEach(J),delete this._in[Q],delete this._preds[Q],Object.keys(this._out[Q]).forEach(J),delete this._out[Q],delete this._sucs[Q],--this._nodeCount}return this}setParent(Q,q){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(q===void 0)q=L;else{q+="";for(var J=q;J!==void 0;J=this.parent(J))if(J===Q)throw new Error("Setting "+q+" as parent of "+Q+" would create a cycle");this.setNode(q)}return this.setNode(Q),this._removeFromParentsChildList(Q),this._parent[Q]=q,this._children[q][Q]=!0,this}_removeFromParentsChildList(Q){delete this._children[this._parent[Q]][Q]}parent(Q){if(this._isCompound){var q=this._parent[Q];if(q!==L)return q}}children(Q=L){if(this._isCompound){var q=this._children[Q];if(q)return Object.keys(q)}else{if(Q===L)return this.nodes();if(this.hasNode(Q))return[]}}predecessors(Q){var q=this._preds[Q];if(q)return Object.keys(q)}successors(Q){var q=this._sucs[Q];if(q)return Object.keys(q)}neighbors(Q){var q=this.predecessors(Q);if(q){let K=new Set(q);for(var J of this.successors(Q))K.add(J);return Array.from(K.values())}}isLeaf(Q){var q;return this.isDirected()?q=this.successors(Q):q=this.neighbors(Q),q.length===0}filterNodes(Q){var q=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});q.setGraph(this.graph());var J=this;Object.entries(this._nodes).forEach(function([de,pe]){Q(de)&&q.setNode(de,pe)}),Object.values(this._edgeObjs).forEach(function(de){q.hasNode(de.v)&&q.hasNode(de.w)&&q.setEdge(de,J.edge(de))});var K={};function re(de){var pe=J.parent(de);return pe===void 0||q.hasNode(pe)?(K[de]=pe,pe):pe in K?K[pe]:re(pe)}return this._isCompound&&q.nodes().forEach(de=>q.setParent(de,re(de))),q}setDefaultEdgeLabel(Q){return this._defaultEdgeLabelFn=Q,typeof Q!="function"&&(this._defaultEdgeLabelFn=()=>Q),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(Q,q){var J=this,K=arguments;return Q.reduce(function(re,de){return K.length>1?J.setEdge(re,de,q):J.setEdge(re,de),de}),this}setEdge(){var Q,q,J,K,re=!1,de=arguments[0];typeof de=="object"&&de!==null&&"v"in de?(Q=de.v,q=de.w,J=de.name,arguments.length===2&&(K=arguments[1],re=!0)):(Q=de,q=arguments[1],J=arguments[3],arguments.length>2&&(K=arguments[2],re=!0)),Q=""+Q,q=""+q,J!==void 0&&(J=""+J);var pe=P(this._isDirected,Q,q,J);if(Object.hasOwn(this._edgeLabels,pe))return re&&(this._edgeLabels[pe]=K),this;if(J!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(Q),this.setNode(q),this._edgeLabels[pe]=re?K:this._defaultEdgeLabelFn(Q,q,J);var te=ee(this._isDirected,Q,q,J);return Q=te.v,q=te.w,Object.freeze(te),this._edgeObjs[pe]=te,Y(this._preds[q],Q),Y(this._sucs[Q],q),this._in[q][pe]=te,this._out[Q][pe]=te,this._edgeCount++,this}edge(Q,q,J){var K=arguments.length===1?$(this._isDirected,arguments[0]):P(this._isDirected,Q,q,J);return this._edgeLabels[K]}edgeAsObj(){let Q=this.edge(...arguments);return typeof Q!="object"?{label:Q}:Q}hasEdge(Q,q,J){var K=arguments.length===1?$(this._isDirected,arguments[0]):P(this._isDirected,Q,q,J);return Object.hasOwn(this._edgeLabels,K)}removeEdge(Q,q,J){var K=arguments.length===1?$(this._isDirected,arguments[0]):P(this._isDirected,Q,q,J),re=this._edgeObjs[K];return re&&(Q=re.v,q=re.w,delete this._edgeLabels[K],delete this._edgeObjs[K],D(this._preds[q],Q),D(this._sucs[Q],q),delete this._in[q][K],delete this._out[Q][K],this._edgeCount--),this}inEdges(Q,q){return this.isDirected()?this.filterEdges(this._in[Q],Q,q):this.nodeEdges(Q,q)}outEdges(Q,q){return this.isDirected()?this.filterEdges(this._out[Q],Q,q):this.nodeEdges(Q,q)}nodeEdges(Q,q){if(Q in this._nodes)return this.filterEdges({...this._in[Q],...this._out[Q]},Q,q)}filterEdges(Q,q,J){if(Q){var K=Object.values(Q);return J?K.filter(function(re){return re.v===q&&re.w===J||re.v===J&&re.w===q}):K}}};function Y(Q,q){Q[q]?Q[q]++:Q[q]=1}function D(Q,q){--Q[q]||delete Q[q]}function P(Q,q,J,K){var re=""+q,de=""+J;if(!Q&&re>de){var pe=re;re=de,de=pe}return re+F+de+F+(K===void 0?U:K)}function ee(Q,q,J,K){var re=""+q,de=""+J;if(!Q&&re>de){var pe=re;re=de,de=pe}var te={v:re,w:de};return K&&(te.name=K),te}function $(Q,q){return P(Q,q.v,q.w,q.name)}M.exports=Z}),d=a((G,M)=>{M.exports="3.0.2"}),u=a((G,M)=>{M.exports={Graph:c(),version:d()}}),f=a((G,M)=>{var U=c();M.exports={write:L,read:Y};function L(D){var P={options:{directed:D.isDirected(),multigraph:D.isMultigraph(),compound:D.isCompound()},nodes:F(D),edges:Z(D)};return D.graph()!==void 0&&(P.value=structuredClone(D.graph())),P}function F(D){return D.nodes().map(function(P){var ee=D.node(P),$=D.parent(P),Q={v:P};return ee!==void 0&&(Q.value=ee),$!==void 0&&(Q.parent=$),Q})}function Z(D){return D.edges().map(function(P){var ee=D.edge(P),$={v:P.v,w:P.w};return P.name!==void 0&&($.name=P.name),ee!==void 0&&($.value=ee),$})}function Y(D){var P=new U(D.options).setGraph(D.value);return D.nodes.forEach(function(ee){P.setNode(ee.v,ee.value),ee.parent&&P.setParent(ee.v,ee.parent)}),D.edges.forEach(function(ee){P.setEdge({v:ee.v,w:ee.w,name:ee.name},ee.value)}),P}}),h=a((G,M)=>{M.exports=L;var U=()=>1;function L(Z,Y,D,P){return F(Z,String(Y),D||U,P||function(ee){return Z.outEdges(ee)})}function F(Z,Y,D,P){var ee={},$=!0,Q=0,q=Z.nodes(),J=function(pe){var te=D(pe);ee[pe.v].distance+te<ee[pe.w].distance&&(ee[pe.w]={distance:ee[pe.v].distance+te,predecessor:pe.v},$=!0)},K=function(){q.forEach(function(pe){P(pe).forEach(function(te){var we=te.v===pe?te.v:te.w,ce=we===te.v?te.w:te.v;J({v:we,w:ce})})})};q.forEach(function(pe){var te=pe===Y?0:Number.POSITIVE_INFINITY;ee[pe]={distance:te}});for(var re=q.length,de=1;de<re&&($=!1,Q++,K(),!!$);de++);if(Q===re-1&&($=!1,K(),$))throw new Error("The graph contains a negative weight cycle");return ee}}),p=a((G,M)=>{M.exports=U;function U(L){var F={},Z=[],Y;function D(P){Object.hasOwn(F,P)||(F[P]=!0,Y.push(P),L.successors(P).forEach(D),L.predecessors(P).forEach(D))}return L.nodes().forEach(function(P){Y=[],D(P),Y.length&&Z.push(Y)}),Z}}),x=a((G,M)=>{var U=class{constructor(){o(this,"_arr",[]),o(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(L){return L.key})}has(L){return Object.hasOwn(this._keyIndices,L)}priority(L){var F=this._keyIndices[L];if(F!==void 0)return this._arr[F].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(L,F){var Z=this._keyIndices;if(L=String(L),!Object.hasOwn(Z,L)){var Y=this._arr,D=Y.length;return Z[L]=D,Y.push({key:L,priority:F}),this._decrease(D),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var L=this._arr.pop();return delete this._keyIndices[L.key],this._heapify(0),L.key}decrease(L,F){var Z=this._keyIndices[L];if(F>this._arr[Z].priority)throw new Error("New priority is greater than current priority. Key: "+L+" Old: "+this._arr[Z].priority+" New: "+F);this._arr[Z].priority=F,this._decrease(Z)}_heapify(L){var F=this._arr,Z=2*L,Y=Z+1,D=L;Z<F.length&&(D=F[Z].priority<F[D].priority?Z:D,Y<F.length&&(D=F[Y].priority<F[D].priority?Y:D),D!==L&&(this._swap(L,D),this._heapify(D)))}_decrease(L){for(var F=this._arr,Z=F[L].priority,Y;L!==0&&(Y=L>>1,!(F[Y].priority<Z));)this._swap(L,Y),L=Y}_swap(L,F){var Z=this._arr,Y=this._keyIndices,D=Z[L],P=Z[F];Z[L]=P,Z[F]=D,Y[P.key]=L,Y[D.key]=F}};M.exports=U}),b=a((G,M)=>{var U=x();M.exports=F;var L=()=>1;function F(Y,D,P,ee){var $=function(Q){return Y.outEdges(Q)};return Z(Y,String(D),P||L,ee||$)}function Z(Y,D,P,ee){var $={},Q=new U,q,J,K=function(re){var de=re.v!==q?re.v:re.w,pe=$[de],te=P(re),we=J.distance+te;if(te<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+re+" Weight: "+te);we<pe.distance&&(pe.distance=we,pe.predecessor=q,Q.decrease(de,we))};for(Y.nodes().forEach(function(re){var de=re===D?0:Number.POSITIVE_INFINITY;$[re]={distance:de},Q.add(re,de)});Q.size()>0&&(q=Q.removeMin(),J=$[q],J.distance!==Number.POSITIVE_INFINITY);)ee(q).forEach(K);return $}}),y=a((G,M)=>{var U=b();M.exports=L;function L(F,Z,Y){return F.nodes().reduce(function(D,P){return D[P]=U(F,P,Z,Y),D},{})}}),k=a((G,M)=>{M.exports=U;function U(F,Z,Y){if(F[Z].predecessor!==void 0)throw new Error("Invalid source vertex");if(F[Y].predecessor===void 0&&Y!==Z)throw new Error("Invalid destination vertex");return{weight:F[Y].distance,path:L(F,Z,Y)}}function L(F,Z,Y){for(var D=[],P=Y;P!==Z;)D.push(P),P=F[P].predecessor;return D.push(Z),D.reverse()}}),j=a((G,M)=>{M.exports=U;function U(L){var F=0,Z=[],Y={},D=[];function P(ee){var $=Y[ee]={onStack:!0,lowlink:F,index:F++};if(Z.push(ee),L.successors(ee).forEach(function(J){Object.hasOwn(Y,J)?Y[J].onStack&&($.lowlink=Math.min($.lowlink,Y[J].index)):(P(J),$.lowlink=Math.min($.lowlink,Y[J].lowlink))}),$.lowlink===$.index){var Q=[],q;do q=Z.pop(),Y[q].onStack=!1,Q.push(q);while(ee!==q);D.push(Q)}}return L.nodes().forEach(function(ee){Object.hasOwn(Y,ee)||P(ee)}),D}}),S=a((G,M)=>{var U=j();M.exports=L;function L(F){return U(F).filter(function(Z){return Z.length>1||Z.length===1&&F.hasEdge(Z[0],Z[0])})}}),T=a((G,M)=>{M.exports=L;var U=()=>1;function L(Z,Y,D){return F(Z,Y||U,D||function(P){return Z.outEdges(P)})}function F(Z,Y,D){var P={},ee=Z.nodes();return ee.forEach(function($){P[$]={},P[$][$]={distance:0},ee.forEach(function(Q){$!==Q&&(P[$][Q]={distance:Number.POSITIVE_INFINITY})}),D($).forEach(function(Q){var q=Q.v===$?Q.w:Q.v,J=Y(Q);P[$][q]={distance:J,predecessor:$}})}),ee.forEach(function($){var Q=P[$];ee.forEach(function(q){var J=P[q];ee.forEach(function(K){var re=J[$],de=Q[K],pe=J[K],te=re.distance+de.distance;te<pe.distance&&(pe.distance=te,pe.predecessor=de.predecessor)})})}),P}}),N=a((G,M)=>{function U(F){var Z={},Y={},D=[];function P(ee){if(Object.hasOwn(Y,ee))throw new L;Object.hasOwn(Z,ee)||(Y[ee]=!0,Z[ee]=!0,F.predecessors(ee).forEach(P),delete Y[ee],D.push(ee))}if(F.sinks().forEach(P),Object.keys(Z).length!==F.nodeCount())throw new L;return D}var L=class extends Error{constructor(){super(...arguments)}};M.exports=U,U.CycleException=L}),E=a((G,M)=>{var U=N();M.exports=L;function L(F){try{U(F)}catch(Z){if(Z instanceof U.CycleException)return!1;throw Z}return!0}}),B=a((G,M)=>{M.exports=U;function U(F,Z,Y,D,P){Array.isArray(Z)||(Z=[Z]);var ee=(F.isDirected()?F.successors:F.neighbors).bind(F),$={};return Z.forEach(function(Q){if(!F.hasNode(Q))throw new Error("Graph does not have node: "+Q);P=L(F,Q,Y==="post",$,ee,D,P)}),P}function L(F,Z,Y,D,P,ee,$){return Object.hasOwn(D,Z)||(D[Z]=!0,Y||($=ee($,Z)),P(Z).forEach(function(Q){$=L(F,Q,Y,D,P,ee,$)}),Y&&($=ee($,Z))),$}}),A=a((G,M)=>{var U=B();M.exports=L;function L(F,Z,Y){return U(F,Z,Y,function(D,P){return D.push(P),D},[])}}),H=a((G,M)=>{var U=A();M.exports=L;function L(F,Z){return U(F,Z,"post")}}),O=a((G,M)=>{var U=A();M.exports=L;function L(F,Z){return U(F,Z,"pre")}}),z=a((G,M)=>{var U=c(),L=x();M.exports=F;function F(Z,Y){var D=new U,P={},ee=new L,$;function Q(J){var K=J.v===$?J.w:J.v,re=ee.priority(K);if(re!==void 0){var de=Y(J);de<re&&(P[K]=$,ee.decrease(K,de))}}if(Z.nodeCount()===0)return D;Z.nodes().forEach(function(J){ee.add(J,Number.POSITIVE_INFINITY),D.setNode(J)}),ee.decrease(Z.nodes()[0],0);for(var q=!1;ee.size()>0;){if($=ee.removeMin(),Object.hasOwn(P,$))D.setEdge($,P[$]);else{if(q)throw new Error("Input graph is not connected: "+Z);q=!0}Z.nodeEdges($).forEach(Q)}return D}}),I=a((G,M)=>{var U=b(),L=h();M.exports=F;function F(Y,D,P,ee){return Z(Y,D,P,ee||function($){return Y.outEdges($)})}function Z(Y,D,P,ee){if(P===void 0)return U(Y,D,P,ee);for(var $=!1,Q=Y.nodes(),q=0;q<Q.length;q++){for(var J=ee(Q[q]),K=0;K<J.length;K++){var re=J[K],de=re.v===Q[q]?re.v:re.w,pe=de===re.v?re.w:re.v;P({v:de,w:pe})<0&&($=!0)}if($)return L(Y,D,P,ee)}return U(Y,D,P,ee)}}),_=a((G,M)=>{M.exports={bellmanFord:h(),components:p(),dijkstra:b(),dijkstraAll:y(),extractPath:k(),findCycles:S(),floydWarshall:T(),isAcyclic:E(),postorder:H(),preorder:O(),prim:z(),shortestPaths:I(),reduce:B(),tarjan:j(),topsort:N()}}),X=u();t.exports={Graph:X.Graph,json:f(),alg:_(),version:X.version}}),XQ=Jn((e,t)=>{var n=class{constructor(){let o={};o._next=o._prev=o,this._sentinel=o}dequeue(){let o=this._sentinel,c=o._prev;if(c!==o)return s(c),c}enqueue(o){let c=this._sentinel;o._prev&&o._next&&s(o),o._next=c._next,c._next._prev=o,c._next=o,o._prev=c}toString(){let o=[],c=this._sentinel,d=c._prev;for(;d!==c;)o.push(JSON.stringify(d,a)),d=d._prev;return"["+o.join(", ")+"]"}};function s(o){o._prev._next=o._next,o._next._prev=o._prev,delete o._next,delete o._prev}function a(o,c){if(o!=="_next"&&o!=="_prev")return c}t.exports=n}),ZQ=Jn((e,t)=>{var n=qa().Graph,s=XQ();t.exports=o;var a=()=>1;function o(p,x){if(p.nodeCount()<=1)return[];let b=u(p,x||a);return c(b.graph,b.buckets,b.zeroIdx).flatMap(y=>p.outEdges(y.v,y.w))}function c(p,x,b){let y=[],k=x[x.length-1],j=x[0],S;for(;p.nodeCount();){for(;S=j.dequeue();)d(p,x,b,S);for(;S=k.dequeue();)d(p,x,b,S);if(p.nodeCount()){for(let T=x.length-2;T>0;--T)if(S=x[T].dequeue(),S){y=y.concat(d(p,x,b,S,!0));break}}}return y}function d(p,x,b,y,k){let j=k?[]:void 0;return p.inEdges(y.v).forEach(S=>{let T=p.edge(S),N=p.node(S.v);k&&j.push({v:S.v,w:S.w}),N.out-=T,f(x,b,N)}),p.outEdges(y.v).forEach(S=>{let T=p.edge(S),N=S.w,E=p.node(N);E.in-=T,f(x,b,E)}),p.removeNode(y.v),j}function u(p,x){let b=new n,y=0,k=0;p.nodes().forEach(T=>{b.setNode(T,{v:T,in:0,out:0})}),p.edges().forEach(T=>{let N=b.edge(T.v,T.w)||0,E=x(T),B=N+E;b.setEdge(T.v,T.w,B),k=Math.max(k,b.node(T.v).out+=E),y=Math.max(y,b.node(T.w).in+=E)});let j=h(k+y+3).map(()=>new s),S=y+1;return b.nodes().forEach(T=>{f(j,S,b.node(T))}),{graph:b,buckets:j,zeroIdx:S}}function f(p,x,b){b.out?b.in?p[b.out-b.in+x].enqueue(b):p[p.length-1].enqueue(b):p[0].enqueue(b)}function h(p){let x=[];for(let b=0;b<p;b++)x.push(b);return x}}),Yr=Jn((e,t)=>{var n=qa().Graph;t.exports={addBorderNode:x,addDummyNode:s,applyWithChunking:k,asNonCompoundGraph:o,buildLayerMatrix:f,intersectRect:u,mapValues:O,maxRank:j,normalizeRanks:h,notime:N,partition:S,pick:H,predecessorWeights:d,range:A,removeEmptyRanks:p,simplify:a,successorWeights:c,time:T,uniqueId:B,zipObject:z};function s(I,_,X,G){for(var M=G;I.hasNode(M);)M=B(G);return X.dummy=_,I.setNode(M,X),M}function a(I){let _=new n().setGraph(I.graph());return I.nodes().forEach(X=>_.setNode(X,I.node(X))),I.edges().forEach(X=>{let G=_.edge(X.v,X.w)||{weight:0,minlen:1},M=I.edge(X);_.setEdge(X.v,X.w,{weight:G.weight+M.weight,minlen:Math.max(G.minlen,M.minlen)})}),_}function o(I){let _=new n({multigraph:I.isMultigraph()}).setGraph(I.graph());return I.nodes().forEach(X=>{I.children(X).length||_.setNode(X,I.node(X))}),I.edges().forEach(X=>{_.setEdge(X,I.edge(X))}),_}function c(I){let _=I.nodes().map(X=>{let G={};return I.outEdges(X).forEach(M=>{G[M.w]=(G[M.w]||0)+I.edge(M).weight}),G});return z(I.nodes(),_)}function d(I){let _=I.nodes().map(X=>{let G={};return I.inEdges(X).forEach(M=>{G[M.v]=(G[M.v]||0)+I.edge(M).weight}),G});return z(I.nodes(),_)}function u(I,_){let X=I.x,G=I.y,M=_.x-X,U=_.y-G,L=I.width/2,F=I.height/2;if(!M&&!U)throw new Error("Not possible to find intersection inside of the rectangle");let Z,Y;return Math.abs(U)*L>Math.abs(M)*F?(U<0&&(F=-F),Z=F*M/U,Y=F):(M<0&&(L=-L),Z=L,Y=L*U/M),{x:X+Z,y:G+Y}}function f(I){let _=A(j(I)+1).map(()=>[]);return I.nodes().forEach(X=>{let G=I.node(X),M=G.rank;M!==void 0&&(_[M][G.order]=X)}),_}function h(I){let _=I.nodes().map(G=>{let M=I.node(G).rank;return M===void 0?Number.MAX_VALUE:M}),X=k(Math.min,_);I.nodes().forEach(G=>{let M=I.node(G);Object.hasOwn(M,"rank")&&(M.rank-=X)})}function p(I){let _=I.nodes().map(L=>I.node(L).rank).filter(L=>L!==void 0),X=k(Math.min,_),G=[];I.nodes().forEach(L=>{let F=I.node(L).rank-X;G[F]||(G[F]=[]),G[F].push(L)});let M=0,U=I.graph().nodeRankFactor;Array.from(G).forEach((L,F)=>{L===void 0&&F%U!==0?--M:L!==void 0&&M&&L.forEach(Z=>I.node(Z).rank+=M)})}function x(I,_,X,G){let M={width:0,height:0};return arguments.length>=4&&(M.rank=X,M.order=G),s(I,"border",M,_)}function b(I,_=y){let X=[];for(let G=0;G<I.length;G+=_){let M=I.slice(G,G+_);X.push(M)}return X}var y=65535;function k(I,_){if(_.length>y){let X=b(_);return I.apply(null,X.map(G=>I.apply(null,G)))}else return I.apply(null,_)}function j(I){let _=I.nodes().map(X=>{let G=I.node(X).rank;return G===void 0?Number.MIN_VALUE:G});return k(Math.max,_)}function S(I,_){let X={lhs:[],rhs:[]};return I.forEach(G=>{_(G)?X.lhs.push(G):X.rhs.push(G)}),X}function T(I,_){let X=Date.now();try{return _()}finally{console.log(I+" time: "+(Date.now()-X)+"ms")}}function N(I,_){return _()}var E=0;function B(I){var _=++E;return I+(""+_)}function A(I,_,X=1){_==null&&(_=I,I=0);let G=U=>U<_;X<0&&(G=U=>_<U);let M=[];for(let U=I;G(U);U+=X)M.push(U);return M}function H(I,_){let X={};for(let G of _)I[G]!==void 0&&(X[G]=I[G]);return X}function O(I,_){let X=_;return typeof _=="string"&&(X=G=>G[_]),Object.entries(I).reduce((G,[M,U])=>(G[M]=X(U,M),G),{})}function z(I,_){return I.reduce((X,G,M)=>(X[G]=_[M],X),{})}}),QQ=Jn((e,t)=>{var n=ZQ(),s=Yr().uniqueId;t.exports={run:a,undo:c};function a(d){(d.graph().acyclicer==="greedy"?n(d,u(d)):o(d)).forEach(f=>{let h=d.edge(f);d.removeEdge(f),h.forwardName=f.name,h.reversed=!0,d.setEdge(f.w,f.v,h,s("rev"))});function u(f){return h=>f.edge(h).weight}}function o(d){let u=[],f={},h={};function p(x){Object.hasOwn(h,x)||(h[x]=!0,f[x]=!0,d.outEdges(x).forEach(b=>{Object.hasOwn(f,b.w)?u.push(b):p(b.w)}),delete f[x])}return d.nodes().forEach(p),u}function c(d){d.edges().forEach(u=>{let f=d.edge(u);if(f.reversed){d.removeEdge(u);let h=f.forwardName;delete f.reversed,delete f.forwardName,d.setEdge(u.w,u.v,f,h)}})}}),JQ=Jn((e,t)=>{var n=Yr();t.exports={run:s,undo:o};function s(c){c.graph().dummyChains=[],c.edges().forEach(d=>a(c,d))}function a(c,d){let u=d.v,f=c.node(u).rank,h=d.w,p=c.node(h).rank,x=d.name,b=c.edge(d),y=b.labelRank;if(p===f+1)return;c.removeEdge(d);let k,j,S;for(S=0,++f;f<p;++S,++f)b.points=[],j={width:0,height:0,edgeLabel:b,edgeObj:d,rank:f},k=n.addDummyNode(c,"edge",j,"_d"),f===y&&(j.width=b.width,j.height=b.height,j.dummy="edge-label",j.labelpos=b.labelpos),c.setEdge(u,k,{weight:b.weight},x),S===0&&c.graph().dummyChains.push(k),u=k;c.setEdge(u,h,{weight:b.weight},x)}function o(c){c.graph().dummyChains.forEach(d=>{let u=c.node(d),f=u.edgeLabel,h;for(c.setEdge(u.edgeObj,f);u.dummy;)h=c.successors(d)[0],c.removeNode(d),f.points.push({x:u.x,y:u.y}),u.dummy==="edge-label"&&(f.x=u.x,f.y=u.y,f.width=u.width,f.height=u.height),d=h,u=c.node(d)})}}),Jf=Jn((e,t)=>{var{applyWithChunking:n}=Yr();t.exports={longestPath:s,slack:a};function s(o){var c={};function d(u){var f=o.node(u);if(Object.hasOwn(c,u))return f.rank;c[u]=!0;let h=o.outEdges(u).map(x=>x==null?Number.POSITIVE_INFINITY:d(x.w)-o.edge(x).minlen);var p=n(Math.min,h);return p===Number.POSITIVE_INFINITY&&(p=0),f.rank=p}o.sources().forEach(d)}function a(o,c){return o.node(c.w).rank-o.node(c.v).rank-o.edge(c).minlen}}),a7=Jn((e,t)=>{var n=qa().Graph,s=Jf().slack;t.exports=a;function a(u){var f=new n({directed:!1}),h=u.nodes()[0],p=u.nodeCount();f.setNode(h,{});for(var x,b;o(f,u)<p;)x=c(f,u),b=f.hasNode(x.v)?s(u,x):-s(u,x),d(f,u,b);return f}function o(u,f){function h(p){f.nodeEdges(p).forEach(x=>{var b=x.v,y=p===b?x.w:b;!u.hasNode(y)&&!s(f,x)&&(u.setNode(y,{}),u.setEdge(p,y,{}),h(y))})}return u.nodes().forEach(h),u.nodeCount()}function c(u,f){return f.edges().reduce((h,p)=>{let x=Number.POSITIVE_INFINITY;return u.hasNode(p.v)!==u.hasNode(p.w)&&(x=s(f,p)),x<h[0]?[x,p]:h},[Number.POSITIVE_INFINITY,null])[1]}function d(u,f,h){u.nodes().forEach(p=>f.node(p).rank+=h)}}),eJ=Jn((e,t)=>{var n=a7(),s=Jf().slack,a=Jf().longestPath,o=qa().alg.preorder,c=qa().alg.postorder,d=Yr().simplify;t.exports=u,u.initLowLimValues=x,u.initCutValues=f,u.calcCutValue=p,u.leaveEdge=y,u.enterEdge=k,u.exchangeEdges=j;function u(E){E=d(E),a(E);var B=n(E);x(B),f(B,E);for(var A,H;A=y(B);)H=k(B,E,A),j(B,E,A,H)}function f(E,B){var A=c(E,E.nodes());A=A.slice(0,A.length-1),A.forEach(H=>h(E,B,H))}function h(E,B,A){var H=E.node(A),O=H.parent;E.edge(A,O).cutvalue=p(E,B,A)}function p(E,B,A){var H=E.node(A),O=H.parent,z=!0,I=B.edge(A,O),_=0;return I||(z=!1,I=B.edge(O,A)),_=I.weight,B.nodeEdges(A).forEach(X=>{var G=X.v===A,M=G?X.w:X.v;if(M!==O){var U=G===z,L=B.edge(X).weight;if(_+=U?L:-L,T(E,A,M)){var F=E.edge(A,M).cutvalue;_+=U?-F:F}}}),_}function x(E,B){arguments.length<2&&(B=E.nodes()[0]),b(E,{},1,B)}function b(E,B,A,H,O){var z=A,I=E.node(H);return B[H]=!0,E.neighbors(H).forEach(_=>{Object.hasOwn(B,_)||(A=b(E,B,A,_,H))}),I.low=z,I.lim=A++,O?I.parent=O:delete I.parent,A}function y(E){return E.edges().find(B=>E.edge(B).cutvalue<0)}function k(E,B,A){var H=A.v,O=A.w;B.hasEdge(H,O)||(H=A.w,O=A.v);var z=E.node(H),I=E.node(O),_=z,X=!1;z.lim>I.lim&&(_=I,X=!0);var G=B.edges().filter(M=>X===N(E,E.node(M.v),_)&&X!==N(E,E.node(M.w),_));return G.reduce((M,U)=>s(B,U)<s(B,M)?U:M)}function j(E,B,A,H){var O=A.v,z=A.w;E.removeEdge(O,z),E.setEdge(H.v,H.w,{}),x(E),f(E,B),S(E,B)}function S(E,B){var A=E.nodes().find(O=>!B.node(O).parent),H=o(E,A);H=H.slice(1),H.forEach(O=>{var z=E.node(O).parent,I=B.edge(O,z),_=!1;I||(I=B.edge(z,O),_=!0),B.node(O).rank=B.node(z).rank+(_?I.minlen:-I.minlen)})}function T(E,B,A){return E.hasEdge(B,A)}function N(E,B,A){return A.low<=B.lim&&B.lim<=A.lim}}),tJ=Jn((e,t)=>{var n=Jf(),s=n.longestPath,a=a7(),o=eJ();t.exports=c;function c(h){var p=h.graph().ranker;if(p instanceof Function)return p(h);switch(h.graph().ranker){case"network-simplex":f(h);break;case"tight-tree":u(h);break;case"longest-path":d(h);break;case"none":break;default:f(h)}}var d=s;function u(h){s(h),a(h)}function f(h){o(h)}}),nJ=Jn((e,t)=>{t.exports=n;function n(o){let c=a(o);o.graph().dummyChains.forEach(d=>{let u=o.node(d),f=u.edgeObj,h=s(o,c,f.v,f.w),p=h.path,x=h.lca,b=0,y=p[b],k=!0;for(;d!==f.w;){if(u=o.node(d),k){for(;(y=p[b])!==x&&o.node(y).maxRank<u.rank;)b++;y===x&&(k=!1)}if(!k){for(;b<p.length-1&&o.node(y=p[b+1]).minRank<=u.rank;)b++;y=p[b]}o.setParent(d,y),d=o.successors(d)[0]}})}function s(o,c,d,u){let f=[],h=[],p=Math.min(c[d].low,c[u].low),x=Math.max(c[d].lim,c[u].lim),b,y;b=d;do b=o.parent(b),f.push(b);while(b&&(c[b].low>p||x>c[b].lim));for(y=b,b=u;(b=o.parent(b))!==y;)h.push(b);return{path:f.concat(h.reverse()),lca:y}}function a(o){let c={},d=0;function u(f){let h=d;o.children(f).forEach(u),c[f]={low:h,lim:d++}}return o.children().forEach(u),c}}),rJ=Jn((e,t)=>{var n=Yr();t.exports={run:s,cleanup:d};function s(u){let f=n.addDummyNode(u,"root",{},"_root"),h=o(u),p=Object.values(h),x=n.applyWithChunking(Math.max,p)-1,b=2*x+1;u.graph().nestingRoot=f,u.edges().forEach(k=>u.edge(k).minlen*=b);let y=c(u)+1;u.children().forEach(k=>a(u,f,b,y,x,h,k)),u.graph().nodeRankFactor=b}function a(u,f,h,p,x,b,y){let k=u.children(y);if(!k.length){y!==f&&u.setEdge(f,y,{weight:0,minlen:h});return}let j=n.addBorderNode(u,"_bt"),S=n.addBorderNode(u,"_bb"),T=u.node(y);u.setParent(j,y),T.borderTop=j,u.setParent(S,y),T.borderBottom=S,k.forEach(N=>{a(u,f,h,p,x,b,N);let E=u.node(N),B=E.borderTop?E.borderTop:N,A=E.borderBottom?E.borderBottom:N,H=E.borderTop?p:2*p,O=B!==A?1:x-b[y]+1;u.setEdge(j,B,{weight:H,minlen:O,nestingEdge:!0}),u.setEdge(A,S,{weight:H,minlen:O,nestingEdge:!0})}),u.parent(y)||u.setEdge(f,j,{weight:0,minlen:x+b[y]})}function o(u){var f={};function h(p,x){var b=u.children(p);b&&b.length&&b.forEach(y=>h(y,x+1)),f[p]=x}return u.children().forEach(p=>h(p,1)),f}function c(u){return u.edges().reduce((f,h)=>f+u.edge(h).weight,0)}function d(u){var f=u.graph();u.removeNode(f.nestingRoot),delete f.nestingRoot,u.edges().forEach(h=>{var p=u.edge(h);p.nestingEdge&&u.removeEdge(h)})}}),sJ=Jn((e,t)=>{var n=Yr();t.exports=s;function s(o){function c(d){let u=o.children(d),f=o.node(d);if(u.length&&u.forEach(c),Object.hasOwn(f,"minRank")){f.borderLeft=[],f.borderRight=[];for(let h=f.minRank,p=f.maxRank+1;h<p;++h)a(o,"borderLeft","_bl",d,f,h),a(o,"borderRight","_br",d,f,h)}}o.children().forEach(c)}function a(o,c,d,u,f,h){let p={width:0,height:0,rank:h,borderType:c},x=f[c][h-1],b=n.addDummyNode(o,"border",p,d);f[c][h]=b,o.setParent(b,u),x&&o.setEdge(x,b,{weight:1})}}),aJ=Jn((e,t)=>{t.exports={adjust:n,undo:s};function n(h){let p=h.graph().rankdir.toLowerCase();(p==="lr"||p==="rl")&&a(h)}function s(h){let p=h.graph().rankdir.toLowerCase();(p==="bt"||p==="rl")&&c(h),(p==="lr"||p==="rl")&&(u(h),a(h))}function a(h){h.nodes().forEach(p=>o(h.node(p))),h.edges().forEach(p=>o(h.edge(p)))}function o(h){let p=h.width;h.width=h.height,h.height=p}function c(h){h.nodes().forEach(p=>d(h.node(p))),h.edges().forEach(p=>{let x=h.edge(p);x.points.forEach(d),Object.hasOwn(x,"y")&&d(x)})}function d(h){h.y=-h.y}function u(h){h.nodes().forEach(p=>f(h.node(p))),h.edges().forEach(p=>{let x=h.edge(p);x.points.forEach(f),Object.hasOwn(x,"x")&&f(x)})}function f(h){let p=h.x;h.x=h.y,h.y=p}}),iJ=Jn((e,t)=>{var n=Yr();t.exports=s;function s(a){let o={},c=a.nodes().filter(p=>!a.children(p).length),d=c.map(p=>a.node(p).rank),u=n.applyWithChunking(Math.max,d),f=n.range(u+1).map(()=>[]);function h(p){if(o[p])return;o[p]=!0;let x=a.node(p);f[x.rank].push(p),a.successors(p).forEach(h)}return c.sort((p,x)=>a.node(p).rank-a.node(x).rank).forEach(h),f}}),oJ=Jn((e,t)=>{var n=Yr().zipObject;t.exports=s;function s(o,c){let d=0;for(let u=1;u<c.length;++u)d+=a(o,c[u-1],c[u]);return d}function a(o,c,d){let u=n(d,d.map((y,k)=>k)),f=c.flatMap(y=>o.outEdges(y).map(k=>({pos:u[k.w],weight:o.edge(k).weight})).sort((k,j)=>k.pos-j.pos)),h=1;for(;h<d.length;)h<<=1;let p=2*h-1;h-=1;let x=new Array(p).fill(0),b=0;return f.forEach(y=>{let k=y.pos+h;x[k]+=y.weight;let j=0;for(;k>0;)k%2&&(j+=x[k+1]),k=k-1>>1,x[k]+=y.weight;b+=y.weight*j}),b}}),lJ=Jn((e,t)=>{t.exports=n;function n(s,a=[]){return a.map(o=>{let c=s.inEdges(o);if(c.length){let d=c.reduce((u,f)=>{let h=s.edge(f),p=s.node(f.v);return{sum:u.sum+h.weight*p.order,weight:u.weight+h.weight}},{sum:0,weight:0});return{v:o,barycenter:d.sum/d.weight,weight:d.weight}}else return{v:o}})}}),cJ=Jn((e,t)=>{var n=Yr();t.exports=s;function s(c,d){let u={};c.forEach((h,p)=>{let x=u[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:p};h.barycenter!==void 0&&(x.barycenter=h.barycenter,x.weight=h.weight)}),d.edges().forEach(h=>{let p=u[h.v],x=u[h.w];p!==void 0&&x!==void 0&&(x.indegree++,p.out.push(u[h.w]))});let f=Object.values(u).filter(h=>!h.indegree);return a(f)}function a(c){let d=[];function u(h){return p=>{p.merged||(p.barycenter===void 0||h.barycenter===void 0||p.barycenter>=h.barycenter)&&o(h,p)}}function f(h){return p=>{p.in.push(h),--p.indegree===0&&c.push(p)}}for(;c.length;){let h=c.pop();d.push(h),h.in.reverse().forEach(u(h)),h.out.forEach(f(h))}return d.filter(h=>!h.merged).map(h=>n.pick(h,["vs","i","barycenter","weight"]))}function o(c,d){let u=0,f=0;c.weight&&(u+=c.barycenter*c.weight,f+=c.weight),d.weight&&(u+=d.barycenter*d.weight,f+=d.weight),c.vs=d.vs.concat(c.vs),c.barycenter=u/f,c.weight=f,c.i=Math.min(d.i,c.i),d.merged=!0}}),dJ=Jn((e,t)=>{var n=Yr();t.exports=s;function s(c,d){let u=n.partition(c,j=>Object.hasOwn(j,"barycenter")),f=u.lhs,h=u.rhs.sort((j,S)=>S.i-j.i),p=[],x=0,b=0,y=0;f.sort(o(!!d)),y=a(p,h,y),f.forEach(j=>{y+=j.vs.length,p.push(j.vs),x+=j.barycenter*j.weight,b+=j.weight,y=a(p,h,y)});let k={vs:p.flat(!0)};return b&&(k.barycenter=x/b,k.weight=b),k}function a(c,d,u){let f;for(;d.length&&(f=d[d.length-1]).i<=u;)d.pop(),c.push(f.vs),u++;return u}function o(c){return(d,u)=>d.barycenter<u.barycenter?-1:d.barycenter>u.barycenter?1:c?u.i-d.i:d.i-u.i}}),uJ=Jn((e,t)=>{var n=lJ(),s=cJ(),a=dJ();t.exports=o;function o(u,f,h,p){let x=u.children(f),b=u.node(f),y=b?b.borderLeft:void 0,k=b?b.borderRight:void 0,j={};y&&(x=x.filter(E=>E!==y&&E!==k));let S=n(u,x);S.forEach(E=>{if(u.children(E.v).length){let B=o(u,E.v,h,p);j[E.v]=B,Object.hasOwn(B,"barycenter")&&d(E,B)}});let T=s(S,h);c(T,j);let N=a(T,p);if(y&&(N.vs=[y,N.vs,k].flat(!0),u.predecessors(y).length)){let E=u.node(u.predecessors(y)[0]),B=u.node(u.predecessors(k)[0]);Object.hasOwn(N,"barycenter")||(N.barycenter=0,N.weight=0),N.barycenter=(N.barycenter*N.weight+E.order+B.order)/(N.weight+2),N.weight+=2}return N}function c(u,f){u.forEach(h=>{h.vs=h.vs.flatMap(p=>f[p]?f[p].vs:p)})}function d(u,f){u.barycenter!==void 0?(u.barycenter=(u.barycenter*u.weight+f.barycenter*f.weight)/(u.weight+f.weight),u.weight+=f.weight):(u.barycenter=f.barycenter,u.weight=f.weight)}}),fJ=Jn((e,t)=>{var n=qa().Graph,s=Yr();t.exports=a;function a(c,d,u,f){f||(f=c.nodes());let h=o(c),p=new n({compound:!0}).setGraph({root:h}).setDefaultNodeLabel(x=>c.node(x));return f.forEach(x=>{let b=c.node(x),y=c.parent(x);(b.rank===d||b.minRank<=d&&d<=b.maxRank)&&(p.setNode(x),p.setParent(x,y||h),c[u](x).forEach(k=>{let j=k.v===x?k.w:k.v,S=p.edge(j,x),T=S!==void 0?S.weight:0;p.setEdge(j,x,{weight:c.edge(k).weight+T})}),Object.hasOwn(b,"minRank")&&p.setNode(x,{borderLeft:b.borderLeft[d],borderRight:b.borderRight[d]}))}),p}function o(c){for(var d;c.hasNode(d=s.uniqueId("_root")););return d}}),mJ=Jn((e,t)=>{t.exports=n;function n(s,a,o){let c={},d;o.forEach(u=>{let f=s.parent(u),h,p;for(;f;){if(h=s.parent(f),h?(p=c[h],c[h]=f):(p=d,d=f),p&&p!==f){a.setEdge(p,f);return}f=h}})}}),hJ=Jn((e,t)=>{var n=iJ(),s=oJ(),a=uJ(),o=fJ(),c=mJ(),d=qa().Graph,u=Yr();t.exports=f;function f(b,y={}){if(typeof y.customOrder=="function"){y.customOrder(b,f);return}let k=u.maxRank(b),j=h(b,u.range(1,k+1),"inEdges"),S=h(b,u.range(k-1,-1,-1),"outEdges"),T=n(b);if(x(b,T),y.disableOptimalOrderHeuristic)return;let N=Number.POSITIVE_INFINITY,E,B=y.constraints||[];for(let A=0,H=0;H<4;++A,++H){p(A%2?j:S,A%4>=2,B),T=u.buildLayerMatrix(b);let O=s(b,T);O<N?(H=0,E=Object.assign({},T),N=O):O===N&&(E=structuredClone(T))}x(b,E)}function h(b,y,k){let j=new Map,S=(T,N)=>{j.has(T)||j.set(T,[]),j.get(T).push(N)};for(let T of b.nodes()){let N=b.node(T);if(typeof N.rank=="number"&&S(N.rank,T),typeof N.minRank=="number"&&typeof N.maxRank=="number")for(let E=N.minRank;E<=N.maxRank;E++)E!==N.rank&&S(E,T)}return y.map(function(T){return o(b,T,k,j.get(T)||[])})}function p(b,y,k){let j=new d;b.forEach(function(S){k.forEach(E=>j.setEdge(E.left,E.right));let T=S.graph().root,N=a(S,T,j,y);N.vs.forEach((E,B)=>S.node(E).order=B),c(S,j,N.vs)})}function x(b,y){Object.values(y).forEach(k=>k.forEach((j,S)=>b.node(j).order=S))}}),pJ=Jn((e,t)=>{var n=qa().Graph,s=Yr();t.exports={positionX:k,findType1Conflicts:a,findType2Conflicts:o,addConflict:d,hasConflict:u,verticalAlignment:f,horizontalCompaction:h,alignCoordinates:b,findSmallestWidthAlignment:x,balance:y};function a(T,N){let E={};function B(A,H){let O=0,z=0,I=A.length,_=H[H.length-1];return H.forEach((X,G)=>{let M=c(T,X),U=M?T.node(M).order:I;(M||X===_)&&(H.slice(z,G+1).forEach(L=>{T.predecessors(L).forEach(F=>{let Z=T.node(F),Y=Z.order;(Y<O||U<Y)&&!(Z.dummy&&T.node(L).dummy)&&d(E,F,L)})}),z=G+1,O=U)}),H}return N.length&&N.reduce(B),E}function o(T,N){let E={};function B(H,O,z,I,_){let X;s.range(O,z).forEach(G=>{X=H[G],T.node(X).dummy&&T.predecessors(X).forEach(M=>{let U=T.node(M);U.dummy&&(U.order<I||U.order>_)&&d(E,M,X)})})}function A(H,O){let z=-1,I,_=0;return O.forEach((X,G)=>{if(T.node(X).dummy==="border"){let M=T.predecessors(X);M.length&&(I=T.node(M[0]).order,B(O,_,G,z,I),_=G,z=I)}B(O,_,O.length,I,H.length)}),O}return N.length&&N.reduce(A),E}function c(T,N){if(T.node(N).dummy)return T.predecessors(N).find(E=>T.node(E).dummy)}function d(T,N,E){if(N>E){let A=N;N=E,E=A}let B=T[N];B||(T[N]=B={}),B[E]=!0}function u(T,N,E){if(N>E){let B=N;N=E,E=B}return!!T[N]&&Object.hasOwn(T[N],E)}function f(T,N,E,B){let A={},H={},O={};return N.forEach(z=>{z.forEach((I,_)=>{A[I]=I,H[I]=I,O[I]=_})}),N.forEach(z=>{let I=-1;z.forEach(_=>{let X=B(_);if(X.length){X=X.sort((M,U)=>O[M]-O[U]);let G=(X.length-1)/2;for(let M=Math.floor(G),U=Math.ceil(G);M<=U;++M){let L=X[M];H[_]===_&&I<O[L]&&!u(E,_,L)&&(H[L]=_,H[_]=A[_]=A[L],I=O[L])}}})}),{root:A,align:H}}function h(T,N,E,B,A){let H={},O=p(T,N,E,A),z=A?"borderLeft":"borderRight";function I(G,M){let U=O.nodes().slice(),L={},F=U.pop();for(;F;){if(L[F])G(F);else{L[F]=!0,U.push(F);for(let Z of M(F))U.push(Z)}F=U.pop()}}function _(G){H[G]=O.inEdges(G).reduce((M,U)=>Math.max(M,H[U.v]+O.edge(U)),0)}function X(G){let M=O.outEdges(G).reduce((L,F)=>Math.min(L,H[F.w]-O.edge(F)),Number.POSITIVE_INFINITY),U=T.node(G);M!==Number.POSITIVE_INFINITY&&U.borderType!==z&&(H[G]=Math.max(H[G],M))}return I(_,O.predecessors.bind(O)),I(X,O.successors.bind(O)),Object.keys(B).forEach(G=>H[G]=H[E[G]]),H}function p(T,N,E,B){let A=new n,H=T.graph(),O=j(H.nodesep,H.edgesep,B);return N.forEach(z=>{let I;z.forEach(_=>{let X=E[_];if(A.setNode(X),I){var G=E[I],M=A.edge(G,X);A.setEdge(G,X,Math.max(O(T,_,I),M||0))}I=_})}),A}function x(T,N){return Object.values(N).reduce((E,B)=>{let A=Number.NEGATIVE_INFINITY,H=Number.POSITIVE_INFINITY;Object.entries(B).forEach(([z,I])=>{let _=S(T,z)/2;A=Math.max(I+_,A),H=Math.min(I-_,H)});let O=A-H;return O<E[0]&&(E=[O,B]),E},[Number.POSITIVE_INFINITY,null])[1]}function b(T,N){let E=Object.values(N),B=s.applyWithChunking(Math.min,E),A=s.applyWithChunking(Math.max,E);["u","d"].forEach(H=>{["l","r"].forEach(O=>{let z=H+O,I=T[z];if(I===N)return;let _=Object.values(I),X=B-s.applyWithChunking(Math.min,_);O!=="l"&&(X=A-s.applyWithChunking(Math.max,_)),X&&(T[z]=s.mapValues(I,G=>G+X))})})}function y(T,N){return s.mapValues(T.ul,(E,B)=>{if(N)return T[N.toLowerCase()][B];{let A=Object.values(T).map(H=>H[B]).sort((H,O)=>H-O);return(A[1]+A[2])/2}})}function k(T){let N=s.buildLayerMatrix(T),E=Object.assign(a(T,N),o(T,N)),B={},A;["u","d"].forEach(O=>{A=O==="u"?N:Object.values(N).reverse(),["l","r"].forEach(z=>{z==="r"&&(A=A.map(G=>Object.values(G).reverse()));let I=(O==="u"?T.predecessors:T.successors).bind(T),_=f(T,A,E,I),X=h(T,A,_.root,_.align,z==="r");z==="r"&&(X=s.mapValues(X,G=>-G)),B[O+z]=X})});let H=x(T,B);return b(B,H),y(B,T.graph().align)}function j(T,N,E){return(B,A,H)=>{let O=B.node(A),z=B.node(H),I=0,_;if(I+=O.width/2,Object.hasOwn(O,"labelpos"))switch(O.labelpos.toLowerCase()){case"l":_=-O.width/2;break;case"r":_=O.width/2;break}if(_&&(I+=E?_:-_),_=0,I+=(O.dummy?N:T)/2,I+=(z.dummy?N:T)/2,I+=z.width/2,Object.hasOwn(z,"labelpos"))switch(z.labelpos.toLowerCase()){case"l":_=z.width/2;break;case"r":_=-z.width/2;break}return _&&(I+=E?_:-_),_=0,I}}function S(T,N){return T.node(N).width}}),gJ=Jn((e,t)=>{var n=Yr(),s=pJ().positionX;t.exports=a;function a(c){c=n.asNonCompoundGraph(c),o(c),Object.entries(s(c)).forEach(([d,u])=>c.node(d).x=u)}function o(c){let d=n.buildLayerMatrix(c),u=c.graph().ranksep,f=c.graph().rankalign,h=0;d.forEach(p=>{let x=p.reduce((b,y)=>{let k=c.node(y).height;return b>k?b:k},0);p.forEach(b=>{let y=c.node(b);f==="top"?y.y=h+y.height/2:f==="bottom"?y.y=h+x-y.height/2:y.y=h+x/2}),h+=x+u})}}),xJ=Jn((e,t)=>{var n=QQ(),s=JQ(),a=tJ(),o=Yr().normalizeRanks,c=nJ(),d=Yr().removeEmptyRanks,u=rJ(),f=sJ(),h=aJ(),p=hJ(),x=gJ(),b=Yr(),y=qa().Graph;t.exports=k;function k(q,J={}){let K=J.debugTiming?b.time:b.notime;return K("layout",()=>{let re=K(" buildLayoutGraph",()=>I(q));return K(" runLayout",()=>j(re,K,J)),K(" updateInputGraph",()=>S(q,re)),re})}function j(q,J,K){J(" makeSpaceForEdgeLabels",()=>_(q)),J(" removeSelfEdges",()=>D(q)),J(" acyclic",()=>n.run(q)),J(" nestingGraph.run",()=>u.run(q)),J(" rank",()=>a(b.asNonCompoundGraph(q))),J(" injectEdgeLabelProxies",()=>X(q)),J(" removeEmptyRanks",()=>d(q)),J(" nestingGraph.cleanup",()=>u.cleanup(q)),J(" normalizeRanks",()=>o(q)),J(" assignRankMinMax",()=>G(q)),J(" removeEdgeLabelProxies",()=>M(q)),J(" normalize.run",()=>s.run(q)),J(" parentDummyChains",()=>c(q)),J(" addBorderSegments",()=>f(q)),J(" order",()=>p(q,K)),J(" insertSelfEdges",()=>P(q)),J(" adjustCoordinateSystem",()=>h.adjust(q)),J(" position",()=>x(q)),J(" positionSelfEdges",()=>ee(q)),J(" removeBorderNodes",()=>Y(q)),J(" normalize.undo",()=>s.undo(q)),J(" fixupEdgeLabelCoords",()=>F(q)),J(" undoCoordinateSystem",()=>h.undo(q)),J(" translateGraph",()=>U(q)),J(" assignNodeIntersects",()=>L(q)),J(" reversePoints",()=>Z(q)),J(" acyclic.undo",()=>n.undo(q))}function S(q,J){q.nodes().forEach(K=>{let re=q.node(K),de=J.node(K);re&&(re.x=de.x,re.y=de.y,re.order=de.order,re.rank=de.rank,J.children(K).length&&(re.width=de.width,re.height=de.height))}),q.edges().forEach(K=>{let re=q.edge(K),de=J.edge(K);re.points=de.points,Object.hasOwn(de,"x")&&(re.x=de.x,re.y=de.y)}),q.graph().width=J.graph().width,q.graph().height=J.graph().height}var T=["nodesep","edgesep","ranksep","marginx","marginy"],N={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},E=["acyclicer","ranker","rankdir","align","rankalign"],B=["width","height","rank"],A={width:0,height:0},H=["minlen","weight","width","height","labeloffset"],O={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},z=["labelpos"];function I(q){let J=new y({multigraph:!0,compound:!0}),K=Q(q.graph());return J.setGraph(Object.assign({},N,$(K,T),b.pick(K,E))),q.nodes().forEach(re=>{let de=Q(q.node(re)),pe=$(de,B);Object.keys(A).forEach(te=>{pe[te]===void 0&&(pe[te]=A[te])}),J.setNode(re,pe),J.setParent(re,q.parent(re))}),q.edges().forEach(re=>{let de=Q(q.edge(re));J.setEdge(re,Object.assign({},O,$(de,H),b.pick(de,z)))}),J}function _(q){let J=q.graph();J.ranksep/=2,q.edges().forEach(K=>{let re=q.edge(K);re.minlen*=2,re.labelpos.toLowerCase()!=="c"&&(J.rankdir==="TB"||J.rankdir==="BT"?re.width+=re.labeloffset:re.height+=re.labeloffset)})}function X(q){q.edges().forEach(J=>{let K=q.edge(J);if(K.width&&K.height){let re=q.node(J.v),de={rank:(q.node(J.w).rank-re.rank)/2+re.rank,e:J};b.addDummyNode(q,"edge-proxy",de,"_ep")}})}function G(q){let J=0;q.nodes().forEach(K=>{let re=q.node(K);re.borderTop&&(re.minRank=q.node(re.borderTop).rank,re.maxRank=q.node(re.borderBottom).rank,J=Math.max(J,re.maxRank))}),q.graph().maxRank=J}function M(q){q.nodes().forEach(J=>{let K=q.node(J);K.dummy==="edge-proxy"&&(q.edge(K.e).labelRank=K.rank,q.removeNode(J))})}function U(q){let J=Number.POSITIVE_INFINITY,K=0,re=Number.POSITIVE_INFINITY,de=0,pe=q.graph(),te=pe.marginx||0,we=pe.marginy||0;function ce(ge){let Ce=ge.x,Be=ge.y,Qe=ge.width,We=ge.height;J=Math.min(J,Ce-Qe/2),K=Math.max(K,Ce+Qe/2),re=Math.min(re,Be-We/2),de=Math.max(de,Be+We/2)}q.nodes().forEach(ge=>ce(q.node(ge))),q.edges().forEach(ge=>{let Ce=q.edge(ge);Object.hasOwn(Ce,"x")&&ce(Ce)}),J-=te,re-=we,q.nodes().forEach(ge=>{let Ce=q.node(ge);Ce.x-=J,Ce.y-=re}),q.edges().forEach(ge=>{let Ce=q.edge(ge);Ce.points.forEach(Be=>{Be.x-=J,Be.y-=re}),Object.hasOwn(Ce,"x")&&(Ce.x-=J),Object.hasOwn(Ce,"y")&&(Ce.y-=re)}),pe.width=K-J+te,pe.height=de-re+we}function L(q){q.edges().forEach(J=>{let K=q.edge(J),re=q.node(J.v),de=q.node(J.w),pe,te;K.points?(pe=K.points[0],te=K.points[K.points.length-1]):(K.points=[],pe=de,te=re),K.points.unshift(b.intersectRect(re,pe)),K.points.push(b.intersectRect(de,te))})}function F(q){q.edges().forEach(J=>{let K=q.edge(J);if(Object.hasOwn(K,"x"))switch((K.labelpos==="l"||K.labelpos==="r")&&(K.width-=K.labeloffset),K.labelpos){case"l":K.x-=K.width/2+K.labeloffset;break;case"r":K.x+=K.width/2+K.labeloffset;break}})}function Z(q){q.edges().forEach(J=>{let K=q.edge(J);K.reversed&&K.points.reverse()})}function Y(q){q.nodes().forEach(J=>{if(q.children(J).length){let K=q.node(J),re=q.node(K.borderTop),de=q.node(K.borderBottom),pe=q.node(K.borderLeft[K.borderLeft.length-1]),te=q.node(K.borderRight[K.borderRight.length-1]);K.width=Math.abs(te.x-pe.x),K.height=Math.abs(de.y-re.y),K.x=pe.x+K.width/2,K.y=re.y+K.height/2}}),q.nodes().forEach(J=>{q.node(J).dummy==="border"&&q.removeNode(J)})}function D(q){q.edges().forEach(J=>{if(J.v===J.w){var K=q.node(J.v);K.selfEdges||(K.selfEdges=[]),K.selfEdges.push({e:J,label:q.edge(J)}),q.removeEdge(J)}})}function P(q){var J=b.buildLayerMatrix(q);J.forEach(K=>{var re=0;K.forEach((de,pe)=>{var te=q.node(de);te.order=pe+re,(te.selfEdges||[]).forEach(we=>{b.addDummyNode(q,"selfedge",{width:we.label.width,height:we.label.height,rank:te.rank,order:pe+ ++re,e:we.e,label:we.label},"_se")}),delete te.selfEdges})})}function ee(q){q.nodes().forEach(J=>{var K=q.node(J);if(K.dummy==="selfedge"){var re=q.node(K.e.v),de=re.x+re.width/2,pe=re.y,te=K.x-de,we=re.height/2;q.setEdge(K.e,K.label),q.removeNode(J),K.label.points=[{x:de+2*te/3,y:pe-we},{x:de+5*te/6,y:pe-we},{x:de+te,y:pe},{x:de+5*te/6,y:pe+we},{x:de+2*te/3,y:pe+we}],K.label.x=K.x,K.label.y=K.y}})}function $(q,J){return b.mapValues(b.pick(q,J),Number)}function Q(q){var J={};return q&&Object.entries(q).forEach(([K,re])=>{typeof K=="string"&&(K=K.toLowerCase()),J[K]=re}),J}}),bJ=Jn((e,t)=>{var n=Yr(),s=qa().Graph;t.exports={debugOrdering:a};function a(o){let c=n.buildLayerMatrix(o),d=new s({compound:!0,multigraph:!0}).setGraph({});return o.nodes().forEach(u=>{d.setNode(u,{label:u}),d.setParent(u,"layer"+o.node(u).rank)}),o.edges().forEach(u=>d.setEdge(u.v,u.w,{},u.name)),c.forEach((u,f)=>{let h="layer"+f;d.setNode(h,{rank:"same"}),u.reduce((p,x)=>(d.setEdge(p,x,{style:"invis"}),x))}),d}}),yJ=Jn((e,t)=>{t.exports="2.0.4"}),vJ=Jn((e,t)=>{t.exports={graphlib:qa(),layout:xJ(),debug:bJ(),util:{time:Yr().time,notime:Yr().notime},version:yJ()}});const Z3=vJ();const Q3={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"}},wJ={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function kJ({data:e}){const{task:t,agentName:n,selected:s}=e,a=Q3[t.status]??Q3.pending,o=t.taskType==="scheduled"&&!!t.scheduleConfig,c=o?t.scheduleConfig.every?`Every ${t.scheduleConfig.every}`:t.scheduleConfig.cron?"Cron":"":"";return r.jsxs("div",{className:`rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${o?`${a.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${a.bg} ${a.border}`} ${s?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[r.jsx(Ro,{type:"target",position:_t.Top,className:"!bg-border-default !w-2 !h-2"}),r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${wJ[t.priority]??"bg-gray-500"}`}),r.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${a.text}`,children:t.status.replace("_"," ")}),o&&r.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:[r.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:r.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]})]}),r.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:t.title}),n&&r.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:n}),t.blockedBy&&t.blockedBy.length>0&&r.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[t.blockedBy.length," dep",t.blockedBy.length>1?"s":""]}),r.jsx(Ro,{type:"source",position:_t.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const J3={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"}},ek={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function jJ({data:e}){const{req:t,selected:n}=e,s=J3[t.status]??J3.pending;return r.jsxs("div",{className:`rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${s.bg} ${s.border} ${n?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[r.jsx(Ro,{type:"target",position:_t.Top,className:"!bg-border-default !w-2 !h-2"}),r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:"REQ"}),r.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${s.text}`,children:t.status.replace("_"," ")})]}),r.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:t.title}),t.taskIds.length>0&&r.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[t.taskIds.length," task",t.taskIds.length>1?"s":""]}),r.jsx(Ro,{type:"source",position:_t.Bottom,className:"!bg-border-default !w-2 !h-2"})]})}const NJ={task:kJ,requirement:jJ},SJ=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&window.matchMedia("(prefers-color-scheme: light)").matches,CJ=e=>{const t=new MutationObserver(e);t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const n=window.matchMedia("(prefers-color-scheme: light)");return n.addEventListener("change",e),()=>{t.disconnect(),n.removeEventListener("change",e)}};function TJ(){return v.useSyncExternalStore(CJ,SJ,()=>!1)}const Zx=200,Qx=80;function tk(e,t,n="TB"){const s=new Z3.graphlib.Graph;s.setDefaultEdgeLabel(()=>({})),s.setGraph({rankdir:n,nodesep:40,ranksep:60});for(const a of e)s.setNode(a.id,{width:Zx,height:Qx});for(const a of t)s.setEdge(a.source,a.target);return Z3.layout(s),e.map(a=>{const o=s.node(a.id);return{...a,position:{x:(o?.x??0)-Zx/2,y:(o?.y??0)-Qx/2}}})}function AJ(e,t){const n=new Map,s=new Map;for(const c of e)s.set(c.id,c),n.set(c.id,new Set);for(const c of t)n.get(c.source)?.add(c.target),n.get(c.target)?.add(c.source);const a=new Set,o=[];for(const c of e){if(a.has(c.id))continue;const d=new Set,u=[c.id];for(;u.length>0;){const f=u.pop();if(!a.has(f)){a.add(f),d.add(f);for(const h of n.get(f)??[])a.has(h)||u.push(h)}}o.push({nodes:e.filter(f=>d.has(f.id)),edges:t.filter(f=>d.has(f.source)&&d.has(f.target))})}return o}function EJ(e,t){if(e.length===0)return[];const n=AJ(e,t);if(n.length===1)return tk(e,t);const s=n.map(p=>{const x=tk(p.nodes,p.edges);let b=1/0,y=-1/0,k=1/0,j=-1/0;for(const S of x)b=Math.min(b,S.position.x),y=Math.max(y,S.position.x+Zx),k=Math.min(k,S.position.y),j=Math.max(j,S.position.y+Qx);for(const S of x)S.position.x-=b,S.position.y-=k;return{nodes:x,w:y-b,h:j-k}});s.sort((p,x)=>x.h-p.h);const a=60,o=s.reduce((p,x)=>p+(x.w+a)*(x.h+a),0),c=Math.sqrt(o)*1.1,d=[];let u=0,f=0,h=0;for(const p of s){u>0&&u+p.w>c&&(u=0,f+=h+a,h=0);for(const x of p.nodes)d.push({...x,position:{x:x.position.x+u,y:x.position.y+f}});u+=p.w+a,h=Math.max(h,p.h)}return d}function MJ(e,t,n){const s=new Set,a=[t];for(;a.length>0;){const o=a.pop();if(o===n)return!0;if(s.has(o))continue;s.add(o);const c=e.get(o);if(c?.blockedBy)for(const d of c.blockedBy)a.push(d)}return!1}const Bd=[{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","archived"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}],qg=new Set(Bd.map(e=>e.id)),nk=e=>e.status==="archived";function DJ({tasks:e,requirements:t=[],agents:n,showArchived:s,onShowArchivedChange:a,onTaskClick:o,onReqClick:c,onDependencyChange:d,selectedTaskId:u,selectedReqId:f}){const h=TJ(),[p,x]=v.useState(null),[b,y]=v.useState(null),[k,j]=v.useState(new Set(qg)),[S,T]=v.useState(s??!1),N=s??S,E=v.useCallback(ce=>{const ge=typeof ce=="function"?ce(N):ce;T(ge),a?.(ge)},[N,a]);v.useEffect(()=>{s!==void 0&&T(s)},[s]);const B=v.useMemo(()=>e.filter(ce=>nk(ce)).length,[e]),A=v.useMemo(()=>{const ce=new Set;for(const ge of Bd)if(k.has(ge.id))for(const Ce of ge.statuses)ce.add(Ce);return ce},[k]),H=v.useMemo(()=>{const ce=new Set;for(const ge of e)for(const Ce of Bd)if(Ce.statuses.has(ge.status)){ce.add(Ce.id);break}for(const ge of t){const Ce=ek[ge.status];Ce&&ce.add(Ce)}return Bd.filter(ge=>ce.has(ge.id))},[e,t]),O=v.useCallback(ce=>{j(ge=>{const Ce=new Set(ge);return Ce.has(ce)?Ce.delete(ce):Ce.add(ce),Ce})},[]),z=v.useCallback((ce,ge="success")=>{x({msg:ce,type:ge}),setTimeout(()=>x(null),2500)},[]),I=v.useMemo(()=>{const ce=new Map;for(const ge of n)ce.set(ge.id,ge.name);return ce},[n]),_=v.useMemo(()=>{const ce=new Map;for(const ge of e)ce.set(ge.id,ge);return ce},[e]),X=v.useMemo(()=>{const ce=new Map;for(const ge of t)ce.set(ge.id,ge);return ce},[t]),G=h?"#94a3b8":"#6b7280",M=v.useCallback((ce,ge,Ce)=>({id:`${ce}->${ge}`,source:ce,target:ge,animated:Ce==="blocked",markerEnd:{type:Sc.ArrowClosed,width:14,height:14,color:Ce==="blocked"?"#ef4444":G},style:{stroke:Ce==="blocked"?"#ef4444":G,strokeWidth:1.5,cursor:"pointer"}}),[G]),{initialNodes:U,initialEdges:L}=v.useMemo(()=>{const ce=e.filter(dt=>A.has(dt.status)&&(N||!nk(dt))),ge=ce.map(dt=>({id:dt.id,type:"task",data:{task:dt,agentName:dt.assignedAgentId?I.get(dt.assignedAgentId):void 0,selected:dt.id===u},position:{x:0,y:0}})),Ce=new Set(ge.map(dt=>dt.id)),Be=new Set;for(const dt of Bd)k.has(dt.id)&&Be.add(dt.id);const Qe=t.filter(dt=>{const me=ek[dt.status];return me&&Be.has(me)});for(const dt of Qe){const me=`req-${dt.id}`;ge.push({id:me,type:"requirement",data:{req:dt,selected:dt.id===f},position:{x:0,y:0}}),Ce.add(me)}const We=[];for(const dt of ce)if(dt.blockedBy)for(const me of dt.blockedBy)Ce.has(me)&&We.push(M(me,dt.id,dt.status));const wt=new Set,bt=(dt,me)=>{const ve=`${dt}->${me}`;wt.has(ve)||(wt.add(ve),We.push({id:ve,source:dt,target:me,markerEnd:{type:Sc.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const dt of Qe){const me=`req-${dt.id}`;for(const ve of dt.taskIds)Ce.has(ve)&&bt(me,ve)}for(const dt of ce)if(dt.requirementId){const me=`req-${dt.requirementId}`;Ce.has(me)&&bt(me,dt.id)}return{initialNodes:EJ(ge,We),initialEdges:We}},[e,t,I,_,M,A,k,N,u,f]),[F,Z,Y]=vQ(U),[D,P,ee]=wQ(L),$=v.useRef(null),Q=v.useRef(!1),q=v.useRef({groupFilter:k,showArchived:N});v.useEffect(()=>{const ce=q.current;(ce.groupFilter!==k||ce.showArchived!==N)&&(Q.current=!1,q.current={groupFilter:k,showArchived:N})},[k,N]),v.useEffect(()=>{Z(U),P(L),Q.current||requestAnimationFrame(()=>{$.current?.fitView({padding:.2,duration:300})})},[U,L,Z,P]);const J=v.useCallback(ce=>{ce&&(Q.current=!0)},[]),K=v.useCallback((ce,ge)=>{if(ge.id.startsWith("req-")){const Ce=X.get(ge.id.slice(4));Ce&&c&&c(Ce)}else{const Ce=_.get(ge.id);Ce&&o&&o(Ce)}},[_,X,o,c]),re=v.useCallback(async ce=>{const{source:ge,target:Ce}=ce;if(!ge||!Ce||ge===Ce)return;const Be=_.get(Ce);if(!Be)return;if(Be.blockedBy?.includes(ge)){z("Dependency already exists","error");return}if(MJ(_,ge,Ce)){z("Cannot add: would create a cycle","error");return}const Qe=[...Be.blockedBy??[],ge];try{await ue.tasks.update(Ce,{blockedBy:Qe}),z("Dependency added"),d?.()}catch(We){z(`Failed: ${We instanceof Error?We.message:String(We)}`,"error")}},[_,z,d]),de=v.useCallback((ce,ge)=>{y(ge)},[]),pe=v.useCallback(async()=>{if(!b)return;const ce=_.get(b.target);if(!ce){y(null);return}const ge=(ce.blockedBy??[]).filter(Ce=>Ce!==b.source);try{await ue.tasks.update(b.target,{blockedBy:ge}),z("Dependency removed"),d?.()}catch(Ce){z(`Failed: ${Ce instanceof Error?Ce.message:String(Ce)}`,"error")}y(null)},[b,_,z,d]);if(e.length===0)return r.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:"No tasks to display"});const te=b?_.get(b.source):null,we=b?_.get(b.target):null;return r.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[r.jsxs(yQ,{nodes:F,edges:D,onNodesChange:Y,onEdgesChange:ee,onNodeClick:K,onConnect:re,onEdgeClick:de,onMoveEnd:J,onInit:ce=>{$.current=ce},nodeTypes:NJ,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[r.jsx(CQ,{color:h?"#cbd5e1":"#374151",gap:20,size:1}),r.jsx(LQ,{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"}),r.jsx(GQ,{nodeColor:ce=>{const ge=ce.data?.task,Ce=ge?.status;return ge?.taskType==="scheduled"?"#06b6d4":Ce==="completed"||Ce==="accepted"?"#10b981":Ce==="in_progress"?"#f59e0b":Ce==="blocked"||Ce==="failed"?"#ef4444":h?"#94a3b8":"#6b7280"},maskColor:h?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),r.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:[r.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[H.map(ce=>{const ge=k.has(ce.id);return r.jsx("button",{onClick:()=>O(ce.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${ge?`${ce.color.bg} ${ce.color.border} ${ce.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:ce.label},ce.id)}),B>0&&r.jsxs("button",{onClick:()=>E(ce=>!ce),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${N?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:["Archived ",B]}),k.size<qg.size&&r.jsx("button",{onClick:()=>{j(new Set(qg)),E(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:"Reset"})]}),r.jsx("div",{className:"text-[10px] text-fg-tertiary select-none",children:"Drag to add dependency · Click edge to remove"})]}),p&&r.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${p.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:p.msg}),b&&r.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>y(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:ce=>ce.stopPropagation(),children:[r.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:"Remove dependency?"}),r.jsxs("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:[r.jsx("span",{className:"text-fg-secondary font-medium",children:we?.title??b.target.slice(-8)})," ","will no longer be blocked by"," ",r.jsx("span",{className:"text-fg-secondary font-medium",children:te?.title??b.source.slice(-8)}),"."]}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>y(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"}),r.jsx("button",{onClick:pe,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 RJ({orgId:e,onCreated:t,onClose:n}){const{t:s}=ht(["work","common"]),[a,o]=v.useState(""),[c,d]=v.useState(""),[u,f]=v.useState(""),[h,p]=v.useState("main"),[x,b]=v.useState([]),[y,k]=v.useState([]),[j,S]=v.useState(!1),[T,N]=v.useState(""),[E,B]=v.useState(!1),A=ws();v.useEffect(()=>{ue.teams.list().then(z=>k(z.teams)).catch(()=>{})},[]);const H=v.useCallback(async z=>{if(z?.preventDefault(),B(!0),!(!a.trim()||j)){S(!0),N("");try{const I=u.trim()?[{url:u.trim(),defaultBranch:h.trim()||"main"}]:[],_=await ue.projects.create({name:a.trim(),description:c.trim()||void 0,repositories:I.length>0?I:void 0,teamIds:x.length>0?x:void 0,orgId:e??"default"});t(_.project)}catch(I){N(I instanceof Error?I.message:s("project.failedToCreate"))}S(!1)}},[a,c,u,h,x,e,j,t,s]),O=E&&!a.trim();return bu.createPortal(r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:n,children:r.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto ${A?"w-full":"w-[520px]"}`,onClick:z=>z.stopPropagation(),onSubmit:H,children:[r.jsx("h3",{className:"text-base font-semibold mb-5",children:s("project.newProject")}),r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.projectName")}),r.jsx("input",{value:a,onChange:z=>{o(z.target.value),N("")},onBlur:()=>B(!0),placeholder:s("project.projectNamePlaceholder"),className:`input ${O?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!A}),O&&r.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:s("project.projectNameRequired")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.description")}),r.jsx("textarea",{value:c,onChange:z=>d(z.target.value),placeholder:s("project.descriptionPlaceholder"),className:"input",rows:3})]}),y.length>0&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.assignTeams")}),r.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:y.map(z=>{const I=x.includes(z.id);return r.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer hover:text-fg-primary py-0.5",children:[r.jsx("input",{type:"checkbox",checked:I,onChange:()=>b(_=>I?_.filter(X=>X!==z.id):[..._,z.id]),className:"accent-brand-500"}),r.jsx("span",{className:"truncate",children:z.name})]},z.id)})})]}),r.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.repositoryUrl")}),r.jsx("input",{value:u,onChange:z=>f(z.target.value),placeholder:s("project.repositoryPlaceholder"),className:"input"})]}),u.trim()&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.branch")}),r.jsx("input",{value:h,onChange:z=>p(z.target.value),placeholder:s("project.branchPlaceholder"),className:"input !w-24"})]})]}),T&&r.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:T}),r.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[r.jsx("button",{type:"button",onClick:n,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),r.jsx("button",{type:"submit",disabled:!a.trim()||j,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:s(j?"common:creating":"project.createProject")})]})]})]})}),document.body)}function i7(e,t){const[n,s]=v.useState(null);return v.useEffect(()=>{if(!t||!e.current){s(null);return}const a=()=>{const o=e.current?.getBoundingClientRect();if(!o)return;const c=240,d=window.innerHeight-o.bottom-8,u=o.top-8,f=d<c&&u>d;s(f?{top:o.top-4,left:o.left,width:o.width,flipUp:!0}:{top:o.bottom+4,left:o.left,width:o.width,flipUp:!1})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[t,e]),n}function Ld({options:e,value:t,onChange:n,placeholder:s,noMatchesText:a,className:o}){const[c,d]=v.useState(!1),[u,f]=v.useState(""),h=v.useRef(null),p=v.useRef(null),x=v.useRef(null),b=v.useRef(null),y=i7(p,c);v.useEffect(()=>{const S=T=>{h.current&&!h.current.contains(T.target)&&b.current&&!b.current.contains(T.target)&&d(!1)};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[]);const k=e.find(S=>S.value===t)?.label??"",j=u?e.filter(S=>S.label.toLowerCase().includes(u.toLowerCase())):e;return r.jsxs("div",{ref:h,className:o??"",children:[r.jsxs("div",{ref:p,onClick:()=>{d(!c),f(""),setTimeout(()=>x.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[c?r.jsx("input",{ref:x,value:u,onChange:S=>f(S.target.value),onClick:S=>S.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:k||s,autoFocus:!0}):r.jsx("span",{className:k?"text-fg-primary":"text-fg-tertiary",children:k||s}),r.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&y&&r.jsx("div",{ref:b,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:y.flipUp?{bottom:window.innerHeight-y.top,left:y.left,width:y.width}:{top:y.top,left:y.left,width:y.width},children:j.length===0?r.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:a??"No matches"}):j.map(S=>r.jsx("div",{onClick:()=>{n(S.value),d(!1),f("")},className:`px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 ${S.value===t?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:S.label},S.value))})]})}function LJ({options:e,selected:t,onAdd:n,placeholder:s,noMatchesText:a,className:o}){const[c,d]=v.useState(!1),[u,f]=v.useState(""),h=v.useRef(null),p=v.useRef(null),x=v.useRef(null),b=v.useRef(null),y=i7(p,c);v.useEffect(()=>{const S=T=>{h.current&&!h.current.contains(T.target)&&b.current&&!b.current.contains(T.target)&&d(!1)};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[]);const k=e.filter(S=>!t.includes(S.value)),j=u?k.filter(S=>S.label.toLowerCase().includes(u.toLowerCase())):k;return r.jsxs("div",{ref:h,className:o??"",children:[r.jsxs("div",{ref:p,onClick:()=>{d(!c),f(""),setTimeout(()=>x.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[c?r.jsx("input",{ref:x,value:u,onChange:S=>f(S.target.value),onClick:S=>S.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:s,autoFocus:!0}):r.jsx("span",{className:"text-fg-tertiary",children:s}),r.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&y&&r.jsx("div",{ref:b,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:y.flipUp?{bottom:window.innerHeight-y.top,left:y.left,width:y.width}:{top:y.top,left:y.left,width:y.width},children:j.length===0?r.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:a??"No matches"}):j.map(S=>r.jsx("div",{onClick:()=>{n(S.value),f("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:S.label},S.value))})]})}function Mc(e,t,n,s="Admin"){if(!e)return null;const a=t.find(c=>c.id===e);if(a)return a.name;const o=n.find(c=>c.id===e);return o?o.name:e==="anonymous"?s:null}function OJ({value:e,onSave:t,className:n,placeholder:s}){const{t:a}=ht(["work","common"]),[o,c]=v.useState(!1),[d,u]=v.useState(e),f=v.useRef(null);v.useEffect(()=>{u(e)},[e]),v.useEffect(()=>{o&&f.current?.focus()},[o]);const h=async()=>{c(!1);const p=d.trim();if(p&&p!==e)try{await t(p)}catch{u(e)}else u(e)};return o?r.jsx("input",{ref:f,value:d,onChange:p=>u(p.target.value),onBlur:()=>{h()},onKeyDown:p=>{p.key==="Enter"&&h(),p.key==="Escape"&&(u(e),c(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${n??""}`,placeholder:s}):r.jsx("span",{onClick:()=>c(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${n??""}`,title:a("work:task.clickToEdit"),children:e||r.jsx("span",{className:"text-fg-tertiary italic",children:s??a("work:task.clickToEdit")})})}function _J({value:e,onSave:t,className:n,placeholder:s}){const{t:a}=ht(["work","common"]),[o,c]=v.useState(!1),[d,u]=v.useState(e),f=v.useRef(null);v.useEffect(()=>{u(e)},[e]),v.useEffect(()=>{o&&f.current&&(f.current.focus(),f.current.style.height="auto",f.current.style.height=f.current.scrollHeight+"px")},[o]);const h=async()=>{c(!1);const p=d.trim();if(p!==e)try{await t(p)}catch{u(e)}else u(e)};return o?r.jsx("textarea",{ref:f,value:d,onChange:p=>{u(p.target.value),p.target.style.height="auto",p.target.style.height=p.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:p=>{p.key==="Escape"&&(u(e),c(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${n??""}`,placeholder:s,rows:2}):r.jsx("p",{onClick:()=>c(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${n??""}`,title:a("work:task.clickToEdit"),children:e||r.jsx("span",{className:"text-fg-tertiary italic",children:s??a("work:task.addDescription")})})}const IJ=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function o7(e){const t=e.match(IJ);return t?{timestamp:t[1].trim(),author:t[2]?.trim()??"System",content:t[3].trim()}:{timestamp:"",author:"",content:e}}function PJ(e,t){if(!e)return"";const n=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!n)return e;const s=new Date,a=+n[1],o=+n[2]-1,c=+n[3],d=+n[4],u=+n[5],f=new Date(a,o,c,d,u),h=s.getTime()-f.getTime();return h<6e4?t("work:relative.justNow"):h<36e5?t("work:relative.minutesAgo",{count:Math.floor(h/6e4)}):h<864e5?t("work:relative.hoursAgo",{count:Math.floor(h/36e5)}):h<6048e5?t("work:relative.daysAgo",{count:Math.floor(h/864e5)}):`${a}-${String(o+1).padStart(2,"0")}-${String(c).padStart(2,"0")}`}const rk=[{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 zJ(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return rk[Math.abs(t)%rk.length]}function $J({note:e,compact:t}){const{t:n}=ht(["work","common"]),s=o7(e),a=n("work:task.systemAuthor"),o=zJ(s.author||a),c=s.author?s.author.split(/[\s_-]+/).map(f=>f[0]).join("").slice(0,2).toUpperCase():"SY",d=PJ(s.timestamp,n),u=!s.author||s.author==="System";return t?r.jsxs("div",{className:"flex gap-2.5 group",children:[r.jsx("div",{className:`w-6 h-6 rounded-full ${o.bg} flex items-center justify-center text-[9px] font-bold ${o.text} shrink-0 mt-0.5`,children:c}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[r.jsx("span",{className:`text-[11px] font-medium ${u?"text-fg-tertiary":o.text}`,children:u?a:s.author}),d&&r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d})]}),r.jsx("div",{className:"text-xs text-fg-secondary",children:r.jsx(Lr,{content:s.content,className:"text-xs text-fg-secondary"})})]})]}):r.jsxs("div",{className:"flex gap-3 group",children:[r.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[r.jsx("div",{className:`w-7 h-7 rounded-full ${o.bg} flex items-center justify-center text-[10px] font-bold ${o.text}`,children:c}),r.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),r.jsx("div",{className:"flex-1 min-w-0 pb-4",children:r.jsxs("div",{className:`border ${o.border} rounded-lg overflow-hidden`,children:[r.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${o.bg} border-b ${o.border}`,children:[r.jsx("span",{className:`text-[11px] font-medium ${u?"text-fg-secondary":o.text}`,children:u?a:s.author}),d&&r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d})]}),r.jsx("div",{className:"px-3 py-2.5",children:r.jsx(Lr,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const f1=[{id:"failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",statuses:["pending"],accent:"border-t-amber-500",dropStatus:"pending"},{id:"in_progress",statuses:["in_progress","blocked"],accent:"border-t-brand-500",dropStatus:"in_progress"},{id:"review",statuses:["review"],accent:"border-t-purple-500",dropStatus:"review"},{id:"done",statuses:["completed"],accent:"border-t-green-500",dropStatus:"completed"},{id:"closed",statuses:["rejected","cancelled","archived"],accent:"border-t-gray-500",dropStatus:"cancelled"}],sk={pending:"bg-amber-500/15 text-amber-600",blocked:"bg-amber-500/15 text-amber-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500"},ak={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-blue-500/15 text-blue-500",blocked:"bg-orange-500/15 text-orange-500",review:"bg-purple-500/15 text-purple-500",revision:"bg-amber-500/15 text-amber-600",completed:"bg-green-500/15 text-green-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-500/15 text-fg-tertiary",archived:"bg-gray-500/15 text-fg-tertiary"},BJ={urgent:"border-l-red-500",high:"border-l-amber-500",medium:"border-l-blue-500",low:"border-l-gray-500"},ik={low:"bg-gray-500/15 text-fg-tertiary",medium:"bg-blue-500/15 text-blue-500",high:"bg-amber-500/15 text-amber-600",urgent:"bg-red-500/15 text-red-500"},ok={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-brand-500/15 text-brand-500",completed:"bg-green-500/15 text-green-600",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-600/15 text-fg-tertiary",archived:"bg-gray-600/10 text-fg-tertiary/60"};function l7(e){return Object.keys(ak).reduce((t,n)=>(t[n]={label:e(`work:status.task.${n}`),cls:ak[n]},t),{})}function c7(e){return Object.keys(sk).reduce((t,n)=>(t[n]={label:e(`work:status.sub.${n}`),cls:sk[n]},t),{})}function HJ(e){return Object.keys(ik).reduce((t,n)=>(t[n]={label:e(`work:priority.${n}`),cls:ik[n]},t),{})}function m1(e){return Object.keys(ok).reduce((t,n)=>(t[n]={label:e(`work:status.requirement.${n}`),cls:ok[n]},t),{})}const lk=["low","medium","high","urgent"],ck=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],dk=["pending","in_progress","completed","rejected","cancelled"],uk={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived"]),archived:new Set([])},Jx={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},eb={idle:"bg-green-400",working:"bg-blue-400",error:"bg-red-400",paused:"bg-amber-400",offline:"bg-gray-600",pending:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",rejected:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},fk={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function qJ({agent:e,anchorRect:t,onClose:n}){const{t:s}=ht(["work","common"]),a=v.useRef(null);v.useEffect(()=>{const u=f=>{a.current&&!a.current.contains(f.target)&&n()};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[n]);const o=e.status!=="error"&&!!e.lastError&&!!e.lastErrorAt&&Date.now()-new Date(e.lastErrorAt).getTime()<1800*1e3,c=e.status==="idle"&&!o?"bg-green-400":e.status==="working"&&!o?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":o?"bg-amber-400":"bg-gray-500",d=e.status==="idle"?s("work:task.online"):e.status==="working"?s("work:task.working"):e.status==="error"?s("work:task.error"):e.status==="paused"?s("work:task.paused"):s("work:task.offline");return r.jsxs("div",{ref:a,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:t.top+4,left:t.left},children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.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()}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),r.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),r.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${c}`}),r.jsx("span",{className:"text-[10px] text-fg-secondary",children:d})]})]})]}),r.jsx("button",{onClick:()=>{n(),St.navigate(_e.TEAM,{selectAgent:e.id})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1 transition-colors",children:s("work:task.viewProfile")})]})}function Kd({comment:e,agents:t,onReply:n}){const{t:s}=ht(["work","common"]),a=e.authorType==="agent"||e.authorType==="system",o=new Date(e.createdAt),c=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),d=o.toLocaleDateString([],{month:"short",day:"numeric"}),[u,f]=v.useState(null),[h,p]=v.useState(!1),[x,b]=v.useState([]),[y,k]=v.useState(!1),j=v.useCallback((E,B)=>{const A=t.find(H=>H.name.toLowerCase()===E.toLowerCase());if(A){const H=B.target.getBoundingClientRect();f({agent:A,top:H.bottom,left:H.left})}},[t]),S=v.useCallback(E=>{const B=t.find(A=>A.name.toLowerCase()===e.authorName.toLowerCase());if(B){const A=E.currentTarget.getBoundingClientRect();f({agent:B,top:A.bottom,left:A.left})}},[t,e.authorName]),T=v.useCallback(async()=>{if(h){p(!1);return}const E=e.activityId;if(E&&(p(!0),!(x.length>0))){k(!0);try{const{logs:B}=await ue.agents.getActivityLogs(e.authorId,E),A=B.map(H=>zk(H,E,e.authorId)).filter(H=>H!==null).map(H=>({...H,ts:new Date(H.createdAt).getTime()}));b(A)}catch{}k(!1)}},[h,x.length,e]),N=v.useMemo(()=>su(x.map(au).filter(E=>E!==null)),[x]);return r.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[r.jsx("div",{onClick:S,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${a?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[r.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${a?"text-indigo-400":"text-blue-400"}`,onClick:S,children:e.authorName}),r.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[d," ",c]}),n&&r.jsx("button",{onClick:()=>n(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s("work:task.reply")}),e.activityId&&a&&r.jsx("button",{onClick:T,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s(h?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&r.jsxs("button",{onClick:()=>{const E=document.getElementById(`comment-${e.replyTo}`);E&&(E.scrollIntoView({behavior:"smooth",block:"center"}),E.classList.add("bg-brand-500/10"),setTimeout(()=>E.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[r.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),r.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),r.jsx(Lr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:j,knownNames:t.map(E=>E.name)}),e.attachments?.map((E,B)=>E.type==="image"?r.jsx("img",{src:E.url,alt:E.name,className:"mt-1 max-w-[200px] rounded"},B):null),h&&r.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:y?r.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:s("work:task.loadingExecutionLog")}):N.length===0?r.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:s("work:task.noExecutionLogAvailable")}):r.jsx(ym,{entries:x,isActive:!1,onCollapse:()=>p(!1),embedded:!0})})]}),u&&r.jsx(qJ,{agent:u.agent,anchorRect:{top:u.top,left:u.left},onClose:()=>f(null)})]})}function FJ({task:e,agents:t,users:n,authUser:s}){const{t:a}=ht(["work","common"]),[o,c]=v.useState([]),[d,u]=v.useState([]),f=v.useRef(null);v.useEffect(()=>{ue.tasks.getComments(e.id).then(k=>c(k.comments)).catch(()=>{})},[e.id]),v.useEffect(()=>gn.on("task:comment",j=>{if(j.payload?.taskId===e.id&&j.payload.comment){const S=j.payload.comment;c(T=>T.some(N=>N.id===S.id)?T:[...T,S]),(S.authorType==="agent"||S.authorId?.startsWith("agt_"))&&u(T=>{const N=T.filter(E=>E.id!==S.authorId);return N.length===0&&f.current&&(clearTimeout(f.current),f.current=null),N})}}),[e.id]);const h=v.useMemo(()=>{const k=[];for(const j of e.notes??[]){const S=o7(j);let T;if(S.timestamp){const N=S.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);T=N?new Date(+N[1],+N[2]-1,+N[3],+N[4],+N[5],+(N[6]??0)):new Date(0)}else T=new Date(0);k.push({type:"note",note:j,ts:T})}for(const j of o)k.push({type:"comment",comment:j,ts:new Date(j.createdAt)});return k.sort((j,S)=>j.ts.getTime()-S.ts.getTime()),k},[e.notes,o]),[p,x]=v.useState(null),b=async(k,j,S,T)=>{let N;S.length>0&&(N=(await ue.uploads.upload(S.map(O=>({dataUrl:O.dataUrl,name:O.name})),"comments")).files.map(O=>({type:"image",url:O.url,name:O.name}))),await ue.tasks.addComment(e.id,k,s?.name,N,s?.id,j.length>0?j:void 0,T);const E=[],B=new Set,A=H=>{if(B.has(H)||H===s?.id)return;B.add(H);const O=t.find(z=>z.id===H);O&&E.push({id:O.id,name:O.name,avatarUrl:O.avatarUrl})};for(const H of j){const O=t.find(z=>z.name.toLowerCase()===H.toLowerCase());O&&A(O.id)}e.assignedAgentId&&A(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&A(e.createdBy),E.length>0&&(f.current&&clearTimeout(f.current),u(E),f.current=setTimeout(()=>u([]),12e4))},y=v.useCallback(k=>{x({id:k.id,authorName:k.authorName,content:k.content.slice(0,100)})},[]);return r.jsxs("div",{className:"mt-5",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:a("work:task.activityCommentsHeading")}),r.jsxs("div",{className:"space-y-0.5 mb-3",children:[h.length===0&&r.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:a("work:task.noActivityYet")}),h.map((k,j)=>k.type==="note"?r.jsx($J,{note:k.note,compact:!0},`n-${j}`):r.jsx(Kd,{comment:k.comment,agents:t,onReply:y},`c-${k.comment.id}`)),d.length>0&&r.jsx("div",{className:"flex flex-col gap-1 pt-1",children:d.map(k=>r.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>St.navigate(_e.TEAM,{agentId:k.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(hs,{name:k.name,avatarUrl:k.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),r.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),r.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:k.name}),r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:a("work:task.agentProcessing")}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]},k.id))})]}),r.jsx(iN,{agents:t,humans:n,onSubmit:b,replyTo:p,onCancelReply:()=>x(null),placeholder:a("work:task.commentPlaceholder")})]})}function UJ({task:e,isRunning:t,authUser:n,agents:s}){const a=e.id,{t:o}=ht(["work","common"]),[c,d]=v.useState([]),[u,f]=v.useState(new Map),[h,p]=v.useState(new Set),[x,b]=v.useState([]),[y,k]=v.useState(""),[j,S]=v.useState(t),[T,N]=v.useState(!0),[E,B]=v.useState(new Set),[A,H]=v.useState(""),[O,z]=v.useState(!1),[I,_]=v.useState([]),X=v.useRef(null),[G,M]=v.useState([]),[U,L]=v.useState([]),[F,Z]=v.useState(!1),Y=v.useRef(null),D=v.useRef(null);v.useEffect(()=>{S(t)},[t]),v.useEffect(()=>{N(!0),Promise.all([ue.tasks.getLogsSummary(a).catch(()=>({rounds:[]})),ue.tasks.getComments(a).catch(()=>({comments:[]}))]).then(([te,we])=>{const ce=te.rounds;if(d(ce),b(we.comments),ce.length===0){N(!1);return}const ge=ce[ce.length-1].round;B(new Set([ge])),ue.tasks.getLogs(a,ge).catch(()=>({logs:[]})).then(Ce=>{f(new Map([[ge,Ce.logs]])),N(!1)})})},[a]),v.useEffect(()=>{const te=e.assignedAgentId;te&&(Z(!0),ue.agents.getActivities(te,{taskId:a,limit:20}).then(we=>L(we.activities)).catch(()=>L([])).finally(()=>Z(!1)))},[a,e.assignedAgentId]);const P=v.useCallback(te=>{u.has(te)||h.has(te)||(p(we=>new Set(we).add(te)),ue.tasks.getLogs(a,te).catch(()=>({logs:[]})).then(we=>{f(ce=>new Map(ce).set(te,we.logs)),p(ce=>{const ge=new Set(ce);return ge.delete(te),ge})}))},[a,u,h]),ee=v.useCallback(te=>{B(we=>{const ce=new Set(we);return ce.has(te)?ce.delete(te):(ce.add(te),u.has(te)||P(te)),ce})},[u,P]);v.useEffect(()=>{const te=gn.on("task:log",ge=>{const Ce=ge.payload;if(Ce.taskId!==a)return;const Be={id:Ce.id,taskId:Ce.taskId,agentId:Ce.agentId,seq:Ce.seq,type:Ce.logType,content:Ce.content,metadata:Ce.metadata,executionRound:Ce.executionRound,createdAt:Ce.createdAt},Qe=Be.executionRound??1;d(We=>We.find(bt=>bt.round===Qe)?We:[...We,{round:Qe,logCount:0,toolCount:0,firstAt:Be.createdAt,lastAt:Be.createdAt,status:"running"}]),B(We=>We.has(Qe)?We:new Set(We).add(Qe)),f(We=>{const wt=We.get(Qe)??[];return Be.id&&wt.some(bt=>bt.id===Be.id)?We:new Map(We).set(Qe,[...wt,Be])}),Be.type==="text"&&k(""),Be.type==="status"&&(Be.content==="started"||Be.content==="resumed"?S(!0):["completed","failed","cancelled","execution_finished"].includes(Be.content)&&(S(!1),d(We=>We.map(wt=>wt.round===Qe?{...wt,status:Be.content}:wt)))),Be.type==="error"&&S(!1)}),we=gn.on("task:log:delta",ge=>{const Ce=ge.payload;Ce.taskId===a&&k(Be=>Be+Ce.text)}),ce=gn.on("task:comment",ge=>{const Ce=ge.payload;if(Ce.taskId!==a)return;const Be=Ce.comment;b(Qe=>Qe.some(We=>We.id===Be.id)?Qe:[...Qe,Be]),(Be.authorType==="agent"||Be.authorId?.startsWith("agt_"))&&_(Qe=>{const We=Qe.filter(wt=>wt.id!==Be.authorId);return We.length===0&&X.current&&(clearTimeout(X.current),X.current=null),We})});return()=>{te(),we(),ce()}},[a]);const $=v.useMemo(()=>{const te=[];for(const[,we]of u)te.push(...we);return te.sort((we,ce)=>we.seq-ce.seq),te},[u]),Q=v.useMemo(()=>$.map(te=>Xg(te)),[$]),q=c.length>1,J=te=>{const we=te.target.files;if(we){for(const ce of Array.from(we)){if(!ce.type.startsWith("image/"))continue;const ge=new FileReader;ge.onload=()=>{M(Ce=>[...Ce,{type:"image",url:ge.result,name:ce.name}])},ge.readAsDataURL(ce)}te.target.value=""}},K=async()=>{if(!(!A.trim()&&G.length===0)){z(!0);try{let te;G.length>0&&(te=(await ue.uploads.upload(G.map(Qe=>({dataUrl:Qe.url,name:Qe.name})),"comments")).files.map(Qe=>({type:"image",url:Qe.url,name:Qe.name})));const we=await ue.tasks.addComment(a,A,n?.name,te,n?.id);we.comment&&b(Be=>Be.some(Qe=>Qe.id===we.comment.id)?Be:[...Be,we.comment]),H(""),M([]);const ce=[],ge=new Set,Ce=Be=>{if(ge.has(Be)||Be===n?.id)return;ge.add(Be);const Qe=s.find(We=>We.id===Be);Qe&&ce.push({id:Qe.id,name:Qe.name,avatarUrl:Qe.avatarUrl})};e.assignedAgentId&&Ce(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&Ce(e.createdBy),ce.length>0&&(X.current&&clearTimeout(X.current),_(ce),X.current=setTimeout(()=>_([]),12e4))}catch{}z(!1)}},re=r.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-secondary z-10",children:[G.length>0&&r.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:G.map((te,we)=>r.jsxs("div",{className:"relative group",children:[r.jsx("img",{src:te.url,alt:te.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),r.jsx("button",{onClick:()=>M(ce=>ce.filter((ge,Ce)=>Ce!==we)),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:"×"})]},we))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:A,onChange:te=>H(te.target.value),onKeyDown:te=>{te.key==="Enter"&&!te.shiftKey&&(te.preventDefault(),K())},placeholder:o("work:task.commentInstructionPlaceholder"),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"}),r.jsx("input",{type:"file",ref:Y,accept:"image/*",multiple:!0,onChange:J,className:"hidden"}),r.jsx("button",{onClick:()=>Y.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:o("work:task.attachImage"),children:"📎"}),r.jsx("button",{onClick:()=>{K()},disabled:O||!A.trim()&&G.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:o("common:send")})]})]});if(T)return r.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:o("work:task.loadingLogs")});if(c.length===0&&!y){const te=e.assignedAgentId?s.find(bt=>bt.id===e.assignedAgentId):void 0,we=U.length>0,ce=te&&te.currentTaskId&&te.currentTaskId!==e.id,ge=e.status==="pending",Ce=e.status==="in_progress",Be=!e.assignedAgentId;let Qe="📋",We=o("work:task.emptyLogs.default"),wt=o("work:task.emptyLogs.defaultHint");return Be?(Qe="👤",We=o("work:task.emptyLogs.noAgent"),wt=o("work:task.emptyLogs.noAgentHint")):ge?(Qe="⏳",We=o("work:task.emptyLogs.pending"),wt=o("work:task.emptyLogs.pendingHint")):Ce&&ce?(Qe="🔄",We=o("work:task.emptyLogs.agentBusy",{agent:te?.name??e.assignedAgentId}),wt=o("work:task.emptyLogs.agentBusyHint")):Ce&&(Qe="⏳",We=o("work:task.emptyLogs.starting"),wt=o("work:task.emptyLogs.startingHint")),r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsx("div",{className:"flex-1 overflow-y-auto",children:F?r.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:o("work:task.loadingLogs")}):we?r.jsxs("div",{className:"px-4 py-4",children:[r.jsxs("div",{className:"text-xs text-fg-secondary mb-3 flex items-center gap-1.5",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-blue-500"}),o("work:task.relatedSessions",{agent:te?.name??o("work:task.agent"),count:U.length})]}),r.jsx("div",{className:"space-y-1.5",children:U.map(bt=>{const $t=!bt.endedAt,dt=bt.type==="task"?"🔧":bt.type==="chat"||bt.type==="respond_in_session"?"💬":bt.type==="heartbeat"?"💓":"📋";return r.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default/50 text-left transition-colors group",onClick:()=>St.navigate(_e.TEAM,{agentId:e.assignedAgentId}),children:[r.jsx("span",{className:"text-sm shrink-0",children:dt}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs text-fg-primary truncate",children:bt.label}),r.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(bt.startedAt).toLocaleString(),bt.endedAt?` — ${bt.totalTools} tools, ${bt.totalTokens.toLocaleString()} tokens`:""]})]}),$t&&r.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10px] text-green-500 font-medium",children:[r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"}),o("work:task.sessionLive")]}),!$t&&r.jsx("span",{className:`shrink-0 text-[10px] ${bt.success?"text-fg-tertiary":"text-red-400"}`,children:bt.success?"✓":"✗"}),r.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},bt.id)})})]}):r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsxs("div",{className:"text-center text-fg-tertiary",children:[r.jsx("div",{className:"text-2xl mb-2",children:Qe}),r.jsxs("div",{className:"text-xs",children:[We,r.jsx("br",{}),r.jsx("span",{className:"text-fg-muted",children:wt})]})]})})}),re]})}if(!q){const te=Q.map(ge=>au(ge)).filter(ge=>ge!==null),we=mw($,su(te)),ce=[...we.map(ge=>({kind:"entry",entry:ge,ts:ge.timestamp?new Date(ge.timestamp).getTime():0})),...x.map(ge=>({kind:"comment",comment:ge,ts:new Date(ge.createdAt).getTime()}))];return ce.sort((ge,Ce)=>ge.ts-Ce.ts),r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsxs("div",{className:"px-4 py-3 flex-1 space-y-0.5",children:[ce.map((ge,Ce)=>ge.kind==="comment"?r.jsx(Kd,{comment:ge.comment,agents:s},`c-${ge.comment.id}`):r.jsx(zf,{entry:ge.entry,showTime:!0,isLast:Ce===ce.length-1},`e-${Ce}`)),j&&y&&r.jsx(Mx,{content:y}),j&&!y&&we.length>0&&r.jsx(Ex,{})]}),re]})}const de=(te,we)=>{const ce=te.firstAt?new Date(te.firstAt).getTime():0,ge=we?.firstAt?new Date(we.firstAt).getTime():1/0;return x.filter(Ce=>{const Be=new Date(Ce.createdAt).getTime();return Be>=ce&&Be<ge})},pe=c.length>0?x.filter(te=>new Date(te.createdAt).getTime()<new Date(c[0].firstAt).getTime()):[];return r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsx("div",{ref:D}),r.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[pe.length>0&&r.jsx("div",{className:"space-y-0.5",children:pe.map(te=>r.jsx(Kd,{comment:te,agents:s},te.id))}),c.map((te,we)=>{const ce=E.has(te.round),ge=te.round===c[c.length-1].round,Ce=u.get(te.round),Be=h.has(te.round),Qe=de(te,c[we+1]),We=te.status==="completed"||te.status==="execution_finished"?"✅":te.status==="failed"?"❌":te.status==="cancelled"?"⏹":"🔄",wt=te.lastAt&&te.firstAt?Math.max(0,new Date(te.lastAt).getTime()-new Date(te.firstAt).getTime()):0,bt=wt>=6e4?`${Math.floor(wt/6e4)}m ${Math.floor(wt%6e4/1e3)}s`:wt>=1e3?`${Math.floor(wt/1e3)}s`:"";return r.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>ee(te.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:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm",children:We}),r.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:o("work:task.roundHeader",{n:te.round})}),Qe.length>0&&r.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",Qe.length]}),ge&&j&&r.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.toolCount",{count:te.toolCount})}),bt&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:bt}),r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${ce?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})]})]}),ce&&r.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[Be&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:o("work:task.loadingRound",{n:te.round})}),Ce&&(()=>{const dt=Ce.map(Re=>Xg(Re)).map(Re=>au(Re)).filter(Re=>Re!==null),ve=[...mw(Ce,su(dt)).map(Re=>({kind:"entry",entry:Re,ts:Re.timestamp?new Date(Re.timestamp).getTime():0})),...Qe.map(Re=>({kind:"comment",comment:Re,ts:new Date(Re.createdAt).getTime()}))];return ve.sort((Re,ke)=>Re.ts-ke.ts),ve.map((Re,ke)=>Re.kind==="comment"?r.jsx(Kd,{comment:Re.comment,agents:s},`c-${Re.comment.id}`):r.jsx(zf,{entry:Re.entry,showTime:!0,isLast:ke===ve.length-1},`e-${ke}`))})(),ge&&j&&y&&r.jsx(Mx,{content:y}),ge&&j&&!y&&!Be&&r.jsx(Ex,{})]})]},te.round)}),I.length>0&&r.jsx("div",{className:"flex flex-col gap-1 mt-2",children:I.map(te=>r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>St.navigate(_e.TEAM,{agentId:te.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(hs,{name:te.name,avatarUrl:te.avatarUrl,size:24,bgClass:"bg-brand-500/15 text-brand-600"}),r.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),r.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[r.jsx("span",{className:"text-xs font-medium text-fg-secondary truncate",children:te.name}),r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")})]}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]},te.id))})]}),re]})}function VJ({filePath:e,onClose:t}){const{t:n}=ht(["work","common"]),[s,a]=v.useState(null),[o,c]=v.useState(null),[d,u]=v.useState(!0);v.useEffect(()=>{u(!0),c(null),ue.files.preview(e).then(h=>a(h)).catch(h=>c(String(h))).finally(()=>u(!1))},[e]);const f=e.split("/").pop()??e;return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",onClick:t,children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl w-[720px] max-w-[92vw] max-h-[85vh] flex flex-col shadow-2xl",onClick:h=>h.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[r.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),r.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),r.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:f})]}),r.jsx("button",{onClick:t,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0 ml-3",children:"×"})]}),r.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:e})}),r.jsxs("div",{className:"flex-1 overflow-auto min-h-0 p-5",children:[d&&r.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:n("work:task.filePreviewLoading")}),o&&r.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:o}),s&&s.type==="image"&&r.jsx("div",{className:"flex justify-center",children:r.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"&&r.jsx(Lr,{content:s.content,className:"text-sm text-fg-secondary leading-relaxed"}),s&&s.type==="text"&&r.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 GJ({task:e,agents:t,projects:n,requirements:s,allTasks:a,users:o,onClose:c,onRefresh:d,authUser:u,scrollToComments:f,onScrollToCommentsDone:h}){const{t:p}=ht(["work","common"]),x=v.useMemo(()=>l7(p),[p]),[b,y]=v.useState([]),[k,j]=v.useState(""),[S,T]=v.useState(!1),[N,E]=v.useState(!1),[B,A]=v.useState(null),[H,O]=v.useState(null),[z,I]=v.useState(!1),[_,X]=v.useState(!1),[G,M]=v.useState(!1),[U,L]=v.useState("every"),[F,Z]=v.useState(""),[Y,D]=v.useState(""),[P,ee]=v.useState(""),[$,Q]=v.useState(!1),[q,J]=v.useState("details"),K=v.useRef(null),[re,de]=v.useState("none"),pe=v.useCallback(Ee=>{J(Ee),requestAnimationFrame(()=>{K.current?.scrollTo({top:0,behavior:"instant"})})},[]),te=v.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),we=Hi(te,q,pe);v.useEffect(()=>{const Ee=K.current;if(!Ee)return;const Ke=()=>{const{scrollTop:ot,scrollHeight:ut,clientHeight:jt}=Ee;if(!(ut>jt+50)){de("none");return}const Hn=ot<30,Tr=ot+jt>=ut-30;de(Hn?"top":Tr?"bottom":"middle")};Ke(),Ee.addEventListener("scroll",Ke,{passive:!0});const Ae=new ResizeObserver(Ke);return Ae.observe(Ee),()=>{Ee.removeEventListener("scroll",Ke),Ae.disconnect()}},[q]),v.useEffect(()=>{if(!f)return;J("details");const Ee=setTimeout(()=>{const Ke=K.current;Ke&&Ke.scrollTo({top:Ke.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(Ee)},[f,h]);const[ce,ge]=v.useState(null),[Ce,Be]=v.useState(null),[Qe,We]=v.useState(!1),[wt,bt]=v.useState(e.description),[$t,dt]=v.useState(!1),[me,ve]=v.useState(""),[Re,ke]=v.useState(1),[Pe,lt]=v.useState(!1),at=ws(),gt=20,Ft=v.useCallback(async()=>{try{const Ee=await ue.tasks.listSubtasks(e.id);y(Ee.subtasks)}catch{}},[e.id]);v.useEffect(()=>{Ft()},[Ft]);const Bt=async Ee=>{if(!$){Q(!0);try{await Ee(),d(),await Ft()}catch(Ke){ge(String(Ke).replace("Error: ",""))}finally{Q(!1)}}},tn=Ee=>Bt(()=>ue.tasks.update(e.id,{priority:Ee})),It=Ee=>Bt(()=>ue.tasks.assign(e.id,Ee||null)),Pt=Ee=>Bt(()=>ue.tasks.update(e.id,{projectId:Ee||null})),Nt=async()=>{if(!$){Q(!0);try{await ue.tasks.pause(e.id),d()}finally{Q(!1)}}},cn=async()=>{if(!$){Q(!0),ge(null),pe("logs");try{await ue.tasks.resume(e.id),d()}catch(Ee){ge(String(Ee).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{Q(!1)}}},Xt=async()=>{k.trim()&&(await ue.tasks.createSubtask(e.id,k.trim()),j(""),T(!1),Ft(),d())},pn=async Ee=>{Ee.status==="completed"?await ue.tasks.cancelSubtask(e.id,Ee.id):await ue.tasks.completeSubtask(e.id,Ee.id),Ft(),d()},On=async Ee=>{await ue.tasks.deleteSubtask(e.id,Ee.id),A(null),Ft(),d()},rn=async()=>{if(!$){Q(!0);try{await ue.tasks.updateStatus(e.id,"in_progress"),d()}finally{Q(!1)}}},xn=async()=>{if(!$){Q(!0),ge(null),pe("logs");try{await ue.tasks.retry(e.id),d()}catch(Ee){ge(String(Ee).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{Q(!1)}}},Gn=async()=>{if(!$){Q(!0),ge(null),pe("logs");try{await ue.tasks.runNow(e.id),d()}catch(Ee){ge(String(Ee).replace("Error: API error: 400","Server error").replace("Error: ","")),d()}finally{Q(!1)}}},wn=v.useRef(d);wn.current=d,v.useEffect(()=>gn.on("task:update",Ke=>{Ke.payload.taskId===e.id&&(Ft(),wn.current())}),[e.id,Ft]);const An=b.filter(Ee=>Ee.status==="completed").length,sn=e.status==="in_progress",Pn=e.status==="blocked",Dn=e.status==="completed",Zt=e.status==="failed",Sr=e.status==="rejected",Bn=e.status==="cancelled",zr=e.status==="archived",gr=Dn||Zt||Sr||Bn||zr,sr=e.taskType==="scheduled"&&!!e.scheduleConfig,fr=sr&&!!e.scheduleConfig?.paused,Cr=n.find(Ee=>Ee.id===e.projectId),$r=s.find(Ee=>Ee.id===e.requirementId);return t.find(Ee=>Ee.id===e.assignedAgentId),r.jsxs("div",{className:"flex flex-col h-full overflow-hidden bg-surface-secondary",children:[r.jsxs("div",{className:"flex items-start justify-between px-6 pt-5 pb-3 border-b border-border-default shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1 pr-4",children:[at&&r.jsx("button",{onClick:c,className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),r.jsxs("div",{className:"flex items-center gap-2 flex-wrap flex-1 min-w-0",children:[r.jsx("h3",{className:"text-base font-semibold leading-snug truncate",children:e.title}),(()=>{const Ee=x[e.status];return Ee?r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap ${Ee.cls}`,children:Ee.label}):r.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," ")})})()]})]}),!at&&r.jsx("button",{onClick:c,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]}),r.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 border-b border-border-default shrink-0 bg-surface-secondary",children:[r.jsx("button",{onClick:()=>pe("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${q==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:p("work:task.detailsTab")}),r.jsxs("button",{onClick:()=>pe("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${q==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[p("work:task.executionLogTab"),sn&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),r.jsx("button",{onClick:()=>pe("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${q==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const Ee=(e.deliverables??[]).filter(Ke=>Ke.type!=="branch"&&typeof Ke.reference=="string"&&Ke.reference.length>0).length;return Ee>0?p("work:task.deliverablesCount",{count:Ee}):p("work:task.deliverables")})()}),r.jsx("button",{onClick:()=>pe("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${q==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:p("work:task.historyTab")})]}),r.jsxs("div",{className:"flex-1 min-h-0 relative",children:[r.jsxs("div",{ref:K,className:"h-full overflow-y-auto",onTouchStart:we.onTouchStart,onTouchEnd:we.onTouchEnd,children:[q==="logs"&&r.jsxs("div",{className:"overflow-x-clip min-w-0 min-h-full",children:[ce&&r.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:[r.jsx("span",{className:"font-medium",children:p("work:task.failedToStart")})," ",ce]}),r.jsx(UJ,{task:e,isRunning:e.status==="in_progress",authUser:u,agents:t})]}),q==="details"&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:Qe?r.jsxs("div",{className:"space-y-2",children:[r.jsx("textarea",{value:wt,onChange:Ee=>bt(Ee.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:p("work:task.addDescription")}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{onClick:()=>{We(!1),bt(e.description)},className:"px-2.5 py-1 text-xs border border-border-default rounded-lg hover:bg-surface-elevated",children:p("common:cancel")}),r.jsx("button",{onClick:()=>{Bt(()=>ue.tasks.update(e.id,{description:wt})),We(!1)},disabled:$,className:"px-2.5 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:p("common:save")})]})]}):r.jsxs("div",{className:"group relative",children:[e.description?r.jsxs("div",{children:[r.jsx("div",{className:at&&!Pe?"line-clamp-3":"",children:r.jsx(Lr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),at&&e.description.length>150&&r.jsx("button",{onClick:()=>lt(!Pe),className:"text-[11px] text-brand-500 mt-1 font-medium",children:p(Pe?"work:task.collapse":"common:showMore")})]}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:p("work:task.noDescription")}),r.jsx("button",{onClick:()=>{bt(e.description),We(!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:p("common:edit")})]})}),(Cr||$r)&&r.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Cr&&r.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:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:p("work:task.projectLabel")}),Cr.name]}),$r&&r.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:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:p("work:task.requirementLabel")}),$r.title.length>40?$r.title.slice(0,40)+"…":$r.title]})]}),r.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default",children:[r.jsx("div",{className:"flex items-center justify-between mb-1.5",children:r.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:p("work:task.dependencies")})}),e.blockedBy&&e.blockedBy.length>0?r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(Ee=>{const Ke=a.find(ot=>ot.id===Ee),Ae=Ke&&(Ke.status==="completed"||Ke.status==="cancelled");return r.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Ae?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[r.jsx("span",{className:"text-[9px]",children:Ae?"✓":"⏳"}),r.jsx("span",{className:`font-mono ${Ae?"line-through opacity-60":""}`,children:Ke?Ke.title.slice(0,30):Ee.slice(-8)}),!gr&&r.jsx("button",{onClick:async()=>{const ot=(e.blockedBy??[]).filter(ut=>ut!==Ee);await ue.tasks.update(e.id,{blockedBy:ot}),d()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:p("work:task.removeDependency"),children:"×"})]},Ee)})}):r.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:p("work:task.noDependencies")}),!gr&&r.jsxs("select",{value:"",onChange:async Ee=>{const Ke=Ee.target.value;if(!Ke)return;const Ae=[...e.blockedBy??[],Ke];await ue.tasks.update(e.id,{blockedBy:Ae}),d()},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:[r.jsx("option",{value:"",children:p("work:task.addDependency")}),a.filter(Ee=>Ee.id!==e.id&&!(e.blockedBy??[]).includes(Ee.id)).map(Ee=>r.jsx("option",{value:Ee.id,children:Ee.title},Ee.id))]})]}),r.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:p("work:task.projectLabel")}),r.jsxs("select",{value:e.projectId??"",onChange:Ee=>{Pt(Ee.target.value)},disabled:$,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.jsx("option",{value:"",children:p("work:task.noProject")}),n.map(Ee=>r.jsx("option",{value:Ee.id,children:Ee.name},Ee.id))]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:p("work:task.requirementLabel")}),r.jsxs("select",{value:e.requirementId??"",onChange:Ee=>Bt(()=>ue.tasks.update(e.id,{requirementId:Ee.target.value||null})),disabled:$,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.jsx("option",{value:"",children:p("work:task.noRequirement")}),s.filter(Ee=>!e.projectId||Ee.projectId===e.projectId).map(Ee=>r.jsx("option",{value:Ee.id,children:Ee.title},Ee.id))]})]})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:p("work:task.assignee")}),r.jsxs("select",{value:e.assignedAgentId??"",onChange:Ee=>{It(Ee.target.value)},disabled:$,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.jsx("option",{value:"",children:p("work:task.unassigned")}),t.map(Ee=>r.jsxs("option",{value:Ee.id,children:[Ee.name," (",Ee.status,")"]},Ee.id))]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:p("work:task.reviewer")}),r.jsxs("select",{value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:Ee=>{const Ke=Ee.target.value;if(!Ke)return;const Ae=Ke.startsWith("human:"),ot=Ke.replace(/^(human|agent):/,"");(ot!==e.reviewerId||(Ae?"human":"agent")!==(e.reviewerType??"agent"))&&Bt(()=>ue.tasks.update(e.id,{reviewerId:ot,reviewerType:Ae?"human":"agent"}))},disabled:$,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:[o.map(Ee=>r.jsx("option",{value:`human:${Ee.id}`,children:Ee.name},`human:${Ee.id}`)),t.map(Ee=>r.jsx("option",{value:`agent:${Ee.id}`,children:Ee.name},`agent:${Ee.id}`))]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:p("work:task.priority")}),r.jsxs("select",{value:e.priority,onChange:Ee=>{tn(Ee.target.value)},disabled:$,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.jsx("option",{value:"low",children:p("work:priority.low")}),r.jsx("option",{value:"medium",children:p("work:priority.medium")}),r.jsx("option",{value:"high",children:p("work:priority.high")}),r.jsx("option",{value:"urgent",children:p("work:priority.urgent")})]})]})]})]}),r.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&&r.jsx("span",{children:p("work:task.createdBy",{name:Mc(e.createdBy,t,o)??e.createdBy})}),e.updatedBy&&r.jsx("span",{children:p("work:task.updatedBy",{name:Mc(e.updatedBy,t,o)??e.updatedBy})}),e.createdAt&&r.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&r.jsx("span",{children:p("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&r.jsx("span",{children:p("work:task.updatedMeta",{date:new Date(e.updatedAt).toLocaleDateString()})}),e.projectId&&r.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&r.jsx("span",{className:"text-amber-600",children:p("work:task.executionRound",{n:e.executionRound})})]}),r.jsxs("div",{className:"px-6 py-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:[p("work:task.subtasks")," ",b.length>0&&r.jsx("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:p("work:task.subtasksProgress",{done:An,total:b.length})})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[An>0&&r.jsx("button",{onClick:()=>E(Ee=>!Ee),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?p("work:task.hideCompleted"):p("work:task.showCompleted",{count:An})}),r.jsx("button",{onClick:()=>T(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:p("work:task.addSubtask")})]})]}),(()=>{const Ee=N?b:b.filter(Ke=>Ke.status!=="completed");return Ee.length>0?r.jsx("div",{className:"space-y-1.5 mb-3",children:Ee.map(Ke=>r.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:[r.jsx("button",{onClick:()=>{pn(Ke)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${Ke.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:Ke.status==="completed"&&r.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:r.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsx("span",{className:`flex-1 text-sm ${Ke.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:Ke.title}),r.jsx("button",{onClick:()=>A(Ke),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},Ke.id))}):null})(),b.length===0&&!S&&r.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:p("work:task.noSubtasksYet")}),S&&r.jsxs("div",{className:"flex gap-2 mt-2",children:[r.jsx("input",{autoFocus:!0,value:k,onChange:Ee=>j(Ee.target.value),onKeyDown:Ee=>{Ee.key==="Enter"&&Xt(),Ee.key==="Escape"&&(T(!1),j(""))},placeholder:p("work:task.subtaskTitlePlaceholder"),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"}),r.jsx("button",{onClick:()=>{Xt()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:p("work:task.add")}),r.jsx("button",{onClick:()=>{T(!1),j("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:p("common:cancel")})]}),(()=>{const Ee=(e.deliverables??[]).filter(ot=>ot.type!=="branch"&&typeof ot.reference=="string"&&ot.reference.length>0);if(Ee.length===0)return null;const Ke={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"},Ae=Ee.slice(0,3);return r.jsxs("div",{className:"mt-5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:p("work:task.deliverablesCount",{count:Ee.length})}),Ee.length>3&&r.jsx("button",{onClick:()=>pe("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:p("work:task.viewAll")})]}),r.jsx("div",{className:"space-y-1.5",children:Ae.map((ot,ut)=>{const jt=/^https?:\/\//i.test(ot.reference),er=jt?ot.summary||ot.reference:ot.reference.split("/").pop()??ot.reference;return r.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:[r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Ke[ot.type]??"bg-gray-500/15 text-fg-secondary"}`,children:ot.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[jt?r.jsxs("a",{href:ot.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:ot.reference,children:[er," ",r.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),r.jsx("path",{d:"M7 2h3v3"}),r.jsx("path",{d:"M5 7 10 2"})]})]}):r.jsx("button",{onClick:()=>Be(ot.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:ot.reference,children:er}),ot.summary&&!jt&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:ot.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:ot.reference})]})]},ut)})})]})})(),r.jsx(FJ,{task:e,agents:t,users:o,authUser:u})]})]}),q==="history"&&r.jsx(f7,{entityType:"task",entityId:e.id}),q==="deliverables"&&r.jsx("div",{className:"px-6 py-4",children:(()=>{const Ee=(e.deliverables??[]).filter(ut=>ut.type!=="branch"&&typeof ut.reference=="string"&&ut.reference.length>0);if(Ee.length===0)return r.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:p("work:task.noDeliverablesYet")});const Ke={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"},Ae=Math.ceil(Ee.length/gt),ot=Ee.slice((Re-1)*gt,Re*gt);return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:p("work:task.deliverablesCount",{count:Ee.length})}),Ae>1&&r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[r.jsx("button",{disabled:Re<=1,onClick:()=>ke(ut=>ut-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),r.jsxs("span",{children:[Re,"/",Ae]}),r.jsx("button",{disabled:Re>=Ae,onClick:()=>ke(ut=>ut+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),r.jsx("div",{className:"space-y-1.5",children:ot.map((ut,jt)=>{const er=/^https?:\/\//i.test(ut.reference),Hn=er?ut.summary||ut.reference:ut.reference.split("/").pop()??ut.reference;return r.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:[r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Ke[ut.type]??"bg-gray-500/15 text-fg-secondary"}`,children:ut.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[er?r.jsxs("a",{href:ut.reference,target:"_blank",rel:"noopener noreferrer",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:[Hn," ",r.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),r.jsx("path",{d:"M7 2h3v3"}),r.jsx("path",{d:"M5 7 10 2"})]})]}):r.jsx("button",{onClick:()=>Be(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:Hn}),ut.summary&&!er&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:ut.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:ut.reference})]})]},jt)})})]})})()})]}),re!=="none"&&re!=="top"&&r.jsx("button",{onClick:()=>K.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:p("work:task.scrollToTop"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})}),re!=="none"&&re!=="bottom"&&r.jsx("button",{onClick:()=>{const Ee=K.current;Ee&&Ee.scrollTo({top:Ee.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:p("work:task.scrollToBottom"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})})]}),sr&&e.scheduleConfig&&r.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${fr?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"}`,children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:fr?"text-amber-600":"text-brand-500",children:fr?p("work:task.schedulePaused"):r.jsxs(r.Fragment,{children:[r.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:r.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"})})," ",p("work:task.scheduled")]})}),r.jsx("span",{className:"text-fg-tertiary",children:"·"}),r.jsx("span",{className:"text-fg-secondary",children:e.scheduleConfig.every?p("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):e.scheduleConfig.cron?p("work:task.scheduleCron",{expr:e.scheduleConfig.cron}):e.scheduleConfig.runAt?p("work:task.scheduleOneShot"):p("work:task.scheduleNA")}),!fr&&e.scheduleConfig.nextRunAt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-fg-tertiary",children:"·"}),r.jsx("span",{className:"text-fg-secondary",children:p("work:task.scheduleNext",{when:(()=>{const Ee=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(Ee<=0)return p("work:task.scheduleDueNow");const Ke=Math.floor(Ee/6e4);if(Ke<60)return p("work:task.scheduleInMinutes",{count:Ke});const Ae=Math.floor(Ke/60);return Ae<24?p("work:task.scheduleInHoursMinutes",{h:Ae,m:Ke%60}):p("work:task.scheduleInDaysHours",{d:Math.floor(Ae/24),h:Ae%24})})()})})]}),!sn&&!G&&!e.scheduleConfig.runAt&&r.jsx("button",{onClick:()=>{L(e.scheduleConfig?.cron?"cron":"every"),Z(e.scheduleConfig?.every??"4h"),D(e.scheduleConfig?.cron??""),ee(e.scheduleConfig?.maxRuns!=null?String(e.scheduleConfig.maxRuns):""),M(!0)},className:"text-brand-500 hover:text-brand-400 ml-1",children:p("work:task.editSchedule")})]}),G?r.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("select",{value:U,onChange:Ee=>L(Ee.target.value),className:"px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[r.jsx("option",{value:"every",children:p("work:task.scheduleEveryMode")}),r.jsx("option",{value:"cron",children:p("work:task.scheduleCronMode")})]}),U==="every"?r.jsxs("select",{value:F,onChange:Ee=>Z(Ee.target.value),className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[r.jsx("option",{value:"30m",children:p("work:task.freq30m")}),r.jsx("option",{value:"1h",children:p("work:task.freq1h")}),r.jsx("option",{value:"2h",children:p("work:task.freq2h")}),r.jsx("option",{value:"4h",children:p("work:task.freq4h")}),r.jsx("option",{value:"8h",children:p("work:task.freq8h")}),r.jsx("option",{value:"12h",children:p("work:task.freq12h")}),r.jsx("option",{value:"1d",children:p("work:task.freq1d")}),r.jsx("option",{value:"1w",children:p("work:task.freq1w")})]}):r.jsx("input",{value:Y,onChange:Ee=>D(Ee.target.value),placeholder:"0 9 * * 1-5",className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("label",{className:"text-fg-tertiary shrink-0",children:p("work:task.scheduleMaxRuns")}),r.jsx("input",{value:P,onChange:Ee=>ee(Ee.target.value.replace(/\D/g,"")),placeholder:p("work:task.scheduleMaxRunsPlaceholder"),className:"w-20 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),r.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[r.jsx("button",{onClick:async()=>{const Ee={};U==="every"?Ee.every=F:Ee.cron=Y.trim(),P&&(Ee.maxRuns=parseInt(P,10)),await Bt(()=>ue.tasks.updateSchedule(e.id,Ee)),M(!1)},disabled:$,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:p("common:save")}),r.jsx("button",{onClick:()=>M(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:p("common:cancel")})]})]}):r.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[r.jsx("span",{children:p("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns!=null?p("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{children:"·"}),r.jsx("span",{children:p("work:task.scheduleLast",{when:(()=>{const Ee=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),Ke=Math.floor(Ee/6e4);if(Ke<1)return p("work:task.noteTimeJustNow");if(Ke<60)return p("work:task.noteTimeMinutes",{count:Ke});const Ae=Math.floor(Ke/60);return Ae<24?p("work:task.noteTimeHours",{count:Ae}):p("work:task.noteTimeDays",{count:Math.floor(Ae/24)})})()})})]})]})]}),r.jsx("div",{className:"px-6 py-4 border-t border-border-default flex items-center justify-between gap-2",children:r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.status==="pending"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>Bt(()=>ue.tasks.approve(e.id)),disabled:$,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:e.createdBy&&!e.createdBy.startsWith("agt_")?p("work:task.startExecution"):p("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?r.jsx("button",{onClick:()=>{Bt(()=>ue.tasks.cancel(e.id))},disabled:$,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:p("work:task.cancelTask")}):r.jsx("button",{onClick:()=>I(!0),disabled:$,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:p("work:task.reject")})]}),e.status==="review"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{Bt(()=>ue.tasks.accept(e.id,u?.id))},disabled:$,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:p("work:task.approveCheck")}),$t?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("input",{type:"text",value:me,onChange:Ee=>ve(Ee.target.value),onKeyDown:Ee=>{Ee.key==="Enter"&&me.trim()&&(Bt(()=>ue.tasks.revision(e.id,me.trim(),u?.id)),dt(!1),ve(""))},placeholder:p("work:task.revisionReasonPlaceholder"),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"}),r.jsx("button",{onClick:()=>{Bt(()=>ue.tasks.revision(e.id,me.trim()||p("work:task.revisionsNeededDefault"),u?.id)),dt(!1),ve("")},disabled:$,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:p("common:send")}),r.jsx("button",{onClick:()=>{dt(!1),ve("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):r.jsx("button",{onClick:()=>dt(!0),disabled:$,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:p("work:task.requestRevision")})]}),sn&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{Nt()},disabled:$,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:[r.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[r.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),r.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),p("work:task.pause")]}),r.jsxs("button",{onClick:()=>{xn()},disabled:$,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:[r.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[r.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),r.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),p("work:task.retry")]})]}),Pn&&r.jsx("button",{onClick:()=>{cn()},disabled:$,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:$?r.jsx(r.Fragment,{children:p("work:task.resuming")}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:r.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),p("work:task.resume")]})}),Zt&&!sr&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{xn()},disabled:$,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:[r.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[r.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),r.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),p("work:task.retry")]}),r.jsxs("button",{onClick:()=>{rn()},disabled:$,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:[r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:r.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),p("work:task.continueTask")]})]}),sr&&(Dn||Zt)&&r.jsx("button",{onClick:()=>{Gn()},disabled:$,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:$?r.jsx(r.Fragment,{children:p("work:task.running")}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:r.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),p("work:task.runNow")]})}),sr&&!sn&&(fr?r.jsx("button",{onClick:()=>{Bt(()=>ue.tasks.resumeSchedule(e.id))},disabled:$,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:p("work:task.resumeSchedule")}):r.jsx("button",{onClick:()=>{Bt(()=>ue.tasks.pauseSchedule(e.id))},disabled:$,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:p("work:task.pauseSchedule")})),(Dn||Zt||Sr||Bn)&&r.jsx("button",{onClick:()=>X(!0),disabled:$,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:p("work:task.archive")}),Dn&&!sr&&r.jsx("button",{onClick:()=>{rn()},disabled:$,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:p("work:task.reopen")}),!gr&&e.status!=="pending"&&r.jsx("button",{onClick:async()=>{const{count:Ee}=await ue.tasks.getDependentCount(e.id);O({dependentCount:Ee})},disabled:$,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:p("work:task.cancelTask")})]})}),B&&r.jsx(cc,{title:p("work:task.deleteSubtaskTitle",{title:B.title}),message:p("work:task.deleteSubtaskMessage"),confirmLabel:p("common:delete"),onConfirm:()=>{On(B)},onCancel:()=>A(null)}),z&&r.jsx(cc,{title:p("work:task.rejectConfirmTitle"),message:p("work:task.rejectConfirmMessage"),confirmLabel:p("work:task.reject"),onConfirm:()=>{I(!1),Bt(()=>ue.tasks.reject(e.id))},onCancel:()=>I(!1)}),_&&r.jsx(cc,{title:p("work:task.archiveConfirmTitle"),message:p(sr?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:p("work:task.archive"),onConfirm:()=>{X(!1),Bt(()=>ue.tasks.archive(e.id))},onCancel:()=>X(!1)}),H&&H.dependentCount>0?r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>O(null),children:r.jsxs("div",{className:"bg-surface-default border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:Ee=>Ee.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:p("work:task.cancelTaskModalTitle")}),r.jsx("p",{className:"text-sm text-fg-secondary mb-4",children:p("work:task.cancelTaskDependent",{count:H.dependentCount})}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("button",{onClick:()=>{O(null),Bt(()=>ue.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:[r.jsx("span",{className:"font-medium",children:p("work:task.cancelTaskOnly")}),r.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:p("work:task.cancelTaskOnlyHint")})]}),r.jsxs("button",{onClick:()=>{O(null),Bt(()=>ue.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:[r.jsx("span",{className:"font-medium",children:p("work:task.cancelWithDependents")}),r.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:p("work:task.cancelWithDependentsHint",{count:H.dependentCount})})]}),r.jsx("button",{onClick:()=>O(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:p("work:task.keepTaskRunning")})]})]})}):H&&r.jsx(cc,{title:p("work:task.cancelTaskModalTitle"),message:p("work:task.cancelConfirmMessage"),confirmLabel:p("work:task.cancelTask"),onConfirm:()=>{O(null),Bt(()=>ue.tasks.cancel(e.id))},onCancel:()=>O(null)}),Ce&&r.jsx(VJ,{filePath:Ce,onClose:()=>Be(null)})]})}function YJ({project:e,tasks:t,requirements:n,agents:s,onDeleteProject:a,onUpdateProject:o,onRefresh:c}){const d=v.useMemo(()=>t.filter(z=>z.projectId===e.id),[t,e.id]),u=v.useMemo(()=>n.filter(z=>z.projectId===e.id),[n,e.id]),f=v.useMemo(()=>{const z={total:d.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:u.length,reqsDone:0};for(const I of d)I.status==="completed"||I.status==="accepted"?z.completed++:I.status==="in_progress"?z.inProgress++:I.status==="review"||I.status==="revision"?z.inReview++:I.status==="blocked"?z.blocked++:I.status==="failed"?z.failed++:z.pending++;for(const I of u)I.status==="completed"&&z.reqsDone++;return z},[d,u]),h=v.useMemo(()=>new Set(d.map(z=>z.assignedAgentId).filter(Boolean)),[d]),p=v.useMemo(()=>s.filter(z=>h.has(z.id)),[s,h]),[x,b]=v.useState(!1),[y,k]=v.useState(""),[j,S]=v.useState("main"),[T,N]=v.useState(!1),{t:E}=ht(["work","common"]),B=[{value:"active",label:E("work:project.statusActive"),desc:E("work:project.statusActiveDesc")},{value:"paused",label:E("work:project.statusPaused"),desc:E("work:project.statusPausedDesc")},{value:"archived",label:E("work:project.statusArchived"),desc:E("work:project.statusArchivedDesc")}],A=async z=>{if(z!==e.status){N(!0);try{await o({status:z}),c()}finally{N(!1)}}},H=async()=>{const z=y.trim();if(!z)return;const I=[...e.repositories??[],{url:"",localPath:z,defaultBranch:j||"main"}];await o({repositories:I}),k(""),S("main"),b(!1),c()},O=async z=>{const I=(e.repositories??[]).filter((_,X)=>X!==z);await o({repositories:I}),c()};return r.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsx(_J,{value:e.description??"",onSave:async z=>{await o({description:z}),c()},className:"text-sm text-fg-secondary",placeholder:E("work:project.descriptionPlaceholderLong")}),r.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&r.jsxs("span",{children:[E("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&r.jsxs("span",{children:[E("work:project.updatedLabel")," ",new Date(e.updatedAt).toLocaleDateString()]})]})]}),r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:E("work:project.projectStatusHeading")}),r.jsx("div",{className:"flex gap-2",children:B.map(z=>r.jsxs("button",{disabled:T,onClick:()=>A(z.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===z.value?z.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":z.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"} ${T?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[r.jsx("div",{children:z.label}),r.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:z.desc})]},z.value))})]}),r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:E("work:project.taskOverview")}),r.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[r.jsx(Li,{label:E("work:project.statTotal"),value:f.total,color:"text-fg-primary"}),r.jsx(Li,{label:E("work:project.statCompleted"),value:f.completed,color:"text-green-600"}),r.jsx(Li,{label:E("work:project.statInProgress"),value:f.inProgress,color:"text-brand-500"}),r.jsx(Li,{label:E("work:project.statInReview"),value:f.inReview,color:"text-brand-500"}),r.jsx(Li,{label:E("work:project.statBlocked"),value:f.blocked,color:"text-amber-600"}),r.jsx(Li,{label:E("work:project.statFailed"),value:f.failed,color:"text-red-500"})]}),f.total>0&&r.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[f.completed>0&&r.jsx("div",{className:"bg-green-500",style:{width:`${f.completed/f.total*100}%`}}),f.inProgress>0&&r.jsx("div",{className:"bg-brand-500",style:{width:`${f.inProgress/f.total*100}%`}}),f.inReview>0&&r.jsx("div",{className:"bg-brand-500",style:{width:`${f.inReview/f.total*100}%`}}),f.blocked>0&&r.jsx("div",{className:"bg-amber-500",style:{width:`${f.blocked/f.total*100}%`}}),f.pending>0&&r.jsx("div",{className:"bg-blue-500/40",style:{width:`${f.pending/f.total*100}%`}}),f.failed>0&&r.jsx("div",{className:"bg-red-500",style:{width:`${f.failed/f.total*100}%`}})]})]}),r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:E("work:project.requirementsHeading")}),r.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[r.jsx(Li,{label:E("work:project.statTotal"),value:f.reqs,color:"text-fg-primary"}),r.jsx(Li,{label:E("work:project.statCompleted"),value:f.reqsDone,color:"text-green-600"}),r.jsx(Li,{label:E("work:project.statActive"),value:f.reqs-f.reqsDone,color:"text-brand-500"})]})]}),p.length>0&&r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:E("work:project.agentsHeading",{count:p.length})}),r.jsx("div",{className:"flex flex-wrap gap-2",children:p.map(z=>{const I=d.filter(X=>X.assignedAgentId===z.id),_=I.filter(X=>!["completed","failed","cancelled","archived"].includes(X.status));return r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-elevated/60 rounded-lg",children:[r.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${z.status==="working"?"bg-blue-500":z.status==="idle"?"bg-green-500":"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary",children:z.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:E("work:project.agentTaskCounts",{active:_.length,total:I.length})})]},z.id)})})]}),r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:E("work:project.repositories")}),r.jsx("button",{onClick:()=>b(!x),className:"text-[10px] text-brand-500 hover:text-brand-500",children:E(x?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!x&&r.jsx("p",{className:"text-xs text-fg-tertiary",children:E("work:project.noReposLinked")}),(e.repositories??[]).map((z,I)=>r.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[r.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:[r.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"}),r.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate",children:z.url||z.localPath}),r.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:z.defaultBranch}),r.jsx("button",{onClick:()=>O(I),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:E("work:project.removeRepo"),children:r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},I)),x&&r.jsxs("div",{className:"mt-2 space-y-2 p-3 bg-surface-elevated rounded-lg border border-border-default",children:[r.jsx("input",{value:y,onChange:z=>k(z.target.value),placeholder:E("work:project.repoPathPlaceholder"),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"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:j,onChange:z=>S(z.target.value),placeholder:E("work:project.repoBranchPlaceholder"),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"}),r.jsx("button",{onClick:H,disabled:!y.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:E("work:task.add")})]})]})]}),r.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:E("work:project.dangerZone")}),r.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:E("work:project.dangerZoneDeleteHint")}),r.jsx("button",{onClick:a,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:E("work:project.deleteProject")})]})]})}function Li({label:e,value:t,color:n}){return r.jsxs("div",{className:"text-center py-2",children:[r.jsx("div",{className:`text-xl font-bold ${n}`,children:t}),r.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const d7={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},u7={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},WJ={urgent:0,high:1,medium:2,low:3},mk={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},hk={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"},KJ={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"},XJ=["pending","in_progress","completed","rejected","cancelled","archived"];function ZJ(e){for(const t of f1)if(t.statuses.includes(e))return t.id;return"closed"}function pk(e,t){const n=Date.now()-new Date(e).getTime(),s=Math.floor(n/6e4);if(s<1)return t("work:relative.justNow");if(s<60)return t("work:relative.minutesAgo",{count:s});const a=Math.floor(s/60);if(a<24)return t("work:relative.hoursAgo",{count:a});const o=Math.floor(a/24);return t("work:relative.daysAgo",{count:o})}function of({value:e,options:t,onSelect:n,allowedValues:s}){const[a,o]=v.useState(!1),c=v.useRef(null),d=v.useRef(null),u=t.find(f=>f.value===e);return v.useEffect(()=>{if(!a)return;const f=h=>{d.current&&!d.current.contains(h.target)&&c.current&&!c.current.contains(h.target)&&o(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[a]),r.jsxs("div",{className:"relative",children:[r.jsx("button",{ref:c,onClick:()=>o(f=>!f),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${u?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:u?.label??e}),a&&r.jsx("div",{ref:d,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:t.map(f=>{const h=f.value===e,p=h||!s||s.has(f.value);return r.jsxs("button",{disabled:!p,onClick:()=>{!h&&p&&n(f.value),o(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${h?"bg-surface-elevated":p?"hover:bg-surface-elevated/60":"opacity-35 cursor-not-allowed"}`,children:[r.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 ${p?f.cls.split(" ")[0]:"bg-gray-600"}`}),r.jsx("span",{className:`font-medium ${h?"text-fg-primary":p?"text-fg-secondary":"text-fg-muted"}`,children:f.label}),h&&r.jsx("svg",{className:"w-3 h-3 ml-auto text-brand-500",viewBox:"0 0 12 12",fill:"none",children:r.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},f.value)})})]})}function gk({row:e,idx:t,dragIdx:n,agentMap:s,projMap:a,onTaskClick:o,onReqClick:c,onRowDragStart:d,onRowDragEnd:u,handleStatusChange:f,handlePriorityChange:h,selected:p,isMobile:x}){const{t:b}=ht(["work","common"]),y=v.useMemo(()=>l7(b),[b]),k=v.useMemo(()=>m1(b),[b]),j=v.useMemo(()=>HJ(b),[b]),S=e.data.status,T=e.data.priority,N=e.kind==="task"?s.get(e.data.assignedAgentId??""):void 0,E=a.get((e.kind==="task",e.data.projectId??"")),B=e.kind==="req"?r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:b("work:task.requirementShort")}):e.data.taskType==="scheduled"?r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600",children:b("work:task.schedShort")}):r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:b("work:task.taskShort")});return x?r.jsxs("div",{onClick:()=>e.kind==="task"?o(e.data):c(e.data),className:`px-3 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${hk[e.group]??"border-l-gray-700"} ${p?"bg-brand-500/10 border-l-brand-500":"active:bg-surface-elevated/50"}`,children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[B,r.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),r.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[r.jsx("div",{onClick:A=>A.stopPropagation(),children:r.jsx(of,{value:S,options:e.kind==="task"?ck.map(A=>({value:A,label:y[A]?.label??A,cls:y[A]?.cls??"bg-gray-500/15 text-fg-tertiary"})):dk.map(A=>({value:A,label:k[A]?.label??A,cls:k[A]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?uk[S]:Jx[S],onSelect:A=>{f(e,A)}})}),r.jsx("div",{onClick:A=>A.stopPropagation(),children:r.jsx(of,{value:T,options:lk.map(A=>({value:A,label:j[A]?.label??A,cls:j[A]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:A=>{h(e,A)}})}),N&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${eb[N.status]??"bg-gray-500"}`}),r.jsx("span",{className:`${fk[N.status]??"text-fg-secondary"}`,children:N.name})]}),E?.name&&r.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:E.name}),r.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:pk(e.data.updatedAt??"",b)})]})]}):r.jsxs("div",{draggable:!0,onDragStart:A=>d(A,t),onDragEnd:u,onClick:()=>e.kind==="task"?o(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 ${hk[e.group]??"border-l-gray-700"} ${n===t?"opacity-40":""} ${p?"bg-brand-500/10 border-l-brand-500 hover:bg-brand-500/15":"hover:bg-surface-elevated/50"}`,children:[r.jsx("div",{className:"w-12 shrink-0",children:B}),r.jsx("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate",children:e.data.title}),r.jsx("div",{className:"w-[130px] shrink-0",onClick:A=>A.stopPropagation(),children:r.jsx(of,{value:S,options:e.kind==="task"?ck.map(A=>({value:A,label:y[A]?.label??A,cls:y[A]?.cls??"bg-gray-500/15 text-fg-tertiary"})):dk.map(A=>({value:A,label:k[A]?.label??A,cls:k[A]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?uk[S]:Jx[S],onSelect:A=>{f(e,A)}})}),r.jsx("div",{className:"w-[100px] shrink-0",onClick:A=>A.stopPropagation(),children:r.jsx(of,{value:T,options:lk.map(A=>({value:A,label:j[A]?.label??A,cls:j[A]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:A=>{h(e,A)}})}),r.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:N?r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${eb[N.status]??"bg-gray-500"}`}),r.jsx("span",{className:`font-medium ${fk[N.status]??"text-fg-secondary"}`,children:N.name})]}):r.jsx("span",{className:"text-fg-muted",children:"—"})}),r.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:E?.name?r.jsx("span",{className:"text-brand-400/70",children:E.name}):r.jsx("span",{className:"text-fg-muted",children:"—"})}),r.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-muted text-right",children:pk(e.data.updatedAt??"",b)})]})}function QJ({tasks:e,requirements:t,agents:n,projects:s,onTaskClick:a,onReqClick:o,onRefresh:c,selectedTaskId:d,selectedReqId:u}){const{t:f}=ht(["work","common"]),h=ws(),[p,x]=v.useState("status"),[b,y]=v.useState(null),[k,j]=v.useState(null),S=v.useMemo(()=>{const U=[];for(const L of e){const F=ZJ(L.status);U.push({kind:"task",data:L,group:F,groupOrder:mk[F]??5})}for(const L of t){const F=d7[L.status]??"todo";U.push({kind:"req",data:L,group:F,groupOrder:mk[F]??5})}if(p==="status")U.sort((L,F)=>{if(L.groupOrder!==F.groupOrder)return L.groupOrder-F.groupOrder;const Z=new Date(L.data.updatedAt??0).getTime();return new Date(F.data.updatedAt??0).getTime()-Z});else{const L=F=>WJ[F.data.priority]??2;U.sort((F,Z)=>{const Y=L(F),D=L(Z);return Y!==D?Y-D:new Date(Z.data.updatedAt??0).getTime()-new Date(F.data.updatedAt??0).getTime()})}return U},[e,t,p]),T=async(U,L)=>{try{U.kind==="task"?await ue.tasks.updateStatus(U.data.id,L):await ue.requirements.updateStatus(U.data.id,L),c()}catch{}},N=async(U,L)=>{try{U.kind==="task"?await ue.tasks.update(U.data.id,{priority:L}):await ue.requirements.update(U.data.id,{priority:L}),c()}catch{}},E=(U,L)=>{y(L),U.dataTransfer.effectAllowed="move",U.dataTransfer.setData("text/plain",String(L)),U.currentTarget.style.opacity="0.4"},B=U=>{U.currentTarget.style.opacity="1",y(null),j(null)},A=(U,L)=>{U.preventDefault(),U.dataTransfer.dropEffect="move",k!==L&&j(L)},H=async(U,L)=>{if(U.preventDefault(),j(null),b==null)return;const F=S[b];if(!F||F.group===L)return;const Z=f1.find(Y=>Y.id===L);if(Z){try{if(F.kind==="task"){if(F.data.status==="pending")return;await ue.tasks.updateStatus(F.data.id,Z.dropStatus)}else{const Y=u7[L];Y&&await ue.requirements.updateStatus(F.data.id,Y)}c()}catch{}y(null)}},O=v.useMemo(()=>new Map(n.map(U=>[U.id,U])),[n]),z=v.useMemo(()=>new Map(s.map(U=>[U.id,U])),[s]),I=["todo","in_progress","review","done"],_=v.useMemo(()=>{const U={};for(const L of S)U[L.group]=(U[L.group]??0)+1;return U},[S]),{rowsByGroup:X,rowIndexMap:G}=v.useMemo(()=>{const U=new Map,L=new Map;for(let F=0;F<S.length;F++){const Z=S[F];L.set(Z,F);const Y=U.get(Z.group)??[];Y.push(Z),U.set(Z.group,Y)}return{rowsByGroup:U,rowIndexMap:L}},[S]),M=v.useMemo(()=>{if(p!=="status")return null;const U=new Set(S.map(Z=>Z.group)),L=[],F=new Set;U.has("failed")&&(L.push("failed"),F.add("failed"));for(const Z of I)L.push(Z),F.add(Z);for(const Z of S)F.has(Z.group)||(L.push(Z.group),F.add(Z.group));return L},[S,p]);return r.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-secondary ${h?"overflow-x-hidden w-full":""}`,children:r.jsxs("div",{className:h?"w-full":"w-fit min-w-full",children:[!h&&r.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:[r.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:S.length}),r.jsx("div",{className:"flex-1 min-w-[200px]",children:f("work:task.backlogTitle")}),r.jsxs("button",{onClick:()=>x("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${p==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[f("work:filters.status")," ",p==="status"&&r.jsx("span",{className:"text-[8px]",children:"▼"})]}),r.jsxs("button",{onClick:()=>x("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${p==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[f("work:filters.priority")," ",p==="priority"&&r.jsx("span",{className:"text-[8px]",children:"▼"})]}),r.jsx("div",{className:"w-[120px] shrink-0",children:f("work:filters.assignee")}),r.jsx("div",{className:"w-[120px] shrink-0",children:f("work:task.projectLabel")}),r.jsx("div",{className:"w-[90px] shrink-0 text-right",children:f("work:task.backlogUpdated")})]}),r.jsxs("div",{children:[p==="status"&&M?M.map(U=>{const L=X.get(U)??[];return r.jsxs("div",{children:[r.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-secondary/60 sticky top-0 z-10 ${KJ[U]??""} ${k===U?"ring-1 ring-brand-500/40":""}`,onDragOver:F=>A(F,U),onDragLeave:()=>j(null),onDrop:F=>{H(F,U)},children:[r.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:f(`work:boardColumn.${U}`)}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:_[U]??0})]}),L.map(F=>r.jsx(gk,{row:F,idx:G.get(F)??0,dragIdx:b,agentMap:O,projMap:z,onTaskClick:a,onReqClick:o,onRowDragStart:E,onRowDragEnd:B,handleStatusChange:T,handlePriorityChange:N,selected:F.kind==="task"?F.data.id===d:F.data.id===u,isMobile:h},`${F.kind}-${F.data.id}`))]},U)}):S.map((U,L)=>r.jsx(gk,{row:U,idx:L,dragIdx:b,agentMap:O,projMap:z,onTaskClick:a,onReqClick:o,onRowDragStart:E,onRowDragEnd:B,handleStatusChange:T,handlePriorityChange:N,selected:U.kind==="task"?U.data.id===d:U.data.id===u,isMobile:h},`${U.kind}-${U.data.id}`)),S.length===0&&r.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-fg-tertiary",children:f("work:task.noItems")})]})]})})}function xk({authUser:e}){const{t}=ht(["work","common"]),n=v.useMemo(()=>f1.map(le=>({...le,label:t(`work:boardColumn.${le.id}`)})),[t]),s=v.useMemo(()=>c7(t),[t]),a=v.useMemo(()=>m1(t),[t]),o=ws(),c=vm({side:"right",defaultWidth:Math.round(window.innerWidth/2),minWidth:380,maxWidth:Math.round(window.innerWidth*.8),storageKey:"markus_projects_detail_v3"}),[d,u]=v.useState(!1),f=v.useRef(d);f.current=d;const[h,p]=v.useState([]),[x,b]=v.useState("all"),[y,k]=v.useState(null),[j,S]=v.useState({}),[T,N]=v.useState([]),[E,B]=v.useState([]),[A,H]=v.useState([]),[O,z]=v.useState(!0),[I,_]=v.useState(""),[X,G]=v.useState(!1),M=v.useCallback(()=>{$r(y??""),Zt(!0)},[y]),[U,L]=v.useState(!1),[F,Z]=v.useState(!1),[Y,D]=v.useState(""),[P,ee]=v.useState(""),[$,Q]=v.useState("medium"),[q,J]=v.useState(""),[K,re]=v.useState(""),[de,pe]=v.useState(""),[te,we]=v.useState(""),[ce,ge]=v.useState([]),[Ce,Be]=v.useState("standard"),[Qe,We]=v.useState("4h"),[wt,bt]=v.useState(""),[$t,dt]=v.useState(null),[me,ve]=v.useState(null),[Re,ke]=v.useState(new Set),[Pe,lt]=v.useState(!1),[at,gt]=v.useState(new Set),Ft=v.useRef(new Set),Bt=v.useRef(new Set),[tn,It]=v.useState(null),[Pt,Nt]=v.useState("backlog"),cn=v.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"}],[]),Xt=Hi(cn,Pt,Nt),pn=v.useRef(null),On=v.useMemo(()=>({scrollContainerRef:pn}),[]),rn=Hi(cn,Pt,Nt,On),[xn,Gn]=v.useState(!1),[wn,An]=v.useState(!1),sn=v.useRef(null),Pn=v.useRef(null),[Dn,Zt]=v.useState(!1),[Sr,Bn]=v.useState(""),[zr,gr]=v.useState(""),[sr,fr]=v.useState("medium"),[Cr,$r]=v.useState(""),[Ee,Ke]=v.useState(null),[Ae,ot]=v.useState(""),[ut,jt]=v.useState(""),[er,Hn]=v.useState(""),[Tr,Ar]=v.useState(null),fe=le=>{_(le),setTimeout(()=>_(""),3e3)},Fe=h.find(le=>le.id===y)??null;v.useEffect(()=>{Bt.current=at},[at]);const Xe=v.useCallback(async()=>{try{const{projects:le}=await ue.projects.list();p(le)}catch{}},[]),ft=v.useCallback(async()=>{const le={};x==="project"&&y&&(le.projectId=y);try{const{board:se}=await ue.tasks.board(le);S(se)}catch{}},[x,y]),pt=v.useCallback(async()=>{try{const{agents:le}=await ue.agents.list();N(le)}catch{}},[]),Vt=v.useCallback(async()=>{try{const{users:le}=await ue.users.list(e?.orgId);B(le)}catch{}},[e?.orgId]),bn=v.useCallback(async()=>{try{const{requirements:le}=await ue.requirements.list({});H(le)}catch{}},[]),Wn=v.useCallback(async()=>{await Promise.all([Xe(),ft(),pt(),Vt(),bn()]),z(!1)},[Xe,ft,pt,Vt,bn]);v.useEffect(()=>{Wn()},[Wn]);const yn=v.useCallback(le=>{dt(se=>se?.id===le.id?(o&&f.current&&u(!1),null):(o&&(u(!0),history.pushState({mobileDetail:_e.WORK},"",window.location.hash)),le)),ve(null)},[o]),At=v.useCallback(le=>{ve(se=>se?.id===le.id?(o&&f.current&&u(!1),null):(o&&(u(!0),history.pushState({mobileDetail:_e.WORK},"",window.location.hash)),le)),dt(null)},[o]),Ot=v.useCallback(()=>{dt(null),ve(null),o&&f.current&&u(!1)},[o]);v.useEffect(()=>{if(!o)return;const le=()=>{f.current&&(u(!1),dt(null),ve(null))};return window.addEventListener("popstate",le),()=>window.removeEventListener("popstate",le)},[o]);const ns=v.useRef($t);ns.current=$t,v.useEffect(()=>{const le=ns.current?6e4:15e3,se=setInterval(()=>{ft(),pt(),bn()},le),be=gn.on("task:update",Mt=>{ft();const et=Mt?.payload;et?.taskId&&dt(Ps=>{if(!Ps||Ps.id!==et.taskId)return Ps;const gs={};return typeof et.status=="string"&&(gs.status=et.status),Array.isArray(et.deliverables)&&(gs.deliverables=et.deliverables),Array.isArray(et.notes)&&(gs.notes=et.notes),et.result!==void 0&&(gs.result=et.result),{...Ps,...gs}})}),Me=gn.on("task:create",()=>{ft()}),an=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(Mt=>gn.on(Mt,()=>{bn()}));return()=>{clearInterval(se),be(),Me(),an.forEach(Mt=>Mt())}},[ft,pt,bn]);const Xr=v.useRef(j);Xr.current=j;const Kn=v.useRef(A);Kn.current=A;const ar=v.useCallback(le=>{if(!le)return;const se=Bt.current;se.size>0&&!se.has(le)&&gt(be=>new Set([...be,le]))},[]),[Or,Xn]=v.useState(!1),un=v.useCallback((le,se)=>{dt(le),ve(null),se?.scrollToComments&&Xn(!0),o&&(u(!0),history.pushState({mobileDetail:_e.WORK},"",window.location.hash))},[o]),rs=v.useCallback((le,se)=>{ve(le),dt(null),se?.scrollToComments&&Xn(!0),o&&(u(!0),history.pushState({mobileDetail:_e.WORK},"",window.location.hash))},[o]);v.useEffect(()=>{const le=localStorage.getItem("markus_nav_openTask");if(!le)return;const be=Object.values(j).flat().find(Me=>Me.id===le);be&&(ar(be.projectId),un(be),localStorage.removeItem("markus_nav_openTask"))},[j,un,ar]),v.useEffect(()=>{const le=window.location.hash.slice(1).split("/");if(So(le[0])===_e.WORK&&le[1])Ms(le[1]);else{const se=localStorage.getItem("markus_nav_projectId");se&&(localStorage.removeItem("markus_nav_projectId"),Ms(se))}},[]);const os=v.useRef(So(window.location.hash.slice(1).split("/")[0]));v.useEffect(()=>{const le=()=>{const be=window.location.hash.slice(1).split("/"),Me=So(be[0]),it=os.current===_e.WORK;os.current=Me,Me===_e.WORK&&(Me===_e.WORK&&be[1]?Ms(be[1]):it&&ls())},se=async be=>{const Me=be.detail;if(So(Me.page)===_e.WORK){if(Me.params?.openTask){const it=Me.params.openTask,an=Me.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let Mt=Object.values(Xr.current).flat().find(et=>et.id===it);if(!Mt)try{Mt=(await ue.tasks.get(it)).task}catch{}Mt&&(ar(Mt.projectId),un(Mt,{scrollToComments:an}))}if(Me.params?.openRequirement){const it=Me.params.openRequirement,an=Me.params.scrollToComments==="true";let Mt=Kn.current.find(et=>et.id===it);if(!Mt)try{Mt=(await ue.requirements.get(it)).requirement}catch{}Mt&&(ar(Mt.projectId),rs(Mt,{scrollToComments:an}))}Me.params?.projectId&&Ms(Me.params.projectId)}};return window.addEventListener("markus:navigate",se),window.addEventListener("hashchange",le),()=>{window.removeEventListener("markus:navigate",se),window.removeEventListener("hashchange",le)}},[]);const Ms=le=>{Bt.current.size>0&&(Ft.current=new Set(Bt.current)),gt(new Set),k(le),b("project"),G(!1),history.replaceState(null,"",b2(_e.WORK,le))},ls=()=>{gt(Ft.current),k(null),b("all"),G(!1),history.replaceState(null,"",b2(_e.WORK))},Ua=()=>{L(!1),fe(t("work:task.projectCreated")),Xe()},xr=async le=>{if(confirm("Delete this project and unlink all its tasks?"))try{await ue.projects.delete(le),y===le&&ls(),fe("Project deleted"),Xe(),ft()}catch(se){fe(`Error: ${se}`)}},ps=async()=>{if(!Y||!q||!K)return;bt("");const le=K.startsWith("human:"),se=K.replace(/^(human|agent):/,"");if(q===se&&!le){fe(t("work:task.assignedReviewerDifferent"));return}const be=de||void 0,Me=te||void 0;try{const{task:it}=await ue.tasks.create(Y,P,q,se,$,be,ce.length>0?ce:void 0,Me,Ce!=="standard"?Ce:void 0,Ce==="scheduled"?{every:Qe}:void 0,le?"human":"agent");D(""),ee(""),ge([]),we(""),Be("standard"),We("4h"),Z(!1),ft(),it&&un(it)}catch(it){const Mt=`work:task.errorCode_${(it instanceof Pk?it.code:void 0)||"unknown"}`,et=t(Mt,{defaultValue:""});bt(et||t("work:task.errorCreatingTask",{message:it instanceof Error?it.message:String(it)}))}},Zr=le=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:le}))},Ks=()=>{ft(),$t&&(Zr({taskId:$t.id}),setTimeout(()=>{const le={};x==="project"&&y&&(le.projectId=y),ue.tasks.board(le).then(se=>{const Me=Object.values(se.board).flat().find(it=>it.id===$t.id);dt(Me||null)}).catch(()=>{})},150))},Er=()=>{bn(),me&&setTimeout(()=>{ue.requirements.list({}).then(({requirements:le})=>{const se=le.find(be=>be.id===me.id);ve(se||null)}).catch(()=>{})},150)},Xs=async()=>{if(!Sr.trim()){jt(t("work:task.pleaseReqTitle"));return}if(!zr.trim()){jt(t("work:task.pleaseReqDesc"));return}if(!Cr){jt(t("work:task.pleaseReqProject"));return}jt("");try{const{requirement:le}=await ue.requirements.create({title:Sr.trim(),description:zr.trim(),priority:sr,projectId:Cr});fe(t("work:task.requirementCreated")),Bn(""),gr(""),Zt(!1),bn(),le&&rs(le)}catch(le){jt(le instanceof Error?le.message:String(le))}},Ma=async le=>{try{await ue.requirements.approve(le),fe("Requirement approved"),Zr({requirementId:le}),Er(),ft()}catch(se){fe(`Error: ${se}`)}},ks=async()=>{if(Ee){Hn("");try{await ue.requirements.reject(Ee,Ae),fe("Requirement rejected"),Zr({requirementId:Ee}),Ke(null),ot(""),Hn(""),Er()}catch(le){Hn(le instanceof Error?le.message:String(le))}}},En=async le=>{try{await ue.requirements.cancel(le),fe("Requirement cancelled"),Zr({requirementId:le}),Er()}catch(se){fe(`Error: ${se}`)}},ss=(le,se)=>{sn.current=se,Pn.current=null,le.dataTransfer.effectAllowed="move",le.dataTransfer.setData("text/plain",`task:${se.id}`),le.currentTarget.style.opacity="0.4"},Va=(le,se)=>{Pn.current=se,sn.current=null,le.dataTransfer.effectAllowed="move",le.dataTransfer.setData("text/plain",`req:${se.id}`),le.currentTarget.style.opacity="0.4"},Ds=le=>{le.currentTarget.style.opacity="1",sn.current=null,Pn.current=null,It(null)},_o=(le,se)=>{le.preventDefault(),le.dataTransfer.dropEffect="move",tn!==se&&It(se)},Ga=(le,se)=>{const be=le.currentTarget.getBoundingClientRect(),{clientX:Me,clientY:it}=le;(Me<be.left||Me>be.right||it<be.top||it>be.bottom)&&tn===se&&It(null)},Ya=async(le,se)=>{le.preventDefault(),It(null);const be=sn.current,Me=Pn.current;if(be){const it=n.find(Mt=>Mt.id===se);if(!it)return;const an=it.dropStatus;if(be.status===an||be.status==="pending")return;try{await ue.tasks.updateStatus(be.id,an),ft()}catch{}}else if(Me){const it=u7[se];if(!it||Me.status===it)return;try{await ue.requirements.updateStatus(Me.id,it),bn()}catch{}}},cs=le=>{ke(se=>{const be=new Set(se);return be.has(le)?be.delete(le):be.add(le),be})},Wa=le=>{gt(se=>{const be=new Set(se);return be.has(le)?be.delete(le):be.add(le),be})},Zs=le=>le.status==="archived",Rs=(le,se=!1)=>{let be=le.filter(Me=>xn||se||!Zs(Me));return x==="project"&&y&&(be=be.filter(Me=>Me.projectId===y)),at.size>0&&(be=be.filter(Me=>Me.projectId&&at.has(Me.projectId))),Re.size>0&&(be=be.filter(Me=>Me.assignedAgentId&&Re.has(Me.assignedAgentId))),Pe&&e?.id&&(be=be.filter(Me=>Me.createdBy===e.id)),be},as=v.useMemo(()=>new Set(T.map(le=>le.id)),[T]),Da=le=>le.statuses.flatMap(se=>Rs(j[se]??[])),Ls=v.useMemo(()=>{let le=A;if(xn||(le=le.filter(se=>!Zs(se))),x==="project"&&y&&(le=le.filter(se=>se.projectId===y)),at.size>0&&(le=le.filter(se=>se.projectId&&at.has(se.projectId))),Re.size>0){const se=e?.id;le=le.filter(be=>Re.has(be.createdBy)||se!=null&&be.createdBy===se||!as.has(be.createdBy))}return Pe&&e?.id&&(le=le.filter(se=>se.createdBy===e.id)),le},[A,xn,x,y,at,Re,Pe,e?.id,as]),Os=v.useCallback(le=>Ls.filter(se=>d7[se.status]===le.id),[Ls]),pa=n.filter(le=>{if(le.id==="failed"||le.id==="closed"){const se=Da(le),be=Os(le);return se.length+be.length>0}return!0}),Yn=Object.values(j).flat().filter(le=>Zs(le)).length+A.filter(le=>Zs(le)).length,Qs=v.useMemo(()=>{const le=new Set(["completed","failed","cancelled","archived"]),se=Object.values(j).flat(),be=new Set;for(const Me of se)Me.assignedAgentId&&!le.has(Me.status)&&(!y||Me.projectId===y)&&be.add(Me.assignedAgentId);return[...T].sort((Me,it)=>{const an=be.has(Me.id)?0:1,Mt=be.has(it.id)?0:1;return an-Mt})},[T,j,y]),ga=v.useMemo(()=>{const le=new Set(["completed","failed","cancelled","archived"]),se=Object.values(j).flat(),be=new Set;for(const Me of se)Me.projectId&&!le.has(Me.status)&&be.add(Me.projectId);return[...h].sort((Me,it)=>{const an=be.has(Me.id)?0:1,Mt=be.has(it.id)?0:1;return an-Mt})},[h,j]),cr=v.useMemo(()=>{const le={};for(const se of Object.values(j))for(const be of se){const Me=be.projectId??"__none__";le[Me]=(le[Me]??0)+1}return le},[j]),_s=Object.values(cr).reduce((le,se)=>le+se,0);if(O)return r.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:t("work:task.loadingPage")});const Is=!!($t||me);return r.jsxs("div",{className:"flex-1 overflow-hidden flex bg-surface-secondary",children:[r.jsxs("div",{className:`${o?"flex-1 min-w-0":Is?"shrink-0":"flex-1"} overflow-hidden flex flex-col bg-surface-secondary`,style:o?d?{display:"none"}:void 0:Is?{width:`calc(100% - ${c.width}px - 4px)`}:void 0,children:[I&&r.jsx("div",{className:"mx-6 mt-2 px-3 py-1.5 bg-green-500/15 text-green-600 text-xs rounded-lg",children:I}),o?r.jsxs("div",{className:"border-b border-border-default bg-surface-secondary/80 shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[Fe?r.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[r.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:Fe.name}),r.jsx("button",{onClick:()=>G(!X),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${X?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.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"})]})})]}):r.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:h.length===1?h[0].name:t("work:task.projectsCount",{count:h.length})}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:()=>L(!0),className:"px-2 py-1 text-[11px] bg-teal-600 text-white rounded-md",children:t("work:task.shortProject")}),r.jsx("button",{onClick:M,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:t("work:task.shortReq")}),r.jsx("button",{onClick:()=>{pe(y??""),Z(!0)},className:"px-2 py-1 text-[11px] border border-amber-500/60 text-amber-600 rounded-md",children:t("work:task.shortTask")})]})]}),r.jsxs("div",{className:"flex items-center gap-2 px-3 h-9 border-t border-border-default/40",children:[r.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(le=>r.jsx("button",{onClick:()=>Nt(le),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${Pt===le?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:t(le==="backlog"?"work:task.backlog":le==="kanban"?"work:task.kanban":"work:task.dag")},le))}),Yn>0&&r.jsx("button",{onClick:()=>Gn(le=>!le),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${xn?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:xn?t("work:task.hideArchived"):t("work:task.archivedCount",{count:Yn})}),r.jsx("div",{className:"flex-1"}),(at.size>0||Re.size>0||Pe||h.length>1||T.length>0)&&r.jsxs("button",{onClick:()=>An(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${at.size>0||Re.size>0||Pe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),at.size+Re.size+(Pe?1:0)>0?t("work:task.filterWithCount",{count:at.size+Re.size+(Pe?1:0)}):t("work:task.filter")]})]})]}):r.jsxs("div",{className:"flex items-center gap-3 px-6 h-14 border-b border-border-default bg-surface-secondary/80 shrink-0",children:[Fe?r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx(OJ,{value:Fe.name,onSave:async le=>{await ue.projects.update(Fe.id,{name:le}),Xe()},className:"text-sm font-semibold text-fg-primary"}),r.jsx("button",{onClick:()=>G(!X),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${X?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:t("work:project.settingsTitle"),children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.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"})]})})]}):r.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:h.length===1?h[0].name:t("work:task.projectsCount",{count:h.length})}),Yn>0&&r.jsx("button",{onClick:()=>Gn(le=>!le),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${xn?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:xn?t("work:task.hideArchivedWithCount",{count:Yn}):t("work:task.archivedCount",{count:Yn})}),r.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(le=>r.jsx("button",{onClick:()=>Nt(le),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Pt===le?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:t(le==="backlog"?"work:task.backlog":le==="kanban"?"work:task.kanban":"work:task.dag")},le))}),r.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[r.jsx("button",{onClick:()=>L(!0),className:"px-3 py-1.5 bg-teal-600 hover:bg-teal-500 text-white text-xs rounded-lg font-medium transition-colors",children:t("work:task.shortProject")}),r.jsx("button",{onClick:M,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:t("work:task.newRequirement")}),r.jsx("button",{onClick:()=>{pe(y??""),Z(!0)},className:"px-3 py-1.5 border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 text-xs rounded-lg font-medium transition-colors",children:t("work:task.newTaskBtn")})]}),r.jsx("div",{className:"flex-1"})]}),!o&&h.length>1&&!y&&!X&&(_s>0||A.length>0)&&r.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:[r.jsx("button",{onClick:()=>gt(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 ${at.size>0?"visible opacity-100":"invisible opacity-0"}`,children:t("work:task.clear")}),ga.map(le=>{const se=at.has(le.id),be=cr[le.id]??0;return r.jsxs("button",{onClick:()=>Wa(le.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${se?"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:[r.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${se?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:le.name[0]?.toUpperCase()}),le.name,be>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:be})]},le.id)})]}),!o&&(T.length>0||e?.id)&&!X&&(_s>0||A.length>0)&&r.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:[r.jsx("button",{type:"button",onClick:()=>{ke(new Set),lt(!1)},className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${Re.size>0||Pe?"visible opacity-100":"invisible opacity-0"}`,children:t("work:task.clear")}),e?.id&&r.jsx("button",{type:"button",onClick:()=>lt(le=>!le),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Pe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:t("work:task.myTasks")}),Qs.map(le=>{const se=Re.has(le.id);return r.jsxs("button",{onClick:()=>cs(le.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${se?"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:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${se?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:le.name[0]?.toUpperCase()}),le.name]},le.id)})]}),X&&Fe?r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsx(YJ,{project:Fe,tasks:Object.values(j).flat(),requirements:A,agents:T,onDeleteProject:()=>xr(Fe.id),onUpdateProject:async le=>{await ue.projects.update(Fe.id,le)},onRefresh:()=>{Xe()}})}):_s===0&&Ls.length===0?r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:h.length===0?r.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[r.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:r.jsx("path",{d:"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"})})}),r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:t("work:task.emptyNoProjectsTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:t("work:task.emptyNoProjectsHint")}),r.jsx("button",{onClick:()=>L(!0),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:t("work:project.newProject")})]}):r.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[r.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:[r.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),r.jsx("polyline",{points:"14 2 14 8 20 8"}),r.jsx("line",{x1:"12",y1:"18",x2:"12",y2:"12"}),r.jsx("line",{x1:"9",y1:"15",x2:"15",y2:"15"})]})}),r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:t("work:task.emptyNoReqsTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed whitespace-pre-line",children:t("work:task.emptyNoReqsHint")}),r.jsx("button",{onClick:M,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:t("work:task.createRequirementCta")})]})}):Pt==="backlog"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:o?Xt.onTouchStart:void 0,onTouchEnd:o?Xt.onTouchEnd:void 0,children:r.jsx(QJ,{tasks:Rs(Object.values(j).flat()),requirements:Ls,agents:T,projects:h,onTaskClick:le=>yn(le),onReqClick:le=>At(le),onRefresh:()=>{ft(),bn()},selectedTaskId:$t?.id,selectedReqId:me?.id})}):Pt==="dag"?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:o?Xt.onTouchStart:void 0,onTouchEnd:o?Xt.onTouchEnd:void 0,children:[r.jsx(DJ,{tasks:Rs(Object.values(j).flat(),!0),requirements:Ls,agents:T,showArchived:xn,onShowArchivedChange:Gn,onTaskClick:le=>yn(le),onReqClick:le=>At(le),onDependencyChange:ft,selectedTaskId:$t?.id,selectedReqId:me?.id}),o&&r.jsx("button",{onClick:()=>Nt("kanban"),className:"absolute left-3 top-1/2 -translate-y-1/2 w-11 h-11 rounded-full bg-brand-500 border border-brand-400/60 shadow-xl shadow-brand-500/30 flex items-center justify-center text-white active:bg-brand-400 backdrop-blur-sm z-10",title:t("work:task.backToKanban"),children:r.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})})})]}):r.jsx("div",{ref:pn,className:"flex-1 min-h-0 overflow-x-auto overflow-y-hidden px-4 py-5",onTouchStart:o?rn.onTouchStart:void 0,onTouchEnd:o?rn.onTouchEnd:void 0,children:r.jsx("div",{className:"flex gap-3 h-full",children:pa.map(le=>{const se=Da(le),be=Os(le),Me=se.length+be.length,it=tn===le.id;return r.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col h-full transition-colors ${it?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:an=>_o(an,le.id),onDragLeave:an=>Ga(an,le.id),onDrop:an=>{Ya(an,le.id)},children:[r.jsxs("div",{className:"flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${le.accent.replace("border-t-","bg-")}`}),r.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:le.label})]}),r.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:Me})]}),r.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin px-2 py-2",children:(()=>{const an=[...be.map(Mt=>({kind:"req",data:Mt,time:new Date(Mt.updatedAt??Mt.createdAt).getTime()})),...se.map(Mt=>({kind:"task",data:Mt,time:new Date(Mt.updatedAt??Mt.createdAt??0).getTime()}))];return an.sort((Mt,et)=>et.time-Mt.time),an.map(Mt=>{if(Mt.kind==="req"){const et=Mt.data,Ps=a[et.status]??{label:et.status,cls:"bg-gray-500/15 text-fg-secondary"},ae=et.source==="agent"&&et.status==="pending",De=x==="all"&&et.projectId?h.find(mt=>mt.id===et.projectId):null,ze=Mc(et.createdBy,T,E)??et.createdBy.slice(0,10),qe=me?.id===et.id;return r.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:mt=>Va(mt,et),onDragEnd:Ds,onClick:()=>At(et),onKeyDown:mt=>mt.key==="Enter"&&At(et),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
350
350
  ${ae?"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"}
351
- ${qe?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),r.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:t("work:task.requirementShort")}),r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${Ps.cls}`,children:Ps.label})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:et.title}),et.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:et.description}),r.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[De&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:De.name,children:De.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:et.priority}),r.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",ze]})]}),r.jsx("div",{className:"flex items-center gap-1",children:et.taskIds.length>0&&r.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",et.taskIds.length]})})]}),ae&&r.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[r.jsx("button",{onClick:mt=>{mt.stopPropagation(),Ma(et.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:t("work:task.approve")}),r.jsx("button",{onClick:mt=>{mt.stopPropagation(),Ke(et.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:t("work:task.reject")})]})]},`req-${et.id}`)}else{const et=Mt.data,Ps=et.subtasks?.length??0,gs=s[et.status],ae=et.status==="pending",De=et.taskType==="scheduled"&&!!et.scheduleConfig,ze=De?et.scheduleConfig.every?t("work:task.everyInterval",{interval:et.scheduleConfig.every}):et.scheduleConfig.cron?t("work:task.cronLabel"):t("work:task.scheduledShort"):null,qe=x==="all"&&et.projectId?h.find(Je=>Je.id===et.projectId)?.name:null,mt=et.requirementId?A.find(Je=>Je.id===et.requirementId)?.title:null,Ve=et.createdBy?Mc(et.createdBy,T,E)??et.createdBy:null,tt=$t?.id===et.id,Ht={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"};return r.jsxs("div",{role:"button",tabIndex:0,"aria-label":et.title,draggable:!ae,onDragStart:Je=>!ae&&ss(Je,et),onDragEnd:Ds,onClick:()=>yn(et),onKeyDown:Je=>Je.key==="Enter"&&yn(et),className:`group rounded-lg p-2.5 border border-transparent transition-all ${ae?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":De?"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"} ${tt?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ht[et.priority]??"bg-gray-400"}`,title:et.priority}),De&&r.jsx("span",{className:"text-blue-500 shrink-0",title:ze??"Scheduled",children:r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.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"})})}),De&&ze&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:ze}),gs&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${gs.cls}`,children:gs.label})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:et.title}),et.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:et.description}),(qe||mt||et.blockedBy&&et.blockedBy.length>0)&&r.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[qe&&r.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:qe,children:qe}),mt&&r.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:mt,children:["# ",mt]}),et.blockedBy&&et.blockedBy.length>0&&r.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",et.blockedBy.length," dep",et.blockedBy.length>1?"s":""]})]}),r.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[r.jsx("div",{className:"flex items-center gap-1.5",children:Ve&&r.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Ve}`,children:["by ",Ve]})}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[Ps>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ps]}),et.notes&&et.notes.length>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",et.notes.length]}),et.assignedAgentId&&r.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:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${eb[T.find(Je=>Je.id===et.assignedAgentId)?.status??""]??"bg-gray-500"}`}),T.find(Je=>Je.id===et.assignedAgentId)?.name??et.assignedAgentId.slice(0,8)]})]})]})]},et.id)}})})()}),it&&r.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:r.jsx("span",{className:"text-[11px] text-brand-500/50",children:t("work:task.dropHere")})})]},le.id)})})})]}),!o&&Is&&r.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:c.onResizeStart}),(!o||d)&&Is&&r.jsx("div",{className:`${o?"flex-1":"shrink-0"} overflow-hidden min-w-0 border-l border-border-default`,style:o?void 0:{width:c.width},children:$t?r.jsx(GJ,{task:$t,agents:T,projects:h,requirements:A,allTasks:Object.values(j).flat(),users:E,onClose:Ot,onRefresh:Ks,authUser:e,scrollToComments:Or,onScrollToCommentsDone:()=>Xn(!1)}):me?r.jsx(eee,{req:me,agents:T,projects:h,allTasks:Object.values(j).flat(),users:E,onClose:Ot,onApprove:le=>{Ma(le)},onReject:le=>{Ke(le)},onCancel:le=>{En(le),Ot()},onStatusChange:async(le,se)=>{try{await ue.requirements.updateStatus(le,se),fe(`Requirement status → ${se}`),Zr({requirementId:le}),Er(),ft()}catch(be){fe(`Error: ${be}`)}},scrollToComments:Or,onScrollToCommentsDone:()=>Xn(!1),onRefresh:Er,authUser:e,onTaskClick:le=>yn(le),onCreateTask:(le,se)=>{we(le),se&&pe(se),Z(!0)}}):null}),U&&r.jsx(RJ,{orgId:e?.orgId,onCreated:Ua,onClose:()=>L(!1)}),F&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Z(!1),bt("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${o?"w-full":"w-[28rem]"}`,onClick:le=>le.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:t("work:task.newTask")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.titleLabel")}),r.jsx("input",{autoFocus:!o,value:Y,onChange:le=>D(le.target.value),onKeyDown:le=>{le.key==="Enter"&&ps()},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.descriptionField")}),r.jsx("textarea",{value:P,onChange:le=>ee(le.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"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.projectLabel")}),r.jsx(Ld,{options:[{value:"",label:t("work:task.noProject")},...h.map(le=>({value:le.id,label:le.name}))],value:de,onChange:le=>{pe(le),we("")},placeholder:t("work:task.noProject"),noMatchesText:t("work:task.noMatches")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.requirementLabel")}),r.jsx(Ld,{options:[{value:"",label:t("work:task.selectRequirement")},...A.filter(le=>le.status==="in_progress"&&(!de||le.projectId===de)).map(le=>({value:le.id,label:le.title}))],value:te,onChange:we,placeholder:t("work:task.selectRequirement"),noMatchesText:t("work:task.noMatches")})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.assignToRequired")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx(Ld,{options:T.map(le=>({value:le.id,label:`${le.name} (${le.status})`})),value:q,onChange:J,placeholder:t("work:task.selectAgent"),noMatchesText:t("work:task.noMatches")})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.reviewerRequired")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx(Ld,{options:[...E.map(le=>({value:`human:${le.id}`,label:le.name})),...T.filter(le=>le.id!==q).map(le=>({value:`agent:${le.id}`,label:`${le.name} (${le.status})`}))],value:K,onChange:re,placeholder:t("work:task.selectReviewer"),noMatchesText:t("work:task.noMatches")})]})]}),r.jsxs("div",{className:`grid gap-4 ${Ce==="scheduled"?"grid-cols-3":"grid-cols-2"}`,children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.priorityField")}),r.jsxs("select",{value:$,onChange:le=>Q(le.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:[r.jsx("option",{value:"low",children:t("work:priority.low")}),r.jsx("option",{value:"medium",children:t("work:priority.medium")}),r.jsx("option",{value:"high",children:t("work:priority.high")}),r.jsx("option",{value:"urgent",children:t("work:priority.urgent")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.taskType")}),r.jsxs("select",{value:Ce,onChange:le=>Be(le.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:[r.jsx("option",{value:"standard",children:t("work:task.taskTypeStandard")}),r.jsx("option",{value:"scheduled",children:t("work:task.taskTypeScheduled")})]})]}),Ce==="scheduled"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.frequency")}),r.jsxs("select",{value:Qe,onChange:le=>We(le.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:[r.jsx("option",{value:"30m",children:t("work:task.freq30m")}),r.jsx("option",{value:"1h",children:t("work:task.freq1h")}),r.jsx("option",{value:"2h",children:t("work:task.freq2h")}),r.jsx("option",{value:"4h",children:t("work:task.freq4h")}),r.jsx("option",{value:"8h",children:t("work:task.freq8h")}),r.jsx("option",{value:"12h",children:t("work:task.freq12h")}),r.jsx("option",{value:"1d",children:t("work:task.freq1d")}),r.jsx("option",{value:"1w",children:t("work:task.freq1w")})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.blockedBy")}),r.jsx(LJ,{options:Object.values(j).flat().filter(le=>le.status!=="completed"&&le.status!=="cancelled").map(le=>({value:le.id,label:le.title})),selected:ce,onAdd:le=>ge([...ce,le]),placeholder:t("work:task.selectDependency"),noMatchesText:t("work:task.noMatches")}),ce.length>0&&r.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ce.map(le=>{const se=Object.values(j).flat().find(be=>be.id===le);return r.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:[se?se.title.slice(0,30):le.slice(-8),r.jsx("button",{onClick:()=>ge(ce.filter(be=>be!==le)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},le)})})]}),wt&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:wt}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{Z(!1),bt("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:t("common:cancel")}),r.jsx("button",{onClick:()=>{ps()},disabled:!Y.trim()||!q||!K,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:t("common:create")})]})]})}),Dn&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Zt(!1),Bn(""),gr(""),jt("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${o?"w-full":"w-[28rem]"}`,onClick:le=>le.stopPropagation(),children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:t("work:task.newRequirementModalTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:t("work:task.newRequirementModalHint")})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.projectLabel")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx(Ld,{options:h.map(le=>({value:le.id,label:le.name})),value:Cr,onChange:$r,placeholder:t("work:task.selectProject"),noMatchesText:t("work:task.noMatches")})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.titleField")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx("input",{value:Sr,onChange:le=>Bn(le.target.value),placeholder:t("work:task.reqTitleExample"),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:!o,onKeyDown:le=>{le.key==="Enter"&&Sr.trim()&&Xs()}})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.descriptionField")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx("textarea",{value:zr,onChange:le=>gr(le.target.value),placeholder:t("work:task.reqDescPlaceholder"),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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.priorityField")}),r.jsxs("select",{value:sr,onChange:le=>fr(le.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:[r.jsx("option",{value:"low",children:t("work:priority.low")}),r.jsx("option",{value:"medium",children:t("work:priority.medium")}),r.jsx("option",{value:"high",children:t("work:priority.high")}),r.jsx("option",{value:"urgent",children:t("work:priority.urgent")})]})]}),ut&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:ut}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{Zt(!1),Bn(""),gr(""),jt("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:t("common:cancel")}),r.jsx("button",{onClick:()=>{Xs()},disabled:!Sr.trim()||!zr.trim()||!Cr,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:t("common:create")})]})]})}),Ee&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ke(null),Hn("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${o?"w-full":"w-96"}`,onClick:le=>le.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:t("work:task.rejectRequirementTitle")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.rejectReasonLabel")}),r.jsx("textarea",{value:Ae,onChange:le=>ot(le.target.value),placeholder:t("work:task.rejectReasonPlaceholder"),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:!o})]}),er&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:er}),r.jsxs("div",{className:"flex justify-end gap-3",children:[r.jsx("button",{onClick:()=>{Ke(null),Hn("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:t("common:cancel")}),r.jsx("button",{onClick:()=>{ks()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:t("work:task.reject")})]})]})}),wn&&r.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>An(!1),children:[r.jsx("div",{className:"absolute inset-0 bg-black/50"}),r.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:le=>le.stopPropagation(),children:[r.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:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:t("work:task.filtersSheetTitle")}),r.jsxs("div",{className:"flex items-center gap-2",children:[(at.size>0||Re.size>0||Pe)&&r.jsx("button",{onClick:()=>{gt(new Set),ke(new Set),lt(!1)},className:"text-[11px] text-brand-500 font-medium",children:t("work:task.clearAll")}),r.jsx("button",{onClick:()=>An(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),h.length>1&&r.jsxs("div",{className:"px-4 py-3",children:[r.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:t("work:task.projectsFilterGroup")}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:ga.map(le=>{const se=at.has(le.id),be=cr[le.id]??0;return r.jsxs("button",{onClick:()=>Wa(le.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${se?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${se?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:le.name[0]?.toUpperCase()}),le.name,be>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:be})]},le.id)})})]}),e?.id&&r.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:r.jsx("button",{type:"button",onClick:()=>lt(le=>!le),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Pe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:t("work:task.myTasks")})}),T.length>0&&r.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[r.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:t("work:task.agentsFilterGroup")}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:Qs.map(le=>{const se=Re.has(le.id);return r.jsxs("button",{onClick:()=>cs(le.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${se?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${se?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:le.name[0]?.toUpperCase()}),le.name]},le.id)})})]}),r.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function JJ({requirementId:e,createdBy:t,agents:n,users:s,authUser:a}){const{t:o}=ht(["work","common"]),[c,d]=v.useState([]),[u,f]=v.useState([]),h=v.useRef(null);v.useEffect(()=>{ue.requirements.getComments(e).then(k=>d(k.comments)).catch(()=>{})},[e]),v.useEffect(()=>gn.on("requirement:comment",j=>{if(j.payload?.requirementId===e&&j.payload.comment){const S=j.payload.comment;d(T=>T.some(N=>N.id===S.id)?T:[...T,S]),(S.authorType==="agent"||S.authorId?.startsWith("agt_"))&&f(T=>{const N=T.filter(E=>E.id!==S.authorId);return N.length===0&&h.current&&(clearTimeout(h.current),h.current=null),N})}}),[e]);const[p,x]=v.useState(null),b=async(k,j,S,T)=>{let N;S.length>0&&(N=(await ue.uploads.upload(S.map(O=>({dataUrl:O.dataUrl,name:O.name})),"comments")).files.map(O=>({type:"image",url:O.url,name:O.name}))),await ue.requirements.addComment(e,k,a?.name,N,a?.id,j.length>0?j:void 0,T);const E=[],B=new Set,A=H=>{if(B.has(H)||H===a?.id)return;B.add(H);const O=n.find(z=>z.id===H);O&&E.push({id:O.id,name:O.name,avatarUrl:O.avatarUrl})};for(const H of j){const O=n.find(z=>z.name.toLowerCase()===H.toLowerCase());O&&A(O.id)}t?.startsWith("agt_")&&A(t),E.length>0&&(h.current&&clearTimeout(h.current),f(E),h.current=setTimeout(()=>f([]),12e4))},y=v.useCallback(k=>{x({id:k.id,authorName:k.authorName,content:k.content.slice(0,100)})},[]);return r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:c.length>0?o("work:task.commentsWithCount",{count:c.length}):o("work:task.comments")}),r.jsxs("div",{className:"space-y-0.5 mb-3",children:[c.length===0&&r.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:o("work:task.noCommentsYet")}),c.map(k=>r.jsx(Kd,{comment:k,agents:n,onReply:y},k.id)),u.length>0&&r.jsx("div",{className:"flex flex-col gap-1 pt-1",children:u.map(k=>r.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>St.navigate(_e.TEAM,{agentId:k.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(hs,{name:k.name,avatarUrl:k.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),r.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),r.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:k.name}),r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]},k.id))})]}),r.jsx(iN,{agents:n,humans:s,onSubmit:b,replyTo:p,onCancelReply:()=>x(null)})]})}function eee({req:e,agents:t,projects:n,allTasks:s,users:a,onClose:o,onApprove:c,onReject:d,onCancel:u,onStatusChange:f,onRefresh:h,authUser:p,scrollToComments:x,onScrollToCommentsDone:b,onTaskClick:y,onCreateTask:k}){const{t:j}=ht(["work","common"]),S=v.useMemo(()=>m1(j),[j]),T=v.useMemo(()=>c7(j),[j]),N=ws(),[E,B]=v.useState(!1),[A,H]=v.useState(e.description),[O,z]=v.useState(!1),[I,_]=v.useState(!1),X=v.useRef(null);v.useEffect(()=>{if(!x)return;const P=setTimeout(()=>{const ee=X.current;ee&&ee.scrollTo({top:ee.scrollHeight,behavior:"smooth"}),b?.()},300);return()=>clearTimeout(P)},[x,b]);const G=S[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},M=e.source==="agent",U=M&&e.status==="pending",L=e.status==="pending"||e.status==="in_progress",F=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",Z=e.projectId?n.find(P=>P.id===e.projectId):null,Y=Mc(e.createdBy,t,a)??e.createdBy.slice(0,12),D=s.filter(P=>e.taskIds.includes(P.id));return v.useEffect(()=>{H(e.description),B(!1)},[e.id,e.description]),r.jsxs("div",{className:"flex flex-col h-full overflow-hidden bg-surface-secondary",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[N&&r.jsx("button",{onClick:o,className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),r.jsxs("div",{className:"flex-1 min-w-0 pb-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded",children:j("work:task.requirementShort")}),r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${G.cls}`,children:G.label}),e.priority==="high"||e.priority==="urgent"?r.jsx("span",{className:`text-[10px] font-medium ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:e.priority}):r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:e.priority})]}),r.jsx("h2",{className:"text-lg font-semibold text-fg-primary leading-snug",children:e.title})]})]}),!N&&r.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),r.jsxs("div",{ref:X,className:"flex-1 overflow-y-auto p-5 space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:j("work:task.requirementDetailDescription")}),E?r.jsxs("div",{className:"space-y-2",children:[r.jsx("textarea",{value:A,onChange:P=>H(P.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}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{onClick:()=>{B(!1),H(e.description)},className:"px-2.5 py-1 text-xs border border-border-default rounded-lg hover:bg-surface-elevated",children:j("common:cancel")}),r.jsx("button",{onClick:async()=>{z(!0);try{await ue.requirements.update(e.id,{description:A}),B(!1),h?.()}catch{}finally{z(!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:j("common:save")})]})]}):r.jsxs("div",{className:"group relative",children:[e.description?r.jsx(Lr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:j("work:task.requirementNoDescription")}),!F&&r.jsx("button",{onClick:()=>{H(e.description),B(!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:j("common:edit")})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[r.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:j("work:task.createdByLabel")}),r.jsx("span",{className:"text-fg-secondary",children:Y}),M&&r.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:j("work:task.agentTag")})]}),r.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:j("work:task.createdLabel")}),r.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),Z&&r.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:j("work:task.projectLabel")}),r.jsx("span",{className:"text-fg-secondary",children:Z.name})]}),e.approvedBy&&r.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:j("work:task.approvedBy")}),r.jsx("span",{className:"text-fg-secondary",children:Mc(e.approvedBy,t,a)??e.approvedBy.slice(0,12)}),e.approvedAt&&r.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&r.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[r.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:j("work:task.rejectionReason")}),r.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),Array.isArray(e.tags)&&e.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(P=>r.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",P]},P))}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:j("work:task.linkedTasks",{count:D.length})}),!F&&k&&r.jsxs("button",{onClick:()=>k(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[r.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),j("work:requirement.createTask")]})]}),D.length>0?r.jsx("div",{className:"space-y-1.5",children:D.map(P=>{const ee=T[P.status];return r.jsxs("div",{onClick:()=>y?.(P),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${y?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${BJ[P.priority]?.replace("border-l-","bg-")??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:P.title}),ee&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${ee.cls}`,children:ee.label})]},P.id)})}):r.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:j("work:requirement.noLinkedTasks")})]}),r.jsx(JJ,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:a,authUser:p}),r.jsx(f7,{entityType:"requirement",entityId:e.id})]}),r.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[U&&r.jsxs(r.Fragment,{children:[r.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:j("work:requirement.approveRequirement")}),r.jsx("button",{onClick:()=>d(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:j("work:requirement.rejectRequirement")})]}),!U&&f&&!F&&r.jsx("select",{value:e.status,onChange:P=>{P.target.value!==e.status&&f(e.id,P.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:XJ.map(P=>{const ee=S[P],$=P===e.status||(Jx[e.status]?.has(P)??!1);return r.jsx("option",{value:P,disabled:!$,children:ee?.label??P},P)})}),F&&f&&r.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:j("work:task.reopen")}),r.jsx("div",{className:"flex-1"}),L&&!U&&r.jsx("button",{onClick:()=>_(!0),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:j("work:task.cancelRequirement")})]}),I&&r.jsx(cc,{title:j("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:j("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:j("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{_(!1),u(e.id)},onCancel:()=>_(!1)})]})}function f7({entityType:e,entityId:t}){const{t:n}=ht(["work"]),[s,a]=v.useState([]),[o,c]=v.useState(!0),[d,u]=v.useState(!1);if(v.useEffect(()=>{c(!0),(e==="task"?ue.tasks.getHistory:ue.requirements.getHistory)(t).then(b=>a(b.history)).catch(()=>a([])).finally(()=>c(!1))},[e,t]),o)return r.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:n("work:task.loadingHistory","Loading history...")});if(s.length===0)return r.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:n("work:task.noHistory","No status change history.")});const f=d?s:s.slice(-5),h=s.length>5&&!d,p=x=>{const b=x.changedByName||x.changedById||(x.changedByType==="human"?"User":x.changedByType==="agent"?"Agent":"System"),y=x.changedByType==="human"?"bg-blue-500/20 text-blue-500":x.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${y}`,children:b})};return r.jsxs("div",{className:"px-6 py-4",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:n("work:task.statusHistory","Status History")}),h&&r.jsx("button",{onClick:()=>u(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:n("work:task.showAllHistory",{count:s.length})}),r.jsxs("div",{className:"relative ml-2",children:[r.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),r.jsx("div",{className:"space-y-3",children:f.map(x=>r.jsxs("div",{className:"flex items-start gap-3 relative",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:x.changedByType==="human"?"#3b82f6":x.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[p(x),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:x.fromStatus}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:x.toStatus})]}),x.reason&&r.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:x.reason}),r.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(x.createdAt).toLocaleString()})]})]},x.id))})]})]})}function Ja(e){return Array.isArray(e)?e.map(t=>String(t).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function tee(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function tl({label:e,value:t}){return t?r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),r.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:t})]}):null}function sc({label:e,value:t,color:n}){if(!t)return null;const s={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 r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),r.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${s[n]??s.gray} capitalize inline-block`,children:t})]})}function Fg({files:e}){const{t}=ht(["builder","common"]),[n,s]=v.useState(Object.keys(e)[0]??""),a=Object.keys(e);return a.length===0?null:r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("builder:artifact.files",{count:a.length})}),r.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[r.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:a.map(o=>r.jsx("button",{onClick:()=>s(o),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${n===o?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:o},o))}),n&&e[n]!=null&&r.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[n]})]})]})}function nee({artifact:e,mode:t}){const{t:n}=ht(["builder","common"]),s=tee(e),a=e.agent,o=e.team,c=e.dependencies,d=e.displayName??e.name;if(t==="agent"){const u=a?.roleName,f=a?.agentRole,h=a?.llmProvider,p=a?.llmModel,x=Ja(c?.env),b=Ja(c?.skills);return r.jsxs("div",{className:"space-y-3 text-sm",children:[r.jsx(tl,{label:n("builder:artifact.name"),value:d}),r.jsx(tl,{label:n("builder:artifact.description"),value:e.description}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[u&&r.jsx(sc,{label:n("builder:artifact.baseTemplate"),value:u,color:"indigo"}),r.jsx(sc,{label:n("builder:artifact.agentRole"),value:f,color:f==="manager"?"purple":"cyan"})]}),Ja(e.tags).length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:Ja(e.tags).map(y=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:y},y))}),(h||p)&&r.jsxs("div",{className:"flex gap-2",children:[h&&r.jsx(sc,{label:n("builder:artifact.llmProvider"),value:h,color:"gray"}),p&&r.jsx(sc,{label:n("builder:artifact.llmModel"),value:p,color:"gray"})]}),x.length>0&&r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:n("builder:artifact.requiredEnv")}),r.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:x.map(y=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/10 text-amber-600 rounded font-mono",children:y},y))})]}),b.length>0&&r.jsx(tl,{label:n("builder:artifact.skills"),value:b.join(", ")}),s&&r.jsx(Fg,{files:s})]})}if(t==="team"){const f=o?.members??[];return r.jsxs("div",{className:"space-y-3 text-sm",children:[r.jsx(tl,{label:n("builder:artifact.name"),value:d}),r.jsx(tl,{label:n("builder:artifact.description"),value:e.description}),r.jsx("div",{className:"flex flex-wrap gap-2",children:r.jsx(sc,{label:n("builder:artifact.category"),value:e.category,color:"indigo"})}),Ja(e.tags).length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:Ja(e.tags).map(h=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:h},h))}),s&&r.jsx(Fg,{files:s}),r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:n("builder:artifact.members",{count:f.length})}),r.jsx("div",{className:"mt-1.5 space-y-1.5",children:f.map((h,p)=>r.jsxs("div",{className:"bg-surface-elevated/30 rounded-lg px-2 py-1.5 border border-border-default/20",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`w-5 h-5 rounded flex items-center justify-center text-[10px] font-bold ${h.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:h.role==="manager"?"★":p+1}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:h.name}),typeof h.roleName=="string"&&h.roleName&&r.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:h.roleName}),r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(h.count??1)]})]}),Ja(h.skills).length>0&&r.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:Ja(h.skills).map(x=>r.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:x},x))})]},p))})]})]})}return r.jsxs("div",{className:"space-y-3 text-sm",children:[r.jsx(tl,{label:n("builder:artifact.name"),value:d}),r.jsx(tl,{label:n("builder:artifact.description"),value:e.description}),r.jsx("div",{className:"flex gap-2",children:r.jsx(sc,{label:n("builder:artifact.category"),value:e.category,color:"indigo"})}),s&&r.jsx(Fg,{files:s}),Ja(e.tags).length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:Ja(e.tags).map(u=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:u},u))})]})}const Od={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},bk={active:{color:"text-green-600 bg-green-500/10"},verified:{color:"text-blue-600 bg-blue-500/10"},outdated:{color:"text-red-500 bg-red-500/10"}},yk=["file","directory"];function _d(e){return/^https?:\/\//i.test(e)}const nl={agent:{icon:"✦",color:"bg-brand-500/10 text-brand-500"},team:{icon:"◈",color:"bg-blue-500/10 text-blue-600"},skill:{icon:"⬡",color:"bg-amber-500/10 text-amber-600"}};function vk({authUser:e}={}){const{t}=ht(["deliverables","common"]),n=ws(),s=vm({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[a,o]=v.useState(!1),c=v.useRef(a);c.current=a,v.useEffect(()=>{if(!n)return;const Ae=()=>{c.current&&o(!1)};return window.addEventListener("popstate",Ae),()=>window.removeEventListener("popstate",Ae)},[n]);const d=100,[u,f]=v.useState([]),[h,p]=v.useState(0),[x,b]=v.useState(!1),[y,k]=v.useState([]),[j,S]=v.useState([]),[T,N]=v.useState(!0),[E,B]=v.useState(""),[A,H]=v.useState(""),[O,z]=v.useState(""),[I,_]=v.useState(""),[X,G]=v.useState(""),[M,U]=v.useState(""),[L,F]=v.useState(""),[Z,Y]=v.useState("date"),[D,P]=v.useState(null),[ee,$]=v.useState(null),[Q,q]=v.useState(""),[J,K]=v.useState(!1),[re,de]=v.useState(!1),[pe,te]=v.useState(new Set),we=v.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),ce=v.useCallback(Ae=>{Y(Ae),te(new Set)},[]),ge=Hi(we,Z,ce),Ce=v.useRef(null),[Be,Qe]=v.useState("file"),[We,wt]=v.useState(""),[bt,$t]=v.useState(""),[dt,me]=v.useState(""),[ve,Re]=v.useState(""),[ke,Pe]=v.useState(""),[lt,at]=v.useState(null),[gt,Ft]=v.useState(null),[Bt,tn]=v.useState(!1),[It,Pt]=v.useState(!1),[Nt,cn]=v.useState(!1),[Xt,pn]=v.useState(""),On=v.useRef(void 0),rn=(Ae,ot)=>{$({type:Ae,text:ot}),setTimeout(()=>$(null),3e3)},xn=async Ae=>{await qb(Ae)?(cn(!0),setTimeout(()=>cn(!1),1500)):rn("error",t("detail.copyFailed"))},Gn=v.useMemo(()=>new Map(j.map(Ae=>[Ae.id,Ae])),[j]),wn=v.useMemo(()=>new Map(y.map(Ae=>[Ae.id,Ae])),[y]);v.useEffect(()=>{ue.projects.list().then(Ae=>k(Ae.projects)).catch(()=>{}),ue.agents.list().then(Ae=>S(Ae.agents??[])).catch(()=>{}),ue.system.storage().then(Ae=>pn(Ae.dataDir+"/shared")).catch(()=>{})},[]),v.useEffect(()=>(On.current=setTimeout(()=>H(E),300),()=>clearTimeout(On.current)),[E]);const An=v.useMemo(()=>({q:A||void 0,projectId:I||void 0,agentId:X||void 0,type:O||void 0,status:M||void 0,artifactType:L||void 0}),[A,I,X,O,M,L]),sn=v.useCallback(async()=>{N(!0);try{const{results:Ae,total:ot}=await ue.deliverables.search({...An,offset:0,limit:d});f(Ae),p(ot)}catch{f([]),p(0)}N(!1)},[An]),Pn=v.useCallback(async()=>{if(!(x||u.length>=h)){b(!0);try{const{results:Ae,total:ot}=await ue.deliverables.search({...An,offset:u.length,limit:d});f(ut=>[...ut,...Ae]),p(ot)}catch{}b(!1)}},[An,u.length,h,x]);v.useEffect(()=>{sn()},[sn]),v.useEffect(()=>{const Ae=gn.on("deliverable:created",()=>sn()),ot=gn.on("deliverable:updated",()=>sn()),ut=gn.on("deliverable:removed",()=>sn());return()=>{Ae(),ot(),ut()}},[sn]);const Dn=v.useCallback(()=>{const Ae=Ce.current;!Ae||T||x||u.length>=h||Ae.scrollHeight<=Ae.clientHeight+100&&Pn()},[T,x,u.length,h,Pn]);v.useEffect(()=>{const Ae=Ce.current;if(!Ae)return;const ot=()=>{Ae.scrollTop+Ae.clientHeight>=Ae.scrollHeight-100&&Pn()};return Ae.addEventListener("scroll",ot,{passive:!0}),()=>Ae.removeEventListener("scroll",ot)},[Pn]),v.useEffect(()=>{Dn()},[Dn,pe]);const Zt=v.useMemo(()=>{const Ae=new Map;for(const ut of u){let jt,er;if(Z==="project")jt=ut.projectId??"_none",er=ut.projectId?wn.get(ut.projectId)?.name??ut.projectId:t("noProject");else if(Z==="agent")jt=ut.agentId??"_none",er=ut.agentId?Gn.get(ut.agentId)?.name??ut.agentId:t("common:unknown");else if(Z==="type")jt=ut.type,er=ut.type.charAt(0).toUpperCase()+ut.type.slice(1);else{const Hn=new Date(ut.updatedAt);jt=`${Hn.getFullYear()}-${String(Hn.getMonth()+1).padStart(2,"0")}-${String(Hn.getDate()).padStart(2,"0")}`,er=jt}Ae.has(jt)||Ae.set(jt,{label:er,items:[]}),Ae.get(jt).items.push(ut)}const ot=[...Ae.entries()];return Z==="date"?ot.sort((ut,jt)=>jt[0].localeCompare(ut[0])):ot.sort((ut,jt)=>ut[1].label.localeCompare(jt[1].label)),ot},[u,Z,wn,Gn,t]),Sr=async()=>{if(!(!We.trim()||!bt.trim())){de(!0);try{await ue.deliverables.create({type:Be,title:We,summary:bt,reference:dt,projectId:ve||void 0,tags:ke.split(",").map(Ae=>Ae.trim()).filter(Boolean)}),K(!1),rn("success",t("createModal.created")),sn()}catch(Ae){rn("error",t("common:error",{message:String(Ae)}))}de(!1)}},Bn=async Ae=>{q("verify");try{await ue.deliverables.verify(Ae.id),rn("success",t("common:verified")),P({...Ae,status:"verified"}),sn()}catch(ot){rn("error",t("common:error",{message:String(ot)}))}q("")},zr=async Ae=>{q("flag");try{await ue.deliverables.update(Ae.id,{status:"outdated"}),rn("success",t("flaggedOutdated")),P({...Ae,status:"outdated"}),sn()}catch(ot){rn("error",t("common:error",{message:String(ot)}))}q("")},gr=async Ae=>{q("remove");try{await ue.deliverables.remove(Ae.id),rn("success",t("removed")),P(null),sn()}catch(ot){rn("error",t("common:error",{message:String(ot)}))}q("")},sr=()=>{St.navigate(_e.BUILDER)},fr=async Ae=>{if(Ae.reference&&!_d(Ae.reference)){if(Ae.type==="directory"){Pt(!0);return}tn(!0);try{const ot=await ue.files.preview(Ae.reference);ot.type==="image"&&ot.mimeType?Ft({src:`data:${ot.mimeType};base64,${ot.content}`,name:ot.name}):at(ot.content)}catch{at(null),Ae.type==="file"&&Pt(!0)}tn(!1)}};v.useEffect(()=>{at(null),Ft(null),Pt(!1),D&&fr(D)},[D?.id]);const Cr=v.useCallback(Ae=>{te(ot=>{const ut=new Set(ot);return ut.has(Ae)?ut.delete(Ae):ut.add(Ae),ut})},[]),$r=v.useCallback(()=>{pe.size===Zt.length?te(new Set):te(new Set(Zt.map(([Ae])=>Ae)))},[pe.size,Zt]),Ee=()=>{wt(""),$t(""),me(""),Pe(""),Qe("file"),y.length>0&&Re(y[0].id),K(!0)},Ke=Ae=>{P(Ae),n&&(o(!0),history.pushState({mobileDetail:_e.DELIVERABLES},"",window.location.hash))};return r.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[r.jsxs("div",{className:`${n?"flex-1 min-w-0":"shrink-0"} border-r border-border-default flex flex-col bg-surface-primary`,style:n?a?{display:"none"}:void 0:{width:s.width},children:[r.jsxs("div",{className:"p-4 border-b border-border-default space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary",children:[t("title"),h>0&&r.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",h,")"]})]}),r.jsx("button",{onClick:Ee,className:"text-xs px-2.5 py-1 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:t("create")})]}),r.jsx("input",{value:E,onChange:Ae=>B(Ae.target.value),placeholder:t("searchPlaceholder"),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"}),Xt&&r.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:[r.jsx("span",{className:"truncate font-mono",children:Xt}),r.jsx("button",{onClick:()=>{ue.system.openPath(Xt)},className:"shrink-0 underline hover:text-fg-secondary transition-colors",children:t("common:open")})]}),r.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[r.jsx(jo,{label:t("filters.allTypes"),value:"",current:O||L||"",onClick:()=>{z(""),F("")}}),yk.map(Ae=>r.jsx(jo,{label:`${Od[Ae]?.icon??""} ${Ae}`,value:Ae,current:O,onClick:ot=>{z(ot),F("")}},Ae)),["agent","team","skill"].map(Ae=>r.jsx(jo,{label:`${nl[Ae].icon} ${t(`artifactTypes.${Ae}`)}`,value:Ae,current:L,onClick:ot=>{F(ot),z("")}},Ae))]}),y.length>0&&r.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[r.jsx(jo,{label:t("filters.allProjects"),value:"",current:I,onClick:_}),y.map(Ae=>r.jsx(jo,{label:Ae.name,value:Ae.id,current:I,onClick:_},Ae.id))]}),r.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[r.jsx(jo,{label:t("filters.active"),value:"",current:M,onClick:U}),r.jsx(jo,{label:t("filters.verified"),value:"verified",current:M,onClick:U}),r.jsx(jo,{label:t("filters.outdated"),value:"outdated",current:M,onClick:U})]}),r.jsxs("div",{className:"flex gap-1.5 items-center",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:t("filters.group")}),["date","project","agent","type"].map(Ae=>r.jsx("button",{onClick:()=>{Y(Ae),te(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${Z===Ae?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:t(`groupBy.${Ae}`)},Ae)),Zt.length>1&&r.jsx("button",{onClick:$r,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:pe.size===Zt.length?t("expandAllTooltip"):t("collapseAllTooltip"),children:pe.size===Zt.length?t("expandAll"):t("collapseAll")})]})]}),ee&&r.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${ee.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:ee.text}),r.jsxs("div",{ref:Ce,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:n?ge.onTouchStart:void 0,onTouchEnd:n?ge.onTouchEnd:void 0,children:[T?r.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(Ae=>r.jsxs("div",{className:"animate-pulse space-y-2",children:[r.jsx("div",{className:"h-4 bg-surface-elevated rounded w-3/4"}),r.jsx("div",{className:"h-3 bg-surface-elevated rounded w-1/2"})]},Ae))}):u.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[r.jsx("svg",{className:"w-12 h-12 text-fg-muted mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:r.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"})}),r.jsx("p",{className:"text-sm text-fg-secondary",children:t("empty.title")}),r.jsx("p",{className:"text-xs text-fg-tertiary mt-1 mb-3",children:t("empty.subtitle")}),r.jsx("button",{onClick:Ee,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:t("empty.createFirst")})]}):Zt.map(([Ae,ot])=>{const ut=pe.has(Ae);return r.jsxs("div",{children:[r.jsxs("button",{onClick:()=>Cr(Ae),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:[r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform duration-200 shrink-0 ${ut?"":"rotate-90"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),r.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider truncate",children:ot.label}),r.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",ot.items.length,")"]})]}),!ut&&ot.items.map(jt=>r.jsxs("button",{onClick:()=>Ke(jt),className:`w-full text-left p-3 rounded-lg transition-colors ${D?.id===jt.id?"bg-brand-600/20 border border-brand-500/30":"hover:bg-surface-elevated/60 border border-transparent"}`,children:[r.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:jt.title}),r.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[jt.artifactType&&nl[jt.artifactType]?r.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${nl[jt.artifactType].color}`,children:[nl[jt.artifactType].icon," ",t(`artifactTypes.${jt.artifactType}`)]}):r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium uppercase ${Od[jt.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:jt.type}),r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${bk[jt.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:t(`common:status.${jt.status}`,{defaultValue:jt.status})}),jt.agentId&&r.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:Gn.get(jt.agentId)?.name??t("groupBy.agent")})]})]},jt.id))]},Ae)}),x&&r.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[r.jsx(Ug,{})," ",r.jsx("span",{className:"text-[10px]",children:t("common:loadingMore")})]}),!T&&u.length>0&&r.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:u.length<h?t("count.partial",{loaded:u.length,total:h}):t("count.total",{total:h})})]})]}),!n&&r.jsx("div",{className:"w-1 shrink-0 cursor-col-resize hover:bg-brand-500/30 active:bg-brand-500/50 transition-colors",onMouseDown:s.onResizeStart}),(!n||a)&&r.jsxs("div",{className:"flex-1 overflow-y-auto min-w-0",children:[n&&r.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:[r.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),r.jsx("span",{className:"text-sm font-medium truncate",children:D?.title??t("detail.details")})]}),D?r.jsxs("div",{className:"p-6 space-y-5",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-xl font-semibold text-fg-primary",children:D.title}),r.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[D.status!=="verified"&&r.jsx("button",{onClick:()=>Bn(D),disabled:!!Q,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:t(Q==="verify"?"common:verifying":"detail.verify")}),D.status!=="outdated"&&r.jsx("button",{onClick:()=>zr(D),disabled:!!Q,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:t(Q==="flag"?"detail.flagging":"detail.flagOutdated")}),r.jsx("button",{onClick:()=>gr(D),disabled:!!Q,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:t(Q==="remove"?"common:removing":"common:remove")})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-2 flex-wrap",children:[r.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium uppercase ${Od[D.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[Od[D.type]?.icon??""," ",D.type]}),r.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${bk[D.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:t(`common:status.${D.status}`,{defaultValue:D.status})}),D.artifactType&&nl[D.artifactType]&&r.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${nl[D.artifactType].color}`,children:[nl[D.artifactType].icon," ",t("detail.builderWithType",{type:t(`artifactTypes.${D.artifactType}`)})]})]}),D.reference&&_d(D.reference)&&r.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:[r.jsx("a",{href:D.reference,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-brand-500 hover:text-brand-500 hover:underline truncate flex-1 text-left cursor-pointer",children:D.reference}),r.jsx("button",{onClick:()=>window.open(D.reference,"_blank","noopener,noreferrer"),className:"px-2 py-1 text-[10px] rounded bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",children:t("common:open")}),r.jsx("button",{onClick:()=>xn(D.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Nt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:t(Nt?"common:copied":"common:copy")})]}),D.reference&&!_d(D.reference)&&(D.type==="file"||D.type==="directory")&&r.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:[r.jsx("button",{onClick:()=>{ue.files.reveal(D.reference).catch(()=>rn("error",t("detail.failedToOpenBrowser")))},className:"text-xs font-mono text-brand-500 hover:text-brand-500 hover:underline truncate flex-1 text-left cursor-pointer",title:t("detail.openInFileBrowser"),children:D.reference}),r.jsx("button",{onClick:()=>{ue.files.reveal(D.reference).catch(()=>rn("error",t("detail.failedToOpenBrowser")))},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:t("detail.revealInFinder"),children:t("common:open")}),r.jsx("button",{onClick:()=>xn(D.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Nt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:t("detail.copyPath"),children:t(Nt?"common:copied":"common:copy")})]}),D.reference&&!_d(D.reference)&&D.type!=="file"&&D.type!=="directory"&&r.jsx("div",{className:"mt-2",children:r.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:D.reference})})]}),D.artifactType&&D.artifactData?r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:r.jsx(nee,{artifact:D.artifactData,mode:D.artifactType})}),D.reference&&r.jsxs("div",{className:"px-3 py-2 bg-surface-secondary/50 border border-border-default rounded-lg",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider block mb-1",children:t("detail.artifactDirectory")}),r.jsx("span",{className:"text-xs text-fg-secondary font-mono break-all",children:D.reference})]}),r.jsx("div",{className:"flex gap-2",children:r.jsx("button",{onClick:sr,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:t("detail.openInBuilder")})}),D.summary&&r.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:r.jsx(Lr,{content:D.summary,className:"text-fg-secondary text-sm"})})]}):r.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:Bt?r.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[r.jsx(Ug,{})," ",t("detail.loadingPreview")]}):gt?r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("img",{src:gt.src,alt:gt.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),r.jsx("span",{className:"text-xs text-fg-tertiary",children:gt.name})]}):lt?r.jsx(Lr,{content:lt,className:"text-fg-secondary text-sm"}):It?r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-fg-secondary",children:t("detail.cannotPreview",{type:D.type})}),r.jsxs("div",{className:"flex items-center gap-2",children:[_d(D.reference)?r.jsxs(r.Fragment,{children:[r.jsx("a",{href:D.reference,target:"_blank",rel:"noopener noreferrer",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",children:D.reference}),r.jsx("button",{onClick:()=>window.open(D.reference,"_blank","noopener,noreferrer"),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:t("common:open")})]}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{ue.files.reveal(D.reference).catch(()=>rn("error",t("detail.failedToOpen")))},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:t("detail.openInFileBrowser"),children:D.reference}),r.jsx("button",{onClick:()=>{ue.files.reveal(D.reference).catch(()=>rn("error",t("detail.failedToOpen")))},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:t("common:open")})]}),r.jsx("button",{onClick:()=>xn(D.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Nt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:t(Nt?"common:copied":"common:copy")})]})]}):D.summary?r.jsx(Lr,{content:D.summary,className:"text-fg-secondary text-sm"}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:t("detail.noContent")})}),(D.diffStats||D.testResults)&&r.jsxs("div",{className:"flex gap-4 flex-wrap",children:[D.diffStats&&r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-lg px-4 py-3 text-xs space-y-1",children:[r.jsx("div",{className:"text-fg-tertiary font-medium",children:t("diffStats.title")}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx("span",{className:"text-fg-secondary",children:t("diffStats.files",{count:D.diffStats.filesChanged})}),r.jsxs("span",{className:"text-green-600",children:["+",D.diffStats.additions]}),r.jsxs("span",{className:"text-red-500",children:["-",D.diffStats.deletions]})]})]}),D.testResults&&r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-lg px-4 py-3 text-xs space-y-1",children:[r.jsx("div",{className:"text-fg-tertiary font-medium",children:t("testResults.title")}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx("span",{className:"text-green-600",children:t("testResults.passed",{count:D.testResults.passed})}),r.jsx("span",{className:"text-red-500",children:t("testResults.failed",{count:D.testResults.failed})}),r.jsx("span",{className:"text-fg-secondary",children:t("testResults.skipped",{count:D.testResults.skipped})})]})]})]}),D.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5",children:D.tags.map(Ae=>r.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:Ae},Ae))}),r.jsxs("div",{className:"border-t border-border-default pt-4 space-y-2",children:[r.jsx("div",{className:"text-xs text-fg-tertiary font-medium",children:t("links.title")}),r.jsxs("div",{className:"flex gap-3 flex-wrap",children:[D.taskId&&r.jsx("button",{onClick:()=>St.navigate(_e.WORK,{openTask:D.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2.5 py-1 rounded",children:t("links.task",{id:`${D.taskId.slice(0,12)}...`})}),D.agentId&&r.jsx("button",{onClick:()=>St.navigate(_e.TEAM,{selectAgent:D.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:t("links.agent",{name:Gn.get(D.agentId)?.name??D.agentId.slice(0,12)})}),D.projectId&&r.jsx("button",{onClick:()=>St.navigate(_e.WORK,{projectId:D.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:t("links.project",{name:wn.get(D.projectId)?.name??D.projectId.slice(0,12)})})]})]}),r.jsxs("div",{className:"text-xs text-fg-tertiary space-y-1 border-t border-border-default pt-4",children:[r.jsxs("div",{className:"flex gap-6 flex-wrap",children:[r.jsxs("span",{children:[t("metadata.created")," ",r.jsx("span",{className:"text-fg-secondary",children:new Date(D.createdAt).toLocaleString()})]}),r.jsxs("span",{children:[t("metadata.updated")," ",r.jsx("span",{className:"text-fg-secondary",children:new Date(D.updatedAt).toLocaleString()})]})]}),r.jsx("div",{className:"text-fg-muted select-all",children:t("metadata.id",{id:D.id})})]})]}):r.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:r.jsxs("div",{className:"text-center text-fg-tertiary space-y-2",children:[r.jsx("svg",{className:"w-12 h-12 mx-auto text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:r.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"})}),r.jsx("p",{className:"text-sm",children:t("detail.selectToView")})]})})]}),J&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!re&&K(!1),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:Ae=>Ae.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:t("createModal.title")}),r.jsxs("div",{children:[r.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:t("createModal.type")}),r.jsx("select",{value:Be,onChange:Ae=>Qe(Ae.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:yk.map(Ae=>r.jsxs("option",{value:Ae,children:[Od[Ae]?.icon??""," ",Ae]},Ae))})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[t("createModal.titleField")," ",r.jsx("span",{className:"text-red-500",children:t("createModal.required")})]}),r.jsx("input",{value:We,onChange:Ae=>wt(Ae.target.value),placeholder:t("createModal.titlePlaceholder"),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"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[t("createModal.reference")," ",r.jsxs("span",{className:"text-fg-tertiary",children:["(",t("createModal.referenceHint"),")"]})]}),r.jsx("input",{value:dt,onChange:Ae=>me(Ae.target.value),placeholder:t("createModal.referencePlaceholder"),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"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[t("createModal.summary")," ",r.jsx("span",{className:"text-red-500",children:t("createModal.required")})," ",r.jsxs("span",{className:"text-fg-tertiary",children:["(",t("createModal.summaryHint"),")"]})]}),r.jsx("textarea",{value:bt,onChange:Ae=>$t(Ae.target.value),placeholder:t("createModal.summaryPlaceholder"),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"})]}),r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("div",{className:"flex-1",children:[r.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[t("createModal.tags")," ",r.jsxs("span",{className:"text-fg-tertiary",children:["(",t("createModal.tagsHint"),")"]})]}),r.jsx("input",{value:ke,onChange:Ae=>Pe(Ae.target.value),placeholder:t("createModal.tagsPlaceholder"),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"})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:t("createModal.project")}),r.jsxs("select",{value:ve,onChange:Ae=>Re(Ae.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:[r.jsx("option",{value:"",children:t("common:none")}),y.map(Ae=>r.jsx("option",{value:Ae.id,children:Ae.name},Ae.id))]})]})]}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1 border-t border-border-default",children:[r.jsx("button",{onClick:()=>K(!1),disabled:re,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:t("common:cancel")}),r.jsxs("button",{onClick:Sr,disabled:re||!We.trim()||!bt.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:[re&&r.jsx(Ug,{}),t(re?"common:creating":"common:create")]})]})]})})]})}function jo({label:e,value:t,current:n,onClick:s}){return r.jsx("button",{onClick:()=>s(n===t?"":t),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${n===t?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function Ug(){return r.jsxs("svg",{className:"animate-spin h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function Oi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function oc(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function ree(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 m7({authUser:e}){const{t}=ht(["reports","common"]),[n,s]=v.useState("weekly"),[a,o]=v.useState(null),[c,d]=v.useState(!0),[u,f]=v.useState(""),[h,p]=v.useState(null),[x,b]=v.useState([]),[y,k]=v.useState("totalTokens"),[j,S]=v.useState(!0),[T,N]=v.useState("generate"),[E,B]=v.useState([]),[A,H]=v.useState(null),[O,z]=v.useState([]),[I,_]=v.useState(""),[X,G]=v.useState(""),M=q=>{G(q),setTimeout(()=>G(""),3e3)},U=v.useCallback(async q=>{d(!0),f("");try{const{report:J}=await ue.reports.generate({period:q,scope:"org",orgId:"default"});o(J)}catch(J){f(String(J)),o(null)}d(!1)},[]),L=v.useCallback(()=>{ue.usage.summary().then(q=>p(q.usage)).catch(()=>{}),ue.usage.agents().then(q=>b(q.agents)).catch(()=>{})},[]),F=v.useCallback(async()=>{try{const{reports:q}=await ue.reports.list();B(q)}catch{}},[]),Z=v.useCallback(async q=>{H(q);try{const{feedback:J}=await ue.reports.getFeedback(q.id);z(J)}catch{z([])}},[]);v.useEffect(()=>{U(n)},[n,U]),v.useEffect(()=>{L();const q=setInterval(L,3e4);return()=>clearInterval(q)},[L]),v.useEffect(()=>{T==="history"&&F()},[T,F]);const Y=v.useMemo(()=>[...x].sort((q,J)=>{const K=q[y],re=J[y];return j?re-K:K-re}),[x,y,j]),D=x.reduce((q,J)=>q+J.estimatedCost,0),P=x.reduce((q,J)=>q+J.tokensUsedToday,0),ee=Math.max(1,...x.map(q=>q.totalTokens)),$=q=>{y===q?S(!j):(k(q),S(!0))},Q=v.useMemo(()=>({daily:t("period.today"),weekly:t("period.thisWeek"),monthly:t("period.thisMonth")}),[t]);return r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl p-6 space-y-6",children:[r.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[r.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[r.jsx("h1",{className:"text-xl font-semibold text-fg-primary",children:t("title")}),r.jsxs("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:[r.jsx("button",{onClick:()=>N("generate"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${T==="generate"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("tabs.generate")}),r.jsxs("button",{onClick:()=>N("history"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${T==="history"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:[t("tabs.history"),E.length>0?` (${E.length})`:""]})]})]}),r.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[X&&r.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:X}),T==="generate"&&r.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(q=>r.jsx("button",{onClick:()=>s(q),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${n===q?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t(`period.${q}`)},q))})]})]}),T==="history"&&!A&&r.jsx("section",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden",children:E.length===0?r.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:t("noReportsYet")}):r.jsx("div",{className:"divide-y divide-border-default/50",children:E.map(q=>r.jsxs("button",{onClick:()=>Z(q),className:"w-full text-left px-5 py-3 flex items-center gap-4 hover:bg-surface-elevated/30 transition-colors",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("reportType",{type:q.type})}),r.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(q.periodStart).toLocaleDateString()," — ",new Date(q.periodEnd).toLocaleDateString()]})]}),q.plan&&r.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${q.plan.status==="approved"?"bg-green-500/10 text-green-600":q.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:q.plan.status==="pending"?t("upcomingPlan.planPending"):t("upcomingPlan.planStatus",{status:q.plan.status})}),r.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(q.generatedAt).toLocaleDateString()})]},q.id))})}),T==="history"&&A&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:()=>{H(null),z([])},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:t("backToList")}),r.jsx("span",{className:"text-sm font-medium text-fg-primary",children:t("reportType",{type:A.type})}),r.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(A.periodStart).toLocaleDateString()," — ",new Date(A.periodEnd).toLocaleDateString()]})]}),A.metrics&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskMetrics.title")}),r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[r.jsx(ei,{label:t("taskMetrics.completed"),value:A.metrics.tasksCompleted,color:"text-green-600"}),r.jsx(ei,{label:t("taskMetrics.inProgress"),value:A.metrics.tasksInProgress,color:"text-brand-500"}),r.jsx(ei,{label:t("taskMetrics.created"),value:A.metrics.tasksCreated,color:"text-blue-600"}),r.jsx(ei,{label:t("taskMetrics.blocked"),value:A.metrics.tasksBlocked,color:"text-amber-600"}),r.jsx(ei,{label:t("taskMetrics.failed"),value:A.metrics.tasksFailed,color:"text-red-500"})]})]}),A.costSummary&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("costOverview.title")}),r.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:[r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:A.costSummary.totalTokens.toLocaleString()}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.totalTokens")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:oc(A.costSummary.totalEstimatedCost)}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.estimatedCost")})]}),r.jsxs("div",{children:[r.jsxs("div",{className:`text-2xl font-bold ${A.costSummary.trend==="decreasing"?"text-green-600":A.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[A.costSummary.trend==="decreasing"?"↓":A.costSummary.trend==="increasing"?"↑":"→"," ",A.costSummary.trend]}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.trend")})]})]}),A.costSummary.byAgent&&A.costSummary.byAgent.length>0&&r.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:A.costSummary.byAgent.map((q,J)=>r.jsxs("div",{className:"flex items-center justify-between text-xs",children:[r.jsx("span",{className:"text-fg-secondary",children:q.agentId}),r.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t("costOverview.byAgentRow",{tokens:Oi(q.tokens),cost:oc(q.cost)})})]},J))})]}),A.taskSummary&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 overflow-hidden",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskSummary.title")}),r.jsxs("div",{className:"space-y-4 min-w-0",children:[A.taskSummary.completed.length>0&&r.jsx(ac,{title:t("taskSummary.completedCount",{count:A.taskSummary.completed.length}),color:"emerald",items:A.taskSummary.completed.map(q=>({id:q.id,label:q.title,sub:q.agent}))}),A.taskSummary.inProgress.length>0&&r.jsx(ac,{title:t("taskSummary.inProgressCount",{count:A.taskSummary.inProgress.length}),color:"indigo",items:A.taskSummary.inProgress.map(q=>({id:q.id,label:q.title,sub:q.agent}))}),A.taskSummary.blocked.length>0&&r.jsx(ac,{title:t("taskSummary.blockedCount",{count:A.taskSummary.blocked.length}),color:"amber",items:A.taskSummary.blocked.map(q=>({id:q.id,label:q.title,sub:q.reason||q.agent}))}),A.taskSummary.completed.length===0&&A.taskSummary.inProgress.length===0&&A.taskSummary.blocked.length===0&&r.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]}),A.highlights&&A.highlights.length>0&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-2",children:t("highlights")}),r.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:A.highlights.map((q,J)=>r.jsx("li",{children:q},J))})]}),A.blockers&&A.blockers.length>0&&r.jsxs("section",{className:"bg-surface-secondary border border-amber-500/20 rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-amber-600 mb-2",children:t("blockers")}),r.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:A.blockers.map((q,J)=>r.jsx("li",{children:q},J))})]}),A.plan&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("h3",{className:"text-xs font-semibold text-fg-secondary",children:[t("upcomingPlan.title"),r.jsx("span",{className:`ml-2 px-1.5 py-0.5 rounded text-[10px] font-medium ${A.plan.status==="approved"?"bg-green-500/10 text-green-600":A.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:t(`common:status.${A.plan.status}`,{defaultValue:A.plan.status})})]}),A.plan.status==="pending"&&r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:async()=>{try{const{report:q}=await ue.reports.approvePlan(A.id,{approvedBy:e?.id??"unknown"});H(q),M(t("upcomingPlan.planApproved")),F()}catch(q){M(t("common:error",{message:String(q)}))}},className:"px-3 py-1.5 text-xs font-medium bg-green-600 text-white rounded-lg hover:bg-green-500 transition-colors",children:t("upcomingPlan.approvePlan")}),r.jsx("button",{onClick:async()=>{const q=prompt(t("upcomingPlan.rejectionReason"));if(q)try{const{report:J}=await ue.reports.rejectPlan(A.id,{rejectedBy:e?.id??"unknown",reason:q});H(J),M(t("upcomingPlan.planRejected")),F()}catch(J){M(t("common:error",{message:String(J)}))}},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:t("upcomingPlan.rejectPlan")})]})]}),A.plan.items&&A.plan.items.length>0&&r.jsx("div",{className:"space-y-1.5",children:A.plan.items.map((q,J)=>r.jsxs("div",{className:"flex items-center gap-2 text-sm text-fg-secondary",children:[r.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${q.priority==="high"?"bg-red-500/10 text-red-500":q.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:q.priority}),r.jsx("span",{children:q.title}),q.assignee&&r.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:q.assignee})]},J))})]}),!A.metrics&&!A.taskSummary&&!A.costSummary&&r.jsx("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-8 text-center",children:r.jsx("p",{className:"text-sm text-fg-tertiary",children:t("noDetailedMetrics")})}),r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("feedback.title",{count:O.length})}),O.length>0&&r.jsx("div",{className:"space-y-2 mb-4",children:O.map(q=>r.jsxs("div",{className:"p-3 bg-surface-elevated/50 rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary mb-1",children:[r.jsx("span",{className:"font-medium text-fg-secondary",children:q.authorName}),r.jsx("span",{children:q.type}),r.jsx("span",{children:new Date(q.createdAt).toLocaleDateString()})]}),r.jsx("p",{className:"text-xs text-fg-secondary",children:q.content})]},q.id))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:I,onChange:q=>_(q.target.value),placeholder:t("feedback.placeholder"),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:q=>{q.key==="Enter"&&I.trim()&&ue.reports.addFeedback(A.id,{author:e?.id??"unknown",type:"comment",content:I.trim()}).then(({feedback:J})=>{z(K=>[...K,J]),_(""),M(t("feedback.added"))}).catch(J=>M(t("common:error",{message:String(J)})))}}),r.jsx("button",{onClick:()=>{I.trim()&&ue.reports.addFeedback(A.id,{author:e?.id??"unknown",type:"comment",content:I.trim()}).then(({feedback:q})=>{z(J=>[...J,q]),_(""),M(t("feedback.added"))}).catch(q=>M(t("common:error",{message:String(q)})))},disabled:!I.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:t("common:send")})]})]})]}),T==="generate"&&h&&r.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[r.jsx(lf,{label:t("usage.llmTokens"),value:Oi(h.llmTokens),color:"text-brand-500"}),r.jsx(lf,{label:t("usage.toolCalls"),value:Oi(h.toolCalls),color:"text-blue-600"}),r.jsx(lf,{label:t("usage.messages"),value:Oi(h.messages),color:"text-green-600"}),r.jsx(lf,{label:t("usage.storage"),value:ree(h.storageBytes),color:"text-amber-600"})]}),T==="generate"&&(c?r.jsx("div",{className:"flex items-center justify-center h-32 text-fg-tertiary text-sm",children:t("common:loading")}):u?r.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:u}):a?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"text-xs text-fg-tertiary",children:[Q[n]," · ",new Date(a.periodStart).toLocaleDateString()," — ",new Date(a.periodEnd).toLocaleDateString()]}),a.metrics&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskMetrics.title")}),r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[r.jsx(ei,{label:t("taskMetrics.completed"),value:a.metrics.tasksCompleted,color:"text-green-600"}),r.jsx(ei,{label:t("taskMetrics.inProgress"),value:a.metrics.tasksInProgress,color:"text-brand-500"}),r.jsx(ei,{label:t("taskMetrics.created"),value:a.metrics.tasksCreated,color:"text-blue-600"}),r.jsx(ei,{label:t("taskMetrics.blocked"),value:a.metrics.tasksBlocked,color:"text-amber-600"}),r.jsx(ei,{label:t("taskMetrics.failed"),value:a.metrics.tasksFailed,color:"text-red-500"})]})]}),r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("costOverview.title")}),r.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:oc(D)}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.estCostAllTime")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:Oi(P)}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.tokensToday")})]}),a.costSummary&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:a.costSummary.totalTokens.toLocaleString()}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.tokensPeriod",{period:Q[n]})})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:oc(a.costSummary.totalEstimatedCost)}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.costPeriod",{period:Q[n]})})]})]})]})]}),a.taskSummary&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskSummary.title")}),r.jsxs("div",{className:"space-y-4",children:[a.taskSummary.completed.length>0&&r.jsx(ac,{title:t("taskSummary.completedCount",{count:a.taskSummary.completed.length}),color:"emerald",items:a.taskSummary.completed.map(q=>({id:q.id,label:q.title,sub:q.agent}))}),a.taskSummary.inProgress.length>0&&r.jsx(ac,{title:t("taskSummary.inProgressCount",{count:a.taskSummary.inProgress.length}),color:"indigo",items:a.taskSummary.inProgress.map(q=>({id:q.id,label:q.title,sub:q.agent}))}),a.taskSummary.blocked.length>0&&r.jsx(ac,{title:t("taskSummary.blockedCount",{count:a.taskSummary.blocked.length}),color:"amber",items:a.taskSummary.blocked.map(q=>({id:q.id,label:q.title,sub:q.reason||q.agent}))}),a.taskSummary.completed.length===0&&a.taskSummary.inProgress.length===0&&a.taskSummary.blocked.length===0&&r.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]})]}):null),T==="generate"&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden",children:[r.jsx("div",{className:"px-5 py-4 border-b border-border-default",children:r.jsx("h3",{className:"text-sm font-semibold text-fg-secondary",children:t("perAgentUsage.title")})}),x.length===0?r.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:t("perAgentUsage.noData")}):r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"border-b border-border-default text-xs text-fg-tertiary uppercase tracking-wider",children:[r.jsx("th",{className:"px-4 py-3 text-left font-medium",children:t("perAgentUsage.agent")}),r.jsx(Id,{label:t("perAgentUsage.totalTokens"),col:"totalTokens",current:y,desc:j,onSort:$}),r.jsx(Id,{label:t("perAgentUsage.today"),col:"tokensUsedToday",current:y,desc:j,onSort:$}),r.jsx(Id,{label:t("perAgentUsage.requests"),col:"requestCount",current:y,desc:j,onSort:$}),r.jsx(Id,{label:t("perAgentUsage.toolCalls"),col:"toolCalls",current:y,desc:j,onSort:$}),r.jsx(Id,{label:t("perAgentUsage.estCost"),col:"estimatedCost",current:y,desc:j,onSort:$,align:"right"})]})}),r.jsx("tbody",{children:Y.map(q=>r.jsx(see,{agent:q,maxTokens:ee},q.agentId))}),r.jsx("tfoot",{children:r.jsxs("tr",{className:"border-t border-border-default bg-surface-elevated/30",children:[r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary",children:t("perAgentUsage.totalAgents",{count:x.length})}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Oi(x.reduce((q,J)=>q+J.totalTokens,0))}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Oi(P)}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:x.reduce((q,J)=>q+J.requestCount,0)}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:x.reduce((q,J)=>q+J.toolCalls,0)}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:oc(D)})]})})]})})]})]})})}function ei({label:e,value:t,color:n}){return r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:`text-2xl font-bold ${n}`,children:t}),r.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function ac({title:e,color:t,items:n}){return r.jsxs("div",{className:"min-w-0 overflow-hidden",children:[r.jsx("div",{className:`text-xs font-medium text-${t}-400 mb-1.5`,children:e}),r.jsx("div",{className:"space-y-1.5",children:n.map((s,a)=>r.jsxs("div",{className:`text-sm text-fg-secondary min-w-0 ${s.id?"cursor-pointer hover:text-fg-primary group":""}`,onClick:s.id?()=>St.navigate(_e.WORK,{openTask:s.id}):void 0,children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${t}-500 shrink-0`}),r.jsx("span",{className:`truncate min-w-0 ${s.id?"group-hover:text-brand-500 transition-colors":""}`,children:s.label})]}),s.sub&&s.sub!=="unassigned"&&r.jsx("div",{className:"text-[10px] text-fg-tertiary ml-3.5 mt-0.5 break-all line-clamp-2",children:s.sub})]},s.id??a))})]})}function lf({label:e,value:t,color:n}){return r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("div",{className:"text-sm text-fg-secondary mb-2",children:e}),r.jsx("div",{className:`text-2xl font-bold ${n}`,children:t})]})}function Id({label:e,col:t,current:n,desc:s,onSort:a,align:o}){const c=n===t?s?"↓":"↑":"↕",d=n===t?"text-brand-500":"text-fg-muted";return r.jsxs("th",{className:`px-4 py-3 ${o==="right"?"text-right":"text-left"} font-medium cursor-pointer select-none hover:text-fg-secondary`,onClick:()=>a(t),children:[e,r.jsx("span",{className:`ml-1 ${d}`,children:c})]})}function see({agent:e,maxTokens:t}){const n=t>0?Math.min(100,e.totalTokens/t*100):0,s=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 r.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>St.navigate(_e.TEAM,{selectAgent:e.agentId}),children:[r.jsx("td",{className:"px-4 py-3",children:r.jsxs("div",{className:"flex items-center gap-2.5",children:[r.jsx("div",{className:`w-2 h-2 rounded-full ${s}`}),r.jsxs("div",{children:[r.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),r.jsx("td",{className:"px-4 py-3",children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:r.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${n}%`}})}),r.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:Oi(e.totalTokens)})]})}),r.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:Oi(e.tokensUsedToday)}),r.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.requestCount}),r.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.toolCalls}),r.jsx("td",{className:"px-4 py-3 text-sm text-right text-fg-secondary tabular-nums",children:oc(e.estimatedCost)})]})}function aee({d:e,size:t=18}){return r.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:r.jsx("path",{d:e})})}function iee({authUser:e,onClose:t,onSaved:n}){const{t:s}=ht("common"),[a,o]=v.useState(e.name||""),[c,d]=v.useState(e.email||""),[u,f]=v.useState(!1),[h,p]=v.useState(""),[x,b]=v.useState(e.avatarUrl),y=async k=>{if(k.preventDefault(),!a.trim()){p(s("profile.nameRequired"));return}if(c&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c.trim())){p(s("profile.invalidEmail"));return}f(!0),p("");try{const{user:j}=await ue.auth.updateProfile(a.trim(),c.trim());n({...j,avatarUrl:x??j.avatarUrl})}catch{p(s("profile.failedToSave"))}finally{f(!1)}};return r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50",onClick:t,children:r.jsxs("form",{onSubmit:y,className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[400px] shadow-2xl",onClick:k=>k.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold mb-5",children:s("profile.editProfile")}),r.jsx("div",{className:"flex justify-center mb-5",children:r.jsx(Vb,{currentUrl:x,name:a,size:72,targetType:"user",targetId:e.id,onUploaded:k=>b(k)})}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.name")}),r.jsx("input",{value:a,onChange:k=>o(k.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.email")}),r.jsx("input",{value:c,onChange:k=>d(k.target.value),type:"email",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"})]}),h&&r.jsx("div",{className:"text-xs text-red-500 bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2",children:h})]}),r.jsxs("div",{className:"flex justify-end gap-3 mt-5",children:[r.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated",children:s("cancel")}),r.jsx("button",{type:"submit",disabled:u,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white rounded-lg",children:s(u?"saving":"save")})]})]})})}function oee({authUser:e,collapsed:t,onLogout:n,onUserUpdated:s}){const{t:a}=ht(["nav","common"]),[o,c]=v.useState(!1),[d,u]=v.useState(!1),f=v.useRef(null);if(v.useEffect(()=>{if(!o)return;const x=b=>{f.current&&!f.current.contains(b.target)&&c(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[o]),!e)return null;const h=e.name||a("common:userPlaceholder"),p=e.email||e.role?.[0]?.toUpperCase()+e.role?.slice(1);return r.jsxs(r.Fragment,{children:[r.jsxs("div",{ref:f,className:`relative ${t?"p-2 flex flex-col items-center":"px-4 py-3"}`,children:[r.jsxs("button",{onClick:()=>c(!o),className:`${t?"hover:ring-2 hover:ring-brand-500/50 transition-all rounded-full":"w-full flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-surface-overlay transition-colors"}`,title:t?`${h} — ${p}`:void 0,children:[r.jsx(hs,{name:h,avatarUrl:e.avatarUrl,size:28}),!t&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[r.jsx("div",{className:"text-xs text-fg-secondary truncate",children:h}),r.jsx("div",{className:"text-[11px] text-fg-tertiary truncate",children:p})]}),r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:r.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]}),o&&r.jsxs("div",{className:`absolute ${t?"left-full bottom-0 ml-2":"left-4 right-4 bottom-full mb-1"} bg-surface-secondary border border-border-default rounded-xl shadow-xl z-50 overflow-hidden`,style:t?{minWidth:200}:void 0,children:[r.jsxs("div",{className:"px-4 py-3 border-b border-border-default",children:[r.jsx("div",{className:"text-sm font-medium text-fg-primary",children:h}),r.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:p}),r.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 capitalize",children:e.role})]}),r.jsxs("div",{className:"py-1",children:[r.jsxs("button",{onClick:()=>{c(!1),u(!0)},className:"w-full flex items-center gap-2.5 px-4 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),r.jsx("circle",{cx:"12",cy:"7",r:"4"})]}),a("common:profile.editProfile")]}),r.jsxs("button",{onClick:()=>{c(!1),n()},className:"w-full flex items-center gap-2.5 px-4 py-2 text-sm text-red-500 hover:bg-red-500/10 transition-colors",children:[r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),r.jsx("polyline",{points:"16 17 21 12 16 7"}),r.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]}),a("sidebar.signOut")]})]})]})]}),d&&r.jsx(iee,{authUser:e,onClose:()=>u(!1),onSaved:x=>{u(!1),s?.(x)}})]})}function lee({currentPage:e,onNavigate:t,authUser:n,onLogout:s,onUserUpdated:a,collapsed:o,onToggleCollapse:c}){const{t:d}=ht(["nav","common"]),u=async()=>{try{await ue.auth.logout()}catch{}s?.()};return r.jsxs("aside",{className:"h-dvh bg-surface-secondary flex flex-col shrink-0 overflow-hidden border-r border-border-subtle",children:[r.jsx("div",{className:`flex items-center ${o?"px-2 py-3.5 justify-center":"px-4 h-14 justify-between"}`,children:o?r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("button",{onClick:c,title:d("sidebar.expandSidebar"),className:"group",children:r.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"})}),r.jsx(Cx,{collapsed:!0,userId:n?.id})]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:c,className:"flex items-center gap-2.5 min-w-0 group",title:d("sidebar.collapseSidebar"),children:[r.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"}),r.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx(Cx,{userId:n?.id}),r.jsx("button",{onClick:c,className:"text-fg-tertiary hover:text-fg-secondary transition-colors p-1 rounded-md hover:bg-surface-overlay",title:d("sidebar.collapseSidebar"),children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("polyline",{points:"11 17 6 12 11 7"}),r.jsx("polyline",{points:"18 17 13 12 18 7"})]})})]})]})}),r.jsx("nav",{className:`${o?"p-1.5":"p-3"} flex-1 overflow-y-auto`,children:BO.map((f,h)=>r.jsx("div",{children:r.jsxs("div",{className:"mb-3",children:[!o&&r.jsx("div",{className:"px-3 py-1.5 text-[11px] font-semibold text-fg-tertiary uppercase tracking-widest",children:d(`sections.${f.key}`)}),o&&h>0&&r.jsx("div",{className:"my-2 mx-1"}),HO.filter(p=>p.section===f.key).map(p=>{const x=e===p.id;return r.jsxs("button",{onClick:()=>t(p.id),title:o?d(p.id):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 ${x?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":"text-fg-primary hover:bg-surface-overlay"}`,children:[r.jsx(aee,{d:Ik[p.id]??""}),!o&&d(p.id)]},p.id)})]})},f.key))}),r.jsx(oee,{authUser:n,collapsed:o,onLogout:u,onUserUpdated:a}),!o&&r.jsxs("div",{className:"px-4 pb-2 text-[10px] text-fg-muted",children:["v","0.5.10"]})]})}function cee({currentPage:e,onNavigate:t}){const{t:n}=ht("nav");return r.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:qO.map(s=>{const a=s.group.includes(e);return r.jsxs("button",{onClick:()=>t(s.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${a?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[r.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:a?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:r.jsx("path",{d:Ik[s.id]})}),r.jsx("span",{className:`text-[10px] leading-tight ${a?"font-semibold":""}`,children:n(s.id)})]},s.id)})})}function dee({authUser:e}){const{t}=ht(["nav","common"]),n=v.useMemo(()=>[{id:"builder",label:t("nav:builder")},{id:"agents",label:t("nav:tabs.agents")},{id:"teams",label:t("nav:tabs.teams")},{id:"skills",label:t("nav:tabs.skills")}],[t]),[s,a]=v.useState("builder"),o=Hi(n,s,a);return r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:o.onTouchStart,onTouchEnd:o.onTouchEnd,children:[r.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:n.map(c=>r.jsx("button",{onClick:()=>a(c.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===c.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:c.label},c.id))}),r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="builder"&&r.jsx(uN,{}),s==="agents"&&r.jsx(hN,{authUser:e}),s==="teams"&&r.jsx(xN,{}),s==="skills"&&r.jsx(bN,{})]})]})}function uee({theme:e,onThemeChange:t,authUser:n}){const{t:s}=ht(["nav","common"]),a=v.useMemo(()=>[{id:"settings",label:s("nav:settings")},{id:"reports",label:s("nav:reports")}],[s]),[o,c]=v.useState("settings"),d=Hi(a,o,c);return r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:d.onTouchStart,onTouchEnd:d.onTouchEnd,children:[r.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:a.map(u=>r.jsx("button",{onClick:()=>c(u.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 ${o===u.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:u.label},u.id))}),r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[o==="settings"&&r.jsx(dN,{theme:e,onThemeChange:t,authUser:n}),o==="reports"&&r.jsx(m7,{authUser:n})]})]})}const cf=1,wk=3;function fee({onComplete:e,theme:t,onThemeChange:n}){const{t:s}=ht(["onboarding","common"]),[a,o]=v.useState(0),[c,d]=v.useState(""),[u,f]=v.useState(""),[h,p]=v.useState(""),[x,b]=v.useState(""),[y,k]=v.useState(!1),[j,S]=v.useState(""),[T,N]=v.useState(!1),[E,B]=v.useState(null);v.useEffect(()=>{ue.auth.me().then(({user:ce})=>{ce.name&&d(ce.name),ce.email&&f(ce.email),ce.avatarUrl&&B(ce.avatarUrl)}).catch(()=>{})},[]);const[A,H]=v.useState(null),[O,z]=v.useState(!1),[I,_]=v.useState({}),[X,G]=v.useState(!1),[M,U]=v.useState(null),[L,F]=v.useState(!1),[Z,Y]=v.useState(!1),[D,P]=v.useState(null),ee=v.useRef(!1),$=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});v.useEffect(()=>{fetch("/api/settings/llm").then(ce=>ce.ok?ce.json():null).then(ce=>{ce?.providers&&Object.values(ce.providers).some(ge=>ge.configured)&&Y(!0)}).catch(()=>{})},[]),v.useEffect(()=>{a===wk&&!ee.current&&!Z&&(ee.current=!0,Q())},[a,Z]);const Q=async()=>{z(!0);try{const ce=await fetch("/api/settings/env-models",{headers:$()});if(ce.ok){const ge=await ce.json();if(H(ge),ge.detected.length>0){const Ce={};for(const Be of ge.detected)Ce[Be.provider]=!0;_(Ce)}}}catch{}finally{z(!1)}},q=async()=>{if(!A)return;const ce=A.detected.filter(ge=>I[ge.provider]);if(ce.length!==0){G(!0),P(null);try{const ge=await fetch("/api/settings/env-models",{method:"POST",headers:$(),body:JSON.stringify({providers:ce.map(Ce=>({provider:Ce.provider,model:Ce.model,baseUrl:Ce.baseUrl,enabled:!0}))})});if(ge.ok){const Ce=await ge.json();P({type:"ok",text:Ce.message}),Y(!0)}else P({type:"err",text:s("llm.failedToApply")})}catch{P({type:"err",text:s("common:networkError")})}finally{G(!1)}}},J=async()=>{F(!0);try{const ge=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:$(),body:JSON.stringify({preview:!0})})).json();"error"in ge||U(ge)}catch{}finally{F(!1)}},K=async()=>{F(!0),P(null);try{const ge=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:$(),body:JSON.stringify({preview:!1})})).json();"error"in ge?P({type:"err",text:ge.error}):(P({type:"ok",text:s("llm.importedModels",{count:ge.appliedModels})}),Y(!0))}catch{P({type:"err",text:s("llm.importFailed")})}finally{F(!1)}},re=async()=>{if(S(""),!c.trim()){S(s("profile.errors.nameRequired"));return}if(!u.trim()){S(s("profile.errors.emailRequired"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u.trim())){S(s("profile.errors.emailInvalid"));return}if(h&&h.length<6){S(s("profile.errors.passwordTooShort"));return}if(h&&h!==x){S(s("profile.errors.passwordMismatch"));return}k(!0);try{await ue.auth.updateProfile(c.trim(),u.trim()),h&&await ue.auth.changePassword("",h),N(!0)}catch{S(s("profile.errors.saveFailed"))}finally{k(!1)}},de=[{value:"system",label:s("theme.system"),icon:"💻",desc:s("theme.systemDesc")},{value:"light",label:s("theme.light"),icon:"☀️",desc:s("theme.lightDesc")},{value:"dark",label:s("theme.dark"),icon:"🌙",desc:s("theme.darkDesc")},{value:"cyberpunk",label:s("theme.cyberpunk"),icon:"🔮",desc:s("theme.cyberpunkDesc")},{value:"midnight",label:s("theme.midnight"),icon:"🌊",desc:s("theme.midnightDesc")}],pe=[{title:s("welcome.title"),subtitle:s("welcome.subtitle"),content:r.jsxs("div",{className:"space-y-4 text-fg-secondary text-sm leading-relaxed",children:[r.jsx("p",{className:"text-fg-secondary",children:r.jsx(Qd,{i18nKey:"welcome.description",ns:"onboarding",components:{strong:r.jsx("strong",{className:"text-fg-primary"})}})}),r.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[[s("welcome.features.operation"),s("welcome.features.operationDesc")],[s("welcome.features.collaboration"),s("welcome.features.collaborationDesc")],[s("welcome.features.memory"),s("welcome.features.memoryDesc")],[s("welcome.features.anyLlm"),s("welcome.features.anyLlmDesc")]].map(([ce,ge])=>r.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[r.jsx("div",{className:"font-medium text-fg-primary text-xs",children:ce}),r.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:ge})]},ce))})]})},{title:s("profile.title"),subtitle:s("profile.subtitle"),content:T?r.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[r.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-sm font-medium text-green-600",children:s("profile.saved")}),r.jsxs("div",{className:"text-xs text-fg-secondary mt-0.5",children:[c," · ",u]})]})]}):r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"flex justify-center",children:r.jsx(Vb,{currentUrl:E,name:c,size:64,targetType:"user"})}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[s("profile.nameLabel")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx("input",{type:"text",value:c,onChange:ce=>d(ce.target.value),placeholder:s("profile.namePlaceholder"),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",autoFocus:!0})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[s("profile.emailLabel")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx("input",{type:"email",value:u,onChange:ce=>f(ce.target.value),placeholder:s("profile.emailPlaceholder"),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"})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:s("profile.newPasswordLabel")}),r.jsx("input",{type:"password",value:h,onChange:ce=>p(ce.target.value),placeholder:s("profile.newPasswordPlaceholder"),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"})]}),h&&r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:s("profile.confirmPasswordLabel")}),r.jsx("input",{type:"password",value:x,onChange:ce=>b(ce.target.value),placeholder:s("profile.confirmPasswordPlaceholder"),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"})]}),j&&r.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:j}),r.jsx("button",{onClick:()=>{re()},disabled:y||!c.trim()||!u.trim(),className:"w-full px-4 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:s(y?"common:saving":"profile.saveProfile")})]})},{title:s("theme.title"),subtitle:s("theme.subtitle"),content:r.jsx("div",{className:"grid grid-cols-3 gap-3",children:de.map(ce=>r.jsxs("button",{onClick:()=>n(ce.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===ce.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[r.jsx("span",{className:"text-2xl",children:ce.icon}),r.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ce.label}),r.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:ce.desc})]},ce.value))})},{title:s("llm.title"),subtitle:s("llm.subtitle"),content:Z?r.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[r.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-sm font-medium text-green-600",children:s("llm.configured")}),r.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:s("llm.configuredHint")})]})]}):r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:s("llm.fromEnv")}),O&&r.jsx("div",{className:"text-xs text-fg-tertiary animate-pulse",children:s("llm.detectingKeys")}),A&&A.detected.length>0&&r.jsxs("div",{className:"space-y-2",children:[A.detected.map(ce=>r.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:[r.jsx("input",{type:"checkbox",checked:I[ce.provider]??!1,onChange:ge=>_({...I,[ce.provider]:ge.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-sm text-fg-primary",children:ce.displayName}),r.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:ce.model})]}),r.jsx("code",{className:"text-[10px] text-fg-tertiary",children:ce.apiKeyPreview})]},ce.provider)),r.jsx("button",{onClick:()=>{q()},disabled:X||Object.values(I).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:X?s("common:applying"):s("llm.applyProviders",{count:Object.values(I).filter(Boolean).length})})]}),A&&A.detected.length===0&&!O&&r.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:r.jsx(Qd,{i18nKey:"llm.noKeysFound",ns:"onboarding",components:{code:r.jsx("code",{className:"text-fg-secondary"})}})})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex-1 h-px bg-border-default"}),r.jsx("span",{className:"text-xs text-fg-tertiary",children:s("llm.or")}),r.jsx("div",{className:"flex-1 h-px bg-border-default"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:s("llm.fromOpenClaw")}),M?M.found?r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"text-xs text-green-600",children:[s("llm.openClawFoundLabel")," ",r.jsx("code",{className:"text-fg-secondary",children:M.summary.configPath}),M.summary.models&&r.jsx("span",{className:"text-fg-tertiary ml-1",children:s("llm.openClawProviders",{count:M.summary.models.providerCount})})]}),r.jsx("button",{onClick:()=>{K()},disabled:L,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:s(L?"common:importing":"llm.importModelConfigs")})]}):r.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:s("llm.noOpenClawFound")}):r.jsx("button",{onClick:()=>{J()},disabled:L,className:"px-4 py-2 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-secondary text-sm rounded-lg transition-colors w-full",children:s(L?"common:detecting":"llm.detectOpenClaw")})]}),D&&r.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${D.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:D.text})]})},{title:s("done.title"),subtitle:s("done.subtitle"),content:r.jsx("div",{className:"space-y-2 text-fg-secondary text-sm",children:[[s("done.chat"),s("done.chatDesc")],[s("done.projects"),s("done.projectsDesc")],[s("done.builder"),s("done.builderDesc")],[s("done.settings"),s("done.settingsDesc")]].map(([ce,ge])=>r.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[r.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),r.jsxs("div",{children:[r.jsx("div",{className:"font-medium text-fg-primary text-xs",children:ce}),r.jsx("div",{className:"text-fg-secondary text-xs",children:ge})]})]},ce))})}],te=()=>{a===cf&&!T||(a<pe.length-1?o(a+1):e())},we=pe[a];return r.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:r.jsx("div",{className:"w-full max-w-lg",children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl p-8",children:[r.jsx("div",{className:"flex gap-1.5 mb-8",children:pe.map((ce,ge)=>r.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${ge<=a?"bg-brand-500":"bg-surface-elevated"}`},ge))}),r.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:we.title}),r.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:we.subtitle}),we.content,r.jsxs("div",{className:"flex justify-between mt-8",children:[a>0?r.jsx("button",{onClick:()=>o(a-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:s("common:back")}):r.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("common:skip")}),r.jsxs("div",{className:"flex items-center gap-3",children:[a===cf&&!T&&r.jsx("button",{onClick:()=>o(a+1),className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("llm.skipForNow")}),a===wk&&!Z&&r.jsx("button",{onClick:te,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("llm.skipForNow")}),r.jsx("button",{onClick:te,disabled:a===cf&&!T,className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${a===cf&&!T?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:a===pe.length-1?s("getStarted"):s("common:next")})]})]})]})})})}function mee({onLogin:e}){const{t}=ht("auth"),[n,s]=v.useState(""),[a,o]=v.useState(""),[c,d]=v.useState(""),[u,f]=v.useState(!1),h=async p=>{if(p.preventDefault(),!(!n.trim()||!a)){d(""),f(!0);try{const{user:x}=await ue.auth.login(n.trim(),a),b=n.trim().toLowerCase()==="admin@markus.local"&&a==="markus123";e(x,b)}catch{d(t("login.invalidCredentials"))}finally{f(!1)}}};return r.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[r.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),r.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[r.jsxs("div",{className:"text-center mb-8",children:[r.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),r.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),r.jsx("div",{className:"text-sm text-fg-tertiary",children:t("login.subtitle")})]}),r.jsxs("form",{onSubmit:h,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[r.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:t("login.signIn")}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("login.email")}),r.jsx("input",{type:"email",value:n,onChange:p=>s(p.target.value),autoComplete:"email",placeholder:"your@email.com",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 placeholder:text-fg-tertiary",required:!0})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("login.password")}),r.jsx("input",{type:"password",value:a,onChange:p=>o(p.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),c&&r.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:c}),r.jsx("button",{type:"submit",disabled:u||!n||!a,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:t(u?"login.signingIn":"login.signIn")}),r.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:t("login.defaultCredentials")})]})]})]})}function hee({token:e,onComplete:t}){const{t:n}=ht("auth"),[s,a]=v.useState(null),[o,c]=v.useState(""),[d,u]=v.useState(""),[f,h]=v.useState(""),[p,x]=v.useState(!1),[b,y]=v.useState(!1),[k,j]=v.useState(!1);v.useEffect(()=>{ue.auth.inviteInfo(e).then(T=>a(T)).catch(()=>j(!0))},[e]);const S=async T=>{if(T.preventDefault(),h(""),o.length<6){h(n("invite.passwordMinLength"));return}if(o!==d){h(n("invite.passwordsDoNotMatch"));return}x(!0);try{await ue.auth.setup(e,o),y(!0),setTimeout(()=>{window.location.hash="",t()},2e3)}catch{h(n("invite.error"))}finally{x(!1)}};return r.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[r.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),r.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[r.jsxs("div",{className:"text-center mb-8",children:[r.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),r.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),r.jsx("div",{className:"text-sm text-fg-tertiary",children:n("invite.subtitle")})]}),r.jsx("div",{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:k?r.jsxs("div",{className:"text-center space-y-3",children:[r.jsx("div",{className:"text-red-500 text-3xl",children:"⚠"}),r.jsx("p",{className:"text-sm text-fg-secondary",children:n("invite.invalidLink")}),r.jsx("button",{onClick:()=>{window.location.hash="",t()},className:"text-sm text-brand-500 hover:text-brand-400",children:n("login.signIn")})]}):b?r.jsxs("div",{className:"text-center space-y-3",children:[r.jsx("div",{className:"text-green-500 text-3xl",children:"✓"}),r.jsx("p",{className:"text-sm text-fg-secondary",children:n("invite.setupComplete")})]}):s?r.jsxs("form",{onSubmit:S,className:"space-y-5",children:[r.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:n("invite.greeting",{name:s.name})}),r.jsx("p",{className:"text-xs text-fg-tertiary text-center",children:s.email}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("invite.setPassword")}),r.jsx("input",{type:"password",value:o,onChange:T=>c(T.target.value),autoComplete:"new-password",autoFocus:!0,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})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("invite.confirmPassword")}),r.jsx("input",{type:"password",value:d,onChange:T=>u(T.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})]}),f&&r.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:f}),r.jsx("button",{type:"submit",disabled:p||!o||!d,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:n(p?"invite.settingUp":"invite.setupAccount")})]}):r.jsx("div",{className:"text-center text-fg-tertiary text-sm animate-pulse py-4",children:"Loading…"})})]})]})}function pee({onComplete:e,isFirstTime:t}){const{t:n}=ht("auth"),[s,a]=v.useState(""),[o,c]=v.useState(""),[d,u]=v.useState(""),[f,h]=v.useState(""),[p,x]=v.useState(!1),b=async y=>{if(y.preventDefault(),h(""),o.length<6){h(n("changePassword.passwordMinLength"));return}if(o!==d){h(n("changePassword.passwordsDoNotMatch"));return}x(!0);try{await ue.auth.changePassword(s,o),e()}catch{h(n("changePassword.failedToChange"))}finally{x(!1)}};return r.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[r.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),r.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[r.jsxs("div",{className:"text-center mb-8",children:[r.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),r.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),r.jsx("div",{className:"text-sm text-fg-tertiary",children:n("login.subtitle")})]}),r.jsxs("form",{onSubmit:b,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:n(t?"changePassword.setYourPassword":"changePassword.changePassword")}),t&&r.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:n("changePassword.defaultPasswordWarning")})]}),!t&&r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.currentPassword")}),r.jsx("input",{type:"password",value:s,onChange:y=>a(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"})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.newPassword")}),r.jsx("input",{type:"password",value:o,onChange:y=>c(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})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.confirmNewPassword")}),r.jsx("input",{type:"password",value:d,onChange:y=>u(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})]}),f&&r.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:f}),r.jsx("button",{type:"submit",disabled:p||!o||!d,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:n(p?"changePassword.saving":t?"changePassword.setPasswordAndContinue":"changePassword.changePassword")})]})]})]})}const Vg={};function gee(){const{t:e}=ht("common"),[t,n]=v.useState(jd),[s,a]=v.useState(()=>!localStorage.getItem("markus_onboarded")),[o,c]=v.useState(!0),d=ws(),u=pV(),f=vm({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[h,p]=v.useState(()=>new Set([jd()])),[x,b]=v.useState("loading"),[y,k]=v.useState(!1),[j,S]=v.useState(null),[T,N]=v.useState(!1),[E,B]=v.useState(null),[A,H]=v.useState(()=>{const M=localStorage.getItem("markus_update_dismissed");return M||null}),O=v.useCallback(M=>{let U=So(M);d&&(U=$O[U]??U);const L=jd(),F=window.location.hash.slice(1);F!==L?Vg[L]=F:delete Vg[L];const Z=U!==_e.WORK?Vg[U]:void 0;Z&&Z!==U?(history.pushState(null,"","#"+U),history.pushState(null,"","#"+Z)):history.pushState(null,"","#"+U),window.dispatchEvent(new HashChangeEvent("hashchange")),n(U),p(Y=>Y.has(U)?Y:new Set([...Y,U]))},[d]);v.useEffect(()=>{St.setHandler(M=>O(M))},[O]);const z=v.useCallback(()=>{fetch("/api/settings/llm").then(M=>M.ok?M.json():null).then(M=>{if(M?.providers){const U=Object.values(M.providers).some(L=>L.configured);S(U)}}).catch(()=>{})},[]);v.useEffect(()=>{const M=window.location.hash.startsWith("#invite?token="),U=new URLSearchParams(window.location.search),L=U.get("install");if(L&&jd()!==_e.STORE){const Y=U.get("type"),P=Y&&{agent:"agents",team:"teams",skill:"skills"}[Y]||"agents";localStorage.setItem("markus_nav_installItem",L),localStorage.setItem("markus_nav_storeTab",P),U.delete("install"),U.delete("type");const ee=U.toString();window.history.replaceState(null,"",window.location.pathname+(ee?`?${ee}`:"")+"#store"),setTimeout(()=>St.navigate(_e.STORE,{storeTab:P,installItem:L}),300)}ue.auth.me().then(({user:Y})=>{b(Y),!M&&!localStorage.getItem("markus_onboarded")&&(localStorage.setItem("markus_onboarded","1"),a(!1)),gn.connect(Y.id),z(),ue.health().then(D=>{D.updateAvailable&&D.latestVersion&&B({latestVersion:D.latestVersion,currentVersion:D.version})}).catch(()=>{}),el(Vs.builderArtifacts,()=>ue.builder.artifacts.list()),el(Vs.builderAgents,()=>ue.agents.list()),el(Vs.builderHubMyItems,()=>Nn.myItems()),el(Vs.builderInstalled,()=>ue.builder.artifacts.installed()),el(Vs.hubAgents,()=>Nn.search({type:"agent",limit:50})),el(Vs.hubTeams,()=>Nn.search({type:"team",limit:50})),el(Vs.hubSkills,()=>Nn.search({type:"skill",limit:50}))}).catch(()=>b(null)),gn.connect();const F=gn.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),Z=()=>{const Y=jd();n(Y),p(D=>D.has(Y)?D:new Set([...D,Y]))};return window.addEventListener("hashchange",Z),()=>{F(),gn.disconnect(),window.removeEventListener("hashchange",Z)}},[]);const I=x!=="loading"&&x!==null?x:void 0,_=v.useMemo(()=>d?{[_e.HOME]:r.jsx(cw,{authUser:I}),[_e.TEAM]:r.jsx(Ow,{authUser:I}),[_e.BUILDER]:r.jsx(dee,{authUser:I}),[_e.SETTINGS]:r.jsx(uee,{theme:u.mode,onThemeChange:u.setMode,authUser:I}),[_e.WORK]:r.jsx(xk,{authUser:I}),[_e.DELIVERABLES]:r.jsx(vk,{authUser:I})}:{[_e.HOME]:r.jsx(cw,{authUser:I}),[_e.TEAM]:r.jsx(Ow,{authUser:I}),[_e.SETTINGS]:r.jsx(dN,{theme:u.mode,onThemeChange:u.setMode,authUser:I}),[_e.STORE]:r.jsx(UV,{authUser:I}),[_e.BUILDER]:r.jsx(uN,{authUser:I}),[_e.WORK]:r.jsx(xk,{authUser:I}),[_e.DELIVERABLES]:r.jsx(vk,{authUser:I}),[_e.REPORTS]:r.jsx(m7,{authUser:I})},[I?.id,I?.role,u.mode,d]);if(x==="loading")return r.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:r.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:e("loading")})});const G=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return G?r.jsx(hee,{token:G[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),a(!0),b("loading"),ue.auth.me().then(M=>b(M.user)).catch(()=>b(null))}}):x===null?r.jsx(mee,{onLogin:(M,U)=>{b(M),U?k(!0):localStorage.getItem("markus_onboarded")||(localStorage.setItem("markus_onboarded","1"),a(!1))}}):y?r.jsx(pee,{onComplete:()=>k(!1),isFirstTime:!0}):s?r.jsx(fee,{theme:u.mode,onThemeChange:u.setMode,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),a(!1),z()}}):r.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"relative z-40 shrink-0",style:{width:f.width},children:r.jsx(lee,{currentPage:t,onNavigate:M=>{O(M),c(!1)},authUser:x,onLogout:()=>b(null),onUserUpdated:M=>b(M),collapsed:f.collapsed,onToggleCollapse:f.toggle})}),!f.collapsed&&r.jsx("div",{className:"w-1 cursor-col-resize shrink-0 group relative z-10",onMouseDown:f.onResizeStart,children:r.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"})})]}),r.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col min-w-0 ${d?"pb-14":""}`,children:[j===!1&&!T&&t!==_e.SETTINGS&&r.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:[r.jsx("span",{className:d?"text-xs":"",children:"No LLM provider configured — agents cannot process requests."}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:()=>{O(_e.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"}),r.jsx("button",{onClick:()=>N(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:e("dismiss")})]})]}),E&&A!==E.latestVersion&&r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-brand-500/10 border-b border-brand-500/30 text-brand-400 text-sm shrink-0",children:[r.jsxs("span",{className:d?"text-xs":"",children:["New version available: ",r.jsxs("strong",{children:["v",E.latestVersion]})," (current: v",E.currentVersion,")",!d&&r.jsxs("span",{className:"text-fg-tertiary ml-2",children:["— run ",r.jsx("code",{className:"bg-surface-overlay px-1.5 py-0.5 rounded text-xs font-mono",children:"npm i -g @markus-global/cli"})," to upgrade"]})]}),r.jsx("button",{onClick:()=>{H(E.latestVersion),localStorage.setItem("markus_update_dismissed",E.latestVersion)},className:"text-brand-400 hover:text-brand-300 text-xs shrink-0",children:e("dismiss")})]}),r.jsx("main",{className:"flex-1 overflow-hidden flex flex-col",children:Object.keys(_).map(M=>h.has(M)?r.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:M===t?"flex":"none"},children:_[M]},M):null)})]}),d&&r.jsx(cee,{currentPage:t,onNavigate:O})]})}nC.createRoot(document.getElementById("root")).render(r.jsx(v.StrictMode,{children:r.jsx(gee,{})}));
351
+ ${qe?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),r.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:t("work:task.requirementShort")}),r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${Ps.cls}`,children:Ps.label})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:et.title}),et.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:et.description}),r.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[De&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:De.name,children:De.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:et.priority}),r.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",ze]})]}),r.jsx("div",{className:"flex items-center gap-1",children:et.taskIds.length>0&&r.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",et.taskIds.length]})})]}),ae&&r.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[r.jsx("button",{onClick:mt=>{mt.stopPropagation(),Ma(et.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:t("work:task.approve")}),r.jsx("button",{onClick:mt=>{mt.stopPropagation(),Ke(et.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:t("work:task.reject")})]})]},`req-${et.id}`)}else{const et=Mt.data,Ps=et.subtasks?.length??0,gs=s[et.status],ae=et.status==="pending",De=et.taskType==="scheduled"&&!!et.scheduleConfig,ze=De?et.scheduleConfig.every?t("work:task.everyInterval",{interval:et.scheduleConfig.every}):et.scheduleConfig.cron?t("work:task.cronLabel"):t("work:task.scheduledShort"):null,qe=x==="all"&&et.projectId?h.find(Je=>Je.id===et.projectId)?.name:null,mt=et.requirementId?A.find(Je=>Je.id===et.requirementId)?.title:null,Ve=et.createdBy?Mc(et.createdBy,T,E)??et.createdBy:null,tt=$t?.id===et.id,Ht={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"};return r.jsxs("div",{role:"button",tabIndex:0,"aria-label":et.title,draggable:!ae,onDragStart:Je=>!ae&&ss(Je,et),onDragEnd:Ds,onClick:()=>yn(et),onKeyDown:Je=>Je.key==="Enter"&&yn(et),className:`group rounded-lg p-2.5 border border-transparent transition-all ${ae?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":De?"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"} ${tt?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ht[et.priority]??"bg-gray-400"}`,title:et.priority}),De&&r.jsx("span",{className:"text-blue-500 shrink-0",title:ze??"Scheduled",children:r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.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"})})}),De&&ze&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:ze}),gs&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${gs.cls}`,children:gs.label})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:et.title}),et.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:et.description}),(qe||mt||et.blockedBy&&et.blockedBy.length>0)&&r.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[qe&&r.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:qe,children:qe}),mt&&r.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:mt,children:["# ",mt]}),et.blockedBy&&et.blockedBy.length>0&&r.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",et.blockedBy.length," dep",et.blockedBy.length>1?"s":""]})]}),r.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[r.jsx("div",{className:"flex items-center gap-1.5",children:Ve&&r.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Ve}`,children:["by ",Ve]})}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[Ps>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ps]}),et.notes&&et.notes.length>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",et.notes.length]}),et.assignedAgentId&&r.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:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${eb[T.find(Je=>Je.id===et.assignedAgentId)?.status??""]??"bg-gray-500"}`}),T.find(Je=>Je.id===et.assignedAgentId)?.name??et.assignedAgentId.slice(0,8)]})]})]})]},et.id)}})})()}),it&&r.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:r.jsx("span",{className:"text-[11px] text-brand-500/50",children:t("work:task.dropHere")})})]},le.id)})})})]}),!o&&Is&&r.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:c.onResizeStart}),(!o||d)&&Is&&r.jsx("div",{className:`${o?"flex-1":"shrink-0"} overflow-hidden min-w-0 border-l border-border-default`,style:o?void 0:{width:c.width},children:$t?r.jsx(GJ,{task:$t,agents:T,projects:h,requirements:A,allTasks:Object.values(j).flat(),users:E,onClose:Ot,onRefresh:Ks,authUser:e,scrollToComments:Or,onScrollToCommentsDone:()=>Xn(!1)}):me?r.jsx(eee,{req:me,agents:T,projects:h,allTasks:Object.values(j).flat(),users:E,onClose:Ot,onApprove:le=>{Ma(le)},onReject:le=>{Ke(le)},onCancel:le=>{En(le),Ot()},onStatusChange:async(le,se)=>{try{await ue.requirements.updateStatus(le,se),fe(`Requirement status → ${se}`),Zr({requirementId:le}),Er(),ft()}catch(be){fe(`Error: ${be}`)}},scrollToComments:Or,onScrollToCommentsDone:()=>Xn(!1),onRefresh:Er,authUser:e,onTaskClick:le=>yn(le),onCreateTask:(le,se)=>{we(le),se&&pe(se),Z(!0)}}):null}),U&&r.jsx(RJ,{orgId:e?.orgId,onCreated:Ua,onClose:()=>L(!1)}),F&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Z(!1),bt("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${o?"w-full":"w-[28rem]"}`,onClick:le=>le.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:t("work:task.newTask")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.titleLabel")}),r.jsx("input",{autoFocus:!o,value:Y,onChange:le=>D(le.target.value),onKeyDown:le=>{le.key==="Enter"&&ps()},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.descriptionField")}),r.jsx("textarea",{value:P,onChange:le=>ee(le.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"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.projectLabel")}),r.jsx(Ld,{options:[{value:"",label:t("work:task.noProject")},...h.map(le=>({value:le.id,label:le.name}))],value:de,onChange:le=>{pe(le),we("")},placeholder:t("work:task.noProject"),noMatchesText:t("work:task.noMatches")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.requirementLabel")}),r.jsx(Ld,{options:[{value:"",label:t("work:task.selectRequirement")},...A.filter(le=>le.status==="in_progress"&&(!de||le.projectId===de)).map(le=>({value:le.id,label:le.title}))],value:te,onChange:we,placeholder:t("work:task.selectRequirement"),noMatchesText:t("work:task.noMatches")})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.assignToRequired")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx(Ld,{options:T.map(le=>({value:le.id,label:`${le.name} (${le.status})`})),value:q,onChange:J,placeholder:t("work:task.selectAgent"),noMatchesText:t("work:task.noMatches")})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.reviewerRequired")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx(Ld,{options:[...E.map(le=>({value:`human:${le.id}`,label:le.name})),...T.filter(le=>le.id!==q).map(le=>({value:`agent:${le.id}`,label:`${le.name} (${le.status})`}))],value:K,onChange:re,placeholder:t("work:task.selectReviewer"),noMatchesText:t("work:task.noMatches")})]})]}),r.jsxs("div",{className:`grid gap-4 ${Ce==="scheduled"?"grid-cols-3":"grid-cols-2"}`,children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.priorityField")}),r.jsxs("select",{value:$,onChange:le=>Q(le.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:[r.jsx("option",{value:"low",children:t("work:priority.low")}),r.jsx("option",{value:"medium",children:t("work:priority.medium")}),r.jsx("option",{value:"high",children:t("work:priority.high")}),r.jsx("option",{value:"urgent",children:t("work:priority.urgent")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.taskType")}),r.jsxs("select",{value:Ce,onChange:le=>Be(le.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:[r.jsx("option",{value:"standard",children:t("work:task.taskTypeStandard")}),r.jsx("option",{value:"scheduled",children:t("work:task.taskTypeScheduled")})]})]}),Ce==="scheduled"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.frequency")}),r.jsxs("select",{value:Qe,onChange:le=>We(le.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:[r.jsx("option",{value:"30m",children:t("work:task.freq30m")}),r.jsx("option",{value:"1h",children:t("work:task.freq1h")}),r.jsx("option",{value:"2h",children:t("work:task.freq2h")}),r.jsx("option",{value:"4h",children:t("work:task.freq4h")}),r.jsx("option",{value:"8h",children:t("work:task.freq8h")}),r.jsx("option",{value:"12h",children:t("work:task.freq12h")}),r.jsx("option",{value:"1d",children:t("work:task.freq1d")}),r.jsx("option",{value:"1w",children:t("work:task.freq1w")})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.blockedBy")}),r.jsx(LJ,{options:Object.values(j).flat().filter(le=>le.status!=="completed"&&le.status!=="cancelled").map(le=>({value:le.id,label:le.title})),selected:ce,onAdd:le=>ge([...ce,le]),placeholder:t("work:task.selectDependency"),noMatchesText:t("work:task.noMatches")}),ce.length>0&&r.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ce.map(le=>{const se=Object.values(j).flat().find(be=>be.id===le);return r.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:[se?se.title.slice(0,30):le.slice(-8),r.jsx("button",{onClick:()=>ge(ce.filter(be=>be!==le)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},le)})})]}),wt&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:wt}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{Z(!1),bt("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:t("common:cancel")}),r.jsx("button",{onClick:()=>{ps()},disabled:!Y.trim()||!q||!K,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:t("common:create")})]})]})}),Dn&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Zt(!1),Bn(""),gr(""),jt("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${o?"w-full":"w-[28rem]"}`,onClick:le=>le.stopPropagation(),children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:t("work:task.newRequirementModalTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:t("work:task.newRequirementModalHint")})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.projectLabel")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx(Ld,{options:h.map(le=>({value:le.id,label:le.name})),value:Cr,onChange:$r,placeholder:t("work:task.selectProject"),noMatchesText:t("work:task.noMatches")})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.titleField")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx("input",{value:Sr,onChange:le=>Bn(le.target.value),placeholder:t("work:task.reqTitleExample"),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:!o,onKeyDown:le=>{le.key==="Enter"&&Sr.trim()&&Xs()}})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[t("work:task.descriptionField")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx("textarea",{value:zr,onChange:le=>gr(le.target.value),placeholder:t("work:task.reqDescPlaceholder"),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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.priorityField")}),r.jsxs("select",{value:sr,onChange:le=>fr(le.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:[r.jsx("option",{value:"low",children:t("work:priority.low")}),r.jsx("option",{value:"medium",children:t("work:priority.medium")}),r.jsx("option",{value:"high",children:t("work:priority.high")}),r.jsx("option",{value:"urgent",children:t("work:priority.urgent")})]})]}),ut&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:ut}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{Zt(!1),Bn(""),gr(""),jt("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:t("common:cancel")}),r.jsx("button",{onClick:()=>{Xs()},disabled:!Sr.trim()||!zr.trim()||!Cr,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:t("common:create")})]})]})}),Ee&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ke(null),Hn("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${o?"w-full":"w-96"}`,onClick:le=>le.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:t("work:task.rejectRequirementTitle")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:t("work:task.rejectReasonLabel")}),r.jsx("textarea",{value:Ae,onChange:le=>ot(le.target.value),placeholder:t("work:task.rejectReasonPlaceholder"),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:!o})]}),er&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:er}),r.jsxs("div",{className:"flex justify-end gap-3",children:[r.jsx("button",{onClick:()=>{Ke(null),Hn("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:t("common:cancel")}),r.jsx("button",{onClick:()=>{ks()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:t("work:task.reject")})]})]})}),wn&&r.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>An(!1),children:[r.jsx("div",{className:"absolute inset-0 bg-black/50"}),r.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:le=>le.stopPropagation(),children:[r.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:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:t("work:task.filtersSheetTitle")}),r.jsxs("div",{className:"flex items-center gap-2",children:[(at.size>0||Re.size>0||Pe)&&r.jsx("button",{onClick:()=>{gt(new Set),ke(new Set),lt(!1)},className:"text-[11px] text-brand-500 font-medium",children:t("work:task.clearAll")}),r.jsx("button",{onClick:()=>An(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),h.length>1&&r.jsxs("div",{className:"px-4 py-3",children:[r.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:t("work:task.projectsFilterGroup")}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:ga.map(le=>{const se=at.has(le.id),be=cr[le.id]??0;return r.jsxs("button",{onClick:()=>Wa(le.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${se?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${se?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:le.name[0]?.toUpperCase()}),le.name,be>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:be})]},le.id)})})]}),e?.id&&r.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:r.jsx("button",{type:"button",onClick:()=>lt(le=>!le),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Pe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:t("work:task.myTasks")})}),T.length>0&&r.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[r.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:t("work:task.agentsFilterGroup")}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:Qs.map(le=>{const se=Re.has(le.id);return r.jsxs("button",{onClick:()=>cs(le.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${se?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${se?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:le.name[0]?.toUpperCase()}),le.name]},le.id)})})]}),r.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function JJ({requirementId:e,createdBy:t,agents:n,users:s,authUser:a}){const{t:o}=ht(["work","common"]),[c,d]=v.useState([]),[u,f]=v.useState([]),h=v.useRef(null);v.useEffect(()=>{ue.requirements.getComments(e).then(k=>d(k.comments)).catch(()=>{})},[e]),v.useEffect(()=>gn.on("requirement:comment",j=>{if(j.payload?.requirementId===e&&j.payload.comment){const S=j.payload.comment;d(T=>T.some(N=>N.id===S.id)?T:[...T,S]),(S.authorType==="agent"||S.authorId?.startsWith("agt_"))&&f(T=>{const N=T.filter(E=>E.id!==S.authorId);return N.length===0&&h.current&&(clearTimeout(h.current),h.current=null),N})}}),[e]);const[p,x]=v.useState(null),b=async(k,j,S,T)=>{let N;S.length>0&&(N=(await ue.uploads.upload(S.map(O=>({dataUrl:O.dataUrl,name:O.name})),"comments")).files.map(O=>({type:"image",url:O.url,name:O.name}))),await ue.requirements.addComment(e,k,a?.name,N,a?.id,j.length>0?j:void 0,T);const E=[],B=new Set,A=H=>{if(B.has(H)||H===a?.id)return;B.add(H);const O=n.find(z=>z.id===H);O&&E.push({id:O.id,name:O.name,avatarUrl:O.avatarUrl})};for(const H of j){const O=n.find(z=>z.name.toLowerCase()===H.toLowerCase());O&&A(O.id)}t?.startsWith("agt_")&&A(t),E.length>0&&(h.current&&clearTimeout(h.current),f(E),h.current=setTimeout(()=>f([]),12e4))},y=v.useCallback(k=>{x({id:k.id,authorName:k.authorName,content:k.content.slice(0,100)})},[]);return r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:c.length>0?o("work:task.commentsWithCount",{count:c.length}):o("work:task.comments")}),r.jsxs("div",{className:"space-y-0.5 mb-3",children:[c.length===0&&r.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:o("work:task.noCommentsYet")}),c.map(k=>r.jsx(Kd,{comment:k,agents:n,onReply:y},k.id)),u.length>0&&r.jsx("div",{className:"flex flex-col gap-1 pt-1",children:u.map(k=>r.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>St.navigate(_e.TEAM,{agentId:k.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(hs,{name:k.name,avatarUrl:k.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),r.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),r.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:k.name}),r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]},k.id))})]}),r.jsx(iN,{agents:n,humans:s,onSubmit:b,replyTo:p,onCancelReply:()=>x(null)})]})}function eee({req:e,agents:t,projects:n,allTasks:s,users:a,onClose:o,onApprove:c,onReject:d,onCancel:u,onStatusChange:f,onRefresh:h,authUser:p,scrollToComments:x,onScrollToCommentsDone:b,onTaskClick:y,onCreateTask:k}){const{t:j}=ht(["work","common"]),S=v.useMemo(()=>m1(j),[j]),T=v.useMemo(()=>c7(j),[j]),N=ws(),[E,B]=v.useState(!1),[A,H]=v.useState(e.description),[O,z]=v.useState(!1),[I,_]=v.useState(!1),X=v.useRef(null);v.useEffect(()=>{if(!x)return;const P=setTimeout(()=>{const ee=X.current;ee&&ee.scrollTo({top:ee.scrollHeight,behavior:"smooth"}),b?.()},300);return()=>clearTimeout(P)},[x,b]);const G=S[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},M=e.source==="agent",U=M&&e.status==="pending",L=e.status==="pending"||e.status==="in_progress",F=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",Z=e.projectId?n.find(P=>P.id===e.projectId):null,Y=Mc(e.createdBy,t,a)??e.createdBy.slice(0,12),D=s.filter(P=>e.taskIds.includes(P.id));return v.useEffect(()=>{H(e.description),B(!1)},[e.id,e.description]),r.jsxs("div",{className:"flex flex-col h-full overflow-hidden bg-surface-secondary",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[N&&r.jsx("button",{onClick:o,className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),r.jsxs("div",{className:"flex-1 min-w-0 pb-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded",children:j("work:task.requirementShort")}),r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${G.cls}`,children:G.label}),e.priority==="high"||e.priority==="urgent"?r.jsx("span",{className:`text-[10px] font-medium ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:e.priority}):r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:e.priority})]}),r.jsx("h2",{className:"text-lg font-semibold text-fg-primary leading-snug",children:e.title})]})]}),!N&&r.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),r.jsxs("div",{ref:X,className:"flex-1 overflow-y-auto p-5 space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:j("work:task.requirementDetailDescription")}),E?r.jsxs("div",{className:"space-y-2",children:[r.jsx("textarea",{value:A,onChange:P=>H(P.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}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{onClick:()=>{B(!1),H(e.description)},className:"px-2.5 py-1 text-xs border border-border-default rounded-lg hover:bg-surface-elevated",children:j("common:cancel")}),r.jsx("button",{onClick:async()=>{z(!0);try{await ue.requirements.update(e.id,{description:A}),B(!1),h?.()}catch{}finally{z(!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:j("common:save")})]})]}):r.jsxs("div",{className:"group relative",children:[e.description?r.jsx(Lr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:j("work:task.requirementNoDescription")}),!F&&r.jsx("button",{onClick:()=>{H(e.description),B(!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:j("common:edit")})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[r.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:j("work:task.createdByLabel")}),r.jsx("span",{className:"text-fg-secondary",children:Y}),M&&r.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:j("work:task.agentTag")})]}),r.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:j("work:task.createdLabel")}),r.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),Z&&r.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:j("work:task.projectLabel")}),r.jsx("span",{className:"text-fg-secondary",children:Z.name})]}),e.approvedBy&&r.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:j("work:task.approvedBy")}),r.jsx("span",{className:"text-fg-secondary",children:Mc(e.approvedBy,t,a)??e.approvedBy.slice(0,12)}),e.approvedAt&&r.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&r.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[r.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:j("work:task.rejectionReason")}),r.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),Array.isArray(e.tags)&&e.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(P=>r.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",P]},P))}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:j("work:task.linkedTasks",{count:D.length})}),!F&&k&&r.jsxs("button",{onClick:()=>k(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[r.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),j("work:requirement.createTask")]})]}),D.length>0?r.jsx("div",{className:"space-y-1.5",children:D.map(P=>{const ee=T[P.status];return r.jsxs("div",{onClick:()=>y?.(P),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${y?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${BJ[P.priority]?.replace("border-l-","bg-")??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:P.title}),ee&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${ee.cls}`,children:ee.label})]},P.id)})}):r.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:j("work:requirement.noLinkedTasks")})]}),r.jsx(JJ,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:a,authUser:p}),r.jsx(f7,{entityType:"requirement",entityId:e.id})]}),r.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[U&&r.jsxs(r.Fragment,{children:[r.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:j("work:requirement.approveRequirement")}),r.jsx("button",{onClick:()=>d(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:j("work:requirement.rejectRequirement")})]}),!U&&f&&!F&&r.jsx("select",{value:e.status,onChange:P=>{P.target.value!==e.status&&f(e.id,P.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:XJ.map(P=>{const ee=S[P],$=P===e.status||(Jx[e.status]?.has(P)??!1);return r.jsx("option",{value:P,disabled:!$,children:ee?.label??P},P)})}),F&&f&&r.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:j("work:task.reopen")}),r.jsx("div",{className:"flex-1"}),L&&!U&&r.jsx("button",{onClick:()=>_(!0),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:j("work:task.cancelRequirement")})]}),I&&r.jsx(cc,{title:j("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:j("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:j("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{_(!1),u(e.id)},onCancel:()=>_(!1)})]})}function f7({entityType:e,entityId:t}){const{t:n}=ht(["work"]),[s,a]=v.useState([]),[o,c]=v.useState(!0),[d,u]=v.useState(!1);if(v.useEffect(()=>{c(!0),(e==="task"?ue.tasks.getHistory:ue.requirements.getHistory)(t).then(b=>a(b.history)).catch(()=>a([])).finally(()=>c(!1))},[e,t]),o)return r.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:n("work:task.loadingHistory","Loading history...")});if(s.length===0)return r.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:n("work:task.noHistory","No status change history.")});const f=d?s:s.slice(-5),h=s.length>5&&!d,p=x=>{const b=x.changedByName||x.changedById||(x.changedByType==="human"?"User":x.changedByType==="agent"?"Agent":"System"),y=x.changedByType==="human"?"bg-blue-500/20 text-blue-500":x.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${y}`,children:b})};return r.jsxs("div",{className:"px-6 py-4",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:n("work:task.statusHistory","Status History")}),h&&r.jsx("button",{onClick:()=>u(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:n("work:task.showAllHistory",{count:s.length})}),r.jsxs("div",{className:"relative ml-2",children:[r.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),r.jsx("div",{className:"space-y-3",children:f.map(x=>r.jsxs("div",{className:"flex items-start gap-3 relative",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:x.changedByType==="human"?"#3b82f6":x.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[p(x),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:x.fromStatus}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:x.toStatus})]}),x.reason&&r.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:x.reason}),r.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(x.createdAt).toLocaleString()})]})]},x.id))})]})]})}function Ja(e){return Array.isArray(e)?e.map(t=>String(t).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function tee(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function tl({label:e,value:t}){return t?r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),r.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:t})]}):null}function sc({label:e,value:t,color:n}){if(!t)return null;const s={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 r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),r.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${s[n]??s.gray} capitalize inline-block`,children:t})]})}function Fg({files:e}){const{t}=ht(["builder","common"]),[n,s]=v.useState(Object.keys(e)[0]??""),a=Object.keys(e);return a.length===0?null:r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("builder:artifact.files",{count:a.length})}),r.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[r.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:a.map(o=>r.jsx("button",{onClick:()=>s(o),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${n===o?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:o},o))}),n&&e[n]!=null&&r.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[n]})]})]})}function nee({artifact:e,mode:t}){const{t:n}=ht(["builder","common"]),s=tee(e),a=e.agent,o=e.team,c=e.dependencies,d=e.displayName??e.name;if(t==="agent"){const u=a?.roleName,f=a?.agentRole,h=a?.llmProvider,p=a?.llmModel,x=Ja(c?.env),b=Ja(c?.skills);return r.jsxs("div",{className:"space-y-3 text-sm",children:[r.jsx(tl,{label:n("builder:artifact.name"),value:d}),r.jsx(tl,{label:n("builder:artifact.description"),value:e.description}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[u&&r.jsx(sc,{label:n("builder:artifact.baseTemplate"),value:u,color:"indigo"}),r.jsx(sc,{label:n("builder:artifact.agentRole"),value:f,color:f==="manager"?"purple":"cyan"})]}),Ja(e.tags).length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:Ja(e.tags).map(y=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:y},y))}),(h||p)&&r.jsxs("div",{className:"flex gap-2",children:[h&&r.jsx(sc,{label:n("builder:artifact.llmProvider"),value:h,color:"gray"}),p&&r.jsx(sc,{label:n("builder:artifact.llmModel"),value:p,color:"gray"})]}),x.length>0&&r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:n("builder:artifact.requiredEnv")}),r.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:x.map(y=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/10 text-amber-600 rounded font-mono",children:y},y))})]}),b.length>0&&r.jsx(tl,{label:n("builder:artifact.skills"),value:b.join(", ")}),s&&r.jsx(Fg,{files:s})]})}if(t==="team"){const f=o?.members??[];return r.jsxs("div",{className:"space-y-3 text-sm",children:[r.jsx(tl,{label:n("builder:artifact.name"),value:d}),r.jsx(tl,{label:n("builder:artifact.description"),value:e.description}),r.jsx("div",{className:"flex flex-wrap gap-2",children:r.jsx(sc,{label:n("builder:artifact.category"),value:e.category,color:"indigo"})}),Ja(e.tags).length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:Ja(e.tags).map(h=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:h},h))}),s&&r.jsx(Fg,{files:s}),r.jsxs("div",{children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:n("builder:artifact.members",{count:f.length})}),r.jsx("div",{className:"mt-1.5 space-y-1.5",children:f.map((h,p)=>r.jsxs("div",{className:"bg-surface-elevated/30 rounded-lg px-2 py-1.5 border border-border-default/20",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`w-5 h-5 rounded flex items-center justify-center text-[10px] font-bold ${h.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:h.role==="manager"?"★":p+1}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:h.name}),typeof h.roleName=="string"&&h.roleName&&r.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:h.roleName}),r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(h.count??1)]})]}),Ja(h.skills).length>0&&r.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:Ja(h.skills).map(x=>r.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:x},x))})]},p))})]})]})}return r.jsxs("div",{className:"space-y-3 text-sm",children:[r.jsx(tl,{label:n("builder:artifact.name"),value:d}),r.jsx(tl,{label:n("builder:artifact.description"),value:e.description}),r.jsx("div",{className:"flex gap-2",children:r.jsx(sc,{label:n("builder:artifact.category"),value:e.category,color:"indigo"})}),s&&r.jsx(Fg,{files:s}),Ja(e.tags).length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:Ja(e.tags).map(u=>r.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:u},u))})]})}const Od={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},bk={active:{color:"text-green-600 bg-green-500/10"},verified:{color:"text-blue-600 bg-blue-500/10"},outdated:{color:"text-red-500 bg-red-500/10"}},yk=["file","directory"];function _d(e){return/^https?:\/\//i.test(e)}const nl={agent:{icon:"✦",color:"bg-brand-500/10 text-brand-500"},team:{icon:"◈",color:"bg-blue-500/10 text-blue-600"},skill:{icon:"⬡",color:"bg-amber-500/10 text-amber-600"}};function vk({authUser:e}={}){const{t}=ht(["deliverables","common"]),n=ws(),s=vm({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[a,o]=v.useState(!1),c=v.useRef(a);c.current=a,v.useEffect(()=>{if(!n)return;const Ae=()=>{c.current&&o(!1)};return window.addEventListener("popstate",Ae),()=>window.removeEventListener("popstate",Ae)},[n]);const d=100,[u,f]=v.useState([]),[h,p]=v.useState(0),[x,b]=v.useState(!1),[y,k]=v.useState([]),[j,S]=v.useState([]),[T,N]=v.useState(!0),[E,B]=v.useState(""),[A,H]=v.useState(""),[O,z]=v.useState(""),[I,_]=v.useState(""),[X,G]=v.useState(""),[M,U]=v.useState(""),[L,F]=v.useState(""),[Z,Y]=v.useState("date"),[D,P]=v.useState(null),[ee,$]=v.useState(null),[Q,q]=v.useState(""),[J,K]=v.useState(!1),[re,de]=v.useState(!1),[pe,te]=v.useState(new Set),we=v.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),ce=v.useCallback(Ae=>{Y(Ae),te(new Set)},[]),ge=Hi(we,Z,ce),Ce=v.useRef(null),[Be,Qe]=v.useState("file"),[We,wt]=v.useState(""),[bt,$t]=v.useState(""),[dt,me]=v.useState(""),[ve,Re]=v.useState(""),[ke,Pe]=v.useState(""),[lt,at]=v.useState(null),[gt,Ft]=v.useState(null),[Bt,tn]=v.useState(!1),[It,Pt]=v.useState(!1),[Nt,cn]=v.useState(!1),[Xt,pn]=v.useState(""),On=v.useRef(void 0),rn=(Ae,ot)=>{$({type:Ae,text:ot}),setTimeout(()=>$(null),3e3)},xn=async Ae=>{await qb(Ae)?(cn(!0),setTimeout(()=>cn(!1),1500)):rn("error",t("detail.copyFailed"))},Gn=v.useMemo(()=>new Map(j.map(Ae=>[Ae.id,Ae])),[j]),wn=v.useMemo(()=>new Map(y.map(Ae=>[Ae.id,Ae])),[y]);v.useEffect(()=>{ue.projects.list().then(Ae=>k(Ae.projects)).catch(()=>{}),ue.agents.list().then(Ae=>S(Ae.agents??[])).catch(()=>{}),ue.system.storage().then(Ae=>pn(Ae.dataDir+"/shared")).catch(()=>{})},[]),v.useEffect(()=>(On.current=setTimeout(()=>H(E),300),()=>clearTimeout(On.current)),[E]);const An=v.useMemo(()=>({q:A||void 0,projectId:I||void 0,agentId:X||void 0,type:O||void 0,status:M||void 0,artifactType:L||void 0}),[A,I,X,O,M,L]),sn=v.useCallback(async()=>{N(!0);try{const{results:Ae,total:ot}=await ue.deliverables.search({...An,offset:0,limit:d});f(Ae),p(ot)}catch{f([]),p(0)}N(!1)},[An]),Pn=v.useCallback(async()=>{if(!(x||u.length>=h)){b(!0);try{const{results:Ae,total:ot}=await ue.deliverables.search({...An,offset:u.length,limit:d});f(ut=>[...ut,...Ae]),p(ot)}catch{}b(!1)}},[An,u.length,h,x]);v.useEffect(()=>{sn()},[sn]),v.useEffect(()=>{const Ae=gn.on("deliverable:created",()=>sn()),ot=gn.on("deliverable:updated",()=>sn()),ut=gn.on("deliverable:removed",()=>sn());return()=>{Ae(),ot(),ut()}},[sn]);const Dn=v.useCallback(()=>{const Ae=Ce.current;!Ae||T||x||u.length>=h||Ae.scrollHeight<=Ae.clientHeight+100&&Pn()},[T,x,u.length,h,Pn]);v.useEffect(()=>{const Ae=Ce.current;if(!Ae)return;const ot=()=>{Ae.scrollTop+Ae.clientHeight>=Ae.scrollHeight-100&&Pn()};return Ae.addEventListener("scroll",ot,{passive:!0}),()=>Ae.removeEventListener("scroll",ot)},[Pn]),v.useEffect(()=>{Dn()},[Dn,pe]);const Zt=v.useMemo(()=>{const Ae=new Map;for(const ut of u){let jt,er;if(Z==="project")jt=ut.projectId??"_none",er=ut.projectId?wn.get(ut.projectId)?.name??ut.projectId:t("noProject");else if(Z==="agent")jt=ut.agentId??"_none",er=ut.agentId?Gn.get(ut.agentId)?.name??ut.agentId:t("common:unknown");else if(Z==="type")jt=ut.type,er=ut.type.charAt(0).toUpperCase()+ut.type.slice(1);else{const Hn=new Date(ut.updatedAt);jt=`${Hn.getFullYear()}-${String(Hn.getMonth()+1).padStart(2,"0")}-${String(Hn.getDate()).padStart(2,"0")}`,er=jt}Ae.has(jt)||Ae.set(jt,{label:er,items:[]}),Ae.get(jt).items.push(ut)}const ot=[...Ae.entries()];return Z==="date"?ot.sort((ut,jt)=>jt[0].localeCompare(ut[0])):ot.sort((ut,jt)=>ut[1].label.localeCompare(jt[1].label)),ot},[u,Z,wn,Gn,t]),Sr=async()=>{if(!(!We.trim()||!bt.trim())){de(!0);try{await ue.deliverables.create({type:Be,title:We,summary:bt,reference:dt,projectId:ve||void 0,tags:ke.split(",").map(Ae=>Ae.trim()).filter(Boolean)}),K(!1),rn("success",t("createModal.created")),sn()}catch(Ae){rn("error",t("common:error",{message:String(Ae)}))}de(!1)}},Bn=async Ae=>{q("verify");try{await ue.deliverables.verify(Ae.id),rn("success",t("common:verified")),P({...Ae,status:"verified"}),sn()}catch(ot){rn("error",t("common:error",{message:String(ot)}))}q("")},zr=async Ae=>{q("flag");try{await ue.deliverables.update(Ae.id,{status:"outdated"}),rn("success",t("flaggedOutdated")),P({...Ae,status:"outdated"}),sn()}catch(ot){rn("error",t("common:error",{message:String(ot)}))}q("")},gr=async Ae=>{q("remove");try{await ue.deliverables.remove(Ae.id),rn("success",t("removed")),P(null),sn()}catch(ot){rn("error",t("common:error",{message:String(ot)}))}q("")},sr=()=>{St.navigate(_e.BUILDER)},fr=async Ae=>{if(Ae.reference&&!_d(Ae.reference)){if(Ae.type==="directory"){Pt(!0);return}tn(!0);try{const ot=await ue.files.preview(Ae.reference);ot.type==="image"&&ot.mimeType?Ft({src:`data:${ot.mimeType};base64,${ot.content}`,name:ot.name}):at(ot.content)}catch{at(null),Ae.type==="file"&&Pt(!0)}tn(!1)}};v.useEffect(()=>{at(null),Ft(null),Pt(!1),D&&fr(D)},[D?.id]);const Cr=v.useCallback(Ae=>{te(ot=>{const ut=new Set(ot);return ut.has(Ae)?ut.delete(Ae):ut.add(Ae),ut})},[]),$r=v.useCallback(()=>{pe.size===Zt.length?te(new Set):te(new Set(Zt.map(([Ae])=>Ae)))},[pe.size,Zt]),Ee=()=>{wt(""),$t(""),me(""),Pe(""),Qe("file"),y.length>0&&Re(y[0].id),K(!0)},Ke=Ae=>{P(Ae),n&&(o(!0),history.pushState({mobileDetail:_e.DELIVERABLES},"",window.location.hash))};return r.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[r.jsxs("div",{className:`${n?"flex-1 min-w-0":"shrink-0"} border-r border-border-default flex flex-col bg-surface-primary`,style:n?a?{display:"none"}:void 0:{width:s.width},children:[r.jsxs("div",{className:"p-4 border-b border-border-default space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary",children:[t("title"),h>0&&r.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",h,")"]})]}),r.jsx("button",{onClick:Ee,className:"text-xs px-2.5 py-1 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:t("create")})]}),r.jsx("input",{value:E,onChange:Ae=>B(Ae.target.value),placeholder:t("searchPlaceholder"),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"}),Xt&&r.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:[r.jsx("span",{className:"truncate font-mono",children:Xt}),r.jsx("button",{onClick:()=>{ue.system.openPath(Xt)},className:"shrink-0 underline hover:text-fg-secondary transition-colors",children:t("common:open")})]}),r.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[r.jsx(jo,{label:t("filters.allTypes"),value:"",current:O||L||"",onClick:()=>{z(""),F("")}}),yk.map(Ae=>r.jsx(jo,{label:`${Od[Ae]?.icon??""} ${Ae}`,value:Ae,current:O,onClick:ot=>{z(ot),F("")}},Ae)),["agent","team","skill"].map(Ae=>r.jsx(jo,{label:`${nl[Ae].icon} ${t(`artifactTypes.${Ae}`)}`,value:Ae,current:L,onClick:ot=>{F(ot),z("")}},Ae))]}),y.length>0&&r.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[r.jsx(jo,{label:t("filters.allProjects"),value:"",current:I,onClick:_}),y.map(Ae=>r.jsx(jo,{label:Ae.name,value:Ae.id,current:I,onClick:_},Ae.id))]}),r.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[r.jsx(jo,{label:t("filters.active"),value:"",current:M,onClick:U}),r.jsx(jo,{label:t("filters.verified"),value:"verified",current:M,onClick:U}),r.jsx(jo,{label:t("filters.outdated"),value:"outdated",current:M,onClick:U})]}),r.jsxs("div",{className:"flex gap-1.5 items-center",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:t("filters.group")}),["date","project","agent","type"].map(Ae=>r.jsx("button",{onClick:()=>{Y(Ae),te(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${Z===Ae?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:t(`groupBy.${Ae}`)},Ae)),Zt.length>1&&r.jsx("button",{onClick:$r,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:pe.size===Zt.length?t("expandAllTooltip"):t("collapseAllTooltip"),children:pe.size===Zt.length?t("expandAll"):t("collapseAll")})]})]}),ee&&r.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${ee.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:ee.text}),r.jsxs("div",{ref:Ce,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:n?ge.onTouchStart:void 0,onTouchEnd:n?ge.onTouchEnd:void 0,children:[T?r.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(Ae=>r.jsxs("div",{className:"animate-pulse space-y-2",children:[r.jsx("div",{className:"h-4 bg-surface-elevated rounded w-3/4"}),r.jsx("div",{className:"h-3 bg-surface-elevated rounded w-1/2"})]},Ae))}):u.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[r.jsx("svg",{className:"w-12 h-12 text-fg-muted mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:r.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"})}),r.jsx("p",{className:"text-sm text-fg-secondary",children:t("empty.title")}),r.jsx("p",{className:"text-xs text-fg-tertiary mt-1 mb-3",children:t("empty.subtitle")}),r.jsx("button",{onClick:Ee,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:t("empty.createFirst")})]}):Zt.map(([Ae,ot])=>{const ut=pe.has(Ae);return r.jsxs("div",{children:[r.jsxs("button",{onClick:()=>Cr(Ae),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:[r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform duration-200 shrink-0 ${ut?"":"rotate-90"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),r.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider truncate",children:ot.label}),r.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",ot.items.length,")"]})]}),!ut&&ot.items.map(jt=>r.jsxs("button",{onClick:()=>Ke(jt),className:`w-full text-left p-3 rounded-lg transition-colors ${D?.id===jt.id?"bg-brand-600/20 border border-brand-500/30":"hover:bg-surface-elevated/60 border border-transparent"}`,children:[r.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:jt.title}),r.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[jt.artifactType&&nl[jt.artifactType]?r.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${nl[jt.artifactType].color}`,children:[nl[jt.artifactType].icon," ",t(`artifactTypes.${jt.artifactType}`)]}):r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium uppercase ${Od[jt.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:jt.type}),r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${bk[jt.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:t(`common:status.${jt.status}`,{defaultValue:jt.status})}),jt.agentId&&r.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:Gn.get(jt.agentId)?.name??t("groupBy.agent")})]})]},jt.id))]},Ae)}),x&&r.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[r.jsx(Ug,{})," ",r.jsx("span",{className:"text-[10px]",children:t("common:loadingMore")})]}),!T&&u.length>0&&r.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:u.length<h?t("count.partial",{loaded:u.length,total:h}):t("count.total",{total:h})})]})]}),!n&&r.jsx("div",{className:"w-1 shrink-0 cursor-col-resize hover:bg-brand-500/30 active:bg-brand-500/50 transition-colors",onMouseDown:s.onResizeStart}),(!n||a)&&r.jsxs("div",{className:"flex-1 overflow-y-auto min-w-0",children:[n&&r.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:[r.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),r.jsx("span",{className:"text-sm font-medium truncate",children:D?.title??t("detail.details")})]}),D?r.jsxs("div",{className:"p-6 space-y-5",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-xl font-semibold text-fg-primary",children:D.title}),r.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[D.status!=="verified"&&r.jsx("button",{onClick:()=>Bn(D),disabled:!!Q,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:t(Q==="verify"?"common:verifying":"detail.verify")}),D.status!=="outdated"&&r.jsx("button",{onClick:()=>zr(D),disabled:!!Q,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:t(Q==="flag"?"detail.flagging":"detail.flagOutdated")}),r.jsx("button",{onClick:()=>gr(D),disabled:!!Q,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:t(Q==="remove"?"common:removing":"common:remove")})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-2 flex-wrap",children:[r.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium uppercase ${Od[D.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[Od[D.type]?.icon??""," ",D.type]}),r.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${bk[D.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:t(`common:status.${D.status}`,{defaultValue:D.status})}),D.artifactType&&nl[D.artifactType]&&r.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${nl[D.artifactType].color}`,children:[nl[D.artifactType].icon," ",t("detail.builderWithType",{type:t(`artifactTypes.${D.artifactType}`)})]})]}),D.reference&&_d(D.reference)&&r.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:[r.jsx("a",{href:D.reference,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-brand-500 hover:text-brand-500 hover:underline truncate flex-1 text-left cursor-pointer",children:D.reference}),r.jsx("button",{onClick:()=>window.open(D.reference,"_blank","noopener,noreferrer"),className:"px-2 py-1 text-[10px] rounded bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",children:t("common:open")}),r.jsx("button",{onClick:()=>xn(D.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Nt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:t(Nt?"common:copied":"common:copy")})]}),D.reference&&!_d(D.reference)&&(D.type==="file"||D.type==="directory")&&r.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:[r.jsx("button",{onClick:()=>{ue.files.reveal(D.reference).catch(()=>rn("error",t("detail.failedToOpenBrowser")))},className:"text-xs font-mono text-brand-500 hover:text-brand-500 hover:underline truncate flex-1 text-left cursor-pointer",title:t("detail.openInFileBrowser"),children:D.reference}),r.jsx("button",{onClick:()=>{ue.files.reveal(D.reference).catch(()=>rn("error",t("detail.failedToOpenBrowser")))},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:t("detail.revealInFinder"),children:t("common:open")}),r.jsx("button",{onClick:()=>xn(D.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Nt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:t("detail.copyPath"),children:t(Nt?"common:copied":"common:copy")})]}),D.reference&&!_d(D.reference)&&D.type!=="file"&&D.type!=="directory"&&r.jsx("div",{className:"mt-2",children:r.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:D.reference})})]}),D.artifactType&&D.artifactData?r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:r.jsx(nee,{artifact:D.artifactData,mode:D.artifactType})}),D.reference&&r.jsxs("div",{className:"px-3 py-2 bg-surface-secondary/50 border border-border-default rounded-lg",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider block mb-1",children:t("detail.artifactDirectory")}),r.jsx("span",{className:"text-xs text-fg-secondary font-mono break-all",children:D.reference})]}),r.jsx("div",{className:"flex gap-2",children:r.jsx("button",{onClick:sr,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:t("detail.openInBuilder")})}),D.summary&&r.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:r.jsx(Lr,{content:D.summary,className:"text-fg-secondary text-sm"})})]}):r.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:Bt?r.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[r.jsx(Ug,{})," ",t("detail.loadingPreview")]}):gt?r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("img",{src:gt.src,alt:gt.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),r.jsx("span",{className:"text-xs text-fg-tertiary",children:gt.name})]}):lt?r.jsx(Lr,{content:lt,className:"text-fg-secondary text-sm"}):It?r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-fg-secondary",children:t("detail.cannotPreview",{type:D.type})}),r.jsxs("div",{className:"flex items-center gap-2",children:[_d(D.reference)?r.jsxs(r.Fragment,{children:[r.jsx("a",{href:D.reference,target:"_blank",rel:"noopener noreferrer",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",children:D.reference}),r.jsx("button",{onClick:()=>window.open(D.reference,"_blank","noopener,noreferrer"),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:t("common:open")})]}):r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{ue.files.reveal(D.reference).catch(()=>rn("error",t("detail.failedToOpen")))},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:t("detail.openInFileBrowser"),children:D.reference}),r.jsx("button",{onClick:()=>{ue.files.reveal(D.reference).catch(()=>rn("error",t("detail.failedToOpen")))},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:t("common:open")})]}),r.jsx("button",{onClick:()=>xn(D.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Nt?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:t(Nt?"common:copied":"common:copy")})]})]}):D.summary?r.jsx(Lr,{content:D.summary,className:"text-fg-secondary text-sm"}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:t("detail.noContent")})}),(D.diffStats||D.testResults)&&r.jsxs("div",{className:"flex gap-4 flex-wrap",children:[D.diffStats&&r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-lg px-4 py-3 text-xs space-y-1",children:[r.jsx("div",{className:"text-fg-tertiary font-medium",children:t("diffStats.title")}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx("span",{className:"text-fg-secondary",children:t("diffStats.files",{count:D.diffStats.filesChanged})}),r.jsxs("span",{className:"text-green-600",children:["+",D.diffStats.additions]}),r.jsxs("span",{className:"text-red-500",children:["-",D.diffStats.deletions]})]})]}),D.testResults&&r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-lg px-4 py-3 text-xs space-y-1",children:[r.jsx("div",{className:"text-fg-tertiary font-medium",children:t("testResults.title")}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx("span",{className:"text-green-600",children:t("testResults.passed",{count:D.testResults.passed})}),r.jsx("span",{className:"text-red-500",children:t("testResults.failed",{count:D.testResults.failed})}),r.jsx("span",{className:"text-fg-secondary",children:t("testResults.skipped",{count:D.testResults.skipped})})]})]})]}),D.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5",children:D.tags.map(Ae=>r.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:Ae},Ae))}),r.jsxs("div",{className:"border-t border-border-default pt-4 space-y-2",children:[r.jsx("div",{className:"text-xs text-fg-tertiary font-medium",children:t("links.title")}),r.jsxs("div",{className:"flex gap-3 flex-wrap",children:[D.taskId&&r.jsx("button",{onClick:()=>St.navigate(_e.WORK,{openTask:D.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2.5 py-1 rounded",children:t("links.task",{id:`${D.taskId.slice(0,12)}...`})}),D.agentId&&r.jsx("button",{onClick:()=>St.navigate(_e.TEAM,{selectAgent:D.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:t("links.agent",{name:Gn.get(D.agentId)?.name??D.agentId.slice(0,12)})}),D.projectId&&r.jsx("button",{onClick:()=>St.navigate(_e.WORK,{projectId:D.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2.5 py-1 rounded",children:t("links.project",{name:wn.get(D.projectId)?.name??D.projectId.slice(0,12)})})]})]}),r.jsxs("div",{className:"text-xs text-fg-tertiary space-y-1 border-t border-border-default pt-4",children:[r.jsxs("div",{className:"flex gap-6 flex-wrap",children:[r.jsxs("span",{children:[t("metadata.created")," ",r.jsx("span",{className:"text-fg-secondary",children:new Date(D.createdAt).toLocaleString()})]}),r.jsxs("span",{children:[t("metadata.updated")," ",r.jsx("span",{className:"text-fg-secondary",children:new Date(D.updatedAt).toLocaleString()})]})]}),r.jsx("div",{className:"text-fg-muted select-all",children:t("metadata.id",{id:D.id})})]})]}):r.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:r.jsxs("div",{className:"text-center text-fg-tertiary space-y-2",children:[r.jsx("svg",{className:"w-12 h-12 mx-auto text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:r.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"})}),r.jsx("p",{className:"text-sm",children:t("detail.selectToView")})]})})]}),J&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!re&&K(!1),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:Ae=>Ae.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:t("createModal.title")}),r.jsxs("div",{children:[r.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:t("createModal.type")}),r.jsx("select",{value:Be,onChange:Ae=>Qe(Ae.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:yk.map(Ae=>r.jsxs("option",{value:Ae,children:[Od[Ae]?.icon??""," ",Ae]},Ae))})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[t("createModal.titleField")," ",r.jsx("span",{className:"text-red-500",children:t("createModal.required")})]}),r.jsx("input",{value:We,onChange:Ae=>wt(Ae.target.value),placeholder:t("createModal.titlePlaceholder"),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"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[t("createModal.reference")," ",r.jsxs("span",{className:"text-fg-tertiary",children:["(",t("createModal.referenceHint"),")"]})]}),r.jsx("input",{value:dt,onChange:Ae=>me(Ae.target.value),placeholder:t("createModal.referencePlaceholder"),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"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[t("createModal.summary")," ",r.jsx("span",{className:"text-red-500",children:t("createModal.required")})," ",r.jsxs("span",{className:"text-fg-tertiary",children:["(",t("createModal.summaryHint"),")"]})]}),r.jsx("textarea",{value:bt,onChange:Ae=>$t(Ae.target.value),placeholder:t("createModal.summaryPlaceholder"),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"})]}),r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("div",{className:"flex-1",children:[r.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[t("createModal.tags")," ",r.jsxs("span",{className:"text-fg-tertiary",children:["(",t("createModal.tagsHint"),")"]})]}),r.jsx("input",{value:ke,onChange:Ae=>Pe(Ae.target.value),placeholder:t("createModal.tagsPlaceholder"),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"})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:t("createModal.project")}),r.jsxs("select",{value:ve,onChange:Ae=>Re(Ae.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:[r.jsx("option",{value:"",children:t("common:none")}),y.map(Ae=>r.jsx("option",{value:Ae.id,children:Ae.name},Ae.id))]})]})]}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1 border-t border-border-default",children:[r.jsx("button",{onClick:()=>K(!1),disabled:re,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:t("common:cancel")}),r.jsxs("button",{onClick:Sr,disabled:re||!We.trim()||!bt.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:[re&&r.jsx(Ug,{}),t(re?"common:creating":"common:create")]})]})]})})]})}function jo({label:e,value:t,current:n,onClick:s}){return r.jsx("button",{onClick:()=>s(n===t?"":t),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${n===t?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function Ug(){return r.jsxs("svg",{className:"animate-spin h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function Oi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function oc(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function ree(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 m7({authUser:e}){const{t}=ht(["reports","common"]),[n,s]=v.useState("weekly"),[a,o]=v.useState(null),[c,d]=v.useState(!0),[u,f]=v.useState(""),[h,p]=v.useState(null),[x,b]=v.useState([]),[y,k]=v.useState("totalTokens"),[j,S]=v.useState(!0),[T,N]=v.useState("generate"),[E,B]=v.useState([]),[A,H]=v.useState(null),[O,z]=v.useState([]),[I,_]=v.useState(""),[X,G]=v.useState(""),M=q=>{G(q),setTimeout(()=>G(""),3e3)},U=v.useCallback(async q=>{d(!0),f("");try{const{report:J}=await ue.reports.generate({period:q,scope:"org",orgId:"default"});o(J)}catch(J){f(String(J)),o(null)}d(!1)},[]),L=v.useCallback(()=>{ue.usage.summary().then(q=>p(q.usage)).catch(()=>{}),ue.usage.agents().then(q=>b(q.agents)).catch(()=>{})},[]),F=v.useCallback(async()=>{try{const{reports:q}=await ue.reports.list();B(q)}catch{}},[]),Z=v.useCallback(async q=>{H(q);try{const{feedback:J}=await ue.reports.getFeedback(q.id);z(J)}catch{z([])}},[]);v.useEffect(()=>{U(n)},[n,U]),v.useEffect(()=>{L();const q=setInterval(L,3e4);return()=>clearInterval(q)},[L]),v.useEffect(()=>{T==="history"&&F()},[T,F]);const Y=v.useMemo(()=>[...x].sort((q,J)=>{const K=q[y],re=J[y];return j?re-K:K-re}),[x,y,j]),D=x.reduce((q,J)=>q+J.estimatedCost,0),P=x.reduce((q,J)=>q+J.tokensUsedToday,0),ee=Math.max(1,...x.map(q=>q.totalTokens)),$=q=>{y===q?S(!j):(k(q),S(!0))},Q=v.useMemo(()=>({daily:t("period.today"),weekly:t("period.thisWeek"),monthly:t("period.thisMonth")}),[t]);return r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsxs("div",{className:"max-w-5xl p-6 space-y-6",children:[r.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[r.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[r.jsx("h1",{className:"text-xl font-semibold text-fg-primary",children:t("title")}),r.jsxs("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:[r.jsx("button",{onClick:()=>N("generate"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${T==="generate"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("tabs.generate")}),r.jsxs("button",{onClick:()=>N("history"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${T==="history"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:[t("tabs.history"),E.length>0?` (${E.length})`:""]})]})]}),r.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[X&&r.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:X}),T==="generate"&&r.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(q=>r.jsx("button",{onClick:()=>s(q),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${n===q?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t(`period.${q}`)},q))})]})]}),T==="history"&&!A&&r.jsx("section",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden",children:E.length===0?r.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:t("noReportsYet")}):r.jsx("div",{className:"divide-y divide-border-default/50",children:E.map(q=>r.jsxs("button",{onClick:()=>Z(q),className:"w-full text-left px-5 py-3 flex items-center gap-4 hover:bg-surface-elevated/30 transition-colors",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("reportType",{type:q.type})}),r.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(q.periodStart).toLocaleDateString()," — ",new Date(q.periodEnd).toLocaleDateString()]})]}),q.plan&&r.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${q.plan.status==="approved"?"bg-green-500/10 text-green-600":q.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:q.plan.status==="pending"?t("upcomingPlan.planPending"):t("upcomingPlan.planStatus",{status:q.plan.status})}),r.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(q.generatedAt).toLocaleDateString()})]},q.id))})}),T==="history"&&A&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:()=>{H(null),z([])},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:t("backToList")}),r.jsx("span",{className:"text-sm font-medium text-fg-primary",children:t("reportType",{type:A.type})}),r.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(A.periodStart).toLocaleDateString()," — ",new Date(A.periodEnd).toLocaleDateString()]})]}),A.metrics&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskMetrics.title")}),r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[r.jsx(ei,{label:t("taskMetrics.completed"),value:A.metrics.tasksCompleted,color:"text-green-600"}),r.jsx(ei,{label:t("taskMetrics.inProgress"),value:A.metrics.tasksInProgress,color:"text-brand-500"}),r.jsx(ei,{label:t("taskMetrics.created"),value:A.metrics.tasksCreated,color:"text-blue-600"}),r.jsx(ei,{label:t("taskMetrics.blocked"),value:A.metrics.tasksBlocked,color:"text-amber-600"}),r.jsx(ei,{label:t("taskMetrics.failed"),value:A.metrics.tasksFailed,color:"text-red-500"})]})]}),A.costSummary&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("costOverview.title")}),r.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:[r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:A.costSummary.totalTokens.toLocaleString()}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.totalTokens")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:oc(A.costSummary.totalEstimatedCost)}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.estimatedCost")})]}),r.jsxs("div",{children:[r.jsxs("div",{className:`text-2xl font-bold ${A.costSummary.trend==="decreasing"?"text-green-600":A.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[A.costSummary.trend==="decreasing"?"↓":A.costSummary.trend==="increasing"?"↑":"→"," ",A.costSummary.trend]}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.trend")})]})]}),A.costSummary.byAgent&&A.costSummary.byAgent.length>0&&r.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:A.costSummary.byAgent.map((q,J)=>r.jsxs("div",{className:"flex items-center justify-between text-xs",children:[r.jsx("span",{className:"text-fg-secondary",children:q.agentId}),r.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t("costOverview.byAgentRow",{tokens:Oi(q.tokens),cost:oc(q.cost)})})]},J))})]}),A.taskSummary&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 overflow-hidden",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskSummary.title")}),r.jsxs("div",{className:"space-y-4 min-w-0",children:[A.taskSummary.completed.length>0&&r.jsx(ac,{title:t("taskSummary.completedCount",{count:A.taskSummary.completed.length}),color:"emerald",items:A.taskSummary.completed.map(q=>({id:q.id,label:q.title,sub:q.agent}))}),A.taskSummary.inProgress.length>0&&r.jsx(ac,{title:t("taskSummary.inProgressCount",{count:A.taskSummary.inProgress.length}),color:"indigo",items:A.taskSummary.inProgress.map(q=>({id:q.id,label:q.title,sub:q.agent}))}),A.taskSummary.blocked.length>0&&r.jsx(ac,{title:t("taskSummary.blockedCount",{count:A.taskSummary.blocked.length}),color:"amber",items:A.taskSummary.blocked.map(q=>({id:q.id,label:q.title,sub:q.reason||q.agent}))}),A.taskSummary.completed.length===0&&A.taskSummary.inProgress.length===0&&A.taskSummary.blocked.length===0&&r.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]}),A.highlights&&A.highlights.length>0&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-2",children:t("highlights")}),r.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:A.highlights.map((q,J)=>r.jsx("li",{children:q},J))})]}),A.blockers&&A.blockers.length>0&&r.jsxs("section",{className:"bg-surface-secondary border border-amber-500/20 rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-amber-600 mb-2",children:t("blockers")}),r.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:A.blockers.map((q,J)=>r.jsx("li",{children:q},J))})]}),A.plan&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("h3",{className:"text-xs font-semibold text-fg-secondary",children:[t("upcomingPlan.title"),r.jsx("span",{className:`ml-2 px-1.5 py-0.5 rounded text-[10px] font-medium ${A.plan.status==="approved"?"bg-green-500/10 text-green-600":A.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:t(`common:status.${A.plan.status}`,{defaultValue:A.plan.status})})]}),A.plan.status==="pending"&&r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:async()=>{try{const{report:q}=await ue.reports.approvePlan(A.id,{approvedBy:e?.id??"unknown"});H(q),M(t("upcomingPlan.planApproved")),F()}catch(q){M(t("common:error",{message:String(q)}))}},className:"px-3 py-1.5 text-xs font-medium bg-green-600 text-white rounded-lg hover:bg-green-500 transition-colors",children:t("upcomingPlan.approvePlan")}),r.jsx("button",{onClick:async()=>{const q=prompt(t("upcomingPlan.rejectionReason"));if(q)try{const{report:J}=await ue.reports.rejectPlan(A.id,{rejectedBy:e?.id??"unknown",reason:q});H(J),M(t("upcomingPlan.planRejected")),F()}catch(J){M(t("common:error",{message:String(J)}))}},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:t("upcomingPlan.rejectPlan")})]})]}),A.plan.items&&A.plan.items.length>0&&r.jsx("div",{className:"space-y-1.5",children:A.plan.items.map((q,J)=>r.jsxs("div",{className:"flex items-center gap-2 text-sm text-fg-secondary",children:[r.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${q.priority==="high"?"bg-red-500/10 text-red-500":q.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:q.priority}),r.jsx("span",{children:q.title}),q.assignee&&r.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:q.assignee})]},J))})]}),!A.metrics&&!A.taskSummary&&!A.costSummary&&r.jsx("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-8 text-center",children:r.jsx("p",{className:"text-sm text-fg-tertiary",children:t("noDetailedMetrics")})}),r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("feedback.title",{count:O.length})}),O.length>0&&r.jsx("div",{className:"space-y-2 mb-4",children:O.map(q=>r.jsxs("div",{className:"p-3 bg-surface-elevated/50 rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary mb-1",children:[r.jsx("span",{className:"font-medium text-fg-secondary",children:q.authorName}),r.jsx("span",{children:q.type}),r.jsx("span",{children:new Date(q.createdAt).toLocaleDateString()})]}),r.jsx("p",{className:"text-xs text-fg-secondary",children:q.content})]},q.id))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:I,onChange:q=>_(q.target.value),placeholder:t("feedback.placeholder"),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:q=>{q.key==="Enter"&&I.trim()&&ue.reports.addFeedback(A.id,{author:e?.id??"unknown",type:"comment",content:I.trim()}).then(({feedback:J})=>{z(K=>[...K,J]),_(""),M(t("feedback.added"))}).catch(J=>M(t("common:error",{message:String(J)})))}}),r.jsx("button",{onClick:()=>{I.trim()&&ue.reports.addFeedback(A.id,{author:e?.id??"unknown",type:"comment",content:I.trim()}).then(({feedback:q})=>{z(J=>[...J,q]),_(""),M(t("feedback.added"))}).catch(q=>M(t("common:error",{message:String(q)})))},disabled:!I.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:t("common:send")})]})]})]}),T==="generate"&&h&&r.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[r.jsx(lf,{label:t("usage.llmTokens"),value:Oi(h.llmTokens),color:"text-brand-500"}),r.jsx(lf,{label:t("usage.toolCalls"),value:Oi(h.toolCalls),color:"text-blue-600"}),r.jsx(lf,{label:t("usage.messages"),value:Oi(h.messages),color:"text-green-600"}),r.jsx(lf,{label:t("usage.storage"),value:ree(h.storageBytes),color:"text-amber-600"})]}),T==="generate"&&(c?r.jsx("div",{className:"flex items-center justify-center h-32 text-fg-tertiary text-sm",children:t("common:loading")}):u?r.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:u}):a?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"text-xs text-fg-tertiary",children:[Q[n]," · ",new Date(a.periodStart).toLocaleDateString()," — ",new Date(a.periodEnd).toLocaleDateString()]}),a.metrics&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskMetrics.title")}),r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[r.jsx(ei,{label:t("taskMetrics.completed"),value:a.metrics.tasksCompleted,color:"text-green-600"}),r.jsx(ei,{label:t("taskMetrics.inProgress"),value:a.metrics.tasksInProgress,color:"text-brand-500"}),r.jsx(ei,{label:t("taskMetrics.created"),value:a.metrics.tasksCreated,color:"text-blue-600"}),r.jsx(ei,{label:t("taskMetrics.blocked"),value:a.metrics.tasksBlocked,color:"text-amber-600"}),r.jsx(ei,{label:t("taskMetrics.failed"),value:a.metrics.tasksFailed,color:"text-red-500"})]})]}),r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("costOverview.title")}),r.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:oc(D)}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.estCostAllTime")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:Oi(P)}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.tokensToday")})]}),a.costSummary&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:a.costSummary.totalTokens.toLocaleString()}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.tokensPeriod",{period:Q[n]})})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:oc(a.costSummary.totalEstimatedCost)}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.costPeriod",{period:Q[n]})})]})]})]})]}),a.taskSummary&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskSummary.title")}),r.jsxs("div",{className:"space-y-4",children:[a.taskSummary.completed.length>0&&r.jsx(ac,{title:t("taskSummary.completedCount",{count:a.taskSummary.completed.length}),color:"emerald",items:a.taskSummary.completed.map(q=>({id:q.id,label:q.title,sub:q.agent}))}),a.taskSummary.inProgress.length>0&&r.jsx(ac,{title:t("taskSummary.inProgressCount",{count:a.taskSummary.inProgress.length}),color:"indigo",items:a.taskSummary.inProgress.map(q=>({id:q.id,label:q.title,sub:q.agent}))}),a.taskSummary.blocked.length>0&&r.jsx(ac,{title:t("taskSummary.blockedCount",{count:a.taskSummary.blocked.length}),color:"amber",items:a.taskSummary.blocked.map(q=>({id:q.id,label:q.title,sub:q.reason||q.agent}))}),a.taskSummary.completed.length===0&&a.taskSummary.inProgress.length===0&&a.taskSummary.blocked.length===0&&r.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]})]}):null),T==="generate"&&r.jsxs("section",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden",children:[r.jsx("div",{className:"px-5 py-4 border-b border-border-default",children:r.jsx("h3",{className:"text-sm font-semibold text-fg-secondary",children:t("perAgentUsage.title")})}),x.length===0?r.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:t("perAgentUsage.noData")}):r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"border-b border-border-default text-xs text-fg-tertiary uppercase tracking-wider",children:[r.jsx("th",{className:"px-4 py-3 text-left font-medium",children:t("perAgentUsage.agent")}),r.jsx(Id,{label:t("perAgentUsage.totalTokens"),col:"totalTokens",current:y,desc:j,onSort:$}),r.jsx(Id,{label:t("perAgentUsage.today"),col:"tokensUsedToday",current:y,desc:j,onSort:$}),r.jsx(Id,{label:t("perAgentUsage.requests"),col:"requestCount",current:y,desc:j,onSort:$}),r.jsx(Id,{label:t("perAgentUsage.toolCalls"),col:"toolCalls",current:y,desc:j,onSort:$}),r.jsx(Id,{label:t("perAgentUsage.estCost"),col:"estimatedCost",current:y,desc:j,onSort:$,align:"right"})]})}),r.jsx("tbody",{children:Y.map(q=>r.jsx(see,{agent:q,maxTokens:ee},q.agentId))}),r.jsx("tfoot",{children:r.jsxs("tr",{className:"border-t border-border-default bg-surface-elevated/30",children:[r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary",children:t("perAgentUsage.totalAgents",{count:x.length})}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Oi(x.reduce((q,J)=>q+J.totalTokens,0))}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:Oi(P)}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:x.reduce((q,J)=>q+J.requestCount,0)}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:x.reduce((q,J)=>q+J.toolCalls,0)}),r.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:oc(D)})]})})]})})]})]})})}function ei({label:e,value:t,color:n}){return r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:`text-2xl font-bold ${n}`,children:t}),r.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function ac({title:e,color:t,items:n}){return r.jsxs("div",{className:"min-w-0 overflow-hidden",children:[r.jsx("div",{className:`text-xs font-medium text-${t}-400 mb-1.5`,children:e}),r.jsx("div",{className:"space-y-1.5",children:n.map((s,a)=>r.jsxs("div",{className:`text-sm text-fg-secondary min-w-0 ${s.id?"cursor-pointer hover:text-fg-primary group":""}`,onClick:s.id?()=>St.navigate(_e.WORK,{openTask:s.id}):void 0,children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${t}-500 shrink-0`}),r.jsx("span",{className:`truncate min-w-0 ${s.id?"group-hover:text-brand-500 transition-colors":""}`,children:s.label})]}),s.sub&&s.sub!=="unassigned"&&r.jsx("div",{className:"text-[10px] text-fg-tertiary ml-3.5 mt-0.5 break-all line-clamp-2",children:s.sub})]},s.id??a))})]})}function lf({label:e,value:t,color:n}){return r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:[r.jsx("div",{className:"text-sm text-fg-secondary mb-2",children:e}),r.jsx("div",{className:`text-2xl font-bold ${n}`,children:t})]})}function Id({label:e,col:t,current:n,desc:s,onSort:a,align:o}){const c=n===t?s?"↓":"↑":"↕",d=n===t?"text-brand-500":"text-fg-muted";return r.jsxs("th",{className:`px-4 py-3 ${o==="right"?"text-right":"text-left"} font-medium cursor-pointer select-none hover:text-fg-secondary`,onClick:()=>a(t),children:[e,r.jsx("span",{className:`ml-1 ${d}`,children:c})]})}function see({agent:e,maxTokens:t}){const n=t>0?Math.min(100,e.totalTokens/t*100):0,s=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 r.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>St.navigate(_e.TEAM,{selectAgent:e.agentId}),children:[r.jsx("td",{className:"px-4 py-3",children:r.jsxs("div",{className:"flex items-center gap-2.5",children:[r.jsx("div",{className:`w-2 h-2 rounded-full ${s}`}),r.jsxs("div",{children:[r.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),r.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),r.jsx("td",{className:"px-4 py-3",children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:r.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${n}%`}})}),r.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:Oi(e.totalTokens)})]})}),r.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:Oi(e.tokensUsedToday)}),r.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.requestCount}),r.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.toolCalls}),r.jsx("td",{className:"px-4 py-3 text-sm text-right text-fg-secondary tabular-nums",children:oc(e.estimatedCost)})]})}function aee({d:e,size:t=18}){return r.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:r.jsx("path",{d:e})})}function iee({authUser:e,onClose:t,onSaved:n}){const{t:s}=ht("common"),[a,o]=v.useState(e.name||""),[c,d]=v.useState(e.email||""),[u,f]=v.useState(!1),[h,p]=v.useState(""),[x,b]=v.useState(e.avatarUrl),y=async k=>{if(k.preventDefault(),!a.trim()){p(s("profile.nameRequired"));return}if(c&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c.trim())){p(s("profile.invalidEmail"));return}f(!0),p("");try{const{user:j}=await ue.auth.updateProfile(a.trim(),c.trim());n({...j,avatarUrl:x??j.avatarUrl})}catch{p(s("profile.failedToSave"))}finally{f(!1)}};return r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50",onClick:t,children:r.jsxs("form",{onSubmit:y,className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[400px] shadow-2xl",onClick:k=>k.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold mb-5",children:s("profile.editProfile")}),r.jsx("div",{className:"flex justify-center mb-5",children:r.jsx(Vb,{currentUrl:x,name:a,size:72,targetType:"user",targetId:e.id,onUploaded:k=>b(k)})}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.name")}),r.jsx("input",{value:a,onChange:k=>o(k.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.email")}),r.jsx("input",{value:c,onChange:k=>d(k.target.value),type:"email",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"})]}),h&&r.jsx("div",{className:"text-xs text-red-500 bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2",children:h})]}),r.jsxs("div",{className:"flex justify-end gap-3 mt-5",children:[r.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated",children:s("cancel")}),r.jsx("button",{type:"submit",disabled:u,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white rounded-lg",children:s(u?"saving":"save")})]})]})})}function oee({authUser:e,collapsed:t,onLogout:n,onUserUpdated:s}){const{t:a}=ht(["nav","common"]),[o,c]=v.useState(!1),[d,u]=v.useState(!1),f=v.useRef(null);if(v.useEffect(()=>{if(!o)return;const x=b=>{f.current&&!f.current.contains(b.target)&&c(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[o]),!e)return null;const h=e.name||a("common:userPlaceholder"),p=e.email||e.role?.[0]?.toUpperCase()+e.role?.slice(1);return r.jsxs(r.Fragment,{children:[r.jsxs("div",{ref:f,className:`relative ${t?"p-2 flex flex-col items-center":"px-4 py-3"}`,children:[r.jsxs("button",{onClick:()=>c(!o),className:`${t?"hover:ring-2 hover:ring-brand-500/50 transition-all rounded-full":"w-full flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-surface-overlay transition-colors"}`,title:t?`${h} — ${p}`:void 0,children:[r.jsx(hs,{name:h,avatarUrl:e.avatarUrl,size:28}),!t&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[r.jsx("div",{className:"text-xs text-fg-secondary truncate",children:h}),r.jsx("div",{className:"text-[11px] text-fg-tertiary truncate",children:p})]}),r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:r.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]}),o&&r.jsxs("div",{className:`absolute ${t?"left-full bottom-0 ml-2":"left-4 right-4 bottom-full mb-1"} bg-surface-secondary border border-border-default rounded-xl shadow-xl z-50 overflow-hidden`,style:t?{minWidth:200}:void 0,children:[r.jsxs("div",{className:"px-4 py-3 border-b border-border-default",children:[r.jsx("div",{className:"text-sm font-medium text-fg-primary",children:h}),r.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:p}),r.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 capitalize",children:e.role})]}),r.jsxs("div",{className:"py-1",children:[r.jsxs("button",{onClick:()=>{c(!1),u(!0)},className:"w-full flex items-center gap-2.5 px-4 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),r.jsx("circle",{cx:"12",cy:"7",r:"4"})]}),a("common:profile.editProfile")]}),r.jsxs("button",{onClick:()=>{c(!1),n()},className:"w-full flex items-center gap-2.5 px-4 py-2 text-sm text-red-500 hover:bg-red-500/10 transition-colors",children:[r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),r.jsx("polyline",{points:"16 17 21 12 16 7"}),r.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]}),a("sidebar.signOut")]})]})]})]}),d&&r.jsx(iee,{authUser:e,onClose:()=>u(!1),onSaved:x=>{u(!1),s?.(x)}})]})}function lee({currentPage:e,onNavigate:t,authUser:n,onLogout:s,onUserUpdated:a,collapsed:o,onToggleCollapse:c}){const{t:d}=ht(["nav","common"]),u=async()=>{try{await ue.auth.logout()}catch{}s?.()};return r.jsxs("aside",{className:"h-dvh bg-surface-secondary flex flex-col shrink-0 overflow-hidden border-r border-border-subtle",children:[r.jsx("div",{className:`flex items-center ${o?"px-2 py-3.5 justify-center":"px-4 h-14 justify-between"}`,children:o?r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("button",{onClick:c,title:d("sidebar.expandSidebar"),className:"group",children:r.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"})}),r.jsx(Cx,{collapsed:!0,userId:n?.id})]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:c,className:"flex items-center gap-2.5 min-w-0 group",title:d("sidebar.collapseSidebar"),children:[r.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"}),r.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx(Cx,{userId:n?.id}),r.jsx("button",{onClick:c,className:"text-fg-tertiary hover:text-fg-secondary transition-colors p-1 rounded-md hover:bg-surface-overlay",title:d("sidebar.collapseSidebar"),children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("polyline",{points:"11 17 6 12 11 7"}),r.jsx("polyline",{points:"18 17 13 12 18 7"})]})})]})]})}),r.jsx("nav",{className:`${o?"p-1.5":"p-3"} flex-1 overflow-y-auto`,children:BO.map((f,h)=>r.jsx("div",{children:r.jsxs("div",{className:"mb-3",children:[!o&&r.jsx("div",{className:"px-3 py-1.5 text-[11px] font-semibold text-fg-tertiary uppercase tracking-widest",children:d(`sections.${f.key}`)}),o&&h>0&&r.jsx("div",{className:"my-2 mx-1"}),HO.filter(p=>p.section===f.key).map(p=>{const x=e===p.id;return r.jsxs("button",{onClick:()=>t(p.id),title:o?d(p.id):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 ${x?"bg-brand-600 text-white shadow-sm shadow-brand-900/30":"text-fg-primary hover:bg-surface-overlay"}`,children:[r.jsx(aee,{d:Ik[p.id]??""}),!o&&d(p.id)]},p.id)})]})},f.key))}),r.jsx(oee,{authUser:n,collapsed:o,onLogout:u,onUserUpdated:a}),!o&&r.jsxs("div",{className:"px-4 pb-2 text-[10px] text-fg-muted",children:["v","0.6.0"]})]})}function cee({currentPage:e,onNavigate:t}){const{t:n}=ht("nav");return r.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:qO.map(s=>{const a=s.group.includes(e);return r.jsxs("button",{onClick:()=>t(s.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${a?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[r.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:a?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:r.jsx("path",{d:Ik[s.id]})}),r.jsx("span",{className:`text-[10px] leading-tight ${a?"font-semibold":""}`,children:n(s.id)})]},s.id)})})}function dee({authUser:e}){const{t}=ht(["nav","common"]),n=v.useMemo(()=>[{id:"builder",label:t("nav:builder")},{id:"agents",label:t("nav:tabs.agents")},{id:"teams",label:t("nav:tabs.teams")},{id:"skills",label:t("nav:tabs.skills")}],[t]),[s,a]=v.useState("builder"),o=Hi(n,s,a);return r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:o.onTouchStart,onTouchEnd:o.onTouchEnd,children:[r.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:n.map(c=>r.jsx("button",{onClick:()=>a(c.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===c.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:c.label},c.id))}),r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="builder"&&r.jsx(uN,{}),s==="agents"&&r.jsx(hN,{authUser:e}),s==="teams"&&r.jsx(xN,{}),s==="skills"&&r.jsx(bN,{})]})]})}function uee({theme:e,onThemeChange:t,authUser:n}){const{t:s}=ht(["nav","common"]),a=v.useMemo(()=>[{id:"settings",label:s("nav:settings")},{id:"reports",label:s("nav:reports")}],[s]),[o,c]=v.useState("settings"),d=Hi(a,o,c);return r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:d.onTouchStart,onTouchEnd:d.onTouchEnd,children:[r.jsx("div",{className:"flex border-b border-border-default bg-surface-secondary shrink-0 overflow-x-auto scrollbar-hide",children:a.map(u=>r.jsx("button",{onClick:()=>c(u.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 ${o===u.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:u.label},u.id))}),r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[o==="settings"&&r.jsx(dN,{theme:e,onThemeChange:t,authUser:n}),o==="reports"&&r.jsx(m7,{authUser:n})]})]})}const cf=1,wk=3;function fee({onComplete:e,theme:t,onThemeChange:n}){const{t:s}=ht(["onboarding","common"]),[a,o]=v.useState(0),[c,d]=v.useState(""),[u,f]=v.useState(""),[h,p]=v.useState(""),[x,b]=v.useState(""),[y,k]=v.useState(!1),[j,S]=v.useState(""),[T,N]=v.useState(!1),[E,B]=v.useState(null);v.useEffect(()=>{ue.auth.me().then(({user:ce})=>{ce.name&&d(ce.name),ce.email&&f(ce.email),ce.avatarUrl&&B(ce.avatarUrl)}).catch(()=>{})},[]);const[A,H]=v.useState(null),[O,z]=v.useState(!1),[I,_]=v.useState({}),[X,G]=v.useState(!1),[M,U]=v.useState(null),[L,F]=v.useState(!1),[Z,Y]=v.useState(!1),[D,P]=v.useState(null),ee=v.useRef(!1),$=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});v.useEffect(()=>{fetch("/api/settings/llm").then(ce=>ce.ok?ce.json():null).then(ce=>{ce?.providers&&Object.values(ce.providers).some(ge=>ge.configured)&&Y(!0)}).catch(()=>{})},[]),v.useEffect(()=>{a===wk&&!ee.current&&!Z&&(ee.current=!0,Q())},[a,Z]);const Q=async()=>{z(!0);try{const ce=await fetch("/api/settings/env-models",{headers:$()});if(ce.ok){const ge=await ce.json();if(H(ge),ge.detected.length>0){const Ce={};for(const Be of ge.detected)Ce[Be.provider]=!0;_(Ce)}}}catch{}finally{z(!1)}},q=async()=>{if(!A)return;const ce=A.detected.filter(ge=>I[ge.provider]);if(ce.length!==0){G(!0),P(null);try{const ge=await fetch("/api/settings/env-models",{method:"POST",headers:$(),body:JSON.stringify({providers:ce.map(Ce=>({provider:Ce.provider,model:Ce.model,baseUrl:Ce.baseUrl,enabled:!0}))})});if(ge.ok){const Ce=await ge.json();P({type:"ok",text:Ce.message}),Y(!0)}else P({type:"err",text:s("llm.failedToApply")})}catch{P({type:"err",text:s("common:networkError")})}finally{G(!1)}}},J=async()=>{F(!0);try{const ge=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:$(),body:JSON.stringify({preview:!0})})).json();"error"in ge||U(ge)}catch{}finally{F(!1)}},K=async()=>{F(!0),P(null);try{const ge=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:$(),body:JSON.stringify({preview:!1})})).json();"error"in ge?P({type:"err",text:ge.error}):(P({type:"ok",text:s("llm.importedModels",{count:ge.appliedModels})}),Y(!0))}catch{P({type:"err",text:s("llm.importFailed")})}finally{F(!1)}},re=async()=>{if(S(""),!c.trim()){S(s("profile.errors.nameRequired"));return}if(!u.trim()){S(s("profile.errors.emailRequired"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u.trim())){S(s("profile.errors.emailInvalid"));return}if(h&&h.length<6){S(s("profile.errors.passwordTooShort"));return}if(h&&h!==x){S(s("profile.errors.passwordMismatch"));return}k(!0);try{await ue.auth.updateProfile(c.trim(),u.trim()),h&&await ue.auth.changePassword("",h),N(!0)}catch{S(s("profile.errors.saveFailed"))}finally{k(!1)}},de=[{value:"system",label:s("theme.system"),icon:"💻",desc:s("theme.systemDesc")},{value:"light",label:s("theme.light"),icon:"☀️",desc:s("theme.lightDesc")},{value:"dark",label:s("theme.dark"),icon:"🌙",desc:s("theme.darkDesc")},{value:"cyberpunk",label:s("theme.cyberpunk"),icon:"🔮",desc:s("theme.cyberpunkDesc")},{value:"midnight",label:s("theme.midnight"),icon:"🌊",desc:s("theme.midnightDesc")}],pe=[{title:s("welcome.title"),subtitle:s("welcome.subtitle"),content:r.jsxs("div",{className:"space-y-4 text-fg-secondary text-sm leading-relaxed",children:[r.jsx("p",{className:"text-fg-secondary",children:r.jsx(Qd,{i18nKey:"welcome.description",ns:"onboarding",components:{strong:r.jsx("strong",{className:"text-fg-primary"})}})}),r.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[[s("welcome.features.operation"),s("welcome.features.operationDesc")],[s("welcome.features.collaboration"),s("welcome.features.collaborationDesc")],[s("welcome.features.memory"),s("welcome.features.memoryDesc")],[s("welcome.features.anyLlm"),s("welcome.features.anyLlmDesc")]].map(([ce,ge])=>r.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[r.jsx("div",{className:"font-medium text-fg-primary text-xs",children:ce}),r.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:ge})]},ce))})]})},{title:s("profile.title"),subtitle:s("profile.subtitle"),content:T?r.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[r.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-sm font-medium text-green-600",children:s("profile.saved")}),r.jsxs("div",{className:"text-xs text-fg-secondary mt-0.5",children:[c," · ",u]})]})]}):r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"flex justify-center",children:r.jsx(Vb,{currentUrl:E,name:c,size:64,targetType:"user"})}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[s("profile.nameLabel")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx("input",{type:"text",value:c,onChange:ce=>d(ce.target.value),placeholder:s("profile.namePlaceholder"),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",autoFocus:!0})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[s("profile.emailLabel")," ",r.jsx("span",{className:"text-red-500",children:"*"})]}),r.jsx("input",{type:"email",value:u,onChange:ce=>f(ce.target.value),placeholder:s("profile.emailPlaceholder"),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"})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:s("profile.newPasswordLabel")}),r.jsx("input",{type:"password",value:h,onChange:ce=>p(ce.target.value),placeholder:s("profile.newPasswordPlaceholder"),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"})]}),h&&r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:s("profile.confirmPasswordLabel")}),r.jsx("input",{type:"password",value:x,onChange:ce=>b(ce.target.value),placeholder:s("profile.confirmPasswordPlaceholder"),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"})]}),j&&r.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:j}),r.jsx("button",{onClick:()=>{re()},disabled:y||!c.trim()||!u.trim(),className:"w-full px-4 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:s(y?"common:saving":"profile.saveProfile")})]})},{title:s("theme.title"),subtitle:s("theme.subtitle"),content:r.jsx("div",{className:"grid grid-cols-3 gap-3",children:de.map(ce=>r.jsxs("button",{onClick:()=>n(ce.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===ce.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[r.jsx("span",{className:"text-2xl",children:ce.icon}),r.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ce.label}),r.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:ce.desc})]},ce.value))})},{title:s("llm.title"),subtitle:s("llm.subtitle"),content:Z?r.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[r.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-sm font-medium text-green-600",children:s("llm.configured")}),r.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:s("llm.configuredHint")})]})]}):r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:s("llm.fromEnv")}),O&&r.jsx("div",{className:"text-xs text-fg-tertiary animate-pulse",children:s("llm.detectingKeys")}),A&&A.detected.length>0&&r.jsxs("div",{className:"space-y-2",children:[A.detected.map(ce=>r.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:[r.jsx("input",{type:"checkbox",checked:I[ce.provider]??!1,onChange:ge=>_({...I,[ce.provider]:ge.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-sm text-fg-primary",children:ce.displayName}),r.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:ce.model})]}),r.jsx("code",{className:"text-[10px] text-fg-tertiary",children:ce.apiKeyPreview})]},ce.provider)),r.jsx("button",{onClick:()=>{q()},disabled:X||Object.values(I).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:X?s("common:applying"):s("llm.applyProviders",{count:Object.values(I).filter(Boolean).length})})]}),A&&A.detected.length===0&&!O&&r.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:r.jsx(Qd,{i18nKey:"llm.noKeysFound",ns:"onboarding",components:{code:r.jsx("code",{className:"text-fg-secondary"})}})})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex-1 h-px bg-border-default"}),r.jsx("span",{className:"text-xs text-fg-tertiary",children:s("llm.or")}),r.jsx("div",{className:"flex-1 h-px bg-border-default"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:s("llm.fromOpenClaw")}),M?M.found?r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"text-xs text-green-600",children:[s("llm.openClawFoundLabel")," ",r.jsx("code",{className:"text-fg-secondary",children:M.summary.configPath}),M.summary.models&&r.jsx("span",{className:"text-fg-tertiary ml-1",children:s("llm.openClawProviders",{count:M.summary.models.providerCount})})]}),r.jsx("button",{onClick:()=>{K()},disabled:L,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:s(L?"common:importing":"llm.importModelConfigs")})]}):r.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:s("llm.noOpenClawFound")}):r.jsx("button",{onClick:()=>{J()},disabled:L,className:"px-4 py-2 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-secondary text-sm rounded-lg transition-colors w-full",children:s(L?"common:detecting":"llm.detectOpenClaw")})]}),D&&r.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${D.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:D.text})]})},{title:s("done.title"),subtitle:s("done.subtitle"),content:r.jsx("div",{className:"space-y-2 text-fg-secondary text-sm",children:[[s("done.chat"),s("done.chatDesc")],[s("done.projects"),s("done.projectsDesc")],[s("done.builder"),s("done.builderDesc")],[s("done.settings"),s("done.settingsDesc")]].map(([ce,ge])=>r.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[r.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),r.jsxs("div",{children:[r.jsx("div",{className:"font-medium text-fg-primary text-xs",children:ce}),r.jsx("div",{className:"text-fg-secondary text-xs",children:ge})]})]},ce))})}],te=()=>{a===cf&&!T||(a<pe.length-1?o(a+1):e())},we=pe[a];return r.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:r.jsx("div",{className:"w-full max-w-lg",children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl p-8",children:[r.jsx("div",{className:"flex gap-1.5 mb-8",children:pe.map((ce,ge)=>r.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${ge<=a?"bg-brand-500":"bg-surface-elevated"}`},ge))}),r.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:we.title}),r.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:we.subtitle}),we.content,r.jsxs("div",{className:"flex justify-between mt-8",children:[a>0?r.jsx("button",{onClick:()=>o(a-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:s("common:back")}):r.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("common:skip")}),r.jsxs("div",{className:"flex items-center gap-3",children:[a===cf&&!T&&r.jsx("button",{onClick:()=>o(a+1),className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("llm.skipForNow")}),a===wk&&!Z&&r.jsx("button",{onClick:te,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("llm.skipForNow")}),r.jsx("button",{onClick:te,disabled:a===cf&&!T,className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${a===cf&&!T?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:a===pe.length-1?s("getStarted"):s("common:next")})]})]})]})})})}function mee({onLogin:e}){const{t}=ht("auth"),[n,s]=v.useState(""),[a,o]=v.useState(""),[c,d]=v.useState(""),[u,f]=v.useState(!1),h=async p=>{if(p.preventDefault(),!(!n.trim()||!a)){d(""),f(!0);try{const{user:x}=await ue.auth.login(n.trim(),a),b=n.trim().toLowerCase()==="admin@markus.local"&&a==="markus123";e(x,b)}catch{d(t("login.invalidCredentials"))}finally{f(!1)}}};return r.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[r.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),r.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[r.jsxs("div",{className:"text-center mb-8",children:[r.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),r.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),r.jsx("div",{className:"text-sm text-fg-tertiary",children:t("login.subtitle")})]}),r.jsxs("form",{onSubmit:h,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[r.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:t("login.signIn")}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("login.email")}),r.jsx("input",{type:"email",value:n,onChange:p=>s(p.target.value),autoComplete:"email",placeholder:"your@email.com",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 placeholder:text-fg-tertiary",required:!0})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("login.password")}),r.jsx("input",{type:"password",value:a,onChange:p=>o(p.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),c&&r.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:c}),r.jsx("button",{type:"submit",disabled:u||!n||!a,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:t(u?"login.signingIn":"login.signIn")}),r.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:t("login.defaultCredentials")})]})]})]})}function hee({token:e,onComplete:t}){const{t:n}=ht("auth"),[s,a]=v.useState(null),[o,c]=v.useState(""),[d,u]=v.useState(""),[f,h]=v.useState(""),[p,x]=v.useState(!1),[b,y]=v.useState(!1),[k,j]=v.useState(!1);v.useEffect(()=>{ue.auth.inviteInfo(e).then(T=>a(T)).catch(()=>j(!0))},[e]);const S=async T=>{if(T.preventDefault(),h(""),o.length<6){h(n("invite.passwordMinLength"));return}if(o!==d){h(n("invite.passwordsDoNotMatch"));return}x(!0);try{await ue.auth.setup(e,o),y(!0),setTimeout(()=>{window.location.hash="",t()},2e3)}catch{h(n("invite.error"))}finally{x(!1)}};return r.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[r.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),r.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[r.jsxs("div",{className:"text-center mb-8",children:[r.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),r.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),r.jsx("div",{className:"text-sm text-fg-tertiary",children:n("invite.subtitle")})]}),r.jsx("div",{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:k?r.jsxs("div",{className:"text-center space-y-3",children:[r.jsx("div",{className:"text-red-500 text-3xl",children:"⚠"}),r.jsx("p",{className:"text-sm text-fg-secondary",children:n("invite.invalidLink")}),r.jsx("button",{onClick:()=>{window.location.hash="",t()},className:"text-sm text-brand-500 hover:text-brand-400",children:n("login.signIn")})]}):b?r.jsxs("div",{className:"text-center space-y-3",children:[r.jsx("div",{className:"text-green-500 text-3xl",children:"✓"}),r.jsx("p",{className:"text-sm text-fg-secondary",children:n("invite.setupComplete")})]}):s?r.jsxs("form",{onSubmit:S,className:"space-y-5",children:[r.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:n("invite.greeting",{name:s.name})}),r.jsx("p",{className:"text-xs text-fg-tertiary text-center",children:s.email}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("invite.setPassword")}),r.jsx("input",{type:"password",value:o,onChange:T=>c(T.target.value),autoComplete:"new-password",autoFocus:!0,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})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("invite.confirmPassword")}),r.jsx("input",{type:"password",value:d,onChange:T=>u(T.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})]}),f&&r.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:f}),r.jsx("button",{type:"submit",disabled:p||!o||!d,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:n(p?"invite.settingUp":"invite.setupAccount")})]}):r.jsx("div",{className:"text-center text-fg-tertiary text-sm animate-pulse py-4",children:"Loading…"})})]})]})}function pee({onComplete:e,isFirstTime:t}){const{t:n}=ht("auth"),[s,a]=v.useState(""),[o,c]=v.useState(""),[d,u]=v.useState(""),[f,h]=v.useState(""),[p,x]=v.useState(!1),b=async y=>{if(y.preventDefault(),h(""),o.length<6){h(n("changePassword.passwordMinLength"));return}if(o!==d){h(n("changePassword.passwordsDoNotMatch"));return}x(!0);try{await ue.auth.changePassword(s,o),e()}catch{h(n("changePassword.failedToChange"))}finally{x(!1)}};return r.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[r.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),r.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[r.jsxs("div",{className:"text-center mb-8",children:[r.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),r.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),r.jsx("div",{className:"text-sm text-fg-tertiary",children:n("login.subtitle")})]}),r.jsxs("form",{onSubmit:b,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:n(t?"changePassword.setYourPassword":"changePassword.changePassword")}),t&&r.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:n("changePassword.defaultPasswordWarning")})]}),!t&&r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.currentPassword")}),r.jsx("input",{type:"password",value:s,onChange:y=>a(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"})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.newPassword")}),r.jsx("input",{type:"password",value:o,onChange:y=>c(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})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.confirmNewPassword")}),r.jsx("input",{type:"password",value:d,onChange:y=>u(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})]}),f&&r.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:f}),r.jsx("button",{type:"submit",disabled:p||!o||!d,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:n(p?"changePassword.saving":t?"changePassword.setPasswordAndContinue":"changePassword.changePassword")})]})]})]})}const Vg={};function gee(){const{t:e}=ht("common"),[t,n]=v.useState(jd),[s,a]=v.useState(()=>!localStorage.getItem("markus_onboarded")),[o,c]=v.useState(!0),d=ws(),u=pV(),f=vm({side:"left",defaultWidth:240,minWidth:180,maxWidth:400,collapsedWidth:48,storageKey:"markus_sidebar"}),[h,p]=v.useState(()=>new Set([jd()])),[x,b]=v.useState("loading"),[y,k]=v.useState(!1),[j,S]=v.useState(null),[T,N]=v.useState(!1),[E,B]=v.useState(null),[A,H]=v.useState(()=>{const M=localStorage.getItem("markus_update_dismissed");return M||null}),O=v.useCallback(M=>{let U=So(M);d&&(U=$O[U]??U);const L=jd(),F=window.location.hash.slice(1);F!==L?Vg[L]=F:delete Vg[L];const Z=U!==_e.WORK?Vg[U]:void 0;Z&&Z!==U?(history.pushState(null,"","#"+U),history.pushState(null,"","#"+Z)):history.pushState(null,"","#"+U),window.dispatchEvent(new HashChangeEvent("hashchange")),n(U),p(Y=>Y.has(U)?Y:new Set([...Y,U]))},[d]);v.useEffect(()=>{St.setHandler(M=>O(M))},[O]);const z=v.useCallback(()=>{fetch("/api/settings/llm").then(M=>M.ok?M.json():null).then(M=>{if(M?.providers){const U=Object.values(M.providers).some(L=>L.configured);S(U)}}).catch(()=>{})},[]);v.useEffect(()=>{const M=window.location.hash.startsWith("#invite?token="),U=new URLSearchParams(window.location.search),L=U.get("install");if(L&&jd()!==_e.STORE){const Y=U.get("type"),P=Y&&{agent:"agents",team:"teams",skill:"skills"}[Y]||"agents";localStorage.setItem("markus_nav_installItem",L),localStorage.setItem("markus_nav_storeTab",P),U.delete("install"),U.delete("type");const ee=U.toString();window.history.replaceState(null,"",window.location.pathname+(ee?`?${ee}`:"")+"#store"),setTimeout(()=>St.navigate(_e.STORE,{storeTab:P,installItem:L}),300)}ue.auth.me().then(({user:Y})=>{b(Y),!M&&!localStorage.getItem("markus_onboarded")&&(localStorage.setItem("markus_onboarded","1"),a(!1)),gn.connect(Y.id),z(),ue.health().then(D=>{D.updateAvailable&&D.latestVersion&&B({latestVersion:D.latestVersion,currentVersion:D.version})}).catch(()=>{}),el(Vs.builderArtifacts,()=>ue.builder.artifacts.list()),el(Vs.builderAgents,()=>ue.agents.list()),el(Vs.builderHubMyItems,()=>Nn.myItems()),el(Vs.builderInstalled,()=>ue.builder.artifacts.installed()),el(Vs.hubAgents,()=>Nn.search({type:"agent",limit:50})),el(Vs.hubTeams,()=>Nn.search({type:"team",limit:50})),el(Vs.hubSkills,()=>Nn.search({type:"skill",limit:50}))}).catch(()=>b(null)),gn.connect();const F=gn.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),Z=()=>{const Y=jd();n(Y),p(D=>D.has(Y)?D:new Set([...D,Y]))};return window.addEventListener("hashchange",Z),()=>{F(),gn.disconnect(),window.removeEventListener("hashchange",Z)}},[]);const I=x!=="loading"&&x!==null?x:void 0,_=v.useMemo(()=>d?{[_e.HOME]:r.jsx(cw,{authUser:I}),[_e.TEAM]:r.jsx(Ow,{authUser:I}),[_e.BUILDER]:r.jsx(dee,{authUser:I}),[_e.SETTINGS]:r.jsx(uee,{theme:u.mode,onThemeChange:u.setMode,authUser:I}),[_e.WORK]:r.jsx(xk,{authUser:I}),[_e.DELIVERABLES]:r.jsx(vk,{authUser:I})}:{[_e.HOME]:r.jsx(cw,{authUser:I}),[_e.TEAM]:r.jsx(Ow,{authUser:I}),[_e.SETTINGS]:r.jsx(dN,{theme:u.mode,onThemeChange:u.setMode,authUser:I}),[_e.STORE]:r.jsx(UV,{authUser:I}),[_e.BUILDER]:r.jsx(uN,{authUser:I}),[_e.WORK]:r.jsx(xk,{authUser:I}),[_e.DELIVERABLES]:r.jsx(vk,{authUser:I}),[_e.REPORTS]:r.jsx(m7,{authUser:I})},[I?.id,I?.role,u.mode,d]);if(x==="loading")return r.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:r.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:e("loading")})});const G=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return G?r.jsx(hee,{token:G[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),a(!0),b("loading"),ue.auth.me().then(M=>b(M.user)).catch(()=>b(null))}}):x===null?r.jsx(mee,{onLogin:(M,U)=>{b(M),U?k(!0):localStorage.getItem("markus_onboarded")||(localStorage.setItem("markus_onboarded","1"),a(!1))}}):y?r.jsx(pee,{onComplete:()=>k(!1),isFirstTime:!0}):s?r.jsx(fee,{theme:u.mode,onThemeChange:u.setMode,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),a(!1),z()}}):r.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"relative z-40 shrink-0",style:{width:f.width},children:r.jsx(lee,{currentPage:t,onNavigate:M=>{O(M),c(!1)},authUser:x,onLogout:()=>b(null),onUserUpdated:M=>b(M),collapsed:f.collapsed,onToggleCollapse:f.toggle})}),!f.collapsed&&r.jsx("div",{className:"w-1 cursor-col-resize shrink-0 group relative z-10",onMouseDown:f.onResizeStart,children:r.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"})})]}),r.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col min-w-0 ${d?"pb-14":""}`,children:[j===!1&&!T&&t!==_e.SETTINGS&&r.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:[r.jsx("span",{className:d?"text-xs":"",children:"No LLM provider configured — agents cannot process requests."}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{onClick:()=>{O(_e.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"}),r.jsx("button",{onClick:()=>N(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:e("dismiss")})]})]}),E&&A!==E.latestVersion&&r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-brand-500/10 border-b border-brand-500/30 text-brand-400 text-sm shrink-0",children:[r.jsxs("span",{className:d?"text-xs":"",children:["New version available: ",r.jsxs("strong",{children:["v",E.latestVersion]})," (current: v",E.currentVersion,")",!d&&r.jsxs("span",{className:"text-fg-tertiary ml-2",children:["— run ",r.jsx("code",{className:"bg-surface-overlay px-1.5 py-0.5 rounded text-xs font-mono",children:"npm i -g @markus-global/cli"})," to upgrade"]})]}),r.jsx("button",{onClick:()=>{H(E.latestVersion),localStorage.setItem("markus_update_dismissed",E.latestVersion)},className:"text-brand-400 hover:text-brand-300 text-xs shrink-0",children:e("dismiss")})]}),r.jsx("main",{className:"flex-1 overflow-hidden flex flex-col",children:Object.keys(_).map(M=>h.has(M)?r.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:M===t?"flex":"none"},children:_[M]},M):null)})]}),d&&r.jsx(cee,{currentPage:t,onNavigate:O})]})}nC.createRoot(document.getElementById("root")).render(r.jsx(v.StrictMode,{children:r.jsx(gee,{})}));