@markus-global/cli 0.11.3-rc.0 → 0.12.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +5 -1
- package/dist/backend.js.map +1 -1
- package/dist/commands/approval-card.d.ts +53 -0
- package/dist/commands/approval-card.d.ts.map +1 -0
- package/dist/commands/approval-card.js +43 -0
- package/dist/commands/approval-card.js.map +1 -0
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +11 -5
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +7 -5
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/model.d.ts.map +1 -1
- package/dist/commands/model.js +6 -4
- package/dist/commands/model.js.map +1 -1
- package/dist/commands/outbound.d.ts +76 -0
- package/dist/commands/outbound.d.ts.map +1 -0
- package/dist/commands/outbound.js +80 -0
- package/dist/commands/outbound.js.map +1 -0
- package/dist/commands/start.d.ts +124 -2
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +718 -82
- package/dist/commands/start.js.map +1 -1
- package/dist/index.js +5 -20
- package/dist/index.js.map +1 -1
- package/dist/markus.mjs +112615 -103125
- package/dist/web-ui/assets/AsyncState-BebkDWbq.js +1 -0
- package/dist/web-ui/assets/{CommentInput-C-niUbUY.js → CommentInput-BRZWIC3U.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-DxsnJJRX.js → ContentRenderer-PGP8H_Zz.js} +2 -2
- package/dist/web-ui/assets/DeliverableShareModal-CcigVYGz.js +1 -0
- package/dist/web-ui/assets/Deliverables-CQwXaCA4.js +3 -0
- package/dist/web-ui/assets/{Notifications-4KXYRdkr.js → Notifications-BvHJCIRG.js} +1 -1
- package/dist/web-ui/assets/Search-BA-aXh7i.js +1 -0
- package/dist/web-ui/assets/SendToChat-CAfyKhpq.js +1 -0
- package/dist/web-ui/assets/Settings-icFp6tNI.js +8 -0
- package/dist/web-ui/assets/{Store-JWjwXfTU.js → Store-DKwOcmMu.js} +1 -1
- package/dist/web-ui/assets/Switch-C7lFnHA7.js +1 -0
- package/dist/web-ui/assets/Team-DyqXLZ-X.js +84 -0
- package/dist/web-ui/assets/Work-BXGrda4S.js +12 -0
- package/dist/web-ui/assets/{arc-DPZmpo1U.js → arc-Dnk6N-Zc.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-DlOs02JO.js → architectureDiagram-3BPJPVTR-CV8JIXXD.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-C7qsXNUe.js → blockDiagram-GPEHLZMM-D9pKmrXH.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-Drwp-rtM.js → c4Diagram-AAUBKEIU-Q26HvIpY.js} +1 -1
- package/dist/web-ui/assets/channel-BZs6ereM.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-VgR09Mqk.js → chunk-2J33WTMH-BSjFVwnx.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-CuwDpBRL.js → chunk-4BX2VUAB-BZXv4MQp.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-nC7YWJ_i.js → chunk-55IACEB6-CeKd3oeJ.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-Dw6mBsRE.js → chunk-727SXJPM-DP1tSQo5.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-CPhNJbHl.js → chunk-AQP2D5EJ-DqEncn7j.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-AyhQakG8.js → chunk-FMBD7UC4-tuDUJ9Xx.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-DgYemv8I.js → chunk-ND2GUHAM-DoC8aLWB.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-CLdqxrFB.js → chunk-QZHKN3VN-74zpvcgs.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-C9JIxJeJ.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-C9JIxJeJ.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-DrOgwDIH.js → cose-bilkent-S5V4N54A-DjYUalC1.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-DhoJiA83.js → dagre-BM42HDAG-oSewacE8.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-BDILSgqK.js → diagram-2AECGRRQ-C1fiWe46.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-CeXywd1i.js → diagram-5GNKFQAL-9G_q6hCa.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-Bi4RlMT0.js → diagram-KO2AKTUF-CSm-lJp-.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-Cw1yxk8b.js → diagram-LMA3HP47-BTAORcHx.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-Bl857da2.js → diagram-OG6HWLK6-DbcCkDfo.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-CjoUhrMq.js → docx-preview-DjqdA44x.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-DEiaMhuV.js → erDiagram-TEJ5UH35-DFa-B8-u.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-BgKZhO0h.js → flowDiagram-I6XJVG4X-WCTnaK9M.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-Dkx-EaS8.js → ganttDiagram-6RSMTGT7-DbW1CoJJ.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-DXaQwA0y.js → gitGraphDiagram-PVQCEYII-1faDfO29.js} +1 -1
- package/dist/web-ui/assets/index-B8h1PPzP.js +883 -0
- package/dist/web-ui/assets/index-DD3NMntN.css +1 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-Dpx9IOkx.js → infoDiagram-5YYISTIA-DfXKP4tQ.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-BWqWgitQ.js → ishikawaDiagram-YF4QCWOH-D6FOsFQ5.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-BBwIZ4k9.js → journeyDiagram-JHISSGLW-DXpxntIF.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-C_MRWV8R.js → kanban-definition-UN3LZRKU-Dt7FBCF3.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-BMAh3nnq.js → mermaid.core-sTcSUoRD.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-B6vJQcat.js → mindmap-definition-RKZ34NQL-CvOU23ga.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-BxdEttqt.js → pieDiagram-4H26LBE5-DUedtXVj.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-gsNs2VfP.js → quadrantDiagram-W4KKPZXB-CqpHHRca.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-BSC9KvC2.js → requirementDiagram-4Y6WPE33-CKZYvVDJ.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-DktAZfe_.js → sankeyDiagram-5OEKKPKP-gZ0nzDfs.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-BIPt8kGU.js → sequenceDiagram-3UESZ5HK-DN3XdBkW.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-DiXmJWB0.js → stateDiagram-AJRCARHV-BvtafGxO.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-B2nWDV5R.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-LRi7H35g.js → timeline-definition-PNZ67QCA-BrR919lp.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-DWQ1I022.js → vennDiagram-CIIHVFJN-B7CTm4yM.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-BUb6dYqN.js → wardley-L42UT6IY-CyqFngx_.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-BYE1B3xT.js → wardleyDiagram-YWT4CUSO-BCqEPBJ5.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-D-pS2-Sa.js → xychartDiagram-2RQKCTM6-BmT6Cmz-.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/README.md +1 -0
- package/docs/architecture/architecture.md +1 -1
- package/docs/architecture/configuration-model.md +156 -0
- package/docs/architecture/messaging-gateway.md +1043 -0
- package/docs/architecture/notification-delivery.md +273 -0
- package/docs/design/remote-access-contract.md +445 -0
- package/docs/guides/development.md +1 -1
- package/docs/guides/guide.md +4 -2
- package/docs/guides/remote-access.md +147 -214
- package/docs/handoff/approval-tri-state-handoff.md +69 -0
- package/docs/handoff/remote-access-handoff.md +160 -0
- package/docs/records/agent-platform-friction-2026-10.md +102 -2
- package/package.json +1 -1
- package/dist/web-ui/assets/DeliverableShareModal-DV3TiZx0.js +0 -1
- package/dist/web-ui/assets/Deliverables-tlLsJnxZ.js +0 -3
- package/dist/web-ui/assets/Search-CPFwZv1U.js +0 -1
- package/dist/web-ui/assets/Settings-DIa-_qre.js +0 -8
- package/dist/web-ui/assets/Team-COBxn96h.js +0 -84
- package/dist/web-ui/assets/Work-BScJUqWL.js +0 -12
- package/dist/web-ui/assets/channel-DCChB-1T.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-CrNiYfSI.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-CrNiYfSI.js +0 -1
- package/dist/web-ui/assets/index-C_QhfMcC.js +0 -882
- package/dist/web-ui/assets/index-DEN_qReg.css +0 -1
- package/dist/web-ui/assets/modelCapabilities-DDtCBZ6o.js +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-COOgTXIX.js +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{u as Oe,j as t,z as sc,B as oc,y as ac,R as ic,r as p,l as re,C as lc,a as jr,k as cc,n as Bt,P as He,b as dc,c as uc,m as fc,s as qo,E as hc,F as mc,w as Tt,G as Dt,H as Wr,p as Fr,M as pc,i as gc,J as Fn,q as pr,d as xc,K as ci,A as Us,L as Wo,Q as Fo,U as Vo,O as bc,V as di,W as yc,X as wc,Y as ui,Z as vc,$ as kc}from"./index-B8h1PPzP.js";import{a as fi,s as jc,S as Nc,r as Cc}from"./SendToChat-CAfyKhpq.js";import{L as Sc,P as Ec}from"./AsyncState-BebkDWbq.js";import{ContentRenderer as Mc}from"./ContentRenderer-PGP8H_Zz.js";import{s as Mt,e as hi,f as Zs,T as Ns,g as Cs,t as Ic}from"./transform-CpIVI4vC.js";import{i as Ss}from"./value-DIujSiJ7.js";import{C as mi}from"./CommentInput-BRZWIC3U.js";function Tc(e){let n;for(;n=e.sourceEvent;)e=n;return e}function At(e,n){if(e=Tc(e),n===void 0&&(n=e.currentTarget),n){var s=n.ownerSVGElement||n;if(s.createSVGPoint){var r=s.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(n.getScreenCTM().inverse()),[r.x,r.y]}if(n.getBoundingClientRect){var i=n.getBoundingClientRect();return[e.clientX-i.left-n.clientLeft,e.clientY-i.top-n.clientTop]}}return[e.pageX,e.pageY]}const Rc={passive:!1},gr={capture:!0,passive:!1};function Es(e){e.stopImmediatePropagation()}function Kn(e){e.preventDefault(),e.stopImmediatePropagation()}function pi(e){var n=e.document.documentElement,s=Mt(e).on("dragstart.drag",Kn,gr);"onselectstart"in n?s.on("selectstart.drag",Kn,gr):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function gi(e,n){var s=e.document.documentElement,r=Mt(e).on("dragstart.drag",null);n&&(r.on("click.drag",Kn,gr),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in s?r.on("selectstart.drag",null):(s.style.MozUserSelect=s.__noselect,delete s.__noselect)}const Vr=e=>()=>e;function Bs(e,{sourceEvent:n,subject:s,target:r,identifier:i,active:o,x:a,y:l,dx:c,dy:d,dispatch:f}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:s,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:a,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:f}})}Bs.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function _c(e){return!e.ctrlKey&&!e.button}function Lc(){return this.parentNode}function Dc(e,n){return n??{x:e.x,y:e.y}}function Ac(){return navigator.maxTouchPoints||"ontouchstart"in this}function xi(){var e=_c,n=Lc,s=Dc,r=Ac,i={},o=hi("start","drag","end"),a=0,l,c,d,f,h=0;function m(b){b.on("mousedown.drag",u).filter(r).on("touchstart.drag",S).on("touchmove.drag",v,Rc).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(b,j){if(!(f||!e.call(this,b,j))){var k=x(this,n.call(this,b,j),b,j,"mouse");k&&(Mt(b.view).on("mousemove.drag",g,gr).on("mouseup.drag",C,gr),pi(b.view),Es(b),d=!1,l=b.clientX,c=b.clientY,k("start",b))}}function g(b){if(Kn(b),!d){var j=b.clientX-l,k=b.clientY-c;d=j*j+k*k>h}i.mouse("drag",b)}function C(b){Mt(b.view).on("mousemove.drag mouseup.drag",null),gi(b.view,d),Kn(b),i.mouse("end",b)}function S(b,j){if(e.call(this,b,j)){var k=b.changedTouches,M=n.call(this,b,j),T=k.length,A,D;for(A=0;A<T;++A)(D=x(this,M,b,j,k[A].identifier,k[A]))&&(Es(b),D("start",b,k[A]))}}function v(b){var j=b.changedTouches,k=j.length,M,T;for(M=0;M<k;++M)(T=i[j[M].identifier])&&(Kn(b),T("drag",b,j[M]))}function y(b){var j=b.changedTouches,k=j.length,M,T;for(f&&clearTimeout(f),f=setTimeout(function(){f=null},500),M=0;M<k;++M)(T=i[j[M].identifier])&&(Es(b),T("end",b,j[M]))}function x(b,j,k,M,T,A){var D=o.copy(),E=At(A||k,j),P,q,N;if((N=s.call(b,new Bs("beforestart",{sourceEvent:k,target:m,identifier:T,active:a,x:E[0],y:E[1],dx:0,dy:0,dispatch:D}),M))!=null)return P=N.x-E[0]||0,q=N.y-E[1]||0,function O(_,z,L){var R=E,$;switch(_){case"start":i[T]=O,$=a++;break;case"end":delete i[T],--a;case"drag":E=At(L||z,j),$=a;break}D.call(_,b,new Bs(_,{sourceEvent:z,subject:N,target:m,identifier:T,active:$,x:E[0]+P,y:E[1]+q,dx:E[0]-R[0],dy:E[1]-R[1],dispatch:D}),M)}}return m.filter=function(b){return arguments.length?(e=typeof b=="function"?b:Vr(!!b),m):e},m.container=function(b){return arguments.length?(n=typeof b=="function"?b:Vr(b),m):n},m.subject=function(b){return arguments.length?(s=typeof b=="function"?b:Vr(b),m):s},m.touchable=function(b){return arguments.length?(r=typeof b=="function"?b:Vr(!!b),m):r},m.on=function(){var b=o.on.apply(o,arguments);return b===o?m:b},m.clickDistance=function(b){return arguments.length?(h=(b=+b)*b,m):Math.sqrt(h)},m}var Pc=1e-12;function Yo(e){return((e=Math.exp(e))+1/e)/2}function $c(e){return((e=Math.exp(e))-1/e)/2}function Bc(e){return((e=Math.exp(2*e))-1)/(e+1)}const ts=(function e(n,s,r){function i(o,a){var l=o[0],c=o[1],d=o[2],f=a[0],h=a[1],m=a[2],u=f-l,g=h-c,C=u*u+g*g,S,v;if(C<Pc)v=Math.log(m/d)/n,S=function(M){return[l+M*u,c+M*g,d*Math.exp(n*M*v)]};else{var y=Math.sqrt(C),x=(m*m-d*d+r*C)/(2*d*s*y),b=(m*m-d*d-r*C)/(2*m*s*y),j=Math.log(Math.sqrt(x*x+1)-x),k=Math.log(Math.sqrt(b*b+1)-b);v=(k-j)/n,S=function(M){var T=M*v,A=Yo(j),D=d/(s*y)*(A*Bc(n*T+j)-$c(j));return[l+D*u,c+D*g,d*A/Yo(n*T+j)]}}return S.duration=v*1e3*n/Math.SQRT2,S}return i.rho=function(o){var a=Math.max(.001,+o),l=a*a,c=l*l;return e(a,l,c)},i})(Math.SQRT2,2,4),Yr=e=>()=>e;function Oc(e,{sourceEvent:n,target:s,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:s,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function Ms(e){e.stopImmediatePropagation()}function hr(e){e.preventDefault(),e.stopImmediatePropagation()}function zc(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Hc(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Go(){return this.__zoom||Zs}function qc(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Wc(){return navigator.maxTouchPoints||"ontouchstart"in this}function Fc(e,n,s){var r=e.invertX(n[0][0])-s[0][0],i=e.invertX(n[1][0])-s[1][0],o=e.invertY(n[0][1])-s[0][1],a=e.invertY(n[1][1])-s[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),a>o?(o+a)/2:Math.min(0,o)||Math.max(0,a))}function bi(){var e=zc,n=Hc,s=Fc,r=qc,i=Wc,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],l=250,c=ts,d=hi("start","zoom","end"),f,h,m,u=500,g=150,C=0,S=10;function v(N){N.property("__zoom",Go).on("wheel.zoom",T,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",D).filter(i).on("touchstart.zoom",E).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",q).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}v.transform=function(N,O,_,z){var L=N.selection?N.selection():N;L.property("__zoom",Go),N!==L?j(N,O,_,z):L.interrupt().each(function(){k(this,arguments).event(z).start().zoom(null,typeof O=="function"?O.apply(this,arguments):O).end()})},v.scaleBy=function(N,O,_,z){v.scaleTo(N,function(){var L=this.__zoom.k,R=typeof O=="function"?O.apply(this,arguments):O;return L*R},_,z)},v.scaleTo=function(N,O,_,z){v.transform(N,function(){var L=n.apply(this,arguments),R=this.__zoom,$=_==null?b(L):typeof _=="function"?_.apply(this,arguments):_,W=R.invert($),F=typeof O=="function"?O.apply(this,arguments):O;return s(x(y(R,F),$,W),L,a)},_,z)},v.translateBy=function(N,O,_,z){v.transform(N,function(){return s(this.__zoom.translate(typeof O=="function"?O.apply(this,arguments):O,typeof _=="function"?_.apply(this,arguments):_),n.apply(this,arguments),a)},null,z)},v.translateTo=function(N,O,_,z,L){v.transform(N,function(){var R=n.apply(this,arguments),$=this.__zoom,W=z==null?b(R):typeof z=="function"?z.apply(this,arguments):z;return s(Zs.translate(W[0],W[1]).scale($.k).translate(typeof O=="function"?-O.apply(this,arguments):-O,typeof _=="function"?-_.apply(this,arguments):-_),R,a)},z,L)};function y(N,O){return O=Math.max(o[0],Math.min(o[1],O)),O===N.k?N:new Ns(O,N.x,N.y)}function x(N,O,_){var z=O[0]-_[0]*N.k,L=O[1]-_[1]*N.k;return z===N.x&&L===N.y?N:new Ns(N.k,z,L)}function b(N){return[(+N[0][0]+ +N[1][0])/2,(+N[0][1]+ +N[1][1])/2]}function j(N,O,_,z){N.on("start.zoom",function(){k(this,arguments).event(z).start()}).on("interrupt.zoom end.zoom",function(){k(this,arguments).event(z).end()}).tween("zoom",function(){var L=this,R=arguments,$=k(L,R).event(z),W=n.apply(L,R),F=_==null?b(W):typeof _=="function"?_.apply(L,R):_,X=Math.max(W[1][0]-W[0][0],W[1][1]-W[0][1]),B=L.__zoom,I=typeof O=="function"?O.apply(L,R):O,Y=c(B.invert(F).concat(X/B.k),I.invert(F).concat(X/I.k));return function(V){if(V===1)V=I;else{var H=Y(V),Z=X/H[2];V=new Ns(Z,F[0]-H[0]*Z,F[1]-H[1]*Z)}$.zoom(null,V)}})}function k(N,O,_){return!_&&N.__zooming||new M(N,O)}function M(N,O){this.that=N,this.args=O,this.active=0,this.sourceEvent=null,this.extent=n.apply(N,O),this.taps=0}M.prototype={event:function(N){return N&&(this.sourceEvent=N),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(N,O){return this.mouse&&N!=="mouse"&&(this.mouse[1]=O.invert(this.mouse[0])),this.touch0&&N!=="touch"&&(this.touch0[1]=O.invert(this.touch0[0])),this.touch1&&N!=="touch"&&(this.touch1[1]=O.invert(this.touch1[0])),this.that.__zoom=O,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(N){var O=Mt(this.that).datum();d.call(N,this.that,new Oc(N,{sourceEvent:this.sourceEvent,target:v,transform:this.that.__zoom,dispatch:d}),O)}};function T(N,...O){if(!e.apply(this,arguments))return;var _=k(this,O).event(N),z=this.__zoom,L=Math.max(o[0],Math.min(o[1],z.k*Math.pow(2,r.apply(this,arguments)))),R=At(N);if(_.wheel)(_.mouse[0][0]!==R[0]||_.mouse[0][1]!==R[1])&&(_.mouse[1]=z.invert(_.mouse[0]=R)),clearTimeout(_.wheel);else{if(z.k===L)return;_.mouse=[R,z.invert(R)],Cs(this),_.start()}hr(N),_.wheel=setTimeout($,g),_.zoom("mouse",s(x(y(z,L),_.mouse[0],_.mouse[1]),_.extent,a));function $(){_.wheel=null,_.end()}}function A(N,...O){if(m||!e.apply(this,arguments))return;var _=N.currentTarget,z=k(this,O,!0).event(N),L=Mt(N.view).on("mousemove.zoom",F,!0).on("mouseup.zoom",X,!0),R=At(N,_),$=N.clientX,W=N.clientY;pi(N.view),Ms(N),z.mouse=[R,this.__zoom.invert(R)],Cs(this),z.start();function F(B){if(hr(B),!z.moved){var I=B.clientX-$,Y=B.clientY-W;z.moved=I*I+Y*Y>C}z.event(B).zoom("mouse",s(x(z.that.__zoom,z.mouse[0]=At(B,_),z.mouse[1]),z.extent,a))}function X(B){L.on("mousemove.zoom mouseup.zoom",null),gi(B.view,z.moved),hr(B),z.event(B).end()}}function D(N,...O){if(e.apply(this,arguments)){var _=this.__zoom,z=At(N.changedTouches?N.changedTouches[0]:N,this),L=_.invert(z),R=_.k*(N.shiftKey?.5:2),$=s(x(y(_,R),z,L),n.apply(this,O),a);hr(N),l>0?Mt(this).transition().duration(l).call(j,$,z,N):Mt(this).call(v.transform,$,z,N)}}function E(N,...O){if(e.apply(this,arguments)){var _=N.touches,z=_.length,L=k(this,O,N.changedTouches.length===z).event(N),R,$,W,F;for(Ms(N),$=0;$<z;++$)W=_[$],F=At(W,this),F=[F,this.__zoom.invert(F),W.identifier],L.touch0?!L.touch1&&L.touch0[2]!==F[2]&&(L.touch1=F,L.taps=0):(L.touch0=F,R=!0,L.taps=1+!!f);f&&(f=clearTimeout(f)),R&&(L.taps<2&&(h=F[0],f=setTimeout(function(){f=null},u)),Cs(this),L.start())}}function P(N,...O){if(this.__zooming){var _=k(this,O).event(N),z=N.changedTouches,L=z.length,R,$,W,F;for(hr(N),R=0;R<L;++R)$=z[R],W=At($,this),_.touch0&&_.touch0[2]===$.identifier?_.touch0[0]=W:_.touch1&&_.touch1[2]===$.identifier&&(_.touch1[0]=W);if($=_.that.__zoom,_.touch1){var X=_.touch0[0],B=_.touch0[1],I=_.touch1[0],Y=_.touch1[1],V=(V=I[0]-X[0])*V+(V=I[1]-X[1])*V,H=(H=Y[0]-B[0])*H+(H=Y[1]-B[1])*H;$=y($,Math.sqrt(V/H)),W=[(X[0]+I[0])/2,(X[1]+I[1])/2],F=[(B[0]+Y[0])/2,(B[1]+Y[1])/2]}else if(_.touch0)W=_.touch0[0],F=_.touch0[1];else return;_.zoom("touch",s(x($,W,F),_.extent,a))}}function q(N,...O){if(this.__zooming){var _=k(this,O).event(N),z=N.changedTouches,L=z.length,R,$;for(Ms(N),m&&clearTimeout(m),m=setTimeout(function(){m=null},u),R=0;R<L;++R)$=z[R],_.touch0&&_.touch0[2]===$.identifier?delete _.touch0:_.touch1&&_.touch1[2]===$.identifier&&delete _.touch1;if(_.touch1&&!_.touch0&&(_.touch0=_.touch1,delete _.touch1),_.touch0)_.touch0[1]=this.__zoom.invert(_.touch0[0]);else if(_.end(),_.taps===2&&($=At($,this),Math.hypot(h[0]-$[0],h[1]-$[1])<S)){var W=Mt(this).on("dblclick.zoom");W&&W.apply(this,arguments)}}}return v.wheelDelta=function(N){return arguments.length?(r=typeof N=="function"?N:Yr(+N),v):r},v.filter=function(N){return arguments.length?(e=typeof N=="function"?N:Yr(!!N),v):e},v.touchable=function(N){return arguments.length?(i=typeof N=="function"?N:Yr(!!N),v):i},v.extent=function(N){return arguments.length?(n=typeof N=="function"?N:Yr([[+N[0][0],+N[0][1]],[+N[1][0],+N[1][1]]]),v):n},v.scaleExtent=function(N){return arguments.length?(o[0]=+N[0],o[1]=+N[1],v):[o[0],o[1]]},v.translateExtent=function(N){return arguments.length?(a[0][0]=+N[0][0],a[1][0]=+N[1][0],a[0][1]=+N[0][1],a[1][1]=+N[1][1],v):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},v.constrain=function(N){return arguments.length?(s=N,v):s},v.duration=function(N){return arguments.length?(l=+N,v):l},v.interpolate=function(N){return arguments.length?(c=N,v):c},v.on=function(){var N=d.on.apply(d,arguments);return N===d?v:N},v.clickDistance=function(N){return arguments.length?(C=(N=+N)*N,v):Math.sqrt(C)},v.tapDistance=function(N){return arguments.length?(S=+N,v):S},v}const Vc=["30m","1h","2h","4h","8h","12h","1d","1w"],Yc={"30m":"freq30m","1h":"freq1h","2h":"freq2h","4h":"freq4h","8h":"freq8h","12h":"freq12h","1d":"freq1d","1w":"freq1w"};function Ko(e){return Yc[e]??"freq4h"}function Gc(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function Os(){return{mode:"calendar",every:"4h",calendar:"daily",weekdays:[1,2,3,4,5],time:"09:00",cron:"",maxRuns:"",timezone:Gc()}}function yi(e){const n=/^(\d{1,2}):(\d{2})$/.exec((e??"").trim());if(!n)return[9,0];const s=Math.min(23,Math.max(0,parseInt(n[1],10))),r=Math.min(59,Math.max(0,parseInt(n[2],10)));return[s,r]}function Kc(e){const[n,s]=yi(e);return`${String(n).padStart(2,"0")}:${String(s).padStart(2,"0")}`}function Uc(e,n,s){if(e==="cron")return"";const[r,i]=yi(s),o=e==="daily"?"*":e==="weekdays"?"1-5":n.length>0?[...n].sort((a,l)=>a-l).join(","):"*";return`${i} ${r} * * ${o}`}function Zc(e){const n=/^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+(\S+)$/.exec((e??"").trim());if(!n)return null;const s=parseInt(n[1],10),r=parseInt(n[2],10);if(s>59||r>23)return null;const i=n[3],o=`${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}`;if(i==="*")return{calendar:"daily",weekdays:[1,2,3,4,5],time:o};if(i==="1-5")return{calendar:"weekdays",weekdays:[1,2,3,4,5],time:o};if(/^\d(,\d)*$/.test(i)){const a=i.split(",").map(l=>parseInt(l,10)).filter(l=>l>=0&&l<=6);if(a.length>0)return{calendar:"weekly",weekdays:a,time:o}}return null}function Xc(e){const n=Os();if(!e)return n;if(e.timezone&&(n.timezone=e.timezone),n.maxRuns=e.maxRuns&&e.maxRuns>0?String(e.maxRuns):"",e.cron){const s=Zc(e.cron);n.mode="calendar",s?(n.calendar=s.calendar,n.weekdays=s.weekdays,n.time=s.time):(n.calendar="cron",n.cron=e.cron)}else e.every&&(n.mode="interval",n.every=e.every);return n}function wi(e){const n={};e.mode==="interval"?n.every=e.every||"4h":(n.cron=e.calendar==="cron"?e.cron.trim():Uc(e.calendar,e.weekdays,e.time),e.timezone&&(n.timezone=e.timezone));const s=parseInt(e.maxRuns,10);return e.maxRuns.trim()!==""&&Number.isFinite(s)&&s>0&&(n.maxRuns=s),n}const Qc=[1,2,3,4,5,6,0];function Jc({options:e,value:n,onChange:s,size:r="md"}){const i=r==="sm"?"px-2.5 py-1 text-xs":"px-3 py-1.5 text-sm";return t.jsx("div",{className:"inline-flex rounded-lg border border-border-default overflow-hidden",children:e.map(o=>t.jsx("button",{type:"button",onClick:()=>s(o.value),className:`${i} transition-colors ${n===o.value?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:o.label},o.value))})}function vi({value:e,onChange:n,compact:s=!1}){const{t:r}=Oe(),i=f=>n({...e,...f}),o=`px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500 ${s?"text-xs":"text-sm"}`,a=f=>{const m=e.weekdays.includes(f)?e.weekdays.filter(u=>u!==f):[...e.weekdays,f];i({weekdays:m})};let l;if(e.mode==="interval")l=r(`work:task.${Ko(e.every)}`);else if(e.calendar==="cron")l=r("work:task.scheduleCron",{expr:e.cron.trim()||"—"});else{const f=Kc(e.time);if(e.calendar==="daily")l=r("work:task.scheduleDailyAt",{time:f});else if(e.calendar==="weekdays")l=r("work:task.scheduleWeekdaysAt",{time:f});else{const h=[...e.weekdays].sort((m,u)=>m-u).map(m=>r(`work:task.weekdayShort.${m}`)).join(" ");l=e.weekdays.length?r("work:task.scheduleWeeklyAt",{days:h,time:f}):r("work:task.scheduleNoDays")}}const c=e.calendar==="daily"||e.calendar==="weekdays"||e.calendar==="weekly",d="text-fg-tertiary shrink-0 text-xs w-20";return t.jsxs("div",{className:"rounded-lg border border-border-default/70 bg-surface-elevated/40 p-3 space-y-2.5",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[t.jsx("span",{className:d,children:r("work:task.scheduleRepeatMode")}),t.jsx(Jc,{size:s?"sm":"md",value:e.mode,onChange:f=>i({mode:f}),options:[{value:"interval",label:r("work:task.scheduleByInterval")},{value:"calendar",label:r("work:task.scheduleByCalendar")}]})]}),e.mode==="interval"?t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:d,children:r("work:task.scheduleEveryLabel")}),t.jsx("select",{value:e.every,onChange:f=>i({every:f.target.value}),className:o,children:Vc.map(f=>t.jsx("option",{value:f,children:r(`work:task.${Ko(f)}`)},f))})]}):t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:d,children:r("work:task.scheduleRepeatLabel")}),t.jsxs("select",{value:e.calendar,onChange:f=>i({calendar:f.target.value}),className:o,children:[t.jsx("option",{value:"daily",children:r("work:task.scheduleCalendarDaily")}),t.jsx("option",{value:"weekdays",children:r("work:task.scheduleCalendarWeekdays")}),t.jsx("option",{value:"weekly",children:r("work:task.scheduleCalendarWeekly")}),t.jsx("option",{value:"cron",children:r("work:task.scheduleCalendarCron")})]}),c&&t.jsx("input",{type:"time",value:e.time,onChange:f=>i({time:f.target.value}),className:o})]}),e.calendar==="weekly"&&t.jsx("div",{className:"flex flex-wrap gap-1 pl-[5.5rem]",children:Qc.map(f=>{const h=e.weekdays.includes(f);return t.jsx("button",{type:"button",onClick:()=>a(f),className:`w-7 h-7 rounded-full text-xs transition-colors ${h?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary border border-border-default hover:text-fg-primary"}`,children:r(`work:task.weekdayShort.${f}`)},f)})}),e.calendar==="cron"&&t.jsx("input",{value:e.cron,onChange:f=>i({cron:f.target.value}),placeholder:"0 9 * * 1-5",className:`${o} w-full font-mono`})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:d,children:r("work:task.scheduleMaxRuns")}),t.jsx("input",{value:e.maxRuns,onChange:f=>i({maxRuns:f.target.value.replace(/\D/g,"")}),placeholder:r("work:task.scheduleMaxRunsPlaceholder"),className:`${o} w-20`})]}),t.jsxs("div",{className:"text-[11px] text-fg-secondary pt-1 border-t border-border-default/50",children:[r("work:task.schedulePreview",{desc:l}),t.jsxs("span",{className:"text-fg-tertiary",children:[" · ",r("work:task.scheduleTimezoneNote",{tz:e.timezone})]})]})]})}function tt(e){if(typeof e=="string"||typeof e=="number")return""+e;let n="";if(Array.isArray(e))for(let s=0,r;s<e.length;s++)(r=tt(e[s]))!==""&&(n+=(n&&" ")+r);else for(let s in e)e[s]&&(n+=(n&&" ")+s);return n}const Vt={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:n,sourceHandle:s,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?s:r}", edge id: ${n}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},xr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ki=["Enter"," ","Escape"],ji={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:n,y:s})=>`Moved selected node ${e}. New position, x: ${n}, y: ${s}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Un;(function(e){e.Strict="strict",e.Loose="loose"})(Un||(Un={}));var Mn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Mn||(Mn={}));var br;(function(e){e.Partial="partial",e.Full="full"})(br||(br={}));const Ni={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var dn;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(dn||(dn={}));var Zn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Zn||(Zn={}));var ye;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ye||(ye={}));const Uo={[ye.Left]:ye.Right,[ye.Right]:ye.Left,[ye.Top]:ye.Bottom,[ye.Bottom]:ye.Top};function Ci(e){return e===null?null:e?"valid":"invalid"}const Si=e=>"id"in e&&"source"in e&&"target"in e,ed=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Xs=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Nr=(e,n=[0,0])=>{const{width:s,height:r}=en(e),i=e.origin??n,o=s*i[0],a=r*i[1];return{x:e.position.x-o,y:e.position.y-a}},td=(e,n={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const s=e.reduce((r,i)=>{const o=typeof i=="string";let a=!n.nodeLookup&&!o?i:void 0;n.nodeLookup&&(a=o?n.nodeLookup.get(i):Xs(i)?i:n.nodeLookup.get(i.id));const l=a?os(a,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return fs(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return hs(s)},Cr=(e,n={})=>{let s={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(i=>{(n.filter===void 0||n.filter(i))&&(s=fs(s,os(i)),r=!0)}),r?hs(s):{x:0,y:0,width:0,height:0}},Qs=(e,n,[s,r,i]=[0,0,1],o=!1,a=!1)=>{const l={...Er(n,[s,r,i]),width:n.width/i,height:n.height/i},c=[];for(const d of e.values()){const{measured:f,selectable:h=!0,hidden:m=!1}=d;if(a&&!h||m)continue;const u=f.width??d.width??d.initialWidth??null,g=f.height??d.height??d.initialHeight??null,C=yr(l,Qn(d)),S=(u??0)*(g??0),v=o&&C>0;(!d.internals.handleBounds||v||C>=S||d.dragging)&&c.push(d)}return c},nd=(e,n)=>{const s=new Set;return e.forEach(r=>{s.add(r.id)}),n.filter(r=>s.has(r.source)||s.has(r.target))};function rd(e,n){const s=new Map,r=n?.nodes?new Set(n.nodes.map(i=>i.id)):null;return e.forEach(i=>{i.measured.width&&i.measured.height&&(n?.includeHiddenNodes||!i.hidden)&&(!r||r.has(i.id))&&s.set(i.id,i)}),s}async function sd({nodes:e,width:n,height:s,panZoom:r,minZoom:i,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const l=rd(e,a),c=Cr(l),d=Js(c,n,s,a?.minZoom??i,a?.maxZoom??o,a?.padding??.1);return await r.setViewport(d,{duration:a?.duration,ease:a?.ease,interpolate:a?.interpolate}),Promise.resolve(!0)}function Ei({nodeId:e,nextPosition:n,nodeLookup:s,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const a=s.get(e),l=a.parentId?s.get(a.parentId):void 0,{x:c,y:d}=l?l.internals.positionAbsolute:{x:0,y:0},f=a.origin??r;let h=a.extent||i;if(a.extent==="parent"&&!a.expandParent)if(!l)o?.("005",Vt.error005());else{const u=l.measured.width,g=l.measured.height;u&&g&&(h=[[c,d],[c+u,d+g]])}else l&&Jn(a.extent)&&(h=[[a.extent[0][0]+c,a.extent[0][1]+d],[a.extent[1][0]+c,a.extent[1][1]+d]]);const m=Jn(h)?In(n,h,a.measured):n;return(a.measured.width===void 0||a.measured.height===void 0)&&o?.("015",Vt.error015()),{position:{x:m.x-c+(a.measured.width??0)*f[0],y:m.y-d+(a.measured.height??0)*f[1]},positionAbsolute:m}}async function od({nodesToRemove:e=[],edgesToRemove:n=[],nodes:s,edges:r,onBeforeDelete:i}){const o=new Set(e.map(m=>m.id)),a=[];for(const m of s){if(m.deletable===!1)continue;const u=o.has(m.id),g=!u&&m.parentId&&a.find(C=>C.id===m.parentId);(u||g)&&a.push(m)}const l=new Set(n.map(m=>m.id)),c=r.filter(m=>m.deletable!==!1),f=nd(a,c);for(const m of c)l.has(m.id)&&!f.find(g=>g.id===m.id)&&f.push(m);if(!i)return{edges:f,nodes:a};const h=await i({nodes:a,edges:f});return typeof h=="boolean"?h?{edges:f,nodes:a}:{edges:[],nodes:[]}:h}const Xn=(e,n=0,s=1)=>Math.min(Math.max(e,n),s),In=(e={x:0,y:0},n,s)=>({x:Xn(e.x,n[0][0],n[1][0]-(s?.width??0)),y:Xn(e.y,n[0][1],n[1][1]-(s?.height??0))});function Mi(e,n,s){const{width:r,height:i}=en(s),{x:o,y:a}=s.internals.positionAbsolute;return In(e,[[o,a],[o+r,a+i]],n)}const Zo=(e,n,s)=>e<n?Xn(Math.abs(e-n),1,n)/n:e>s?-Xn(Math.abs(e-s),1,n)/n:0,Ii=(e,n,s=15,r=40)=>{const i=Zo(e.x,r,n.width-r)*s,o=Zo(e.y,r,n.height-r)*s;return[i,o]},fs=(e,n)=>({x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),x2:Math.max(e.x2,n.x2),y2:Math.max(e.y2,n.y2)}),zs=({x:e,y:n,width:s,height:r})=>({x:e,y:n,x2:e+s,y2:n+r}),hs=({x:e,y:n,x2:s,y2:r})=>({x:e,y:n,width:s-e,height:r-n}),Qn=(e,n=[0,0])=>{const{x:s,y:r}=Xs(e)?e.internals.positionAbsolute:Nr(e,n);return{x:s,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},os=(e,n=[0,0])=>{const{x:s,y:r}=Xs(e)?e.internals.positionAbsolute:Nr(e,n);return{x:s,y:r,x2:s+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},Ti=(e,n)=>hs(fs(zs(e),zs(n))),yr=(e,n)=>{const s=Math.max(0,Math.min(e.x+e.width,n.x+n.width)-Math.max(e.x,n.x)),r=Math.max(0,Math.min(e.y+e.height,n.y+n.height)-Math.max(e.y,n.y));return Math.ceil(s*r)},Xo=e=>Pt(e.width)&&Pt(e.height)&&Pt(e.x)&&Pt(e.y),Pt=e=>!isNaN(e)&&isFinite(e),ad=(e,n)=>{},Sr=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),Er=({x:e,y:n},[s,r,i],o=!1,a=[1,1])=>{const l={x:(e-s)/i,y:(n-r)/i};return o?Sr(l,a):l},as=({x:e,y:n},[s,r,i])=>({x:e*i+s,y:n*i+r});function Wn(e,n){if(typeof e=="number")return Math.floor((n-n/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const s=parseFloat(e);if(!Number.isNaN(s))return Math.floor(s)}if(typeof e=="string"&&e.endsWith("%")){const s=parseFloat(e);if(!Number.isNaN(s))return Math.floor(n*s*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function id(e,n,s){if(typeof e=="string"||typeof e=="number"){const r=Wn(e,s),i=Wn(e,n);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=Wn(e.top??e.y??0,s),i=Wn(e.bottom??e.y??0,s),o=Wn(e.left??e.x??0,n),a=Wn(e.right??e.x??0,n);return{top:r,right:a,bottom:i,left:o,x:o+a,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function ld(e,n,s,r,i,o){const{x:a,y:l}=as(e,[n,s,r]),{x:c,y:d}=as({x:e.x+e.width,y:e.y+e.height},[n,s,r]),f=i-c,h=o-d;return{left:Math.floor(a),top:Math.floor(l),right:Math.floor(f),bottom:Math.floor(h)}}const Js=(e,n,s,r,i,o)=>{const a=id(o,n,s),l=(n-a.x)/e.width,c=(s-a.y)/e.height,d=Math.min(l,c),f=Xn(d,r,i),h=e.x+e.width/2,m=e.y+e.height/2,u=n/2-h*f,g=s/2-m*f,C=ld(e,u,g,f,n,s),S={left:Math.min(C.left-a.left,0),top:Math.min(C.top-a.top,0),right:Math.min(C.right-a.right,0),bottom:Math.min(C.bottom-a.bottom,0)};return{x:u-S.left+S.right,y:g-S.top+S.bottom,zoom:f}},wr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Jn(e){return e!=null&&e!=="parent"}function en(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function Ri(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function _i(e,n={width:0,height:0},s,r,i){const o={...e},a=r.get(s);if(a){const l=a.origin||i;o.x+=a.internals.positionAbsolute.x-(n.width??0)*l[0],o.y+=a.internals.positionAbsolute.y-(n.height??0)*l[1]}return o}function Qo(e,n){if(e.size!==n.size)return!1;for(const s of e)if(!n.has(s))return!1;return!0}function cd(){let e,n;return{promise:new Promise((r,i)=>{e=r,n=i}),resolve:e,reject:n}}function dd(e){return{...ji,...e||{}}}function mr(e,{snapGrid:n=[0,0],snapToGrid:s=!1,transform:r,containerBounds:i}){const{x:o,y:a}=$t(e),l=Er({x:o-(i?.left??0),y:a-(i?.top??0)},r),{x:c,y:d}=s?Sr(l,n):l;return{xSnapped:c,ySnapped:d,...l}}const eo=e=>({width:e.offsetWidth,height:e.offsetHeight}),Li=e=>e?.getRootNode?.()||window?.document,ud=["INPUT","SELECT","TEXTAREA"];function Di(e){const n=e.composedPath?.()?.[0]||e.target;return n?.nodeType!==1?!1:ud.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const Ai=e=>"clientX"in e,$t=(e,n)=>{const s=Ai(e),r=s?e.clientX:e.touches?.[0].clientX,i=s?e.clientY:e.touches?.[0].clientY;return{x:r-(n?.left??0),y:i-(n?.top??0)}},Jo=(e,n,s,r,i)=>{const o=n.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const l=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:i,position:a.getAttribute("data-handlepos"),x:(l.left-s.left)/r,y:(l.top-s.top)/r,...eo(a)}})};function Pi({sourceX:e,sourceY:n,targetX:s,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:a,targetControlY:l}){const c=e*.125+i*.375+a*.375+s*.125,d=n*.125+o*.375+l*.375+r*.125,f=Math.abs(c-e),h=Math.abs(d-n);return[c,d,f,h]}function Gr(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function ea({pos:e,x1:n,y1:s,x2:r,y2:i,c:o}){switch(e){case ye.Left:return[n-Gr(n-r,o),s];case ye.Right:return[n+Gr(r-n,o),s];case ye.Top:return[n,s-Gr(s-i,o)];case ye.Bottom:return[n,s+Gr(i-s,o)]}}function $i({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top,curvature:a=.25}){const[l,c]=ea({pos:s,x1:e,y1:n,x2:r,y2:i,c:a}),[d,f]=ea({pos:o,x1:r,y1:i,x2:e,y2:n,c:a}),[h,m,u,g]=Pi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:l,sourceControlY:c,targetControlX:d,targetControlY:f});return[`M${e},${n} C${l},${c} ${d},${f} ${r},${i}`,h,m,u,g]}function Bi({sourceX:e,sourceY:n,targetX:s,targetY:r}){const i=Math.abs(s-e)/2,o=s<e?s+i:s-i,a=Math.abs(r-n)/2,l=r<n?r+a:r-a;return[o,l,i,a]}function fd({sourceNode:e,targetNode:n,selected:s=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const a=i&&s?r+1e3:r,l=Math.max(e.parentId||i&&e.selected?e.internals.z:0,n.parentId||i&&n.selected?n.internals.z:0);return a+l}function hd({sourceNode:e,targetNode:n,width:s,height:r,transform:i}){const o=fs(os(e),os(n));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const a={x:-i[0]/i[2],y:-i[1]/i[2],width:s/i[2],height:r/i[2]};return yr(a,hs(o))>0}const md=({source:e,sourceHandle:n,target:s,targetHandle:r})=>`xy-edge__${e}${n||""}-${s}${r||""}`,pd=(e,n)=>n.some(s=>s.source===e.source&&s.target===e.target&&(s.sourceHandle===e.sourceHandle||!s.sourceHandle&&!e.sourceHandle)&&(s.targetHandle===e.targetHandle||!s.targetHandle&&!e.targetHandle)),gd=(e,n,s={})=>{if(!e.source||!e.target)return n;const r=s.getEdgeId||md;let i;return Si(e)?i={...e}:i={...e,id:r(e)},pd(i,n)?n:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,n.concat(i))};function Oi({sourceX:e,sourceY:n,targetX:s,targetY:r}){const[i,o,a,l]=Bi({sourceX:e,sourceY:n,targetX:s,targetY:r});return[`M ${e},${n}L ${s},${r}`,i,o,a,l]}const ta={[ye.Left]:{x:-1,y:0},[ye.Right]:{x:1,y:0},[ye.Top]:{x:0,y:-1},[ye.Bottom]:{x:0,y:1}},xd=({source:e,sourcePosition:n=ye.Bottom,target:s})=>n===ye.Left||n===ye.Right?e.x<s.x?{x:1,y:0}:{x:-1,y:0}:e.y<s.y?{x:0,y:1}:{x:0,y:-1},na=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function bd({source:e,sourcePosition:n=ye.Bottom,target:s,targetPosition:r=ye.Top,center:i,offset:o,stepPosition:a}){const l=ta[n],c=ta[r],d={x:e.x+l.x*o,y:e.y+l.y*o},f={x:s.x+c.x*o,y:s.y+c.y*o},h=xd({source:d,sourcePosition:n,target:f}),m=h.x!==0?"x":"y",u=h[m];let g=[],C,S;const v={x:0,y:0},y={x:0,y:0},[,,x,b]=Bi({sourceX:e.x,sourceY:e.y,targetX:s.x,targetY:s.y});if(l[m]*c[m]===-1){m==="x"?(C=i.x??d.x+(f.x-d.x)*a,S=i.y??(d.y+f.y)/2):(C=i.x??(d.x+f.x)/2,S=i.y??d.y+(f.y-d.y)*a);const k=[{x:C,y:d.y},{x:C,y:f.y}],M=[{x:d.x,y:S},{x:f.x,y:S}];l[m]===u?g=m==="x"?k:M:g=m==="x"?M:k}else{const k=[{x:d.x,y:f.y}],M=[{x:f.x,y:d.y}];if(m==="x"?g=l.x===u?M:k:g=l.y===u?k:M,n===r){const P=Math.abs(e[m]-s[m]);if(P<=o){const q=Math.min(o-1,o-P);l[m]===u?v[m]=(d[m]>e[m]?-1:1)*q:y[m]=(f[m]>s[m]?-1:1)*q}}if(n!==r){const P=m==="x"?"y":"x",q=l[m]===c[P],N=d[P]>f[P],O=d[P]<f[P];(l[m]===1&&(!q&&N||q&&O)||l[m]!==1&&(!q&&O||q&&N))&&(g=m==="x"?k:M)}const T={x:d.x+v.x,y:d.y+v.y},A={x:f.x+y.x,y:f.y+y.y},D=Math.max(Math.abs(T.x-g[0].x),Math.abs(A.x-g[0].x)),E=Math.max(Math.abs(T.y-g[0].y),Math.abs(A.y-g[0].y));D>=E?(C=(T.x+A.x)/2,S=g[0].y):(C=g[0].x,S=(T.y+A.y)/2)}return[[e,{x:d.x+v.x,y:d.y+v.y},...g,{x:f.x+y.x,y:f.y+y.y},s],C,S,x,b]}function yd(e,n,s,r){const i=Math.min(na(e,n)/2,na(n,s)/2,r),{x:o,y:a}=n;if(e.x===o&&o===s.x||e.y===a&&a===s.y)return`L${o} ${a}`;if(e.y===a){const d=e.x<s.x?-1:1,f=e.y<s.y?1:-1;return`L ${o+i*d},${a}Q ${o},${a} ${o},${a+i*f}`}const l=e.x<s.x?1:-1,c=e.y<s.y?-1:1;return`L ${o},${a+i*c}Q ${o},${a} ${o+i*l},${a}`}function Hs({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top,borderRadius:a=5,centerX:l,centerY:c,offset:d=20,stepPosition:f=.5}){const[h,m,u,g,C]=bd({source:{x:e,y:n},sourcePosition:s,target:{x:r,y:i},targetPosition:o,center:{x:l,y:c},offset:d,stepPosition:f});return[h.reduce((v,y,x)=>{let b="";return x>0&&x<h.length-1?b=yd(h[x-1],y,h[x+1],a):b=`${x===0?"M":"L"}${y.x} ${y.y}`,v+=b,v},""),m,u,g,C]}function ra(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function wd(e){const{sourceNode:n,targetNode:s}=e;if(!ra(n)||!ra(s))return null;const r=n.internals.handleBounds||sa(n.handles),i=s.internals.handleBounds||sa(s.handles),o=oa(r?.source??[],e.sourceHandle),a=oa(e.connectionMode===Un.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!a)return e.onError?.("008",Vt.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=o?.position||ye.Bottom,c=a?.position||ye.Top,d=Tn(n,o,l),f=Tn(s,a,c);return{sourceX:d.x,sourceY:d.y,targetX:f.x,targetY:f.y,sourcePosition:l,targetPosition:c}}function sa(e){if(!e)return null;const n=[],s=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?n.push(r):r.type==="target"&&s.push(r);return{source:n,target:s}}function Tn(e,n,s=ye.Left,r=!1){const i=(n?.x??0)+e.internals.positionAbsolute.x,o=(n?.y??0)+e.internals.positionAbsolute.y,{width:a,height:l}=n??en(e);if(r)return{x:i+a/2,y:o+l/2};switch(n?.position??s){case ye.Top:return{x:i+a/2,y:o};case ye.Right:return{x:i+a,y:o+l/2};case ye.Bottom:return{x:i+a/2,y:o+l};case ye.Left:return{x:i,y:o+l/2}}}function oa(e,n){return e&&(n?e.find(s=>s.id===n):e[0])||null}function qs(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function vd(e,{id:n,defaultColor:s,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((a,l)=>([l.markerStart||r,l.markerEnd||i].forEach(c=>{if(c&&typeof c=="object"){const d=qs(c,n);o.has(d)||(a.push({id:d,color:c.color||s,...c}),o.add(d))}}),a),[]).sort((a,l)=>a.id.localeCompare(l.id))}const zi=1e3,kd=10,to={nodeOrigin:[0,0],nodeExtent:xr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},jd={...to,checkEquality:!0};function no(e,n){const s={...e};for(const r in n)n[r]!==void 0&&(s[r]=n[r]);return s}function Nd(e,n,s){const r=no(to,s);for(const i of e.values())if(i.parentId)so(i,e,n,r);else{const o=Nr(i,r.nodeOrigin),a=Jn(i.extent)?i.extent:r.nodeExtent,l=In(o,a,en(i));i.internals.positionAbsolute=l}}function Cd(e,n){if(!e.handles)return e.measured?n?.internals.handleBounds:void 0;const s=[],r=[];for(const i of e.handles){const o={id:i.id,width:i.width??1,height:i.height??1,nodeId:e.id,x:i.x,y:i.y,position:i.position,type:i.type};i.type==="source"?s.push(o):i.type==="target"&&r.push(o)}return{source:s,target:r}}function ro(e){return e==="manual"}function Ws(e,n,s,r={}){const i=no(jd,r),o={i:0},a=new Map(n),l=i?.elevateNodesOnSelect&&!ro(i.zIndexMode)?zi:0;let c=e.length>0;n.clear(),s.clear();for(const d of e){let f=a.get(d.id);if(i.checkEquality&&d===f?.internals.userNode)n.set(d.id,f);else{const h=Nr(d,i.nodeOrigin),m=Jn(d.extent)?d.extent:i.nodeExtent,u=In(h,m,en(d));f={...i.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:u,handleBounds:Cd(d,f),z:Hi(d,l,i.zIndexMode),userNode:d}},n.set(d.id,f)}(f.measured===void 0||f.measured.width===void 0||f.measured.height===void 0)&&!f.hidden&&(c=!1),d.parentId&&so(f,n,s,r,o)}return c}function Sd(e,n){if(!e.parentId)return;const s=n.get(e.parentId);s?s.set(e.id,e):n.set(e.parentId,new Map([[e.id,e]]))}function so(e,n,s,r,i){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:l,zIndexMode:c}=no(to,r),d=e.parentId,f=n.get(d);if(!f){console.warn(`Parent node ${d} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Sd(e,s),i&&!f.parentId&&f.internals.rootParentIndex===void 0&&c==="auto"&&(f.internals.rootParentIndex=++i.i,f.internals.z=f.internals.z+i.i*kd),i&&f.internals.rootParentIndex!==void 0&&(i.i=f.internals.rootParentIndex);const h=o&&!ro(c)?zi:0,{x:m,y:u,z:g}=Ed(e,f,a,l,h,c),{positionAbsolute:C}=e.internals,S=m!==C.x||u!==C.y;(S||g!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:S?{x:m,y:u}:C,z:g}})}function Hi(e,n,s){const r=Pt(e.zIndex)?e.zIndex:0;return ro(s)?r:r+(e.selected?n:0)}function Ed(e,n,s,r,i,o){const{x:a,y:l}=n.internals.positionAbsolute,c=en(e),d=Nr(e,s),f=Jn(e.extent)?In(d,e.extent,c):d;let h=In({x:a+f.x,y:l+f.y},r,c);e.extent==="parent"&&(h=Mi(h,c,n));const m=Hi(e,i,o),u=n.internals.z??0;return{x:h.x,y:h.y,z:u>=m?u+1:m}}function oo(e,n,s,r=[0,0]){const i=[],o=new Map;for(const a of e){const l=n.get(a.parentId);if(!l)continue;const c=o.get(a.parentId)?.expandedRect??Qn(l),d=Ti(c,a.rect);o.set(a.parentId,{expandedRect:d,parent:l})}return o.size>0&&o.forEach(({expandedRect:a,parent:l},c)=>{const d=l.internals.positionAbsolute,f=en(l),h=l.origin??r,m=a.x<d.x?Math.round(Math.abs(d.x-a.x)):0,u=a.y<d.y?Math.round(Math.abs(d.y-a.y)):0,g=Math.max(f.width,Math.round(a.width)),C=Math.max(f.height,Math.round(a.height)),S=(g-f.width)*h[0],v=(C-f.height)*h[1];(m>0||u>0||S||v)&&(i.push({id:c,type:"position",position:{x:l.position.x-m+S,y:l.position.y-u+v}}),s.get(c)?.forEach(y=>{e.some(x=>x.id===y.id)||i.push({id:y.id,type:"position",position:{x:y.position.x+m,y:y.position.y+u}})})),(f.width<a.width||f.height<a.height||m||u)&&i.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(m?h[0]*m-S:0),height:C+(u?h[1]*u-v:0)}})}),i}function Md(e,n,s,r,i,o,a){const l=r?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const d=[],f=window.getComputedStyle(l),{m22:h}=new window.DOMMatrixReadOnly(f.transform),m=[];for(const u of e.values()){const g=n.get(u.id);if(!g)continue;if(g.hidden){n.set(g.id,{...g,internals:{...g.internals,handleBounds:void 0}}),c=!0;continue}const C=eo(u.nodeElement),S=g.measured.width!==C.width||g.measured.height!==C.height;if(!!(C.width&&C.height&&(S||!g.internals.handleBounds||u.force))){const y=u.nodeElement.getBoundingClientRect(),x=Jn(g.extent)?g.extent:o;let{positionAbsolute:b}=g.internals;g.parentId&&g.extent==="parent"?b=Mi(b,C,n.get(g.parentId)):x&&(b=In(b,x,C));const j={...g,measured:C,internals:{...g.internals,positionAbsolute:b,handleBounds:{source:Jo("source",u.nodeElement,y,h,g.id),target:Jo("target",u.nodeElement,y,h,g.id)}}};n.set(g.id,j),g.parentId&&so(j,n,s,{nodeOrigin:i,zIndexMode:a}),c=!0,S&&(d.push({id:g.id,type:"dimensions",dimensions:C}),g.expandParent&&g.parentId&&m.push({id:g.id,parentId:g.parentId,rect:Qn(j,i)}))}}if(m.length>0){const u=oo(m,n,s,i);d.push(...u)}return{changes:d,updatedInternals:c}}async function Id({delta:e,panZoom:n,transform:s,translateExtent:r,width:i,height:o}){if(!n||!e.x&&!e.y)return Promise.resolve(!1);const a=await n.setViewportConstrained({x:s[0]+e.x,y:s[1]+e.y,zoom:s[2]},[[0,0],[i,o]],r),l=!!a&&(a.x!==s[0]||a.y!==s[1]||a.k!==s[2]);return Promise.resolve(l)}function aa(e,n,s,r,i,o){let a=i;const l=r.get(a)||new Map;r.set(a,l.set(s,n)),a=`${i}-${e}`;const c=r.get(a)||new Map;if(r.set(a,c.set(s,n)),o){a=`${i}-${e}-${o}`;const d=r.get(a)||new Map;r.set(a,d.set(s,n))}}function qi(e,n,s){e.clear(),n.clear();for(const r of s){const{source:i,target:o,sourceHandle:a=null,targetHandle:l=null}=r,c={edgeId:r.id,source:i,target:o,sourceHandle:a,targetHandle:l},d=`${i}-${a}--${o}-${l}`,f=`${o}-${l}--${i}-${a}`;aa("source",c,f,e,i,a),aa("target",c,d,e,o,l),n.set(r.id,r)}}function Wi(e,n){if(!e.parentId)return!1;const s=n.get(e.parentId);return s?s.selected?!0:Wi(s,n):!1}function ia(e,n,s){let r=e;do{if(r?.matches?.(n))return!0;if(r===s)return!1;r=r?.parentElement}while(r);return!1}function Td(e,n,s,r){const i=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!Wi(a,e))&&(a.draggable||n&&typeof a.draggable>"u")){const l=e.get(o);l&&i.set(o,{id:o,position:l.position||{x:0,y:0},distance:{x:s.x-l.internals.positionAbsolute.x,y:s.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return i}function Is({nodeId:e,dragItems:n,nodeLookup:s,dragging:r=!0}){const i=[];for(const[a,l]of n){const c=s.get(a)?.internals.userNode;c&&i.push({...c,position:l.position,dragging:r})}if(!e)return[i[0],i];const o=s.get(e)?.internals.userNode;return[o?{...o,position:n.get(e)?.position||o.position,dragging:r}:i[0],i]}function Rd({dragItems:e,snapGrid:n,x:s,y:r}){const i=e.values().next().value;if(!i)return null;const o={x:s-i.distance.x,y:r-i.distance.y},a=Sr(o,n);return{x:a.x-o.x,y:a.y-o.y}}function _d({onNodeMouseDown:e,getStoreItems:n,onDragStart:s,onDrag:r,onDragStop:i}){let o={x:null,y:null},a=0,l=new Map,c=!1,d={x:0,y:0},f=null,h=!1,m=null,u=!1,g=!1,C=null;function S({noDragClassName:y,handleSelector:x,domNode:b,isSelectable:j,nodeId:k,nodeClickDistance:M=0}){m=Mt(b);function T({x:P,y:q}){const{nodeLookup:N,nodeExtent:O,snapGrid:_,snapToGrid:z,nodeOrigin:L,onNodeDrag:R,onSelectionDrag:$,onError:W,updateNodePositions:F}=n();o={x:P,y:q};let X=!1;const B=l.size>1,I=B&&O?zs(Cr(l)):null,Y=B&&z?Rd({dragItems:l,snapGrid:_,x:P,y:q}):null;for(const[V,H]of l){if(!N.has(V))continue;let Z={x:P-H.distance.x,y:q-H.distance.y};z&&(Z=Y?{x:Math.round(Z.x+Y.x),y:Math.round(Z.y+Y.y)}:Sr(Z,_));let te=null;if(B&&O&&!H.extent&&I){const{positionAbsolute:Q}=H.internals,le=Q.x-I.x+O[0][0],de=Q.x+H.measured.width-I.x2+O[1][0],fe=Q.y-I.y+O[0][1],xe=Q.y+H.measured.height-I.y2+O[1][1];te=[[le,fe],[de,xe]]}const{position:oe,positionAbsolute:ue}=Ei({nodeId:V,nextPosition:Z,nodeLookup:N,nodeExtent:te||O,nodeOrigin:L,onError:W});X=X||H.position.x!==oe.x||H.position.y!==oe.y,H.position=oe,H.internals.positionAbsolute=ue}if(g=g||X,!!X&&(F(l,!0),C&&(r||R||!k&&$))){const[V,H]=Is({nodeId:k,dragItems:l,nodeLookup:N});r?.(C,l,V,H),R?.(C,V,H),k||$?.(C,H)}}async function A(){if(!f)return;const{transform:P,panBy:q,autoPanSpeed:N,autoPanOnNodeDrag:O}=n();if(!O){c=!1,cancelAnimationFrame(a);return}const[_,z]=Ii(d,f,N);(_!==0||z!==0)&&(o.x=(o.x??0)-_/P[2],o.y=(o.y??0)-z/P[2],await q({x:_,y:z})&&T(o)),a=requestAnimationFrame(A)}function D(P){const{nodeLookup:q,multiSelectionActive:N,nodesDraggable:O,transform:_,snapGrid:z,snapToGrid:L,selectNodesOnDrag:R,onNodeDragStart:$,onSelectionDragStart:W,unselectNodesAndEdges:F}=n();h=!0,(!R||!j)&&!N&&k&&(q.get(k)?.selected||F()),j&&R&&k&&e?.(k);const X=mr(P.sourceEvent,{transform:_,snapGrid:z,snapToGrid:L,containerBounds:f});if(o=X,l=Td(q,O,X,k),l.size>0&&(s||$||!k&&W)){const[B,I]=Is({nodeId:k,dragItems:l,nodeLookup:q});s?.(P.sourceEvent,l,B,I),$?.(P.sourceEvent,B,I),k||W?.(P.sourceEvent,I)}}const E=xi().clickDistance(M).on("start",P=>{const{domNode:q,nodeDragThreshold:N,transform:O,snapGrid:_,snapToGrid:z}=n();f=q?.getBoundingClientRect()||null,u=!1,g=!1,C=P.sourceEvent,N===0&&D(P),o=mr(P.sourceEvent,{transform:O,snapGrid:_,snapToGrid:z,containerBounds:f}),d=$t(P.sourceEvent,f)}).on("drag",P=>{const{autoPanOnNodeDrag:q,transform:N,snapGrid:O,snapToGrid:_,nodeDragThreshold:z,nodeLookup:L}=n(),R=mr(P.sourceEvent,{transform:N,snapGrid:O,snapToGrid:_,containerBounds:f});if(C=P.sourceEvent,(P.sourceEvent.type==="touchmove"&&P.sourceEvent.touches.length>1||k&&!L.has(k))&&(u=!0),!u){if(!c&&q&&h&&(c=!0,A()),!h){const $=$t(P.sourceEvent,f),W=$.x-d.x,F=$.y-d.y;Math.sqrt(W*W+F*F)>z&&D(P)}(o.x!==R.xSnapped||o.y!==R.ySnapped)&&l&&h&&(d=$t(P.sourceEvent,f),T(R))}}).on("end",P=>{if(!(!h||u)&&(c=!1,h=!1,cancelAnimationFrame(a),l.size>0)){const{nodeLookup:q,updateNodePositions:N,onNodeDragStop:O,onSelectionDragStop:_}=n();if(g&&(N(l,!1),g=!1),i||O||!k&&_){const[z,L]=Is({nodeId:k,dragItems:l,nodeLookup:q,dragging:!1});i?.(P.sourceEvent,l,z,L),O?.(P.sourceEvent,z,L),k||_?.(P.sourceEvent,L)}}}).filter(P=>{const q=P.target;return!P.button&&(!y||!ia(q,`.${y}`,b))&&(!x||ia(q,x,b))});m.call(E)}function v(){m?.on(".drag",null)}return{update:S,destroy:v}}function Ld(e,n,s){const r=[],i={x:e.x-s,y:e.y-s,width:s*2,height:s*2};for(const o of n.values())yr(i,Qn(o))>0&&r.push(o);return r}const Dd=250;function Ad(e,n,s,r){let i=[],o=1/0;const a=Ld(e,s,n+Dd);for(const l of a){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const d of c){if(r.nodeId===d.nodeId&&r.type===d.type&&r.id===d.id)continue;const{x:f,y:h}=Tn(l,d,d.position,!0),m=Math.sqrt(Math.pow(f-e.x,2)+Math.pow(h-e.y,2));m>n||(m<o?(i=[{...d,x:f,y:h}],o=m):m===o&&i.push({...d,x:f,y:h}))}}if(!i.length)return null;if(i.length>1){const l=r.type==="source"?"target":"source";return i.find(c=>c.type===l)??i[0]}return i[0]}function Fi(e,n,s,r,i,o=!1){const a=r.get(e);if(!a)return null;const l=i==="strict"?a.internals.handleBounds?.[n]:[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]],c=(s?l?.find(d=>d.id===s):l?.[0])??null;return c&&o?{...c,...Tn(a,c,c.position,!0)}:c}function Vi(e,n){return e||(n?.classList.contains("target")?"target":n?.classList.contains("source")?"source":null)}function Pd(e,n){let s=null;return n?s=!0:e&&!n&&(s=!1),s}const Yi=()=>!0;function $d(e,{connectionMode:n,connectionRadius:s,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:a,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:f,flowId:h,panBy:m,cancelConnection:u,onConnectStart:g,onConnect:C,onConnectEnd:S,isValidConnection:v=Yi,onReconnectEnd:y,updateConnection:x,getTransform:b,getFromHandle:j,autoPanSpeed:k,dragThreshold:M=1,handleDomNode:T}){const A=Li(e.target);let D=0,E;const{x:P,y:q}=$t(e),N=Vi(o,T),O=l?.getBoundingClientRect();let _=!1;if(!O||!N)return;const z=Fi(i,N,r,c,n);if(!z)return;let L=$t(e,O),R=!1,$=null,W=!1,F=null;function X(){if(!f||!O)return;const[oe,ue]=Ii(L,O,k);m({x:oe,y:ue}),D=requestAnimationFrame(X)}const B={...z,nodeId:i,type:N,position:z.position},I=c.get(i);let V={inProgress:!0,isValid:null,from:Tn(I,B,ye.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:I,to:L,toHandle:null,toPosition:Uo[B.position],toNode:null,pointer:L};function H(){_=!0,x(V),g?.(e,{nodeId:i,handleId:r,handleType:N})}M===0&&H();function Z(oe){if(!_){const{x:xe,y:be}=$t(oe),U=xe-P,ce=be-q;if(!(U*U+ce*ce>M*M))return;H()}if(!j()||!B){te(oe);return}const ue=b();L=$t(oe,O),E=Ad(Er(L,ue,!1,[1,1]),s,c,B),R||(X(),R=!0);const Q=Gi(oe,{handle:E,connectionMode:n,fromNodeId:i,fromHandleId:r,fromType:a?"target":"source",isValidConnection:v,doc:A,lib:d,flowId:h,nodeLookup:c});F=Q.handleDomNode,$=Q.connection,W=Pd(!!E,Q.isValid);const le=c.get(i),de=le?Tn(le,B,ye.Left,!0):V.from,fe={...V,from:de,isValid:W,to:Q.toHandle&&W?as({x:Q.toHandle.x,y:Q.toHandle.y},ue):L,toHandle:Q.toHandle,toPosition:W&&Q.toHandle?Q.toHandle.position:Uo[B.position],toNode:Q.toHandle?c.get(Q.toHandle.nodeId):null,pointer:L};x(fe),V=fe}function te(oe){if(!("touches"in oe&&oe.touches.length>0)){if(_){(E||F)&&$&&W&&C?.($);const{inProgress:ue,...Q}=V,le={...Q,toPosition:V.toHandle?V.toPosition:null};S?.(oe,le),o&&y?.(oe,le)}u(),cancelAnimationFrame(D),R=!1,W=!1,$=null,F=null,A.removeEventListener("mousemove",Z),A.removeEventListener("mouseup",te),A.removeEventListener("touchmove",Z),A.removeEventListener("touchend",te)}}A.addEventListener("mousemove",Z),A.addEventListener("mouseup",te),A.addEventListener("touchmove",Z),A.addEventListener("touchend",te)}function Gi(e,{handle:n,connectionMode:s,fromNodeId:r,fromHandleId:i,fromType:o,doc:a,lib:l,flowId:c,isValidConnection:d=Yi,nodeLookup:f}){const h=o==="target",m=n?a.querySelector(`.${l}-flow__handle[data-id="${c}-${n?.nodeId}-${n?.id}-${n?.type}"]`):null,{x:u,y:g}=$t(e),C=a.elementFromPoint(u,g),S=C?.classList.contains(`${l}-flow__handle`)?C:m,v={handleDomNode:S,isValid:!1,connection:null,toHandle:null};if(S){const y=Vi(void 0,S),x=S.getAttribute("data-nodeid"),b=S.getAttribute("data-handleid"),j=S.classList.contains("connectable"),k=S.classList.contains("connectableend");if(!x||!y)return v;const M={source:h?x:r,sourceHandle:h?b:i,target:h?r:x,targetHandle:h?i:b};v.connection=M;const A=j&&k&&(s===Un.Strict?h&&y==="source"||!h&&y==="target":x!==r||b!==i);v.isValid=A&&d(M),v.toHandle=Fi(x,y,b,f,s,!0)}return v}const Fs={onPointerDown:$d,isValid:Gi};function Bd({domNode:e,panZoom:n,getTransform:s,getViewScale:r}){const i=Mt(e);function o({translateExtent:l,width:c,height:d,zoomStep:f=1,pannable:h=!0,zoomable:m=!0,inversePan:u=!1}){const g=x=>{if(x.sourceEvent.type!=="wheel"||!n)return;const b=s(),j=x.sourceEvent.ctrlKey&&wr()?10:1,k=-x.sourceEvent.deltaY*(x.sourceEvent.deltaMode===1?.05:x.sourceEvent.deltaMode?1:.002)*f,M=b[2]*Math.pow(2,k*j);n.scaleTo(M)};let C=[0,0];const S=x=>{(x.sourceEvent.type==="mousedown"||x.sourceEvent.type==="touchstart")&&(C=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY])},v=x=>{const b=s();if(x.sourceEvent.type!=="mousemove"&&x.sourceEvent.type!=="touchmove"||!n)return;const j=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY],k=[j[0]-C[0],j[1]-C[1]];C=j;const M=r()*Math.max(b[2],Math.log(b[2]))*(u?-1:1),T={x:b[0]-k[0]*M,y:b[1]-k[1]*M},A=[[0,0],[c,d]];n.setViewportConstrained({x:T.x,y:T.y,zoom:b[2]},A,l)},y=bi().on("start",S).on("zoom",h?v:null).on("zoom.wheel",m?g:null);i.call(y,{})}function a(){i.on("zoom",null)}return{update:o,destroy:a,pointer:At}}const ms=e=>({x:e.x,y:e.y,zoom:e.k}),Ts=({x:e,y:n,zoom:s})=>Zs.translate(e,n).scale(s),Vn=(e,n)=>e.target.closest(`.${n}`),Ki=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),Od=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Rs=(e,n=0,s=Od,r=()=>{})=>{const i=typeof n=="number"&&n>0;return i||r(),i?e.transition().duration(n).ease(s).on("end",r):e},Ui=e=>{const n=e.ctrlKey&&wr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function zd({zoomPanValues:e,noWheelClassName:n,d3Selection:s,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return f=>{if(Vn(f,n))return f.ctrlKey&&f.preventDefault(),!1;f.preventDefault(),f.stopImmediatePropagation();const h=s.property("__zoom").k||1;if(f.ctrlKey&&a){const S=At(f),v=Ui(f),y=h*Math.pow(2,v);r.scaleTo(s,y,S,f);return}const m=f.deltaMode===1?20:1;let u=i===Mn.Vertical?0:f.deltaX*m,g=i===Mn.Horizontal?0:f.deltaY*m;!wr()&&f.shiftKey&&i!==Mn.Vertical&&(u=f.deltaY*m,g=0),r.translateBy(s,-(u/h)*o,-(g/h)*o,{internal:!0});const C=ms(s.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(f,C),e.panScrollTimeout=setTimeout(()=>{d?.(f,C),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(f,C))}}function Hd({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:s}){return function(r,i){const o=r.type==="wheel",a=!n&&o&&!r.ctrlKey,l=Vn(r,e);if(r.ctrlKey&&o&&l&&r.preventDefault(),a||l)return null;r.preventDefault(),s.call(this,r,i)}}function qd({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:s}){return r=>{if(r.sourceEvent?.internal)return;const i=ms(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type==="mousedown"&&n(!0),s&&s?.(r.sourceEvent,i)}}function Wd({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:s,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(s&&Ki(n,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,ms(o.transform))}}function Fd({zoomPanValues:e,panOnDrag:n,panOnScroll:s,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return a=>{if(!a.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&Ki(n,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const l=ms(a.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(a.sourceEvent,l)},s?150:0)}}}function Vd({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:s,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:a,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:f}){return h=>{const m=e||n,u=s&&h.ctrlKey,g=h.type==="wheel";if(h.button===1&&h.type==="mousedown"&&(Vn(h,`${d}-flow__node`)||Vn(h,`${d}-flow__edge`)))return!0;if(!r&&!m&&!i&&!o&&!s||a||f&&!g||Vn(h,l)&&g||Vn(h,c)&&(!g||i&&g&&!e)||!s&&h.ctrlKey&&g)return!1;if(!s&&h.type==="touchstart"&&h.touches?.length>1)return h.preventDefault(),!1;if(!m&&!i&&!u&&g||!r&&(h.type==="mousedown"||h.type==="touchstart")||Array.isArray(r)&&!r.includes(h.button)&&h.type==="mousedown")return!1;const C=Array.isArray(r)&&r.includes(h.button)||!h.button||h.button<=1;return(!h.ctrlKey||g)&&C}}function Yd({domNode:e,minZoom:n,maxZoom:s,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:l,onDraggingChange:c}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},f=e.getBoundingClientRect(),h=bi().scaleExtent([n,s]).translateExtent(r),m=Mt(e).call(h);y({x:i.x,y:i.y,zoom:Xn(i.zoom,n,s)},[[0,0],[f.width,f.height]],r);const u=m.on("wheel.zoom"),g=m.on("dblclick.zoom");h.wheelDelta(Ui);function C(E,P){return m?new Promise(q=>{h?.interpolate(P?.interpolate==="linear"?Ss:ts).transform(Rs(m,P?.duration,P?.ease,()=>q(!0)),E)}):Promise.resolve(!1)}function S({noWheelClassName:E,noPanClassName:P,onPaneContextMenu:q,userSelectionActive:N,panOnScroll:O,panOnDrag:_,panOnScrollMode:z,panOnScrollSpeed:L,preventScrolling:R,zoomOnPinch:$,zoomOnScroll:W,zoomOnDoubleClick:F,zoomActivationKeyPressed:X,lib:B,onTransformChange:I,connectionInProgress:Y,paneClickDistance:V,selectionOnDrag:H}){N&&!d.isZoomingOrPanning&&v();const Z=O&&!X&&!N;h.clickDistance(H?1/0:!Pt(V)||V<0?0:V);const te=Z?zd({zoomPanValues:d,noWheelClassName:E,d3Selection:m,d3Zoom:h,panOnScrollMode:z,panOnScrollSpeed:L,zoomOnPinch:$,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:l}):Hd({noWheelClassName:E,preventScrolling:R,d3ZoomHandler:u});if(m.on("wheel.zoom",te,{passive:!1}),!N){const ue=qd({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:a});h.on("start",ue);const Q=Wd({zoomPanValues:d,panOnDrag:_,onPaneContextMenu:!!q,onPanZoom:o,onTransformChange:I});h.on("zoom",Q);const le=Fd({zoomPanValues:d,panOnDrag:_,panOnScroll:O,onPaneContextMenu:q,onPanZoomEnd:l,onDraggingChange:c});h.on("end",le)}const oe=Vd({zoomActivationKeyPressed:X,panOnDrag:_,zoomOnScroll:W,panOnScroll:O,zoomOnDoubleClick:F,zoomOnPinch:$,userSelectionActive:N,noPanClassName:P,noWheelClassName:E,lib:B,connectionInProgress:Y});h.filter(oe),F?m.on("dblclick.zoom",g):m.on("dblclick.zoom",null)}function v(){h.on("zoom",null)}async function y(E,P,q){const N=Ts(E),O=h?.constrain()(N,P,q);return O&&await C(O),new Promise(_=>_(O))}async function x(E,P){const q=Ts(E);return await C(q,P),new Promise(N=>N(q))}function b(E){if(m){const P=Ts(E),q=m.property("__zoom");(q.k!==E.zoom||q.x!==E.x||q.y!==E.y)&&h?.transform(m,P,null,{sync:!0})}}function j(){const E=m?Ic(m.node()):{x:0,y:0,k:1};return{x:E.x,y:E.y,zoom:E.k}}function k(E,P){return m?new Promise(q=>{h?.interpolate(P?.interpolate==="linear"?Ss:ts).scaleTo(Rs(m,P?.duration,P?.ease,()=>q(!0)),E)}):Promise.resolve(!1)}function M(E,P){return m?new Promise(q=>{h?.interpolate(P?.interpolate==="linear"?Ss:ts).scaleBy(Rs(m,P?.duration,P?.ease,()=>q(!0)),E)}):Promise.resolve(!1)}function T(E){h?.scaleExtent(E)}function A(E){h?.translateExtent(E)}function D(E){const P=!Pt(E)||E<0?0:E;h?.clickDistance(P)}return{update:S,destroy:v,setViewport:x,setViewportConstrained:y,getViewport:j,scaleTo:k,scaleBy:M,setScaleExtent:T,setTranslateExtent:A,syncViewport:b,setClickDistance:D}}var er;(function(e){e.Line="line",e.Handle="handle"})(er||(er={}));function Gd({width:e,prevWidth:n,height:s,prevHeight:r,affectsX:i,affectsY:o}){const a=e-n,l=s-r,c=[a>0?1:a<0?-1:0,l>0?1:l<0?-1:0];return a&&i&&(c[0]=c[0]*-1),l&&o&&(c[1]=c[1]*-1),c}function la(e){const n=e.includes("right")||e.includes("left"),s=e.includes("bottom")||e.includes("top"),r=e.includes("left"),i=e.includes("top");return{isHorizontal:n,isVertical:s,affectsX:r,affectsY:i}}function ln(e,n){return Math.max(0,n-e)}function cn(e,n){return Math.max(0,e-n)}function Kr(e,n,s){return Math.max(0,n-e,e-s)}function ca(e,n){return e?!n:n}function Kd(e,n,s,r,i,o,a,l){let{affectsX:c,affectsY:d}=n;const{isHorizontal:f,isVertical:h}=n,m=f&&h,{xSnapped:u,ySnapped:g}=s,{minWidth:C,maxWidth:S,minHeight:v,maxHeight:y}=r,{x,y:b,width:j,height:k,aspectRatio:M}=e;let T=Math.floor(f?u-e.pointerX:0),A=Math.floor(h?g-e.pointerY:0);const D=j+(c?-T:T),E=k+(d?-A:A),P=-o[0]*j,q=-o[1]*k;let N=Kr(D,C,S),O=Kr(E,v,y);if(a){let L=0,R=0;c&&T<0?L=ln(x+T+P,a[0][0]):!c&&T>0&&(L=cn(x+D+P,a[1][0])),d&&A<0?R=ln(b+A+q,a[0][1]):!d&&A>0&&(R=cn(b+E+q,a[1][1])),N=Math.max(N,L),O=Math.max(O,R)}if(l){let L=0,R=0;c&&T>0?L=cn(x+T,l[0][0]):!c&&T<0&&(L=ln(x+D,l[1][0])),d&&A>0?R=cn(b+A,l[0][1]):!d&&A<0&&(R=ln(b+E,l[1][1])),N=Math.max(N,L),O=Math.max(O,R)}if(i){if(f){const L=Kr(D/M,v,y)*M;if(N=Math.max(N,L),a){let R=0;!c&&!d||c&&!d&&m?R=cn(b+q+D/M,a[1][1])*M:R=ln(b+q+(c?T:-T)/M,a[0][1])*M,N=Math.max(N,R)}if(l){let R=0;!c&&!d||c&&!d&&m?R=ln(b+D/M,l[1][1])*M:R=cn(b+(c?T:-T)/M,l[0][1])*M,N=Math.max(N,R)}}if(h){const L=Kr(E*M,C,S)/M;if(O=Math.max(O,L),a){let R=0;!c&&!d||d&&!c&&m?R=cn(x+E*M+P,a[1][0])/M:R=ln(x+(d?A:-A)*M+P,a[0][0])/M,O=Math.max(O,R)}if(l){let R=0;!c&&!d||d&&!c&&m?R=ln(x+E*M,l[1][0])/M:R=cn(x+(d?A:-A)*M,l[0][0])/M,O=Math.max(O,R)}}}A=A+(A<0?O:-O),T=T+(T<0?N:-N),i&&(m?D>E*M?A=(ca(c,d)?-T:T)/M:T=(ca(c,d)?-A:A)*M:f?(A=T/M,d=c):(T=A*M,c=d));const _=c?x+T:x,z=d?b+A:b;return{width:j+(c?-T:T),height:k+(d?-A:A),x:o[0]*T*(c?-1:1)+_,y:o[1]*A*(d?-1:1)+z}}const Zi={width:0,height:0,x:0,y:0},Ud={...Zi,pointerX:0,pointerY:0,aspectRatio:1};function Zd(e){return[[0,0],[e.measured.width,e.measured.height]]}function Xd(e,n,s){const r=n.position.x+e.position.x,i=n.position.y+e.position.y,o=e.measured.width??0,a=e.measured.height??0,l=s[0]*o,c=s[1]*a;return[[r-l,i-c],[r+o-l,i+a-c]]}function Qd({domNode:e,nodeId:n,getStoreItems:s,onChange:r,onEnd:i}){const o=Mt(e);let a={controlDirection:la("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:d,boundaries:f,keepAspectRatio:h,resizeDirection:m,onResizeStart:u,onResize:g,onResizeEnd:C,shouldResize:S}){let v={...Zi},y={...Ud};a={boundaries:f,resizeDirection:m,keepAspectRatio:h,controlDirection:la(d)};let x,b=null,j=[],k,M,T,A=!1;const D=xi().on("start",E=>{const{nodeLookup:P,transform:q,snapGrid:N,snapToGrid:O,nodeOrigin:_,paneDomNode:z}=s();if(x=P.get(n),!x)return;b=z?.getBoundingClientRect()??null;const{xSnapped:L,ySnapped:R}=mr(E.sourceEvent,{transform:q,snapGrid:N,snapToGrid:O,containerBounds:b});v={width:x.measured.width??0,height:x.measured.height??0,x:x.position.x??0,y:x.position.y??0},y={...v,pointerX:L,pointerY:R,aspectRatio:v.width/v.height},k=void 0,x.parentId&&(x.extent==="parent"||x.expandParent)&&(k=P.get(x.parentId),M=k&&x.extent==="parent"?Zd(k):void 0),j=[],T=void 0;for(const[$,W]of P)if(W.parentId===n&&(j.push({id:$,position:{...W.position},extent:W.extent}),W.extent==="parent"||W.expandParent)){const F=Xd(W,x,W.origin??_);T?T=[[Math.min(F[0][0],T[0][0]),Math.min(F[0][1],T[0][1])],[Math.max(F[1][0],T[1][0]),Math.max(F[1][1],T[1][1])]]:T=F}u?.(E,{...v})}).on("drag",E=>{const{transform:P,snapGrid:q,snapToGrid:N,nodeOrigin:O}=s(),_=mr(E.sourceEvent,{transform:P,snapGrid:q,snapToGrid:N,containerBounds:b}),z=[];if(!x)return;const{x:L,y:R,width:$,height:W}=v,F={},X=x.origin??O,{width:B,height:I,x:Y,y:V}=Kd(y,a.controlDirection,_,a.boundaries,a.keepAspectRatio,X,M,T),H=B!==$,Z=I!==W,te=Y!==L&&H,oe=V!==R&&Z;if(!te&&!oe&&!H&&!Z)return;if((te||oe||X[0]===1||X[1]===1)&&(F.x=te?Y:v.x,F.y=oe?V:v.y,v.x=F.x,v.y=F.y,j.length>0)){const de=Y-L,fe=V-R;for(const xe of j)xe.position={x:xe.position.x-de+X[0]*(B-$),y:xe.position.y-fe+X[1]*(I-W)},z.push(xe)}if((H||Z)&&(F.width=H&&(!a.resizeDirection||a.resizeDirection==="horizontal")?B:v.width,F.height=Z&&(!a.resizeDirection||a.resizeDirection==="vertical")?I:v.height,v.width=F.width,v.height=F.height),k&&x.expandParent){const de=X[0]*(F.width??0);F.x&&F.x<de&&(v.x=de,y.x=y.x-(F.x-de));const fe=X[1]*(F.height??0);F.y&&F.y<fe&&(v.y=fe,y.y=y.y-(F.y-fe))}const ue=Gd({width:v.width,prevWidth:$,height:v.height,prevHeight:W,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),Q={...v,direction:ue};S?.(E,Q)!==!1&&(A=!0,g?.(E,Q),r(F,z))}).on("end",E=>{A&&(C?.(E,{...v}),i?.({...v}),A=!1)});o.call(D)}function c(){o.on(".drag",null)}return{update:l,destroy:c}}var _s={exports:{}},Ls={};var da;function Jd(){if(da)return Ls;da=1;var e=sc(),n=oc();function s(d,f){return d===f&&(d!==0||1/d===1/f)||d!==d&&f!==f}var r=typeof Object.is=="function"?Object.is:s,i=n.useSyncExternalStore,o=e.useRef,a=e.useEffect,l=e.useMemo,c=e.useDebugValue;return Ls.useSyncExternalStoreWithSelector=function(d,f,h,m,u){var g=o(null);if(g.current===null){var C={hasValue:!1,value:null};g.current=C}else C=g.current;g=l(function(){function v(k){if(!y){if(y=!0,x=k,k=m(k),u!==void 0&&C.hasValue){var M=C.value;if(u(M,k))return b=M}return b=k}if(M=b,r(x,k))return M;var T=m(k);return u!==void 0&&u(M,T)?(x=k,M):(x=k,b=T)}var y=!1,x,b,j=h===void 0?null:h;return[function(){return v(f())},j===null?void 0:function(){return v(j())}]},[f,h,m,u]);var S=i(d,g[0],g[1]);return a(function(){C.hasValue=!0,C.value=S},[S]),c(S),S},Ls}var ua;function eu(){return ua||(ua=1,_s.exports=Jd()),_s.exports}var tu=eu();const nu=ac(tu),ru={},fa=e=>{let n;const s=new Set,r=(f,h)=>{const m=typeof f=="function"?f(n):f;if(!Object.is(m,n)){const u=n;n=h??(typeof m!="object"||m===null)?m:Object.assign({},n,m),s.forEach(g=>g(n,u))}},i=()=>n,c={setState:r,getState:i,getInitialState:()=>d,subscribe:f=>(s.add(f),()=>s.delete(f)),destroy:()=>{(ru?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),s.clear()}},d=n=e(r,i,c);return c},su=e=>e?fa(e):fa,{useDebugValue:ou}=ic,{useSyncExternalStoreWithSelector:au}=nu,iu=e=>e;function Xi(e,n=iu,s){const r=au(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,s);return ou(r),r}const ha=(e,n)=>{const s=su(e),r=(i,o=n)=>Xi(s,i,o);return Object.assign(r,s),r},lu=(e,n)=>e?ha(e,n):ha;function Ke(e,n){if(Object.is(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;if(e instanceof Map&&n instanceof Map){if(e.size!==n.size)return!1;for(const[r,i]of e)if(!Object.is(i,n.get(r)))return!1;return!0}if(e instanceof Set&&n instanceof Set){if(e.size!==n.size)return!1;for(const r of e)if(!n.has(r))return!1;return!0}const s=Object.keys(e);if(s.length!==Object.keys(n).length)return!1;for(const r of s)if(!Object.prototype.hasOwnProperty.call(n,r)||!Object.is(e[r],n[r]))return!1;return!0}const ps=p.createContext(null),cu=ps.Provider,Qi=Vt.error001();function Le(e,n){const s=p.useContext(ps);if(s===null)throw new Error(Qi);return Xi(s,e,n)}function Ye(){const e=p.useContext(ps);if(e===null)throw new Error(Qi);return p.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const ma={display:"none"},du={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Ji="react-flow__node-desc",el="react-flow__edge-desc",uu="react-flow__aria-live",fu=e=>e.ariaLiveMessage,hu=e=>e.ariaLabelConfig;function mu({rfId:e}){const n=Le(fu);return t.jsx("div",{id:`${uu}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:du,children:n})}function pu({rfId:e,disableKeyboardA11y:n}){const s=Le(hu);return t.jsxs(t.Fragment,{children:[t.jsx("div",{id:`${Ji}-${e}`,style:ma,children:n?s["node.a11yDescription.default"]:s["node.a11yDescription.keyboardDisabled"]}),t.jsx("div",{id:`${el}-${e}`,style:ma,children:s["edge.a11yDescription.default"]}),!n&&t.jsx(mu,{rfId:e})]})}const gs=p.forwardRef(({position:e="top-left",children:n,className:s,style:r,...i},o)=>{const a=`${e}`.split("-");return t.jsx("div",{className:tt(["react-flow__panel",s,...a]),style:r,ref:o,...i,children:n})});gs.displayName="Panel";function gu({proOptions:e,position:n="bottom-right"}){return e?.hideAttribution?null:t.jsx(gs,{position:n,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:t.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const xu=e=>{const n=[],s=[];for(const[,r]of e.nodeLookup)r.selected&&n.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&s.push(r);return{selectedNodes:n,selectedEdges:s}},Ur=e=>e.id;function bu(e,n){return Ke(e.selectedNodes.map(Ur),n.selectedNodes.map(Ur))&&Ke(e.selectedEdges.map(Ur),n.selectedEdges.map(Ur))}function yu({onSelectionChange:e}){const n=Ye(),{selectedNodes:s,selectedEdges:r}=Le(xu,bu);return p.useEffect(()=>{const i={nodes:s,edges:r};e?.(i),n.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[s,r,e]),null}const wu=e=>!!e.onSelectionChangeHandlers;function vu({onSelectionChange:e}){const n=Le(wu);return e||n?t.jsx(yu,{onSelectionChange:e}):null}const tl=[0,0],ku={x:0,y:0,zoom:1},ju=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],pa=[...ju,"rfId"],Nu=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),ga={translateExtent:xr,nodeOrigin:tl,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function Cu(e){const{setNodes:n,setEdges:s,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:a,reset:l,setDefaultNodesAndEdges:c}=Le(Nu,Ke),d=Ye();p.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{f.current=ga,l()}),[]);const f=p.useRef(ga);return p.useEffect(()=>{for(const h of pa){const m=e[h],u=f.current[h];m!==u&&(typeof e[h]>"u"||(h==="nodes"?n(m):h==="edges"?s(m):h==="minZoom"?r(m):h==="maxZoom"?i(m):h==="translateExtent"?o(m):h==="nodeExtent"?a(m):h==="ariaLabelConfig"?d.setState({ariaLabelConfig:dd(m)}):h==="fitView"?d.setState({fitViewQueued:m}):h==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[h]:m})))}f.current=e},pa.map(h=>e[h])),null}function xa(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Su(e){const[n,s]=p.useState(e==="system"?null:e);return p.useEffect(()=>{if(e!=="system"){s(e);return}const r=xa(),i=()=>s(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),n!==null?n:xa()?.matches?"dark":"light"}const ba=typeof document<"u"?document:null;function vr(e=null,n={target:ba,actInsideInputWithModifier:!0}){const[s,r]=p.useState(!1),i=p.useRef(!1),o=p.useRef(new Set([])),[a,l]=p.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(h=>typeof h=="string").map(h=>h.replace("+",`
|
|
2
|
+
`).replace(`
|
|
3
|
+
|
|
4
|
+
`,`
|
|
5
|
+
+`).split(`
|
|
6
|
+
`)),f=d.reduce((h,m)=>h.concat(...m),[]);return[d,f]}return[[],[]]},[e]);return p.useEffect(()=>{const c=n?.target??ba,d=n?.actInsideInputWithModifier??!0;if(e!==null){const f=u=>{if(i.current=u.ctrlKey||u.metaKey||u.shiftKey||u.altKey,(!i.current||i.current&&!d)&&Di(u))return!1;const C=wa(u.code,l);if(o.current.add(u[C]),ya(a,o.current,!1)){const S=u.composedPath?.()?.[0]||u.target,v=S?.nodeName==="BUTTON"||S?.nodeName==="A";n.preventDefault!==!1&&(i.current||!v)&&u.preventDefault(),r(!0)}},h=u=>{const g=wa(u.code,l);ya(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(u[g]),u.key==="Meta"&&o.current.clear(),i.current=!1},m=()=>{o.current.clear(),r(!1)};return c?.addEventListener("keydown",f),c?.addEventListener("keyup",h),window.addEventListener("blur",m),window.addEventListener("contextmenu",m),()=>{c?.removeEventListener("keydown",f),c?.removeEventListener("keyup",h),window.removeEventListener("blur",m),window.removeEventListener("contextmenu",m)}}},[e,r]),s}function ya(e,n,s){return e.filter(r=>s||r.length===n.size).some(r=>r.every(i=>n.has(i)))}function wa(e,n){return n.includes(e)?"code":"key"}const Eu=()=>{const e=Ye();return p.useMemo(()=>({zoomIn:n=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1.2,{duration:n?.duration}):Promise.resolve(!1)},zoomOut:n=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1/1.2,{duration:n?.duration}):Promise.resolve(!1)},zoomTo:(n,s)=>{const{panZoom:r}=e.getState();return r?r.scaleTo(n,{duration:s?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(n,s)=>{const{transform:[r,i,o],panZoom:a}=e.getState();return a?(await a.setViewport({x:n.x??r,y:n.y??i,zoom:n.zoom??o},s),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[n,s,r]=e.getState().transform;return{x:n,y:s,zoom:r}},setCenter:async(n,s,r)=>e.getState().setCenter(n,s,r),fitBounds:async(n,s)=>{const{width:r,height:i,minZoom:o,maxZoom:a,panZoom:l}=e.getState(),c=Js(n,r,i,o,a,s?.padding??.1);return l?(await l.setViewport(c,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(n,s={})=>{const{transform:r,snapGrid:i,snapToGrid:o,domNode:a}=e.getState();if(!a)return n;const{x:l,y:c}=a.getBoundingClientRect(),d={x:n.x-l,y:n.y-c},f=s.snapGrid??i,h=s.snapToGrid??o;return Er(d,r,h,f)},flowToScreenPosition:n=>{const{transform:s,domNode:r}=e.getState();if(!r)return n;const{x:i,y:o}=r.getBoundingClientRect(),a=as(n,s);return{x:a.x+i,y:a.y+o}}}),[])};function nl(e,n){const s=[],r=new Map,i=[];for(const o of e)if(o.type==="add"){i.push(o);continue}else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const a=r.get(o.id);a?a.push(o):r.set(o.id,[o])}for(const o of n){const a=r.get(o.id);if(!a){s.push(o);continue}if(a[0].type==="remove")continue;if(a[0].type==="replace"){s.push({...a[0].item});continue}const l={...o};for(const c of a)Mu(c,l);s.push(l)}return i.length&&i.forEach(o=>{o.index!==void 0?s.splice(o.index,0,{...o.item}):s.push({...o.item})}),s}function Mu(e,n){switch(e.type){case"select":{n.selected=e.selected;break}case"position":{typeof e.position<"u"&&(n.position=e.position),typeof e.dragging<"u"&&(n.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(n.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(n.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(n.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(n.resizing=e.resizing);break}}}function rl(e,n){return nl(e,n)}function sl(e,n){return nl(e,n)}function En(e,n){return{id:e,type:"select",selected:n}}function Yn(e,n=new Set,s=!1){const r=[];for(const[i,o]of e){const a=n.has(i);!(o.selected===void 0&&!a)&&o.selected!==a&&(s&&(o.selected=a),r.push(En(o.id,a)))}return r}function va({items:e=[],lookup:n}){const s=[],r=new Map(e.map(i=>[i.id,i]));for(const[i,o]of e.entries()){const a=n.get(o.id),l=a?.internals?.userNode??a;l!==void 0&&l!==o&&s.push({id:o.id,item:o,type:"replace"}),l===void 0&&s.push({item:o,type:"add",index:i})}for(const[i]of n)r.get(i)===void 0&&s.push({id:i,type:"remove"});return s}function ka(e){return{id:e.id,type:"remove"}}const ja=e=>ed(e),Iu=e=>Si(e);function ol(e){return p.forwardRef(e)}const Tu=typeof window<"u"?p.useLayoutEffect:p.useEffect;function Na(e){const[n,s]=p.useState(BigInt(0)),[r]=p.useState(()=>Ru(()=>s(i=>i+BigInt(1))));return Tu(()=>{const i=r.get();i.length&&(e(i),r.reset())},[n]),r}function Ru(e){let n=[];return{get:()=>n,reset:()=>{n=[]},push:s=>{n.push(s),e()}}}const al=p.createContext(null);function _u({children:e}){const n=Ye(),s=p.useCallback(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:f,onNodesChange:h,nodeLookup:m,fitViewQueued:u,onNodesChangeMiddlewareMap:g}=n.getState();let C=c;for(const v of l)C=typeof v=="function"?v(C):v;let S=va({items:C,lookup:m});for(const v of g.values())S=v(S);f&&d(C),S.length>0?h?.(S):u&&window.requestAnimationFrame(()=>{const{fitViewQueued:v,nodes:y,setNodes:x}=n.getState();v&&x(y)})},[]),r=Na(s),i=p.useCallback(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:f,onEdgesChange:h,edgeLookup:m}=n.getState();let u=c;for(const g of l)u=typeof g=="function"?g(u):g;f?d(u):h&&h(va({items:u,lookup:m}))},[]),o=Na(i),a=p.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return t.jsx(al.Provider,{value:a,children:e})}function Lu(){const e=p.useContext(al);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Du=e=>!!e.panZoom;function ao(){const e=Eu(),n=Ye(),s=Lu(),r=Le(Du),i=p.useMemo(()=>{const o=h=>n.getState().nodeLookup.get(h),a=h=>{s.nodeQueue.push(h)},l=h=>{s.edgeQueue.push(h)},c=h=>{const{nodeLookup:m,nodeOrigin:u}=n.getState(),g=ja(h)?h:m.get(h.id),C=g.parentId?_i(g.position,g.measured,g.parentId,m,u):g.position,S={...g,position:C,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return Qn(S)},d=(h,m,u={replace:!1})=>{a(g=>g.map(C=>{if(C.id===h){const S=typeof m=="function"?m(C):m;return u.replace&&ja(S)?S:{...C,...S}}return C}))},f=(h,m,u={replace:!1})=>{l(g=>g.map(C=>{if(C.id===h){const S=typeof m=="function"?m(C):m;return u.replace&&Iu(S)?S:{...C,...S}}return C}))};return{getNodes:()=>n.getState().nodes.map(h=>({...h})),getNode:h=>o(h)?.internals.userNode,getInternalNode:o,getEdges:()=>{const{edges:h=[]}=n.getState();return h.map(m=>({...m}))},getEdge:h=>n.getState().edgeLookup.get(h),setNodes:a,setEdges:l,addNodes:h=>{const m=Array.isArray(h)?h:[h];s.nodeQueue.push(u=>[...u,...m])},addEdges:h=>{const m=Array.isArray(h)?h:[h];s.edgeQueue.push(u=>[...u,...m])},toObject:()=>{const{nodes:h=[],edges:m=[],transform:u}=n.getState(),[g,C,S]=u;return{nodes:h.map(v=>({...v})),edges:m.map(v=>({...v})),viewport:{x:g,y:C,zoom:S}}},deleteElements:async({nodes:h=[],edges:m=[]})=>{const{nodes:u,edges:g,onNodesDelete:C,onEdgesDelete:S,triggerNodeChanges:v,triggerEdgeChanges:y,onDelete:x,onBeforeDelete:b}=n.getState(),{nodes:j,edges:k}=await od({nodesToRemove:h,edgesToRemove:m,nodes:u,edges:g,onBeforeDelete:b}),M=k.length>0,T=j.length>0;if(M){const A=k.map(ka);S?.(k),y(A)}if(T){const A=j.map(ka);C?.(j),v(A)}return(T||M)&&x?.({nodes:j,edges:k}),{deletedNodes:j,deletedEdges:k}},getIntersectingNodes:(h,m=!0,u)=>{const g=Xo(h),C=g?h:c(h),S=u!==void 0;return C?(u||n.getState().nodes).filter(v=>{const y=n.getState().nodeLookup.get(v.id);if(y&&!g&&(v.id===h.id||!y.internals.positionAbsolute))return!1;const x=Qn(S?v:y),b=yr(x,C);return m&&b>0||b>=x.width*x.height||b>=C.width*C.height}):[]},isNodeIntersecting:(h,m,u=!0)=>{const C=Xo(h)?h:c(h);if(!C)return!1;const S=yr(C,m);return u&&S>0||S>=m.width*m.height||S>=C.width*C.height},updateNode:d,updateNodeData:(h,m,u={replace:!1})=>{d(h,g=>{const C=typeof m=="function"?m(g):m;return u.replace?{...g,data:C}:{...g,data:{...g.data,...C}}},u)},updateEdge:f,updateEdgeData:(h,m,u={replace:!1})=>{f(h,g=>{const C=typeof m=="function"?m(g):m;return u.replace?{...g,data:C}:{...g,data:{...g.data,...C}}},u)},getNodesBounds:h=>{const{nodeLookup:m,nodeOrigin:u}=n.getState();return td(h,{nodeLookup:m,nodeOrigin:u})},getHandleConnections:({type:h,id:m,nodeId:u})=>Array.from(n.getState().connectionLookup.get(`${u}-${h}${m?`-${m}`:""}`)?.values()??[]),getNodeConnections:({type:h,handleId:m,nodeId:u})=>Array.from(n.getState().connectionLookup.get(`${u}${h?m?`-${h}-${m}`:`-${h}`:""}`)?.values()??[]),fitView:async h=>{const m=n.getState().fitViewResolver??cd();return n.setState({fitViewQueued:!0,fitViewOptions:h,fitViewResolver:m}),s.nodeQueue.push(u=>[...u]),m.promise}}},[]);return p.useMemo(()=>({...i,...e,viewportInitialized:r}),[r])}const Ca=e=>e.selected,Au=typeof window<"u"?window:void 0;function Pu({deleteKeyCode:e,multiSelectionKeyCode:n}){const s=Ye(),{deleteElements:r}=ao(),i=vr(e,{actInsideInputWithModifier:!1}),o=vr(n,{target:Au});p.useEffect(()=>{if(i){const{edges:a,nodes:l}=s.getState();r({nodes:l.filter(Ca),edges:a.filter(Ca)}),s.setState({nodesSelectionActive:!1})}},[i]),p.useEffect(()=>{s.setState({multiSelectionActive:o})},[o])}function $u(e){const n=Ye();p.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=eo(e.current);(r.height===0||r.width===0)&&n.getState().onError?.("004",Vt.error004()),n.setState({width:r.width||500,height:r.height||500})};if(e.current){s(),window.addEventListener("resize",s);const r=new ResizeObserver(()=>s());return r.observe(e.current),()=>{window.removeEventListener("resize",s),r&&e.current&&r.unobserve(e.current)}}},[])}const xs={position:"absolute",width:"100%",height:"100%",top:0,left:0},Bu=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function Ou({onPaneContextMenu:e,zoomOnScroll:n=!0,zoomOnPinch:s=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:o=Mn.Free,zoomOnDoubleClick:a=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:f,maxZoom:h,zoomActivationKeyCode:m,preventScrolling:u=!0,children:g,noWheelClassName:C,noPanClassName:S,onViewportChange:v,isControlledViewport:y,paneClickDistance:x,selectionOnDrag:b}){const j=Ye(),k=p.useRef(null),{userSelectionActive:M,lib:T,connectionInProgress:A}=Le(Bu,Ke),D=vr(m),E=p.useRef();$u(k);const P=p.useCallback(q=>{v?.({x:q[0],y:q[1],zoom:q[2]}),y||j.setState({transform:q})},[v,y]);return p.useEffect(()=>{if(k.current){E.current=Yd({domNode:k.current,minZoom:f,maxZoom:h,translateExtent:d,viewport:c,onDraggingChange:_=>j.setState(z=>z.paneDragging===_?z:{paneDragging:_}),onPanZoomStart:(_,z)=>{const{onViewportChangeStart:L,onMoveStart:R}=j.getState();R?.(_,z),L?.(z)},onPanZoom:(_,z)=>{const{onViewportChange:L,onMove:R}=j.getState();R?.(_,z),L?.(z)},onPanZoomEnd:(_,z)=>{const{onViewportChangeEnd:L,onMoveEnd:R}=j.getState();R?.(_,z),L?.(z)}});const{x:q,y:N,zoom:O}=E.current.getViewport();return j.setState({panZoom:E.current,transform:[q,N,O],domNode:k.current.closest(".react-flow")}),()=>{E.current?.destroy()}}},[]),p.useEffect(()=>{E.current?.update({onPaneContextMenu:e,zoomOnScroll:n,zoomOnPinch:s,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:l,zoomActivationKeyPressed:D,preventScrolling:u,noPanClassName:S,userSelectionActive:M,noWheelClassName:C,lib:T,onTransformChange:P,connectionInProgress:A,selectionOnDrag:b,paneClickDistance:x})},[e,n,s,r,i,o,a,l,D,u,S,M,C,T,P,A,b,x]),t.jsx("div",{className:"react-flow__renderer",ref:k,style:xs,children:g})}const zu=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function Hu(){const{userSelectionActive:e,userSelectionRect:n}=Le(zu,Ke);return e&&n?t.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:n.width,height:n.height,transform:`translate(${n.x}px, ${n.y}px)`}}):null}const Ds=(e,n)=>s=>{s.target===n.current&&e?.(s)},qu=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function Wu({isSelecting:e,selectionKeyPressed:n,selectionMode:s=br.Full,panOnDrag:r,paneClickDistance:i,selectionOnDrag:o,onSelectionStart:a,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:f,onPaneMouseEnter:h,onPaneMouseMove:m,onPaneMouseLeave:u,children:g}){const C=Ye(),{userSelectionActive:S,elementsSelectable:v,dragging:y,connectionInProgress:x}=Le(qu,Ke),b=v&&(e||S),j=p.useRef(null),k=p.useRef(),M=p.useRef(new Set),T=p.useRef(new Set),A=p.useRef(!1),D=L=>{if(A.current||x){A.current=!1;return}c?.(L),C.getState().resetSelectedElements(),C.setState({nodesSelectionActive:!1})},E=L=>{if(Array.isArray(r)&&r?.includes(2)){L.preventDefault();return}d?.(L)},P=f?L=>f(L):void 0,q=L=>{A.current&&(L.stopPropagation(),A.current=!1)},N=L=>{const{domNode:R}=C.getState();if(k.current=R?.getBoundingClientRect(),!k.current)return;const $=L.target===j.current;if(!$&&!!L.target.closest(".nokey")||!e||!(o&&$||n)||L.button!==0||!L.isPrimary)return;L.target?.setPointerCapture?.(L.pointerId),A.current=!1;const{x:X,y:B}=$t(L.nativeEvent,k.current);C.setState({userSelectionRect:{width:0,height:0,startX:X,startY:B,x:X,y:B}}),$||(L.stopPropagation(),L.preventDefault())},O=L=>{const{userSelectionRect:R,transform:$,nodeLookup:W,edgeLookup:F,connectionLookup:X,triggerNodeChanges:B,triggerEdgeChanges:I,defaultEdgeOptions:Y,resetSelectedElements:V}=C.getState();if(!k.current||!R)return;const{x:H,y:Z}=$t(L.nativeEvent,k.current),{startX:te,startY:oe}=R;if(!A.current){const fe=n?0:i;if(Math.hypot(H-te,Z-oe)<=fe)return;V(),a?.(L)}A.current=!0;const ue={startX:te,startY:oe,x:H<te?H:te,y:Z<oe?Z:oe,width:Math.abs(H-te),height:Math.abs(Z-oe)},Q=M.current,le=T.current;M.current=new Set(Qs(W,ue,$,s===br.Partial,!0).map(fe=>fe.id)),T.current=new Set;const de=Y?.selectable??!0;for(const fe of M.current){const xe=X.get(fe);if(xe)for(const{edgeId:be}of xe.values()){const U=F.get(be);U&&(U.selectable??de)&&T.current.add(be)}}if(!Qo(Q,M.current)){const fe=Yn(W,M.current,!0);B(fe)}if(!Qo(le,T.current)){const fe=Yn(F,T.current);I(fe)}C.setState({userSelectionRect:ue,userSelectionActive:!0,nodesSelectionActive:!1})},_=L=>{L.button===0&&(L.target?.releasePointerCapture?.(L.pointerId),!S&&L.target===j.current&&C.getState().userSelectionRect&&D?.(L),C.setState({userSelectionActive:!1,userSelectionRect:null}),A.current&&(l?.(L),C.setState({nodesSelectionActive:M.current.size>0})))},z=r===!0||Array.isArray(r)&&r.includes(0);return t.jsxs("div",{className:tt(["react-flow__pane",{draggable:z,dragging:y,selection:e}]),onClick:b?void 0:Ds(D,j),onContextMenu:Ds(E,j),onWheel:Ds(P,j),onPointerEnter:b?void 0:h,onPointerMove:b?O:m,onPointerUp:b?_:void 0,onPointerDownCapture:b?N:void 0,onClickCapture:b?q:void 0,onPointerLeave:u,ref:j,style:xs,children:[g,t.jsx(Hu,{})]})}function Vs({id:e,store:n,unselect:s=!1,nodeRef:r}){const{addSelectedNodes:i,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:l,onError:c}=n.getState(),d=l.get(e);if(!d){c?.("012",Vt.error012(e));return}n.setState({nodesSelectionActive:!1}),d.selected?(s||d.selected&&a)&&(o({nodes:[d],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function il({nodeRef:e,disabled:n=!1,noDragClassName:s,handleSelector:r,nodeId:i,isSelectable:o,nodeClickDistance:a}){const l=Ye(),[c,d]=p.useState(!1),f=p.useRef();return p.useEffect(()=>{f.current=_d({getStoreItems:()=>l.getState(),onNodeMouseDown:h=>{Vs({id:h,store:l,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),p.useEffect(()=>{if(!(n||!e.current||!f.current))return f.current.update({noDragClassName:s,handleSelector:r,domNode:e.current,isSelectable:o,nodeId:i,nodeClickDistance:a}),()=>{f.current?.destroy()}},[s,r,n,o,e,i,a]),c}const Fu=e=>n=>n.selected&&(n.draggable||e&&typeof n.draggable>"u");function ll(){const e=Ye();return p.useCallback(s=>{const{nodeExtent:r,snapToGrid:i,snapGrid:o,nodesDraggable:a,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:f}=e.getState(),h=new Map,m=Fu(a),u=i?o[0]:5,g=i?o[1]:5,C=s.direction.x*u*s.factor,S=s.direction.y*g*s.factor;for(const[,v]of d){if(!m(v))continue;let y={x:v.internals.positionAbsolute.x+C,y:v.internals.positionAbsolute.y+S};i&&(y=Sr(y,o));const{position:x,positionAbsolute:b}=Ei({nodeId:v.id,nextPosition:y,nodeLookup:d,nodeExtent:r,nodeOrigin:f,onError:l});v.position=x,v.internals.positionAbsolute=b,h.set(v.id,v)}c(h)},[])}const io=p.createContext(null),Vu=io.Provider;io.Consumer;const cl=()=>p.useContext(io),Yu=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Gu=(e,n,s)=>r=>{const{connectionClickStartHandle:i,connectionMode:o,connection:a}=r,{fromHandle:l,toHandle:c,isValid:d}=a,f=c?.nodeId===e&&c?.id===n&&c?.type===s;return{connectingFrom:l?.nodeId===e&&l?.id===n&&l?.type===s,connectingTo:f,clickConnecting:i?.nodeId===e&&i?.id===n&&i?.type===s,isPossibleEndHandle:o===Un.Strict?l?.type!==s:e!==l?.nodeId||n!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!i,valid:f&&d}};function Ku({type:e="source",position:n=ye.Top,isValidConnection:s,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,id:a,onConnect:l,children:c,className:d,onMouseDown:f,onTouchStart:h,...m},u){const g=a||null,C=e==="target",S=Ye(),v=cl(),{connectOnClick:y,noPanClassName:x,rfId:b}=Le(Yu,Ke),{connectingFrom:j,connectingTo:k,clickConnecting:M,isPossibleEndHandle:T,connectionInProcess:A,clickConnectionInProcess:D,valid:E}=Le(Gu(v,g,e),Ke);v||S.getState().onError?.("010",Vt.error010());const P=O=>{const{defaultEdgeOptions:_,onConnect:z,hasDefaultEdges:L}=S.getState(),R={..._,...O};if(L){const{edges:$,setEdges:W}=S.getState();W(gd(R,$))}z?.(R),l?.(R)},q=O=>{if(!v)return;const _=Ai(O.nativeEvent);if(i&&(_&&O.button===0||!_)){const z=S.getState();Fs.onPointerDown(O.nativeEvent,{handleDomNode:O.currentTarget,autoPanOnConnect:z.autoPanOnConnect,connectionMode:z.connectionMode,connectionRadius:z.connectionRadius,domNode:z.domNode,nodeLookup:z.nodeLookup,lib:z.lib,isTarget:C,handleId:g,nodeId:v,flowId:z.rfId,panBy:z.panBy,cancelConnection:z.cancelConnection,onConnectStart:z.onConnectStart,onConnectEnd:(...L)=>S.getState().onConnectEnd?.(...L),updateConnection:z.updateConnection,onConnect:P,isValidConnection:s||((...L)=>S.getState().isValidConnection?.(...L)??!0),getTransform:()=>S.getState().transform,getFromHandle:()=>S.getState().connection.fromHandle,autoPanSpeed:z.autoPanSpeed,dragThreshold:z.connectionDragThreshold})}_?f?.(O):h?.(O)},N=O=>{const{onClickConnectStart:_,onClickConnectEnd:z,connectionClickStartHandle:L,connectionMode:R,isValidConnection:$,lib:W,rfId:F,nodeLookup:X,connection:B}=S.getState();if(!v||!L&&!i)return;if(!L){_?.(O.nativeEvent,{nodeId:v,handleId:g,handleType:e}),S.setState({connectionClickStartHandle:{nodeId:v,type:e,id:g}});return}const I=Li(O.target),Y=s||$,{connection:V,isValid:H}=Fs.isValid(O.nativeEvent,{handle:{nodeId:v,id:g,type:e},connectionMode:R,fromNodeId:L.nodeId,fromHandleId:L.id||null,fromType:L.type,isValidConnection:Y,flowId:F,doc:I,lib:W,nodeLookup:X});H&&V&&P(V);const Z=structuredClone(B);delete Z.inProgress,Z.toPosition=Z.toHandle?Z.toHandle.position:null,z?.(O,Z),S.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":g,"data-nodeid":v,"data-handlepos":n,"data-id":`${b}-${v}-${g}-${e}`,className:tt(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",x,d,{source:!C,target:C,connectable:r,connectablestart:i,connectableend:o,clickconnecting:M,connectingfrom:j,connectingto:k,valid:E,connectionindicator:r&&(!A||T)&&(A||D?o:i)}]),onMouseDown:q,onTouchStart:q,onClick:y?N:void 0,ref:u,...m,children:c})}const fn=p.memo(ol(Ku));function Uu({data:e,isConnectable:n,sourcePosition:s=ye.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(fn,{type:"source",position:s,isConnectable:n})]})}function Zu({data:e,isConnectable:n,targetPosition:s=ye.Top,sourcePosition:r=ye.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(fn,{type:"target",position:s,isConnectable:n}),e?.label,t.jsx(fn,{type:"source",position:r,isConnectable:n})]})}function Xu(){return null}function Qu({data:e,isConnectable:n,targetPosition:s=ye.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(fn,{type:"target",position:s,isConnectable:n}),e?.label]})}const is={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Sa={input:Uu,default:Zu,output:Qu,group:Xu};function Ju(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}const ef=e=>{const{width:n,height:s,x:r,y:i}=Cr(e.nodeLookup,{filter:o=>!!o.selected});return{width:Pt(n)?n:null,height:Pt(s)?s:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${i}px)`}};function tf({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:s}){const r=Ye(),{width:i,height:o,transformString:a,userSelectionActive:l}=Le(ef,Ke),c=ll(),d=p.useRef(null);p.useEffect(()=>{s||d.current?.focus({preventScroll:!0})},[s]);const f=!l&&i!==null&&o!==null;if(il({nodeRef:d,disabled:!f}),!f)return null;const h=e?u=>{const g=r.getState().nodes.filter(C=>C.selected);e(u,g)}:void 0,m=u=>{Object.prototype.hasOwnProperty.call(is,u.key)&&(u.preventDefault(),c({direction:is[u.key],factor:u.shiftKey?4:1}))};return t.jsx("div",{className:tt(["react-flow__nodesselection","react-flow__container",n]),style:{transform:a},children:t.jsx("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:h,tabIndex:s?void 0:-1,onKeyDown:s?void 0:m,style:{width:i,height:o}})})}const Ea=typeof window<"u"?window:void 0,nf=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function dl({children:e,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:f,selectionMode:h,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:g,panActivationKeyCode:C,zoomActivationKeyCode:S,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:x,panOnScroll:b,panOnScrollSpeed:j,panOnScrollMode:k,zoomOnDoubleClick:M,panOnDrag:T,defaultViewport:A,translateExtent:D,minZoom:E,maxZoom:P,preventScrolling:q,onSelectionContextMenu:N,noWheelClassName:O,noPanClassName:_,disableKeyboardA11y:z,onViewportChange:L,isControlledViewport:R}){const{nodesSelectionActive:$,userSelectionActive:W}=Le(nf,Ke),F=vr(d,{target:Ea}),X=vr(C,{target:Ea}),B=X||T,I=X||b,Y=f&&B!==!0,V=F||W||Y;return Pu({deleteKeyCode:c,multiSelectionKeyCode:g}),t.jsx(Ou,{onPaneContextMenu:o,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:x,panOnScroll:I,panOnScrollSpeed:j,panOnScrollMode:k,zoomOnDoubleClick:M,panOnDrag:!F&&B,defaultViewport:A,translateExtent:D,minZoom:E,maxZoom:P,zoomActivationKeyCode:S,preventScrolling:q,noWheelClassName:O,noPanClassName:_,onViewportChange:L,isControlledViewport:R,paneClickDistance:l,selectionOnDrag:Y,children:t.jsxs(Wu,{onSelectionStart:m,onSelectionEnd:u,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:B,isSelecting:!!V,selectionMode:h,selectionKeyPressed:F,paneClickDistance:l,selectionOnDrag:Y,children:[e,$&&t.jsx(tf,{onSelectionContextMenu:N,noPanClassName:_,disableKeyboardA11y:z})]})})}dl.displayName="FlowRenderer";const rf=p.memo(dl),sf=e=>n=>e?Qs(n.nodeLookup,{x:0,y:0,width:n.width,height:n.height},n.transform,!0).map(s=>s.id):Array.from(n.nodeLookup.keys());function of(e){return Le(p.useCallback(sf(e),[e]),Ke)}const af=e=>e.updateNodeInternals;function lf(){const e=Le(af),[n]=p.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const r=new Map;s.forEach(i=>{const o=i.target.getAttribute("data-id");r.set(o,{id:o,nodeElement:i.target,force:!0})}),e(r)}));return p.useEffect(()=>()=>{n?.disconnect()},[n]),n}function cf({node:e,nodeType:n,hasDimensions:s,resizeObserver:r}){const i=Ye(),o=p.useRef(null),a=p.useRef(null),l=p.useRef(e.sourcePosition),c=p.useRef(e.targetPosition),d=p.useRef(n),f=s&&!!e.internals.handleBounds;return p.useEffect(()=>{o.current&&!e.hidden&&(!f||a.current!==o.current)&&(a.current&&r?.unobserve(a.current),r?.observe(o.current),a.current=o.current)},[f,e.hidden]),p.useEffect(()=>()=>{a.current&&(r?.unobserve(a.current),a.current=null)},[]),p.useEffect(()=>{if(o.current){const h=d.current!==n,m=l.current!==e.sourcePosition,u=c.current!==e.targetPosition;(h||m||u)&&(d.current=n,l.current=e.sourcePosition,c.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:o.current,force:!0}]])))}},[e.id,n,e.sourcePosition,e.targetPosition]),o}function df({id:e,onClick:n,onMouseEnter:s,onMouseMove:r,onMouseLeave:i,onContextMenu:o,onDoubleClick:a,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:f,resizeObserver:h,noDragClassName:m,noPanClassName:u,disableKeyboardA11y:g,rfId:C,nodeTypes:S,nodeClickDistance:v,onError:y}){const{node:x,internals:b,isParent:j}=Le(H=>{const Z=H.nodeLookup.get(e),te=H.parentLookup.has(e);return{node:Z,internals:Z.internals,isParent:te}},Ke);let k=x.type||"default",M=S?.[k]||Sa[k];M===void 0&&(y?.("003",Vt.error003(k)),k="default",M=S?.default||Sa.default);const T=!!(x.draggable||l&&typeof x.draggable>"u"),A=!!(x.selectable||c&&typeof x.selectable>"u"),D=!!(x.connectable||d&&typeof x.connectable>"u"),E=!!(x.focusable||f&&typeof x.focusable>"u"),P=Ye(),q=Ri(x),N=cf({node:x,nodeType:k,hasDimensions:q,resizeObserver:h}),O=il({nodeRef:N,disabled:x.hidden||!T,noDragClassName:m,handleSelector:x.dragHandle,nodeId:e,isSelectable:A,nodeClickDistance:v}),_=ll();if(x.hidden)return null;const z=en(x),L=Ju(x),R=A||T||n||s||r||i,$=s?H=>s(H,{...b.userNode}):void 0,W=r?H=>r(H,{...b.userNode}):void 0,F=i?H=>i(H,{...b.userNode}):void 0,X=o?H=>o(H,{...b.userNode}):void 0,B=a?H=>a(H,{...b.userNode}):void 0,I=H=>{const{selectNodesOnDrag:Z,nodeDragThreshold:te}=P.getState();A&&(!Z||!T||te>0)&&Vs({id:e,store:P,nodeRef:N}),n&&n(H,{...b.userNode})},Y=H=>{if(!(Di(H.nativeEvent)||g)){if(ki.includes(H.key)&&A){const Z=H.key==="Escape";Vs({id:e,store:P,unselect:Z,nodeRef:N})}else if(T&&x.selected&&Object.prototype.hasOwnProperty.call(is,H.key)){H.preventDefault();const{ariaLabelConfig:Z}=P.getState();P.setState({ariaLiveMessage:Z["node.a11yDescription.ariaLiveMessage"]({direction:H.key.replace("Arrow","").toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),_({direction:is[H.key],factor:H.shiftKey?4:1})}}},V=()=>{if(g||!N.current?.matches(":focus-visible"))return;const{transform:H,width:Z,height:te,autoPanOnNodeFocus:oe,setCenter:ue}=P.getState();if(!oe)return;Qs(new Map([[e,x]]),{x:0,y:0,width:Z,height:te},H,!0).length>0||ue(x.position.x+z.width/2,x.position.y+z.height/2,{zoom:H[2]})};return t.jsx("div",{className:tt(["react-flow__node",`react-flow__node-${k}`,{[u]:T},x.className,{selected:x.selected,selectable:A,parent:j,draggable:T,dragging:O}]),ref:N,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:R?"all":"none",visibility:q?"visible":"hidden",...x.style,...L},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:$,onMouseMove:W,onMouseLeave:F,onContextMenu:X,onClick:I,onDoubleClick:B,onKeyDown:E?Y:void 0,tabIndex:E?0:void 0,onFocus:E?V:void 0,role:x.ariaRole??(E?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${Ji}-${C}`,"aria-label":x.ariaLabel,...x.domAttributes,children:t.jsx(Vu,{value:e,children:t.jsx(M,{id:e,data:x.data,type:k,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:x.selected??!1,selectable:A,draggable:T,deletable:x.deletable??!0,isConnectable:D,sourcePosition:x.sourcePosition,targetPosition:x.targetPosition,dragging:O,dragHandle:x.dragHandle,zIndex:b.z,parentId:x.parentId,...z})})})}var uf=p.memo(df);const ff=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function ul(e){const{nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,onError:o}=Le(ff,Ke),a=of(e.onlyRenderVisibleElements),l=lf();return t.jsx("div",{className:"react-flow__nodes",style:xs,children:a.map(c=>t.jsx(uf,{id:c,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:l,nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:o},c))})}ul.displayName="NodeRenderer";const hf=p.memo(ul);function mf(e){return Le(p.useCallback(s=>{if(!e)return s.edges.map(i=>i.id);const r=[];if(s.width&&s.height)for(const i of s.edges){const o=s.nodeLookup.get(i.source),a=s.nodeLookup.get(i.target);o&&a&&hd({sourceNode:o,targetNode:a,width:s.width,height:s.height,transform:s.transform})&&r.push(i.id)}return r},[e]),Ke)}const pf=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...e&&{stroke:e}};return t.jsx("polyline",{className:"arrow",style:s,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},gf=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...e&&{stroke:e,fill:e}};return t.jsx("polyline",{className:"arrowclosed",style:s,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Ma={[Zn.Arrow]:pf,[Zn.ArrowClosed]:gf};function xf(e){const n=Ye();return p.useMemo(()=>Object.prototype.hasOwnProperty.call(Ma,e)?Ma[e]:(n.getState().onError?.("009",Vt.error009(e)),null),[e])}const bf=({id:e,type:n,color:s,width:r=12.5,height:i=12.5,markerUnits:o="strokeWidth",strokeWidth:a,orient:l="auto-start-reverse"})=>{const c=xf(n);return c?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:l,refX:"0",refY:"0",children:t.jsx(c,{color:s,strokeWidth:a})}):null},fl=({defaultColor:e,rfId:n})=>{const s=Le(o=>o.edges),r=Le(o=>o.defaultEdgeOptions),i=p.useMemo(()=>vd(s,{id:n,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[s,r,n,e]);return i.length?t.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:t.jsx("defs",{children:i.map(o=>t.jsx(bf,{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};fl.displayName="MarkerDefinitions";var yf=p.memo(fl);function hl({x:e,y:n,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:l=2,children:c,className:d,...f}){const[h,m]=p.useState({x:1,y:0,width:0,height:0}),u=tt(["react-flow__edge-textwrapper",d]),g=p.useRef(null);return p.useEffect(()=>{if(g.current){const C=g.current.getBBox();m({x:C.x,y:C.y,width:C.width,height:C.height})}},[s]),s?t.jsxs("g",{transform:`translate(${e-h.width/2} ${n-h.height/2})`,className:u,visibility:h.width?"visible":"hidden",...f,children:[i&&t.jsx("rect",{width:h.width+2*a[0],x:-a[0],y:-a[1],height:h.height+2*a[1],className:"react-flow__edge-textbg",style:o,rx:l,ry:l}),t.jsx("text",{className:"react-flow__edge-text",y:h.height/2,dy:"0.3em",ref:g,style:r,children:s}),c]}):null}hl.displayName="EdgeText";const wf=p.memo(hl);function bs({path:e,labelX:n,labelY:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...f}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...f,d:e,fill:"none",className:tt(["react-flow__edge-path",f.className])}),d?t.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:d,className:"react-flow__edge-interaction"}):null,r&&Pt(n)&&Pt(s)?t.jsx(wf,{x:n,y:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Ia({pos:e,x1:n,y1:s,x2:r,y2:i}){return e===ye.Left||e===ye.Right?[.5*(n+r),s]:[n,.5*(s+i)]}function ml({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top}){const[a,l]=Ia({pos:s,x1:e,y1:n,x2:r,y2:i}),[c,d]=Ia({pos:o,x1:r,y1:i,x2:e,y2:n}),[f,h,m,u]=Pi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:a,sourceControlY:l,targetControlX:c,targetControlY:d});return[`M${e},${n} C${a},${l} ${c},${d} ${r},${i}`,f,h,m,u]}function pl(e){return p.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a,targetPosition:l,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:u,style:g,markerEnd:C,markerStart:S,interactionWidth:v})=>{const[y,x,b]=ml({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:l}),j=e.isInternal?void 0:n;return t.jsx(bs,{id:j,path:y,labelX:x,labelY:b,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:u,style:g,markerEnd:C,markerStart:S,interactionWidth:v})})}const vf=pl({isInternal:!1}),gl=pl({isInternal:!0});vf.displayName="SimpleBezierEdge";gl.displayName="SimpleBezierEdgeInternal";function xl(e){return p.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:h,style:m,sourcePosition:u=ye.Bottom,targetPosition:g=ye.Top,markerEnd:C,markerStart:S,pathOptions:v,interactionWidth:y})=>{const[x,b,j]=Hs({sourceX:s,sourceY:r,sourcePosition:u,targetX:i,targetY:o,targetPosition:g,borderRadius:v?.borderRadius,offset:v?.offset,stepPosition:v?.stepPosition}),k=e.isInternal?void 0:n;return t.jsx(bs,{id:k,path:x,labelX:b,labelY:j,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:h,style:m,markerEnd:C,markerStart:S,interactionWidth:y})})}const bl=xl({isInternal:!1}),yl=xl({isInternal:!0});bl.displayName="SmoothStepEdge";yl.displayName="SmoothStepEdgeInternal";function wl(e){return p.memo(({id:n,...s})=>{const r=e.isInternal?void 0:n;return t.jsx(bl,{...s,id:r,pathOptions:p.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const kf=wl({isInternal:!1}),vl=wl({isInternal:!0});kf.displayName="StepEdge";vl.displayName="StepEdgeInternal";function kl(e){return p.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:h,style:m,markerEnd:u,markerStart:g,interactionWidth:C})=>{const[S,v,y]=Oi({sourceX:s,sourceY:r,targetX:i,targetY:o}),x=e.isInternal?void 0:n;return t.jsx(bs,{id:x,path:S,labelX:v,labelY:y,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:h,style:m,markerEnd:u,markerStart:g,interactionWidth:C})})}const jf=kl({isInternal:!1}),jl=kl({isInternal:!0});jf.displayName="StraightEdge";jl.displayName="StraightEdgeInternal";function Nl(e){return p.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a=ye.Bottom,targetPosition:l=ye.Top,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:u,style:g,markerEnd:C,markerStart:S,pathOptions:v,interactionWidth:y})=>{const[x,b,j]=$i({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:l,curvature:v?.curvature}),k=e.isInternal?void 0:n;return t.jsx(bs,{id:k,path:x,labelX:b,labelY:j,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:u,style:g,markerEnd:C,markerStart:S,interactionWidth:y})})}const Nf=Nl({isInternal:!1}),Cl=Nl({isInternal:!0});Nf.displayName="BezierEdge";Cl.displayName="BezierEdgeInternal";const Ta={default:Cl,straight:jl,step:vl,smoothstep:yl,simplebezier:gl},Ra={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},Cf=(e,n,s)=>s===ye.Left?e-n:s===ye.Right?e+n:e,Sf=(e,n,s)=>s===ye.Top?e-n:s===ye.Bottom?e+n:e,_a="react-flow__edgeupdater";function La({position:e,centerX:n,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:o,onMouseOut:a,type:l}){return t.jsx("circle",{onMouseDown:i,onMouseEnter:o,onMouseOut:a,className:tt([_a,`${_a}-${l}`]),cx:Cf(n,r,e),cy:Sf(s,r,e),r,stroke:"transparent",fill:"transparent"})}function Ef({isReconnectable:e,reconnectRadius:n,edge:s,sourceX:r,sourceY:i,targetX:o,targetY:a,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:f,onReconnectEnd:h,setReconnecting:m,setUpdateHover:u}){const g=Ye(),C=(b,j)=>{if(b.button!==0)return;const{autoPanOnConnect:k,domNode:M,connectionMode:T,connectionRadius:A,lib:D,onConnectStart:E,cancelConnection:P,nodeLookup:q,rfId:N,panBy:O,updateConnection:_}=g.getState(),z=j.type==="target",L=(W,F)=>{m(!1),h?.(W,s,j.type,F)},R=W=>d?.(s,W),$=(W,F)=>{m(!0),f?.(b,s,j.type),E?.(W,F)};Fs.onPointerDown(b.nativeEvent,{autoPanOnConnect:k,connectionMode:T,connectionRadius:A,domNode:M,handleId:j.id,nodeId:j.nodeId,nodeLookup:q,isTarget:z,edgeUpdaterType:j.type,lib:D,flowId:N,cancelConnection:P,panBy:O,isValidConnection:(...W)=>g.getState().isValidConnection?.(...W)??!0,onConnect:R,onConnectStart:$,onConnectEnd:(...W)=>g.getState().onConnectEnd?.(...W),onReconnectEnd:L,updateConnection:_,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:b.currentTarget})},S=b=>C(b,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),v=b=>C(b,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),y=()=>u(!0),x=()=>u(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(La,{position:l,centerX:r,centerY:i,radius:n,onMouseDown:S,onMouseEnter:y,onMouseOut:x,type:"source"}),(e===!0||e==="target")&&t.jsx(La,{position:c,centerX:o,centerY:a,radius:n,onMouseDown:v,onMouseEnter:y,onMouseOut:x,type:"target"})]})}function Mf({id:e,edgesFocusable:n,edgesReconnectable:s,elementsSelectable:r,onClick:i,onDoubleClick:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:f,onReconnect:h,onReconnectStart:m,onReconnectEnd:u,rfId:g,edgeTypes:C,noPanClassName:S,onError:v,disableKeyboardA11y:y}){let x=Le(ue=>ue.edgeLookup.get(e));const b=Le(ue=>ue.defaultEdgeOptions);x=b?{...b,...x}:x;let j=x.type||"default",k=C?.[j]||Ta[j];k===void 0&&(v?.("011",Vt.error011(j)),j="default",k=C?.default||Ta.default);const M=!!(x.focusable||n&&typeof x.focusable>"u"),T=typeof h<"u"&&(x.reconnectable||s&&typeof x.reconnectable>"u"),A=!!(x.selectable||r&&typeof x.selectable>"u"),D=p.useRef(null),[E,P]=p.useState(!1),[q,N]=p.useState(!1),O=Ye(),{zIndex:_,sourceX:z,sourceY:L,targetX:R,targetY:$,sourcePosition:W,targetPosition:F}=Le(p.useCallback(ue=>{const Q=ue.nodeLookup.get(x.source),le=ue.nodeLookup.get(x.target);if(!Q||!le)return{zIndex:x.zIndex,...Ra};const de=wd({id:e,sourceNode:Q,targetNode:le,sourceHandle:x.sourceHandle||null,targetHandle:x.targetHandle||null,connectionMode:ue.connectionMode,onError:v});return{zIndex:fd({selected:x.selected,zIndex:x.zIndex,sourceNode:Q,targetNode:le,elevateOnSelect:ue.elevateEdgesOnSelect,zIndexMode:ue.zIndexMode}),...de||Ra}},[x.source,x.target,x.sourceHandle,x.targetHandle,x.selected,x.zIndex]),Ke),X=p.useMemo(()=>x.markerStart?`url('#${qs(x.markerStart,g)}')`:void 0,[x.markerStart,g]),B=p.useMemo(()=>x.markerEnd?`url('#${qs(x.markerEnd,g)}')`:void 0,[x.markerEnd,g]);if(x.hidden||z===null||L===null||R===null||$===null)return null;const I=ue=>{const{addSelectedEdges:Q,unselectNodesAndEdges:le,multiSelectionActive:de}=O.getState();A&&(O.setState({nodesSelectionActive:!1}),x.selected&&de?(le({nodes:[],edges:[x]}),D.current?.blur()):Q([e])),i&&i(ue,x)},Y=o?ue=>{o(ue,{...x})}:void 0,V=a?ue=>{a(ue,{...x})}:void 0,H=l?ue=>{l(ue,{...x})}:void 0,Z=c?ue=>{c(ue,{...x})}:void 0,te=d?ue=>{d(ue,{...x})}:void 0,oe=ue=>{if(!y&&ki.includes(ue.key)&&A){const{unselectNodesAndEdges:Q,addSelectedEdges:le}=O.getState();ue.key==="Escape"?(D.current?.blur(),Q({edges:[x]})):le([e])}};return t.jsx("svg",{style:{zIndex:_},children:t.jsxs("g",{className:tt(["react-flow__edge",`react-flow__edge-${j}`,x.className,S,{selected:x.selected,animated:x.animated,inactive:!A&&!i,updating:E,selectable:A}]),onClick:I,onDoubleClick:Y,onContextMenu:V,onMouseEnter:H,onMouseMove:Z,onMouseLeave:te,onKeyDown:M?oe:void 0,tabIndex:M?0:void 0,role:x.ariaRole??(M?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":x.ariaLabel===null?void 0:x.ariaLabel||`Edge from ${x.source} to ${x.target}`,"aria-describedby":M?`${el}-${g}`:void 0,ref:D,...x.domAttributes,children:[!q&&t.jsx(k,{id:e,source:x.source,target:x.target,type:x.type,selected:x.selected,animated:x.animated,selectable:A,deletable:x.deletable??!0,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,sourceX:z,sourceY:L,targetX:R,targetY:$,sourcePosition:W,targetPosition:F,data:x.data,style:x.style,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerStart:X,markerEnd:B,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth}),T&&t.jsx(Ef,{edge:x,isReconnectable:T,reconnectRadius:f,onReconnect:h,onReconnectStart:m,onReconnectEnd:u,sourceX:z,sourceY:L,targetX:R,targetY:$,sourcePosition:W,targetPosition:F,setUpdateHover:P,setReconnecting:N})]})})}var If=p.memo(Mf);const Tf=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Sl({defaultMarkerColor:e,onlyRenderVisibleElements:n,rfId:s,edgeTypes:r,noPanClassName:i,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:f,reconnectRadius:h,onEdgeDoubleClick:m,onReconnectStart:u,onReconnectEnd:g,disableKeyboardA11y:C}){const{edgesFocusable:S,edgesReconnectable:v,elementsSelectable:y,onError:x}=Le(Tf,Ke),b=mf(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(yf,{defaultColor:e,rfId:s}),b.map(j=>t.jsx(If,{id:j,edgesFocusable:S,edgesReconnectable:v,elementsSelectable:y,noPanClassName:i,onReconnect:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:f,reconnectRadius:h,onDoubleClick:m,onReconnectStart:u,onReconnectEnd:g,rfId:s,onError:x,edgeTypes:r,disableKeyboardA11y:C},j))]})}Sl.displayName="EdgeRenderer";const Rf=p.memo(Sl),_f=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Lf({children:e}){const n=Le(_f);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function Df(e){const n=ao(),s=p.useRef(!1);p.useEffect(()=>{!s.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),s.current=!0)},[e,n.viewportInitialized])}const Af=e=>e.panZoom?.syncViewport;function Pf(e){const n=Le(Af),s=Ye();return p.useEffect(()=>{e&&(n?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,n]),null}function $f(e){return e.connection.inProgress?{...e.connection,to:Er(e.connection.to,e.transform)}:{...e.connection}}function Bf(e){return $f}function Of(e){const n=Bf();return Le(n,Ke)}const zf=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function Hf({containerStyle:e,style:n,type:s,component:r}){const{nodesConnectable:i,width:o,height:a,isValid:l,inProgress:c}=Le(zf,Ke);return!(o&&i&&c)?null:t.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:tt(["react-flow__connection",Ci(l)]),children:t.jsx(El,{style:n,type:s,CustomComponent:r,isValid:l})})})}const El=({style:e,type:n=dn.Bezier,CustomComponent:s,isValid:r})=>{const{inProgress:i,from:o,fromNode:a,fromHandle:l,fromPosition:c,to:d,toNode:f,toHandle:h,toPosition:m,pointer:u}=Of();if(!i)return;if(s)return t.jsx(s,{connectionLineType:n,connectionLineStyle:e,fromNode:a,fromHandle:l,fromX:o.x,fromY:o.y,toX:d.x,toY:d.y,fromPosition:c,toPosition:m,connectionStatus:Ci(r),toNode:f,toHandle:h,pointer:u});let g="";const C={sourceX:o.x,sourceY:o.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:m};switch(n){case dn.Bezier:[g]=$i(C);break;case dn.SimpleBezier:[g]=ml(C);break;case dn.Step:[g]=Hs({...C,borderRadius:0});break;case dn.SmoothStep:[g]=Hs(C);break;default:[g]=Oi(C)}return t.jsx("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};El.displayName="ConnectionLine";const qf={};function Da(e=qf){p.useRef(e),Ye(),p.useEffect(()=>{},[e])}function Wf(){Ye(),p.useRef(!1),p.useEffect(()=>{},[])}function Ml({nodeTypes:e,edgeTypes:n,onInit:s,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:f,onSelectionContextMenu:h,onSelectionStart:m,onSelectionEnd:u,connectionLineType:g,connectionLineStyle:C,connectionLineComponent:S,connectionLineContainerStyle:v,selectionKeyCode:y,selectionOnDrag:x,selectionMode:b,multiSelectionKeyCode:j,panActivationKeyCode:k,zoomActivationKeyCode:M,deleteKeyCode:T,onlyRenderVisibleElements:A,elementsSelectable:D,defaultViewport:E,translateExtent:P,minZoom:q,maxZoom:N,preventScrolling:O,defaultMarkerColor:_,zoomOnScroll:z,zoomOnPinch:L,panOnScroll:R,panOnScrollSpeed:$,panOnScrollMode:W,zoomOnDoubleClick:F,panOnDrag:X,onPaneClick:B,onPaneMouseEnter:I,onPaneMouseMove:Y,onPaneMouseLeave:V,onPaneScroll:H,onPaneContextMenu:Z,paneClickDistance:te,nodeClickDistance:oe,onEdgeContextMenu:ue,onEdgeMouseEnter:Q,onEdgeMouseMove:le,onEdgeMouseLeave:de,reconnectRadius:fe,onReconnect:xe,onReconnectStart:be,onReconnectEnd:U,noDragClassName:ce,noWheelClassName:pe,noPanClassName:we,disableKeyboardA11y:_e,nodeExtent:ee,rfId:Se,viewport:ae,onViewportChange:ie}){return Da(e),Da(n),Wf(),Df(s),Pf(ae),t.jsx(rf,{onPaneClick:B,onPaneMouseEnter:I,onPaneMouseMove:Y,onPaneMouseLeave:V,onPaneContextMenu:Z,onPaneScroll:H,paneClickDistance:te,deleteKeyCode:T,selectionKeyCode:y,selectionOnDrag:x,selectionMode:b,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:j,panActivationKeyCode:k,zoomActivationKeyCode:M,elementsSelectable:D,zoomOnScroll:z,zoomOnPinch:L,zoomOnDoubleClick:F,panOnScroll:R,panOnScrollSpeed:$,panOnScrollMode:W,panOnDrag:X,defaultViewport:E,translateExtent:P,minZoom:q,maxZoom:N,onSelectionContextMenu:h,preventScrolling:O,noDragClassName:ce,noWheelClassName:pe,noPanClassName:we,disableKeyboardA11y:_e,onViewportChange:ie,isControlledViewport:!!ae,children:t.jsxs(Lf,{children:[t.jsx(Rf,{edgeTypes:n,onEdgeClick:i,onEdgeDoubleClick:a,onReconnect:xe,onReconnectStart:be,onReconnectEnd:U,onlyRenderVisibleElements:A,onEdgeContextMenu:ue,onEdgeMouseEnter:Q,onEdgeMouseMove:le,onEdgeMouseLeave:de,reconnectRadius:fe,defaultMarkerColor:_,noPanClassName:we,disableKeyboardA11y:_e,rfId:Se}),t.jsx(Hf,{style:C,type:g,component:S,containerStyle:v}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(hf,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:f,nodeClickDistance:oe,onlyRenderVisibleElements:A,noPanClassName:we,noDragClassName:ce,disableKeyboardA11y:_e,nodeExtent:ee,rfId:Se}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}Ml.displayName="GraphView";const Ff=p.memo(Ml),Aa=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c=.5,maxZoom:d=2,nodeOrigin:f,nodeExtent:h,zIndexMode:m="basic"}={})=>{const u=new Map,g=new Map,C=new Map,S=new Map,v=r??n??[],y=s??e??[],x=f??[0,0],b=h??xr;qi(C,S,v);const j=Ws(y,u,g,{nodeOrigin:x,nodeExtent:b,zIndexMode:m});let k=[0,0,1];if(a&&i&&o){const M=Cr(u,{filter:E=>!!((E.width||E.initialWidth)&&(E.height||E.initialHeight))}),{x:T,y:A,zoom:D}=Js(M,i,o,c,d,l?.padding??.1);k=[T,A,D]}return{rfId:"1",width:i??0,height:o??0,transform:k,nodes:y,nodesInitialized:j,nodeLookup:u,parentLookup:g,edges:v,edgeLookup:S,connectionLookup:C,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:xr,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Un.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:x,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:a??!1,fitViewOptions:l,fitViewResolver:null,connection:{...Ni},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:ad,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:ji,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},Vf=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:f,nodeExtent:h,zIndexMode:m})=>lu((u,g)=>{async function C(){const{nodeLookup:S,panZoom:v,fitViewOptions:y,fitViewResolver:x,width:b,height:j,minZoom:k,maxZoom:M}=g();v&&(await sd({nodes:S,width:b,height:j,panZoom:v,minZoom:k,maxZoom:M},y),x?.resolve(!0),u({fitViewResolver:null}))}return{...Aa({nodes:e,edges:n,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:f,nodeExtent:h,defaultNodes:s,defaultEdges:r,zIndexMode:m}),setNodes:S=>{const{nodeLookup:v,parentLookup:y,nodeOrigin:x,elevateNodesOnSelect:b,fitViewQueued:j,zIndexMode:k}=g(),M=Ws(S,v,y,{nodeOrigin:x,nodeExtent:h,elevateNodesOnSelect:b,checkEquality:!0,zIndexMode:k});j&&M?(C(),u({nodes:S,nodesInitialized:M,fitViewQueued:!1,fitViewOptions:void 0})):u({nodes:S,nodesInitialized:M})},setEdges:S=>{const{connectionLookup:v,edgeLookup:y}=g();qi(v,y,S),u({edges:S})},setDefaultNodesAndEdges:(S,v)=>{if(S){const{setNodes:y}=g();y(S),u({hasDefaultNodes:!0})}if(v){const{setEdges:y}=g();y(v),u({hasDefaultEdges:!0})}},updateNodeInternals:S=>{const{triggerNodeChanges:v,nodeLookup:y,parentLookup:x,domNode:b,nodeOrigin:j,nodeExtent:k,debug:M,fitViewQueued:T,zIndexMode:A}=g(),{changes:D,updatedInternals:E}=Md(S,y,x,b,j,k,A);E&&(Nd(y,x,{nodeOrigin:j,nodeExtent:k,zIndexMode:A}),T?(C(),u({fitViewQueued:!1,fitViewOptions:void 0})):u({}),D?.length>0&&(M&&console.log("React Flow: trigger node changes",D),v?.(D)))},updateNodePositions:(S,v=!1)=>{const y=[];let x=[];const{nodeLookup:b,triggerNodeChanges:j,connection:k,updateConnection:M,onNodesChangeMiddlewareMap:T}=g();for(const[A,D]of S){const E=b.get(A),P=!!(E?.expandParent&&E?.parentId&&D?.position),q={id:A,type:"position",position:P?{x:Math.max(0,D.position.x),y:Math.max(0,D.position.y)}:D.position,dragging:v};if(E&&k.inProgress&&k.fromNode.id===E.id){const N=Tn(E,k.fromHandle,ye.Left,!0);M({...k,from:N})}P&&E.parentId&&y.push({id:A,parentId:E.parentId,rect:{...D.internals.positionAbsolute,width:D.measured.width??0,height:D.measured.height??0}}),x.push(q)}if(y.length>0){const{parentLookup:A,nodeOrigin:D}=g(),E=oo(y,b,A,D);x.push(...E)}for(const A of T.values())x=A(x);j(x)},triggerNodeChanges:S=>{const{onNodesChange:v,setNodes:y,nodes:x,hasDefaultNodes:b,debug:j}=g();if(S?.length){if(b){const k=rl(S,x);y(k)}j&&console.log("React Flow: trigger node changes",S),v?.(S)}},triggerEdgeChanges:S=>{const{onEdgesChange:v,setEdges:y,edges:x,hasDefaultEdges:b,debug:j}=g();if(S?.length){if(b){const k=sl(S,x);y(k)}j&&console.log("React Flow: trigger edge changes",S),v?.(S)}},addSelectedNodes:S=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:x,triggerNodeChanges:b,triggerEdgeChanges:j}=g();if(v){const k=S.map(M=>En(M,!0));b(k);return}b(Yn(x,new Set([...S]),!0)),j(Yn(y))},addSelectedEdges:S=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:x,triggerNodeChanges:b,triggerEdgeChanges:j}=g();if(v){const k=S.map(M=>En(M,!0));j(k);return}j(Yn(y,new Set([...S]))),b(Yn(x,new Set,!0))},unselectNodesAndEdges:({nodes:S,edges:v}={})=>{const{edges:y,nodes:x,nodeLookup:b,triggerNodeChanges:j,triggerEdgeChanges:k}=g(),M=S||x,T=v||y,A=[];for(const E of M){if(!E.selected)continue;const P=b.get(E.id);P&&(P.selected=!1),A.push(En(E.id,!1))}const D=[];for(const E of T)E.selected&&D.push(En(E.id,!1));j(A),k(D)},setMinZoom:S=>{const{panZoom:v,maxZoom:y}=g();v?.setScaleExtent([S,y]),u({minZoom:S})},setMaxZoom:S=>{const{panZoom:v,minZoom:y}=g();v?.setScaleExtent([y,S]),u({maxZoom:S})},setTranslateExtent:S=>{g().panZoom?.setTranslateExtent(S),u({translateExtent:S})},resetSelectedElements:()=>{const{edges:S,nodes:v,triggerNodeChanges:y,triggerEdgeChanges:x,elementsSelectable:b}=g();if(!b)return;const j=v.reduce((M,T)=>T.selected?[...M,En(T.id,!1)]:M,[]),k=S.reduce((M,T)=>T.selected?[...M,En(T.id,!1)]:M,[]);y(j),x(k)},setNodeExtent:S=>{const{nodes:v,nodeLookup:y,parentLookup:x,nodeOrigin:b,elevateNodesOnSelect:j,nodeExtent:k,zIndexMode:M}=g();S[0][0]===k[0][0]&&S[0][1]===k[0][1]&&S[1][0]===k[1][0]&&S[1][1]===k[1][1]||(Ws(v,y,x,{nodeOrigin:b,nodeExtent:S,elevateNodesOnSelect:j,checkEquality:!1,zIndexMode:M}),u({nodeExtent:S}))},panBy:S=>{const{transform:v,width:y,height:x,panZoom:b,translateExtent:j}=g();return Id({delta:S,panZoom:b,transform:v,translateExtent:j,width:y,height:x})},setCenter:async(S,v,y)=>{const{width:x,height:b,maxZoom:j,panZoom:k}=g();if(!k)return Promise.resolve(!1);const M=typeof y?.zoom<"u"?y.zoom:j;return await k.setViewport({x:x/2-S*M,y:b/2-v*M,zoom:M},{duration:y?.duration,ease:y?.ease,interpolate:y?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{u({connection:{...Ni}})},updateConnection:S=>{u({connection:S})},reset:()=>u({...Aa()})}},Object.is);function Yf({initialNodes:e,initialEdges:n,defaultNodes:s,defaultEdges:r,initialWidth:i,initialHeight:o,initialMinZoom:a,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:f,nodeExtent:h,zIndexMode:m,children:u}){const[g]=p.useState(()=>Vf({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:d,minZoom:a,maxZoom:l,fitViewOptions:c,nodeOrigin:f,nodeExtent:h,zIndexMode:m}));return t.jsx(cu,{value:g,children:t.jsx(_u,{children:u})})}function Gf({children:e,nodes:n,edges:s,defaultNodes:r,defaultEdges:i,width:o,height:a,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:f,nodeOrigin:h,nodeExtent:m,zIndexMode:u}){return p.useContext(ps)?t.jsx(t.Fragment,{children:e}):t.jsx(Yf,{initialNodes:n,initialEdges:s,defaultNodes:r,defaultEdges:i,initialWidth:o,initialHeight:a,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:f,nodeOrigin:h,nodeExtent:m,zIndexMode:u,children:e})}const Kf={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function Uf({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,className:i,nodeTypes:o,edgeTypes:a,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:f,onMoveStart:h,onMoveEnd:m,onConnect:u,onConnectStart:g,onConnectEnd:C,onClickConnectStart:S,onClickConnectEnd:v,onNodeMouseEnter:y,onNodeMouseMove:x,onNodeMouseLeave:b,onNodeContextMenu:j,onNodeDoubleClick:k,onNodeDragStart:M,onNodeDrag:T,onNodeDragStop:A,onNodesDelete:D,onEdgesDelete:E,onDelete:P,onSelectionChange:q,onSelectionDragStart:N,onSelectionDrag:O,onSelectionDragStop:_,onSelectionContextMenu:z,onSelectionStart:L,onSelectionEnd:R,onBeforeDelete:$,connectionMode:W,connectionLineType:F=dn.Bezier,connectionLineStyle:X,connectionLineComponent:B,connectionLineContainerStyle:I,deleteKeyCode:Y="Backspace",selectionKeyCode:V="Shift",selectionOnDrag:H=!1,selectionMode:Z=br.Full,panActivationKeyCode:te="Space",multiSelectionKeyCode:oe=wr()?"Meta":"Control",zoomActivationKeyCode:ue=wr()?"Meta":"Control",snapToGrid:Q,snapGrid:le,onlyRenderVisibleElements:de=!1,selectNodesOnDrag:fe,nodesDraggable:xe,autoPanOnNodeFocus:be,nodesConnectable:U,nodesFocusable:ce,nodeOrigin:pe=tl,edgesFocusable:we,edgesReconnectable:_e,elementsSelectable:ee=!0,defaultViewport:Se=ku,minZoom:ae=.5,maxZoom:ie=2,translateExtent:me=xr,preventScrolling:Ge=!0,nodeExtent:Ne,defaultMarkerColor:je="#b1b1b7",zoomOnScroll:Ze=!0,zoomOnPinch:yt=!0,panOnScroll:wt=!1,panOnScrollSpeed:lt=.5,panOnScrollMode:vt=Mn.Free,zoomOnDoubleClick:Je=!0,panOnDrag:$e=!0,onPaneClick:ft,onPaneMouseEnter:at,onPaneMouseMove:zt,onPaneMouseLeave:kt,onPaneScroll:dt,onPaneContextMenu:Yt,paneClickDistance:jt=1,nodeClickDistance:hn=0,children:ve,onReconnect:ct,onReconnectStart:ht,onReconnectEnd:mt,onEdgeContextMenu:pt,onEdgeDoubleClick:Ht,onEdgeMouseEnter:bt,onEdgeMouseMove:Re,onEdgeMouseLeave:qe,reconnectRadius:gt=10,onNodesChange:qt,onEdgesChange:Wt,noDragClassName:Xe="nodrag",noWheelClassName:Pe="nowheel",noPanClassName:ze="nopan",fitView:De,fitViewOptions:We,connectOnClick:nt,attributionPosition:Qe,proOptions:Nt,defaultEdgeOptions:it,elevateNodesOnSelect:G=!0,elevateEdgesOnSelect:ge=!1,disableKeyboardA11y:Ie=!1,autoPanOnConnect:Te,autoPanOnNodeDrag:Ee,autoPanSpeed:rt,connectionRadius:mn,isValidConnection:Rn,onError:nr,style:Ct,id:pn,nodeDragThreshold:tn,connectionDragThreshold:Mr,viewport:rr,onViewportChange:nn,width:_n,height:Ln,colorMode:sr="light",debug:gn,onScroll:rn,ariaLabelConfig:sn,zIndexMode:xn="basic",...bn},Ir){const or=pn||"1",Dn=Su(sr),ar=p.useCallback(Gt=>{Gt.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),rn?.(Gt)},[rn]);return t.jsx("div",{"data-testid":"rf__wrapper",...bn,onScroll:ar,style:{...Ct,...Kf},ref:Ir,className:tt(["react-flow",i,Dn]),id:pn,role:"application",children:t.jsxs(Gf,{nodes:e,edges:n,width:_n,height:Ln,fitView:De,fitViewOptions:We,minZoom:ae,maxZoom:ie,nodeOrigin:pe,nodeExtent:Ne,zIndexMode:xn,children:[t.jsx(Ff,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:x,onNodeMouseLeave:b,onNodeContextMenu:j,onNodeDoubleClick:k,nodeTypes:o,edgeTypes:a,connectionLineType:F,connectionLineStyle:X,connectionLineComponent:B,connectionLineContainerStyle:I,selectionKeyCode:V,selectionOnDrag:H,selectionMode:Z,deleteKeyCode:Y,multiSelectionKeyCode:oe,panActivationKeyCode:te,zoomActivationKeyCode:ue,onlyRenderVisibleElements:de,defaultViewport:Se,translateExtent:me,minZoom:ae,maxZoom:ie,preventScrolling:Ge,zoomOnScroll:Ze,zoomOnPinch:yt,zoomOnDoubleClick:Je,panOnScroll:wt,panOnScrollSpeed:lt,panOnScrollMode:vt,panOnDrag:$e,onPaneClick:ft,onPaneMouseEnter:at,onPaneMouseMove:zt,onPaneMouseLeave:kt,onPaneScroll:dt,onPaneContextMenu:Yt,paneClickDistance:jt,nodeClickDistance:hn,onSelectionContextMenu:z,onSelectionStart:L,onSelectionEnd:R,onReconnect:ct,onReconnectStart:ht,onReconnectEnd:mt,onEdgeContextMenu:pt,onEdgeDoubleClick:Ht,onEdgeMouseEnter:bt,onEdgeMouseMove:Re,onEdgeMouseLeave:qe,reconnectRadius:gt,defaultMarkerColor:je,noDragClassName:Xe,noWheelClassName:Pe,noPanClassName:ze,rfId:or,disableKeyboardA11y:Ie,nodeExtent:Ne,viewport:rr,onViewportChange:nn}),t.jsx(Cu,{nodes:e,edges:n,defaultNodes:s,defaultEdges:r,onConnect:u,onConnectStart:g,onConnectEnd:C,onClickConnectStart:S,onClickConnectEnd:v,nodesDraggable:xe,autoPanOnNodeFocus:be,nodesConnectable:U,nodesFocusable:ce,edgesFocusable:we,edgesReconnectable:_e,elementsSelectable:ee,elevateNodesOnSelect:G,elevateEdgesOnSelect:ge,minZoom:ae,maxZoom:ie,nodeExtent:Ne,onNodesChange:qt,onEdgesChange:Wt,snapToGrid:Q,snapGrid:le,connectionMode:W,translateExtent:me,connectOnClick:nt,defaultEdgeOptions:it,fitView:De,fitViewOptions:We,onNodesDelete:D,onEdgesDelete:E,onDelete:P,onNodeDragStart:M,onNodeDrag:T,onNodeDragStop:A,onSelectionDrag:O,onSelectionDragStart:N,onSelectionDragStop:_,onMove:f,onMoveStart:h,onMoveEnd:m,noPanClassName:ze,nodeOrigin:pe,rfId:or,autoPanOnConnect:Te,autoPanOnNodeDrag:Ee,autoPanSpeed:rt,onError:nr,connectionRadius:mn,isValidConnection:Rn,selectNodesOnDrag:fe,nodeDragThreshold:tn,connectionDragThreshold:Mr,onBeforeDelete:$,debug:gn,ariaLabelConfig:sn,zIndexMode:xn}),t.jsx(vu,{onSelectionChange:q}),ve,t.jsx(gu,{proOptions:Nt,position:Qe}),t.jsx(pu,{rfId:or,disableKeyboardA11y:Ie})]})})}var Zf=ol(Uf);function Xf(){const e=Ye();return p.useCallback(n=>{const{domNode:s,updateNodeInternals:r}=e.getState(),i=Array.isArray(n)?n:[n],o=new Map;i.forEach(a=>{const l=s?.querySelector(`.react-flow__node[data-id="${a}"]`);l&&o.set(a,{id:a,nodeElement:l,force:!0})}),requestAnimationFrame(()=>r(o,{triggerFitView:!1}))},[])}function Qf(e){const[n,s]=p.useState(e),r=p.useCallback(i=>s(o=>rl(i,o)),[]);return[n,s,r]}function Jf(e){const[n,s]=p.useState(e),r=p.useCallback(i=>s(o=>sl(i,o)),[]);return[n,s,r]}function eh({dimensions:e,lineWidth:n,variant:s,className:r}){return t.jsx("path",{strokeWidth:n,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:tt(["react-flow__background-pattern",s,r])})}function th({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:tt(["react-flow__background-pattern","dots",n])})}var un;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(un||(un={}));const nh={[un.Dots]:1,[un.Lines]:1,[un.Cross]:6},rh=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Il({id:e,variant:n=un.Dots,gap:s=20,size:r,lineWidth:i=1,offset:o=0,color:a,bgColor:l,style:c,className:d,patternClassName:f}){const h=p.useRef(null),{transform:m,patternId:u}=Le(rh,Ke),g=r||nh[n],C=n===un.Dots,S=n===un.Cross,v=Array.isArray(s)?s:[s,s],y=[v[0]*m[2]||1,v[1]*m[2]||1],x=g*m[2],b=Array.isArray(o)?o:[o,o],j=S?[x,x]:y,k=[b[0]*m[2]||1+j[0]/2,b[1]*m[2]||1+j[1]/2],M=`${u}${e||""}`;return t.jsxs("svg",{className:tt(["react-flow__background",d]),style:{...c,...xs,"--xy-background-color-props":l,"--xy-background-pattern-color-props":a},ref:h,"data-testid":"rf__background",children:[t.jsx("pattern",{id:M,x:m[0]%y[0],y:m[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${k[0]},-${k[1]})`,children:C?t.jsx(th,{radius:x/2,className:f}):t.jsx(eh,{dimensions:j,lineWidth:i,variant:n,className:f})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}Il.displayName="Background";const sh=p.memo(Il);function oh(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:t.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function ah(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:t.jsx("path",{d:"M0 0h32v4.2H0z"})})}function ih(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:t.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function lh(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function ch(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Zr({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:tt(["react-flow__controls-button",n]),...s,children:e})}const dh=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Tl({style:e,showZoom:n=!0,showFitView:s=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:o,onZoomOut:a,onFitView:l,onInteractiveChange:c,className:d,children:f,position:h="bottom-left",orientation:m="vertical","aria-label":u}){const g=Ye(),{isInteractive:C,minZoomReached:S,maxZoomReached:v,ariaLabelConfig:y}=Le(dh,Ke),{zoomIn:x,zoomOut:b,fitView:j}=ao(),k=()=>{x(),o?.()},M=()=>{b(),a?.()},T=()=>{j(i),l?.()},A=()=>{g.setState({nodesDraggable:!C,nodesConnectable:!C,elementsSelectable:!C}),c?.(!C)},D=m==="horizontal"?"horizontal":"vertical";return t.jsxs(gs,{className:tt(["react-flow__controls",D,d]),position:h,style:e,"data-testid":"rf__controls","aria-label":u??y["controls.ariaLabel"],children:[n&&t.jsxs(t.Fragment,{children:[t.jsx(Zr,{onClick:k,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:v,children:t.jsx(oh,{})}),t.jsx(Zr,{onClick:M,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:S,children:t.jsx(ah,{})})]}),s&&t.jsx(Zr,{className:"react-flow__controls-fitview",onClick:T,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:t.jsx(ih,{})}),r&&t.jsx(Zr,{className:"react-flow__controls-interactive",onClick:A,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:C?t.jsx(ch,{}):t.jsx(lh,{})}),f]})}Tl.displayName="Controls";const uh=p.memo(Tl);function fh({id:e,x:n,y:s,width:r,height:i,style:o,color:a,strokeColor:l,strokeWidth:c,className:d,borderRadius:f,shapeRendering:h,selected:m,onClick:u}){const{background:g,backgroundColor:C}=o||{},S=a||g||C;return t.jsx("rect",{className:tt(["react-flow__minimap-node",{selected:m},d]),x:n,y:s,rx:f,ry:f,width:r,height:i,style:{fill:S,stroke:l,strokeWidth:c},shapeRendering:h,onClick:u?v=>u(v,e):void 0})}const hh=p.memo(fh),mh=e=>e.nodes.map(n=>n.id),As=e=>e instanceof Function?e:()=>e;function ph({nodeStrokeColor:e,nodeColor:n,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:o=hh,onClick:a}){const l=Le(mh,Ke),c=As(n),d=As(e),f=As(s),h=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:l.map(m=>t.jsx(xh,{id:m,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:f,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:o,onClick:a,shapeRendering:h},m))})}function gh({id:e,nodeColorFunc:n,nodeStrokeColorFunc:s,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:o,shapeRendering:a,NodeComponent:l,onClick:c}){const{node:d,x:f,y:h,width:m,height:u}=Le(g=>{const C=g.nodeLookup.get(e);if(!C)return{node:void 0,x:0,y:0,width:0,height:0};const S=C.internals.userNode,{x:v,y}=C.internals.positionAbsolute,{width:x,height:b}=en(S);return{node:S,x:v,y,width:x,height:b}},Ke);return!d||d.hidden||!Ri(d)?null:t.jsx(l,{x:f,y:h,width:m,height:u,style:d.style,selected:!!d.selected,className:r(d),color:n(d),borderRadius:i,strokeColor:s(d),strokeWidth:o,shapeRendering:a,onClick:c,id:d.id})}const xh=p.memo(gh);var bh=p.memo(ph);const yh=200,wh=150,vh=e=>!e.hidden,kh=e=>{const n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:e.nodeLookup.size>0?Ti(Cr(e.nodeLookup,{filter:vh}),n):n,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},jh="react-flow__minimap-desc";function Rl({style:e,className:n,nodeStrokeColor:s,nodeColor:r,nodeClassName:i="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:f,maskStrokeWidth:h,position:m="bottom-right",onClick:u,onNodeClick:g,pannable:C=!1,zoomable:S=!1,ariaLabel:v,inversePan:y,zoomStep:x=1,offsetScale:b=5}){const j=Ye(),k=p.useRef(null),{boundingRect:M,viewBB:T,rfId:A,panZoom:D,translateExtent:E,flowWidth:P,flowHeight:q,ariaLabelConfig:N}=Le(kh,Ke),O=e?.width??yh,_=e?.height??wh,z=M.width/O,L=M.height/_,R=Math.max(z,L),$=R*O,W=R*_,F=b*R,X=M.x-($-M.width)/2-F,B=M.y-(W-M.height)/2-F,I=$+F*2,Y=W+F*2,V=`${jh}-${A}`,H=p.useRef(0),Z=p.useRef();H.current=R,p.useEffect(()=>{if(k.current&&D)return Z.current=Bd({domNode:k.current,panZoom:D,getTransform:()=>j.getState().transform,getViewScale:()=>H.current}),()=>{Z.current?.destroy()}},[D]),p.useEffect(()=>{Z.current?.update({translateExtent:E,width:P,height:q,inversePan:y,pannable:C,zoomStep:x,zoomable:S})},[C,S,y,x,E,P,q]);const te=u?Q=>{const[le,de]=Z.current?.pointer(Q)||[0,0];u(Q,{x:le,y:de})}:void 0,oe=g?p.useCallback((Q,le)=>{const de=j.getState().nodeLookup.get(le).internals.userNode;g(Q,de)},[]):void 0,ue=v??N["minimap.ariaLabel"];return t.jsx(gs,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof f=="string"?f:void 0,"--xy-minimap-mask-stroke-width-props":typeof h=="number"?h*R:void 0,"--xy-minimap-node-background-color-props":typeof r=="string"?r:void 0,"--xy-minimap-node-stroke-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-width-props":typeof a=="number"?a:void 0},className:tt(["react-flow__minimap",n]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:O,height:_,viewBox:`${X} ${B} ${I} ${Y}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":V,ref:k,onClick:te,children:[ue&&t.jsx("title",{id:V,children:ue}),t.jsx(bh,{onClick:oe,nodeColor:r,nodeStrokeColor:s,nodeBorderRadius:o,nodeClassName:i,nodeStrokeWidth:a,nodeComponent:l}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${X-F},${B-F}h${I+F*2}v${Y+F*2}h${-I-F*2}z
|
|
7
|
+
M${T.x},${T.y}h${T.width}v${T.height}h${-T.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}Rl.displayName="MiniMap";const Nh=p.memo(Rl),Ch=e=>n=>e?`${Math.max(1/n.transform[2],1)}`:void 0,Sh={[er.Line]:"right",[er.Handle]:"bottom-right"};function Eh({nodeId:e,position:n,variant:s=er.Handle,className:r,style:i=void 0,children:o,color:a,minWidth:l=10,minHeight:c=10,maxWidth:d=Number.MAX_VALUE,maxHeight:f=Number.MAX_VALUE,keepAspectRatio:h=!1,resizeDirection:m,autoScale:u=!0,shouldResize:g,onResizeStart:C,onResize:S,onResizeEnd:v}){const y=cl(),x=typeof e=="string"?e:y,b=Ye(),j=p.useRef(null),k=s===er.Handle,M=Le(p.useCallback(Ch(k&&u),[k,u]),Ke),T=p.useRef(null),A=n??Sh[s];p.useEffect(()=>{if(!(!j.current||!x))return T.current||(T.current=Qd({domNode:j.current,nodeId:x,getStoreItems:()=>{const{nodeLookup:E,transform:P,snapGrid:q,snapToGrid:N,nodeOrigin:O,domNode:_}=b.getState();return{nodeLookup:E,transform:P,snapGrid:q,snapToGrid:N,nodeOrigin:O,paneDomNode:_}},onChange:(E,P)=>{const{triggerNodeChanges:q,nodeLookup:N,parentLookup:O,nodeOrigin:_}=b.getState(),z=[],L={x:E.x,y:E.y},R=N.get(x);if(R&&R.expandParent&&R.parentId){const $=R.origin??_,W=E.width??R.measured.width??0,F=E.height??R.measured.height??0,X={id:R.id,parentId:R.parentId,rect:{width:W,height:F,..._i({x:E.x??R.position.x,y:E.y??R.position.y},{width:W,height:F},R.parentId,N,$)}},B=oo([X],N,O,_);z.push(...B),L.x=E.x?Math.max($[0]*W,E.x):void 0,L.y=E.y?Math.max($[1]*F,E.y):void 0}if(L.x!==void 0&&L.y!==void 0){const $={id:x,type:"position",position:{...L}};z.push($)}if(E.width!==void 0&&E.height!==void 0){const W={id:x,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:E.width,height:E.height}};z.push(W)}for(const $ of P){const W={...$,type:"position"};z.push(W)}q(z)},onEnd:({width:E,height:P})=>{const q={id:x,type:"dimensions",resizing:!1,dimensions:{width:E,height:P}};b.getState().triggerNodeChanges([q])}})),T.current.update({controlPosition:A,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:f},keepAspectRatio:h,resizeDirection:m,onResizeStart:C,onResize:S,onResizeEnd:v,shouldResize:g}),()=>{T.current?.destroy()}},[A,l,c,d,f,h,C,S,v,g]);const D=A.split("-");return t.jsx("div",{className:tt(["react-flow__resize-control","nodrag",...D,s,r]),ref:j,style:{...i,scale:M,...a&&{[k?"backgroundColor":"borderColor"]:a}},children:o})}p.memo(Eh);var Be=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),Ot=Be((e,n)=>{var s=Object.defineProperty,r=(q,N,O)=>N in q?s(q,N,{enumerable:!0,configurable:!0,writable:!0,value:O}):q[N]=O,i=(q,N)=>()=>(N||q((N={exports:{}}).exports,N),N.exports),o=(q,N,O)=>r(q,typeof N!="symbol"?N+"":N,O),a=i((q,N)=>{var O="\0",_="\0",z="",L=class{constructor(B){o(this,"_isDirected",!0),o(this,"_isMultigraph",!1),o(this,"_isCompound",!1),o(this,"_label"),o(this,"_defaultNodeLabelFn",()=>{}),o(this,"_defaultEdgeLabelFn",()=>{}),o(this,"_nodes",{}),o(this,"_in",{}),o(this,"_preds",{}),o(this,"_out",{}),o(this,"_sucs",{}),o(this,"_edgeObjs",{}),o(this,"_edgeLabels",{}),o(this,"_nodeCount",0),o(this,"_edgeCount",0),o(this,"_parent"),o(this,"_children"),B&&(this._isDirected=Object.hasOwn(B,"directed")?B.directed:!0,this._isMultigraph=Object.hasOwn(B,"multigraph")?B.multigraph:!1,this._isCompound=Object.hasOwn(B,"compound")?B.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[_]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(B){return this._label=B,this}graph(){return this._label}setDefaultNodeLabel(B){return this._defaultNodeLabelFn=B,typeof B!="function"&&(this._defaultNodeLabelFn=()=>B),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var B=this;return this.nodes().filter(I=>Object.keys(B._in[I]).length===0)}sinks(){var B=this;return this.nodes().filter(I=>Object.keys(B._out[I]).length===0)}setNodes(B,I){var Y=arguments,V=this;return B.forEach(function(H){Y.length>1?V.setNode(H,I):V.setNode(H)}),this}setNode(B,I){return Object.hasOwn(this._nodes,B)?(arguments.length>1&&(this._nodes[B]=I),this):(this._nodes[B]=arguments.length>1?I:this._defaultNodeLabelFn(B),this._isCompound&&(this._parent[B]=_,this._children[B]={},this._children[_][B]=!0),this._in[B]={},this._preds[B]={},this._out[B]={},this._sucs[B]={},++this._nodeCount,this)}node(B){return this._nodes[B]}hasNode(B){return Object.hasOwn(this._nodes,B)}removeNode(B){var I=this;if(Object.hasOwn(this._nodes,B)){var Y=V=>I.removeEdge(I._edgeObjs[V]);delete this._nodes[B],this._isCompound&&(this._removeFromParentsChildList(B),delete this._parent[B],this.children(B).forEach(function(V){I.setParent(V)}),delete this._children[B]),Object.keys(this._in[B]).forEach(Y),delete this._in[B],delete this._preds[B],Object.keys(this._out[B]).forEach(Y),delete this._out[B],delete this._sucs[B],--this._nodeCount}return this}setParent(B,I){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(I===void 0)I=_;else{I+="";for(var Y=I;Y!==void 0;Y=this.parent(Y))if(Y===B)throw new Error("Setting "+I+" as parent of "+B+" would create a cycle");this.setNode(I)}return this.setNode(B),this._removeFromParentsChildList(B),this._parent[B]=I,this._children[I][B]=!0,this}_removeFromParentsChildList(B){delete this._children[this._parent[B]][B]}parent(B){if(this._isCompound){var I=this._parent[B];if(I!==_)return I}}children(B=_){if(this._isCompound){var I=this._children[B];if(I)return Object.keys(I)}else{if(B===_)return this.nodes();if(this.hasNode(B))return[]}}predecessors(B){var I=this._preds[B];if(I)return Object.keys(I)}successors(B){var I=this._sucs[B];if(I)return Object.keys(I)}neighbors(B){var I=this.predecessors(B);if(I){let V=new Set(I);for(var Y of this.successors(B))V.add(Y);return Array.from(V.values())}}isLeaf(B){var I;return this.isDirected()?I=this.successors(B):I=this.neighbors(B),I.length===0}filterNodes(B){var I=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});I.setGraph(this.graph());var Y=this;Object.entries(this._nodes).forEach(function([Z,te]){B(Z)&&I.setNode(Z,te)}),Object.values(this._edgeObjs).forEach(function(Z){I.hasNode(Z.v)&&I.hasNode(Z.w)&&I.setEdge(Z,Y.edge(Z))});var V={};function H(Z){var te=Y.parent(Z);return te===void 0||I.hasNode(te)?(V[Z]=te,te):te in V?V[te]:H(te)}return this._isCompound&&I.nodes().forEach(Z=>I.setParent(Z,H(Z))),I}setDefaultEdgeLabel(B){return this._defaultEdgeLabelFn=B,typeof B!="function"&&(this._defaultEdgeLabelFn=()=>B),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(B,I){var Y=this,V=arguments;return B.reduce(function(H,Z){return V.length>1?Y.setEdge(H,Z,I):Y.setEdge(H,Z),Z}),this}setEdge(){var B,I,Y,V,H=!1,Z=arguments[0];typeof Z=="object"&&Z!==null&&"v"in Z?(B=Z.v,I=Z.w,Y=Z.name,arguments.length===2&&(V=arguments[1],H=!0)):(B=Z,I=arguments[1],Y=arguments[3],arguments.length>2&&(V=arguments[2],H=!0)),B=""+B,I=""+I,Y!==void 0&&(Y=""+Y);var te=W(this._isDirected,B,I,Y);if(Object.hasOwn(this._edgeLabels,te))return H&&(this._edgeLabels[te]=V),this;if(Y!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(B),this.setNode(I),this._edgeLabels[te]=H?V:this._defaultEdgeLabelFn(B,I,Y);var oe=F(this._isDirected,B,I,Y);return B=oe.v,I=oe.w,Object.freeze(oe),this._edgeObjs[te]=oe,R(this._preds[I],B),R(this._sucs[B],I),this._in[I][te]=oe,this._out[B][te]=oe,this._edgeCount++,this}edge(B,I,Y){var V=arguments.length===1?X(this._isDirected,arguments[0]):W(this._isDirected,B,I,Y);return this._edgeLabels[V]}edgeAsObj(){let B=this.edge(...arguments);return typeof B!="object"?{label:B}:B}hasEdge(B,I,Y){var V=arguments.length===1?X(this._isDirected,arguments[0]):W(this._isDirected,B,I,Y);return Object.hasOwn(this._edgeLabels,V)}removeEdge(B,I,Y){var V=arguments.length===1?X(this._isDirected,arguments[0]):W(this._isDirected,B,I,Y),H=this._edgeObjs[V];return H&&(B=H.v,I=H.w,delete this._edgeLabels[V],delete this._edgeObjs[V],$(this._preds[I],B),$(this._sucs[B],I),delete this._in[I][V],delete this._out[B][V],this._edgeCount--),this}inEdges(B,I){return this.isDirected()?this.filterEdges(this._in[B],B,I):this.nodeEdges(B,I)}outEdges(B,I){return this.isDirected()?this.filterEdges(this._out[B],B,I):this.nodeEdges(B,I)}nodeEdges(B,I){if(B in this._nodes)return this.filterEdges({...this._in[B],...this._out[B]},B,I)}filterEdges(B,I,Y){if(B){var V=Object.values(B);return Y?V.filter(function(H){return H.v===I&&H.w===Y||H.v===Y&&H.w===I}):V}}};function R(B,I){B[I]?B[I]++:B[I]=1}function $(B,I){--B[I]||delete B[I]}function W(B,I,Y,V){var H=""+I,Z=""+Y;if(!B&&H>Z){var te=H;H=Z,Z=te}return H+z+Z+z+(V===void 0?O:V)}function F(B,I,Y,V){var H=""+I,Z=""+Y;if(!B&&H>Z){var te=H;H=Z,Z=te}var oe={v:H,w:Z};return V&&(oe.name=V),oe}function X(B,I){return W(B,I.v,I.w,I.name)}N.exports=L}),l=i((q,N)=>{N.exports="3.0.2"}),c=i((q,N)=>{N.exports={Graph:a(),version:l()}}),d=i((q,N)=>{var O=a();N.exports={write:_,read:R};function _($){var W={options:{directed:$.isDirected(),multigraph:$.isMultigraph(),compound:$.isCompound()},nodes:z($),edges:L($)};return $.graph()!==void 0&&(W.value=structuredClone($.graph())),W}function z($){return $.nodes().map(function(W){var F=$.node(W),X=$.parent(W),B={v:W};return F!==void 0&&(B.value=F),X!==void 0&&(B.parent=X),B})}function L($){return $.edges().map(function(W){var F=$.edge(W),X={v:W.v,w:W.w};return W.name!==void 0&&(X.name=W.name),F!==void 0&&(X.value=F),X})}function R($){var W=new O($.options).setGraph($.value);return $.nodes.forEach(function(F){W.setNode(F.v,F.value),F.parent&&W.setParent(F.v,F.parent)}),$.edges.forEach(function(F){W.setEdge({v:F.v,w:F.w,name:F.name},F.value)}),W}}),f=i((q,N)=>{N.exports=_;var O=()=>1;function _(L,R,$,W){return z(L,String(R),$||O,W||function(F){return L.outEdges(F)})}function z(L,R,$,W){var F={},X=!0,B=0,I=L.nodes(),Y=function(te){var oe=$(te);F[te.v].distance+oe<F[te.w].distance&&(F[te.w]={distance:F[te.v].distance+oe,predecessor:te.v},X=!0)},V=function(){I.forEach(function(te){W(te).forEach(function(oe){var ue=oe.v===te?oe.v:oe.w,Q=ue===oe.v?oe.w:oe.v;Y({v:ue,w:Q})})})};I.forEach(function(te){var oe=te===R?0:Number.POSITIVE_INFINITY;F[te]={distance:oe}});for(var H=I.length,Z=1;Z<H&&(X=!1,B++,V(),!!X);Z++);if(B===H-1&&(X=!1,V(),X))throw new Error("The graph contains a negative weight cycle");return F}}),h=i((q,N)=>{N.exports=O;function O(_){var z={},L=[],R;function $(W){Object.hasOwn(z,W)||(z[W]=!0,R.push(W),_.successors(W).forEach($),_.predecessors(W).forEach($))}return _.nodes().forEach(function(W){R=[],$(W),R.length&&L.push(R)}),L}}),m=i((q,N)=>{var O=class{constructor(){o(this,"_arr",[]),o(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(_){return _.key})}has(_){return Object.hasOwn(this._keyIndices,_)}priority(_){var z=this._keyIndices[_];if(z!==void 0)return this._arr[z].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(_,z){var L=this._keyIndices;if(_=String(_),!Object.hasOwn(L,_)){var R=this._arr,$=R.length;return L[_]=$,R.push({key:_,priority:z}),this._decrease($),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var _=this._arr.pop();return delete this._keyIndices[_.key],this._heapify(0),_.key}decrease(_,z){var L=this._keyIndices[_];if(z>this._arr[L].priority)throw new Error("New priority is greater than current priority. Key: "+_+" Old: "+this._arr[L].priority+" New: "+z);this._arr[L].priority=z,this._decrease(L)}_heapify(_){var z=this._arr,L=2*_,R=L+1,$=_;L<z.length&&($=z[L].priority<z[$].priority?L:$,R<z.length&&($=z[R].priority<z[$].priority?R:$),$!==_&&(this._swap(_,$),this._heapify($)))}_decrease(_){for(var z=this._arr,L=z[_].priority,R;_!==0&&(R=_>>1,!(z[R].priority<L));)this._swap(_,R),_=R}_swap(_,z){var L=this._arr,R=this._keyIndices,$=L[_],W=L[z];L[_]=W,L[z]=$,R[W.key]=_,R[$.key]=z}};N.exports=O}),u=i((q,N)=>{var O=m();N.exports=z;var _=()=>1;function z(R,$,W,F){var X=function(B){return R.outEdges(B)};return L(R,String($),W||_,F||X)}function L(R,$,W,F){var X={},B=new O,I,Y,V=function(H){var Z=H.v!==I?H.v:H.w,te=X[Z],oe=W(H),ue=Y.distance+oe;if(oe<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+H+" Weight: "+oe);ue<te.distance&&(te.distance=ue,te.predecessor=I,B.decrease(Z,ue))};for(R.nodes().forEach(function(H){var Z=H===$?0:Number.POSITIVE_INFINITY;X[H]={distance:Z},B.add(H,Z)});B.size()>0&&(I=B.removeMin(),Y=X[I],Y.distance!==Number.POSITIVE_INFINITY);)F(I).forEach(V);return X}}),g=i((q,N)=>{var O=u();N.exports=_;function _(z,L,R){return z.nodes().reduce(function($,W){return $[W]=O(z,W,L,R),$},{})}}),C=i((q,N)=>{N.exports=O;function O(z,L,R){if(z[L].predecessor!==void 0)throw new Error("Invalid source vertex");if(z[R].predecessor===void 0&&R!==L)throw new Error("Invalid destination vertex");return{weight:z[R].distance,path:_(z,L,R)}}function _(z,L,R){for(var $=[],W=R;W!==L;)$.push(W),W=z[W].predecessor;return $.push(L),$.reverse()}}),S=i((q,N)=>{N.exports=O;function O(_){var z=0,L=[],R={},$=[];function W(F){var X=R[F]={onStack:!0,lowlink:z,index:z++};if(L.push(F),_.successors(F).forEach(function(Y){Object.hasOwn(R,Y)?R[Y].onStack&&(X.lowlink=Math.min(X.lowlink,R[Y].index)):(W(Y),X.lowlink=Math.min(X.lowlink,R[Y].lowlink))}),X.lowlink===X.index){var B=[],I;do I=L.pop(),R[I].onStack=!1,B.push(I);while(F!==I);$.push(B)}}return _.nodes().forEach(function(F){Object.hasOwn(R,F)||W(F)}),$}}),v=i((q,N)=>{var O=S();N.exports=_;function _(z){return O(z).filter(function(L){return L.length>1||L.length===1&&z.hasEdge(L[0],L[0])})}}),y=i((q,N)=>{N.exports=_;var O=()=>1;function _(L,R,$){return z(L,R||O,$||function(W){return L.outEdges(W)})}function z(L,R,$){var W={},F=L.nodes();return F.forEach(function(X){W[X]={},W[X][X]={distance:0},F.forEach(function(B){X!==B&&(W[X][B]={distance:Number.POSITIVE_INFINITY})}),$(X).forEach(function(B){var I=B.v===X?B.w:B.v,Y=R(B);W[X][I]={distance:Y,predecessor:X}})}),F.forEach(function(X){var B=W[X];F.forEach(function(I){var Y=W[I];F.forEach(function(V){var H=Y[X],Z=B[V],te=Y[V],oe=H.distance+Z.distance;oe<te.distance&&(te.distance=oe,te.predecessor=Z.predecessor)})})}),W}}),x=i((q,N)=>{function O(z){var L={},R={},$=[];function W(F){if(Object.hasOwn(R,F))throw new _;Object.hasOwn(L,F)||(R[F]=!0,L[F]=!0,z.predecessors(F).forEach(W),delete R[F],$.push(F))}if(z.sinks().forEach(W),Object.keys(L).length!==z.nodeCount())throw new _;return $}var _=class extends Error{constructor(){super(...arguments)}};N.exports=O,O.CycleException=_}),b=i((q,N)=>{var O=x();N.exports=_;function _(z){try{O(z)}catch(L){if(L instanceof O.CycleException)return!1;throw L}return!0}}),j=i((q,N)=>{N.exports=O;function O(z,L,R,$,W){Array.isArray(L)||(L=[L]);var F=(z.isDirected()?z.successors:z.neighbors).bind(z),X={};return L.forEach(function(B){if(!z.hasNode(B))throw new Error("Graph does not have node: "+B);W=_(z,B,R==="post",X,F,$,W)}),W}function _(z,L,R,$,W,F,X){return Object.hasOwn($,L)||($[L]=!0,R||(X=F(X,L)),W(L).forEach(function(B){X=_(z,B,R,$,W,F,X)}),R&&(X=F(X,L))),X}}),k=i((q,N)=>{var O=j();N.exports=_;function _(z,L,R){return O(z,L,R,function($,W){return $.push(W),$},[])}}),M=i((q,N)=>{var O=k();N.exports=_;function _(z,L){return O(z,L,"post")}}),T=i((q,N)=>{var O=k();N.exports=_;function _(z,L){return O(z,L,"pre")}}),A=i((q,N)=>{var O=a(),_=m();N.exports=z;function z(L,R){var $=new O,W={},F=new _,X;function B(Y){var V=Y.v===X?Y.w:Y.v,H=F.priority(V);if(H!==void 0){var Z=R(Y);Z<H&&(W[V]=X,F.decrease(V,Z))}}if(L.nodeCount()===0)return $;L.nodes().forEach(function(Y){F.add(Y,Number.POSITIVE_INFINITY),$.setNode(Y)}),F.decrease(L.nodes()[0],0);for(var I=!1;F.size()>0;){if(X=F.removeMin(),Object.hasOwn(W,X))$.setEdge(X,W[X]);else{if(I)throw new Error("Input graph is not connected: "+L);I=!0}L.nodeEdges(X).forEach(B)}return $}}),D=i((q,N)=>{var O=u(),_=f();N.exports=z;function z(R,$,W,F){return L(R,$,W,F||function(X){return R.outEdges(X)})}function L(R,$,W,F){if(W===void 0)return O(R,$,W,F);for(var X=!1,B=R.nodes(),I=0;I<B.length;I++){for(var Y=F(B[I]),V=0;V<Y.length;V++){var H=Y[V],Z=H.v===B[I]?H.v:H.w,te=Z===H.v?H.w:H.v;W({v:Z,w:te})<0&&(X=!0)}if(X)return _(R,$,W,F)}return O(R,$,W,F)}}),E=i((q,N)=>{N.exports={bellmanFord:f(),components:h(),dijkstra:u(),dijkstraAll:g(),extractPath:C(),findCycles:v(),floydWarshall:y(),isAcyclic:b(),postorder:M(),preorder:T(),prim:A(),shortestPaths:D(),reduce:j(),tarjan:S(),topsort:x()}}),P=c();n.exports={Graph:P.Graph,json:d(),alg:E(),version:P.version}}),Mh=Be((e,n)=>{var s=class{constructor(){let o={};o._next=o._prev=o,this._sentinel=o}dequeue(){let o=this._sentinel,a=o._prev;if(a!==o)return r(a),a}enqueue(o){let a=this._sentinel;o._prev&&o._next&&r(o),o._next=a._next,a._next._prev=o,a._next=o,o._prev=a}toString(){let o=[],a=this._sentinel,l=a._prev;for(;l!==a;)o.push(JSON.stringify(l,i)),l=l._prev;return"["+o.join(", ")+"]"}};function r(o){o._prev._next=o._next,o._next._prev=o._prev,delete o._next,delete o._prev}function i(o,a){if(o!=="_next"&&o!=="_prev")return a}n.exports=s}),Ih=Be((e,n)=>{var s=Ot().Graph,r=Mh();n.exports=o;var i=()=>1;function o(h,m){if(h.nodeCount()<=1)return[];let u=c(h,m||i);return a(u.graph,u.buckets,u.zeroIdx).flatMap(g=>h.outEdges(g.v,g.w))}function a(h,m,u){let g=[],C=m[m.length-1],S=m[0],v;for(;h.nodeCount();){for(;v=S.dequeue();)l(h,m,u,v);for(;v=C.dequeue();)l(h,m,u,v);if(h.nodeCount()){for(let y=m.length-2;y>0;--y)if(v=m[y].dequeue(),v){g=g.concat(l(h,m,u,v,!0));break}}}return g}function l(h,m,u,g,C){let S=C?[]:void 0;return h.inEdges(g.v).forEach(v=>{let y=h.edge(v),x=h.node(v.v);C&&S.push({v:v.v,w:v.w}),x.out-=y,d(m,u,x)}),h.outEdges(g.v).forEach(v=>{let y=h.edge(v),x=v.w,b=h.node(x);b.in-=y,d(m,u,b)}),h.removeNode(g.v),S}function c(h,m){let u=new s,g=0,C=0;h.nodes().forEach(y=>{u.setNode(y,{v:y,in:0,out:0})}),h.edges().forEach(y=>{let x=u.edge(y.v,y.w)||0,b=m(y),j=x+b;u.setEdge(y.v,y.w,j),C=Math.max(C,u.node(y.v).out+=b),g=Math.max(g,u.node(y.w).in+=b)});let S=f(C+g+3).map(()=>new r),v=g+1;return u.nodes().forEach(y=>{d(S,v,u.node(y))}),{graph:u,buckets:S,zeroIdx:v}}function d(h,m,u){u.out?u.in?h[u.out-u.in+m].enqueue(u):h[h.length-1].enqueue(u):h[0].enqueue(u)}function f(h){let m=[];for(let u=0;u<h;u++)m.push(u);return m}}),et=Be((e,n)=>{var s=Ot().Graph;n.exports={addBorderNode:m,addDummyNode:r,applyWithChunking:C,asNonCompoundGraph:o,buildLayerMatrix:d,intersectRect:c,mapValues:T,maxRank:S,normalizeRanks:f,notime:x,partition:v,pick:M,predecessorWeights:l,range:k,removeEmptyRanks:h,simplify:i,successorWeights:a,time:y,uniqueId:j,zipObject:A};function r(D,E,P,q){for(var N=q;D.hasNode(N);)N=j(q);return P.dummy=E,D.setNode(N,P),N}function i(D){let E=new s().setGraph(D.graph());return D.nodes().forEach(P=>E.setNode(P,D.node(P))),D.edges().forEach(P=>{let q=E.edge(P.v,P.w)||{weight:0,minlen:1},N=D.edge(P);E.setEdge(P.v,P.w,{weight:q.weight+N.weight,minlen:Math.max(q.minlen,N.minlen)})}),E}function o(D){let E=new s({multigraph:D.isMultigraph()}).setGraph(D.graph());return D.nodes().forEach(P=>{D.children(P).length||E.setNode(P,D.node(P))}),D.edges().forEach(P=>{E.setEdge(P,D.edge(P))}),E}function a(D){let E=D.nodes().map(P=>{let q={};return D.outEdges(P).forEach(N=>{q[N.w]=(q[N.w]||0)+D.edge(N).weight}),q});return A(D.nodes(),E)}function l(D){let E=D.nodes().map(P=>{let q={};return D.inEdges(P).forEach(N=>{q[N.v]=(q[N.v]||0)+D.edge(N).weight}),q});return A(D.nodes(),E)}function c(D,E){let P=D.x,q=D.y,N=E.x-P,O=E.y-q,_=D.width/2,z=D.height/2;if(!N&&!O)throw new Error("Not possible to find intersection inside of the rectangle");let L,R;return Math.abs(O)*_>Math.abs(N)*z?(O<0&&(z=-z),L=z*N/O,R=z):(N<0&&(_=-_),L=_,R=_*O/N),{x:P+L,y:q+R}}function d(D){let E=k(S(D)+1).map(()=>[]);return D.nodes().forEach(P=>{let q=D.node(P),N=q.rank;N!==void 0&&(E[N][q.order]=P)}),E}function f(D){let E=D.nodes().map(q=>{let N=D.node(q).rank;return N===void 0?Number.MAX_VALUE:N}),P=C(Math.min,E);D.nodes().forEach(q=>{let N=D.node(q);Object.hasOwn(N,"rank")&&(N.rank-=P)})}function h(D){let E=D.nodes().map(_=>D.node(_).rank).filter(_=>_!==void 0),P=C(Math.min,E),q=[];D.nodes().forEach(_=>{let z=D.node(_).rank-P;q[z]||(q[z]=[]),q[z].push(_)});let N=0,O=D.graph().nodeRankFactor;Array.from(q).forEach((_,z)=>{_===void 0&&z%O!==0?--N:_!==void 0&&N&&_.forEach(L=>D.node(L).rank+=N)})}function m(D,E,P,q){let N={width:0,height:0};return arguments.length>=4&&(N.rank=P,N.order=q),r(D,"border",N,E)}function u(D,E=g){let P=[];for(let q=0;q<D.length;q+=E){let N=D.slice(q,q+E);P.push(N)}return P}var g=65535;function C(D,E){if(E.length>g){let P=u(E);return D.apply(null,P.map(q=>D.apply(null,q)))}else return D.apply(null,E)}function S(D){let E=D.nodes().map(P=>{let q=D.node(P).rank;return q===void 0?Number.MIN_VALUE:q});return C(Math.max,E)}function v(D,E){let P={lhs:[],rhs:[]};return D.forEach(q=>{E(q)?P.lhs.push(q):P.rhs.push(q)}),P}function y(D,E){let P=Date.now();try{return E()}finally{console.log(D+" time: "+(Date.now()-P)+"ms")}}function x(D,E){return E()}var b=0;function j(D){var E=++b;return D+(""+E)}function k(D,E,P=1){E==null&&(E=D,D=0);let q=O=>O<E;P<0&&(q=O=>E<O);let N=[];for(let O=D;q(O);O+=P)N.push(O);return N}function M(D,E){let P={};for(let q of E)D[q]!==void 0&&(P[q]=D[q]);return P}function T(D,E){let P=E;return typeof E=="string"&&(P=q=>q[E]),Object.entries(D).reduce((q,[N,O])=>(q[N]=P(O,N),q),{})}function A(D,E){return D.reduce((P,q,N)=>(P[q]=E[N],P),{})}}),Th=Be((e,n)=>{var s=Ih(),r=et().uniqueId;n.exports={run:i,undo:a};function i(l){(l.graph().acyclicer==="greedy"?s(l,c(l)):o(l)).forEach(d=>{let f=l.edge(d);l.removeEdge(d),f.forwardName=d.name,f.reversed=!0,l.setEdge(d.w,d.v,f,r("rev"))});function c(d){return f=>d.edge(f).weight}}function o(l){let c=[],d={},f={};function h(m){Object.hasOwn(f,m)||(f[m]=!0,d[m]=!0,l.outEdges(m).forEach(u=>{Object.hasOwn(d,u.w)?c.push(u):h(u.w)}),delete d[m])}return l.nodes().forEach(h),c}function a(l){l.edges().forEach(c=>{let d=l.edge(c);if(d.reversed){l.removeEdge(c);let f=d.forwardName;delete d.reversed,delete d.forwardName,l.setEdge(c.w,c.v,d,f)}})}}),Rh=Be((e,n)=>{var s=et();n.exports={run:r,undo:o};function r(a){a.graph().dummyChains=[],a.edges().forEach(l=>i(a,l))}function i(a,l){let c=l.v,d=a.node(c).rank,f=l.w,h=a.node(f).rank,m=l.name,u=a.edge(l),g=u.labelRank;if(h===d+1)return;a.removeEdge(l);let C,S,v;for(v=0,++d;d<h;++v,++d)u.points=[],S={width:0,height:0,edgeLabel:u,edgeObj:l,rank:d},C=s.addDummyNode(a,"edge",S,"_d"),d===g&&(S.width=u.width,S.height=u.height,S.dummy="edge-label",S.labelpos=u.labelpos),a.setEdge(c,C,{weight:u.weight},m),v===0&&a.graph().dummyChains.push(C),c=C;a.setEdge(c,f,{weight:u.weight},m)}function o(a){a.graph().dummyChains.forEach(l=>{let c=a.node(l),d=c.edgeLabel,f;for(a.setEdge(c.edgeObj,d);c.dummy;)f=a.successors(l)[0],a.removeNode(l),d.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(d.x=c.x,d.y=c.y,d.width=c.width,d.height=c.height),l=f,c=a.node(l)})}}),ls=Be((e,n)=>{var{applyWithChunking:s}=et();n.exports={longestPath:r,slack:i};function r(o){var a={};function l(c){var d=o.node(c);if(Object.hasOwn(a,c))return d.rank;a[c]=!0;let f=o.outEdges(c).map(m=>m==null?Number.POSITIVE_INFINITY:l(m.w)-o.edge(m).minlen);var h=s(Math.min,f);return h===Number.POSITIVE_INFINITY&&(h=0),d.rank=h}o.sources().forEach(l)}function i(o,a){return o.node(a.w).rank-o.node(a.v).rank-o.edge(a).minlen}}),_l=Be((e,n)=>{var s=Ot().Graph,r=ls().slack;n.exports=i;function i(c){var d=new s({directed:!1}),f=c.nodes()[0],h=c.nodeCount();d.setNode(f,{});for(var m,u;o(d,c)<h;)m=a(d,c),u=d.hasNode(m.v)?r(c,m):-r(c,m),l(d,c,u);return d}function o(c,d){function f(h){d.nodeEdges(h).forEach(m=>{var u=m.v,g=h===u?m.w:u;!c.hasNode(g)&&!r(d,m)&&(c.setNode(g,{}),c.setEdge(h,g,{}),f(g))})}return c.nodes().forEach(f),c.nodeCount()}function a(c,d){return d.edges().reduce((f,h)=>{let m=Number.POSITIVE_INFINITY;return c.hasNode(h.v)!==c.hasNode(h.w)&&(m=r(d,h)),m<f[0]?[m,h]:f},[Number.POSITIVE_INFINITY,null])[1]}function l(c,d,f){c.nodes().forEach(h=>d.node(h).rank+=f)}}),_h=Be((e,n)=>{var s=_l(),r=ls().slack,i=ls().longestPath,o=Ot().alg.preorder,a=Ot().alg.postorder,l=et().simplify;n.exports=c,c.initLowLimValues=m,c.initCutValues=d,c.calcCutValue=h,c.leaveEdge=g,c.enterEdge=C,c.exchangeEdges=S;function c(b){b=l(b),i(b);var j=s(b);m(j),d(j,b);for(var k,M;k=g(j);)M=C(j,b,k),S(j,b,k,M)}function d(b,j){var k=a(b,b.nodes());k=k.slice(0,k.length-1),k.forEach(M=>f(b,j,M))}function f(b,j,k){var M=b.node(k),T=M.parent;b.edge(k,T).cutvalue=h(b,j,k)}function h(b,j,k){var M=b.node(k),T=M.parent,A=!0,D=j.edge(k,T),E=0;return D||(A=!1,D=j.edge(T,k)),E=D.weight,j.nodeEdges(k).forEach(P=>{var q=P.v===k,N=q?P.w:P.v;if(N!==T){var O=q===A,_=j.edge(P).weight;if(E+=O?_:-_,y(b,k,N)){var z=b.edge(k,N).cutvalue;E+=O?-z:z}}}),E}function m(b,j){arguments.length<2&&(j=b.nodes()[0]),u(b,{},1,j)}function u(b,j,k,M,T){var A=k,D=b.node(M);return j[M]=!0,b.neighbors(M).forEach(E=>{Object.hasOwn(j,E)||(k=u(b,j,k,E,M))}),D.low=A,D.lim=k++,T?D.parent=T:delete D.parent,k}function g(b){return b.edges().find(j=>b.edge(j).cutvalue<0)}function C(b,j,k){var M=k.v,T=k.w;j.hasEdge(M,T)||(M=k.w,T=k.v);var A=b.node(M),D=b.node(T),E=A,P=!1;A.lim>D.lim&&(E=D,P=!0);var q=j.edges().filter(N=>P===x(b,b.node(N.v),E)&&P!==x(b,b.node(N.w),E));return q.reduce((N,O)=>r(j,O)<r(j,N)?O:N)}function S(b,j,k,M){var T=k.v,A=k.w;b.removeEdge(T,A),b.setEdge(M.v,M.w,{}),m(b),d(b,j),v(b,j)}function v(b,j){var k=b.nodes().find(T=>!j.node(T).parent),M=o(b,k);M=M.slice(1),M.forEach(T=>{var A=b.node(T).parent,D=j.edge(T,A),E=!1;D||(D=j.edge(A,T),E=!0),j.node(T).rank=j.node(A).rank+(E?D.minlen:-D.minlen)})}function y(b,j,k){return b.hasEdge(j,k)}function x(b,j,k){return k.low<=j.lim&&j.lim<=k.lim}}),Lh=Be((e,n)=>{var s=ls(),r=s.longestPath,i=_l(),o=_h();n.exports=a;function a(f){var h=f.graph().ranker;if(h instanceof Function)return h(f);switch(f.graph().ranker){case"network-simplex":d(f);break;case"tight-tree":c(f);break;case"longest-path":l(f);break;case"none":break;default:d(f)}}var l=r;function c(f){r(f),i(f)}function d(f){o(f)}}),Dh=Be((e,n)=>{n.exports=s;function s(o){let a=i(o);o.graph().dummyChains.forEach(l=>{let c=o.node(l),d=c.edgeObj,f=r(o,a,d.v,d.w),h=f.path,m=f.lca,u=0,g=h[u],C=!0;for(;l!==d.w;){if(c=o.node(l),C){for(;(g=h[u])!==m&&o.node(g).maxRank<c.rank;)u++;g===m&&(C=!1)}if(!C){for(;u<h.length-1&&o.node(g=h[u+1]).minRank<=c.rank;)u++;g=h[u]}o.setParent(l,g),l=o.successors(l)[0]}})}function r(o,a,l,c){let d=[],f=[],h=Math.min(a[l].low,a[c].low),m=Math.max(a[l].lim,a[c].lim),u,g;u=l;do u=o.parent(u),d.push(u);while(u&&(a[u].low>h||m>a[u].lim));for(g=u,u=c;(u=o.parent(u))!==g;)f.push(u);return{path:d.concat(f.reverse()),lca:g}}function i(o){let a={},l=0;function c(d){let f=l;o.children(d).forEach(c),a[d]={low:f,lim:l++}}return o.children().forEach(c),a}}),Ah=Be((e,n)=>{var s=et();n.exports={run:r,cleanup:l};function r(c){let d=s.addDummyNode(c,"root",{},"_root"),f=o(c),h=Object.values(f),m=s.applyWithChunking(Math.max,h)-1,u=2*m+1;c.graph().nestingRoot=d,c.edges().forEach(C=>c.edge(C).minlen*=u);let g=a(c)+1;c.children().forEach(C=>i(c,d,u,g,m,f,C)),c.graph().nodeRankFactor=u}function i(c,d,f,h,m,u,g){let C=c.children(g);if(!C.length){g!==d&&c.setEdge(d,g,{weight:0,minlen:f});return}let S=s.addBorderNode(c,"_bt"),v=s.addBorderNode(c,"_bb"),y=c.node(g);c.setParent(S,g),y.borderTop=S,c.setParent(v,g),y.borderBottom=v,C.forEach(x=>{i(c,d,f,h,m,u,x);let b=c.node(x),j=b.borderTop?b.borderTop:x,k=b.borderBottom?b.borderBottom:x,M=b.borderTop?h:2*h,T=j!==k?1:m-u[g]+1;c.setEdge(S,j,{weight:M,minlen:T,nestingEdge:!0}),c.setEdge(k,v,{weight:M,minlen:T,nestingEdge:!0})}),c.parent(g)||c.setEdge(d,S,{weight:0,minlen:m+u[g]})}function o(c){var d={};function f(h,m){var u=c.children(h);u&&u.length&&u.forEach(g=>f(g,m+1)),d[h]=m}return c.children().forEach(h=>f(h,1)),d}function a(c){return c.edges().reduce((d,f)=>d+c.edge(f).weight,0)}function l(c){var d=c.graph();c.removeNode(d.nestingRoot),delete d.nestingRoot,c.edges().forEach(f=>{var h=c.edge(f);h.nestingEdge&&c.removeEdge(f)})}}),Ph=Be((e,n)=>{var s=et();n.exports=r;function r(o){function a(l){let c=o.children(l),d=o.node(l);if(c.length&&c.forEach(a),Object.hasOwn(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(let f=d.minRank,h=d.maxRank+1;f<h;++f)i(o,"borderLeft","_bl",l,d,f),i(o,"borderRight","_br",l,d,f)}}o.children().forEach(a)}function i(o,a,l,c,d,f){let h={width:0,height:0,rank:f,borderType:a},m=d[a][f-1],u=s.addDummyNode(o,"border",h,l);d[a][f]=u,o.setParent(u,c),m&&o.setEdge(m,u,{weight:1})}}),$h=Be((e,n)=>{n.exports={adjust:s,undo:r};function s(f){let h=f.graph().rankdir.toLowerCase();(h==="lr"||h==="rl")&&i(f)}function r(f){let h=f.graph().rankdir.toLowerCase();(h==="bt"||h==="rl")&&a(f),(h==="lr"||h==="rl")&&(c(f),i(f))}function i(f){f.nodes().forEach(h=>o(f.node(h))),f.edges().forEach(h=>o(f.edge(h)))}function o(f){let h=f.width;f.width=f.height,f.height=h}function a(f){f.nodes().forEach(h=>l(f.node(h))),f.edges().forEach(h=>{let m=f.edge(h);m.points.forEach(l),Object.hasOwn(m,"y")&&l(m)})}function l(f){f.y=-f.y}function c(f){f.nodes().forEach(h=>d(f.node(h))),f.edges().forEach(h=>{let m=f.edge(h);m.points.forEach(d),Object.hasOwn(m,"x")&&d(m)})}function d(f){let h=f.x;f.x=f.y,f.y=h}}),Bh=Be((e,n)=>{var s=et();n.exports=r;function r(i){let o={},a=i.nodes().filter(h=>!i.children(h).length),l=a.map(h=>i.node(h).rank),c=s.applyWithChunking(Math.max,l),d=s.range(c+1).map(()=>[]);function f(h){if(o[h])return;o[h]=!0;let m=i.node(h);d[m.rank].push(h),i.successors(h).forEach(f)}return a.sort((h,m)=>i.node(h).rank-i.node(m).rank).forEach(f),d}}),Oh=Be((e,n)=>{var s=et().zipObject;n.exports=r;function r(o,a){let l=0;for(let c=1;c<a.length;++c)l+=i(o,a[c-1],a[c]);return l}function i(o,a,l){let c=s(l,l.map((g,C)=>C)),d=a.flatMap(g=>o.outEdges(g).map(C=>({pos:c[C.w],weight:o.edge(C).weight})).sort((C,S)=>C.pos-S.pos)),f=1;for(;f<l.length;)f<<=1;let h=2*f-1;f-=1;let m=new Array(h).fill(0),u=0;return d.forEach(g=>{let C=g.pos+f;m[C]+=g.weight;let S=0;for(;C>0;)C%2&&(S+=m[C+1]),C=C-1>>1,m[C]+=g.weight;u+=g.weight*S}),u}}),zh=Be((e,n)=>{n.exports=s;function s(r,i=[]){return i.map(o=>{let a=r.inEdges(o);if(a.length){let l=a.reduce((c,d)=>{let f=r.edge(d),h=r.node(d.v);return{sum:c.sum+f.weight*h.order,weight:c.weight+f.weight}},{sum:0,weight:0});return{v:o,barycenter:l.sum/l.weight,weight:l.weight}}else return{v:o}})}}),Hh=Be((e,n)=>{var s=et();n.exports=r;function r(a,l){let c={};a.forEach((f,h)=>{let m=c[f.v]={indegree:0,in:[],out:[],vs:[f.v],i:h};f.barycenter!==void 0&&(m.barycenter=f.barycenter,m.weight=f.weight)}),l.edges().forEach(f=>{let h=c[f.v],m=c[f.w];h!==void 0&&m!==void 0&&(m.indegree++,h.out.push(c[f.w]))});let d=Object.values(c).filter(f=>!f.indegree);return i(d)}function i(a){let l=[];function c(f){return h=>{h.merged||(h.barycenter===void 0||f.barycenter===void 0||h.barycenter>=f.barycenter)&&o(f,h)}}function d(f){return h=>{h.in.push(f),--h.indegree===0&&a.push(h)}}for(;a.length;){let f=a.pop();l.push(f),f.in.reverse().forEach(c(f)),f.out.forEach(d(f))}return l.filter(f=>!f.merged).map(f=>s.pick(f,["vs","i","barycenter","weight"]))}function o(a,l){let c=0,d=0;a.weight&&(c+=a.barycenter*a.weight,d+=a.weight),l.weight&&(c+=l.barycenter*l.weight,d+=l.weight),a.vs=l.vs.concat(a.vs),a.barycenter=c/d,a.weight=d,a.i=Math.min(l.i,a.i),l.merged=!0}}),qh=Be((e,n)=>{var s=et();n.exports=r;function r(a,l){let c=s.partition(a,S=>Object.hasOwn(S,"barycenter")),d=c.lhs,f=c.rhs.sort((S,v)=>v.i-S.i),h=[],m=0,u=0,g=0;d.sort(o(!!l)),g=i(h,f,g),d.forEach(S=>{g+=S.vs.length,h.push(S.vs),m+=S.barycenter*S.weight,u+=S.weight,g=i(h,f,g)});let C={vs:h.flat(!0)};return u&&(C.barycenter=m/u,C.weight=u),C}function i(a,l,c){let d;for(;l.length&&(d=l[l.length-1]).i<=c;)l.pop(),a.push(d.vs),c++;return c}function o(a){return(l,c)=>l.barycenter<c.barycenter?-1:l.barycenter>c.barycenter?1:a?c.i-l.i:l.i-c.i}}),Wh=Be((e,n)=>{var s=zh(),r=Hh(),i=qh();n.exports=o;function o(c,d,f,h){let m=c.children(d),u=c.node(d),g=u?u.borderLeft:void 0,C=u?u.borderRight:void 0,S={};g&&(m=m.filter(b=>b!==g&&b!==C));let v=s(c,m);v.forEach(b=>{if(c.children(b.v).length){let j=o(c,b.v,f,h);S[b.v]=j,Object.hasOwn(j,"barycenter")&&l(b,j)}});let y=r(v,f);a(y,S);let x=i(y,h);if(g&&(x.vs=[g,x.vs,C].flat(!0),c.predecessors(g).length)){let b=c.node(c.predecessors(g)[0]),j=c.node(c.predecessors(C)[0]);Object.hasOwn(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+b.order+j.order)/(x.weight+2),x.weight+=2}return x}function a(c,d){c.forEach(f=>{f.vs=f.vs.flatMap(h=>d[h]?d[h].vs:h)})}function l(c,d){c.barycenter!==void 0?(c.barycenter=(c.barycenter*c.weight+d.barycenter*d.weight)/(c.weight+d.weight),c.weight+=d.weight):(c.barycenter=d.barycenter,c.weight=d.weight)}}),Fh=Be((e,n)=>{var s=Ot().Graph,r=et();n.exports=i;function i(a,l,c,d){d||(d=a.nodes());let f=o(a),h=new s({compound:!0}).setGraph({root:f}).setDefaultNodeLabel(m=>a.node(m));return d.forEach(m=>{let u=a.node(m),g=a.parent(m);(u.rank===l||u.minRank<=l&&l<=u.maxRank)&&(h.setNode(m),h.setParent(m,g||f),a[c](m).forEach(C=>{let S=C.v===m?C.w:C.v,v=h.edge(S,m),y=v!==void 0?v.weight:0;h.setEdge(S,m,{weight:a.edge(C).weight+y})}),Object.hasOwn(u,"minRank")&&h.setNode(m,{borderLeft:u.borderLeft[l],borderRight:u.borderRight[l]}))}),h}function o(a){for(var l;a.hasNode(l=r.uniqueId("_root")););return l}}),Vh=Be((e,n)=>{n.exports=s;function s(r,i,o){let a={},l;o.forEach(c=>{let d=r.parent(c),f,h;for(;d;){if(f=r.parent(d),f?(h=a[f],a[f]=d):(h=l,l=d),h&&h!==d){i.setEdge(h,d);return}d=f}})}}),Yh=Be((e,n)=>{var s=Bh(),r=Oh(),i=Wh(),o=Fh(),a=Vh(),l=Ot().Graph,c=et();n.exports=d;function d(u,g={}){if(typeof g.customOrder=="function"){g.customOrder(u,d);return}let C=c.maxRank(u),S=f(u,c.range(1,C+1),"inEdges"),v=f(u,c.range(C-1,-1,-1),"outEdges"),y=s(u);if(m(u,y),g.disableOptimalOrderHeuristic)return;let x=Number.POSITIVE_INFINITY,b,j=g.constraints||[];for(let k=0,M=0;M<4;++k,++M){h(k%2?S:v,k%4>=2,j),y=c.buildLayerMatrix(u);let T=r(u,y);T<x?(M=0,b=Object.assign({},y),x=T):T===x&&(b=structuredClone(y))}m(u,b)}function f(u,g,C){let S=new Map,v=(y,x)=>{S.has(y)||S.set(y,[]),S.get(y).push(x)};for(let y of u.nodes()){let x=u.node(y);if(typeof x.rank=="number"&&v(x.rank,y),typeof x.minRank=="number"&&typeof x.maxRank=="number")for(let b=x.minRank;b<=x.maxRank;b++)b!==x.rank&&v(b,y)}return g.map(function(y){return o(u,y,C,S.get(y)||[])})}function h(u,g,C){let S=new l;u.forEach(function(v){C.forEach(b=>S.setEdge(b.left,b.right));let y=v.graph().root,x=i(v,y,S,g);x.vs.forEach((b,j)=>v.node(b).order=j),a(v,S,x.vs)})}function m(u,g){Object.values(g).forEach(C=>C.forEach((S,v)=>u.node(S).order=v))}}),Gh=Be((e,n)=>{var s=Ot().Graph,r=et();n.exports={positionX:C,findType1Conflicts:i,findType2Conflicts:o,addConflict:l,hasConflict:c,verticalAlignment:d,horizontalCompaction:f,alignCoordinates:u,findSmallestWidthAlignment:m,balance:g};function i(y,x){let b={};function j(k,M){let T=0,A=0,D=k.length,E=M[M.length-1];return M.forEach((P,q)=>{let N=a(y,P),O=N?y.node(N).order:D;(N||P===E)&&(M.slice(A,q+1).forEach(_=>{y.predecessors(_).forEach(z=>{let L=y.node(z),R=L.order;(R<T||O<R)&&!(L.dummy&&y.node(_).dummy)&&l(b,z,_)})}),A=q+1,T=O)}),M}return x.length&&x.reduce(j),b}function o(y,x){let b={};function j(M,T,A,D,E){let P;r.range(T,A).forEach(q=>{P=M[q],y.node(P).dummy&&y.predecessors(P).forEach(N=>{let O=y.node(N);O.dummy&&(O.order<D||O.order>E)&&l(b,N,P)})})}function k(M,T){let A=-1,D,E=0;return T.forEach((P,q)=>{if(y.node(P).dummy==="border"){let N=y.predecessors(P);N.length&&(D=y.node(N[0]).order,j(T,E,q,A,D),E=q,A=D)}j(T,E,T.length,D,M.length)}),T}return x.length&&x.reduce(k),b}function a(y,x){if(y.node(x).dummy)return y.predecessors(x).find(b=>y.node(b).dummy)}function l(y,x,b){if(x>b){let k=x;x=b,b=k}let j=y[x];j||(y[x]=j={}),j[b]=!0}function c(y,x,b){if(x>b){let j=x;x=b,b=j}return!!y[x]&&Object.hasOwn(y[x],b)}function d(y,x,b,j){let k={},M={},T={};return x.forEach(A=>{A.forEach((D,E)=>{k[D]=D,M[D]=D,T[D]=E})}),x.forEach(A=>{let D=-1;A.forEach(E=>{let P=j(E);if(P.length){P=P.sort((N,O)=>T[N]-T[O]);let q=(P.length-1)/2;for(let N=Math.floor(q),O=Math.ceil(q);N<=O;++N){let _=P[N];M[E]===E&&D<T[_]&&!c(b,E,_)&&(M[_]=E,M[E]=k[E]=k[_],D=T[_])}}})}),{root:k,align:M}}function f(y,x,b,j,k){let M={},T=h(y,x,b,k),A=k?"borderLeft":"borderRight";function D(q,N){let O=T.nodes().slice(),_={},z=O.pop();for(;z;){if(_[z])q(z);else{_[z]=!0,O.push(z);for(let L of N(z))O.push(L)}z=O.pop()}}function E(q){M[q]=T.inEdges(q).reduce((N,O)=>Math.max(N,M[O.v]+T.edge(O)),0)}function P(q){let N=T.outEdges(q).reduce((_,z)=>Math.min(_,M[z.w]-T.edge(z)),Number.POSITIVE_INFINITY),O=y.node(q);N!==Number.POSITIVE_INFINITY&&O.borderType!==A&&(M[q]=Math.max(M[q],N))}return D(E,T.predecessors.bind(T)),D(P,T.successors.bind(T)),Object.keys(j).forEach(q=>M[q]=M[b[q]]),M}function h(y,x,b,j){let k=new s,M=y.graph(),T=S(M.nodesep,M.edgesep,j);return x.forEach(A=>{let D;A.forEach(E=>{let P=b[E];if(k.setNode(P),D){var q=b[D],N=k.edge(q,P);k.setEdge(q,P,Math.max(T(y,E,D),N||0))}D=E})}),k}function m(y,x){return Object.values(x).reduce((b,j)=>{let k=Number.NEGATIVE_INFINITY,M=Number.POSITIVE_INFINITY;Object.entries(j).forEach(([A,D])=>{let E=v(y,A)/2;k=Math.max(D+E,k),M=Math.min(D-E,M)});let T=k-M;return T<b[0]&&(b=[T,j]),b},[Number.POSITIVE_INFINITY,null])[1]}function u(y,x){let b=Object.values(x),j=r.applyWithChunking(Math.min,b),k=r.applyWithChunking(Math.max,b);["u","d"].forEach(M=>{["l","r"].forEach(T=>{let A=M+T,D=y[A];if(D===x)return;let E=Object.values(D),P=j-r.applyWithChunking(Math.min,E);T!=="l"&&(P=k-r.applyWithChunking(Math.max,E)),P&&(y[A]=r.mapValues(D,q=>q+P))})})}function g(y,x){return r.mapValues(y.ul,(b,j)=>{if(x)return y[x.toLowerCase()][j];{let k=Object.values(y).map(M=>M[j]).sort((M,T)=>M-T);return(k[1]+k[2])/2}})}function C(y){let x=r.buildLayerMatrix(y),b=Object.assign(i(y,x),o(y,x)),j={},k;["u","d"].forEach(T=>{k=T==="u"?x:Object.values(x).reverse(),["l","r"].forEach(A=>{A==="r"&&(k=k.map(q=>Object.values(q).reverse()));let D=(T==="u"?y.predecessors:y.successors).bind(y),E=d(y,k,b,D),P=f(y,k,E.root,E.align,A==="r");A==="r"&&(P=r.mapValues(P,q=>-q)),j[T+A]=P})});let M=m(y,j);return u(j,M),g(j,y.graph().align)}function S(y,x,b){return(j,k,M)=>{let T=j.node(k),A=j.node(M),D=0,E;if(D+=T.width/2,Object.hasOwn(T,"labelpos"))switch(T.labelpos.toLowerCase()){case"l":E=-T.width/2;break;case"r":E=T.width/2;break}if(E&&(D+=b?E:-E),E=0,D+=(T.dummy?x:y)/2,D+=(A.dummy?x:y)/2,D+=A.width/2,Object.hasOwn(A,"labelpos"))switch(A.labelpos.toLowerCase()){case"l":E=A.width/2;break;case"r":E=-A.width/2;break}return E&&(D+=b?E:-E),E=0,D}}function v(y,x){return y.node(x).width}}),Kh=Be((e,n)=>{var s=et(),r=Gh().positionX;n.exports=i;function i(a){a=s.asNonCompoundGraph(a),o(a),Object.entries(r(a)).forEach(([l,c])=>a.node(l).x=c)}function o(a){let l=s.buildLayerMatrix(a),c=a.graph().ranksep,d=a.graph().rankalign,f=0;l.forEach(h=>{let m=h.reduce((u,g)=>{let C=a.node(g).height;return u>C?u:C},0);h.forEach(u=>{let g=a.node(u);d==="top"?g.y=f+g.height/2:d==="bottom"?g.y=f+m-g.height/2:g.y=f+m/2}),f+=m+c})}}),Uh=Be((e,n)=>{var s=Th(),r=Rh(),i=Lh(),o=et().normalizeRanks,a=Dh(),l=et().removeEmptyRanks,c=Ah(),d=Ph(),f=$h(),h=Yh(),m=Kh(),u=et(),g=Ot().Graph;n.exports=C;function C(I,Y={}){let V=Y.debugTiming?u.time:u.notime;return V("layout",()=>{let H=V(" buildLayoutGraph",()=>D(I));return V(" runLayout",()=>S(H,V,Y)),V(" updateInputGraph",()=>v(I,H)),H})}function S(I,Y,V){Y(" makeSpaceForEdgeLabels",()=>E(I)),Y(" removeSelfEdges",()=>$(I)),Y(" acyclic",()=>s.run(I)),Y(" nestingGraph.run",()=>c.run(I)),Y(" rank",()=>i(u.asNonCompoundGraph(I))),Y(" injectEdgeLabelProxies",()=>P(I)),Y(" removeEmptyRanks",()=>l(I)),Y(" nestingGraph.cleanup",()=>c.cleanup(I)),Y(" normalizeRanks",()=>o(I)),Y(" assignRankMinMax",()=>q(I)),Y(" removeEdgeLabelProxies",()=>N(I)),Y(" normalize.run",()=>r.run(I)),Y(" parentDummyChains",()=>a(I)),Y(" addBorderSegments",()=>d(I)),Y(" order",()=>h(I,V)),Y(" insertSelfEdges",()=>W(I)),Y(" adjustCoordinateSystem",()=>f.adjust(I)),Y(" position",()=>m(I)),Y(" positionSelfEdges",()=>F(I)),Y(" removeBorderNodes",()=>R(I)),Y(" normalize.undo",()=>r.undo(I)),Y(" fixupEdgeLabelCoords",()=>z(I)),Y(" undoCoordinateSystem",()=>f.undo(I)),Y(" translateGraph",()=>O(I)),Y(" assignNodeIntersects",()=>_(I)),Y(" reversePoints",()=>L(I)),Y(" acyclic.undo",()=>s.undo(I))}function v(I,Y){I.nodes().forEach(V=>{let H=I.node(V),Z=Y.node(V);H&&(H.x=Z.x,H.y=Z.y,H.order=Z.order,H.rank=Z.rank,Y.children(V).length&&(H.width=Z.width,H.height=Z.height))}),I.edges().forEach(V=>{let H=I.edge(V),Z=Y.edge(V);H.points=Z.points,Object.hasOwn(Z,"x")&&(H.x=Z.x,H.y=Z.y)}),I.graph().width=Y.graph().width,I.graph().height=Y.graph().height}var y=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},b=["acyclicer","ranker","rankdir","align","rankalign"],j=["width","height","rank"],k={width:0,height:0},M=["minlen","weight","width","height","labeloffset"],T={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},A=["labelpos"];function D(I){let Y=new g({multigraph:!0,compound:!0}),V=B(I.graph());return Y.setGraph(Object.assign({},x,X(V,y),u.pick(V,b))),I.nodes().forEach(H=>{let Z=B(I.node(H)),te=X(Z,j);Object.keys(k).forEach(oe=>{te[oe]===void 0&&(te[oe]=k[oe])}),Y.setNode(H,te),Y.setParent(H,I.parent(H))}),I.edges().forEach(H=>{let Z=B(I.edge(H));Y.setEdge(H,Object.assign({},T,X(Z,M),u.pick(Z,A)))}),Y}function E(I){let Y=I.graph();Y.ranksep/=2,I.edges().forEach(V=>{let H=I.edge(V);H.minlen*=2,H.labelpos.toLowerCase()!=="c"&&(Y.rankdir==="TB"||Y.rankdir==="BT"?H.width+=H.labeloffset:H.height+=H.labeloffset)})}function P(I){I.edges().forEach(Y=>{let V=I.edge(Y);if(V.width&&V.height){let H=I.node(Y.v),Z={rank:(I.node(Y.w).rank-H.rank)/2+H.rank,e:Y};u.addDummyNode(I,"edge-proxy",Z,"_ep")}})}function q(I){let Y=0;I.nodes().forEach(V=>{let H=I.node(V);H.borderTop&&(H.minRank=I.node(H.borderTop).rank,H.maxRank=I.node(H.borderBottom).rank,Y=Math.max(Y,H.maxRank))}),I.graph().maxRank=Y}function N(I){I.nodes().forEach(Y=>{let V=I.node(Y);V.dummy==="edge-proxy"&&(I.edge(V.e).labelRank=V.rank,I.removeNode(Y))})}function O(I){let Y=Number.POSITIVE_INFINITY,V=0,H=Number.POSITIVE_INFINITY,Z=0,te=I.graph(),oe=te.marginx||0,ue=te.marginy||0;function Q(le){let de=le.x,fe=le.y,xe=le.width,be=le.height;Y=Math.min(Y,de-xe/2),V=Math.max(V,de+xe/2),H=Math.min(H,fe-be/2),Z=Math.max(Z,fe+be/2)}I.nodes().forEach(le=>Q(I.node(le))),I.edges().forEach(le=>{let de=I.edge(le);Object.hasOwn(de,"x")&&Q(de)}),Y-=oe,H-=ue,I.nodes().forEach(le=>{let de=I.node(le);de.x-=Y,de.y-=H}),I.edges().forEach(le=>{let de=I.edge(le);de.points.forEach(fe=>{fe.x-=Y,fe.y-=H}),Object.hasOwn(de,"x")&&(de.x-=Y),Object.hasOwn(de,"y")&&(de.y-=H)}),te.width=V-Y+oe,te.height=Z-H+ue}function _(I){I.edges().forEach(Y=>{let V=I.edge(Y),H=I.node(Y.v),Z=I.node(Y.w),te,oe;V.points?(te=V.points[0],oe=V.points[V.points.length-1]):(V.points=[],te=Z,oe=H),V.points.unshift(u.intersectRect(H,te)),V.points.push(u.intersectRect(Z,oe))})}function z(I){I.edges().forEach(Y=>{let V=I.edge(Y);if(Object.hasOwn(V,"x"))switch((V.labelpos==="l"||V.labelpos==="r")&&(V.width-=V.labeloffset),V.labelpos){case"l":V.x-=V.width/2+V.labeloffset;break;case"r":V.x+=V.width/2+V.labeloffset;break}})}function L(I){I.edges().forEach(Y=>{let V=I.edge(Y);V.reversed&&V.points.reverse()})}function R(I){I.nodes().forEach(Y=>{if(I.children(Y).length){let V=I.node(Y),H=I.node(V.borderTop),Z=I.node(V.borderBottom),te=I.node(V.borderLeft[V.borderLeft.length-1]),oe=I.node(V.borderRight[V.borderRight.length-1]);V.width=Math.abs(oe.x-te.x),V.height=Math.abs(Z.y-H.y),V.x=te.x+V.width/2,V.y=H.y+V.height/2}}),I.nodes().forEach(Y=>{I.node(Y).dummy==="border"&&I.removeNode(Y)})}function $(I){I.edges().forEach(Y=>{if(Y.v===Y.w){var V=I.node(Y.v);V.selfEdges||(V.selfEdges=[]),V.selfEdges.push({e:Y,label:I.edge(Y)}),I.removeEdge(Y)}})}function W(I){var Y=u.buildLayerMatrix(I);Y.forEach(V=>{var H=0;V.forEach((Z,te)=>{var oe=I.node(Z);oe.order=te+H,(oe.selfEdges||[]).forEach(ue=>{u.addDummyNode(I,"selfedge",{width:ue.label.width,height:ue.label.height,rank:oe.rank,order:te+ ++H,e:ue.e,label:ue.label},"_se")}),delete oe.selfEdges})})}function F(I){I.nodes().forEach(Y=>{var V=I.node(Y);if(V.dummy==="selfedge"){var H=I.node(V.e.v),Z=H.x+H.width/2,te=H.y,oe=V.x-Z,ue=H.height/2;I.setEdge(V.e,V.label),I.removeNode(Y),V.label.points=[{x:Z+2*oe/3,y:te-ue},{x:Z+5*oe/6,y:te-ue},{x:Z+oe,y:te},{x:Z+5*oe/6,y:te+ue},{x:Z+2*oe/3,y:te+ue}],V.label.x=V.x,V.label.y=V.y}})}function X(I,Y){return u.mapValues(u.pick(I,Y),Number)}function B(I){var Y={};return I&&Object.entries(I).forEach(([V,H])=>{typeof V=="string"&&(V=V.toLowerCase()),Y[V]=H}),Y}}),Zh=Be((e,n)=>{var s=et(),r=Ot().Graph;n.exports={debugOrdering:i};function i(o){let a=s.buildLayerMatrix(o),l=new r({compound:!0,multigraph:!0}).setGraph({});return o.nodes().forEach(c=>{l.setNode(c,{label:c}),l.setParent(c,"layer"+o.node(c).rank)}),o.edges().forEach(c=>l.setEdge(c.v,c.w,{},c.name)),a.forEach((c,d)=>{let f="layer"+d;l.setNode(f,{rank:"same"}),c.reduce((h,m)=>(l.setEdge(h,m,{style:"invis"}),m))}),l}}),Xh=Be((e,n)=>{n.exports="2.0.4"}),Qh=Be((e,n)=>{n.exports={graphlib:Ot(),layout:Uh(),debug:Zh(),util:{time:et().time,notime:et().notime},version:Xh()}});const Pa=Qh();const $a={pending:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},in_progress:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},blocked:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},review:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},failed:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},rejected:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"},archived:{bg:"bg-gray-500/5",border:"border-gray-500/15",text:"text-fg-tertiary"}},Jh={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function em({data:e}){const{t:n}=Oe(["work","common"]),{task:s,agentName:r,selected:i,direction:o="TB",isExpandedRoot:a,onCollapse:l}=e,c=$a[s.status]??$a.pending,d=s.taskType==="scheduled"&&!!s.scheduleConfig,f=d?s.scheduleConfig.every?n("work:task.everyInterval",{interval:s.scheduleConfig.every}):s.scheduleConfig.cron?n("work:task.cronLabel"):"":"",h=o==="LR"?ye.Left:ye.Top,m=o==="LR"?ye.Right:ye.Bottom;return t.jsxs("div",{className:`relative rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${d?`${c.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${c.bg} ${c.border}`} ${i?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[t.jsx(fn,{type:"target",position:h,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Jh[s.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${c.text}`,children:n(`work:status.task.${s.status}`,{defaultValue:s.status.replace("_"," ")})}),d&&t.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/15 text-blue-600 ml-auto whitespace-nowrap inline-flex items-center gap-0.5",children:[t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})}),f]})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:s.title}),r&&t.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:r}),s.blockedBy&&s.blockedBy.length>0&&t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:n("work:dag.depCount",{count:s.blockedBy.length})}),t.jsx(fn,{type:"source",position:m,className:"!bg-border-default !w-2 !h-2"}),a&&l&&t.jsx("button",{onClick:u=>{u.stopPropagation(),l()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const Ba={pending:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},in_progress:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},rejected:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"}},Oa={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function tm({data:e}){const{t:n}=Oe(["work","common"]),{req:s,selected:r,direction:i="TB",isExpandedRoot:o,onCollapse:a}=e,l=Ba[s.status]??Ba.pending,c=i==="LR"?ye.Left:ye.Top,d=i==="LR"?ye.Right:ye.Bottom;return t.jsxs("div",{className:`relative rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${l.bg} ${l.border} ${r?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[t.jsx(fn,{type:"target",position:c,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:n("work:dag.reqLabel")}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${l.text}`,children:n(`work:status.requirement.${s.status}`,{defaultValue:s.status.replace("_"," ")})})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:s.title}),s.taskIds.length>0&&t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:n("work:dag.taskCount",{count:s.taskIds.length})}),t.jsx(fn,{type:"source",position:d,className:"!bg-border-default !w-2 !h-2"}),o&&a&&t.jsx("button",{onClick:f=>{f.stopPropagation(),a()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const nm={task:em,requirement:tm};function rm({nodeIds:e,rfRef:n}){const s=Xf();return p.useEffect(()=>{if(e.length===0)return;const r=setTimeout(()=>{s(e),requestAnimationFrame(()=>{n.current?.fitView({padding:.2})})},300);return()=>clearTimeout(r)},[e.length]),null}const sm=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&!document.documentElement.classList.contains("cyberpunk")&&!document.documentElement.classList.contains("mono")&&window.matchMedia("(prefers-color-scheme: light)").matches,om=e=>{const n=new MutationObserver(e);n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const s=window.matchMedia("(prefers-color-scheme: light)");return s.addEventListener("change",e),()=>{n.disconnect(),s.removeEventListener("change",e)}};function am(){return p.useSyncExternalStore(om,sm,()=>!1)}const ns=200,rs=80;function za(e,n,s="TB"){const r=o=>{const a=new Pa.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:o,nodesep:40,ranksep:60});for(const l of e)a.setNode(l.id,{width:ns,height:rs});for(const l of n)a.setEdge(l.source,l.target);return Pa.layout(a),e.map(l=>{const c=a.node(l.id);return{...l,position:{x:(c?.x??0)-ns/2,y:(c?.y??0)-rs/2}}})},i=r(s);if(n.length>0&&e.length>4){let o=1/0,a=-1/0,l=1/0,c=-1/0;for(const m of i)o=Math.min(o,m.position.x),a=Math.max(a,m.position.x+ns),l=Math.min(l,m.position.y),c=Math.max(c,m.position.y+rs);const d=a-o,f=c-l,h=s==="TB"?"LR":"TB";if(d>f*3)return{nodes:r(h),direction:h}}return{nodes:i,direction:s}}function im(e,n){const s=new Map,r=new Map;for(const a of e)r.set(a.id,a),s.set(a.id,new Set);for(const a of n)s.get(a.source)?.add(a.target),s.get(a.target)?.add(a.source);const i=new Set,o=[];for(const a of e){if(i.has(a.id))continue;const l=new Set,c=[a.id];for(;c.length>0;){const d=c.pop();if(!i.has(d)){i.add(d),l.add(d);for(const f of s.get(d)??[])i.has(f)||c.push(f)}}o.push({nodes:e.filter(d=>l.has(d.id)),edges:n.filter(d=>l.has(d.source)&&l.has(d.target))})}return o}function Ha(e,n){if(e.length===0)return{nodes:[],direction:"TB"};const s=im(e,n);if(s.length===1)return za(e,n);let r="TB";const i=s.map(m=>{const{nodes:u,direction:g}=za(m.nodes,m.edges);r=g;let C=1/0,S=-1/0,v=1/0,y=-1/0;for(const x of u)C=Math.min(C,x.position.x),S=Math.max(S,x.position.x+ns),v=Math.min(v,x.position.y),y=Math.max(y,x.position.y+rs);for(const x of u)x.position.x-=C,x.position.y-=v;return{nodes:u,w:S-C,h:y-v}});i.sort((m,u)=>u.h-m.h);const o=60,a=i.reduce((m,u)=>m+(u.w+o)*(u.h+o),0),l=Math.sqrt(a)*1.1,c=[];let d=0,f=0,h=0;for(const m of i){d>0&&d+m.w>l&&(d=0,f+=h+o,h=0);for(const u of m.nodes)c.push({...u,position:{x:u.position.x+d,y:u.position.y+f}});d+=m.w+o,h=Math.max(h,m.h)}return{nodes:c,direction:r}}function lm(e,n,s){const r=new Set,i=[n];for(;i.length>0;){const o=i.pop();if(o===s)return!0;if(r.has(o))continue;r.add(o);const a=e.get(o);if(a?.blockedBy)for(const l of a.blockedBy)i.push(l)}return!1}const Gn=[{id:"todo",statuses:new Set(["pending"]),color:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"}},{id:"in_progress",statuses:new Set(["in_progress","blocked"]),color:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"}},{id:"review",statuses:new Set(["review"]),color:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"}},{id:"done",statuses:new Set(["completed","failed","rejected","cancelled","archived"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}];new Set(Gn.map(e=>e.id));const Xr=new Set(Gn.filter(e=>e.id!=="done").map(e=>e.id)),Ps=e=>e.status==="archived";function cm(e,n,s,r){const i=new Set,o=[e];for(;o.length>0;){const a=o.pop();if(!i.has(a))if(i.add(a),a.startsWith("req-")){const l=s.get(a.slice(4));if(l)for(const c of l.taskIds)o.push(c)}else{const l=n.get(a);if(l?.blockedBy)for(const c of l.blockedBy)o.push(c);l?.requirementId&&o.push(`req-${l.requirementId}`)}}for(const a of r)a.requirementId&&i.has(a.id)&&i.add(`req-${a.requirementId}`);return i}function dm({tasks:e,requirements:n=[],agents:s,showArchived:r,onShowArchivedChange:i,onTaskClick:o,onReqClick:a,onCollapseDAG:l,onDependencyChange:c,selectedTaskId:d,selectedReqId:f,hasDetailPanel:h,defaultExpandedNodeId:m,previewMode:u}){const{t:g}=Oe(["work","common"]),C=am(),[S,v]=p.useState(null),[y,x]=p.useState(null),[b,j]=p.useState(()=>new Set(Xr)),[k,M]=p.useState(m??null),[T,A]=p.useState(r??!1),D=r??T,E=p.useCallback(ae=>{const ie=typeof ae=="function"?ae(D):ae;A(ie),i?.(ie)},[D,i]);p.useEffect(()=>{r!==void 0&&A(r)},[r]),p.useEffect(()=>{m&&M(m)},[m]);const P=p.useMemo(()=>e.filter(ae=>Ps(ae)).length,[e]),q=p.useMemo(()=>{const ae=new Set;for(const ie of Gn)if(b.has(ie.id))for(const me of ie.statuses)ae.add(me);return ae},[b]),N=p.useMemo(()=>{const ae=new Set;for(const ie of e)for(const me of Gn)if(me.statuses.has(ie.status)){ae.add(me.id);break}for(const ie of n){const me=Oa[ie.status];me&&ae.add(me)}return Gn.filter(ie=>ae.has(ie.id))},[e,n]),O=p.useCallback(ae=>{j(ie=>{const me=new Set(ie);return me.has(ae)?me.delete(ae):me.add(ae),me})},[]),_=p.useCallback((ae,ie="success")=>{v({msg:ae,type:ie}),setTimeout(()=>v(null),2500)},[]),z=p.useMemo(()=>{const ae=new Map;for(const ie of s)ae.set(ie.id,ie.name);return ae},[s]),L=p.useMemo(()=>{const ae=new Map;for(const ie of e)ae.set(ie.id,ie);return ae},[e]),R=p.useMemo(()=>{const ae=new Map;for(const ie of n)ae.set(ie.id,ie);return ae},[n]),$=p.useRef(!1),W=p.useCallback(()=>{$.current=!1,M(null),l?.()},[l]),F=C?"#94a3b8":"#6b7280",X=p.useCallback((ae,ie,me)=>({id:`${ae}->${ie}`,source:ae,target:ie,animated:me==="blocked",markerEnd:{type:Zn.ArrowClosed,width:14,height:14,color:me==="blocked"?"#ef4444":F},style:{stroke:me==="blocked"?"#ef4444":F,strokeWidth:1.5,cursor:"pointer"}}),[F]),{initialNodes:B,initialEdges:I,topLevelIds:Y}=p.useMemo(()=>{const ae=(ve,ct)=>{const ht=new Set,mt=ve.map(Re=>(ht.add(Re.id),{id:Re.id,type:"task",data:{task:Re,agentName:Re.assignedAgentId?z.get(Re.assignedAgentId):void 0,selected:Re.id===d},position:{x:0,y:0}}));for(const Re of ct){const qe=`req-${Re.id}`;ht.add(qe),mt.push({id:qe,type:"requirement",data:{req:Re,selected:Re.id===f},position:{x:0,y:0}})}const pt=[];for(const Re of ve)if(Re.blockedBy)for(const qe of Re.blockedBy)ht.has(qe)&&pt.push(X(qe,Re.id,Re.status));const Ht=new Set,bt=(Re,qe)=>{const gt=`${Re}->${qe}`;Ht.has(gt)||(Ht.add(gt),pt.push({id:gt,source:Re,target:qe,markerEnd:{type:Zn.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Re of ct){const qe=`req-${Re.id}`;for(const gt of Re.taskIds)ht.has(gt)&&bt(qe,gt)}for(const Re of ve)if(Re.requirementId){const qe=`req-${Re.requirementId}`;ht.has(qe)&&bt(qe,Re.id)}return{nodes:mt,edges:pt}},ie=e.filter(ve=>q.has(ve.status)&&(D||!Ps(ve))),me=new Set;for(const ve of Gn)b.has(ve.id)&&me.add(ve.id);const Ge=n.filter(ve=>{const ct=Oa[ve.status];return ct&&me.has(ct)}),Ne=new Set(["completed","rejected","cancelled","archived"]),je=new Set(Ge.filter(ve=>!Ne.has(ve.status)).map(ve=>ve.id)),Ze=new Set;for(const ve of n)if(je.has(ve.id))for(const ct of ve.taskIds)Ze.add(ct);const yt=e.filter(ve=>Ze.has(ve.id)&&(D||!Ps(ve))),wt=[...new Map([...ie,...yt].map(ve=>[ve.id,ve])).values()],{nodes:lt,edges:vt}=ae(wt,Ge),Je=new Set;for(const ve of vt)Je.add(ve.target);const $e=new Set(lt.filter(ve=>!Je.has(ve.id)).map(ve=>ve.id));if(!k||!$e.has(k)){const ve=lt,{nodes:ct,direction:ht}=Ha(ve,vt);return{initialNodes:ct.map(pt=>({...pt,data:{...pt.data,direction:ht}})),initialEdges:vt,topLevelIds:$e}}const{nodes:ft,edges:at}=ae(e,n),zt=cm(k,L,R,e),kt=ft.filter(ve=>zt.has(ve.id)).map(ve=>ve.id===k?{...ve,data:{...ve.data,isExpandedRoot:!0,onCollapse:W}}:ve),dt=at.filter(ve=>zt.has(ve.source)&&zt.has(ve.target)),{nodes:Yt,direction:jt}=Ha(kt,dt);return{initialNodes:Yt.map(ve=>({...ve,data:{...ve.data,direction:jt}})),initialEdges:dt,topLevelIds:$e}},[e,n,z,L,R,X,q,b,D,d,f,k,W]),[V,H,Z]=Qf(B),[te,oe,ue]=Jf(I),Q=p.useRef(null),le=p.useRef({groupFilter:b,showArchived:D});p.useEffect(()=>{const ae=le.current;(ae.groupFilter!==b||ae.showArchived!==D)&&($.current=!1,M(null),le.current={groupFilter:b,showArchived:D})},[b,D]),p.useEffect(()=>{H(B),oe(I),$.current||requestAnimationFrame(()=>{Q.current?.fitView({padding:.2,duration:300})})},[B,I,H,oe]),p.useEffect(()=>{const ae=setTimeout(()=>{Q.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(ae)},[h]);const de=p.useCallback(ae=>{ae&&($.current=!0)},[]),fe=p.useCallback((ae,ie)=>{if(!k&&Y.has(ie.id)&&($.current=!1,M(ie.id)),ie.id.startsWith("req-")){const me=R.get(ie.id.slice(4));me&&a&&a(me)}else{const me=L.get(ie.id);me&&o&&o(me)}},[L,R,o,a,Y,k]),xe=p.useCallback(async ae=>{const{source:ie,target:me}=ae;if(!ie||!me||ie===me)return;const Ge=L.get(me);if(!Ge)return;if(Ge.blockedBy?.includes(ie)){_(g("work:dag.toast.dependencyExists"),"error");return}if(lm(L,ie,me)){_(g("work:dag.toast.cycleError"),"error");return}const Ne=[...Ge.blockedBy??[],ie];try{await re.tasks.update(me,{blockedBy:Ne}),_(g("work:dag.toast.dependencyAdded")),c?.()}catch(je){_(g("work:dag.toast.failed",{message:je instanceof Error?je.message:String(je)}),"error")}},[L,_,c,g]),be=p.useCallback((ae,ie)=>{x(ie)},[]),U=p.useCallback(async()=>{if(!y)return;const ae=L.get(y.target);if(!ae){x(null);return}const ie=(ae.blockedBy??[]).filter(me=>me!==y.source);try{await re.tasks.update(y.target,{blockedBy:ie}),_(g("work:dag.toast.dependencyRemoved")),c?.()}catch(me){_(g("work:dag.toast.failed",{message:me instanceof Error?me.message:String(me)}),"error")}x(null)},[y,L,_,c,g]),ce=p.useRef(null),[pe,we]=p.useState(null);if(p.useEffect(()=>{let ae=document;const ie=()=>{const Ne=ce.current;if(!Ne){we(null);return}let je=Ne.parentElement;for(;je;){const at=getComputedStyle(je).overflowY;if((at==="auto"||at==="scroll")&&je.clientHeight>0)break;je=je.parentElement}if(!document.documentElement.classList.contains("mobile-doc-scroll")&&!(je!==null)){we(null);return}const wt=je?je.clientHeight:window.innerHeight,lt=je?je.getBoundingClientRect().top:0,vt=je?je.scrollTop:window.scrollY,$e=Ne.getBoundingClientRect().top-lt+vt,ft=Math.min(wt,window.innerHeight)-$e-8;we(Math.max(320,Math.round(ft))),je&&ae!==je&&(me.disconnect(),me.observe(je),ae=je)},me=new ResizeObserver(ie);ie(),me.observe(document.documentElement),window.addEventListener("resize",ie);const Ge=new MutationObserver(ie);return Ge.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{window.removeEventListener("resize",ie),me.disconnect(),Ge.disconnect()}},[]),p.useEffect(()=>{if(pe===null)return;const ae=requestAnimationFrame(()=>{Q.current?.fitView({padding:.2})});return()=>cancelAnimationFrame(ae)},[pe]),e.length===0)return t.jsx("div",{className:"doc-scroll-viewport flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"flex flex-col items-center gap-3 max-w-sm text-center",children:[t.jsx("svg",{className:"w-10 h-10 text-fg-quaternary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:g("work:task.dagEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:g("work:task.dagEmptyDesc")})]})});const _e=b.size===Xr.size&&[...Xr].every(ae=>b.has(ae))&&!D,ee=y?L.get(y.source):null,Se=y?L.get(y.target):null;return t.jsxs("div",{ref:ce,className:"doc-scroll-viewport flex-1 min-h-0 relative",style:{height:pe??"100%"},children:[t.jsxs(Zf,{nodes:V,edges:te,onNodesChange:Z,onEdgesChange:ue,onNodeClick:fe,onConnect:xe,onEdgeClick:be,onMoveEnd:de,onInit:ae=>{Q.current=ae},nodeTypes:nm,fitView:!0,minZoom:.08,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[u&&t.jsx(rm,{nodeIds:V.map(ae=>ae.id),rfRef:Q}),t.jsx(sh,{color:C?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(uh,{showInteractive:!1,className:"!bg-surface-secondary !border-border-default !shadow-xl [&>button]:!bg-surface-elevated [&>button]:!border-border-default [&>button]:!text-fg-secondary [&>button:hover]:!bg-surface-overlay"}),t.jsx(Nh,{nodeColor:ae=>{const ie=ae.data?.task,me=ie?.status;return ie?.taskType==="scheduled"?"#8b8fa3":me==="completed"||me==="accepted"?"#10b981":me==="in_progress"?"#f59e0b":me==="blocked"||me==="failed"?"#ef4444":C?"#94a3b8":"#6b7280"},maskColor:C?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),t.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-surface-secondary/90 border border-border-default rounded-lg backdrop-blur-sm z-10 flex flex-col items-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[N.map(ae=>{const ie=b.has(ae.id);return t.jsx("button",{onClick:()=>O(ae.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${ie?`${ae.color.bg} ${ae.color.border} ${ae.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:g(`work:dag.filter.${ae.id}`)},ae.id)}),P>0&&t.jsx("button",{onClick:()=>E(ae=>!ae),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${D?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:g("work:dag.archivedToggle",{count:P})}),!_e&&t.jsx("button",{onClick:()=>{j(new Set(Xr)),E(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:g("work:dag.reset")})]}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[k?t.jsx("button",{onClick:W,className:"text-brand-500 hover:text-brand-400 transition-colors",children:g("work:dag.backToOverview")}):t.jsx("span",{children:g("work:dag.expandHint")}),t.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),t.jsx("span",{children:g("work:dag.dragHint")})]})]}),S&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${S.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:S.msg}),y&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>x(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:ae=>ae.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:g("work:dag.removeDependencyTitle")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:g("work:dag.removeDependencyBody",{target:Se?.title??y.target.slice(-8),source:ee?.title??y.source.slice(-8)})}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>x(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:g("common:cancel")}),t.jsx("button",{onClick:U,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:g("common:remove")})]})]})})]})}const Ys="grid grid-cols-[auto_1fr] gap-x-3 gap-y-3.5 items-start",Ll="grid grid-cols-[auto_1fr] sm:grid-cols-[auto_1fr_auto_1fr] gap-x-5 gap-y-3 items-start",Ve="pt-2 text-sm text-fg-secondary whitespace-nowrap",Jt="w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",$s="shrink-0 whitespace-nowrap text-[11px] font-medium text-brand-500 hover:text-brand-400";function um(e){return/^(https?:\/\/|git@|ssh:\/\/|git:\/\/)/i.test(e)}function qa({orgId:e,onCreated:n,onClose:s}){const{t:r}=Oe(["work","common"]);lc(!0);const[i,o]=p.useState(""),[a,l]=p.useState(""),[c,d]=p.useState(""),[f,h]=p.useState("main"),[m,u]=p.useState(!1),[g,C]=p.useState(""),[S,v]=p.useState(!1),y=jr();p.useEffect(()=>{const j=k=>{k.key==="Escape"&&s()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[s]);const x=p.useCallback(async j=>{if(j?.preventDefault(),v(!0),!(!i.trim()||m)){u(!0),C("");try{const k=c.trim(),M=k?[{...um(k)?{url:k}:{localPath:k},defaultBranch:f.trim()||"main",role:"primary"}]:[],T=await re.projects.create({name:i.trim(),description:a.trim()||void 0,repositories:M.length>0?M:void 0,orgId:e??"default"});n(T.project)}catch(k){C(k instanceof Error?k.message:r("project.failedToCreate"))}u(!1)}},[i,a,c,f,e,m,n,r]),b=S&&!i.trim();return cc.createPortal(t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:s,children:t.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto space-y-4 ${y?"w-full":"w-[26rem]"}`,onClick:j=>j.stopPropagation(),onSubmit:x,children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("project.newProject")}),t.jsxs("div",{className:Ys,children:[t.jsx("label",{className:Ve,children:r("project.projectName")}),t.jsxs("div",{children:[t.jsx("input",{value:i,onChange:j=>{o(j.target.value),C("")},onBlur:()=>v(!0),placeholder:r("project.projectNamePlaceholder"),className:`${Jt} ${b?"!border-red-500":""}`,autoFocus:!y}),b&&t.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:r("project.projectNameRequired")})]}),t.jsx("label",{className:Ve,children:r("project.description")}),t.jsx("textarea",{value:a,onChange:j=>l(j.target.value),placeholder:r("project.descriptionPlaceholder"),className:`${Jt} resize-none`,rows:2}),t.jsx("label",{className:Ve,children:r("project.repositoryUrl")}),t.jsx("input",{value:c,onChange:j=>d(j.target.value),placeholder:r("project.repositoryPlaceholder"),className:`${Jt} placeholder:text-[11px]`}),c.trim()&&t.jsxs(t.Fragment,{children:[t.jsx("label",{className:Ve,children:r("project.branch")}),t.jsx("input",{value:f,onChange:j=>h(j.target.value),placeholder:r("project.branchPlaceholder"),className:Jt})]})]}),g&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:g}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||m,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:r(m?"common:creating":"project.createProject")})]})]})}),document.body)}function fm({projects:e,selectedProjectId:n,allSelected:s,taskCounts:r,totalTaskCount:i,onSelectAll:o,onSelectProject:a,onEditProject:l,onCreateProject:c,onCollapse:d,width:f,onResizeStart:h,hidden:m,focused:u,onActivate:g}){const{t:C}=Oe(["work","common"]),S=s??n==null;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-keyboard-pane":"l1",onPointerDown:()=>g?.(),className:"bg-surface-primary flex flex-col shrink-0 border-r border-border-default/60",style:m?{display:"none"}:f!=null?{width:f}:void 0,children:[t.jsxs("div",{"data-electron-drag":!0,className:"px-3 h-14 flex items-center shrink-0 gap-2",children:[d&&t.jsx("button",{type:"button","data-no-drag":!0,onClick:d,className:"w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 bg-brand-500/15 text-brand-500 hover:bg-brand-500/25",title:C("common:shortcuts.toggleLeft"),children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),t.jsx("h2",{className:"text-sm font-semibold text-fg-primary truncate",children:C("work:task.projects",{defaultValue:"Projects"})}),t.jsx("button",{type:"button","data-no-drag":!0,onClick:c,className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:C("work:project.newProject"),children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:e.length===0?t.jsxs("div",{className:"px-2 py-8 text-center space-y-3",children:[t.jsx("div",{className:"w-10 h-10 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),t.jsx("p",{className:"text-[11px] text-fg-tertiary leading-relaxed px-1",children:C("work:task.emptyNoProjectsHint")}),t.jsx("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:C("work:project.newProject")})]}):t.jsxs(t.Fragment,{children:[o&&t.jsxs("button",{type:"button","data-project-id":"__all__",onClick:o,className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors ${S?u?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[t.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center shrink-0 ${S?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),t.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),t.jsx("span",{className:"min-w-0 flex-1",children:t.jsx("span",{className:"block text-[12px] font-medium truncate",children:C("work:task.all")})}),(i??0)>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:i})]}),[...e].sort((v,y)=>{const x=v.status==="archived"?1:0,b=y.status==="archived"?1:0;return x-b}).map(v=>{const y=!S&&v.id===n,x=r[v.id]??0,b=v.status==="paused",j=v.status==="archived";return t.jsxs("div",{role:"button",tabIndex:0,"data-project-id":v.id,onClick:()=>a(v.id),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),a(v.id))},className:`group w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left cursor-pointer transition-colors ${y?u?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[t.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center text-[11px] font-bold shrink-0 ${y?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:v.name[0]?.toUpperCase()??"?"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block text-[12px] font-medium truncate",children:v.name}),j&&t.jsx("span",{className:"block text-[10px] text-fg-tertiary italic",children:C("work:project.statusArchived")}),b&&t.jsx("span",{className:"block text-[10px] text-amber-500/80",children:C("work:project.statusPaused")})]}),l&&t.jsx("button",{type:"button","data-no-drag":!0,title:C("work:project.editProject"),"aria-label":C("work:project.editProject"),onClick:k=>{k.stopPropagation(),l(v.id)},className:"w-6 h-6 flex items-center justify-center rounded-md text-fg-tertiary hover:text-brand-500 hover:bg-surface-elevated transition-opacity opacity-0 group-hover:opacity-100 focus:opacity-100 shrink-0",children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),x>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:x})]},v.id)})]})})]}),!m&&h&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:h,children:t.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})})]})}function hm({project:e,onUpdateProject:n}){const{t:s}=Oe(["work","common"]),r=e.knowledgeBasePaths??[],[i,o]=p.useState(""),[a,l]=p.useState(!1),[c,d]=p.useState(!0),[f,h]=p.useState([]),[m,u]=p.useState(null),[g,C]=p.useState(null),S=p.useCallback(async()=>{if(e.id){d(!0);try{const{results:T}=await re.deliverables.search({projectId:e.id,source:"knowledge",limit:200});h(T)}catch(T){u({type:"error",text:`${s("work:project.kbLoadFailed")}: ${String(T)}`})}finally{d(!1)}}},[e.id,s]);p.useEffect(()=>{S()},[S]);const v=async()=>{const T=i.trim();if(!(!T||a))try{const A=[...new Set([...r,T])];await n({knowledgeBasePaths:A}),o(""),await j()}catch(A){u({type:"error",text:`${s("work:project.kbPathsSaveFailed")}: ${String(A)}`})}},y=async()=>{const T=g;if(!T||a)return;C(null);const A=r.filter(D=>D!==T);await n({knowledgeBasePaths:A}),await j(A)},x=typeof window<"u"&&!!window.markusDesktop?.selectDirectory,b=async()=>{try{const T=await window.markusDesktop?.selectDirectory?.(s("work:project.kbBrowseTitle"));T&&o(T)}catch(T){u({type:"error",text:`${s("work:project.kbBrowseFailed")}: ${String(T)}`})}},j=async T=>{if(!a){l(!0),u(null);try{const A=await re.projects.syncKnowledge(e.id,T);u({type:A.errors.length>0?"error":"success",text:s("work:project.kbSyncResult",{scanned:A.scanned,registered:A.registered,updated:A.updated,outdated:A.outdated,errors:A.errors.length})}),await S()}catch(A){u({type:"error",text:`${s("work:project.kbSyncFailed")}: ${String(A)}`})}finally{l(!1)}}},k=async()=>{await j(r.length?r:void 0)},M=T=>{Bt.navigate(He.DELIVERABLES,{projectId:e.id,source:"knowledge",...T?{openDeliverable:T}:{}})};return t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 mb-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:s("work:project.kbHeading")}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("button",{type:"button",onClick:()=>M(),className:"text-[10px] px-2 py-1 rounded-md text-fg-tertiary hover:text-brand-500 hover:bg-surface-overlay transition-colors",children:s("work:project.kbOpenInDeliverables")}),t.jsx("button",{type:"button",onClick:k,disabled:a||r.length===0,className:"text-[10px] px-2 py-1 rounded-md bg-brand-600 text-white hover:bg-brand-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:s(a?"work:project.kbSyncing":"work:project.kbSync")})]})]}),g&&t.jsxs("div",{className:"mb-3 px-3 py-2 bg-surface-overlay border border-border-default rounded-lg",children:[t.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:s("work:project.kbRemoveConfirm",{path:g})}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx("button",{type:"button",onClick:()=>C(null),className:"px-2.5 py-1 text-xs rounded-md bg-surface-secondary text-fg-secondary hover:text-fg-primary border border-border-default transition-colors",children:s("common:cancel")}),t.jsx("button",{type:"button",onClick:()=>{y()},disabled:a,className:"px-2.5 py-1 text-xs rounded-md bg-red-600 text-white hover:bg-red-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:s(a?"work:project.kbSyncing":"common:confirm")})]})]}),t.jsxs("div",{className:"space-y-1.5 mb-3",children:[r.length===0&&t.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("work:project.kbNoPaths")}),r.map((T,A)=>t.jsxs("div",{className:"flex items-center gap-2 group",children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:t.jsx("path",{d:"M3 7v10a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-6l-2-2H5a2 2 0 0 0-2 2z"})}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate font-mono",title:T,children:T}),t.jsx("button",{type:"button",onClick:()=>C(T),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:s("work:project.removeRepo"),children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},`${T}-${A}`)),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:i,onChange:T=>o(T.target.value),onKeyDown:T=>{T.key==="Enter"&&v()},placeholder:s("work:project.kbPathPlaceholder"),className:"flex-1 min-w-0 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary font-mono"}),x&&t.jsx("button",{type:"button",onClick:()=>{b()},disabled:a,title:s("work:project.kbBrowse"),className:"shrink-0 px-2.5 py-1.5 text-xs bg-surface-overlay text-fg-secondary hover:text-fg-primary rounded-md disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:s("work:project.kbBrowse")}),t.jsx("button",{type:"button",onClick:v,disabled:!i.trim()||a,className:"px-2.5 py-1.5 text-xs bg-surface-overlay text-fg-secondary hover:text-fg-primary rounded-md disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:s(a?"work:project.kbSyncing":"work:project.kbAdd")})]})]}),m&&t.jsx("div",{className:`mb-2 px-2.5 py-1.5 text-[11px] rounded-md ${m.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:m.text}),t.jsxs("div",{className:"border-t border-border-default/60 pt-3",children:[t.jsxs("h5",{className:"text-[11px] font-medium text-fg-tertiary mb-2",children:[s("work:project.kbDocsHeading"),f.length>0&&t.jsxs("span",{className:"ml-1 text-fg-quaternary",children:["(",f.length,")"]})]}),c?t.jsx(Sc,{variant:"text",label:s("work:project.kbLoadingDocs"),className:"px-0"}):f.length===0?t.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("work:project.kbNoDocs")}):t.jsx("div",{className:"max-h-64 overflow-y-auto space-y-0.5",children:f.map(T=>t.jsxs("button",{type:"button",onClick:()=>M(T.id),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left hover:bg-surface-overlay transition-colors group",title:T.reference??T.title,children:[t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-overlay text-fg-tertiary shrink-0 uppercase",children:T.format??"file"}),t.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 min-w-0 group-hover:text-brand-500",children:T.title}),t.jsx("span",{className:"text-[10px] text-fg-quaternary shrink-0",children:"→"})]},T.id))})]})]})}const Wa="markus_work_l1_collapsed",Fa=["backlog","kanban","dag","workflows"];function lo(e){const n=e.agentId,s=e.activityId;return!n||!s?null:di({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},s,n)}function co(e,n,s){const r=e.get(n)??[];if(r.some(o=>o.id===s.id))return e;const i=new Map(e);return i.set(n,[...r,s]),i}function uo({entries:e}){const[n,s]=p.useState("compact");return e.length===0?null:t.jsx("div",{onClick:r=>r.stopPropagation(),children:n==="compact"?t.jsx(vc,{entries:e,isActive:!0,onExpand:()=>s("full"),embedded:!0}):t.jsx(ui,{entries:e,isActive:!0,onCollapse:()=>s("compact"),embedded:!0})})}function fo(e,n){const[s,r]=p.useState(null);return p.useEffect(()=>{if(!n||!e.current){r(null);return}const i=()=>{const o=e.current?.getBoundingClientRect();if(!o)return;const a=240,l=window.innerHeight-o.bottom-8,c=o.top-8,d=l<a&&c>l;r(d?{top:o.top-4,left:o.left,width:o.width,flipUp:!0}:{top:o.bottom+4,left:o.left,width:o.width,flipUp:!1})};return i(),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[n,e]),s}function It({options:e,value:n,onChange:s,placeholder:r,noMatchesText:i,className:o,disabled:a,size:l}){const[c,d]=p.useState(!1),[f,h]=p.useState(""),m=p.useRef(null),u=p.useRef(null),g=p.useRef(null),C=p.useRef(null),S=fo(u,c);p.useEffect(()=>{const b=j=>{m.current&&!m.current.contains(j.target)&&C.current&&!C.current.contains(j.target)&&d(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]);const v=l==="sm"?"px-2 py-1.5 text-xs":"px-3 py-2 text-sm",y=e.find(b=>b.value===n)?.label??"",x=f?e.filter(b=>b.label.toLowerCase().includes(f.toLowerCase())):e;return t.jsxs("div",{ref:m,className:o??"",children:[t.jsxs("div",{ref:u,onClick:()=>{a||(d(!c),h(""),setTimeout(()=>g.current?.focus(),0))},className:`w-full ${v} bg-surface-elevated border border-border-default rounded-lg focus-within:border-brand-500 outline-none flex items-center ${a?"opacity-50 cursor-not-allowed pointer-events-none":"cursor-pointer"}`,children:[c?t.jsx("input",{ref:g,value:f,onChange:b=>h(b.target.value),onClick:b=>b.stopPropagation(),className:`w-full bg-transparent outline-none text-fg-primary ${v.split(" ").slice(2).join(" ")}`,placeholder:y||r,autoFocus:!0}):t.jsx("span",{className:y?"text-fg-primary":"text-fg-tertiary",children:y||r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&S&&t.jsx("div",{ref:C,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:S.flipUp?{bottom:window.innerHeight-S.top,left:S.left,width:S.width}:{top:S.top,left:S.left,width:S.width},children:x.length===0?t.jsx("div",{className:`${v} text-fg-tertiary`,children:i??"No matches"}):x.map(b=>t.jsx("div",{onClick:()=>{s(b.value),d(!1),h("")},className:`${v} cursor-pointer hover:bg-brand-500/10 ${b.value===n?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:b.label},b.value))})]})}const mm=[{value:"low",labelKey:"work:priority.low",dot:"bg-slate-400",active:"bg-slate-500/15 text-slate-500 border-slate-500/40"},{value:"medium",labelKey:"work:priority.medium",dot:"bg-blue-500",active:"bg-blue-500/15 text-blue-500 border-blue-500/40"},{value:"high",labelKey:"work:priority.high",dot:"bg-amber-500",active:"bg-amber-500/15 text-amber-600 border-amber-500/40"},{value:"urgent",labelKey:"work:priority.urgent",dot:"bg-red-500",active:"bg-red-500/15 text-red-500 border-red-500/40"}];function cs({value:e,onChange:n}){const{t:s}=Oe("work");return t.jsx("div",{className:"flex flex-wrap gap-2",children:mm.map(r=>{const i=e===r.value;return t.jsxs("button",{type:"button",onClick:()=>n(r.value),"aria-pressed":i,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-all ${i?`${r.active} font-medium`:"border-border-default text-fg-secondary hover:bg-surface-elevated"}`,children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${r.dot}`}),s(r.labelKey)]},r.value)})})}function Dl({kind:e,entity:n,agents:s,users:r,projects:i,onClose:o}){const a=n.title?.trim()||n.id,l=jc(a),c=n.projectId?i.find(h=>h.id===n.projectId)?.name??n.projectId:"",d=`${e==="requirement"?"📋":"✅"} ${l}`,f=[`@[${a}](${e}:${n.id})`,`[${e}]`,`ID: ${n.id}`,`Title: ${a}`,n.status?`Status: ${n.status}`:"",n.priority?`Priority: ${n.priority}`:"",c?`Project: ${c}`:""].filter(Boolean).join(`
|
|
8
|
+
`);return t.jsx(Nc,{chipLabel:d,chipContent:f,agents:s,users:r,defaultTarget:Cc(n.createdBy,s,r),onClose:o})}function pm({options:e,selected:n,onAdd:s,placeholder:r,noMatchesText:i,className:o}){const[a,l]=p.useState(!1),[c,d]=p.useState(""),f=p.useRef(null),h=p.useRef(null),m=p.useRef(null),u=p.useRef(null),g=fo(h,a);p.useEffect(()=>{const v=y=>{f.current&&!f.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const C=e.filter(v=>!n.includes(v.value)),S=c?C.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):C;return t.jsxs("div",{ref:f,className:o??"",children:[t.jsxs("div",{ref:h,onClick:()=>{l(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:c,onChange:v=>d(v.target.value),onClick:v=>v.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:r,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&g&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:g.flipUp?{bottom:window.innerHeight-g.top,left:g.left,width:g.width}:{top:g.top,left:g.left,width:g.width},children:S.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):S.map(v=>t.jsx("div",{onClick:()=>{s(v.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:v.label},v.value))})]})}function gm({options:e,onSelect:n,placeholder:s,noMatchesText:r,className:i,itemSuffix:o}){const[a,l]=p.useState(!1),[c,d]=p.useState(""),f=p.useRef(null),h=p.useRef(null),m=p.useRef(null),u=p.useRef(null),g=fo(h,a);p.useEffect(()=>{const S=v=>{f.current&&!f.current.contains(v.target)&&u.current&&!u.current.contains(v.target)&&l(!1)};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[]);const C=c?e.filter(S=>S.label.toLowerCase().includes(c.toLowerCase())):e;return t.jsxs("div",{ref:f,className:i??"",children:[t.jsxs("div",{ref:h,onClick:()=>{l(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:c,onChange:S=>d(S.target.value),onClick:S=>S.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-[11px]",placeholder:s,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:s}),t.jsx("svg",{className:"w-3.5 h-3.5 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&g&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:g.flipUp?{bottom:window.innerHeight-g.top,left:g.left,width:g.width}:{top:g.top,left:g.left,width:g.width},children:C.length===0?t.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:r??"No matches"}):C.map(S=>t.jsxs("div",{onClick:()=>{n(S.value),l(!1),d("")},className:"px-3 py-2 text-xs cursor-pointer hover:bg-brand-500/10 text-fg-primary flex items-center justify-between gap-2",children:[t.jsx("span",{className:"truncate",children:S.label}),o?.(S)]},S.value))})]})}function tr(e,n,s,r="Admin"){if(!e)return null;const i=n.find(a=>a.id===e);if(i)return i.name;const o=s.find(a=>a.id===e);return o?o.name:e==="anonymous"?r:null}function xm({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=Oe(["work","common"]),[o,a]=p.useState(!1),[l,c]=p.useState(e),d=p.useRef(null);p.useEffect(()=>{c(e)},[e]),p.useEffect(()=>{o&&d.current?.focus()},[o]);const f=async()=>{a(!1);const h=l.trim();if(h&&h!==e)try{await n(h)}catch{c(e)}else c(e)};return o?t.jsx("input",{ref:d,value:l,onChange:h=>c(h.target.value),onBlur:()=>{f()},onKeyDown:h=>{h.key==="Enter"&&f(),h.key==="Escape"&&(c(e),a(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${s??""}`,placeholder:r}):t.jsx("span",{onClick:()=>a(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.clickToEdit")})})}function bm({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=Oe(["work","common"]),[o,a]=p.useState(!1),[l,c]=p.useState(e),d=p.useRef(null);p.useEffect(()=>{c(e)},[e]),p.useEffect(()=>{o&&d.current&&(d.current.focus(),d.current.style.height="auto",d.current.style.height=d.current.scrollHeight+"px")},[o]);const f=async()=>{a(!1);const h=l.trim();if(h!==e)try{await n(h)}catch{c(e)}else c(e)};return o?t.jsx("textarea",{ref:d,value:l,onChange:h=>{c(h.target.value),h.target.style.height="auto",h.target.style.height=h.target.scrollHeight+"px"},onBlur:()=>{f()},onKeyDown:h=>{h.key==="Escape"&&(c(e),a(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${s??""}`,placeholder:r,rows:2}):t.jsx("p",{onClick:()=>a(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.addDescription")})})}const ym=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function Al(e){const n=e.match(ym);return n?{timestamp:n[1].trim(),author:n[2]?.trim()??"System",content:n[3].trim()}:{timestamp:"",author:"",content:e}}function wm(e,n){if(!e)return"";const s=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!s)return e;const r=new Date,i=+s[1],o=+s[2]-1,a=+s[3],l=+s[4],c=+s[5],d=new Date(i,o,a,l,c),f=r.getTime()-d.getTime();return f<6e4?n("work:relative.justNow"):f<36e5?n("work:relative.minutesAgo",{count:Math.floor(f/6e4)}):f<864e5?n("work:relative.hoursAgo",{count:Math.floor(f/36e5)}):f<6048e5?n("work:relative.daysAgo",{count:Math.floor(f/864e5)}):`${i}-${String(o+1).padStart(2,"0")}-${String(a).padStart(2,"0")}`}const Va=[{bg:"bg-brand-600/30",text:"text-brand-500",border:"border-brand-500/30"},{bg:"bg-blue-600/30",text:"text-blue-400",border:"border-blue-500/30"},{bg:"bg-green-600/30",text:"text-green-400",border:"border-green-500/30"},{bg:"bg-amber-600/30",text:"text-amber-400",border:"border-amber-500/30"},{bg:"bg-purple-600/30",text:"text-purple-400",border:"border-purple-500/30"},{bg:"bg-pink-600/30",text:"text-pink-400",border:"border-pink-500/30"}];function vm(e){let n=0;for(let s=0;s<e.length;s++)n=(n<<5)-n+e.charCodeAt(s)|0;return Va[Math.abs(n)%Va.length]}function km({note:e,compact:n}){const{t:s}=Oe(["work","common"]),r=Al(e),i=s("work:task.systemAuthor"),o=vm(r.author||i),a=r.author?r.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",l=wm(r.timestamp,s),c=!r.author||r.author==="System";return n?t.jsxs("div",{className:"flex gap-2.5 group",children:[t.jsx("div",{className:`w-6 h-6 rounded-full ${o.bg} flex items-center justify-center text-[9px] font-bold ${o.text} shrink-0 mt-0.5`,children:a}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-tertiary":o.text}`,children:c?i:r.author}),l&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l})]}),t.jsx("div",{className:"text-xs text-fg-secondary",children:t.jsx(pr,{content:r.content,className:"text-xs text-fg-secondary"})})]})]}):t.jsxs("div",{className:"flex gap-3 group",children:[t.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[t.jsx("div",{className:`w-7 h-7 rounded-full ${o.bg} flex items-center justify-center text-[10px] font-bold ${o.text}`,children:a}),t.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),t.jsx("div",{className:"flex-1 min-w-0 pb-4",children:t.jsxs("div",{className:`border ${o.border} rounded-lg overflow-hidden`,children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${o.bg} border-b ${o.border}`,children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-secondary":o.text}`,children:c?i:r.author}),l&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l})]}),t.jsx("div",{className:"px-3 py-2.5",children:t.jsx(pr,{content:r.content,className:"text-xs text-fg-secondary"})})]})})]})}const jm=new Set(["rejected","cancelled","archived"]),ds=[{id:"failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",statuses:["pending"],accent:"border-t-amber-500",dropStatus:"pending"},{id:"in_progress",statuses:["in_progress","blocked"],accent:"border-t-brand-500",dropStatus:"in_progress"},{id:"review",statuses:["review"],accent:"border-t-purple-500",dropStatus:"review"},{id:"done",statuses:["completed"],accent:"border-t-green-500",dropStatus:"completed"},{id:"closed",statuses:["rejected","cancelled","archived"],accent:"border-t-gray-500",dropStatus:"cancelled"}],Ya={pending:"bg-amber-500/15 text-amber-600",blocked:"bg-amber-500/15 text-amber-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500"},Ga={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-blue-500/15 text-blue-500",blocked:"bg-orange-500/15 text-orange-500",review:"bg-purple-500/15 text-purple-500",revision:"bg-amber-500/15 text-amber-600",completed:"bg-green-500/15 text-green-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-500/15 text-fg-tertiary",archived:"bg-gray-500/15 text-fg-tertiary"},Ka={low:"bg-gray-500/15 text-fg-tertiary",medium:"bg-blue-500/15 text-blue-500",high:"bg-amber-500/15 text-amber-600",urgent:"bg-red-500/15 text-red-500"},Ua={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-brand-500/15 text-brand-500",completed:"bg-green-500/15 text-green-600",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-600/15 text-fg-tertiary",archived:"bg-gray-600/10 text-fg-tertiary/60"};function Pl(e){return Object.keys(Ga).reduce((n,s)=>(n[s]={label:e(`work:status.task.${s}`),cls:Ga[s]},n),{})}function $l(e){return Object.keys(Ya).reduce((n,s)=>(n[s]={label:e(`work:status.sub.${s}`),cls:Ya[s]},n),{})}function Nm(e){return Object.keys(Ka).reduce((n,s)=>(n[s]={label:e(`work:priority.${s}`),cls:Ka[s]},n),{})}function ho(e){return Object.keys(Ua).reduce((n,s)=>(n[s]={label:e(`work:status.requirement.${s}`),cls:Ua[s]},n),{})}const Za=["low","medium","high","urgent"],Xa=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],Qa=["pending","in_progress","completed","rejected","cancelled"],Ja={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived"]),archived:new Set([])},Gs={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},kr={idle:"bg-green-400",working:"bg-blue-400",error:"bg-red-400",paused:"bg-amber-400",offline:"bg-gray-600",pending:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",rejected:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},ei={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function Cm({agent:e,anchorRect:n,onClose:s}){const{t:r}=Oe(["work","common"]),i=p.useRef(null);p.useEffect(()=>{const l=c=>{i.current&&!i.current.contains(c.target)&&s()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[s]);const o=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",a=e.status==="idle"?r("work:task.online"):e.status==="working"?r("work:task.working"):e.status==="error"?r("work:task.error"):r("work:task.offline");return t.jsxs("div",{ref:i,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:n.top+4,left:n.left},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[10px] font-bold text-brand-600 shrink-0",children:e.name.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),t.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o}`}),t.jsx("span",{className:"text-[10px] text-fg-secondary",children:a})]})]})]}),t.jsx("button",{onClick:()=>{s(),Bt.navigate(He.TEAM,{selectAgent:e.id})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1 transition-colors",children:r("work:task.viewProfile")})]})}function ys({comment:e,agents:n,onReply:s}){const{t:r}=Oe(["work","common"]),i=e.authorType==="agent"||e.authorType==="system",o=new Date(e.createdAt),a=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),l=o.toLocaleDateString([],{month:"short",day:"numeric"}),[c,d]=p.useState(null),[f,h]=p.useState(!1),[m,u]=p.useState([]),[g,C]=p.useState(!1),S=p.useCallback((j,k)=>{const M=n.find(T=>T.name.toLowerCase()===j.toLowerCase());if(M){const T=k.target.getBoundingClientRect();d({agent:M,top:T.bottom,left:T.left})}},[n]),v=p.useMemo(()=>n.map(j=>j.name),[n]),y=p.useCallback(j=>{const k=n.find(M=>M.name.toLowerCase()===e.authorName.toLowerCase());if(k){const M=j.currentTarget.getBoundingClientRect();d({agent:k,top:M.bottom,left:M.left})}},[n,e.authorName]),x=p.useCallback(async()=>{if(f){h(!1);return}const j=e.activityId;if(j&&(h(!0),!(m.length>0))){C(!0);try{const{logs:k}=await re.agents.getActivityLogs(e.authorId,j),M=k.map(T=>di(T,j,e.authorId)).filter(T=>T!==null).map(T=>({...T,ts:new Date(T.createdAt).getTime()}));u(M)}catch{}C(!1)}},[f,m.length,e]),b=p.useMemo(()=>yc(m.map(wc).filter(j=>j!==null)),[m]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[t.jsx("div",{onClick:y,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${i?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${i?"text-indigo-400":"text-blue-400"}`,onClick:y,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[l," ",a]}),s&&t.jsx("button",{onClick:()=>s(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r("work:task.reply")}),e.activityId&&i&&t.jsx("button",{onClick:x,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r(f?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&t.jsxs("button",{onClick:()=>{const j=document.getElementById(`comment-${e.replyTo}`);j&&(j.scrollIntoView({behavior:"smooth",block:"center"}),j.classList.add("bg-brand-500/10"),setTimeout(()=>j.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[t.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),t.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),t.jsx(pr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:S,knownNames:v}),e.attachments?.map((j,k)=>j.type==="image"?t.jsx("img",{src:j.url,alt:j.name,className:"mt-1 max-w-[200px] rounded"},k):null),f&&t.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:g?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:r("work:task.loadingExecutionLog")}):b.length===0?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:r("work:task.noExecutionLogAvailable")}):t.jsx(ui,{entries:m,isActive:!1,onCollapse:()=>h(!1),embedded:!0})})]}),c&&t.jsx(Cm,{agent:c.agent,anchorRect:{top:c.top,left:c.left},onClose:()=>d(null)})]})}function Sm({task:e,agents:n,users:s,authUser:r}){const{t:i}=Oe(["work","common"]),[o,a]=p.useState([]),[l,c]=p.useState([]),d=p.useRef(null),[f,h]=p.useState(new Map);p.useEffect(()=>{c([]),h(new Map),d.current&&(clearTimeout(d.current),d.current=null),re.tasks.getComments(e.id).then(v=>a(v.comments)).catch(()=>{})},[e.id]),p.useEffect(()=>Tt.on("task:comment",y=>{if(y.payload?.taskId===e.id&&y.payload.comment){const x=y.payload.comment;a(b=>b.some(j=>j.id===x.id)?b:[...b,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(c(b=>{const j=b.filter(k=>k.id!==x.authorId);return j.length===0&&d.current&&(clearTimeout(d.current),d.current=null),j}),h(b=>{const j=new Map(b);return j.delete(x.authorId),j}))}}),[e.id]),p.useEffect(()=>{if(l.length===0)return;const v=new Set(l.map(x=>x.id));return Tt.on("agent:activity_log",x=>{const b=x.payload;if(!b)return;const j=b.agentId;if(!v.has(j))return;const k=lo(b);k&&h(M=>co(M,j,k))})},[l]);const m=p.useMemo(()=>{const v=[];for(const y of e.notes??[]){const x=Al(y);let b;if(x.timestamp){const j=x.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);b=j?new Date(+j[1],+j[2]-1,+j[3],+j[4],+j[5],+(j[6]??0)):new Date(0)}else b=new Date(0);v.push({type:"note",note:y,ts:b})}for(const y of o)v.push({type:"comment",comment:y,ts:new Date(y.createdAt)});return v.sort((y,x)=>y.ts.getTime()-x.ts.getTime()),v},[e.notes,o]),[u,g]=p.useState(null),C=async(v,y,x,b)=>{let j;x.length>0&&(j=(await re.uploads.upload(x.map(D=>({dataUrl:D.dataUrl,name:D.name})),"comments")).files.map(D=>({type:"image",url:D.url,name:D.name}))),await re.tasks.addComment(e.id,v,r?.name,j,r?.id,y.length>0?y:void 0,b);const k=[],M=new Set,T=A=>{if(M.has(A)||A===r?.id)return;M.add(A);const D=n.find(E=>E.id===A);D&&k.push({id:D.id,name:D.name,avatarUrl:D.avatarUrl})};for(const A of y){const D=n.find(E=>E.name.toLowerCase()===A.toLowerCase());D&&T(D.id)}e.assignedAgentId&&T(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&T(e.createdBy),k.length>0&&(d.current&&clearTimeout(d.current),c(k),d.current=setTimeout(()=>c([]),12e4))},S=p.useCallback(v=>{g({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return t.jsxs("div",{className:"mt-5",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:i("work:task.activityCommentsHeading")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[m.length===0&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:i("work:task.noActivityYet")}),m.map((v,y)=>v.type==="note"?t.jsx(km,{note:v.note,compact:!0},`n-${y}`):t.jsx(ys,{comment:v.comment,agents:n,onReply:S},`c-${v.comment.id}`)),l.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(v=>{const y=f.get(v.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(He.TEAM,{agentId:v.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Us,{name:v.name,avatarUrl:v.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:v.name}),y.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(uo,{entries:y})})]},v.id)})})]}),t.jsx(mi,{agents:n,humans:s,onSubmit:C,replyTo:u,onCancelReply:()=>g(null),placeholder:i("work:task.commentPlaceholder")})]})}function ti({entries:e,comments:n,agents:s,isExecuting:r}){const i=p.useMemo(()=>{const a=[...e.map(l=>({kind:"entry",entry:l,ts:l.createdAt?new Date(l.createdAt).getTime():0})),...n.map(l=>({kind:"comment",comment:l,ts:new Date(l.createdAt).getTime()}))];return a.sort((l,c)=>l.ts-c.ts),a},[e,n]),o=p.useMemo(()=>{const a=[];let l=[];const c=()=>{l.length!==0&&(a.push({kind:"entries",key:`entries-${a.length}`,entries:l}),l=[])};return i.forEach(d=>{d.kind==="comment"?(c(),a.push({kind:"comment",key:`c-${d.comment.id}`,comment:d.comment})):l.push(d.entry)}),c(),a},[i]);return t.jsx(t.Fragment,{children:o.map(a=>a.kind==="comment"?t.jsx(ys,{comment:a.comment,agents:s},a.key):t.jsx(kc,{entries:a.entries,isStreaming:r},a.key))})}function Em({task:e,isRunning:n,authUser:s,agents:r}){const i=e.id,{t:o}=Oe(["work","common"]),[a,l]=p.useState([]),[c,d]=p.useState(new Map),[f,h]=p.useState(new Set),[m,u]=p.useState([]),[g,C]=p.useState(""),[S,v]=p.useState(n),[y,x]=p.useState(!0),[b,j]=p.useState(new Set),[k,M]=p.useState(""),[T,A]=p.useState(!1),[D,E]=p.useState([]),P=p.useRef(null),[q,N]=p.useState(new Map),[O,_]=p.useState([]),[z,L]=p.useState([]),[R,$]=p.useState(!1),W=p.useRef(null),F=p.useRef(null);p.useEffect(()=>{v(n)},[n]),p.useEffect(()=>{E([]),N(new Map),P.current&&(clearTimeout(P.current),P.current=null)},[i]),p.useEffect(()=>{x(!0),Promise.all([re.tasks.getLogsSummary(i).catch(()=>({rounds:[]})),re.tasks.getComments(i).catch(()=>({comments:[]}))]).then(([Q,le])=>{const de=Q.rounds;if(l(de),u(le.comments),de.length===0){x(!1);return}const fe=de[de.length-1].round;j(new Set([fe])),re.tasks.getLogs(i,fe).catch(()=>({logs:[]})).then(xe=>{d(new Map([[fe,xe.logs]])),x(!1)})})},[i]),p.useEffect(()=>{const Q=e.assignedAgentId;Q&&($(!0),re.agents.getActivities(Q,{taskId:i,limit:20}).then(le=>L(le.activities)).catch(()=>L([])).finally(()=>$(!1)))},[i,e.assignedAgentId]);const X=p.useCallback(Q=>{c.has(Q)||f.has(Q)||(h(le=>new Set(le).add(Q)),re.tasks.getLogs(i,Q).catch(()=>({logs:[]})).then(le=>{d(de=>new Map(de).set(Q,le.logs)),h(de=>{const fe=new Set(de);return fe.delete(Q),fe})}))},[i,c,f]),B=p.useCallback(Q=>{j(le=>{const de=new Set(le);return de.has(Q)?de.delete(Q):(de.add(Q),c.has(Q)||X(Q)),de})},[c,X]);p.useEffect(()=>{const Q=Tt.on("task:log",fe=>{const xe=fe.payload;if(xe.taskId!==i)return;const be={id:xe.id,taskId:xe.taskId,agentId:xe.agentId,seq:xe.seq,type:xe.logType,content:xe.content,metadata:xe.metadata,executionRound:xe.executionRound,createdAt:xe.createdAt},U=be.executionRound??1;l(ce=>ce.find(we=>we.round===U)?ce:[...ce,{round:U,logCount:0,toolCount:0,firstAt:be.createdAt,lastAt:be.createdAt,status:"running"}]),j(ce=>ce.has(U)?ce:new Set(ce).add(U)),d(ce=>{const pe=ce.get(U)??[];return be.id&&pe.some(we=>we.id===be.id)?ce:new Map(ce).set(U,[...pe,be])}),be.type==="text"&&C(""),be.type==="status"&&(be.content==="started"||be.content==="resumed"?v(!0):["completed","failed","cancelled","execution_finished"].includes(be.content)&&(v(!1),l(ce=>ce.map(pe=>pe.round===U?{...pe,status:be.content}:pe)))),be.type==="error"&&v(!1)}),le=Tt.on("task:log:delta",fe=>{const xe=fe.payload;xe.taskId===i&&C(be=>be+xe.text)}),de=Tt.on("task:comment",fe=>{const xe=fe.payload;if(xe.taskId!==i)return;const be=xe.comment;u(U=>U.some(ce=>ce.id===be.id)?U:[...U,be]),(be.authorType==="agent"||be.authorId?.startsWith("agt_"))&&(E(U=>{const ce=U.filter(pe=>pe.id!==be.authorId);return ce.length===0&&P.current&&(clearTimeout(P.current),P.current=null),ce}),N(U=>{const ce=new Map(U);return ce.delete(be.authorId),ce}))});return()=>{Q(),le(),de()}},[i]),p.useEffect(()=>{if(D.length===0)return;const Q=new Set(D.map(de=>de.id));return Tt.on("agent:activity_log",de=>{const fe=de.payload;if(!fe)return;const xe=fe.agentId;if(!Q.has(xe))return;const be=lo(fe);be&&N(U=>co(U,xe,be))})},[D]);const I=p.useMemo(()=>{const Q=[];for(const[,le]of c)Q.push(...le);return Q.sort((le,de)=>le.seq-de.seq),Q},[c]),Y=p.useMemo(()=>I.map(Q=>Wo(Q)),[I]),V=a.length>1,H=Q=>{const le=Q.target.files;if(le){for(const de of Array.from(le)){if(!de.type.startsWith("image/"))continue;const fe=new FileReader;fe.onload=()=>{_(xe=>[...xe,{type:"image",url:fe.result,name:de.name}])},fe.readAsDataURL(de)}Q.target.value=""}},Z=async()=>{if(!(!k.trim()&&O.length===0)){A(!0);try{let Q;O.length>0&&(Q=(await re.uploads.upload(O.map(U=>({dataUrl:U.url,name:U.name})),"comments")).files.map(U=>({type:"image",url:U.url,name:U.name})));const le=await re.tasks.addComment(i,k,s?.name,Q,s?.id);le.comment&&u(be=>be.some(U=>U.id===le.comment.id)?be:[...be,le.comment]),M(""),_([]);const de=[],fe=new Set,xe=be=>{if(fe.has(be)||be===s?.id)return;fe.add(be);const U=r.find(ce=>ce.id===be);U&&de.push({id:U.id,name:U.name,avatarUrl:U.avatarUrl})};e.assignedAgentId&&xe(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&xe(e.createdBy),de.length>0&&(P.current&&clearTimeout(P.current),E(de),P.current=setTimeout(()=>E([]),12e4))}catch{}A(!1)}},te=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[O.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:O.map((Q,le)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:Q.url,alt:Q.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>_(de=>de.filter((fe,xe)=>xe!==le)),className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-600 text-white text-[10px] flex items-center justify-center opacity-0 group-hover:opacity-100",children:"×"})]},le))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:k,onChange:Q=>M(Q.target.value),onKeyDown:Q=>{Q.key==="Enter"&&!Q.shiftKey&&(Q.preventDefault(),Z())},placeholder:o("work:task.commentInstructionPlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-blue-500 outline-none text-fg-primary placeholder-gray-600"}),t.jsx("input",{type:"file",ref:W,accept:"image/*",multiple:!0,onChange:H,className:"hidden"}),t.jsx("button",{onClick:()=>W.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:o("work:task.attachImage"),children:"📎"}),t.jsx("button",{onClick:()=>{Z()},disabled:T||!k.trim()&&O.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:o("common:send")})]})]});if(y)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:o("work:task.loadingLogs")});if(a.length===0&&!g){const Q=e.assignedAgentId?r.find(we=>we.id===e.assignedAgentId):void 0,le=z.length>0,de=Q&&Q.currentTaskId&&Q.currentTaskId!==e.id,fe=e.status==="pending",xe=e.status==="in_progress",be=!e.assignedAgentId;let U="📋",ce=o("work:task.emptyLogs.default"),pe=o("work:task.emptyLogs.defaultHint");return be?(U="👤",ce=o("work:task.emptyLogs.noAgent"),pe=o("work:task.emptyLogs.noAgentHint")):fe?(U="⏳",ce=o("work:task.emptyLogs.pending"),pe=o("work:task.emptyLogs.pendingHint")):xe&&de?(U="🔄",ce=o("work:task.emptyLogs.agentBusy",{agent:Q?.name??e.assignedAgentId}),pe=o("work:task.emptyLogs.agentBusyHint")):xe&&(U="⏳",ce=o("work:task.emptyLogs.starting"),pe=o("work:task.emptyLogs.startingHint")),t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsx("div",{className:"flex-1 overflow-y-auto",children:R?t.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:o("work:task.loadingLogs")}):le?t.jsxs("div",{className:"px-4 py-4",children:[t.jsxs("div",{className:"text-xs text-fg-secondary mb-3 flex items-center gap-1.5",children:[t.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-blue-500"}),o("work:task.relatedSessions",{agent:Q?.name??o("work:task.agent"),count:z.length})]}),t.jsx("div",{className:"space-y-1.5",children:z.map(we=>{const _e=!we.endedAt,ee=we.type==="task"?"🔧":we.type==="chat"||we.type==="respond_in_session"?"💬":we.type==="heartbeat"?"💓":"📋";return t.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default/50 text-left transition-colors group",onClick:()=>Bt.navigate(He.TEAM,{agentId:e.assignedAgentId}),children:[t.jsx("span",{className:"text-sm shrink-0",children:ee}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary truncate",children:we.label}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(we.startedAt).toLocaleString(),we.endedAt?` — ${we.totalTools} tools, ${we.totalTokens.toLocaleString()} tokens`:""]})]}),_e&&t.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10px] text-green-500 font-medium",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"}),o("work:task.sessionLive")]}),!_e&&t.jsx("span",{className:`shrink-0 text-[10px] ${we.success?"text-fg-tertiary":"text-red-400"}`,children:we.success?"✓":"✗"}),t.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},we.id)})})]}):t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsxs("div",{className:"text-center text-fg-tertiary",children:[t.jsx("div",{className:"text-2xl mb-2",children:U}),t.jsxs("div",{className:"text-xs",children:[ce,t.jsx("br",{}),t.jsx("span",{className:"text-fg-muted",children:pe})]})]})})}),te]})}if(!V)return t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[t.jsx(ti,{entries:Y,comments:m,agents:r,isExecuting:S}),S&&g&&t.jsx(Fo,{content:g}),S&&!g&&Y.length>0&&t.jsx(Vo,{})]}),te]});const oe=(Q,le)=>{const de=Q.firstAt?new Date(Q.firstAt).getTime():0,fe=le?.firstAt?new Date(le.firstAt).getTime():1/0;return m.filter(xe=>{const be=new Date(xe.createdAt).getTime();return be>=de&&be<fe})},ue=a.length>0?m.filter(Q=>new Date(Q.createdAt).getTime()<new Date(a[0].firstAt).getTime()):[];return t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsx("div",{ref:F}),t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[ue.length>0&&t.jsx("div",{className:"space-y-0.5",children:ue.map(Q=>t.jsx(ys,{comment:Q,agents:r},Q.id))}),a.map((Q,le)=>{const de=b.has(Q.round),fe=Q.round===a[a.length-1].round,xe=c.get(Q.round),be=f.has(Q.round),U=oe(Q,a[le+1]),ce=Q.status==="completed"||Q.status==="execution_finished"?"✅":Q.status==="failed"?"❌":Q.status==="cancelled"?"⏹":"🔄",pe=Q.lastAt&&Q.firstAt?Math.max(0,new Date(Q.lastAt).getTime()-new Date(Q.firstAt).getTime()):0,we=pe>=6e4?`${Math.floor(pe/6e4)}m ${Math.floor(pe%6e4/1e3)}s`:pe>=1e3?`${Math.floor(pe/1e3)}s`:"";return t.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[t.jsxs("button",{onClick:()=>B(Q.round),className:"w-full flex items-center justify-between px-3 py-2 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm",children:ce}),t.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:o("work:task.roundHeader",{n:Q.round})}),U.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",U.length]}),fe&&S&&t.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.toolCount",{count:Q.toolCount})}),we&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:we}),t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${de?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})]}),de&&t.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[be&&t.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:o("work:task.loadingRound",{n:Q.round})}),xe&&t.jsx(ti,{entries:xe.map(_e=>Wo(_e)),comments:U,agents:r,isExecuting:fe&&S}),fe&&S&&g&&t.jsx(Fo,{content:g}),fe&&S&&!g&&!be&&t.jsx(Vo,{})]})]},Q.round)}),D.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:D.map(Q=>{const le=q.get(Q.id)??[];return t.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(He.TEAM,{agentId:Q.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Us,{name:Q.name,avatarUrl:Q.avatarUrl,size:24,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx("span",{className:"text-xs font-medium text-fg-secondary truncate",children:Q.name}),le.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")})]}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),le.length>0&&t.jsx("div",{className:"ml-9 mt-1",children:t.jsx(uo,{entries:le})})]},Q.id)})})]}),te]})}const ni=new Set([".md",".markdown",".txt",".json",".yaml",".yml",".toml",".csv",".xml",".html",".htm",".css",".js",".ts",".jsx",".tsx",".py",".sh",".log",".env",".cfg",".ini",".png",".jpg",".jpeg",".gif",".webp",".svg",".mp3",".wav",".ogg",".flac",".aac",".m4a",".opus",".mp4",".webm",".mov",".mkv",".m4v",".pdf",".docx",".doc",".xlsx",".xls",".pptx",".ppt"]);function Qr(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Mm({filePath:e,onClose:n,onOpenExternal:s}){const{t:r}=Oe(["work","common"]),[i,o]=p.useState([e]),a=i[i.length-1],[l,c]=p.useState(null),[d,f]=p.useState(null),[h,m]=p.useState(!0),[u,g]=p.useState(!1);p.useEffect(()=>{m(!0),f(null),c(null),re.files.preview(a).then(T=>c(T)).catch(T=>f(String(T))).finally(()=>m(!1))},[a]);const C=T=>o(A=>[...A,T]),S=()=>o(T=>T.length>1?T.slice(0,-1):T),v=i.length>1,y=T=>{re.files.reveal(T).catch(()=>{})},x=()=>{navigator.clipboard?.writeText(a).then(()=>{g(!0),setTimeout(()=>g(!1),1500)}).catch(()=>{})},b=T=>{T.isDirectory||ni.has(T.ext)?C(T.path):y(T.path)},j=a.split("/").pop()??a,k=l?.type==="directory",M=(T,A)=>{if(A)return"📁";const D=[".md",".markdown"],E=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return D.includes(T)?"📝":E.includes(T)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(T)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(T)?"💻":"📄"};return t.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",onClick:n,children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl w-[720px] max-w-[92vw] max-h-[85vh] flex flex-col shadow-2xl",onClick:T=>T.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[v&&t.jsx("button",{onClick:S,className:"text-fg-tertiary hover:text-fg-primary text-sm shrink-0 p-1 -ml-1 rounded hover:bg-surface-elevated/60 transition-colors",title:r("common:back"),children:t.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),k?t.jsx("svg",{className:"w-4 h-4 text-amber-500 shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l.872.87A.5.5 0 008.665 3.5H13.5A1.5 1.5 0 0115 5v8.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-10z"})}):t.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),t.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),t.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:j}),k&&l.entries&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",l.entries.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[t.jsx("button",{onClick:x,className:"text-fg-tertiary hover:text-fg-primary px-2 py-1.5 rounded hover:bg-surface-elevated/60 transition-colors text-xs",title:r("common:copyPath",{defaultValue:"复制路径"}),children:u?`${r("common:copied",{defaultValue:"已复制"})} ✓`:r("common:copyPath",{defaultValue:"复制路径"})}),t.jsx("button",{onClick:()=>s?s():y(a),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:r(s?"work:task.openInDeliverables":"work:task.openInFinder"),children:t.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),t.jsx("button",{onClick:n,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]})]}),t.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:a})}),t.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[h&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.filePreviewLoading")}),d&&t.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:d}),l?.type==="directory"&&l.entries&&t.jsxs("div",{className:"divide-y divide-border-default/50",children:[l.entries.length===0&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.emptyDirectory")}),l.entries.map(T=>t.jsxs("button",{onClick:()=>b(T),className:"w-full flex items-center gap-3 px-5 py-2.5 hover:bg-surface-elevated/40 transition-colors text-left group",children:[t.jsx("span",{className:"text-sm shrink-0",children:M(T.ext,T.isDirectory)}),t.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:T.name}),!T.isDirectory&&T.size!=null&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Qr(T.size)}),T.isDirectory&&t.jsx("svg",{className:"w-3.5 h-3.5 text-fg-tertiary shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})}),!T.isDirectory&&!ni.has(T.ext)&&t.jsxs("svg",{className:"w-3 h-3 text-fg-tertiary shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})]},T.path))]}),l&&l.type!=="directory"&&t.jsx("div",{className:"p-5",children:l.type==="office"&&l.streamUrl?t.jsx(bc,{data:{format:(l.extension||"").replace(/^\./,"")||"pdf",streamUrl:l.streamUrl||(l.path?re.files.streamUrl(l.path):re.files.streamUrl(a)),name:l.name,size:l.size},reference:l.path||a,onFallback:()=>y(a)}):l.type==="image"&&l.content?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:`data:${l.mimeType};base64,${l.content}`,alt:l.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):l.type==="audio"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("audio",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?re.files.streamUrl(l.path):re.files.streamUrl(a)),className:"w-full"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${Qr(l.size)}`:""]})]}):l.type==="video"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("video",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?re.files.streamUrl(l.path):re.files.streamUrl(a)),className:"w-full max-h-[60vh] rounded-lg bg-black"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${Qr(l.size)}`:""]})]}):l.type==="binary"||l.content==null?t.jsxs("div",{className:"space-y-3 text-center py-6",children:[t.jsx("p",{className:"text-sm text-fg-secondary",children:r("work:task.cannotPreviewFile",{defaultValue:"This file type cannot be previewed."})}),t.jsxs("p",{className:"text-xs text-fg-tertiary font-mono",children:[l.name,l.extension?` (${l.extension})`:"",l.size!=null?` · ${Qr(l.size)}`:""]}),t.jsx("button",{onClick:()=>y(a),className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",children:r("work:task.openInFinder")})]}):t.jsx(Mc,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function ri({task:e,agents:n,projects:s,requirements:r,allTasks:i,users:o,onClose:a,onRefresh:l,authUser:c,scrollToComments:d,onScrollToCommentsDone:f,onReqClick:h,onProjectClick:m}){const{t:u}=Oe(["work","common"]),g=p.useMemo(()=>Pl(u),[u]),[C,S]=p.useState([]),[v,y]=p.useState(""),[x,b]=p.useState(!1),[j,k]=p.useState(!1),[M,T]=p.useState(null),[A,D]=p.useState(null),[E,P]=p.useState(!1),[q,N]=p.useState(!1),[O,_]=p.useState(!1),[z,L]=p.useState(null),[R,$]=p.useState(!1),[W,F]=p.useState(!1),[X,B]=p.useState("details"),I=p.useRef(null),[Y,V]=p.useState("none"),[H,Z]=p.useState(1),[te,oe]=p.useState([]),ue=p.useCallback(async()=>{try{const{results:G}=await re.deliverables.search({taskId:e.id,limit:200});oe(G.filter(ge=>ge.status!=="outdated"))}catch{}},[e.id]),Q=p.useCallback(G=>{B(G),G==="deliverables"&&ue(),requestAnimationFrame(()=>{I.current?.scrollTo({top:0,behavior:"instant"})})},[ue]),le=p.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),de=xc(le,X,Q);p.useEffect(()=>{const G=I.current;if(!G)return;const ge=()=>{const{scrollTop:Te,scrollHeight:Ee,clientHeight:rt}=G;if(!(Ee>rt+50)){V("none");return}const Rn=Te<30,nr=Te+rt>=Ee-30;V(Rn?"top":nr?"bottom":"middle")};ge(),G.addEventListener("scroll",ge,{passive:!0});const Ie=new ResizeObserver(ge);return Ie.observe(G),()=>{G.removeEventListener("scroll",ge),Ie.disconnect()}},[X]),p.useEffect(()=>{if(!d)return;B("details");const G=setTimeout(()=>{const ge=I.current;ge&&ge.scrollTo({top:ge.scrollHeight,behavior:"smooth"}),f?.()},300);return()=>clearTimeout(G)},[d,f]);const[fe,xe]=p.useState(null),[be,U]=p.useState(!1),[ce,pe]=p.useState(null),[we,_e]=p.useState(!1),[ee,Se]=p.useState(e.description),ae=p.useRef(null),ie=p.useRef(null),me=p.useRef(80);p.useEffect(()=>{if(we&&ie.current){const G=ie.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,me.current)+"px",G.focus()}},[we]);const[Ge,Ne]=p.useState(!1),[je,Ze]=p.useState("");p.useEffect(()=>{ue()},[ue,e.updatedAt]),p.useEffect(()=>{const G=["created","updated","removed"].map(ge=>Tt.on(`deliverable:${ge}`,Ie=>{const Te=Ie.payload;!Te||Te.taskId!==e.id||ue()}));return()=>{G.forEach(ge=>ge())}},[e.id,ue]);const[yt,wt]=p.useState(!1),lt=jr(),vt=20,Je=p.useCallback(async()=>{try{const G=await re.tasks.listSubtasks(e.id);S(G.subtasks)}catch{}},[e.id]);p.useEffect(()=>{Je()},[Je,e.updatedAt]);const $e=async G=>{if(!R){$(!0);try{await G(),l(),await Je()}catch(ge){xe(String(ge).replace("Error: ",""))}finally{$(!1)}}},ft=G=>$e(()=>re.tasks.update(e.id,{priority:G})),at=G=>$e(()=>re.tasks.assign(e.id,G||null)),zt=G=>$e(()=>re.tasks.update(e.id,{projectId:G||null})),kt=async()=>{if(!R){$(!0);try{await re.tasks.pause(e.id),l()}finally{$(!1)}}},dt=G=>{if(G instanceof ci){if(G.code==="TASK_BLOCKED"){const ge=G.data?.dependencyTitles??[];return ge.length?u("work:task.errorBlockedDeps",{deps:ge.join("、")}):u("work:task.errorBlocked")}if(G.code==="TASK_NOT_BLOCKED")return u("work:task.errorNotBlocked");if(G.code==="TASK_NOT_RETRYABLE")return u("work:task.errorNotRetryable")}return String(G).replace("Error: API error: 400","Server error").replace("Error: ","")},Yt=async()=>{if(!R){$(!0),xe(null),Q("logs");try{await re.tasks.resume(e.id),l()}catch(G){xe(dt(G))}finally{$(!1)}}},jt=async()=>{v.trim()&&(await re.tasks.createSubtask(e.id,v.trim()),y(""),b(!1),Je(),l())},hn=async G=>{G.status==="completed"||G.status==="cancelled"?await re.tasks.cancelSubtask(e.id,G.id):await re.tasks.completeSubtask(e.id,G.id),Je(),l()},ve=async G=>{await re.tasks.deleteSubtask(e.id,G.id),T(null),Je(),l()},ct=async()=>{if(!R){$(!0);try{await re.tasks.updateStatus(e.id,"in_progress"),l()}finally{$(!1)}}},ht=async()=>{if(!R){$(!0),xe(null),Q("logs");try{await re.tasks.retry(e.id),l()}catch(G){xe(dt(G))}finally{$(!1)}}},mt=async()=>{if(!R){$(!0),xe(null),Q("logs");try{await re.tasks.runNow(e.id),l()}catch(G){xe(dt(G)),l()}finally{$(!1)}}},pt=p.useRef(l);pt.current=l,p.useEffect(()=>Tt.on("task:update",ge=>{ge.payload.taskId===e.id&&(Je(),ue(),pt.current())}),[e.id,Je,ue]);const Ht=C.filter(G=>G.status==="completed").length,bt=C.filter(G=>G.status==="cancelled").length,Re=Ht+bt,qe=e.status==="in_progress",gt=e.status==="blocked",qt=gt&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(G=>{const ge=i.find(Ie=>Ie.id===G);return ge&&ge.status==="completed"})),Wt=e.status==="completed",Xe=e.status==="failed",Pe=e.status==="rejected",ze=e.status==="cancelled",De=e.status==="archived",We=Wt||Xe||Pe||ze||De,nt=e.taskType==="scheduled"&&!!e.scheduleConfig,Qe=nt&&!!e.scheduleConfig?.paused,Nt=(()=>{const G=s.find(ge=>ge.id===e.projectId);return G&&G.name!=="default"?G:void 0})(),it=r.find(G=>G.id===e.requirementId);return n.find(G=>G.id===e.assignedAgentId),t.jsxs("div",{className:"flex flex-col w-full h-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 px-6 pt-5 pb-3 border-b border-border-default shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[lt&&t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("h3",{className:"flex-1 min-w-0 text-base font-semibold leading-snug text-fg-primary",children:[e.title," ",(()=>{const G=g[e.status];return G?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${G.cls}`,children:G.label}):t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium bg-gray-500/15 text-fg-tertiary whitespace-nowrap align-middle",children:e.status.replace(/_/g," ")})})(),qt&&t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle bg-red-500/15 text-red-500",children:u("work:task.abnormalBlock")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t.jsx(fi,{onClick:()=>F(!0),label:u("work:task.sendToChat",{defaultValue:"发送到对话"})}),t.jsx("button",{onClick:a,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]})]}),W&&t.jsx(Dl,{kind:"task",entity:e,agents:n,users:o,projects:s,onClose:()=>F(!1)}),t.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[t.jsx("button",{onClick:()=>Q("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${X==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:u("work:task.detailsTab")}),t.jsxs("button",{onClick:()=>Q("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${X==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("work:task.executionLogTab"),qe&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsx("button",{onClick:()=>Q("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${X==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const G=te.filter(ge=>typeof ge.reference=="string"&&ge.reference.length>0).length;return G>0?u("work:task.deliverablesCount",{count:G}):u("work:task.deliverables")})()}),t.jsx("button",{onClick:()=>Q("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${X==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:u("work:task.historyTab")})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:I,"data-swipe-owner":!0,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:de.onTouchStart,onTouchEnd:de.onTouchEnd,children:[t.jsxs("div",{className:X==="logs"?"min-w-0 min-h-full":"hidden",children:[fe&&t.jsxs("div",{className:"mx-4 mt-3 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:[t.jsx("span",{className:"font-medium",children:u("work:task.failedToStart")})," ",fe]}),t.jsx(Em,{task:e,isRunning:e.status==="in_progress",authUser:c,agents:n})]}),t.jsxs("div",{className:X==="details"?"":"hidden",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:we?t.jsx("textarea",{ref:ie,value:ee,onChange:G=>{Se(G.target.value);const ge=G.target;ge.style.height="auto",ge.style.height=ge.scrollHeight+"px"},onBlur:()=>{ee!==e.description&&$e(()=>re.tasks.update(e.id,{description:ee})),_e(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),Se(e.description),_e(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:u("work:task.addDescription")}):t.jsx("div",{ref:ae,className:"group relative cursor-pointer rounded-lg -mx-2 px-2 -my-1 py-1 hover:bg-surface-elevated/50 transition-colors",onClick:G=>{G.target.closest("a, button, [data-entity-link]")||(me.current=Math.max(ae.current?.offsetHeight??80,60),Se(e.description),_e(!0))},role:"button",tabIndex:0,onKeyDown:G=>G.key==="Enter"&&(Se(e.description),_e(!0)),children:e.description?t.jsxs("div",{children:[t.jsx("div",{className:lt&&!yt?"line-clamp-3":"",children:t.jsx(pr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),lt&&e.description.length>150&&t.jsx("button",{onClick:G=>{G.stopPropagation(),wt(!yt)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:u(yt?"work:task.collapse":"common:showMore")})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:u("work:task.noDescription")})})}),(Nt||it)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Nt&&t.jsxs("span",{className:`flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full ${m?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:m?()=>m(Nt.id):void 0,role:m?"button":void 0,tabIndex:m?0:void 0,onKeyDown:m?G=>G.key==="Enter"&&m(Nt.id):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.projectLabel")}),Nt.name]}),it&&t.jsxs("span",{className:`flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full ${h?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:h?()=>h(it):void 0,role:h?"button":void 0,tabIndex:h?0:void 0,onKeyDown:h?G=>G.key==="Enter"&&h(it):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.requirementLabel")}),it.title.length>40?it.title.slice(0,40)+"…":it.title]})]}),t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default",children:[t.jsx("div",{className:"flex items-center justify-between mb-1.5",children:t.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:u("work:task.dependencies")})}),e.blockedBy&&e.blockedBy.length>0?t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(G=>{const ge=i.find(Te=>Te.id===G),Ie=ge&&(ge.status==="completed"||ge.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Ie?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:Ie?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${Ie?"line-through opacity-60":""}`,children:ge?ge.title.slice(0,30):G.slice(-8)}),!We&&t.jsx("button",{onClick:async()=>{const Te=(e.blockedBy??[]).filter(Ee=>Ee!==G);await re.tasks.update(e.id,{blockedBy:Te}),l()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:u("work:task.removeDependency"),children:"×"})]},G)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:u("work:task.noDependencies")}),qt&&t.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 bg-red-500/10 border border-red-500/20 rounded-lg text-xs text-red-500 mb-2",children:[t.jsxs("svg",{className:"w-3.5 h-3.5 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),t.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),t.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),t.jsx("span",{children:u("work:task.abnormalBlockHint")})]}),!We&&t.jsx(gm,{options:i.filter(G=>G.id!==e.id&&!(e.blockedBy??[]).includes(G.id)).map(G=>({value:G.id,label:G.title,status:G.status})),placeholder:u("work:task.addDependency"),noMatchesText:u("work:task.noMatches"),itemSuffix:G=>G.status==="completed"||G.status==="archived"?t.jsx("span",{className:"text-[9px] text-green-600 shrink-0",children:"✓"}):G.status==="cancelled"?t.jsx("span",{className:"text-[9px] text-fg-tertiary shrink-0",children:"✕"}):null,onSelect:async G=>{if(!G)return;const ge=[...e.blockedBy??[],G];await re.tasks.update(e.id,{blockedBy:ge}),l()}})]}),t.jsx("div",{className:"px-6 py-4 border-b border-border-default/60",children:t.jsxs("div",{className:Ll,children:[t.jsx("label",{className:Ve,children:u("work:task.projectLabel")}),t.jsx(It,{size:"sm",disabled:R,options:[{value:"",label:u("work:task.noProject")},...s.map(G=>({value:G.id,label:G.name}))],value:e.projectId??"",onChange:G=>{zt(G)},placeholder:u("work:task.noProject"),noMatchesText:u("work:task.noMatches")}),t.jsx("label",{className:Ve,children:u("work:task.requirementLabel")}),t.jsx(It,{size:"sm",disabled:R,options:[{value:"",label:u("work:task.noRequirement")},...r.filter(G=>!e.projectId||G.projectId===e.projectId).map(G=>({value:G.id,label:G.title}))],value:e.requirementId??"",onChange:G=>$e(()=>re.tasks.update(e.id,{requirementId:G||null})),placeholder:u("work:task.noRequirement"),noMatchesText:u("work:task.noMatches")}),t.jsx("label",{className:Ve,children:u("work:task.assignee")}),t.jsx(It,{size:"sm",disabled:R,options:[{value:"",label:u("work:task.unassigned")},...n.map(G=>({value:G.id,label:`${G.name} (${G.status})`}))],value:e.assignedAgentId??"",onChange:G=>{at(G)},placeholder:u("work:task.unassigned"),noMatchesText:u("work:task.noMatches")}),t.jsx("label",{className:Ve,children:u("work:task.reviewer")}),t.jsx(It,{size:"sm",disabled:R,options:[...o.map(G=>({value:`human:${G.id}`,label:G.name})),...n.map(G=>({value:`agent:${G.id}`,label:`${G.name} (${G.status})`}))],value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:G=>{if(!G)return;const ge=G.startsWith("human:"),Ie=G.replace(/^(human|agent):/,"");(Ie!==e.reviewerId||(ge?"human":"agent")!==(e.reviewerType??"agent"))&&$e(()=>re.tasks.update(e.id,{reviewerId:Ie,reviewerType:ge?"human":"agent"}))},placeholder:u("work:task.selectReviewer"),noMatchesText:u("work:task.noMatches")}),t.jsx("label",{className:Ve,children:u("work:task.priority")}),t.jsx(cs,{value:e.priority,onChange:G=>{ft(G)}})]})}),t.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&t.jsx("span",{children:u("work:task.createdBy",{name:tr(e.createdBy,n,o)??e.createdBy})}),e.updatedBy&&t.jsx("span",{children:u("work:task.updatedBy",{name:tr(e.updatedBy,n,o)??e.updatedBy})}),e.createdAt&&t.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&t.jsx("span",{children:u("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&t.jsx("span",{children:u("work:task.updatedMeta",{date:new Date(e.updatedAt).toLocaleDateString()})}),e.projectId&&t.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&t.jsx("span",{className:"text-amber-600",children:u("work:task.executionRound",{n:e.executionRound})})]}),t.jsxs("div",{className:"px-6 py-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:[u("work:task.subtasks")," ",C.length>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[u("work:task.subtasksProgress",{done:Ht,total:C.length-bt}),bt>0?` · ${bt} cancelled`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[Re>0&&t.jsx("button",{onClick:()=>k(G=>!G),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${j?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:j?u("work:task.hideCompleted"):u("work:task.showCompleted",{count:Re})}),t.jsx("button",{onClick:()=>b(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:u("work:task.addSubtask")})]})]}),(()=>{const G=j?C:C.filter(ge=>ge.status!=="completed"&&ge.status!=="cancelled");return G.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:G.map(ge=>t.jsxs("div",{className:`group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors ${ge.status==="cancelled"?"opacity-50":""}`,children:[t.jsxs("button",{onClick:()=>{hn(ge)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${ge.status==="completed"?"bg-green-600 border-green-600 text-white":ge.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[ge.status==="completed"&&t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),ge.status==="cancelled"&&t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M3 3l6 6M9 3l-6 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),t.jsx("span",{className:`flex-1 text-sm ${ge.status==="completed"?"line-through text-fg-tertiary":ge.status==="cancelled"?"line-through text-fg-quaternary":"text-fg-secondary"}`,children:ge.title}),t.jsx("button",{onClick:()=>T(ge),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},ge.id))}):null})(),C.length===0&&!x&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:u("work:task.noSubtasksYet")}),x&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:v,onChange:G=>y(G.target.value),onKeyDown:G=>{G.key==="Enter"&&jt(),G.key==="Escape"&&(b(!1),y(""))},placeholder:u("work:task.subtaskTitlePlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{onClick:()=>{jt()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:u("work:task.add")}),t.jsx("button",{onClick:()=>{b(!1),y("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:u("common:cancel")})]}),(()=>{const G=te.filter(Te=>typeof Te.reference=="string"&&Te.reference.length>0);if(G.length===0)return null;const ge={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},Ie=G.slice(0,3);return t.jsxs("div",{className:"mt-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:u("work:task.deliverablesCount",{count:G.length})}),G.length>3&&t.jsx("button",{onClick:()=>Q("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:u("work:task.viewAll")})]}),t.jsx("div",{className:"space-y-1.5",children:Ie.map(Te=>{const Ee=/^https?:\/\//i.test(Te.reference),rt=Ee?Te.summary||Te.reference:Te.reference.split("/").pop()??Te.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${ge[Te.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Te.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Ee?t.jsxs("a",{href:Te.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Te.reference,children:[rt," ",t.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),t.jsx("path",{d:"M7 2h3v3"}),t.jsx("path",{d:"M5 7 10 2"})]})]}):t.jsx("button",{onClick:()=>pe(Te.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Te.reference,children:rt}),Te.summary&&!Ee&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Te.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Te.reference})]})]},Te.id)})})]})})(),t.jsx(Sm,{task:e,agents:n,users:o,authUser:c})]})]}),t.jsx("div",{className:X==="history"?"":"hidden",children:t.jsx(zl,{entityType:"task",entityId:e.id})}),t.jsx("div",{className:X==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const G=te.filter(Ee=>typeof Ee.reference=="string"&&Ee.reference.length>0);if(G.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:u("work:task.noDeliverablesYet")});const ge={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},Ie=Math.ceil(G.length/vt),Te=G.slice((H-1)*vt,H*vt);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:u("work:task.deliverablesCount",{count:G.length})}),Ie>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:H<=1,onClick:()=>Z(Ee=>Ee-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[H,"/",Ie]}),t.jsx("button",{disabled:H>=Ie,onClick:()=>Z(Ee=>Ee+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),t.jsx("div",{className:"space-y-1.5",children:Te.map(Ee=>{const rt=/^https?:\/\//i.test(Ee.reference),mn=rt?Ee.summary||Ee.reference:Ee.reference.split("/").pop()??Ee.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${ge[Ee.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Ee.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[rt?t.jsxs("a",{href:Ee.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ee.reference,children:[mn," ",t.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),t.jsx("path",{d:"M7 2h3v3"}),t.jsx("path",{d:"M5 7 10 2"})]})]}):t.jsx("button",{onClick:()=>pe(Ee.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ee.reference,children:mn}),Ee.summary&&!rt&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Ee.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Ee.reference})]})]},Ee.id)})})]})})()})]}),Y!=="none"&&Y!=="top"&&t.jsx("button",{onClick:()=>I.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-36 right-4 md:bottom-28 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:u("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),Y!=="none"&&Y!=="bottom"&&t.jsx("button",{onClick:()=>{const G=I.current;G&&G.scrollTo({top:G.scrollHeight,behavior:"smooth"})},className:"absolute bottom-22 right-4 md:bottom-18 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:u("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),nt&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Qe?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!qe&&!O&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{qe||O||e.scheduleConfig?.runAt||(L(Xc(e.scheduleConfig)),_(!0))},children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:Qe?"text-amber-600":"text-brand-500",children:Qe?u("work:task.schedulePaused"):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3.5 h-3.5 inline -mt-0.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})," ",u("work:task.scheduled")]})}),t.jsx("span",{className:"text-fg-tertiary",children:"·"}),t.jsx("span",{className:"text-fg-secondary",children:e.scheduleConfig.every?u("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):e.scheduleConfig.cron?u("work:task.scheduleCron",{expr:e.scheduleConfig.cron}):e.scheduleConfig.runAt?u("work:task.scheduleOneShot"):u("work:task.scheduleNA")}),!Qe&&e.scheduleConfig.nextRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-fg-tertiary",children:"·"}),t.jsx("span",{className:"text-fg-secondary",children:u("work:task.scheduleNext",{when:(()=>{const G=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(G<=0)return u("work:task.scheduleDueNow");const ge=Math.floor(G/6e4);if(ge<60)return u("work:task.scheduleInMinutes",{count:ge});const Ie=Math.floor(ge/60);return Ie<24?u("work:task.scheduleInHoursMinutes",{h:Ie,m:ge%60}):u("work:task.scheduleInDaysHours",{d:Math.floor(Ie/24),h:Ie%24})})()})})]}),!qe&&!O&&!e.scheduleConfig.runAt&&t.jsxs("svg",{className:"w-3 h-3 text-brand-500 ml-auto shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})]}),O&&z?t.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:G=>G.stopPropagation(),children:[t.jsx(vi,{value:z,onChange:L,compact:!0}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx("button",{onClick:async()=>{await $e(()=>re.tasks.updateSchedule(e.id,wi(z))),_(!1)},disabled:R,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:u("common:save")}),t.jsx("button",{onClick:()=>_(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:u("common:cancel")})]})]}):t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[t.jsx("span",{children:u("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?u("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:u("work:task.scheduleLast",{when:(()=>{const G=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),ge=Math.floor(G/6e4);if(ge<1)return u("work:task.noteTimeJustNow");if(ge<60)return u("work:task.noteTimeMinutes",{count:ge});const Ie=Math.floor(ge/60);return Ie<24?u("work:task.noteTimeHours",{count:Ie}):u("work:task.noteTimeDays",{count:Math.floor(Ie/24)})})()})})]})]})]}),t.jsx("div",{className:"px-6 py-4 border-t border-border-default flex items-center justify-between gap-2",children:t.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.status==="pending"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{if(nt){U(!0);return}$e(()=>re.tasks.approve(e.id))},disabled:R,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:e.createdBy&&!e.createdBy.startsWith("agt_")?u("work:task.startExecution"):u("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?t.jsx("button",{onClick:async()=>{const{count:G}=await re.tasks.getDependentCount(e.id);D({dependentCount:G})},disabled:R,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")}):t.jsx("button",{onClick:()=>P(!0),disabled:R,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.reject")})]}),e.status==="review"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{$e(()=>re.tasks.accept(e.id,c?.id))},disabled:R,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.approveCheck")}),Ge?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:je,onChange:G=>Ze(G.target.value),onKeyDown:G=>{G.key==="Enter"&&je.trim()&&($e(()=>re.tasks.revision(e.id,je.trim(),c?.id)),Ne(!1),Ze(""))},placeholder:u("work:task.revisionReasonPlaceholder"),autoFocus:!0,className:"px-2 py-1 text-xs bg-surface-elevated border border-amber-500/40 rounded-lg text-fg-primary focus:border-amber-400 outline-none w-48"}),t.jsx("button",{onClick:()=>{$e(()=>re.tasks.revision(e.id,je.trim()||u("work:task.revisionsNeededDefault"),c?.id)),Ne(!1),Ze("")},disabled:R,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:u("common:send")}),t.jsx("button",{onClick:()=>{Ne(!1),Ze("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>Ne(!0),disabled:R,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.requestRevision")})]}),qe&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{kt()},disabled:R,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[t.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),t.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),u("work:task.pause")]}),t.jsxs("button",{onClick:()=>{ht()},disabled:R,className:"px-3 py-1.5 text-xs border border-blue-500/30 text-blue-600 rounded-lg hover:bg-blue-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),u("work:task.retry")]})]}),gt&&t.jsx("button",{onClick:()=>{Yt()},disabled:R,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:R?t.jsx(t.Fragment,{children:u("work:task.resuming")}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.resume")]})}),Xe&&!nt&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{ht()},disabled:R,className:"px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),u("work:task.retry")]}),t.jsxs("button",{onClick:()=>{ct()},disabled:R,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.continueTask")]})]}),nt&&(Wt||Xe||ze)&&!De&&t.jsx("button",{onClick:()=>{mt()},disabled:R,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1.5",children:R?t.jsx(t.Fragment,{children:u("work:task.running")}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.runNow")]})}),nt&&!qe&&!De&&!Pe&&(Qe?t.jsx("button",{onClick:()=>{$e(()=>re.tasks.resumeSchedule(e.id))},disabled:R,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.resumeSchedule")}):t.jsx("button",{onClick:()=>{$e(()=>re.tasks.pauseSchedule(e.id))},disabled:R,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50",children:u("work:task.pauseSchedule")})),(Wt||Xe||Pe||ze)&&t.jsx("button",{onClick:()=>N(!0),disabled:R,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.archive")}),Wt&&!nt&&t.jsx("button",{onClick:()=>{ct()},disabled:R,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary disabled:opacity-50",children:u("work:task.reopen")}),!We&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:G}=await re.tasks.getDependentCount(e.id);D({dependentCount:G})},disabled:R,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")})]})}),M&&t.jsx(Fn,{title:u("work:task.deleteSubtaskTitle",{title:M.title}),message:u("work:task.deleteSubtaskMessage"),confirmLabel:u("common:delete"),onConfirm:()=>{ve(M)},onCancel:()=>T(null)}),E&&t.jsx(Fn,{title:u("work:task.rejectConfirmTitle"),message:u("work:task.rejectConfirmMessage"),confirmLabel:u("work:task.reject"),onConfirm:()=>{P(!1),$e(()=>re.tasks.reject(e.id))},onCancel:()=>P(!1)}),q&&t.jsx(Fn,{title:u("work:task.archiveConfirmTitle"),message:u(nt?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:u("work:task.archive"),onConfirm:()=>{N(!1),$e(()=>re.tasks.archive(e.id))},onCancel:()=>N(!1)}),A&&A.dependentCount>0?t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>D(null),children:t.jsxs("div",{className:"bg-surface-default border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:G=>G.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:u("work:task.cancelTaskModalTitle")}),t.jsxs("p",{className:"text-sm text-fg-secondary mb-4",children:[nt&&t.jsx(t.Fragment,{children:t.jsx("span",{className:"block mb-1 text-amber-600",children:u("work:task.cancelScheduledConfirmMessage")})}),u("work:task.cancelTaskDependent",{count:A.dependentCount})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("button",{onClick:()=>{D(null),$e(()=>re.tasks.cancel(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-surface-elevated border border-border-default rounded-lg hover:bg-surface-overlay text-fg-primary text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelTaskOnly")}),t.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:u("work:task.cancelTaskOnlyHint")})]}),t.jsxs("button",{onClick:()=>{D(null),$e(()=>re.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelWithDependents")}),t.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:u("work:task.cancelWithDependentsHint",{count:A.dependentCount})})]}),t.jsx("button",{onClick:()=>D(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("work:task.keepTaskRunning")})]})]})}):A&&t.jsx(Fn,{title:u("work:task.cancelTaskModalTitle"),message:u(nt?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:u("work:task.cancelTask"),onConfirm:()=>{D(null),$e(()=>re.tasks.cancel(e.id))},onCancel:()=>D(null)}),ce&&t.jsx(Mm,{filePath:ce,onClose:()=>pe(null),onOpenExternal:()=>{pe(null),re.deliverables.search({taskId:e.id,limit:100}).then(({results:G})=>{const ge=G.find(Ie=>Ie.reference===ce);ge?Bt.navigate(He.DELIVERABLES,{openDeliverable:ge.id}):Bt.navigate(He.DELIVERABLES)}).catch(()=>Bt.navigate(He.DELIVERABLES))}}),be&&e.scheduleConfig&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>U(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:G=>G.stopPropagation(),children:[t.jsx("h3",{className:"font-semibold text-base mb-2",children:u("work:task.scheduleApproveTitle")}),t.jsx("p",{className:"text-sm text-fg-secondary mb-5 leading-relaxed",children:u("work:task.scheduleApproveDesc",{schedule:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.every?u("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):"",nextRun:e.scheduleConfig.nextRunAt?new Date(e.scheduleConfig.nextRunAt).toLocaleString():u("work:task.scheduleNA")})}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("button",{disabled:R,onClick:()=>{U(!1),$e(()=>re.tasks.approve(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-green-600 hover:bg-green-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveRunNow")}),t.jsx("button",{disabled:R,onClick:()=>{U(!1),$e(()=>re.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveWait")}),t.jsx("button",{onClick:()=>U(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("common:cancel")})]})]})})]})}function Im({project:e,tasks:n,requirements:s,agents:r,onDeleteProject:i,onUpdateProject:o,onRefresh:a}){const l=p.useMemo(()=>n.filter(E=>E.projectId===e.id),[n,e.id]),c=p.useMemo(()=>s.filter(E=>E.projectId===e.id),[s,e.id]),d=p.useMemo(()=>{const E={total:l.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:c.length,reqsDone:0};for(const P of l)P.status==="completed"||P.status==="accepted"?E.completed++:P.status==="in_progress"?E.inProgress++:P.status==="review"||P.status==="revision"?E.inReview++:P.status==="blocked"?E.blocked++:P.status==="failed"?E.failed++:E.pending++;for(const P of c)P.status==="completed"&&E.reqsDone++;return E},[l,c]),f=p.useMemo(()=>new Set(l.map(E=>E.assignedAgentId).filter(Boolean)),[l]),h=p.useMemo(()=>r.filter(E=>f.has(E.id)),[r,f]),[m,u]=p.useState(!1),[g,C]=p.useState(""),[S,v]=p.useState("main"),[y,x]=p.useState(!1),[b,j]=p.useState(!1),{t:k}=Oe(["work","common"]),M=[{value:"active",label:k("work:project.statusActive"),desc:k("work:project.statusActiveDesc")},{value:"paused",label:k("work:project.statusPaused"),desc:k("work:project.statusPausedDesc")},{value:"archived",label:k("work:project.statusArchived"),desc:k("work:project.statusArchivedDesc")}],T=async E=>{if(E!==e.status){x(!0);try{await o({status:E}),a()}finally{x(!1)}}},A=async()=>{const E=g.trim();if(!E)return;const P=[...e.repositories??[],{url:"",localPath:E,defaultBranch:S||"main"}];await o({repositories:P}),C(""),v("main"),u(!1),a()},D=async E=>{const P=(e.repositories??[]).filter((q,N)=>N!==E);await o({repositories:P}),a()};return t.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx(bm,{value:e.description??"",onSave:async E=>{await o({description:E}),a()},className:"text-sm text-fg-secondary",placeholder:k("work:project.descriptionPlaceholderLong")}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&t.jsxs("span",{children:[k("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:[k("work:project.updatedLabel")," ",new Date(e.updatedAt).toLocaleDateString()]})]})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:k("work:project.projectStatusHeading")}),t.jsx("div",{className:"flex gap-2",children:M.map(E=>t.jsxs("button",{disabled:y,onClick:()=>T(E.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===E.value?E.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":E.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${y?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:E.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:E.desc})]},E.value))})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:k("work:project.taskOverview")}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(Qt,{label:k("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),t.jsx(Qt,{label:k("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),t.jsx(Qt,{label:k("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),t.jsx(Qt,{label:k("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),t.jsx(Qt,{label:k("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),t.jsx(Qt,{label:k("work:project.statFailed"),value:d.failed,color:"text-red-500"})]}),d.total>0&&t.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[d.completed>0&&t.jsx("div",{className:"bg-green-500",style:{width:`${d.completed/d.total*100}%`}}),d.inProgress>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${d.inProgress/d.total*100}%`}}),d.inReview>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${d.inReview/d.total*100}%`}}),d.blocked>0&&t.jsx("div",{className:"bg-amber-500",style:{width:`${d.blocked/d.total*100}%`}}),d.pending>0&&t.jsx("div",{className:"bg-blue-500/40",style:{width:`${d.pending/d.total*100}%`}}),d.failed>0&&t.jsx("div",{className:"bg-red-500",style:{width:`${d.failed/d.total*100}%`}})]})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:k("work:project.requirementsHeading")}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(Qt,{label:k("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),t.jsx(Qt,{label:k("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),t.jsx(Qt,{label:k("work:project.statActive"),value:d.reqs-d.reqsDone,color:"text-brand-500"})]})]}),h.length>0&&t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:k("work:project.agentsHeading",{count:h.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:h.map(E=>{const P=l.filter(N=>N.assignedAgentId===E.id),q=P.filter(N=>!["completed","failed","cancelled","archived"].includes(N.status));return t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-elevated/60 rounded-lg",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${E.status==="working"?"bg-blue-500":E.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:E.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:k("work:project.agentTaskCounts",{active:q.length,total:P.length})})]},E.id)})})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:k("work:project.repositories")}),t.jsx("button",{onClick:()=>u(!m),className:"text-[10px] text-brand-500 hover:text-brand-500",children:k(m?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!m&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:k("work:project.noReposLinked")}),(e.repositories??[]).map((E,P)=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:[t.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),t.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate",children:E.url||E.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:E.defaultBranch}),t.jsx("button",{onClick:()=>D(P),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:k("work:project.removeRepo"),children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},P)),m&&t.jsxs("div",{className:"mt-2 space-y-2 p-3 bg-surface-elevated rounded-lg border border-border-default",children:[t.jsx("input",{value:g,onChange:E=>C(E.target.value),placeholder:k("work:project.repoPathPlaceholder"),className:"w-full px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:S,onChange:E=>v(E.target.value),placeholder:k("work:project.repoBranchPlaceholder"),className:"flex-1 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsx("button",{onClick:A,disabled:!g.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:k("work:task.add")})]})]})]}),t.jsx(hm,{project:e,onUpdateProject:o}),t.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:k("work:project.dangerZone")}),t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:k("work:project.dangerZoneDeleteHint")}),t.jsx("button",{onClick:()=>j(!0),className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 hover:bg-red-500/10 rounded-lg transition-colors",children:k("work:project.deleteProject")})]}),b&&t.jsx(Fn,{title:k("work:project.deleteProjectConfirmTitle"),message:k("work:project.deleteProjectConfirmBody",{name:e.name,tasks:d.total,reqs:d.reqs}),confirmLabel:k("work:project.deleteProject"),onConfirm:()=>{j(!1),i()},onCancel:()=>j(!1)})]})}function Qt({label:e,value:n,color:s}){return t.jsxs("div",{className:"text-center py-2",children:[t.jsx("div",{className:`text-xl font-bold ${s}`,children:n}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const ss={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},Bl={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Tm={urgent:0,high:1,medium:2,low:3},us={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},si={failed:"border-l-red-500 bg-red-500/5",todo:"border-l-blue-500 bg-blue-500/5",in_progress:"border-l-brand-500 bg-brand-500/5",review:"border-l-purple-500 bg-brand-500/5",done:"border-l-green-500 bg-green-500/5",closed:"border-l-gray-500 bg-gray-500/5"},Rm={failed:"border-l-red-500 text-red-500",todo:"border-l-blue-500 text-blue-600",in_progress:"border-l-brand-500 text-brand-500",review:"border-l-purple-500 text-brand-500",done:"border-l-green-500 text-green-600",closed:"border-l-gray-500 text-fg-tertiary"},_m=["pending","in_progress","completed","rejected","cancelled","archived"];function Ol(e){for(const n of ds)if(n.statuses.includes(e))return n.id;return"closed"}function oi(e,n){const s=Date.now()-new Date(e).getTime(),r=Math.floor(s/6e4);if(r<1)return n("work:relative.justNow");if(r<60)return n("work:relative.minutesAgo",{count:r});const i=Math.floor(r/60);if(i<24)return n("work:relative.hoursAgo",{count:i});const o=Math.floor(i/24);return n("work:relative.daysAgo",{count:o})}function Jr({value:e,options:n,onSelect:s,allowedValues:r}){const[i,o]=p.useState(!1),a=p.useRef(null),l=p.useRef(null),c=n.find(d=>d.value===e);return p.useEffect(()=>{if(!i)return;const d=f=>{l.current&&!l.current.contains(f.target)&&a.current&&!a.current.contains(f.target)&&o(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[i]),t.jsxs("div",{className:"relative",children:[t.jsx("button",{ref:a,onClick:()=>o(d=>!d),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${c?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:c?.label??e}),i&&t.jsx("div",{ref:l,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:n.map(d=>{const f=d.value===e,h=f||!r||r.has(d.value);return t.jsxs("button",{disabled:!h,onClick:()=>{!f&&h&&s(d.value),o(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${f?"bg-surface-elevated":h?"hover:bg-surface-elevated/60":"opacity-35 cursor-not-allowed"}`,children:[t.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 ${h?d.cls.split(" ")[0]:"bg-gray-600"}`}),t.jsx("span",{className:`font-medium ${f?"text-fg-primary":h?"text-fg-secondary":"text-fg-muted"}`,children:d.label}),f&&t.jsx("svg",{className:"w-3 h-3 ml-auto text-brand-500",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},d.value)})})]})}function Lm({onQuickCreateReq:e,onQuickCreateTask:n}){const{t:s}=Oe(["work","common"]),[r,i]=p.useState("req"),[o,a]=p.useState(!1),[l,c]=p.useState(""),d=p.useRef(null),f=p.useRef(null);p.useEffect(()=>{o&&(d.current?.focus({preventScroll:!0}),f.current?.scrollIntoView({block:"nearest",inline:"start"}))},[o]);const h=()=>{const m=l.trim();c(""),a(!1),m&&(r==="req"?e(m):n(m))};return t.jsxs("div",{ref:f,className:"flex items-center gap-2 px-3 md:px-6 py-2.5 md:py-2 border-l-2 border-l-transparent hover:bg-surface-elevated/30 transition-colors",children:[t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{type:"button",onMouseDown:m=>m.preventDefault(),onClick:()=>i("req"),className:`text-[9px] px-1.5 py-0.5 rounded font-semibold transition-colors ${r==="req"?"bg-amber-500/20 text-amber-600":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary"}`,children:s("work:task.requirementShort")}),t.jsx("button",{type:"button",onMouseDown:m=>m.preventDefault(),onClick:()=>i("task"),className:`text-[9px] px-1.5 py-0.5 rounded font-semibold transition-colors ${r==="task"?"bg-brand-500/20 text-brand-600":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary"}`,children:s("work:task.taskShort")})]}),o?t.jsx("input",{ref:d,value:l,onChange:m=>c(m.target.value),onKeyDown:m=>{m.key==="Enter"?h():m.key==="Escape"&&(c(""),a(!1))},onBlur:h,placeholder:s("work:task.quickAddPlaceholder"),className:"flex-1 min-w-0 bg-transparent border-none outline-none text-base md:text-xs text-fg-primary placeholder:text-fg-tertiary"}):t.jsxs("button",{type:"button",onClick:()=>a(!0),className:"flex-1 min-w-0 text-left text-base md:text-xs text-fg-tertiary hover:text-fg-secondary truncate",children:["+ ",s("work:task.quickAddHint")]})]})}function ai({row:e,idx:n,dragIdx:s,agentMap:r,projMap:i,onTaskClick:o,onReqClick:a,onRowDragStart:l,onRowDragEnd:c,handleStatusChange:d,handlePriorityChange:f,selected:h,isMobile:m,isAbnormalBlocked:u}){const{t:g}=Oe(["work","common"]),C=p.useMemo(()=>Pl(g),[g]),S=p.useMemo(()=>ho(g),[g]),v=p.useMemo(()=>Nm(g),[g]),y=e.data.status,x=e.data.priority,b=e.kind==="task"?r.get(e.data.assignedAgentId??""):void 0,j=(()=>{const M=i.get((e.kind==="task",e.data.projectId??""));return M&&M.name!=="default"?M:void 0})(),k=e.kind==="req"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:g("work:task.requirementShort")}):e.data.taskType==="scheduled"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600",children:g("work:task.schedShort")}):t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:g("work:task.taskShort")});return m?t.jsxs("div",{"data-work-item-id":e.data.id,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`px-3 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${si[e.group]??"border-l-gray-700"} ${h?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35":"active:bg-surface-elevated/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[k,u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500",children:"⚠"}),t.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsx("div",{onClick:M=>M.stopPropagation(),children:t.jsx(Jr,{value:y,options:e.kind==="task"?Xa.map(M=>({value:M,label:C[M]?.label??M,cls:C[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Qa.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Ja[y]:Gs[y],onSelect:M=>{d(e,M)}})}),t.jsx("div",{onClick:M=>M.stopPropagation(),children:t.jsx(Jr,{value:x,options:Za.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{f(e,M)}})}),b&&t.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${kr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`${ei[b.status]??"text-fg-secondary"}`,children:b.name})]}),j?.name&&t.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:j.name}),t.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:oi(e.data.updatedAt??"",g)})]})]}):t.jsxs("div",{"data-work-item-id":e.data.id,draggable:!0,onDragStart:M=>l(M,n),onDragEnd:c,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${si[e.group]??"border-l-gray-700"} ${s===n?"opacity-40":""} ${h?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35 hover:bg-brand-500/30":"hover:bg-surface-elevated/50"}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:k}),t.jsxs("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate",children:e.data.title}),u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500 shrink-0",children:"⚠"})]}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:M=>M.stopPropagation(),children:t.jsx(Jr,{value:y,options:e.kind==="task"?Xa.map(M=>({value:M,label:C[M]?.label??M,cls:C[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Qa.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Ja[y]:Gs[y],onSelect:M=>{d(e,M)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:M=>M.stopPropagation(),children:t.jsx(Jr,{value:x,options:Za.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{f(e,M)}})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:b?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${kr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`font-medium ${ei[b.status]??"text-fg-secondary"}`,children:b.name})]}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:j?.name?t.jsx("span",{className:"text-brand-400/70",children:j.name}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-muted text-right",children:oi(e.data.updatedAt??"",g)})]})}function Dm({tasks:e,requirements:n,agents:s,projects:r,onTaskClick:i,onReqClick:o,onRefresh:a,selectedTaskId:l,selectedReqId:c,onQuickCreateReq:d,onQuickCreateTask:f}){const{t:h}=Oe(["work","common"]),m=jr(),[u,g]=p.useState("status"),[C,S]=p.useState(null),[v,y]=p.useState(null),x=p.useMemo(()=>{const R=new Map;for(const $ of e)R.set($.id,$);return R},[e]),b=p.useCallback(R=>R.status!=="blocked"?!1:!R.blockedBy||R.blockedBy.length===0?!0:R.blockedBy.every($=>{const W=x.get($);return W&&W.status==="completed"}),[x]),j=p.useMemo(()=>{const R=[];for(const $ of e){const W=Ol($.status);R.push({kind:"task",data:$,group:W,groupOrder:us[W]??5})}for(const $ of n){const W=ss[$.status]??"todo";R.push({kind:"req",data:$,group:W,groupOrder:us[W]??5})}if(u==="status")R.sort(($,W)=>{if($.groupOrder!==W.groupOrder)return $.groupOrder-W.groupOrder;const F=new Date($.data.updatedAt??0).getTime();return new Date(W.data.updatedAt??0).getTime()-F});else{const $=W=>Tm[W.data.priority]??2;R.sort((W,F)=>{const X=$(W),B=$(F);return X!==B?X-B:new Date(F.data.updatedAt??0).getTime()-new Date(W.data.updatedAt??0).getTime()})}return R},[e,n,u]),k=async(R,$)=>{try{R.kind==="task"?await re.tasks.updateStatus(R.data.id,$):await re.requirements.updateStatus(R.data.id,$),a()}catch{}},M=async(R,$)=>{try{R.kind==="task"?await re.tasks.update(R.data.id,{priority:$}):await re.requirements.update(R.data.id,{priority:$}),a()}catch{}},T=(R,$)=>{S($),R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("text/plain",String($)),R.currentTarget.style.opacity="0.4"},A=R=>{R.currentTarget.style.opacity="1",S(null),y(null)},D=(R,$)=>{R.preventDefault(),R.dataTransfer.dropEffect="move",v!==$&&y($)},E=async(R,$)=>{if(R.preventDefault(),y(null),C==null)return;const W=j[C];if(!W||W.group===$)return;const F=ds.find(X=>X.id===$);if(F){try{if(W.kind==="task"){if(W.data.status==="pending")return;await re.tasks.updateStatus(W.data.id,F.dropStatus)}else{const X=Bl[$];X&&await re.requirements.updateStatus(W.data.id,X)}a()}catch{}S(null)}},P=p.useMemo(()=>new Map(s.map(R=>[R.id,R])),[s]),q=p.useMemo(()=>new Map(r.map(R=>[R.id,R])),[r]),N=["todo","in_progress","review","done"],O=p.useMemo(()=>{const R={};for(const $ of j)R[$.group]=(R[$.group]??0)+1;return R},[j]),{rowsByGroup:_,rowIndexMap:z}=p.useMemo(()=>{const R=new Map,$=new Map;for(let W=0;W<j.length;W++){const F=j[W];$.set(F,W);const X=R.get(F.group)??[];X.push(F),R.set(F.group,X)}return{rowsByGroup:R,rowIndexMap:$}},[j]),L=p.useMemo(()=>{if(u!=="status")return null;const R=new Set(j.map(F=>F.group)),$=[],W=new Set;R.has("failed")&&($.push("failed"),W.add("failed"));for(const F of N)$.push(F),W.add(F);for(const F of j)W.has(F.group)||($.push(F.group),W.add(F.group));return $},[j,u]);return t.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${m?"overflow-x-hidden w-full":""}`,children:t.jsxs("div",{className:m?"w-full":"w-fit min-w-full",children:[!m&&t.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider sticky top-0 z-20 bg-surface-primary",children:[t.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:j.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:h("work:task.backlogTitle")}),t.jsxs("button",{onClick:()=>g("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${u==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[h("work:filters.status")," ",u==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>g("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${u==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[h("work:filters.priority")," ",u==="priority"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsx("div",{className:"w-[120px] shrink-0",children:h("work:filters.assignee")}),t.jsx("div",{className:"w-[120px] shrink-0",children:h("work:task.projectLabel")}),t.jsx("div",{className:"w-[90px] shrink-0 text-right",children:h("work:task.backlogUpdated")})]}),t.jsxs("div",{children:[u==="status"&&L?L.map(R=>{const $=_.get(R)??[];return t.jsxs("div",{children:[t.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-primary/80 sticky top-0 z-10 ${Rm[R]??""} ${v===R?"ring-1 ring-brand-500/40":""}`,onDragOver:W=>D(W,R),onDragLeave:()=>y(null),onDrop:W=>{E(W,R)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:h(`work:boardColumn.${R}`)}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:O[R]??0})]}),$.map(W=>t.jsx(ai,{row:W,idx:z.get(W)??0,dragIdx:C,agentMap:P,projMap:q,onTaskClick:i,onReqClick:o,onRowDragStart:T,onRowDragEnd:A,handleStatusChange:k,handlePriorityChange:M,selected:W.kind==="task"?W.data.id===l:W.data.id===c,isMobile:m,isAbnormalBlocked:W.kind==="task"?b(W.data):!1},`${W.kind}-${W.data.id}`)),R==="todo"&&t.jsx(Lm,{onQuickCreateReq:d,onQuickCreateTask:f})]},R)}):j.map((R,$)=>t.jsx(ai,{row:R,idx:$,dragIdx:C,agentMap:P,projMap:q,onTaskClick:i,onReqClick:o,onRowDragStart:T,onRowDragEnd:A,handleStatusChange:k,handlePriorityChange:M,selected:R.kind==="task"?R.data.id===l:R.data.id===c,isMobile:m,isAbnormalBlocked:R.kind==="task"?b(R.data):!1},`${R.kind}-${R.data.id}`)),j.length===0&&t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3 max-w-sm mx-auto text-center",children:[t.jsx("svg",{className:"w-10 h-10 text-fg-quaternary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),t.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:h("work:task.backlogEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:h("work:task.backlogEmptyDesc")})]})]})]})})}function Ks(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function Am(e,n){const s=new Map,r=new Map(e.map(l=>[l.id,l])),i=new Set;for(const l of e){let c=Ks(l.title).replace(/[^a-z0-9-]/g,"").slice(0,30)||"step";i.has(c)&&(c=`${c}-${l.id.slice(-4)}`),i.add(c),s.set(l.id,c)}const o=new Map,a=new Set;for(const l of e){const c=l.assignedAgentId;if(c&&!o.has(c)){const d=n[c]??"worker";let f=Ks(d).replace(/[^a-z0-9-]/g,"")||"worker";a.has(f)&&(f=`${f}-${c.slice(-4)}`),a.add(f),o.set(c,f)}}return e.map(l=>({id:s.get(l.id),name:l.title,role:o.get(l.assignedAgentId)??"worker",prompt:l.description||l.title,depends_on:(l.blockedBy??[]).filter(c=>r.has(c)).map(c=>s.get(c)).filter(Boolean)}))}function es(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function Pm(e,n,s){const r=[];r.push(`name: ${es(e)}`),r.push(`description: ${es(n.replace(/\n/g," ").slice(0,200))}`),r.push('version: "1.0.0"'),r.push(""),r.push("steps:");for(const i of s){if(r.push(` - id: ${i.id}`),r.push(` name: ${es(i.name)}`),r.push(" type: agent_task"),r.push(` role: ${es(i.role)}`),i.depends_on.length>0&&r.push(` depends_on: [${i.depends_on.join(", ")}]`),i.depends_on.length>0){r.push(" inputs:");for(const o of i.depends_on)r.push(` - from: ${o}`),r.push(` as: ${o}_output`)}r.push(" prompt: |");for(const o of i.prompt.split(`
|
|
9
|
+
`))r.push(` ${o}`);r.push("")}return r.join(`
|
|
10
|
+
`)}function $m({req:e,tasks:n,agents:s,teamId:r,onClose:i,onSaved:o}){const{t:a}=Oe(["work"]),l=p.useMemo(()=>{const A={};for(const D of s)A[D.id]=D.name;return A},[s]),c=p.useMemo(()=>Am(n,l),[n,l]),[d,f]=p.useState(()=>Ks(e.title)),[h,m]=p.useState(e.description||e.title),[u,g]=p.useState(c),[C,S]=p.useState(!1),[v,y]=p.useState(null),x=(A,D,E)=>{g(P=>P.map((q,N)=>N===A?{...q,[D]:E}:q))},b=A=>{const D=u[A]?.id;g(E=>E.filter((P,q)=>q!==A).map(P=>({...P,depends_on:P.depends_on.filter(q=>q!==D)})))},[j,k]=p.useState(!1),M=async()=>{if(d.trim()){S(!0),y(null);try{const A=Pm(d.trim(),h,u);await re.workflows.create(r,d.trim(),A),k(!0),setTimeout(()=>o(),800)}catch(A){y(String(A))}S(!1)}},T=p.useMemo(()=>[...new Set(u.map(A=>A.role))],[u]);return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:i,children:t.jsxs("div",{className:"bg-surface-primary border border-border-default rounded-2xl shadow-2xl w-full max-w-[640px] mx-4 max-h-[85vh] flex flex-col",onClick:A=>A.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-4 border-b border-border-default",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-base font-semibold text-fg-primary",children:a("work:task.saveAsWorkflow","Save as Workflow")}),t.jsx("p",{className:"text-xs text-fg-tertiary mt-0.5",children:a("work:task.saveAsWorkflowDesc","Turn this task structure into a reusable workflow template")})]}),t.jsx("button",{onClick:i,className:"text-fg-tertiary hover:text-fg-secondary p-1 rounded-lg hover:bg-surface-elevated transition-colors",children:t.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t.jsxs("div",{className:"flex-1 overflow-auto px-4 sm:px-6 py-4 space-y-4",children:[t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:a("work:task.workflowName","Name")}),t.jsx("input",{value:d,onChange:A=>f(A.target.value),className:"w-full text-sm bg-surface-secondary border border-border-default/50 rounded-lg px-3 py-2 text-fg-primary focus:outline-none focus:ring-1 focus:ring-brand-500",placeholder:"content-publishing"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:a("work:task.roles","Roles")}),t.jsx("div",{className:"flex flex-wrap gap-1 py-2",children:T.map(A=>t.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:A},A))})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:a("work:task.description","Description")}),t.jsx("input",{value:h,onChange:A=>m(A.target.value),className:"w-full text-sm bg-surface-secondary border border-border-default/50 rounded-lg px-3 py-2 text-fg-primary focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:[a("work:task.workflowSteps","Steps")," (",u.length,")"]}),t.jsx("div",{className:"space-y-2",children:u.map((A,D)=>t.jsx("div",{className:"bg-surface-secondary border border-border-default/40 rounded-xl p-3 group",children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500 mt-0.5",children:D+1}),t.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{value:A.name,onChange:E=>x(D,"name",E.target.value),className:"flex-1 text-sm font-medium bg-transparent border-b border-transparent hover:border-border-default focus:border-brand-500 text-fg-primary focus:outline-none px-0 py-0.5 transition-colors"}),t.jsx("input",{value:A.role,onChange:E=>x(D,"role",E.target.value),className:"w-28 text-[10px] bg-surface-elevated border border-border-default/40 rounded-md px-2 py-1 text-fg-secondary focus:outline-none focus:ring-1 focus:ring-brand-500",title:a("work:task.role","Role")})]}),A.depends_on.length>0&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsxs("span",{children:[a("work:task.dependsOn","Depends on"),":"]}),A.depends_on.map(E=>{const P=u.find(q=>q.id===E);return t.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:P?.name??E},E)})]}),t.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:A.prompt})]}),t.jsx("button",{onClick:()=>b(D),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-quaternary hover:text-red-500 p-1 rounded transition-all",title:a("work:task.removeStep","Remove step"),children:t.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},A.id))})]}),v&&t.jsx("p",{className:"text-xs text-red-500",children:v}),j&&t.jsx("p",{className:"text-xs text-green-500 font-medium",children:a("work:task.workflowSavedSuccess","Workflow saved successfully")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default",children:[t.jsx("button",{onClick:i,className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated rounded-lg transition-colors",children:a("work:task.cancel","Cancel")}),t.jsx("button",{onClick:M,disabled:C||j||!d.trim()||u.length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm rounded-lg font-medium transition-colors",children:C?a("work:task.saving","Saving..."):j?a("work:task.workflowSavedSuccess","Saved!"):a("work:task.saveWorkflow","Save Workflow")})]})]})})}function ii({teamId:e,agents:n,compact:s}){const{t:r}=Oe(["work"]),i=p.useMemo(()=>e?n.find(a=>a.teamId===e&&a.agentRole==="manager"):n.find(a=>a.agentRole==="manager"),[n,e]),o=()=>{i&&Bt.navigate(He.TEAM,{agentId:i.id,prefillMessage:r("work:task.workflowCreatePrompt","Please create a workflow template for our team. Review the team composition, then design a multi-step process that matches our regular work. Use the workflow_create tool to save it. If the user specifies a project, bind the workflow to that project by including a project_id parameter. Otherwise, leave project as an optional runtime parameter so users can choose when starting a run.")})};return t.jsxs("div",{className:s?"max-w-4xl space-y-3":"max-w-lg w-full text-center space-y-5",children:[!s&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-brand-500/10",children:t.jsx("svg",{className:"w-8 h-8 text-brand-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3.75 6A2.25 2.25 0 016 3.75h2.25A2.25 2.25 0 0110.5 6v2.25a2.25 2.25 0 01-2.25 2.25H6a2.25 2.25 0 01-2.25-2.25V6zM3.75 15.75A2.25 2.25 0 016 13.5h2.25a2.25 2.25 0 012.25 2.25V18a2.25 2.25 0 01-2.25 2.25H6A2.25 2.25 0 013.75 18v-2.25zM13.5 6a2.25 2.25 0 012.25-2.25H18A2.25 2.25 0 0120.25 6v2.25A2.25 2.25 0 0118 10.5h-2.25a2.25 2.25 0 01-2.25-2.25V6zM13.5 15.75a2.25 2.25 0 012.25-2.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-2.25A2.25 2.25 0 0113.5 18v-2.25z"})})}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-1.5",children:r("work:task.workflowEmptyTitle","No workflow templates yet")}),t.jsx("p",{className:"text-sm text-fg-secondary leading-relaxed",children:r("work:task.workflowEmptyDesc","Workflows automate repeatable multi-step processes. Define a sequence of tasks as a DAG — the system handles dependencies, role assignment, and scheduling automatically.")})]})]}),t.jsxs("details",{className:s?"group":"",open:!s,children:[t.jsxs("summary",{className:`text-xs font-medium text-fg-secondary uppercase tracking-wider cursor-pointer select-none list-none flex items-center gap-1.5 ${s?"py-1":"sr-only"}`,children:[t.jsx("svg",{className:"w-3 h-3 transition-transform group-open:rotate-90",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),r("work:task.workflowHowItWorks","How it works")]}),t.jsxs("div",{className:`bg-surface-secondary border border-border-default/40 rounded-xl p-4 text-left space-y-3 ${s?"mt-2":""}`,children:[!s&&t.jsx("p",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:r("work:task.workflowHowItWorks","How it works")}),t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"1"}),t.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[t.jsx("span",{className:"font-medium text-fg-primary",children:r("work:task.workflowStep1Title","Requirement")})," — ",r("work:task.workflowStep1Desc","A workflow run creates a Requirement to group all its tasks under one trackable goal.")]})]}),t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"2"}),t.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[t.jsx("span",{className:"font-medium text-fg-primary",children:r("work:task.workflowStep2Title","Task DAG")})," — ",r("work:task.workflowStep2Desc","Each step becomes a Task assigned to the right team member. Dependencies are tracked — downstream tasks wait for upstream ones to finish.")]})]}),t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"3"}),t.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[t.jsx("span",{className:"font-medium text-fg-primary",children:r("work:task.workflowStep3Title","Auto-execution")})," — ",r("work:task.workflowStep3Desc","Agents pick up tasks, pass deliverables downstream, and the workflow completes automatically. Optionally, schedule it to run on a recurring basis.")]})]})]})]}),i&&t.jsx("div",{className:s?"":"text-center",children:t.jsxs("button",{onClick:o,className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-lg font-medium transition-colors",children:[t.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),r("work:task.workflowAskManager","Ask {{name}} to create a workflow",{name:i.name})]})})]})}function Bm({teamId:e,projectId:n,agents:s,projects:r,onViewRunTasks:i}){const{t:o}=Oe(["work"]),[a,l]=p.useState([]),[c,d]=p.useState({}),[f,h]=p.useState(!1),[m,u]=p.useState(null),[g,C]=p.useState({}),[S,v]=p.useState(!1),[y,x]=p.useState(null),[b,j]=p.useState([]),[k,M]=p.useState(null),[T,A]=p.useState(null),[D,E]=p.useState({}),[P,q]=p.useState(null),[N,O]=p.useState(null),[_,z]=p.useState(null),[L,R]=p.useState([]),[$,W]=p.useState({}),[F,X]=p.useState(null),[B,I]=p.useState({}),[Y,V]=p.useState(new Set),H=e??k;p.useEffect(()=>{e||re.teams.list().then(({teams:U})=>{j(U.map(ce=>({id:ce.id,name:ce.name})))}).catch(()=>{})},[e]),p.useMemo(()=>{const U={};for(const ce of s)U[ce.id]=ce.name;return U},[s]);const Z=p.useCallback(async()=>{const U=H?[H]:b.map(ce=>ce.id);if(U.length!==0){h(!0);try{const ce=[],pe={},we={};await Promise.all(U.map(async _e=>{try{const{workflows:ee}=await re.workflows.list(_e);for(const Se of ee)we[Se.name]=_e;ce.push(...ee),await Promise.all(ee.map(async Se=>{try{const{runs:ae}=await re.workflows.listRuns(_e,Se.name,5);pe[Se.name]=ae}catch{}}))}catch{}})),l(ce),d(pe),I(we)}catch{}h(!1)}},[H,b]);p.useEffect(()=>{Z()},[Z]);const te=U=>H??B[U],oe=async U=>{if(T===U.name){A(null);return}A(U.name);const ce=te(U.name);if(!D[U.name]&&ce)try{const{template:pe}=await re.workflows.get(ce,U.name);E(we=>({...we,[U.name]:pe}))}catch{}},ue=U=>{const ce={};for(const ee of U.params??[])ee.default&&(ce[ee.name]=ee.default);C(ce),x(null),R([]),W({});const pe=localStorage.getItem(`markus_wf_project_${U.name}`)??localStorage.getItem("markus_wf_project_last"),we=pe&&r.some(ee=>ee.id===pe)?pe:null;X(n??we??r[0]?.id??null),u(U);const _e=te(U.name);_e&&re.workflows.roles(_e,U.name).then(({roles:ee})=>R(ee)).catch(()=>{})},Q=async()=>{const U=F??r[0]?.id,ce=m?te(m.name):void 0;if(!m||!ce||!U){x(U?o("work:task.workflowNoTeam","Cannot determine team for this workflow"):o("work:task.workflowNoProject","Please select a project"));return}v(!0),x(null);try{let pe;if(L.length>0){pe={};for(const we of L)pe[we.role]=$[we.role]??we.recommended??""}await re.workflows.startRun(ce,m.name,U,g,pe),localStorage.setItem(`markus_wf_project_${m.name}`,U),localStorage.setItem("markus_wf_project_last",U),u(null),Z()}catch(pe){x(String(pe))}v(!1)};if(!H&&b.length===0&&!e)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:o("work:task.selectProjectForWorkflows","Select a project with a team to view workflows")});if(f&&a.length===0)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:o("work:task.workflowLoading","Loading...")});const le=async U=>{q(U),O(null);try{await re.workflows.cancelRun(U),Z()}catch{}q(null)},de=async U=>{z(U.id);try{U.status==="running"?await re.workflows.pauseRun(U.id):U.status==="paused"&&await re.workflows.resumeRun(U.id),Z()}catch{}z(null)},fe=U=>{U.requirementId&&i&&i(U.requirementId)},xe=U=>{const ce={running:"bg-blue-500/20 text-blue-400",paused:"bg-amber-500/20 text-amber-400",completed:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",cancelled:"bg-gray-500/20 text-gray-400"};return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${ce[U]??"bg-gray-500/20 text-gray-400"}`,children:U})},be=m&&(m.params??[]).some(U=>U.required&&!g[U.name]?.trim());return t.jsxs("div",{className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:[!e&&b.length>0&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-4",children:[t.jsx("button",{onClick:()=>{k!==null&&(M(null),l([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${k===null?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:o("work:task.all","All")}),b.map(U=>t.jsx("button",{onClick:()=>{k!==U.id&&(M(U.id),l([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${k===U.id?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:U.name},U.id))]}),a.length===0&&!f?t.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:t.jsx(ii,{teamId:H,agents:s})}):t.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[a.map(U=>{const ce=T===U.name,pe=D[U.name],_e=(c[U.name]??[]).some(ee=>ee.status==="running"||ee.status==="paused");return t.jsxs("div",{className:"bg-surface-secondary border border-border-default/50 rounded-xl p-4",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-2 sm:gap-3 mb-2 cursor-pointer",onClick:()=>oe(U),children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("svg",{className:`w-3.5 h-3.5 text-fg-tertiary shrink-0 transition-transform ${ce?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:U.displayName||U.name}),t.jsx("span",{className:"text-[11px] text-fg-tertiary",children:o("work:task.workflowStepsCount","{{count}} steps",{count:U.stepCount})})]})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 shrink-0",children:[t.jsxs("span",{className:"text-[10px] text-fg-quaternary font-mono cursor-pointer hover:text-fg-tertiary transition-colors max-w-[12rem] truncate",title:o("work:task.workflowSendToAgent","Send to agent chat"),onClick:ee=>{ee.stopPropagation();const Se=te(U.name),ie=(Se?s.find(me=>me.teamId===Se&&me.agentRole==="manager"):void 0)?.id??s.find(me=>me.agentRole==="manager")?.id??s[0]?.id;ie&&Bt.navigate(He.TEAM,{agentId:ie,prefillMessage:`@[${U.displayName||U.name}](workflow:${U.name}) `})},children:[t.jsx("svg",{className:"w-3.5 h-3.5 inline mr-0.5 -mt-px",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),U.name]}),U.hasSchedule&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-500/20 text-purple-400",children:o("work:task.workflowScheduled","Scheduled")}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["v",U.version]}),_e?t.jsxs("span",{className:"px-3 py-1 bg-blue-500/20 text-blue-400 text-xs rounded-lg font-medium inline-flex items-center gap-1.5",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 animate-pulse"}),o("work:task.workflowRunning","Running")]}):t.jsx("button",{onClick:ee=>{ee.stopPropagation(),ue(U)},className:"px-3 py-1 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:o("work:task.workflowRun","Run")})]})]}),ce&&pe&&t.jsxs("div",{className:"border-t border-border-default/30 pt-3 mt-1 ml-5 space-y-3",children:[U.description&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:U.description}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:o("work:task.workflowSteps","Steps")}),t.jsx("div",{className:"space-y-1.5",children:pe.steps.map((ee,Se)=>t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"shrink-0 w-5 h-5 rounded-full bg-brand-500/15 flex items-center justify-center text-[9px] font-bold text-brand-500 mt-0.5",children:Se+1}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[t.jsx("span",{className:"text-xs font-medium text-fg-primary",children:ee.name}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary",children:ee.role}),ee.depends_on&&ee.depends_on.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["← ",ee.depends_on.join(", ")]})]}),t.jsx("p",{className:"text-[10px] text-fg-tertiary line-clamp-1 mt-0.5",children:ee.prompt})]})]},ee.id))})]}),pe.steps.some(ee=>ee.depends_on&&ee.depends_on.length>0)&&t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-1.5 uppercase tracking-wider",children:"DAG"}),t.jsx("div",{className:"flex items-center gap-1 flex-wrap text-[10px]",children:pe.steps.map((ee,Se)=>{const ae=ee.depends_on&&ee.depends_on.length>0;return t.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[ae&&t.jsx("span",{className:"text-fg-quaternary",children:"→"}),t.jsx("span",{className:"px-1.5 py-0.5 rounded bg-surface-elevated text-fg-secondary font-medium",children:ee.name})]},ee.id)})})]}),pe.params&&pe.params.length>0&&t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-1.5 uppercase tracking-wider",children:o("work:task.workflowParamsCount","Parameters",{count:pe.params.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:pe.params.map(ee=>t.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-[10px] rounded bg-surface-elevated border border-border-default/30",children:[t.jsx("span",{className:"font-medium text-fg-secondary",children:ee.label||ee.name}),t.jsxs("span",{className:"text-fg-quaternary",children:["(",ee.type||"string",")"]}),ee.required&&t.jsx("span",{className:"text-red-400",children:"*"})]},ee.name))})]}),pe.schedule&&t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-1 uppercase tracking-wider",children:o("work:task.workflowScheduled","Schedule")}),t.jsxs("p",{className:"text-xs text-fg-secondary",children:[pe.schedule.cron&&`cron: ${pe.schedule.cron}`,pe.schedule.interval&&`every: ${pe.schedule.interval}`]})]})]}),(()=>{const ee=c[U.name]??[];if(ee.length===0)return null;const Se=Y.has(U.name),ae=Se?ee:ee.slice(0,1);return t.jsxs("div",{className:"border-t border-border-default/30 pt-2 mt-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 cursor-pointer select-none",onClick:()=>V(ie=>{const me=new Set(ie);return me.has(U.name)?me.delete(U.name):me.add(U.name),me}),children:[t.jsx("svg",{className:`w-3 h-3 text-fg-quaternary transition-transform ${Se?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium uppercase tracking-wider",children:o("work:task.workflowRecentRuns","Recent Runs")}),ee.length>1&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["(",ee.length,")"]})]}),t.jsx("div",{className:"space-y-1",children:ae.map(ie=>t.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs px-2 py-1.5 rounded hover:bg-surface-elevated/50",children:[t.jsxs("span",{className:"text-fg-secondary font-medium",children:["#",ie.runNumber]}),xe(ie.status),t.jsxs("span",{className:"text-fg-tertiary",children:[ie.taskIds.length," tasks"]}),t.jsx("span",{className:"text-fg-tertiary",children:new Date(ie.startedAt).toLocaleDateString()}),ie.triggeredBy==="schedule"&&t.jsx("span",{className:"text-[10px] text-purple-400",children:"auto"}),t.jsx("span",{className:"flex-1"}),(ie.status==="running"||ie.status==="paused")&&t.jsx("button",{onClick:me=>{me.stopPropagation(),de(ie)},disabled:_===ie.id,className:`px-2.5 py-0.5 text-[10px] rounded-lg font-medium transition-colors ${ie.status==="running"?"bg-amber-500/20 text-amber-400 hover:bg-amber-500/30":"bg-green-500/20 text-green-400 hover:bg-green-500/30"}`,children:_===ie.id?"...":ie.status==="running"?o("work:task.workflowPause","Pause"):o("work:task.workflowResume","Resume")}),(ie.status==="running"||ie.status==="paused")&&t.jsx("button",{onClick:me=>{me.stopPropagation(),O(ie.id)},className:"px-2.5 py-0.5 text-[10px] rounded-lg font-medium bg-red-500/20 text-red-400 hover:bg-red-500/30 transition-colors",children:o("work:task.workflowCancelRun","Cancel Run")}),t.jsx("button",{onClick:()=>fe(ie),className:"px-2.5 py-0.5 text-[10px] rounded-lg font-medium bg-brand-500/20 text-brand-400 hover:bg-brand-500/30 transition-colors",children:o("work:task.workflowViewTasks","View Tasks")})]},ie.id))})]})})()]},U.name)}),t.jsx(ii,{teamId:H,agents:s,compact:!0})]}),m&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>u(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-md shadow-2xl",onClick:U=>U.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-1",children:o("work:task.workflowRunTitle","Run: {{name}}",{name:m.displayName||m.name})}),t.jsx("p",{className:"text-xs text-fg-tertiary mb-4",children:m.description}),(m.params??[]).length>0&&t.jsx("div",{className:"space-y-3 mb-4",children:(m.params??[]).map(U=>t.jsxs("div",{children:[t.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[U.label||U.name,U.required&&t.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),U.type==="enum"&&U.options?t.jsx(It,{options:[{value:"",label:"—"},...U.options.map(ce=>({value:ce,label:ce}))],value:g[U.name]??"",onChange:ce=>C(pe=>({...pe,[U.name]:ce})),placeholder:"—",className:"w-full"}):t.jsx("textarea",{value:g[U.name]??"",onChange:ce=>{C(_e=>({..._e,[U.name]:ce.target.value}));const pe=ce.target;pe.style.height="auto";const we=parseFloat(getComputedStyle(pe).lineHeight)||18;pe.style.height=Math.min(pe.scrollHeight,we*7)+"px"},placeholder:U.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},U.name))}),L.length>0&&t.jsxs("div",{className:"mb-4",children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:o("work:task.roles","Roles")}),t.jsx("div",{className:"space-y-2",children:L.map(U=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs text-fg-secondary w-24 shrink-0 font-medium",children:U.role}),t.jsx(It,{options:U.candidates.map(ce=>({value:ce.agentId,label:ce.agentName+(ce.agentId===U.recommended?" ★":"")})),value:$[U.role]??U.recommended??"",onChange:ce=>W(pe=>({...pe,[U.role]:ce})),className:"flex-1"})]},U.role))})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1",children:o("work:task.workflowProject","Project")}),t.jsx(It,{options:[{value:"",label:o("work:task.workflowSelectProject","— Select a project —")},...r.map(U=>({value:U.id,label:U.name}))],value:F??"",onChange:U=>{const ce=U||null;X(ce),x(null),ce&&localStorage.setItem("markus_wf_project_last",ce)},placeholder:o("work:task.workflowSelectProject","— Select a project —"),className:"w-full"})]}),y&&t.jsx("p",{className:"text-xs text-red-400 mb-3",children:y}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>u(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowCancel","Cancel")}),t.jsx("button",{onClick:Q,disabled:S||!!be,className:"btn-primary text-xs px-4 py-1.5",children:S?o("work:task.workflowStarting","Starting..."):o("work:task.workflowStartRun","Start Run")})]})]})}),N&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>O(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:U=>U.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-2",children:o("work:task.workflowConfirmCancelTitle","Cancel Workflow Run")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-5",children:o("work:task.workflowConfirmCancelDesc","This will cancel all running and pending tasks in this workflow run. This action cannot be undone.")}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>O(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowNo","No")}),t.jsx("button",{onClick:()=>le(N),disabled:P===N,className:"px-4 py-1.5 bg-red-600 hover:bg-red-500 text-white text-xs rounded-lg font-medium transition-colors",children:P===N?o("work:task.workflowCancelling","Cancelling..."):o("work:task.workflowConfirmCancelBtn","Confirm Cancel")})]})]})})]})}function Gm({authUser:e,previewMode:n,previewData:s}={}){const{t:r}=Oe(["work","common"]),i=dc(He.WORK),o=p.useMemo(()=>ds.map(w=>({...w,label:r(`work:boardColumn.${w.id}`)})),[r]),a=p.useMemo(()=>$l(r),[r]),l=p.useMemo(()=>ho(r),[r]),c=jr(),d=uc(),f=d?.leftCollapsed??!1,h=p.useRef(null),[m,u]=p.useState(0);p.useEffect(()=>{const w=h.current;if(!w)return;const K=new ResizeObserver(([J])=>u(J.contentRect.width));return K.observe(w),u(w.clientWidth),()=>K.disconnect()},[]);const[g,C]=p.useState(()=>{if(n)return!1;try{return localStorage.getItem(Wa)==="1"}catch{return!1}}),S=p.useCallback(w=>{C(w);try{localStorage.setItem(Wa,w?"1":"0")}catch{}},[]),v=p.useRef(f);p.useEffect(()=>{n||c||v.current!==f&&(v.current=f,C(f))},[f,n,c]);const y=fc({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),x=6,b=!c&&!g?y.width+x:0,j=Math.max(0,(m||window.innerWidth)-b-x-8),k=Math.max(320,Math.round(j/2)),[M,T]=p.useState("auto"),A=Math.max(320,j-280),D=M==="auto"?Math.min(k,A):M,E=Math.max(320,Math.min(D,A)),P=p.useRef(E);P.current=E;const q=p.useRef(A);q.current=A;const N=p.useCallback(w=>{w.preventDefault();const K=w.clientX,J=P.current,ne=Me=>{const ke=Math.max(320,Math.min(q.current,J+(K-Me.clientX)));T(ke)},he=()=>{document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",he),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ne),document.addEventListener("mouseup",he),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[O,_]=p.useState(!1),z=p.useRef(O);z.current=O,p.useEffect(()=>(qo(He.WORK,c&&O?1:0),()=>qo(He.WORK,0)),[c,O]);const[L,R]=p.useState(s?.projects??[]),[$,W]=p.useState("all"),[F,X]=p.useState(null),[B,I]=p.useState("closed"),[Y,V]=p.useState("projects"),[H,Z]=p.useState(s?.board??{}),[te,oe]=p.useState(s?.agents??[]),[ue,Q]=p.useState([]),[le,de]=p.useState(s?.users??[]),[fe,xe]=p.useState(s?.allRequirements??[]),[be,U]=p.useState(!s),[ce,pe]=p.useState(""),we=p.useCallback(()=>{ar(F??""),gn(!0)},[F]),_e=async w=>{if(!F){sn(w),we();return}try{const{requirement:K}=await re.requirements.create({title:w,description:w,priority:"medium",projectId:F});st(r("work:task.quickAddReqDone",{title:w})),St(),K&&jn(K)}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},ee=w=>{Ne(w),at(F??""),me(!0),st(r("work:task.quickAddTaskHint"))},[Se,ae]=p.useState(!1),[ie,me]=p.useState(!1),[Ge,Ne]=p.useState(""),[je,Ze]=p.useState(""),[yt,wt]=p.useState("medium"),[lt,vt]=p.useState(""),[Je,$e]=p.useState(""),[ft,at]=p.useState(""),[zt,kt]=p.useState(""),[dt,Yt]=p.useState([]),[jt,hn]=p.useState("standard"),[ve,ct]=p.useState(()=>Os()),[ht,mt]=p.useState(""),[pt,Ht]=p.useState(!1),[bt,Re]=p.useState(null),[qe,gt]=p.useState(!1),[qt,Wt]=p.useState(""),[Xe,Pe]=p.useState(null),[ze,De]=p.useState(()=>s?.initialSelectedReqId&&s.allRequirements?s.allRequirements.find(w=>w.id===s.initialSelectedReqId)??null:null);p.useEffect(()=>{s?.initialSelectedReqId&&ze&&I("item")},[]);const[We,nt]=p.useState(new Set),[Qe,Nt]=p.useState(!1),[it,G]=p.useState(new Set),ge=p.useRef(new Set),[Ie,Te]=p.useState(null),[Ee,rt]=p.useState(s?.initialBoardType??"backlog"),[mn,Rn]=p.useState(null);p.useEffect(()=>hc(He.WORK,()=>Lr.current),[]),p.useEffect(()=>mc((w,K)=>{w===He.WORK&&Fa.includes(K)&&rt(K)}),[]);const nr=p.useRef(null),[Ct,pn]=p.useState(!1),[tn,Mr]=p.useState(null),[rr,nn]=p.useState(!1),_n=p.useRef(null),Ln=p.useRef(null),[sr,gn]=p.useState(!1),[rn,sn]=p.useState(""),[xn,bn]=p.useState(""),[Ir,or]=p.useState("medium"),[Dn,ar]=p.useState(""),[Gt,yn]=p.useState(null),[mo,po]=p.useState(""),[go,on]=p.useState(""),[ws,xo]=p.useState(!1),[bo,An]=p.useState(""),st=w=>{pe(w),setTimeout(()=>pe(""),3e3)};p.useEffect(()=>{const w=K=>{K.key==="Escape"&&(bt?Re(null):qe?(gt(!1),Wt("")):Gt?(yn(null),An("")):ie?(me(!1),mt("")):sr?(gn(!1),sn(""),bn(""),on("")):rr?nn(!1):B!=="closed"&&(I("closed"),Pe(null),De(null),c&&z.current&&_(!1)))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[bt,qe,Gt,ie,sr,rr,B,c]);const Rt=L.find(w=>w.id===F)??null,Hl=Rt?.teamIds?.[0]??null,ql=p.useMemo(()=>L.filter(w=>w.status!=="archived"),[L]),yo=p.useCallback(()=>{F&&(Pe(null),De(null),I("project"),T("auto"),c&&_(!0))},[F,c]),Tr=p.useCallback(()=>{if(B==="project"){I("closed"),c&&_(!1);return}yo()},[B,yo,c]);p.useEffect(()=>{ge.current=it},[it]);const wn=p.useCallback(async()=>{try{const{projects:w}=await re.projects.list();R(w)}catch{}},[]),ut=p.useCallback(async()=>{const w={};$==="project"&&F&&(w.projectId=F);try{const{board:K}=await re.tasks.board(w);Z(K)}catch{}},[$,F]),ir=p.useCallback(async()=>{try{const{agents:w}=await re.agents.list();oe(w)}catch{}},[]),wo=p.useCallback(async()=>{try{const{teams:w}=await re.teams.list();Q(w.map(K=>({id:K.id,name:K.name})))}catch{}},[]),vo=p.useCallback(async()=>{try{const{users:w}=await re.users.list(e?.orgId);de(w)}catch{}},[e?.orgId]),St=p.useCallback(async()=>{try{const{requirements:w}=await re.requirements.list({});xe(w)}catch{}},[]),ko=p.useCallback(async()=>{await Promise.all([wn(),ut(),ir(),vo(),St(),wo()]),U(!1)},[wn,ut,ir,vo,St,wo]);p.useEffect(()=>{n||ko()},[n,ko]),p.useEffect(()=>{!n||!s||(R(s.projects??[]),Z(s.board??{}),oe(s.agents??[]),de(s.users??[]),xe(s.allRequirements??[]))},[n,s]);const Rr=p.useCallback(w=>{V("items"),Pe(K=>K?.id===w.id&&B==="item"?(I("closed"),c&&z.current&&_(!1),null):(I("item"),T("auto"),c&&(_(!0),history.pushState({mobileDetail:He.WORK},"",window.location.hash)),w)),De(null)},[c,B]),_r=p.useCallback(w=>{V("items"),De(K=>K?.id===w.id&&B==="item"?(I("closed"),c&&z.current&&_(!1),null):(I("item"),T("auto"),c&&(_(!0),history.pushState({mobileDetail:He.WORK},"",window.location.hash)),w)),Pe(null)},[c,B]),vn=p.useCallback(()=>{Pe(null),De(null),I("closed"),c&&z.current&&_(!1)},[c]),Kt=p.useRef(Xe);Kt.current=Xe;const Ut=p.useRef(ze);Ut.current=ze;const kn=p.useRef(B);kn.current=B;const Pn=p.useRef(Y);Pn.current=Y;const $n=p.useRef(g);$n.current=g;const Lr=p.useRef(Ee);Lr.current=Ee;const Wl=p.useCallback(()=>{Pe(null),Ut.current||(I("closed"),c&&z.current&&_(!1))},[c]);p.useEffect(()=>{if(!c)return;const w=()=>{z.current&&(_(!1),Pe(null),De(null),I("closed"))};return window.addEventListener("popstate",w),()=>window.removeEventListener("popstate",w)},[c]),p.useEffect(()=>{if(n||!i)return;ut(),ir(),St();const w=Kt.current?12e4:45e3,K=setInterval(()=>{ut(),ir(),St()},w);let J=null;const ne=()=>{J||(J=setTimeout(()=>{J=null,ut()},800))};let he=null;const Me=()=>{he||(he=setTimeout(()=>{he=null,St()},800))},ke=Tt.on("task:update",Fe=>{Dt("/taskboard"),ne();const Ce=Fe?.payload;Ce?.taskId&&(Pe(Ue=>{if(!Ue||Ue.id!==Ce.taskId)return Ue;const Ae={};return typeof Ce.status=="string"&&(Ae.status=Ce.status),Array.isArray(Ce.deliverables)&&(Ae.deliverables=Ce.deliverables),Array.isArray(Ce.notes)&&(Ae.notes=Ce.notes),Ce.result!==void 0&&(Ae.result=Ce.result),{...Ue,...Ae}}),Kt.current?.id===Ce.taskId&&(Dt("/tasks/"+Ce.taskId),re.tasks.get(Ce.taskId).then(Ue=>{Ue.task&&Pe(Ae=>Ae?.id===Ue.task.id?Ue.task:Ae)}).catch(()=>{})))}),se=Tt.on("task:create",()=>{ne()}),_t=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(Fe=>Tt.on(Fe,Ce=>{Dt("/requirements"),Me();const Ue=Ce?.payload,Ae=Ue?.id??Ue?.requirementId;Ae&&Ut.current?.id===Ae&&(Dt("/requirements/"+Ae),re.requirements.get(Ae).then(Xt=>{Xt.requirement&&De(Sn=>Sn?.id===Xt.requirement.id?Xt.requirement:Sn)}).catch(()=>{}))})),Et=()=>{Dt("/taskboard"),Dt("/tasks"),Dt("/requirements"),ut(),St(),Kt.current&&re.tasks.get(Kt.current.id).then(Fe=>{Fe.task&&Pe(Ce=>Ce?.id===Fe.task.id?Fe.task:Ce)}).catch(()=>{}),Ut.current&&re.requirements.get(Ut.current.id).then(Fe=>{Fe.requirement&&De(Ce=>Ce?.id===Fe.requirement.id?Fe.requirement:Ce)}).catch(()=>{})};return window.addEventListener("markus:data-changed",Et),()=>{clearInterval(K),ke(),se(),_t.forEach(Fe=>Fe()),window.removeEventListener("markus:data-changed",Et),J&&clearTimeout(J),he&&clearTimeout(he)}},[n,i,ut,ir,St]);const jo=p.useRef(H);jo.current=H;const No=p.useRef(fe);No.current=fe,p.useEffect(()=>{const w=Kt.current;if(!w)return;const J=Object.values(H).flat().find(ne=>ne.id===w.id);J&&J.updatedAt!==w.updatedAt&&Pe(J)},[H]),p.useEffect(()=>{const w=Ut.current;if(!w)return;const K=fe.find(J=>J.id===w.id);K&&K.updatedAt!==w.updatedAt&&De(K)},[fe]);const an=p.useCallback(w=>{if(!w){G(new Set),X(null),W("all"),history.replaceState(null,"",Wr(He.WORK)),re.tasks.board({}).then(K=>Z(K.board)).catch(()=>{});return}X(w),W("project"),G(new Set),history.replaceState(null,"",Wr(He.WORK,w)),re.tasks.board({projectId:w}).then(K=>Z(K.board)).catch(()=>{})},[]),[vs,lr]=p.useState(!1),cr=p.useCallback((w,K)=>{Pe(w),De(null),I("item"),V("items"),T("auto"),K?.scrollToComments&&lr(!0),c&&_(!0)},[c]),jn=p.useCallback((w,K)=>{De(w),Pe(null),I("item"),V("items"),T("auto"),K?.scrollToComments&&lr(!0),c&&_(!0)},[c]),Bn=p.useRef(null);p.useEffect(()=>{const w=Bn.current||localStorage.getItem("markus_nav_openTask");if(!w)return;const J=Object.values(H).flat().find(ne=>ne.id===w);J?(Bn.current=null,an(J.projectId),cr(J),localStorage.removeItem("markus_nav_openTask")):Bn.current||(Bn.current=w,localStorage.removeItem("markus_nav_openTask"),re.tasks.get(w).then(ne=>{ne.task&&(Bn.current=null,an(ne.task.projectId),cr(ne.task))}).catch(()=>{Bn.current=null}))},[H,cr,an]);const On=p.useRef(null);p.useEffect(()=>{const w=On.current||localStorage.getItem("markus_nav_openRequirement");if(!w)return;const K=fe.find(J=>J.id===w);K?(On.current=null,an(K.projectId),jn(K),localStorage.removeItem("markus_nav_openRequirement")):On.current||(On.current=w,localStorage.removeItem("markus_nav_openRequirement"),re.requirements.get(w).then(J=>{J.requirement&&(On.current=null,an(J.requirement.projectId),jn(J.requirement))}).catch(()=>{On.current=null}))},[fe,jn,an]);const Lt=p.useCallback((w,K)=>{G(new Set),X(w),W("project"),V(g?"items":"projects"),K?.keepItemDetail||(Pe(null),De(null),I(J=>J==="closed"?J:"project")),history.replaceState(null,"",Wr(He.WORK,w))},[g]),Ft=p.useCallback(w=>{G(new Set),X(null),W("all"),V(g?"items":"projects"),w?.keepItemDetail||(Pe(null),De(null),I(K=>K==="closed"?K:K==="project"?"closed":"empty")),history.replaceState(null,"",Wr(He.WORK))},[g]),Nn=p.useRef(!1);p.useEffect(()=>{if(Nn.current)return;const w=window.location.hash.slice(1).split("/");if(Fr(w[0])===He.WORK&&w[1]){Nn.current=!0,Lt(w[1],{keepItemDetail:!0});return}const K=localStorage.getItem("markus_nav_projectId");if(K){Nn.current=!0,localStorage.removeItem("markus_nav_projectId"),Lt(K,{keepItemDetail:!0});return}Nn.current=!0,Ft({keepItemDetail:!0})},[]),p.useEffect(()=>{if(!be){if(!F){Nn.current=!0,$!=="all"&&W("all");return}if(L.some(w=>w.id===F)){Nn.current=!0;return}Nn.current=!0,Ft({keepItemDetail:!0})}},[be,L,F,Ft,$]);const Fl=p.useRef(Fr(window.location.hash.slice(1).split("/")[0]));p.useEffect(()=>{if(n)return;const w=()=>{const J=window.location.hash.slice(1).split("/"),ne=Fr(J[0]);Fl.current=ne,ne===He.WORK&&(J[1]?Lt(J[1],{keepItemDetail:!0}):Ft({keepItemDetail:!0}))},K=async J=>{const ne=J.detail;if(Fr(ne.page)===He.WORK){if(ne.params?.openTask){const he=ne.params.openTask,Me=ne.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let ke=Object.values(jo.current).flat().find(se=>se.id===he);if(!ke)try{ke=(await re.tasks.get(he)).task}catch{}ke&&(an(ke.projectId),cr(ke,{scrollToComments:Me}))}if(ne.params?.openRequirement){const he=ne.params.openRequirement,Me=ne.params.scrollToComments==="true";let ke=No.current.find(se=>se.id===he);if(!ke)try{ke=(await re.requirements.get(he)).requirement}catch{}ke&&(an(ke.projectId),jn(ke,{scrollToComments:Me}))}if(ne.params?.projectId&&Lt(ne.params.projectId),ne.params?.statusFilter){const he=ne.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),jm.has(he)&&pn(!0),Mr(he)}}};return window.addEventListener("markus:navigate",K),window.addEventListener("hashchange",w),()=>{window.removeEventListener("markus:navigate",K),window.removeEventListener("hashchange",w)}},[n]);const Vl=w=>{ae(!1),st(r("work:task.projectCreated")),R(K=>K.some(J=>J.id===w.id)?K:[...K,w]),Lt(w.id),wn()},Yl=async w=>{try{await re.projects.delete(w),F===w&&Ft(),st(r("work:task.projectDeleted")),wn(),ut()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},Co=async()=>{if(!Ge||!lt||!Je||pt)return;mt("");const w=Je.startsWith("human:"),K=Je.replace(/^(human|agent):/,"");if(lt===K&&!w){st(r("work:task.assignedReviewerDifferent"));return}const J=ft||void 0,ne=zt||void 0;Ht(!0);try{const{task:he}=await re.tasks.create(Ge,je,lt,K,yt,J,dt.length>0?dt:void 0,ne,jt!=="standard"?jt:void 0,jt==="scheduled"?wi(ve):void 0,w?"human":"agent");Ne(""),Ze(""),Yt([]),kt(""),hn("standard"),ct(Os()),me(!1),ut(),he&&cr(he)}catch(he){const ke=`work:task.errorCode_${(he instanceof ci?he.code:void 0)||"unknown"}`,se=r(ke,{defaultValue:""});mt(se||r("work:task.errorCreatingTask",{message:he instanceof Error?he.message:String(he)}))}finally{Ht(!1)}},So=async()=>{if(!(!qt.trim()||!ft))try{const{requirement:w}=await re.requirements.create({title:qt.trim(),description:qt.trim(),priority:"medium",projectId:ft});Wt(""),gt(!1),st(r("work:task.requirementCreated")),St(),w&&kt(w.id)}catch(w){mt(w instanceof Error?w.message:String(w))}},zn=w=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:w}))},Eo=()=>{Dt("/taskboard"),ut(),Xe&&(zn({taskId:Xe.id}),Dt("/tasks/"+Xe.id),re.tasks.get(Xe.id).then(w=>{w.task&&Pe(K=>K?.id===w.task.id?w.task:K)}).catch(()=>{}))},Cn=()=>{Dt("/requirements"),St(),ze&&(Dt("/requirements/"+ze.id),re.requirements.get(ze.id).then(w=>{w.requirement&&De(K=>K?.id===w.requirement.id?w.requirement:K)}).catch(()=>{}))},Mo=async()=>{if(!ws){if(!rn.trim()){on(r("work:task.pleaseReqTitle"));return}if(!xn.trim()){on(r("work:task.pleaseReqDesc"));return}if(!Dn){on(r("work:task.pleaseReqProject"));return}on(""),xo(!0);try{const{requirement:w}=await re.requirements.create({title:rn.trim(),description:xn.trim(),priority:Ir,projectId:Dn});st(r("work:task.requirementCreated")),sn(""),bn(""),gn(!1),St(),w&&jn(w)}catch(w){on(w instanceof Error?w.message:String(w))}finally{xo(!1)}}},ks=async w=>{try{await re.requirements.approve(w),st(r("work:task.requirementApproved")),zn({requirementId:w}),Cn(),ut()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},Gl=async()=>{if(Gt){An("");try{await re.requirements.reject(Gt,mo),st(r("work:task.requirementRejected")),zn({requirementId:Gt}),yn(null),po(""),An(""),Cn()}catch(w){An(w instanceof Error?w.message:String(w))}}},Io=async w=>{try{await re.requirements.cancel(w),st(r("work:task.requirementCancelled")),zn({requirementId:w}),Cn()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},Kl=(w,K)=>{_n.current=K,Ln.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`task:${K.id}`),w.currentTarget.style.opacity="0.4"},Ul=(w,K)=>{Ln.current=K,_n.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`req:${K.id}`),w.currentTarget.style.opacity="0.4"},To=w=>{w.currentTarget.style.opacity="1",_n.current=null,Ln.current=null,Te(null)},Zl=(w,K)=>{w.preventDefault(),w.dataTransfer.dropEffect="move",Ie!==K&&Te(K)},Xl=(w,K)=>{const J=w.currentTarget.getBoundingClientRect(),{clientX:ne,clientY:he}=w;(ne<J.left||ne>J.right||he<J.top||he>J.bottom)&&Ie===K&&Te(null)},Ql=async(w,K)=>{w.preventDefault(),Te(null);const J=_n.current,ne=Ln.current;if(J){const he=o.find(ke=>ke.id===K);if(!he)return;const Me=he.dropStatus;if(J.status===Me||J.status==="pending")return;try{await re.tasks.updateStatus(J.id,Me),ut()}catch{}}else if(ne){const he=Bl[K];if(!he||ne.status===he)return;try{await re.requirements.updateStatus(ne.id,he),St()}catch{}}},Ro=w=>{nt(K=>{const J=new Set(K);return J.has(w)?J.delete(w):J.add(w),J})},Dr=w=>{Lt(w)},Jl=new Set(["rejected","cancelled","archived"]),Ar=w=>Jl.has(w.status),dr=(w,K=!1)=>{let J=w.filter(ne=>Ct||!Ar(ne));return tn&&(J=J.filter(ne=>ne.status===tn)),$==="project"&&F&&(J=J.filter(ne=>ne.projectId===F)),it.size>0&&(J=J.filter(ne=>ne.projectId&&it.has(ne.projectId))),We.size>0&&(J=J.filter(ne=>ne.assignedAgentId&&We.has(ne.assignedAgentId))),Qe&&e?.id&&(J=J.filter(ne=>ne.createdBy===e.id)),J},ec=p.useMemo(()=>{const w=new Map;for(const K of Object.values(H))for(const J of K)w.set(J.id,J);return w},[H]),tc=p.useMemo(()=>new Set(te.map(w=>w.id)),[te]),_o=w=>w.statuses.flatMap(K=>dr(H[K]??[])),Zt=p.useMemo(()=>{let w=fe;return Ct||(w=w.filter(K=>!Ar(K))),$==="project"&&F&&(w=w.filter(K=>K.projectId===F)),it.size>0&&(w=w.filter(K=>K.projectId&&it.has(K.projectId))),We.size>0&&(w=w.filter(K=>We.has(K.createdBy))),Qe&&e?.id&&(w=w.filter(K=>K.createdBy===e.id)),w},[fe,Ct,$,F,it,We,Qe,e?.id,tc]),Lo=p.useCallback(w=>Zt.filter(K=>ss[K.status]===w.id),[Zt]),nc=o.filter(w=>{if(w.id==="failed"||w.id==="closed"){const K=_o(w),J=Lo(w);return K.length+J.length>0}return!0}),ur=Object.values(H).flat().filter(w=>Ar(w)).length+fe.filter(w=>Ar(w)).length,Do=p.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),K=Object.values(H).flat(),J=new Set;for(const ne of K)ne.assignedAgentId&&!w.has(ne.status)&&(!F||ne.projectId===F)&&J.add(ne.assignedAgentId);return[...te].sort((ne,he)=>{const Me=J.has(ne.id)?0:1,ke=J.has(he.id)?0:1;return Me-ke})},[te,H,F]),Pr=p.useMemo(()=>{const w=new Map,K=[];for(const ne of Do)if(ne.teamId){const he=w.get(ne.teamId)??[];he.push(ne.id),w.set(ne.teamId,he)}else K.push(ne);const J=[];for(const ne of K)J.push({kind:"agent",agent:ne});for(const ne of ue){const he=w.get(ne.id);he&&he.length>0&&J.push({kind:"team",id:ne.id,name:ne.name,agentIds:he})}return J},[Do,ue]);p.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),K=Object.values(H).flat(),J=new Set;for(const he of K)he.projectId&&!w.has(he.status)&&J.add(he.projectId);return[...Ct?L:L.filter(he=>he.status!=="archived")].sort((he,Me)=>{const ke=he.status==="archived"?1:0,se=Me.status==="archived"?1:0;if(ke!==se)return ke-se;const ot=J.has(he.id)?0:1,_t=J.has(Me.id)?0:1;return ot!==_t?ot-_t:he.name.localeCompare(Me.name)})},[L,H,Ct]);const $r=p.useMemo(()=>[...L].sort((w,K)=>{const J=w.status==="archived"?1:0,ne=K.status==="archived"?1:0;return J!==ne?J-ne:w.name.localeCompare(K.name)}),[L]),Br=p.useMemo(()=>{const w={};for(const K of Object.values(H))for(const J of K){const ne=J.projectId??"__none__";w[ne]=(w[ne]??0)+1}return w},[H]),Or=Object.values(Br).reduce((w,K)=>w+K,0),rc=F?Br[F]??0:Or,Ao=p.useMemo(()=>{const w=dr(Object.values(H).flat()),K=[];if(Ee==="kanban"){for(const ne of ds){const he=ne.statuses.flatMap(se=>w.filter(ot=>ot.status===se)),ke=[...Zt.filter(se=>ss[se.status]===ne.id).map(se=>({kind:"req",data:se,time:new Date(se.updatedAt??se.createdAt).getTime()})),...he.map(se=>({kind:"task",data:se,time:new Date(se.updatedAt??se.createdAt??0).getTime()}))];ke.sort((se,ot)=>ot.time-se.time);for(const se of ke)se.kind==="req"?K.push({kind:"req",data:se.data}):K.push({kind:"task",data:se.data})}return K}const J=[];for(const ne of w){const he=Ol(ne.status);J.push({kind:"task",data:ne,groupOrder:us[he]??5,time:new Date(ne.updatedAt??ne.createdAt??0).getTime()})}for(const ne of Zt){const he=ss[ne.status]??"todo";J.push({kind:"req",data:ne,groupOrder:us[he]??5,time:new Date(ne.updatedAt??ne.createdAt).getTime()})}return J.sort((ne,he)=>ne.groupOrder!==he.groupOrder?ne.groupOrder-he.groupOrder:he.time-ne.time),J.map(ne=>ne.kind==="req"?{kind:"req",data:ne.data}:{kind:"task",data:ne.data})},[H,Zt,Ee,Ct,tn,F,it,We,Qe,e?.id,$]),zr=p.useRef(Ao);zr.current=Ao;const Po=p.useRef($r);Po.current=$r;const js=p.useRef(F);js.current=F;const Hn=p.useCallback(w=>{w.kind==="req"?(De(w.data),Pe(null)):(Pe(w.data),De(null)),I("item"),T("auto"),V("items")},[]),$o=p.useCallback(()=>{if(kn.current==="item"||kn.current==="empty"){I("closed"),Pe(null),De(null);return}if(Kt.current||Ut.current){I("item"),T("auto"),V("items");return}const w=zr.current;if(w.length>0){Hn(w[0]);return}Pe(null),De(null),I("empty"),T("auto")},[Hn]);p.useEffect(()=>{if(!c)if(g){if(V("items"),kn.current==="project")if(Kt.current||Ut.current)I("item");else{const w=zr.current;w.length>0?Hn(w[0]):I("closed")}}else Pn.current==="items"&&kn.current==="closed"||!g&&kn.current==="closed"&&V("projects")},[g,c,Hn]);const fr=d?.keyboardPane??"content",Bo=p.useRef(fr);if(p.useEffect(()=>{if(n||c||!i)return;const w=Bo.current;Bo.current=fr,fr==="l1"&&(V("projects"),w!=="l1"&&$n.current&&(S(!1),d?.setLeftCollapsed(!1)))},[fr,n,c,i,S,d]),p.useEffect(()=>{if(n||c||!i)return;const w=navigator.platform.toUpperCase().includes("MAC"),K=J=>{if(d?.keyboardPane==="l0")return;const ne=w?J.metaKey&&!J.ctrlKey:J.ctrlKey&&!J.metaKey;if(J.ctrlKey&&!J.metaKey&&J.key==="Tab"){J.preventDefault();const Ce=Fa,Ue=Ce.indexOf(Lr.current),Ae=J.shiftKey?Ce[(Ue-1+Ce.length)%Ce.length]:Ce[(Ue+1)%Ce.length];rt(Ae);return}if(ne&&!J.altKey&&!J.shiftKey){const Ce=J.key.toLowerCase();if(Ce==="j"){J.preventDefault(),Tr();return}if(Ce==="l"){J.preventDefault(),$o();return}}if(ne||J.altKey||J.ctrlKey||J.metaKey||gc(J.target))return;const he=J.key.length===1?J.key.toLowerCase():J.key;if(he==="h"||he==="ArrowLeft"){if($n.current){J.preventDefault(),S(!1),d?.setLeftCollapsed(!1),V("projects"),d?.setKeyboardPane("l1");return}if(Pn.current==="items"){J.preventDefault(),V("projects"),d?.setKeyboardPane("l1");return}J.preventDefault(),d?.setL0FocusPageId(He.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((he==="l"||he==="ArrowRight"||he==="Tab"&&!J.shiftKey)&&!$n.current&&Pn.current==="projects"){J.preventDefault(),V("items"),d?.setKeyboardPane("content");return}if((he==="l"||he==="ArrowRight")&&($n.current||Pn.current==="items")){J.preventDefault();return}const Me=he==="j"||he==="ArrowDown"?1:he==="k"||he==="ArrowUp"?-1:0;if(!Me)return;if(($n.current?"items":Pn.current)==="projects"){J.preventDefault(),d?.setKeyboardPane("l1");const Ce=Po.current,Ue=Ce.length+1;if(Ce.length===0)return;const Ae=js.current==null?0:Ce.findIndex(qn=>qn.id===js.current)+1,Xt=Ae<0?0:Ae,Sn=Math.max(0,Math.min(Ue-1,Xt+Me));if(Sn===0)Ft(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const qn=Ce[Sn-1];Lt(qn.id),kn.current!=="closed"&&(I("project"),Pe(null),De(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${qn.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const se=Lr.current;if(se!=="backlog"&&se!=="kanban")return;J.preventDefault(),d?.setKeyboardPane("content");const ot=zr.current;if(ot.length===0){I(Ce=>Ce==="closed"?"empty":Ce);return}const _t=Kt.current?.id??Ut.current?.id??null;let Et=_t?ot.findIndex(Ce=>Ce.data.id===_t):-1;Et<0&&(Et=Me>0?-1:0);const Fe=Math.max(0,Math.min(ot.length-1,Et+Me));Hn(ot[Fe]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${ot[Fe].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",K,!0),()=>document.removeEventListener("keydown",K,!0)},[n,c,i,Tr,$o,Lt,Ft,Hn,S,d]),be)return t.jsx(Ec,{label:r("work:task.loadingPage")});const Oo=B!=="closed"||!!(Xe||ze),Hr=!c&&!!(Xe&&ze)&&B==="item",zo=c?O:Oo;return t.jsxs("div",{ref:h,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!c&&t.jsx(fm,{projects:$r,selectedProjectId:F,allSelected:$==="all"&&!F,taskCounts:Br,totalTaskCount:Or,onSelectAll:()=>{Ft(),V("projects")},onSelectProject:w=>{Lt(w),V("projects")},onEditProject:w=>{Lt(w),Pe(null),De(null),I("project"),V("projects")},onCreateProject:()=>ae(!0),onCollapse:()=>{const w=!g;S(w),d?.setLeftCollapsed(w)},width:y.width,onResizeStart:y.onResizeStart,hidden:g,focused:fr==="l1"&&Y==="projects"&&!g,onActivate:()=>V("projects")}),t.jsxs("div",{"data-keyboard-pane":"content",onPointerDown:()=>V("items"),className:`${c?"flex-1 min-w-0":Hr?"w-0 shrink-0 overflow-hidden":"flex-1 min-w-0"} overflow-hidden flex flex-col bg-surface-primary`,style:c&&O?{display:"none"}:void 0,children:[ce&&t.jsx("div",{className:"mx-6 mt-2 px-3 py-1.5 bg-green-500/15 text-green-600 text-xs rounded-lg",children:ce}),c?t.jsxs("div",{className:"shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[t.jsx(pc,{}),Rt?t.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[t.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:Rt.name}),t.jsx("button",{onClick:Tr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${B==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:r("work:task.projectsCount",{count:L.length})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>ae(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortProject")}),t.jsx("button",{onClick:we,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortReq")}),t.jsx("button",{onClick:()=>{at(F??""),me(!0)},className:"px-2 py-1 text-[11px] border border-amber-500/60 text-amber-600 rounded-md",children:r("work:task.shortTask")})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-3 py-1.5 min-h-9",children:[t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(w=>t.jsx("button",{onClick:()=>rt(w),className:`px-2 py-0.5 text-[10px] font-medium whitespace-nowrap transition-colors ${Ee===w?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:w==="backlog"?r("work:task.backlog"):w==="kanban"?r("work:task.kanban"):w==="dag"?r("work:task.dag"):r("work:task.workflows","Workflows")},w))}),ur>0&&t.jsx("button",{onClick:()=>pn(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ct?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Ct?r("work:task.hideArchived"):r("work:task.archivedCount",{count:ur})}),t.jsx("div",{className:"flex-1"}),tn&&t.jsxs("button",{onClick:()=>Mr(null),className:"px-2 py-0.5 text-[11px] rounded-md font-medium bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30 flex items-center gap-1",children:[r(`common:status.${tn==="in_progress"?"inProgress":tn}`),t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})]}),(ql.length>1||te.length>0||e?.id)&&t.jsxs("button",{onClick:()=>nn(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${We.size>0||Qe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),t.jsx("span",{children:We.size+(Qe?1:0)>0?r("work:task.filterWithCount",{count:We.size+(Qe?1:0)}):r("work:task.filter")})]})]})]}):t.jsxs("div",{"data-electron-drag":!0,className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[t.jsx("button",{"data-no-drag":!0,type:"button",onClick:()=>{const w=!g;S(w),d?.setLeftCollapsed(w),V("projects")},className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors shrink-0 ${g?"bg-brand-500/15 text-brand-500 hover:bg-brand-500/25":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,title:r(g?"work:task.expand":"work:task.collapse"),children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),Rt?t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[t.jsx(xm,{value:Rt.name,onSave:async w=>{await re.projects.update(Rt.id,{name:w}),wn()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:Tr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${B==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:`${r("work:project.settingsTitle")} (⌘J)`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:r("work:task.projectsCount",{count:L.length})}),ur>0&&t.jsx("button",{onClick:()=>pn(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ct?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Ct?r("work:task.hideArchivedWithCount",{count:ur}):r("work:task.archivedCount",{count:ur})}),t.jsx("div",{"data-no-drag":!0,className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(w=>t.jsx("button",{onClick:()=>rt(w),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Ee===w?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:w==="backlog"?r("work:task.backlog"):w==="kanban"?r("work:task.kanban"):w==="dag"?r("work:task.dag"):r("work:task.workflows","Workflows")},w))}),t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:()=>ae(!0),className:"px-3 py-1.5 border border-border-default text-fg-secondary hover:bg-surface-elevated text-xs rounded-lg font-medium transition-colors",children:r("work:task.newProjectBtn")}),t.jsx("button",{onClick:we,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:r("work:task.newRequirement")}),t.jsx("button",{onClick:()=>{at(F??""),me(!0)},className:"px-3 py-1.5 border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 text-xs rounded-lg font-medium transition-colors",children:r("work:task.newTaskBtn")})]}),t.jsx("div",{className:"flex-1"})]}),!c&&Ee!=="workflows"&&(Pr.length>0||e?.id)&&(rc>0||Zt.length>0||We.size>0||Qe)&&t.jsxs("div",{className:"px-6 py-1.5 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[t.jsx("button",{type:"button",onClick:()=>{nt(new Set),Nt(!1)},className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${We.size>0||Qe?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),e?.id&&t.jsx("button",{type:"button",onClick:()=>Nt(w=>!w),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Qe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:r("work:task.myTasks")}),Pr.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(Me=>We.has(Me)),he=!ne&&w.agentIds.some(Me=>We.has(Me));return t.jsxs("button",{onClick:()=>{nt(Me=>{const ke=new Set(Me);if(ne)for(const se of w.agentIds)ke.delete(se);else for(const se of w.agentIds)ke.add(se);return ke})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ne?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})}),w.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:w.agentIds.length})]},`team-${w.id}`)}const K=w.agent,J=We.has(K.id);return t.jsxs("button",{onClick:()=>Ro(K.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${J?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${J?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:K.name[0]?.toUpperCase()}),K.name]},K.id)})]}),L.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyNoProjectsTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyNoProjectsHint")}),t.jsx("button",{onClick:()=>ae(!0),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:r("work:project.newProject")})]})}):dr(Object.values(H).flat()).length===0&&Zt.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:[t.jsx("path",{d:"M9 11l3 3L22 4"}),t.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}),We.size>0||Qe?t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyFilteredTitle",{defaultValue:"No matching work"})}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyFilteredHint",{defaultValue:"Nothing matches the current assignee filter. Clear filters to see all items in this project."})}),t.jsx("button",{type:"button",onClick:()=>{nt(new Set),Nt(!1)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg font-medium transition-colors",children:r("work:task.clear")})]}):t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyNoReqsTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed whitespace-pre-line",children:r("work:task.emptyNoReqsHint")}),t.jsxs("div",{className:"flex items-center justify-center gap-2 pt-1",children:[t.jsx("button",{onClick:we,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:r("work:task.createRequirementCta")}),t.jsx("button",{onClick:()=>{at(F??""),me(!0)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 rounded-lg font-medium transition-colors",children:r("work:task.newTaskBtn")})]}),$==="project"&&t.jsxs("p",{className:"pt-3 text-[11px] text-fg-tertiary leading-relaxed",children:[r("work:task.emptyNoReqsUnassignedHint")," ",t.jsx("button",{type:"button",onClick:()=>Ft(),className:"inline text-brand-500 hover:text-brand-500 hover:underline",children:r("work:allProjects")})]})]})]})}):Ee==="backlog"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:t.jsx(Dm,{tasks:dr(Object.values(H).flat()),requirements:Zt,agents:te,projects:L,onTaskClick:w=>Rr(w),onReqClick:w=>_r(w),onRefresh:()=>{ut(),St()},selectedTaskId:Xe?.id,selectedReqId:ze?.id,onQuickCreateReq:_e,onQuickCreateTask:ee})}):Ee==="workflows"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col relative",children:t.jsx(Bm,{teamId:Hl,projectId:F,agents:te,projects:L,onViewRunTasks:w=>{const K=ne=>{jn(ne),Rn(`req-${ne.id}`),rt("dag")},J=fe.find(ne=>ne.id===w);J?K(J):re.requirements.get(w).then(ne=>{ne.requirement&&(xe(he=>[...he,ne.requirement]),K(ne.requirement))}).catch(()=>{})}})}):Ee==="dag"?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",children:[t.jsx(dm,{tasks:(()=>{const w=dr(Object.values(H).flat(),!0);if(n&&ze){const K=new Set(ze.taskIds??[]);return w.filter(J=>K.has(J.id))}return w})(),requirements:n&&ze?[ze]:Zt,agents:te,showArchived:Ct,onShowArchivedChange:pn,onTaskClick:w=>Rr(w),onReqClick:w=>_r(w),onCollapseDAG:()=>{Pe(null),De(null),Rn(null)},onDependencyChange:ut,selectedTaskId:Xe?.id,selectedReqId:ze?.id,hasDetailPanel:Oo,defaultExpandedNodeId:mn??(n&&ze?`req-${ze.id}`:void 0),previewMode:n}),c&&t.jsx("button",{onClick:()=>rt("kanban"),className:"absolute left-3 top-1/2 -translate-y-1/2 w-11 h-11 rounded-full bg-brand-500 border border-brand-400/60 shadow-xl shadow-brand-500/30 flex items-center justify-center text-white active:bg-brand-400 backdrop-blur-sm z-10",title:r("work:task.backToKanban"),children:t.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})})}),c&&t.jsx("button",{onClick:()=>rt("workflows"),className:"absolute right-3 top-1/2 -translate-y-1/2 w-11 h-11 rounded-full bg-brand-500 border border-brand-400/60 shadow-xl shadow-brand-500/30 flex items-center justify-center text-white active:bg-brand-400 backdrop-blur-sm z-10",title:r("work:task.toWorkflows","Workflows"),children:t.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})})]}):t.jsx("div",{ref:nr,className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:t.jsx("div",{className:"flex gap-3 items-stretch",children:nc.map(w=>{const K=_o(w),J=Lo(w),ne=K.length+J.length,he=Ie===w.id;return t.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col transition-colors ${he?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:Me=>Zl(Me,w.id),onDragLeave:Me=>Xl(Me,w.id),onDrop:Me=>{Ql(Me,w.id)},children:[t.jsxs("div",{className:`flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30 sticky top-0 z-10 rounded-t-xl ${he?"bg-surface-elevated/60":"bg-surface-secondary/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${w.accent.replace("border-t-","bg-")}`}),t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:w.label})]}),t.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:ne})]}),t.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const Me=[...J.map(ke=>({kind:"req",data:ke,time:new Date(ke.updatedAt??ke.createdAt).getTime()})),...K.map(ke=>({kind:"task",data:ke,time:new Date(ke.updatedAt??ke.createdAt??0).getTime()}))];return Me.sort((ke,se)=>se.time-ke.time),Me.map(ke=>{if(ke.kind==="req"){const se=ke.data,ot=l[se.status]??{label:se.status,cls:"bg-gray-500/15 text-fg-secondary"},Et=se.source==="agent"&&se.status==="pending",Fe=$==="all"&&se.projectId?L.find(Ae=>Ae.id===se.projectId):null,Ce=tr(se.createdBy,te,le)??se.createdBy.slice(0,10),Ue=ze?.id===se.id;return t.jsxs("div",{"data-work-item-id":se.id,role:"button",tabIndex:0,draggable:!0,onDragStart:Ae=>Ul(Ae,se),onDragEnd:To,onClick:()=>_r(se),onKeyDown:Ae=>Ae.key==="Enter"&&_r(se),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
|
|
11
|
+
${Et?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40"}
|
|
12
|
+
${Ue?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),t.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:r("work:task.requirementShort")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${ot.cls}`,children:ot.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:se.title}),se.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:se.description}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[Fe&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:Fe.name,children:Fe.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:se.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",Ce]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[se.goalConfig?.loopEnabled&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",title:se.goalConfig.completionCriteria,children:["🎯 ",se.goalConfig.currentIteration,"/",se.goalConfig.maxIterations]}),se.taskIds.length>0&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",se.taskIds.length]})]})]}),Et&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:Ae=>{Ae.stopPropagation(),ks(se.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:r("work:task.approve")}),t.jsx("button",{onClick:Ae=>{Ae.stopPropagation(),yn(se.id)},className:"flex-1 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:r("work:task.reject")})]})]},`req-${se.id}`)}else{const se=ke.data,ot=se.subtasks?.length??0,_t=a[se.status],Et=se.status==="pending",Fe=se.taskType==="scheduled"&&!!se.scheduleConfig,Ce=Fe?se.scheduleConfig.every?r("work:task.everyInterval",{interval:se.scheduleConfig.every}):se.scheduleConfig.cron?r("work:task.cronLabel"):r("work:task.scheduledShort"):null,Ue=$==="all"&&se.projectId?(()=>{const xt=L.find(qr=>qr.id===se.projectId)?.name;return xt&&xt!=="default"?xt:null})():null,Ae=se.requirementId?fe.find(xt=>xt.id===se.requirementId)?.title:null,Xt=se.createdBy?tr(se.createdBy,te,le)??se.createdBy:null,Sn=Xe?.id===se.id,qn={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},Ho=se.status==="blocked"&&(!se.blockedBy||se.blockedBy.length===0||se.blockedBy.every(xt=>{const qr=ec.get(xt);return qr&&qr.status==="completed"}));return t.jsxs("div",{"data-work-item-id":se.id,role:"button",tabIndex:0,"aria-label":se.title,draggable:!Et,onDragStart:xt=>!Et&&Kl(xt,se),onDragEnd:To,onClick:()=>Rr(se),onKeyDown:xt=>xt.key==="Enter"&&Rr(se),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Ho?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":Et?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Fe?"bg-blue-500/[0.04] border-blue-500/20 hover:border-blue-400/40 cursor-pointer":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40 cursor-grab active:cursor-grabbing"} ${Sn?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${qn[se.priority]??"bg-gray-400"}`,title:se.priority}),Fe&&t.jsx("span",{className:"text-blue-500 shrink-0",title:Ce??"Scheduled",children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})}),Fe&&Ce&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:Ce}),_t&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${_t.cls}`,children:_t.label}),Ho&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md shrink-0 bg-red-500/15 text-red-500 font-medium",children:"⚠"})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:se.title}),se.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:se.description}),(Ue||Ae||se.blockedBy&&se.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[Ue&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded-md truncate max-w-[100px]",title:Ue,children:Ue}),Ae&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-brand-500/8 text-brand-500 rounded-md truncate max-w-[110px]",title:Ae,children:["# ",Ae]}),se.blockedBy&&se.blockedBy.length>0&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",se.blockedBy.length," dep",se.blockedBy.length>1?"s":""]})]}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:Xt&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Xt}`,children:["by ",Xt]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[ot>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",ot]}),se.notes&&se.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",se.notes.length]}),se.assignedAgentId&&t.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${kr[te.find(xt=>xt.id===se.assignedAgentId)?.status??""]??"bg-gray-500"}`}),te.find(xt=>xt.id===se.assignedAgentId)?.name??se.assignedAgentId.slice(0,8)]})]})]})]},se.id)}})})()}),he&&t.jsx("div",{className:"sticky bottom-2 mx-2 mb-2 border-2 border-dashed border-brand-500/25 rounded-lg h-10 flex items-center justify-center shrink-0 bg-surface-secondary/80 backdrop-blur-sm",children:t.jsx("span",{className:"text-[11px] text-brand-500/50",children:r("work:task.dropHere")})})]},w.id)})})})]}),!c&&zo&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:N,children:t.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),zo&&t.jsx("div",{className:`${c||Hr?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:c||Hr?void 0:{width:E},children:B==="project"&&Rt?t.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[t.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 border-b border-border-default/60 sticky top-0 bg-surface-primary z-10",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary truncate flex-1",children:r("work:project.settingsTitle")}),t.jsx("button",{type:"button",onClick:vn,className:"w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated","aria-label":r("common:close"),children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),t.jsx(Im,{project:Rt,tasks:Object.values(H).flat().filter(w=>w.projectId===Rt.id),requirements:fe.filter(w=>w.projectId===Rt.id),agents:te,onDeleteProject:()=>Yl(Rt.id),onUpdateProject:async w=>{await re.projects.update(Rt.id,w),wn()},onRefresh:()=>{wn()}})]}):B==="empty"?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-surface-elevated flex items-center justify-center",children:t.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),t.jsx("path",{d:"M9 12h6"})]})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyDetailTitle",{defaultValue:"No item selected"})}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyDetailHint",{defaultValue:"Select a requirement or task from the list, or create one to get started."})}),t.jsxs("div",{className:"flex items-center justify-center gap-2",children:[t.jsx("button",{onClick:we,className:"px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:r("work:task.newRequirement")}),t.jsx("button",{onClick:()=>{at(F??""),me(!0)},className:"px-3 py-1.5 text-[11px] border border-amber-500/60 text-amber-600 rounded-lg font-medium",children:r("work:task.newTaskBtn")})]}),t.jsx("button",{type:"button",onClick:vn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})}):Hr?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(li,{req:ze,agents:te,projects:L,allTasks:Object.values(H).flat(),users:le,onClose:()=>{De(null),Xe||vn()},onApprove:w=>{ks(w)},onReject:w=>{yn(w)},onCancel:w=>{Io(w),De(null)},onStatusChange:async(w,K)=>{try{await re.requirements.updateStatus(w,K),st(`Requirement status → ${K}`),zn({requirementId:w}),Cn(),ut()}catch(J){st(`Error: ${J}`)}},onRefresh:Cn,authUser:e,onTaskClick:w=>{Pe(w),I("item")},onCreateTask:(w,K)=>{kt(w),K&&at(K),me(!0)},onProjectClick:Dr,previewMode:n})}),t.jsx("div",{className:"w-px shrink-0 bg-border-default"}),t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(ri,{task:Xe,agents:te,projects:L,requirements:fe,allTasks:Object.values(H).flat(),users:le,onClose:Wl,onRefresh:Eo,authUser:e,scrollToComments:vs,onScrollToCommentsDone:()=>lr(!1),onReqClick:w=>{De(K=>K?.id===w.id?null:w),I("item")},onProjectClick:Dr})})]}):Xe?t.jsx(ri,{task:Xe,agents:te,projects:L,requirements:fe,allTasks:Object.values(H).flat(),users:le,onClose:vn,onRefresh:Eo,authUser:e,scrollToComments:vs,onScrollToCommentsDone:()=>lr(!1),onReqClick:w=>{De(w),Pe(null),I("item")},onProjectClick:Dr}):ze?t.jsx(li,{req:ze,agents:te,projects:L,allTasks:Object.values(H).flat(),users:le,onClose:vn,onApprove:w=>{ks(w)},onReject:w=>{yn(w)},onCancel:w=>{Io(w),vn()},onStatusChange:async(w,K)=>{try{await re.requirements.updateStatus(w,K),st(`Requirement status → ${K}`),zn({requirementId:w}),Cn(),ut()}catch(J){st(`Error: ${J}`)}},scrollToComments:vs,onScrollToCommentsDone:()=>lr(!1),onRefresh:Cn,authUser:e,onTaskClick:w=>{Pe(w),De(null),I("item"),c&&(_(!0),history.pushState({mobileDetail:He.WORK},"",window.location.hash))},onCreateTask:(w,K)=>{kt(w),K&&at(K),me(!0)},onProjectClick:Dr,previewMode:n}):t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyDetailTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyDetailHint")}),t.jsx("button",{type:"button",onClick:vn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})})}),Se&&t.jsx(qa,{orgId:e?.orgId,onCreated:Vl,onClose:()=>ae(!1)}),bt&&t.jsx(qa,{orgId:e?.orgId,onCreated:w=>{R(K=>K.some(J=>J.id===w.id)?K:[...K,w]),bt==="task"?(at(w.id),kt("")):ar(w.id),Re(null),st(r("work:task.projectCreated"))},onClose:()=>Re(null)}),ie&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{me(!1),mt("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:w=>w.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.newTask")}),t.jsxs("div",{className:Ys,children:[t.jsx("label",{className:Ve,children:r("work:task.taskType")}),t.jsx("div",{className:"inline-flex w-full p-0.5 bg-surface-elevated border border-border-default rounded-lg",children:["standard","scheduled"].map(w=>t.jsx("button",{type:"button",onClick:()=>hn(w),"aria-pressed":jt===w,className:`flex-1 px-3 py-1.5 text-sm rounded-md transition-colors ${jt===w?"bg-brand-600 text-white font-medium":"text-fg-secondary hover:text-fg-primary"}`,children:r(w==="standard"?"work:task.taskTypeStandard":"work:task.taskTypeScheduled")},w))}),t.jsx("label",{className:Ve,children:r("work:task.titleLabel")}),t.jsx("input",{autoFocus:!c,value:Ge,onChange:w=>Ne(w.target.value),onKeyDown:w=>{w.key==="Enter"&&Co()},className:Jt}),t.jsx("label",{className:Ve,children:r("work:task.descriptionField")}),t.jsx("textarea",{value:je,onChange:w=>Ze(w.target.value),rows:2,className:`${Jt} resize-none`}),t.jsx("label",{className:Ve,children:r("work:task.priorityField")}),t.jsx(cs,{value:yt,onChange:wt}),t.jsx("label",{className:Ve,children:r("work:task.projectLabel")}),t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(It,{className:"flex-1",options:[{value:"",label:r("work:task.noProject")},...L.map(w=>({value:w.id,label:w.name}))],value:ft,onChange:w=>{at(w),kt("")},placeholder:r("work:task.noProject"),noMatchesText:r("work:task.noMatches")}),t.jsx("button",{type:"button",onClick:()=>Re("task"),className:$s,children:r("work:task.newProjectInline")})]}),t.jsx("label",{className:Ve,children:r("work:task.requirementLabel")}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(It,{className:"flex-1",options:[{value:"",label:r("work:task.selectRequirement")},...fe.filter(w=>w.status==="in_progress"&&(!ft||w.projectId===ft)).map(w=>({value:w.id,label:w.title}))],value:zt,onChange:kt,placeholder:r("work:task.selectRequirement"),noMatchesText:r("work:task.noMatches")}),t.jsx("button",{type:"button",onClick:()=>{gt(!0),mt("")},className:$s,children:r("work:task.newRequirementInline")})]}),qe&&t.jsxs("div",{className:"mt-2 space-y-1.5",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{autoFocus:!0,value:qt,onChange:w=>Wt(w.target.value),placeholder:r("work:task.newReqInlinePlaceholder"),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),So())},className:"flex-1 px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{type:"button",onClick:()=>{So()},disabled:!qt.trim(),className:"px-3 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40",children:r("common:create")})]}),t.jsx("p",{className:"text-[11px] text-fg-tertiary",children:r(ft?"work:task.newReqInlineHint":"work:task.newReqInlineNeedProject")})]})]}),t.jsxs("label",{className:Ve,children:[r("work:task.assignToRequired"),t.jsx("span",{className:"text-red-500",children:" *"})]}),t.jsx(It,{options:te.map(w=>({value:w.id,label:`${w.name} (${w.status})`})),value:lt,onChange:vt,placeholder:r("work:task.selectAgent"),noMatchesText:r("work:task.noMatches")}),t.jsxs("label",{className:Ve,children:[r("work:task.reviewerRequired"),t.jsx("span",{className:"text-red-500",children:" *"})]}),t.jsx(It,{options:[...le.map(w=>({value:`human:${w.id}`,label:w.name})),...te.filter(w=>w.id!==lt).map(w=>({value:`agent:${w.id}`,label:`${w.name} (${w.status})`}))],value:Je,onChange:$e,placeholder:r("work:task.selectReviewer"),noMatchesText:r("work:task.noMatches")}),jt==="scheduled"&&t.jsx("div",{className:"col-span-2",children:t.jsx(vi,{value:ve,onChange:ct})}),t.jsx("label",{className:Ve,children:r("work:task.blockedBy")}),t.jsxs("div",{className:"min-w-0",children:[t.jsx(pm,{options:Object.values(H).flat().filter(w=>w.status!=="completed"&&w.status!=="cancelled").map(w=>({value:w.id,label:w.title})),selected:dt,onAdd:w=>Yt([...dt,w]),placeholder:r("work:task.selectDependency"),noMatchesText:r("work:task.noMatches")}),dt.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:dt.map(w=>{const K=Object.values(H).flat().find(J=>J.id===w);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:[K?K.title.slice(0,30):w.slice(-8),t.jsx("button",{onClick:()=>Yt(dt.filter(J=>J!==w)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},w)})})]})]}),ht&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:ht}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{me(!1),mt("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{Co()},disabled:!Ge.trim()||!lt||!Je||pt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:r(pt?"common:creating":"common:create")})]})]})}),sr&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{gn(!1),sn(""),bn(""),on("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:w=>w.stopPropagation(),children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.newRequirementModalTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:r("work:task.newRequirementModalHint")})]}),t.jsxs("div",{className:Ys,children:[t.jsxs("label",{className:Ve,children:[r("work:task.projectLabel"),t.jsx("span",{className:"text-red-500",children:" *"})]}),t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(It,{className:"flex-1",options:L.map(w=>({value:w.id,label:w.name})),value:Dn,onChange:ar,placeholder:r("work:task.selectProject"),noMatchesText:r("work:task.noMatches")}),t.jsx("button",{type:"button",onClick:()=>Re("req"),className:$s,children:r("work:task.newProjectInline")})]}),t.jsxs("label",{className:Ve,children:[r("work:task.titleField"),t.jsx("span",{className:"text-red-500",children:" *"})]}),t.jsx("input",{value:rn,onChange:w=>sn(w.target.value),placeholder:r("work:task.reqTitleExample"),className:Jt,autoFocus:!c,onKeyDown:w=>{w.key==="Enter"&&rn.trim()&&Mo()}}),t.jsxs("label",{className:Ve,children:[r("work:task.descriptionField"),t.jsx("span",{className:"text-red-500",children:" *"})]}),t.jsx("textarea",{value:xn,onChange:w=>bn(w.target.value),placeholder:r("work:task.reqDescPlaceholder"),rows:3,className:`${Jt} resize-none`}),t.jsx("label",{className:Ve,children:r("work:task.priorityField")}),t.jsx(cs,{value:Ir,onChange:or})]}),go&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:go}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{gn(!1),sn(""),bn(""),on("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{Mo()},disabled:!rn.trim()||!xn.trim()||!Dn||ws,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40 disabled:cursor-not-allowed",children:r(ws?"common:creating":"common:create")})]})]})}),Gt&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{yn(null),An("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${c?"w-full":"w-96"}`,onClick:w=>w.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.rejectRequirementTitle")}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.rejectReasonLabel")}),t.jsx("textarea",{value:mo,onChange:w=>po(w.target.value),placeholder:r("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!c})]}),bo&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:bo}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>{yn(null),An("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{Gl()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:r("work:task.reject")})]})]})}),rr&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>nn(!1),children:[t.jsx("div",{className:"absolute inset-0 bg-black/50"}),t.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:w=>w.stopPropagation(),children:[t.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:r("work:task.filtersSheetTitle")}),t.jsxs("div",{className:"flex items-center gap-2",children:[(We.size>0||Qe)&&t.jsx("button",{onClick:()=>{nt(new Set),Nt(!1)},className:"text-[11px] text-brand-500 font-medium",children:r("work:task.clearAll")}),t.jsx("button",{onClick:()=>nn(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),L.length>0&&t.jsxs("div",{className:"px-4 py-3",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:r("work:task.projectsFilterGroup")}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{Ft(),nn(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${$==="all"&&!F?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[r("work:task.all"),Or>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Or})]}),$r.map(w=>{const K=F===w.id,J=Br[w.id]??0;return t.jsxs("button",{type:"button",onClick:()=>{Lt(w.id),nn(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${K?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${K?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:w.name[0]?.toUpperCase()}),w.name,J>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:J})]},w.id)})]})]}),e?.id&&t.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:t.jsx("button",{type:"button",onClick:()=>Nt(w=>!w),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Qe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:r("work:task.myTasks")})}),Pr.length>0&&t.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:r("work:task.agentsFilterGroup")}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Pr.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(Me=>We.has(Me)),he=!ne&&w.agentIds.some(Me=>We.has(Me));return t.jsxs("button",{onClick:()=>{nt(Me=>{const ke=new Set(Me);if(ne)for(const se of w.agentIds)ke.delete(se);else for(const se of w.agentIds)ke.add(se);return ke})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ne?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})}),w.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:w.agentIds.length})]},`team-${w.id}`)}const K=w.agent,J=We.has(K.id);return t.jsxs("button",{onClick:()=>Ro(K.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${J?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${J?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:K.name[0]?.toUpperCase()}),K.name]},K.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Om({requirementId:e,createdBy:n,agents:s,users:r,authUser:i}){const{t:o}=Oe(["work","common"]),[a,l]=p.useState([]),[c,d]=p.useState([]),f=p.useRef(null),[h,m]=p.useState(new Map);p.useEffect(()=>{d([]),m(new Map),f.current&&(clearTimeout(f.current),f.current=null),re.requirements.getComments(e).then(v=>l(v.comments)).catch(()=>{})},[e]),p.useEffect(()=>Tt.on("requirement:comment",y=>{if(y.payload?.requirementId===e&&y.payload.comment){const x=y.payload.comment;l(b=>b.some(j=>j.id===x.id)?b:[...b,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(d(b=>{const j=b.filter(k=>k.id!==x.authorId);return j.length===0&&f.current&&(clearTimeout(f.current),f.current=null),j}),m(b=>{const j=new Map(b);return j.delete(x.authorId),j}))}}),[e]),p.useEffect(()=>{if(c.length===0)return;const v=new Set(c.map(x=>x.id));return Tt.on("agent:activity_log",x=>{const b=x.payload;if(!b)return;const j=b.agentId;if(!v.has(j))return;const k=lo(b);k&&m(M=>co(M,j,k))})},[c]);const[u,g]=p.useState(null),C=async(v,y,x,b)=>{let j;x.length>0&&(j=(await re.uploads.upload(x.map(D=>({dataUrl:D.dataUrl,name:D.name})),"comments")).files.map(D=>({type:"image",url:D.url,name:D.name}))),await re.requirements.addComment(e,v,i?.name,j,i?.id,y.length>0?y:void 0,b);const k=[],M=new Set,T=A=>{if(M.has(A)||A===i?.id)return;M.add(A);const D=s.find(E=>E.id===A);D&&k.push({id:D.id,name:D.name,avatarUrl:D.avatarUrl})};for(const A of y){const D=s.find(E=>E.name.toLowerCase()===A.toLowerCase());D&&T(D.id)}n?.startsWith("agt_")&&T(n),k.length>0&&(f.current&&clearTimeout(f.current),d(k),f.current=setTimeout(()=>d([]),12e4))},S=p.useCallback(v=>{g({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:a.length>0?o("work:task.commentsWithCount",{count:a.length}):o("work:task.comments")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[a.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:o("work:task.noCommentsYet")}),a.map(v=>t.jsx(ys,{comment:v,agents:s,onReply:S},v.id)),c.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(v=>{const y=h.get(v.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(He.TEAM,{agentId:v.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Us,{name:v.name,avatarUrl:v.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:v.name}),y.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(uo,{entries:y})})]},v.id)})})]}),t.jsx(mi,{agents:s,humans:r,onSubmit:C,replyTo:u,onCancelReply:()=>g(null)})]})}function li({req:e,agents:n,projects:s,allTasks:r,users:i,onClose:o,onApprove:a,onReject:l,onCancel:c,onStatusChange:d,onRefresh:f,authUser:h,scrollToComments:m,onScrollToCommentsDone:u,onTaskClick:g,onCreateTask:C,onProjectClick:S,previewMode:v}){const{t:y}=Oe(["work","common"]),x=p.useMemo(()=>ho(y),[y]),b=p.useMemo(()=>$l(y),[y]),j=jr(),[k,M]=p.useState(!1),[T,A]=p.useState(e.description),[D,E]=p.useState(!1),[P,q]=p.useState(!1),[N,O]=p.useState(!1),[_,z]=p.useState(!1),L=p.useRef(null),[R,$]=p.useState("none"),W=p.useRef(null),F=p.useRef(null),X=p.useRef(80);p.useEffect(()=>{const ee=L.current;if(!ee)return;const Se=()=>{const{scrollTop:ie,scrollHeight:me,clientHeight:Ge}=ee;if(!(me>Ge+50)){$("none");return}const je=ie<30,Ze=ie+Ge>=me-30;$(je?"top":Ze?"bottom":"middle")};Se(),ee.addEventListener("scroll",Se,{passive:!0});const ae=new ResizeObserver(Se);return ae.observe(ee),()=>{ee.removeEventListener("scroll",Se),ae.disconnect()}},[]),p.useEffect(()=>{if(k&&F.current){const ee=F.current;ee.style.height="auto",ee.style.height=Math.max(ee.scrollHeight,X.current)+"px",ee.focus()}},[k]),p.useEffect(()=>{if(!m)return;const ee=setTimeout(()=>{const Se=L.current;Se&&Se.scrollTo({top:Se.scrollHeight,behavior:"smooth"}),u?.()},300);return()=>clearTimeout(ee)},[m,u]);const B=x[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},I=e.source==="agent",Y=I&&e.status==="pending",V=e.status==="pending"||e.status==="in_progress",H=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",Z=e.projectId?s.find(ee=>ee.id===e.projectId):null,te=tr(e.createdBy,n,i)??e.createdBy.slice(0,12),oe=r.filter(ee=>e.taskIds.includes(ee.id)),ue=Z?.teamIds?.[0]??null;p.useMemo(()=>new Map(oe.map(ee=>[ee.id,ee])),[oe]);const Q=oe.length>=2;p.useEffect(()=>{A(e.description),M(!1)},[e.id,e.description]);const[le,de]=p.useState(!1),[fe,xe]=p.useState(e.title),[be,U]=p.useState(!1),[ce,pe]=p.useState((e.tags??[]).join(", ")),we=p.useRef(null);p.useEffect(()=>{xe(e.title),de(!1)},[e.id,e.title]),p.useEffect(()=>{pe((e.tags??[]).join(", ")),U(!1)},[e.id,e.tags]),p.useEffect(()=>{le&&we.current?.focus()},[le]);const _e=async ee=>{try{await re.requirements.update(e.id,ee),f?.()}catch{}};return t.jsxs("div",{className:"flex flex-col w-full h-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[j&&t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("h2",{className:"flex-1 min-w-0 pb-4 text-lg font-semibold text-fg-primary leading-snug",children:[le?t.jsx("input",{ref:we,value:fe,onChange:ee=>xe(ee.target.value),onBlur:()=>{const ee=fe.trim();ee&&ee!==e.title&&_e({title:ee}),de(!1)},onKeyDown:ee=>{ee.key==="Enter"&&ee.target.blur(),ee.key==="Escape"&&(xe(e.title),de(!1))},className:"w-full bg-transparent border-b border-brand-500/40 text-lg font-semibold text-fg-primary focus:border-brand-500 outline-none"}):t.jsx("span",{className:`align-middle rounded px-0.5 -mx-0.5 transition-colors ${H?"":"cursor-text hover:bg-surface-elevated/60"}`,onClick:H?void 0:()=>de(!0),role:H?void 0:"button",tabIndex:H?void 0:0,onKeyDown:H?void 0:ee=>ee.key==="Enter"&&de(!0),title:H?void 0:y("work:task.clickToEdit",{defaultValue:"点击编辑"}),children:e.title})," ",t.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded align-middle",children:y("work:task.requirementShort")})," ",t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${B.cls}`,children:B.label})," ",e.priority==="high"||e.priority==="urgent"?t.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:y("common:priority."+e.priority,{defaultValue:e.priority})}):t.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:y("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0 mb-4",children:[t.jsx(fi,{onClick:()=>z(!0),label:y("work:task.sendToChat",{defaultValue:"发送到对话"})}),t.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0",children:"×"})]})]}),_&&t.jsx(Dl,{kind:"requirement",entity:e,agents:n,users:i,projects:s,onClose:()=>z(!1)}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:L,className:"h-full overflow-y-auto p-5 space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:y("work:task.requirementDetailDescription")}),k?t.jsx("textarea",{ref:F,value:T,onChange:ee=>{A(ee.target.value);const Se=ee.target;Se.style.height="auto",Se.style.height=Se.scrollHeight+"px"},onBlur:async()=>{if(T!==e.description){E(!0);try{await re.requirements.update(e.id,{description:T}),f?.()}catch{}finally{E(!1)}}M(!1)},onKeyDown:ee=>{ee.key==="Escape"&&(ee.preventDefault(),A(e.description),M(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:y("work:task.requirementDetailDescription")}):t.jsx("div",{ref:W,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${H?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:H?void 0:ee=>{ee.target.closest("a, button, [data-entity-link]")||(X.current=Math.max(W.current?.offsetHeight??80,60),A(e.description),M(!0))},role:H?void 0:"button",tabIndex:H?void 0:0,onKeyDown:H?void 0:ee=>ee.key==="Enter"&&(A(e.description),M(!0)),children:e.description?t.jsx(pr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:y("work:task.requirementNoDescription")})})]}),t.jsxs("div",{className:"border-t border-border-default/60 pt-4",children:[t.jsxs("div",{className:Ll,children:[t.jsx("label",{className:Ve,children:y("work:task.projectLabel")}),t.jsx(It,{size:"sm",disabled:H,options:[{value:"",label:y("work:task.noProject")},...s.map(ee=>({value:ee.id,label:ee.name}))],value:e.projectId??"",onChange:ee=>{_e({projectId:ee||null})},placeholder:y("work:task.noProject"),noMatchesText:y("work:task.noMatches")}),t.jsx("label",{className:Ve,children:y("work:task.priority")}),t.jsx(cs,{value:e.priority,onChange:ee=>{_e({priority:ee})}}),t.jsx("label",{className:Ve,children:y("work:task.tagsLabel")}),be&&!H?t.jsx("input",{autoFocus:!0,value:ce,onChange:ee=>pe(ee.target.value),onBlur:()=>{const ee=ce.split(",").map(ae=>ae.trim()).filter(Boolean),Se=e.tags??[];ee.join("\0")!==Se.join("\0")&&_e({tags:ee}),U(!1)},onKeyDown:ee=>{ee.key==="Enter"&&ee.target.blur(),ee.key==="Escape"&&(pe((e.tags??[]).join(", ")),U(!1))},placeholder:y("work:task.tagsPlaceholder"),className:`${Jt} !py-1.5 !text-xs`}):t.jsx("div",{className:`flex flex-wrap items-center gap-1.5 rounded-lg -mx-2 px-2 py-1 transition-colors ${H?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:H?void 0:()=>U(!0),role:H?void 0:"button",tabIndex:H?void 0:0,onKeyDown:H?void 0:ee=>ee.key==="Enter"&&U(!0),children:e.tags&&e.tags.length>0?e.tags.map(ee=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",ee]},ee)):t.jsx("span",{className:"text-xs text-fg-tertiary italic",children:y("work:task.noTags")})})]}),t.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-fg-tertiary",children:[t.jsxs("span",{children:[y("work:task.createdByLabel"),": ",t.jsx("span",{className:"text-fg-secondary",children:te}),I&&t.jsx("span",{className:"text-brand-500 ml-1",children:y("work:task.agentTag")})]}),t.jsx("span",{children:new Date(e.createdAt).toLocaleString()}),S&&Z&&t.jsxs("button",{onClick:()=>S(Z.id),className:"hover:text-fg-secondary transition-colors",children:[y("work:task.projectLabel"),": ",Z.name]}),e.approvedBy&&t.jsxs("span",{children:[y("work:task.approvedBy"),": ",t.jsx("span",{className:"text-fg-secondary",children:tr(e.approvedBy,n,i)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:y("work:task.rejectionReason")}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.goalConfig?.loopEnabled&&t.jsxs("div",{className:"bg-brand-500/8 border border-brand-500/20 rounded-lg p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("span",{className:"text-[10px] font-semibold text-brand-500 uppercase tracking-wider",children:y("work:requirement.goal")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${e.goalConfig.currentIteration>=e.goalConfig.maxIterations?"bg-amber-500/15 text-amber-600":"bg-green-500/15 text-green-600"}`,children:e.goalConfig.currentIteration>=e.goalConfig.maxIterations?y("work:requirement.goalMaxReached"):y("work:requirement.goalActive")})]}),t.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:e.goalConfig.completionCriteria}),t.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary",children:[t.jsx("span",{children:y("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&t.jsx("span",{children:y("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&t.jsx("span",{className:"text-brand-500",children:y("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(ee=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",ee]},ee))}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:y("work:task.linkedTasks",{count:oe.length})}),t.jsxs("div",{className:"flex items-center gap-2",children:[Q&&ue&&t.jsxs("button",{onClick:()=>O(!0),className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),y("work:task.saveAsWorkflow")]}),!H&&C&&t.jsxs("button",{onClick:()=>C(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),y("work:requirement.createTask")]})]})]}),oe.length>0?(()=>{const ee=new Map(oe.map(Ne=>[Ne.id,Ne]));if(!oe.some(Ne=>Ne.blockedBy?.some(je=>ee.has(je))))return t.jsx("div",{className:"space-y-1.5",children:oe.map(Ne=>{const je=b[Ne.status];return t.jsxs("div",{onClick:()=>g?.(Ne),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${g?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${kr[Ne.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:Ne.title}),je&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${je.cls}`,children:je.label})]},Ne.id)})});const ae=new Map,ie=new Set;for(const Ne of oe)for(const je of Ne.blockedBy??[])if(ee.has(je)){ie.add(Ne.id);const Ze=ae.get(je)??[];Ze.push(Ne.id),ae.set(je,Ze)}const me=oe.filter(Ne=>!ie.has(Ne.id)),Ge=(Ne,je)=>{const Ze=b[Ne.status],yt=(ae.get(Ne.id)??[]).map(wt=>ee.get(wt)).filter(Boolean);return t.jsxs("div",{children:[t.jsxs("div",{onClick:()=>g?.(Ne),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${g?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:je>0?{marginLeft:je*20}:void 0,children:[je>0&&t.jsx("span",{className:"text-fg-quaternary text-[10px] shrink-0",children:"↳"}),t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${kr[Ne.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:Ne.title}),Ze&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ze.cls}`,children:Ze.label})]}),yt.map(wt=>Ge(wt,je+1))]},Ne.id)};return t.jsx("div",{className:"space-y-1.5",children:me.map(Ne=>Ge(Ne,0))})})():t.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:y("work:requirement.noLinkedTasks")})]}),!v&&t.jsx(Om,{requirementId:e.id,createdBy:e.createdBy,agents:n,users:i,authUser:h}),!v&&t.jsx(zl,{entityType:"requirement",entityId:e.id})]}),R!=="none"&&R!=="top"&&t.jsx("button",{onClick:()=>L.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),R!=="none"&&R!=="bottom"&&t.jsx("button",{onClick:()=>{const ee=L.current;ee&&ee.scrollTo({top:ee.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[Y&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>a(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.approveRequirement")}),t.jsx("button",{onClick:()=>l(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.rejectRequirement")})]}),!Y&&d&&!H&&t.jsx("select",{value:e.status,onChange:ee=>{ee.target.value!==e.status&&d(e.id,ee.target.value)},className:"px-2 py-1.5 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-secondary cursor-pointer hover:border-gray-500 transition-colors",children:_m.map(ee=>{const Se=x[ee],ae=ee===e.status||(Gs[e.status]?.has(ee)??!1);return t.jsx("option",{value:ee,disabled:!ae,children:Se?.label??ee},ee)})}),H&&d&&t.jsx("button",{onClick:()=>d(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:y("work:task.reopen")}),t.jsx("div",{className:"flex-1"}),V&&!Y&&t.jsx("button",{onClick:()=>q(!0),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:y("work:task.cancelRequirement")})]}),P&&t.jsx(Fn,{title:y("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:y("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:y("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{q(!1),c(e.id)},onCancel:()=>q(!1)}),N&&ue&&t.jsx($m,{req:e,tasks:oe,agents:n,teamId:ue,onClose:()=>O(!1),onSaved:()=>O(!1)})]})}function zl({entityType:e,entityId:n}){const{t:s}=Oe(["work"]),[r,i]=p.useState([]),[o,a]=p.useState(!0),[l,c]=p.useState(!1);if(p.useEffect(()=>{a(!0),(e==="task"?re.tasks.getHistory:re.requirements.getHistory)(n).then(u=>i(u.history)).catch(()=>i([])).finally(()=>a(!1))},[e,n]),o)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:s("work:task.loadingHistory","Loading history...")});if(r.length===0)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:s("work:task.noHistory","No status change history.")});const d=l?r:r.slice(-5),f=r.length>5&&!l,h=m=>{const u=m.changedByName||m.changedById||(m.changedByType==="human"?"User":m.changedByType==="agent"?"Agent":"System"),g=m.changedByType==="human"?"bg-blue-500/20 text-blue-500":m.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${g}`,children:u})};return t.jsxs("div",{className:"px-6 py-4",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:s("work:task.statusHistory","Status History")}),f&&t.jsx("button",{onClick:()=>c(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:s("work:task.showAllHistory",{count:r.length})}),t.jsxs("div",{className:"relative ml-2",children:[t.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),t.jsx("div",{className:"space-y-3",children:d.map(m=>t.jsxs("div",{className:"flex items-start gap-3 relative",children:[t.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:m.changedByType==="human"?"#3b82f6":m.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[h(m),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:m.fromStatus}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:m.toStatus})]}),m.reason&&t.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:m.reason}),t.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(m.createdAt).toLocaleString()})]})]},m.id))})]})]})}export{Gm as WorkPage};
|