tycono 0.3.44 → 0.3.45-beta.1
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.
- package/package.json +1 -1
- package/src/api/src/create-server.ts +1 -1
- package/src/api/src/engine/context-assembler.ts +4 -4
- package/src/api/src/services/claude-md-manager.ts +5 -4
- package/src/api/src/services/file-reader.ts +2 -2
- package/src/api/src/services/preset-loader.ts +2 -2
- package/src/api/src/services/scaffold.ts +12 -11
- package/src/api/src/services/team-recommender.ts +382 -0
- package/src/web/dist/assets/{index-C6r_vHBI.js → index-BJyiMGkM.js} +3 -3
- package/src/web/dist/assets/{index-Czp8wshq.js → index-DDPzbp9E.js} +1 -1
- package/src/web/dist/assets/{preview-app-CMGFfqT-.js → preview-app-DZ6WxhDc.js} +1 -1
- package/src/web/dist/index.html +1 -1
- package/src/web/dist/tyconoforge.js +1 -0
- package/templates/CLAUDE.md.tmpl +46 -45
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DDPzbp9E.js","assets/index-BOuHc64o.css"])))=>i.map(i=>d[i]);
|
|
2
2
|
var T4=Object.defineProperty;var _4=(e,t,n)=>t in e?T4(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var fb=(e,t,n)=>_4(e,typeof t!="symbol"?t+"":t,n);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))i(a);new MutationObserver(a=>{for(const o of a)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&i(c)}).observe(document,{childList:!0,subtree:!0});function n(a){const o={};return a.integrity&&(o.integrity=a.integrity),a.referrerPolicy&&(o.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?o.credentials="include":a.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function i(a){if(a.ep)return;a.ep=!0;const o=n(a);fetch(a.href,o)}})();function zf(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Wm={exports:{}},xc={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.production.js
|
|
@@ -109,7 +109,7 @@ Error generating stack: `+h.message+`
|
|
|
109
109
|
`,`
|
|
110
110
|
+`).split(`
|
|
111
111
|
`)),x=f.reduce((p,y)=>p.concat(...y),[]);return[f,x]}return[[],[]]},[e]);return S.useEffect(()=>{const m=(t==null?void 0:t.target)??kw,f=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const x=g=>{var j,C;if(a.current=g.ctrlKey||g.metaKey||g.shiftKey||g.altKey,(!a.current||a.current&&!f)&&Bk(g))return!1;const k=jw(g.code,d);if(o.current.add(g[k]),Sw(c,o.current,!1)){const N=((C=(j=g.composedPath)==null?void 0:j.call(g))==null?void 0:C[0])||g.target,E=(N==null?void 0:N.nodeName)==="BUTTON"||(N==null?void 0:N.nodeName)==="A";t.preventDefault!==!1&&(a.current||!E)&&g.preventDefault(),i(!0)}},p=g=>{const w=jw(g.code,d);Sw(c,o.current,!0)?(i(!1),o.current.clear()):o.current.delete(g[w]),g.key==="Meta"&&o.current.clear(),a.current=!1},y=()=>{o.current.clear(),i(!1)};return m==null||m.addEventListener("keydown",x),m==null||m.addEventListener("keyup",p),window.addEventListener("blur",y),window.addEventListener("contextmenu",y),()=>{m==null||m.removeEventListener("keydown",x),m==null||m.removeEventListener("keyup",p),window.removeEventListener("blur",y),window.removeEventListener("contextmenu",y)}}},[e,i]),n}function Sw(e,t,n){return e.filter(i=>n||i.length===t.size).some(i=>i.every(a=>t.has(a)))}function jw(e,t){return t.includes(e)?"code":"key"}const k9=()=>{const e=Dn();return S.useMemo(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,{duration:t==null?void 0:t.duration}):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,{duration:t==null?void 0:t.duration}):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:i}=e.getState();return i?i.scaleTo(t,{duration:n==null?void 0:n.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[i,a,o],panZoom:c}=e.getState();return c?(await c.setViewport({x:t.x??i,y:t.y??a,zoom:t.zoom??o},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,i]=e.getState().transform;return{x:t,y:n,zoom:i}},setCenter:async(t,n,i)=>e.getState().setCenter(t,n,i),fitBounds:async(t,n)=>{const{width:i,height:a,minZoom:o,maxZoom:c,panZoom:d}=e.getState(),m=_0(t,i,a,o,c,(n==null?void 0:n.padding)??.1);return d?(await d.setViewport(m,{duration:n==null?void 0:n.duration,ease:n==null?void 0:n.ease,interpolate:n==null?void 0:n.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:i,snapGrid:a,snapToGrid:o,domNode:c}=e.getState();if(!c)return t;const{x:d,y:m}=c.getBoundingClientRect(),f={x:t.x-d,y:t.y-m},x=n.snapGrid??a,p=n.snapToGrid??o;return ou(f,i,p,x)},flowToScreenPosition:t=>{const{transform:n,domNode:i}=e.getState();if(!i)return t;const{x:a,y:o}=i.getBoundingClientRect(),c=_f(t,n);return{x:c.x+a,y:c.y+o}}}),[])};function i3(e,t){const n=[],i=new Map,a=[];for(const o of e)if(o.type==="add"){a.push(o);continue}else if(o.type==="remove"||o.type==="replace")i.set(o.id,[o]);else{const c=i.get(o.id);c?c.push(o):i.set(o.id,[o])}for(const o of t){const c=i.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 m of c)S9(m,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 S9(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 j9(e,t){return i3(e,t)}function C9(e,t){return i3(e,t)}function rl(e,t){return{id:e,type:"select",selected:t}}function ro(e,t=new Set,n=!1){const i=[];for(const[a,o]of e){const c=t.has(a);!(o.selected===void 0&&!c)&&o.selected!==c&&(n&&(o.selected=c),i.push(rl(o.id,c)))}return i}function Cw({items:e=[],lookup:t}){var a;const n=[],i=new Map(e.map(o=>[o.id,o]));for(const[o,c]of e.entries()){const d=t.get(c.id),m=((a=d==null?void 0:d.internals)==null?void 0:a.userNode)??d;m!==void 0&&m!==c&&n.push({id:c.id,item:c,type:"replace"}),m===void 0&&n.push({item:c,type:"add",index:o})}for(const[o]of t)i.get(o)===void 0&&n.push({id:o,type:"remove"});return n}function Nw(e){return{id:e.id,type:"remove"}}const Ew=e=>VR(e),N9=e=>Ak(e);function s3(e){return S.forwardRef(e)}const E9=typeof window<"u"?S.useLayoutEffect:S.useEffect;function Aw(e){const[t,n]=S.useState(BigInt(0)),[i]=S.useState(()=>A9(()=>n(a=>a+BigInt(1))));return E9(()=>{const a=i.get();a.length&&(e(a),i.reset())},[t]),i}function A9(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const a3=S.createContext(null);function D9({children:e}){const t=Dn(),n=S.useCallback(d=>{const{nodes:m=[],setNodes:f,hasDefaultNodes:x,onNodesChange:p,nodeLookup:y,fitViewQueued:g,onNodesChangeMiddlewareMap:w}=t.getState();let k=m;for(const C of d)k=typeof C=="function"?C(k):C;let j=Cw({items:k,lookup:y});for(const C of w.values())j=C(j);x&&f(k),j.length>0?p==null||p(j):g&&window.requestAnimationFrame(()=>{const{fitViewQueued:C,nodes:N,setNodes:E}=t.getState();C&&E(N)})},[]),i=Aw(n),a=S.useCallback(d=>{const{edges:m=[],setEdges:f,hasDefaultEdges:x,onEdgesChange:p,edgeLookup:y}=t.getState();let g=m;for(const w of d)g=typeof w=="function"?w(g):w;x?f(g):p&&p(Cw({items:g,lookup:y}))},[]),o=Aw(a),c=S.useMemo(()=>({nodeQueue:i,edgeQueue:o}),[]);return l.jsx(a3.Provider,{value:c,children:e})}function T9(){const e=S.useContext(a3);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const _9=e=>!!e.panZoom;function O0(){const e=k9(),t=Dn(),n=T9(),i=qt(_9),a=S.useMemo(()=>{const o=p=>t.getState().nodeLookup.get(p),c=p=>{n.nodeQueue.push(p)},d=p=>{n.edgeQueue.push(p)},m=p=>{var C,N;const{nodeLookup:y,nodeOrigin:g}=t.getState(),w=Ew(p)?p:y.get(p.id),k=w.parentId?Rk(w.position,w.measured,w.parentId,y,g):w.position,j={...w,position:k,width:((C=w.measured)==null?void 0:C.width)??w.width,height:((N=w.measured)==null?void 0:N.height)??w.height};return xo(j)},f=(p,y,g={replace:!1})=>{c(w=>w.map(k=>{if(k.id===p){const j=typeof y=="function"?y(k):y;return g.replace&&Ew(j)?j:{...k,...j}}return k}))},x=(p,y,g={replace:!1})=>{d(w=>w.map(k=>{if(k.id===p){const j=typeof y=="function"?y(k):y;return g.replace&&N9(j)?j:{...k,...j}}return k}))};return{getNodes:()=>t.getState().nodes.map(p=>({...p})),getNode:p=>{var y;return(y=o(p))==null?void 0:y.internals.userNode},getInternalNode:o,getEdges:()=>{const{edges:p=[]}=t.getState();return p.map(y=>({...y}))},getEdge:p=>t.getState().edgeLookup.get(p),setNodes:c,setEdges:d,addNodes:p=>{const y=Array.isArray(p)?p:[p];n.nodeQueue.push(g=>[...g,...y])},addEdges:p=>{const y=Array.isArray(p)?p:[p];n.edgeQueue.push(g=>[...g,...y])},toObject:()=>{const{nodes:p=[],edges:y=[],transform:g}=t.getState(),[w,k,j]=g;return{nodes:p.map(C=>({...C})),edges:y.map(C=>({...C})),viewport:{x:w,y:k,zoom:j}}},deleteElements:async({nodes:p=[],edges:y=[]})=>{const{nodes:g,edges:w,onNodesDelete:k,onEdgesDelete:j,triggerNodeChanges:C,triggerEdgeChanges:N,onDelete:E,onBeforeDelete:A}=t.getState(),{nodes:z,edges:D}=await ZR({nodesToRemove:p,edgesToRemove:y,nodes:g,edges:w,onBeforeDelete:A}),F=D.length>0,q=z.length>0;if(F){const V=D.map(Nw);j==null||j(D),N(V)}if(q){const V=z.map(Nw);k==null||k(z),C(V)}return(q||F)&&(E==null||E({nodes:z,edges:D})),{deletedNodes:z,deletedEdges:D}},getIntersectingNodes:(p,y=!0,g)=>{const w=Jv(p),k=w?p:m(p),j=g!==void 0;return k?(g||t.getState().nodes).filter(C=>{const N=t.getState().nodeLookup.get(C.id);if(N&&!w&&(C.id===p.id||!N.internals.positionAbsolute))return!1;const E=xo(j?C:N),A=Vc(E,k);return y&&A>0||A>=E.width*E.height||A>=k.width*k.height}):[]},isNodeIntersecting:(p,y,g=!0)=>{const k=Jv(p)?p:m(p);if(!k)return!1;const j=Vc(k,y);return g&&j>0||j>=y.width*y.height||j>=k.width*k.height},updateNode:f,updateNodeData:(p,y,g={replace:!1})=>{f(p,w=>{const k=typeof y=="function"?y(w):y;return g.replace?{...w,data:k}:{...w,data:{...w.data,...k}}},g)},updateEdge:x,updateEdgeData:(p,y,g={replace:!1})=>{x(p,w=>{const k=typeof y=="function"?y(w):y;return g.replace?{...w,data:k}:{...w,data:{...w.data,...k}}},g)},getNodesBounds:p=>{const{nodeLookup:y,nodeOrigin:g}=t.getState();return WR(p,{nodeLookup:y,nodeOrigin:g})},getHandleConnections:({type:p,id:y,nodeId:g})=>{var w;return Array.from(((w=t.getState().connectionLookup.get(`${g}-${p}${y?`-${y}`:""}`))==null?void 0:w.values())??[])},getNodeConnections:({type:p,handleId:y,nodeId:g})=>{var w;return Array.from(((w=t.getState().connectionLookup.get(`${g}${p?y?`-${p}-${y}`:`-${p}`:""}`))==null?void 0:w.values())??[])},fitView:async p=>{const y=t.getState().fitViewResolver??nz();return t.setState({fitViewQueued:!0,fitViewOptions:p,fitViewResolver:y}),n.nodeQueue.push(g=>[...g]),y.promise}}},[]);return S.useMemo(()=>({...a,...e,viewportInitialized:i}),[i])}const Dw=e=>e.selected,M9=typeof window<"u"?window:void 0;function F9({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=Dn(),{deleteElements:i}=O0(),a=Gc(e,{actInsideInputWithModifier:!1}),o=Gc(t,{target:M9});S.useEffect(()=>{if(a){const{edges:c,nodes:d}=n.getState();i({nodes:d.filter(Dw),edges:c.filter(Dw)}),n.setState({nodesSelectionActive:!1})}},[a]),S.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])}function R9(e){const t=Dn();S.useEffect(()=>{const n=()=>{var a,o,c,d;if(!e.current||!(((o=(a=e.current).checkVisibility)==null?void 0:o.call(a))??!0))return!1;const i=M0(e.current);(i.height===0||i.width===0)&&((d=(c=t.getState()).onError)==null||d.call(c,"004",Ji.error004())),t.setState({width:i.width||500,height:i.height||500})};if(e.current){n(),window.addEventListener("resize",n);const i=new ResizeObserver(()=>n());return i.observe(e.current),()=>{window.removeEventListener("resize",n),i&&e.current&&i.unobserve(e.current)}}},[])}const Qf={position:"absolute",width:"100%",height:"100%",top:0,left:0},z9=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function B9({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:i=!1,panOnScrollSpeed:a=.5,panOnScrollMode:o=dl.Free,zoomOnDoubleClick:c=!0,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:x,maxZoom:p,zoomActivationKeyCode:y,preventScrolling:g=!0,children:w,noWheelClassName:k,noPanClassName:j,onViewportChange:C,isControlledViewport:N,paneClickDistance:E,selectionOnDrag:A}){const z=Dn(),D=S.useRef(null),{userSelectionActive:F,lib:q,connectionInProgress:V}=qt(z9,An),L=Gc(y),_=S.useRef();R9(D);const B=S.useCallback(X=>{C==null||C({x:X[0],y:X[1],zoom:X[2]}),N||z.setState({transform:X})},[C,N]);return S.useEffect(()=>{if(D.current){_.current=Lz({domNode:D.current,minZoom:x,maxZoom:p,translateExtent:f,viewport:m,onDraggingChange:$=>z.setState(G=>G.paneDragging===$?G:{paneDragging:$}),onPanZoomStart:($,G)=>{const{onViewportChangeStart:Q,onMoveStart:K}=z.getState();K==null||K($,G),Q==null||Q(G)},onPanZoom:($,G)=>{const{onViewportChange:Q,onMove:K}=z.getState();K==null||K($,G),Q==null||Q(G)},onPanZoomEnd:($,G)=>{const{onViewportChangeEnd:Q,onMoveEnd:K}=z.getState();K==null||K($,G),Q==null||Q(G)}});const{x:X,y:R,zoom:H}=_.current.getViewport();return z.setState({panZoom:_.current,transform:[X,R,H],domNode:D.current.closest(".react-flow")}),()=>{var $;($=_.current)==null||$.destroy()}}},[]),S.useEffect(()=>{var X;(X=_.current)==null||X.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:i,panOnScrollSpeed:a,panOnScrollMode:o,zoomOnDoubleClick:c,panOnDrag:d,zoomActivationKeyPressed:L,preventScrolling:g,noPanClassName:j,userSelectionActive:F,noWheelClassName:k,lib:q,onTransformChange:B,connectionInProgress:V,selectionOnDrag:A,paneClickDistance:E})},[e,t,n,i,a,o,c,d,L,g,j,F,k,q,B,V,A,E]),l.jsx("div",{className:"react-flow__renderer",ref:D,style:Qf,children:w})}const $9=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function O9(){const{userSelectionActive:e,userSelectionRect:t}=qt($9,An);return e&&t?l.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 Rp=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},L9=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function I9({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Xc.Full,panOnDrag:i,paneClickDistance:a,selectionOnDrag:o,onSelectionStart:c,onSelectionEnd:d,onPaneClick:m,onPaneContextMenu:f,onPaneScroll:x,onPaneMouseEnter:p,onPaneMouseMove:y,onPaneMouseLeave:g,children:w}){const k=Dn(),{userSelectionActive:j,elementsSelectable:C,dragging:N,connectionInProgress:E}=qt(L9,An),A=C&&(e||j),z=S.useRef(null),D=S.useRef(),F=S.useRef(new Set),q=S.useRef(new Set),V=S.useRef(!1),L=Q=>{if(V.current||E){V.current=!1;return}m==null||m(Q),k.getState().resetSelectedElements(),k.setState({nodesSelectionActive:!1})},_=Q=>{if(Array.isArray(i)&&(i!=null&&i.includes(2))){Q.preventDefault();return}f==null||f(Q)},B=x?Q=>x(Q):void 0,X=Q=>{V.current&&(Q.stopPropagation(),V.current=!1)},R=Q=>{var ee,J;const{domNode:K}=k.getState();if(D.current=K==null?void 0:K.getBoundingClientRect(),!D.current)return;const M=Q.target===z.current;if(!M&&!!Q.target.closest(".nokey")||!e||!(o&&M||t)||Q.button!==0||!Q.isPrimary)return;(J=(ee=Q.target)==null?void 0:ee.setPointerCapture)==null||J.call(ee,Q.pointerId),V.current=!1;const{x:O,y:Z}=Ci(Q.nativeEvent,D.current);k.setState({userSelectionRect:{width:0,height:0,startX:O,startY:Z,x:O,y:Z}}),M||(Q.stopPropagation(),Q.preventDefault())},H=Q=>{const{userSelectionRect:K,transform:M,nodeLookup:U,edgeLookup:P,connectionLookup:O,triggerNodeChanges:Z,triggerEdgeChanges:ee,defaultEdgeOptions:J,resetSelectedElements:se}=k.getState();if(!D.current||!K)return;const{x:le,y:ye}=Ci(Q.nativeEvent,D.current),{startX:De,startY:Ee}=K;if(!V.current){const Pe=t?0:a;if(Math.hypot(le-De,ye-Ee)<=Pe)return;se(),c==null||c(Q)}V.current=!0;const Re={startX:De,startY:Ee,x:le<De?le:De,y:ye<Ee?ye:Ee,width:Math.abs(le-De),height:Math.abs(ye-Ee)},me=F.current,Fe=q.current;F.current=new Set(T0(U,Re,M,n===Xc.Partial,!0).map(Pe=>Pe.id)),q.current=new Set;const Je=(J==null?void 0:J.selectable)??!0;for(const Pe of F.current){const it=O.get(Pe);if(it)for(const{edgeId:ht}of it.values()){const Ye=P.get(ht);Ye&&(Ye.selectable??Je)&&q.current.add(ht)}}if(!ew(me,F.current)){const Pe=ro(U,F.current,!0);Z(Pe)}if(!ew(Fe,q.current)){const Pe=ro(P,q.current);ee(Pe)}k.setState({userSelectionRect:Re,userSelectionActive:!0,nodesSelectionActive:!1})},$=Q=>{var K,M;Q.button===0&&((M=(K=Q.target)==null?void 0:K.releasePointerCapture)==null||M.call(K,Q.pointerId),!j&&Q.target===z.current&&k.getState().userSelectionRect&&(L==null||L(Q)),k.setState({userSelectionActive:!1,userSelectionRect:null}),V.current&&(d==null||d(Q),k.setState({nodesSelectionActive:F.current.size>0})))},G=i===!0||Array.isArray(i)&&i.includes(0);return l.jsxs("div",{className:Yn(["react-flow__pane",{draggable:G,dragging:N,selection:e}]),onClick:A?void 0:Rp(L,z),onContextMenu:Rp(_,z),onWheel:Rp(B,z),onPointerEnter:A?void 0:p,onPointerMove:A?H:y,onPointerUp:A?$:void 0,onPointerDownCapture:A?R:void 0,onClickCapture:A?X:void 0,onPointerLeave:g,ref:z,style:Qf,children:[w,l.jsx(O9,{})]})}function $x({id:e,store:t,unselect:n=!1,nodeRef:i}){const{addSelectedNodes:a,unselectNodesAndEdges:o,multiSelectionActive:c,nodeLookup:d,onError:m}=t.getState(),f=d.get(e);if(!f){m==null||m("012",Ji.error012(e));return}t.setState({nodesSelectionActive:!1}),f.selected?(n||f.selected&&c)&&(o({nodes:[f],edges:[]}),requestAnimationFrame(()=>{var x;return(x=i==null?void 0:i.current)==null?void 0:x.blur()})):a([e])}function l3({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:i,nodeId:a,isSelectable:o,nodeClickDistance:c}){const d=Dn(),[m,f]=S.useState(!1),x=S.useRef();return S.useEffect(()=>{x.current=Cz({getStoreItems:()=>d.getState(),onNodeMouseDown:p=>{$x({id:p,store:d,nodeRef:e})},onDragStart:()=>{f(!0)},onDragStop:()=>{f(!1)}})},[]),S.useEffect(()=>{if(!(t||!e.current||!x.current))return x.current.update({noDragClassName:n,handleSelector:i,domNode:e.current,isSelectable:o,nodeId:a,nodeClickDistance:c}),()=>{var p;(p=x.current)==null||p.destroy()}},[n,i,t,o,e,a,c]),m}const H9=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function o3(){const e=Dn();return S.useCallback(n=>{const{nodeExtent:i,snapToGrid:a,snapGrid:o,nodesDraggable:c,onError:d,updateNodePositions:m,nodeLookup:f,nodeOrigin:x}=e.getState(),p=new Map,y=H9(c),g=a?o[0]:5,w=a?o[1]:5,k=n.direction.x*g*n.factor,j=n.direction.y*w*n.factor;for(const[,C]of f){if(!y(C))continue;let N={x:C.internals.positionAbsolute.x+k,y:C.internals.positionAbsolute.y+j};a&&(N=lu(N,o));const{position:E,positionAbsolute:A}=Dk({nodeId:C.id,nextPosition:N,nodeLookup:f,nodeExtent:i,nodeOrigin:x,onError:d});C.position=E,C.internals.positionAbsolute=A,p.set(C.id,C)}m(p)},[])}const L0=S.createContext(null),U9=L0.Provider;L0.Consumer;const c3=()=>S.useContext(L0),q9=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Y9=(e,t,n)=>i=>{const{connectionClickStartHandle:a,connectionMode:o,connection:c}=i,{fromHandle:d,toHandle:m,isValid:f}=c,x=(m==null?void 0:m.nodeId)===e&&(m==null?void 0:m.id)===t&&(m==null?void 0:m.type)===n;return{connectingFrom:(d==null?void 0:d.nodeId)===e&&(d==null?void 0:d.id)===t&&(d==null?void 0:d.type)===n,connectingTo:x,clickConnecting:(a==null?void 0:a.nodeId)===e&&(a==null?void 0:a.id)===t&&(a==null?void 0:a.type)===n,isPossibleEndHandle:o===mo.Strict?(d==null?void 0:d.type)!==n:e!==(d==null?void 0:d.nodeId)||t!==(d==null?void 0:d.id),connectionInProcess:!!d,clickConnectionInProcess:!!a,valid:x&&f}};function P9({type:e="source",position:t=at.Top,isValidConnection:n,isConnectable:i=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,id:c,onConnect:d,children:m,className:f,onMouseDown:x,onTouchStart:p,...y},g){var H,$;const w=c||null,k=e==="target",j=Dn(),C=c3(),{connectOnClick:N,noPanClassName:E,rfId:A}=qt(q9,An),{connectingFrom:z,connectingTo:D,clickConnecting:F,isPossibleEndHandle:q,connectionInProcess:V,clickConnectionInProcess:L,valid:_}=qt(Y9(C,w,e),An);C||($=(H=j.getState()).onError)==null||$.call(H,"010",Ji.error010());const B=G=>{const{defaultEdgeOptions:Q,onConnect:K,hasDefaultEdges:M}=j.getState(),U={...Q,...G};if(M){const{edges:P,setEdges:O}=j.getState();O(cz(U,P))}K==null||K(U),d==null||d(U)},X=G=>{if(!C)return;const Q=$k(G.nativeEvent);if(a&&(Q&&G.button===0||!Q)){const K=j.getState();Bx.onPointerDown(G.nativeEvent,{handleDomNode:G.currentTarget,autoPanOnConnect:K.autoPanOnConnect,connectionMode:K.connectionMode,connectionRadius:K.connectionRadius,domNode:K.domNode,nodeLookup:K.nodeLookup,lib:K.lib,isTarget:k,handleId:w,nodeId:C,flowId:K.rfId,panBy:K.panBy,cancelConnection:K.cancelConnection,onConnectStart:K.onConnectStart,onConnectEnd:(...M)=>{var U,P;return(P=(U=j.getState()).onConnectEnd)==null?void 0:P.call(U,...M)},updateConnection:K.updateConnection,onConnect:B,isValidConnection:n||((...M)=>{var U,P;return((P=(U=j.getState()).isValidConnection)==null?void 0:P.call(U,...M))??!0}),getTransform:()=>j.getState().transform,getFromHandle:()=>j.getState().connection.fromHandle,autoPanSpeed:K.autoPanSpeed,dragThreshold:K.connectionDragThreshold})}Q?x==null||x(G):p==null||p(G)},R=G=>{const{onClickConnectStart:Q,onClickConnectEnd:K,connectionClickStartHandle:M,connectionMode:U,isValidConnection:P,lib:O,rfId:Z,nodeLookup:ee,connection:J}=j.getState();if(!C||!M&&!a)return;if(!M){Q==null||Q(G.nativeEvent,{nodeId:C,handleId:w,handleType:e}),j.setState({connectionClickStartHandle:{nodeId:C,type:e,id:w}});return}const se=zk(G.target),le=n||P,{connection:ye,isValid:De}=Bx.isValid(G.nativeEvent,{handle:{nodeId:C,id:w,type:e},connectionMode:U,fromNodeId:M.nodeId,fromHandleId:M.id||null,fromType:M.type,isValidConnection:le,flowId:Z,doc:se,lib:O,nodeLookup:ee});De&&ye&&B(ye);const Ee=structuredClone(J);delete Ee.inProgress,Ee.toPosition=Ee.toHandle?Ee.toHandle.position:null,K==null||K(G,Ee),j.setState({connectionClickStartHandle:null})};return l.jsx("div",{"data-handleid":w,"data-nodeid":C,"data-handlepos":t,"data-id":`${A}-${C}-${w}-${e}`,className:Yn(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",E,f,{source:!k,target:k,connectable:i,connectablestart:a,connectableend:o,clickconnecting:F,connectingfrom:z,connectingto:D,valid:_,connectionindicator:i&&(!V||q)&&(V||L?o:a)}]),onMouseDown:X,onTouchStart:X,onClick:N?R:void 0,ref:g,...y,children:m})}const bo=S.memo(s3(P9));function X9({data:e,isConnectable:t,sourcePosition:n=at.Bottom}){return l.jsxs(l.Fragment,{children:[e==null?void 0:e.label,l.jsx(bo,{type:"source",position:n,isConnectable:t})]})}function V9({data:e,isConnectable:t,targetPosition:n=at.Top,sourcePosition:i=at.Bottom}){return l.jsxs(l.Fragment,{children:[l.jsx(bo,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,l.jsx(bo,{type:"source",position:i,isConnectable:t})]})}function W9(){return null}function G9({data:e,isConnectable:t,targetPosition:n=at.Top}){return l.jsxs(l.Fragment,{children:[l.jsx(bo,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label]})}const Ff={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Tw={input:X9,default:V9,output:G9,group:W9};function K9(e){var t,n,i,a;return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??((t=e.style)==null?void 0:t.width),height:e.height??e.initialHeight??((n=e.style)==null?void 0:n.height)}:{width:e.width??((i=e.style)==null?void 0:i.width),height:e.height??((a=e.style)==null?void 0:a.height)}}const Q9=e=>{const{width:t,height:n,x:i,y:a}=au(e.nodeLookup,{filter:o=>!!o.selected});return{width:ji(t)?t:null,height:ji(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${i}px,${a}px)`}};function Z9({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const i=Dn(),{width:a,height:o,transformString:c,userSelectionActive:d}=qt(Q9,An),m=o3(),f=S.useRef(null);S.useEffect(()=>{var g;n||(g=f.current)==null||g.focus({preventScroll:!0})},[n]);const x=!d&&a!==null&&o!==null;if(l3({nodeRef:f,disabled:!x}),!x)return null;const p=e?g=>{const w=i.getState().nodes.filter(k=>k.selected);e(g,w)}:void 0,y=g=>{Object.prototype.hasOwnProperty.call(Ff,g.key)&&(g.preventDefault(),m({direction:Ff[g.key],factor:g.shiftKey?4:1}))};return l.jsx("div",{className:Yn(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c},children:l.jsx("div",{ref:f,className:"react-flow__nodesselection-rect",onContextMenu:p,tabIndex:n?void 0:-1,onKeyDown:n?void 0:y,style:{width:a,height:o}})})}const _w=typeof window<"u"?window:void 0,J9=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function u3({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:a,onPaneContextMenu:o,onPaneScroll:c,paneClickDistance:d,deleteKeyCode:m,selectionKeyCode:f,selectionOnDrag:x,selectionMode:p,onSelectionStart:y,onSelectionEnd:g,multiSelectionKeyCode:w,panActivationKeyCode:k,zoomActivationKeyCode:j,elementsSelectable:C,zoomOnScroll:N,zoomOnPinch:E,panOnScroll:A,panOnScrollSpeed:z,panOnScrollMode:D,zoomOnDoubleClick:F,panOnDrag:q,defaultViewport:V,translateExtent:L,minZoom:_,maxZoom:B,preventScrolling:X,onSelectionContextMenu:R,noWheelClassName:H,noPanClassName:$,disableKeyboardA11y:G,onViewportChange:Q,isControlledViewport:K}){const{nodesSelectionActive:M,userSelectionActive:U}=qt(J9,An),P=Gc(f,{target:_w}),O=Gc(k,{target:_w}),Z=O||q,ee=O||A,J=x&&Z!==!0,se=P||U||J;return F9({deleteKeyCode:m,multiSelectionKeyCode:w}),l.jsx(B9,{onPaneContextMenu:o,elementsSelectable:C,zoomOnScroll:N,zoomOnPinch:E,panOnScroll:ee,panOnScrollSpeed:z,panOnScrollMode:D,zoomOnDoubleClick:F,panOnDrag:!P&&Z,defaultViewport:V,translateExtent:L,minZoom:_,maxZoom:B,zoomActivationKeyCode:j,preventScrolling:X,noWheelClassName:H,noPanClassName:$,onViewportChange:Q,isControlledViewport:K,paneClickDistance:d,selectionOnDrag:J,children:l.jsxs(I9,{onSelectionStart:y,onSelectionEnd:g,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:a,onPaneContextMenu:o,onPaneScroll:c,panOnDrag:Z,isSelecting:!!se,selectionMode:p,selectionKeyPressed:P,paneClickDistance:d,selectionOnDrag:J,children:[e,M&&l.jsx(Z9,{onSelectionContextMenu:R,noPanClassName:$,disableKeyboardA11y:G})]})})}u3.displayName="FlowRenderer";const e7=S.memo(u3),t7=e=>t=>e?T0(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 n7(e){return qt(S.useCallback(t7(e),[e]),An)}const r7=e=>e.updateNodeInternals;function i7(){const e=qt(r7),[t]=S.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const i=new Map;n.forEach(a=>{const o=a.target.getAttribute("data-id");i.set(o,{id:o,nodeElement:a.target,force:!0})}),e(i)}));return S.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function s7({node:e,nodeType:t,hasDimensions:n,resizeObserver:i}){const a=Dn(),o=S.useRef(null),c=S.useRef(null),d=S.useRef(e.sourcePosition),m=S.useRef(e.targetPosition),f=S.useRef(t),x=n&&!!e.internals.handleBounds;return S.useEffect(()=>{o.current&&!e.hidden&&(!x||c.current!==o.current)&&(c.current&&(i==null||i.unobserve(c.current)),i==null||i.observe(o.current),c.current=o.current)},[x,e.hidden]),S.useEffect(()=>()=>{c.current&&(i==null||i.unobserve(c.current),c.current=null)},[]),S.useEffect(()=>{if(o.current){const p=f.current!==t,y=d.current!==e.sourcePosition,g=m.current!==e.targetPosition;(p||y||g)&&(f.current=t,d.current=e.sourcePosition,m.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 a7({id:e,onClick:t,onMouseEnter:n,onMouseMove:i,onMouseLeave:a,onContextMenu:o,onDoubleClick:c,nodesDraggable:d,elementsSelectable:m,nodesConnectable:f,nodesFocusable:x,resizeObserver:p,noDragClassName:y,noPanClassName:g,disableKeyboardA11y:w,rfId:k,nodeTypes:j,nodeClickDistance:C,onError:N}){const{node:E,internals:A,isParent:z}=qt(le=>{const ye=le.nodeLookup.get(e),De=le.parentLookup.has(e);return{node:ye,internals:ye.internals,isParent:De}},An);let D=E.type||"default",F=(j==null?void 0:j[D])||Tw[D];F===void 0&&(N==null||N("003",Ji.error003(D)),D="default",F=(j==null?void 0:j.default)||Tw.default);const q=!!(E.draggable||d&&typeof E.draggable>"u"),V=!!(E.selectable||m&&typeof E.selectable>"u"),L=!!(E.connectable||f&&typeof E.connectable>"u"),_=!!(E.focusable||x&&typeof E.focusable>"u"),B=Dn(),X=Fk(E),R=s7({node:E,nodeType:D,hasDimensions:X,resizeObserver:p}),H=l3({nodeRef:R,disabled:E.hidden||!q,noDragClassName:y,handleSelector:E.dragHandle,nodeId:e,isSelectable:V,nodeClickDistance:C}),$=o3();if(E.hidden)return null;const G=Os(E),Q=K9(E),K=V||q||t||n||i||a,M=n?le=>n(le,{...A.userNode}):void 0,U=i?le=>i(le,{...A.userNode}):void 0,P=a?le=>a(le,{...A.userNode}):void 0,O=o?le=>o(le,{...A.userNode}):void 0,Z=c?le=>c(le,{...A.userNode}):void 0,ee=le=>{const{selectNodesOnDrag:ye,nodeDragThreshold:De}=B.getState();V&&(!ye||!q||De>0)&&$x({id:e,store:B,nodeRef:R}),t&&t(le,{...A.userNode})},J=le=>{if(!(Bk(le.nativeEvent)||w)){if(jk.includes(le.key)&&V){const ye=le.key==="Escape";$x({id:e,store:B,unselect:ye,nodeRef:R})}else if(q&&E.selected&&Object.prototype.hasOwnProperty.call(Ff,le.key)){le.preventDefault();const{ariaLabelConfig:ye}=B.getState();B.setState({ariaLiveMessage:ye["node.a11yDescription.ariaLiveMessage"]({direction:le.key.replace("Arrow","").toLowerCase(),x:~~A.positionAbsolute.x,y:~~A.positionAbsolute.y})}),$({direction:Ff[le.key],factor:le.shiftKey?4:1})}}},se=()=>{var Fe;if(w||!((Fe=R.current)!=null&&Fe.matches(":focus-visible")))return;const{transform:le,width:ye,height:De,autoPanOnNodeFocus:Ee,setCenter:Re}=B.getState();if(!Ee)return;T0(new Map([[e,E]]),{x:0,y:0,width:ye,height:De},le,!0).length>0||Re(E.position.x+G.width/2,E.position.y+G.height/2,{zoom:le[2]})};return l.jsx("div",{className:Yn(["react-flow__node",`react-flow__node-${D}`,{[g]:q},E.className,{selected:E.selected,selectable:V,parent:z,draggable:q,dragging:H}]),ref:R,style:{zIndex:A.z,transform:`translate(${A.positionAbsolute.x}px,${A.positionAbsolute.y}px)`,pointerEvents:K?"all":"none",visibility:X?"visible":"hidden",...E.style,...Q},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:M,onMouseMove:U,onMouseLeave:P,onContextMenu:O,onClick:ee,onDoubleClick:Z,onKeyDown:_?J:void 0,tabIndex:_?0:void 0,onFocus:_?se:void 0,role:E.ariaRole??(_?"group":void 0),"aria-roledescription":"node","aria-describedby":w?void 0:`${t3}-${k}`,"aria-label":E.ariaLabel,...E.domAttributes,children:l.jsx(U9,{value:e,children:l.jsx(F,{id:e,data:E.data,type:D,positionAbsoluteX:A.positionAbsolute.x,positionAbsoluteY:A.positionAbsolute.y,selected:E.selected??!1,selectable:V,draggable:q,deletable:E.deletable??!0,isConnectable:L,sourcePosition:E.sourcePosition,targetPosition:E.targetPosition,dragging:H,dragHandle:E.dragHandle,zIndex:A.z,parentId:E.parentId,...G})})})}var l7=S.memo(a7);const o7=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function d3(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:a,onError:o}=qt(o7,An),c=n7(e.onlyRenderVisibleElements),d=i7();return l.jsx("div",{className:"react-flow__nodes",style:Qf,children:c.map(m=>l.jsx(l7,{id:m,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:d,nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:a,nodeClickDistance:e.nodeClickDistance,onError:o},m))})}d3.displayName="NodeRenderer";const c7=S.memo(d3);function u7(e){return qt(S.useCallback(n=>{if(!e)return n.edges.map(a=>a.id);const i=[];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&&az({sourceNode:o,targetNode:c,width:n.width,height:n.height,transform:n.transform})&&i.push(a.id)}return i},[e]),An)}const d7=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return l.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},f7=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return l.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Mw={[Df.Arrow]:d7,[Df.ArrowClosed]:f7};function h7(e){const t=Dn();return S.useMemo(()=>{var a,o;return Object.prototype.hasOwnProperty.call(Mw,e)?Mw[e]:((o=(a=t.getState()).onError)==null||o.call(a,"009",Ji.error009(e)),null)},[e])}const m7=({id:e,type:t,color:n,width:i=12.5,height:a=12.5,markerUnits:o="strokeWidth",strokeWidth:c,orient:d="auto-start-reverse"})=>{const m=h7(t);return m?l.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${i}`,markerHeight:`${a}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:d,refX:"0",refY:"0",children:l.jsx(m,{color:n,strokeWidth:c})}):null},f3=({defaultColor:e,rfId:t})=>{const n=qt(o=>o.edges),i=qt(o=>o.defaultEdgeOptions),a=S.useMemo(()=>mz(n,{id:t,defaultColor:e,defaultMarkerStart:i==null?void 0:i.markerStart,defaultMarkerEnd:i==null?void 0:i.markerEnd}),[n,i,t,e]);return a.length?l.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:l.jsx("defs",{children:a.map(o=>l.jsx(m7,{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};f3.displayName="MarkerDefinitions";var p7=S.memo(f3);function h3({x:e,y:t,label:n,labelStyle:i,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:d=2,children:m,className:f,...x}){const[p,y]=S.useState({x:1,y:0,width:0,height:0}),g=Yn(["react-flow__edge-textwrapper",f]),w=S.useRef(null);return S.useEffect(()=>{if(w.current){const k=w.current.getBBox();y({x:k.x,y:k.y,width:k.width,height:k.height})}},[n]),n?l.jsxs("g",{transform:`translate(${e-p.width/2} ${t-p.height/2})`,className:g,visibility:p.width?"visible":"hidden",...x,children:[a&&l.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}),l.jsx("text",{className:"react-flow__edge-text",y:p.height/2,dy:"0.3em",ref:w,style:i,children:n}),m]}):null}h3.displayName="EdgeText";const x7=S.memo(h3);function cu({path:e,labelX:t,labelY:n,label:i,labelStyle:a,labelShowBg:o,labelBgStyle:c,labelBgPadding:d,labelBgBorderRadius:m,interactionWidth:f=20,...x}){return l.jsxs(l.Fragment,{children:[l.jsx("path",{...x,d:e,fill:"none",className:Yn(["react-flow__edge-path",x.className])}),f?l.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}):null,i&&ji(t)&&ji(n)?l.jsx(x7,{x:t,y:n,label:i,labelStyle:a,labelShowBg:o,labelBgStyle:c,labelBgPadding:d,labelBgBorderRadius:m}):null]})}function Fw({pos:e,x1:t,y1:n,x2:i,y2:a}){return e===at.Left||e===at.Right?[.5*(t+i),n]:[t,.5*(n+a)]}function m3({sourceX:e,sourceY:t,sourcePosition:n=at.Bottom,targetX:i,targetY:a,targetPosition:o=at.Top}){const[c,d]=Fw({pos:n,x1:e,y1:t,x2:i,y2:a}),[m,f]=Fw({pos:o,x1:i,y1:a,x2:e,y2:t}),[x,p,y,g]=Ok({sourceX:e,sourceY:t,targetX:i,targetY:a,sourceControlX:c,sourceControlY:d,targetControlX:m,targetControlY:f});return[`M${e},${t} C${c},${d} ${m},${f} ${i},${a}`,x,p,y,g]}function p3(e){return S.memo(({id:t,sourceX:n,sourceY:i,targetX:a,targetY:o,sourcePosition:c,targetPosition:d,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:p,labelBgPadding:y,labelBgBorderRadius:g,style:w,markerEnd:k,markerStart:j,interactionWidth:C})=>{const[N,E,A]=m3({sourceX:n,sourceY:i,sourcePosition:c,targetX:a,targetY:o,targetPosition:d}),z=e.isInternal?void 0:t;return l.jsx(cu,{id:z,path:N,labelX:E,labelY:A,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:p,labelBgPadding:y,labelBgBorderRadius:g,style:w,markerEnd:k,markerStart:j,interactionWidth:C})})}const g7=p3({isInternal:!1}),x3=p3({isInternal:!0});g7.displayName="SimpleBezierEdge";x3.displayName="SimpleBezierEdgeInternal";function g3(e){return S.memo(({id:t,sourceX:n,sourceY:i,targetX:a,targetY:o,label:c,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:p,style:y,sourcePosition:g=at.Bottom,targetPosition:w=at.Top,markerEnd:k,markerStart:j,pathOptions:C,interactionWidth:N})=>{const[E,A,z]=Mf({sourceX:n,sourceY:i,sourcePosition:g,targetX:a,targetY:o,targetPosition:w,borderRadius:C==null?void 0:C.borderRadius,offset:C==null?void 0:C.offset,stepPosition:C==null?void 0:C.stepPosition}),D=e.isInternal?void 0:t;return l.jsx(cu,{id:D,path:E,labelX:A,labelY:z,label:c,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:p,style:y,markerEnd:k,markerStart:j,interactionWidth:N})})}const y3=g3({isInternal:!1}),b3=g3({isInternal:!0});y3.displayName="SmoothStepEdge";b3.displayName="SmoothStepEdgeInternal";function v3(e){return S.memo(({id:t,...n})=>{var a;const i=e.isInternal?void 0:t;return l.jsx(y3,{...n,id:i,pathOptions:S.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset])})})}const y7=v3({isInternal:!1}),w3=v3({isInternal:!0});y7.displayName="StepEdge";w3.displayName="StepEdgeInternal";function k3(e){return S.memo(({id:t,sourceX:n,sourceY:i,targetX:a,targetY:o,label:c,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:p,style:y,markerEnd:g,markerStart:w,interactionWidth:k})=>{const[j,C,N]=Hk({sourceX:n,sourceY:i,targetX:a,targetY:o}),E=e.isInternal?void 0:t;return l.jsx(cu,{id:E,path:j,labelX:C,labelY:N,label:c,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:p,style:y,markerEnd:g,markerStart:w,interactionWidth:k})})}const b7=k3({isInternal:!1}),S3=k3({isInternal:!0});b7.displayName="StraightEdge";S3.displayName="StraightEdgeInternal";function j3(e){return S.memo(({id:t,sourceX:n,sourceY:i,targetX:a,targetY:o,sourcePosition:c=at.Bottom,targetPosition:d=at.Top,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:p,labelBgPadding:y,labelBgBorderRadius:g,style:w,markerEnd:k,markerStart:j,pathOptions:C,interactionWidth:N})=>{const[E,A,z]=Lk({sourceX:n,sourceY:i,sourcePosition:c,targetX:a,targetY:o,targetPosition:d,curvature:C==null?void 0:C.curvature}),D=e.isInternal?void 0:t;return l.jsx(cu,{id:D,path:E,labelX:A,labelY:z,label:m,labelStyle:f,labelShowBg:x,labelBgStyle:p,labelBgPadding:y,labelBgBorderRadius:g,style:w,markerEnd:k,markerStart:j,interactionWidth:N})})}const v7=j3({isInternal:!1}),C3=j3({isInternal:!0});v7.displayName="BezierEdge";C3.displayName="BezierEdgeInternal";const Rw={default:C3,straight:S3,step:w3,smoothstep:b3,simplebezier:x3},zw={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},w7=(e,t,n)=>n===at.Left?e-t:n===at.Right?e+t:e,k7=(e,t,n)=>n===at.Top?e-t:n===at.Bottom?e+t:e,Bw="react-flow__edgeupdater";function $w({position:e,centerX:t,centerY:n,radius:i=10,onMouseDown:a,onMouseEnter:o,onMouseOut:c,type:d}){return l.jsx("circle",{onMouseDown:a,onMouseEnter:o,onMouseOut:c,className:Yn([Bw,`${Bw}-${d}`]),cx:w7(t,i,e),cy:k7(n,i,e),r:i,stroke:"transparent",fill:"transparent"})}function S7({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:i,sourceY:a,targetX:o,targetY:c,sourcePosition:d,targetPosition:m,onReconnect:f,onReconnectStart:x,onReconnectEnd:p,setReconnecting:y,setUpdateHover:g}){const w=Dn(),k=(A,z)=>{if(A.button!==0)return;const{autoPanOnConnect:D,domNode:F,connectionMode:q,connectionRadius:V,lib:L,onConnectStart:_,cancelConnection:B,nodeLookup:X,rfId:R,panBy:H,updateConnection:$}=w.getState(),G=z.type==="target",Q=(U,P)=>{y(!1),p==null||p(U,n,z.type,P)},K=U=>f==null?void 0:f(n,U),M=(U,P)=>{y(!0),x==null||x(A,n,z.type),_==null||_(U,P)};Bx.onPointerDown(A.nativeEvent,{autoPanOnConnect:D,connectionMode:q,connectionRadius:V,domNode:F,handleId:z.id,nodeId:z.nodeId,nodeLookup:X,isTarget:G,edgeUpdaterType:z.type,lib:L,flowId:R,cancelConnection:B,panBy:H,isValidConnection:(...U)=>{var P,O;return((O=(P=w.getState()).isValidConnection)==null?void 0:O.call(P,...U))??!0},onConnect:K,onConnectStart:M,onConnectEnd:(...U)=>{var P,O;return(O=(P=w.getState()).onConnectEnd)==null?void 0:O.call(P,...U)},onReconnectEnd:Q,updateConnection:$,getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,dragThreshold:w.getState().connectionDragThreshold,handleDomNode:A.currentTarget})},j=A=>k(A,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),C=A=>k(A,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),N=()=>g(!0),E=()=>g(!1);return l.jsxs(l.Fragment,{children:[(e===!0||e==="source")&&l.jsx($w,{position:d,centerX:i,centerY:a,radius:t,onMouseDown:j,onMouseEnter:N,onMouseOut:E,type:"source"}),(e===!0||e==="target")&&l.jsx($w,{position:m,centerX:o,centerY:c,radius:t,onMouseDown:C,onMouseEnter:N,onMouseOut:E,type:"target"})]})}function j7({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:i,onClick:a,onDoubleClick:o,onContextMenu:c,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,reconnectRadius:x,onReconnect:p,onReconnectStart:y,onReconnectEnd:g,rfId:w,edgeTypes:k,noPanClassName:j,onError:C,disableKeyboardA11y:N}){let E=qt(Re=>Re.edgeLookup.get(e));const A=qt(Re=>Re.defaultEdgeOptions);E=A?{...A,...E}:E;let z=E.type||"default",D=(k==null?void 0:k[z])||Rw[z];D===void 0&&(C==null||C("011",Ji.error011(z)),z="default",D=(k==null?void 0:k.default)||Rw.default);const F=!!(E.focusable||t&&typeof E.focusable>"u"),q=typeof p<"u"&&(E.reconnectable||n&&typeof E.reconnectable>"u"),V=!!(E.selectable||i&&typeof E.selectable>"u"),L=S.useRef(null),[_,B]=S.useState(!1),[X,R]=S.useState(!1),H=Dn(),{zIndex:$,sourceX:G,sourceY:Q,targetX:K,targetY:M,sourcePosition:U,targetPosition:P}=qt(S.useCallback(Re=>{const me=Re.nodeLookup.get(E.source),Fe=Re.nodeLookup.get(E.target);if(!me||!Fe)return{zIndex:E.zIndex,...zw};const Je=hz({id:e,sourceNode:me,targetNode:Fe,sourceHandle:E.sourceHandle||null,targetHandle:E.targetHandle||null,connectionMode:Re.connectionMode,onError:C});return{zIndex:sz({selected:E.selected,zIndex:E.zIndex,sourceNode:me,targetNode:Fe,elevateOnSelect:Re.elevateEdgesOnSelect,zIndexMode:Re.zIndexMode}),...Je||zw}},[E.source,E.target,E.sourceHandle,E.targetHandle,E.selected,E.zIndex]),An),O=S.useMemo(()=>E.markerStart?`url('#${Rx(E.markerStart,w)}')`:void 0,[E.markerStart,w]),Z=S.useMemo(()=>E.markerEnd?`url('#${Rx(E.markerEnd,w)}')`:void 0,[E.markerEnd,w]);if(E.hidden||G===null||Q===null||K===null||M===null)return null;const ee=Re=>{var Pe;const{addSelectedEdges:me,unselectNodesAndEdges:Fe,multiSelectionActive:Je}=H.getState();V&&(H.setState({nodesSelectionActive:!1}),E.selected&&Je?(Fe({nodes:[],edges:[E]}),(Pe=L.current)==null||Pe.blur()):me([e])),a&&a(Re,E)},J=o?Re=>{o(Re,{...E})}:void 0,se=c?Re=>{c(Re,{...E})}:void 0,le=d?Re=>{d(Re,{...E})}:void 0,ye=m?Re=>{m(Re,{...E})}:void 0,De=f?Re=>{f(Re,{...E})}:void 0,Ee=Re=>{var me;if(!N&&jk.includes(Re.key)&&V){const{unselectNodesAndEdges:Fe,addSelectedEdges:Je}=H.getState();Re.key==="Escape"?((me=L.current)==null||me.blur(),Fe({edges:[E]})):Je([e])}};return l.jsx("svg",{style:{zIndex:$},children:l.jsxs("g",{className:Yn(["react-flow__edge",`react-flow__edge-${z}`,E.className,j,{selected:E.selected,animated:E.animated,inactive:!V&&!a,updating:_,selectable:V}]),onClick:ee,onDoubleClick:J,onContextMenu:se,onMouseEnter:le,onMouseMove:ye,onMouseLeave:De,onKeyDown:F?Ee:void 0,tabIndex:F?0:void 0,role:E.ariaRole??(F?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":E.ariaLabel===null?void 0:E.ariaLabel||`Edge from ${E.source} to ${E.target}`,"aria-describedby":F?`${n3}-${w}`:void 0,ref:L,...E.domAttributes,children:[!X&&l.jsx(D,{id:e,source:E.source,target:E.target,type:E.type,selected:E.selected,animated:E.animated,selectable:V,deletable:E.deletable??!0,label:E.label,labelStyle:E.labelStyle,labelShowBg:E.labelShowBg,labelBgStyle:E.labelBgStyle,labelBgPadding:E.labelBgPadding,labelBgBorderRadius:E.labelBgBorderRadius,sourceX:G,sourceY:Q,targetX:K,targetY:M,sourcePosition:U,targetPosition:P,data:E.data,style:E.style,sourceHandleId:E.sourceHandle,targetHandleId:E.targetHandle,markerStart:O,markerEnd:Z,pathOptions:"pathOptions"in E?E.pathOptions:void 0,interactionWidth:E.interactionWidth}),q&&l.jsx(S7,{edge:E,isReconnectable:q,reconnectRadius:x,onReconnect:p,onReconnectStart:y,onReconnectEnd:g,sourceX:G,sourceY:Q,targetX:K,targetY:M,sourcePosition:U,targetPosition:P,setUpdateHover:B,setReconnecting:R})]})})}var C7=S.memo(j7);const N7=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function N3({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:i,noPanClassName:a,onReconnect:o,onEdgeContextMenu:c,onEdgeMouseEnter:d,onEdgeMouseMove:m,onEdgeMouseLeave:f,onEdgeClick:x,reconnectRadius:p,onEdgeDoubleClick:y,onReconnectStart:g,onReconnectEnd:w,disableKeyboardA11y:k}){const{edgesFocusable:j,edgesReconnectable:C,elementsSelectable:N,onError:E}=qt(N7,An),A=u7(t);return l.jsxs("div",{className:"react-flow__edges",children:[l.jsx(p7,{defaultColor:e,rfId:n}),A.map(z=>l.jsx(C7,{id:z,edgesFocusable:j,edgesReconnectable:C,elementsSelectable:N,noPanClassName:a,onReconnect:o,onContextMenu:c,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onClick:x,reconnectRadius:p,onDoubleClick:y,onReconnectStart:g,onReconnectEnd:w,rfId:n,onError:E,edgeTypes:i,disableKeyboardA11y:k},z))]})}N3.displayName="EdgeRenderer";const E7=S.memo(N3),A7=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function D7({children:e}){const t=qt(A7);return l.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function T7(e){const t=O0(),n=S.useRef(!1);S.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const _7=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function M7(e){const t=qt(_7),n=Dn();return S.useEffect(()=>{e&&(t==null||t(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function F7(e){return e.connection.inProgress?{...e.connection,to:ou(e.connection.to,e.transform)}:{...e.connection}}function R7(e){return F7}function z7(e){const t=R7();return qt(t,An)}const B7=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function $7({containerStyle:e,style:t,type:n,component:i}){const{nodesConnectable:a,width:o,height:c,isValid:d,inProgress:m}=qt(B7,An);return!(o&&a&&m)?null:l.jsx("svg",{style:e,width:o,height:c,className:"react-flow__connectionline react-flow__container",children:l.jsx("g",{className:Yn(["react-flow__connection",Ek(d)]),children:l.jsx(E3,{style:t,type:n,CustomComponent:i,isValid:d})})})}const E3=({style:e,type:t=ja.Bezier,CustomComponent:n,isValid:i})=>{const{inProgress:a,from:o,fromNode:c,fromHandle:d,fromPosition:m,to:f,toNode:x,toHandle:p,toPosition:y,pointer:g}=z7();if(!a)return;if(n)return l.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:c,fromHandle:d,fromX:o.x,fromY:o.y,toX:f.x,toY:f.y,fromPosition:m,toPosition:y,connectionStatus:Ek(i),toNode:x,toHandle:p,pointer:g});let w="";const k={sourceX:o.x,sourceY:o.y,sourcePosition:m,targetX:f.x,targetY:f.y,targetPosition:y};switch(t){case ja.Bezier:[w]=Lk(k);break;case ja.SimpleBezier:[w]=m3(k);break;case ja.Step:[w]=Mf({...k,borderRadius:0});break;case ja.SmoothStep:[w]=Mf(k);break;default:[w]=Hk(k)}return l.jsx("path",{d:w,fill:"none",className:"react-flow__connection-path",style:e})};E3.displayName="ConnectionLine";const O7={};function Ow(e=O7){S.useRef(e),Dn(),S.useEffect(()=>{},[e])}function L7(){Dn(),S.useRef(!1),S.useEffect(()=>{},[])}function A3({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:i,onEdgeClick:a,onNodeDoubleClick:o,onEdgeDoubleClick:c,onNodeMouseEnter:d,onNodeMouseMove:m,onNodeMouseLeave:f,onNodeContextMenu:x,onSelectionContextMenu:p,onSelectionStart:y,onSelectionEnd:g,connectionLineType:w,connectionLineStyle:k,connectionLineComponent:j,connectionLineContainerStyle:C,selectionKeyCode:N,selectionOnDrag:E,selectionMode:A,multiSelectionKeyCode:z,panActivationKeyCode:D,zoomActivationKeyCode:F,deleteKeyCode:q,onlyRenderVisibleElements:V,elementsSelectable:L,defaultViewport:_,translateExtent:B,minZoom:X,maxZoom:R,preventScrolling:H,defaultMarkerColor:$,zoomOnScroll:G,zoomOnPinch:Q,panOnScroll:K,panOnScrollSpeed:M,panOnScrollMode:U,zoomOnDoubleClick:P,panOnDrag:O,onPaneClick:Z,onPaneMouseEnter:ee,onPaneMouseMove:J,onPaneMouseLeave:se,onPaneScroll:le,onPaneContextMenu:ye,paneClickDistance:De,nodeClickDistance:Ee,onEdgeContextMenu:Re,onEdgeMouseEnter:me,onEdgeMouseMove:Fe,onEdgeMouseLeave:Je,reconnectRadius:Pe,onReconnect:it,onReconnectStart:ht,onReconnectEnd:Ye,noDragClassName:nt,noWheelClassName:ut,noPanClassName:kt,disableKeyboardA11y:mt,nodeExtent:ve,rfId:be,viewport:te,onViewportChange:oe}){return Ow(e),Ow(t),L7(),T7(n),M7(te),l.jsx(e7,{onPaneClick:Z,onPaneMouseEnter:ee,onPaneMouseMove:J,onPaneMouseLeave:se,onPaneContextMenu:ye,onPaneScroll:le,paneClickDistance:De,deleteKeyCode:q,selectionKeyCode:N,selectionOnDrag:E,selectionMode:A,onSelectionStart:y,onSelectionEnd:g,multiSelectionKeyCode:z,panActivationKeyCode:D,zoomActivationKeyCode:F,elementsSelectable:L,zoomOnScroll:G,zoomOnPinch:Q,zoomOnDoubleClick:P,panOnScroll:K,panOnScrollSpeed:M,panOnScrollMode:U,panOnDrag:O,defaultViewport:_,translateExtent:B,minZoom:X,maxZoom:R,onSelectionContextMenu:p,preventScrolling:H,noDragClassName:nt,noWheelClassName:ut,noPanClassName:kt,disableKeyboardA11y:mt,onViewportChange:oe,isControlledViewport:!!te,children:l.jsxs(D7,{children:[l.jsx(E7,{edgeTypes:t,onEdgeClick:a,onEdgeDoubleClick:c,onReconnect:it,onReconnectStart:ht,onReconnectEnd:Ye,onlyRenderVisibleElements:V,onEdgeContextMenu:Re,onEdgeMouseEnter:me,onEdgeMouseMove:Fe,onEdgeMouseLeave:Je,reconnectRadius:Pe,defaultMarkerColor:$,noPanClassName:kt,disableKeyboardA11y:mt,rfId:be}),l.jsx($7,{style:k,type:w,component:j,containerStyle:C}),l.jsx("div",{className:"react-flow__edgelabel-renderer"}),l.jsx(c7,{nodeTypes:e,onNodeClick:i,onNodeDoubleClick:o,onNodeMouseEnter:d,onNodeMouseMove:m,onNodeMouseLeave:f,onNodeContextMenu:x,nodeClickDistance:Ee,onlyRenderVisibleElements:V,noPanClassName:kt,noDragClassName:nt,disableKeyboardA11y:mt,nodeExtent:ve,rfId:be}),l.jsx("div",{className:"react-flow__viewport-portal"})]})})}A3.displayName="GraphView";const I7=S.memo(A3),Lw=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:a,height:o,fitView:c,fitViewOptions:d,minZoom:m=.5,maxZoom:f=2,nodeOrigin:x,nodeExtent:p,zIndexMode:y="basic"}={})=>{const g=new Map,w=new Map,k=new Map,j=new Map,C=i??t??[],N=n??e??[],E=x??[0,0],A=p??Pc;Yk(k,j,C);const z=zx(N,g,w,{nodeOrigin:E,nodeExtent:A,zIndexMode:y});let D=[0,0,1];if(c&&a&&o){const F=au(g,{filter:_=>!!((_.width||_.initialWidth)&&(_.height||_.initialHeight))}),{x:q,y:V,zoom:L}=_0(F,a,o,m,f,(d==null?void 0:d.padding)??.1);D=[q,V,L]}return{rfId:"1",width:a??0,height:o??0,transform:D,nodes:N,nodesInitialized:z,nodeLookup:g,parentLookup:w,edges:C,edgeLookup:j,connectionLookup:k,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:i!==void 0,panZoom:null,minZoom:m,maxZoom:f,translateExtent:Pc,nodeExtent:A,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:mo.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:E,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:{...Nk},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:JR,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Ck,zIndexMode:y,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},H7=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:a,height:o,fitView:c,fitViewOptions:d,minZoom:m,maxZoom:f,nodeOrigin:x,nodeExtent:p,zIndexMode:y})=>r9((g,w)=>{async function k(){const{nodeLookup:j,panZoom:C,fitViewOptions:N,fitViewResolver:E,width:A,height:z,minZoom:D,maxZoom:F}=w();C&&(await QR({nodes:j,width:A,height:z,panZoom:C,minZoom:D,maxZoom:F},N),E==null||E.resolve(!0),g({fitViewResolver:null}))}return{...Lw({nodes:e,edges:t,width:a,height:o,fitView:c,fitViewOptions:d,minZoom:m,maxZoom:f,nodeOrigin:x,nodeExtent:p,defaultNodes:n,defaultEdges:i,zIndexMode:y}),setNodes:j=>{const{nodeLookup:C,parentLookup:N,nodeOrigin:E,elevateNodesOnSelect:A,fitViewQueued:z,zIndexMode:D}=w(),F=zx(j,C,N,{nodeOrigin:E,nodeExtent:p,elevateNodesOnSelect:A,checkEquality:!0,zIndexMode:D});z&&F?(k(),g({nodes:j,nodesInitialized:F,fitViewQueued:!1,fitViewOptions:void 0})):g({nodes:j,nodesInitialized:F})},setEdges:j=>{const{connectionLookup:C,edgeLookup:N}=w();Yk(C,N,j),g({edges:j})},setDefaultNodesAndEdges:(j,C)=>{if(j){const{setNodes:N}=w();N(j),g({hasDefaultNodes:!0})}if(C){const{setEdges:N}=w();N(C),g({hasDefaultEdges:!0})}},updateNodeInternals:j=>{const{triggerNodeChanges:C,nodeLookup:N,parentLookup:E,domNode:A,nodeOrigin:z,nodeExtent:D,debug:F,fitViewQueued:q,zIndexMode:V}=w(),{changes:L,updatedInternals:_}=wz(j,N,E,A,z,D,V);_&&(gz(N,E,{nodeOrigin:z,nodeExtent:D,zIndexMode:V}),q?(k(),g({fitViewQueued:!1,fitViewOptions:void 0})):g({}),(L==null?void 0:L.length)>0&&(F&&console.log("React Flow: trigger node changes",L),C==null||C(L)))},updateNodePositions:(j,C=!1)=>{const N=[];let E=[];const{nodeLookup:A,triggerNodeChanges:z,connection:D,updateConnection:F,onNodesChangeMiddlewareMap:q}=w();for(const[V,L]of j){const _=A.get(V),B=!!(_!=null&&_.expandParent&&(_!=null&&_.parentId)&&(L!=null&&L.position)),X={id:V,type:"position",position:B?{x:Math.max(0,L.position.x),y:Math.max(0,L.position.y)}:L.position,dragging:C};if(_&&D.inProgress&&D.fromNode.id===_.id){const R=yl(_,D.fromHandle,at.Left,!0);F({...D,from:R})}B&&_.parentId&&N.push({id:V,parentId:_.parentId,rect:{...L.internals.positionAbsolute,width:L.measured.width??0,height:L.measured.height??0}}),E.push(X)}if(N.length>0){const{parentLookup:V,nodeOrigin:L}=w(),_=$0(N,A,V,L);E.push(..._)}for(const V of q.values())E=V(E);z(E)},triggerNodeChanges:j=>{const{onNodesChange:C,setNodes:N,nodes:E,hasDefaultNodes:A,debug:z}=w();if(j!=null&&j.length){if(A){const D=j9(j,E);N(D)}z&&console.log("React Flow: trigger node changes",j),C==null||C(j)}},triggerEdgeChanges:j=>{const{onEdgesChange:C,setEdges:N,edges:E,hasDefaultEdges:A,debug:z}=w();if(j!=null&&j.length){if(A){const D=C9(j,E);N(D)}z&&console.log("React Flow: trigger edge changes",j),C==null||C(j)}},addSelectedNodes:j=>{const{multiSelectionActive:C,edgeLookup:N,nodeLookup:E,triggerNodeChanges:A,triggerEdgeChanges:z}=w();if(C){const D=j.map(F=>rl(F,!0));A(D);return}A(ro(E,new Set([...j]),!0)),z(ro(N))},addSelectedEdges:j=>{const{multiSelectionActive:C,edgeLookup:N,nodeLookup:E,triggerNodeChanges:A,triggerEdgeChanges:z}=w();if(C){const D=j.map(F=>rl(F,!0));z(D);return}z(ro(N,new Set([...j]))),A(ro(E,new Set,!0))},unselectNodesAndEdges:({nodes:j,edges:C}={})=>{const{edges:N,nodes:E,nodeLookup:A,triggerNodeChanges:z,triggerEdgeChanges:D}=w(),F=j||E,q=C||N,V=[];for(const _ of F){if(!_.selected)continue;const B=A.get(_.id);B&&(B.selected=!1),V.push(rl(_.id,!1))}const L=[];for(const _ of q)_.selected&&L.push(rl(_.id,!1));z(V),D(L)},setMinZoom:j=>{const{panZoom:C,maxZoom:N}=w();C==null||C.setScaleExtent([j,N]),g({minZoom:j})},setMaxZoom:j=>{const{panZoom:C,minZoom:N}=w();C==null||C.setScaleExtent([N,j]),g({maxZoom:j})},setTranslateExtent:j=>{var C;(C=w().panZoom)==null||C.setTranslateExtent(j),g({translateExtent:j})},resetSelectedElements:()=>{const{edges:j,nodes:C,triggerNodeChanges:N,triggerEdgeChanges:E,elementsSelectable:A}=w();if(!A)return;const z=C.reduce((F,q)=>q.selected?[...F,rl(q.id,!1)]:F,[]),D=j.reduce((F,q)=>q.selected?[...F,rl(q.id,!1)]:F,[]);N(z),E(D)},setNodeExtent:j=>{const{nodes:C,nodeLookup:N,parentLookup:E,nodeOrigin:A,elevateNodesOnSelect:z,nodeExtent:D,zIndexMode:F}=w();j[0][0]===D[0][0]&&j[0][1]===D[0][1]&&j[1][0]===D[1][0]&&j[1][1]===D[1][1]||(zx(C,N,E,{nodeOrigin:A,nodeExtent:j,elevateNodesOnSelect:z,checkEquality:!1,zIndexMode:F}),g({nodeExtent:j}))},panBy:j=>{const{transform:C,width:N,height:E,panZoom:A,translateExtent:z}=w();return kz({delta:j,panZoom:A,transform:C,translateExtent:z,width:N,height:E})},setCenter:async(j,C,N)=>{const{width:E,height:A,maxZoom:z,panZoom:D}=w();if(!D)return Promise.resolve(!1);const F=typeof(N==null?void 0:N.zoom)<"u"?N.zoom:z;return await D.setViewport({x:E/2-j*F,y:A/2-C*F,zoom:F},{duration:N==null?void 0:N.duration,ease:N==null?void 0:N.ease,interpolate:N==null?void 0:N.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{g({connection:{...Nk}})},updateConnection:j=>{g({connection:j})},reset:()=>g({...Lw()})}},Object.is);function U7({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:i,initialWidth:a,initialHeight:o,initialMinZoom:c,initialMaxZoom:d,initialFitViewOptions:m,fitView:f,nodeOrigin:x,nodeExtent:p,zIndexMode:y,children:g}){const[w]=S.useState(()=>H7({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:a,height:o,fitView:f,minZoom:c,maxZoom:d,fitViewOptions:m,nodeOrigin:x,nodeExtent:p,zIndexMode:y}));return l.jsx(i9,{value:w,children:l.jsx(D9,{children:g})})}function q7({children:e,nodes:t,edges:n,defaultNodes:i,defaultEdges:a,width:o,height:c,fitView:d,fitViewOptions:m,minZoom:f,maxZoom:x,nodeOrigin:p,nodeExtent:y,zIndexMode:g}){return S.useContext(Gf)?l.jsx(l.Fragment,{children:e}):l.jsx(U7,{initialNodes:t,initialEdges:n,defaultNodes:i,defaultEdges:a,initialWidth:o,initialHeight:c,fitView:d,initialFitViewOptions:m,initialMinZoom:f,initialMaxZoom:x,nodeOrigin:p,nodeExtent:y,zIndexMode:g,children:e})}const Y7={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function P7({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,className:a,nodeTypes:o,edgeTypes:c,onNodeClick:d,onEdgeClick:m,onInit:f,onMove:x,onMoveStart:p,onMoveEnd:y,onConnect:g,onConnectStart:w,onConnectEnd:k,onClickConnectStart:j,onClickConnectEnd:C,onNodeMouseEnter:N,onNodeMouseMove:E,onNodeMouseLeave:A,onNodeContextMenu:z,onNodeDoubleClick:D,onNodeDragStart:F,onNodeDrag:q,onNodeDragStop:V,onNodesDelete:L,onEdgesDelete:_,onDelete:B,onSelectionChange:X,onSelectionDragStart:R,onSelectionDrag:H,onSelectionDragStop:$,onSelectionContextMenu:G,onSelectionStart:Q,onSelectionEnd:K,onBeforeDelete:M,connectionMode:U,connectionLineType:P=ja.Bezier,connectionLineStyle:O,connectionLineComponent:Z,connectionLineContainerStyle:ee,deleteKeyCode:J="Backspace",selectionKeyCode:se="Shift",selectionOnDrag:le=!1,selectionMode:ye=Xc.Full,panActivationKeyCode:De="Space",multiSelectionKeyCode:Ee=Wc()?"Meta":"Control",zoomActivationKeyCode:Re=Wc()?"Meta":"Control",snapToGrid:me,snapGrid:Fe,onlyRenderVisibleElements:Je=!1,selectNodesOnDrag:Pe,nodesDraggable:it,autoPanOnNodeFocus:ht,nodesConnectable:Ye,nodesFocusable:nt,nodeOrigin:ut=r3,edgesFocusable:kt,edgesReconnectable:mt,elementsSelectable:ve=!0,defaultViewport:be=g9,minZoom:te=.5,maxZoom:oe=2,translateExtent:Ce=Pc,preventScrolling:pe=!0,nodeExtent:Se,defaultMarkerColor:Me="#b1b1b7",zoomOnScroll:Ge=!0,zoomOnPinch:Ie=!0,panOnScroll:qe=!1,panOnScrollSpeed:Xe=.5,panOnScrollMode:et=dl.Free,zoomOnDoubleClick:ze=!0,panOnDrag:Be=!0,onPaneClick:_t,onPaneMouseEnter:en,onPaneMouseMove:Tt,onPaneMouseLeave:Pt,onPaneScroll:hn,onPaneContextMenu:Zt,paneClickDistance:ae=1,nodeClickDistance:Ve=0,children:We,onReconnect:tn,onReconnectStart:Ne,onReconnectEnd:Ct,onEdgeContextMenu:ln,onEdgeDoubleClick:nn,onEdgeMouseEnter:Kr,onEdgeMouseMove:gr,onEdgeMouseLeave:vn,reconnectRadius:ce=10,onNodesChange:Ue,onEdgesChange:$e,noDragClassName:dt="nodrag",noWheelClassName:wt="nowheel",noPanClassName:yr="nopan",fitView:Pn,fitViewOptions:Qr,connectOnClick:fi,attributionPosition:Ls,proOptions:Zr,defaultEdgeOptions:Ma,elevateNodesOnSelect:jr=!0,elevateEdgesOnSelect:dr=!1,disableKeyboardA11y:Ai=!1,autoPanOnConnect:Di,autoPanOnNodeDrag:Sn,autoPanSpeed:Fa,connectionRadius:Is,isValidConnection:$n,onError:Ti,style:_i,id:is,nodeDragThreshold:hi,connectionDragThreshold:Mi,viewport:Fr,onViewportChange:ss,width:Zn,height:nr,colorMode:Ra="light",debug:za,onScroll:mi,ariaLabelConfig:Ba,zIndexMode:as="basic",...pi},jn){const Jn=is||"1",Rr=w9(Ra),br=S.useCallback(mn=>{mn.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),mi==null||mi(mn)},[mi]);return l.jsx("div",{"data-testid":"rf__wrapper",...pi,onScroll:br,style:{..._i,...Y7},ref:jn,className:Yn(["react-flow",a,Rr]),id:is,role:"application",children:l.jsxs(q7,{nodes:e,edges:t,width:Zn,height:nr,fitView:Pn,fitViewOptions:Qr,minZoom:te,maxZoom:oe,nodeOrigin:ut,nodeExtent:Se,zIndexMode:as,children:[l.jsx(I7,{onInit:f,onNodeClick:d,onEdgeClick:m,onNodeMouseEnter:N,onNodeMouseMove:E,onNodeMouseLeave:A,onNodeContextMenu:z,onNodeDoubleClick:D,nodeTypes:o,edgeTypes:c,connectionLineType:P,connectionLineStyle:O,connectionLineComponent:Z,connectionLineContainerStyle:ee,selectionKeyCode:se,selectionOnDrag:le,selectionMode:ye,deleteKeyCode:J,multiSelectionKeyCode:Ee,panActivationKeyCode:De,zoomActivationKeyCode:Re,onlyRenderVisibleElements:Je,defaultViewport:be,translateExtent:Ce,minZoom:te,maxZoom:oe,preventScrolling:pe,zoomOnScroll:Ge,zoomOnPinch:Ie,zoomOnDoubleClick:ze,panOnScroll:qe,panOnScrollSpeed:Xe,panOnScrollMode:et,panOnDrag:Be,onPaneClick:_t,onPaneMouseEnter:en,onPaneMouseMove:Tt,onPaneMouseLeave:Pt,onPaneScroll:hn,onPaneContextMenu:Zt,paneClickDistance:ae,nodeClickDistance:Ve,onSelectionContextMenu:G,onSelectionStart:Q,onSelectionEnd:K,onReconnect:tn,onReconnectStart:Ne,onReconnectEnd:Ct,onEdgeContextMenu:ln,onEdgeDoubleClick:nn,onEdgeMouseEnter:Kr,onEdgeMouseMove:gr,onEdgeMouseLeave:vn,reconnectRadius:ce,defaultMarkerColor:Me,noDragClassName:dt,noWheelClassName:wt,noPanClassName:yr,rfId:Jn,disableKeyboardA11y:Ai,nodeExtent:Se,viewport:Fr,onViewportChange:ss}),l.jsx(v9,{nodes:e,edges:t,defaultNodes:n,defaultEdges:i,onConnect:g,onConnectStart:w,onConnectEnd:k,onClickConnectStart:j,onClickConnectEnd:C,nodesDraggable:it,autoPanOnNodeFocus:ht,nodesConnectable:Ye,nodesFocusable:nt,edgesFocusable:kt,edgesReconnectable:mt,elementsSelectable:ve,elevateNodesOnSelect:jr,elevateEdgesOnSelect:dr,minZoom:te,maxZoom:oe,nodeExtent:Se,onNodesChange:Ue,onEdgesChange:$e,snapToGrid:me,snapGrid:Fe,connectionMode:U,translateExtent:Ce,connectOnClick:fi,defaultEdgeOptions:Ma,fitView:Pn,fitViewOptions:Qr,onNodesDelete:L,onEdgesDelete:_,onDelete:B,onNodeDragStart:F,onNodeDrag:q,onNodeDragStop:V,onSelectionDrag:H,onSelectionDragStart:R,onSelectionDragStop:$,onMove:x,onMoveStart:p,onMoveEnd:y,noPanClassName:yr,nodeOrigin:ut,rfId:Jn,autoPanOnConnect:Di,autoPanOnNodeDrag:Sn,autoPanSpeed:Fa,onError:Ti,connectionRadius:Is,isValidConnection:$n,selectNodesOnDrag:Pe,nodeDragThreshold:hi,connectionDragThreshold:Mi,onBeforeDelete:M,debug:za,ariaLabelConfig:Ba,zIndexMode:as}),l.jsx(x9,{onSelectionChange:X}),We,l.jsx(d9,{proOptions:Zr,position:Ls}),l.jsx(u9,{rfId:Jn,disableKeyboardA11y:Ai})]})})}var X7=s3(P7);function V7({dimensions:e,lineWidth:t,variant:n,className:i}){return l.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Yn(["react-flow__background-pattern",n,i])})}function W7({radius:e,className:t}){return l.jsx("circle",{cx:e,cy:e,r:e,className:Yn(["react-flow__background-pattern","dots",t])})}var Ea;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Ea||(Ea={}));const G7={[Ea.Dots]:1,[Ea.Lines]:1,[Ea.Cross]:6},K7=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function D3({id:e,variant:t=Ea.Dots,gap:n=20,size:i,lineWidth:a=1,offset:o=0,color:c,bgColor:d,style:m,className:f,patternClassName:x}){const p=S.useRef(null),{transform:y,patternId:g}=qt(K7,An),w=i||G7[t],k=t===Ea.Dots,j=t===Ea.Cross,C=Array.isArray(n)?n:[n,n],N=[C[0]*y[2]||1,C[1]*y[2]||1],E=w*y[2],A=Array.isArray(o)?o:[o,o],z=j?[E,E]:N,D=[A[0]*y[2]||1+z[0]/2,A[1]*y[2]||1+z[1]/2],F=`${g}${e||""}`;return l.jsxs("svg",{className:Yn(["react-flow__background",f]),style:{...m,...Qf,"--xy-background-color-props":d,"--xy-background-pattern-color-props":c},ref:p,"data-testid":"rf__background",children:[l.jsx("pattern",{id:F,x:y[0]%N[0],y:y[1]%N[1],width:N[0],height:N[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${D[0]},-${D[1]})`,children:k?l.jsx(W7,{radius:E/2,className:x}):l.jsx(V7,{dimensions:z,lineWidth:a,variant:t,className:x})}),l.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${F})`})]})}D3.displayName="Background";S.memo(D3);function Q7(){return l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:l.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function Z7(){return l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:l.jsx("path",{d:"M0 0h32v4.2H0z"})})}function J7(){return l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:l.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 eB(){return l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:l.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 tB(){return l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:l.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 Xd({children:e,className:t,...n}){return l.jsx("button",{type:"button",className:Yn(["react-flow__controls-button",t]),...n,children:e})}const nB=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function T3({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:i=!0,fitViewOptions:a,onZoomIn:o,onZoomOut:c,onFitView:d,onInteractiveChange:m,className:f,children:x,position:p="bottom-left",orientation:y="vertical","aria-label":g}){const w=Dn(),{isInteractive:k,minZoomReached:j,maxZoomReached:C,ariaLabelConfig:N}=qt(nB,An),{zoomIn:E,zoomOut:A,fitView:z}=O0(),D=()=>{E(),o==null||o()},F=()=>{A(),c==null||c()},q=()=>{z(a),d==null||d()},V=()=>{w.setState({nodesDraggable:!k,nodesConnectable:!k,elementsSelectable:!k}),m==null||m(!k)},L=y==="horizontal"?"horizontal":"vertical";return l.jsxs(Kf,{className:Yn(["react-flow__controls",L,f]),position:p,style:e,"data-testid":"rf__controls","aria-label":g??N["controls.ariaLabel"],children:[t&&l.jsxs(l.Fragment,{children:[l.jsx(Xd,{onClick:D,className:"react-flow__controls-zoomin",title:N["controls.zoomIn.ariaLabel"],"aria-label":N["controls.zoomIn.ariaLabel"],disabled:C,children:l.jsx(Q7,{})}),l.jsx(Xd,{onClick:F,className:"react-flow__controls-zoomout",title:N["controls.zoomOut.ariaLabel"],"aria-label":N["controls.zoomOut.ariaLabel"],disabled:j,children:l.jsx(Z7,{})})]}),n&&l.jsx(Xd,{className:"react-flow__controls-fitview",onClick:q,title:N["controls.fitView.ariaLabel"],"aria-label":N["controls.fitView.ariaLabel"],children:l.jsx(J7,{})}),i&&l.jsx(Xd,{className:"react-flow__controls-interactive",onClick:V,title:N["controls.interactive.ariaLabel"],"aria-label":N["controls.interactive.ariaLabel"],children:k?l.jsx(tB,{}):l.jsx(eB,{})}),x]})}T3.displayName="Controls";S.memo(T3);function rB({id:e,x:t,y:n,width:i,height:a,style:o,color:c,strokeColor:d,strokeWidth:m,className:f,borderRadius:x,shapeRendering:p,selected:y,onClick:g}){const{background:w,backgroundColor:k}=o||{},j=c||w||k;return l.jsx("rect",{className:Yn(["react-flow__minimap-node",{selected:y},f]),x:t,y:n,rx:x,ry:x,width:i,height:a,style:{fill:j,stroke:d,strokeWidth:m},shapeRendering:p,onClick:g?C=>g(C,e):void 0})}const iB=S.memo(rB),sB=e=>e.nodes.map(t=>t.id),zp=e=>e instanceof Function?e:()=>e;function aB({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:i=5,nodeStrokeWidth:a,nodeComponent:o=iB,onClick:c}){const d=qt(sB,An),m=zp(t),f=zp(e),x=zp(n),p=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return l.jsx(l.Fragment,{children:d.map(y=>l.jsx(oB,{id:y,nodeColorFunc:m,nodeStrokeColorFunc:f,nodeClassNameFunc:x,nodeBorderRadius:i,nodeStrokeWidth:a,NodeComponent:o,onClick:c,shapeRendering:p},y))})}function lB({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:i,nodeBorderRadius:a,nodeStrokeWidth:o,shapeRendering:c,NodeComponent:d,onClick:m}){const{node:f,x,y:p,width:y,height:g}=qt(w=>{const k=w.nodeLookup.get(e);if(!k)return{node:void 0,x:0,y:0,width:0,height:0};const j=k.internals.userNode,{x:C,y:N}=k.internals.positionAbsolute,{width:E,height:A}=Os(j);return{node:j,x:C,y:N,width:E,height:A}},An);return!f||f.hidden||!Fk(f)?null:l.jsx(d,{x,y:p,width:y,height:g,style:f.style,selected:!!f.selected,className:i(f),color:t(f),borderRadius:a,strokeColor:n(f),strokeWidth:o,shapeRendering:c,onClick:m,id:f.id})}const oB=S.memo(lB);var cB=S.memo(aB);const uB=200,dB=150,fB=e=>!e.hidden,hB=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?Mk(au(e.nodeLookup,{filter:fB}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},mB="react-flow__minimap-desc";function _3({style:e,className:t,nodeStrokeColor:n,nodeColor:i,nodeClassName:a="",nodeBorderRadius:o=5,nodeStrokeWidth:c,nodeComponent:d,bgColor:m,maskColor:f,maskStrokeColor:x,maskStrokeWidth:p,position:y="bottom-right",onClick:g,onNodeClick:w,pannable:k=!1,zoomable:j=!1,ariaLabel:C,inversePan:N,zoomStep:E=1,offsetScale:A=5}){const z=Dn(),D=S.useRef(null),{boundingRect:F,viewBB:q,rfId:V,panZoom:L,translateExtent:_,flowWidth:B,flowHeight:X,ariaLabelConfig:R}=qt(hB,An),H=(e==null?void 0:e.width)??uB,$=(e==null?void 0:e.height)??dB,G=F.width/H,Q=F.height/$,K=Math.max(G,Q),M=K*H,U=K*$,P=A*K,O=F.x-(M-F.width)/2-P,Z=F.y-(U-F.height)/2-P,ee=M+P*2,J=U+P*2,se=`${mB}-${V}`,le=S.useRef(0),ye=S.useRef();le.current=K,S.useEffect(()=>{if(D.current&&L)return ye.current=_z({domNode:D.current,panZoom:L,getTransform:()=>z.getState().transform,getViewScale:()=>le.current}),()=>{var me;(me=ye.current)==null||me.destroy()}},[L]),S.useEffect(()=>{var me;(me=ye.current)==null||me.update({translateExtent:_,width:B,height:X,inversePan:N,pannable:k,zoomStep:E,zoomable:j})},[k,j,N,E,_,B,X]);const De=g?me=>{var Pe;const[Fe,Je]=((Pe=ye.current)==null?void 0:Pe.pointer(me))||[0,0];g(me,{x:Fe,y:Je})}:void 0,Ee=w?S.useCallback((me,Fe)=>{const Je=z.getState().nodeLookup.get(Fe).internals.userNode;w(me,Je)},[]):void 0,Re=C??R["minimap.ariaLabel"];return l.jsx(Kf,{position:y,style:{...e,"--xy-minimap-background-color-props":typeof m=="string"?m:void 0,"--xy-minimap-mask-background-color-props":typeof f=="string"?f:void 0,"--xy-minimap-mask-stroke-color-props":typeof x=="string"?x:void 0,"--xy-minimap-mask-stroke-width-props":typeof p=="number"?p*K:void 0,"--xy-minimap-node-background-color-props":typeof i=="string"?i: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:Yn(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:l.jsxs("svg",{width:H,height:$,viewBox:`${O} ${Z} ${ee} ${J}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":se,ref:D,onClick:De,children:[Re&&l.jsx("title",{id:se,children:Re}),l.jsx(cB,{onClick:Ee,nodeColor:i,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:a,nodeStrokeWidth:c,nodeComponent:d}),l.jsx("path",{className:"react-flow__minimap-mask",d:`M${O-P},${Z-P}h${ee+P*2}v${J+P*2}h${-ee-P*2}z
|
|
112
|
-
M${q.x},${q.y}h${q.width}v${q.height}h${-q.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}_3.displayName="MiniMap";S.memo(_3);const pB=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,xB={[yo.Line]:"right",[yo.Handle]:"bottom-right"};function gB({nodeId:e,position:t,variant:n=yo.Handle,className:i,style:a=void 0,children:o,color:c,minWidth:d=10,minHeight:m=10,maxWidth:f=Number.MAX_VALUE,maxHeight:x=Number.MAX_VALUE,keepAspectRatio:p=!1,resizeDirection:y,autoScale:g=!0,shouldResize:w,onResizeStart:k,onResize:j,onResizeEnd:C}){const N=c3(),E=typeof e=="string"?e:N,A=Dn(),z=S.useRef(null),D=n===yo.Handle,F=qt(S.useCallback(pB(D&&g),[D,g]),An),q=S.useRef(null),V=t??xB[n];S.useEffect(()=>{if(!(!z.current||!E))return q.current||(q.current=Pz({domNode:z.current,nodeId:E,getStoreItems:()=>{const{nodeLookup:_,transform:B,snapGrid:X,snapToGrid:R,nodeOrigin:H,domNode:$}=A.getState();return{nodeLookup:_,transform:B,snapGrid:X,snapToGrid:R,nodeOrigin:H,paneDomNode:$}},onChange:(_,B)=>{const{triggerNodeChanges:X,nodeLookup:R,parentLookup:H,nodeOrigin:$}=A.getState(),G=[],Q={x:_.x,y:_.y},K=R.get(E);if(K&&K.expandParent&&K.parentId){const M=K.origin??$,U=_.width??K.measured.width??0,P=_.height??K.measured.height??0,O={id:K.id,parentId:K.parentId,rect:{width:U,height:P,...Rk({x:_.x??K.position.x,y:_.y??K.position.y},{width:U,height:P},K.parentId,R,M)}},Z=$0([O],R,H,$);G.push(...Z),Q.x=_.x?Math.max(M[0]*U,_.x):void 0,Q.y=_.y?Math.max(M[1]*P,_.y):void 0}if(Q.x!==void 0&&Q.y!==void 0){const M={id:E,type:"position",position:{...Q}};G.push(M)}if(_.width!==void 0&&_.height!==void 0){const U={id:E,type:"dimensions",resizing:!0,setAttributes:y?y==="horizontal"?"width":"height":!0,dimensions:{width:_.width,height:_.height}};G.push(U)}for(const M of B){const U={...M,type:"position"};G.push(U)}X(G)},onEnd:({width:_,height:B})=>{const X={id:E,type:"dimensions",resizing:!1,dimensions:{width:_,height:B}};A.getState().triggerNodeChanges([X])}})),q.current.update({controlPosition:V,boundaries:{minWidth:d,minHeight:m,maxWidth:f,maxHeight:x},keepAspectRatio:p,resizeDirection:y,onResizeStart:k,onResize:j,onResizeEnd:C,shouldResize:w}),()=>{var _;(_=q.current)==null||_.destroy()}},[V,d,m,f,x,p,k,j,C,w]);const L=V.split("-");return l.jsx("div",{className:Yn(["react-flow__resize-control","nodrag",...L,n,i]),ref:z,style:{...a,scale:F,...c&&{[D?"backgroundColor":"borderColor"]:c}},children:o})}S.memo(gB);const yB={ceo:"#B71C1C",cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#7C4DFF",designer:"#E91E63",qa:"#00897B","data-analyst":"#0288D1","designer-seek":"#E91E63",test:"#78909C"},bB={ceo:"👑",cto:"⚙️",cbo:"📊",pm:"📋",engineer:"🏗️",designer:"🎨",qa:"🔍","data-analyst":"📈","designer-seek":"🎨",test:"🧪"};function vB(e){switch(e.status){case"streaming":return"#60A5FA";case"awaiting_input":return"#FBBF24";case"done":return"#4ADE80";case"error":return"#F87171";case"not-dispatched":return"#4B5563";default:return"#6B7280"}}function wB(e,t){switch(e.status){case"streaming":return"● Working...";case"awaiting_input":return"◉ Awaiting Reply";case"done":return t?"◎ Supervising":"✓ Complete";case"error":return"✗ Error";case"waiting":return"○ Waiting";default:return""}}const io={ceo:{w:120,h:48},"c-level":{w:170,h:64},member:{w:156,h:56}};function kB({data:e,id:t}){const n=e,{node:i,roleLevel:a,isSelected:o,isChecked:c,showCheckbox:d,isEligible:m,hasActiveChildren:f}=n,x=yB[i.roleId]??"#6B7280",p=vB(i),y=Na(i.status),g=a==="ceo",w=io[a],k=bB[i.roleId]??"👤",j=i.status==="not-dispatched",C=g?o?.9:.65:j&&!c?.4:1;return l.jsxs("div",{className:"org-rf-node",style:{width:w.w,height:w.h,borderRadius:g?24:12,background:g?"linear-gradient(135deg, #1a1a2e 0%, #16213e 100%)":`linear-gradient(180deg, ${x}10 0%, var(--terminal-bg-deeper, #181825) 40%)`,border:o?`2px solid ${x}`:c?"2px solid #EF5350":`1px solid ${j?"#333":x+"30"}`,borderStyle:j&&!c?"dashed":"solid",cursor:"pointer",opacity:C,display:"flex",flexDirection:"column",position:"relative",overflow:"hidden",boxShadow:y?`0 0 20px ${x}30, 0 4px 12px rgba(0,0,0,0.3)`:o?`0 0 12px ${x}20, 0 2px 8px rgba(0,0,0,0.2)`:"0 2px 6px rgba(0,0,0,0.15)"},children:[l.jsx(bo,{type:"target",position:at.Top,style:{opacity:0,width:1,height:1}}),l.jsx(bo,{type:"source",position:at.Bottom,style:{opacity:0,width:1,height:1}}),y&&l.jsx("div",{style:{position:"absolute",inset:-2,borderRadius:g?26:14,border:`2px solid ${p}`,animation:"org-rf-glow 2s ease-in-out infinite",pointerEvents:"none"}}),g?l.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",gap:8,padding:"0 16px"},children:[l.jsx("span",{style:{fontSize:18,lineHeight:1},children:"👑"}),l.jsx("span",{style:{fontSize:13,fontWeight:900,color:"#fff",fontFamily:"var(--pixel-font)",letterSpacing:2},children:"CEO"})]}):l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:a==="c-level"?"10px 12px":"8px 10px",flex:1},children:[l.jsx("div",{style:{width:a==="c-level"?32:28,height:a==="c-level"?32:28,borderRadius:8,background:`${x}18`,border:`1px solid ${x}30`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:a==="c-level"?16:14,flexShrink:0},children:k}),l.jsxs("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:[l.jsx("div",{style:{fontSize:a==="c-level"?12:11,fontWeight:800,color:x,fontFamily:"var(--pixel-font)",letterSpacing:.5,lineHeight:1.2},children:i.roleId.toUpperCase()}),i.roleName&&i.roleName!==i.roleId&&l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-secondary, #aaa)",fontFamily:"var(--pixel-font)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:1},children:i.roleName}),l.jsx("div",{style:{fontSize:9,color:p,fontFamily:"var(--pixel-font)",fontWeight:600,marginTop:2},children:wB(i,f)})]}),d&&!g?l.jsx("div",{onClick:N=>{N.stopPropagation(),m&&window.dispatchEvent(new CustomEvent("org-toggle-check",{detail:{roleId:t}}))},style:{cursor:m?"pointer":"default",opacity:m?1:.2,flexShrink:0},children:l.jsx("div",{style:{width:16,height:16,borderRadius:4,background:c?"#EF5350":"transparent",border:`2px solid ${c?"#EF5350":"#555"}`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,color:"#fff",transition:"all 0.15s"},children:c&&"✓"})}):!d&&i.status==="done"?l.jsx("span",{style:{fontSize:14,color:"#4ADE80",flexShrink:0,fontWeight:700},children:"✓"}):!d&&i.status==="error"?l.jsx("span",{style:{fontSize:14,color:"#F87171",flexShrink:0,fontWeight:700},children:"✗"}):null]})]})}const SB=S.memo(kB),jB={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#7C4DFF",designer:"#E91E63",qa:"#00897B","data-analyst":"#0288D1","designer-seek":"#E91E63",test:"#78909C"};function CB(e){const{sourceX:t,sourceY:n,targetX:i,targetY:a,data:o}=e,c=o??{},[d]=Mf({sourceX:t,sourceY:n,targetX:i,targetY:a,borderRadius:16});let m="rgba(180,200,240,0.08)",f="6 6",x=!1,p=1.5;return c.childStatus==="done"||c.parentStatus==="done"?(m="#4ADE8040",f="",p=2):c.childStatus==="awaiting_input"?(m="#FBBF2466",f="8 5",x=!0,p=2):c.childStatus==="streaming"&&(m=(jB[c.childRoleId??""]??"#60A5FA")+"55",f="8 5",x=!0,p=2.2),l.jsx(cu,{path:d,style:{stroke:m,strokeWidth:p,strokeDasharray:f},className:x?"wave-edge-flow":void 0})}const NB=S.memo(CB),Bp=24,EB=56,AB={orgRole:SB},DB={orgEdge:NB};function TB(e,t,n){var i,a;return e===t?"ceo":((i=n==null?void 0:n[e])==null?void 0:i.level)==="c-level"||((a=n==null?void 0:n[e])==null?void 0:a.reportsTo)===t?"c-level":"member"}function _B(e,t,n){if(!e.get(t))return[];const a=[],o=[],c=[{id:t,depth:0,parentId:null}],d=new Set;for(;c.length>0;){const{id:f,depth:x,parentId:p}=c.shift();if(d.has(f))continue;for(d.add(f);o.length<=x;)o.push([]);o[x].push(f);const y=TB(f,t,n);a.push({roleId:f,x:0,y:0,parentId:p,level:y});const g=e.get(f);if(g)for(const w of g.children)e.has(w)&&!d.has(w)&&c.push({id:w,depth:x+1,parentId:f})}let m=0;for(let f=0;f<o.length;f++){const x=o[f],p=Math.max(...x.map(w=>{const k=a.find(j=>j.roleId===w);return k?io[k.level].h:44}));let g=-x.reduce((w,k)=>{const j=a.find(C=>C.roleId===k);return w+(j?io[j.level].w:130)+Bp},-Bp)/2;for(const w of x){const k=a.find(C=>C.roleId===w);if(!k)continue;const j=io[k.level];k.x=g+j.w/2,k.y=m+(p-j.h)/2,g+=j.w+Bp}m+=p+EB}for(const f of a){const x=io[f.level];f.x-=x.w/2}return a}function M3({nodes:e,rootId:t,selectedRoleId:n,onSelectNode:i,checkedRoles:a,onToggleCheck:o,eligibleRoles:c,orgNodes:d}){const m=!!o,{rfNodes:f,rfEdges:x}=S.useMemo(()=>{const y=_B(e,t,d),g=y.map(k=>{const j=e.get(k.roleId);if(!j)return null;const C=j.children.some(A=>{const z=e.get(A);return z&&Na(z.status)}),N={node:j,roleLevel:k.level,isSelected:n===k.roleId,isChecked:(a==null?void 0:a.has(k.roleId))??!1,showCheckbox:m,isEligible:!c||c.has(k.roleId),hasActiveChildren:C},E=io[k.level];return{id:k.roleId,type:"orgRole",position:{x:k.x,y:k.y},data:N,draggable:!1,selectable:!1,width:E.w,height:E.h}}).filter(Boolean),w=y.filter(k=>k.parentId).map(k=>{const j=e.get(k.roleId),C=e.get(k.parentId);return{id:`${k.parentId}-${k.roleId}`,source:k.parentId,target:k.roleId,type:"orgEdge",data:{childStatus:j==null?void 0:j.status,parentStatus:C==null?void 0:C.status,childRoleId:k.roleId},selectable:!1}});return{rfNodes:g,rfEdges:w}},[e,t,n,a,c,m,d]),p=S.useCallback((y,g)=>{i(g.id)},[i]);return S.useEffect(()=>{if(!o)return;const y=g=>{var k;const w=(k=g.detail)==null?void 0:k.roleId;w&&o(w)};return window.addEventListener("org-toggle-check",y),()=>window.removeEventListener("org-toggle-check",y)},[o]),l.jsx("div",{className:"org-rf-container",style:{width:"100%",height:"100%",minHeight:220},children:l.jsx(X7,{nodes:f,edges:x,nodeTypes:AB,edgeTypes:DB,onNodeClick:p,fitView:!0,fitViewOptions:{padding:.12,minZoom:.5,maxZoom:1},zoomOnScroll:!1,zoomOnPinch:!1,panOnDrag:!1,panOnScroll:!1,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,preventScrolling:!1,proOptions:{hideAttribution:!0},minZoom:.3,maxZoom:2})})}const MB={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function FB({directive:e,rootDispatches:t,orgNodes:n,rootRoleId:i,waveId:a,onClose:o,onMinimize:c,onDone:d,onOpenKnowledgeDoc:m,onSave:f}){const{nodes:x,selectedRoleId:p,selectNode:y,progress:g,allDone:w,connectStream:k}=K5(t,n,i,a),[j,C]=S.useState(0),[N,E]=S.useState(new Set),[A,z]=S.useState(""),[D,F]=S.useState(!1),[q,V]=S.useState(!1),L=S.useRef(null),_=S.useRef(Date.now()),B=S.useRef(!1),X=S.useCallback(async()=>{if(f){V(!0);try{const P=t.map(O=>O.sessionId).filter(Boolean);await f(P)}catch(P){console.error("Save failed:",P)}finally{V(!1),o()}}},[f,t,o]),R=S.useCallback(async()=>{if(!p||!A.trim())return;const P=x.get(p);if(!(!(P!=null&&P.sessionId)||P.status!=="awaiting_input"&&P.status!=="done")){F(!0);try{await ke.replyToSession(P.sessionId,A.trim()),z(""),k(P.sessionId,p)}catch(O){console.error("Reply failed:",O)}finally{F(!1)}}},[p,A,x,k]),H=S.useCallback(async P=>{const O=x.get(P);if(O!=null&&O.sessionId)try{await ke.abortSession(O.sessionId)}catch{}},[x]),$=S.useCallback(async()=>{for(const[,P]of x)if(Na(P.status))try{P.sessionId&&await ke.abortSession(P.sessionId)}catch{}},[x]);S.useEffect(()=>{const P=setInterval(()=>{C(Math.floor((Date.now()-_.current)/1e3))},1e3);return()=>clearInterval(P)},[]);const G=S.useRef(!1);S.useEffect(()=>{const P=L.current;if(!P)return;const O=()=>{const Z=P.scrollHeight-P.scrollTop-P.clientHeight<60;G.current=!Z};return P.addEventListener("scroll",O),()=>P.removeEventListener("scroll",O)},[]),S.useEffect(()=>{G.current=!1,L.current&&(L.current.scrollTop=L.current.scrollHeight)},[p]),S.useEffect(()=>{L.current&&!G.current&&(L.current.scrollTop=L.current.scrollHeight)},[x]),S.useEffect(()=>{w&&!B.current&&(B.current=!0,d==null||d()),!w&&B.current&&(B.current=!1)},[w,d]);const Q=P=>`${Math.floor(P/60)}:${String(P%60).padStart(2,"0")}`,K=p?x.get(p):null,M=p?MB[p]??"#888":"#888",U=P=>{E(O=>{const Z=new Set(O);return Z.has(P)?Z.delete(P):Z.add(P),Z})};return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm pointer-events-none"}),l.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[960px] max-w-[95vw] h-[85vh] z-[61] bg-[var(--terminal-bg)] rounded-2xl shadow-2xl overflow-hidden flex flex-col",children:[l.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[var(--terminal-border)] shrink-0",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"w-3 h-3 rounded-full",style:{background:w?"#2E7D32":"#B71C1C",animation:w?void 0:"wave-pulse 2s ease-in-out infinite"}}),l.jsx("div",{children:l.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-sm",children:w?"WAVE COMPLETE":"WAVE COMMAND CENTER"})})]}),l.jsxs("div",{className:"flex items-center gap-4",children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs font-mono",children:Q(j)}),g.awaitingInput>0&&l.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:"#F59E0B22",color:"#F59E0B"},children:[g.awaitingInput," awaiting reply"]}),l.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:w?"#2E7D3222":"#B71C1C22",color:w?"#2E7D32":"#B71C1C"},children:[g.done,"/",g.total," done"]}),!w&&(g.running>0||g.awaitingInput>0)&&l.jsx("button",{onClick:$,className:"text-xs px-2 py-0.5 rounded font-semibold cursor-pointer",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},title:"Stop all running jobs",children:"Stop All"}),l.jsx("button",{onClick:c,title:"Minimize",className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-sm cursor-pointer px-1",children:"–"}),l.jsx("button",{onClick:o,className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-lg cursor-pointer",title:w?"Dismiss wave":"Close (jobs keep running)",children:"×"})]})]}),l.jsx("div",{className:"px-5 py-2 border-b border-[var(--terminal-border)] shrink-0",children:l.jsxs("span",{className:"text-[var(--terminal-text-secondary)] text-xs italic",children:["“",e,"”"]})}),l.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[l.jsxs("div",{className:"shrink-0 border-b border-[var(--terminal-border)] flex flex-col",children:[l.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5",children:[l.jsx("span",{className:"text-[10px] font-bold text-[var(--terminal-text-secondary)] uppercase tracking-wider",children:"Org Propagation"}),l.jsx("div",{className:"flex gap-x-3 ml-auto",children:[{label:"streaming",color:"#FBBF24",dot:!0},{label:"awaiting",color:"#F59E0B",dot:!0},{label:"done",color:"#2E7D32",dot:!1},{label:"waiting",color:"#888",dot:!1},{label:"error",color:"#C62828",dot:!1}].map(P=>l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:P.color,animation:P.dot?"wave-pulse 1.5s ease-in-out infinite":void 0}}),l.jsx("span",{className:"text-[8px] text-[var(--terminal-text-muted)]",children:P.label})]},P.label))})]}),l.jsx("div",{className:"px-3 pb-2",style:{height:"35vh"},children:l.jsx(M3,{nodes:x,rootId:i,selectedRoleId:p,onSelectNode:y,orgNodes:n})})]}),l.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[K&&l.jsxs("div",{className:"px-4 py-2 border-b border-[var(--terminal-border)] shrink-0 flex items-center gap-2",children:[l.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:M}}),l.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-xs",children:K.roleId.toUpperCase()}),l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs",children:K.roleName}),l.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full font-semibold",style:{background:K.status==="awaiting_input"?"#F59E0B22":`${M}22`,color:K.status==="awaiting_input"?"#F59E0B":M},children:K.status==="streaming"?"Working":K.status==="done"?"Complete":K.status==="error"?"Error":K.status==="waiting"?"Waiting":K.status==="awaiting_input"?"Awaiting Reply":"Not dispatched"}),Na(K.status)&&K.sessionId&&l.jsx("button",{onClick:()=>H(K.roleId),className:"text-[10px] px-2 py-0.5 rounded font-semibold cursor-pointer ml-1",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},title:"Force stop this execution",children:"Stop"})]}),l.jsxs("div",{ref:L,className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-1 text-xs font-mono select-text",children:[K&&K.events.length===0&&l.jsx("div",{className:"text-[var(--terminal-text-muted)]",children:K.status==="waiting"?"Waiting for dispatch...":K.status==="streaming"?"Connecting to activity stream...":K.status==="not-dispatched"?"This role was not dispatched in this wave.":""}),K==null?void 0:K.events.map(P=>l.jsx(k0,{event:P,isThinkingCollapsed:N.has(P.seq),onToggleThinking:()=>U(P.seq),onNavigateToSession:O=>{const Z=K==null?void 0:K.events.find(J=>J.type==="dispatch:start"&&J.data.childSessionId===O),ee=Z==null?void 0:Z.data.targetRoleId;ee&&x.has(ee)&&y(ee)},onOpenKnowledgeDoc:m},P.seq)),(K==null?void 0:K.status)==="streaming"&&l.jsx("span",{className:"inline-block w-2 h-4 bg-green-400 animate-pulse ml-0.5"})]}),(K==null?void 0:K.status)==="awaiting_input"&&l.jsxs("div",{className:"px-4 py-3 border-t border-[var(--terminal-border)] shrink-0",style:{background:"#F59E0B0A"},children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:"#F59E0B",animation:"wave-pulse 1.5s ease-in-out infinite"}}),l.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#F59E0B"},children:[K.roleName," is waiting for your response"]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{type:"text",value:A,onChange:P=>z(P.target.value),onKeyDown:P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),R())},placeholder:"Type your response...",disabled:D,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] border-[var(--terminal-border)] outline-none focus:border-[#F59E0B]",autoFocus:!0}),l.jsx("button",{onClick:R,disabled:D||!A.trim(),className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#F59E0B",color:"#000"},children:D?"...":"Reply"})]})]}),(K==null?void 0:K.status)==="done"&&K.sessionId&&l.jsxs("div",{className:"px-4 py-3 border-t border-[var(--terminal-border)] shrink-0",style:{background:"#1565C00A"},children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#64B5F6"},children:["Follow-up to ",K.roleName]}),l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:"Send a follow-up directive"})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{type:"text",value:A,onChange:P=>z(P.target.value),onKeyDown:P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),R())},placeholder:"e.g., 좋아 KB-3 진행해, Engineer에게 시켜...",disabled:D,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] border-[var(--terminal-border)] outline-none focus:border-[#64B5F6]"}),l.jsx("button",{onClick:R,disabled:D||!A.trim(),className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#1565C0",color:"#fff"},children:D?"...":"Send"})]})]}),!K&&l.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-xs",children:"Click a node in the org tree to view activity"}),l.jsxs("div",{className:"px-4 py-2 border-t border-[var(--terminal-border)] flex items-center justify-between shrink-0",children:[l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:K&&K.events.length>0&&`${K.events.length} events`}),w&&l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("button",{onClick:o,className:"px-4 py-1.5 text-xs rounded-lg font-semibold cursor-pointer",style:{background:"rgba(255,255,255,0.08)",color:"var(--terminal-text-muted)"},children:"Dismiss"}),f&&l.jsx("button",{onClick:X,disabled:q,className:"px-4 py-1.5 text-xs text-white rounded-lg font-semibold cursor-pointer disabled:opacity-50",style:{background:"#2E7D32"},children:q?"Saving...":"Save Wave"})]})]})]})]})]})]})}const RB={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function Iw({orgNodes:e,rootRoleId:t,cLevelRoles:n,pastWaves:i,activeWaves:a,onDispatch:o,onClose:c,onDone:d,onSave:m,onOpenKnowledgeDoc:f,onRefreshWaves:x,terminalWidth:p=0,onMaximize:y,inline:g=!1,onOpenSaveModal:w}){const[k,j]=S.useState(""),[C,N]=S.useState(!1),[E,A]=S.useState(null),[z,D]=S.useState(!1),[F,q]=S.useState(a.length>0?0:-1),[,V]=S.useState(!1),L=S.useRef(null),_=F>=0?a[F]??null:null,B=S.useMemo(()=>[],[]),X=(_==null?void 0:_.rootDispatches)??B,R=K5(X,e,t,(_==null?void 0:_.id)??null);S.useEffect(()=>{if(E){const ce=zB(e,t,E.roles);R.injectStaticNodes(ce);for(const Ue of E.roles??[])if(y2(Ue.status)&&Ue.sessionId){const $e=ce.get(Ue.roleId);$e!=null&&$e.sessionId&&setTimeout(()=>R.connectStream($e.sessionId,Ue.roleId),100)}}},[E,e,t]),S.useEffect(()=>{!R.selectedRoleId&&t&&R.selectNode(t)},[t]);const H=S.useRef(a.length);S.useEffect(()=>{const ce=a.length>H.current;H.current=a.length,ce&&(q(0),A(null),V(!1))},[a.length]);const[$,G]=S.useState(null),Q=S.useMemo(()=>{if(!$)return null;const ce=$.modified.length+$.untracked.length;return{branch:$.branch,dirty:ce>0,count:ce}},[$]),K=S.useCallback(()=>{ke.getSaveStatus("code").then(ce=>{G({dirty:ce.modified.length+ce.untracked.length>0,modified:ce.modified,untracked:ce.untracked,lastCommit:ce.lastCommit,branch:ce.branch})}).catch(()=>{})},[]);S.useEffect(()=>{K()},[K]);const[M,U]=S.useState(0);S.useEffect(()=>{if(!_)return;const ce=setInterval(()=>{U(Math.floor((Date.now()-_.startedAt)/1e3))},1e3);return()=>clearInterval(ce)},[_]);const[P,O]=S.useState(""),[Z,ee]=S.useState(!1),[J,se]=S.useState([]),[le,ye]=S.useState(!1),[De,Ee]=S.useState(null),Re=S.useRef(null);S.useEffect(()=>{if(De){const ce=setTimeout(()=>Ee(null),3e3);return()=>clearTimeout(ce)}},[De]);const me=S.useCallback(async ce=>["image/png","image/jpeg","image/gif","image/webp"].includes(ce.type)?ce.size>5*1024*1024?(Ee(`Too large: ${(ce.size/1024/1024).toFixed(1)}MB. Max 5MB.`),null):new Promise($e=>{const dt=new FileReader;dt.onload=()=>{const wt=dt.result.split(",")[1];$e({type:"image",data:wt,name:ce.name,mediaType:ce.type})},dt.onerror=()=>{Ee("Failed to read file"),$e(null)},dt.readAsDataURL(ce)}):(Ee(`Unsupported: ${ce.type}. Use PNG, JPG, GIF, or WebP.`),null),[]),Fe=S.useCallback(async ce=>{const Ue=[];for(const $e of Array.from(ce)){const dt=await me($e);dt&&Ue.push(dt)}Ue.length>0&&se($e=>[...$e,...Ue])},[me]),Je=S.useCallback(ce=>{ce.preventDefault(),ce.stopPropagation(),ye(!0)},[]),Pe=S.useCallback(ce=>{ce.preventDefault(),ce.stopPropagation(),ye(!1)},[]),it=S.useCallback(ce=>{ce.preventDefault(),ce.stopPropagation(),ye(!1),ce.dataTransfer.files.length>0&&Fe(ce.dataTransfer.files)},[Fe]),ht=S.useCallback(ce=>{const Ue=[];for(let $e=0;$e<ce.clipboardData.items.length;$e++){const dt=ce.clipboardData.items[$e];if(dt.type.startsWith("image/")){const wt=dt.getAsFile();wt&&Ue.push(wt)}}Ue.length>0&&(ce.preventDefault(),Fe(Ue))},[Fe]),[Ye,nt]=S.useState(320),ut=S.useRef(!1),kt=S.useRef(0),mt=S.useRef(0),ve=S.useCallback(ce=>{ce.preventDefault(),ut.current=!0,kt.current=ce.clientX,mt.current=Ye;const Ue=dt=>{if(!ut.current)return;const wt=kt.current-dt.clientX;nt(Math.max(200,Math.min(500,mt.current+wt)))},$e=()=>{ut.current=!1,window.removeEventListener("mousemove",Ue),window.removeEventListener("mouseup",$e)};window.addEventListener("mousemove",Ue),window.addEventListener("mouseup",$e)},[Ye]),[be,te]=S.useState(new Set),oe=S.useRef(null),Ce=S.useRef(!1);S.useEffect(()=>{const ce=oe.current;if(!ce)return;const Ue=()=>{const $e=ce.scrollHeight-ce.scrollTop-ce.clientHeight<60;Ce.current=!$e};return ce.addEventListener("scroll",Ue),()=>ce.removeEventListener("scroll",Ue)},[]),S.useEffect(()=>{!Ce.current&&oe.current&&(oe.current.scrollTop=oe.current.scrollHeight)},[R.nodes,R.selectedRoleId]);const pe=R.selectedRoleId?R.nodes.get(R.selectedRoleId)??null:null,Se=pe?RB[pe.roleId]??"#888":"#888",Me=R.progress.running>0||R.progress.awaitingInput>0,Ge=R.selectedRoleId===t,Ie=!!E&&!_,qe=(_==null?void 0:_.directive)??(E==null?void 0:E.directive)??"",Xe=S.useCallback(ce=>{const Ue=new Set,$e=[ce];for(;$e.length>0;){const dt=$e.shift();if(Ue.has(dt))continue;Ue.add(dt);const wt=e[dt];wt&&$e.push(...wt.children)}return Ue},[e]),et=S.useMemo(()=>{if(!R.selectedRoleId)return new Set;const ce=Xe(R.selectedRoleId);return ce.delete(t),ce},[R.selectedRoleId,Xe,t]),ze=S.useRef(null);S.useEffect(()=>{if(R.selectedRoleId===ze.current||(ze.current=R.selectedRoleId,!R.selectedRoleId))return;const ce=Xe(R.selectedRoleId);ce.delete(t),R.setCheckedRoles(ce)},[R.selectedRoleId,Xe,t]);const Be=R.checkedRoles.size,_t=()=>{if(!k.trim()&&J.length===0||Be===0)return;const Ue=Array.from(R.nodes.keys()).filter(dt=>dt!==t).every(dt=>R.checkedRoles.has(dt)),$e=J.length>0?J:void 0;o(k.trim(),Ue?void 0:Array.from(R.checkedRoles),$e,C||void 0),j(""),se([])},en=ce=>{ce.key==="Enter"&&(ce.metaKey||ce.ctrlKey)&&(ce.preventDefault(),_t()),ce.key==="Escape"&&c()},Tt=S.useCallback(async()=>{if(!R.selectedRoleId||!P.trim()&&J.length===0)return;const ce=R.nodes.get(R.selectedRoleId);if(!ce)return;const Ue=J.length>0?J:void 0;ee(!0);try{if(ce.status==="awaiting_input"&&ce.sessionId){const $e=await ke.replyToSession(ce.sessionId,P.trim(),Ue);O(""),se([]),!!(_!=null&&_.id)||R.connectStream($e.sessionId||ce.sessionId,R.selectedRoleId)}else{const $e=(_==null?void 0:_.id)??(E==null?void 0:E.waveId)??(E==null?void 0:E.id),dt=await ke.execute({type:"assign",roleId:R.selectedRoleId,task:P.trim(),...$e&&{waveId:$e},...Ue&&{attachments:Ue}});O(""),se([]),dt.sessionId&&(_!=null&&_.id||R.connectStream(dt.sessionId,R.selectedRoleId))}}catch($e){console.error("Reply failed:",$e)}finally{ee(!1)}},[R,P,J,_,E]),Pt=S.useCallback(async ce=>{const Ue=R.nodes.get(ce);if(Ue!=null&&Ue.sessionId)try{await ke.abortSession(Ue.sessionId)}catch{}},[R.nodes]),hn=S.useCallback(async()=>{for(const[,ce]of R.nodes)if(Na(ce.status))try{ce.sessionId&&await ke.abortSession(ce.sessionId)}catch{}},[R.nodes]),Zt=S.useCallback(async ce=>{D(!0),A(null),q(-1);try{const Ue=await ke.getWaveDetail(ce);Ue.replay&&A(Ue.replay)}catch(Ue){console.error("Failed to load wave:",Ue)}finally{D(!1)}},[]),ae=S.useRef(!1);S.useEffect(()=>{ae.current||a.length===0&&i.length>0&&!E&&!z&&(ae.current=!0,Zt(i[0].id))},[a.length,i,E,z,Zt]);const Ve=S.useRef(!1),We=S.useRef(null);S.useEffect(()=>{if(!(E||z)&&((_==null?void 0:_.id)!==We.current&&(Ve.current=!1,We.current=(_==null?void 0:_.id)??null),R.allDone&&!Ve.current&&_&&(Ve.current=!0,K(),d==null||d(),m))){const ce=_.rootDispatches.map(Ue=>Ue.sessionId).filter(Boolean);m(_.directive,ce,{waveId:_.id,sessionIds:_.sessionIds}).catch(()=>{})}},[R.allDone,_,d,m,K,E,z]);const tn=S.useCallback(async()=>{if(!m||!_)return;const ce=_.rootDispatches.map(Ue=>Ue.sessionId).filter(Boolean);await m(_.directive,ce,{waveId:_.id,sessionIds:_.sessionIds})},[m,_]),Ne=ce=>{te(Ue=>{const $e=new Set(Ue);return $e.has(ce)?$e.delete(ce):$e.add(ce),$e})},Ct=ce=>{const Ue=Math.floor(ce/60),$e=ce%60;return`${Ue}:${$e.toString().padStart(2,"0")}`},{panelRight:ln,panelWidth:nn,isResizing:Kr,handleResizeStart:gr}=nu(p,700,y),vn=l.jsxs(l.Fragment,{children:[!g&&l.jsxs("div",{className:"shrink-0 px-4 py-3",style:{background:"linear-gradient(180deg, #B71C1C 0%, #7f1d1d 100%)"},children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("span",{className:"text-white font-bold text-lg tracking-wide",style:{fontFamily:"var(--pixel-font)"},children:"Wave Center"}),Me&&l.jsxs("span",{className:"text-white/60 text-xs",children:[R.progress.running+R.progress.awaitingInput," active",R.progress.awaitingInput>0&&` (${R.progress.awaitingInput} awaiting)`]}),l.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[y&&l.jsx("button",{onClick:y,className:"text-white/50 hover:text-white text-xs cursor-pointer",children:"Maximize"}),l.jsx("button",{onClick:c,className:"text-white/50 hover:text-white text-xl leading-none cursor-pointer px-2",children:"✕"})]})]}),l.jsx("div",{className:"text-white/60 text-xs mt-0.5",children:_?`${a.length} active wave${a.length!==1?"s":""}`:Ie?"Reviewing past wave":"Broadcast directives to your organization"})]}),l.jsxs("div",{className:"flex-1 flex min-h-0",children:[l.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[(_||Ie)&&l.jsxs("div",{className:"px-4 py-2 border-b flex items-center gap-3 shrink-0",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("div",{className:"w-3 h-3 rounded-full shrink-0",style:{background:Me?"#FBBF24":R.allDone||Ie?"#2E7D32":"#B71C1C",animation:Me?"wave-pulse 2s ease-in-out infinite":void 0}}),l.jsxs("span",{className:"text-[var(--terminal-text-secondary)] text-xs italic flex-1 min-w-0 truncate",children:["“",qe,"”"]}),_&&l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs font-mono shrink-0",children:Ct(M)}),Ie&&l.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-semibold shrink-0",style:{background:Me?"#FBBF2422":"#2E7D3222",color:Me?"#FBBF24":"#2E7D32"},children:Me?"LIVE":"REPLAY"}),Ie&&(E==null?void 0:E.startedAt)&&l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-[10px] shrink-0",children:new Date(E.startedAt).toLocaleString()}),R.progress.awaitingInput>0&&l.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-semibold shrink-0",style:{background:"#F59E0B22",color:"#F59E0B"},children:[R.progress.awaitingInput," awaiting"]}),l.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-semibold shrink-0",style:{background:R.allDone||Ie&&!Me?"#2E7D3222":"#B71C1C22",color:R.allDone||Ie&&!Me?"#2E7D32":"#B71C1C"},children:[R.progress.done,"/",R.progress.total]}),Me&&l.jsx("button",{onClick:hn,className:"text-[10px] px-2 py-0.5 rounded font-semibold cursor-pointer shrink-0",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},children:"Stop All"})]}),l.jsxs("div",{className:"shrink-0 border-b flex flex-col",style:{borderColor:"var(--terminal-border)"},children:[l.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5",children:[l.jsx("span",{className:"text-[10px] font-bold text-[var(--terminal-text-secondary)] uppercase tracking-wider",children:_||Ie?"Org Propagation":"Select Target Roles"}),l.jsxs("span",{className:"ml-auto text-[10px] text-[var(--terminal-text-muted)]",children:[R.checkedRoles.size,"/",R.progress.total," selected"]}),(_||Ie)&&l.jsx("div",{className:"flex gap-x-3",children:[{label:"streaming",color:"#FBBF24",dot:!0},{label:"awaiting",color:"#F59E0B",dot:!0},{label:"done",color:"#2E7D32",dot:!1},{label:"waiting",color:"#888",dot:!1},{label:"error",color:"#C62828",dot:!1}].map(ce=>l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:ce.color,animation:ce.dot?"wave-pulse 1.5s ease-in-out infinite":void 0}}),l.jsx("span",{className:"text-[8px] text-[var(--terminal-text-muted)]",children:ce.label})]},ce.label))})]}),l.jsx("div",{className:"px-3 pb-2",style:{height:"38vh"},children:l.jsx(M3,{nodes:R.nodes,rootId:t,selectedRoleId:R.selectedRoleId,onSelectNode:R.selectNode,checkedRoles:R.checkedRoles,onToggleCheck:R.toggleCheck,eligibleRoles:et,orgNodes:e})})]}),z?l.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-sm",children:"Loading wave data..."}):Ge?l.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[l.jsxs("div",{className:"px-4 py-2 border-b shrink-0 flex items-center gap-2",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:"#B71C1C"}}),l.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-xs",children:"CEO"}),l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs",children:"Directive Control"}),l.jsxs("span",{className:"ml-auto text-[10px] text-[var(--terminal-text-muted)]",children:[Be," target role",Be!==1?"s":""," selected"]})]}),l.jsxs("div",{ref:oe,className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-2 text-xs font-mono select-text",children:[qe&&l.jsxs("div",{className:"flex items-start gap-2 pb-3 border-b",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("span",{className:"text-[10px] font-bold px-1.5 py-0.5 rounded shrink-0",style:{background:"#B71C1C33",color:"#EF5350"},children:"CEO"}),l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-secondary)] whitespace-pre-wrap",children:qe}),_&&l.jsxs("div",{className:"text-[9px] text-[var(--terminal-text-muted)] mt-1",children:["dispatched ",Ct(M)," ago to ",_.rootDispatches.length," role",_.rootDispatches.length!==1?"s":""]})]})]}),!qe&&!_&&l.jsx("div",{className:"text-[var(--terminal-text-muted)] text-center py-8",children:"Select target roles using checkboxes, then dispatch a directive below."})]}),l.jsxs("div",{className:"px-4 py-3 border-t shrink-0",style:{borderColor:"var(--terminal-border)",background:"var(--hud-bg-alt)"},children:[J.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:J.map((ce,Ue)=>l.jsxs("div",{className:"relative group w-14 h-14 rounded-lg overflow-hidden border border-[var(--terminal-border)] bg-[var(--terminal-inline-bg)]",children:[l.jsx("img",{src:`data:${ce.mediaType};base64,${ce.data}`,alt:ce.name,className:"w-full h-full object-cover"}),l.jsx("button",{onClick:()=>se($e=>$e.filter((dt,wt)=>wt!==Ue)),className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-black/70 text-white text-[9px] flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:"x"}),l.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-[7px] text-white truncate px-1",children:ce.name})]},Ue))}),De&&l.jsx("div",{className:"text-[10px] text-red-400 mb-1",children:De}),l.jsxs("div",{className:"flex gap-2 items-end",children:[l.jsx("button",{onClick:()=>{var ce;return(ce=Re.current)==null?void 0:ce.click()},className:"w-8 h-8 rounded-lg bg-[var(--terminal-inline-bg)] border border-[var(--terminal-border)] text-[var(--terminal-text-muted)] flex items-center justify-center shrink-0 cursor-pointer hover:text-[var(--terminal-text-secondary)] transition-colors",title:"Attach image",children:l.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),l.jsx("textarea",{ref:L,value:k,onChange:ce=>j(ce.target.value),onKeyDown:en,onPaste:ht,placeholder:"e.g. Report current status across all departments",rows:2,className:"flex-1 px-3 py-2 text-sm rounded-lg border bg-[var(--terminal-bg)] text-[var(--terminal-text)] outline-none resize-none",style:{borderColor:"var(--terminal-border)"}}),l.jsxs("button",{onClick:_t,disabled:!k.trim()&&J.length===0||Be===0,className:"px-4 py-2 text-xs font-bold rounded-lg cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed shrink-0",style:{background:k.trim()&&Be>0?"#B71C1C":"#333",color:"#fff",minWidth:140},children:["Dispatch to ",Be," Role",Be!==1?"s":""]})]}),l.jsxs("div",{className:"flex items-center justify-between mt-1",children:[l.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[l.jsx("input",{type:"checkbox",checked:C,onChange:ce=>N(ce.target.checked),className:"accent-[#B71C1C] w-3 h-3 cursor-pointer"}),l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:"Continuous"})]}),l.jsx("div",{className:"text-[9px] text-[var(--terminal-text-muted)]",children:"Cmd+Enter to dispatch"})]})]})]}):l.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[pe&&l.jsxs("div",{className:"px-4 py-2 border-b shrink-0 flex items-center gap-2",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:Se}}),l.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-xs",children:pe.roleId.toUpperCase()}),l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs",children:pe.roleName}),l.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full font-semibold",style:{background:pe.status==="awaiting_input"?"#F59E0B22":pe.status==="streaming"?"#FBBF2422":`${Se}22`,color:pe.status==="awaiting_input"?"#F59E0B":pe.status==="streaming"?"#FBBF24":Se},children:pe.status==="streaming"?"Working...":pe.status==="done"?pe.children.some(ce=>{const Ue=R.nodes.get(ce);return Ue&&Na(Ue.status)})?"Supervising...":"Complete":pe.status==="error"?"Error":pe.status==="waiting"?"Waiting":pe.status==="awaiting_input"?"Awaiting Reply":"Not dispatched"}),l.jsxs("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:[pe.events.length," events"]}),Na(pe.status)&&pe.sessionId&&l.jsx("button",{onClick:()=>Pt(pe.roleId),className:"text-[10px] px-2 py-0.5 rounded font-semibold cursor-pointer ml-1",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},children:"Stop"})]}),pe&&l.jsxs("div",{className:"px-4 py-2 border-b shrink-0",style:{borderColor:"var(--terminal-border)",background:"var(--hud-bg-alt)"},children:[l.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-[10px] font-mono",children:[pe.sessionId&&l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)]",children:"Session "}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)]",children:pe.sessionId.slice(0,8)})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)]",children:"Events "}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)]",children:pe.events.length})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)]",children:"Stream "}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)]",children:pe.streamStatus})]}),(()=>{const ce=pe.events[pe.events.length-1];if(!(ce!=null&&ce.ts))return null;const Ue=Math.floor((Date.now()-new Date(ce.ts).getTime())/1e3);if(isNaN(Ue)||Ue<0)return null;const $e=Ue<60?`${Ue}s ago`:Ue<3600?`${Math.floor(Ue/60)}m ago`:`${Math.floor(Ue/3600)}h ago`;return l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)]",children:"Last activity "}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)]",children:$e})]})})()]}),(()=>{var wt,yr;const ce=pe.events.filter(Pn=>Pn.type==="text"||Pn.type==="tool:result"),Ue=ce[ce.length-1];if(!Ue)return null;const $e=typeof((wt=Ue.data)==null?void 0:wt.text)=="string"?Ue.data.text:typeof((yr=Ue.data)==null?void 0:yr.content)=="string"?Ue.data.content:null;if(!$e)return null;const dt=$e.length>120?$e.slice(0,120)+"...":$e;return l.jsx("div",{className:"mt-1.5 text-[10px] text-[var(--terminal-text-muted)] italic truncate",title:$e,children:dt})})()]}),l.jsx("input",{ref:Re,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",multiple:!0,onChange:ce=>{var Ue;(Ue=ce.target.files)!=null&&Ue.length&&Fe(ce.target.files),ce.target.value=""},className:"hidden"}),l.jsxs("div",{ref:oe,className:`flex-1 min-h-0 overflow-y-auto p-4 space-y-1 text-xs font-mono select-text transition-colors ${le?"bg-amber-500/5 ring-1 ring-inset ring-amber-500/30":""}`,onDragOver:Je,onDragLeave:Pe,onDrop:it,children:[pe&&qe&&pe.status!=="waiting"&&pe.status!=="not-dispatched"&&l.jsxs("div",{className:"flex items-start gap-2 mb-3 pb-2 border-b",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("span",{className:"text-[10px] font-bold px-1.5 py-0.5 rounded shrink-0",style:{background:"#B71C1C33",color:"#EF5350"},children:"CEO"}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)] whitespace-pre-wrap",children:qe})]}),pe&&pe.events.length===0&&l.jsx("div",{className:"text-[var(--terminal-text-muted)]",children:pe.status==="waiting"?"Waiting for dispatch...":pe.status==="streaming"?"Connecting to activity stream...":pe.status==="not-dispatched"?"This role was not dispatched. Send a follow-up to activate.":""}),pe==null?void 0:pe.events.map((ce,Ue)=>{const $e=pe.events,dt=ce.type==="msg:start"&&Ue>0,wt=$e[Ue+1];if((ce.type==="msg:done"||ce.type==="msg:error"||ce.type==="msg:awaiting_input")&&(wt==null?void 0:wt.type)==="msg:start")return null;if(dt){const Pn=ce.data.task??"",Qr=Pn.match(/\[CEO Follow-up\]\n([\s\S]+)$/),fi=Qr?Qr[1].trim():Pn;return l.jsx(S.Fragment,{children:l.jsxs("div",{className:"flex items-start gap-2 my-3 pt-2 pb-2 border-t border-b",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("span",{className:"text-[10px] font-bold px-1.5 py-0.5 rounded shrink-0",style:{background:"#B71C1C33",color:"#EF5350"},children:"CEO"}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)] whitespace-pre-wrap",children:fi})]})},`followup-${ce.seq}`)}return l.jsx(k0,{event:ce,isThinkingCollapsed:be.has(ce.seq),onToggleThinking:()=>Ne(ce.seq),onNavigateToSession:Pn=>{for(const[,Qr]of R.nodes)if(Qr.events.some(fi=>fi.data.childSessionId===Pn)){R.selectNode(Qr.roleId);return}},onOpenKnowledgeDoc:f},ce.seq)}),(pe==null?void 0:pe.status)==="streaming"&&l.jsx("span",{className:"inline-block w-2 h-4 bg-green-400 animate-pulse ml-0.5"}),!pe&&l.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-xs h-full",children:"Click a node in the org tree to view activity"})]}),((pe==null?void 0:pe.status)==="awaiting_input"||(pe==null?void 0:pe.status)==="done"||(pe==null?void 0:pe.status)==="not-dispatched")&&(J.length>0||De||le)&&l.jsxs("div",{className:"px-4 pt-2 border-t shrink-0",style:{borderColor:"var(--terminal-border)"},children:[De&&l.jsx("div",{className:"text-[10px] text-red-400 mb-1",children:De}),le&&l.jsx("div",{className:"text-[11px] text-amber-400 text-center mb-1",children:"Drop image here"}),J.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2 mb-1",children:J.map((ce,Ue)=>l.jsxs("div",{className:"relative group w-14 h-14 rounded-lg overflow-hidden border border-[var(--terminal-border)] bg-[var(--terminal-inline-bg)]",children:[l.jsx("img",{src:`data:${ce.mediaType};base64,${ce.data}`,alt:ce.name,className:"w-full h-full object-cover"}),l.jsx("button",{onClick:()=>se($e=>$e.filter((dt,wt)=>wt!==Ue)),className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-black/70 text-white text-[9px] flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:"x"}),l.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-[7px] text-white truncate px-1",children:ce.name})]},Ue))})]}),(pe==null?void 0:pe.status)==="awaiting_input"&&l.jsxs("div",{className:"px-4 py-3 border-t shrink-0",style:{borderColor:"var(--terminal-border)",background:"#F59E0B0A"},children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:"#F59E0B",animation:"wave-pulse 1.5s ease-in-out infinite"}}),l.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#F59E0B"},children:[pe.roleName," is waiting for your response"]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>{var ce;return(ce=Re.current)==null?void 0:ce.click()},disabled:Z,className:"w-7 h-7 rounded bg-[var(--terminal-inline-bg)] border border-[var(--terminal-border)] text-[var(--terminal-text-muted)] flex items-center justify-center shrink-0 cursor-pointer hover:text-[var(--terminal-text-secondary)] disabled:opacity-30 transition-colors",title:"Attach image",children:l.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),l.jsx("input",{type:"text",value:P,onChange:ce=>O(ce.target.value),onKeyDown:ce=>{ce.key==="Enter"&&!ce.shiftKey&&(ce.preventDefault(),Tt())},onPaste:ht,placeholder:"Type your response...",disabled:Z,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] outline-none",style:{borderColor:"var(--terminal-border)"},autoFocus:!0}),l.jsx("button",{onClick:Tt,disabled:Z||!P.trim()&&J.length===0,className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#F59E0B",color:"#000"},children:Z?"...":"Reply"})]})]}),pe&&(pe.status==="done"||pe.status==="not-dispatched")&&l.jsxs("div",{className:"px-4 py-3 border-t shrink-0",style:{borderColor:"var(--terminal-border)",background:"#1565C00A"},children:[l.jsx("div",{className:"flex items-center gap-2 mb-2",children:l.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#64B5F6"},children:["Follow-up to ",pe.roleName]})}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>{var ce;return(ce=Re.current)==null?void 0:ce.click()},disabled:Z,className:"w-7 h-7 rounded bg-[var(--terminal-inline-bg)] border border-[var(--terminal-border)] text-[var(--terminal-text-muted)] flex items-center justify-center shrink-0 cursor-pointer hover:text-[var(--terminal-text-secondary)] disabled:opacity-30 transition-colors",title:"Attach image",children:l.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),l.jsx("input",{type:"text",value:P,onChange:ce=>O(ce.target.value),onKeyDown:ce=>{ce.key==="Enter"&&!ce.shiftKey&&(ce.preventDefault(),Tt())},onPaste:ht,placeholder:"Send a follow-up directive...",disabled:Z,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] outline-none",style:{borderColor:"var(--terminal-border)"}}),l.jsx("button",{onClick:Tt,disabled:Z||!P.trim()&&J.length===0,className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#1565C0",color:"#fff"},children:Z?"...":"Send"})]})]}),R.allDone&&_&&m&&l.jsx("div",{className:"px-4 py-2 border-t shrink-0 flex justify-end",style:{borderColor:"var(--terminal-border)"},children:l.jsx("button",{onClick:tn,className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer",style:{background:"#1565C022",color:"#64B5F6",border:"1px solid #1565C044"},children:"Save Wave"})})]})]}),l.jsxs("div",{className:"shrink-0 border-l flex flex-col relative",style:{width:Ye,borderColor:"var(--terminal-border)",background:"var(--hud-bg-alt)"},children:[l.jsx("div",{className:"absolute top-0 bottom-0 w-1.5 cursor-col-resize hover:bg-[var(--accent)] z-10",style:{left:-2},onMouseDown:ve}),l.jsx("div",{className:"p-3 pb-0",children:l.jsx("button",{onClick:()=>{A(null),q(-1),V(!0),R.reset()},className:"w-full px-3 py-1.5 text-[11px] font-bold rounded-lg cursor-pointer transition-colors",style:{background:!E&&F<0?"#B71C1C":"var(--terminal-inline-bg)",color:!E&&F<0?"#fff":"var(--terminal-text-secondary)",border:"1px solid",borderColor:!E&&F<0?"#B71C1C":"var(--terminal-border)"},children:"+ New Wave"})}),a.length>0&&l.jsxs("div",{className:"p-3",children:[l.jsx("div",{className:"text-[10px] font-bold text-[var(--terminal-text-muted)] uppercase tracking-wider mb-2",children:"Active"}),l.jsx("div",{className:"flex flex-col gap-1.5",children:a.map((ce,Ue)=>l.jsxs("button",{onClick:()=>{q(Ue),A(null),V(!1),R.reset()},className:"text-left p-2 rounded-lg cursor-pointer transition-colors",style:{background:F===Ue&&!E?"var(--terminal-bg)":"transparent",border:F===Ue&&!E?"1px solid var(--accent)":"1px solid transparent"},children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500 shrink-0 animate-pulse"}),l.jsxs("span",{className:"text-[11px] text-[var(--terminal-text)] truncate font-medium",children:[ce.directive.slice(0,40),ce.directive.length>40?"...":""]})]}),l.jsxs("div",{className:"text-[9px] text-[var(--terminal-text-muted)] mt-0.5 pl-3.5",children:[ce.rootDispatches.length," role",ce.rootDispatches.length!==1?"s":""]})]},ce.id))})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto p-3",children:[l.jsxs("div",{className:"text-[10px] font-bold text-[var(--terminal-text-muted)] uppercase tracking-wider mb-2",children:["Past Waves (",i.length,")"]}),i.length===0&&l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)] italic",children:"No past waves yet"}),l.jsx("div",{className:"flex flex-col gap-1.5",children:i.map(ce=>l.jsx(BB,{wave:ce,active:(E==null?void 0:E.id)===ce.id,onLoad:()=>Zt(ce.id)},ce.id))})]}),Q&&l.jsxs("button",{onClick:w,disabled:!w,className:"px-3 py-2.5 border-t shrink-0 flex items-center gap-1.5 w-full text-left hover:bg-white/5 transition-colors cursor-pointer disabled:cursor-default",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:{background:Q.dirty?"var(--idle-amber)":"#2E7D32"}}),l.jsx("span",{className:"text-[10px] font-mono text-[var(--terminal-text-muted)] truncate",children:Q.branch}),Q.dirty&&l.jsxs("span",{className:"text-[9px] ml-auto shrink-0",style:{color:"var(--idle-amber)"},children:[Q.count," unsaved"]}),!Q.dirty&&l.jsx("span",{className:"text-[9px] text-green-400 ml-auto shrink-0",children:"clean"})]})]})]})]});return g?l.jsx("div",{className:"flex flex-col h-full w-full",style:{background:"var(--terminal-bg)"},children:vn}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"dimmer fixed top-0 left-0 bottom-0 bg-black/30 z-40 open",style:{right:ln},onClick:c}),l.jsxs("div",{className:"fixed top-0 bottom-0 z-50 flex flex-col",style:{right:ln,width:nn,background:"var(--terminal-bg)",borderLeft:"1px solid var(--terminal-border)",transition:Kr?"none":"width 0.2s ease"},children:[l.jsx("div",{className:"absolute top-0 bottom-0 w-1 cursor-col-resize hover:bg-[var(--accent)] z-50",style:{left:0},onMouseDown:gr}),vn]})]})}function zB(e,t,n){const i=new Map,a=c=>{const d=e[c];!d||i.has(c)||(i.set(c,{sessionId:"",roleId:c,roleName:d.name,children:d.children,status:"not-dispatched",events:[],streamStatus:"idle"}),d.children.forEach(a))},o=e[t];o&&(i.set(t,{sessionId:"",roleId:t,roleName:"CEO",children:o.children,status:"not-dispatched",events:[],streamStatus:"idle"}),o.children.forEach(a));for(const c of n){const d=i.get(c.roleId);if(d){const f=y2(c.status);i.set(c.roleId,{...d,sessionId:c.sessionId??"",status:c.status||"done",events:c.events,streamStatus:f?"connecting":"done"})}const m=c.childSessions??[];for(const f of m){const x=i.get(f.roleId);x&&i.set(f.roleId,{...x,sessionId:f.sessionId??"",status:f.status||"done",events:f.events,streamStatus:"done"})}}return i}function BB({wave:e,active:t,onLoad:n}){const i=e.id.match(/^(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})/),a=i?`${i[1]}-${i[2]}-${i[3]} ${i[4]}:${i[5]}`:e.id;return l.jsx("div",{className:"rounded-lg cursor-pointer transition-colors hover:bg-[var(--terminal-bg)]",style:{border:t?"1px solid var(--accent)":"1px solid var(--terminal-border)",background:t?"var(--terminal-bg)":void 0},onClick:n,children:l.jsxs("div",{className:"p-2",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[e.hasRunning?l.jsx("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse shrink-0",style:{background:"#4CAF50"}}):l.jsx("span",{className:"text-[10px]",children:"▶"}),l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:a}),e.hasRunning?l.jsx("span",{className:"text-[9px] ml-auto animate-pulse",style:{color:"#4CAF50"},children:"running"}):e.commit?l.jsx("span",{className:"text-[9px] text-green-400 ml-auto font-mono",title:`Committed: ${e.commit.sha}`,children:e.commit.sha.slice(0,7)}):e.rolesCount?l.jsx("span",{className:"text-[9px] ml-auto",style:{color:"var(--idle-amber)"},title:"No commit recorded",children:"uncommitted"}):null]}),l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-secondary)] mt-0.5 line-clamp-2 leading-relaxed",children:e.directive.slice(0,80)}),e.rolesCount?l.jsxs("div",{className:"text-[9px] text-[var(--terminal-text-muted)] mt-0.5",children:[e.rolesCount," role",e.rolesCount!==1?"s":""]}):null]})})}const $B={cto:{skinColor:"#F5CBA7",hairColor:"#2C1810",shirtColor:"#1565C0",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"short",outfitStyle:"tshirt",accessory:"glasses"},cbo:{skinColor:"#FDEBD0",hairColor:"#1A0A00",shirtColor:"#E65100",pantsColor:"#37474F",shoeColor:"#1A1A1A",hairStyle:"slicked",outfitStyle:"suit",accessory:"lapels"},pm:{skinColor:"#FDEBD0",hairColor:"#6D4C41",shirtColor:"#2E7D32",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"bun",outfitStyle:"tshirt",accessory:"blush"},engineer:{skinColor:"#F5CBA7",hairColor:"#1A1A1A",shirtColor:"#4A148C",pantsColor:"#37474F",shoeColor:"#7B1FA2",hairStyle:"messy",outfitStyle:"hoodie",accessory:"headphones"},designer:{skinColor:"#FDEBD0",hairColor:"#AD1457",shirtColor:"#AD1457",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"bob",outfitStyle:"tshirt",accessory:"beret"},qa:{skinColor:"#F5CBA7",hairColor:"#4E342E",shirtColor:"#00695C",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"short",outfitStyle:"tshirt",accessory:"badge"},"data-analyst":{skinColor:"#F5CBA7",hairColor:"#3E2723",shirtColor:"#0277BD",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"curly",outfitStyle:"vest",accessory:"none"}};function I0(e){return $B[e]??{skinColor:"#B0BEC5",hairColor:"#78909C",shirtColor:"#607D8B",pantsColor:"#455A64",shoeColor:"#37474F"}}const F3=["#FDEBD0","#F5CBA7","#D4A07A","#C68642","#8D5524","#5C3A1E","#F3D1C7","#E8BEAC","#B07D62","#704214"],R3=["#1A0A00","#2C1810","#4E342E","#6D4C41","#8D6E63","#D4A574","#F5E6CA","#FFD700","#B71C1C","#AD1457","#4A148C","#1A237E","#004D40","#1A1A1A","#78909C","#E0E0E0"],z3=["#1565C0","#E65100","#2E7D32","#4A148C","#AD1457","#00695C","#D32F2F","#F57F17","#1B5E20","#283593","#4E342E","#37474F","#880E4F","#00838F","#6A1B9A","#FF6F00"],B3=["#37474F","#1A237E","#3E2723","#263238","#1B5E20","#455A64","#212121","#4E342E","#0D47A1","#311B92"],$3=["#212121","#1A1A1A","#37474F","#4E342E","#7B1FA2","#D32F2F","#1565C0","#F57F17","#2E7D32","#FFFFFF"],Bs={default:{name:"MIDNIGHT",icon:"🌃",vars:{"--floor-light":"#0d1117","--floor-dark":"#0a0e14","--hud-bg":"#0d1117","--hud-bg-alt":"#161b22","--pixel-border":"#30363d","--terminal-bg":"#0d1117","--terminal-border":"#21262d","--terminal-border-hover":"#388bfd","--terminal-text":"#e6edf3","--terminal-text-secondary":"#8b949e","--terminal-text-muted":"#484f58","--accent":"#388bfd","--active-green":"#3fb950","--idle-amber":"#d29922"}},light:{name:"DAYLIGHT",icon:"☀️",vars:{"--floor-light":"#f6f8fa","--floor-dark":"#eaeef2","--hud-bg":"#f0f3f6","--hud-bg-alt":"#e4e8ec","--pixel-border":"#c0c8d0","--terminal-bg":"#ffffff","--terminal-border":"#d0d7de","--terminal-border-hover":"#0969da","--terminal-text":"#1f2328","--terminal-text-secondary":"#484f58","--terminal-text-muted":"#6e7781","--accent":"#0969da","--active-green":"#1a7f37","--idle-amber":"#9a6700","--bar-bg":"#24292f","--bar-text":"#e6edf3","--bar-border":"#444c56","--terminal-bg-deeper":"#e8ecf0"}},retro:{name:"RETRO",icon:"🎮",vars:{"--floor-light":"#1a1410","--floor-dark":"#140f0a","--hud-bg":"#1a1410","--hud-bg-alt":"#2a2018","--pixel-border":"#5c4a32","--terminal-bg":"#1a1410","--terminal-border":"#3a2e20","--terminal-border-hover":"#d4a44e","--terminal-text":"#e8d5b0","--terminal-text-secondary":"#a08860","--terminal-text-muted":"#6b5840","--accent":"#d4a44e","--active-green":"#8bba4a","--idle-amber":"#e8a030"}},cyberpunk:{name:"NEON",icon:"🌌",vars:{"--floor-light":"#0a0014","--floor-dark":"#06000e","--hud-bg":"#0a0014","--hud-bg-alt":"#14002a","--pixel-border":"#4a1a80","--terminal-bg":"#0a0014","--terminal-border":"#2a0a50","--terminal-border-hover":"#e040fb","--terminal-text":"#e0d0ff","--terminal-text-secondary":"#9070c0","--terminal-text-muted":"#5a3a80","--accent":"#e040fb","--active-green":"#00ff88","--idle-amber":"#ffab00"}},forest:{name:"FOREST",icon:"🌲",vars:{"--floor-light":"#0a1410","--floor-dark":"#060e0a","--hud-bg":"#0a1410","--hud-bg-alt":"#142a1e","--pixel-border":"#2a5a3a","--terminal-bg":"#0a1410","--terminal-border":"#1a3a26","--terminal-border-hover":"#4ade80","--terminal-text":"#d0f0d8","--terminal-text-secondary":"#70a880","--terminal-text-muted":"#3a6848","--accent":"#4ade80","--active-green":"#86efac","--idle-amber":"#fcd34d"}},ocean:{name:"OCEAN",icon:"🌊",vars:{"--floor-light":"#0a1420","--floor-dark":"#060e18","--hud-bg":"#0a1420","--hud-bg-alt":"#142a40","--pixel-border":"#1e4a6a","--terminal-bg":"#0a1420","--terminal-border":"#163050","--terminal-border-hover":"#38bdf8","--terminal-text":"#d0e8f8","--terminal-text-secondary":"#6090b0","--terminal-text-muted":"#305070","--accent":"#38bdf8","--active-green":"#34d399","--idle-amber":"#fbbf24"}}};function OB({color:e,selected:t,onClick:n}){return l.jsx("button",{onClick:n,className:"customize-swatch",style:{background:e,outline:t?"2px solid #fff":"2px solid transparent",boxShadow:t?`0 0 0 1px ${e}, 0 0 6px ${e}88`:"none"}})}function Nc({label:e,presets:t,value:n,onChange:i}){return l.jsxs("div",{className:"customize-row",children:[l.jsxs("div",{className:"customize-row-header",children:[l.jsx("span",{className:"customize-row-label",children:e}),l.jsx("div",{className:"customize-row-current",style:{background:n}})]}),l.jsx("div",{className:"customize-swatches",children:t.map(a=>l.jsx(OB,{color:a,selected:a===n,onClick:()=>i(a)},a))})]})}function $p({label:e,items:t,value:n,onChange:i,lockInfo:a}){return l.jsxs("div",{className:"customize-row",children:[l.jsx("div",{className:"customize-row-header",children:l.jsx("span",{className:"customize-row-label",children:e})}),l.jsx("div",{className:"customize-swatches",style:{gap:4},children:t.map(o=>{const c=a?a.getLockLevel(o.id):1,d=a!=null&&a.getCost?a.getCost(o.id):0,m=o.id===n,f=a?c>a.roleLevel&&!m:!1,x=d>0&&(a==null?void 0:a.purchased)&&!a.purchased.has(o.id)&&!m,p=(a==null?void 0:a.coinBalance)!==void 0?a.coinBalance>=d:!0,y=f||!1,g=a?m&&c>a.roleLevel:!1;return l.jsxs("button",{onClick:()=>{if(!y){if(x&&!f){p&&(a!=null&&a.onPurchase)&&a.onPurchase(o.id,d);return}i(o.id===n?void 0:o.id)}},className:"customize-swatch",style:{width:"auto",height:"auto",padding:y||x?"2px 6px 12px 6px":"2px 6px",fontSize:9,fontFamily:"var(--font-pixel, monospace)",background:m?"rgba(255,255,255,0.15)":y?"rgba(255,255,255,0.02)":x?"rgba(255,200,0,0.04)":"rgba(255,255,255,0.04)",outline:m?g?"2px solid #F59E0B":"2px solid #fff":x&&!y?"2px solid rgba(255,200,0,0.3)":"2px solid transparent",color:y?"rgba(255,255,255,0.25)":x?"rgba(255,255,255,0.45)":m?"#fff":"rgba(255,255,255,0.5)",borderRadius:4,cursor:y?"not-allowed":x?p?"pointer":"not-allowed":"pointer",opacity:y?.35:1,position:"relative"},children:[o.name,y&&l.jsxs("span",{style:{position:"absolute",bottom:1,left:"50%",transform:"translateX(-50%)",fontSize:8,color:"rgba(255,255,255,0.5)",whiteSpace:"nowrap"},children:["🔒"," Lv.",c]}),!y&&x&&l.jsxs("span",{style:{position:"absolute",bottom:1,left:"50%",transform:"translateX(-50%)",fontSize:8,color:p?"#FFD700":"#F87171",whiteSpace:"nowrap"},children:["🪙"," ",d]}),g&&l.jsxs("span",{style:{position:"absolute",bottom:-8,left:"50%",transform:"translateX(-50%)",fontSize:7,color:"#F59E0B",whiteSpace:"nowrap"},children:["⚠"," Lv.",c]})]},o.id)})})]})}function Op({label:e,active:t,onClick:n}){return l.jsx("button",{onClick:n,style:{flex:1,padding:"6px 0",fontSize:10,fontFamily:"var(--font-pixel, monospace)",fontWeight:"bold",letterSpacing:1,background:t?"rgba(255,255,255,0.08)":"transparent",color:t?"#fff":"rgba(255,255,255,0.35)",border:"none",borderBottom:t?"2px solid #3B82F6":"2px solid transparent",cursor:"pointer",transition:"all 0.15s"},children:e})}function ya(e){return e[Math.floor(Math.random()*e.length)]}function to(e){var a,o,c;const t=h0().filter(d=>!e||E5(d.id,e)),n=m0().filter(d=>!e||D5(d.id,e)),i=p0().filter(d=>!e||M5(d.id,e));return{skinColor:ya(F3),hairColor:ya(R3),shirtColor:ya(z3),pantsColor:ya(B3),shoeColor:ya($3),hairStyle:(a=ya(t))==null?void 0:a.id,outfitStyle:(o=ya(n))==null?void 0:o.id,accessory:(c=ya(i))==null?void 0:c.id}}function O3({roleId:e,appearance:t,onChange:n,onRandomize:i,onReset:a,label:o,roleLevel:c,coinBalance:d,purchased:m,onPurchase:f}){const[x,p]=S.useState("look"),y=S.useCallback((D,F)=>{n({...t,[D]:F})},[t,n]),g=S.useRef(null),w=S.useCallback(D=>{var V;const F=(V=D.target.files)==null?void 0:V[0];if(!F)return;const q=new Image;q.onload=()=>{const L=O8(q);n({...L,hairStyle:t.hairStyle,outfitStyle:t.outfitStyle,accessory:t.accessory}),URL.revokeObjectURL(q.src)},q.src=URL.createObjectURL(F),D.target.value=""},[t.hairStyle,t.outfitStyle,t.accessory,n]),k=h0(),j=m0(),C=p0(),N=c!==void 0?k.filter(D=>E5(D.id,c)).length:k.length,E=c!==void 0?j.filter(D=>D5(D.id,c)).length:j.length,A=c!==void 0?C.filter(D=>M5(D.id,c)).length:C.length,z=(D,F)=>c!==void 0?{roleLevel:c,getLockLevel:D,getCost:F,purchased:m,onPurchase:f,coinBalance:d}:void 0;return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"customize-preview",children:[l.jsx("div",{className:"customize-preview-bg",children:l.jsx(Aa,{roleId:e,appearance:t,scale:12})}),o&&l.jsx("div",{className:"customize-preview-name",children:o}),l.jsxs("div",{className:"customize-preview-actions",children:[l.jsx("button",{className:"customize-btn customize-btn--random",onClick:i,children:"RANDOM"}),l.jsx("button",{className:"customize-btn customize-btn--reset",onClick:a,children:"RESET"}),l.jsx("button",{className:"customize-btn",onClick:()=>{var D;return(D=g.current)==null?void 0:D.click()},style:{fontSize:9,opacity:.7},children:"PHOTO"}),l.jsx("input",{ref:g,type:"file",accept:"image/*",onChange:w,style:{display:"none"}})]})]}),l.jsxs("div",{className:"customize-colors",children:[l.jsxs("div",{style:{display:"flex",borderBottom:"1px solid rgba(255,255,255,0.06)",marginBottom:4},children:[l.jsx(Op,{label:"LOOK",active:x==="look",onClick:()=>p("look")}),l.jsx(Op,{label:"OUTFIT",active:x==="outfit",onClick:()=>p("outfit")}),l.jsx(Op,{label:"ACCESSORY",active:x==="accessory",onClick:()=>p("accessory")})]}),x==="look"&&l.jsxs(l.Fragment,{children:[l.jsx(Nc,{label:"SKIN",presets:F3,value:t.skinColor,onChange:D=>y("skinColor",D)}),l.jsx(Nc,{label:"HAIR COLOR",presets:R3,value:t.hairColor,onChange:D=>y("hairColor",D)}),c!==void 0&&l.jsxs("div",{style:{padding:"4px 8px",marginBottom:4,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:9,fontFamily:"var(--font-pixel, monospace)",color:"rgba(255,255,255,0.5)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("span",{children:["Lv.",c]}),l.jsxs("span",{children:[N,"/",k.length," unlocked"]})]}),l.jsx($p,{label:"HAIR STYLE",items:k,value:t.hairStyle,onChange:D=>y("hairStyle",D),lockInfo:z(N5,E8)})]}),x==="outfit"&&l.jsxs(l.Fragment,{children:[c!==void 0&&l.jsxs("div",{style:{padding:"4px 8px",marginBottom:4,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:9,fontFamily:"var(--font-pixel, monospace)",color:"rgba(255,255,255,0.5)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("span",{children:["Lv.",c]}),l.jsxs("span",{children:[E,"/",j.length," unlocked"]})]}),l.jsx($p,{label:"STYLE",items:j,value:t.outfitStyle,onChange:D=>y("outfitStyle",D),lockInfo:z(A5,T8)}),l.jsx(Nc,{label:"TOP",presets:z3,value:t.shirtColor,onChange:D=>y("shirtColor",D)}),l.jsx(Nc,{label:"PANTS",presets:B3,value:t.pantsColor,onChange:D=>y("pantsColor",D)}),l.jsx(Nc,{label:"SHOES",presets:$3,value:t.shoeColor,onChange:D=>y("shoeColor",D)})]}),x==="accessory"&&l.jsxs(l.Fragment,{children:[c!==void 0&&l.jsxs("div",{style:{padding:"4px 8px",marginBottom:4,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:9,fontFamily:"var(--font-pixel, monospace)",color:"rgba(255,255,255,0.5)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("span",{children:["Lv.",c]}),l.jsxs("span",{children:[A,"/",C.length," unlocked"]})]}),l.jsx($p,{label:"ACCESSORY",items:C,value:t.accessory,onChange:D=>y("accessory",D),lockInfo:z(_5,R8)}),l.jsx("div",{style:{marginTop:12,padding:"8px 10px",background:"rgba(255,255,255,0.03)",borderRadius:6,border:"1px dashed rgba(255,255,255,0.08)",color:"rgba(255,255,255,0.25)",fontSize:9,fontFamily:"var(--font-pixel, monospace)",textAlign:"center"},children:c!==void 0&&c<10?"Level up to unlock more accessories":"More accessories coming soon"})]})]})]})}const LB=[{value:"c-level",label:"C-Level"},{value:"member",label:"Member"}];function Ox(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)}function Lp(e){switch(e){case"c-level":return{authority:{autonomous:["Strategic decisions within domain","Task delegation to reports"],needsApproval:["Budget over $5K","External commitments"]},knowledge:{reads:["company/","operations/","projects/"],writes:["operations/","knowledge/"]},reports:{daily:"standup",weekly:"summary"}};default:return{authority:{autonomous:["Implementation within assigned tasks"],needsApproval:["Design changes","New dependencies"]},knowledge:{reads:["projects/"],writes:[]},reports:{daily:"standup",weekly:""}}}}const IB={cto:{name:"CTO",id:"cto",level:"c-level"},cbo:{name:"CBO",id:"cbo",level:"c-level"},pm:{name:"PM",id:"pm",level:"member"},engineer:{name:"Engineer",id:"engineer",level:"member"},designer:{name:"Designer",id:"designer",level:"member"},qa:{name:"QA Engineer",id:"qa",level:"member"}};let wa=null;async function HB(){if(wa)return wa;try{const n=await ke.getPreferences();if(n.instanceId)return wa=n.instanceId,localStorage.setItem("tycono_instance_id",wa),wa}catch{}const e="tycono_instance_id";let t=localStorage.getItem(e);return t||(t=crypto.randomUUID(),localStorage.setItem(e,t)),wa=t,t}const Ec=4;function UB(e,t,n){const i=e.trim();if(!i||i.startsWith("#"))return null;const a=i.split(",").map(p=>p.trim()),o=a[0];if(!o)return null;const c=Ox(o),m=(a[1]||"member").toLowerCase()==="c-level"?"c-level":"member",f=a[2]||"ceo";let x;return t.has(c)?x="ID already exists":n.has(c)&&(x="Duplicate ID in batch"),n.add(c),{name:o,id:c,level:m,reportsTo:f,error:x}}function qB({existingRoles:e,onClose:t,onHire:n,onStoreVisit:i,questHint:a}){const[o,c]=S.useState("single"),[d,m]=S.useState([]),[f,x]=S.useState(!1),[p,y]=S.useState("popular"),[g,w]=S.useState(""),[k,j]=S.useState(null),[C,N]=S.useState(!1),[E,A]=S.useState(""),[z,D]=S.useState("browse"),[F,q]=S.useState(""),[V,L]=S.useState(""),[_,B]=S.useState("ceo"),[X,R]=S.useState(null),[H,$]=S.useState(1),[G,Q]=S.useState(""),[K,M]=S.useState(""),[U,P]=S.useState(!1),[O,Z]=S.useState("member"),[ee,J]=S.useState(()=>{const ae=e.find(Ve=>Ve.level==="c-level");return(ae==null?void 0:ae.id)??"ceo"}),[se,le]=S.useState(""),[ye,De]=S.useState(to),[Ee,Re]=S.useState(!1),[me,Fe]=S.useState(""),[Je,Pe]=S.useState([]),[it,ht]=S.useState(new Set),[Ye,nt]=S.useState(""),[ut,kt]=S.useState("input"),[mt,ve]=S.useState({done:0,total:0}),be=S.useRef(null),te=S.useRef(null),oe=S.useRef(null);S.useEffect(()=>{ke.getSkills().then(ae=>Pe(ae.filter(Ve=>Ve.installed))).catch(()=>{}),HB().then(ae=>R(ae)).catch(()=>{})},[]),S.useEffect(()=>{var ae,Ve,We;o==="single"?(H===1&&((ae=be.current)==null||ae.focus()),H===2&&((Ve=te.current)==null||Ve.focus())):o==="bulk"&&ut==="input"&&((We=oe.current)==null||We.focus())},[H,o,ut]),S.useEffect(()=>{o==="store"&&z==="browse"&&d.length===0&&Ce()},[o,z]);const Ce=async()=>{x(!0);try{const ae=await ur.getCharacters({sort:p,instanceId:X??void 0});m(ae.characters)}catch{A("Failed to load job board")}x(!1)};S.useEffect(()=>{o==="store"&&z==="browse"&&Ce()},[p,X]);const pe=S.useMemo(()=>{if(!g.trim())return d;const ae=g.toLowerCase();return d.filter(Ve=>Ve.name.toLowerCase().includes(ae)||Ve.id.toLowerCase().includes(ae)||(Ve.tagline??"").toLowerCase().includes(ae))},[d,g]),Se=S.useMemo(()=>new Set(e.map(ae=>ae.id)),[e]),Me=S.useMemo(()=>{const ae=Ye.split(`
|
|
112
|
+
M${q.x},${q.y}h${q.width}v${q.height}h${-q.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}_3.displayName="MiniMap";S.memo(_3);const pB=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,xB={[yo.Line]:"right",[yo.Handle]:"bottom-right"};function gB({nodeId:e,position:t,variant:n=yo.Handle,className:i,style:a=void 0,children:o,color:c,minWidth:d=10,minHeight:m=10,maxWidth:f=Number.MAX_VALUE,maxHeight:x=Number.MAX_VALUE,keepAspectRatio:p=!1,resizeDirection:y,autoScale:g=!0,shouldResize:w,onResizeStart:k,onResize:j,onResizeEnd:C}){const N=c3(),E=typeof e=="string"?e:N,A=Dn(),z=S.useRef(null),D=n===yo.Handle,F=qt(S.useCallback(pB(D&&g),[D,g]),An),q=S.useRef(null),V=t??xB[n];S.useEffect(()=>{if(!(!z.current||!E))return q.current||(q.current=Pz({domNode:z.current,nodeId:E,getStoreItems:()=>{const{nodeLookup:_,transform:B,snapGrid:X,snapToGrid:R,nodeOrigin:H,domNode:$}=A.getState();return{nodeLookup:_,transform:B,snapGrid:X,snapToGrid:R,nodeOrigin:H,paneDomNode:$}},onChange:(_,B)=>{const{triggerNodeChanges:X,nodeLookup:R,parentLookup:H,nodeOrigin:$}=A.getState(),G=[],Q={x:_.x,y:_.y},K=R.get(E);if(K&&K.expandParent&&K.parentId){const M=K.origin??$,U=_.width??K.measured.width??0,P=_.height??K.measured.height??0,O={id:K.id,parentId:K.parentId,rect:{width:U,height:P,...Rk({x:_.x??K.position.x,y:_.y??K.position.y},{width:U,height:P},K.parentId,R,M)}},Z=$0([O],R,H,$);G.push(...Z),Q.x=_.x?Math.max(M[0]*U,_.x):void 0,Q.y=_.y?Math.max(M[1]*P,_.y):void 0}if(Q.x!==void 0&&Q.y!==void 0){const M={id:E,type:"position",position:{...Q}};G.push(M)}if(_.width!==void 0&&_.height!==void 0){const U={id:E,type:"dimensions",resizing:!0,setAttributes:y?y==="horizontal"?"width":"height":!0,dimensions:{width:_.width,height:_.height}};G.push(U)}for(const M of B){const U={...M,type:"position"};G.push(U)}X(G)},onEnd:({width:_,height:B})=>{const X={id:E,type:"dimensions",resizing:!1,dimensions:{width:_,height:B}};A.getState().triggerNodeChanges([X])}})),q.current.update({controlPosition:V,boundaries:{minWidth:d,minHeight:m,maxWidth:f,maxHeight:x},keepAspectRatio:p,resizeDirection:y,onResizeStart:k,onResize:j,onResizeEnd:C,shouldResize:w}),()=>{var _;(_=q.current)==null||_.destroy()}},[V,d,m,f,x,p,k,j,C,w]);const L=V.split("-");return l.jsx("div",{className:Yn(["react-flow__resize-control","nodrag",...L,n,i]),ref:z,style:{...a,scale:F,...c&&{[D?"backgroundColor":"borderColor"]:c}},children:o})}S.memo(gB);const yB={ceo:"#B71C1C",cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#7C4DFF",designer:"#E91E63",qa:"#00897B","data-analyst":"#0288D1","designer-seek":"#E91E63",test:"#78909C"},bB={ceo:"👑",cto:"⚙️",cbo:"📊",pm:"📋",engineer:"🏗️",designer:"🎨",qa:"🔍","data-analyst":"📈","designer-seek":"🎨",test:"🧪"};function vB(e){switch(e.status){case"streaming":return"#60A5FA";case"awaiting_input":return"#FBBF24";case"done":return"#4ADE80";case"error":return"#F87171";case"not-dispatched":return"#4B5563";default:return"#6B7280"}}function wB(e,t){switch(e.status){case"streaming":return"● Working...";case"awaiting_input":return"◉ Awaiting Reply";case"done":return t?"◎ Supervising":"✓ Complete";case"error":return"✗ Error";case"waiting":return"○ Waiting";default:return""}}const io={ceo:{w:120,h:48},"c-level":{w:170,h:64},member:{w:156,h:56}};function kB({data:e,id:t}){const n=e,{node:i,roleLevel:a,isSelected:o,isChecked:c,showCheckbox:d,isEligible:m,hasActiveChildren:f}=n,x=yB[i.roleId]??"#6B7280",p=vB(i),y=Na(i.status),g=a==="ceo",w=io[a],k=bB[i.roleId]??"👤",j=i.status==="not-dispatched",C=g?o?.9:.65:j&&!c?.4:1;return l.jsxs("div",{className:"org-rf-node",style:{width:w.w,height:w.h,borderRadius:g?24:12,background:g?"linear-gradient(135deg, #1a1a2e 0%, #16213e 100%)":`linear-gradient(180deg, ${x}10 0%, var(--terminal-bg-deeper, #181825) 40%)`,border:o?`2px solid ${x}`:c?"2px solid #EF5350":`1px solid ${j?"#333":x+"30"}`,borderStyle:j&&!c?"dashed":"solid",cursor:"pointer",opacity:C,display:"flex",flexDirection:"column",position:"relative",overflow:"hidden",boxShadow:y?`0 0 20px ${x}30, 0 4px 12px rgba(0,0,0,0.3)`:o?`0 0 12px ${x}20, 0 2px 8px rgba(0,0,0,0.2)`:"0 2px 6px rgba(0,0,0,0.15)"},children:[l.jsx(bo,{type:"target",position:at.Top,style:{opacity:0,width:1,height:1}}),l.jsx(bo,{type:"source",position:at.Bottom,style:{opacity:0,width:1,height:1}}),y&&l.jsx("div",{style:{position:"absolute",inset:-2,borderRadius:g?26:14,border:`2px solid ${p}`,animation:"org-rf-glow 2s ease-in-out infinite",pointerEvents:"none"}}),g?l.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",gap:8,padding:"0 16px"},children:[l.jsx("span",{style:{fontSize:18,lineHeight:1},children:"👑"}),l.jsx("span",{style:{fontSize:13,fontWeight:900,color:"#fff",fontFamily:"var(--pixel-font)",letterSpacing:2},children:"CEO"})]}):l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:a==="c-level"?"10px 12px":"8px 10px",flex:1},children:[l.jsx("div",{style:{width:a==="c-level"?32:28,height:a==="c-level"?32:28,borderRadius:8,background:`${x}18`,border:`1px solid ${x}30`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:a==="c-level"?16:14,flexShrink:0},children:k}),l.jsxs("div",{style:{flex:1,minWidth:0,overflow:"hidden"},children:[l.jsx("div",{style:{fontSize:a==="c-level"?12:11,fontWeight:800,color:x,fontFamily:"var(--pixel-font)",letterSpacing:.5,lineHeight:1.2},children:i.roleId.toUpperCase()}),i.roleName&&i.roleName!==i.roleId&&l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-secondary, #aaa)",fontFamily:"var(--pixel-font)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:1},children:i.roleName}),l.jsx("div",{style:{fontSize:9,color:p,fontFamily:"var(--pixel-font)",fontWeight:600,marginTop:2},children:wB(i,f)})]}),d&&!g?l.jsx("div",{onClick:N=>{N.stopPropagation(),m&&window.dispatchEvent(new CustomEvent("org-toggle-check",{detail:{roleId:t}}))},style:{cursor:m?"pointer":"default",opacity:m?1:.2,flexShrink:0},children:l.jsx("div",{style:{width:16,height:16,borderRadius:4,background:c?"#EF5350":"transparent",border:`2px solid ${c?"#EF5350":"#555"}`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,color:"#fff",transition:"all 0.15s"},children:c&&"✓"})}):!d&&i.status==="done"?l.jsx("span",{style:{fontSize:14,color:"#4ADE80",flexShrink:0,fontWeight:700},children:"✓"}):!d&&i.status==="error"?l.jsx("span",{style:{fontSize:14,color:"#F87171",flexShrink:0,fontWeight:700},children:"✗"}):null]})]})}const SB=S.memo(kB),jB={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#7C4DFF",designer:"#E91E63",qa:"#00897B","data-analyst":"#0288D1","designer-seek":"#E91E63",test:"#78909C"};function CB(e){const{sourceX:t,sourceY:n,targetX:i,targetY:a,data:o}=e,c=o??{},[d]=Mf({sourceX:t,sourceY:n,targetX:i,targetY:a,borderRadius:16});let m="rgba(180,200,240,0.08)",f="6 6",x=!1,p=1.5;return c.childStatus==="done"||c.parentStatus==="done"?(m="#4ADE8040",f="",p=2):c.childStatus==="awaiting_input"?(m="#FBBF2466",f="8 5",x=!0,p=2):c.childStatus==="streaming"&&(m=(jB[c.childRoleId??""]??"#60A5FA")+"55",f="8 5",x=!0,p=2.2),l.jsx(cu,{path:d,style:{stroke:m,strokeWidth:p,strokeDasharray:f},className:x?"wave-edge-flow":void 0})}const NB=S.memo(CB),Bp=24,EB=56,AB={orgRole:SB},DB={orgEdge:NB};function TB(e,t,n){var i,a;return e===t?"ceo":((i=n==null?void 0:n[e])==null?void 0:i.level)==="c-level"||((a=n==null?void 0:n[e])==null?void 0:a.reportsTo)===t?"c-level":"member"}function _B(e,t,n){if(!e.get(t))return[];const a=[],o=[],c=[{id:t,depth:0,parentId:null}],d=new Set;for(;c.length>0;){const{id:f,depth:x,parentId:p}=c.shift();if(d.has(f))continue;for(d.add(f);o.length<=x;)o.push([]);o[x].push(f);const y=TB(f,t,n);a.push({roleId:f,x:0,y:0,parentId:p,level:y});const g=e.get(f);if(g)for(const w of g.children)e.has(w)&&!d.has(w)&&c.push({id:w,depth:x+1,parentId:f})}let m=0;for(let f=0;f<o.length;f++){const x=o[f],p=Math.max(...x.map(w=>{const k=a.find(j=>j.roleId===w);return k?io[k.level].h:44}));let g=-x.reduce((w,k)=>{const j=a.find(C=>C.roleId===k);return w+(j?io[j.level].w:130)+Bp},-Bp)/2;for(const w of x){const k=a.find(C=>C.roleId===w);if(!k)continue;const j=io[k.level];k.x=g+j.w/2,k.y=m+(p-j.h)/2,g+=j.w+Bp}m+=p+EB}for(const f of a){const x=io[f.level];f.x-=x.w/2}return a}function M3({nodes:e,rootId:t,selectedRoleId:n,onSelectNode:i,checkedRoles:a,onToggleCheck:o,eligibleRoles:c,orgNodes:d}){const m=!!o,{rfNodes:f,rfEdges:x}=S.useMemo(()=>{const y=_B(e,t,d),g=y.map(k=>{const j=e.get(k.roleId);if(!j)return null;const C=j.children.some(A=>{const z=e.get(A);return z&&Na(z.status)}),N={node:j,roleLevel:k.level,isSelected:n===k.roleId,isChecked:(a==null?void 0:a.has(k.roleId))??!1,showCheckbox:m,isEligible:!c||c.has(k.roleId),hasActiveChildren:C},E=io[k.level];return{id:k.roleId,type:"orgRole",position:{x:k.x,y:k.y},data:N,draggable:!1,selectable:!1,width:E.w,height:E.h}}).filter(Boolean),w=y.filter(k=>k.parentId).map(k=>{const j=e.get(k.roleId),C=e.get(k.parentId);return{id:`${k.parentId}-${k.roleId}`,source:k.parentId,target:k.roleId,type:"orgEdge",data:{childStatus:j==null?void 0:j.status,parentStatus:C==null?void 0:C.status,childRoleId:k.roleId},selectable:!1}});return{rfNodes:g,rfEdges:w}},[e,t,n,a,c,m,d]),p=S.useCallback((y,g)=>{i(g.id)},[i]);return S.useEffect(()=>{if(!o)return;const y=g=>{var k;const w=(k=g.detail)==null?void 0:k.roleId;w&&o(w)};return window.addEventListener("org-toggle-check",y),()=>window.removeEventListener("org-toggle-check",y)},[o]),l.jsx("div",{className:"org-rf-container",style:{width:"100%",height:"100%",minHeight:220},children:l.jsx(X7,{nodes:f,edges:x,nodeTypes:AB,edgeTypes:DB,onNodeClick:p,fitView:!0,fitViewOptions:{padding:.12,minZoom:.5,maxZoom:1},zoomOnScroll:!1,zoomOnPinch:!1,panOnDrag:!1,panOnScroll:!1,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,preventScrolling:!1,proOptions:{hideAttribution:!0},minZoom:.3,maxZoom:2})})}const MB={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function FB({directive:e,rootDispatches:t,orgNodes:n,rootRoleId:i,waveId:a,onClose:o,onMinimize:c,onDone:d,onOpenKnowledgeDoc:m,onSave:f}){const{nodes:x,selectedRoleId:p,selectNode:y,progress:g,allDone:w,connectStream:k}=K5(t,n,i,a),[j,C]=S.useState(0),[N,E]=S.useState(new Set),[A,z]=S.useState(""),[D,F]=S.useState(!1),[q,V]=S.useState(!1),L=S.useRef(null),_=S.useRef(Date.now()),B=S.useRef(!1),X=S.useCallback(async()=>{if(f){V(!0);try{const P=t.map(O=>O.sessionId).filter(Boolean);await f(P)}catch(P){console.error("Save failed:",P)}finally{V(!1),o()}}},[f,t,o]),R=S.useCallback(async()=>{if(!p||!A.trim())return;const P=x.get(p);if(!(!(P!=null&&P.sessionId)||P.status!=="awaiting_input"&&P.status!=="done")){F(!0);try{await ke.replyToSession(P.sessionId,A.trim()),z(""),k(P.sessionId,p)}catch(O){console.error("Reply failed:",O)}finally{F(!1)}}},[p,A,x,k]),H=S.useCallback(async P=>{const O=x.get(P);if(O!=null&&O.sessionId)try{await ke.abortSession(O.sessionId)}catch{}},[x]),$=S.useCallback(async()=>{for(const[,P]of x)if(Na(P.status))try{P.sessionId&&await ke.abortSession(P.sessionId)}catch{}},[x]);S.useEffect(()=>{const P=setInterval(()=>{C(Math.floor((Date.now()-_.current)/1e3))},1e3);return()=>clearInterval(P)},[]);const G=S.useRef(!1);S.useEffect(()=>{const P=L.current;if(!P)return;const O=()=>{const Z=P.scrollHeight-P.scrollTop-P.clientHeight<60;G.current=!Z};return P.addEventListener("scroll",O),()=>P.removeEventListener("scroll",O)},[]),S.useEffect(()=>{G.current=!1,L.current&&(L.current.scrollTop=L.current.scrollHeight)},[p]),S.useEffect(()=>{L.current&&!G.current&&(L.current.scrollTop=L.current.scrollHeight)},[x]),S.useEffect(()=>{w&&!B.current&&(B.current=!0,d==null||d()),!w&&B.current&&(B.current=!1)},[w,d]);const Q=P=>`${Math.floor(P/60)}:${String(P%60).padStart(2,"0")}`,K=p?x.get(p):null,M=p?MB[p]??"#888":"#888",U=P=>{E(O=>{const Z=new Set(O);return Z.has(P)?Z.delete(P):Z.add(P),Z})};return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm pointer-events-none"}),l.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[960px] max-w-[95vw] h-[85vh] z-[61] bg-[var(--terminal-bg)] rounded-2xl shadow-2xl overflow-hidden flex flex-col",children:[l.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[var(--terminal-border)] shrink-0",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"w-3 h-3 rounded-full",style:{background:w?"#2E7D32":"#B71C1C",animation:w?void 0:"wave-pulse 2s ease-in-out infinite"}}),l.jsx("div",{children:l.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-sm",children:w?"WAVE COMPLETE":"WAVE COMMAND CENTER"})})]}),l.jsxs("div",{className:"flex items-center gap-4",children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs font-mono",children:Q(j)}),g.awaitingInput>0&&l.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:"#F59E0B22",color:"#F59E0B"},children:[g.awaitingInput," awaiting reply"]}),l.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold",style:{background:w?"#2E7D3222":"#B71C1C22",color:w?"#2E7D32":"#B71C1C"},children:[g.done,"/",g.total," done"]}),!w&&(g.running>0||g.awaitingInput>0)&&l.jsx("button",{onClick:$,className:"text-xs px-2 py-0.5 rounded font-semibold cursor-pointer",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},title:"Stop all running jobs",children:"Stop All"}),l.jsx("button",{onClick:c,title:"Minimize",className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-sm cursor-pointer px-1",children:"–"}),l.jsx("button",{onClick:o,className:"text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text)] text-lg cursor-pointer",title:w?"Dismiss wave":"Close (jobs keep running)",children:"×"})]})]}),l.jsx("div",{className:"px-5 py-2 border-b border-[var(--terminal-border)] shrink-0",children:l.jsxs("span",{className:"text-[var(--terminal-text-secondary)] text-xs italic",children:["“",e,"”"]})}),l.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[l.jsxs("div",{className:"shrink-0 border-b border-[var(--terminal-border)] flex flex-col",children:[l.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5",children:[l.jsx("span",{className:"text-[10px] font-bold text-[var(--terminal-text-secondary)] uppercase tracking-wider",children:"Org Propagation"}),l.jsx("div",{className:"flex gap-x-3 ml-auto",children:[{label:"streaming",color:"#FBBF24",dot:!0},{label:"awaiting",color:"#F59E0B",dot:!0},{label:"done",color:"#2E7D32",dot:!1},{label:"waiting",color:"#888",dot:!1},{label:"error",color:"#C62828",dot:!1}].map(P=>l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:P.color,animation:P.dot?"wave-pulse 1.5s ease-in-out infinite":void 0}}),l.jsx("span",{className:"text-[8px] text-[var(--terminal-text-muted)]",children:P.label})]},P.label))})]}),l.jsx("div",{className:"px-3 pb-2",style:{height:"35vh"},children:l.jsx(M3,{nodes:x,rootId:i,selectedRoleId:p,onSelectNode:y,orgNodes:n})})]}),l.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[K&&l.jsxs("div",{className:"px-4 py-2 border-b border-[var(--terminal-border)] shrink-0 flex items-center gap-2",children:[l.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:M}}),l.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-xs",children:K.roleId.toUpperCase()}),l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs",children:K.roleName}),l.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full font-semibold",style:{background:K.status==="awaiting_input"?"#F59E0B22":`${M}22`,color:K.status==="awaiting_input"?"#F59E0B":M},children:K.status==="streaming"?"Working":K.status==="done"?"Complete":K.status==="error"?"Error":K.status==="waiting"?"Waiting":K.status==="awaiting_input"?"Awaiting Reply":"Not dispatched"}),Na(K.status)&&K.sessionId&&l.jsx("button",{onClick:()=>H(K.roleId),className:"text-[10px] px-2 py-0.5 rounded font-semibold cursor-pointer ml-1",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},title:"Force stop this execution",children:"Stop"})]}),l.jsxs("div",{ref:L,className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-1 text-xs font-mono select-text",children:[K&&K.events.length===0&&l.jsx("div",{className:"text-[var(--terminal-text-muted)]",children:K.status==="waiting"?"Waiting for dispatch...":K.status==="streaming"?"Connecting to activity stream...":K.status==="not-dispatched"?"This role was not dispatched in this wave.":""}),K==null?void 0:K.events.map(P=>l.jsx(k0,{event:P,isThinkingCollapsed:N.has(P.seq),onToggleThinking:()=>U(P.seq),onNavigateToSession:O=>{const Z=K==null?void 0:K.events.find(J=>J.type==="dispatch:start"&&J.data.childSessionId===O),ee=Z==null?void 0:Z.data.targetRoleId;ee&&x.has(ee)&&y(ee)},onOpenKnowledgeDoc:m},P.seq)),(K==null?void 0:K.status)==="streaming"&&l.jsx("span",{className:"inline-block w-2 h-4 bg-green-400 animate-pulse ml-0.5"})]}),(K==null?void 0:K.status)==="awaiting_input"&&l.jsxs("div",{className:"px-4 py-3 border-t border-[var(--terminal-border)] shrink-0",style:{background:"#F59E0B0A"},children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:"#F59E0B",animation:"wave-pulse 1.5s ease-in-out infinite"}}),l.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#F59E0B"},children:[K.roleName," is waiting for your response"]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{type:"text",value:A,onChange:P=>z(P.target.value),onKeyDown:P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),R())},placeholder:"Type your response...",disabled:D,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] border-[var(--terminal-border)] outline-none focus:border-[#F59E0B]",autoFocus:!0}),l.jsx("button",{onClick:R,disabled:D||!A.trim(),className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#F59E0B",color:"#000"},children:D?"...":"Reply"})]})]}),(K==null?void 0:K.status)==="done"&&K.sessionId&&l.jsxs("div",{className:"px-4 py-3 border-t border-[var(--terminal-border)] shrink-0",style:{background:"#1565C00A"},children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#64B5F6"},children:["Follow-up to ",K.roleName]}),l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:"Send a follow-up directive"})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{type:"text",value:A,onChange:P=>z(P.target.value),onKeyDown:P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),R())},placeholder:"e.g., 좋아 KB-3 진행해, Engineer에게 시켜...",disabled:D,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] border-[var(--terminal-border)] outline-none focus:border-[#64B5F6]"}),l.jsx("button",{onClick:R,disabled:D||!A.trim(),className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#1565C0",color:"#fff"},children:D?"...":"Send"})]})]}),!K&&l.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-xs",children:"Click a node in the org tree to view activity"}),l.jsxs("div",{className:"px-4 py-2 border-t border-[var(--terminal-border)] flex items-center justify-between shrink-0",children:[l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:K&&K.events.length>0&&`${K.events.length} events`}),w&&l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("button",{onClick:o,className:"px-4 py-1.5 text-xs rounded-lg font-semibold cursor-pointer",style:{background:"rgba(255,255,255,0.08)",color:"var(--terminal-text-muted)"},children:"Dismiss"}),f&&l.jsx("button",{onClick:X,disabled:q,className:"px-4 py-1.5 text-xs text-white rounded-lg font-semibold cursor-pointer disabled:opacity-50",style:{background:"#2E7D32"},children:q?"Saving...":"Save Wave"})]})]})]})]})]})]})}const RB={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function Iw({orgNodes:e,rootRoleId:t,cLevelRoles:n,pastWaves:i,activeWaves:a,onDispatch:o,onClose:c,onDone:d,onSave:m,onOpenKnowledgeDoc:f,onRefreshWaves:x,terminalWidth:p=0,onMaximize:y,inline:g=!1,onOpenSaveModal:w}){const[k,j]=S.useState(""),[C,N]=S.useState(!1),[E,A]=S.useState(null),[z,D]=S.useState(!1),[F,q]=S.useState(a.length>0?0:-1),[,V]=S.useState(!1),L=S.useRef(null),_=F>=0?a[F]??null:null,B=S.useMemo(()=>[],[]),X=(_==null?void 0:_.rootDispatches)??B,R=K5(X,e,t,(_==null?void 0:_.id)??null);S.useEffect(()=>{if(E){const ce=zB(e,t,E.roles);R.injectStaticNodes(ce);for(const Ue of E.roles??[])if(y2(Ue.status)&&Ue.sessionId){const $e=ce.get(Ue.roleId);$e!=null&&$e.sessionId&&setTimeout(()=>R.connectStream($e.sessionId,Ue.roleId),100)}}},[E,e,t]),S.useEffect(()=>{!R.selectedRoleId&&t&&R.selectNode(t)},[t]);const H=S.useRef(a.length);S.useEffect(()=>{const ce=a.length>H.current;H.current=a.length,ce&&(q(0),A(null),V(!1))},[a.length]);const[$,G]=S.useState(null),Q=S.useMemo(()=>{if(!$)return null;const ce=$.modified.length+$.untracked.length;return{branch:$.branch,dirty:ce>0,count:ce}},[$]),K=S.useCallback(()=>{ke.getSaveStatus("code").then(ce=>{G({dirty:ce.modified.length+ce.untracked.length>0,modified:ce.modified,untracked:ce.untracked,lastCommit:ce.lastCommit,branch:ce.branch})}).catch(()=>{})},[]);S.useEffect(()=>{K()},[K]);const[M,U]=S.useState(0);S.useEffect(()=>{if(!_)return;const ce=setInterval(()=>{U(Math.floor((Date.now()-_.startedAt)/1e3))},1e3);return()=>clearInterval(ce)},[_]);const[P,O]=S.useState(""),[Z,ee]=S.useState(!1),[J,se]=S.useState([]),[le,ye]=S.useState(!1),[De,Ee]=S.useState(null),Re=S.useRef(null);S.useEffect(()=>{if(De){const ce=setTimeout(()=>Ee(null),3e3);return()=>clearTimeout(ce)}},[De]);const me=S.useCallback(async ce=>["image/png","image/jpeg","image/gif","image/webp"].includes(ce.type)?ce.size>5*1024*1024?(Ee(`Too large: ${(ce.size/1024/1024).toFixed(1)}MB. Max 5MB.`),null):new Promise($e=>{const dt=new FileReader;dt.onload=()=>{const wt=dt.result.split(",")[1];$e({type:"image",data:wt,name:ce.name,mediaType:ce.type})},dt.onerror=()=>{Ee("Failed to read file"),$e(null)},dt.readAsDataURL(ce)}):(Ee(`Unsupported: ${ce.type}. Use PNG, JPG, GIF, or WebP.`),null),[]),Fe=S.useCallback(async ce=>{const Ue=[];for(const $e of Array.from(ce)){const dt=await me($e);dt&&Ue.push(dt)}Ue.length>0&&se($e=>[...$e,...Ue])},[me]),Je=S.useCallback(ce=>{ce.preventDefault(),ce.stopPropagation(),ye(!0)},[]),Pe=S.useCallback(ce=>{ce.preventDefault(),ce.stopPropagation(),ye(!1)},[]),it=S.useCallback(ce=>{ce.preventDefault(),ce.stopPropagation(),ye(!1),ce.dataTransfer.files.length>0&&Fe(ce.dataTransfer.files)},[Fe]),ht=S.useCallback(ce=>{const Ue=[];for(let $e=0;$e<ce.clipboardData.items.length;$e++){const dt=ce.clipboardData.items[$e];if(dt.type.startsWith("image/")){const wt=dt.getAsFile();wt&&Ue.push(wt)}}Ue.length>0&&(ce.preventDefault(),Fe(Ue))},[Fe]),[Ye,nt]=S.useState(320),ut=S.useRef(!1),kt=S.useRef(0),mt=S.useRef(0),ve=S.useCallback(ce=>{ce.preventDefault(),ut.current=!0,kt.current=ce.clientX,mt.current=Ye;const Ue=dt=>{if(!ut.current)return;const wt=kt.current-dt.clientX;nt(Math.max(200,Math.min(500,mt.current+wt)))},$e=()=>{ut.current=!1,window.removeEventListener("mousemove",Ue),window.removeEventListener("mouseup",$e)};window.addEventListener("mousemove",Ue),window.addEventListener("mouseup",$e)},[Ye]),[be,te]=S.useState(new Set),oe=S.useRef(null),Ce=S.useRef(!1);S.useEffect(()=>{const ce=oe.current;if(!ce)return;const Ue=()=>{const $e=ce.scrollHeight-ce.scrollTop-ce.clientHeight<60;Ce.current=!$e};return ce.addEventListener("scroll",Ue),()=>ce.removeEventListener("scroll",Ue)},[]),S.useEffect(()=>{!Ce.current&&oe.current&&(oe.current.scrollTop=oe.current.scrollHeight)},[R.nodes,R.selectedRoleId]);const pe=R.selectedRoleId?R.nodes.get(R.selectedRoleId)??null:null,Se=pe?RB[pe.roleId]??"#888":"#888",Me=R.progress.running>0||R.progress.awaitingInput>0,Ge=R.selectedRoleId===t,Ie=!!E&&!_,qe=(_==null?void 0:_.directive)??(E==null?void 0:E.directive)??"",Xe=S.useCallback(ce=>{const Ue=new Set,$e=[ce];for(;$e.length>0;){const dt=$e.shift();if(Ue.has(dt))continue;Ue.add(dt);const wt=e[dt];wt&&$e.push(...wt.children)}return Ue},[e]),et=S.useMemo(()=>{if(!R.selectedRoleId)return new Set;const ce=Xe(R.selectedRoleId);return ce.delete(t),ce},[R.selectedRoleId,Xe,t]),ze=S.useRef(null);S.useEffect(()=>{if(R.selectedRoleId===ze.current||(ze.current=R.selectedRoleId,!R.selectedRoleId))return;const ce=Xe(R.selectedRoleId);ce.delete(t),R.setCheckedRoles(ce)},[R.selectedRoleId,Xe,t]);const Be=R.checkedRoles.size,_t=()=>{if(!k.trim()&&J.length===0||Be===0)return;const Ue=Array.from(R.nodes.keys()).filter(dt=>dt!==t).every(dt=>R.checkedRoles.has(dt)),$e=J.length>0?J:void 0;o(k.trim(),Ue?void 0:Array.from(R.checkedRoles),$e,C||void 0),j(""),se([])},en=ce=>{ce.key==="Enter"&&(ce.metaKey||ce.ctrlKey)&&(ce.preventDefault(),_t()),ce.key==="Escape"&&c()},Tt=S.useCallback(async()=>{if(!R.selectedRoleId||!P.trim()&&J.length===0)return;const ce=R.nodes.get(R.selectedRoleId);if(!ce)return;const Ue=J.length>0?J:void 0;ee(!0);try{if(ce.status==="awaiting_input"&&ce.sessionId){const $e=await ke.replyToSession(ce.sessionId,P.trim(),Ue);O(""),se([]),!!(_!=null&&_.id)||R.connectStream($e.sessionId||ce.sessionId,R.selectedRoleId)}else{const $e=(_==null?void 0:_.id)??(E==null?void 0:E.waveId)??(E==null?void 0:E.id),dt=await ke.execute({type:"assign",roleId:R.selectedRoleId,task:P.trim(),...$e&&{waveId:$e},...Ue&&{attachments:Ue}});O(""),se([]),dt.sessionId&&(_!=null&&_.id||R.connectStream(dt.sessionId,R.selectedRoleId))}}catch($e){console.error("Reply failed:",$e)}finally{ee(!1)}},[R,P,J,_,E]),Pt=S.useCallback(async ce=>{const Ue=R.nodes.get(ce);if(Ue!=null&&Ue.sessionId)try{await ke.abortSession(Ue.sessionId)}catch{}},[R.nodes]),hn=S.useCallback(async()=>{for(const[,ce]of R.nodes)if(Na(ce.status))try{ce.sessionId&&await ke.abortSession(ce.sessionId)}catch{}},[R.nodes]),Zt=S.useCallback(async ce=>{D(!0),A(null),q(-1);try{const Ue=await ke.getWaveDetail(ce);Ue.replay&&A(Ue.replay)}catch(Ue){console.error("Failed to load wave:",Ue)}finally{D(!1)}},[]),ae=S.useRef(!1);S.useEffect(()=>{ae.current||a.length===0&&i.length>0&&!E&&!z&&(ae.current=!0,Zt(i[0].id))},[a.length,i,E,z,Zt]);const Ve=S.useRef(!1),We=S.useRef(null);S.useEffect(()=>{if(!(E||z)&&((_==null?void 0:_.id)!==We.current&&(Ve.current=!1,We.current=(_==null?void 0:_.id)??null),R.allDone&&!Ve.current&&_&&(Ve.current=!0,K(),d==null||d(),m))){const ce=_.rootDispatches.map(Ue=>Ue.sessionId).filter(Boolean);m(_.directive,ce,{waveId:_.id,sessionIds:_.sessionIds}).catch(()=>{})}},[R.allDone,_,d,m,K,E,z]);const tn=S.useCallback(async()=>{if(!m||!_)return;const ce=_.rootDispatches.map(Ue=>Ue.sessionId).filter(Boolean);await m(_.directive,ce,{waveId:_.id,sessionIds:_.sessionIds})},[m,_]),Ne=ce=>{te(Ue=>{const $e=new Set(Ue);return $e.has(ce)?$e.delete(ce):$e.add(ce),$e})},Ct=ce=>{const Ue=Math.floor(ce/60),$e=ce%60;return`${Ue}:${$e.toString().padStart(2,"0")}`},{panelRight:ln,panelWidth:nn,isResizing:Kr,handleResizeStart:gr}=nu(p,700,y),vn=l.jsxs(l.Fragment,{children:[!g&&l.jsxs("div",{className:"shrink-0 px-4 py-3",style:{background:"linear-gradient(180deg, #B71C1C 0%, #7f1d1d 100%)"},children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("span",{className:"text-white font-bold text-lg tracking-wide",style:{fontFamily:"var(--pixel-font)"},children:"Wave Center"}),Me&&l.jsxs("span",{className:"text-white/60 text-xs",children:[R.progress.running+R.progress.awaitingInput," active",R.progress.awaitingInput>0&&` (${R.progress.awaitingInput} awaiting)`]}),l.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[y&&l.jsx("button",{onClick:y,className:"text-white/50 hover:text-white text-xs cursor-pointer",children:"Maximize"}),l.jsx("button",{onClick:c,className:"text-white/50 hover:text-white text-xl leading-none cursor-pointer px-2",children:"✕"})]})]}),l.jsx("div",{className:"text-white/60 text-xs mt-0.5",children:_?`${a.length} active wave${a.length!==1?"s":""}`:Ie?"Reviewing past wave":"Broadcast directives to your organization"})]}),l.jsxs("div",{className:"flex-1 flex min-h-0",children:[l.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[(_||Ie)&&l.jsxs("div",{className:"px-4 py-2 border-b flex items-center gap-3 shrink-0",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("div",{className:"w-3 h-3 rounded-full shrink-0",style:{background:Me?"#FBBF24":R.allDone||Ie?"#2E7D32":"#B71C1C",animation:Me?"wave-pulse 2s ease-in-out infinite":void 0}}),l.jsxs("span",{className:"text-[var(--terminal-text-secondary)] text-xs italic flex-1 min-w-0 truncate",children:["“",qe,"”"]}),_&&l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs font-mono shrink-0",children:Ct(M)}),Ie&&l.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-semibold shrink-0",style:{background:Me?"#FBBF2422":"#2E7D3222",color:Me?"#FBBF24":"#2E7D32"},children:Me?"LIVE":"REPLAY"}),Ie&&(E==null?void 0:E.startedAt)&&l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-[10px] shrink-0",children:new Date(E.startedAt).toLocaleString()}),R.progress.awaitingInput>0&&l.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-semibold shrink-0",style:{background:"#F59E0B22",color:"#F59E0B"},children:[R.progress.awaitingInput," awaiting"]}),l.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-semibold shrink-0",style:{background:R.allDone||Ie&&!Me?"#2E7D3222":"#B71C1C22",color:R.allDone||Ie&&!Me?"#2E7D32":"#B71C1C"},children:[R.progress.done,"/",R.progress.total]}),Me&&l.jsx("button",{onClick:hn,className:"text-[10px] px-2 py-0.5 rounded font-semibold cursor-pointer shrink-0",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},children:"Stop All"})]}),l.jsxs("div",{className:"shrink-0 border-b flex flex-col",style:{borderColor:"var(--terminal-border)"},children:[l.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5",children:[l.jsx("span",{className:"text-[10px] font-bold text-[var(--terminal-text-secondary)] uppercase tracking-wider",children:_||Ie?"Org Propagation":"Select Target Roles"}),l.jsxs("span",{className:"ml-auto text-[10px] text-[var(--terminal-text-muted)]",children:[R.checkedRoles.size,"/",R.progress.total," selected"]}),(_||Ie)&&l.jsx("div",{className:"flex gap-x-3",children:[{label:"streaming",color:"#FBBF24",dot:!0},{label:"awaiting",color:"#F59E0B",dot:!0},{label:"done",color:"#2E7D32",dot:!1},{label:"waiting",color:"#888",dot:!1},{label:"error",color:"#C62828",dot:!1}].map(ce=>l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:ce.color,animation:ce.dot?"wave-pulse 1.5s ease-in-out infinite":void 0}}),l.jsx("span",{className:"text-[8px] text-[var(--terminal-text-muted)]",children:ce.label})]},ce.label))})]}),l.jsx("div",{className:"px-3 pb-2",style:{height:"38vh"},children:l.jsx(M3,{nodes:R.nodes,rootId:t,selectedRoleId:R.selectedRoleId,onSelectNode:R.selectNode,checkedRoles:R.checkedRoles,onToggleCheck:R.toggleCheck,eligibleRoles:et,orgNodes:e})})]}),z?l.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-sm",children:"Loading wave data..."}):Ge?l.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[l.jsxs("div",{className:"px-4 py-2 border-b shrink-0 flex items-center gap-2",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:"#B71C1C"}}),l.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-xs",children:"CEO"}),l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs",children:"Directive Control"}),l.jsxs("span",{className:"ml-auto text-[10px] text-[var(--terminal-text-muted)]",children:[Be," target role",Be!==1?"s":""," selected"]})]}),l.jsxs("div",{ref:oe,className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-2 text-xs font-mono select-text",children:[qe&&l.jsxs("div",{className:"flex items-start gap-2 pb-3 border-b",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("span",{className:"text-[10px] font-bold px-1.5 py-0.5 rounded shrink-0",style:{background:"#B71C1C33",color:"#EF5350"},children:"CEO"}),l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-secondary)] whitespace-pre-wrap",children:qe}),_&&l.jsxs("div",{className:"text-[9px] text-[var(--terminal-text-muted)] mt-1",children:["dispatched ",Ct(M)," ago to ",_.rootDispatches.length," role",_.rootDispatches.length!==1?"s":""]})]})]}),!qe&&!_&&l.jsx("div",{className:"text-[var(--terminal-text-muted)] text-center py-8",children:"Select target roles using checkboxes, then dispatch a directive below."})]}),l.jsxs("div",{className:"px-4 py-3 border-t shrink-0",style:{borderColor:"var(--terminal-border)",background:"var(--hud-bg-alt)"},children:[J.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:J.map((ce,Ue)=>l.jsxs("div",{className:"relative group w-14 h-14 rounded-lg overflow-hidden border border-[var(--terminal-border)] bg-[var(--terminal-inline-bg)]",children:[l.jsx("img",{src:`data:${ce.mediaType};base64,${ce.data}`,alt:ce.name,className:"w-full h-full object-cover"}),l.jsx("button",{onClick:()=>se($e=>$e.filter((dt,wt)=>wt!==Ue)),className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-black/70 text-white text-[9px] flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:"x"}),l.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-[7px] text-white truncate px-1",children:ce.name})]},Ue))}),De&&l.jsx("div",{className:"text-[10px] text-red-400 mb-1",children:De}),l.jsxs("div",{className:"flex gap-2 items-end",children:[l.jsx("button",{onClick:()=>{var ce;return(ce=Re.current)==null?void 0:ce.click()},className:"w-8 h-8 rounded-lg bg-[var(--terminal-inline-bg)] border border-[var(--terminal-border)] text-[var(--terminal-text-muted)] flex items-center justify-center shrink-0 cursor-pointer hover:text-[var(--terminal-text-secondary)] transition-colors",title:"Attach image",children:l.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),l.jsx("textarea",{ref:L,value:k,onChange:ce=>j(ce.target.value),onKeyDown:en,onPaste:ht,placeholder:"e.g. Report current status across all departments",rows:2,className:"flex-1 px-3 py-2 text-sm rounded-lg border bg-[var(--terminal-bg)] text-[var(--terminal-text)] outline-none resize-none",style:{borderColor:"var(--terminal-border)"}}),l.jsxs("button",{onClick:_t,disabled:!k.trim()&&J.length===0||Be===0,className:"px-4 py-2 text-xs font-bold rounded-lg cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed shrink-0",style:{background:k.trim()&&Be>0?"#B71C1C":"#333",color:"#fff",minWidth:140},children:["Dispatch to ",Be," Role",Be!==1?"s":""]})]}),l.jsxs("div",{className:"flex items-center justify-between mt-1",children:[l.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[l.jsx("input",{type:"checkbox",checked:C,onChange:ce=>N(ce.target.checked),className:"accent-[#B71C1C] w-3 h-3 cursor-pointer"}),l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:"Continuous"})]}),l.jsx("div",{className:"text-[9px] text-[var(--terminal-text-muted)]",children:"Cmd+Enter to dispatch"})]})]})]}):l.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[pe&&l.jsxs("div",{className:"px-4 py-2 border-b shrink-0 flex items-center gap-2",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:Se}}),l.jsx("span",{className:"text-[var(--terminal-text)] font-bold text-xs",children:pe.roleId.toUpperCase()}),l.jsx("span",{className:"text-[var(--terminal-text-muted)] text-xs",children:pe.roleName}),l.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full font-semibold",style:{background:pe.status==="awaiting_input"?"#F59E0B22":pe.status==="streaming"?"#FBBF2422":`${Se}22`,color:pe.status==="awaiting_input"?"#F59E0B":pe.status==="streaming"?"#FBBF24":Se},children:pe.status==="streaming"?"Working...":pe.status==="done"?pe.children.some(ce=>{const Ue=R.nodes.get(ce);return Ue&&Na(Ue.status)})?"Supervising...":"Complete":pe.status==="error"?"Error":pe.status==="waiting"?"Waiting":pe.status==="awaiting_input"?"Awaiting Reply":"Not dispatched"}),l.jsxs("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:[pe.events.length," events"]}),Na(pe.status)&&pe.sessionId&&l.jsx("button",{onClick:()=>Pt(pe.roleId),className:"text-[10px] px-2 py-0.5 rounded font-semibold cursor-pointer ml-1",style:{background:"#C6282822",color:"#C62828",border:"1px solid #C6282844"},children:"Stop"})]}),pe&&l.jsxs("div",{className:"px-4 py-2 border-b shrink-0",style:{borderColor:"var(--terminal-border)",background:"var(--hud-bg-alt)"},children:[l.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-[10px] font-mono",children:[pe.sessionId&&l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)]",children:"Session "}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)]",children:pe.sessionId.slice(0,8)})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)]",children:"Events "}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)]",children:pe.events.length})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)]",children:"Stream "}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)]",children:pe.streamStatus})]}),(()=>{const ce=pe.events[pe.events.length-1];if(!(ce!=null&&ce.ts))return null;const Ue=Math.floor((Date.now()-new Date(ce.ts).getTime())/1e3);if(isNaN(Ue)||Ue<0)return null;const $e=Ue<60?`${Ue}s ago`:Ue<3600?`${Math.floor(Ue/60)}m ago`:`${Math.floor(Ue/3600)}h ago`;return l.jsxs("div",{children:[l.jsx("span",{className:"text-[var(--terminal-text-muted)]",children:"Last activity "}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)]",children:$e})]})})()]}),(()=>{var wt,yr;const ce=pe.events.filter(Pn=>Pn.type==="text"||Pn.type==="tool:result"),Ue=ce[ce.length-1];if(!Ue)return null;const $e=typeof((wt=Ue.data)==null?void 0:wt.text)=="string"?Ue.data.text:typeof((yr=Ue.data)==null?void 0:yr.content)=="string"?Ue.data.content:null;if(!$e)return null;const dt=$e.length>120?$e.slice(0,120)+"...":$e;return l.jsx("div",{className:"mt-1.5 text-[10px] text-[var(--terminal-text-muted)] italic truncate",title:$e,children:dt})})()]}),l.jsx("input",{ref:Re,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",multiple:!0,onChange:ce=>{var Ue;(Ue=ce.target.files)!=null&&Ue.length&&Fe(ce.target.files),ce.target.value=""},className:"hidden"}),l.jsxs("div",{ref:oe,className:`flex-1 min-h-0 overflow-y-auto p-4 space-y-1 text-xs font-mono select-text transition-colors ${le?"bg-amber-500/5 ring-1 ring-inset ring-amber-500/30":""}`,onDragOver:Je,onDragLeave:Pe,onDrop:it,children:[pe&&qe&&pe.status!=="waiting"&&pe.status!=="not-dispatched"&&l.jsxs("div",{className:"flex items-start gap-2 mb-3 pb-2 border-b",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("span",{className:"text-[10px] font-bold px-1.5 py-0.5 rounded shrink-0",style:{background:"#B71C1C33",color:"#EF5350"},children:"CEO"}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)] whitespace-pre-wrap",children:qe})]}),pe&&pe.events.length===0&&l.jsx("div",{className:"text-[var(--terminal-text-muted)]",children:pe.status==="waiting"?"Waiting for dispatch...":pe.status==="streaming"?"Connecting to activity stream...":pe.status==="not-dispatched"?"This role was not dispatched. Send a follow-up to activate.":""}),pe==null?void 0:pe.events.map((ce,Ue)=>{const $e=pe.events,dt=ce.type==="msg:start"&&Ue>0,wt=$e[Ue+1];if((ce.type==="msg:done"||ce.type==="msg:error"||ce.type==="msg:awaiting_input")&&(wt==null?void 0:wt.type)==="msg:start")return null;if(dt){const Pn=ce.data.task??"",Qr=Pn.match(/\[CEO Follow-up\]\n([\s\S]+)$/),fi=Qr?Qr[1].trim():Pn;return l.jsx(S.Fragment,{children:l.jsxs("div",{className:"flex items-start gap-2 my-3 pt-2 pb-2 border-t border-b",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("span",{className:"text-[10px] font-bold px-1.5 py-0.5 rounded shrink-0",style:{background:"#B71C1C33",color:"#EF5350"},children:"CEO"}),l.jsx("span",{className:"text-[var(--terminal-text-secondary)] whitespace-pre-wrap",children:fi})]})},`followup-${ce.seq}`)}return l.jsx(k0,{event:ce,isThinkingCollapsed:be.has(ce.seq),onToggleThinking:()=>Ne(ce.seq),onNavigateToSession:Pn=>{for(const[,Qr]of R.nodes)if(Qr.events.some(fi=>fi.data.childSessionId===Pn)){R.selectNode(Qr.roleId);return}},onOpenKnowledgeDoc:f},ce.seq)}),(pe==null?void 0:pe.status)==="streaming"&&l.jsx("span",{className:"inline-block w-2 h-4 bg-green-400 animate-pulse ml-0.5"}),!pe&&l.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-xs h-full",children:"Click a node in the org tree to view activity"})]}),((pe==null?void 0:pe.status)==="awaiting_input"||(pe==null?void 0:pe.status)==="done"||(pe==null?void 0:pe.status)==="not-dispatched")&&(J.length>0||De||le)&&l.jsxs("div",{className:"px-4 pt-2 border-t shrink-0",style:{borderColor:"var(--terminal-border)"},children:[De&&l.jsx("div",{className:"text-[10px] text-red-400 mb-1",children:De}),le&&l.jsx("div",{className:"text-[11px] text-amber-400 text-center mb-1",children:"Drop image here"}),J.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2 mb-1",children:J.map((ce,Ue)=>l.jsxs("div",{className:"relative group w-14 h-14 rounded-lg overflow-hidden border border-[var(--terminal-border)] bg-[var(--terminal-inline-bg)]",children:[l.jsx("img",{src:`data:${ce.mediaType};base64,${ce.data}`,alt:ce.name,className:"w-full h-full object-cover"}),l.jsx("button",{onClick:()=>se($e=>$e.filter((dt,wt)=>wt!==Ue)),className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-black/70 text-white text-[9px] flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:"x"}),l.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-[7px] text-white truncate px-1",children:ce.name})]},Ue))})]}),(pe==null?void 0:pe.status)==="awaiting_input"&&l.jsxs("div",{className:"px-4 py-3 border-t shrink-0",style:{borderColor:"var(--terminal-border)",background:"#F59E0B0A"},children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx("span",{className:"w-2 h-2 rounded-full inline-block",style:{background:"#F59E0B",animation:"wave-pulse 1.5s ease-in-out infinite"}}),l.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#F59E0B"},children:[pe.roleName," is waiting for your response"]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>{var ce;return(ce=Re.current)==null?void 0:ce.click()},disabled:Z,className:"w-7 h-7 rounded bg-[var(--terminal-inline-bg)] border border-[var(--terminal-border)] text-[var(--terminal-text-muted)] flex items-center justify-center shrink-0 cursor-pointer hover:text-[var(--terminal-text-secondary)] disabled:opacity-30 transition-colors",title:"Attach image",children:l.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),l.jsx("input",{type:"text",value:P,onChange:ce=>O(ce.target.value),onKeyDown:ce=>{ce.key==="Enter"&&!ce.shiftKey&&(ce.preventDefault(),Tt())},onPaste:ht,placeholder:"Type your response...",disabled:Z,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] outline-none",style:{borderColor:"var(--terminal-border)"},autoFocus:!0}),l.jsx("button",{onClick:Tt,disabled:Z||!P.trim()&&J.length===0,className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#F59E0B",color:"#000"},children:Z?"...":"Reply"})]})]}),pe&&(pe.status==="done"||pe.status==="not-dispatched")&&l.jsxs("div",{className:"px-4 py-3 border-t shrink-0",style:{borderColor:"var(--terminal-border)",background:"#1565C00A"},children:[l.jsx("div",{className:"flex items-center gap-2 mb-2",children:l.jsxs("span",{className:"text-[11px] font-semibold",style:{color:"#64B5F6"},children:["Follow-up to ",pe.roleName]})}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>{var ce;return(ce=Re.current)==null?void 0:ce.click()},disabled:Z,className:"w-7 h-7 rounded bg-[var(--terminal-inline-bg)] border border-[var(--terminal-border)] text-[var(--terminal-text-muted)] flex items-center justify-center shrink-0 cursor-pointer hover:text-[var(--terminal-text-secondary)] disabled:opacity-30 transition-colors",title:"Attach image",children:l.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),l.jsx("input",{type:"text",value:P,onChange:ce=>O(ce.target.value),onKeyDown:ce=>{ce.key==="Enter"&&!ce.shiftKey&&(ce.preventDefault(),Tt())},onPaste:ht,placeholder:"Send a follow-up directive...",disabled:Z,className:"flex-1 px-3 py-1.5 text-xs rounded border bg-[var(--terminal-bg)] text-[var(--terminal-text)] outline-none",style:{borderColor:"var(--terminal-border)"}}),l.jsx("button",{onClick:Tt,disabled:Z||!P.trim()&&J.length===0,className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#1565C0",color:"#fff"},children:Z?"...":"Send"})]})]}),R.allDone&&_&&m&&l.jsx("div",{className:"px-4 py-2 border-t shrink-0 flex justify-end",style:{borderColor:"var(--terminal-border)"},children:l.jsx("button",{onClick:tn,className:"px-4 py-1.5 text-xs rounded font-semibold cursor-pointer",style:{background:"#1565C022",color:"#64B5F6",border:"1px solid #1565C044"},children:"Save Wave"})})]})]}),l.jsxs("div",{className:"shrink-0 border-l flex flex-col relative",style:{width:Ye,borderColor:"var(--terminal-border)",background:"var(--hud-bg-alt)"},children:[l.jsx("div",{className:"absolute top-0 bottom-0 w-1.5 cursor-col-resize hover:bg-[var(--accent)] z-10",style:{left:-2},onMouseDown:ve}),l.jsx("div",{className:"p-3 pb-0",children:l.jsx("button",{onClick:()=>{A(null),q(-1),V(!0),R.reset()},className:"w-full px-3 py-1.5 text-[11px] font-bold rounded-lg cursor-pointer transition-colors",style:{background:!E&&F<0?"#B71C1C":"var(--terminal-inline-bg)",color:!E&&F<0?"#fff":"var(--terminal-text-secondary)",border:"1px solid",borderColor:!E&&F<0?"#B71C1C":"var(--terminal-border)"},children:"+ New Wave"})}),a.length>0&&l.jsxs("div",{className:"p-3",children:[l.jsx("div",{className:"text-[10px] font-bold text-[var(--terminal-text-muted)] uppercase tracking-wider mb-2",children:"Active"}),l.jsx("div",{className:"flex flex-col gap-1.5",children:a.map((ce,Ue)=>l.jsxs("button",{onClick:()=>{q(Ue),A(null),V(!1),R.reset()},className:"text-left p-2 rounded-lg cursor-pointer transition-colors",style:{background:F===Ue&&!E?"var(--terminal-bg)":"transparent",border:F===Ue&&!E?"1px solid var(--accent)":"1px solid transparent"},children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500 shrink-0 animate-pulse"}),l.jsxs("span",{className:"text-[11px] text-[var(--terminal-text)] truncate font-medium",children:[ce.directive.slice(0,40),ce.directive.length>40?"...":""]})]}),l.jsxs("div",{className:"text-[9px] text-[var(--terminal-text-muted)] mt-0.5 pl-3.5",children:[ce.rootDispatches.length," role",ce.rootDispatches.length!==1?"s":""]})]},ce.id))})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto p-3",children:[l.jsxs("div",{className:"text-[10px] font-bold text-[var(--terminal-text-muted)] uppercase tracking-wider mb-2",children:["Past Waves (",i.length,")"]}),i.length===0&&l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)] italic",children:"No past waves yet"}),l.jsx("div",{className:"flex flex-col gap-1.5",children:i.map(ce=>l.jsx(BB,{wave:ce,active:(E==null?void 0:E.id)===ce.id,onLoad:()=>Zt(ce.id)},ce.id))})]}),Q&&l.jsxs("button",{onClick:w,disabled:!w,className:"px-3 py-2.5 border-t shrink-0 flex items-center gap-1.5 w-full text-left hover:bg-white/5 transition-colors cursor-pointer disabled:cursor-default",style:{borderColor:"var(--terminal-border)"},children:[l.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:{background:Q.dirty?"var(--idle-amber)":"#2E7D32"}}),l.jsx("span",{className:"text-[10px] font-mono text-[var(--terminal-text-muted)] truncate",children:Q.branch}),Q.dirty&&l.jsxs("span",{className:"text-[9px] ml-auto shrink-0",style:{color:"var(--idle-amber)"},children:[Q.count," unsaved"]}),!Q.dirty&&l.jsx("span",{className:"text-[9px] text-green-400 ml-auto shrink-0",children:"clean"})]})]})]})]});return g?l.jsx("div",{className:"flex flex-col h-full w-full",style:{background:"var(--terminal-bg)"},children:vn}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"dimmer fixed top-0 left-0 bottom-0 bg-black/30 z-40 open",style:{right:ln},onClick:c}),l.jsxs("div",{className:"fixed top-0 bottom-0 z-50 flex flex-col",style:{right:ln,width:nn,background:"var(--terminal-bg)",borderLeft:"1px solid var(--terminal-border)",transition:Kr?"none":"width 0.2s ease"},children:[l.jsx("div",{className:"absolute top-0 bottom-0 w-1 cursor-col-resize hover:bg-[var(--accent)] z-50",style:{left:0},onMouseDown:gr}),vn]})]})}function zB(e,t,n){const i=new Map,a=c=>{const d=e[c];!d||i.has(c)||(i.set(c,{sessionId:"",roleId:c,roleName:d.name,children:d.children,status:"not-dispatched",events:[],streamStatus:"idle"}),d.children.forEach(a))},o=e[t];o&&(i.set(t,{sessionId:"",roleId:t,roleName:"CEO",children:o.children,status:"not-dispatched",events:[],streamStatus:"idle"}),o.children.forEach(a));for(const c of n){const d=i.get(c.roleId);if(d){const f=y2(c.status);i.set(c.roleId,{...d,sessionId:c.sessionId??"",status:c.status||"done",events:c.events,streamStatus:f?"connecting":"done"})}const m=c.childSessions??[];for(const f of m){const x=i.get(f.roleId);x&&i.set(f.roleId,{...x,sessionId:f.sessionId??"",status:f.status||"done",events:f.events,streamStatus:"done"})}}return i}function BB({wave:e,active:t,onLoad:n}){const i=e.id.match(/^(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})/),a=i?`${i[1]}-${i[2]}-${i[3]} ${i[4]}:${i[5]}`:e.id;return l.jsx("div",{className:"rounded-lg cursor-pointer transition-colors hover:bg-[var(--terminal-bg)]",style:{border:t?"1px solid var(--accent)":"1px solid var(--terminal-border)",background:t?"var(--terminal-bg)":void 0},onClick:n,children:l.jsxs("div",{className:"p-2",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[e.hasRunning?l.jsx("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse shrink-0",style:{background:"#4CAF50"}}):l.jsx("span",{className:"text-[10px]",children:"▶"}),l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:a}),e.hasRunning?l.jsx("span",{className:"text-[9px] ml-auto animate-pulse",style:{color:"#4CAF50"},children:"running"}):e.commit?l.jsx("span",{className:"text-[9px] text-green-400 ml-auto font-mono",title:`Committed: ${e.commit.sha}`,children:e.commit.sha.slice(0,7)}):e.rolesCount?l.jsx("span",{className:"text-[9px] ml-auto",style:{color:"var(--idle-amber)"},title:"No commit recorded",children:"uncommitted"}):null]}),l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-secondary)] mt-0.5 line-clamp-2 leading-relaxed",children:e.directive.slice(0,80)}),e.rolesCount?l.jsxs("div",{className:"text-[9px] text-[var(--terminal-text-muted)] mt-0.5",children:[e.rolesCount," role",e.rolesCount!==1?"s":""]}):null]})})}const $B={cto:{skinColor:"#F5CBA7",hairColor:"#2C1810",shirtColor:"#1565C0",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"short",outfitStyle:"tshirt",accessory:"glasses"},cbo:{skinColor:"#FDEBD0",hairColor:"#1A0A00",shirtColor:"#E65100",pantsColor:"#37474F",shoeColor:"#1A1A1A",hairStyle:"slicked",outfitStyle:"suit",accessory:"lapels"},pm:{skinColor:"#FDEBD0",hairColor:"#6D4C41",shirtColor:"#2E7D32",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"bun",outfitStyle:"tshirt",accessory:"blush"},engineer:{skinColor:"#F5CBA7",hairColor:"#1A1A1A",shirtColor:"#4A148C",pantsColor:"#37474F",shoeColor:"#7B1FA2",hairStyle:"messy",outfitStyle:"hoodie",accessory:"headphones"},designer:{skinColor:"#FDEBD0",hairColor:"#AD1457",shirtColor:"#AD1457",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"bob",outfitStyle:"tshirt",accessory:"beret"},qa:{skinColor:"#F5CBA7",hairColor:"#4E342E",shirtColor:"#00695C",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"short",outfitStyle:"tshirt",accessory:"badge"},"data-analyst":{skinColor:"#F5CBA7",hairColor:"#3E2723",shirtColor:"#0277BD",pantsColor:"#37474F",shoeColor:"#212121",hairStyle:"curly",outfitStyle:"vest",accessory:"none"}};function I0(e){return $B[e]??{skinColor:"#B0BEC5",hairColor:"#78909C",shirtColor:"#607D8B",pantsColor:"#455A64",shoeColor:"#37474F"}}const F3=["#FDEBD0","#F5CBA7","#D4A07A","#C68642","#8D5524","#5C3A1E","#F3D1C7","#E8BEAC","#B07D62","#704214"],R3=["#1A0A00","#2C1810","#4E342E","#6D4C41","#8D6E63","#D4A574","#F5E6CA","#FFD700","#B71C1C","#AD1457","#4A148C","#1A237E","#004D40","#1A1A1A","#78909C","#E0E0E0"],z3=["#1565C0","#E65100","#2E7D32","#4A148C","#AD1457","#00695C","#D32F2F","#F57F17","#1B5E20","#283593","#4E342E","#37474F","#880E4F","#00838F","#6A1B9A","#FF6F00"],B3=["#37474F","#1A237E","#3E2723","#263238","#1B5E20","#455A64","#212121","#4E342E","#0D47A1","#311B92"],$3=["#212121","#1A1A1A","#37474F","#4E342E","#7B1FA2","#D32F2F","#1565C0","#F57F17","#2E7D32","#FFFFFF"],Bs={default:{name:"MIDNIGHT",icon:"🌃",vars:{"--floor-light":"#0d1117","--floor-dark":"#0a0e14","--hud-bg":"#0d1117","--hud-bg-alt":"#161b22","--pixel-border":"#30363d","--terminal-bg":"#0d1117","--terminal-border":"#21262d","--terminal-border-hover":"#388bfd","--terminal-text":"#e6edf3","--terminal-text-secondary":"#8b949e","--terminal-text-muted":"#484f58","--accent":"#388bfd","--active-green":"#3fb950","--idle-amber":"#d29922"}},light:{name:"DAYLIGHT",icon:"☀️",vars:{"--floor-light":"#f6f8fa","--floor-dark":"#eaeef2","--hud-bg":"#f0f3f6","--hud-bg-alt":"#e4e8ec","--pixel-border":"#c0c8d0","--terminal-bg":"#ffffff","--terminal-border":"#d0d7de","--terminal-border-hover":"#0969da","--terminal-text":"#1f2328","--terminal-text-secondary":"#484f58","--terminal-text-muted":"#6e7781","--accent":"#0969da","--active-green":"#1a7f37","--idle-amber":"#9a6700","--bar-bg":"#24292f","--bar-text":"#e6edf3","--bar-border":"#444c56","--terminal-bg-deeper":"#e8ecf0"}},retro:{name:"RETRO",icon:"🎮",vars:{"--floor-light":"#1a1410","--floor-dark":"#140f0a","--hud-bg":"#1a1410","--hud-bg-alt":"#2a2018","--pixel-border":"#5c4a32","--terminal-bg":"#1a1410","--terminal-border":"#3a2e20","--terminal-border-hover":"#d4a44e","--terminal-text":"#e8d5b0","--terminal-text-secondary":"#a08860","--terminal-text-muted":"#6b5840","--accent":"#d4a44e","--active-green":"#8bba4a","--idle-amber":"#e8a030"}},cyberpunk:{name:"NEON",icon:"🌌",vars:{"--floor-light":"#0a0014","--floor-dark":"#06000e","--hud-bg":"#0a0014","--hud-bg-alt":"#14002a","--pixel-border":"#4a1a80","--terminal-bg":"#0a0014","--terminal-border":"#2a0a50","--terminal-border-hover":"#e040fb","--terminal-text":"#e0d0ff","--terminal-text-secondary":"#9070c0","--terminal-text-muted":"#5a3a80","--accent":"#e040fb","--active-green":"#00ff88","--idle-amber":"#ffab00"}},forest:{name:"FOREST",icon:"🌲",vars:{"--floor-light":"#0a1410","--floor-dark":"#060e0a","--hud-bg":"#0a1410","--hud-bg-alt":"#142a1e","--pixel-border":"#2a5a3a","--terminal-bg":"#0a1410","--terminal-border":"#1a3a26","--terminal-border-hover":"#4ade80","--terminal-text":"#d0f0d8","--terminal-text-secondary":"#70a880","--terminal-text-muted":"#3a6848","--accent":"#4ade80","--active-green":"#86efac","--idle-amber":"#fcd34d"}},ocean:{name:"OCEAN",icon:"🌊",vars:{"--floor-light":"#0a1420","--floor-dark":"#060e18","--hud-bg":"#0a1420","--hud-bg-alt":"#142a40","--pixel-border":"#1e4a6a","--terminal-bg":"#0a1420","--terminal-border":"#163050","--terminal-border-hover":"#38bdf8","--terminal-text":"#d0e8f8","--terminal-text-secondary":"#6090b0","--terminal-text-muted":"#305070","--accent":"#38bdf8","--active-green":"#34d399","--idle-amber":"#fbbf24"}}};function OB({color:e,selected:t,onClick:n}){return l.jsx("button",{onClick:n,className:"customize-swatch",style:{background:e,outline:t?"2px solid #fff":"2px solid transparent",boxShadow:t?`0 0 0 1px ${e}, 0 0 6px ${e}88`:"none"}})}function Nc({label:e,presets:t,value:n,onChange:i}){return l.jsxs("div",{className:"customize-row",children:[l.jsxs("div",{className:"customize-row-header",children:[l.jsx("span",{className:"customize-row-label",children:e}),l.jsx("div",{className:"customize-row-current",style:{background:n}})]}),l.jsx("div",{className:"customize-swatches",children:t.map(a=>l.jsx(OB,{color:a,selected:a===n,onClick:()=>i(a)},a))})]})}function $p({label:e,items:t,value:n,onChange:i,lockInfo:a}){return l.jsxs("div",{className:"customize-row",children:[l.jsx("div",{className:"customize-row-header",children:l.jsx("span",{className:"customize-row-label",children:e})}),l.jsx("div",{className:"customize-swatches",style:{gap:4},children:t.map(o=>{const c=a?a.getLockLevel(o.id):1,d=a!=null&&a.getCost?a.getCost(o.id):0,m=o.id===n,f=a?c>a.roleLevel&&!m:!1,x=d>0&&(a==null?void 0:a.purchased)&&!a.purchased.has(o.id)&&!m,p=(a==null?void 0:a.coinBalance)!==void 0?a.coinBalance>=d:!0,y=f||!1,g=a?m&&c>a.roleLevel:!1;return l.jsxs("button",{onClick:()=>{if(!y){if(x&&!f){p&&(a!=null&&a.onPurchase)&&a.onPurchase(o.id,d);return}i(o.id===n?void 0:o.id)}},className:"customize-swatch",style:{width:"auto",height:"auto",padding:y||x?"2px 6px 12px 6px":"2px 6px",fontSize:9,fontFamily:"var(--font-pixel, monospace)",background:m?"rgba(255,255,255,0.15)":y?"rgba(255,255,255,0.02)":x?"rgba(255,200,0,0.04)":"rgba(255,255,255,0.04)",outline:m?g?"2px solid #F59E0B":"2px solid #fff":x&&!y?"2px solid rgba(255,200,0,0.3)":"2px solid transparent",color:y?"rgba(255,255,255,0.25)":x?"rgba(255,255,255,0.45)":m?"#fff":"rgba(255,255,255,0.5)",borderRadius:4,cursor:y?"not-allowed":x?p?"pointer":"not-allowed":"pointer",opacity:y?.35:1,position:"relative"},children:[o.name,y&&l.jsxs("span",{style:{position:"absolute",bottom:1,left:"50%",transform:"translateX(-50%)",fontSize:8,color:"rgba(255,255,255,0.5)",whiteSpace:"nowrap"},children:["🔒"," Lv.",c]}),!y&&x&&l.jsxs("span",{style:{position:"absolute",bottom:1,left:"50%",transform:"translateX(-50%)",fontSize:8,color:p?"#FFD700":"#F87171",whiteSpace:"nowrap"},children:["🪙"," ",d]}),g&&l.jsxs("span",{style:{position:"absolute",bottom:-8,left:"50%",transform:"translateX(-50%)",fontSize:7,color:"#F59E0B",whiteSpace:"nowrap"},children:["⚠"," Lv.",c]})]},o.id)})})]})}function Op({label:e,active:t,onClick:n}){return l.jsx("button",{onClick:n,style:{flex:1,padding:"6px 0",fontSize:10,fontFamily:"var(--font-pixel, monospace)",fontWeight:"bold",letterSpacing:1,background:t?"rgba(255,255,255,0.08)":"transparent",color:t?"#fff":"rgba(255,255,255,0.35)",border:"none",borderBottom:t?"2px solid #3B82F6":"2px solid transparent",cursor:"pointer",transition:"all 0.15s"},children:e})}function ya(e){return e[Math.floor(Math.random()*e.length)]}function to(e){var a,o,c;const t=h0().filter(d=>!e||E5(d.id,e)),n=m0().filter(d=>!e||D5(d.id,e)),i=p0().filter(d=>!e||M5(d.id,e));return{skinColor:ya(F3),hairColor:ya(R3),shirtColor:ya(z3),pantsColor:ya(B3),shoeColor:ya($3),hairStyle:(a=ya(t))==null?void 0:a.id,outfitStyle:(o=ya(n))==null?void 0:o.id,accessory:(c=ya(i))==null?void 0:c.id}}function O3({roleId:e,appearance:t,onChange:n,onRandomize:i,onReset:a,label:o,roleLevel:c,coinBalance:d,purchased:m,onPurchase:f}){const[x,p]=S.useState("look"),y=S.useCallback((D,F)=>{n({...t,[D]:F})},[t,n]),g=S.useRef(null),w=S.useCallback(D=>{var V;const F=(V=D.target.files)==null?void 0:V[0];if(!F)return;const q=new Image;q.onload=()=>{const L=O8(q);n({...L,hairStyle:t.hairStyle,outfitStyle:t.outfitStyle,accessory:t.accessory}),URL.revokeObjectURL(q.src)},q.src=URL.createObjectURL(F),D.target.value=""},[t.hairStyle,t.outfitStyle,t.accessory,n]),k=h0(),j=m0(),C=p0(),N=c!==void 0?k.filter(D=>E5(D.id,c)).length:k.length,E=c!==void 0?j.filter(D=>D5(D.id,c)).length:j.length,A=c!==void 0?C.filter(D=>M5(D.id,c)).length:C.length,z=(D,F)=>c!==void 0?{roleLevel:c,getLockLevel:D,getCost:F,purchased:m,onPurchase:f,coinBalance:d}:void 0;return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"customize-preview",children:[l.jsx("div",{className:"customize-preview-bg",children:l.jsx(Aa,{roleId:e,appearance:t,scale:12})}),o&&l.jsx("div",{className:"customize-preview-name",children:o}),l.jsxs("div",{className:"customize-preview-actions",children:[l.jsx("button",{className:"customize-btn customize-btn--random",onClick:i,children:"RANDOM"}),l.jsx("button",{className:"customize-btn customize-btn--reset",onClick:a,children:"RESET"}),l.jsx("button",{className:"customize-btn",onClick:()=>{var D;return(D=g.current)==null?void 0:D.click()},style:{fontSize:9,opacity:.7},children:"PHOTO"}),l.jsx("input",{ref:g,type:"file",accept:"image/*",onChange:w,style:{display:"none"}})]})]}),l.jsxs("div",{className:"customize-colors",children:[l.jsxs("div",{style:{display:"flex",borderBottom:"1px solid rgba(255,255,255,0.06)",marginBottom:4},children:[l.jsx(Op,{label:"LOOK",active:x==="look",onClick:()=>p("look")}),l.jsx(Op,{label:"OUTFIT",active:x==="outfit",onClick:()=>p("outfit")}),l.jsx(Op,{label:"ACCESSORY",active:x==="accessory",onClick:()=>p("accessory")})]}),x==="look"&&l.jsxs(l.Fragment,{children:[l.jsx(Nc,{label:"SKIN",presets:F3,value:t.skinColor,onChange:D=>y("skinColor",D)}),l.jsx(Nc,{label:"HAIR COLOR",presets:R3,value:t.hairColor,onChange:D=>y("hairColor",D)}),c!==void 0&&l.jsxs("div",{style:{padding:"4px 8px",marginBottom:4,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:9,fontFamily:"var(--font-pixel, monospace)",color:"rgba(255,255,255,0.5)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("span",{children:["Lv.",c]}),l.jsxs("span",{children:[N,"/",k.length," unlocked"]})]}),l.jsx($p,{label:"HAIR STYLE",items:k,value:t.hairStyle,onChange:D=>y("hairStyle",D),lockInfo:z(N5,E8)})]}),x==="outfit"&&l.jsxs(l.Fragment,{children:[c!==void 0&&l.jsxs("div",{style:{padding:"4px 8px",marginBottom:4,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:9,fontFamily:"var(--font-pixel, monospace)",color:"rgba(255,255,255,0.5)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("span",{children:["Lv.",c]}),l.jsxs("span",{children:[E,"/",j.length," unlocked"]})]}),l.jsx($p,{label:"STYLE",items:j,value:t.outfitStyle,onChange:D=>y("outfitStyle",D),lockInfo:z(A5,T8)}),l.jsx(Nc,{label:"TOP",presets:z3,value:t.shirtColor,onChange:D=>y("shirtColor",D)}),l.jsx(Nc,{label:"PANTS",presets:B3,value:t.pantsColor,onChange:D=>y("pantsColor",D)}),l.jsx(Nc,{label:"SHOES",presets:$3,value:t.shoeColor,onChange:D=>y("shoeColor",D)})]}),x==="accessory"&&l.jsxs(l.Fragment,{children:[c!==void 0&&l.jsxs("div",{style:{padding:"4px 8px",marginBottom:4,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:9,fontFamily:"var(--font-pixel, monospace)",color:"rgba(255,255,255,0.5)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("span",{children:["Lv.",c]}),l.jsxs("span",{children:[A,"/",C.length," unlocked"]})]}),l.jsx($p,{label:"ACCESSORY",items:C,value:t.accessory,onChange:D=>y("accessory",D),lockInfo:z(_5,R8)}),l.jsx("div",{style:{marginTop:12,padding:"8px 10px",background:"rgba(255,255,255,0.03)",borderRadius:6,border:"1px dashed rgba(255,255,255,0.08)",color:"rgba(255,255,255,0.25)",fontSize:9,fontFamily:"var(--font-pixel, monospace)",textAlign:"center"},children:c!==void 0&&c<10?"Level up to unlock more accessories":"More accessories coming soon"})]})]})]})}const LB=[{value:"c-level",label:"C-Level"},{value:"member",label:"Member"}];function Ox(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)}function Lp(e){switch(e){case"c-level":return{authority:{autonomous:["Strategic decisions within domain","Task delegation to reports"],needsApproval:["Budget over $5K","External commitments"]},knowledge:{reads:["company.md","projects/","architecture/"],writes:["decisions/","knowledge/"]},reports:{daily:"standup",weekly:"summary"}};default:return{authority:{autonomous:["Implementation within assigned tasks"],needsApproval:["Design changes","New dependencies"]},knowledge:{reads:["projects/"],writes:[]},reports:{daily:"standup",weekly:""}}}}const IB={cto:{name:"CTO",id:"cto",level:"c-level"},cbo:{name:"CBO",id:"cbo",level:"c-level"},pm:{name:"PM",id:"pm",level:"member"},engineer:{name:"Engineer",id:"engineer",level:"member"},designer:{name:"Designer",id:"designer",level:"member"},qa:{name:"QA Engineer",id:"qa",level:"member"}};let wa=null;async function HB(){if(wa)return wa;try{const n=await ke.getPreferences();if(n.instanceId)return wa=n.instanceId,localStorage.setItem("tycono_instance_id",wa),wa}catch{}const e="tycono_instance_id";let t=localStorage.getItem(e);return t||(t=crypto.randomUUID(),localStorage.setItem(e,t)),wa=t,t}const Ec=4;function UB(e,t,n){const i=e.trim();if(!i||i.startsWith("#"))return null;const a=i.split(",").map(p=>p.trim()),o=a[0];if(!o)return null;const c=Ox(o),m=(a[1]||"member").toLowerCase()==="c-level"?"c-level":"member",f=a[2]||"ceo";let x;return t.has(c)?x="ID already exists":n.has(c)&&(x="Duplicate ID in batch"),n.add(c),{name:o,id:c,level:m,reportsTo:f,error:x}}function qB({existingRoles:e,onClose:t,onHire:n,onStoreVisit:i,questHint:a}){const[o,c]=S.useState("single"),[d,m]=S.useState([]),[f,x]=S.useState(!1),[p,y]=S.useState("popular"),[g,w]=S.useState(""),[k,j]=S.useState(null),[C,N]=S.useState(!1),[E,A]=S.useState(""),[z,D]=S.useState("browse"),[F,q]=S.useState(""),[V,L]=S.useState(""),[_,B]=S.useState("ceo"),[X,R]=S.useState(null),[H,$]=S.useState(1),[G,Q]=S.useState(""),[K,M]=S.useState(""),[U,P]=S.useState(!1),[O,Z]=S.useState("member"),[ee,J]=S.useState(()=>{const ae=e.find(Ve=>Ve.level==="c-level");return(ae==null?void 0:ae.id)??"ceo"}),[se,le]=S.useState(""),[ye,De]=S.useState(to),[Ee,Re]=S.useState(!1),[me,Fe]=S.useState(""),[Je,Pe]=S.useState([]),[it,ht]=S.useState(new Set),[Ye,nt]=S.useState(""),[ut,kt]=S.useState("input"),[mt,ve]=S.useState({done:0,total:0}),be=S.useRef(null),te=S.useRef(null),oe=S.useRef(null);S.useEffect(()=>{ke.getSkills().then(ae=>Pe(ae.filter(Ve=>Ve.installed))).catch(()=>{}),HB().then(ae=>R(ae)).catch(()=>{})},[]),S.useEffect(()=>{var ae,Ve,We;o==="single"?(H===1&&((ae=be.current)==null||ae.focus()),H===2&&((Ve=te.current)==null||Ve.focus())):o==="bulk"&&ut==="input"&&((We=oe.current)==null||We.focus())},[H,o,ut]),S.useEffect(()=>{o==="store"&&z==="browse"&&d.length===0&&Ce()},[o,z]);const Ce=async()=>{x(!0);try{const ae=await ur.getCharacters({sort:p,instanceId:X??void 0});m(ae.characters)}catch{A("Failed to load job board")}x(!1)};S.useEffect(()=>{o==="store"&&z==="browse"&&Ce()},[p,X]);const pe=S.useMemo(()=>{if(!g.trim())return d;const ae=g.toLowerCase();return d.filter(Ve=>Ve.name.toLowerCase().includes(ae)||Ve.id.toLowerCase().includes(ae)||(Ve.tagline??"").toLowerCase().includes(ae))},[d,g]),Se=S.useMemo(()=>new Set(e.map(ae=>ae.id)),[e]),Me=S.useMemo(()=>{const ae=Ye.split(`
|
|
113
113
|
`),Ve=new Set;return ae.map(We=>UB(We,Se,Ve)).filter(We=>We!==null)},[Ye,Se]),Ge=Me.length>0&&Me.every(ae=>!ae.error),Ie=ae=>{Q(ae),U||M(Ox(ae))},qe=G.trim().length>0&&K.trim().length>0&&!e.some(ae=>ae.id===K),Xe=se.trim().length>0,et=async()=>{Re(!0),Fe("");const ae=Lp(O);try{await n({id:K,name:G.trim(),level:O,reportsTo:ee,persona:se.trim(),...ae,skills:it.size>0?[...it]:void 0},ye),t()}catch(Ve){Fe(Ve instanceof Error?Ve.message:"Failed to create role"),Re(!1)}},ze=ae=>ae===1?qe:ae===2?Xe:!0,Be=async()=>{Re(!0),Fe(""),ve({done:0,total:Me.length});try{for(let ae=0;ae<Me.length;ae++){const Ve=Me[ae],We=Lp(Ve.level),tn=to(),Ne=`${Ve.name}. A ${Ve.level} role reporting to ${Ve.reportsTo}.`;await n({id:Ve.id,name:Ve.name,level:Ve.level,reportsTo:Ve.reportsTo,persona:Ne,...We},tn),ve({done:ae+1,total:Me.length})}t()}catch(ae){Fe(ae instanceof Error?ae.message:"Failed to create roles"),Re(!1)}},_t=async ae=>{N(!0),A("");try{const Ve=await ur.getCharacter(ae);j(Ve),q(Ve.name||""),L(Ox(Ve.name||ae)),D("review")}catch{A("Failed to load character details")}finally{N(!1)}},en=async(ae,Ve)=>{if(!X)return;const We=d.find(Ne=>Ne.id===ae);if(!We)return;const tn=We.my_vote===Ve?0:Ve;try{const Ne=await ur.voteCharacter(ae,X,tn);m(Ct=>Ct.map(ln=>ln.id===ae?{...ln,upvotes:Ne.upvotes,downvotes:Ne.downvotes,vote_score:Ne.upvotes-Ne.downvotes,my_vote:tn===0?null:tn}:ln))}catch{}},Tt=async()=>{if(!k)return;Re(!0),Fe("");const ae=k,Ve=ae.level==="c-level"?"c-level":"member",We=Lp(Ve),tn=ae.skills!=null&&typeof ae.skills=="object"&&!Array.isArray(ae.skills)&&"primary"in ae.skills;try{await n({id:V,name:F.trim(),level:Ve,reportsTo:_,persona:ae.persona||`${F}. Imported from Job Board.`,authority:ae.authority||We.authority,knowledge:We.knowledge,reports:We.reports,source:{id:`tycono/${ae.id}`,sync:"manual",forked_at:"1.0.0",upstream_version:"1.0.0"},skillContent:tn?ae.skills:void 0},ae.appearance?ae.appearance:to()),ur.trackInstall(ae.id).catch(()=>{}),t()}catch(Ne){Fe(Ne instanceof Error?Ne.message:"Failed to hire"),Re(!1)}},Pt=async ae=>{if(X)try{await ur.deleteCharacter(ae,X),m(Ve=>Ve.filter(We=>We.id!==ae))}catch{}},hn=ae=>{ae.key==="Escape"&&t(),ae.key==="Enter"&&(ae.metaKey||ae.ctrlKey)&&(o==="single"?H<Ec&&ze(H)?$(H+1):H===Ec&&et():o==="bulk"?ut==="input"&&Ge?kt("review"):ut==="review"&&Be():o==="store"&&z==="review"&&Tt())},Zt=e.some(ae=>ae.id===K)&&K.length>0;return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm",onClick:t}),l.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[560px] max-h-[90vh] z-[61] bg-[var(--wall)] rounded-2xl shadow-2xl overflow-hidden flex flex-col",onKeyDown:hn,children:[l.jsxs("div",{className:"p-5 text-white",style:{background:"linear-gradient(135deg, #2E7D32, #43A047)"},children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("div",{className:"text-lg font-bold",children:"Hire New Role"}),l.jsxs("div",{className:"flex bg-black/20 rounded-lg p-0.5",children:[l.jsx("button",{onClick:()=>{c("single"),Fe("")},className:`px-3 py-1 text-xs font-semibold rounded-md cursor-pointer transition-colors ${o==="single"?"bg-white/20 text-white":"text-white/50 hover:text-white/70"}`,children:"Single"}),l.jsx("button",{onClick:()=>{c("bulk"),Fe("")},className:`px-3 py-1 text-xs font-semibold rounded-md cursor-pointer transition-colors ${o==="bulk"?"bg-white/20 text-white":"text-white/50 hover:text-white/70"}`,children:"Bulk"}),l.jsx("button",{onClick:()=>{c("store"),Fe(""),i==null||i()},className:`px-3 py-1 text-xs font-semibold rounded-md cursor-pointer transition-colors ${o==="store"?"bg-white/20 text-white":"text-white/50 hover:text-white/70"}`,children:"Job Board"})]})]}),a&&l.jsxs("div",{className:"mt-2 px-3 py-1.5 rounded-lg text-xs flex items-center gap-2",style:{background:"rgba(0,0,0,0.2)"},children:[l.jsx("span",{children:"🐾"}),l.jsx("span",{className:"opacity-90",children:a.message}),a.roleId&&o==="single"&&H===1&&!G&&l.jsx("button",{className:"ml-auto px-2 py-0.5 rounded text-[10px] font-semibold cursor-pointer hover:brightness-125",style:{background:"rgba(255,255,255,0.15)",color:"#fff"},onClick:()=>{const ae=IB[a.roleId];ae&&(Q(ae.name),M(ae.id),P(!0),Z(ae.level))},children:"Auto-fill →"})]}),l.jsxs("div",{className:"text-sm opacity-80 mt-0.5 flex items-center gap-2",children:[l.jsx("span",{children:o==="single"?`Step ${H} of ${Ec}`:o==="bulk"?ut==="input"?"Enter roles, one per line":`Review ${Me.length} roles`:z==="browse"?`${d.length} roles available`:"Review & customize"}),o==="store"&&z==="browse"&&l.jsx("a",{href:"https://tycono.ai/jobs",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] opacity-60 hover:opacity-100 transition-opacity",onClick:ae=>ae.stopPropagation(),children:"Open in browser ↗"})]})]}),o==="single"&&l.jsx("div",{className:"flex gap-1 px-5 pt-4",children:Array.from({length:Ec},(ae,Ve)=>Ve+1).map(ae=>l.jsx("div",{className:"flex-1 h-1 rounded-full transition-colors",style:{background:ae<=H?"#2E7D32":"rgba(255,255,255,0.1)"}},ae))}),l.jsx("div",{className:"p-5 min-h-[240px] overflow-y-auto flex-1",children:o==="store"?l.jsxs(l.Fragment,{children:[z==="browse"&&l.jsxs("div",{className:"space-y-3",children:[X?l.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 rounded-lg bg-green-900/10 border border-green-800/20 text-[10px]",children:[l.jsxs("span",{className:"text-green-400/70",children:["Signed in · ",l.jsxs("span",{className:"font-mono text-white/40",children:[X.slice(0,8),"..."]})]}),l.jsx("button",{onClick:()=>{wa=null,localStorage.removeItem("tycono_instance_id"),R(null)},className:"text-white/30 hover:text-white/60 cursor-pointer",children:"Sign out"})]}):l.jsx(YB,{onLogin:ae=>{wa=ae,localStorage.setItem("tycono_instance_id",ae),R(ae)}}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{placeholder:"Paste ID (tycono:engineer)",className:"flex-1 p-2 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 focus:outline-none focus:border-accent/40 transition-colors font-mono",onKeyDown:ae=>{if(ae.key==="Enter"){const We=ae.target.value.trim().replace(/^tycono:/,"");We&&(_t(We),ae.target.value="")}}}),l.jsx("button",{onClick:()=>{const ae=document.querySelector('[placeholder="Paste ID (tycono:engineer)"]');if(ae){const We=ae.value.trim().replace(/^tycono:/,"");We&&(_t(We),ae.value="")}},disabled:C,className:"px-3 py-2 rounded-lg bg-accent/10 border border-accent/25 text-accent text-xs font-medium hover:bg-accent/20 transition-colors shrink-0 cursor-pointer disabled:opacity-50",children:C?"Loading...":"Fetch"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("div",{className:"flex-1 h-px bg-white/10"}),l.jsx("span",{className:"text-[10px] text-white/30",children:"or browse"}),l.jsx("div",{className:"flex-1 h-px bg-white/10"})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{value:g,onChange:ae=>w(ae.target.value),placeholder:"Search roles...",className:"flex-1 p-2 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 focus:outline-none focus:border-white/25 transition-colors",autoFocus:!0}),l.jsxs("select",{value:p,onChange:ae=>y(ae.target.value),className:"px-2 py-2 rounded-lg border border-white/10 bg-white/5 text-xs text-white/70 focus:outline-none cursor-pointer",children:[l.jsx("option",{value:"popular",className:"bg-[var(--wall)]",children:"Popular"}),l.jsx("option",{value:"installs",className:"bg-[var(--wall)]",children:"Most Hired"}),l.jsx("option",{value:"newest",className:"bg-[var(--wall)]",children:"Newest"}),l.jsx("option",{value:"name",className:"bg-[var(--wall)]",children:"A-Z"})]})]}),f?l.jsx("div",{className:"text-center py-8 text-sm text-white/40",children:"Loading store..."}):E?l.jsxs("div",{className:"text-center py-8",children:[l.jsx("div",{className:"text-xs text-red-400 mb-2",children:E}),l.jsx("button",{onClick:Ce,className:"text-xs text-green-400 hover:underline cursor-pointer",children:"Retry"})]}):pe.length===0?l.jsx("div",{className:"text-center py-8 text-sm text-white/40",children:g?"No matches found":"No characters in store yet"}):l.jsx("div",{className:"space-y-2 max-h-[380px] overflow-y-auto pr-1",children:pe.map(ae=>l.jsx(PB,{char:ae,isHired:Se.has(ae.id),onSelect:()=>_t(ae.id),onVote:Ve=>en(ae.id,Ve),onDelete:()=>Pt(ae.id),fetching:C,token:X},ae.id))})]}),z==="review"&&k&&l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"bg-white/5 rounded-xl p-4 border border-white/10",children:[l.jsxs("div",{className:"flex gap-4",children:[k.appearance&&l.jsx("div",{className:"flex-shrink-0 rounded-lg overflow-hidden",style:{background:"#0d1117",padding:8},children:l.jsx(Aa,{roleId:"store-preview",appearance:k.appearance,scale:4})}),l.jsxs("div",{className:"flex-1 space-y-2.5",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-[10px] text-white/30 uppercase tracking-wider mb-0.5",children:"Name"}),l.jsx("input",{value:F,onChange:ae=>q(ae.target.value),className:"w-full p-2 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 focus:outline-none focus:border-white/25 transition-colors"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-[10px] text-white/30 uppercase tracking-wider mb-0.5",children:"Role ID"}),l.jsx("input",{value:V,onChange:ae=>L(ae.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),className:"w-full p-2 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 font-mono focus:outline-none focus:border-white/25 transition-colors"}),e.some(ae=>ae.id===V)&&V.length>0&&l.jsx("div",{className:"text-xs text-red-500 mt-1",children:"ID already exists"})]}),l.jsxs("div",{className:"flex gap-3",children:[l.jsxs("div",{className:"flex-1",children:[l.jsx("label",{className:"block text-[10px] text-white/30 uppercase tracking-wider mb-0.5",children:"Level"}),l.jsx("div",{className:"text-sm text-white/70 p-2 rounded-lg bg-white/5 border border-white/10",children:k.level==="c-level"?"C-Level":"Member"})]}),l.jsxs("div",{className:"flex-1",children:[l.jsx("label",{className:"block text-[10px] text-white/30 uppercase tracking-wider mb-0.5",children:"Reports To"}),l.jsxs("select",{value:_,onChange:ae=>B(ae.target.value),className:"w-full p-2 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 focus:outline-none focus:border-white/25 transition-colors",children:[l.jsx("option",{value:"ceo",className:"bg-[var(--wall)] text-white",children:"CEO"}),e.map(ae=>l.jsxs("option",{value:ae.id,className:"bg-[var(--wall)] text-white",children:[ae.name," (",ae.id,")"]},ae.id))]})]})]})]})]}),k.persona&&l.jsxs("div",{className:"pt-3 mt-3 border-t border-white/10",children:[l.jsx("div",{className:"text-[10px] text-white/30 uppercase tracking-wider mb-1",children:"Persona"}),l.jsx("div",{className:"text-xs text-white/60 leading-relaxed line-clamp-3",children:k.persona})]}),k.skills&&l.jsxs("div",{className:"pt-3 mt-3 border-t border-white/10",children:[l.jsx("div",{className:"text-[10px] text-white/30 uppercase tracking-wider mb-1",children:"Skills"}),l.jsx("div",{className:"flex flex-wrap gap-1.5",children:(()=>{var tn,Ne;const ae=k.skills;if(ae&&typeof ae=="object"&&!Array.isArray(ae)&&"primary"in ae){const Ct=[];return(Ne=(tn=ae.primary)==null?void 0:tn.frontmatter)!=null&&Ne.name&&Ct.push(ae.primary.frontmatter.name),ae.shared&&ae.shared.forEach(ln=>{var nn;return Ct.push(((nn=ln.frontmatter)==null?void 0:nn.name)||ln.id)}),Ct.map(ln=>l.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-green-900/20 border border-green-800/30 text-green-400",children:ln},ln))}return(Array.isArray(ae)?ae:[]).map((Ct,ln)=>l.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-green-900/20 border border-green-800/30 text-green-400",children:typeof Ct=="string"?Ct:Ct.name},ln))})()})]})]}),me&&l.jsx("div",{className:"text-xs text-red-400 bg-red-900/20 p-2 rounded-lg border border-red-800/30",children:me})]})]}):o==="single"?l.jsxs(l.Fragment,{children:[H===1&&l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-1",children:"Role Name"}),l.jsx("input",{ref:be,value:G,onChange:ae=>Ie(ae.target.value),placeholder:"e.g. Data Analyst",className:"w-full p-2.5 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 focus:outline-none focus:border-white/25 transition-colors"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-1",children:"Role ID (slug)"}),l.jsx("input",{value:K,onChange:ae=>{M(ae.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),P(!0)},className:`w-full p-2.5 rounded-lg border bg-white/5 text-sm text-white/90 font-mono focus:outline-none transition-colors ${Zt?"border-red-400":"border-white/10 focus:border-white/25"}`}),Zt&&l.jsx("div",{className:"text-xs text-red-500 mt-1",children:"ID already exists"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-1",children:"Level"}),l.jsx("div",{className:"flex gap-2",children:LB.map(ae=>l.jsx("button",{onClick:()=>{if(Z(ae.value),ae.value==="c-level")J("ceo");else{const Ve=e.find(We=>We.level==="c-level");J((Ve==null?void 0:Ve.id)??"ceo")}},className:`flex-1 p-2 text-xs font-semibold rounded-lg border cursor-pointer transition-colors ${O===ae.value?"border-green-600 bg-green-900/30 text-green-400":"border-white/10 text-white/50 hover:border-white/20"}`,children:ae.label},ae.value))})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-1",children:"Reports To"}),O==="c-level"?l.jsx("div",{className:"w-full p-2.5 rounded-lg border border-white/10 bg-white/5 text-sm text-white/40",children:"CEO (automatic)"}):l.jsx("select",{value:ee,onChange:ae=>J(ae.target.value),className:"w-full p-2.5 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 focus:outline-none focus:border-white/25 transition-colors",children:e.filter(ae=>ae.level==="c-level").map(ae=>l.jsxs("option",{value:ae.id,className:"bg-[var(--wall)] text-white",children:[ae.name," (",ae.id,")"]},ae.id))})]})]}),H===2&&l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Persona"}),l.jsx("textarea",{ref:te,value:se,onChange:ae=>le(ae.target.value),placeholder:"Describe this role's personality, expertise, and working style...",className:"w-full h-32 p-3 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 resize-none focus:outline-none focus:border-white/25 transition-colors"}),l.jsx("div",{className:"text-[10px] text-gray-400 mt-1",children:"This defines how the AI agent will behave in this role"})]}),Je.length>0&&l.jsxs("div",{children:[l.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Skills"}),l.jsx("div",{className:"space-y-1.5 max-h-[120px] overflow-y-auto",children:Je.map(ae=>l.jsxs("label",{className:"flex items-center gap-2 p-2 rounded-lg border border-white/10 bg-white/5 cursor-pointer hover:border-white/20 transition-colors",children:[l.jsx("input",{type:"checkbox",checked:it.has(ae.id),onChange:()=>ht(Ve=>{const We=new Set(Ve);return We.has(ae.id)?We.delete(ae.id):We.add(ae.id),We}),className:"accent-green-600"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("div",{className:"text-xs font-semibold text-white/80",children:ae.name}),l.jsx("div",{className:"text-[10px] text-white/40 truncate",children:ae.description})]})]},ae.id))})]})]}),H===3&&l.jsx("div",{className:"customize-body",style:{padding:0},children:l.jsx(O3,{roleId:"default",appearance:ye,onChange:De,onRandomize:()=>De(to()),onReset:()=>De(to()),label:l.jsxs("span",{children:[K||"new-role"," — ",G||"New Role"]})})}),H===4&&l.jsxs("div",{className:"space-y-3",children:[l.jsx("div",{className:"text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Review"}),l.jsxs("div",{className:"bg-white/5 rounded-xl p-4 border border-white/10",children:[l.jsxs("div",{className:"flex gap-4",children:[l.jsx("div",{className:"flex-shrink-0 rounded-lg overflow-hidden",style:{background:"#0d1117",padding:8},children:l.jsx(Aa,{roleId:"default",appearance:ye,scale:4})}),l.jsxs("div",{className:"flex-1 space-y-2.5",children:[l.jsx(Ac,{label:"Name",value:G}),l.jsx(Ac,{label:"ID",value:K,mono:!0}),l.jsx(Ac,{label:"Level",value:O}),l.jsx(Ac,{label:"Reports To",value:ee}),it.size>0&&l.jsx(Ac,{label:"Skills",value:[...it].join(", ")})]})]}),l.jsxs("div",{className:"pt-3 mt-3 border-t border-white/10",children:[l.jsx("div",{className:"text-[10px] text-white/30 uppercase tracking-wider mb-1",children:"Persona"}),l.jsx("div",{className:"text-xs text-white/60 leading-relaxed",children:se})]})]}),me&&l.jsx("div",{className:"text-xs text-red-400 bg-red-900/20 p-2 rounded-lg border border-red-800/30",children:me})]})]}):l.jsxs(l.Fragment,{children:[ut==="input"&&l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:"Roles (one per line)"}),l.jsx("textarea",{ref:oe,value:Ye,onChange:ae=>nt(ae.target.value),placeholder:`Name, Level, ReportsTo
|
|
114
114
|
e.g.
|
|
115
115
|
Data Analyst
|
|
@@ -135,4 +135,4 @@ ${re}`;hs(de.id,we,"do")}catch(de){Mt(`Failed to delegate: ${de instanceof Error
|
|
|
135
135
|
|
|
136
136
|
Skip this if you don't have a codebase yet — you can connect one later from Settings.`,tag:"optional",open:B,onToggle:()=>X(!B),children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${We} flex-1`,placeholder:"/path/to/code/repo",value:R,onChange:Ne=>H(Ne.target.value)}),l.jsx("button",{onClick:()=>G(!$),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"})]}),$&&l.jsx(rf,{onSelect:Ne=>{H(Ne),G(!1)},onClose:()=>G(!1)})]}),l.jsxs(x2,{icon:"📚",title:"Knowledge Import",hint:"Import existing documents into knowledge base.",help:`Point to folders with docs (.md, .txt, etc.) — AI will read, summarize, and organize them into a searchable knowledge base.
|
|
137
137
|
|
|
138
|
-
Skip this to start with an empty knowledge base. You can import documents anytime from the office.`,tag:"optional",open:Q,onToggle:()=>K(!Q),children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${We} flex-1`,placeholder:"/path/to/docs",value:P,onChange:Ne=>O(Ne.target.value),onKeyDown:Ne=>{Ne.key==="Enter"&&(Ne.preventDefault(),Tt())}}),l.jsx("button",{onClick:()=>ee(!Z),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"}),l.jsx("button",{onClick:Tt,disabled:!P.trim(),className:"px-3 py-2 rounded text-xs font-medium shrink-0",style:{background:"var(--accent)",color:"#fff",opacity:P.trim()?1:.5},children:"Add"})]}),Z&&l.jsx(rf,{onSelect:Ne=>{M.includes(Ne)||U([...M,Ne]),ee(!1)},onClose:()=>ee(!1)}),M.length>0&&l.jsx("div",{className:"space-y-1 mt-2",children:M.map((Ne,Ct)=>l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:[l.jsx("span",{className:"flex-1 truncate",style:{fontFamily:"var(--pixel-font)"},children:Ne}),l.jsx("button",{onClick:()=>U(M.filter((ln,nn)=>nn!==Ct)),className:"opacity-50 hover:opacity-100",children:"✕"})]},Ct))})]})]}):l.jsx("div",{className:"space-y-3",children:l.jsxs(p2,{icon:"🔗",title:"AKB Path",hint:"Directory with existing CLAUDE.md and AKB structure.",help:"Connect to a directory that was previously set up with Tycono. It must contain a CLAUDE.md file. All existing roles, knowledge, and settings will be loaded.",children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${We} flex-1`,placeholder:"/path/to/your/akb",value:J,onChange:Ne=>{se(Ne.target.value),ye(null)},autoFocus:!0}),l.jsx("button",{onClick:()=>me(!Re),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"}),l.jsx("button",{onClick:en,disabled:De||!J.trim(),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0",style:{background:"var(--accent)",color:"#fff",opacity:De||!J.trim()?.5:1},children:De?"...":"Verify"})]}),le===!0&&l.jsxs("div",{className:"text-xs mt-2",style:{color:"var(--active-green)"},children:["✅"," Valid AKB found"]}),le===!1&&l.jsxs("div",{className:"text-xs mt-2",style:{color:"#EF4444"},children:["❌"," No valid AKB (CLAUDE.md required)"]}),Re&&l.jsx(rf,{onSelect:Ne=>{se(Ne),ye(null),me(!1)},onClose:()=>me(!1)})]})})]}),Xe==="team"&&l.jsxs("div",{className:"space-y-4",children:[l.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Team Template"}),l.jsx("p",{className:"text-xs",style:{color:"var(--terminal-text-secondary)"},children:"Choose a starting team. You can add or remove roles later."}),Fe.map(Ne=>l.jsxs("div",{className:tn(Pe===Ne.id),onClick:()=>it(Ne.id),children:[l.jsx("div",{className:"font-medium text-sm capitalize",children:Ne.id}),l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:Ne.roles.map(Ct=>l.jsx("span",{className:"px-2 py-0.5 rounded text-[10px]",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:Ct.id.toUpperCase()},Ct.id))})]},Ne.id)),l.jsxs("div",{className:tn(Pe==="custom"),onClick:()=>it("custom"),children:[l.jsx("div",{className:"font-medium text-sm",children:"Custom"}),l.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Start with no pre-built roles. Hire them from the office."})]})]}),Xe==="create"&&l.jsxs("div",{className:"space-y-4",children:[l.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:nt?N==="existing-akb"?"AKB Connected!":"Company Created!":"Review & Create"}),!nt&&!ht&&!Ce&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"rounded-lg p-4 space-y-2 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:N==="existing-akb"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Mode:"})," Connect Existing AKB"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Path:"})," ",J]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Engine:"})," ",o==="claude-cli"?"Claude Code CLI":"Direct API"]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Company:"})," ",p]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Location:"})," ",A||"(default)"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Engine:"})," ",o==="claude-cli"?"Claude Code CLI":"Direct API"]}),R.trim()&&l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Code Repo:"})," ",R]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Knowledge:"})," ",M.length>0?`Import ${M.length} source(s)`:"Fresh (empty)"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Team:"})," ",Pe]}),M.length>0&&l.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--idle-amber)"},children:"Knowledge import will run in the background after entering the office."})]})}),kt&&l.jsx("div",{className:"text-xs p-3 rounded",style:{background:"rgba(220,38,38,0.15)",color:"#f87171"},children:kt})]}),(ht||Ce)&&l.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[l.jsx("div",{className:"w-8 h-8 border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),l.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-secondary)"},children:Ce?"Connecting to AKB...":"Scaffolding your company..."})]}),nt&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"text-center py-4 text-4xl",children:"🏢"}),te&&l.jsxs("div",{className:"rounded-lg p-3 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[l.jsx("span",{className:"opacity-50",children:"Location:"})," ",te]}),l.jsx("div",{className:"rounded-lg p-4 text-xs max-h-40 overflow-y-auto",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:ve.map((Ne,Ct)=>l.jsxs("div",{className:"py-0.5",children:[l.jsx("span",{style:{color:"var(--active-green)"},children:"✓"})," ",Ne]},Ct))}),(Se||Ge.length>0)&&l.jsxs("div",{className:"rounded-lg p-4 text-xs space-y-1",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[l.jsx("div",{className:"font-medium mb-2",style:{color:"var(--terminal-text-secondary)"},children:Se?"Installing skill tools...":"Skill tools"}),Ge.map((Ne,Ct)=>l.jsxs("div",{className:"py-0.5 flex items-center gap-2",children:[l.jsx("span",{style:{color:Ne.event==="installed"||Ne.event==="skipped"?"var(--active-green)":Ne.event==="error"?"#f87171":"var(--terminal-text-muted)"},children:Ne.event==="installed"||Ne.event==="skipped"?"✓":Ne.event==="error"?"✗":"…"}),l.jsx("span",{children:Ne.tool}),l.jsx("span",{style:{color:"var(--terminal-text-muted)"},children:Ne.detail})]},Ct)),Se&&l.jsxs("div",{className:"flex items-center gap-2 mt-1",style:{color:"var(--terminal-text-muted)"},children:[l.jsx("div",{className:"w-3 h-3 border border-current rounded-full animate-spin",style:{borderTopColor:"var(--accent)"}}),l.jsx("span",{children:"Please wait..."})]})]}),M.length>0&&l.jsx("div",{className:"text-xs p-3 rounded",style:{background:"var(--accent)",color:"#fff",opacity:.9},children:"Knowledge import will start in the background after entering the office."})]})]})]}),l.jsxs("div",{className:"px-6 py-4 flex justify-between items-center",style:{borderTop:"1px solid var(--terminal-border)"},children:[l.jsx("div",{children:t>0&&!nt&&l.jsx("button",{onClick:Be,className:"px-4 py-2 rounded text-sm transition-colors",style:{color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:"Back"})}),l.jsxs("div",{className:"text-xs",style:{color:"var(--terminal-text-muted)"},children:[t+1," / ",qe.length]}),l.jsx("div",{children:nt?l.jsx("button",{onClick:ae,disabled:Se,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:"var(--active-green)",color:"#fff",opacity:Se?.5:1},children:Se?"Setting up tools...":"Enter Office"}):l.jsx("button",{onClick:ze,disabled:!et()||ht||Ce,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:et()?"var(--accent)":"var(--terminal-border)",color:"#fff",opacity:et()&&!ht&&!Ce?1:.5},children:Xe==="create"?ht||Ce?Ce?"Connecting...":"Creating...":N==="existing-akb"?"Connect AKB":"Create Company":"Next"})})]})]})})}function X0({text:e}){const[t,n]=S.useState(!1),[i,a]=S.useState({top:0,left:0}),o=S.useRef(null),c=()=>{if(o.current){const d=o.current.getBoundingClientRect();a({top:d.bottom+6,left:d.left})}n(!0)};return l.jsxs("span",{className:"inline-flex",ref:o,children:[l.jsx("span",{className:"w-4 h-4 rounded-full text-[9px] font-bold flex items-center justify-center cursor-help shrink-0 select-none",style:{background:"var(--terminal-surface)",color:"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)"},onMouseEnter:c,onMouseLeave:()=>n(!1),onClick:d=>{d.stopPropagation(),t?n(!1):c()},children:"?"}),t&&l.jsxs("div",{className:"fixed z-[9999] px-3 py-2 rounded-lg text-[11px] leading-relaxed whitespace-pre-line w-60 shadow-lg pointer-events-none",style:{top:i.top,left:Math.min(i.left,window.innerWidth-260),background:"var(--terminal-bg)",color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:[l.jsx("div",{className:"absolute bottom-full w-0 h-0",style:{left:8,borderLeft:"5px solid transparent",borderRight:"5px solid transparent",borderBottom:"5px solid var(--terminal-border)"}}),e]})]})}function p2({icon:e,title:t,hint:n,help:i,children:a}){return l.jsxs("div",{className:"rounded-lg p-3 space-y-2",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm",children:e}),l.jsx("span",{className:"text-xs font-medium",style:{color:"var(--terminal-text)"},children:t}),i&&l.jsx(X0,{text:i})]}),l.jsx("div",{className:"text-[10px] mt-0.5 ml-6",style:{color:"var(--terminal-text-muted)"},children:n})]}),a]})}function x2({icon:e,title:t,hint:n,help:i,tag:a,open:o,onToggle:c,children:d}){return l.jsxs("div",{className:"rounded-lg",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{className:"p-3 cursor-pointer flex items-center gap-2 hover:bg-[var(--terminal-surface-light)] transition-colors",onClick:c,children:[l.jsx("span",{className:"text-sm",children:e}),l.jsx("span",{className:"text-xs font-medium flex-1",style:{color:"var(--terminal-text)"},children:t}),i&&l.jsx(X0,{text:i}),a&&l.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded",style:{background:"var(--terminal-surface)",color:"var(--terminal-text-muted)"},children:a}),l.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:o?"▲":"▼"})]}),!o&&l.jsx("div",{className:"px-3 pb-2 -mt-1",children:l.jsx("div",{className:"text-[10px] ml-6",style:{color:"var(--terminal-text-muted)"},children:n})}),o&&l.jsx("div",{className:"px-3 pb-3 space-y-2",children:d})]})}function kL(){const[e,t]=S.useState(null),[n,i]=S.useState(!0),[a,o]=S.useState(null),c=S.useCallback(async()=>{i(!0),o(null);try{const d=await ke.getStatus();t(d)}catch(d){o(d instanceof Error?d.message:"Failed to fetch status")}finally{i(!1)}},[]);return S.useEffect(()=>{c()},[c]),{initialized:(e==null?void 0:e.initialized)??!1,companyName:(e==null?void 0:e.companyName)??null,engine:(e==null?void 0:e.engine)??"none",companyRoot:(e==null?void 0:e.companyRoot)??"",loading:n,error:a,refetch:c}}const SL=S.lazy(()=>Px(()=>import("./preview-app-CMGFfqT-.js"),[])),jL=S.lazy(()=>Px(()=>import("./index-Czp8wshq.js"),__vite__mapDeps([0,1])));function Yx(){return l.jsx("div",{className:"h-full flex items-center justify-center",style:{background:"var(--floor-dark)"},children:l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"w-10 h-10 mx-auto border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),l.jsx("div",{className:"mt-4 text-sm",style:{color:"var(--terminal-text-secondary)",fontFamily:"var(--pixel-font)"},children:"Loading..."})]})})}function CL(){var e;try{const t=localStorage.getItem("tycono-theme"),n=t&&t in Bs?t:"default",i=(e=Bs[n])==null?void 0:e.vars;if(!i)return;const a=document.documentElement;for(const[o,c]of Object.entries(i))a.style.setProperty(o,c)}catch{}}function NL(){const{initialized:e,loading:t,refetch:n}=kL(),[i,a]=S.useState(null);S.useEffect(()=>{CL()},[]);const o=c=>{c&&a(c),n()};return t?l.jsx(Yx,{}):e?l.jsx(bL,{importReq:i,onImportDone:()=>a(null)}):l.jsx(wL,{onComplete:o})}function EL(){const e=new URLSearchParams(window.location.search),t=e.has("sprite-preview"),n=e.has("rpg-game");return l.jsx(Y4,{children:t?l.jsx(S.Suspense,{fallback:l.jsx(Yx,{}),children:l.jsx(SL,{})}):n?l.jsx(S.Suspense,{fallback:l.jsx(Yx,{}),children:l.jsx(jL,{})}):l.jsx(NL,{})})}H4.createRoot(document.getElementById("root")).render(l.jsx(S.StrictMode,{children:l.jsx(EL,{})}));export{ML as A,R3 as H,_L as O,B3 as P,$3 as S,z3 as a,F3 as b,DL as c,TL as d,l as j,S as r};
|
|
138
|
+
Skip this to start with an empty knowledge base. You can import documents anytime from the office.`,tag:"optional",open:Q,onToggle:()=>K(!Q),children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${We} flex-1`,placeholder:"/path/to/docs",value:P,onChange:Ne=>O(Ne.target.value),onKeyDown:Ne=>{Ne.key==="Enter"&&(Ne.preventDefault(),Tt())}}),l.jsx("button",{onClick:()=>ee(!Z),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"}),l.jsx("button",{onClick:Tt,disabled:!P.trim(),className:"px-3 py-2 rounded text-xs font-medium shrink-0",style:{background:"var(--accent)",color:"#fff",opacity:P.trim()?1:.5},children:"Add"})]}),Z&&l.jsx(rf,{onSelect:Ne=>{M.includes(Ne)||U([...M,Ne]),ee(!1)},onClose:()=>ee(!1)}),M.length>0&&l.jsx("div",{className:"space-y-1 mt-2",children:M.map((Ne,Ct)=>l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:[l.jsx("span",{className:"flex-1 truncate",style:{fontFamily:"var(--pixel-font)"},children:Ne}),l.jsx("button",{onClick:()=>U(M.filter((ln,nn)=>nn!==Ct)),className:"opacity-50 hover:opacity-100",children:"✕"})]},Ct))})]})]}):l.jsx("div",{className:"space-y-3",children:l.jsxs(p2,{icon:"🔗",title:"AKB Path",hint:"Directory with existing CLAUDE.md and AKB structure.",help:"Connect to a directory that was previously set up with Tycono. It must contain a CLAUDE.md file. All existing roles, knowledge, and settings will be loaded.",children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${We} flex-1`,placeholder:"/path/to/your/akb",value:J,onChange:Ne=>{se(Ne.target.value),ye(null)},autoFocus:!0}),l.jsx("button",{onClick:()=>me(!Re),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"}),l.jsx("button",{onClick:en,disabled:De||!J.trim(),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0",style:{background:"var(--accent)",color:"#fff",opacity:De||!J.trim()?.5:1},children:De?"...":"Verify"})]}),le===!0&&l.jsxs("div",{className:"text-xs mt-2",style:{color:"var(--active-green)"},children:["✅"," Valid AKB found"]}),le===!1&&l.jsxs("div",{className:"text-xs mt-2",style:{color:"#EF4444"},children:["❌"," No valid AKB (CLAUDE.md required)"]}),Re&&l.jsx(rf,{onSelect:Ne=>{se(Ne),ye(null),me(!1)},onClose:()=>me(!1)})]})})]}),Xe==="team"&&l.jsxs("div",{className:"space-y-4",children:[l.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Team Template"}),l.jsx("p",{className:"text-xs",style:{color:"var(--terminal-text-secondary)"},children:"Choose a starting team. You can add or remove roles later."}),Fe.map(Ne=>l.jsxs("div",{className:tn(Pe===Ne.id),onClick:()=>it(Ne.id),children:[l.jsx("div",{className:"font-medium text-sm capitalize",children:Ne.id}),l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:Ne.roles.map(Ct=>l.jsx("span",{className:"px-2 py-0.5 rounded text-[10px]",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:Ct.id.toUpperCase()},Ct.id))})]},Ne.id)),l.jsxs("div",{className:tn(Pe==="custom"),onClick:()=>it("custom"),children:[l.jsx("div",{className:"font-medium text-sm",children:"Custom"}),l.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Start with no pre-built roles. Hire them from the office."})]})]}),Xe==="create"&&l.jsxs("div",{className:"space-y-4",children:[l.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:nt?N==="existing-akb"?"AKB Connected!":"Company Created!":"Review & Create"}),!nt&&!ht&&!Ce&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"rounded-lg p-4 space-y-2 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:N==="existing-akb"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Mode:"})," Connect Existing AKB"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Path:"})," ",J]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Engine:"})," ",o==="claude-cli"?"Claude Code CLI":"Direct API"]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Company:"})," ",p]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Location:"})," ",A||"(default)"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Engine:"})," ",o==="claude-cli"?"Claude Code CLI":"Direct API"]}),R.trim()&&l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Code Repo:"})," ",R]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Knowledge:"})," ",M.length>0?`Import ${M.length} source(s)`:"Fresh (empty)"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Team:"})," ",Pe]}),M.length>0&&l.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--idle-amber)"},children:"Knowledge import will run in the background after entering the office."})]})}),kt&&l.jsx("div",{className:"text-xs p-3 rounded",style:{background:"rgba(220,38,38,0.15)",color:"#f87171"},children:kt})]}),(ht||Ce)&&l.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[l.jsx("div",{className:"w-8 h-8 border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),l.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-secondary)"},children:Ce?"Connecting to AKB...":"Scaffolding your company..."})]}),nt&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"text-center py-4 text-4xl",children:"🏢"}),te&&l.jsxs("div",{className:"rounded-lg p-3 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[l.jsx("span",{className:"opacity-50",children:"Location:"})," ",te]}),l.jsx("div",{className:"rounded-lg p-4 text-xs max-h-40 overflow-y-auto",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:ve.map((Ne,Ct)=>l.jsxs("div",{className:"py-0.5",children:[l.jsx("span",{style:{color:"var(--active-green)"},children:"✓"})," ",Ne]},Ct))}),(Se||Ge.length>0)&&l.jsxs("div",{className:"rounded-lg p-4 text-xs space-y-1",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[l.jsx("div",{className:"font-medium mb-2",style:{color:"var(--terminal-text-secondary)"},children:Se?"Installing skill tools...":"Skill tools"}),Ge.map((Ne,Ct)=>l.jsxs("div",{className:"py-0.5 flex items-center gap-2",children:[l.jsx("span",{style:{color:Ne.event==="installed"||Ne.event==="skipped"?"var(--active-green)":Ne.event==="error"?"#f87171":"var(--terminal-text-muted)"},children:Ne.event==="installed"||Ne.event==="skipped"?"✓":Ne.event==="error"?"✗":"…"}),l.jsx("span",{children:Ne.tool}),l.jsx("span",{style:{color:"var(--terminal-text-muted)"},children:Ne.detail})]},Ct)),Se&&l.jsxs("div",{className:"flex items-center gap-2 mt-1",style:{color:"var(--terminal-text-muted)"},children:[l.jsx("div",{className:"w-3 h-3 border border-current rounded-full animate-spin",style:{borderTopColor:"var(--accent)"}}),l.jsx("span",{children:"Please wait..."})]})]}),M.length>0&&l.jsx("div",{className:"text-xs p-3 rounded",style:{background:"var(--accent)",color:"#fff",opacity:.9},children:"Knowledge import will start in the background after entering the office."})]})]})]}),l.jsxs("div",{className:"px-6 py-4 flex justify-between items-center",style:{borderTop:"1px solid var(--terminal-border)"},children:[l.jsx("div",{children:t>0&&!nt&&l.jsx("button",{onClick:Be,className:"px-4 py-2 rounded text-sm transition-colors",style:{color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:"Back"})}),l.jsxs("div",{className:"text-xs",style:{color:"var(--terminal-text-muted)"},children:[t+1," / ",qe.length]}),l.jsx("div",{children:nt?l.jsx("button",{onClick:ae,disabled:Se,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:"var(--active-green)",color:"#fff",opacity:Se?.5:1},children:Se?"Setting up tools...":"Enter Office"}):l.jsx("button",{onClick:ze,disabled:!et()||ht||Ce,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:et()?"var(--accent)":"var(--terminal-border)",color:"#fff",opacity:et()&&!ht&&!Ce?1:.5},children:Xe==="create"?ht||Ce?Ce?"Connecting...":"Creating...":N==="existing-akb"?"Connect AKB":"Create Company":"Next"})})]})]})})}function X0({text:e}){const[t,n]=S.useState(!1),[i,a]=S.useState({top:0,left:0}),o=S.useRef(null),c=()=>{if(o.current){const d=o.current.getBoundingClientRect();a({top:d.bottom+6,left:d.left})}n(!0)};return l.jsxs("span",{className:"inline-flex",ref:o,children:[l.jsx("span",{className:"w-4 h-4 rounded-full text-[9px] font-bold flex items-center justify-center cursor-help shrink-0 select-none",style:{background:"var(--terminal-surface)",color:"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)"},onMouseEnter:c,onMouseLeave:()=>n(!1),onClick:d=>{d.stopPropagation(),t?n(!1):c()},children:"?"}),t&&l.jsxs("div",{className:"fixed z-[9999] px-3 py-2 rounded-lg text-[11px] leading-relaxed whitespace-pre-line w-60 shadow-lg pointer-events-none",style:{top:i.top,left:Math.min(i.left,window.innerWidth-260),background:"var(--terminal-bg)",color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:[l.jsx("div",{className:"absolute bottom-full w-0 h-0",style:{left:8,borderLeft:"5px solid transparent",borderRight:"5px solid transparent",borderBottom:"5px solid var(--terminal-border)"}}),e]})]})}function p2({icon:e,title:t,hint:n,help:i,children:a}){return l.jsxs("div",{className:"rounded-lg p-3 space-y-2",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm",children:e}),l.jsx("span",{className:"text-xs font-medium",style:{color:"var(--terminal-text)"},children:t}),i&&l.jsx(X0,{text:i})]}),l.jsx("div",{className:"text-[10px] mt-0.5 ml-6",style:{color:"var(--terminal-text-muted)"},children:n})]}),a]})}function x2({icon:e,title:t,hint:n,help:i,tag:a,open:o,onToggle:c,children:d}){return l.jsxs("div",{className:"rounded-lg",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{className:"p-3 cursor-pointer flex items-center gap-2 hover:bg-[var(--terminal-surface-light)] transition-colors",onClick:c,children:[l.jsx("span",{className:"text-sm",children:e}),l.jsx("span",{className:"text-xs font-medium flex-1",style:{color:"var(--terminal-text)"},children:t}),i&&l.jsx(X0,{text:i}),a&&l.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded",style:{background:"var(--terminal-surface)",color:"var(--terminal-text-muted)"},children:a}),l.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:o?"▲":"▼"})]}),!o&&l.jsx("div",{className:"px-3 pb-2 -mt-1",children:l.jsx("div",{className:"text-[10px] ml-6",style:{color:"var(--terminal-text-muted)"},children:n})}),o&&l.jsx("div",{className:"px-3 pb-3 space-y-2",children:d})]})}function kL(){const[e,t]=S.useState(null),[n,i]=S.useState(!0),[a,o]=S.useState(null),c=S.useCallback(async()=>{i(!0),o(null);try{const d=await ke.getStatus();t(d)}catch(d){o(d instanceof Error?d.message:"Failed to fetch status")}finally{i(!1)}},[]);return S.useEffect(()=>{c()},[c]),{initialized:(e==null?void 0:e.initialized)??!1,companyName:(e==null?void 0:e.companyName)??null,engine:(e==null?void 0:e.engine)??"none",companyRoot:(e==null?void 0:e.companyRoot)??"",loading:n,error:a,refetch:c}}const SL=S.lazy(()=>Px(()=>import("./preview-app-DZ6WxhDc.js"),[])),jL=S.lazy(()=>Px(()=>import("./index-DDPzbp9E.js"),__vite__mapDeps([0,1])));function Yx(){return l.jsx("div",{className:"h-full flex items-center justify-center",style:{background:"var(--floor-dark)"},children:l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"w-10 h-10 mx-auto border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),l.jsx("div",{className:"mt-4 text-sm",style:{color:"var(--terminal-text-secondary)",fontFamily:"var(--pixel-font)"},children:"Loading..."})]})})}function CL(){var e;try{const t=localStorage.getItem("tycono-theme"),n=t&&t in Bs?t:"default",i=(e=Bs[n])==null?void 0:e.vars;if(!i)return;const a=document.documentElement;for(const[o,c]of Object.entries(i))a.style.setProperty(o,c)}catch{}}function NL(){const{initialized:e,loading:t,refetch:n}=kL(),[i,a]=S.useState(null);S.useEffect(()=>{CL()},[]);const o=c=>{c&&a(c),n()};return t?l.jsx(Yx,{}):e?l.jsx(bL,{importReq:i,onImportDone:()=>a(null)}):l.jsx(wL,{onComplete:o})}function EL(){const e=new URLSearchParams(window.location.search),t=e.has("sprite-preview"),n=e.has("rpg-game");return l.jsx(Y4,{children:t?l.jsx(S.Suspense,{fallback:l.jsx(Yx,{}),children:l.jsx(SL,{})}):n?l.jsx(S.Suspense,{fallback:l.jsx(Yx,{}),children:l.jsx(jL,{})}):l.jsx(NL,{})})}H4.createRoot(document.getElementById("root")).render(l.jsx(S.StrictMode,{children:l.jsx(EL,{})}));export{ML as A,R3 as H,_L as O,B3 as P,$3 as S,z3 as a,F3 as b,DL as c,TL as d,l as j,S as r};
|