@markus-global/cli 0.9.9 → 0.10.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/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +15 -1
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/model.d.ts.map +1 -1
- package/dist/commands/model.js +28 -14
- package/dist/commands/model.js.map +1 -1
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +66 -11
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/start.js +55 -3
- package/dist/commands/start.js.map +1 -1
- package/dist/lib/provider-models.d.ts +48 -0
- package/dist/lib/provider-models.d.ts.map +1 -0
- package/dist/lib/provider-models.js +88 -0
- package/dist/lib/provider-models.js.map +1 -0
- package/dist/markus.mjs +11590 -4895
- package/dist/web-ui/assets/{CommentInput-B9QvgXRU.js → CommentInput-DVEZsFdH.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-BEWNNIbH.js → ContentRenderer-D7liy5Ei.js} +3 -3
- package/dist/web-ui/assets/DeliverableShareModal-3Z6n5SPB.js +1 -0
- package/dist/web-ui/assets/Deliverables-pJ0mZrCG.js +3 -0
- package/dist/web-ui/assets/{Notifications-CApxHk72.js → Notifications-B7m8KM5F.js} +1 -1
- package/dist/web-ui/assets/{Search-Afkxd1a6.js → Search-Dg1QnxMv.js} +1 -1
- package/dist/web-ui/assets/Settings-KeOQ8NBT.js +8 -0
- package/dist/web-ui/assets/{Store-DOYqG495.js → Store-znN3kITL.js} +1 -1
- package/dist/web-ui/assets/Team-B3HjBTMx.js +84 -0
- package/dist/web-ui/assets/Work-CLAetrCe.js +12 -0
- package/dist/web-ui/assets/{arc-DaSSpFFZ.js → arc-DLJKkSLU.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-DLDEmNda.js → architectureDiagram-3BPJPVTR-CErxJL8z.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-wjnnl7YH.js → blockDiagram-GPEHLZMM-DhnC1GHJ.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-PlSSecfa.js → c4Diagram-AAUBKEIU-CWcg6zCh.js} +1 -1
- package/dist/web-ui/assets/channel-DXLppOOi.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-DK9cA6te.js → chunk-2J33WTMH-BOcDAFHW.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-QfjEzeta.js → chunk-4BX2VUAB-Dc8q34rQ.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-Baasjplz.js → chunk-55IACEB6-CjeuFc0_.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-ChZiZqSs.js → chunk-727SXJPM-DsyO9cPr.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-CvnzN3BF.js → chunk-AQP2D5EJ-DOhY_Zn6.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-BnvdtniW.js → chunk-FMBD7UC4-C4wQwaKj.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-Cya4BDdk.js → chunk-ND2GUHAM-DAxE9n6p.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-DWHJ4QkC.js → chunk-QZHKN3VN-BqskBLc5.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-Ugc4ArHR.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-Ugc4ArHR.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-CELyP0mw.js → cose-bilkent-S5V4N54A-q7ZrVkOv.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-CDI3cyCz.js → dagre-BM42HDAG-CzpG9RNW.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-BsR5QcOg.js → diagram-2AECGRRQ-Cq3sRUJD.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-qfBEt9Wm.js → diagram-5GNKFQAL-BZlWfVNc.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-DgV2-oUF.js → diagram-KO2AKTUF-BR3FEkPK.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-D3G5wDy7.js → diagram-LMA3HP47-BhgVodCu.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-Did_RC7f.js → diagram-OG6HWLK6-aEqNtQM7.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-CaBnt7lQ.js → docx-preview-BCUdrB1J.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-DkCfZBLl.js → erDiagram-TEJ5UH35-CmKuqvTk.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-CSExusvH.js → flowDiagram-I6XJVG4X-B9PwU7vi.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-BueFExNX.js → ganttDiagram-6RSMTGT7-D4eRLO6n.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-B6AA-uri.js → gitGraphDiagram-PVQCEYII-BX5vzMBG.js} +1 -1
- package/dist/web-ui/assets/index-BrU2YO3p.js +713 -0
- package/dist/web-ui/assets/index-CT8Kx3sa.css +1 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-pN1OECDX.js → infoDiagram-5YYISTIA-isLK7RCT.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-DYLLTDk5.js → ishikawaDiagram-YF4QCWOH-D_KwMIC_.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-Cvhifuv6.js → journeyDiagram-JHISSGLW-BERHrAd2.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-DQlM9G-1.js → kanban-definition-UN3LZRKU-iWhVeCEA.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-DL-UboGV.js → mermaid.core-DBb2SvbA.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-h2m6w0EF.js → mindmap-definition-RKZ34NQL-B1e7ShjO.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-eSVk7_C0.js → pieDiagram-4H26LBE5-CINLSMM2.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-DIryaeZl.js → quadrantDiagram-W4KKPZXB-5OsDJzw-.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-BVjw_HOt.js → requirementDiagram-4Y6WPE33-TckyECvk.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CBvvHuJW.js → sankeyDiagram-5OEKKPKP-BBUaDX49.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-DrhK7vnS.js → sequenceDiagram-3UESZ5HK-CDvlRmkY.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-CwvoCJ1j.js → stateDiagram-AJRCARHV-KuO58ZEJ.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-DxZVvQnr.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-DOet_7ho.js → timeline-definition-PNZ67QCA-De3GteSx.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-B6DiA4eK.js → vennDiagram-CIIHVFJN-B-XEM6Hx.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-DgN-f4t8.js → wardley-L42UT6IY-DX7ioE-0.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-66dcjCfX.js → wardleyDiagram-YWT4CUSO-BrOYIz-Z.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-D8EN-vdQ.js → xychartDiagram-2RQKCTM6-CQANrcat.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/package.json +1 -1
- package/templates/skills/chrome-devtools/SKILL.md +55 -0
- package/dist/web-ui/assets/DeliverableShareModal-C4bKsQbU.js +0 -42
- package/dist/web-ui/assets/Deliverables-Bx8nwOQ9.js +0 -3
- package/dist/web-ui/assets/Settings-B90Lsxn1.js +0 -8
- package/dist/web-ui/assets/Team-BLcZORSs.js +0 -81
- package/dist/web-ui/assets/Work-FiluoP3I.js +0 -11
- package/dist/web-ui/assets/channel-eCnCx_6n.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-Bm-i2o0g.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-Bm-i2o0g.js +0 -1
- package/dist/web-ui/assets/index-BfGY_nvu.css +0 -1
- package/dist/web-ui/assets/index-DHzWBdt5.js +0 -672
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-BflH5xmz.js +0 -1
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{y as zl,z as Hl,x as ql,R as Wl,r as g,j as t,u as Oe,l as ae,B as Vl,a as vr,k as Fl,n as Ot,P as Ve,b as Yl,c as Gl,m as Kl,d as Ls,w as jt,C as At,D as ys,p as Or,M as Zl,i as Xl,E as Hn,q as fr,F as Qa,A as Fs,G as Do,H as Ds,J as Ao,K as As,L as Po,O as $o,Q as Bo,U as Ja,V as ei,W as Ul}from"./index-DHzWBdt5.js";import{ContentRenderer as Ql}from"./ContentRenderer-BEWNNIbH.js";import{s as mt,e as ti,f as Ys,T as vs,g as ws,t as Jl}from"./transform-CpIVI4vC.js";import{i as ks}from"./value-DIujSiJ7.js";import{C as ni}from"./CommentInput-B9QvgXRU.js";function ec(e){let n;for(;n=e.sourceEvent;)e=n;return e}function Pt(e,n){if(e=ec(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 tc={passive:!1},hr={capture:!0,passive:!1};function js(e){e.stopImmediatePropagation()}function Fn(e){e.preventDefault(),e.stopImmediatePropagation()}function ri(e){var n=e.document.documentElement,s=mt(e).on("dragstart.drag",Fn,hr);"onselectstart"in n?s.on("selectstart.drag",Fn,hr):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function si(e,n){var s=e.document.documentElement,r=mt(e).on("dragstart.drag",null);n&&(r.on("click.drag",Fn,hr),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 zr=e=>()=>e;function Ps(e,{sourceEvent:n,subject:s,target:r,identifier:i,active:o,x:a,y:c,dx:l,dy:d,dispatch:h}){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:c,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:h}})}Ps.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function nc(e){return!e.ctrlKey&&!e.button}function rc(){return this.parentNode}function sc(e,n){return n??{x:e.x,y:e.y}}function oc(){return navigator.maxTouchPoints||"ontouchstart"in this}function oi(){var e=nc,n=rc,s=sc,r=oc,i={},o=ti("start","drag","end"),a=0,c,l,d,h,f=0;function m(b){b.on("mousedown.drag",u).filter(r).on("touchstart.drag",C).on("touchmove.drag",y,tc).on("touchend.drag touchcancel.drag",v).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(b,k){if(!(h||!e.call(this,b,k))){var N=x(this,n.call(this,b,k),b,k,"mouse");N&&(mt(b.view).on("mousemove.drag",p,hr).on("mouseup.drag",E,hr),ri(b.view),js(b),d=!1,c=b.clientX,l=b.clientY,N("start",b))}}function p(b){if(Fn(b),!d){var k=b.clientX-c,N=b.clientY-l;d=k*k+N*N>f}i.mouse("drag",b)}function E(b){mt(b.view).on("mousemove.drag mouseup.drag",null),si(b.view,d),Fn(b),i.mouse("end",b)}function C(b,k){if(e.call(this,b,k)){var N=b.changedTouches,I=n.call(this,b,k),D=N.length,A,L;for(A=0;A<D;++A)(L=x(this,I,b,k,N[A].identifier,N[A]))&&(js(b),L("start",b,N[A]))}}function y(b){var k=b.changedTouches,N=k.length,I,D;for(I=0;I<N;++I)(D=i[k[I].identifier])&&(Fn(b),D("drag",b,k[I]))}function v(b){var k=b.changedTouches,N=k.length,I,D;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),I=0;I<N;++I)(D=i[k[I].identifier])&&(js(b),D("end",b,k[I]))}function x(b,k,N,I,D,A){var L=o.copy(),M=Pt(A||N,k),$,z,j;if((j=s.call(b,new Ps("beforestart",{sourceEvent:N,target:m,identifier:D,active:a,x:M[0],y:M[1],dx:0,dy:0,dispatch:L}),I))!=null)return $=j.x-M[0]||0,z=j.y-M[1]||0,function O(_,T,R){var P=M,W;switch(_){case"start":i[D]=O,W=a++;break;case"end":delete i[D],--a;case"drag":M=Pt(R||T,k),W=a;break}L.call(_,b,new Ps(_,{sourceEvent:T,subject:j,target:m,identifier:D,active:W,x:M[0]+$,y:M[1]+z,dx:M[0]-P[0],dy:M[1]-P[1],dispatch:L}),I)}}return m.filter=function(b){return arguments.length?(e=typeof b=="function"?b:zr(!!b),m):e},m.container=function(b){return arguments.length?(n=typeof b=="function"?b:zr(b),m):n},m.subject=function(b){return arguments.length?(s=typeof b=="function"?b:zr(b),m):s},m.touchable=function(b){return arguments.length?(r=typeof b=="function"?b:zr(!!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?(f=(b=+b)*b,m):Math.sqrt(f)},m}var ac=1e-12;function Oo(e){return((e=Math.exp(e))+1/e)/2}function ic(e){return((e=Math.exp(e))-1/e)/2}function lc(e){return((e=Math.exp(2*e))-1)/(e+1)}const Xr=(function e(n,s,r){function i(o,a){var c=o[0],l=o[1],d=o[2],h=a[0],f=a[1],m=a[2],u=h-c,p=f-l,E=u*u+p*p,C,y;if(E<ac)y=Math.log(m/d)/n,C=function(I){return[c+I*u,l+I*p,d*Math.exp(n*I*y)]};else{var v=Math.sqrt(E),x=(m*m-d*d+r*E)/(2*d*s*v),b=(m*m-d*d-r*E)/(2*m*s*v),k=Math.log(Math.sqrt(x*x+1)-x),N=Math.log(Math.sqrt(b*b+1)-b);y=(N-k)/n,C=function(I){var D=I*y,A=Oo(k),L=d/(s*v)*(A*lc(n*D+k)-ic(k));return[c+L*u,l+L*p,d*A/Oo(n*D+k)]}}return C.duration=y*1e3*n/Math.SQRT2,C}return i.rho=function(o){var a=Math.max(.001,+o),c=a*a,l=c*c;return e(a,c,l)},i})(Math.SQRT2,2,4),Hr=e=>()=>e;function cc(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 Ns(e){e.stopImmediatePropagation()}function lr(e){e.preventDefault(),e.stopImmediatePropagation()}function dc(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function uc(){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 zo(){return this.__zoom||Ys}function fc(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function hc(){return navigator.maxTouchPoints||"ontouchstart"in this}function mc(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 ai(){var e=dc,n=uc,s=mc,r=fc,i=hc,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],c=250,l=Xr,d=ti("start","zoom","end"),h,f,m,u=500,p=150,E=0,C=10;function y(j){j.property("__zoom",zo).on("wheel.zoom",D,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",L).filter(i).on("touchstart.zoom",M).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}y.transform=function(j,O,_,T){var R=j.selection?j.selection():j;R.property("__zoom",zo),j!==R?k(j,O,_,T):R.interrupt().each(function(){N(this,arguments).event(T).start().zoom(null,typeof O=="function"?O.apply(this,arguments):O).end()})},y.scaleBy=function(j,O,_,T){y.scaleTo(j,function(){var R=this.__zoom.k,P=typeof O=="function"?O.apply(this,arguments):O;return R*P},_,T)},y.scaleTo=function(j,O,_,T){y.transform(j,function(){var R=n.apply(this,arguments),P=this.__zoom,W=_==null?b(R):typeof _=="function"?_.apply(this,arguments):_,Y=P.invert(W),F=typeof O=="function"?O.apply(this,arguments):O;return s(x(v(P,F),W,Y),R,a)},_,T)},y.translateBy=function(j,O,_,T){y.transform(j,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,T)},y.translateTo=function(j,O,_,T,R){y.transform(j,function(){var P=n.apply(this,arguments),W=this.__zoom,Y=T==null?b(P):typeof T=="function"?T.apply(this,arguments):T;return s(Ys.translate(Y[0],Y[1]).scale(W.k).translate(typeof O=="function"?-O.apply(this,arguments):-O,typeof _=="function"?-_.apply(this,arguments):-_),P,a)},T,R)};function v(j,O){return O=Math.max(o[0],Math.min(o[1],O)),O===j.k?j:new vs(O,j.x,j.y)}function x(j,O,_){var T=O[0]-_[0]*j.k,R=O[1]-_[1]*j.k;return T===j.x&&R===j.y?j:new vs(j.k,T,R)}function b(j){return[(+j[0][0]+ +j[1][0])/2,(+j[0][1]+ +j[1][1])/2]}function k(j,O,_,T){j.on("start.zoom",function(){N(this,arguments).event(T).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(T).end()}).tween("zoom",function(){var R=this,P=arguments,W=N(R,P).event(T),Y=n.apply(R,P),F=_==null?b(Y):typeof _=="function"?_.apply(R,P):_,Q=Math.max(Y[1][0]-Y[0][0],Y[1][1]-Y[0][1]),B=R.__zoom,S=typeof O=="function"?O.apply(R,P):O,V=l(B.invert(F).concat(Q/B.k),S.invert(F).concat(Q/S.k));return function(q){if(q===1)q=S;else{var H=V(q),Z=Q/H[2];q=new vs(Z,F[0]-H[0]*Z,F[1]-H[1]*Z)}W.zoom(null,q)}})}function N(j,O,_){return!_&&j.__zooming||new I(j,O)}function I(j,O){this.that=j,this.args=O,this.active=0,this.sourceEvent=null,this.extent=n.apply(j,O),this.taps=0}I.prototype={event:function(j){return j&&(this.sourceEvent=j),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(j,O){return this.mouse&&j!=="mouse"&&(this.mouse[1]=O.invert(this.mouse[0])),this.touch0&&j!=="touch"&&(this.touch0[1]=O.invert(this.touch0[0])),this.touch1&&j!=="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(j){var O=mt(this.that).datum();d.call(j,this.that,new cc(j,{sourceEvent:this.sourceEvent,target:y,transform:this.that.__zoom,dispatch:d}),O)}};function D(j,...O){if(!e.apply(this,arguments))return;var _=N(this,O).event(j),T=this.__zoom,R=Math.max(o[0],Math.min(o[1],T.k*Math.pow(2,r.apply(this,arguments)))),P=Pt(j);if(_.wheel)(_.mouse[0][0]!==P[0]||_.mouse[0][1]!==P[1])&&(_.mouse[1]=T.invert(_.mouse[0]=P)),clearTimeout(_.wheel);else{if(T.k===R)return;_.mouse=[P,T.invert(P)],ws(this),_.start()}lr(j),_.wheel=setTimeout(W,p),_.zoom("mouse",s(x(v(T,R),_.mouse[0],_.mouse[1]),_.extent,a));function W(){_.wheel=null,_.end()}}function A(j,...O){if(m||!e.apply(this,arguments))return;var _=j.currentTarget,T=N(this,O,!0).event(j),R=mt(j.view).on("mousemove.zoom",F,!0).on("mouseup.zoom",Q,!0),P=Pt(j,_),W=j.clientX,Y=j.clientY;ri(j.view),Ns(j),T.mouse=[P,this.__zoom.invert(P)],ws(this),T.start();function F(B){if(lr(B),!T.moved){var S=B.clientX-W,V=B.clientY-Y;T.moved=S*S+V*V>E}T.event(B).zoom("mouse",s(x(T.that.__zoom,T.mouse[0]=Pt(B,_),T.mouse[1]),T.extent,a))}function Q(B){R.on("mousemove.zoom mouseup.zoom",null),si(B.view,T.moved),lr(B),T.event(B).end()}}function L(j,...O){if(e.apply(this,arguments)){var _=this.__zoom,T=Pt(j.changedTouches?j.changedTouches[0]:j,this),R=_.invert(T),P=_.k*(j.shiftKey?.5:2),W=s(x(v(_,P),T,R),n.apply(this,O),a);lr(j),c>0?mt(this).transition().duration(c).call(k,W,T,j):mt(this).call(y.transform,W,T,j)}}function M(j,...O){if(e.apply(this,arguments)){var _=j.touches,T=_.length,R=N(this,O,j.changedTouches.length===T).event(j),P,W,Y,F;for(Ns(j),W=0;W<T;++W)Y=_[W],F=Pt(Y,this),F=[F,this.__zoom.invert(F),Y.identifier],R.touch0?!R.touch1&&R.touch0[2]!==F[2]&&(R.touch1=F,R.taps=0):(R.touch0=F,P=!0,R.taps=1+!!h);h&&(h=clearTimeout(h)),P&&(R.taps<2&&(f=F[0],h=setTimeout(function(){h=null},u)),ws(this),R.start())}}function $(j,...O){if(this.__zooming){var _=N(this,O).event(j),T=j.changedTouches,R=T.length,P,W,Y,F;for(lr(j),P=0;P<R;++P)W=T[P],Y=Pt(W,this),_.touch0&&_.touch0[2]===W.identifier?_.touch0[0]=Y:_.touch1&&_.touch1[2]===W.identifier&&(_.touch1[0]=Y);if(W=_.that.__zoom,_.touch1){var Q=_.touch0[0],B=_.touch0[1],S=_.touch1[0],V=_.touch1[1],q=(q=S[0]-Q[0])*q+(q=S[1]-Q[1])*q,H=(H=V[0]-B[0])*H+(H=V[1]-B[1])*H;W=v(W,Math.sqrt(q/H)),Y=[(Q[0]+S[0])/2,(Q[1]+S[1])/2],F=[(B[0]+V[0])/2,(B[1]+V[1])/2]}else if(_.touch0)Y=_.touch0[0],F=_.touch0[1];else return;_.zoom("touch",s(x(W,Y,F),_.extent,a))}}function z(j,...O){if(this.__zooming){var _=N(this,O).event(j),T=j.changedTouches,R=T.length,P,W;for(Ns(j),m&&clearTimeout(m),m=setTimeout(function(){m=null},u),P=0;P<R;++P)W=T[P],_.touch0&&_.touch0[2]===W.identifier?delete _.touch0:_.touch1&&_.touch1[2]===W.identifier&&delete _.touch1;if(_.touch1&&!_.touch0&&(_.touch0=_.touch1,delete _.touch1),_.touch0)_.touch0[1]=this.__zoom.invert(_.touch0[0]);else if(_.end(),_.taps===2&&(W=Pt(W,this),Math.hypot(f[0]-W[0],f[1]-W[1])<C)){var Y=mt(this).on("dblclick.zoom");Y&&Y.apply(this,arguments)}}}return y.wheelDelta=function(j){return arguments.length?(r=typeof j=="function"?j:Hr(+j),y):r},y.filter=function(j){return arguments.length?(e=typeof j=="function"?j:Hr(!!j),y):e},y.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:Hr(!!j),y):i},y.extent=function(j){return arguments.length?(n=typeof j=="function"?j:Hr([[+j[0][0],+j[0][1]],[+j[1][0],+j[1][1]]]),y):n},y.scaleExtent=function(j){return arguments.length?(o[0]=+j[0],o[1]=+j[1],y):[o[0],o[1]]},y.translateExtent=function(j){return arguments.length?(a[0][0]=+j[0][0],a[1][0]=+j[1][0],a[0][1]=+j[0][1],a[1][1]=+j[1][1],y):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},y.constrain=function(j){return arguments.length?(s=j,y):s},y.duration=function(j){return arguments.length?(c=+j,y):c},y.interpolate=function(j){return arguments.length?(l=j,y):l},y.on=function(){var j=d.on.apply(d,arguments);return j===d?y:j},y.clickDistance=function(j){return arguments.length?(E=(j=+j)*j,y):Math.sqrt(E)},y.tapDistance=function(j){return arguments.length?(C=+j,y):C},y}function Ke(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=Ke(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."},mr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ii=["Enter"," ","Escape"],li={"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 Yn;(function(e){e.Strict="strict",e.Loose="loose"})(Yn||(Yn={}));var En;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(En||(En={}));var gr;(function(e){e.Partial="partial",e.Full="full"})(gr||(gr={}));const ci={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 Gn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Gn||(Gn={}));var be;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(be||(be={}));const Ho={[be.Left]:be.Right,[be.Right]:be.Left,[be.Top]:be.Bottom,[be.Bottom]:be.Top};function di(e){return e===null?null:e?"valid":"invalid"}const ui=e=>"id"in e&&"source"in e&&"target"in e,gc=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Gs=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),wr=(e,n=[0,0])=>{const{width:s,height:r}=Qt(e),i=e.origin??n,o=s*i[0],a=r*i[1];return{x:e.position.x-o,y:e.position.y-a}},pc=(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):Gs(i)?i:n.nodeLookup.get(i.id));const c=a?es(a,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return as(r,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return is(s)},kr=(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=as(s,es(i)),r=!0)}),r?is(s):{x:0,y:0,width:0,height:0}},Ks=(e,n,[s,r,i]=[0,0,1],o=!1,a=!1)=>{const c={...Nr(n,[s,r,i]),width:n.width/i,height:n.height/i},l=[];for(const d of e.values()){const{measured:h,selectable:f=!0,hidden:m=!1}=d;if(a&&!f||m)continue;const u=h.width??d.width??d.initialWidth??null,p=h.height??d.height??d.initialHeight??null,E=pr(c,Zn(d)),C=(u??0)*(p??0),y=o&&E>0;(!d.internals.handleBounds||y||E>=C||d.dragging)&&l.push(d)}return l},xc=(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 bc(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 yc({nodes:e,width:n,height:s,panZoom:r,minZoom:i,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const c=bc(e,a),l=kr(c),d=Zs(l,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 fi({nodeId:e,nextPosition:n,nodeLookup:s,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const a=s.get(e),c=a.parentId?s.get(a.parentId):void 0,{x:l,y:d}=c?c.internals.positionAbsolute:{x:0,y:0},h=a.origin??r;let f=a.extent||i;if(a.extent==="parent"&&!a.expandParent)if(!c)o?.("005",Vt.error005());else{const u=c.measured.width,p=c.measured.height;u&&p&&(f=[[l,d],[l+u,d+p]])}else c&&Xn(a.extent)&&(f=[[a.extent[0][0]+l,a.extent[0][1]+d],[a.extent[1][0]+l,a.extent[1][1]+d]]);const m=Xn(f)?Mn(n,f,a.measured):n;return(a.measured.width===void 0||a.measured.height===void 0)&&o?.("015",Vt.error015()),{position:{x:m.x-l+(a.measured.width??0)*h[0],y:m.y-d+(a.measured.height??0)*h[1]},positionAbsolute:m}}async function vc({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),p=!u&&m.parentId&&a.find(E=>E.id===m.parentId);(u||p)&&a.push(m)}const c=new Set(n.map(m=>m.id)),l=r.filter(m=>m.deletable!==!1),h=xc(a,l);for(const m of l)c.has(m.id)&&!h.find(p=>p.id===m.id)&&h.push(m);if(!i)return{edges:h,nodes:a};const f=await i({nodes:a,edges:h});return typeof f=="boolean"?f?{edges:h,nodes:a}:{edges:[],nodes:[]}:f}const Kn=(e,n=0,s=1)=>Math.min(Math.max(e,n),s),Mn=(e={x:0,y:0},n,s)=>({x:Kn(e.x,n[0][0],n[1][0]-(s?.width??0)),y:Kn(e.y,n[0][1],n[1][1]-(s?.height??0))});function hi(e,n,s){const{width:r,height:i}=Qt(s),{x:o,y:a}=s.internals.positionAbsolute;return Mn(e,[[o,a],[o+r,a+i]],n)}const qo=(e,n,s)=>e<n?Kn(Math.abs(e-n),1,n)/n:e>s?-Kn(Math.abs(e-s),1,n)/n:0,mi=(e,n,s=15,r=40)=>{const i=qo(e.x,r,n.width-r)*s,o=qo(e.y,r,n.height-r)*s;return[i,o]},as=(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)}),$s=({x:e,y:n,width:s,height:r})=>({x:e,y:n,x2:e+s,y2:n+r}),is=({x:e,y:n,x2:s,y2:r})=>({x:e,y:n,width:s-e,height:r-n}),Zn=(e,n=[0,0])=>{const{x:s,y:r}=Gs(e)?e.internals.positionAbsolute:wr(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}},es=(e,n=[0,0])=>{const{x:s,y:r}=Gs(e)?e.internals.positionAbsolute:wr(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)}},gi=(e,n)=>is(as($s(e),$s(n))),pr=(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)},Wo=e=>$t(e.width)&&$t(e.height)&&$t(e.x)&&$t(e.y),$t=e=>!isNaN(e)&&isFinite(e),wc=(e,n)=>{},jr=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),Nr=({x:e,y:n},[s,r,i],o=!1,a=[1,1])=>{const c={x:(e-s)/i,y:(n-r)/i};return o?jr(c,a):c},ts=({x:e,y:n},[s,r,i])=>({x:e*i+s,y:n*i+r});function zn(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 kc(e,n,s){if(typeof e=="string"||typeof e=="number"){const r=zn(e,s),i=zn(e,n);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=zn(e.top??e.y??0,s),i=zn(e.bottom??e.y??0,s),o=zn(e.left??e.x??0,n),a=zn(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 jc(e,n,s,r,i,o){const{x:a,y:c}=ts(e,[n,s,r]),{x:l,y:d}=ts({x:e.x+e.width,y:e.y+e.height},[n,s,r]),h=i-l,f=o-d;return{left:Math.floor(a),top:Math.floor(c),right:Math.floor(h),bottom:Math.floor(f)}}const Zs=(e,n,s,r,i,o)=>{const a=kc(o,n,s),c=(n-a.x)/e.width,l=(s-a.y)/e.height,d=Math.min(c,l),h=Kn(d,r,i),f=e.x+e.width/2,m=e.y+e.height/2,u=n/2-f*h,p=s/2-m*h,E=jc(e,u,p,h,n,s),C={left:Math.min(E.left-a.left,0),top:Math.min(E.top-a.top,0),right:Math.min(E.right-a.right,0),bottom:Math.min(E.bottom-a.bottom,0)};return{x:u-C.left+C.right,y:p-C.top+C.bottom,zoom:h}},xr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Xn(e){return e!=null&&e!=="parent"}function Qt(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function pi(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function xi(e,n={width:0,height:0},s,r,i){const o={...e},a=r.get(s);if(a){const c=a.origin||i;o.x+=a.internals.positionAbsolute.x-(n.width??0)*c[0],o.y+=a.internals.positionAbsolute.y-(n.height??0)*c[1]}return o}function Vo(e,n){if(e.size!==n.size)return!1;for(const s of e)if(!n.has(s))return!1;return!0}function Nc(){let e,n;return{promise:new Promise((r,i)=>{e=r,n=i}),resolve:e,reject:n}}function Cc(e){return{...li,...e||{}}}function dr(e,{snapGrid:n=[0,0],snapToGrid:s=!1,transform:r,containerBounds:i}){const{x:o,y:a}=Bt(e),c=Nr({x:o-(i?.left??0),y:a-(i?.top??0)},r),{x:l,y:d}=s?jr(c,n):c;return{xSnapped:l,ySnapped:d,...c}}const Xs=e=>({width:e.offsetWidth,height:e.offsetHeight}),bi=e=>e?.getRootNode?.()||window?.document,Sc=["INPUT","SELECT","TEXTAREA"];function yi(e){const n=e.composedPath?.()?.[0]||e.target;return n?.nodeType!==1?!1:Sc.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const vi=e=>"clientX"in e,Bt=(e,n)=>{const s=vi(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)}},Fo=(e,n,s,r,i)=>{const o=n.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const c=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:i,position:a.getAttribute("data-handlepos"),x:(c.left-s.left)/r,y:(c.top-s.top)/r,...Xs(a)}})};function wi({sourceX:e,sourceY:n,targetX:s,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:a,targetControlY:c}){const l=e*.125+i*.375+a*.375+s*.125,d=n*.125+o*.375+c*.375+r*.125,h=Math.abs(l-e),f=Math.abs(d-n);return[l,d,h,f]}function qr(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function Yo({pos:e,x1:n,y1:s,x2:r,y2:i,c:o}){switch(e){case be.Left:return[n-qr(n-r,o),s];case be.Right:return[n+qr(r-n,o),s];case be.Top:return[n,s-qr(s-i,o)];case be.Bottom:return[n,s+qr(i-s,o)]}}function ki({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top,curvature:a=.25}){const[c,l]=Yo({pos:s,x1:e,y1:n,x2:r,y2:i,c:a}),[d,h]=Yo({pos:o,x1:r,y1:i,x2:e,y2:n,c:a}),[f,m,u,p]=wi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:c,sourceControlY:l,targetControlX:d,targetControlY:h});return[`M${e},${n} C${c},${l} ${d},${h} ${r},${i}`,f,m,u,p]}function ji({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,c=r<n?r+a:r-a;return[o,c,i,a]}function Ec({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,c=Math.max(e.parentId||i&&e.selected?e.internals.z:0,n.parentId||i&&n.selected?n.internals.z:0);return a+c}function Mc({sourceNode:e,targetNode:n,width:s,height:r,transform:i}){const o=as(es(e),es(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 pr(a,is(o))>0}const Ic=({source:e,sourceHandle:n,target:s,targetHandle:r})=>`xy-edge__${e}${n||""}-${s}${r||""}`,Tc=(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)),Rc=(e,n,s={})=>{if(!e.source||!e.target)return n;const r=s.getEdgeId||Ic;let i;return ui(e)?i={...e}:i={...e,id:r(e)},Tc(i,n)?n:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,n.concat(i))};function Ni({sourceX:e,sourceY:n,targetX:s,targetY:r}){const[i,o,a,c]=ji({sourceX:e,sourceY:n,targetX:s,targetY:r});return[`M ${e},${n}L ${s},${r}`,i,o,a,c]}const Go={[be.Left]:{x:-1,y:0},[be.Right]:{x:1,y:0},[be.Top]:{x:0,y:-1},[be.Bottom]:{x:0,y:1}},_c=({source:e,sourcePosition:n=be.Bottom,target:s})=>n===be.Left||n===be.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},Ko=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function Lc({source:e,sourcePosition:n=be.Bottom,target:s,targetPosition:r=be.Top,center:i,offset:o,stepPosition:a}){const c=Go[n],l=Go[r],d={x:e.x+c.x*o,y:e.y+c.y*o},h={x:s.x+l.x*o,y:s.y+l.y*o},f=_c({source:d,sourcePosition:n,target:h}),m=f.x!==0?"x":"y",u=f[m];let p=[],E,C;const y={x:0,y:0},v={x:0,y:0},[,,x,b]=ji({sourceX:e.x,sourceY:e.y,targetX:s.x,targetY:s.y});if(c[m]*l[m]===-1){m==="x"?(E=i.x??d.x+(h.x-d.x)*a,C=i.y??(d.y+h.y)/2):(E=i.x??(d.x+h.x)/2,C=i.y??d.y+(h.y-d.y)*a);const N=[{x:E,y:d.y},{x:E,y:h.y}],I=[{x:d.x,y:C},{x:h.x,y:C}];c[m]===u?p=m==="x"?N:I:p=m==="x"?I:N}else{const N=[{x:d.x,y:h.y}],I=[{x:h.x,y:d.y}];if(m==="x"?p=c.x===u?I:N:p=c.y===u?N:I,n===r){const $=Math.abs(e[m]-s[m]);if($<=o){const z=Math.min(o-1,o-$);c[m]===u?y[m]=(d[m]>e[m]?-1:1)*z:v[m]=(h[m]>s[m]?-1:1)*z}}if(n!==r){const $=m==="x"?"y":"x",z=c[m]===l[$],j=d[$]>h[$],O=d[$]<h[$];(c[m]===1&&(!z&&j||z&&O)||c[m]!==1&&(!z&&O||z&&j))&&(p=m==="x"?N:I)}const D={x:d.x+y.x,y:d.y+y.y},A={x:h.x+v.x,y:h.y+v.y},L=Math.max(Math.abs(D.x-p[0].x),Math.abs(A.x-p[0].x)),M=Math.max(Math.abs(D.y-p[0].y),Math.abs(A.y-p[0].y));L>=M?(E=(D.x+A.x)/2,C=p[0].y):(E=p[0].x,C=(D.y+A.y)/2)}return[[e,{x:d.x+y.x,y:d.y+y.y},...p,{x:h.x+v.x,y:h.y+v.y},s],E,C,x,b]}function Dc(e,n,s,r){const i=Math.min(Ko(e,n)/2,Ko(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,h=e.y<s.y?1:-1;return`L ${o+i*d},${a}Q ${o},${a} ${o},${a+i*h}`}const c=e.x<s.x?1:-1,l=e.y<s.y?-1:1;return`L ${o},${a+i*l}Q ${o},${a} ${o+i*c},${a}`}function Bs({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top,borderRadius:a=5,centerX:c,centerY:l,offset:d=20,stepPosition:h=.5}){const[f,m,u,p,E]=Lc({source:{x:e,y:n},sourcePosition:s,target:{x:r,y:i},targetPosition:o,center:{x:c,y:l},offset:d,stepPosition:h});return[f.reduce((y,v,x)=>{let b="";return x>0&&x<f.length-1?b=Dc(f[x-1],v,f[x+1],a):b=`${x===0?"M":"L"}${v.x} ${v.y}`,y+=b,y},""),m,u,p,E]}function Zo(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Ac(e){const{sourceNode:n,targetNode:s}=e;if(!Zo(n)||!Zo(s))return null;const r=n.internals.handleBounds||Xo(n.handles),i=s.internals.handleBounds||Xo(s.handles),o=Uo(r?.source??[],e.sourceHandle),a=Uo(e.connectionMode===Yn.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 c=o?.position||be.Bottom,l=a?.position||be.Top,d=In(n,o,c),h=In(s,a,l);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:c,targetPosition:l}}function Xo(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 In(e,n,s=be.Left,r=!1){const i=(n?.x??0)+e.internals.positionAbsolute.x,o=(n?.y??0)+e.internals.positionAbsolute.y,{width:a,height:c}=n??Qt(e);if(r)return{x:i+a/2,y:o+c/2};switch(n?.position??s){case be.Top:return{x:i+a/2,y:o};case be.Right:return{x:i+a,y:o+c/2};case be.Bottom:return{x:i+a/2,y:o+c};case be.Left:return{x:i,y:o+c/2}}}function Uo(e,n){return e&&(n?e.find(s=>s.id===n):e[0])||null}function Os(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function Pc(e,{id:n,defaultColor:s,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((a,c)=>([c.markerStart||r,c.markerEnd||i].forEach(l=>{if(l&&typeof l=="object"){const d=Os(l,n);o.has(d)||(a.push({id:d,color:l.color||s,...l}),o.add(d))}}),a),[]).sort((a,c)=>a.id.localeCompare(c.id))}const Ci=1e3,$c=10,Us={nodeOrigin:[0,0],nodeExtent:mr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Bc={...Us,checkEquality:!0};function Qs(e,n){const s={...e};for(const r in n)n[r]!==void 0&&(s[r]=n[r]);return s}function Oc(e,n,s){const r=Qs(Us,s);for(const i of e.values())if(i.parentId)eo(i,e,n,r);else{const o=wr(i,r.nodeOrigin),a=Xn(i.extent)?i.extent:r.nodeExtent,c=Mn(o,a,Qt(i));i.internals.positionAbsolute=c}}function zc(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 Js(e){return e==="manual"}function zs(e,n,s,r={}){const i=Qs(Bc,r),o={i:0},a=new Map(n),c=i?.elevateNodesOnSelect&&!Js(i.zIndexMode)?Ci:0;let l=e.length>0;n.clear(),s.clear();for(const d of e){let h=a.get(d.id);if(i.checkEquality&&d===h?.internals.userNode)n.set(d.id,h);else{const f=wr(d,i.nodeOrigin),m=Xn(d.extent)?d.extent:i.nodeExtent,u=Mn(f,m,Qt(d));h={...i.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:u,handleBounds:zc(d,h),z:Si(d,c,i.zIndexMode),userNode:d}},n.set(d.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(l=!1),d.parentId&&eo(h,n,s,r,o)}return l}function Hc(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 eo(e,n,s,r,i){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:c,zIndexMode:l}=Qs(Us,r),d=e.parentId,h=n.get(d);if(!h){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}Hc(e,s),i&&!h.parentId&&h.internals.rootParentIndex===void 0&&l==="auto"&&(h.internals.rootParentIndex=++i.i,h.internals.z=h.internals.z+i.i*$c),i&&h.internals.rootParentIndex!==void 0&&(i.i=h.internals.rootParentIndex);const f=o&&!Js(l)?Ci:0,{x:m,y:u,z:p}=qc(e,h,a,c,f,l),{positionAbsolute:E}=e.internals,C=m!==E.x||u!==E.y;(C||p!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:C?{x:m,y:u}:E,z:p}})}function Si(e,n,s){const r=$t(e.zIndex)?e.zIndex:0;return Js(s)?r:r+(e.selected?n:0)}function qc(e,n,s,r,i,o){const{x:a,y:c}=n.internals.positionAbsolute,l=Qt(e),d=wr(e,s),h=Xn(e.extent)?Mn(d,e.extent,l):d;let f=Mn({x:a+h.x,y:c+h.y},r,l);e.extent==="parent"&&(f=hi(f,l,n));const m=Si(e,i,o),u=n.internals.z??0;return{x:f.x,y:f.y,z:u>=m?u+1:m}}function to(e,n,s,r=[0,0]){const i=[],o=new Map;for(const a of e){const c=n.get(a.parentId);if(!c)continue;const l=o.get(a.parentId)?.expandedRect??Zn(c),d=gi(l,a.rect);o.set(a.parentId,{expandedRect:d,parent:c})}return o.size>0&&o.forEach(({expandedRect:a,parent:c},l)=>{const d=c.internals.positionAbsolute,h=Qt(c),f=c.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,p=Math.max(h.width,Math.round(a.width)),E=Math.max(h.height,Math.round(a.height)),C=(p-h.width)*f[0],y=(E-h.height)*f[1];(m>0||u>0||C||y)&&(i.push({id:l,type:"position",position:{x:c.position.x-m+C,y:c.position.y-u+y}}),s.get(l)?.forEach(v=>{e.some(x=>x.id===v.id)||i.push({id:v.id,type:"position",position:{x:v.position.x+m,y:v.position.y+u}})})),(h.width<a.width||h.height<a.height||m||u)&&i.push({id:l,type:"dimensions",setAttributes:!0,dimensions:{width:p+(m?f[0]*m-C:0),height:E+(u?f[1]*u-y:0)}})}),i}function Wc(e,n,s,r,i,o,a){const c=r?.querySelector(".xyflow__viewport");let l=!1;if(!c)return{changes:[],updatedInternals:l};const d=[],h=window.getComputedStyle(c),{m22:f}=new window.DOMMatrixReadOnly(h.transform),m=[];for(const u of e.values()){const p=n.get(u.id);if(!p)continue;if(p.hidden){n.set(p.id,{...p,internals:{...p.internals,handleBounds:void 0}}),l=!0;continue}const E=Xs(u.nodeElement),C=p.measured.width!==E.width||p.measured.height!==E.height;if(!!(E.width&&E.height&&(C||!p.internals.handleBounds||u.force))){const v=u.nodeElement.getBoundingClientRect(),x=Xn(p.extent)?p.extent:o;let{positionAbsolute:b}=p.internals;p.parentId&&p.extent==="parent"?b=hi(b,E,n.get(p.parentId)):x&&(b=Mn(b,x,E));const k={...p,measured:E,internals:{...p.internals,positionAbsolute:b,handleBounds:{source:Fo("source",u.nodeElement,v,f,p.id),target:Fo("target",u.nodeElement,v,f,p.id)}}};n.set(p.id,k),p.parentId&&eo(k,n,s,{nodeOrigin:i,zIndexMode:a}),l=!0,C&&(d.push({id:p.id,type:"dimensions",dimensions:E}),p.expandParent&&p.parentId&&m.push({id:p.id,parentId:p.parentId,rect:Zn(k,i)}))}}if(m.length>0){const u=to(m,n,s,i);d.push(...u)}return{changes:d,updatedInternals:l}}async function Vc({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),c=!!a&&(a.x!==s[0]||a.y!==s[1]||a.k!==s[2]);return Promise.resolve(c)}function Qo(e,n,s,r,i,o){let a=i;const c=r.get(a)||new Map;r.set(a,c.set(s,n)),a=`${i}-${e}`;const l=r.get(a)||new Map;if(r.set(a,l.set(s,n)),o){a=`${i}-${e}-${o}`;const d=r.get(a)||new Map;r.set(a,d.set(s,n))}}function Ei(e,n,s){e.clear(),n.clear();for(const r of s){const{source:i,target:o,sourceHandle:a=null,targetHandle:c=null}=r,l={edgeId:r.id,source:i,target:o,sourceHandle:a,targetHandle:c},d=`${i}-${a}--${o}-${c}`,h=`${o}-${c}--${i}-${a}`;Qo("source",l,h,e,i,a),Qo("target",l,d,e,o,c),n.set(r.id,r)}}function Mi(e,n){if(!e.parentId)return!1;const s=n.get(e.parentId);return s?s.selected?!0:Mi(s,n):!1}function Jo(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 Fc(e,n,s,r){const i=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!Mi(a,e))&&(a.draggable||n&&typeof a.draggable>"u")){const c=e.get(o);c&&i.set(o,{id:o,position:c.position||{x:0,y:0},distance:{x:s.x-c.internals.positionAbsolute.x,y:s.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:c.measured.width??0,height:c.measured.height??0}})}return i}function Cs({nodeId:e,dragItems:n,nodeLookup:s,dragging:r=!0}){const i=[];for(const[a,c]of n){const l=s.get(a)?.internals.userNode;l&&i.push({...l,position:c.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 Yc({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=jr(o,n);return{x:a.x-o.x,y:a.y-o.y}}function Gc({onNodeMouseDown:e,getStoreItems:n,onDragStart:s,onDrag:r,onDragStop:i}){let o={x:null,y:null},a=0,c=new Map,l=!1,d={x:0,y:0},h=null,f=!1,m=null,u=!1,p=!1,E=null;function C({noDragClassName:v,handleSelector:x,domNode:b,isSelectable:k,nodeId:N,nodeClickDistance:I=0}){m=mt(b);function D({x:$,y:z}){const{nodeLookup:j,nodeExtent:O,snapGrid:_,snapToGrid:T,nodeOrigin:R,onNodeDrag:P,onSelectionDrag:W,onError:Y,updateNodePositions:F}=n();o={x:$,y:z};let Q=!1;const B=c.size>1,S=B&&O?$s(kr(c)):null,V=B&&T?Yc({dragItems:c,snapGrid:_,x:$,y:z}):null;for(const[q,H]of c){if(!j.has(q))continue;let Z={x:$-H.distance.x,y:z-H.distance.y};T&&(Z=V?{x:Math.round(Z.x+V.x),y:Math.round(Z.y+V.y)}:jr(Z,_));let J=null;if(B&&O&&!H.extent&&S){const{positionAbsolute:X}=H.internals,ie=X.x-S.x+O[0][0],de=X.x+H.measured.width-S.x2+O[1][0],se=X.y-S.y+O[0][1],ge=X.y+H.measured.height-S.y2+O[1][1];J=[[ie,se],[de,ge]]}const{position:le,positionAbsolute:te}=fi({nodeId:q,nextPosition:Z,nodeLookup:j,nodeExtent:J||O,nodeOrigin:R,onError:Y});Q=Q||H.position.x!==le.x||H.position.y!==le.y,H.position=le,H.internals.positionAbsolute=te}if(p=p||Q,!!Q&&(F(c,!0),E&&(r||P||!N&&W))){const[q,H]=Cs({nodeId:N,dragItems:c,nodeLookup:j});r?.(E,c,q,H),P?.(E,q,H),N||W?.(E,H)}}async function A(){if(!h)return;const{transform:$,panBy:z,autoPanSpeed:j,autoPanOnNodeDrag:O}=n();if(!O){l=!1,cancelAnimationFrame(a);return}const[_,T]=mi(d,h,j);(_!==0||T!==0)&&(o.x=(o.x??0)-_/$[2],o.y=(o.y??0)-T/$[2],await z({x:_,y:T})&&D(o)),a=requestAnimationFrame(A)}function L($){const{nodeLookup:z,multiSelectionActive:j,nodesDraggable:O,transform:_,snapGrid:T,snapToGrid:R,selectNodesOnDrag:P,onNodeDragStart:W,onSelectionDragStart:Y,unselectNodesAndEdges:F}=n();f=!0,(!P||!k)&&!j&&N&&(z.get(N)?.selected||F()),k&&P&&N&&e?.(N);const Q=dr($.sourceEvent,{transform:_,snapGrid:T,snapToGrid:R,containerBounds:h});if(o=Q,c=Fc(z,O,Q,N),c.size>0&&(s||W||!N&&Y)){const[B,S]=Cs({nodeId:N,dragItems:c,nodeLookup:z});s?.($.sourceEvent,c,B,S),W?.($.sourceEvent,B,S),N||Y?.($.sourceEvent,S)}}const M=oi().clickDistance(I).on("start",$=>{const{domNode:z,nodeDragThreshold:j,transform:O,snapGrid:_,snapToGrid:T}=n();h=z?.getBoundingClientRect()||null,u=!1,p=!1,E=$.sourceEvent,j===0&&L($),o=dr($.sourceEvent,{transform:O,snapGrid:_,snapToGrid:T,containerBounds:h}),d=Bt($.sourceEvent,h)}).on("drag",$=>{const{autoPanOnNodeDrag:z,transform:j,snapGrid:O,snapToGrid:_,nodeDragThreshold:T,nodeLookup:R}=n(),P=dr($.sourceEvent,{transform:j,snapGrid:O,snapToGrid:_,containerBounds:h});if(E=$.sourceEvent,($.sourceEvent.type==="touchmove"&&$.sourceEvent.touches.length>1||N&&!R.has(N))&&(u=!0),!u){if(!l&&z&&f&&(l=!0,A()),!f){const W=Bt($.sourceEvent,h),Y=W.x-d.x,F=W.y-d.y;Math.sqrt(Y*Y+F*F)>T&&L($)}(o.x!==P.xSnapped||o.y!==P.ySnapped)&&c&&f&&(d=Bt($.sourceEvent,h),D(P))}}).on("end",$=>{if(!(!f||u)&&(l=!1,f=!1,cancelAnimationFrame(a),c.size>0)){const{nodeLookup:z,updateNodePositions:j,onNodeDragStop:O,onSelectionDragStop:_}=n();if(p&&(j(c,!1),p=!1),i||O||!N&&_){const[T,R]=Cs({nodeId:N,dragItems:c,nodeLookup:z,dragging:!1});i?.($.sourceEvent,c,T,R),O?.($.sourceEvent,T,R),N||_?.($.sourceEvent,R)}}}).filter($=>{const z=$.target;return!$.button&&(!v||!Jo(z,`.${v}`,b))&&(!x||Jo(z,x,b))});m.call(M)}function y(){m?.on(".drag",null)}return{update:C,destroy:y}}function Kc(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())pr(i,Zn(o))>0&&r.push(o);return r}const Zc=250;function Xc(e,n,s,r){let i=[],o=1/0;const a=Kc(e,s,n+Zc);for(const c of a){const l=[...c.internals.handleBounds?.source??[],...c.internals.handleBounds?.target??[]];for(const d of l){if(r.nodeId===d.nodeId&&r.type===d.type&&r.id===d.id)continue;const{x:h,y:f}=In(c,d,d.position,!0),m=Math.sqrt(Math.pow(h-e.x,2)+Math.pow(f-e.y,2));m>n||(m<o?(i=[{...d,x:h,y:f}],o=m):m===o&&i.push({...d,x:h,y:f}))}}if(!i.length)return null;if(i.length>1){const c=r.type==="source"?"target":"source";return i.find(l=>l.type===c)??i[0]}return i[0]}function Ii(e,n,s,r,i,o=!1){const a=r.get(e);if(!a)return null;const c=i==="strict"?a.internals.handleBounds?.[n]:[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]],l=(s?c?.find(d=>d.id===s):c?.[0])??null;return l&&o?{...l,...In(a,l,l.position,!0)}:l}function Ti(e,n){return e||(n?.classList.contains("target")?"target":n?.classList.contains("source")?"source":null)}function Uc(e,n){let s=null;return n?s=!0:e&&!n&&(s=!1),s}const Ri=()=>!0;function Qc(e,{connectionMode:n,connectionRadius:s,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:a,domNode:c,nodeLookup:l,lib:d,autoPanOnConnect:h,flowId:f,panBy:m,cancelConnection:u,onConnectStart:p,onConnect:E,onConnectEnd:C,isValidConnection:y=Ri,onReconnectEnd:v,updateConnection:x,getTransform:b,getFromHandle:k,autoPanSpeed:N,dragThreshold:I=1,handleDomNode:D}){const A=bi(e.target);let L=0,M;const{x:$,y:z}=Bt(e),j=Ti(o,D),O=c?.getBoundingClientRect();let _=!1;if(!O||!j)return;const T=Ii(i,j,r,l,n);if(!T)return;let R=Bt(e,O),P=!1,W=null,Y=!1,F=null;function Q(){if(!h||!O)return;const[le,te]=mi(R,O,N);m({x:le,y:te}),L=requestAnimationFrame(Q)}const B={...T,nodeId:i,type:j,position:T.position},S=l.get(i);let q={inProgress:!0,isValid:null,from:In(S,B,be.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:S,to:R,toHandle:null,toPosition:Ho[B.position],toNode:null,pointer:R};function H(){_=!0,x(q),p?.(e,{nodeId:i,handleId:r,handleType:j})}I===0&&H();function Z(le){if(!_){const{x:ge,y:ue}=Bt(le),K=ge-$,ce=ue-z;if(!(K*K+ce*ce>I*I))return;H()}if(!k()||!B){J(le);return}const te=b();R=Bt(le,O),M=Xc(Nr(R,te,!1,[1,1]),s,l,B),P||(Q(),P=!0);const X=_i(le,{handle:M,connectionMode:n,fromNodeId:i,fromHandleId:r,fromType:a?"target":"source",isValidConnection:y,doc:A,lib:d,flowId:f,nodeLookup:l});F=X.handleDomNode,W=X.connection,Y=Uc(!!M,X.isValid);const ie=l.get(i),de=ie?In(ie,B,be.Left,!0):q.from,se={...q,from:de,isValid:Y,to:X.toHandle&&Y?ts({x:X.toHandle.x,y:X.toHandle.y},te):R,toHandle:X.toHandle,toPosition:Y&&X.toHandle?X.toHandle.position:Ho[B.position],toNode:X.toHandle?l.get(X.toHandle.nodeId):null,pointer:R};x(se),q=se}function J(le){if(!("touches"in le&&le.touches.length>0)){if(_){(M||F)&&W&&Y&&E?.(W);const{inProgress:te,...X}=q,ie={...X,toPosition:q.toHandle?q.toPosition:null};C?.(le,ie),o&&v?.(le,ie)}u(),cancelAnimationFrame(L),P=!1,Y=!1,W=null,F=null,A.removeEventListener("mousemove",Z),A.removeEventListener("mouseup",J),A.removeEventListener("touchmove",Z),A.removeEventListener("touchend",J)}}A.addEventListener("mousemove",Z),A.addEventListener("mouseup",J),A.addEventListener("touchmove",Z),A.addEventListener("touchend",J)}function _i(e,{handle:n,connectionMode:s,fromNodeId:r,fromHandleId:i,fromType:o,doc:a,lib:c,flowId:l,isValidConnection:d=Ri,nodeLookup:h}){const f=o==="target",m=n?a.querySelector(`.${c}-flow__handle[data-id="${l}-${n?.nodeId}-${n?.id}-${n?.type}"]`):null,{x:u,y:p}=Bt(e),E=a.elementFromPoint(u,p),C=E?.classList.contains(`${c}-flow__handle`)?E:m,y={handleDomNode:C,isValid:!1,connection:null,toHandle:null};if(C){const v=Ti(void 0,C),x=C.getAttribute("data-nodeid"),b=C.getAttribute("data-handleid"),k=C.classList.contains("connectable"),N=C.classList.contains("connectableend");if(!x||!v)return y;const I={source:f?x:r,sourceHandle:f?b:i,target:f?r:x,targetHandle:f?i:b};y.connection=I;const A=k&&N&&(s===Yn.Strict?f&&v==="source"||!f&&v==="target":x!==r||b!==i);y.isValid=A&&d(I),y.toHandle=Ii(x,v,b,h,s,!0)}return y}const Hs={onPointerDown:Qc,isValid:_i};function Jc({domNode:e,panZoom:n,getTransform:s,getViewScale:r}){const i=mt(e);function o({translateExtent:c,width:l,height:d,zoomStep:h=1,pannable:f=!0,zoomable:m=!0,inversePan:u=!1}){const p=x=>{if(x.sourceEvent.type!=="wheel"||!n)return;const b=s(),k=x.sourceEvent.ctrlKey&&xr()?10:1,N=-x.sourceEvent.deltaY*(x.sourceEvent.deltaMode===1?.05:x.sourceEvent.deltaMode?1:.002)*h,I=b[2]*Math.pow(2,N*k);n.scaleTo(I)};let E=[0,0];const C=x=>{(x.sourceEvent.type==="mousedown"||x.sourceEvent.type==="touchstart")&&(E=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY])},y=x=>{const b=s();if(x.sourceEvent.type!=="mousemove"&&x.sourceEvent.type!=="touchmove"||!n)return;const k=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY],N=[k[0]-E[0],k[1]-E[1]];E=k;const I=r()*Math.max(b[2],Math.log(b[2]))*(u?-1:1),D={x:b[0]-N[0]*I,y:b[1]-N[1]*I},A=[[0,0],[l,d]];n.setViewportConstrained({x:D.x,y:D.y,zoom:b[2]},A,c)},v=ai().on("start",C).on("zoom",f?y:null).on("zoom.wheel",m?p:null);i.call(v,{})}function a(){i.on("zoom",null)}return{update:o,destroy:a,pointer:Pt}}const ls=e=>({x:e.x,y:e.y,zoom:e.k}),Ss=({x:e,y:n,zoom:s})=>Ys.translate(e,n).scale(s),qn=(e,n)=>e.target.closest(`.${n}`),Li=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),ed=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Es=(e,n=0,s=ed,r=()=>{})=>{const i=typeof n=="number"&&n>0;return i||r(),i?e.transition().duration(n).ease(s).on("end",r):e},Di=e=>{const n=e.ctrlKey&&xr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function td({zoomPanValues:e,noWheelClassName:n,d3Selection:s,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:c,onPanZoom:l,onPanZoomEnd:d}){return h=>{if(qn(h,n))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const f=s.property("__zoom").k||1;if(h.ctrlKey&&a){const C=Pt(h),y=Di(h),v=f*Math.pow(2,y);r.scaleTo(s,v,C,h);return}const m=h.deltaMode===1?20:1;let u=i===En.Vertical?0:h.deltaX*m,p=i===En.Horizontal?0:h.deltaY*m;!xr()&&h.shiftKey&&i!==En.Vertical&&(u=h.deltaY*m,p=0),r.translateBy(s,-(u/f)*o,-(p/f)*o,{internal:!0});const E=ls(s.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(l?.(h,E),e.panScrollTimeout=setTimeout(()=>{d?.(h,E),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c?.(h,E))}}function nd({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:s}){return function(r,i){const o=r.type==="wheel",a=!n&&o&&!r.ctrlKey,c=qn(r,e);if(r.ctrlKey&&o&&c&&r.preventDefault(),a||c)return null;r.preventDefault(),s.call(this,r,i)}}function rd({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:s}){return r=>{if(r.sourceEvent?.internal)return;const i=ls(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 sd({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:s,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(s&&Li(n,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,ls(o.transform))}}function od({zoomPanValues:e,panOnDrag:n,panOnScroll:s,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return a=>{if(!a.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&Li(n,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const c=ls(a.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(a.sourceEvent,c)},s?150:0)}}}function ad({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:s,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:a,noWheelClassName:c,noPanClassName:l,lib:d,connectionInProgress:h}){return f=>{const m=e||n,u=s&&f.ctrlKey,p=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(qn(f,`${d}-flow__node`)||qn(f,`${d}-flow__edge`)))return!0;if(!r&&!m&&!i&&!o&&!s||a||h&&!p||qn(f,c)&&p||qn(f,l)&&(!p||i&&p&&!e)||!s&&f.ctrlKey&&p)return!1;if(!s&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!m&&!i&&!u&&p||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const E=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||p)&&E}}function id({domNode:e,minZoom:n,maxZoom:s,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:c,onDraggingChange:l}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},h=e.getBoundingClientRect(),f=ai().scaleExtent([n,s]).translateExtent(r),m=mt(e).call(f);v({x:i.x,y:i.y,zoom:Kn(i.zoom,n,s)},[[0,0],[h.width,h.height]],r);const u=m.on("wheel.zoom"),p=m.on("dblclick.zoom");f.wheelDelta(Di);function E(M,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?ks:Xr).transform(Es(m,$?.duration,$?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function C({noWheelClassName:M,noPanClassName:$,onPaneContextMenu:z,userSelectionActive:j,panOnScroll:O,panOnDrag:_,panOnScrollMode:T,panOnScrollSpeed:R,preventScrolling:P,zoomOnPinch:W,zoomOnScroll:Y,zoomOnDoubleClick:F,zoomActivationKeyPressed:Q,lib:B,onTransformChange:S,connectionInProgress:V,paneClickDistance:q,selectionOnDrag:H}){j&&!d.isZoomingOrPanning&&y();const Z=O&&!Q&&!j;f.clickDistance(H?1/0:!$t(q)||q<0?0:q);const J=Z?td({zoomPanValues:d,noWheelClassName:M,d3Selection:m,d3Zoom:f,panOnScrollMode:T,panOnScrollSpeed:R,zoomOnPinch:W,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:c}):nd({noWheelClassName:M,preventScrolling:P,d3ZoomHandler:u});if(m.on("wheel.zoom",J,{passive:!1}),!j){const te=rd({zoomPanValues:d,onDraggingChange:l,onPanZoomStart:a});f.on("start",te);const X=sd({zoomPanValues:d,panOnDrag:_,onPaneContextMenu:!!z,onPanZoom:o,onTransformChange:S});f.on("zoom",X);const ie=od({zoomPanValues:d,panOnDrag:_,panOnScroll:O,onPaneContextMenu:z,onPanZoomEnd:c,onDraggingChange:l});f.on("end",ie)}const le=ad({zoomActivationKeyPressed:Q,panOnDrag:_,zoomOnScroll:Y,panOnScroll:O,zoomOnDoubleClick:F,zoomOnPinch:W,userSelectionActive:j,noPanClassName:$,noWheelClassName:M,lib:B,connectionInProgress:V});f.filter(le),F?m.on("dblclick.zoom",p):m.on("dblclick.zoom",null)}function y(){f.on("zoom",null)}async function v(M,$,z){const j=Ss(M),O=f?.constrain()(j,$,z);return O&&await E(O),new Promise(_=>_(O))}async function x(M,$){const z=Ss(M);return await E(z,$),new Promise(j=>j(z))}function b(M){if(m){const $=Ss(M),z=m.property("__zoom");(z.k!==M.zoom||z.x!==M.x||z.y!==M.y)&&f?.transform(m,$,null,{sync:!0})}}function k(){const M=m?Jl(m.node()):{x:0,y:0,k:1};return{x:M.x,y:M.y,zoom:M.k}}function N(M,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?ks:Xr).scaleTo(Es(m,$?.duration,$?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function I(M,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?ks:Xr).scaleBy(Es(m,$?.duration,$?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function D(M){f?.scaleExtent(M)}function A(M){f?.translateExtent(M)}function L(M){const $=!$t(M)||M<0?0:M;f?.clickDistance($)}return{update:C,destroy:y,setViewport:x,setViewportConstrained:v,getViewport:k,scaleTo:N,scaleBy:I,setScaleExtent:D,setTranslateExtent:A,syncViewport:b,setClickDistance:L}}var Un;(function(e){e.Line="line",e.Handle="handle"})(Un||(Un={}));function ld({width:e,prevWidth:n,height:s,prevHeight:r,affectsX:i,affectsY:o}){const a=e-n,c=s-r,l=[a>0?1:a<0?-1:0,c>0?1:c<0?-1:0];return a&&i&&(l[0]=l[0]*-1),c&&o&&(l[1]=l[1]*-1),l}function ea(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 Wr(e,n,s){return Math.max(0,n-e,e-s)}function ta(e,n){return e?!n:n}function cd(e,n,s,r,i,o,a,c){let{affectsX:l,affectsY:d}=n;const{isHorizontal:h,isVertical:f}=n,m=h&&f,{xSnapped:u,ySnapped:p}=s,{minWidth:E,maxWidth:C,minHeight:y,maxHeight:v}=r,{x,y:b,width:k,height:N,aspectRatio:I}=e;let D=Math.floor(h?u-e.pointerX:0),A=Math.floor(f?p-e.pointerY:0);const L=k+(l?-D:D),M=N+(d?-A:A),$=-o[0]*k,z=-o[1]*N;let j=Wr(L,E,C),O=Wr(M,y,v);if(a){let R=0,P=0;l&&D<0?R=ln(x+D+$,a[0][0]):!l&&D>0&&(R=cn(x+L+$,a[1][0])),d&&A<0?P=ln(b+A+z,a[0][1]):!d&&A>0&&(P=cn(b+M+z,a[1][1])),j=Math.max(j,R),O=Math.max(O,P)}if(c){let R=0,P=0;l&&D>0?R=cn(x+D,c[0][0]):!l&&D<0&&(R=ln(x+L,c[1][0])),d&&A>0?P=cn(b+A,c[0][1]):!d&&A<0&&(P=ln(b+M,c[1][1])),j=Math.max(j,R),O=Math.max(O,P)}if(i){if(h){const R=Wr(L/I,y,v)*I;if(j=Math.max(j,R),a){let P=0;!l&&!d||l&&!d&&m?P=cn(b+z+L/I,a[1][1])*I:P=ln(b+z+(l?D:-D)/I,a[0][1])*I,j=Math.max(j,P)}if(c){let P=0;!l&&!d||l&&!d&&m?P=ln(b+L/I,c[1][1])*I:P=cn(b+(l?D:-D)/I,c[0][1])*I,j=Math.max(j,P)}}if(f){const R=Wr(M*I,E,C)/I;if(O=Math.max(O,R),a){let P=0;!l&&!d||d&&!l&&m?P=cn(x+M*I+$,a[1][0])/I:P=ln(x+(d?A:-A)*I+$,a[0][0])/I,O=Math.max(O,P)}if(c){let P=0;!l&&!d||d&&!l&&m?P=ln(x+M*I,c[1][0])/I:P=cn(x+(d?A:-A)*I,c[0][0])/I,O=Math.max(O,P)}}}A=A+(A<0?O:-O),D=D+(D<0?j:-j),i&&(m?L>M*I?A=(ta(l,d)?-D:D)/I:D=(ta(l,d)?-A:A)*I:h?(A=D/I,d=l):(D=A*I,l=d));const _=l?x+D:x,T=d?b+A:b;return{width:k+(l?-D:D),height:N+(d?-A:A),x:o[0]*D*(l?-1:1)+_,y:o[1]*A*(d?-1:1)+T}}const Ai={width:0,height:0,x:0,y:0},dd={...Ai,pointerX:0,pointerY:0,aspectRatio:1};function ud(e){return[[0,0],[e.measured.width,e.measured.height]]}function fd(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,c=s[0]*o,l=s[1]*a;return[[r-c,i-l],[r+o-c,i+a-l]]}function hd({domNode:e,nodeId:n,getStoreItems:s,onChange:r,onEnd:i}){const o=mt(e);let a={controlDirection:ea("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:d,boundaries:h,keepAspectRatio:f,resizeDirection:m,onResizeStart:u,onResize:p,onResizeEnd:E,shouldResize:C}){let y={...Ai},v={...dd};a={boundaries:h,resizeDirection:m,keepAspectRatio:f,controlDirection:ea(d)};let x,b=null,k=[],N,I,D,A=!1;const L=oi().on("start",M=>{const{nodeLookup:$,transform:z,snapGrid:j,snapToGrid:O,nodeOrigin:_,paneDomNode:T}=s();if(x=$.get(n),!x)return;b=T?.getBoundingClientRect()??null;const{xSnapped:R,ySnapped:P}=dr(M.sourceEvent,{transform:z,snapGrid:j,snapToGrid:O,containerBounds:b});y={width:x.measured.width??0,height:x.measured.height??0,x:x.position.x??0,y:x.position.y??0},v={...y,pointerX:R,pointerY:P,aspectRatio:y.width/y.height},N=void 0,x.parentId&&(x.extent==="parent"||x.expandParent)&&(N=$.get(x.parentId),I=N&&x.extent==="parent"?ud(N):void 0),k=[],D=void 0;for(const[W,Y]of $)if(Y.parentId===n&&(k.push({id:W,position:{...Y.position},extent:Y.extent}),Y.extent==="parent"||Y.expandParent)){const F=fd(Y,x,Y.origin??_);D?D=[[Math.min(F[0][0],D[0][0]),Math.min(F[0][1],D[0][1])],[Math.max(F[1][0],D[1][0]),Math.max(F[1][1],D[1][1])]]:D=F}u?.(M,{...y})}).on("drag",M=>{const{transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:O}=s(),_=dr(M.sourceEvent,{transform:$,snapGrid:z,snapToGrid:j,containerBounds:b}),T=[];if(!x)return;const{x:R,y:P,width:W,height:Y}=y,F={},Q=x.origin??O,{width:B,height:S,x:V,y:q}=cd(v,a.controlDirection,_,a.boundaries,a.keepAspectRatio,Q,I,D),H=B!==W,Z=S!==Y,J=V!==R&&H,le=q!==P&&Z;if(!J&&!le&&!H&&!Z)return;if((J||le||Q[0]===1||Q[1]===1)&&(F.x=J?V:y.x,F.y=le?q:y.y,y.x=F.x,y.y=F.y,k.length>0)){const de=V-R,se=q-P;for(const ge of k)ge.position={x:ge.position.x-de+Q[0]*(B-W),y:ge.position.y-se+Q[1]*(S-Y)},T.push(ge)}if((H||Z)&&(F.width=H&&(!a.resizeDirection||a.resizeDirection==="horizontal")?B:y.width,F.height=Z&&(!a.resizeDirection||a.resizeDirection==="vertical")?S:y.height,y.width=F.width,y.height=F.height),N&&x.expandParent){const de=Q[0]*(F.width??0);F.x&&F.x<de&&(y.x=de,v.x=v.x-(F.x-de));const se=Q[1]*(F.height??0);F.y&&F.y<se&&(y.y=se,v.y=v.y-(F.y-se))}const te=ld({width:y.width,prevWidth:W,height:y.height,prevHeight:Y,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),X={...y,direction:te};C?.(M,X)!==!1&&(A=!0,p?.(M,X),r(F,T))}).on("end",M=>{A&&(E?.(M,{...y}),i?.({...y}),A=!1)});o.call(L)}function l(){o.on(".drag",null)}return{update:c,destroy:l}}var Ms={exports:{}},Is={};var na;function md(){if(na)return Is;na=1;var e=zl(),n=Hl();function s(d,h){return d===h&&(d!==0||1/d===1/h)||d!==d&&h!==h}var r=typeof Object.is=="function"?Object.is:s,i=n.useSyncExternalStore,o=e.useRef,a=e.useEffect,c=e.useMemo,l=e.useDebugValue;return Is.useSyncExternalStoreWithSelector=function(d,h,f,m,u){var p=o(null);if(p.current===null){var E={hasValue:!1,value:null};p.current=E}else E=p.current;p=c(function(){function y(N){if(!v){if(v=!0,x=N,N=m(N),u!==void 0&&E.hasValue){var I=E.value;if(u(I,N))return b=I}return b=N}if(I=b,r(x,N))return I;var D=m(N);return u!==void 0&&u(I,D)?(x=N,I):(x=N,b=D)}var v=!1,x,b,k=f===void 0?null:f;return[function(){return y(h())},k===null?void 0:function(){return y(k())}]},[h,f,m,u]);var C=i(d,p[0],p[1]);return a(function(){E.hasValue=!0,E.value=C},[C]),l(C),C},Is}var ra;function gd(){return ra||(ra=1,Ms.exports=md()),Ms.exports}var pd=gd();const xd=ql(pd),bd={},sa=e=>{let n;const s=new Set,r=(h,f)=>{const m=typeof h=="function"?h(n):h;if(!Object.is(m,n)){const u=n;n=f??(typeof m!="object"||m===null)?m:Object.assign({},n,m),s.forEach(p=>p(n,u))}},i=()=>n,l={setState:r,getState:i,getInitialState:()=>d,subscribe:h=>(s.add(h),()=>s.delete(h)),destroy:()=>{(bd?"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,l);return l},yd=e=>e?sa(e):sa,{useDebugValue:vd}=Wl,{useSyncExternalStoreWithSelector:wd}=xd,kd=e=>e;function Pi(e,n=kd,s){const r=wd(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,s);return vd(r),r}const oa=(e,n)=>{const s=yd(e),r=(i,o=n)=>Pi(s,i,o);return Object.assign(r,s),r},jd=(e,n)=>e?oa(e,n):oa;function qe(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 cs=g.createContext(null),Nd=cs.Provider,$i=Vt.error001();function Re(e,n){const s=g.useContext(cs);if(s===null)throw new Error($i);return Pi(s,e,n)}function ze(){const e=g.useContext(cs);if(e===null)throw new Error($i);return g.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const aa={display:"none"},Cd={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Bi="react-flow__node-desc",Oi="react-flow__edge-desc",Sd="react-flow__aria-live",Ed=e=>e.ariaLiveMessage,Md=e=>e.ariaLabelConfig;function Id({rfId:e}){const n=Re(Ed);return t.jsx("div",{id:`${Sd}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Cd,children:n})}function Td({rfId:e,disableKeyboardA11y:n}){const s=Re(Md);return t.jsxs(t.Fragment,{children:[t.jsx("div",{id:`${Bi}-${e}`,style:aa,children:n?s["node.a11yDescription.default"]:s["node.a11yDescription.keyboardDisabled"]}),t.jsx("div",{id:`${Oi}-${e}`,style:aa,children:s["edge.a11yDescription.default"]}),!n&&t.jsx(Id,{rfId:e})]})}const ds=g.forwardRef(({position:e="top-left",children:n,className:s,style:r,...i},o)=>{const a=`${e}`.split("-");return t.jsx("div",{className:Ke(["react-flow__panel",s,...a]),style:r,ref:o,...i,children:n})});ds.displayName="Panel";function Rd({proOptions:e,position:n="bottom-right"}){return e?.hideAttribution?null:t.jsx(ds,{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 _d=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}},Vr=e=>e.id;function Ld(e,n){return qe(e.selectedNodes.map(Vr),n.selectedNodes.map(Vr))&&qe(e.selectedEdges.map(Vr),n.selectedEdges.map(Vr))}function Dd({onSelectionChange:e}){const n=ze(),{selectedNodes:s,selectedEdges:r}=Re(_d,Ld);return g.useEffect(()=>{const i={nodes:s,edges:r};e?.(i),n.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[s,r,e]),null}const Ad=e=>!!e.onSelectionChangeHandlers;function Pd({onSelectionChange:e}){const n=Re(Ad);return e||n?t.jsx(Dd,{onSelectionChange:e}):null}const zi=[0,0],$d={x:0,y:0,zoom:1},Bd=["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"],ia=[...Bd,"rfId"],Od=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}),la={translateExtent:mr,nodeOrigin:zi,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function zd(e){const{setNodes:n,setEdges:s,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:a,reset:c,setDefaultNodesAndEdges:l}=Re(Od,qe),d=ze();g.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{h.current=la,c()}),[]);const h=g.useRef(la);return g.useEffect(()=>{for(const f of ia){const m=e[f],u=h.current[f];m!==u&&(typeof e[f]>"u"||(f==="nodes"?n(m):f==="edges"?s(m):f==="minZoom"?r(m):f==="maxZoom"?i(m):f==="translateExtent"?o(m):f==="nodeExtent"?a(m):f==="ariaLabelConfig"?d.setState({ariaLabelConfig:Cc(m)}):f==="fitView"?d.setState({fitViewQueued:m}):f==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[f]:m})))}h.current=e},ia.map(f=>e[f])),null}function ca(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Hd(e){const[n,s]=g.useState(e==="system"?null:e);return g.useEffect(()=>{if(e!=="system"){s(e);return}const r=ca(),i=()=>s(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),n!==null?n:ca()?.matches?"dark":"light"}const da=typeof document<"u"?document:null;function br(e=null,n={target:da,actInsideInputWithModifier:!0}){const[s,r]=g.useState(!1),i=g.useRef(!1),o=g.useRef(new Set([])),[a,c]=g.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
|
|
2
|
-
`).replace(`
|
|
3
|
-
|
|
4
|
-
`,`
|
|
5
|
-
+`).split(`
|
|
6
|
-
`)),h=d.reduce((f,m)=>f.concat(...m),[]);return[d,h]}return[[],[]]},[e]);return g.useEffect(()=>{const l=n?.target??da,d=n?.actInsideInputWithModifier??!0;if(e!==null){const h=u=>{if(i.current=u.ctrlKey||u.metaKey||u.shiftKey||u.altKey,(!i.current||i.current&&!d)&&yi(u))return!1;const E=fa(u.code,c);if(o.current.add(u[E]),ua(a,o.current,!1)){const C=u.composedPath?.()?.[0]||u.target,y=C?.nodeName==="BUTTON"||C?.nodeName==="A";n.preventDefault!==!1&&(i.current||!y)&&u.preventDefault(),r(!0)}},f=u=>{const p=fa(u.code,c);ua(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(u[p]),u.key==="Meta"&&o.current.clear(),i.current=!1},m=()=>{o.current.clear(),r(!1)};return l?.addEventListener("keydown",h),l?.addEventListener("keyup",f),window.addEventListener("blur",m),window.addEventListener("contextmenu",m),()=>{l?.removeEventListener("keydown",h),l?.removeEventListener("keyup",f),window.removeEventListener("blur",m),window.removeEventListener("contextmenu",m)}}},[e,r]),s}function ua(e,n,s){return e.filter(r=>s||r.length===n.size).some(r=>r.every(i=>n.has(i)))}function fa(e,n){return n.includes(e)?"code":"key"}const qd=()=>{const e=ze();return g.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:c}=e.getState(),l=Zs(n,r,i,o,a,s?.padding??.1);return c?(await c.setViewport(l,{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:c,y:l}=a.getBoundingClientRect(),d={x:n.x-c,y:n.y-l},h=s.snapGrid??i,f=s.snapToGrid??o;return Nr(d,r,f,h)},flowToScreenPosition:n=>{const{transform:s,domNode:r}=e.getState();if(!r)return n;const{x:i,y:o}=r.getBoundingClientRect(),a=ts(n,s);return{x:a.x+i,y:a.y+o}}}),[])};function Hi(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 c={...o};for(const l of a)Wd(l,c);s.push(c)}return i.length&&i.forEach(o=>{o.index!==void 0?s.splice(o.index,0,{...o.item}):s.push({...o.item})}),s}function Wd(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 qi(e,n){return Hi(e,n)}function Wi(e,n){return Hi(e,n)}function Sn(e,n){return{id:e,type:"select",selected:n}}function Wn(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(Sn(o.id,a)))}return r}function ha({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),c=a?.internals?.userNode??a;c!==void 0&&c!==o&&s.push({id:o.id,item:o,type:"replace"}),c===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 ma(e){return{id:e.id,type:"remove"}}const ga=e=>gc(e),Vd=e=>ui(e);function Vi(e){return g.forwardRef(e)}const Fd=typeof window<"u"?g.useLayoutEffect:g.useEffect;function pa(e){const[n,s]=g.useState(BigInt(0)),[r]=g.useState(()=>Yd(()=>s(i=>i+BigInt(1))));return Fd(()=>{const i=r.get();i.length&&(e(i),r.reset())},[n]),r}function Yd(e){let n=[];return{get:()=>n,reset:()=>{n=[]},push:s=>{n.push(s),e()}}}const Fi=g.createContext(null);function Gd({children:e}){const n=ze(),s=g.useCallback(c=>{const{nodes:l=[],setNodes:d,hasDefaultNodes:h,onNodesChange:f,nodeLookup:m,fitViewQueued:u,onNodesChangeMiddlewareMap:p}=n.getState();let E=l;for(const y of c)E=typeof y=="function"?y(E):y;let C=ha({items:E,lookup:m});for(const y of p.values())C=y(C);h&&d(E),C.length>0?f?.(C):u&&window.requestAnimationFrame(()=>{const{fitViewQueued:y,nodes:v,setNodes:x}=n.getState();y&&x(v)})},[]),r=pa(s),i=g.useCallback(c=>{const{edges:l=[],setEdges:d,hasDefaultEdges:h,onEdgesChange:f,edgeLookup:m}=n.getState();let u=l;for(const p of c)u=typeof p=="function"?p(u):p;h?d(u):f&&f(ha({items:u,lookup:m}))},[]),o=pa(i),a=g.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return t.jsx(Fi.Provider,{value:a,children:e})}function Kd(){const e=g.useContext(Fi);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Zd=e=>!!e.panZoom;function no(){const e=qd(),n=ze(),s=Kd(),r=Re(Zd),i=g.useMemo(()=>{const o=f=>n.getState().nodeLookup.get(f),a=f=>{s.nodeQueue.push(f)},c=f=>{s.edgeQueue.push(f)},l=f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState(),p=ga(f)?f:m.get(f.id),E=p.parentId?xi(p.position,p.measured,p.parentId,m,u):p.position,C={...p,position:E,width:p.measured?.width??p.width,height:p.measured?.height??p.height};return Zn(C)},d=(f,m,u={replace:!1})=>{a(p=>p.map(E=>{if(E.id===f){const C=typeof m=="function"?m(E):m;return u.replace&&ga(C)?C:{...E,...C}}return E}))},h=(f,m,u={replace:!1})=>{c(p=>p.map(E=>{if(E.id===f){const C=typeof m=="function"?m(E):m;return u.replace&&Vd(C)?C:{...E,...C}}return E}))};return{getNodes:()=>n.getState().nodes.map(f=>({...f})),getNode:f=>o(f)?.internals.userNode,getInternalNode:o,getEdges:()=>{const{edges:f=[]}=n.getState();return f.map(m=>({...m}))},getEdge:f=>n.getState().edgeLookup.get(f),setNodes:a,setEdges:c,addNodes:f=>{const m=Array.isArray(f)?f:[f];s.nodeQueue.push(u=>[...u,...m])},addEdges:f=>{const m=Array.isArray(f)?f:[f];s.edgeQueue.push(u=>[...u,...m])},toObject:()=>{const{nodes:f=[],edges:m=[],transform:u}=n.getState(),[p,E,C]=u;return{nodes:f.map(y=>({...y})),edges:m.map(y=>({...y})),viewport:{x:p,y:E,zoom:C}}},deleteElements:async({nodes:f=[],edges:m=[]})=>{const{nodes:u,edges:p,onNodesDelete:E,onEdgesDelete:C,triggerNodeChanges:y,triggerEdgeChanges:v,onDelete:x,onBeforeDelete:b}=n.getState(),{nodes:k,edges:N}=await vc({nodesToRemove:f,edgesToRemove:m,nodes:u,edges:p,onBeforeDelete:b}),I=N.length>0,D=k.length>0;if(I){const A=N.map(ma);C?.(N),v(A)}if(D){const A=k.map(ma);E?.(k),y(A)}return(D||I)&&x?.({nodes:k,edges:N}),{deletedNodes:k,deletedEdges:N}},getIntersectingNodes:(f,m=!0,u)=>{const p=Wo(f),E=p?f:l(f),C=u!==void 0;return E?(u||n.getState().nodes).filter(y=>{const v=n.getState().nodeLookup.get(y.id);if(v&&!p&&(y.id===f.id||!v.internals.positionAbsolute))return!1;const x=Zn(C?y:v),b=pr(x,E);return m&&b>0||b>=x.width*x.height||b>=E.width*E.height}):[]},isNodeIntersecting:(f,m,u=!0)=>{const E=Wo(f)?f:l(f);if(!E)return!1;const C=pr(E,m);return u&&C>0||C>=m.width*m.height||C>=E.width*E.height},updateNode:d,updateNodeData:(f,m,u={replace:!1})=>{d(f,p=>{const E=typeof m=="function"?m(p):m;return u.replace?{...p,data:E}:{...p,data:{...p.data,...E}}},u)},updateEdge:h,updateEdgeData:(f,m,u={replace:!1})=>{h(f,p=>{const E=typeof m=="function"?m(p):m;return u.replace?{...p,data:E}:{...p,data:{...p.data,...E}}},u)},getNodesBounds:f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState();return pc(f,{nodeLookup:m,nodeOrigin:u})},getHandleConnections:({type:f,id:m,nodeId:u})=>Array.from(n.getState().connectionLookup.get(`${u}-${f}${m?`-${m}`:""}`)?.values()??[]),getNodeConnections:({type:f,handleId:m,nodeId:u})=>Array.from(n.getState().connectionLookup.get(`${u}${f?m?`-${f}-${m}`:`-${f}`:""}`)?.values()??[]),fitView:async f=>{const m=n.getState().fitViewResolver??Nc();return n.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:m}),s.nodeQueue.push(u=>[...u]),m.promise}}},[]);return g.useMemo(()=>({...i,...e,viewportInitialized:r}),[r])}const xa=e=>e.selected,Xd=typeof window<"u"?window:void 0;function Ud({deleteKeyCode:e,multiSelectionKeyCode:n}){const s=ze(),{deleteElements:r}=no(),i=br(e,{actInsideInputWithModifier:!1}),o=br(n,{target:Xd});g.useEffect(()=>{if(i){const{edges:a,nodes:c}=s.getState();r({nodes:c.filter(xa),edges:a.filter(xa)}),s.setState({nodesSelectionActive:!1})}},[i]),g.useEffect(()=>{s.setState({multiSelectionActive:o})},[o])}function Qd(e){const n=ze();g.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=Xs(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 us={position:"absolute",width:"100%",height:"100%",top:0,left:0},Jd=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function eu({onPaneContextMenu:e,zoomOnScroll:n=!0,zoomOnPinch:s=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:o=En.Free,zoomOnDoubleClick:a=!0,panOnDrag:c=!0,defaultViewport:l,translateExtent:d,minZoom:h,maxZoom:f,zoomActivationKeyCode:m,preventScrolling:u=!0,children:p,noWheelClassName:E,noPanClassName:C,onViewportChange:y,isControlledViewport:v,paneClickDistance:x,selectionOnDrag:b}){const k=ze(),N=g.useRef(null),{userSelectionActive:I,lib:D,connectionInProgress:A}=Re(Jd,qe),L=br(m),M=g.useRef();Qd(N);const $=g.useCallback(z=>{y?.({x:z[0],y:z[1],zoom:z[2]}),v||k.setState({transform:z})},[y,v]);return g.useEffect(()=>{if(N.current){M.current=id({domNode:N.current,minZoom:h,maxZoom:f,translateExtent:d,viewport:l,onDraggingChange:_=>k.setState(T=>T.paneDragging===_?T:{paneDragging:_}),onPanZoomStart:(_,T)=>{const{onViewportChangeStart:R,onMoveStart:P}=k.getState();P?.(_,T),R?.(T)},onPanZoom:(_,T)=>{const{onViewportChange:R,onMove:P}=k.getState();P?.(_,T),R?.(T)},onPanZoomEnd:(_,T)=>{const{onViewportChangeEnd:R,onMoveEnd:P}=k.getState();P?.(_,T),R?.(T)}});const{x:z,y:j,zoom:O}=M.current.getViewport();return k.setState({panZoom:M.current,transform:[z,j,O],domNode:N.current.closest(".react-flow")}),()=>{M.current?.destroy()}}},[]),g.useEffect(()=>{M.current?.update({onPaneContextMenu:e,zoomOnScroll:n,zoomOnPinch:s,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:c,zoomActivationKeyPressed:L,preventScrolling:u,noPanClassName:C,userSelectionActive:I,noWheelClassName:E,lib:D,onTransformChange:$,connectionInProgress:A,selectionOnDrag:b,paneClickDistance:x})},[e,n,s,r,i,o,a,c,L,u,C,I,E,D,$,A,b,x]),t.jsx("div",{className:"react-flow__renderer",ref:N,style:us,children:p})}const tu=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function nu(){const{userSelectionActive:e,userSelectionRect:n}=Re(tu,qe);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 Ts=(e,n)=>s=>{s.target===n.current&&e?.(s)},ru=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function su({isSelecting:e,selectionKeyPressed:n,selectionMode:s=gr.Full,panOnDrag:r,paneClickDistance:i,selectionOnDrag:o,onSelectionStart:a,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:d,onPaneScroll:h,onPaneMouseEnter:f,onPaneMouseMove:m,onPaneMouseLeave:u,children:p}){const E=ze(),{userSelectionActive:C,elementsSelectable:y,dragging:v,connectionInProgress:x}=Re(ru,qe),b=y&&(e||C),k=g.useRef(null),N=g.useRef(),I=g.useRef(new Set),D=g.useRef(new Set),A=g.useRef(!1),L=R=>{if(A.current||x){A.current=!1;return}l?.(R),E.getState().resetSelectedElements(),E.setState({nodesSelectionActive:!1})},M=R=>{if(Array.isArray(r)&&r?.includes(2)){R.preventDefault();return}d?.(R)},$=h?R=>h(R):void 0,z=R=>{A.current&&(R.stopPropagation(),A.current=!1)},j=R=>{const{domNode:P}=E.getState();if(N.current=P?.getBoundingClientRect(),!N.current)return;const W=R.target===k.current;if(!W&&!!R.target.closest(".nokey")||!e||!(o&&W||n)||R.button!==0||!R.isPrimary)return;R.target?.setPointerCapture?.(R.pointerId),A.current=!1;const{x:Q,y:B}=Bt(R.nativeEvent,N.current);E.setState({userSelectionRect:{width:0,height:0,startX:Q,startY:B,x:Q,y:B}}),W||(R.stopPropagation(),R.preventDefault())},O=R=>{const{userSelectionRect:P,transform:W,nodeLookup:Y,edgeLookup:F,connectionLookup:Q,triggerNodeChanges:B,triggerEdgeChanges:S,defaultEdgeOptions:V,resetSelectedElements:q}=E.getState();if(!N.current||!P)return;const{x:H,y:Z}=Bt(R.nativeEvent,N.current),{startX:J,startY:le}=P;if(!A.current){const se=n?0:i;if(Math.hypot(H-J,Z-le)<=se)return;q(),a?.(R)}A.current=!0;const te={startX:J,startY:le,x:H<J?H:J,y:Z<le?Z:le,width:Math.abs(H-J),height:Math.abs(Z-le)},X=I.current,ie=D.current;I.current=new Set(Ks(Y,te,W,s===gr.Partial,!0).map(se=>se.id)),D.current=new Set;const de=V?.selectable??!0;for(const se of I.current){const ge=Q.get(se);if(ge)for(const{edgeId:ue}of ge.values()){const K=F.get(ue);K&&(K.selectable??de)&&D.current.add(ue)}}if(!Vo(X,I.current)){const se=Wn(Y,I.current,!0);B(se)}if(!Vo(ie,D.current)){const se=Wn(F,D.current);S(se)}E.setState({userSelectionRect:te,userSelectionActive:!0,nodesSelectionActive:!1})},_=R=>{R.button===0&&(R.target?.releasePointerCapture?.(R.pointerId),!C&&R.target===k.current&&E.getState().userSelectionRect&&L?.(R),E.setState({userSelectionActive:!1,userSelectionRect:null}),A.current&&(c?.(R),E.setState({nodesSelectionActive:I.current.size>0})))},T=r===!0||Array.isArray(r)&&r.includes(0);return t.jsxs("div",{className:Ke(["react-flow__pane",{draggable:T,dragging:v,selection:e}]),onClick:b?void 0:Ts(L,k),onContextMenu:Ts(M,k),onWheel:Ts($,k),onPointerEnter:b?void 0:f,onPointerMove:b?O:m,onPointerUp:b?_:void 0,onPointerDownCapture:b?j:void 0,onClickCapture:b?z:void 0,onPointerLeave:u,ref:k,style:us,children:[p,t.jsx(nu,{})]})}function qs({id:e,store:n,unselect:s=!1,nodeRef:r}){const{addSelectedNodes:i,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:c,onError:l}=n.getState(),d=c.get(e);if(!d){l?.("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 Yi({nodeRef:e,disabled:n=!1,noDragClassName:s,handleSelector:r,nodeId:i,isSelectable:o,nodeClickDistance:a}){const c=ze(),[l,d]=g.useState(!1),h=g.useRef();return g.useEffect(()=>{h.current=Gc({getStoreItems:()=>c.getState(),onNodeMouseDown:f=>{qs({id:f,store:c,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),g.useEffect(()=>{if(!(n||!e.current||!h.current))return h.current.update({noDragClassName:s,handleSelector:r,domNode:e.current,isSelectable:o,nodeId:i,nodeClickDistance:a}),()=>{h.current?.destroy()}},[s,r,n,o,e,i,a]),l}const ou=e=>n=>n.selected&&(n.draggable||e&&typeof n.draggable>"u");function Gi(){const e=ze();return g.useCallback(s=>{const{nodeExtent:r,snapToGrid:i,snapGrid:o,nodesDraggable:a,onError:c,updateNodePositions:l,nodeLookup:d,nodeOrigin:h}=e.getState(),f=new Map,m=ou(a),u=i?o[0]:5,p=i?o[1]:5,E=s.direction.x*u*s.factor,C=s.direction.y*p*s.factor;for(const[,y]of d){if(!m(y))continue;let v={x:y.internals.positionAbsolute.x+E,y:y.internals.positionAbsolute.y+C};i&&(v=jr(v,o));const{position:x,positionAbsolute:b}=fi({nodeId:y.id,nextPosition:v,nodeLookup:d,nodeExtent:r,nodeOrigin:h,onError:c});y.position=x,y.internals.positionAbsolute=b,f.set(y.id,y)}l(f)},[])}const ro=g.createContext(null),au=ro.Provider;ro.Consumer;const Ki=()=>g.useContext(ro),iu=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),lu=(e,n,s)=>r=>{const{connectionClickStartHandle:i,connectionMode:o,connection:a}=r,{fromHandle:c,toHandle:l,isValid:d}=a,h=l?.nodeId===e&&l?.id===n&&l?.type===s;return{connectingFrom:c?.nodeId===e&&c?.id===n&&c?.type===s,connectingTo:h,clickConnecting:i?.nodeId===e&&i?.id===n&&i?.type===s,isPossibleEndHandle:o===Yn.Strict?c?.type!==s:e!==c?.nodeId||n!==c?.id,connectionInProcess:!!c,clickConnectionInProcess:!!i,valid:h&&d}};function cu({type:e="source",position:n=be.Top,isValidConnection:s,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,id:a,onConnect:c,children:l,className:d,onMouseDown:h,onTouchStart:f,...m},u){const p=a||null,E=e==="target",C=ze(),y=Ki(),{connectOnClick:v,noPanClassName:x,rfId:b}=Re(iu,qe),{connectingFrom:k,connectingTo:N,clickConnecting:I,isPossibleEndHandle:D,connectionInProcess:A,clickConnectionInProcess:L,valid:M}=Re(lu(y,p,e),qe);y||C.getState().onError?.("010",Vt.error010());const $=O=>{const{defaultEdgeOptions:_,onConnect:T,hasDefaultEdges:R}=C.getState(),P={..._,...O};if(R){const{edges:W,setEdges:Y}=C.getState();Y(Rc(P,W))}T?.(P),c?.(P)},z=O=>{if(!y)return;const _=vi(O.nativeEvent);if(i&&(_&&O.button===0||!_)){const T=C.getState();Hs.onPointerDown(O.nativeEvent,{handleDomNode:O.currentTarget,autoPanOnConnect:T.autoPanOnConnect,connectionMode:T.connectionMode,connectionRadius:T.connectionRadius,domNode:T.domNode,nodeLookup:T.nodeLookup,lib:T.lib,isTarget:E,handleId:p,nodeId:y,flowId:T.rfId,panBy:T.panBy,cancelConnection:T.cancelConnection,onConnectStart:T.onConnectStart,onConnectEnd:(...R)=>C.getState().onConnectEnd?.(...R),updateConnection:T.updateConnection,onConnect:$,isValidConnection:s||((...R)=>C.getState().isValidConnection?.(...R)??!0),getTransform:()=>C.getState().transform,getFromHandle:()=>C.getState().connection.fromHandle,autoPanSpeed:T.autoPanSpeed,dragThreshold:T.connectionDragThreshold})}_?h?.(O):f?.(O)},j=O=>{const{onClickConnectStart:_,onClickConnectEnd:T,connectionClickStartHandle:R,connectionMode:P,isValidConnection:W,lib:Y,rfId:F,nodeLookup:Q,connection:B}=C.getState();if(!y||!R&&!i)return;if(!R){_?.(O.nativeEvent,{nodeId:y,handleId:p,handleType:e}),C.setState({connectionClickStartHandle:{nodeId:y,type:e,id:p}});return}const S=bi(O.target),V=s||W,{connection:q,isValid:H}=Hs.isValid(O.nativeEvent,{handle:{nodeId:y,id:p,type:e},connectionMode:P,fromNodeId:R.nodeId,fromHandleId:R.id||null,fromType:R.type,isValidConnection:V,flowId:F,doc:S,lib:Y,nodeLookup:Q});H&&q&&$(q);const Z=structuredClone(B);delete Z.inProgress,Z.toPosition=Z.toHandle?Z.toHandle.position:null,T?.(O,Z),C.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":p,"data-nodeid":y,"data-handlepos":n,"data-id":`${b}-${y}-${p}-${e}`,className:Ke(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",x,d,{source:!E,target:E,connectable:r,connectablestart:i,connectableend:o,clickconnecting:I,connectingfrom:k,connectingto:N,valid:M,connectionindicator:r&&(!A||D)&&(A||L?o:i)}]),onMouseDown:z,onTouchStart:z,onClick:v?j:void 0,ref:u,...m,children:l})}const fn=g.memo(Vi(cu));function du({data:e,isConnectable:n,sourcePosition:s=be.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(fn,{type:"source",position:s,isConnectable:n})]})}function uu({data:e,isConnectable:n,targetPosition:s=be.Top,sourcePosition:r=be.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 fu(){return null}function hu({data:e,isConnectable:n,targetPosition:s=be.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(fn,{type:"target",position:s,isConnectable:n}),e?.label]})}const ns={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},ba={input:du,default:uu,output:hu,group:fu};function mu(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 gu=e=>{const{width:n,height:s,x:r,y:i}=kr(e.nodeLookup,{filter:o=>!!o.selected});return{width:$t(n)?n:null,height:$t(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 pu({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:s}){const r=ze(),{width:i,height:o,transformString:a,userSelectionActive:c}=Re(gu,qe),l=Gi(),d=g.useRef(null);g.useEffect(()=>{s||d.current?.focus({preventScroll:!0})},[s]);const h=!c&&i!==null&&o!==null;if(Yi({nodeRef:d,disabled:!h}),!h)return null;const f=e?u=>{const p=r.getState().nodes.filter(E=>E.selected);e(u,p)}:void 0,m=u=>{Object.prototype.hasOwnProperty.call(ns,u.key)&&(u.preventDefault(),l({direction:ns[u.key],factor:u.shiftKey?4:1}))};return t.jsx("div",{className:Ke(["react-flow__nodesselection","react-flow__container",n]),style:{transform:a},children:t.jsx("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:s?void 0:-1,onKeyDown:s?void 0:m,style:{width:i,height:o}})})}const ya=typeof window<"u"?window:void 0,xu=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Zi({children:e,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,paneClickDistance:c,deleteKeyCode:l,selectionKeyCode:d,selectionOnDrag:h,selectionMode:f,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:p,panActivationKeyCode:E,zoomActivationKeyCode:C,elementsSelectable:y,zoomOnScroll:v,zoomOnPinch:x,panOnScroll:b,panOnScrollSpeed:k,panOnScrollMode:N,zoomOnDoubleClick:I,panOnDrag:D,defaultViewport:A,translateExtent:L,minZoom:M,maxZoom:$,preventScrolling:z,onSelectionContextMenu:j,noWheelClassName:O,noPanClassName:_,disableKeyboardA11y:T,onViewportChange:R,isControlledViewport:P}){const{nodesSelectionActive:W,userSelectionActive:Y}=Re(xu,qe),F=br(d,{target:ya}),Q=br(E,{target:ya}),B=Q||D,S=Q||b,V=h&&B!==!0,q=F||Y||V;return Ud({deleteKeyCode:l,multiSelectionKeyCode:p}),t.jsx(eu,{onPaneContextMenu:o,elementsSelectable:y,zoomOnScroll:v,zoomOnPinch:x,panOnScroll:S,panOnScrollSpeed:k,panOnScrollMode:N,zoomOnDoubleClick:I,panOnDrag:!F&&B,defaultViewport:A,translateExtent:L,minZoom:M,maxZoom:$,zoomActivationKeyCode:C,preventScrolling:z,noWheelClassName:O,noPanClassName:_,onViewportChange:R,isControlledViewport:P,paneClickDistance:c,selectionOnDrag:V,children:t.jsxs(su,{onSelectionStart:m,onSelectionEnd:u,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:B,isSelecting:!!q,selectionMode:f,selectionKeyPressed:F,paneClickDistance:c,selectionOnDrag:V,children:[e,W&&t.jsx(pu,{onSelectionContextMenu:j,noPanClassName:_,disableKeyboardA11y:T})]})})}Zi.displayName="FlowRenderer";const bu=g.memo(Zi),yu=e=>n=>e?Ks(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 vu(e){return Re(g.useCallback(yu(e),[e]),qe)}const wu=e=>e.updateNodeInternals;function ku(){const e=Re(wu),[n]=g.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 g.useEffect(()=>()=>{n?.disconnect()},[n]),n}function ju({node:e,nodeType:n,hasDimensions:s,resizeObserver:r}){const i=ze(),o=g.useRef(null),a=g.useRef(null),c=g.useRef(e.sourcePosition),l=g.useRef(e.targetPosition),d=g.useRef(n),h=s&&!!e.internals.handleBounds;return g.useEffect(()=>{o.current&&!e.hidden&&(!h||a.current!==o.current)&&(a.current&&r?.unobserve(a.current),r?.observe(o.current),a.current=o.current)},[h,e.hidden]),g.useEffect(()=>()=>{a.current&&(r?.unobserve(a.current),a.current=null)},[]),g.useEffect(()=>{if(o.current){const f=d.current!==n,m=c.current!==e.sourcePosition,u=l.current!==e.targetPosition;(f||m||u)&&(d.current=n,c.current=e.sourcePosition,l.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 Nu({id:e,onClick:n,onMouseEnter:s,onMouseMove:r,onMouseLeave:i,onContextMenu:o,onDoubleClick:a,nodesDraggable:c,elementsSelectable:l,nodesConnectable:d,nodesFocusable:h,resizeObserver:f,noDragClassName:m,noPanClassName:u,disableKeyboardA11y:p,rfId:E,nodeTypes:C,nodeClickDistance:y,onError:v}){const{node:x,internals:b,isParent:k}=Re(H=>{const Z=H.nodeLookup.get(e),J=H.parentLookup.has(e);return{node:Z,internals:Z.internals,isParent:J}},qe);let N=x.type||"default",I=C?.[N]||ba[N];I===void 0&&(v?.("003",Vt.error003(N)),N="default",I=C?.default||ba.default);const D=!!(x.draggable||c&&typeof x.draggable>"u"),A=!!(x.selectable||l&&typeof x.selectable>"u"),L=!!(x.connectable||d&&typeof x.connectable>"u"),M=!!(x.focusable||h&&typeof x.focusable>"u"),$=ze(),z=pi(x),j=ju({node:x,nodeType:N,hasDimensions:z,resizeObserver:f}),O=Yi({nodeRef:j,disabled:x.hidden||!D,noDragClassName:m,handleSelector:x.dragHandle,nodeId:e,isSelectable:A,nodeClickDistance:y}),_=Gi();if(x.hidden)return null;const T=Qt(x),R=mu(x),P=A||D||n||s||r||i,W=s?H=>s(H,{...b.userNode}):void 0,Y=r?H=>r(H,{...b.userNode}):void 0,F=i?H=>i(H,{...b.userNode}):void 0,Q=o?H=>o(H,{...b.userNode}):void 0,B=a?H=>a(H,{...b.userNode}):void 0,S=H=>{const{selectNodesOnDrag:Z,nodeDragThreshold:J}=$.getState();A&&(!Z||!D||J>0)&&qs({id:e,store:$,nodeRef:j}),n&&n(H,{...b.userNode})},V=H=>{if(!(yi(H.nativeEvent)||p)){if(ii.includes(H.key)&&A){const Z=H.key==="Escape";qs({id:e,store:$,unselect:Z,nodeRef:j})}else if(D&&x.selected&&Object.prototype.hasOwnProperty.call(ns,H.key)){H.preventDefault();const{ariaLabelConfig:Z}=$.getState();$.setState({ariaLiveMessage:Z["node.a11yDescription.ariaLiveMessage"]({direction:H.key.replace("Arrow","").toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),_({direction:ns[H.key],factor:H.shiftKey?4:1})}}},q=()=>{if(p||!j.current?.matches(":focus-visible"))return;const{transform:H,width:Z,height:J,autoPanOnNodeFocus:le,setCenter:te}=$.getState();if(!le)return;Ks(new Map([[e,x]]),{x:0,y:0,width:Z,height:J},H,!0).length>0||te(x.position.x+T.width/2,x.position.y+T.height/2,{zoom:H[2]})};return t.jsx("div",{className:Ke(["react-flow__node",`react-flow__node-${N}`,{[u]:D},x.className,{selected:x.selected,selectable:A,parent:k,draggable:D,dragging:O}]),ref:j,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:P?"all":"none",visibility:z?"visible":"hidden",...x.style,...R},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:W,onMouseMove:Y,onMouseLeave:F,onContextMenu:Q,onClick:S,onDoubleClick:B,onKeyDown:M?V:void 0,tabIndex:M?0:void 0,onFocus:M?q:void 0,role:x.ariaRole??(M?"group":void 0),"aria-roledescription":"node","aria-describedby":p?void 0:`${Bi}-${E}`,"aria-label":x.ariaLabel,...x.domAttributes,children:t.jsx(au,{value:e,children:t.jsx(I,{id:e,data:x.data,type:N,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:x.selected??!1,selectable:A,draggable:D,deletable:x.deletable??!0,isConnectable:L,sourcePosition:x.sourcePosition,targetPosition:x.targetPosition,dragging:O,dragHandle:x.dragHandle,zIndex:b.z,parentId:x.parentId,...T})})})}var Cu=g.memo(Nu);const Su=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Xi(e){const{nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,onError:o}=Re(Su,qe),a=vu(e.onlyRenderVisibleElements),c=ku();return t.jsx("div",{className:"react-flow__nodes",style:us,children:a.map(l=>t.jsx(Cu,{id:l,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:c,nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:o},l))})}Xi.displayName="NodeRenderer";const Eu=g.memo(Xi);function Mu(e){return Re(g.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&&Mc({sourceNode:o,targetNode:a,width:s.width,height:s.height,transform:s.transform})&&r.push(i.id)}return r},[e]),qe)}const Iu=({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"})},Tu=({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"})},va={[Gn.Arrow]:Iu,[Gn.ArrowClosed]:Tu};function Ru(e){const n=ze();return g.useMemo(()=>Object.prototype.hasOwnProperty.call(va,e)?va[e]:(n.getState().onError?.("009",Vt.error009(e)),null),[e])}const _u=({id:e,type:n,color:s,width:r=12.5,height:i=12.5,markerUnits:o="strokeWidth",strokeWidth:a,orient:c="auto-start-reverse"})=>{const l=Ru(n);return l?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:c,refX:"0",refY:"0",children:t.jsx(l,{color:s,strokeWidth:a})}):null},Ui=({defaultColor:e,rfId:n})=>{const s=Re(o=>o.edges),r=Re(o=>o.defaultEdgeOptions),i=g.useMemo(()=>Pc(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(_u,{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};Ui.displayName="MarkerDefinitions";var Lu=g.memo(Ui);function Qi({x:e,y:n,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:c=2,children:l,className:d,...h}){const[f,m]=g.useState({x:1,y:0,width:0,height:0}),u=Ke(["react-flow__edge-textwrapper",d]),p=g.useRef(null);return g.useEffect(()=>{if(p.current){const E=p.current.getBBox();m({x:E.x,y:E.y,width:E.width,height:E.height})}},[s]),s?t.jsxs("g",{transform:`translate(${e-f.width/2} ${n-f.height/2})`,className:u,visibility:f.width?"visible":"hidden",...h,children:[i&&t.jsx("rect",{width:f.width+2*a[0],x:-a[0],y:-a[1],height:f.height+2*a[1],className:"react-flow__edge-textbg",style:o,rx:c,ry:c}),t.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:p,style:r,children:s}),l]}):null}Qi.displayName="EdgeText";const Du=g.memo(Qi);function fs({path:e,labelX:n,labelY:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,interactionWidth:d=20,...h}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...h,d:e,fill:"none",className:Ke(["react-flow__edge-path",h.className])}),d?t.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:d,className:"react-flow__edge-interaction"}):null,r&&$t(n)&&$t(s)?t.jsx(Du,{x:n,y:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null]})}function wa({pos:e,x1:n,y1:s,x2:r,y2:i}){return e===be.Left||e===be.Right?[.5*(n+r),s]:[n,.5*(s+i)]}function Ji({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top}){const[a,c]=wa({pos:s,x1:e,y1:n,x2:r,y2:i}),[l,d]=wa({pos:o,x1:r,y1:i,x2:e,y2:n}),[h,f,m,u]=wi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:d});return[`M${e},${n} C${a},${c} ${l},${d} ${r},${i}`,h,f,m,u]}function el(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a,targetPosition:c,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:E,markerStart:C,interactionWidth:y})=>{const[v,x,b]=Ji({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:c}),k=e.isInternal?void 0:n;return t.jsx(fs,{id:k,path:v,labelX:x,labelY:b,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:E,markerStart:C,interactionWidth:y})})}const Au=el({isInternal:!1}),tl=el({isInternal:!0});Au.displayName="SimpleBezierEdge";tl.displayName="SimpleBezierEdgeInternal";function nl(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,sourcePosition:u=be.Bottom,targetPosition:p=be.Top,markerEnd:E,markerStart:C,pathOptions:y,interactionWidth:v})=>{const[x,b,k]=Bs({sourceX:s,sourceY:r,sourcePosition:u,targetX:i,targetY:o,targetPosition:p,borderRadius:y?.borderRadius,offset:y?.offset,stepPosition:y?.stepPosition}),N=e.isInternal?void 0:n;return t.jsx(fs,{id:N,path:x,labelX:b,labelY:k,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:E,markerStart:C,interactionWidth:v})})}const rl=nl({isInternal:!1}),sl=nl({isInternal:!0});rl.displayName="SmoothStepEdge";sl.displayName="SmoothStepEdgeInternal";function ol(e){return g.memo(({id:n,...s})=>{const r=e.isInternal?void 0:n;return t.jsx(rl,{...s,id:r,pathOptions:g.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const Pu=ol({isInternal:!1}),al=ol({isInternal:!0});Pu.displayName="StepEdge";al.displayName="StepEdgeInternal";function il(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:p,interactionWidth:E})=>{const[C,y,v]=Ni({sourceX:s,sourceY:r,targetX:i,targetY:o}),x=e.isInternal?void 0:n;return t.jsx(fs,{id:x,path:C,labelX:y,labelY:v,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:p,interactionWidth:E})})}const $u=il({isInternal:!1}),ll=il({isInternal:!0});$u.displayName="StraightEdge";ll.displayName="StraightEdgeInternal";function cl(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a=be.Bottom,targetPosition:c=be.Top,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:E,markerStart:C,pathOptions:y,interactionWidth:v})=>{const[x,b,k]=ki({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:c,curvature:y?.curvature}),N=e.isInternal?void 0:n;return t.jsx(fs,{id:N,path:x,labelX:b,labelY:k,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:E,markerStart:C,interactionWidth:v})})}const Bu=cl({isInternal:!1}),dl=cl({isInternal:!0});Bu.displayName="BezierEdge";dl.displayName="BezierEdgeInternal";const ka={default:dl,straight:ll,step:al,smoothstep:sl,simplebezier:tl},ja={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},Ou=(e,n,s)=>s===be.Left?e-n:s===be.Right?e+n:e,zu=(e,n,s)=>s===be.Top?e-n:s===be.Bottom?e+n:e,Na="react-flow__edgeupdater";function Ca({position:e,centerX:n,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:o,onMouseOut:a,type:c}){return t.jsx("circle",{onMouseDown:i,onMouseEnter:o,onMouseOut:a,className:Ke([Na,`${Na}-${c}`]),cx:Ou(n,r,e),cy:zu(s,r,e),r,stroke:"transparent",fill:"transparent"})}function Hu({isReconnectable:e,reconnectRadius:n,edge:s,sourceX:r,sourceY:i,targetX:o,targetY:a,sourcePosition:c,targetPosition:l,onReconnect:d,onReconnectStart:h,onReconnectEnd:f,setReconnecting:m,setUpdateHover:u}){const p=ze(),E=(b,k)=>{if(b.button!==0)return;const{autoPanOnConnect:N,domNode:I,connectionMode:D,connectionRadius:A,lib:L,onConnectStart:M,cancelConnection:$,nodeLookup:z,rfId:j,panBy:O,updateConnection:_}=p.getState(),T=k.type==="target",R=(Y,F)=>{m(!1),f?.(Y,s,k.type,F)},P=Y=>d?.(s,Y),W=(Y,F)=>{m(!0),h?.(b,s,k.type),M?.(Y,F)};Hs.onPointerDown(b.nativeEvent,{autoPanOnConnect:N,connectionMode:D,connectionRadius:A,domNode:I,handleId:k.id,nodeId:k.nodeId,nodeLookup:z,isTarget:T,edgeUpdaterType:k.type,lib:L,flowId:j,cancelConnection:$,panBy:O,isValidConnection:(...Y)=>p.getState().isValidConnection?.(...Y)??!0,onConnect:P,onConnectStart:W,onConnectEnd:(...Y)=>p.getState().onConnectEnd?.(...Y),onReconnectEnd:R,updateConnection:_,getTransform:()=>p.getState().transform,getFromHandle:()=>p.getState().connection.fromHandle,dragThreshold:p.getState().connectionDragThreshold,handleDomNode:b.currentTarget})},C=b=>E(b,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),y=b=>E(b,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),v=()=>u(!0),x=()=>u(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(Ca,{position:c,centerX:r,centerY:i,radius:n,onMouseDown:C,onMouseEnter:v,onMouseOut:x,type:"source"}),(e===!0||e==="target")&&t.jsx(Ca,{position:l,centerX:o,centerY:a,radius:n,onMouseDown:y,onMouseEnter:v,onMouseOut:x,type:"target"})]})}function qu({id:e,edgesFocusable:n,edgesReconnectable:s,elementsSelectable:r,onClick:i,onDoubleClick:o,onContextMenu:a,onMouseEnter:c,onMouseMove:l,onMouseLeave:d,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,rfId:p,edgeTypes:E,noPanClassName:C,onError:y,disableKeyboardA11y:v}){let x=Re(te=>te.edgeLookup.get(e));const b=Re(te=>te.defaultEdgeOptions);x=b?{...b,...x}:x;let k=x.type||"default",N=E?.[k]||ka[k];N===void 0&&(y?.("011",Vt.error011(k)),k="default",N=E?.default||ka.default);const I=!!(x.focusable||n&&typeof x.focusable>"u"),D=typeof f<"u"&&(x.reconnectable||s&&typeof x.reconnectable>"u"),A=!!(x.selectable||r&&typeof x.selectable>"u"),L=g.useRef(null),[M,$]=g.useState(!1),[z,j]=g.useState(!1),O=ze(),{zIndex:_,sourceX:T,sourceY:R,targetX:P,targetY:W,sourcePosition:Y,targetPosition:F}=Re(g.useCallback(te=>{const X=te.nodeLookup.get(x.source),ie=te.nodeLookup.get(x.target);if(!X||!ie)return{zIndex:x.zIndex,...ja};const de=Ac({id:e,sourceNode:X,targetNode:ie,sourceHandle:x.sourceHandle||null,targetHandle:x.targetHandle||null,connectionMode:te.connectionMode,onError:y});return{zIndex:Ec({selected:x.selected,zIndex:x.zIndex,sourceNode:X,targetNode:ie,elevateOnSelect:te.elevateEdgesOnSelect,zIndexMode:te.zIndexMode}),...de||ja}},[x.source,x.target,x.sourceHandle,x.targetHandle,x.selected,x.zIndex]),qe),Q=g.useMemo(()=>x.markerStart?`url('#${Os(x.markerStart,p)}')`:void 0,[x.markerStart,p]),B=g.useMemo(()=>x.markerEnd?`url('#${Os(x.markerEnd,p)}')`:void 0,[x.markerEnd,p]);if(x.hidden||T===null||R===null||P===null||W===null)return null;const S=te=>{const{addSelectedEdges:X,unselectNodesAndEdges:ie,multiSelectionActive:de}=O.getState();A&&(O.setState({nodesSelectionActive:!1}),x.selected&&de?(ie({nodes:[],edges:[x]}),L.current?.blur()):X([e])),i&&i(te,x)},V=o?te=>{o(te,{...x})}:void 0,q=a?te=>{a(te,{...x})}:void 0,H=c?te=>{c(te,{...x})}:void 0,Z=l?te=>{l(te,{...x})}:void 0,J=d?te=>{d(te,{...x})}:void 0,le=te=>{if(!v&&ii.includes(te.key)&&A){const{unselectNodesAndEdges:X,addSelectedEdges:ie}=O.getState();te.key==="Escape"?(L.current?.blur(),X({edges:[x]})):ie([e])}};return t.jsx("svg",{style:{zIndex:_},children:t.jsxs("g",{className:Ke(["react-flow__edge",`react-flow__edge-${k}`,x.className,C,{selected:x.selected,animated:x.animated,inactive:!A&&!i,updating:M,selectable:A}]),onClick:S,onDoubleClick:V,onContextMenu:q,onMouseEnter:H,onMouseMove:Z,onMouseLeave:J,onKeyDown:I?le:void 0,tabIndex:I?0:void 0,role:x.ariaRole??(I?"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":I?`${Oi}-${p}`:void 0,ref:L,...x.domAttributes,children:[!z&&t.jsx(N,{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:T,sourceY:R,targetX:P,targetY:W,sourcePosition:Y,targetPosition:F,data:x.data,style:x.style,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerStart:Q,markerEnd:B,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth}),D&&t.jsx(Hu,{edge:x,isReconnectable:D,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,sourceX:T,sourceY:R,targetX:P,targetY:W,sourcePosition:Y,targetPosition:F,setUpdateHover:$,setReconnecting:j})]})})}var Wu=g.memo(qu);const Vu=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function ul({defaultMarkerColor:e,onlyRenderVisibleElements:n,rfId:s,edgeTypes:r,noPanClassName:i,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:c,onEdgeMouseMove:l,onEdgeMouseLeave:d,onEdgeClick:h,reconnectRadius:f,onEdgeDoubleClick:m,onReconnectStart:u,onReconnectEnd:p,disableKeyboardA11y:E}){const{edgesFocusable:C,edgesReconnectable:y,elementsSelectable:v,onError:x}=Re(Vu,qe),b=Mu(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(Lu,{defaultColor:e,rfId:s}),b.map(k=>t.jsx(Wu,{id:k,edgesFocusable:C,edgesReconnectable:y,elementsSelectable:v,noPanClassName:i,onReconnect:o,onContextMenu:a,onMouseEnter:c,onMouseMove:l,onMouseLeave:d,onClick:h,reconnectRadius:f,onDoubleClick:m,onReconnectStart:u,onReconnectEnd:p,rfId:s,onError:x,edgeTypes:r,disableKeyboardA11y:E},k))]})}ul.displayName="EdgeRenderer";const Fu=g.memo(ul),Yu=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Gu({children:e}){const n=Re(Yu);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function Ku(e){const n=no(),s=g.useRef(!1);g.useEffect(()=>{!s.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),s.current=!0)},[e,n.viewportInitialized])}const Zu=e=>e.panZoom?.syncViewport;function Xu(e){const n=Re(Zu),s=ze();return g.useEffect(()=>{e&&(n?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,n]),null}function Uu(e){return e.connection.inProgress?{...e.connection,to:Nr(e.connection.to,e.transform)}:{...e.connection}}function Qu(e){return Uu}function Ju(e){const n=Qu();return Re(n,qe)}const ef=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function tf({containerStyle:e,style:n,type:s,component:r}){const{nodesConnectable:i,width:o,height:a,isValid:c,inProgress:l}=Re(ef,qe);return!(o&&i&&l)?null:t.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:Ke(["react-flow__connection",di(c)]),children:t.jsx(fl,{style:n,type:s,CustomComponent:r,isValid:c})})})}const fl=({style:e,type:n=dn.Bezier,CustomComponent:s,isValid:r})=>{const{inProgress:i,from:o,fromNode:a,fromHandle:c,fromPosition:l,to:d,toNode:h,toHandle:f,toPosition:m,pointer:u}=Ju();if(!i)return;if(s)return t.jsx(s,{connectionLineType:n,connectionLineStyle:e,fromNode:a,fromHandle:c,fromX:o.x,fromY:o.y,toX:d.x,toY:d.y,fromPosition:l,toPosition:m,connectionStatus:di(r),toNode:h,toHandle:f,pointer:u});let p="";const E={sourceX:o.x,sourceY:o.y,sourcePosition:l,targetX:d.x,targetY:d.y,targetPosition:m};switch(n){case dn.Bezier:[p]=ki(E);break;case dn.SimpleBezier:[p]=Ji(E);break;case dn.Step:[p]=Bs({...E,borderRadius:0});break;case dn.SmoothStep:[p]=Bs(E);break;default:[p]=Ni(E)}return t.jsx("path",{d:p,fill:"none",className:"react-flow__connection-path",style:e})};fl.displayName="ConnectionLine";const nf={};function Sa(e=nf){g.useRef(e),ze(),g.useEffect(()=>{},[e])}function rf(){ze(),g.useRef(!1),g.useEffect(()=>{},[])}function hl({nodeTypes:e,edgeTypes:n,onInit:s,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:c,onNodeMouseMove:l,onNodeMouseLeave:d,onNodeContextMenu:h,onSelectionContextMenu:f,onSelectionStart:m,onSelectionEnd:u,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:C,connectionLineContainerStyle:y,selectionKeyCode:v,selectionOnDrag:x,selectionMode:b,multiSelectionKeyCode:k,panActivationKeyCode:N,zoomActivationKeyCode:I,deleteKeyCode:D,onlyRenderVisibleElements:A,elementsSelectable:L,defaultViewport:M,translateExtent:$,minZoom:z,maxZoom:j,preventScrolling:O,defaultMarkerColor:_,zoomOnScroll:T,zoomOnPinch:R,panOnScroll:P,panOnScrollSpeed:W,panOnScrollMode:Y,zoomOnDoubleClick:F,panOnDrag:Q,onPaneClick:B,onPaneMouseEnter:S,onPaneMouseMove:V,onPaneMouseLeave:q,onPaneScroll:H,onPaneContextMenu:Z,paneClickDistance:J,nodeClickDistance:le,onEdgeContextMenu:te,onEdgeMouseEnter:X,onEdgeMouseMove:ie,onEdgeMouseLeave:de,reconnectRadius:se,onReconnect:ge,onReconnectStart:ue,onReconnectEnd:K,noDragClassName:ce,noWheelClassName:pe,noPanClassName:ve,disableKeyboardA11y:fe,nodeExtent:re,rfId:xe,viewport:Ee,onViewportChange:ye}){return Sa(e),Sa(n),rf(),Ku(s),Xu(Ee),t.jsx(bu,{onPaneClick:B,onPaneMouseEnter:S,onPaneMouseMove:V,onPaneMouseLeave:q,onPaneContextMenu:Z,onPaneScroll:H,paneClickDistance:J,deleteKeyCode:D,selectionKeyCode:v,selectionOnDrag:x,selectionMode:b,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:k,panActivationKeyCode:N,zoomActivationKeyCode:I,elementsSelectable:L,zoomOnScroll:T,zoomOnPinch:R,zoomOnDoubleClick:F,panOnScroll:P,panOnScrollSpeed:W,panOnScrollMode:Y,panOnDrag:Q,defaultViewport:M,translateExtent:$,minZoom:z,maxZoom:j,onSelectionContextMenu:f,preventScrolling:O,noDragClassName:ce,noWheelClassName:pe,noPanClassName:ve,disableKeyboardA11y:fe,onViewportChange:ye,isControlledViewport:!!Ee,children:t.jsxs(Gu,{children:[t.jsx(Fu,{edgeTypes:n,onEdgeClick:i,onEdgeDoubleClick:a,onReconnect:ge,onReconnectStart:ue,onReconnectEnd:K,onlyRenderVisibleElements:A,onEdgeContextMenu:te,onEdgeMouseEnter:X,onEdgeMouseMove:ie,onEdgeMouseLeave:de,reconnectRadius:se,defaultMarkerColor:_,noPanClassName:ve,disableKeyboardA11y:fe,rfId:xe}),t.jsx(tf,{style:E,type:p,component:C,containerStyle:y}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(Eu,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:c,onNodeMouseMove:l,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:le,onlyRenderVisibleElements:A,noPanClassName:ve,noDragClassName:ce,disableKeyboardA11y:fe,nodeExtent:re,rfId:xe}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}hl.displayName="GraphView";const sf=g.memo(hl),Ea=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l=.5,maxZoom:d=2,nodeOrigin:h,nodeExtent:f,zIndexMode:m="basic"}={})=>{const u=new Map,p=new Map,E=new Map,C=new Map,y=r??n??[],v=s??e??[],x=h??[0,0],b=f??mr;Ei(E,C,y);const k=zs(v,u,p,{nodeOrigin:x,nodeExtent:b,zIndexMode:m});let N=[0,0,1];if(a&&i&&o){const I=kr(u,{filter:M=>!!((M.width||M.initialWidth)&&(M.height||M.initialHeight))}),{x:D,y:A,zoom:L}=Zs(I,i,o,l,d,c?.padding??.1);N=[D,A,L]}return{rfId:"1",width:i??0,height:o??0,transform:N,nodes:v,nodesInitialized:k,nodeLookup:u,parentLookup:p,edges:y,edgeLookup:C,connectionLookup:E,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:l,maxZoom:d,translateExtent:mr,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Yn.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:c,fitViewResolver:null,connection:{...ci},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:wc,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:li,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},of=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m})=>jd((u,p)=>{async function E(){const{nodeLookup:C,panZoom:y,fitViewOptions:v,fitViewResolver:x,width:b,height:k,minZoom:N,maxZoom:I}=p();y&&(await yc({nodes:C,width:b,height:k,panZoom:y,minZoom:N,maxZoom:I},v),x?.resolve(!0),u({fitViewResolver:null}))}return{...Ea({nodes:e,edges:n,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:d,nodeOrigin:h,nodeExtent:f,defaultNodes:s,defaultEdges:r,zIndexMode:m}),setNodes:C=>{const{nodeLookup:y,parentLookup:v,nodeOrigin:x,elevateNodesOnSelect:b,fitViewQueued:k,zIndexMode:N}=p(),I=zs(C,y,v,{nodeOrigin:x,nodeExtent:f,elevateNodesOnSelect:b,checkEquality:!0,zIndexMode:N});k&&I?(E(),u({nodes:C,nodesInitialized:I,fitViewQueued:!1,fitViewOptions:void 0})):u({nodes:C,nodesInitialized:I})},setEdges:C=>{const{connectionLookup:y,edgeLookup:v}=p();Ei(y,v,C),u({edges:C})},setDefaultNodesAndEdges:(C,y)=>{if(C){const{setNodes:v}=p();v(C),u({hasDefaultNodes:!0})}if(y){const{setEdges:v}=p();v(y),u({hasDefaultEdges:!0})}},updateNodeInternals:C=>{const{triggerNodeChanges:y,nodeLookup:v,parentLookup:x,domNode:b,nodeOrigin:k,nodeExtent:N,debug:I,fitViewQueued:D,zIndexMode:A}=p(),{changes:L,updatedInternals:M}=Wc(C,v,x,b,k,N,A);M&&(Oc(v,x,{nodeOrigin:k,nodeExtent:N,zIndexMode:A}),D?(E(),u({fitViewQueued:!1,fitViewOptions:void 0})):u({}),L?.length>0&&(I&&console.log("React Flow: trigger node changes",L),y?.(L)))},updateNodePositions:(C,y=!1)=>{const v=[];let x=[];const{nodeLookup:b,triggerNodeChanges:k,connection:N,updateConnection:I,onNodesChangeMiddlewareMap:D}=p();for(const[A,L]of C){const M=b.get(A),$=!!(M?.expandParent&&M?.parentId&&L?.position),z={id:A,type:"position",position:$?{x:Math.max(0,L.position.x),y:Math.max(0,L.position.y)}:L.position,dragging:y};if(M&&N.inProgress&&N.fromNode.id===M.id){const j=In(M,N.fromHandle,be.Left,!0);I({...N,from:j})}$&&M.parentId&&v.push({id:A,parentId:M.parentId,rect:{...L.internals.positionAbsolute,width:L.measured.width??0,height:L.measured.height??0}}),x.push(z)}if(v.length>0){const{parentLookup:A,nodeOrigin:L}=p(),M=to(v,b,A,L);x.push(...M)}for(const A of D.values())x=A(x);k(x)},triggerNodeChanges:C=>{const{onNodesChange:y,setNodes:v,nodes:x,hasDefaultNodes:b,debug:k}=p();if(C?.length){if(b){const N=qi(C,x);v(N)}k&&console.log("React Flow: trigger node changes",C),y?.(C)}},triggerEdgeChanges:C=>{const{onEdgesChange:y,setEdges:v,edges:x,hasDefaultEdges:b,debug:k}=p();if(C?.length){if(b){const N=Wi(C,x);v(N)}k&&console.log("React Flow: trigger edge changes",C),y?.(C)}},addSelectedNodes:C=>{const{multiSelectionActive:y,edgeLookup:v,nodeLookup:x,triggerNodeChanges:b,triggerEdgeChanges:k}=p();if(y){const N=C.map(I=>Sn(I,!0));b(N);return}b(Wn(x,new Set([...C]),!0)),k(Wn(v))},addSelectedEdges:C=>{const{multiSelectionActive:y,edgeLookup:v,nodeLookup:x,triggerNodeChanges:b,triggerEdgeChanges:k}=p();if(y){const N=C.map(I=>Sn(I,!0));k(N);return}k(Wn(v,new Set([...C]))),b(Wn(x,new Set,!0))},unselectNodesAndEdges:({nodes:C,edges:y}={})=>{const{edges:v,nodes:x,nodeLookup:b,triggerNodeChanges:k,triggerEdgeChanges:N}=p(),I=C||x,D=y||v,A=[];for(const M of I){if(!M.selected)continue;const $=b.get(M.id);$&&($.selected=!1),A.push(Sn(M.id,!1))}const L=[];for(const M of D)M.selected&&L.push(Sn(M.id,!1));k(A),N(L)},setMinZoom:C=>{const{panZoom:y,maxZoom:v}=p();y?.setScaleExtent([C,v]),u({minZoom:C})},setMaxZoom:C=>{const{panZoom:y,minZoom:v}=p();y?.setScaleExtent([v,C]),u({maxZoom:C})},setTranslateExtent:C=>{p().panZoom?.setTranslateExtent(C),u({translateExtent:C})},resetSelectedElements:()=>{const{edges:C,nodes:y,triggerNodeChanges:v,triggerEdgeChanges:x,elementsSelectable:b}=p();if(!b)return;const k=y.reduce((I,D)=>D.selected?[...I,Sn(D.id,!1)]:I,[]),N=C.reduce((I,D)=>D.selected?[...I,Sn(D.id,!1)]:I,[]);v(k),x(N)},setNodeExtent:C=>{const{nodes:y,nodeLookup:v,parentLookup:x,nodeOrigin:b,elevateNodesOnSelect:k,nodeExtent:N,zIndexMode:I}=p();C[0][0]===N[0][0]&&C[0][1]===N[0][1]&&C[1][0]===N[1][0]&&C[1][1]===N[1][1]||(zs(y,v,x,{nodeOrigin:b,nodeExtent:C,elevateNodesOnSelect:k,checkEquality:!1,zIndexMode:I}),u({nodeExtent:C}))},panBy:C=>{const{transform:y,width:v,height:x,panZoom:b,translateExtent:k}=p();return Vc({delta:C,panZoom:b,transform:y,translateExtent:k,width:v,height:x})},setCenter:async(C,y,v)=>{const{width:x,height:b,maxZoom:k,panZoom:N}=p();if(!N)return Promise.resolve(!1);const I=typeof v?.zoom<"u"?v.zoom:k;return await N.setViewport({x:x/2-C*I,y:b/2-y*I,zoom:I},{duration:v?.duration,ease:v?.ease,interpolate:v?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{u({connection:{...ci}})},updateConnection:C=>{u({connection:C})},reset:()=>u({...Ea()})}},Object.is);function af({initialNodes:e,initialEdges:n,defaultNodes:s,defaultEdges:r,initialWidth:i,initialHeight:o,initialMinZoom:a,initialMaxZoom:c,initialFitViewOptions:l,fitView:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m,children:u}){const[p]=g.useState(()=>of({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:d,minZoom:a,maxZoom:c,fitViewOptions:l,nodeOrigin:h,nodeExtent:f,zIndexMode:m}));return t.jsx(Nd,{value:p,children:t.jsx(Gd,{children:u})})}function lf({children:e,nodes:n,edges:s,defaultNodes:r,defaultEdges:i,width:o,height:a,fitView:c,fitViewOptions:l,minZoom:d,maxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u}){return g.useContext(cs)?t.jsx(t.Fragment,{children:e}):t.jsx(af,{initialNodes:n,initialEdges:s,defaultNodes:r,defaultEdges:i,initialWidth:o,initialHeight:a,fitView:c,initialFitViewOptions:l,initialMinZoom:d,initialMaxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u,children:e})}const cf={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function df({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,className:i,nodeTypes:o,edgeTypes:a,onNodeClick:c,onEdgeClick:l,onInit:d,onMove:h,onMoveStart:f,onMoveEnd:m,onConnect:u,onConnectStart:p,onConnectEnd:E,onClickConnectStart:C,onClickConnectEnd:y,onNodeMouseEnter:v,onNodeMouseMove:x,onNodeMouseLeave:b,onNodeContextMenu:k,onNodeDoubleClick:N,onNodeDragStart:I,onNodeDrag:D,onNodeDragStop:A,onNodesDelete:L,onEdgesDelete:M,onDelete:$,onSelectionChange:z,onSelectionDragStart:j,onSelectionDrag:O,onSelectionDragStop:_,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:P,onBeforeDelete:W,connectionMode:Y,connectionLineType:F=dn.Bezier,connectionLineStyle:Q,connectionLineComponent:B,connectionLineContainerStyle:S,deleteKeyCode:V="Backspace",selectionKeyCode:q="Shift",selectionOnDrag:H=!1,selectionMode:Z=gr.Full,panActivationKeyCode:J="Space",multiSelectionKeyCode:le=xr()?"Meta":"Control",zoomActivationKeyCode:te=xr()?"Meta":"Control",snapToGrid:X,snapGrid:ie,onlyRenderVisibleElements:de=!1,selectNodesOnDrag:se,nodesDraggable:ge,autoPanOnNodeFocus:ue,nodesConnectable:K,nodesFocusable:ce,nodeOrigin:pe=zi,edgesFocusable:ve,edgesReconnectable:fe,elementsSelectable:re=!0,defaultViewport:xe=$d,minZoom:Ee=.5,maxZoom:ye=2,translateExtent:Le=mr,preventScrolling:gt=!0,nodeExtent:ct,defaultMarkerColor:Nt="#b1b1b7",zoomOnScroll:pt=!0,zoomOnPinch:tt=!0,panOnScroll:Ht=!1,panOnScrollSpeed:dt=.5,panOnScrollMode:Jt=En.Free,zoomOnDoubleClick:xt=!0,panOnDrag:nt=!0,onPaneClick:qt,onPaneMouseEnter:at,onPaneMouseMove:Fe,onPaneMouseLeave:$e,onPaneScroll:Ct,onPaneContextMenu:we,paneClickDistance:Qe=1,nodeClickDistance:it=0,children:bt,onReconnect:Je,onReconnectStart:St,onReconnectEnd:Ft,onEdgeContextMenu:Ne,onEdgeDoubleClick:Ce,onEdgeMouseEnter:De,onEdgeMouseMove:Ae,onEdgeMouseLeave:He,reconnectRadius:Et=10,onNodesChange:Ye,onEdgesChange:Wt,noDragClassName:Ue="nodrag",noWheelClassName:en="nowheel",noPanClassName:hn="nopan",fitView:Mt,fitViewOptions:yt,connectOnClick:Xe,attributionPosition:ut,proOptions:mn,defaultEdgeOptions:tn,elevateNodesOnSelect:rt=!0,elevateEdgesOnSelect:vt=!1,disableKeyboardA11y:It=!1,autoPanOnConnect:Tt,autoPanOnNodeDrag:G,autoPanSpeed:he,connectionRadius:Ie,isValidConnection:Me,onError:Te,style:st,id:ft,nodeDragThreshold:nn,connectionDragThreshold:rn,viewport:Jn,onViewportChange:gn,width:pn,height:xn,colorMode:Tn="light",debug:bn,onScroll:er,ariaLabelConfig:hs,zIndexMode:yn="basic",...Cr},sn){const Rt=ft||"1",Sr=Hd(Tn),Er=g.useCallback(tr=>{tr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),er?.(tr)},[er]);return t.jsx("div",{"data-testid":"rf__wrapper",...Cr,onScroll:Er,style:{...st,...cf},ref:sn,className:Ke(["react-flow",i,Sr]),id:ft,role:"application",children:t.jsxs(lf,{nodes:e,edges:n,width:pn,height:xn,fitView:Mt,fitViewOptions:yt,minZoom:Ee,maxZoom:ye,nodeOrigin:pe,nodeExtent:ct,zIndexMode:yn,children:[t.jsx(sf,{onInit:d,onNodeClick:c,onEdgeClick:l,onNodeMouseEnter:v,onNodeMouseMove:x,onNodeMouseLeave:b,onNodeContextMenu:k,onNodeDoubleClick:N,nodeTypes:o,edgeTypes:a,connectionLineType:F,connectionLineStyle:Q,connectionLineComponent:B,connectionLineContainerStyle:S,selectionKeyCode:q,selectionOnDrag:H,selectionMode:Z,deleteKeyCode:V,multiSelectionKeyCode:le,panActivationKeyCode:J,zoomActivationKeyCode:te,onlyRenderVisibleElements:de,defaultViewport:xe,translateExtent:Le,minZoom:Ee,maxZoom:ye,preventScrolling:gt,zoomOnScroll:pt,zoomOnPinch:tt,zoomOnDoubleClick:xt,panOnScroll:Ht,panOnScrollSpeed:dt,panOnScrollMode:Jt,panOnDrag:nt,onPaneClick:qt,onPaneMouseEnter:at,onPaneMouseMove:Fe,onPaneMouseLeave:$e,onPaneScroll:Ct,onPaneContextMenu:we,paneClickDistance:Qe,nodeClickDistance:it,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:P,onReconnect:Je,onReconnectStart:St,onReconnectEnd:Ft,onEdgeContextMenu:Ne,onEdgeDoubleClick:Ce,onEdgeMouseEnter:De,onEdgeMouseMove:Ae,onEdgeMouseLeave:He,reconnectRadius:Et,defaultMarkerColor:Nt,noDragClassName:Ue,noWheelClassName:en,noPanClassName:hn,rfId:Rt,disableKeyboardA11y:It,nodeExtent:ct,viewport:Jn,onViewportChange:gn}),t.jsx(zd,{nodes:e,edges:n,defaultNodes:s,defaultEdges:r,onConnect:u,onConnectStart:p,onConnectEnd:E,onClickConnectStart:C,onClickConnectEnd:y,nodesDraggable:ge,autoPanOnNodeFocus:ue,nodesConnectable:K,nodesFocusable:ce,edgesFocusable:ve,edgesReconnectable:fe,elementsSelectable:re,elevateNodesOnSelect:rt,elevateEdgesOnSelect:vt,minZoom:Ee,maxZoom:ye,nodeExtent:ct,onNodesChange:Ye,onEdgesChange:Wt,snapToGrid:X,snapGrid:ie,connectionMode:Y,translateExtent:Le,connectOnClick:Xe,defaultEdgeOptions:tn,fitView:Mt,fitViewOptions:yt,onNodesDelete:L,onEdgesDelete:M,onDelete:$,onNodeDragStart:I,onNodeDrag:D,onNodeDragStop:A,onSelectionDrag:O,onSelectionDragStart:j,onSelectionDragStop:_,onMove:h,onMoveStart:f,onMoveEnd:m,noPanClassName:hn,nodeOrigin:pe,rfId:Rt,autoPanOnConnect:Tt,autoPanOnNodeDrag:G,autoPanSpeed:he,onError:Te,connectionRadius:Ie,isValidConnection:Me,selectNodesOnDrag:se,nodeDragThreshold:nn,connectionDragThreshold:rn,onBeforeDelete:W,debug:bn,ariaLabelConfig:hs,zIndexMode:yn}),t.jsx(Pd,{onSelectionChange:z}),bt,t.jsx(Rd,{proOptions:mn,position:ut}),t.jsx(Td,{rfId:Rt,disableKeyboardA11y:It})]})})}var uf=Vi(df);function ff(){const e=ze();return g.useCallback(n=>{const{domNode:s,updateNodeInternals:r}=e.getState(),i=Array.isArray(n)?n:[n],o=new Map;i.forEach(a=>{const c=s?.querySelector(`.react-flow__node[data-id="${a}"]`);c&&o.set(a,{id:a,nodeElement:c,force:!0})}),requestAnimationFrame(()=>r(o,{triggerFitView:!1}))},[])}function hf(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>qi(i,o)),[]);return[n,s,r]}function mf(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>Wi(i,o)),[]);return[n,s,r]}function gf({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:Ke(["react-flow__background-pattern",s,r])})}function pf({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Ke(["react-flow__background-pattern","dots",n])})}var un;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(un||(un={}));const xf={[un.Dots]:1,[un.Lines]:1,[un.Cross]:6},bf=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function ml({id:e,variant:n=un.Dots,gap:s=20,size:r,lineWidth:i=1,offset:o=0,color:a,bgColor:c,style:l,className:d,patternClassName:h}){const f=g.useRef(null),{transform:m,patternId:u}=Re(bf,qe),p=r||xf[n],E=n===un.Dots,C=n===un.Cross,y=Array.isArray(s)?s:[s,s],v=[y[0]*m[2]||1,y[1]*m[2]||1],x=p*m[2],b=Array.isArray(o)?o:[o,o],k=C?[x,x]:v,N=[b[0]*m[2]||1+k[0]/2,b[1]*m[2]||1+k[1]/2],I=`${u}${e||""}`;return t.jsxs("svg",{className:Ke(["react-flow__background",d]),style:{...l,...us,"--xy-background-color-props":c,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[t.jsx("pattern",{id:I,x:m[0]%v[0],y:m[1]%v[1],width:v[0],height:v[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${N[0]},-${N[1]})`,children:E?t.jsx(pf,{radius:x/2,className:h}):t.jsx(gf,{dimensions:k,lineWidth:i,variant:n,className:h})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${I})`})]})}ml.displayName="Background";const yf=g.memo(ml);function vf(){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 wf(){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 kf(){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 jf(){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 Nf(){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 Fr({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:Ke(["react-flow__controls-button",n]),...s,children:e})}const Cf=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function gl({style:e,showZoom:n=!0,showFitView:s=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:o,onZoomOut:a,onFitView:c,onInteractiveChange:l,className:d,children:h,position:f="bottom-left",orientation:m="vertical","aria-label":u}){const p=ze(),{isInteractive:E,minZoomReached:C,maxZoomReached:y,ariaLabelConfig:v}=Re(Cf,qe),{zoomIn:x,zoomOut:b,fitView:k}=no(),N=()=>{x(),o?.()},I=()=>{b(),a?.()},D=()=>{k(i),c?.()},A=()=>{p.setState({nodesDraggable:!E,nodesConnectable:!E,elementsSelectable:!E}),l?.(!E)},L=m==="horizontal"?"horizontal":"vertical";return t.jsxs(ds,{className:Ke(["react-flow__controls",L,d]),position:f,style:e,"data-testid":"rf__controls","aria-label":u??v["controls.ariaLabel"],children:[n&&t.jsxs(t.Fragment,{children:[t.jsx(Fr,{onClick:N,className:"react-flow__controls-zoomin",title:v["controls.zoomIn.ariaLabel"],"aria-label":v["controls.zoomIn.ariaLabel"],disabled:y,children:t.jsx(vf,{})}),t.jsx(Fr,{onClick:I,className:"react-flow__controls-zoomout",title:v["controls.zoomOut.ariaLabel"],"aria-label":v["controls.zoomOut.ariaLabel"],disabled:C,children:t.jsx(wf,{})})]}),s&&t.jsx(Fr,{className:"react-flow__controls-fitview",onClick:D,title:v["controls.fitView.ariaLabel"],"aria-label":v["controls.fitView.ariaLabel"],children:t.jsx(kf,{})}),r&&t.jsx(Fr,{className:"react-flow__controls-interactive",onClick:A,title:v["controls.interactive.ariaLabel"],"aria-label":v["controls.interactive.ariaLabel"],children:E?t.jsx(Nf,{}):t.jsx(jf,{})}),h]})}gl.displayName="Controls";const Sf=g.memo(gl);function Ef({id:e,x:n,y:s,width:r,height:i,style:o,color:a,strokeColor:c,strokeWidth:l,className:d,borderRadius:h,shapeRendering:f,selected:m,onClick:u}){const{background:p,backgroundColor:E}=o||{},C=a||p||E;return t.jsx("rect",{className:Ke(["react-flow__minimap-node",{selected:m},d]),x:n,y:s,rx:h,ry:h,width:r,height:i,style:{fill:C,stroke:c,strokeWidth:l},shapeRendering:f,onClick:u?y=>u(y,e):void 0})}const Mf=g.memo(Ef),If=e=>e.nodes.map(n=>n.id),Rs=e=>e instanceof Function?e:()=>e;function Tf({nodeStrokeColor:e,nodeColor:n,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:o=Mf,onClick:a}){const c=Re(If,qe),l=Rs(n),d=Rs(e),h=Rs(s),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:c.map(m=>t.jsx(_f,{id:m,nodeColorFunc:l,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:o,onClick:a,shapeRendering:f},m))})}function Rf({id:e,nodeColorFunc:n,nodeStrokeColorFunc:s,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:o,shapeRendering:a,NodeComponent:c,onClick:l}){const{node:d,x:h,y:f,width:m,height:u}=Re(p=>{const E=p.nodeLookup.get(e);if(!E)return{node:void 0,x:0,y:0,width:0,height:0};const C=E.internals.userNode,{x:y,y:v}=E.internals.positionAbsolute,{width:x,height:b}=Qt(C);return{node:C,x:y,y:v,width:x,height:b}},qe);return!d||d.hidden||!pi(d)?null:t.jsx(c,{x:h,y:f,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:l,id:d.id})}const _f=g.memo(Rf);var Lf=g.memo(Tf);const Df=200,Af=150,Pf=e=>!e.hidden,$f=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?gi(kr(e.nodeLookup,{filter:Pf}),n):n,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Bf="react-flow__minimap-desc";function pl({style:e,className:n,nodeStrokeColor:s,nodeColor:r,nodeClassName:i="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:c,bgColor:l,maskColor:d,maskStrokeColor:h,maskStrokeWidth:f,position:m="bottom-right",onClick:u,onNodeClick:p,pannable:E=!1,zoomable:C=!1,ariaLabel:y,inversePan:v,zoomStep:x=1,offsetScale:b=5}){const k=ze(),N=g.useRef(null),{boundingRect:I,viewBB:D,rfId:A,panZoom:L,translateExtent:M,flowWidth:$,flowHeight:z,ariaLabelConfig:j}=Re($f,qe),O=e?.width??Df,_=e?.height??Af,T=I.width/O,R=I.height/_,P=Math.max(T,R),W=P*O,Y=P*_,F=b*P,Q=I.x-(W-I.width)/2-F,B=I.y-(Y-I.height)/2-F,S=W+F*2,V=Y+F*2,q=`${Bf}-${A}`,H=g.useRef(0),Z=g.useRef();H.current=P,g.useEffect(()=>{if(N.current&&L)return Z.current=Jc({domNode:N.current,panZoom:L,getTransform:()=>k.getState().transform,getViewScale:()=>H.current}),()=>{Z.current?.destroy()}},[L]),g.useEffect(()=>{Z.current?.update({translateExtent:M,width:$,height:z,inversePan:v,pannable:E,zoomStep:x,zoomable:C})},[E,C,v,x,M,$,z]);const J=u?X=>{const[ie,de]=Z.current?.pointer(X)||[0,0];u(X,{x:ie,y:de})}:void 0,le=p?g.useCallback((X,ie)=>{const de=k.getState().nodeLookup.get(ie).internals.userNode;p(X,de)},[]):void 0,te=y??j["minimap.ariaLabel"];return t.jsx(ds,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*P: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:Ke(["react-flow__minimap",n]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:O,height:_,viewBox:`${Q} ${B} ${S} ${V}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":q,ref:N,onClick:J,children:[te&&t.jsx("title",{id:q,children:te}),t.jsx(Lf,{onClick:le,nodeColor:r,nodeStrokeColor:s,nodeBorderRadius:o,nodeClassName:i,nodeStrokeWidth:a,nodeComponent:c}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${Q-F},${B-F}h${S+F*2}v${V+F*2}h${-S-F*2}z
|
|
7
|
-
M${D.x},${D.y}h${D.width}v${D.height}h${-D.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}pl.displayName="MiniMap";const Of=g.memo(pl),zf=e=>n=>e?`${Math.max(1/n.transform[2],1)}`:void 0,Hf={[Un.Line]:"right",[Un.Handle]:"bottom-right"};function qf({nodeId:e,position:n,variant:s=Un.Handle,className:r,style:i=void 0,children:o,color:a,minWidth:c=10,minHeight:l=10,maxWidth:d=Number.MAX_VALUE,maxHeight:h=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:m,autoScale:u=!0,shouldResize:p,onResizeStart:E,onResize:C,onResizeEnd:y}){const v=Ki(),x=typeof e=="string"?e:v,b=ze(),k=g.useRef(null),N=s===Un.Handle,I=Re(g.useCallback(zf(N&&u),[N,u]),qe),D=g.useRef(null),A=n??Hf[s];g.useEffect(()=>{if(!(!k.current||!x))return D.current||(D.current=hd({domNode:k.current,nodeId:x,getStoreItems:()=>{const{nodeLookup:M,transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:O,domNode:_}=b.getState();return{nodeLookup:M,transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:O,paneDomNode:_}},onChange:(M,$)=>{const{triggerNodeChanges:z,nodeLookup:j,parentLookup:O,nodeOrigin:_}=b.getState(),T=[],R={x:M.x,y:M.y},P=j.get(x);if(P&&P.expandParent&&P.parentId){const W=P.origin??_,Y=M.width??P.measured.width??0,F=M.height??P.measured.height??0,Q={id:P.id,parentId:P.parentId,rect:{width:Y,height:F,...xi({x:M.x??P.position.x,y:M.y??P.position.y},{width:Y,height:F},P.parentId,j,W)}},B=to([Q],j,O,_);T.push(...B),R.x=M.x?Math.max(W[0]*Y,M.x):void 0,R.y=M.y?Math.max(W[1]*F,M.y):void 0}if(R.x!==void 0&&R.y!==void 0){const W={id:x,type:"position",position:{...R}};T.push(W)}if(M.width!==void 0&&M.height!==void 0){const Y={id:x,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:M.width,height:M.height}};T.push(Y)}for(const W of $){const Y={...W,type:"position"};T.push(Y)}z(T)},onEnd:({width:M,height:$})=>{const z={id:x,type:"dimensions",resizing:!1,dimensions:{width:M,height:$}};b.getState().triggerNodeChanges([z])}})),D.current.update({controlPosition:A,boundaries:{minWidth:c,minHeight:l,maxWidth:d,maxHeight:h},keepAspectRatio:f,resizeDirection:m,onResizeStart:E,onResize:C,onResizeEnd:y,shouldResize:p}),()=>{D.current?.destroy()}},[A,c,l,d,h,f,E,C,y,p]);const L=A.split("-");return t.jsx("div",{className:Ke(["react-flow__resize-control","nodrag",...L,s,r]),ref:k,style:{...i,scale:I,...a&&{[N?"backgroundColor":"borderColor"]:a}},children:o})}g.memo(qf);var Pe=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),zt=Pe((e,n)=>{var s=Object.defineProperty,r=(z,j,O)=>j in z?s(z,j,{enumerable:!0,configurable:!0,writable:!0,value:O}):z[j]=O,i=(z,j)=>()=>(j||z((j={exports:{}}).exports,j),j.exports),o=(z,j,O)=>r(z,typeof j!="symbol"?j+"":j,O),a=i((z,j)=>{var O="\0",_="\0",T="",R=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(S=>Object.keys(B._in[S]).length===0)}sinks(){var B=this;return this.nodes().filter(S=>Object.keys(B._out[S]).length===0)}setNodes(B,S){var V=arguments,q=this;return B.forEach(function(H){V.length>1?q.setNode(H,S):q.setNode(H)}),this}setNode(B,S){return Object.hasOwn(this._nodes,B)?(arguments.length>1&&(this._nodes[B]=S),this):(this._nodes[B]=arguments.length>1?S: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 S=this;if(Object.hasOwn(this._nodes,B)){var V=q=>S.removeEdge(S._edgeObjs[q]);delete this._nodes[B],this._isCompound&&(this._removeFromParentsChildList(B),delete this._parent[B],this.children(B).forEach(function(q){S.setParent(q)}),delete this._children[B]),Object.keys(this._in[B]).forEach(V),delete this._in[B],delete this._preds[B],Object.keys(this._out[B]).forEach(V),delete this._out[B],delete this._sucs[B],--this._nodeCount}return this}setParent(B,S){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(S===void 0)S=_;else{S+="";for(var V=S;V!==void 0;V=this.parent(V))if(V===B)throw new Error("Setting "+S+" as parent of "+B+" would create a cycle");this.setNode(S)}return this.setNode(B),this._removeFromParentsChildList(B),this._parent[B]=S,this._children[S][B]=!0,this}_removeFromParentsChildList(B){delete this._children[this._parent[B]][B]}parent(B){if(this._isCompound){var S=this._parent[B];if(S!==_)return S}}children(B=_){if(this._isCompound){var S=this._children[B];if(S)return Object.keys(S)}else{if(B===_)return this.nodes();if(this.hasNode(B))return[]}}predecessors(B){var S=this._preds[B];if(S)return Object.keys(S)}successors(B){var S=this._sucs[B];if(S)return Object.keys(S)}neighbors(B){var S=this.predecessors(B);if(S){let q=new Set(S);for(var V of this.successors(B))q.add(V);return Array.from(q.values())}}isLeaf(B){var S;return this.isDirected()?S=this.successors(B):S=this.neighbors(B),S.length===0}filterNodes(B){var S=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});S.setGraph(this.graph());var V=this;Object.entries(this._nodes).forEach(function([Z,J]){B(Z)&&S.setNode(Z,J)}),Object.values(this._edgeObjs).forEach(function(Z){S.hasNode(Z.v)&&S.hasNode(Z.w)&&S.setEdge(Z,V.edge(Z))});var q={};function H(Z){var J=V.parent(Z);return J===void 0||S.hasNode(J)?(q[Z]=J,J):J in q?q[J]:H(J)}return this._isCompound&&S.nodes().forEach(Z=>S.setParent(Z,H(Z))),S}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,S){var V=this,q=arguments;return B.reduce(function(H,Z){return q.length>1?V.setEdge(H,Z,S):V.setEdge(H,Z),Z}),this}setEdge(){var B,S,V,q,H=!1,Z=arguments[0];typeof Z=="object"&&Z!==null&&"v"in Z?(B=Z.v,S=Z.w,V=Z.name,arguments.length===2&&(q=arguments[1],H=!0)):(B=Z,S=arguments[1],V=arguments[3],arguments.length>2&&(q=arguments[2],H=!0)),B=""+B,S=""+S,V!==void 0&&(V=""+V);var J=Y(this._isDirected,B,S,V);if(Object.hasOwn(this._edgeLabels,J))return H&&(this._edgeLabels[J]=q),this;if(V!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(B),this.setNode(S),this._edgeLabels[J]=H?q:this._defaultEdgeLabelFn(B,S,V);var le=F(this._isDirected,B,S,V);return B=le.v,S=le.w,Object.freeze(le),this._edgeObjs[J]=le,P(this._preds[S],B),P(this._sucs[B],S),this._in[S][J]=le,this._out[B][J]=le,this._edgeCount++,this}edge(B,S,V){var q=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,B,S,V);return this._edgeLabels[q]}edgeAsObj(){let B=this.edge(...arguments);return typeof B!="object"?{label:B}:B}hasEdge(B,S,V){var q=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,B,S,V);return Object.hasOwn(this._edgeLabels,q)}removeEdge(B,S,V){var q=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,B,S,V),H=this._edgeObjs[q];return H&&(B=H.v,S=H.w,delete this._edgeLabels[q],delete this._edgeObjs[q],W(this._preds[S],B),W(this._sucs[B],S),delete this._in[S][q],delete this._out[B][q],this._edgeCount--),this}inEdges(B,S){return this.isDirected()?this.filterEdges(this._in[B],B,S):this.nodeEdges(B,S)}outEdges(B,S){return this.isDirected()?this.filterEdges(this._out[B],B,S):this.nodeEdges(B,S)}nodeEdges(B,S){if(B in this._nodes)return this.filterEdges({...this._in[B],...this._out[B]},B,S)}filterEdges(B,S,V){if(B){var q=Object.values(B);return V?q.filter(function(H){return H.v===S&&H.w===V||H.v===V&&H.w===S}):q}}};function P(B,S){B[S]?B[S]++:B[S]=1}function W(B,S){--B[S]||delete B[S]}function Y(B,S,V,q){var H=""+S,Z=""+V;if(!B&&H>Z){var J=H;H=Z,Z=J}return H+T+Z+T+(q===void 0?O:q)}function F(B,S,V,q){var H=""+S,Z=""+V;if(!B&&H>Z){var J=H;H=Z,Z=J}var le={v:H,w:Z};return q&&(le.name=q),le}function Q(B,S){return Y(B,S.v,S.w,S.name)}j.exports=R}),c=i((z,j)=>{j.exports="3.0.2"}),l=i((z,j)=>{j.exports={Graph:a(),version:c()}}),d=i((z,j)=>{var O=a();j.exports={write:_,read:P};function _(W){var Y={options:{directed:W.isDirected(),multigraph:W.isMultigraph(),compound:W.isCompound()},nodes:T(W),edges:R(W)};return W.graph()!==void 0&&(Y.value=structuredClone(W.graph())),Y}function T(W){return W.nodes().map(function(Y){var F=W.node(Y),Q=W.parent(Y),B={v:Y};return F!==void 0&&(B.value=F),Q!==void 0&&(B.parent=Q),B})}function R(W){return W.edges().map(function(Y){var F=W.edge(Y),Q={v:Y.v,w:Y.w};return Y.name!==void 0&&(Q.name=Y.name),F!==void 0&&(Q.value=F),Q})}function P(W){var Y=new O(W.options).setGraph(W.value);return W.nodes.forEach(function(F){Y.setNode(F.v,F.value),F.parent&&Y.setParent(F.v,F.parent)}),W.edges.forEach(function(F){Y.setEdge({v:F.v,w:F.w,name:F.name},F.value)}),Y}}),h=i((z,j)=>{j.exports=_;var O=()=>1;function _(R,P,W,Y){return T(R,String(P),W||O,Y||function(F){return R.outEdges(F)})}function T(R,P,W,Y){var F={},Q=!0,B=0,S=R.nodes(),V=function(J){var le=W(J);F[J.v].distance+le<F[J.w].distance&&(F[J.w]={distance:F[J.v].distance+le,predecessor:J.v},Q=!0)},q=function(){S.forEach(function(J){Y(J).forEach(function(le){var te=le.v===J?le.v:le.w,X=te===le.v?le.w:le.v;V({v:te,w:X})})})};S.forEach(function(J){var le=J===P?0:Number.POSITIVE_INFINITY;F[J]={distance:le}});for(var H=S.length,Z=1;Z<H&&(Q=!1,B++,q(),!!Q);Z++);if(B===H-1&&(Q=!1,q(),Q))throw new Error("The graph contains a negative weight cycle");return F}}),f=i((z,j)=>{j.exports=O;function O(_){var T={},R=[],P;function W(Y){Object.hasOwn(T,Y)||(T[Y]=!0,P.push(Y),_.successors(Y).forEach(W),_.predecessors(Y).forEach(W))}return _.nodes().forEach(function(Y){P=[],W(Y),P.length&&R.push(P)}),R}}),m=i((z,j)=>{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 T=this._keyIndices[_];if(T!==void 0)return this._arr[T].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(_,T){var R=this._keyIndices;if(_=String(_),!Object.hasOwn(R,_)){var P=this._arr,W=P.length;return R[_]=W,P.push({key:_,priority:T}),this._decrease(W),!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(_,T){var R=this._keyIndices[_];if(T>this._arr[R].priority)throw new Error("New priority is greater than current priority. Key: "+_+" Old: "+this._arr[R].priority+" New: "+T);this._arr[R].priority=T,this._decrease(R)}_heapify(_){var T=this._arr,R=2*_,P=R+1,W=_;R<T.length&&(W=T[R].priority<T[W].priority?R:W,P<T.length&&(W=T[P].priority<T[W].priority?P:W),W!==_&&(this._swap(_,W),this._heapify(W)))}_decrease(_){for(var T=this._arr,R=T[_].priority,P;_!==0&&(P=_>>1,!(T[P].priority<R));)this._swap(_,P),_=P}_swap(_,T){var R=this._arr,P=this._keyIndices,W=R[_],Y=R[T];R[_]=Y,R[T]=W,P[Y.key]=_,P[W.key]=T}};j.exports=O}),u=i((z,j)=>{var O=m();j.exports=T;var _=()=>1;function T(P,W,Y,F){var Q=function(B){return P.outEdges(B)};return R(P,String(W),Y||_,F||Q)}function R(P,W,Y,F){var Q={},B=new O,S,V,q=function(H){var Z=H.v!==S?H.v:H.w,J=Q[Z],le=Y(H),te=V.distance+le;if(le<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+H+" Weight: "+le);te<J.distance&&(J.distance=te,J.predecessor=S,B.decrease(Z,te))};for(P.nodes().forEach(function(H){var Z=H===W?0:Number.POSITIVE_INFINITY;Q[H]={distance:Z},B.add(H,Z)});B.size()>0&&(S=B.removeMin(),V=Q[S],V.distance!==Number.POSITIVE_INFINITY);)F(S).forEach(q);return Q}}),p=i((z,j)=>{var O=u();j.exports=_;function _(T,R,P){return T.nodes().reduce(function(W,Y){return W[Y]=O(T,Y,R,P),W},{})}}),E=i((z,j)=>{j.exports=O;function O(T,R,P){if(T[R].predecessor!==void 0)throw new Error("Invalid source vertex");if(T[P].predecessor===void 0&&P!==R)throw new Error("Invalid destination vertex");return{weight:T[P].distance,path:_(T,R,P)}}function _(T,R,P){for(var W=[],Y=P;Y!==R;)W.push(Y),Y=T[Y].predecessor;return W.push(R),W.reverse()}}),C=i((z,j)=>{j.exports=O;function O(_){var T=0,R=[],P={},W=[];function Y(F){var Q=P[F]={onStack:!0,lowlink:T,index:T++};if(R.push(F),_.successors(F).forEach(function(V){Object.hasOwn(P,V)?P[V].onStack&&(Q.lowlink=Math.min(Q.lowlink,P[V].index)):(Y(V),Q.lowlink=Math.min(Q.lowlink,P[V].lowlink))}),Q.lowlink===Q.index){var B=[],S;do S=R.pop(),P[S].onStack=!1,B.push(S);while(F!==S);W.push(B)}}return _.nodes().forEach(function(F){Object.hasOwn(P,F)||Y(F)}),W}}),y=i((z,j)=>{var O=C();j.exports=_;function _(T){return O(T).filter(function(R){return R.length>1||R.length===1&&T.hasEdge(R[0],R[0])})}}),v=i((z,j)=>{j.exports=_;var O=()=>1;function _(R,P,W){return T(R,P||O,W||function(Y){return R.outEdges(Y)})}function T(R,P,W){var Y={},F=R.nodes();return F.forEach(function(Q){Y[Q]={},Y[Q][Q]={distance:0},F.forEach(function(B){Q!==B&&(Y[Q][B]={distance:Number.POSITIVE_INFINITY})}),W(Q).forEach(function(B){var S=B.v===Q?B.w:B.v,V=P(B);Y[Q][S]={distance:V,predecessor:Q}})}),F.forEach(function(Q){var B=Y[Q];F.forEach(function(S){var V=Y[S];F.forEach(function(q){var H=V[Q],Z=B[q],J=V[q],le=H.distance+Z.distance;le<J.distance&&(J.distance=le,J.predecessor=Z.predecessor)})})}),Y}}),x=i((z,j)=>{function O(T){var R={},P={},W=[];function Y(F){if(Object.hasOwn(P,F))throw new _;Object.hasOwn(R,F)||(P[F]=!0,R[F]=!0,T.predecessors(F).forEach(Y),delete P[F],W.push(F))}if(T.sinks().forEach(Y),Object.keys(R).length!==T.nodeCount())throw new _;return W}var _=class extends Error{constructor(){super(...arguments)}};j.exports=O,O.CycleException=_}),b=i((z,j)=>{var O=x();j.exports=_;function _(T){try{O(T)}catch(R){if(R instanceof O.CycleException)return!1;throw R}return!0}}),k=i((z,j)=>{j.exports=O;function O(T,R,P,W,Y){Array.isArray(R)||(R=[R]);var F=(T.isDirected()?T.successors:T.neighbors).bind(T),Q={};return R.forEach(function(B){if(!T.hasNode(B))throw new Error("Graph does not have node: "+B);Y=_(T,B,P==="post",Q,F,W,Y)}),Y}function _(T,R,P,W,Y,F,Q){return Object.hasOwn(W,R)||(W[R]=!0,P||(Q=F(Q,R)),Y(R).forEach(function(B){Q=_(T,B,P,W,Y,F,Q)}),P&&(Q=F(Q,R))),Q}}),N=i((z,j)=>{var O=k();j.exports=_;function _(T,R,P){return O(T,R,P,function(W,Y){return W.push(Y),W},[])}}),I=i((z,j)=>{var O=N();j.exports=_;function _(T,R){return O(T,R,"post")}}),D=i((z,j)=>{var O=N();j.exports=_;function _(T,R){return O(T,R,"pre")}}),A=i((z,j)=>{var O=a(),_=m();j.exports=T;function T(R,P){var W=new O,Y={},F=new _,Q;function B(V){var q=V.v===Q?V.w:V.v,H=F.priority(q);if(H!==void 0){var Z=P(V);Z<H&&(Y[q]=Q,F.decrease(q,Z))}}if(R.nodeCount()===0)return W;R.nodes().forEach(function(V){F.add(V,Number.POSITIVE_INFINITY),W.setNode(V)}),F.decrease(R.nodes()[0],0);for(var S=!1;F.size()>0;){if(Q=F.removeMin(),Object.hasOwn(Y,Q))W.setEdge(Q,Y[Q]);else{if(S)throw new Error("Input graph is not connected: "+R);S=!0}R.nodeEdges(Q).forEach(B)}return W}}),L=i((z,j)=>{var O=u(),_=h();j.exports=T;function T(P,W,Y,F){return R(P,W,Y,F||function(Q){return P.outEdges(Q)})}function R(P,W,Y,F){if(Y===void 0)return O(P,W,Y,F);for(var Q=!1,B=P.nodes(),S=0;S<B.length;S++){for(var V=F(B[S]),q=0;q<V.length;q++){var H=V[q],Z=H.v===B[S]?H.v:H.w,J=Z===H.v?H.w:H.v;Y({v:Z,w:J})<0&&(Q=!0)}if(Q)return _(P,W,Y,F)}return O(P,W,Y,F)}}),M=i((z,j)=>{j.exports={bellmanFord:h(),components:f(),dijkstra:u(),dijkstraAll:p(),extractPath:E(),findCycles:y(),floydWarshall:v(),isAcyclic:b(),postorder:I(),preorder:D(),prim:A(),shortestPaths:L(),reduce:k(),tarjan:C(),topsort:x()}}),$=l();n.exports={Graph:$.Graph,json:d(),alg:M(),version:$.version}}),Wf=Pe((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,c=a._prev;for(;c!==a;)o.push(JSON.stringify(c,i)),c=c._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}),Vf=Pe((e,n)=>{var s=zt().Graph,r=Wf();n.exports=o;var i=()=>1;function o(f,m){if(f.nodeCount()<=1)return[];let u=l(f,m||i);return a(u.graph,u.buckets,u.zeroIdx).flatMap(p=>f.outEdges(p.v,p.w))}function a(f,m,u){let p=[],E=m[m.length-1],C=m[0],y;for(;f.nodeCount();){for(;y=C.dequeue();)c(f,m,u,y);for(;y=E.dequeue();)c(f,m,u,y);if(f.nodeCount()){for(let v=m.length-2;v>0;--v)if(y=m[v].dequeue(),y){p=p.concat(c(f,m,u,y,!0));break}}}return p}function c(f,m,u,p,E){let C=E?[]:void 0;return f.inEdges(p.v).forEach(y=>{let v=f.edge(y),x=f.node(y.v);E&&C.push({v:y.v,w:y.w}),x.out-=v,d(m,u,x)}),f.outEdges(p.v).forEach(y=>{let v=f.edge(y),x=y.w,b=f.node(x);b.in-=v,d(m,u,b)}),f.removeNode(p.v),C}function l(f,m){let u=new s,p=0,E=0;f.nodes().forEach(v=>{u.setNode(v,{v,in:0,out:0})}),f.edges().forEach(v=>{let x=u.edge(v.v,v.w)||0,b=m(v),k=x+b;u.setEdge(v.v,v.w,k),E=Math.max(E,u.node(v.v).out+=b),p=Math.max(p,u.node(v.w).in+=b)});let C=h(E+p+3).map(()=>new r),y=p+1;return u.nodes().forEach(v=>{d(C,y,u.node(v))}),{graph:u,buckets:C,zeroIdx:y}}function d(f,m,u){u.out?u.in?f[u.out-u.in+m].enqueue(u):f[f.length-1].enqueue(u):f[0].enqueue(u)}function h(f){let m=[];for(let u=0;u<f;u++)m.push(u);return m}}),Ge=Pe((e,n)=>{var s=zt().Graph;n.exports={addBorderNode:m,addDummyNode:r,applyWithChunking:E,asNonCompoundGraph:o,buildLayerMatrix:d,intersectRect:l,mapValues:D,maxRank:C,normalizeRanks:h,notime:x,partition:y,pick:I,predecessorWeights:c,range:N,removeEmptyRanks:f,simplify:i,successorWeights:a,time:v,uniqueId:k,zipObject:A};function r(L,M,$,z){for(var j=z;L.hasNode(j);)j=k(z);return $.dummy=M,L.setNode(j,$),j}function i(L){let M=new s().setGraph(L.graph());return L.nodes().forEach($=>M.setNode($,L.node($))),L.edges().forEach($=>{let z=M.edge($.v,$.w)||{weight:0,minlen:1},j=L.edge($);M.setEdge($.v,$.w,{weight:z.weight+j.weight,minlen:Math.max(z.minlen,j.minlen)})}),M}function o(L){let M=new s({multigraph:L.isMultigraph()}).setGraph(L.graph());return L.nodes().forEach($=>{L.children($).length||M.setNode($,L.node($))}),L.edges().forEach($=>{M.setEdge($,L.edge($))}),M}function a(L){let M=L.nodes().map($=>{let z={};return L.outEdges($).forEach(j=>{z[j.w]=(z[j.w]||0)+L.edge(j).weight}),z});return A(L.nodes(),M)}function c(L){let M=L.nodes().map($=>{let z={};return L.inEdges($).forEach(j=>{z[j.v]=(z[j.v]||0)+L.edge(j).weight}),z});return A(L.nodes(),M)}function l(L,M){let $=L.x,z=L.y,j=M.x-$,O=M.y-z,_=L.width/2,T=L.height/2;if(!j&&!O)throw new Error("Not possible to find intersection inside of the rectangle");let R,P;return Math.abs(O)*_>Math.abs(j)*T?(O<0&&(T=-T),R=T*j/O,P=T):(j<0&&(_=-_),R=_,P=_*O/j),{x:$+R,y:z+P}}function d(L){let M=N(C(L)+1).map(()=>[]);return L.nodes().forEach($=>{let z=L.node($),j=z.rank;j!==void 0&&(M[j][z.order]=$)}),M}function h(L){let M=L.nodes().map(z=>{let j=L.node(z).rank;return j===void 0?Number.MAX_VALUE:j}),$=E(Math.min,M);L.nodes().forEach(z=>{let j=L.node(z);Object.hasOwn(j,"rank")&&(j.rank-=$)})}function f(L){let M=L.nodes().map(_=>L.node(_).rank).filter(_=>_!==void 0),$=E(Math.min,M),z=[];L.nodes().forEach(_=>{let T=L.node(_).rank-$;z[T]||(z[T]=[]),z[T].push(_)});let j=0,O=L.graph().nodeRankFactor;Array.from(z).forEach((_,T)=>{_===void 0&&T%O!==0?--j:_!==void 0&&j&&_.forEach(R=>L.node(R).rank+=j)})}function m(L,M,$,z){let j={width:0,height:0};return arguments.length>=4&&(j.rank=$,j.order=z),r(L,"border",j,M)}function u(L,M=p){let $=[];for(let z=0;z<L.length;z+=M){let j=L.slice(z,z+M);$.push(j)}return $}var p=65535;function E(L,M){if(M.length>p){let $=u(M);return L.apply(null,$.map(z=>L.apply(null,z)))}else return L.apply(null,M)}function C(L){let M=L.nodes().map($=>{let z=L.node($).rank;return z===void 0?Number.MIN_VALUE:z});return E(Math.max,M)}function y(L,M){let $={lhs:[],rhs:[]};return L.forEach(z=>{M(z)?$.lhs.push(z):$.rhs.push(z)}),$}function v(L,M){let $=Date.now();try{return M()}finally{console.log(L+" time: "+(Date.now()-$)+"ms")}}function x(L,M){return M()}var b=0;function k(L){var M=++b;return L+(""+M)}function N(L,M,$=1){M==null&&(M=L,L=0);let z=O=>O<M;$<0&&(z=O=>M<O);let j=[];for(let O=L;z(O);O+=$)j.push(O);return j}function I(L,M){let $={};for(let z of M)L[z]!==void 0&&($[z]=L[z]);return $}function D(L,M){let $=M;return typeof M=="string"&&($=z=>z[M]),Object.entries(L).reduce((z,[j,O])=>(z[j]=$(O,j),z),{})}function A(L,M){return L.reduce(($,z,j)=>($[z]=M[j],$),{})}}),Ff=Pe((e,n)=>{var s=Vf(),r=Ge().uniqueId;n.exports={run:i,undo:a};function i(c){(c.graph().acyclicer==="greedy"?s(c,l(c)):o(c)).forEach(d=>{let h=c.edge(d);c.removeEdge(d),h.forwardName=d.name,h.reversed=!0,c.setEdge(d.w,d.v,h,r("rev"))});function l(d){return h=>d.edge(h).weight}}function o(c){let l=[],d={},h={};function f(m){Object.hasOwn(h,m)||(h[m]=!0,d[m]=!0,c.outEdges(m).forEach(u=>{Object.hasOwn(d,u.w)?l.push(u):f(u.w)}),delete d[m])}return c.nodes().forEach(f),l}function a(c){c.edges().forEach(l=>{let d=c.edge(l);if(d.reversed){c.removeEdge(l);let h=d.forwardName;delete d.reversed,delete d.forwardName,c.setEdge(l.w,l.v,d,h)}})}}),Yf=Pe((e,n)=>{var s=Ge();n.exports={run:r,undo:o};function r(a){a.graph().dummyChains=[],a.edges().forEach(c=>i(a,c))}function i(a,c){let l=c.v,d=a.node(l).rank,h=c.w,f=a.node(h).rank,m=c.name,u=a.edge(c),p=u.labelRank;if(f===d+1)return;a.removeEdge(c);let E,C,y;for(y=0,++d;d<f;++y,++d)u.points=[],C={width:0,height:0,edgeLabel:u,edgeObj:c,rank:d},E=s.addDummyNode(a,"edge",C,"_d"),d===p&&(C.width=u.width,C.height=u.height,C.dummy="edge-label",C.labelpos=u.labelpos),a.setEdge(l,E,{weight:u.weight},m),y===0&&a.graph().dummyChains.push(E),l=E;a.setEdge(l,h,{weight:u.weight},m)}function o(a){a.graph().dummyChains.forEach(c=>{let l=a.node(c),d=l.edgeLabel,h;for(a.setEdge(l.edgeObj,d);l.dummy;)h=a.successors(c)[0],a.removeNode(c),d.points.push({x:l.x,y:l.y}),l.dummy==="edge-label"&&(d.x=l.x,d.y=l.y,d.width=l.width,d.height=l.height),c=h,l=a.node(c)})}}),rs=Pe((e,n)=>{var{applyWithChunking:s}=Ge();n.exports={longestPath:r,slack:i};function r(o){var a={};function c(l){var d=o.node(l);if(Object.hasOwn(a,l))return d.rank;a[l]=!0;let h=o.outEdges(l).map(m=>m==null?Number.POSITIVE_INFINITY:c(m.w)-o.edge(m).minlen);var f=s(Math.min,h);return f===Number.POSITIVE_INFINITY&&(f=0),d.rank=f}o.sources().forEach(c)}function i(o,a){return o.node(a.w).rank-o.node(a.v).rank-o.edge(a).minlen}}),xl=Pe((e,n)=>{var s=zt().Graph,r=rs().slack;n.exports=i;function i(l){var d=new s({directed:!1}),h=l.nodes()[0],f=l.nodeCount();d.setNode(h,{});for(var m,u;o(d,l)<f;)m=a(d,l),u=d.hasNode(m.v)?r(l,m):-r(l,m),c(d,l,u);return d}function o(l,d){function h(f){d.nodeEdges(f).forEach(m=>{var u=m.v,p=f===u?m.w:u;!l.hasNode(p)&&!r(d,m)&&(l.setNode(p,{}),l.setEdge(f,p,{}),h(p))})}return l.nodes().forEach(h),l.nodeCount()}function a(l,d){return d.edges().reduce((h,f)=>{let m=Number.POSITIVE_INFINITY;return l.hasNode(f.v)!==l.hasNode(f.w)&&(m=r(d,f)),m<h[0]?[m,f]:h},[Number.POSITIVE_INFINITY,null])[1]}function c(l,d,h){l.nodes().forEach(f=>d.node(f).rank+=h)}}),Gf=Pe((e,n)=>{var s=xl(),r=rs().slack,i=rs().longestPath,o=zt().alg.preorder,a=zt().alg.postorder,c=Ge().simplify;n.exports=l,l.initLowLimValues=m,l.initCutValues=d,l.calcCutValue=f,l.leaveEdge=p,l.enterEdge=E,l.exchangeEdges=C;function l(b){b=c(b),i(b);var k=s(b);m(k),d(k,b);for(var N,I;N=p(k);)I=E(k,b,N),C(k,b,N,I)}function d(b,k){var N=a(b,b.nodes());N=N.slice(0,N.length-1),N.forEach(I=>h(b,k,I))}function h(b,k,N){var I=b.node(N),D=I.parent;b.edge(N,D).cutvalue=f(b,k,N)}function f(b,k,N){var I=b.node(N),D=I.parent,A=!0,L=k.edge(N,D),M=0;return L||(A=!1,L=k.edge(D,N)),M=L.weight,k.nodeEdges(N).forEach($=>{var z=$.v===N,j=z?$.w:$.v;if(j!==D){var O=z===A,_=k.edge($).weight;if(M+=O?_:-_,v(b,N,j)){var T=b.edge(N,j).cutvalue;M+=O?-T:T}}}),M}function m(b,k){arguments.length<2&&(k=b.nodes()[0]),u(b,{},1,k)}function u(b,k,N,I,D){var A=N,L=b.node(I);return k[I]=!0,b.neighbors(I).forEach(M=>{Object.hasOwn(k,M)||(N=u(b,k,N,M,I))}),L.low=A,L.lim=N++,D?L.parent=D:delete L.parent,N}function p(b){return b.edges().find(k=>b.edge(k).cutvalue<0)}function E(b,k,N){var I=N.v,D=N.w;k.hasEdge(I,D)||(I=N.w,D=N.v);var A=b.node(I),L=b.node(D),M=A,$=!1;A.lim>L.lim&&(M=L,$=!0);var z=k.edges().filter(j=>$===x(b,b.node(j.v),M)&&$!==x(b,b.node(j.w),M));return z.reduce((j,O)=>r(k,O)<r(k,j)?O:j)}function C(b,k,N,I){var D=N.v,A=N.w;b.removeEdge(D,A),b.setEdge(I.v,I.w,{}),m(b),d(b,k),y(b,k)}function y(b,k){var N=b.nodes().find(D=>!k.node(D).parent),I=o(b,N);I=I.slice(1),I.forEach(D=>{var A=b.node(D).parent,L=k.edge(D,A),M=!1;L||(L=k.edge(A,D),M=!0),k.node(D).rank=k.node(A).rank+(M?L.minlen:-L.minlen)})}function v(b,k,N){return b.hasEdge(k,N)}function x(b,k,N){return N.low<=k.lim&&k.lim<=N.lim}}),Kf=Pe((e,n)=>{var s=rs(),r=s.longestPath,i=xl(),o=Gf();n.exports=a;function a(h){var f=h.graph().ranker;if(f instanceof Function)return f(h);switch(h.graph().ranker){case"network-simplex":d(h);break;case"tight-tree":l(h);break;case"longest-path":c(h);break;case"none":break;default:d(h)}}var c=r;function l(h){r(h),i(h)}function d(h){o(h)}}),Zf=Pe((e,n)=>{n.exports=s;function s(o){let a=i(o);o.graph().dummyChains.forEach(c=>{let l=o.node(c),d=l.edgeObj,h=r(o,a,d.v,d.w),f=h.path,m=h.lca,u=0,p=f[u],E=!0;for(;c!==d.w;){if(l=o.node(c),E){for(;(p=f[u])!==m&&o.node(p).maxRank<l.rank;)u++;p===m&&(E=!1)}if(!E){for(;u<f.length-1&&o.node(p=f[u+1]).minRank<=l.rank;)u++;p=f[u]}o.setParent(c,p),c=o.successors(c)[0]}})}function r(o,a,c,l){let d=[],h=[],f=Math.min(a[c].low,a[l].low),m=Math.max(a[c].lim,a[l].lim),u,p;u=c;do u=o.parent(u),d.push(u);while(u&&(a[u].low>f||m>a[u].lim));for(p=u,u=l;(u=o.parent(u))!==p;)h.push(u);return{path:d.concat(h.reverse()),lca:p}}function i(o){let a={},c=0;function l(d){let h=c;o.children(d).forEach(l),a[d]={low:h,lim:c++}}return o.children().forEach(l),a}}),Xf=Pe((e,n)=>{var s=Ge();n.exports={run:r,cleanup:c};function r(l){let d=s.addDummyNode(l,"root",{},"_root"),h=o(l),f=Object.values(h),m=s.applyWithChunking(Math.max,f)-1,u=2*m+1;l.graph().nestingRoot=d,l.edges().forEach(E=>l.edge(E).minlen*=u);let p=a(l)+1;l.children().forEach(E=>i(l,d,u,p,m,h,E)),l.graph().nodeRankFactor=u}function i(l,d,h,f,m,u,p){let E=l.children(p);if(!E.length){p!==d&&l.setEdge(d,p,{weight:0,minlen:h});return}let C=s.addBorderNode(l,"_bt"),y=s.addBorderNode(l,"_bb"),v=l.node(p);l.setParent(C,p),v.borderTop=C,l.setParent(y,p),v.borderBottom=y,E.forEach(x=>{i(l,d,h,f,m,u,x);let b=l.node(x),k=b.borderTop?b.borderTop:x,N=b.borderBottom?b.borderBottom:x,I=b.borderTop?f:2*f,D=k!==N?1:m-u[p]+1;l.setEdge(C,k,{weight:I,minlen:D,nestingEdge:!0}),l.setEdge(N,y,{weight:I,minlen:D,nestingEdge:!0})}),l.parent(p)||l.setEdge(d,C,{weight:0,minlen:m+u[p]})}function o(l){var d={};function h(f,m){var u=l.children(f);u&&u.length&&u.forEach(p=>h(p,m+1)),d[f]=m}return l.children().forEach(f=>h(f,1)),d}function a(l){return l.edges().reduce((d,h)=>d+l.edge(h).weight,0)}function c(l){var d=l.graph();l.removeNode(d.nestingRoot),delete d.nestingRoot,l.edges().forEach(h=>{var f=l.edge(h);f.nestingEdge&&l.removeEdge(h)})}}),Uf=Pe((e,n)=>{var s=Ge();n.exports=r;function r(o){function a(c){let l=o.children(c),d=o.node(c);if(l.length&&l.forEach(a),Object.hasOwn(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(let h=d.minRank,f=d.maxRank+1;h<f;++h)i(o,"borderLeft","_bl",c,d,h),i(o,"borderRight","_br",c,d,h)}}o.children().forEach(a)}function i(o,a,c,l,d,h){let f={width:0,height:0,rank:h,borderType:a},m=d[a][h-1],u=s.addDummyNode(o,"border",f,c);d[a][h]=u,o.setParent(u,l),m&&o.setEdge(m,u,{weight:1})}}),Qf=Pe((e,n)=>{n.exports={adjust:s,undo:r};function s(h){let f=h.graph().rankdir.toLowerCase();(f==="lr"||f==="rl")&&i(h)}function r(h){let f=h.graph().rankdir.toLowerCase();(f==="bt"||f==="rl")&&a(h),(f==="lr"||f==="rl")&&(l(h),i(h))}function i(h){h.nodes().forEach(f=>o(h.node(f))),h.edges().forEach(f=>o(h.edge(f)))}function o(h){let f=h.width;h.width=h.height,h.height=f}function a(h){h.nodes().forEach(f=>c(h.node(f))),h.edges().forEach(f=>{let m=h.edge(f);m.points.forEach(c),Object.hasOwn(m,"y")&&c(m)})}function c(h){h.y=-h.y}function l(h){h.nodes().forEach(f=>d(h.node(f))),h.edges().forEach(f=>{let m=h.edge(f);m.points.forEach(d),Object.hasOwn(m,"x")&&d(m)})}function d(h){let f=h.x;h.x=h.y,h.y=f}}),Jf=Pe((e,n)=>{var s=Ge();n.exports=r;function r(i){let o={},a=i.nodes().filter(f=>!i.children(f).length),c=a.map(f=>i.node(f).rank),l=s.applyWithChunking(Math.max,c),d=s.range(l+1).map(()=>[]);function h(f){if(o[f])return;o[f]=!0;let m=i.node(f);d[m.rank].push(f),i.successors(f).forEach(h)}return a.sort((f,m)=>i.node(f).rank-i.node(m).rank).forEach(h),d}}),eh=Pe((e,n)=>{var s=Ge().zipObject;n.exports=r;function r(o,a){let c=0;for(let l=1;l<a.length;++l)c+=i(o,a[l-1],a[l]);return c}function i(o,a,c){let l=s(c,c.map((p,E)=>E)),d=a.flatMap(p=>o.outEdges(p).map(E=>({pos:l[E.w],weight:o.edge(E).weight})).sort((E,C)=>E.pos-C.pos)),h=1;for(;h<c.length;)h<<=1;let f=2*h-1;h-=1;let m=new Array(f).fill(0),u=0;return d.forEach(p=>{let E=p.pos+h;m[E]+=p.weight;let C=0;for(;E>0;)E%2&&(C+=m[E+1]),E=E-1>>1,m[E]+=p.weight;u+=p.weight*C}),u}}),th=Pe((e,n)=>{n.exports=s;function s(r,i=[]){return i.map(o=>{let a=r.inEdges(o);if(a.length){let c=a.reduce((l,d)=>{let h=r.edge(d),f=r.node(d.v);return{sum:l.sum+h.weight*f.order,weight:l.weight+h.weight}},{sum:0,weight:0});return{v:o,barycenter:c.sum/c.weight,weight:c.weight}}else return{v:o}})}}),nh=Pe((e,n)=>{var s=Ge();n.exports=r;function r(a,c){let l={};a.forEach((h,f)=>{let m=l[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:f};h.barycenter!==void 0&&(m.barycenter=h.barycenter,m.weight=h.weight)}),c.edges().forEach(h=>{let f=l[h.v],m=l[h.w];f!==void 0&&m!==void 0&&(m.indegree++,f.out.push(l[h.w]))});let d=Object.values(l).filter(h=>!h.indegree);return i(d)}function i(a){let c=[];function l(h){return f=>{f.merged||(f.barycenter===void 0||h.barycenter===void 0||f.barycenter>=h.barycenter)&&o(h,f)}}function d(h){return f=>{f.in.push(h),--f.indegree===0&&a.push(f)}}for(;a.length;){let h=a.pop();c.push(h),h.in.reverse().forEach(l(h)),h.out.forEach(d(h))}return c.filter(h=>!h.merged).map(h=>s.pick(h,["vs","i","barycenter","weight"]))}function o(a,c){let l=0,d=0;a.weight&&(l+=a.barycenter*a.weight,d+=a.weight),c.weight&&(l+=c.barycenter*c.weight,d+=c.weight),a.vs=c.vs.concat(a.vs),a.barycenter=l/d,a.weight=d,a.i=Math.min(c.i,a.i),c.merged=!0}}),rh=Pe((e,n)=>{var s=Ge();n.exports=r;function r(a,c){let l=s.partition(a,C=>Object.hasOwn(C,"barycenter")),d=l.lhs,h=l.rhs.sort((C,y)=>y.i-C.i),f=[],m=0,u=0,p=0;d.sort(o(!!c)),p=i(f,h,p),d.forEach(C=>{p+=C.vs.length,f.push(C.vs),m+=C.barycenter*C.weight,u+=C.weight,p=i(f,h,p)});let E={vs:f.flat(!0)};return u&&(E.barycenter=m/u,E.weight=u),E}function i(a,c,l){let d;for(;c.length&&(d=c[c.length-1]).i<=l;)c.pop(),a.push(d.vs),l++;return l}function o(a){return(c,l)=>c.barycenter<l.barycenter?-1:c.barycenter>l.barycenter?1:a?l.i-c.i:c.i-l.i}}),sh=Pe((e,n)=>{var s=th(),r=nh(),i=rh();n.exports=o;function o(l,d,h,f){let m=l.children(d),u=l.node(d),p=u?u.borderLeft:void 0,E=u?u.borderRight:void 0,C={};p&&(m=m.filter(b=>b!==p&&b!==E));let y=s(l,m);y.forEach(b=>{if(l.children(b.v).length){let k=o(l,b.v,h,f);C[b.v]=k,Object.hasOwn(k,"barycenter")&&c(b,k)}});let v=r(y,h);a(v,C);let x=i(v,f);if(p&&(x.vs=[p,x.vs,E].flat(!0),l.predecessors(p).length)){let b=l.node(l.predecessors(p)[0]),k=l.node(l.predecessors(E)[0]);Object.hasOwn(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+b.order+k.order)/(x.weight+2),x.weight+=2}return x}function a(l,d){l.forEach(h=>{h.vs=h.vs.flatMap(f=>d[f]?d[f].vs:f)})}function c(l,d){l.barycenter!==void 0?(l.barycenter=(l.barycenter*l.weight+d.barycenter*d.weight)/(l.weight+d.weight),l.weight+=d.weight):(l.barycenter=d.barycenter,l.weight=d.weight)}}),oh=Pe((e,n)=>{var s=zt().Graph,r=Ge();n.exports=i;function i(a,c,l,d){d||(d=a.nodes());let h=o(a),f=new s({compound:!0}).setGraph({root:h}).setDefaultNodeLabel(m=>a.node(m));return d.forEach(m=>{let u=a.node(m),p=a.parent(m);(u.rank===c||u.minRank<=c&&c<=u.maxRank)&&(f.setNode(m),f.setParent(m,p||h),a[l](m).forEach(E=>{let C=E.v===m?E.w:E.v,y=f.edge(C,m),v=y!==void 0?y.weight:0;f.setEdge(C,m,{weight:a.edge(E).weight+v})}),Object.hasOwn(u,"minRank")&&f.setNode(m,{borderLeft:u.borderLeft[c],borderRight:u.borderRight[c]}))}),f}function o(a){for(var c;a.hasNode(c=r.uniqueId("_root")););return c}}),ah=Pe((e,n)=>{n.exports=s;function s(r,i,o){let a={},c;o.forEach(l=>{let d=r.parent(l),h,f;for(;d;){if(h=r.parent(d),h?(f=a[h],a[h]=d):(f=c,c=d),f&&f!==d){i.setEdge(f,d);return}d=h}})}}),ih=Pe((e,n)=>{var s=Jf(),r=eh(),i=sh(),o=oh(),a=ah(),c=zt().Graph,l=Ge();n.exports=d;function d(u,p={}){if(typeof p.customOrder=="function"){p.customOrder(u,d);return}let E=l.maxRank(u),C=h(u,l.range(1,E+1),"inEdges"),y=h(u,l.range(E-1,-1,-1),"outEdges"),v=s(u);if(m(u,v),p.disableOptimalOrderHeuristic)return;let x=Number.POSITIVE_INFINITY,b,k=p.constraints||[];for(let N=0,I=0;I<4;++N,++I){f(N%2?C:y,N%4>=2,k),v=l.buildLayerMatrix(u);let D=r(u,v);D<x?(I=0,b=Object.assign({},v),x=D):D===x&&(b=structuredClone(v))}m(u,b)}function h(u,p,E){let C=new Map,y=(v,x)=>{C.has(v)||C.set(v,[]),C.get(v).push(x)};for(let v of u.nodes()){let x=u.node(v);if(typeof x.rank=="number"&&y(x.rank,v),typeof x.minRank=="number"&&typeof x.maxRank=="number")for(let b=x.minRank;b<=x.maxRank;b++)b!==x.rank&&y(b,v)}return p.map(function(v){return o(u,v,E,C.get(v)||[])})}function f(u,p,E){let C=new c;u.forEach(function(y){E.forEach(b=>C.setEdge(b.left,b.right));let v=y.graph().root,x=i(y,v,C,p);x.vs.forEach((b,k)=>y.node(b).order=k),a(y,C,x.vs)})}function m(u,p){Object.values(p).forEach(E=>E.forEach((C,y)=>u.node(C).order=y))}}),lh=Pe((e,n)=>{var s=zt().Graph,r=Ge();n.exports={positionX:E,findType1Conflicts:i,findType2Conflicts:o,addConflict:c,hasConflict:l,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:u,findSmallestWidthAlignment:m,balance:p};function i(v,x){let b={};function k(N,I){let D=0,A=0,L=N.length,M=I[I.length-1];return I.forEach(($,z)=>{let j=a(v,$),O=j?v.node(j).order:L;(j||$===M)&&(I.slice(A,z+1).forEach(_=>{v.predecessors(_).forEach(T=>{let R=v.node(T),P=R.order;(P<D||O<P)&&!(R.dummy&&v.node(_).dummy)&&c(b,T,_)})}),A=z+1,D=O)}),I}return x.length&&x.reduce(k),b}function o(v,x){let b={};function k(I,D,A,L,M){let $;r.range(D,A).forEach(z=>{$=I[z],v.node($).dummy&&v.predecessors($).forEach(j=>{let O=v.node(j);O.dummy&&(O.order<L||O.order>M)&&c(b,j,$)})})}function N(I,D){let A=-1,L,M=0;return D.forEach(($,z)=>{if(v.node($).dummy==="border"){let j=v.predecessors($);j.length&&(L=v.node(j[0]).order,k(D,M,z,A,L),M=z,A=L)}k(D,M,D.length,L,I.length)}),D}return x.length&&x.reduce(N),b}function a(v,x){if(v.node(x).dummy)return v.predecessors(x).find(b=>v.node(b).dummy)}function c(v,x,b){if(x>b){let N=x;x=b,b=N}let k=v[x];k||(v[x]=k={}),k[b]=!0}function l(v,x,b){if(x>b){let k=x;x=b,b=k}return!!v[x]&&Object.hasOwn(v[x],b)}function d(v,x,b,k){let N={},I={},D={};return x.forEach(A=>{A.forEach((L,M)=>{N[L]=L,I[L]=L,D[L]=M})}),x.forEach(A=>{let L=-1;A.forEach(M=>{let $=k(M);if($.length){$=$.sort((j,O)=>D[j]-D[O]);let z=($.length-1)/2;for(let j=Math.floor(z),O=Math.ceil(z);j<=O;++j){let _=$[j];I[M]===M&&L<D[_]&&!l(b,M,_)&&(I[_]=M,I[M]=N[M]=N[_],L=D[_])}}})}),{root:N,align:I}}function h(v,x,b,k,N){let I={},D=f(v,x,b,N),A=N?"borderLeft":"borderRight";function L(z,j){let O=D.nodes().slice(),_={},T=O.pop();for(;T;){if(_[T])z(T);else{_[T]=!0,O.push(T);for(let R of j(T))O.push(R)}T=O.pop()}}function M(z){I[z]=D.inEdges(z).reduce((j,O)=>Math.max(j,I[O.v]+D.edge(O)),0)}function $(z){let j=D.outEdges(z).reduce((_,T)=>Math.min(_,I[T.w]-D.edge(T)),Number.POSITIVE_INFINITY),O=v.node(z);j!==Number.POSITIVE_INFINITY&&O.borderType!==A&&(I[z]=Math.max(I[z],j))}return L(M,D.predecessors.bind(D)),L($,D.successors.bind(D)),Object.keys(k).forEach(z=>I[z]=I[b[z]]),I}function f(v,x,b,k){let N=new s,I=v.graph(),D=C(I.nodesep,I.edgesep,k);return x.forEach(A=>{let L;A.forEach(M=>{let $=b[M];if(N.setNode($),L){var z=b[L],j=N.edge(z,$);N.setEdge(z,$,Math.max(D(v,M,L),j||0))}L=M})}),N}function m(v,x){return Object.values(x).reduce((b,k)=>{let N=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;Object.entries(k).forEach(([A,L])=>{let M=y(v,A)/2;N=Math.max(L+M,N),I=Math.min(L-M,I)});let D=N-I;return D<b[0]&&(b=[D,k]),b},[Number.POSITIVE_INFINITY,null])[1]}function u(v,x){let b=Object.values(x),k=r.applyWithChunking(Math.min,b),N=r.applyWithChunking(Math.max,b);["u","d"].forEach(I=>{["l","r"].forEach(D=>{let A=I+D,L=v[A];if(L===x)return;let M=Object.values(L),$=k-r.applyWithChunking(Math.min,M);D!=="l"&&($=N-r.applyWithChunking(Math.max,M)),$&&(v[A]=r.mapValues(L,z=>z+$))})})}function p(v,x){return r.mapValues(v.ul,(b,k)=>{if(x)return v[x.toLowerCase()][k];{let N=Object.values(v).map(I=>I[k]).sort((I,D)=>I-D);return(N[1]+N[2])/2}})}function E(v){let x=r.buildLayerMatrix(v),b=Object.assign(i(v,x),o(v,x)),k={},N;["u","d"].forEach(D=>{N=D==="u"?x:Object.values(x).reverse(),["l","r"].forEach(A=>{A==="r"&&(N=N.map(z=>Object.values(z).reverse()));let L=(D==="u"?v.predecessors:v.successors).bind(v),M=d(v,N,b,L),$=h(v,N,M.root,M.align,A==="r");A==="r"&&($=r.mapValues($,z=>-z)),k[D+A]=$})});let I=m(v,k);return u(k,I),p(k,v.graph().align)}function C(v,x,b){return(k,N,I)=>{let D=k.node(N),A=k.node(I),L=0,M;if(L+=D.width/2,Object.hasOwn(D,"labelpos"))switch(D.labelpos.toLowerCase()){case"l":M=-D.width/2;break;case"r":M=D.width/2;break}if(M&&(L+=b?M:-M),M=0,L+=(D.dummy?x:v)/2,L+=(A.dummy?x:v)/2,L+=A.width/2,Object.hasOwn(A,"labelpos"))switch(A.labelpos.toLowerCase()){case"l":M=A.width/2;break;case"r":M=-A.width/2;break}return M&&(L+=b?M:-M),M=0,L}}function y(v,x){return v.node(x).width}}),ch=Pe((e,n)=>{var s=Ge(),r=lh().positionX;n.exports=i;function i(a){a=s.asNonCompoundGraph(a),o(a),Object.entries(r(a)).forEach(([c,l])=>a.node(c).x=l)}function o(a){let c=s.buildLayerMatrix(a),l=a.graph().ranksep,d=a.graph().rankalign,h=0;c.forEach(f=>{let m=f.reduce((u,p)=>{let E=a.node(p).height;return u>E?u:E},0);f.forEach(u=>{let p=a.node(u);d==="top"?p.y=h+p.height/2:d==="bottom"?p.y=h+m-p.height/2:p.y=h+m/2}),h+=m+l})}}),dh=Pe((e,n)=>{var s=Ff(),r=Yf(),i=Kf(),o=Ge().normalizeRanks,a=Zf(),c=Ge().removeEmptyRanks,l=Xf(),d=Uf(),h=Qf(),f=ih(),m=ch(),u=Ge(),p=zt().Graph;n.exports=E;function E(S,V={}){let q=V.debugTiming?u.time:u.notime;return q("layout",()=>{let H=q(" buildLayoutGraph",()=>L(S));return q(" runLayout",()=>C(H,q,V)),q(" updateInputGraph",()=>y(S,H)),H})}function C(S,V,q){V(" makeSpaceForEdgeLabels",()=>M(S)),V(" removeSelfEdges",()=>W(S)),V(" acyclic",()=>s.run(S)),V(" nestingGraph.run",()=>l.run(S)),V(" rank",()=>i(u.asNonCompoundGraph(S))),V(" injectEdgeLabelProxies",()=>$(S)),V(" removeEmptyRanks",()=>c(S)),V(" nestingGraph.cleanup",()=>l.cleanup(S)),V(" normalizeRanks",()=>o(S)),V(" assignRankMinMax",()=>z(S)),V(" removeEdgeLabelProxies",()=>j(S)),V(" normalize.run",()=>r.run(S)),V(" parentDummyChains",()=>a(S)),V(" addBorderSegments",()=>d(S)),V(" order",()=>f(S,q)),V(" insertSelfEdges",()=>Y(S)),V(" adjustCoordinateSystem",()=>h.adjust(S)),V(" position",()=>m(S)),V(" positionSelfEdges",()=>F(S)),V(" removeBorderNodes",()=>P(S)),V(" normalize.undo",()=>r.undo(S)),V(" fixupEdgeLabelCoords",()=>T(S)),V(" undoCoordinateSystem",()=>h.undo(S)),V(" translateGraph",()=>O(S)),V(" assignNodeIntersects",()=>_(S)),V(" reversePoints",()=>R(S)),V(" acyclic.undo",()=>s.undo(S))}function y(S,V){S.nodes().forEach(q=>{let H=S.node(q),Z=V.node(q);H&&(H.x=Z.x,H.y=Z.y,H.order=Z.order,H.rank=Z.rank,V.children(q).length&&(H.width=Z.width,H.height=Z.height))}),S.edges().forEach(q=>{let H=S.edge(q),Z=V.edge(q);H.points=Z.points,Object.hasOwn(Z,"x")&&(H.x=Z.x,H.y=Z.y)}),S.graph().width=V.graph().width,S.graph().height=V.graph().height}var v=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},b=["acyclicer","ranker","rankdir","align","rankalign"],k=["width","height","rank"],N={width:0,height:0},I=["minlen","weight","width","height","labeloffset"],D={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},A=["labelpos"];function L(S){let V=new p({multigraph:!0,compound:!0}),q=B(S.graph());return V.setGraph(Object.assign({},x,Q(q,v),u.pick(q,b))),S.nodes().forEach(H=>{let Z=B(S.node(H)),J=Q(Z,k);Object.keys(N).forEach(le=>{J[le]===void 0&&(J[le]=N[le])}),V.setNode(H,J),V.setParent(H,S.parent(H))}),S.edges().forEach(H=>{let Z=B(S.edge(H));V.setEdge(H,Object.assign({},D,Q(Z,I),u.pick(Z,A)))}),V}function M(S){let V=S.graph();V.ranksep/=2,S.edges().forEach(q=>{let H=S.edge(q);H.minlen*=2,H.labelpos.toLowerCase()!=="c"&&(V.rankdir==="TB"||V.rankdir==="BT"?H.width+=H.labeloffset:H.height+=H.labeloffset)})}function $(S){S.edges().forEach(V=>{let q=S.edge(V);if(q.width&&q.height){let H=S.node(V.v),Z={rank:(S.node(V.w).rank-H.rank)/2+H.rank,e:V};u.addDummyNode(S,"edge-proxy",Z,"_ep")}})}function z(S){let V=0;S.nodes().forEach(q=>{let H=S.node(q);H.borderTop&&(H.minRank=S.node(H.borderTop).rank,H.maxRank=S.node(H.borderBottom).rank,V=Math.max(V,H.maxRank))}),S.graph().maxRank=V}function j(S){S.nodes().forEach(V=>{let q=S.node(V);q.dummy==="edge-proxy"&&(S.edge(q.e).labelRank=q.rank,S.removeNode(V))})}function O(S){let V=Number.POSITIVE_INFINITY,q=0,H=Number.POSITIVE_INFINITY,Z=0,J=S.graph(),le=J.marginx||0,te=J.marginy||0;function X(ie){let de=ie.x,se=ie.y,ge=ie.width,ue=ie.height;V=Math.min(V,de-ge/2),q=Math.max(q,de+ge/2),H=Math.min(H,se-ue/2),Z=Math.max(Z,se+ue/2)}S.nodes().forEach(ie=>X(S.node(ie))),S.edges().forEach(ie=>{let de=S.edge(ie);Object.hasOwn(de,"x")&&X(de)}),V-=le,H-=te,S.nodes().forEach(ie=>{let de=S.node(ie);de.x-=V,de.y-=H}),S.edges().forEach(ie=>{let de=S.edge(ie);de.points.forEach(se=>{se.x-=V,se.y-=H}),Object.hasOwn(de,"x")&&(de.x-=V),Object.hasOwn(de,"y")&&(de.y-=H)}),J.width=q-V+le,J.height=Z-H+te}function _(S){S.edges().forEach(V=>{let q=S.edge(V),H=S.node(V.v),Z=S.node(V.w),J,le;q.points?(J=q.points[0],le=q.points[q.points.length-1]):(q.points=[],J=Z,le=H),q.points.unshift(u.intersectRect(H,J)),q.points.push(u.intersectRect(Z,le))})}function T(S){S.edges().forEach(V=>{let q=S.edge(V);if(Object.hasOwn(q,"x"))switch((q.labelpos==="l"||q.labelpos==="r")&&(q.width-=q.labeloffset),q.labelpos){case"l":q.x-=q.width/2+q.labeloffset;break;case"r":q.x+=q.width/2+q.labeloffset;break}})}function R(S){S.edges().forEach(V=>{let q=S.edge(V);q.reversed&&q.points.reverse()})}function P(S){S.nodes().forEach(V=>{if(S.children(V).length){let q=S.node(V),H=S.node(q.borderTop),Z=S.node(q.borderBottom),J=S.node(q.borderLeft[q.borderLeft.length-1]),le=S.node(q.borderRight[q.borderRight.length-1]);q.width=Math.abs(le.x-J.x),q.height=Math.abs(Z.y-H.y),q.x=J.x+q.width/2,q.y=H.y+q.height/2}}),S.nodes().forEach(V=>{S.node(V).dummy==="border"&&S.removeNode(V)})}function W(S){S.edges().forEach(V=>{if(V.v===V.w){var q=S.node(V.v);q.selfEdges||(q.selfEdges=[]),q.selfEdges.push({e:V,label:S.edge(V)}),S.removeEdge(V)}})}function Y(S){var V=u.buildLayerMatrix(S);V.forEach(q=>{var H=0;q.forEach((Z,J)=>{var le=S.node(Z);le.order=J+H,(le.selfEdges||[]).forEach(te=>{u.addDummyNode(S,"selfedge",{width:te.label.width,height:te.label.height,rank:le.rank,order:J+ ++H,e:te.e,label:te.label},"_se")}),delete le.selfEdges})})}function F(S){S.nodes().forEach(V=>{var q=S.node(V);if(q.dummy==="selfedge"){var H=S.node(q.e.v),Z=H.x+H.width/2,J=H.y,le=q.x-Z,te=H.height/2;S.setEdge(q.e,q.label),S.removeNode(V),q.label.points=[{x:Z+2*le/3,y:J-te},{x:Z+5*le/6,y:J-te},{x:Z+le,y:J},{x:Z+5*le/6,y:J+te},{x:Z+2*le/3,y:J+te}],q.label.x=q.x,q.label.y=q.y}})}function Q(S,V){return u.mapValues(u.pick(S,V),Number)}function B(S){var V={};return S&&Object.entries(S).forEach(([q,H])=>{typeof q=="string"&&(q=q.toLowerCase()),V[q]=H}),V}}),uh=Pe((e,n)=>{var s=Ge(),r=zt().Graph;n.exports={debugOrdering:i};function i(o){let a=s.buildLayerMatrix(o),c=new r({compound:!0,multigraph:!0}).setGraph({});return o.nodes().forEach(l=>{c.setNode(l,{label:l}),c.setParent(l,"layer"+o.node(l).rank)}),o.edges().forEach(l=>c.setEdge(l.v,l.w,{},l.name)),a.forEach((l,d)=>{let h="layer"+d;c.setNode(h,{rank:"same"}),l.reduce((f,m)=>(c.setEdge(f,m,{style:"invis"}),m))}),c}}),fh=Pe((e,n)=>{n.exports="2.0.4"}),hh=Pe((e,n)=>{n.exports={graphlib:zt(),layout:dh(),debug:uh(),util:{time:Ge().time,notime:Ge().notime},version:fh()}});const Ma=hh();const Ia={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"}},mh={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function gh({data:e}){const{t:n}=Oe(["work","common"]),{task:s,agentName:r,selected:i,direction:o="TB",isExpandedRoot:a,onCollapse:c}=e,l=Ia[s.status]??Ia.pending,d=s.taskType==="scheduled"&&!!s.scheduleConfig,h=d?s.scheduleConfig.every?n("work:task.everyInterval",{interval:s.scheduleConfig.every}):s.scheduleConfig.cron?n("work:task.cronLabel"):"":"",f=o==="LR"?be.Left:be.Top,m=o==="LR"?be.Right:be.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?`${l.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${l.bg} ${l.border}`} ${i?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[t.jsx(fn,{type:"target",position:f,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 ${mh[s.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${l.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"})}),h]})]}),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&&c&&t.jsx("button",{onClick:u=>{u.stopPropagation(),c()},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 Ta={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"}},Ra={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function ph({data:e}){const{t:n}=Oe(["work","common"]),{req:s,selected:r,direction:i="TB",isExpandedRoot:o,onCollapse:a}=e,c=Ta[s.status]??Ta.pending,l=i==="LR"?be.Left:be.Top,d=i==="LR"?be.Right:be.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 ${c.bg} ${c.border} ${r?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[t.jsx(fn,{type:"target",position:l,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 ${c.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:h=>{h.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 xh={task:gh,requirement:ph};function bh({nodeIds:e,rfRef:n}){const s=ff();return g.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 yh=()=>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,vh=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 wh(){return g.useSyncExternalStore(vh,yh,()=>!1)}const Ur=200,Qr=80;function _a(e,n,s="TB"){const r=o=>{const a=new Ma.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:o,nodesep:40,ranksep:60});for(const c of e)a.setNode(c.id,{width:Ur,height:Qr});for(const c of n)a.setEdge(c.source,c.target);return Ma.layout(a),e.map(c=>{const l=a.node(c.id);return{...c,position:{x:(l?.x??0)-Ur/2,y:(l?.y??0)-Qr/2}}})},i=r(s);if(n.length>0&&e.length>4){let o=1/0,a=-1/0,c=1/0,l=-1/0;for(const m of i)o=Math.min(o,m.position.x),a=Math.max(a,m.position.x+Ur),c=Math.min(c,m.position.y),l=Math.max(l,m.position.y+Qr);const d=a-o,h=l-c,f=s==="TB"?"LR":"TB";if(d>h*3)return{nodes:r(f),direction:f}}return{nodes:i,direction:s}}function kh(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 c=new Set,l=[a.id];for(;l.length>0;){const d=l.pop();if(!i.has(d)){i.add(d),c.add(d);for(const h of s.get(d)??[])i.has(h)||l.push(h)}}o.push({nodes:e.filter(d=>c.has(d.id)),edges:n.filter(d=>c.has(d.source)&&c.has(d.target))})}return o}function La(e,n){if(e.length===0)return{nodes:[],direction:"TB"};const s=kh(e,n);if(s.length===1)return _a(e,n);let r="TB";const i=s.map(m=>{const{nodes:u,direction:p}=_a(m.nodes,m.edges);r=p;let E=1/0,C=-1/0,y=1/0,v=-1/0;for(const x of u)E=Math.min(E,x.position.x),C=Math.max(C,x.position.x+Ur),y=Math.min(y,x.position.y),v=Math.max(v,x.position.y+Qr);for(const x of u)x.position.x-=E,x.position.y-=y;return{nodes:u,w:C-E,h:v-y}});i.sort((m,u)=>u.h-m.h);const o=60,a=i.reduce((m,u)=>m+(u.w+o)*(u.h+o),0),c=Math.sqrt(a)*1.1,l=[];let d=0,h=0,f=0;for(const m of i){d>0&&d+m.w>c&&(d=0,h+=f+o,f=0);for(const u of m.nodes)l.push({...u,position:{x:u.position.x+d,y:u.position.y+h}});d+=m.w+o,f=Math.max(f,m.h)}return{nodes:l,direction:r}}function jh(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 c of a.blockedBy)i.push(c)}return!1}const Vn=[{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(Vn.map(e=>e.id));const Yr=new Set(Vn.filter(e=>e.id!=="done").map(e=>e.id)),_s=e=>e.status==="archived";function Nh(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 c=s.get(a.slice(4));if(c)for(const l of c.taskIds)o.push(l)}else{const c=n.get(a);if(c?.blockedBy)for(const l of c.blockedBy)o.push(l);c?.requirementId&&o.push(`req-${c.requirementId}`)}}for(const a of r)a.requirementId&&i.has(a.id)&&i.add(`req-${a.requirementId}`);return i}function Ch({tasks:e,requirements:n=[],agents:s,showArchived:r,onShowArchivedChange:i,onTaskClick:o,onReqClick:a,onCollapseDAG:c,onDependencyChange:l,selectedTaskId:d,selectedReqId:h,hasDetailPanel:f,defaultExpandedNodeId:m,previewMode:u}){const{t:p}=Oe(["work","common"]),E=wh(),[C,y]=g.useState(null),[v,x]=g.useState(null),[b,k]=g.useState(()=>new Set(Yr)),[N,I]=g.useState(m??null),[D,A]=g.useState(r??!1),L=r??D,M=g.useCallback(fe=>{const re=typeof fe=="function"?fe(L):fe;A(re),i?.(re)},[L,i]);g.useEffect(()=>{r!==void 0&&A(r)},[r]),g.useEffect(()=>{m&&I(m)},[m]);const $=g.useMemo(()=>e.filter(fe=>_s(fe)).length,[e]),z=g.useMemo(()=>{const fe=new Set;for(const re of Vn)if(b.has(re.id))for(const xe of re.statuses)fe.add(xe);return fe},[b]),j=g.useMemo(()=>{const fe=new Set;for(const re of e)for(const xe of Vn)if(xe.statuses.has(re.status)){fe.add(xe.id);break}for(const re of n){const xe=Ra[re.status];xe&&fe.add(xe)}return Vn.filter(re=>fe.has(re.id))},[e,n]),O=g.useCallback(fe=>{k(re=>{const xe=new Set(re);return xe.has(fe)?xe.delete(fe):xe.add(fe),xe})},[]),_=g.useCallback((fe,re="success")=>{y({msg:fe,type:re}),setTimeout(()=>y(null),2500)},[]),T=g.useMemo(()=>{const fe=new Map;for(const re of s)fe.set(re.id,re.name);return fe},[s]),R=g.useMemo(()=>{const fe=new Map;for(const re of e)fe.set(re.id,re);return fe},[e]),P=g.useMemo(()=>{const fe=new Map;for(const re of n)fe.set(re.id,re);return fe},[n]),W=g.useRef(!1),Y=g.useCallback(()=>{W.current=!1,I(null),c?.()},[c]),F=E?"#94a3b8":"#6b7280",Q=g.useCallback((fe,re,xe)=>({id:`${fe}->${re}`,source:fe,target:re,animated:xe==="blocked",markerEnd:{type:Gn.ArrowClosed,width:14,height:14,color:xe==="blocked"?"#ef4444":F},style:{stroke:xe==="blocked"?"#ef4444":F,strokeWidth:1.5,cursor:"pointer"}}),[F]),{initialNodes:B,initialEdges:S,topLevelIds:V}=g.useMemo(()=>{const fe=(we,Qe)=>{const it=new Set,bt=we.map(Ne=>(it.add(Ne.id),{id:Ne.id,type:"task",data:{task:Ne,agentName:Ne.assignedAgentId?T.get(Ne.assignedAgentId):void 0,selected:Ne.id===d},position:{x:0,y:0}}));for(const Ne of Qe){const Ce=`req-${Ne.id}`;it.add(Ce),bt.push({id:Ce,type:"requirement",data:{req:Ne,selected:Ne.id===h},position:{x:0,y:0}})}const Je=[];for(const Ne of we)if(Ne.blockedBy)for(const Ce of Ne.blockedBy)it.has(Ce)&&Je.push(Q(Ce,Ne.id,Ne.status));const St=new Set,Ft=(Ne,Ce)=>{const De=`${Ne}->${Ce}`;St.has(De)||(St.add(De),Je.push({id:De,source:Ne,target:Ce,markerEnd:{type:Gn.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ne of Qe){const Ce=`req-${Ne.id}`;for(const De of Ne.taskIds)it.has(De)&&Ft(Ce,De)}for(const Ne of we)if(Ne.requirementId){const Ce=`req-${Ne.requirementId}`;it.has(Ce)&&Ft(Ce,Ne.id)}return{nodes:bt,edges:Je}},re=e.filter(we=>z.has(we.status)&&(L||!_s(we))),xe=new Set;for(const we of Vn)b.has(we.id)&&xe.add(we.id);const Ee=n.filter(we=>{const Qe=Ra[we.status];return Qe&&xe.has(Qe)}),ye=new Set(["completed","rejected","cancelled","archived"]),Le=new Set(Ee.filter(we=>!ye.has(we.status)).map(we=>we.id)),gt=new Set;for(const we of n)if(Le.has(we.id))for(const Qe of we.taskIds)gt.add(Qe);const ct=e.filter(we=>gt.has(we.id)&&(L||!_s(we))),Nt=[...new Map([...re,...ct].map(we=>[we.id,we])).values()],{nodes:pt,edges:tt}=fe(Nt,Ee),Ht=new Set;for(const we of tt)Ht.add(we.target);const dt=new Set(pt.filter(we=>!Ht.has(we.id)).map(we=>we.id));if(!N||!dt.has(N)){const we=pt,{nodes:Qe,direction:it}=La(we,tt);return{initialNodes:Qe.map(Je=>({...Je,data:{...Je.data,direction:it}})),initialEdges:tt,topLevelIds:dt}}const{nodes:Jt,edges:xt}=fe(e,n),nt=Nh(N,R,P,e),qt=Jt.filter(we=>nt.has(we.id)).map(we=>we.id===N?{...we,data:{...we.data,isExpandedRoot:!0,onCollapse:Y}}:we),at=xt.filter(we=>nt.has(we.source)&&nt.has(we.target)),{nodes:Fe,direction:$e}=La(qt,at);return{initialNodes:Fe.map(we=>({...we,data:{...we.data,direction:$e}})),initialEdges:at,topLevelIds:dt}},[e,n,T,R,P,Q,z,b,L,d,h,N,Y]),[q,H,Z]=hf(B),[J,le,te]=mf(S),X=g.useRef(null),ie=g.useRef({groupFilter:b,showArchived:L});g.useEffect(()=>{const fe=ie.current;(fe.groupFilter!==b||fe.showArchived!==L)&&(W.current=!1,I(null),ie.current={groupFilter:b,showArchived:L})},[b,L]),g.useEffect(()=>{H(B),le(S),W.current||requestAnimationFrame(()=>{X.current?.fitView({padding:.2,duration:300})})},[B,S,H,le]),g.useEffect(()=>{const fe=setTimeout(()=>{X.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(fe)},[f]);const de=g.useCallback(fe=>{fe&&(W.current=!0)},[]),se=g.useCallback((fe,re)=>{if(!N&&V.has(re.id)&&(W.current=!1,I(re.id)),re.id.startsWith("req-")){const xe=P.get(re.id.slice(4));xe&&a&&a(xe)}else{const xe=R.get(re.id);xe&&o&&o(xe)}},[R,P,o,a,V,N]),ge=g.useCallback(async fe=>{const{source:re,target:xe}=fe;if(!re||!xe||re===xe)return;const Ee=R.get(xe);if(!Ee)return;if(Ee.blockedBy?.includes(re)){_(p("work:dag.toast.dependencyExists"),"error");return}if(jh(R,re,xe)){_(p("work:dag.toast.cycleError"),"error");return}const ye=[...Ee.blockedBy??[],re];try{await ae.tasks.update(xe,{blockedBy:ye}),_(p("work:dag.toast.dependencyAdded")),l?.()}catch(Le){_(p("work:dag.toast.failed",{message:Le instanceof Error?Le.message:String(Le)}),"error")}},[R,_,l,p]),ue=g.useCallback((fe,re)=>{x(re)},[]),K=g.useCallback(async()=>{if(!v)return;const fe=R.get(v.target);if(!fe){x(null);return}const re=(fe.blockedBy??[]).filter(xe=>xe!==v.source);try{await ae.tasks.update(v.target,{blockedBy:re}),_(p("work:dag.toast.dependencyRemoved")),l?.()}catch(xe){_(p("work:dag.toast.failed",{message:xe instanceof Error?xe.message:String(xe)}),"error")}x(null)},[v,R,_,l,p]);if(e.length===0)return t.jsx("div",{className:"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:p("work:task.dagEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:p("work:task.dagEmptyDesc")})]})});const ce=b.size===Yr.size&&[...Yr].every(fe=>b.has(fe))&&!L,pe=v?R.get(v.source):null,ve=v?R.get(v.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(uf,{nodes:q,edges:J,onNodesChange:Z,onEdgesChange:te,onNodeClick:se,onConnect:ge,onEdgeClick:ue,onMoveEnd:de,onInit:fe=>{X.current=fe},nodeTypes:xh,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[u&&t.jsx(bh,{nodeIds:q.map(fe=>fe.id),rfRef:X}),t.jsx(yf,{color:E?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(Sf,{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(Of,{nodeColor:fe=>{const re=fe.data?.task,xe=re?.status;return re?.taskType==="scheduled"?"#8b8fa3":xe==="completed"||xe==="accepted"?"#10b981":xe==="in_progress"?"#f59e0b":xe==="blocked"||xe==="failed"?"#ef4444":E?"#94a3b8":"#6b7280"},maskColor:E?"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:[j.map(fe=>{const re=b.has(fe.id);return t.jsx("button",{onClick:()=>O(fe.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${re?`${fe.color.bg} ${fe.color.border} ${fe.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:p(`work:dag.filter.${fe.id}`)},fe.id)}),$>0&&t.jsx("button",{onClick:()=>M(fe=>!fe),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${L?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:p("work:dag.archivedToggle",{count:$})}),!ce&&t.jsx("button",{onClick:()=>{k(new Set(Yr)),M(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:p("work:dag.reset")})]}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[N?t.jsx("button",{onClick:Y,className:"text-brand-500 hover:text-brand-400 transition-colors",children:p("work:dag.backToOverview")}):t.jsx("span",{children:p("work:dag.expandHint")}),t.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),t.jsx("span",{children:p("work:dag.dragHint")})]})]}),C&&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 ${C.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:C.msg}),v&&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:fe=>fe.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:p("work:dag.removeDependencyTitle")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:p("work:dag.removeDependencyBody",{target:ve?.title??v.target.slice(-8),source:pe?.title??v.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:p("common:cancel")}),t.jsx("button",{onClick:K,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:p("common:remove")})]})]})})]})}function Sh({orgId:e,onCreated:n,onClose:s}){const{t:r}=Oe(["work","common"]);Vl(!0);const[i,o]=g.useState(""),[a,c]=g.useState(""),[l,d]=g.useState(""),[h,f]=g.useState("main"),[m,u]=g.useState([]),[p,E]=g.useState([]),[C,y]=g.useState(!1),[v,x]=g.useState(""),[b,k]=g.useState(!1),N=vr();g.useEffect(()=>{ae.teams.list().then(A=>E(A.teams)).catch(()=>{})},[]),g.useEffect(()=>{const A=L=>{L.key==="Escape"&&s()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[s]);const I=g.useCallback(async A=>{if(A?.preventDefault(),k(!0),!(!i.trim()||C)){y(!0),x("");try{const L=l.trim()?[{url:l.trim(),defaultBranch:h.trim()||"main"}]:[],M=await ae.projects.create({name:i.trim(),description:a.trim()||void 0,repositories:L.length>0?L:void 0,teamIds:m.length>0?m:void 0,orgId:e??"default"});n(M.project)}catch(L){x(L instanceof Error?L.message:r("project.failedToCreate"))}y(!1)}},[i,a,l,h,m,e,C,n,r]),D=b&&!i.trim();return Fl.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 ${N?"w-full":"w-[520px]"}`,onClick:A=>A.stopPropagation(),onSubmit:I,children:[t.jsx("h3",{className:"text-base font-semibold mb-5",children:r("project.newProject")}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.projectName")}),t.jsx("input",{value:i,onChange:A=>{o(A.target.value),x("")},onBlur:()=>k(!0),placeholder:r("project.projectNamePlaceholder"),className:`input ${D?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!N}),D&&t.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:r("project.projectNameRequired")})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.description")}),t.jsx("textarea",{value:a,onChange:A=>c(A.target.value),placeholder:r("project.descriptionPlaceholder"),className:"input",rows:3})]}),p.length>0&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.assignTeams")}),t.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:p.map(A=>{const L=m.includes(A.id);return t.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer hover:text-fg-primary py-0.5",children:[t.jsx("input",{type:"checkbox",checked:L,onChange:()=>u(M=>L?M.filter($=>$!==A.id):[...M,A.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:A.name})]},A.id)})})]}),t.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.repositoryUrl")}),t.jsx("input",{value:l,onChange:A=>d(A.target.value),placeholder:r("project.repositoryPlaceholder"),className:"input"})]}),l.trim()&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.branch")}),t.jsx("input",{value:h,onChange:A=>f(A.target.value),placeholder:r("project.branchPlaceholder"),className:"input !w-24"})]})]}),v&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:v}),t.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||C,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:r(C?"common:creating":"project.createProject")})]})]})]})}),document.body)}function Eh({projects:e,selectedProjectId:n,allSelected:s,taskCounts:r,totalTaskCount:i,onSelectAll:o,onSelectProject:a,onEditProject:c,onCreateProject:l,onCollapse:d,width:h,onResizeStart:f,hidden:m,focused:u,onActivate:p}){const{t:E}=Oe(["work","common"]),C=s??n==null;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-keyboard-pane":"l1",onPointerDown:()=>p?.(),className:"bg-surface-primary flex flex-col shrink-0 border-r border-border-default/60",style:m?{display:"none"}:h!=null?{width:h}: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:E("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:E("work:task.projects",{defaultValue:"Projects"})}),t.jsx("button",{type:"button","data-no-drag":!0,onClick:l,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:E("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:E("work:task.emptyNoProjectsHint")}),t.jsx("button",{type:"button",onClick:l,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:E("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 ${C?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 ${C?"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:E("work:task.all")})}),(i??0)>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:i})]}),e.map(y=>{const v=!C&&y.id===n,x=r[y.id]??0,b=y.status==="paused";return t.jsxs("div",{role:"button",tabIndex:0,"data-project-id":y.id,onClick:()=>a(y.id),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),a(y.id))},className:`group w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left cursor-pointer transition-colors ${v?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 ${v?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:y.name[0]?.toUpperCase()??"?"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block text-[12px] font-medium truncate",children:y.name}),b&&t.jsx("span",{className:"block text-[10px] text-amber-500/80",children:E("work:project.statusPaused")})]}),c&&t.jsx("button",{type:"button","data-no-drag":!0,title:E("work:project.editProject"),"aria-label":E("work:project.editProject"),onClick:k=>{k.stopPropagation(),c(y.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})]},y.id)})]})})]}),!m&&f&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:f,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 Mh({project:e,onUpdateProject:n}){const{t:s}=Oe(["work","common"]),r=e.knowledgeBasePaths??[],[i,o]=g.useState(""),[a,c]=g.useState(!1),[l,d]=g.useState(!1),[h,f]=g.useState([]),[m,u]=g.useState(null),[p,E]=g.useState(null),C=g.useCallback(async()=>{if(e.id){d(!0);try{const{results:D}=await ae.deliverables.search({projectId:e.id,source:"knowledge",limit:200});f(D)}catch(D){u({type:"error",text:`${s("work:project.kbLoadFailed")}: ${String(D)}`})}finally{d(!1)}}},[e.id,s]);g.useEffect(()=>{C()},[C]);const y=async()=>{const D=i.trim();if(!(!D||a))try{const A=[...new Set([...r,D])];await n({knowledgeBasePaths:A}),o(""),await k()}catch(A){u({type:"error",text:`${s("work:project.kbPathsSaveFailed")}: ${String(A)}`})}},v=async()=>{const D=p;if(!D||a)return;E(null);const A=r.filter(L=>L!==D);await n({knowledgeBasePaths:A}),await k(A)},x=typeof window<"u"&&!!window.markusDesktop?.selectDirectory,b=async()=>{try{const D=await window.markusDesktop?.selectDirectory?.(s("work:project.kbBrowseTitle"));D&&o(D)}catch(D){u({type:"error",text:`${s("work:project.kbBrowseFailed")}: ${String(D)}`})}},k=async D=>{if(!a){c(!0),u(null);try{const A=await ae.projects.syncKnowledge(e.id,D&&D.length?D:void 0);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 C()}catch(A){u({type:"error",text:`${s("work:project.kbSyncFailed")}: ${String(A)}`})}finally{c(!1)}}},N=async()=>{await k(r.length?r:void 0)},I=D=>{Ot.navigate(Ve.DELIVERABLES,{projectId:e.id,source:"knowledge",...D?{openDeliverable:D}:{}})};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:()=>I(),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:N,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")})]})]}),p&&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:p})}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx("button",{type:"button",onClick:()=>E(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:()=>{v()},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((D,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:D,children:D}),t.jsx("button",{type:"button",onClick:()=>E(D),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"})]})})]},`${D}-${A}`)),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:i,onChange:D=>o(D.target.value),onKeyDown:D=>{D.key==="Enter"&&y()},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:y,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"),h.length>0&&t.jsxs("span",{className:"ml-1 text-fg-quaternary",children:["(",h.length,")"]})]}),l?t.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("work:project.kbLoadingDocs")}):h.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:h.map(D=>t.jsxs("button",{type:"button",onClick:()=>I(D.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:D.reference??D.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:D.format??"file"}),t.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 min-w-0 group-hover:text-brand-500",children:D.title}),t.jsx("span",{className:"text-[10px] text-fg-quaternary shrink-0",children:"→"})]},D.id))})]})]})}const Da="markus_work_l1_collapsed",Ih=["backlog","kanban","dag","workflows"];function so(e){const n=e.agentId,s=e.activityId;return!n||!s?null:Ja({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},s,n)}function oo(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 ao({entries:e}){const[n,s]=g.useState("compact");return e.length===0?null:t.jsx("div",{onClick:r=>r.stopPropagation(),children:n==="compact"?t.jsx(Ul,{entries:e,isActive:!0,onExpand:()=>s("full"),embedded:!0}):t.jsx(ei,{entries:e,isActive:!0,onCollapse:()=>s("compact"),embedded:!0})})}function io(e,n){const[s,r]=g.useState(null);return g.useEffect(()=>{if(!n||!e.current){r(null);return}const i=()=>{const o=e.current?.getBoundingClientRect();if(!o)return;const a=240,c=window.innerHeight-o.bottom-8,l=o.top-8,d=c<a&&l>c;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 cr({options:e,value:n,onChange:s,placeholder:r,noMatchesText:i,className:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=io(f,a);g.useEffect(()=>{const y=v=>{h.current&&!h.current.contains(v.target)&&u.current&&!u.current.contains(v.target)&&c(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]);const E=e.find(y=>y.value===n)?.label??"",C=l?e.filter(y=>y.label.toLowerCase().includes(l.toLowerCase())):e;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!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:l,onChange:y=>d(y.target.value),onClick:y=>y.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:E||r,autoFocus:!0}):t.jsx("span",{className:E?"text-fg-primary":"text-fg-tertiary",children:E||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&&p&&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:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:C.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):C.map(y=>t.jsx("div",{onClick:()=>{s(y.value),c(!1),d("")},className:`px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 ${y.value===n?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:y.label},y.value))})]})}function Th({options:e,selected:n,onAdd:s,placeholder:r,noMatchesText:i,className:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=io(f,a);g.useEffect(()=>{const y=v=>{h.current&&!h.current.contains(v.target)&&u.current&&!u.current.contains(v.target)&&c(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]);const E=e.filter(y=>!n.includes(y.value)),C=l?E.filter(y=>y.label.toLowerCase().includes(l.toLowerCase())):E;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!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:l,onChange:y=>d(y.target.value),onClick:y=>y.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&&p&&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:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:C.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):C.map(y=>t.jsx("div",{onClick:()=>{s(y.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:y.label},y.value))})]})}function Rh({options:e,onSelect:n,placeholder:s,noMatchesText:r,className:i,itemSuffix:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=io(f,a);g.useEffect(()=>{const C=y=>{h.current&&!h.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&c(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]);const E=l?e.filter(C=>C.label.toLowerCase().includes(l.toLowerCase())):e;return t.jsxs("div",{ref:h,className:i??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!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:l,onChange:C=>d(C.target.value),onClick:C=>C.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&&p&&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:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:E.length===0?t.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:r??"No matches"}):E.map(C=>t.jsxs("div",{onClick:()=>{n(C.value),c(!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:C.label}),o?.(C)]},C.value))})]})}function Qn(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 _h({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=Oe(["work","common"]),[o,a]=g.useState(!1),[c,l]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{l(e)},[e]),g.useEffect(()=>{o&&d.current?.focus()},[o]);const h=async()=>{a(!1);const f=c.trim();if(f&&f!==e)try{await n(f)}catch{l(e)}else l(e)};return o?t.jsx("input",{ref:d,value:c,onChange:f=>l(f.target.value),onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&h(),f.key==="Escape"&&(l(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 Lh({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=Oe(["work","common"]),[o,a]=g.useState(!1),[c,l]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{l(e)},[e]),g.useEffect(()=>{o&&d.current&&(d.current.focus(),d.current.style.height="auto",d.current.style.height=d.current.scrollHeight+"px")},[o]);const h=async()=>{a(!1);const f=c.trim();if(f!==e)try{await n(f)}catch{l(e)}else l(e)};return o?t.jsx("textarea",{ref:d,value:c,onChange:f=>{l(f.target.value),f.target.style.height="auto",f.target.style.height=f.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Escape"&&(l(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 Dh=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function bl(e){const n=e.match(Dh);return n?{timestamp:n[1].trim(),author:n[2]?.trim()??"System",content:n[3].trim()}:{timestamp:"",author:"",content:e}}function Ah(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],c=+s[4],l=+s[5],d=new Date(i,o,a,c,l),h=r.getTime()-d.getTime();return h<6e4?n("work:relative.justNow"):h<36e5?n("work:relative.minutesAgo",{count:Math.floor(h/6e4)}):h<864e5?n("work:relative.hoursAgo",{count:Math.floor(h/36e5)}):h<6048e5?n("work:relative.daysAgo",{count:Math.floor(h/864e5)}):`${i}-${String(o+1).padStart(2,"0")}-${String(a).padStart(2,"0")}`}const Aa=[{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 Ph(e){let n=0;for(let s=0;s<e.length;s++)n=(n<<5)-n+e.charCodeAt(s)|0;return Aa[Math.abs(n)%Aa.length]}function $h({note:e,compact:n}){const{t:s}=Oe(["work","common"]),r=bl(e),i=s("work:task.systemAuthor"),o=Ph(r.author||i),a=r.author?r.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",c=Ah(r.timestamp,s),l=!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 ${l?"text-fg-tertiary":o.text}`,children:l?i:r.author}),c&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:c})]}),t.jsx("div",{className:"text-xs text-fg-secondary",children:t.jsx(fr,{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 ${l?"text-fg-secondary":o.text}`,children:l?i:r.author}),c&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:c})]}),t.jsx("div",{className:"px-3 py-2.5",children:t.jsx(fr,{content:r.content,className:"text-xs text-fg-secondary"})})]})})]})}const Bh=new Set(["rejected","cancelled","archived"]),ss=[{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"}],Pa={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"},$a={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"},Ba={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"},Oa={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 yl(e){return Object.keys($a).reduce((n,s)=>(n[s]={label:e(`work:status.task.${s}`),cls:$a[s]},n),{})}function vl(e){return Object.keys(Pa).reduce((n,s)=>(n[s]={label:e(`work:status.sub.${s}`),cls:Pa[s]},n),{})}function Oh(e){return Object.keys(Ba).reduce((n,s)=>(n[s]={label:e(`work:priority.${s}`),cls:Ba[s]},n),{})}function lo(e){return Object.keys(Oa).reduce((n,s)=>(n[s]={label:e(`work:status.requirement.${s}`),cls:Oa[s]},n),{})}const za=["low","medium","high","urgent"],Ha=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],qa=["pending","in_progress","completed","rejected","cancelled"],Wa={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([])},Ws={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},yr={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"},Va={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function zh({agent:e,anchorRect:n,onClose:s}){const{t:r}=Oe(["work","common"]),i=g.useRef(null);g.useEffect(()=>{const c=l=>{i.current&&!i.current.contains(l.target)&&s()};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s]);const o=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",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(),Ot.navigate(Ve.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 ur({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"}),c=o.toLocaleDateString([],{month:"short",day:"numeric"}),[l,d]=g.useState(null),[h,f]=g.useState(!1),[m,u]=g.useState([]),[p,E]=g.useState(!1),C=g.useCallback((k,N)=>{const I=n.find(D=>D.name.toLowerCase()===k.toLowerCase());if(I){const D=N.target.getBoundingClientRect();d({agent:I,top:D.bottom,left:D.left})}},[n]),y=g.useMemo(()=>n.map(k=>k.name),[n]),v=g.useCallback(k=>{const N=n.find(I=>I.name.toLowerCase()===e.authorName.toLowerCase());if(N){const I=k.currentTarget.getBoundingClientRect();d({agent:N,top:I.bottom,left:I.left})}},[n,e.authorName]),x=g.useCallback(async()=>{if(h){f(!1);return}const k=e.activityId;if(k&&(f(!0),!(m.length>0))){E(!0);try{const{logs:N}=await ae.agents.getActivityLogs(e.authorId,k),I=N.map(D=>Ja(D,k,e.authorId)).filter(D=>D!==null).map(D=>({...D,ts:new Date(D.createdAt).getTime()}));u(I)}catch{}E(!1)}},[h,m.length,e]),b=g.useMemo(()=>As(m.map(Ds).filter(k=>k!==null)),[m]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[t.jsx("div",{onClick:v,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:v,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[c," ",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(h?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&t.jsxs("button",{onClick:()=>{const k=document.getElementById(`comment-${e.replyTo}`);k&&(k.scrollIntoView({behavior:"smooth",block:"center"}),k.classList.add("bg-brand-500/10"),setTimeout(()=>k.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[t.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),t.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),t.jsx(fr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:C,knownNames:y}),e.attachments?.map((k,N)=>k.type==="image"?t.jsx("img",{src:k.url,alt:k.name,className:"mt-1 max-w-[200px] rounded"},N):null),h&&t.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:p?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(ei,{entries:m,isActive:!1,onCollapse:()=>f(!1),embedded:!0})})]}),l&&t.jsx(zh,{agent:l.agent,anchorRect:{top:l.top,left:l.left},onClose:()=>d(null)})]})}function Hh({task:e,agents:n,users:s,authUser:r}){const{t:i}=Oe(["work","common"]),[o,a]=g.useState([]),[c,l]=g.useState([]),d=g.useRef(null),[h,f]=g.useState(new Map);g.useEffect(()=>{l([]),f(new Map),d.current&&(clearTimeout(d.current),d.current=null),ae.tasks.getComments(e.id).then(y=>a(y.comments)).catch(()=>{})},[e.id]),g.useEffect(()=>jt.on("task:comment",v=>{if(v.payload?.taskId===e.id&&v.payload.comment){const x=v.payload.comment;a(b=>b.some(k=>k.id===x.id)?b:[...b,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(l(b=>{const k=b.filter(N=>N.id!==x.authorId);return k.length===0&&d.current&&(clearTimeout(d.current),d.current=null),k}),f(b=>{const k=new Map(b);return k.delete(x.authorId),k}))}}),[e.id]),g.useEffect(()=>{if(c.length===0)return;const y=new Set(c.map(x=>x.id));return jt.on("agent:activity_log",x=>{const b=x.payload;if(!b)return;const k=b.agentId;if(!y.has(k))return;const N=so(b);N&&f(I=>oo(I,k,N))})},[c]);const m=g.useMemo(()=>{const y=[];for(const v of e.notes??[]){const x=bl(v);let b;if(x.timestamp){const k=x.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);b=k?new Date(+k[1],+k[2]-1,+k[3],+k[4],+k[5],+(k[6]??0)):new Date(0)}else b=new Date(0);y.push({type:"note",note:v,ts:b})}for(const v of o)y.push({type:"comment",comment:v,ts:new Date(v.createdAt)});return y.sort((v,x)=>v.ts.getTime()-x.ts.getTime()),y},[e.notes,o]),[u,p]=g.useState(null),E=async(y,v,x,b)=>{let k;x.length>0&&(k=(await ae.uploads.upload(x.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await ae.tasks.addComment(e.id,y,r?.name,k,r?.id,v.length>0?v:void 0,b);const N=[],I=new Set,D=A=>{if(I.has(A)||A===r?.id)return;I.add(A);const L=n.find(M=>M.id===A);L&&N.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const A of v){const L=n.find(M=>M.name.toLowerCase()===A.toLowerCase());L&&D(L.id)}e.assignedAgentId&&D(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&D(e.createdBy),N.length>0&&(d.current&&clearTimeout(d.current),l(N),d.current=setTimeout(()=>l([]),12e4))},C=g.useCallback(y=>{p({id:y.id,authorName:y.authorName,content:y.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((y,v)=>y.type==="note"?t.jsx($h,{note:y.note,compact:!0},`n-${v}`):t.jsx(ur,{comment:y.comment,agents:n,onReply:C},`c-${y.comment.id}`)),c.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(y=>{const v=h.get(y.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Ot.navigate(Ve.TEAM,{agentId:y.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Fs,{name:y.name,avatarUrl:y.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:y.name}),v.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:"→"})]}),v.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(ao,{entries:v})})]},y.id)})})]}),t.jsx(ni,{agents:n,humans:s,onSubmit:E,replyTo:u,onCancelReply:()=>p(null),placeholder:i("work:task.commentPlaceholder")})]})}function qh({task:e,isRunning:n,authUser:s,agents:r}){const i=e.id,{t:o}=Oe(["work","common"]),[a,c]=g.useState([]),[l,d]=g.useState(new Map),[h,f]=g.useState(new Set),[m,u]=g.useState([]),[p,E]=g.useState(""),[C,y]=g.useState(n),[v,x]=g.useState(!0),[b,k]=g.useState(new Set),[N,I]=g.useState(""),[D,A]=g.useState(!1),[L,M]=g.useState([]),$=g.useRef(null),[z,j]=g.useState(new Map),[O,_]=g.useState([]),[T,R]=g.useState([]),[P,W]=g.useState(!1),Y=g.useRef(null),F=g.useRef(null);g.useEffect(()=>{y(n)},[n]),g.useEffect(()=>{M([]),j(new Map),$.current&&(clearTimeout($.current),$.current=null)},[i]),g.useEffect(()=>{x(!0),Promise.all([ae.tasks.getLogsSummary(i).catch(()=>({rounds:[]})),ae.tasks.getComments(i).catch(()=>({comments:[]}))]).then(([X,ie])=>{const de=X.rounds;if(c(de),u(ie.comments),de.length===0){x(!1);return}const se=de[de.length-1].round;k(new Set([se])),ae.tasks.getLogs(i,se).catch(()=>({logs:[]})).then(ge=>{d(new Map([[se,ge.logs]])),x(!1)})})},[i]),g.useEffect(()=>{const X=e.assignedAgentId;X&&(W(!0),ae.agents.getActivities(X,{taskId:i,limit:20}).then(ie=>R(ie.activities)).catch(()=>R([])).finally(()=>W(!1)))},[i,e.assignedAgentId]);const Q=g.useCallback(X=>{l.has(X)||h.has(X)||(f(ie=>new Set(ie).add(X)),ae.tasks.getLogs(i,X).catch(()=>({logs:[]})).then(ie=>{d(de=>new Map(de).set(X,ie.logs)),f(de=>{const se=new Set(de);return se.delete(X),se})}))},[i,l,h]),B=g.useCallback(X=>{k(ie=>{const de=new Set(ie);return de.has(X)?de.delete(X):(de.add(X),l.has(X)||Q(X)),de})},[l,Q]);g.useEffect(()=>{const X=jt.on("task:log",se=>{const ge=se.payload;if(ge.taskId!==i)return;const ue={id:ge.id,taskId:ge.taskId,agentId:ge.agentId,seq:ge.seq,type:ge.logType,content:ge.content,metadata:ge.metadata,executionRound:ge.executionRound,createdAt:ge.createdAt},K=ue.executionRound??1;c(ce=>ce.find(ve=>ve.round===K)?ce:[...ce,{round:K,logCount:0,toolCount:0,firstAt:ue.createdAt,lastAt:ue.createdAt,status:"running"}]),k(ce=>ce.has(K)?ce:new Set(ce).add(K)),d(ce=>{const pe=ce.get(K)??[];return ue.id&&pe.some(ve=>ve.id===ue.id)?ce:new Map(ce).set(K,[...pe,ue])}),ue.type==="text"&&E(""),ue.type==="status"&&(ue.content==="started"||ue.content==="resumed"?y(!0):["completed","failed","cancelled","execution_finished"].includes(ue.content)&&(y(!1),c(ce=>ce.map(pe=>pe.round===K?{...pe,status:ue.content}:pe)))),ue.type==="error"&&y(!1)}),ie=jt.on("task:log:delta",se=>{const ge=se.payload;ge.taskId===i&&E(ue=>ue+ge.text)}),de=jt.on("task:comment",se=>{const ge=se.payload;if(ge.taskId!==i)return;const ue=ge.comment;u(K=>K.some(ce=>ce.id===ue.id)?K:[...K,ue]),(ue.authorType==="agent"||ue.authorId?.startsWith("agt_"))&&(M(K=>{const ce=K.filter(pe=>pe.id!==ue.authorId);return ce.length===0&&$.current&&(clearTimeout($.current),$.current=null),ce}),j(K=>{const ce=new Map(K);return ce.delete(ue.authorId),ce}))});return()=>{X(),ie(),de()}},[i]),g.useEffect(()=>{if(L.length===0)return;const X=new Set(L.map(de=>de.id));return jt.on("agent:activity_log",de=>{const se=de.payload;if(!se)return;const ge=se.agentId;if(!X.has(ge))return;const ue=so(se);ue&&j(K=>oo(K,ge,ue))})},[L]);const S=g.useMemo(()=>{const X=[];for(const[,ie]of l)X.push(...ie);return X.sort((ie,de)=>ie.seq-de.seq),X},[l]),V=g.useMemo(()=>S.map(X=>Do(X)),[S]),q=a.length>1,H=X=>{const ie=X.target.files;if(ie){for(const de of Array.from(ie)){if(!de.type.startsWith("image/"))continue;const se=new FileReader;se.onload=()=>{_(ge=>[...ge,{type:"image",url:se.result,name:de.name}])},se.readAsDataURL(de)}X.target.value=""}},Z=async()=>{if(!(!N.trim()&&O.length===0)){A(!0);try{let X;O.length>0&&(X=(await ae.uploads.upload(O.map(K=>({dataUrl:K.url,name:K.name})),"comments")).files.map(K=>({type:"image",url:K.url,name:K.name})));const ie=await ae.tasks.addComment(i,N,s?.name,X,s?.id);ie.comment&&u(ue=>ue.some(K=>K.id===ie.comment.id)?ue:[...ue,ie.comment]),I(""),_([]);const de=[],se=new Set,ge=ue=>{if(se.has(ue)||ue===s?.id)return;se.add(ue);const K=r.find(ce=>ce.id===ue);K&&de.push({id:K.id,name:K.name,avatarUrl:K.avatarUrl})};e.assignedAgentId&&ge(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&ge(e.createdBy),de.length>0&&($.current&&clearTimeout($.current),M(de),$.current=setTimeout(()=>M([]),12e4))}catch{}A(!1)}},J=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((X,ie)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:X.url,alt:X.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>_(de=>de.filter((se,ge)=>ge!==ie)),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:"×"})]},ie))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:N,onChange:X=>I(X.target.value),onKeyDown:X=>{X.key==="Enter"&&!X.shiftKey&&(X.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:Y,accept:"image/*",multiple:!0,onChange:H,className:"hidden"}),t.jsx("button",{onClick:()=>Y.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:o("work:task.attachImage"),children:"📎"}),t.jsx("button",{onClick:()=>{Z()},disabled:D||!N.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(v)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&&!p){const X=e.assignedAgentId?r.find(ve=>ve.id===e.assignedAgentId):void 0,ie=T.length>0,de=X&&X.currentTaskId&&X.currentTaskId!==e.id,se=e.status==="pending",ge=e.status==="in_progress",ue=!e.assignedAgentId;let K="📋",ce=o("work:task.emptyLogs.default"),pe=o("work:task.emptyLogs.defaultHint");return ue?(K="👤",ce=o("work:task.emptyLogs.noAgent"),pe=o("work:task.emptyLogs.noAgentHint")):se?(K="⏳",ce=o("work:task.emptyLogs.pending"),pe=o("work:task.emptyLogs.pendingHint")):ge&&de?(K="🔄",ce=o("work:task.emptyLogs.agentBusy",{agent:X?.name??e.assignedAgentId}),pe=o("work:task.emptyLogs.agentBusyHint")):ge&&(K="⏳",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:P?t.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:o("work:task.loadingLogs")}):ie?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:X?.name??o("work:task.agent"),count:T.length})]}),t.jsx("div",{className:"space-y-1.5",children:T.map(ve=>{const fe=!ve.endedAt,re=ve.type==="task"?"🔧":ve.type==="chat"||ve.type==="respond_in_session"?"💬":ve.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:()=>Ot.navigate(Ve.TEAM,{agentId:e.assignedAgentId}),children:[t.jsx("span",{className:"text-sm shrink-0",children:re}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary truncate",children:ve.label}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(ve.startedAt).toLocaleString(),ve.endedAt?` — ${ve.totalTools} tools, ${ve.totalTokens.toLocaleString()} tokens`:""]})]}),fe&&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")]}),!fe&&t.jsx("span",{className:`shrink-0 text-[10px] ${ve.success?"text-fg-tertiary":"text-red-400"}`,children:ve.success?"✓":"✗"}),t.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},ve.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:K}),t.jsxs("div",{className:"text-xs",children:[ce,t.jsx("br",{}),t.jsx("span",{className:"text-fg-muted",children:pe})]})]})})}),J]})}if(!q){const X=V.map(se=>Ds(se)).filter(se=>se!==null),ie=Ao(S,As(X)),de=[...ie.map(se=>({kind:"entry",entry:se,ts:se.timestamp?new Date(se.timestamp).getTime():0})),...m.map(se=>({kind:"comment",comment:se,ts:new Date(se.createdAt).getTime()}))];return de.sort((se,ge)=>se.ts-ge.ts),t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-0.5",children:[de.map((se,ge)=>se.kind==="comment"?t.jsx(ur,{comment:se.comment,agents:r},`c-${se.comment.id}`):t.jsx(Po,{entry:se.entry,showTime:!0,isLast:ge===de.length-1},`e-${ge}`)),C&&p&&t.jsx($o,{content:p}),C&&!p&&ie.length>0&&t.jsx(Bo,{})]}),J]})}const le=(X,ie)=>{const de=X.firstAt?new Date(X.firstAt).getTime():0,se=ie?.firstAt?new Date(ie.firstAt).getTime():1/0;return m.filter(ge=>{const ue=new Date(ge.createdAt).getTime();return ue>=de&&ue<se})},te=a.length>0?m.filter(X=>new Date(X.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:[te.length>0&&t.jsx("div",{className:"space-y-0.5",children:te.map(X=>t.jsx(ur,{comment:X,agents:r},X.id))}),a.map((X,ie)=>{const de=b.has(X.round),se=X.round===a[a.length-1].round,ge=l.get(X.round),ue=h.has(X.round),K=le(X,a[ie+1]),ce=X.status==="completed"||X.status==="execution_finished"?"✅":X.status==="failed"?"❌":X.status==="cancelled"?"⏹":"🔄",pe=X.lastAt&&X.firstAt?Math.max(0,new Date(X.lastAt).getTime()-new Date(X.firstAt).getTime()):0,ve=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(X.round),className:"w-full flex items-center justify-between px-3 py-2 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm",children:ce}),t.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:o("work:task.roundHeader",{n:X.round})}),K.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",K.length]}),se&&C&&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:X.toolCount})}),ve&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:ve}),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:[ue&&t.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:o("work:task.loadingRound",{n:X.round})}),ge&&(()=>{const re=ge.map(ye=>Do(ye)).map(ye=>Ds(ye)).filter(ye=>ye!==null),Ee=[...Ao(ge,As(re)).map(ye=>({kind:"entry",entry:ye,ts:ye.timestamp?new Date(ye.timestamp).getTime():0})),...K.map(ye=>({kind:"comment",comment:ye,ts:new Date(ye.createdAt).getTime()}))];return Ee.sort((ye,Le)=>ye.ts-Le.ts),Ee.map((ye,Le)=>ye.kind==="comment"?t.jsx(ur,{comment:ye.comment,agents:r},`c-${ye.comment.id}`):t.jsx(Po,{entry:ye.entry,showTime:!0,isLast:Le===Ee.length-1},`e-${Le}`))})(),se&&C&&p&&t.jsx($o,{content:p}),se&&C&&!p&&!ue&&t.jsx(Bo,{})]})]},X.round)}),L.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:L.map(X=>{const ie=z.get(X.id)??[];return t.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Ot.navigate(Ve.TEAM,{agentId:X.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(Fs,{name:X.name,avatarUrl:X.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:X.name}),ie.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:"→"})]}),ie.length>0&&t.jsx("div",{className:"ml-9 mt-1",children:t.jsx(ao,{entries:ie})})]},X.id)})})]}),J]})}const Fa=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"]);function Gr(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Wh({filePath:e,onClose:n,onOpenExternal:s}){const{t:r}=Oe(["work","common"]),[i,o]=g.useState([e]),a=i[i.length-1],[c,l]=g.useState(null),[d,h]=g.useState(null),[f,m]=g.useState(!0);g.useEffect(()=>{m(!0),h(null),l(null),ae.files.preview(a).then(k=>l(k)).catch(k=>h(String(k))).finally(()=>m(!1))},[a]);const u=k=>o(N=>[...N,k]),p=()=>o(k=>k.length>1?k.slice(0,-1):k),E=i.length>1,C=k=>{ae.files.reveal(k).catch(()=>{})},y=k=>{k.isDirectory||Fa.has(k.ext)?u(k.path):C(k.path)},v=a.split("/").pop()??a,x=c?.type==="directory",b=(k,N)=>{if(N)return"📁";const I=[".md",".markdown"],D=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return I.includes(k)?"📝":D.includes(k)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(k)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(k)?"💻":"📄"};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:k=>k.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:[E&&t.jsx("button",{onClick:p,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"})})}),x?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:v}),x&&c.entries&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",c.entries.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[t.jsx("button",{onClick:()=>s?s():C(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:[f&&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}),c?.type==="directory"&&c.entries&&t.jsxs("div",{className:"divide-y divide-border-default/50",children:[c.entries.length===0&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.emptyDirectory")}),c.entries.map(k=>t.jsxs("button",{onClick:()=>y(k),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:b(k.ext,k.isDirectory)}),t.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:k.name}),!k.isDirectory&&k.size!=null&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Gr(k.size)}),k.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"})}),!k.isDirectory&&!Fa.has(k.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"})]})]},k.path))]}),c&&c.type!=="directory"&&t.jsx("div",{className:"p-5",children:c.type==="image"&&c.content?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:`data:${c.mimeType};base64,${c.content}`,alt:c.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):c.type==="audio"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("audio",{controls:!0,preload:"metadata",src:c.streamUrl||(c.path?ae.files.streamUrl(c.path):ae.files.streamUrl(a)),className:"w-full"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[c.name,c.size!=null?` · ${Gr(c.size)}`:""]})]}):c.type==="video"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("video",{controls:!0,preload:"metadata",src:c.streamUrl||(c.path?ae.files.streamUrl(c.path):ae.files.streamUrl(a)),className:"w-full max-h-[60vh] rounded-lg bg-black"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[c.name,c.size!=null?` · ${Gr(c.size)}`:""]})]}):c.type==="binary"||c.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:[c.name,c.extension?` (${c.extension})`:"",c.size!=null?` · ${Gr(c.size)}`:""]}),t.jsx("button",{onClick:()=>C(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(Ql,{content:c.content,format:c.type==="text"?"text":c.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function Ya({task:e,agents:n,projects:s,requirements:r,allTasks:i,users:o,onClose:a,onRefresh:c,authUser:l,scrollToComments:d,onScrollToCommentsDone:h,onReqClick:f,onProjectClick:m}){const{t:u}=Oe(["work","common"]),p=g.useMemo(()=>yl(u),[u]),[E,C]=g.useState([]),[y,v]=g.useState(""),[x,b]=g.useState(!1),[k,N]=g.useState(!1),[I,D]=g.useState(null),[A,L]=g.useState(null),[M,$]=g.useState(!1),[z,j]=g.useState(!1),[O,_]=g.useState(!1),[T,R]=g.useState("every"),[P,W]=g.useState(""),[Y,F]=g.useState(""),[Q,B]=g.useState(""),[S,V]=g.useState(!1),[q,H]=g.useState("details"),Z=g.useRef(null),[J,le]=g.useState("none"),te=g.useCallback(G=>{H(G),requestAnimationFrame(()=>{Z.current?.scrollTo({top:0,behavior:"instant"})})},[]),X=g.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),ie=Ls(X,q,te);g.useEffect(()=>{const G=Z.current;if(!G)return;const he=()=>{const{scrollTop:Me,scrollHeight:Te,clientHeight:st}=G;if(!(Te>st+50)){le("none");return}const nn=Me<30,rn=Me+st>=Te-30;le(nn?"top":rn?"bottom":"middle")};he(),G.addEventListener("scroll",he,{passive:!0});const Ie=new ResizeObserver(he);return Ie.observe(G),()=>{G.removeEventListener("scroll",he),Ie.disconnect()}},[q]),g.useEffect(()=>{if(!d)return;H("details");const G=setTimeout(()=>{const he=Z.current;he&&he.scrollTo({top:he.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(G)},[d,h]);const[de,se]=g.useState(null),[ge,ue]=g.useState(!1),[K,ce]=g.useState(null),[pe,ve]=g.useState(!1),[fe,re]=g.useState(e.description),xe=g.useRef(null),Ee=g.useRef(null),ye=g.useRef(80);g.useEffect(()=>{if(pe&&Ee.current){const G=Ee.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,ye.current)+"px",G.focus()}},[pe]);const[Le,gt]=g.useState(!1),[ct,Nt]=g.useState(""),[pt,tt]=g.useState(1),[Ht,dt]=g.useState([]),Jt=g.useCallback(async()=>{try{const{results:G}=await ae.deliverables.search({taskId:e.id,limit:200});dt(G.filter(he=>he.status!=="outdated"))}catch{}},[e.id]);g.useEffect(()=>{Jt()},[Jt]);const[xt,nt]=g.useState(!1),qt=vr(),at=20,Fe=g.useCallback(async()=>{try{const G=await ae.tasks.listSubtasks(e.id);C(G.subtasks)}catch{}},[e.id]);g.useEffect(()=>{Fe()},[Fe]);const $e=async G=>{if(!S){V(!0);try{await G(),c(),await Fe()}catch(he){se(String(he).replace("Error: ",""))}finally{V(!1)}}},Ct=G=>$e(()=>ae.tasks.update(e.id,{priority:G})),we=G=>$e(()=>ae.tasks.assign(e.id,G||null)),Qe=G=>$e(()=>ae.tasks.update(e.id,{projectId:G||null})),it=async()=>{if(!S){V(!0);try{await ae.tasks.pause(e.id),c()}finally{V(!1)}}},bt=G=>{if(G instanceof Qa){if(G.code==="TASK_BLOCKED"){const he=G.data?.dependencyTitles??[];return he.length?u("work:task.errorBlockedDeps",{deps:he.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: ","")},Je=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.resume(e.id),c()}catch(G){se(bt(G))}finally{V(!1)}}},St=async()=>{y.trim()&&(await ae.tasks.createSubtask(e.id,y.trim()),v(""),b(!1),Fe(),c())},Ft=async G=>{G.status==="completed"||G.status==="cancelled"?await ae.tasks.cancelSubtask(e.id,G.id):await ae.tasks.completeSubtask(e.id,G.id),Fe(),c()},Ne=async G=>{await ae.tasks.deleteSubtask(e.id,G.id),D(null),Fe(),c()},Ce=async()=>{if(!S){V(!0);try{await ae.tasks.updateStatus(e.id,"in_progress"),c()}finally{V(!1)}}},De=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.retry(e.id),c()}catch(G){se(bt(G))}finally{V(!1)}}},Ae=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.runNow(e.id),c()}catch(G){se(bt(G)),c()}finally{V(!1)}}},He=g.useRef(c);He.current=c,g.useEffect(()=>jt.on("task:update",he=>{he.payload.taskId===e.id&&(Fe(),He.current())}),[e.id,Fe]);const Et=E.filter(G=>G.status==="completed").length,Ye=E.filter(G=>G.status==="cancelled").length,Wt=Et+Ye,Ue=e.status==="in_progress",en=e.status==="blocked",hn=en&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(G=>{const he=i.find(Ie=>Ie.id===G);return he&&he.status==="completed"})),Mt=e.status==="completed",yt=e.status==="failed",Xe=e.status==="rejected",ut=e.status==="cancelled",mn=e.status==="archived",tn=Mt||yt||Xe||ut||mn,rt=e.taskType==="scheduled"&&!!e.scheduleConfig,vt=rt&&!!e.scheduleConfig?.paused,It=(()=>{const G=s.find(he=>he.id===e.projectId);return G&&G.name!=="default"?G:void 0})(),Tt=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:[qt&&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=p[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," ")})})(),hn&&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.jsx("button",{onClick:a,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),t.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[t.jsx("button",{onClick:()=>te("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${q==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:u("work:task.detailsTab")}),t.jsxs("button",{onClick:()=>te("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${q==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("work:task.executionLogTab"),Ue&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsx("button",{onClick:()=>te("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${q==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const G=Ht.filter(he=>typeof he.reference=="string"&&he.reference.length>0).length;return G>0?u("work:task.deliverablesCount",{count:G}):u("work:task.deliverables")})()}),t.jsx("button",{onClick:()=>te("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${q==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:u("work:task.historyTab")})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:Z,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:ie.onTouchStart,onTouchEnd:ie.onTouchEnd,children:[t.jsxs("div",{className:q==="logs"?"min-w-0 min-h-full":"hidden",children:[de&&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")})," ",de]}),t.jsx(qh,{task:e,isRunning:e.status==="in_progress",authUser:l,agents:n})]}),t.jsxs("div",{className:q==="details"?"":"hidden",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:pe?t.jsx("textarea",{ref:Ee,value:fe,onChange:G=>{re(G.target.value);const he=G.target;he.style.height="auto",he.style.height=he.scrollHeight+"px"},onBlur:()=>{fe!==e.description&&$e(()=>ae.tasks.update(e.id,{description:fe})),ve(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),re(e.description),ve(!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:xe,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]")||(ye.current=Math.max(xe.current?.offsetHeight??80,60),re(e.description),ve(!0))},role:"button",tabIndex:0,onKeyDown:G=>G.key==="Enter"&&(re(e.description),ve(!0)),children:e.description?t.jsxs("div",{children:[t.jsx("div",{className:qt&&!xt?"line-clamp-3":"",children:t.jsx(fr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),qt&&e.description.length>150&&t.jsx("button",{onClick:G=>{G.stopPropagation(),nt(!xt)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:u(xt?"work:task.collapse":"common:showMore")})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:u("work:task.noDescription")})})}),(It||Tt)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[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 ${m?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:m?()=>m(It.id):void 0,role:m?"button":void 0,tabIndex:m?0:void 0,onKeyDown:m?G=>G.key==="Enter"&&m(It.id):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.projectLabel")}),It.name]}),Tt&&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 ${f?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:f?()=>f(Tt):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?G=>G.key==="Enter"&&f(Tt):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.requirementLabel")}),Tt.title.length>40?Tt.title.slice(0,40)+"…":Tt.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 he=i.find(Me=>Me.id===G),Ie=he&&(he.status==="completed"||he.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:he?he.title.slice(0,30):G.slice(-8)}),!tn&&t.jsx("button",{onClick:async()=>{const Me=(e.blockedBy??[]).filter(Te=>Te!==G);await ae.tasks.update(e.id,{blockedBy:Me}),c()},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")}),hn&&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")})]}),!tn&&t.jsx(Rh,{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 he=[...e.blockedBy??[],G];await ae.tasks.update(e.id,{blockedBy:he}),c()}})]}),t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.projectLabel")}),t.jsxs("select",{value:e.projectId??"",onChange:G=>{Qe(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.noProject")}),s.map(G=>t.jsx("option",{value:G.id,children:G.name},G.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.requirementLabel")}),t.jsxs("select",{value:e.requirementId??"",onChange:G=>$e(()=>ae.tasks.update(e.id,{requirementId:G.target.value||null})),disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.noRequirement")}),r.filter(G=>!e.projectId||G.projectId===e.projectId).map(G=>t.jsx("option",{value:G.id,children:G.title},G.id))]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.assignee")}),t.jsxs("select",{value:e.assignedAgentId??"",onChange:G=>{we(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.unassigned")}),n.map(G=>t.jsxs("option",{value:G.id,children:[G.name," (",G.status,")"]},G.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.reviewer")}),t.jsxs("select",{value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:G=>{const he=G.target.value;if(!he)return;const Ie=he.startsWith("human:"),Me=he.replace(/^(human|agent):/,"");(Me!==e.reviewerId||(Ie?"human":"agent")!==(e.reviewerType??"agent"))&&$e(()=>ae.tasks.update(e.id,{reviewerId:Me,reviewerType:Ie?"human":"agent"}))},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[o.map(G=>t.jsx("option",{value:`human:${G.id}`,children:G.name},`human:${G.id}`)),n.map(G=>t.jsx("option",{value:`agent:${G.id}`,children:G.name},`agent:${G.id}`))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.priority")}),t.jsxs("select",{value:e.priority,onChange:G=>{Ct(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"low",children:u("work:priority.low")}),t.jsx("option",{value:"medium",children:u("work:priority.medium")}),t.jsx("option",{value:"high",children:u("work:priority.high")}),t.jsx("option",{value:"urgent",children:u("work:priority.urgent")})]})]})]})]}),t.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&t.jsx("span",{children:u("work:task.createdBy",{name:Qn(e.createdBy,n,o)??e.createdBy})}),e.updatedBy&&t.jsx("span",{children:u("work:task.updatedBy",{name:Qn(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")," ",E.length>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[u("work:task.subtasksProgress",{done:Et,total:E.length-Ye}),Ye>0?` · ${Ye} cancelled`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[Wt>0&&t.jsx("button",{onClick:()=>N(G=>!G),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${k?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:k?u("work:task.hideCompleted"):u("work:task.showCompleted",{count:Wt})}),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=k?E:E.filter(he=>he.status!=="completed"&&he.status!=="cancelled");return G.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:G.map(he=>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 ${he.status==="cancelled"?"opacity-50":""}`,children:[t.jsxs("button",{onClick:()=>{Ft(he)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${he.status==="completed"?"bg-green-600 border-green-600 text-white":he.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[he.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"})}),he.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 ${he.status==="completed"?"line-through text-fg-tertiary":he.status==="cancelled"?"line-through text-fg-quaternary":"text-fg-secondary"}`,children:he.title}),t.jsx("button",{onClick:()=>D(he),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},he.id))}):null})(),E.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:y,onChange:G=>v(G.target.value),onKeyDown:G=>{G.key==="Enter"&&St(),G.key==="Escape"&&(b(!1),v(""))},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:()=>{St()},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),v("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:u("common:cancel")})]}),(()=>{const G=Ht.filter(Me=>typeof Me.reference=="string"&&Me.reference.length>0);if(G.length===0)return null;const he={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:()=>te("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(Me=>{const Te=/^https?:\/\//i.test(Me.reference),st=Te?Me.summary||Me.reference:Me.reference.split("/").pop()??Me.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 ${he[Me.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Me.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Te?t.jsxs("a",{href:Me.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:Me.reference,children:[st," ",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:()=>ce(Me.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Me.reference,children:st}),Me.summary&&!Te&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Me.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Me.reference})]})]},Me.id)})})]})})(),t.jsx(Hh,{task:e,agents:n,users:o,authUser:l})]})]}),t.jsx("div",{className:q==="history"?"":"hidden",children:t.jsx(jl,{entityType:"task",entityId:e.id})}),t.jsx("div",{className:q==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const G=Ht.filter(Te=>typeof Te.reference=="string"&&Te.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 he={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/at),Me=G.slice((pt-1)*at,pt*at);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:pt<=1,onClick:()=>tt(Te=>Te-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[pt,"/",Ie]}),t.jsx("button",{disabled:pt>=Ie,onClick:()=>tt(Te=>Te+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:Me.map(Te=>{const st=/^https?:\/\//i.test(Te.reference),ft=st?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 ${he[Te.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Te.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[st?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:[ft," ",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:()=>ce(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:ft}),Te.summary&&!st&&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)})})]})})()})]}),J!=="none"&&J!=="top"&&t.jsx("button",{onClick:()=>Z.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"})})}),J!=="none"&&J!=="bottom"&&t.jsx("button",{onClick:()=>{const G=Z.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"})})})]}),rt&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${vt?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Ue&&!O&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Ue||O||e.scheduleConfig?.runAt||(R(e.scheduleConfig?.cron?"cron":"every"),W(e.scheduleConfig?.every??"4h"),F(e.scheduleConfig?.cron??""),B(e.scheduleConfig?.maxRuns&&e.scheduleConfig.maxRuns>0?String(e.scheduleConfig.maxRuns):""),_(!0))},children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:vt?"text-amber-600":"text-brand-500",children:vt?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")}),!vt&&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 he=Math.floor(G/6e4);if(he<60)return u("work:task.scheduleInMinutes",{count:he});const Ie=Math.floor(he/60);return Ie<24?u("work:task.scheduleInHoursMinutes",{h:Ie,m:he%60}):u("work:task.scheduleInDaysHours",{d:Math.floor(Ie/24),h:Ie%24})})()})})]}),!Ue&&!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?t.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:G=>G.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("select",{value:T,onChange:G=>R(G.target.value),className:"px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[t.jsx("option",{value:"every",children:u("work:task.scheduleEveryMode")}),t.jsx("option",{value:"cron",children:u("work:task.scheduleCronMode")})]}),T==="every"?t.jsxs("select",{value:P,onChange:G=>W(G.target.value),className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[t.jsx("option",{value:"30m",children:u("work:task.freq30m")}),t.jsx("option",{value:"1h",children:u("work:task.freq1h")}),t.jsx("option",{value:"2h",children:u("work:task.freq2h")}),t.jsx("option",{value:"4h",children:u("work:task.freq4h")}),t.jsx("option",{value:"8h",children:u("work:task.freq8h")}),t.jsx("option",{value:"12h",children:u("work:task.freq12h")}),t.jsx("option",{value:"1d",children:u("work:task.freq1d")}),t.jsx("option",{value:"1w",children:u("work:task.freq1w")})]}):t.jsx("input",{value:Y,onChange:G=>F(G.target.value),placeholder:"0 9 * * 1-5",className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("label",{className:"text-fg-tertiary shrink-0",children:u("work:task.scheduleMaxRuns")}),t.jsx("input",{value:Q,onChange:G=>B(G.target.value.replace(/\D/g,"")),placeholder:u("work:task.scheduleMaxRunsPlaceholder"),className:"w-20 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx("button",{onClick:async()=>{const G={};T==="every"?G.every=P:G.cron=Y.trim(),Q&&(G.maxRuns=parseInt(Q,10)),await $e(()=>ae.tasks.updateSchedule(e.id,G)),_(!1)},disabled:S,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(),he=Math.floor(G/6e4);if(he<1)return u("work:task.noteTimeJustNow");if(he<60)return u("work:task.noteTimeMinutes",{count:he});const Ie=Math.floor(he/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(rt){ue(!0);return}$e(()=>ae.tasks.approve(e.id))},disabled:S,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 ae.tasks.getDependentCount(e.id);L({dependentCount:G})},disabled:S,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:()=>$(!0),disabled:S,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(()=>ae.tasks.accept(e.id,l?.id))},disabled:S,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")}),Le?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:ct,onChange:G=>Nt(G.target.value),onKeyDown:G=>{G.key==="Enter"&&ct.trim()&&($e(()=>ae.tasks.revision(e.id,ct.trim(),l?.id)),gt(!1),Nt(""))},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(()=>ae.tasks.revision(e.id,ct.trim()||u("work:task.revisionsNeededDefault"),l?.id)),gt(!1),Nt("")},disabled:S,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:()=>{gt(!1),Nt("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>gt(!0),disabled:S,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")})]}),Ue&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{it()},disabled:S,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:()=>{De()},disabled:S,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")]})]}),en&&t.jsx("button",{onClick:()=>{Je()},disabled:S,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:S?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")]})}),yt&&!rt&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{De()},disabled:S,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:()=>{Ce()},disabled:S,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")]})]}),rt&&(Mt||yt||ut)&&!mn&&t.jsx("button",{onClick:()=>{Ae()},disabled:S,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:S?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")]})}),rt&&!Ue&&!mn&&!Xe&&(vt?t.jsx("button",{onClick:()=>{$e(()=>ae.tasks.resumeSchedule(e.id))},disabled:S,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(()=>ae.tasks.pauseSchedule(e.id))},disabled:S,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")})),(Mt||yt||Xe||ut)&&t.jsx("button",{onClick:()=>j(!0),disabled:S,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")}),Mt&&!rt&&t.jsx("button",{onClick:()=>{Ce()},disabled:S,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")}),!tn&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:G}=await ae.tasks.getDependentCount(e.id);L({dependentCount:G})},disabled:S,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")})]})}),I&&t.jsx(Hn,{title:u("work:task.deleteSubtaskTitle",{title:I.title}),message:u("work:task.deleteSubtaskMessage"),confirmLabel:u("common:delete"),onConfirm:()=>{Ne(I)},onCancel:()=>D(null)}),M&&t.jsx(Hn,{title:u("work:task.rejectConfirmTitle"),message:u("work:task.rejectConfirmMessage"),confirmLabel:u("work:task.reject"),onConfirm:()=>{$(!1),$e(()=>ae.tasks.reject(e.id))},onCancel:()=>$(!1)}),z&&t.jsx(Hn,{title:u("work:task.archiveConfirmTitle"),message:u(rt?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:u("work:task.archive"),onConfirm:()=>{j(!1),$e(()=>ae.tasks.archive(e.id))},onCancel:()=>j(!1)}),A&&A.dependentCount>0?t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>L(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:[rt&&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:()=>{L(null),$e(()=>ae.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:()=>{L(null),$e(()=>ae.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:()=>L(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(Hn,{title:u("work:task.cancelTaskModalTitle"),message:u(rt?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:u("work:task.cancelTask"),onConfirm:()=>{L(null),$e(()=>ae.tasks.cancel(e.id))},onCancel:()=>L(null)}),K&&t.jsx(Wh,{filePath:K,onClose:()=>ce(null),onOpenExternal:()=>{ce(null),ae.deliverables.search({taskId:e.id,limit:100}).then(({results:G})=>{const he=G.find(Ie=>Ie.reference===K);he?Ot.navigate(Ve.DELIVERABLES,{openDeliverable:he.id}):Ot.navigate(Ve.DELIVERABLES)}).catch(()=>Ot.navigate(Ve.DELIVERABLES))}}),ge&&e.scheduleConfig&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>ue(!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:S,onClick:()=>{ue(!1),$e(()=>ae.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:S,onClick:()=>{ue(!1),$e(()=>ae.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:()=>ue(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("common:cancel")})]})]})})]})}function Vh({project:e,tasks:n,requirements:s,agents:r,onDeleteProject:i,onUpdateProject:o,onRefresh:a}){const c=g.useMemo(()=>n.filter(M=>M.projectId===e.id),[n,e.id]),l=g.useMemo(()=>s.filter(M=>M.projectId===e.id),[s,e.id]),d=g.useMemo(()=>{const M={total:c.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:l.length,reqsDone:0};for(const $ of c)$.status==="completed"||$.status==="accepted"?M.completed++:$.status==="in_progress"?M.inProgress++:$.status==="review"||$.status==="revision"?M.inReview++:$.status==="blocked"?M.blocked++:$.status==="failed"?M.failed++:M.pending++;for(const $ of l)$.status==="completed"&&M.reqsDone++;return M},[c,l]),h=g.useMemo(()=>new Set(c.map(M=>M.assignedAgentId).filter(Boolean)),[c]),f=g.useMemo(()=>r.filter(M=>h.has(M.id)),[r,h]),[m,u]=g.useState(!1),[p,E]=g.useState(""),[C,y]=g.useState("main"),[v,x]=g.useState(!1),[b,k]=g.useState(!1),{t:N}=Oe(["work","common"]),I=[{value:"active",label:N("work:project.statusActive"),desc:N("work:project.statusActiveDesc")},{value:"paused",label:N("work:project.statusPaused"),desc:N("work:project.statusPausedDesc")},{value:"archived",label:N("work:project.statusArchived"),desc:N("work:project.statusArchivedDesc")}],D=async M=>{if(M!==e.status){x(!0);try{await o({status:M}),a()}finally{x(!1)}}},A=async()=>{const M=p.trim();if(!M)return;const $=[...e.repositories??[],{url:"",localPath:M,defaultBranch:C||"main"}];await o({repositories:$}),E(""),y("main"),u(!1),a()},L=async M=>{const $=(e.repositories??[]).filter((z,j)=>j!==M);await o({repositories:$}),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(Lh,{value:e.description??"",onSave:async M=>{await o({description:M}),a()},className:"text-sm text-fg-secondary",placeholder:N("work:project.descriptionPlaceholderLong")}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&t.jsxs("span",{children:[N("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:[N("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:N("work:project.projectStatusHeading")}),t.jsx("div",{className:"flex gap-2",children:I.map(M=>t.jsxs("button",{disabled:v,onClick:()=>D(M.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===M.value?M.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":M.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"} ${v?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:M.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:M.desc})]},M.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:N("work:project.taskOverview")}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(Ut,{label:N("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),t.jsx(Ut,{label:N("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),t.jsx(Ut,{label:N("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),t.jsx(Ut,{label:N("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),t.jsx(Ut,{label:N("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),t.jsx(Ut,{label:N("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:N("work:project.requirementsHeading")}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(Ut,{label:N("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),t.jsx(Ut,{label:N("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),t.jsx(Ut,{label:N("work:project.statActive"),value:d.reqs-d.reqsDone,color:"text-brand-500"})]})]}),f.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:N("work:project.agentsHeading",{count:f.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(M=>{const $=c.filter(j=>j.assignedAgentId===M.id),z=$.filter(j=>!["completed","failed","cancelled","archived"].includes(j.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 ${M.status==="working"?"bg-blue-500":M.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:M.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:N("work:project.agentTaskCounts",{active:z.length,total:$.length})})]},M.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:N("work:project.repositories")}),t.jsx("button",{onClick:()=>u(!m),className:"text-[10px] text-brand-500 hover:text-brand-500",children:N(m?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!m&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:N("work:project.noReposLinked")}),(e.repositories??[]).map((M,$)=>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:M.url||M.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:M.defaultBranch}),t.jsx("button",{onClick:()=>L($),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:N("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"})]})})]},$)),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:p,onChange:M=>E(M.target.value),placeholder:N("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:C,onChange:M=>y(M.target.value),placeholder:N("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:!p.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:N("work:task.add")})]})]})]}),t.jsx(Mh,{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:N("work:project.dangerZone")}),t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:N("work:project.dangerZoneDeleteHint")}),t.jsx("button",{onClick:()=>k(!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:N("work:project.deleteProject")})]}),b&&t.jsx(Hn,{title:N("work:project.deleteProjectConfirmTitle"),message:N("work:project.deleteProjectConfirmBody",{name:e.name,tasks:d.total,reqs:d.reqs}),confirmLabel:N("work:project.deleteProject"),onConfirm:()=>{k(!1),i()},onCancel:()=>k(!1)})]})}function Ut({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 Jr={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},wl={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Fh={urgent:0,high:1,medium:2,low:3},os={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Ga={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"},Yh={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"},Gh=["pending","in_progress","completed","rejected","cancelled","archived"];function kl(e){for(const n of ss)if(n.statuses.includes(e))return n.id;return"closed"}function Ka(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 Kr({value:e,options:n,onSelect:s,allowedValues:r}){const[i,o]=g.useState(!1),a=g.useRef(null),c=g.useRef(null),l=n.find(d=>d.value===e);return g.useEffect(()=>{if(!i)return;const d=h=>{c.current&&!c.current.contains(h.target)&&a.current&&!a.current.contains(h.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 ${l?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:l?.label??e}),i&&t.jsx("div",{ref:c,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:n.map(d=>{const h=d.value===e,f=h||!r||r.has(d.value);return t.jsxs("button",{disabled:!f,onClick:()=>{!h&&f&&s(d.value),o(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${h?"bg-surface-elevated":f?"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 ${f?d.cls.split(" ")[0]:"bg-gray-600"}`}),t.jsx("span",{className:`font-medium ${h?"text-fg-primary":f?"text-fg-secondary":"text-fg-muted"}`,children:d.label}),h&&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 Za({row:e,idx:n,dragIdx:s,agentMap:r,projMap:i,onTaskClick:o,onReqClick:a,onRowDragStart:c,onRowDragEnd:l,handleStatusChange:d,handlePriorityChange:h,selected:f,isMobile:m,isAbnormalBlocked:u}){const{t:p}=Oe(["work","common"]),E=g.useMemo(()=>yl(p),[p]),C=g.useMemo(()=>lo(p),[p]),y=g.useMemo(()=>Oh(p),[p]),v=e.data.status,x=e.data.priority,b=e.kind==="task"?r.get(e.data.assignedAgentId??""):void 0,k=(()=>{const I=i.get((e.kind==="task",e.data.projectId??""));return I&&I.name!=="default"?I:void 0})(),N=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:p("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:p("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:p("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 ${Ga[e.group]??"border-l-gray-700"} ${f?"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:[N,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:I=>I.stopPropagation(),children:t.jsx(Kr,{value:v,options:e.kind==="task"?Ha.map(I=>({value:I,label:E[I]?.label??I,cls:E[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):qa.map(I=>({value:I,label:C[I]?.label??I,cls:C[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Wa[v]:Ws[v],onSelect:I=>{d(e,I)}})}),t.jsx("div",{onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:x,options:za.map(I=>({value:I,label:y[I]?.label??I,cls:y[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:I=>{h(e,I)}})}),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 ${yr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`${Va[b.status]??"text-fg-secondary"}`,children:b.name})]}),k?.name&&t.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:k.name}),t.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:Ka(e.data.updatedAt??"",p)})]})]}):t.jsxs("div",{"data-work-item-id":e.data.id,draggable:!0,onDragStart:I=>c(I,n),onDragEnd:l,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 ${Ga[e.group]??"border-l-gray-700"} ${s===n?"opacity-40":""} ${f?"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:N}),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:I=>I.stopPropagation(),children:t.jsx(Kr,{value:v,options:e.kind==="task"?Ha.map(I=>({value:I,label:E[I]?.label??I,cls:E[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):qa.map(I=>({value:I,label:C[I]?.label??I,cls:C[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Wa[v]:Ws[v],onSelect:I=>{d(e,I)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:x,options:za.map(I=>({value:I,label:y[I]?.label??I,cls:y[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:I=>{h(e,I)}})}),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 ${yr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`font-medium ${Va[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:k?.name?t.jsx("span",{className:"text-brand-400/70",children:k.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:Ka(e.data.updatedAt??"",p)})]})}function Kh({tasks:e,requirements:n,agents:s,projects:r,onTaskClick:i,onReqClick:o,onRefresh:a,selectedTaskId:c,selectedReqId:l}){const{t:d}=Oe(["work","common"]),h=vr(),[f,m]=g.useState("status"),[u,p]=g.useState(null),[E,C]=g.useState(null),y=g.useMemo(()=>{const T=new Map;for(const R of e)T.set(R.id,R);return T},[e]),v=g.useCallback(T=>T.status!=="blocked"?!1:!T.blockedBy||T.blockedBy.length===0?!0:T.blockedBy.every(R=>{const P=y.get(R);return P&&P.status==="completed"}),[y]),x=g.useMemo(()=>{const T=[];for(const R of e){const P=kl(R.status);T.push({kind:"task",data:R,group:P,groupOrder:os[P]??5})}for(const R of n){const P=Jr[R.status]??"todo";T.push({kind:"req",data:R,group:P,groupOrder:os[P]??5})}if(f==="status")T.sort((R,P)=>{if(R.groupOrder!==P.groupOrder)return R.groupOrder-P.groupOrder;const W=new Date(R.data.updatedAt??0).getTime();return new Date(P.data.updatedAt??0).getTime()-W});else{const R=P=>Fh[P.data.priority]??2;T.sort((P,W)=>{const Y=R(P),F=R(W);return Y!==F?Y-F:new Date(W.data.updatedAt??0).getTime()-new Date(P.data.updatedAt??0).getTime()})}return T},[e,n,f]),b=async(T,R)=>{try{T.kind==="task"?await ae.tasks.updateStatus(T.data.id,R):await ae.requirements.updateStatus(T.data.id,R),a()}catch{}},k=async(T,R)=>{try{T.kind==="task"?await ae.tasks.update(T.data.id,{priority:R}):await ae.requirements.update(T.data.id,{priority:R}),a()}catch{}},N=(T,R)=>{p(R),T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",String(R)),T.currentTarget.style.opacity="0.4"},I=T=>{T.currentTarget.style.opacity="1",p(null),C(null)},D=(T,R)=>{T.preventDefault(),T.dataTransfer.dropEffect="move",E!==R&&C(R)},A=async(T,R)=>{if(T.preventDefault(),C(null),u==null)return;const P=x[u];if(!P||P.group===R)return;const W=ss.find(Y=>Y.id===R);if(W){try{if(P.kind==="task"){if(P.data.status==="pending")return;await ae.tasks.updateStatus(P.data.id,W.dropStatus)}else{const Y=wl[R];Y&&await ae.requirements.updateStatus(P.data.id,Y)}a()}catch{}p(null)}},L=g.useMemo(()=>new Map(s.map(T=>[T.id,T])),[s]),M=g.useMemo(()=>new Map(r.map(T=>[T.id,T])),[r]),$=["todo","in_progress","review","done"],z=g.useMemo(()=>{const T={};for(const R of x)T[R.group]=(T[R.group]??0)+1;return T},[x]),{rowsByGroup:j,rowIndexMap:O}=g.useMemo(()=>{const T=new Map,R=new Map;for(let P=0;P<x.length;P++){const W=x[P];R.set(W,P);const Y=T.get(W.group)??[];Y.push(W),T.set(W.group,Y)}return{rowsByGroup:T,rowIndexMap:R}},[x]),_=g.useMemo(()=>{if(f!=="status")return null;const T=new Set(x.map(W=>W.group)),R=[],P=new Set;T.has("failed")&&(R.push("failed"),P.add("failed"));for(const W of $)R.push(W),P.add(W);for(const W of x)P.has(W.group)||(R.push(W.group),P.add(W.group));return R},[x,f]);return t.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${h?"overflow-x-hidden w-full":""}`,children:t.jsxs("div",{className:h?"w-full":"w-fit min-w-full",children:[!h&&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:x.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:d("work:task.backlogTitle")}),t.jsxs("button",{onClick:()=>m("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[d("work:filters.status")," ",f==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>m("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[d("work:filters.priority")," ",f==="priority"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsx("div",{className:"w-[120px] shrink-0",children:d("work:filters.assignee")}),t.jsx("div",{className:"w-[120px] shrink-0",children:d("work:task.projectLabel")}),t.jsx("div",{className:"w-[90px] shrink-0 text-right",children:d("work:task.backlogUpdated")})]}),t.jsxs("div",{children:[f==="status"&&_?_.map(T=>{const R=j.get(T)??[];return t.jsxs("div",{children:[t.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-primary/80 sticky top-0 z-10 ${Yh[T]??""} ${E===T?"ring-1 ring-brand-500/40":""}`,onDragOver:P=>D(P,T),onDragLeave:()=>C(null),onDrop:P=>{A(P,T)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:d(`work:boardColumn.${T}`)}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:z[T]??0})]}),R.map(P=>t.jsx(Za,{row:P,idx:O.get(P)??0,dragIdx:u,agentMap:L,projMap:M,onTaskClick:i,onReqClick:o,onRowDragStart:N,onRowDragEnd:I,handleStatusChange:b,handlePriorityChange:k,selected:P.kind==="task"?P.data.id===c:P.data.id===l,isMobile:h,isAbnormalBlocked:P.kind==="task"?v(P.data):!1},`${P.kind}-${P.data.id}`))]},T)}):x.map((T,R)=>t.jsx(Za,{row:T,idx:R,dragIdx:u,agentMap:L,projMap:M,onTaskClick:i,onReqClick:o,onRowDragStart:N,onRowDragEnd:I,handleStatusChange:b,handlePriorityChange:k,selected:T.kind==="task"?T.data.id===c:T.data.id===l,isMobile:h,isAbnormalBlocked:T.kind==="task"?v(T.data):!1},`${T.kind}-${T.data.id}`)),x.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:d("work:task.backlogEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:d("work:task.backlogEmptyDesc")})]})]})]})})}function Vs(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function Zh(e,n){const s=new Map,r=new Map(e.map(c=>[c.id,c])),i=new Set;for(const c of e){let l=Vs(c.title).replace(/[^a-z0-9-]/g,"").slice(0,30)||"step";i.has(l)&&(l=`${l}-${c.id.slice(-4)}`),i.add(l),s.set(c.id,l)}const o=new Map,a=new Set;for(const c of e){const l=c.assignedAgentId;if(l&&!o.has(l)){const d=n[l]??"worker";let h=Vs(d).replace(/[^a-z0-9-]/g,"")||"worker";a.has(h)&&(h=`${h}-${l.slice(-4)}`),a.add(h),o.set(l,h)}}return e.map(c=>({id:s.get(c.id),name:c.title,role:o.get(c.assignedAgentId)??"worker",prompt:c.description||c.title,depends_on:(c.blockedBy??[]).filter(l=>r.has(l)).map(l=>s.get(l)).filter(Boolean)}))}function Zr(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function Xh(e,n,s){const r=[];r.push(`name: ${Zr(e)}`),r.push(`description: ${Zr(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: ${Zr(i.name)}`),r.push(" type: agent_task"),r.push(` role: ${Zr(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(`
|
|
8
|
-
`))r.push(` ${o}`);r.push("")}return r.join(`
|
|
9
|
-
`)}function Uh({req:e,tasks:n,agents:s,teamId:r,onClose:i,onSaved:o}){const{t:a}=Oe(["work"]),c=g.useMemo(()=>{const A={};for(const L of s)A[L.id]=L.name;return A},[s]),l=g.useMemo(()=>Zh(n,c),[n,c]),[d,h]=g.useState(()=>Vs(e.title)),[f,m]=g.useState(e.description||e.title),[u,p]=g.useState(l),[E,C]=g.useState(!1),[y,v]=g.useState(null),x=(A,L,M)=>{p($=>$.map((z,j)=>j===A?{...z,[L]:M}:z))},b=A=>{const L=u[A]?.id;p(M=>M.filter(($,z)=>z!==A).map($=>({...$,depends_on:$.depends_on.filter(z=>z!==L)})))},[k,N]=g.useState(!1),I=async()=>{if(d.trim()){C(!0),v(null);try{const A=Xh(d.trim(),f,u);await ae.workflows.create(r,d.trim(),A),N(!0),setTimeout(()=>o(),800)}catch(A){v(String(A))}C(!1)}},D=g.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-[640px] max-h-[85vh] flex flex-col",onClick:A=>A.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between 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-6 py-4 space-y-4",children:[t.jsxs("div",{className:"grid 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=>h(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:D.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:f,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,L)=>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:L+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:M=>x(L,"name",M.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:M=>x(L,"role",M.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(M=>{const $=u.find(z=>z.id===M);return t.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:$?.name??M},M)})]}),t.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:A.prompt})]}),t.jsx("button",{onClick:()=>b(L),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))})]}),y&&t.jsx("p",{className:"text-xs text-red-500",children:y}),k&&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:I,disabled:E||k||!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:E?a("work:task.saving","Saving..."):k?a("work:task.workflowSavedSuccess","Saved!"):a("work:task.saveWorkflow","Save Workflow")})]})]})})}function Xa({teamId:e,agents:n,compact:s}){const{t:r}=Oe(["work"]),i=g.useMemo(()=>e?n.find(a=>a.teamId===e&&a.agentRole==="manager"):n.find(a=>a.agentRole==="manager"),[n,e]),o=()=>{i&&Ot.navigate(Ve.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 Qh({teamId:e,projectId:n,agents:s,projects:r,onViewRunTasks:i}){const{t:o}=Oe(["work"]),[a,c]=g.useState([]),[l,d]=g.useState({}),[h,f]=g.useState(!1),[m,u]=g.useState(null),[p,E]=g.useState({}),[C,y]=g.useState(!1),[v,x]=g.useState(null),[b,k]=g.useState([]),[N,I]=g.useState(null),[D,A]=g.useState(null),[L,M]=g.useState({}),[$,z]=g.useState(null),[j,O]=g.useState(null),[_,T]=g.useState(null),[R,P]=g.useState([]),[W,Y]=g.useState({}),[F,Q]=g.useState(null),[B,S]=g.useState({}),[V,q]=g.useState(new Set),H=e??N;g.useEffect(()=>{e||ae.teams.list().then(({teams:K})=>{k(K.map(ce=>({id:ce.id,name:ce.name})))}).catch(()=>{})},[e]),g.useMemo(()=>{const K={};for(const ce of s)K[ce.id]=ce.name;return K},[s]);const Z=g.useCallback(async()=>{const K=H?[H]:b.map(ce=>ce.id);if(K.length!==0){f(!0);try{const ce=[],pe={},ve={};await Promise.all(K.map(async fe=>{try{const{workflows:re}=await ae.workflows.list(fe);for(const xe of re)ve[xe.name]=fe;ce.push(...re),await Promise.all(re.map(async xe=>{try{const{runs:Ee}=await ae.workflows.listRuns(fe,xe.name,5);pe[xe.name]=Ee}catch{}}))}catch{}})),c(ce),d(pe),S(ve)}catch{}f(!1)}},[H,b]);g.useEffect(()=>{Z()},[Z]);const J=K=>H??B[K],le=async K=>{if(D===K.name){A(null);return}A(K.name);const ce=J(K.name);if(!L[K.name]&&ce)try{const{template:pe}=await ae.workflows.get(ce,K.name);M(ve=>({...ve,[K.name]:pe}))}catch{}},te=K=>{const ce={};for(const re of K.params??[])re.default&&(ce[re.name]=re.default);E(ce),x(null),P([]),Y({});const pe=localStorage.getItem(`markus_wf_project_${K.name}`)??localStorage.getItem("markus_wf_project_last"),ve=pe&&r.some(re=>re.id===pe)?pe:null;Q(n??ve??r[0]?.id??null),u(K);const fe=J(K.name);fe&&ae.workflows.roles(fe,K.name).then(({roles:re})=>P(re)).catch(()=>{})},X=async()=>{const K=F??r[0]?.id,ce=m?J(m.name):void 0;if(!m||!ce||!K){x(K?o("work:task.workflowNoTeam","Cannot determine team for this workflow"):o("work:task.workflowNoProject","Please select a project"));return}y(!0),x(null);try{let pe;if(R.length>0){pe={};for(const ve of R)pe[ve.role]=W[ve.role]??ve.recommended??""}await ae.workflows.startRun(ce,m.name,K,p,pe),localStorage.setItem(`markus_wf_project_${m.name}`,K),localStorage.setItem("markus_wf_project_last",K),u(null),Z()}catch(pe){x(String(pe))}y(!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(h&&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 ie=async K=>{z(K),O(null);try{await ae.workflows.cancelRun(K),Z()}catch{}z(null)},de=async K=>{T(K.id);try{K.status==="running"?await ae.workflows.pauseRun(K.id):K.status==="paused"&&await ae.workflows.resumeRun(K.id),Z()}catch{}T(null)},se=K=>{K.requirementId&&i&&i(K.requirementId)},ge=K=>{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[K]??"bg-gray-500/20 text-gray-400"}`,children:K})},ue=m&&(m.params??[]).some(K=>K.required&&!p[K.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:()=>{N!==null&&(I(null),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${N===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(K=>t.jsx("button",{onClick:()=>{N!==K.id&&(I(K.id),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${N===K.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:K.name},K.id))]}),a.length===0&&!h?t.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:t.jsx(Xa,{teamId:H,agents:s})}):t.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[a.map(K=>{const ce=D===K.name,pe=L[K.name],fe=(l[K.name]??[]).some(re=>re.status==="running"||re.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 items-start justify-between gap-3 mb-2 cursor-pointer",onClick:()=>le(K),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:K.displayName||K.name}),t.jsx("span",{className:"text-[11px] text-fg-tertiary",children:o("work:task.workflowStepsCount","{{count}} steps",{count:K.stepCount})})]})}),t.jsxs("div",{className:"flex 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",title:o("work:task.workflowSendToAgent","Send to agent chat"),onClick:re=>{re.stopPropagation();const xe=J(K.name),ye=(xe?s.find(Le=>Le.teamId===xe&&Le.agentRole==="manager"):void 0)?.id??s.find(Le=>Le.agentRole==="manager")?.id??s[0]?.id;ye&&Ot.navigate(Ve.TEAM,{agentId:ye,prefillMessage:`@[${K.displayName||K.name}](workflow:${K.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"})}),K.name]}),K.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",K.version]}),fe?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:re=>{re.stopPropagation(),te(K)},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:[K.description&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:K.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((re,xe)=>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:xe+1}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-medium text-fg-primary",children:re.name}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary",children:re.role}),re.depends_on&&re.depends_on.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["← ",re.depends_on.join(", ")]})]}),t.jsx("p",{className:"text-[10px] text-fg-tertiary line-clamp-1 mt-0.5",children:re.prompt})]})]},re.id))})]}),pe.steps.some(re=>re.depends_on&&re.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((re,xe)=>{const Ee=re.depends_on&&re.depends_on.length>0;return t.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[Ee&&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:re.name})]},re.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(re=>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:re.label||re.name}),t.jsxs("span",{className:"text-fg-quaternary",children:["(",re.type||"string",")"]}),re.required&&t.jsx("span",{className:"text-red-400",children:"*"})]},re.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 re=l[K.name]??[];if(re.length===0)return null;const xe=V.has(K.name),Ee=xe?re:re.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:()=>q(ye=>{const Le=new Set(ye);return Le.has(K.name)?Le.delete(K.name):Le.add(K.name),Le}),children:[t.jsx("svg",{className:`w-3 h-3 text-fg-quaternary transition-transform ${xe?"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")}),re.length>1&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["(",re.length,")"]})]}),t.jsx("div",{className:"space-y-1",children:Ee.map(ye=>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:["#",ye.runNumber]}),ge(ye.status),t.jsxs("span",{className:"text-fg-tertiary",children:[ye.taskIds.length," tasks"]}),t.jsx("span",{className:"text-fg-tertiary",children:new Date(ye.startedAt).toLocaleDateString()}),ye.triggeredBy==="schedule"&&t.jsx("span",{className:"text-[10px] text-purple-400",children:"auto"}),t.jsx("span",{className:"flex-1"}),(ye.status==="running"||ye.status==="paused")&&t.jsx("button",{onClick:Le=>{Le.stopPropagation(),de(ye)},disabled:_===ye.id,className:`px-2.5 py-0.5 text-[10px] rounded-lg font-medium transition-colors ${ye.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:_===ye.id?"...":ye.status==="running"?o("work:task.workflowPause","Pause"):o("work:task.workflowResume","Resume")}),(ye.status==="running"||ye.status==="paused")&&t.jsx("button",{onClick:Le=>{Le.stopPropagation(),O(ye.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:()=>se(ye),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")})]},ye.id))})]})})()]},K.name)}),t.jsx(Xa,{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:K=>K.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(K=>t.jsxs("div",{children:[t.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[K.label||K.name,K.required&&t.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),K.type==="enum"&&K.options?t.jsxs("select",{value:p[K.name]??"",onChange:ce=>E(pe=>({...pe,[K.name]:ce.target.value})),className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:"—"}),K.options.map(ce=>t.jsx("option",{value:ce,children:ce},ce))]}):t.jsx("textarea",{value:p[K.name]??"",onChange:ce=>{E(fe=>({...fe,[K.name]:ce.target.value}));const pe=ce.target;pe.style.height="auto";const ve=parseFloat(getComputedStyle(pe).lineHeight)||18;pe.style.height=Math.min(pe.scrollHeight,ve*7)+"px"},placeholder:K.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},K.name))}),R.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:R.map(K=>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:K.role}),t.jsx("select",{value:W[K.role]??K.recommended??"",onChange:ce=>Y(pe=>({...pe,[K.role]:ce.target.value})),className:"input-field text-xs flex-1",children:K.candidates.map(ce=>t.jsxs("option",{value:ce.agentId,children:[ce.agentName,ce.agentId===K.recommended?" ★":""]},ce.agentId))})]},K.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.jsxs("select",{value:F??"",onChange:K=>{const ce=K.target.value||null;Q(ce),x(null),ce&&localStorage.setItem("markus_wf_project_last",ce)},className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:o("work:task.workflowSelectProject","— Select a project —")}),r.map(K=>t.jsx("option",{value:K.id,children:K.name},K.id))]})]}),v&&t.jsx("p",{className:"text-xs text-red-400 mb-3",children:v}),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:X,disabled:C||!!ue,className:"btn-primary text-xs px-4 py-1.5",children:C?o("work:task.workflowStarting","Starting..."):o("work:task.workflowStartRun","Start Run")})]})]})}),j&&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:K=>K.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:()=>ie(j),disabled:$===j,className:"px-4 py-1.5 bg-red-600 hover:bg-red-500 text-white text-xs rounded-lg font-medium transition-colors",children:$===j?o("work:task.workflowCancelling","Cancelling..."):o("work:task.workflowConfirmCancelBtn","Confirm Cancel")})]})]})})]})}function om({authUser:e,previewMode:n,previewData:s}={}){const{t:r}=Oe(["work","common"]),i=Yl(Ve.WORK),o=g.useMemo(()=>ss.map(w=>({...w,label:r(`work:boardColumn.${w.id}`)})),[r]),a=g.useMemo(()=>vl(r),[r]),c=g.useMemo(()=>lo(r),[r]),l=vr(),d=Gl(),h=d?.leftCollapsed??!1,f=g.useRef(null),[m,u]=g.useState(0);g.useEffect(()=>{const w=f.current;if(!w)return;const U=new ResizeObserver(([ee])=>u(ee.contentRect.width));return U.observe(w),u(w.clientWidth),()=>U.disconnect()},[]);const[p,E]=g.useState(()=>{if(n)return!1;try{return localStorage.getItem(Da)==="1"}catch{return!1}}),C=g.useCallback(w=>{E(w);try{localStorage.setItem(Da,w?"1":"0")}catch{}},[]),y=g.useRef(h);g.useEffect(()=>{n||l||y.current!==h&&(y.current=h,E(h))},[h,n,l]);const v=Kl({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),x=6,b=!l&&!p?v.width+x:0,k=Math.max(0,(m||window.innerWidth)-b-x-8),N=Math.max(320,Math.round(k/2)),[I,D]=g.useState("auto"),A=Math.max(320,k-280),L=I==="auto"?Math.min(N,A):I,M=Math.max(320,Math.min(L,A)),$=g.useRef(M);$.current=M;const z=g.useRef(A);z.current=A;const j=g.useCallback(w=>{w.preventDefault();const U=w.clientX,ee=$.current,ne=Se=>{const ke=Math.max(320,Math.min(z.current,ee+(U-Se.clientX)));D(ke)},me=()=>{document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",me),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ne),document.addEventListener("mouseup",me),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[O,_]=g.useState(!1),T=g.useRef(O);T.current=O;const[R,P]=g.useState(s?.projects??[]),[W,Y]=g.useState("all"),[F,Q]=g.useState(null),[B,S]=g.useState("closed"),[V,q]=g.useState("projects"),[H,Z]=g.useState(s?.board??{}),[J,le]=g.useState(s?.agents??[]),[te,X]=g.useState([]),[ie,de]=g.useState(s?.users??[]),[se,ge]=g.useState(s?.allRequirements??[]),[ue,K]=g.useState(!s),[ce,pe]=g.useState(""),ve=g.useCallback(()=>{Cr(F??""),gn(!0)},[F]),[fe,re]=g.useState(!1),[xe,Ee]=g.useState(!1),[ye,Le]=g.useState(""),[gt,ct]=g.useState(""),[Nt,pt]=g.useState("medium"),[tt,Ht]=g.useState(""),[dt,Jt]=g.useState(""),[xt,nt]=g.useState(""),[qt,at]=g.useState(""),[Fe,$e]=g.useState([]),[Ct,we]=g.useState("standard"),[Qe,it]=g.useState("4h"),[bt,Je]=g.useState(""),[St,Ft]=g.useState(!1),[Ne,Ce]=g.useState(null),[De,Ae]=g.useState(()=>s?.initialSelectedReqId&&s.allRequirements?s.allRequirements.find(w=>w.id===s.initialSelectedReqId)??null:null);g.useEffect(()=>{s?.initialSelectedReqId&&De&&S("item")},[]);const[He,Et]=g.useState(new Set),[Ye,Wt]=g.useState(!1),[Ue,en]=g.useState(new Set),hn=g.useRef(new Set),[Mt,yt]=g.useState(null),[Xe,ut]=g.useState(s?.initialBoardType??"backlog"),[mn,tn]=g.useState(null),rt=g.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"},{id:"workflows"}],[]),vt=Ls(rt,Xe,ut),It=g.useRef(null),Tt=g.useMemo(()=>({scrollContainerRef:It}),[]),G=Ls(rt,Xe,ut,Tt),[he,Ie]=g.useState(!1),[Me,Te]=g.useState(null),[st,ft]=g.useState(!1),nn=g.useRef(null),rn=g.useRef(null),[Jn,gn]=g.useState(!1),[pn,xn]=g.useState(""),[Tn,bn]=g.useState(""),[er,hs]=g.useState("medium"),[yn,Cr]=g.useState(""),[sn,Rt]=g.useState(null),[Sr,Er]=g.useState(""),[tr,on]=g.useState(""),[ms,co]=g.useState(!1),[uo,Rn]=g.useState(""),lt=w=>{pe(w),setTimeout(()=>pe(""),3e3)};g.useEffect(()=>{const w=U=>{U.key==="Escape"&&(sn?(Rt(null),Rn("")):xe?(Ee(!1),Je("")):Jn?(gn(!1),xn(""),bn(""),on("")):st?ft(!1):B!=="closed"&&(S("closed"),Ce(null),Ae(null),l&&T.current&&_(!1)))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[sn,xe,Jn,st,B,l]);const wt=R.find(w=>w.id===F)??null,Nl=wt?.teamIds?.[0]??null,_t=g.useMemo(()=>R.filter(w=>w.status!=="archived"),[R]),fo=g.useCallback(()=>{F&&(Ce(null),Ae(null),S("project"),D("auto"),l&&_(!0))},[F,l]),Mr=g.useCallback(()=>{if(B==="project"){S("closed"),l&&_(!1);return}fo()},[B,fo,l]);g.useEffect(()=>{hn.current=Ue},[Ue]);const vn=g.useCallback(async()=>{try{const{projects:w}=await ae.projects.list();P(w)}catch{}},[]),et=g.useCallback(async()=>{const w={};W==="project"&&F&&(w.projectId=F);try{const{board:U}=await ae.tasks.board(w);Z(U)}catch{}},[W,F]),nr=g.useCallback(async()=>{try{const{agents:w}=await ae.agents.list();le(w)}catch{}},[]),ho=g.useCallback(async()=>{try{const{teams:w}=await ae.teams.list();X(w.map(U=>({id:U.id,name:U.name})))}catch{}},[]),mo=g.useCallback(async()=>{try{const{users:w}=await ae.users.list(e?.orgId);de(w)}catch{}},[e?.orgId]),Lt=g.useCallback(async()=>{try{const{requirements:w}=await ae.requirements.list({});ge(w)}catch{}},[]),go=g.useCallback(async()=>{await Promise.all([vn(),et(),nr(),mo(),Lt(),ho()]),K(!1)},[vn,et,nr,mo,Lt,ho]);g.useEffect(()=>{n||go()},[n,go]),g.useEffect(()=>{!n||!s||(P(s.projects??[]),Z(s.board??{}),le(s.agents??[]),de(s.users??[]),ge(s.allRequirements??[]))},[n,s]);const Ir=g.useCallback(w=>{q("items"),Ce(U=>U?.id===w.id&&B==="item"?(S("closed"),l&&T.current&&_(!1),null):(S("item"),D("auto"),l&&(_(!0),history.pushState({mobileDetail:Ve.WORK},"",window.location.hash)),w)),Ae(null)},[l,B]),Tr=g.useCallback(w=>{q("items"),Ae(U=>U?.id===w.id&&B==="item"?(S("closed"),l&&T.current&&_(!1),null):(S("item"),D("auto"),l&&(_(!0),history.pushState({mobileDetail:Ve.WORK},"",window.location.hash)),w)),Ce(null)},[l,B]),wn=g.useCallback(()=>{Ce(null),Ae(null),S("closed"),l&&T.current&&_(!1)},[l]),Yt=g.useRef(Ne);Yt.current=Ne;const Gt=g.useRef(De);Gt.current=De;const kn=g.useRef(B);kn.current=B;const _n=g.useRef(V);_n.current=V;const Ln=g.useRef(p);Ln.current=p;const gs=g.useRef(Xe);gs.current=Xe;const Cl=g.useCallback(()=>{Ce(null),Gt.current||(S("closed"),l&&T.current&&_(!1))},[l]);g.useEffect(()=>{if(!l)return;const w=()=>{T.current&&(_(!1),Ce(null),Ae(null),S("closed"))};return window.addEventListener("popstate",w),()=>window.removeEventListener("popstate",w)},[l]),g.useEffect(()=>{if(n||!i)return;et(),nr(),Lt();const w=Yt.current?12e4:45e3,U=setInterval(()=>{et(),nr(),Lt()},w);let ee=null;const ne=()=>{ee||(ee=setTimeout(()=>{ee=null,et()},800))};let me=null;const Se=()=>{me||(me=setTimeout(()=>{me=null,Lt()},800))},ke=jt.on("task:update",Be=>{At("/taskboard"),ne();const je=Be?.payload;je?.taskId&&(Ce(We=>{if(!We||We.id!==je.taskId)return We;const _e={};return typeof je.status=="string"&&(_e.status=je.status),Array.isArray(je.deliverables)&&(_e.deliverables=je.deliverables),Array.isArray(je.notes)&&(_e.notes=je.notes),je.result!==void 0&&(_e.result=je.result),{...We,..._e}}),Yt.current?.id===je.taskId&&(At("/tasks/"+je.taskId),ae.tasks.get(je.taskId).then(We=>{We.task&&Ce(_e=>_e?.id===We.task.id?We.task:_e)}).catch(()=>{})))}),oe=jt.on("task:create",()=>{ne()}),kt=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(Be=>jt.on(Be,je=>{At("/requirements"),Se();const We=je?.payload,_e=We?.id??We?.requirementId;_e&&Gt.current?.id===_e&&(At("/requirements/"+_e),ae.requirements.get(_e).then(Xt=>{Xt.requirement&&Ae(Cn=>Cn?.id===Xt.requirement.id?Xt.requirement:Cn)}).catch(()=>{}))})),ht=()=>{At("/taskboard"),At("/tasks"),At("/requirements"),et(),Lt(),Yt.current&&ae.tasks.get(Yt.current.id).then(Be=>{Be.task&&Ce(je=>je?.id===Be.task.id?Be.task:je)}).catch(()=>{}),Gt.current&&ae.requirements.get(Gt.current.id).then(Be=>{Be.requirement&&Ae(je=>je?.id===Be.requirement.id?Be.requirement:je)}).catch(()=>{})};return window.addEventListener("markus:data-changed",ht),()=>{clearInterval(U),ke(),oe(),kt.forEach(Be=>Be()),window.removeEventListener("markus:data-changed",ht),ee&&clearTimeout(ee),me&&clearTimeout(me)}},[n,i,et,nr,Lt]);const po=g.useRef(H);po.current=H;const xo=g.useRef(se);xo.current=se,g.useEffect(()=>{const w=Yt.current;if(!w)return;const ee=Object.values(H).flat().find(ne=>ne.id===w.id);ee&&ee.updatedAt!==w.updatedAt&&Ce(ee)},[H]),g.useEffect(()=>{const w=Gt.current;if(!w)return;const U=se.find(ee=>ee.id===w.id);U&&U.updatedAt!==w.updatedAt&&Ae(U)},[se]);const an=g.useCallback(w=>{w&&(Q(w),Y("project"),en(new Set),history.replaceState(null,"",ys(Ve.WORK,w)))},[]),[ps,rr]=g.useState(!1),sr=g.useCallback((w,U)=>{Ce(w),Ae(null),S("item"),q("items"),D("auto"),U?.scrollToComments&&rr(!0),l&&_(!0)},[l]),Dn=g.useCallback((w,U)=>{Ae(w),Ce(null),S("item"),q("items"),D("auto"),U?.scrollToComments&&rr(!0),l&&_(!0)},[l]),An=g.useRef(null);g.useEffect(()=>{const w=An.current||localStorage.getItem("markus_nav_openTask");if(!w)return;const ee=Object.values(H).flat().find(ne=>ne.id===w);ee?(An.current=null,an(ee.projectId),sr(ee),localStorage.removeItem("markus_nav_openTask")):An.current||(An.current=w,localStorage.removeItem("markus_nav_openTask"),ae.tasks.get(w).then(ne=>{ne.task&&(An.current=null,an(ne.task.projectId),sr(ne.task))}).catch(()=>{An.current=null}))},[H,sr,an]);const Pn=g.useRef(null);g.useEffect(()=>{const w=Pn.current||localStorage.getItem("markus_nav_openRequirement");if(!w)return;const U=se.find(ee=>ee.id===w);U?(Pn.current=null,an(U.projectId),Dn(U),localStorage.removeItem("markus_nav_openRequirement")):Pn.current||(Pn.current=w,localStorage.removeItem("markus_nav_openRequirement"),ae.requirements.get(w).then(ee=>{ee.requirement&&(Pn.current=null,an(ee.requirement.projectId),Dn(ee.requirement))}).catch(()=>{Pn.current=null}))},[se,Dn,an]);const Dt=g.useCallback((w,U)=>{en(new Set),Q(w),Y("project"),q(p?"items":"projects"),U?.keepItemDetail||(Ce(null),Ae(null),S(ee=>ee==="closed"?ee:"project")),history.replaceState(null,"",ys(Ve.WORK,w))},[p]),Kt=g.useCallback(w=>{en(new Set),Q(null),Y("all"),q(p?"items":"projects"),w?.keepItemDetail||(Ce(null),Ae(null),S(U=>U==="closed"?U:U==="project"?"closed":"empty")),history.replaceState(null,"",ys(Ve.WORK))},[p]),jn=g.useRef(!1);g.useEffect(()=>{if(jn.current)return;const w=window.location.hash.slice(1).split("/");if(Or(w[0])===Ve.WORK&&w[1]){jn.current=!0,Dt(w[1],{keepItemDetail:!0});return}const U=localStorage.getItem("markus_nav_projectId");if(U){jn.current=!0,localStorage.removeItem("markus_nav_projectId"),Dt(U,{keepItemDetail:!0});return}jn.current=!0,Kt({keepItemDetail:!0})},[]),g.useEffect(()=>{if(!ue){if(!F){jn.current=!0,W!=="all"&&Y("all");return}if(_t.some(w=>w.id===F)){jn.current=!0;return}jn.current=!0,Kt({keepItemDetail:!0})}},[ue,_t,F,Kt,W]);const Sl=g.useRef(Or(window.location.hash.slice(1).split("/")[0]));g.useEffect(()=>{if(n)return;const w=()=>{const ee=window.location.hash.slice(1).split("/"),ne=Or(ee[0]);Sl.current=ne,ne===Ve.WORK&&(ee[1]?Dt(ee[1],{keepItemDetail:!0}):Kt({keepItemDetail:!0}))},U=async ee=>{const ne=ee.detail;if(Or(ne.page)===Ve.WORK){if(ne.params?.openTask){const me=ne.params.openTask,Se=ne.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let ke=Object.values(po.current).flat().find(oe=>oe.id===me);if(!ke)try{ke=(await ae.tasks.get(me)).task}catch{}ke&&(an(ke.projectId),sr(ke,{scrollToComments:Se}))}if(ne.params?.openRequirement){const me=ne.params.openRequirement,Se=ne.params.scrollToComments==="true";let ke=xo.current.find(oe=>oe.id===me);if(!ke)try{ke=(await ae.requirements.get(me)).requirement}catch{}ke&&(an(ke.projectId),Dn(ke,{scrollToComments:Se}))}if(ne.params?.projectId&&Dt(ne.params.projectId),ne.params?.statusFilter){const me=ne.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),Bh.has(me)&&Ie(!0),Te(me)}}};return window.addEventListener("markus:navigate",U),window.addEventListener("hashchange",w),()=>{window.removeEventListener("markus:navigate",U),window.removeEventListener("hashchange",w)}},[n]);const El=w=>{re(!1),lt(r("work:task.projectCreated")),P(U=>U.some(ee=>ee.id===w.id)?U:[...U,w]),Dt(w.id),vn()},Ml=async w=>{try{await ae.projects.delete(w),F===w&&Kt(),lt(r("work:task.projectDeleted")),vn(),et()}catch(U){lt(r("work:task.errorGeneric",{message:String(U)}))}},bo=async()=>{if(!ye||!tt||!dt||St)return;Je("");const w=dt.startsWith("human:"),U=dt.replace(/^(human|agent):/,"");if(tt===U&&!w){lt(r("work:task.assignedReviewerDifferent"));return}const ee=xt||void 0,ne=qt||void 0;Ft(!0);try{const{task:me}=await ae.tasks.create(ye,gt,tt,U,Nt,ee,Fe.length>0?Fe:void 0,ne,Ct!=="standard"?Ct:void 0,Ct==="scheduled"?{every:Qe}:void 0,w?"human":"agent");Le(""),ct(""),$e([]),at(""),we("standard"),it("4h"),Ee(!1),et(),me&&sr(me)}catch(me){const ke=`work:task.errorCode_${(me instanceof Qa?me.code:void 0)||"unknown"}`,oe=r(ke,{defaultValue:""});Je(oe||r("work:task.errorCreatingTask",{message:me instanceof Error?me.message:String(me)}))}finally{Ft(!1)}},$n=w=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:w}))},yo=()=>{At("/taskboard"),et(),Ne&&($n({taskId:Ne.id}),At("/tasks/"+Ne.id),ae.tasks.get(Ne.id).then(w=>{w.task&&Ce(U=>U?.id===w.task.id?w.task:U)}).catch(()=>{}))},Nn=()=>{At("/requirements"),Lt(),De&&(At("/requirements/"+De.id),ae.requirements.get(De.id).then(w=>{w.requirement&&Ae(U=>U?.id===w.requirement.id?w.requirement:U)}).catch(()=>{}))},vo=async()=>{if(!ms){if(!pn.trim()){on(r("work:task.pleaseReqTitle"));return}if(!Tn.trim()){on(r("work:task.pleaseReqDesc"));return}if(!yn){on(r("work:task.pleaseReqProject"));return}on(""),co(!0);try{const{requirement:w}=await ae.requirements.create({title:pn.trim(),description:Tn.trim(),priority:er,projectId:yn});lt(r("work:task.requirementCreated")),xn(""),bn(""),gn(!1),Lt(),w&&Dn(w)}catch(w){on(w instanceof Error?w.message:String(w))}finally{co(!1)}}},xs=async w=>{try{await ae.requirements.approve(w),lt(r("work:task.requirementApproved")),$n({requirementId:w}),Nn(),et()}catch(U){lt(r("work:task.errorGeneric",{message:String(U)}))}},Il=async()=>{if(sn){Rn("");try{await ae.requirements.reject(sn,Sr),lt(r("work:task.requirementRejected")),$n({requirementId:sn}),Rt(null),Er(""),Rn(""),Nn()}catch(w){Rn(w instanceof Error?w.message:String(w))}}},wo=async w=>{try{await ae.requirements.cancel(w),lt(r("work:task.requirementCancelled")),$n({requirementId:w}),Nn()}catch(U){lt(r("work:task.errorGeneric",{message:String(U)}))}},Tl=(w,U)=>{nn.current=U,rn.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`task:${U.id}`),w.currentTarget.style.opacity="0.4"},Rl=(w,U)=>{rn.current=U,nn.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`req:${U.id}`),w.currentTarget.style.opacity="0.4"},ko=w=>{w.currentTarget.style.opacity="1",nn.current=null,rn.current=null,yt(null)},_l=(w,U)=>{w.preventDefault(),w.dataTransfer.dropEffect="move",Mt!==U&&yt(U)},Ll=(w,U)=>{const ee=w.currentTarget.getBoundingClientRect(),{clientX:ne,clientY:me}=w;(ne<ee.left||ne>ee.right||me<ee.top||me>ee.bottom)&&Mt===U&&yt(null)},Dl=async(w,U)=>{w.preventDefault(),yt(null);const ee=nn.current,ne=rn.current;if(ee){const me=o.find(ke=>ke.id===U);if(!me)return;const Se=me.dropStatus;if(ee.status===Se||ee.status==="pending")return;try{await ae.tasks.updateStatus(ee.id,Se),et()}catch{}}else if(ne){const me=wl[U];if(!me||ne.status===me)return;try{await ae.requirements.updateStatus(ne.id,me),Lt()}catch{}}},jo=w=>{Et(U=>{const ee=new Set(U);return ee.has(w)?ee.delete(w):ee.add(w),ee})},Rr=w=>{Dt(w)},Al=new Set(["rejected","cancelled","archived"]),_r=w=>Al.has(w.status),or=(w,U=!1)=>{let ee=w.filter(ne=>he||!_r(ne));return Me&&(ee=ee.filter(ne=>ne.status===Me)),W==="project"&&F&&(ee=ee.filter(ne=>ne.projectId===F)),Ue.size>0&&(ee=ee.filter(ne=>ne.projectId&&Ue.has(ne.projectId))),He.size>0&&(ee=ee.filter(ne=>ne.assignedAgentId&&He.has(ne.assignedAgentId))),Ye&&e?.id&&(ee=ee.filter(ne=>ne.createdBy===e.id)),ee},Pl=g.useMemo(()=>{const w=new Map;for(const U of Object.values(H))for(const ee of U)w.set(ee.id,ee);return w},[H]),$l=g.useMemo(()=>new Set(J.map(w=>w.id)),[J]),No=w=>w.statuses.flatMap(U=>or(H[U]??[])),Zt=g.useMemo(()=>{let w=se;return he||(w=w.filter(U=>!_r(U))),W==="project"&&F&&(w=w.filter(U=>U.projectId===F)),Ue.size>0&&(w=w.filter(U=>U.projectId&&Ue.has(U.projectId))),He.size>0&&(w=w.filter(U=>He.has(U.createdBy))),Ye&&e?.id&&(w=w.filter(U=>U.createdBy===e.id)),w},[se,he,W,F,Ue,He,Ye,e?.id,$l]),Co=g.useCallback(w=>Zt.filter(U=>Jr[U.status]===w.id),[Zt]),Bl=o.filter(w=>{if(w.id==="failed"||w.id==="closed"){const U=No(w),ee=Co(w);return U.length+ee.length>0}return!0}),ar=Object.values(H).flat().filter(w=>_r(w)).length+se.filter(w=>_r(w)).length,So=g.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),U=Object.values(H).flat(),ee=new Set;for(const ne of U)ne.assignedAgentId&&!w.has(ne.status)&&(!F||ne.projectId===F)&&ee.add(ne.assignedAgentId);return[...J].sort((ne,me)=>{const Se=ee.has(ne.id)?0:1,ke=ee.has(me.id)?0:1;return Se-ke})},[J,H,F]),Lr=g.useMemo(()=>{const w=new Map,U=[];for(const ne of So)if(ne.teamId){const me=w.get(ne.teamId)??[];me.push(ne.id),w.set(ne.teamId,me)}else U.push(ne);const ee=[];for(const ne of U)ee.push({kind:"agent",agent:ne});for(const ne of te){const me=w.get(ne.id);me&&me.length>0&&ee.push({kind:"team",id:ne.id,name:ne.name,agentIds:me})}return ee},[So,te]);g.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),U=Object.values(H).flat(),ee=new Set;for(const me of U)me.projectId&&!w.has(me.status)&&ee.add(me.projectId);return[...he?R:R.filter(me=>me.status!=="archived")].sort((me,Se)=>{const ke=me.status==="archived"?1:0,oe=Se.status==="archived"?1:0;if(ke!==oe)return ke-oe;const Ze=ee.has(me.id)?0:1,kt=ee.has(Se.id)?0:1;return Ze!==kt?Ze-kt:me.name.localeCompare(Se.name)})},[R,H,he]);const Dr=g.useMemo(()=>{const w={};for(const U of Object.values(H))for(const ee of U){const ne=ee.projectId??"__none__";w[ne]=(w[ne]??0)+1}return w},[H]),Ar=Object.values(Dr).reduce((w,U)=>w+U,0),Ol=F?Dr[F]??0:Ar,Eo=g.useMemo(()=>{const w=or(Object.values(H).flat()),U=[];if(Xe==="kanban"){for(const ne of ss){const me=ne.statuses.flatMap(oe=>w.filter(Ze=>Ze.status===oe)),ke=[...Zt.filter(oe=>Jr[oe.status]===ne.id).map(oe=>({kind:"req",data:oe,time:new Date(oe.updatedAt??oe.createdAt).getTime()})),...me.map(oe=>({kind:"task",data:oe,time:new Date(oe.updatedAt??oe.createdAt??0).getTime()}))];ke.sort((oe,Ze)=>Ze.time-oe.time);for(const oe of ke)oe.kind==="req"?U.push({kind:"req",data:oe.data}):U.push({kind:"task",data:oe.data})}return U}const ee=[];for(const ne of w){const me=kl(ne.status);ee.push({kind:"task",data:ne,groupOrder:os[me]??5,time:new Date(ne.updatedAt??ne.createdAt??0).getTime()})}for(const ne of Zt){const me=Jr[ne.status]??"todo";ee.push({kind:"req",data:ne,groupOrder:os[me]??5,time:new Date(ne.updatedAt??ne.createdAt).getTime()})}return ee.sort((ne,me)=>ne.groupOrder!==me.groupOrder?ne.groupOrder-me.groupOrder:me.time-ne.time),ee.map(ne=>ne.kind==="req"?{kind:"req",data:ne.data}:{kind:"task",data:ne.data})},[H,Zt,Xe,he,Me,F,Ue,He,Ye,e?.id,W]),Pr=g.useRef(Eo);Pr.current=Eo;const Mo=g.useRef(_t);Mo.current=_t;const bs=g.useRef(F);bs.current=F;const Bn=g.useCallback(w=>{w.kind==="req"?(Ae(w.data),Ce(null)):(Ce(w.data),Ae(null)),S("item"),D("auto"),q("items")},[]),Io=g.useCallback(()=>{if(kn.current==="item"||kn.current==="empty"){S("closed"),Ce(null),Ae(null);return}if(Yt.current||Gt.current){S("item"),D("auto"),q("items");return}const w=Pr.current;if(w.length>0){Bn(w[0]);return}Ce(null),Ae(null),S("empty"),D("auto")},[Bn]);g.useEffect(()=>{if(!l)if(p){if(q("items"),kn.current==="project")if(Yt.current||Gt.current)S("item");else{const w=Pr.current;w.length>0?Bn(w[0]):S("closed")}}else _n.current==="items"&&kn.current==="closed"||!p&&kn.current==="closed"&&q("projects")},[p,l,Bn]);const ir=d?.keyboardPane??"content",To=g.useRef(ir);if(g.useEffect(()=>{if(n||l||!i)return;const w=To.current;To.current=ir,ir==="l1"&&(q("projects"),w!=="l1"&&Ln.current&&(C(!1),d?.setLeftCollapsed(!1)))},[ir,n,l,i,C,d]),g.useEffect(()=>{if(n||l||!i)return;const w=navigator.platform.toUpperCase().includes("MAC"),U=ee=>{if(d?.keyboardPane==="l0")return;const ne=w?ee.metaKey&&!ee.ctrlKey:ee.ctrlKey&&!ee.metaKey;if(ee.ctrlKey&&!ee.metaKey&&ee.key==="Tab"){ee.preventDefault();const je=Ih,We=je.indexOf(gs.current),_e=ee.shiftKey?je[(We-1+je.length)%je.length]:je[(We+1)%je.length];ut(_e);return}if(ne&&!ee.altKey&&!ee.shiftKey){const je=ee.key.toLowerCase();if(je==="j"){ee.preventDefault(),Mr();return}if(je==="l"){ee.preventDefault(),Io();return}}if(ne||ee.altKey||ee.ctrlKey||ee.metaKey||Xl(ee.target))return;const me=ee.key.length===1?ee.key.toLowerCase():ee.key;if(me==="h"||me==="ArrowLeft"){if(Ln.current){ee.preventDefault(),C(!1),d?.setLeftCollapsed(!1),q("projects"),d?.setKeyboardPane("l1");return}if(_n.current==="items"){ee.preventDefault(),q("projects"),d?.setKeyboardPane("l1");return}ee.preventDefault(),d?.setL0FocusPageId(Ve.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((me==="l"||me==="ArrowRight"||me==="Tab"&&!ee.shiftKey)&&!Ln.current&&_n.current==="projects"){ee.preventDefault(),q("items"),d?.setKeyboardPane("content");return}if((me==="l"||me==="ArrowRight")&&(Ln.current||_n.current==="items")){ee.preventDefault();return}const Se=me==="j"||me==="ArrowDown"?1:me==="k"||me==="ArrowUp"?-1:0;if(!Se)return;if((Ln.current?"items":_n.current)==="projects"){ee.preventDefault(),d?.setKeyboardPane("l1");const je=Mo.current,We=je.length+1;if(je.length===0)return;const _e=bs.current==null?0:je.findIndex(On=>On.id===bs.current)+1,Xt=_e<0?0:_e,Cn=Math.max(0,Math.min(We-1,Xt+Se));if(Cn===0)Kt(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const On=je[Cn-1];Dt(On.id),kn.current!=="closed"&&(S("project"),Ce(null),Ae(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${On.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const oe=gs.current;if(oe!=="backlog"&&oe!=="kanban")return;ee.preventDefault(),d?.setKeyboardPane("content");const Ze=Pr.current;if(Ze.length===0){S(je=>je==="closed"?"empty":je);return}const kt=Yt.current?.id??Gt.current?.id??null;let ht=kt?Ze.findIndex(je=>je.data.id===kt):-1;ht<0&&(ht=Se>0?-1:0);const Be=Math.max(0,Math.min(Ze.length-1,ht+Se));Bn(Ze[Be]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${Ze[Be].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",U,!0),()=>document.removeEventListener("keydown",U,!0)},[n,l,i,Mr,Io,Dt,Kt,Bn,C,d]),ue)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:r("work:task.loadingPage")});const Ro=B!=="closed"||!!(Ne||De),$r=!l&&!!(Ne&&De)&&B==="item",_o=l?O:Ro;return t.jsxs("div",{ref:f,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!l&&t.jsx(Eh,{projects:_t,selectedProjectId:F,allSelected:W==="all"&&!F,taskCounts:Dr,totalTaskCount:Ar,onSelectAll:()=>{Kt(),q("projects")},onSelectProject:w=>{Dt(w),q("projects")},onEditProject:w=>{Dt(w),Ce(null),Ae(null),S("project"),q("projects")},onCreateProject:()=>re(!0),onCollapse:()=>{const w=!p;C(w),d?.setLeftCollapsed(w)},width:v.width,onResizeStart:v.onResizeStart,hidden:p,focused:ir==="l1"&&V==="projects"&&!p,onActivate:()=>q("projects")}),t.jsxs("div",{"data-keyboard-pane":"content",onPointerDown:()=>q("items"),className:`${l?"flex-1 min-w-0":$r?"w-0 shrink-0 overflow-hidden":"flex-1 min-w-0"} overflow-hidden flex flex-col bg-surface-primary`,style:l&&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}),l?t.jsxs("div",{className:"shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[t.jsx(Zl,{}),wt?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:wt.name}),t.jsx("button",{onClick:Mr,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:_t.length})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>re(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortProject")}),t.jsx("button",{onClick:ve,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortReq")}),t.jsx("button",{onClick:()=>{nt(F??""),Ee(!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 items-center gap-2 px-3 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"].map(w=>t.jsx("button",{onClick:()=>ut(w),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${Xe===w?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:r(w==="backlog"?"work:task.backlog":w==="kanban"?"work:task.kanban":"work:task.dag")},w))}),ar>0&&t.jsx("button",{onClick:()=>Ie(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${he?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:he?r("work:task.hideArchived"):r("work:task.archivedCount",{count:ar})}),t.jsx("div",{className:"flex-1"}),Me&&t.jsxs("button",{onClick:()=>Te(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.${Me==="in_progress"?"inProgress":Me}`),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"})]})]}),(_t.length>1||J.length>0||e?.id)&&t.jsxs("button",{onClick:()=>ft(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${He.size>0||Ye?"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"})}),He.size+(Ye?1:0)>0?r("work:task.filterWithCount",{count:He.size+(Ye?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=!p;C(w),d?.setLeftCollapsed(w),q("projects")},className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors shrink-0 ${p?"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(p?"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"})]})}),wt?t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[t.jsx(_h,{value:wt.name,onSave:async w=>{await ae.projects.update(wt.id,{name:w}),vn()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:Mr,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:_t.length})}),ar>0&&t.jsx("button",{onClick:()=>Ie(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${he?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:he?r("work:task.hideArchivedWithCount",{count:ar}):r("work:task.archivedCount",{count:ar})}),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:()=>ut(w),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Xe===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:ve,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:()=>{nt(F??""),Ee(!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"})]}),!l&&Xe!=="workflows"&&(Lr.length>0||e?.id)&&(Ol>0||Zt.length>0||He.size>0||Ye)&&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:()=>{Et(new Set),Wt(!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 ${He.size>0||Ye?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),e?.id&&t.jsx("button",{type:"button",onClick:()=>Wt(w=>!w),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Ye?"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")}),Lr.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(Se=>He.has(Se)),me=!ne&&w.agentIds.some(Se=>He.has(Se));return t.jsxs("button",{onClick:()=>{Et(Se=>{const ke=new Set(Se);if(ne)for(const oe of w.agentIds)ke.delete(oe);else for(const oe of w.agentIds)ke.add(oe);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":me?"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 U=w.agent,ee=He.has(U.id);return t.jsxs("button",{onClick:()=>jo(U.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ee?"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 ${ee?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:U.name[0]?.toUpperCase()}),U.name]},U.id)})]}),_t.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:()=>re(!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")})]})}):or(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"})]})}),He.size>0||Ye?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:()=>{Et(new Set),Wt(!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:ve,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:()=>{nt(F??""),Ee(!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")})]})]})]})}):Xe==="backlog"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:l?vt.onTouchStart:void 0,onTouchEnd:l?vt.onTouchEnd:void 0,children:t.jsx(Kh,{tasks:or(Object.values(H).flat()),requirements:Zt,agents:J,projects:R,onTaskClick:w=>Ir(w),onReqClick:w=>Tr(w),onRefresh:()=>{et(),Lt()},selectedTaskId:Ne?.id,selectedReqId:De?.id})}):Xe==="workflows"?t.jsx(Qh,{teamId:Nl,projectId:F,agents:J,projects:R,onViewRunTasks:w=>{const U=ne=>{Dn(ne),tn(`req-${ne.id}`),ut("dag")},ee=se.find(ne=>ne.id===w);ee?U(ee):ae.requirements.get(w).then(ne=>{ne.requirement&&(ge(me=>[...me,ne.requirement]),U(ne.requirement))}).catch(()=>{})}}):Xe==="dag"?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:l?vt.onTouchStart:void 0,onTouchEnd:l?vt.onTouchEnd:void 0,children:[t.jsx(Ch,{tasks:(()=>{const w=or(Object.values(H).flat(),!0);if(n&&De){const U=new Set(De.taskIds??[]);return w.filter(ee=>U.has(ee.id))}return w})(),requirements:n&&De?[De]:Zt,agents:J,showArchived:he,onShowArchivedChange:Ie,onTaskClick:w=>Ir(w),onReqClick:w=>Tr(w),onCollapseDAG:()=>{Ce(null),Ae(null),tn(null)},onDependencyChange:et,selectedTaskId:Ne?.id,selectedReqId:De?.id,hasDetailPanel:Ro,defaultExpandedNodeId:mn??(n&&De?`req-${De.id}`:void 0),previewMode:n}),l&&t.jsx("button",{onClick:()=>ut("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"})})})]}):t.jsx("div",{ref:It,className:"flex-1 min-h-0 overflow-auto px-4 py-5",onTouchStart:l?G.onTouchStart:void 0,onTouchEnd:l?G.onTouchEnd:void 0,children:t.jsx("div",{className:"flex gap-3 items-stretch",children:Bl.map(w=>{const U=No(w),ee=Co(w),ne=U.length+ee.length,me=Mt===w.id;return t.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col transition-colors ${me?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:Se=>_l(Se,w.id),onDragLeave:Se=>Ll(Se,w.id),onDrop:Se=>{Dl(Se,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 ${me?"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 Se=[...ee.map(ke=>({kind:"req",data:ke,time:new Date(ke.updatedAt??ke.createdAt).getTime()})),...U.map(ke=>({kind:"task",data:ke,time:new Date(ke.updatedAt??ke.createdAt??0).getTime()}))];return Se.sort((ke,oe)=>oe.time-ke.time),Se.map(ke=>{if(ke.kind==="req"){const oe=ke.data,Ze=c[oe.status]??{label:oe.status,cls:"bg-gray-500/15 text-fg-secondary"},ht=oe.source==="agent"&&oe.status==="pending",Be=W==="all"&&oe.projectId?R.find(_e=>_e.id===oe.projectId):null,je=Qn(oe.createdBy,J,ie)??oe.createdBy.slice(0,10),We=De?.id===oe.id;return t.jsxs("div",{"data-work-item-id":oe.id,role:"button",tabIndex:0,draggable:!0,onDragStart:_e=>Rl(_e,oe),onDragEnd:ko,onClick:()=>Tr(oe),onKeyDown:_e=>_e.key==="Enter"&&Tr(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
|
|
10
|
-
${ht?"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"}
|
|
11
|
-
${We?"!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 ${Ze.cls}`,children:Ze.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:oe.title}),oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:oe.description}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[Be&&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:Be.name,children:Be.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:oe.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",je]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[oe.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:oe.goalConfig.completionCriteria,children:["🎯 ",oe.goalConfig.currentIteration,"/",oe.goalConfig.maxIterations]}),oe.taskIds.length>0&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",oe.taskIds.length]})]})]}),ht&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:_e=>{_e.stopPropagation(),xs(oe.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:r("work:task.approve")}),t.jsx("button",{onClick:_e=>{_e.stopPropagation(),Rt(oe.id)},className:"flex-1 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:r("work:task.reject")})]})]},`req-${oe.id}`)}else{const oe=ke.data,Ze=oe.subtasks?.length??0,kt=a[oe.status],ht=oe.status==="pending",Be=oe.taskType==="scheduled"&&!!oe.scheduleConfig,je=Be?oe.scheduleConfig.every?r("work:task.everyInterval",{interval:oe.scheduleConfig.every}):oe.scheduleConfig.cron?r("work:task.cronLabel"):r("work:task.scheduledShort"):null,We=W==="all"&&oe.projectId?(()=>{const ot=R.find(Br=>Br.id===oe.projectId)?.name;return ot&&ot!=="default"?ot:null})():null,_e=oe.requirementId?se.find(ot=>ot.id===oe.requirementId)?.title:null,Xt=oe.createdBy?Qn(oe.createdBy,J,ie)??oe.createdBy:null,Cn=Ne?.id===oe.id,On={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},Lo=oe.status==="blocked"&&(!oe.blockedBy||oe.blockedBy.length===0||oe.blockedBy.every(ot=>{const Br=Pl.get(ot);return Br&&Br.status==="completed"}));return t.jsxs("div",{"data-work-item-id":oe.id,role:"button",tabIndex:0,"aria-label":oe.title,draggable:!ht,onDragStart:ot=>!ht&&Tl(ot,oe),onDragEnd:ko,onClick:()=>Ir(oe),onKeyDown:ot=>ot.key==="Enter"&&Ir(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Lo?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":ht?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Be?"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"} ${Cn?"!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 ${On[oe.priority]??"bg-gray-400"}`,title:oe.priority}),Be&&t.jsx("span",{className:"text-blue-500 shrink-0",title:je??"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"})})}),Be&&je&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:je}),kt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${kt.cls}`,children:kt.label}),Lo&&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:oe.title}),oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:oe.description}),(We||_e||oe.blockedBy&&oe.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[We&&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:We,children:We}),_e&&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:_e,children:["# ",_e]}),oe.blockedBy&&oe.blockedBy.length>0&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",oe.blockedBy.length," dep",oe.blockedBy.length>1?"s":""]})]}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsx("div",{className:"flex items-center gap-1.5",children: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:[Ze>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ze]}),oe.notes&&oe.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",oe.notes.length]}),oe.assignedAgentId&&t.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${yr[J.find(ot=>ot.id===oe.assignedAgentId)?.status??""]??"bg-gray-500"}`}),J.find(ot=>ot.id===oe.assignedAgentId)?.name??oe.assignedAgentId.slice(0,8)]})]})]})]},oe.id)}})})()}),me&&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)})})})]}),!l&&_o&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:j,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"})}),_o&&t.jsx("div",{className:`${l||$r?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:l||$r?void 0:{width:M},children:B==="project"&&wt?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:wn,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(Vh,{project:wt,tasks:Object.values(H).flat().filter(w=>w.projectId===wt.id),requirements:se.filter(w=>w.projectId===wt.id),agents:J,onDeleteProject:()=>Ml(wt.id),onUpdateProject:async w=>{await ae.projects.update(wt.id,w),vn()},onRefresh:()=>{vn()}})]}):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:ve,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:()=>{nt(F??""),Ee(!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:wn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})}):$r?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(Ua,{req:De,agents:J,projects:R,allTasks:Object.values(H).flat(),users:ie,onClose:()=>{Ae(null),Ne||wn()},onApprove:w=>{xs(w)},onReject:w=>{Rt(w)},onCancel:w=>{wo(w),Ae(null)},onStatusChange:async(w,U)=>{try{await ae.requirements.updateStatus(w,U),lt(`Requirement status → ${U}`),$n({requirementId:w}),Nn(),et()}catch(ee){lt(`Error: ${ee}`)}},onRefresh:Nn,authUser:e,onTaskClick:w=>{Ce(w),S("item")},onCreateTask:(w,U)=>{at(w),U&&nt(U),Ee(!0)},onProjectClick:Rr,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(Ya,{task:Ne,agents:J,projects:R,requirements:se,allTasks:Object.values(H).flat(),users:ie,onClose:Cl,onRefresh:yo,authUser:e,scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{Ae(U=>U?.id===w.id?null:w),S("item")},onProjectClick:Rr})})]}):Ne?t.jsx(Ya,{task:Ne,agents:J,projects:R,requirements:se,allTasks:Object.values(H).flat(),users:ie,onClose:wn,onRefresh:yo,authUser:e,scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{Ae(w),Ce(null),S("item")},onProjectClick:Rr}):De?t.jsx(Ua,{req:De,agents:J,projects:R,allTasks:Object.values(H).flat(),users:ie,onClose:wn,onApprove:w=>{xs(w)},onReject:w=>{Rt(w)},onCancel:w=>{wo(w),wn()},onStatusChange:async(w,U)=>{try{await ae.requirements.updateStatus(w,U),lt(`Requirement status → ${U}`),$n({requirementId:w}),Nn(),et()}catch(ee){lt(`Error: ${ee}`)}},scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onRefresh:Nn,authUser:e,onTaskClick:w=>{Ce(w),Ae(null),S("item"),l&&(_(!0),history.pushState({mobileDetail:Ve.WORK},"",window.location.hash))},onCreateTask:(w,U)=>{at(w),U&&nt(U),Ee(!0)},onProjectClick:Rr,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:wn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})})}),fe&&t.jsx(Sh,{orgId:e?.orgId,onCreated:El,onClose:()=>re(!1)}),xe&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ee(!1),Je("")},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 ${l?"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",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.titleLabel")}),t.jsx("input",{autoFocus:!l,value:ye,onChange:w=>Le(w.target.value),onKeyDown:w=>{w.key==="Enter"&&bo()},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.descriptionField")}),t.jsx("textarea",{value:gt,onChange:w=>ct(w.target.value),rows:2,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.projectLabel")}),t.jsx(cr,{options:[{value:"",label:r("work:task.noProject")},...R.map(w=>({value:w.id,label:w.name}))],value:xt,onChange:w=>{nt(w),at("")},placeholder:r("work:task.noProject"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.requirementLabel")}),t.jsx(cr,{options:[{value:"",label:r("work:task.selectRequirement")},...se.filter(w=>w.status==="in_progress"&&(!xt||w.projectId===xt)).map(w=>({value:w.id,label:w.title}))],value:qt,onChange:at,placeholder:r("work:task.selectRequirement"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.assignToRequired")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:J.map(w=>({value:w.id,label:`${w.name} (${w.status})`})),value:tt,onChange:Ht,placeholder:r("work:task.selectAgent"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.reviewerRequired")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:[...ie.map(w=>({value:`human:${w.id}`,label:w.name})),...J.filter(w=>w.id!==tt).map(w=>({value:`agent:${w.id}`,label:`${w.name} (${w.status})`}))],value:dt,onChange:Jt,placeholder:r("work:task.selectReviewer"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:`grid gap-4 ${Ct==="scheduled"?"grid-cols-3":"grid-cols-2"}`,children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.priorityField")}),t.jsxs("select",{value:Nt,onChange:w=>pt(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:r("work:priority.low")}),t.jsx("option",{value:"medium",children:r("work:priority.medium")}),t.jsx("option",{value:"high",children:r("work:priority.high")}),t.jsx("option",{value:"urgent",children:r("work:priority.urgent")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.taskType")}),t.jsxs("select",{value:Ct,onChange:w=>we(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"standard",children:r("work:task.taskTypeStandard")}),t.jsx("option",{value:"scheduled",children:r("work:task.taskTypeScheduled")})]})]}),Ct==="scheduled"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.frequency")}),t.jsxs("select",{value:Qe,onChange:w=>it(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"30m",children:r("work:task.freq30m")}),t.jsx("option",{value:"1h",children:r("work:task.freq1h")}),t.jsx("option",{value:"2h",children:r("work:task.freq2h")}),t.jsx("option",{value:"4h",children:r("work:task.freq4h")}),t.jsx("option",{value:"8h",children:r("work:task.freq8h")}),t.jsx("option",{value:"12h",children:r("work:task.freq12h")}),t.jsx("option",{value:"1d",children:r("work:task.freq1d")}),t.jsx("option",{value:"1w",children:r("work:task.freq1w")})]})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.blockedBy")}),t.jsx(Th,{options:Object.values(H).flat().filter(w=>w.status!=="completed"&&w.status!=="cancelled").map(w=>({value:w.id,label:w.title})),selected:Fe,onAdd:w=>$e([...Fe,w]),placeholder:r("work:task.selectDependency"),noMatchesText:r("work:task.noMatches")}),Fe.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Fe.map(w=>{const U=Object.values(H).flat().find(ee=>ee.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:[U?U.title.slice(0,30):w.slice(-8),t.jsx("button",{onClick:()=>$e(Fe.filter(ee=>ee!==w)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},w)})})]}),bt&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:bt}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{Ee(!1),Je("")},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:()=>{bo()},disabled:!ye.trim()||!tt||!dt||St,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:r(St?"common:creating":"common:create")})]})]})}),Jn&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{gn(!1),xn(""),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 ${l?"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",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.projectLabel")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:R.map(w=>({value:w.id,label:w.name})),value:yn,onChange:Cr,placeholder:r("work:task.selectProject"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.titleField")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("input",{value:pn,onChange:w=>xn(w.target.value),placeholder:r("work:task.reqTitleExample"),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!l,onKeyDown:w=>{w.key==="Enter"&&pn.trim()&&vo()}})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.descriptionField")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("textarea",{value:Tn,onChange:w=>bn(w.target.value),placeholder:r("work:task.reqDescPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.priorityField")}),t.jsxs("select",{value:er,onChange:w=>hs(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:r("work:priority.low")}),t.jsx("option",{value:"medium",children:r("work:priority.medium")}),t.jsx("option",{value:"high",children:r("work:priority.high")}),t.jsx("option",{value:"urgent",children:r("work:priority.urgent")})]})]}),tr&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:tr}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{gn(!1),xn(""),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:()=>{vo()},disabled:!pn.trim()||!Tn.trim()||!yn||ms,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(ms?"common:creating":"common:create")})]})]})}),sn&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Rt(null),Rn("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${l?"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:Sr,onChange:w=>Er(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:!l})]}),uo&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:uo}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>{Rt(null),Rn("")},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:()=>{Il()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:r("work:task.reject")})]})]})}),st&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>ft(!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:[(He.size>0||Ye)&&t.jsx("button",{onClick:()=>{Et(new Set),Wt(!1)},className:"text-[11px] text-brand-500 font-medium",children:r("work:task.clearAll")}),t.jsx("button",{onClick:()=>ft(!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"})]})})]})]}),_t.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:()=>{Kt(),ft(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${W==="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"),Ar>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Ar})]}),_t.map(w=>{const U=F===w.id,ee=Dr[w.id]??0;return t.jsxs("button",{type:"button",onClick:()=>{Dt(w.id),ft(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${U?"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 ${U?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:w.name[0]?.toUpperCase()}),w.name,ee>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:ee})]},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:()=>Wt(w=>!w),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Ye?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:r("work:task.myTasks")})}),Lr.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:Lr.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(Se=>He.has(Se)),me=!ne&&w.agentIds.some(Se=>He.has(Se));return t.jsxs("button",{onClick:()=>{Et(Se=>{const ke=new Set(Se);if(ne)for(const oe of w.agentIds)ke.delete(oe);else for(const oe of w.agentIds)ke.add(oe);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":me?"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 U=w.agent,ee=He.has(U.id);return t.jsxs("button",{onClick:()=>jo(U.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ee?"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 ${ee?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:U.name[0]?.toUpperCase()}),U.name]},U.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Jh({requirementId:e,createdBy:n,agents:s,users:r,authUser:i}){const{t:o}=Oe(["work","common"]),[a,c]=g.useState([]),[l,d]=g.useState([]),h=g.useRef(null),[f,m]=g.useState(new Map);g.useEffect(()=>{d([]),m(new Map),h.current&&(clearTimeout(h.current),h.current=null),ae.requirements.getComments(e).then(y=>c(y.comments)).catch(()=>{})},[e]),g.useEffect(()=>jt.on("requirement:comment",v=>{if(v.payload?.requirementId===e&&v.payload.comment){const x=v.payload.comment;c(b=>b.some(k=>k.id===x.id)?b:[...b,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(d(b=>{const k=b.filter(N=>N.id!==x.authorId);return k.length===0&&h.current&&(clearTimeout(h.current),h.current=null),k}),m(b=>{const k=new Map(b);return k.delete(x.authorId),k}))}}),[e]),g.useEffect(()=>{if(l.length===0)return;const y=new Set(l.map(x=>x.id));return jt.on("agent:activity_log",x=>{const b=x.payload;if(!b)return;const k=b.agentId;if(!y.has(k))return;const N=so(b);N&&m(I=>oo(I,k,N))})},[l]);const[u,p]=g.useState(null),E=async(y,v,x,b)=>{let k;x.length>0&&(k=(await ae.uploads.upload(x.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await ae.requirements.addComment(e,y,i?.name,k,i?.id,v.length>0?v:void 0,b);const N=[],I=new Set,D=A=>{if(I.has(A)||A===i?.id)return;I.add(A);const L=s.find(M=>M.id===A);L&&N.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const A of v){const L=s.find(M=>M.name.toLowerCase()===A.toLowerCase());L&&D(L.id)}n?.startsWith("agt_")&&D(n),N.length>0&&(h.current&&clearTimeout(h.current),d(N),h.current=setTimeout(()=>d([]),12e4))},C=g.useCallback(y=>{p({id:y.id,authorName:y.authorName,content:y.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(y=>t.jsx(ur,{comment:y,agents:s,onReply:C},y.id)),l.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(y=>{const v=f.get(y.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Ot.navigate(Ve.TEAM,{agentId:y.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Fs,{name:y.name,avatarUrl:y.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:y.name}),v.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:"→"})]}),v.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(ao,{entries:v})})]},y.id)})})]}),t.jsx(ni,{agents:s,humans:r,onSubmit:E,replyTo:u,onCancelReply:()=>p(null)})]})}function Ua({req:e,agents:n,projects:s,allTasks:r,users:i,onClose:o,onApprove:a,onReject:c,onCancel:l,onStatusChange:d,onRefresh:h,authUser:f,scrollToComments:m,onScrollToCommentsDone:u,onTaskClick:p,onCreateTask:E,onProjectClick:C,previewMode:y}){const{t:v}=Oe(["work","common"]),x=g.useMemo(()=>lo(v),[v]),b=g.useMemo(()=>vl(v),[v]),k=vr(),[N,I]=g.useState(!1),[D,A]=g.useState(e.description),[L,M]=g.useState(!1),[$,z]=g.useState(!1),[j,O]=g.useState(!1),_=g.useRef(null),[T,R]=g.useState("none"),P=g.useRef(null),W=g.useRef(null),Y=g.useRef(80);g.useEffect(()=>{const te=_.current;if(!te)return;const X=()=>{const{scrollTop:de,scrollHeight:se,clientHeight:ge}=te;if(!(se>ge+50)){R("none");return}const K=de<30,ce=de+ge>=se-30;R(K?"top":ce?"bottom":"middle")};X(),te.addEventListener("scroll",X,{passive:!0});const ie=new ResizeObserver(X);return ie.observe(te),()=>{te.removeEventListener("scroll",X),ie.disconnect()}},[]),g.useEffect(()=>{if(N&&W.current){const te=W.current;te.style.height="auto",te.style.height=Math.max(te.scrollHeight,Y.current)+"px",te.focus()}},[N]),g.useEffect(()=>{if(!m)return;const te=setTimeout(()=>{const X=_.current;X&&X.scrollTo({top:X.scrollHeight,behavior:"smooth"}),u?.()},300);return()=>clearTimeout(te)},[m,u]);const F=x[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},Q=e.source==="agent",B=Q&&e.status==="pending",S=e.status==="pending"||e.status==="in_progress",V=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",q=e.projectId?s.find(te=>te.id===e.projectId):null,H=Qn(e.createdBy,n,i)??e.createdBy.slice(0,12),Z=r.filter(te=>e.taskIds.includes(te.id)),J=q?.teamIds?.[0]??null;g.useMemo(()=>new Map(Z.map(te=>[te.id,te])),[Z]);const le=Z.length>=2;return g.useEffect(()=>{A(e.description),I(!1)},[e.id,e.description]),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:[k&&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:[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:v("work:task.requirementShort")})," ",t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${F.cls}`,children:F.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:v("common:priority."+e.priority,{defaultValue:e.priority})}):t.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:v("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),t.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:_,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:v("work:task.requirementDetailDescription")}),N?t.jsx("textarea",{ref:W,value:D,onChange:te=>{A(te.target.value);const X=te.target;X.style.height="auto",X.style.height=X.scrollHeight+"px"},onBlur:async()=>{if(D!==e.description){M(!0);try{await ae.requirements.update(e.id,{description:D}),h?.()}catch{}finally{M(!1)}}I(!1)},onKeyDown:te=>{te.key==="Escape"&&(te.preventDefault(),A(e.description),I(!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:v("work:task.requirementDetailDescription")}):t.jsx("div",{ref:P,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${V?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:V?void 0:te=>{te.target.closest("a, button, [data-entity-link]")||(Y.current=Math.max(P.current?.offsetHeight??80,60),A(e.description),I(!0))},role:V?void 0:"button",tabIndex:V?void 0:0,onKeyDown:V?void 0:te=>te.key==="Enter"&&(A(e.description),I(!0)),children:e.description?t.jsx(fr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:v("work:task.requirementNoDescription")})})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.createdByLabel")}),t.jsx("span",{className:"text-fg-secondary",children:H}),Q&&t.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:v("work:task.agentTag")})]}),t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.createdLabel")}),t.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),q&&t.jsxs("div",{className:`bg-surface-elevated/60 rounded-lg p-2.5 ${C?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:C?()=>C(q.id):void 0,role:C?"button":void 0,tabIndex:C?0:void 0,onKeyDown:C?te=>te.key==="Enter"&&C(q.id):void 0,children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.projectLabel")}),t.jsx("span",{className:"text-fg-secondary",children:q.name})]}),e.approvedBy&&t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.approvedBy")}),t.jsx("span",{className:"text-fg-secondary",children:Qn(e.approvedBy,n,i)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:v("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:v("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?v("work:requirement.goalMaxReached"):v("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:v("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&t.jsx("span",{children:v("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&t.jsx("span",{className:"text-brand-500",children:v("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(te=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",te]},te))}),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:v("work:task.linkedTasks",{count:Z.length})}),t.jsxs("div",{className:"flex items-center gap-2",children:[le&&J&&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"})}),v("work:task.saveAsWorkflow")]}),!V&&E&&t.jsxs("button",{onClick:()=>E(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"})}),v("work:requirement.createTask")]})]})]}),Z.length>0?(()=>{const te=new Map(Z.map(ue=>[ue.id,ue]));if(!Z.some(ue=>ue.blockedBy?.some(K=>te.has(K))))return t.jsx("div",{className:"space-y-1.5",children:Z.map(ue=>{const K=b[ue.status];return t.jsxs("div",{onClick:()=>p?.(ue),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${p?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[ue.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ue.title}),K&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${K.cls}`,children:K.label})]},ue.id)})});const ie=new Map,de=new Set;for(const ue of Z)for(const K of ue.blockedBy??[])if(te.has(K)){de.add(ue.id);const ce=ie.get(K)??[];ce.push(ue.id),ie.set(K,ce)}const se=Z.filter(ue=>!de.has(ue.id)),ge=(ue,K)=>{const ce=b[ue.status],pe=(ie.get(ue.id)??[]).map(ve=>te.get(ve)).filter(Boolean);return t.jsxs("div",{children:[t.jsxs("div",{onClick:()=>p?.(ue),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${p?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:K>0?{marginLeft:K*20}:void 0,children:[K>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 ${yr[ue.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ue.title}),ce&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${ce.cls}`,children:ce.label})]}),pe.map(ve=>ge(ve,K+1))]},ue.id)};return t.jsx("div",{className:"space-y-1.5",children:se.map(ue=>ge(ue,0))})})():t.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:v("work:requirement.noLinkedTasks")})]}),!y&&t.jsx(Jh,{requirementId:e.id,createdBy:e.createdBy,agents:n,users:i,authUser:f}),!y&&t.jsx(jl,{entityType:"requirement",entityId:e.id})]}),T!=="none"&&T!=="top"&&t.jsx("button",{onClick:()=>_.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:v("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"})})}),T!=="none"&&T!=="bottom"&&t.jsx("button",{onClick:()=>{const te=_.current;te&&te.scrollTo({top:te.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:v("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:[B&&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:v("work:requirement.approveRequirement")}),t.jsx("button",{onClick:()=>c(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:v("work:requirement.rejectRequirement")})]}),!B&&d&&!V&&t.jsx("select",{value:e.status,onChange:te=>{te.target.value!==e.status&&d(e.id,te.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:Gh.map(te=>{const X=x[te],ie=te===e.status||(Ws[e.status]?.has(te)??!1);return t.jsx("option",{value:te,disabled:!ie,children:X?.label??te},te)})}),V&&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:v("work:task.reopen")}),t.jsx("div",{className:"flex-1"}),S&&!B&&t.jsx("button",{onClick:()=>z(!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:v("work:task.cancelRequirement")})]}),$&&t.jsx(Hn,{title:v("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:v("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:v("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{z(!1),l(e.id)},onCancel:()=>z(!1)}),j&&J&&t.jsx(Uh,{req:e,tasks:Z,agents:n,teamId:J,onClose:()=>O(!1),onSaved:()=>O(!1)})]})}function jl({entityType:e,entityId:n}){const{t:s}=Oe(["work"]),[r,i]=g.useState([]),[o,a]=g.useState(!0),[c,l]=g.useState(!1);if(g.useEffect(()=>{a(!0),(e==="task"?ae.tasks.getHistory:ae.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=c?r:r.slice(-5),h=r.length>5&&!c,f=m=>{const u=m.changedByName||m.changedById||(m.changedByType==="human"?"User":m.changedByType==="agent"?"Agent":"System"),p=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 ${p}`,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")}),h&&t.jsx("button",{onClick:()=>l(!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:[f(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{om as WorkPage};
|