@markus-global/cli 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/commands/start.js +25 -0
  2. package/dist/commands/start.js.map +1 -1
  3. package/dist/markus.mjs +123 -14
  4. package/dist/web-ui/assets/{CommentInput-Ccv0KCzc.js → CommentInput-ZW-2JyIg.js} +1 -1
  5. package/dist/web-ui/assets/{ContentRenderer-BbN7QT3E.js → ContentRenderer-Ccoj5KhH.js} +2 -2
  6. package/dist/web-ui/assets/{Deliverables-Dzfujlqv.js → Deliverables-Cfdx-Yeu.js} +1 -1
  7. package/dist/web-ui/assets/Notifications-CKTZO9fn.js +1 -0
  8. package/dist/web-ui/assets/{Search-Va12fH-V.js → Search-_yYhKio7.js} +1 -1
  9. package/dist/web-ui/assets/{Settings-D_0MEUGb.js → Settings-BzI3q_dx.js} +1 -1
  10. package/dist/web-ui/assets/{Store-dRlOlppM.js → Store-DweBtEGf.js} +1 -1
  11. package/dist/web-ui/assets/Team-CpIDXpOi.js +40 -0
  12. package/dist/web-ui/assets/{Work-C6pfFbRU.js → Work-CMguHPuO.js} +5 -5
  13. package/dist/web-ui/assets/{arc-w52qYN0j.js → arc-BCQf-2jC.js} +1 -1
  14. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-Dq5t04Vy.js → architectureDiagram-3BPJPVTR-CPfkQ9P6.js} +1 -1
  15. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-dMSQ7RYP.js → blockDiagram-GPEHLZMM-w0CZJHe6.js} +1 -1
  16. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-yG4K-xPW.js → c4Diagram-AAUBKEIU-BTiNccgB.js} +1 -1
  17. package/dist/web-ui/assets/channel-DIphKEQ6.js +1 -0
  18. package/dist/web-ui/assets/{chunk-2J33WTMH-BMCCyFP7.js → chunk-2J33WTMH-BGdXq7Ci.js} +1 -1
  19. package/dist/web-ui/assets/{chunk-4BX2VUAB-DrZE__0f.js → chunk-4BX2VUAB-CDNqL2YA.js} +1 -1
  20. package/dist/web-ui/assets/{chunk-55IACEB6-BHAPJ9Eo.js → chunk-55IACEB6-B0gL5ae4.js} +1 -1
  21. package/dist/web-ui/assets/{chunk-727SXJPM-Ctfjl9vK.js → chunk-727SXJPM-C377nPB7.js} +1 -1
  22. package/dist/web-ui/assets/{chunk-AQP2D5EJ-SVZPGzSA.js → chunk-AQP2D5EJ-DmrWdQ_x.js} +1 -1
  23. package/dist/web-ui/assets/{chunk-FMBD7UC4-DeTpOrnv.js → chunk-FMBD7UC4-CasLcPiP.js} +1 -1
  24. package/dist/web-ui/assets/{chunk-ND2GUHAM-CudW1r3G.js → chunk-ND2GUHAM-Bl_5b1IO.js} +1 -1
  25. package/dist/web-ui/assets/{chunk-QZHKN3VN-CJSQIoVy.js → chunk-QZHKN3VN-CAFFoh9g.js} +1 -1
  26. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-CIRviJO4.js +1 -0
  27. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-CIRviJO4.js +1 -0
  28. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-CcCOSPt7.js → cose-bilkent-S5V4N54A-CNLxRUfr.js} +1 -1
  29. package/dist/web-ui/assets/{dagre-BM42HDAG-F3l9565T.js → dagre-BM42HDAG-CkqVIRox.js} +1 -1
  30. package/dist/web-ui/assets/{diagram-2AECGRRQ-B5Ep5hBX.js → diagram-2AECGRRQ-CBxL1Jqg.js} +1 -1
  31. package/dist/web-ui/assets/{diagram-5GNKFQAL-Ba-Xi40Z.js → diagram-5GNKFQAL-CpSDzWYR.js} +1 -1
  32. package/dist/web-ui/assets/{diagram-KO2AKTUF-nq3nvV52.js → diagram-KO2AKTUF-DG-3NyJR.js} +1 -1
  33. package/dist/web-ui/assets/{diagram-LMA3HP47-BLQG5suI.js → diagram-LMA3HP47-DOq08i33.js} +1 -1
  34. package/dist/web-ui/assets/{diagram-OG6HWLK6-BZwEfL_A.js → diagram-OG6HWLK6-B6_uG9hH.js} +1 -1
  35. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-x0d6Urzc.js → erDiagram-TEJ5UH35-DOyEVlMM.js} +1 -1
  36. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-Bps4iInm.js → flowDiagram-I6XJVG4X-BiWeEgX3.js} +1 -1
  37. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-BQhqabZG.js → ganttDiagram-6RSMTGT7-D-j-5cEg.js} +1 -1
  38. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-CZsFUtiG.js → gitGraphDiagram-PVQCEYII-C6lcURfO.js} +1 -1
  39. package/dist/web-ui/assets/index-CPULIfuW.css +1 -0
  40. package/dist/web-ui/assets/{index-BVZKeNvh.js → index-lNtr_En-.js} +55 -55
  41. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-bUkRpixn.js → infoDiagram-5YYISTIA-DU_r7Q4O.js} +1 -1
  42. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-C71uSHjN.js → ishikawaDiagram-YF4QCWOH-C7M7fHbe.js} +1 -1
  43. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-CH4cq7H3.js → journeyDiagram-JHISSGLW-DQJbMKSV.js} +1 -1
  44. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-B1plHCmn.js → kanban-definition-UN3LZRKU-D8nO46ug.js} +1 -1
  45. package/dist/web-ui/assets/{mermaid.core-BtKFJxef.js → mermaid.core-D9X_B1hr.js} +5 -5
  46. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-BRinAMnx.js → mindmap-definition-RKZ34NQL-BoWfA0x3.js} +1 -1
  47. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-B8r7cm8D.js → pieDiagram-4H26LBE5-GeMxJnY4.js} +1 -1
  48. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-BlYE_3Bv.js → quadrantDiagram-W4KKPZXB-B5xQl44f.js} +1 -1
  49. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-XHqns5Oh.js → requirementDiagram-4Y6WPE33-DAecntg7.js} +1 -1
  50. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP--WceN9u7.js → sankeyDiagram-5OEKKPKP-DOLj0rKK.js} +1 -1
  51. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-NXQDJA2d.js → sequenceDiagram-3UESZ5HK-BvS7cOXA.js} +1 -1
  52. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-Cs8Vl8wX.js → stateDiagram-AJRCARHV-CqHRpjfn.js} +1 -1
  53. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-Df743oiT.js +1 -0
  54. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-V9TBhcGA.js → timeline-definition-PNZ67QCA-Bsk6HQIz.js} +1 -1
  55. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-BkrjAkwE.js → vennDiagram-CIIHVFJN-CekJLx4L.js} +1 -1
  56. package/dist/web-ui/assets/{wardley-L42UT6IY-DnYl7xFk.js → wardley-L42UT6IY-CBUmu8Xa.js} +1 -1
  57. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-Bgjk8gUy.js → wardleyDiagram-YWT4CUSO-BgoDq86Z.js} +1 -1
  58. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-DVv-I1Er.js → xychartDiagram-2RQKCTM6-zDxkTG1v.js} +1 -1
  59. package/dist/web-ui/index.html +2 -2
  60. package/package.json +1 -1
  61. package/dist/web-ui/assets/Notifications-DMI9cmK5.js +0 -1
  62. package/dist/web-ui/assets/Team-D8m98W3b.js +0 -40
  63. package/dist/web-ui/assets/channel-0x_SxlyN.js +0 -1
  64. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-D4o-x8Tr.js +0 -1
  65. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-D4o-x8Tr.js +0 -1
  66. package/dist/web-ui/assets/index-BDWvYwl1.css +0 -1
  67. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-Cmof_fUq.js +0 -1
@@ -1,11 +1,11 @@
1
- import{ah as dl,ai as ul,F as fl,aj as hl,r as g,j as t,u as He,f as re,G as ml,a as rr,e as gl,B as pl,C as xl,b as cs,P as Ye,w as bt,a9 as kt,D as vr,ak as no,M as bl,J as Sn,n as Lt,t as Xn,al as yl,A as ws,$ as ro,am as ds,an as so,ao as us,ap as oo,aq as ao,ar as io,X as Ca,Z as Sa,Y as vl}from"./index-BVZKeNvh.js";import{ContentRenderer as wl}from"./ContentRenderer-BbN7QT3E.js";import{s as ht,e as Ea,f as ks,T as Kr,g as Qr,t as kl}from"./transform-CpIVI4vC.js";import{i as Jr}from"./value-DIujSiJ7.js";import{C as Ma}from"./CommentInput-Ccv0KCzc.js";function jl(e){let n;for(;n=e.sourceEvent;)e=n;return e}function jt(e,n){if(e=jl(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 Nl={passive:!1},Un={capture:!0,passive:!1};function es(e){e.stopImmediatePropagation()}function Tn(e){e.preventDefault(),e.stopImmediatePropagation()}function Ia(e){var n=e.document.documentElement,s=ht(e).on("dragstart.drag",Tn,Un);"onselectstart"in n?s.on("selectstart.drag",Tn,Un):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function Ta(e,n){var s=e.document.documentElement,r=ht(e).on("dragstart.drag",null);n&&(r.on("click.drag",Tn,Un),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 wr=e=>()=>e;function fs(e,{sourceEvent:n,subject:s,target:r,identifier:i,active:o,x:a,y:l,dx:c,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:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:h}})}fs.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Cl(e){return!e.ctrlKey&&!e.button}function Sl(){return this.parentNode}function El(e,n){return n??{x:e.x,y:e.y}}function Ml(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ra(){var e=Cl,n=Sl,s=El,r=Ml,i={},o=Ea("start","drag","end"),a=0,l,c,d,h,f=0;function m(b){b.on("mousedown.drag",u).filter(r).on("touchstart.drag",S).on("touchmove.drag",v,Nl).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(b,N){if(!(h||!e.call(this,b,N))){var w=p(this,n.call(this,b,N),b,N,"mouse");w&&(ht(b.view).on("mousemove.drag",x,Un).on("mouseup.drag",E,Un),Ia(b.view),es(b),d=!1,l=b.clientX,c=b.clientY,w("start",b))}}function x(b){if(Tn(b),!d){var N=b.clientX-l,w=b.clientY-c;d=N*N+w*w>f}i.mouse("drag",b)}function E(b){ht(b.view).on("mousemove.drag mouseup.drag",null),Ta(b.view,d),Tn(b),i.mouse("end",b)}function S(b,N){if(e.call(this,b,N)){var w=b.changedTouches,M=n.call(this,b,N),D=w.length,P,_;for(P=0;P<D;++P)(_=p(this,M,b,N,w[P].identifier,w[P]))&&(es(b),_("start",b,w[P]))}}function v(b){var N=b.changedTouches,w=N.length,M,D;for(M=0;M<w;++M)(D=i[N[M].identifier])&&(Tn(b),D("drag",b,N[M]))}function y(b){var N=b.changedTouches,w=N.length,M,D;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),M=0;M<w;++M)(D=i[N[M].identifier])&&(es(b),D("end",b,N[M]))}function p(b,N,w,M,D,P){var _=o.copy(),C=jt(P||w,N),$,z,j;if((j=s.call(b,new fs("beforestart",{sourceEvent:w,target:m,identifier:D,active:a,x:C[0],y:C[1],dx:0,dy:0,dispatch:_}),M))!=null)return $=j.x-C[0]||0,z=j.y-C[1]||0,function B(R,T,A){var L=C,q;switch(R){case"start":i[D]=B,q=a++;break;case"end":delete i[D],--a;case"drag":C=jt(A||T,N),q=a;break}_.call(R,b,new fs(R,{sourceEvent:T,subject:j,target:m,identifier:D,active:q,x:C[0]+$,y:C[1]+z,dx:C[0]-L[0],dy:C[1]-L[1],dispatch:_}),M)}}return m.filter=function(b){return arguments.length?(e=typeof b=="function"?b:wr(!!b),m):e},m.container=function(b){return arguments.length?(n=typeof b=="function"?b:wr(b),m):n},m.subject=function(b){return arguments.length?(s=typeof b=="function"?b:wr(b),m):s},m.touchable=function(b){return arguments.length?(r=typeof b=="function"?b:wr(!!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 Il=1e-12;function lo(e){return((e=Math.exp(e))+1/e)/2}function Tl(e){return((e=Math.exp(e))-1/e)/2}function Rl(e){return((e=Math.exp(2*e))-1)/(e+1)}const Rr=(function e(n,s,r){function i(o,a){var l=o[0],c=o[1],d=o[2],h=a[0],f=a[1],m=a[2],u=h-l,x=f-c,E=u*u+x*x,S,v;if(E<Il)v=Math.log(m/d)/n,S=function(M){return[l+M*u,c+M*x,d*Math.exp(n*M*v)]};else{var y=Math.sqrt(E),p=(m*m-d*d+r*E)/(2*d*s*y),b=(m*m-d*d-r*E)/(2*m*s*y),N=Math.log(Math.sqrt(p*p+1)-p),w=Math.log(Math.sqrt(b*b+1)-b);v=(w-N)/n,S=function(M){var D=M*v,P=lo(N),_=d/(s*y)*(P*Rl(n*D+N)-Tl(N));return[l+_*u,c+_*x,d*P/lo(n*D+N)]}}return S.duration=v*1e3*n/Math.SQRT2,S}return i.rho=function(o){var a=Math.max(.001,+o),l=a*a,c=l*l;return e(a,l,c)},i})(Math.SQRT2,2,4),kr=e=>()=>e;function _l(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 ts(e){e.stopImmediatePropagation()}function Fn(e){e.preventDefault(),e.stopImmediatePropagation()}function Al(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Ll(){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 co(){return this.__zoom||ks}function Dl(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Pl(){return navigator.maxTouchPoints||"ontouchstart"in this}function $l(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 _a(){var e=Al,n=Ll,s=$l,r=Dl,i=Pl,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],l=250,c=Rr,d=Ea("start","zoom","end"),h,f,m,u=500,x=150,E=0,S=10;function v(j){j.property("__zoom",co).on("wheel.zoom",D,{passive:!1}).on("mousedown.zoom",P).on("dblclick.zoom",_).filter(i).on("touchstart.zoom",C).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}v.transform=function(j,B,R,T){var A=j.selection?j.selection():j;A.property("__zoom",co),j!==A?N(j,B,R,T):A.interrupt().each(function(){w(this,arguments).event(T).start().zoom(null,typeof B=="function"?B.apply(this,arguments):B).end()})},v.scaleBy=function(j,B,R,T){v.scaleTo(j,function(){var A=this.__zoom.k,L=typeof B=="function"?B.apply(this,arguments):B;return A*L},R,T)},v.scaleTo=function(j,B,R,T){v.transform(j,function(){var A=n.apply(this,arguments),L=this.__zoom,q=R==null?b(A):typeof R=="function"?R.apply(this,arguments):R,F=L.invert(q),Y=typeof B=="function"?B.apply(this,arguments):B;return s(p(y(L,Y),q,F),A,a)},R,T)},v.translateBy=function(j,B,R,T){v.transform(j,function(){return s(this.__zoom.translate(typeof B=="function"?B.apply(this,arguments):B,typeof R=="function"?R.apply(this,arguments):R),n.apply(this,arguments),a)},null,T)},v.translateTo=function(j,B,R,T,A){v.transform(j,function(){var L=n.apply(this,arguments),q=this.__zoom,F=T==null?b(L):typeof T=="function"?T.apply(this,arguments):T;return s(ks.translate(F[0],F[1]).scale(q.k).translate(typeof B=="function"?-B.apply(this,arguments):-B,typeof R=="function"?-R.apply(this,arguments):-R),L,a)},T,A)};function y(j,B){return B=Math.max(o[0],Math.min(o[1],B)),B===j.k?j:new Kr(B,j.x,j.y)}function p(j,B,R){var T=B[0]-R[0]*j.k,A=B[1]-R[1]*j.k;return T===j.x&&A===j.y?j:new Kr(j.k,T,A)}function b(j){return[(+j[0][0]+ +j[1][0])/2,(+j[0][1]+ +j[1][1])/2]}function N(j,B,R,T){j.on("start.zoom",function(){w(this,arguments).event(T).start()}).on("interrupt.zoom end.zoom",function(){w(this,arguments).event(T).end()}).tween("zoom",function(){var A=this,L=arguments,q=w(A,L).event(T),F=n.apply(A,L),Y=R==null?b(F):typeof R=="function"?R.apply(A,L):R,Q=Math.max(F[1][0]-F[0][0],F[1][1]-F[0][1]),O=A.__zoom,I=typeof B=="function"?B.apply(A,L):B,H=c(O.invert(Y).concat(Q/O.k),I.invert(Y).concat(Q/I.k));return function(V){if(V===1)V=I;else{var W=H(V),X=Q/W[2];V=new Kr(X,Y[0]-W[0]*X,Y[1]-W[1]*X)}q.zoom(null,V)}})}function w(j,B,R){return!R&&j.__zooming||new M(j,B)}function M(j,B){this.that=j,this.args=B,this.active=0,this.sourceEvent=null,this.extent=n.apply(j,B),this.taps=0}M.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,B){return this.mouse&&j!=="mouse"&&(this.mouse[1]=B.invert(this.mouse[0])),this.touch0&&j!=="touch"&&(this.touch0[1]=B.invert(this.touch0[0])),this.touch1&&j!=="touch"&&(this.touch1[1]=B.invert(this.touch1[0])),this.that.__zoom=B,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(j){var B=ht(this.that).datum();d.call(j,this.that,new _l(j,{sourceEvent:this.sourceEvent,target:v,transform:this.that.__zoom,dispatch:d}),B)}};function D(j,...B){if(!e.apply(this,arguments))return;var R=w(this,B).event(j),T=this.__zoom,A=Math.max(o[0],Math.min(o[1],T.k*Math.pow(2,r.apply(this,arguments)))),L=jt(j);if(R.wheel)(R.mouse[0][0]!==L[0]||R.mouse[0][1]!==L[1])&&(R.mouse[1]=T.invert(R.mouse[0]=L)),clearTimeout(R.wheel);else{if(T.k===A)return;R.mouse=[L,T.invert(L)],Qr(this),R.start()}Fn(j),R.wheel=setTimeout(q,x),R.zoom("mouse",s(p(y(T,A),R.mouse[0],R.mouse[1]),R.extent,a));function q(){R.wheel=null,R.end()}}function P(j,...B){if(m||!e.apply(this,arguments))return;var R=j.currentTarget,T=w(this,B,!0).event(j),A=ht(j.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",Q,!0),L=jt(j,R),q=j.clientX,F=j.clientY;Ia(j.view),ts(j),T.mouse=[L,this.__zoom.invert(L)],Qr(this),T.start();function Y(O){if(Fn(O),!T.moved){var I=O.clientX-q,H=O.clientY-F;T.moved=I*I+H*H>E}T.event(O).zoom("mouse",s(p(T.that.__zoom,T.mouse[0]=jt(O,R),T.mouse[1]),T.extent,a))}function Q(O){A.on("mousemove.zoom mouseup.zoom",null),Ta(O.view,T.moved),Fn(O),T.event(O).end()}}function _(j,...B){if(e.apply(this,arguments)){var R=this.__zoom,T=jt(j.changedTouches?j.changedTouches[0]:j,this),A=R.invert(T),L=R.k*(j.shiftKey?.5:2),q=s(p(y(R,L),T,A),n.apply(this,B),a);Fn(j),l>0?ht(this).transition().duration(l).call(N,q,T,j):ht(this).call(v.transform,q,T,j)}}function C(j,...B){if(e.apply(this,arguments)){var R=j.touches,T=R.length,A=w(this,B,j.changedTouches.length===T).event(j),L,q,F,Y;for(ts(j),q=0;q<T;++q)F=R[q],Y=jt(F,this),Y=[Y,this.__zoom.invert(Y),F.identifier],A.touch0?!A.touch1&&A.touch0[2]!==Y[2]&&(A.touch1=Y,A.taps=0):(A.touch0=Y,L=!0,A.taps=1+!!h);h&&(h=clearTimeout(h)),L&&(A.taps<2&&(f=Y[0],h=setTimeout(function(){h=null},u)),Qr(this),A.start())}}function $(j,...B){if(this.__zooming){var R=w(this,B).event(j),T=j.changedTouches,A=T.length,L,q,F,Y;for(Fn(j),L=0;L<A;++L)q=T[L],F=jt(q,this),R.touch0&&R.touch0[2]===q.identifier?R.touch0[0]=F:R.touch1&&R.touch1[2]===q.identifier&&(R.touch1[0]=F);if(q=R.that.__zoom,R.touch1){var Q=R.touch0[0],O=R.touch0[1],I=R.touch1[0],H=R.touch1[1],V=(V=I[0]-Q[0])*V+(V=I[1]-Q[1])*V,W=(W=H[0]-O[0])*W+(W=H[1]-O[1])*W;q=y(q,Math.sqrt(V/W)),F=[(Q[0]+I[0])/2,(Q[1]+I[1])/2],Y=[(O[0]+H[0])/2,(O[1]+H[1])/2]}else if(R.touch0)F=R.touch0[0],Y=R.touch0[1];else return;R.zoom("touch",s(p(q,F,Y),R.extent,a))}}function z(j,...B){if(this.__zooming){var R=w(this,B).event(j),T=j.changedTouches,A=T.length,L,q;for(ts(j),m&&clearTimeout(m),m=setTimeout(function(){m=null},u),L=0;L<A;++L)q=T[L],R.touch0&&R.touch0[2]===q.identifier?delete R.touch0:R.touch1&&R.touch1[2]===q.identifier&&delete R.touch1;if(R.touch1&&!R.touch0&&(R.touch0=R.touch1,delete R.touch1),R.touch0)R.touch0[1]=this.__zoom.invert(R.touch0[0]);else if(R.end(),R.taps===2&&(q=jt(q,this),Math.hypot(f[0]-q[0],f[1]-q[1])<S)){var F=ht(this).on("dblclick.zoom");F&&F.apply(this,arguments)}}}return v.wheelDelta=function(j){return arguments.length?(r=typeof j=="function"?j:kr(+j),v):r},v.filter=function(j){return arguments.length?(e=typeof j=="function"?j:kr(!!j),v):e},v.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:kr(!!j),v):i},v.extent=function(j){return arguments.length?(n=typeof j=="function"?j:kr([[+j[0][0],+j[0][1]],[+j[1][0],+j[1][1]]]),v):n},v.scaleExtent=function(j){return arguments.length?(o[0]=+j[0],o[1]=+j[1],v):[o[0],o[1]]},v.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],v):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},v.constrain=function(j){return arguments.length?(s=j,v):s},v.duration=function(j){return arguments.length?(l=+j,v):l},v.interpolate=function(j){return arguments.length?(c=j,v):c},v.on=function(){var j=d.on.apply(d,arguments);return j===d?v:j},v.clickDistance=function(j){return arguments.length?(E=(j=+j)*j,v):Math.sqrt(E)},v.tapDistance=function(j){return arguments.length?(S=+j,v):S},v}function Ze(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=Ze(e[s]))!==""&&(n+=(n&&" ")+r);else for(let s in e)e[s]&&(n+=(n&&" ")+s);return n}const Dt={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."},Kn=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Aa=["Enter"," ","Escape"],La={"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 Rn;(function(e){e.Strict="strict",e.Loose="loose"})(Rn||(Rn={}));var un;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(un||(un={}));var Qn;(function(e){e.Partial="partial",e.Full="full"})(Qn||(Qn={}));const Da={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Kt;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Kt||(Kt={}));var _n;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(_n||(_n={}));var ye;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ye||(ye={}));const uo={[ye.Left]:ye.Right,[ye.Right]:ye.Left,[ye.Top]:ye.Bottom,[ye.Bottom]:ye.Top};function Pa(e){return e===null?null:e?"valid":"invalid"}const $a=e=>"id"in e&&"source"in e&&"target"in e,Bl=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),js=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),sr=(e,n=[0,0])=>{const{width:s,height:r}=Ft(e),i=e.origin??n,o=s*i[0],a=r*i[1];return{x:e.position.x-o,y:e.position.y-a}},Ol=(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):js(i)?i:n.nodeLookup.get(i.id));const l=a?Lr(a,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Br(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Or(s)},or=(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=Br(s,Lr(i)),r=!0)}),r?Or(s):{x:0,y:0,width:0,height:0}},Ns=(e,n,[s,r,i]=[0,0,1],o=!1,a=!1)=>{const l={...ir(n,[s,r,i]),width:n.width/i,height:n.height/i},c=[];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,x=h.height??d.height??d.initialHeight??null,E=Jn(l,Ln(d)),S=(u??0)*(x??0),v=o&&E>0;(!d.internals.handleBounds||v||E>=S||d.dragging)&&c.push(d)}return c},zl=(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 Hl(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 ql({nodes:e,width:n,height:s,panZoom:r,minZoom:i,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const l=Hl(e,a),c=or(l),d=Cs(c,n,s,a?.minZoom??i,a?.maxZoom??o,a?.padding??.1);return await r.setViewport(d,{duration:a?.duration,ease:a?.ease,interpolate:a?.interpolate}),Promise.resolve(!0)}function Ba({nodeId:e,nextPosition:n,nodeLookup:s,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const a=s.get(e),l=a.parentId?s.get(a.parentId):void 0,{x:c,y:d}=l?l.internals.positionAbsolute:{x:0,y:0},h=a.origin??r;let f=a.extent||i;if(a.extent==="parent"&&!a.expandParent)if(!l)o?.("005",Dt.error005());else{const u=l.measured.width,x=l.measured.height;u&&x&&(f=[[c,d],[c+u,d+x]])}else l&&Dn(a.extent)&&(f=[[a.extent[0][0]+c,a.extent[0][1]+d],[a.extent[1][0]+c,a.extent[1][1]+d]]);const m=Dn(f)?fn(n,f,a.measured):n;return(a.measured.width===void 0||a.measured.height===void 0)&&o?.("015",Dt.error015()),{position:{x:m.x-c+(a.measured.width??0)*h[0],y:m.y-d+(a.measured.height??0)*h[1]},positionAbsolute:m}}async function Vl({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),x=!u&&m.parentId&&a.find(E=>E.id===m.parentId);(u||x)&&a.push(m)}const l=new Set(n.map(m=>m.id)),c=r.filter(m=>m.deletable!==!1),h=zl(a,c);for(const m of c)l.has(m.id)&&!h.find(x=>x.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 An=(e,n=0,s=1)=>Math.min(Math.max(e,n),s),fn=(e={x:0,y:0},n,s)=>({x:An(e.x,n[0][0],n[1][0]-(s?.width??0)),y:An(e.y,n[0][1],n[1][1]-(s?.height??0))});function Oa(e,n,s){const{width:r,height:i}=Ft(s),{x:o,y:a}=s.internals.positionAbsolute;return fn(e,[[o,a],[o+r,a+i]],n)}const fo=(e,n,s)=>e<n?An(Math.abs(e-n),1,n)/n:e>s?-An(Math.abs(e-s),1,n)/n:0,za=(e,n,s=15,r=40)=>{const i=fo(e.x,r,n.width-r)*s,o=fo(e.y,r,n.height-r)*s;return[i,o]},Br=(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)}),hs=({x:e,y:n,width:s,height:r})=>({x:e,y:n,x2:e+s,y2:n+r}),Or=({x:e,y:n,x2:s,y2:r})=>({x:e,y:n,width:s-e,height:r-n}),Ln=(e,n=[0,0])=>{const{x:s,y:r}=js(e)?e.internals.positionAbsolute:sr(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}},Lr=(e,n=[0,0])=>{const{x:s,y:r}=js(e)?e.internals.positionAbsolute:sr(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)}},Ha=(e,n)=>Or(Br(hs(e),hs(n))),Jn=(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)},ho=e=>Nt(e.width)&&Nt(e.height)&&Nt(e.x)&&Nt(e.y),Nt=e=>!isNaN(e)&&isFinite(e),Wl=(e,n)=>{},ar=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),ir=({x:e,y:n},[s,r,i],o=!1,a=[1,1])=>{const l={x:(e-s)/i,y:(n-r)/i};return o?ar(l,a):l},Dr=({x:e,y:n},[s,r,i])=>({x:e*i+s,y:n*i+r});function Cn(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 Fl(e,n,s){if(typeof e=="string"||typeof e=="number"){const r=Cn(e,s),i=Cn(e,n);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=Cn(e.top??e.y??0,s),i=Cn(e.bottom??e.y??0,s),o=Cn(e.left??e.x??0,n),a=Cn(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 Yl(e,n,s,r,i,o){const{x:a,y:l}=Dr(e,[n,s,r]),{x:c,y:d}=Dr({x:e.x+e.width,y:e.y+e.height},[n,s,r]),h=i-c,f=o-d;return{left:Math.floor(a),top:Math.floor(l),right:Math.floor(h),bottom:Math.floor(f)}}const Cs=(e,n,s,r,i,o)=>{const a=Fl(o,n,s),l=(n-a.x)/e.width,c=(s-a.y)/e.height,d=Math.min(l,c),h=An(d,r,i),f=e.x+e.width/2,m=e.y+e.height/2,u=n/2-f*h,x=s/2-m*h,E=Yl(e,u,x,h,n,s),S={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-S.left+S.right,y:x-S.top+S.bottom,zoom:h}},er=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Dn(e){return e!=null&&e!=="parent"}function Ft(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function qa(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Va(e,n={width:0,height:0},s,r,i){const o={...e},a=r.get(s);if(a){const l=a.origin||i;o.x+=a.internals.positionAbsolute.x-(n.width??0)*l[0],o.y+=a.internals.positionAbsolute.y-(n.height??0)*l[1]}return o}function mo(e,n){if(e.size!==n.size)return!1;for(const s of e)if(!n.has(s))return!1;return!0}function Gl(){let e,n;return{promise:new Promise((r,i)=>{e=r,n=i}),resolve:e,reject:n}}function Zl(e){return{...La,...e||{}}}function Gn(e,{snapGrid:n=[0,0],snapToGrid:s=!1,transform:r,containerBounds:i}){const{x:o,y:a}=Ct(e),l=ir({x:o-(i?.left??0),y:a-(i?.top??0)},r),{x:c,y:d}=s?ar(l,n):l;return{xSnapped:c,ySnapped:d,...l}}const Ss=e=>({width:e.offsetWidth,height:e.offsetHeight}),Wa=e=>e?.getRootNode?.()||window?.document,Xl=["INPUT","SELECT","TEXTAREA"];function Fa(e){const n=e.composedPath?.()?.[0]||e.target;return n?.nodeType!==1?!1:Xl.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const Ya=e=>"clientX"in e,Ct=(e,n)=>{const s=Ya(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)}},go=(e,n,s,r,i)=>{const o=n.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const l=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:i,position:a.getAttribute("data-handlepos"),x:(l.left-s.left)/r,y:(l.top-s.top)/r,...Ss(a)}})};function Ga({sourceX:e,sourceY:n,targetX:s,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:a,targetControlY:l}){const c=e*.125+i*.375+a*.375+s*.125,d=n*.125+o*.375+l*.375+r*.125,h=Math.abs(c-e),f=Math.abs(d-n);return[c,d,h,f]}function jr(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function po({pos:e,x1:n,y1:s,x2:r,y2:i,c:o}){switch(e){case ye.Left:return[n-jr(n-r,o),s];case ye.Right:return[n+jr(r-n,o),s];case ye.Top:return[n,s-jr(s-i,o)];case ye.Bottom:return[n,s+jr(i-s,o)]}}function Za({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top,curvature:a=.25}){const[l,c]=po({pos:s,x1:e,y1:n,x2:r,y2:i,c:a}),[d,h]=po({pos:o,x1:r,y1:i,x2:e,y2:n,c:a}),[f,m,u,x]=Ga({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:l,sourceControlY:c,targetControlX:d,targetControlY:h});return[`M${e},${n} C${l},${c} ${d},${h} ${r},${i}`,f,m,u,x]}function Xa({sourceX:e,sourceY:n,targetX:s,targetY:r}){const i=Math.abs(s-e)/2,o=s<e?s+i:s-i,a=Math.abs(r-n)/2,l=r<n?r+a:r-a;return[o,l,i,a]}function Ul({sourceNode:e,targetNode:n,selected:s=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const a=i&&s?r+1e3:r,l=Math.max(e.parentId||i&&e.selected?e.internals.z:0,n.parentId||i&&n.selected?n.internals.z:0);return a+l}function Kl({sourceNode:e,targetNode:n,width:s,height:r,transform:i}){const o=Br(Lr(e),Lr(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 Jn(a,Or(o))>0}const Ql=({source:e,sourceHandle:n,target:s,targetHandle:r})=>`xy-edge__${e}${n||""}-${s}${r||""}`,Jl=(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)),ec=(e,n,s={})=>{if(!e.source||!e.target)return n;const r=s.getEdgeId||Ql;let i;return $a(e)?i={...e}:i={...e,id:r(e)},Jl(i,n)?n:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,n.concat(i))};function Ua({sourceX:e,sourceY:n,targetX:s,targetY:r}){const[i,o,a,l]=Xa({sourceX:e,sourceY:n,targetX:s,targetY:r});return[`M ${e},${n}L ${s},${r}`,i,o,a,l]}const xo={[ye.Left]:{x:-1,y:0},[ye.Right]:{x:1,y:0},[ye.Top]:{x:0,y:-1},[ye.Bottom]:{x:0,y:1}},tc=({source:e,sourcePosition:n=ye.Bottom,target:s})=>n===ye.Left||n===ye.Right?e.x<s.x?{x:1,y:0}:{x:-1,y:0}:e.y<s.y?{x:0,y:1}:{x:0,y:-1},bo=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function nc({source:e,sourcePosition:n=ye.Bottom,target:s,targetPosition:r=ye.Top,center:i,offset:o,stepPosition:a}){const l=xo[n],c=xo[r],d={x:e.x+l.x*o,y:e.y+l.y*o},h={x:s.x+c.x*o,y:s.y+c.y*o},f=tc({source:d,sourcePosition:n,target:h}),m=f.x!==0?"x":"y",u=f[m];let x=[],E,S;const v={x:0,y:0},y={x:0,y:0},[,,p,b]=Xa({sourceX:e.x,sourceY:e.y,targetX:s.x,targetY:s.y});if(l[m]*c[m]===-1){m==="x"?(E=i.x??d.x+(h.x-d.x)*a,S=i.y??(d.y+h.y)/2):(E=i.x??(d.x+h.x)/2,S=i.y??d.y+(h.y-d.y)*a);const w=[{x:E,y:d.y},{x:E,y:h.y}],M=[{x:d.x,y:S},{x:h.x,y:S}];l[m]===u?x=m==="x"?w:M:x=m==="x"?M:w}else{const w=[{x:d.x,y:h.y}],M=[{x:h.x,y:d.y}];if(m==="x"?x=l.x===u?M:w:x=l.y===u?w:M,n===r){const $=Math.abs(e[m]-s[m]);if($<=o){const z=Math.min(o-1,o-$);l[m]===u?v[m]=(d[m]>e[m]?-1:1)*z:y[m]=(h[m]>s[m]?-1:1)*z}}if(n!==r){const $=m==="x"?"y":"x",z=l[m]===c[$],j=d[$]>h[$],B=d[$]<h[$];(l[m]===1&&(!z&&j||z&&B)||l[m]!==1&&(!z&&B||z&&j))&&(x=m==="x"?w:M)}const D={x:d.x+v.x,y:d.y+v.y},P={x:h.x+y.x,y:h.y+y.y},_=Math.max(Math.abs(D.x-x[0].x),Math.abs(P.x-x[0].x)),C=Math.max(Math.abs(D.y-x[0].y),Math.abs(P.y-x[0].y));_>=C?(E=(D.x+P.x)/2,S=x[0].y):(E=x[0].x,S=(D.y+P.y)/2)}return[[e,{x:d.x+v.x,y:d.y+v.y},...x,{x:h.x+y.x,y:h.y+y.y},s],E,S,p,b]}function rc(e,n,s,r){const i=Math.min(bo(e,n)/2,bo(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 l=e.x<s.x?1:-1,c=e.y<s.y?-1:1;return`L ${o},${a+i*c}Q ${o},${a} ${o+i*l},${a}`}function ms({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top,borderRadius:a=5,centerX:l,centerY:c,offset:d=20,stepPosition:h=.5}){const[f,m,u,x,E]=nc({source:{x:e,y:n},sourcePosition:s,target:{x:r,y:i},targetPosition:o,center:{x:l,y:c},offset:d,stepPosition:h});return[f.reduce((v,y,p)=>{let b="";return p>0&&p<f.length-1?b=rc(f[p-1],y,f[p+1],a):b=`${p===0?"M":"L"}${y.x} ${y.y}`,v+=b,v},""),m,u,x,E]}function yo(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function sc(e){const{sourceNode:n,targetNode:s}=e;if(!yo(n)||!yo(s))return null;const r=n.internals.handleBounds||vo(n.handles),i=s.internals.handleBounds||vo(s.handles),o=wo(r?.source??[],e.sourceHandle),a=wo(e.connectionMode===Rn.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!a)return e.onError?.("008",Dt.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=o?.position||ye.Bottom,c=a?.position||ye.Top,d=hn(n,o,l),h=hn(s,a,c);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:l,targetPosition:c}}function vo(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 hn(e,n,s=ye.Left,r=!1){const i=(n?.x??0)+e.internals.positionAbsolute.x,o=(n?.y??0)+e.internals.positionAbsolute.y,{width:a,height:l}=n??Ft(e);if(r)return{x:i+a/2,y:o+l/2};switch(n?.position??s){case ye.Top:return{x:i+a/2,y:o};case ye.Right:return{x:i+a,y:o+l/2};case ye.Bottom:return{x:i+a/2,y:o+l};case ye.Left:return{x:i,y:o+l/2}}}function wo(e,n){return e&&(n?e.find(s=>s.id===n):e[0])||null}function gs(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function oc(e,{id:n,defaultColor:s,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((a,l)=>([l.markerStart||r,l.markerEnd||i].forEach(c=>{if(c&&typeof c=="object"){const d=gs(c,n);o.has(d)||(a.push({id:d,color:c.color||s,...c}),o.add(d))}}),a),[]).sort((a,l)=>a.id.localeCompare(l.id))}const Ka=1e3,ac=10,Es={nodeOrigin:[0,0],nodeExtent:Kn,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},ic={...Es,checkEquality:!0};function Ms(e,n){const s={...e};for(const r in n)n[r]!==void 0&&(s[r]=n[r]);return s}function lc(e,n,s){const r=Ms(Es,s);for(const i of e.values())if(i.parentId)Ts(i,e,n,r);else{const o=sr(i,r.nodeOrigin),a=Dn(i.extent)?i.extent:r.nodeExtent,l=fn(o,a,Ft(i));i.internals.positionAbsolute=l}}function cc(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 Is(e){return e==="manual"}function ps(e,n,s,r={}){const i=Ms(ic,r),o={i:0},a=new Map(n),l=i?.elevateNodesOnSelect&&!Is(i.zIndexMode)?Ka:0;let c=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=sr(d,i.nodeOrigin),m=Dn(d.extent)?d.extent:i.nodeExtent,u=fn(f,m,Ft(d));h={...i.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:u,handleBounds:cc(d,h),z:Qa(d,l,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&&(c=!1),d.parentId&&Ts(h,n,s,r,o)}return c}function dc(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 Ts(e,n,s,r,i){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:l,zIndexMode:c}=Ms(Es,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}dc(e,s),i&&!h.parentId&&h.internals.rootParentIndex===void 0&&c==="auto"&&(h.internals.rootParentIndex=++i.i,h.internals.z=h.internals.z+i.i*ac),i&&h.internals.rootParentIndex!==void 0&&(i.i=h.internals.rootParentIndex);const f=o&&!Is(c)?Ka:0,{x:m,y:u,z:x}=uc(e,h,a,l,f,c),{positionAbsolute:E}=e.internals,S=m!==E.x||u!==E.y;(S||x!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:S?{x:m,y:u}:E,z:x}})}function Qa(e,n,s){const r=Nt(e.zIndex)?e.zIndex:0;return Is(s)?r:r+(e.selected?n:0)}function uc(e,n,s,r,i,o){const{x:a,y:l}=n.internals.positionAbsolute,c=Ft(e),d=sr(e,s),h=Dn(e.extent)?fn(d,e.extent,c):d;let f=fn({x:a+h.x,y:l+h.y},r,c);e.extent==="parent"&&(f=Oa(f,c,n));const m=Qa(e,i,o),u=n.internals.z??0;return{x:f.x,y:f.y,z:u>=m?u+1:m}}function Rs(e,n,s,r=[0,0]){const i=[],o=new Map;for(const a of e){const l=n.get(a.parentId);if(!l)continue;const c=o.get(a.parentId)?.expandedRect??Ln(l),d=Ha(c,a.rect);o.set(a.parentId,{expandedRect:d,parent:l})}return o.size>0&&o.forEach(({expandedRect:a,parent:l},c)=>{const d=l.internals.positionAbsolute,h=Ft(l),f=l.origin??r,m=a.x<d.x?Math.round(Math.abs(d.x-a.x)):0,u=a.y<d.y?Math.round(Math.abs(d.y-a.y)):0,x=Math.max(h.width,Math.round(a.width)),E=Math.max(h.height,Math.round(a.height)),S=(x-h.width)*f[0],v=(E-h.height)*f[1];(m>0||u>0||S||v)&&(i.push({id:c,type:"position",position:{x:l.position.x-m+S,y:l.position.y-u+v}}),s.get(c)?.forEach(y=>{e.some(p=>p.id===y.id)||i.push({id:y.id,type:"position",position:{x:y.position.x+m,y:y.position.y+u}})})),(h.width<a.width||h.height<a.height||m||u)&&i.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:x+(m?f[0]*m-S:0),height:E+(u?f[1]*u-v:0)}})}),i}function fc(e,n,s,r,i,o,a){const l=r?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const d=[],h=window.getComputedStyle(l),{m22:f}=new window.DOMMatrixReadOnly(h.transform),m=[];for(const u of e.values()){const x=n.get(u.id);if(!x)continue;if(x.hidden){n.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),c=!0;continue}const E=Ss(u.nodeElement),S=x.measured.width!==E.width||x.measured.height!==E.height;if(!!(E.width&&E.height&&(S||!x.internals.handleBounds||u.force))){const y=u.nodeElement.getBoundingClientRect(),p=Dn(x.extent)?x.extent:o;let{positionAbsolute:b}=x.internals;x.parentId&&x.extent==="parent"?b=Oa(b,E,n.get(x.parentId)):p&&(b=fn(b,p,E));const N={...x,measured:E,internals:{...x.internals,positionAbsolute:b,handleBounds:{source:go("source",u.nodeElement,y,f,x.id),target:go("target",u.nodeElement,y,f,x.id)}}};n.set(x.id,N),x.parentId&&Ts(N,n,s,{nodeOrigin:i,zIndexMode:a}),c=!0,S&&(d.push({id:x.id,type:"dimensions",dimensions:E}),x.expandParent&&x.parentId&&m.push({id:x.id,parentId:x.parentId,rect:Ln(N,i)}))}}if(m.length>0){const u=Rs(m,n,s,i);d.push(...u)}return{changes:d,updatedInternals:c}}async function hc({delta:e,panZoom:n,transform:s,translateExtent:r,width:i,height:o}){if(!n||!e.x&&!e.y)return Promise.resolve(!1);const a=await n.setViewportConstrained({x:s[0]+e.x,y:s[1]+e.y,zoom:s[2]},[[0,0],[i,o]],r),l=!!a&&(a.x!==s[0]||a.y!==s[1]||a.k!==s[2]);return Promise.resolve(l)}function ko(e,n,s,r,i,o){let a=i;const l=r.get(a)||new Map;r.set(a,l.set(s,n)),a=`${i}-${e}`;const c=r.get(a)||new Map;if(r.set(a,c.set(s,n)),o){a=`${i}-${e}-${o}`;const d=r.get(a)||new Map;r.set(a,d.set(s,n))}}function Ja(e,n,s){e.clear(),n.clear();for(const r of s){const{source:i,target:o,sourceHandle:a=null,targetHandle:l=null}=r,c={edgeId:r.id,source:i,target:o,sourceHandle:a,targetHandle:l},d=`${i}-${a}--${o}-${l}`,h=`${o}-${l}--${i}-${a}`;ko("source",c,h,e,i,a),ko("target",c,d,e,o,l),n.set(r.id,r)}}function ei(e,n){if(!e.parentId)return!1;const s=n.get(e.parentId);return s?s.selected?!0:ei(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 mc(e,n,s,r){const i=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!ei(a,e))&&(a.draggable||n&&typeof a.draggable>"u")){const l=e.get(o);l&&i.set(o,{id:o,position:l.position||{x:0,y:0},distance:{x:s.x-l.internals.positionAbsolute.x,y:s.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return i}function ns({nodeId:e,dragItems:n,nodeLookup:s,dragging:r=!0}){const i=[];for(const[a,l]of n){const c=s.get(a)?.internals.userNode;c&&i.push({...c,position:l.position,dragging:r})}if(!e)return[i[0],i];const o=s.get(e)?.internals.userNode;return[o?{...o,position:n.get(e)?.position||o.position,dragging:r}:i[0],i]}function gc({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=ar(o,n);return{x:a.x-o.x,y:a.y-o.y}}function pc({onNodeMouseDown:e,getStoreItems:n,onDragStart:s,onDrag:r,onDragStop:i}){let o={x:null,y:null},a=0,l=new Map,c=!1,d={x:0,y:0},h=null,f=!1,m=null,u=!1,x=!1,E=null;function S({noDragClassName:y,handleSelector:p,domNode:b,isSelectable:N,nodeId:w,nodeClickDistance:M=0}){m=ht(b);function D({x:$,y:z}){const{nodeLookup:j,nodeExtent:B,snapGrid:R,snapToGrid:T,nodeOrigin:A,onNodeDrag:L,onSelectionDrag:q,onError:F,updateNodePositions:Y}=n();o={x:$,y:z};let Q=!1;const O=l.size>1,I=O&&B?hs(or(l)):null,H=O&&T?gc({dragItems:l,snapGrid:R,x:$,y:z}):null;for(const[V,W]of l){if(!j.has(V))continue;let X={x:$-W.distance.x,y:z-W.distance.y};T&&(X=H?{x:Math.round(X.x+H.x),y:Math.round(X.y+H.y)}:ar(X,R));let ee=null;if(O&&B&&!W.extent&&I){const{positionAbsolute:U}=W.internals,oe=U.x-I.x+B[0][0],le=U.x+W.measured.width-I.x2+B[1][0],ie=U.y-I.y+B[0][1],he=U.y+W.measured.height-I.y2+B[1][1];ee=[[oe,ie],[le,he]]}const{position:se,positionAbsolute:J}=Ba({nodeId:V,nextPosition:X,nodeLookup:j,nodeExtent:ee||B,nodeOrigin:A,onError:F});Q=Q||W.position.x!==se.x||W.position.y!==se.y,W.position=se,W.internals.positionAbsolute=J}if(x=x||Q,!!Q&&(Y(l,!0),E&&(r||L||!w&&q))){const[V,W]=ns({nodeId:w,dragItems:l,nodeLookup:j});r?.(E,l,V,W),L?.(E,V,W),w||q?.(E,W)}}async function P(){if(!h)return;const{transform:$,panBy:z,autoPanSpeed:j,autoPanOnNodeDrag:B}=n();if(!B){c=!1,cancelAnimationFrame(a);return}const[R,T]=za(d,h,j);(R!==0||T!==0)&&(o.x=(o.x??0)-R/$[2],o.y=(o.y??0)-T/$[2],await z({x:R,y:T})&&D(o)),a=requestAnimationFrame(P)}function _($){const{nodeLookup:z,multiSelectionActive:j,nodesDraggable:B,transform:R,snapGrid:T,snapToGrid:A,selectNodesOnDrag:L,onNodeDragStart:q,onSelectionDragStart:F,unselectNodesAndEdges:Y}=n();f=!0,(!L||!N)&&!j&&w&&(z.get(w)?.selected||Y()),N&&L&&w&&e?.(w);const Q=Gn($.sourceEvent,{transform:R,snapGrid:T,snapToGrid:A,containerBounds:h});if(o=Q,l=mc(z,B,Q,w),l.size>0&&(s||q||!w&&F)){const[O,I]=ns({nodeId:w,dragItems:l,nodeLookup:z});s?.($.sourceEvent,l,O,I),q?.($.sourceEvent,O,I),w||F?.($.sourceEvent,I)}}const C=Ra().clickDistance(M).on("start",$=>{const{domNode:z,nodeDragThreshold:j,transform:B,snapGrid:R,snapToGrid:T}=n();h=z?.getBoundingClientRect()||null,u=!1,x=!1,E=$.sourceEvent,j===0&&_($),o=Gn($.sourceEvent,{transform:B,snapGrid:R,snapToGrid:T,containerBounds:h}),d=Ct($.sourceEvent,h)}).on("drag",$=>{const{autoPanOnNodeDrag:z,transform:j,snapGrid:B,snapToGrid:R,nodeDragThreshold:T,nodeLookup:A}=n(),L=Gn($.sourceEvent,{transform:j,snapGrid:B,snapToGrid:R,containerBounds:h});if(E=$.sourceEvent,($.sourceEvent.type==="touchmove"&&$.sourceEvent.touches.length>1||w&&!A.has(w))&&(u=!0),!u){if(!c&&z&&f&&(c=!0,P()),!f){const q=Ct($.sourceEvent,h),F=q.x-d.x,Y=q.y-d.y;Math.sqrt(F*F+Y*Y)>T&&_($)}(o.x!==L.xSnapped||o.y!==L.ySnapped)&&l&&f&&(d=Ct($.sourceEvent,h),D(L))}}).on("end",$=>{if(!(!f||u)&&(c=!1,f=!1,cancelAnimationFrame(a),l.size>0)){const{nodeLookup:z,updateNodePositions:j,onNodeDragStop:B,onSelectionDragStop:R}=n();if(x&&(j(l,!1),x=!1),i||B||!w&&R){const[T,A]=ns({nodeId:w,dragItems:l,nodeLookup:z,dragging:!1});i?.($.sourceEvent,l,T,A),B?.($.sourceEvent,T,A),w||R?.($.sourceEvent,A)}}}).filter($=>{const z=$.target;return!$.button&&(!y||!jo(z,`.${y}`,b))&&(!p||jo(z,p,b))});m.call(C)}function v(){m?.on(".drag",null)}return{update:S,destroy:v}}function xc(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())Jn(i,Ln(o))>0&&r.push(o);return r}const bc=250;function yc(e,n,s,r){let i=[],o=1/0;const a=xc(e,s,n+bc);for(const l of a){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const d of c){if(r.nodeId===d.nodeId&&r.type===d.type&&r.id===d.id)continue;const{x:h,y:f}=hn(l,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 l=r.type==="source"?"target":"source";return i.find(c=>c.type===l)??i[0]}return i[0]}function ti(e,n,s,r,i,o=!1){const a=r.get(e);if(!a)return null;const l=i==="strict"?a.internals.handleBounds?.[n]:[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]],c=(s?l?.find(d=>d.id===s):l?.[0])??null;return c&&o?{...c,...hn(a,c,c.position,!0)}:c}function ni(e,n){return e||(n?.classList.contains("target")?"target":n?.classList.contains("source")?"source":null)}function vc(e,n){let s=null;return n?s=!0:e&&!n&&(s=!1),s}const ri=()=>!0;function wc(e,{connectionMode:n,connectionRadius:s,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:a,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:h,flowId:f,panBy:m,cancelConnection:u,onConnectStart:x,onConnect:E,onConnectEnd:S,isValidConnection:v=ri,onReconnectEnd:y,updateConnection:p,getTransform:b,getFromHandle:N,autoPanSpeed:w,dragThreshold:M=1,handleDomNode:D}){const P=Wa(e.target);let _=0,C;const{x:$,y:z}=Ct(e),j=ni(o,D),B=l?.getBoundingClientRect();let R=!1;if(!B||!j)return;const T=ti(i,j,r,c,n);if(!T)return;let A=Ct(e,B),L=!1,q=null,F=!1,Y=null;function Q(){if(!h||!B)return;const[se,J]=za(A,B,w);m({x:se,y:J}),_=requestAnimationFrame(Q)}const O={...T,nodeId:i,type:j,position:T.position},I=c.get(i);let V={inProgress:!0,isValid:null,from:hn(I,O,ye.Left,!0),fromHandle:O,fromPosition:O.position,fromNode:I,to:A,toHandle:null,toPosition:uo[O.position],toNode:null,pointer:A};function W(){R=!0,p(V),x?.(e,{nodeId:i,handleId:r,handleType:j})}M===0&&W();function X(se){if(!R){const{x:he,y:de}=Ct(se),Z=he-$,ae=de-z;if(!(Z*Z+ae*ae>M*M))return;W()}if(!N()||!O){ee(se);return}const J=b();A=Ct(se,B),C=yc(ir(A,J,!1,[1,1]),s,c,O),L||(Q(),L=!0);const U=si(se,{handle:C,connectionMode:n,fromNodeId:i,fromHandleId:r,fromType:a?"target":"source",isValidConnection:v,doc:P,lib:d,flowId:f,nodeLookup:c});Y=U.handleDomNode,q=U.connection,F=vc(!!C,U.isValid);const oe=c.get(i),le=oe?hn(oe,O,ye.Left,!0):V.from,ie={...V,from:le,isValid:F,to:U.toHandle&&F?Dr({x:U.toHandle.x,y:U.toHandle.y},J):A,toHandle:U.toHandle,toPosition:F&&U.toHandle?U.toHandle.position:uo[O.position],toNode:U.toHandle?c.get(U.toHandle.nodeId):null,pointer:A};p(ie),V=ie}function ee(se){if(!("touches"in se&&se.touches.length>0)){if(R){(C||Y)&&q&&F&&E?.(q);const{inProgress:J,...U}=V,oe={...U,toPosition:V.toHandle?V.toPosition:null};S?.(se,oe),o&&y?.(se,oe)}u(),cancelAnimationFrame(_),L=!1,F=!1,q=null,Y=null,P.removeEventListener("mousemove",X),P.removeEventListener("mouseup",ee),P.removeEventListener("touchmove",X),P.removeEventListener("touchend",ee)}}P.addEventListener("mousemove",X),P.addEventListener("mouseup",ee),P.addEventListener("touchmove",X),P.addEventListener("touchend",ee)}function si(e,{handle:n,connectionMode:s,fromNodeId:r,fromHandleId:i,fromType:o,doc:a,lib:l,flowId:c,isValidConnection:d=ri,nodeLookup:h}){const f=o==="target",m=n?a.querySelector(`.${l}-flow__handle[data-id="${c}-${n?.nodeId}-${n?.id}-${n?.type}"]`):null,{x:u,y:x}=Ct(e),E=a.elementFromPoint(u,x),S=E?.classList.contains(`${l}-flow__handle`)?E:m,v={handleDomNode:S,isValid:!1,connection:null,toHandle:null};if(S){const y=ni(void 0,S),p=S.getAttribute("data-nodeid"),b=S.getAttribute("data-handleid"),N=S.classList.contains("connectable"),w=S.classList.contains("connectableend");if(!p||!y)return v;const M={source:f?p:r,sourceHandle:f?b:i,target:f?r:p,targetHandle:f?i:b};v.connection=M;const P=N&&w&&(s===Rn.Strict?f&&y==="source"||!f&&y==="target":p!==r||b!==i);v.isValid=P&&d(M),v.toHandle=ti(p,y,b,h,s,!0)}return v}const xs={onPointerDown:wc,isValid:si};function kc({domNode:e,panZoom:n,getTransform:s,getViewScale:r}){const i=ht(e);function o({translateExtent:l,width:c,height:d,zoomStep:h=1,pannable:f=!0,zoomable:m=!0,inversePan:u=!1}){const x=p=>{if(p.sourceEvent.type!=="wheel"||!n)return;const b=s(),N=p.sourceEvent.ctrlKey&&er()?10:1,w=-p.sourceEvent.deltaY*(p.sourceEvent.deltaMode===1?.05:p.sourceEvent.deltaMode?1:.002)*h,M=b[2]*Math.pow(2,w*N);n.scaleTo(M)};let E=[0,0];const S=p=>{(p.sourceEvent.type==="mousedown"||p.sourceEvent.type==="touchstart")&&(E=[p.sourceEvent.clientX??p.sourceEvent.touches[0].clientX,p.sourceEvent.clientY??p.sourceEvent.touches[0].clientY])},v=p=>{const b=s();if(p.sourceEvent.type!=="mousemove"&&p.sourceEvent.type!=="touchmove"||!n)return;const N=[p.sourceEvent.clientX??p.sourceEvent.touches[0].clientX,p.sourceEvent.clientY??p.sourceEvent.touches[0].clientY],w=[N[0]-E[0],N[1]-E[1]];E=N;const M=r()*Math.max(b[2],Math.log(b[2]))*(u?-1:1),D={x:b[0]-w[0]*M,y:b[1]-w[1]*M},P=[[0,0],[c,d]];n.setViewportConstrained({x:D.x,y:D.y,zoom:b[2]},P,l)},y=_a().on("start",S).on("zoom",f?v:null).on("zoom.wheel",m?x:null);i.call(y,{})}function a(){i.on("zoom",null)}return{update:o,destroy:a,pointer:jt}}const zr=e=>({x:e.x,y:e.y,zoom:e.k}),rs=({x:e,y:n,zoom:s})=>ks.translate(e,n).scale(s),En=(e,n)=>e.target.closest(`.${n}`),oi=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),jc=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,ss=(e,n=0,s=jc,r=()=>{})=>{const i=typeof n=="number"&&n>0;return i||r(),i?e.transition().duration(n).ease(s).on("end",r):e},ai=e=>{const n=e.ctrlKey&&er()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function Nc({zoomPanValues:e,noWheelClassName:n,d3Selection:s,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return h=>{if(En(h,n))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const f=s.property("__zoom").k||1;if(h.ctrlKey&&a){const S=jt(h),v=ai(h),y=f*Math.pow(2,v);r.scaleTo(s,y,S,h);return}const m=h.deltaMode===1?20:1;let u=i===un.Vertical?0:h.deltaX*m,x=i===un.Horizontal?0:h.deltaY*m;!er()&&h.shiftKey&&i!==un.Vertical&&(u=h.deltaY*m,x=0),r.translateBy(s,-(u/f)*o,-(x/f)*o,{internal:!0});const E=zr(s.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(h,E),e.panScrollTimeout=setTimeout(()=>{d?.(h,E),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(h,E))}}function Cc({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:s}){return function(r,i){const o=r.type==="wheel",a=!n&&o&&!r.ctrlKey,l=En(r,e);if(r.ctrlKey&&o&&l&&r.preventDefault(),a||l)return null;r.preventDefault(),s.call(this,r,i)}}function Sc({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:s}){return r=>{if(r.sourceEvent?.internal)return;const i=zr(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 Ec({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:s,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(s&&oi(n,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,zr(o.transform))}}function Mc({zoomPanValues:e,panOnDrag:n,panOnScroll:s,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return a=>{if(!a.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&oi(n,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const l=zr(a.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(a.sourceEvent,l)},s?150:0)}}}function Ic({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:s,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:a,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:h}){return f=>{const m=e||n,u=s&&f.ctrlKey,x=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(En(f,`${d}-flow__node`)||En(f,`${d}-flow__edge`)))return!0;if(!r&&!m&&!i&&!o&&!s||a||h&&!x||En(f,l)&&x||En(f,c)&&(!x||i&&x&&!e)||!s&&f.ctrlKey&&x)return!1;if(!s&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!m&&!i&&!u&&x||!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||x)&&E}}function Tc({domNode:e,minZoom:n,maxZoom:s,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:l,onDraggingChange:c}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},h=e.getBoundingClientRect(),f=_a().scaleExtent([n,s]).translateExtent(r),m=ht(e).call(f);y({x:i.x,y:i.y,zoom:An(i.zoom,n,s)},[[0,0],[h.width,h.height]],r);const u=m.on("wheel.zoom"),x=m.on("dblclick.zoom");f.wheelDelta(ai);function E(C,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?Jr:Rr).transform(ss(m,$?.duration,$?.ease,()=>z(!0)),C)}):Promise.resolve(!1)}function S({noWheelClassName:C,noPanClassName:$,onPaneContextMenu:z,userSelectionActive:j,panOnScroll:B,panOnDrag:R,panOnScrollMode:T,panOnScrollSpeed:A,preventScrolling:L,zoomOnPinch:q,zoomOnScroll:F,zoomOnDoubleClick:Y,zoomActivationKeyPressed:Q,lib:O,onTransformChange:I,connectionInProgress:H,paneClickDistance:V,selectionOnDrag:W}){j&&!d.isZoomingOrPanning&&v();const X=B&&!Q&&!j;f.clickDistance(W?1/0:!Nt(V)||V<0?0:V);const ee=X?Nc({zoomPanValues:d,noWheelClassName:C,d3Selection:m,d3Zoom:f,panOnScrollMode:T,panOnScrollSpeed:A,zoomOnPinch:q,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:l}):Cc({noWheelClassName:C,preventScrolling:L,d3ZoomHandler:u});if(m.on("wheel.zoom",ee,{passive:!1}),!j){const J=Sc({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:a});f.on("start",J);const U=Ec({zoomPanValues:d,panOnDrag:R,onPaneContextMenu:!!z,onPanZoom:o,onTransformChange:I});f.on("zoom",U);const oe=Mc({zoomPanValues:d,panOnDrag:R,panOnScroll:B,onPaneContextMenu:z,onPanZoomEnd:l,onDraggingChange:c});f.on("end",oe)}const se=Ic({zoomActivationKeyPressed:Q,panOnDrag:R,zoomOnScroll:F,panOnScroll:B,zoomOnDoubleClick:Y,zoomOnPinch:q,userSelectionActive:j,noPanClassName:$,noWheelClassName:C,lib:O,connectionInProgress:H});f.filter(se),Y?m.on("dblclick.zoom",x):m.on("dblclick.zoom",null)}function v(){f.on("zoom",null)}async function y(C,$,z){const j=rs(C),B=f?.constrain()(j,$,z);return B&&await E(B),new Promise(R=>R(B))}async function p(C,$){const z=rs(C);return await E(z,$),new Promise(j=>j(z))}function b(C){if(m){const $=rs(C),z=m.property("__zoom");(z.k!==C.zoom||z.x!==C.x||z.y!==C.y)&&f?.transform(m,$,null,{sync:!0})}}function N(){const C=m?kl(m.node()):{x:0,y:0,k:1};return{x:C.x,y:C.y,zoom:C.k}}function w(C,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?Jr:Rr).scaleTo(ss(m,$?.duration,$?.ease,()=>z(!0)),C)}):Promise.resolve(!1)}function M(C,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?Jr:Rr).scaleBy(ss(m,$?.duration,$?.ease,()=>z(!0)),C)}):Promise.resolve(!1)}function D(C){f?.scaleExtent(C)}function P(C){f?.translateExtent(C)}function _(C){const $=!Nt(C)||C<0?0:C;f?.clickDistance($)}return{update:S,destroy:v,setViewport:p,setViewportConstrained:y,getViewport:N,scaleTo:w,scaleBy:M,setScaleExtent:D,setTranslateExtent:P,syncViewport:b,setClickDistance:_}}var Pn;(function(e){e.Line="line",e.Handle="handle"})(Pn||(Pn={}));function Rc({width:e,prevWidth:n,height:s,prevHeight:r,affectsX:i,affectsY:o}){const a=e-n,l=s-r,c=[a>0?1:a<0?-1:0,l>0?1:l<0?-1:0];return a&&i&&(c[0]=c[0]*-1),l&&o&&(c[1]=c[1]*-1),c}function No(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 Xt(e,n){return Math.max(0,n-e)}function Ut(e,n){return Math.max(0,e-n)}function Nr(e,n,s){return Math.max(0,n-e,e-s)}function Co(e,n){return e?!n:n}function _c(e,n,s,r,i,o,a,l){let{affectsX:c,affectsY:d}=n;const{isHorizontal:h,isVertical:f}=n,m=h&&f,{xSnapped:u,ySnapped:x}=s,{minWidth:E,maxWidth:S,minHeight:v,maxHeight:y}=r,{x:p,y:b,width:N,height:w,aspectRatio:M}=e;let D=Math.floor(h?u-e.pointerX:0),P=Math.floor(f?x-e.pointerY:0);const _=N+(c?-D:D),C=w+(d?-P:P),$=-o[0]*N,z=-o[1]*w;let j=Nr(_,E,S),B=Nr(C,v,y);if(a){let A=0,L=0;c&&D<0?A=Xt(p+D+$,a[0][0]):!c&&D>0&&(A=Ut(p+_+$,a[1][0])),d&&P<0?L=Xt(b+P+z,a[0][1]):!d&&P>0&&(L=Ut(b+C+z,a[1][1])),j=Math.max(j,A),B=Math.max(B,L)}if(l){let A=0,L=0;c&&D>0?A=Ut(p+D,l[0][0]):!c&&D<0&&(A=Xt(p+_,l[1][0])),d&&P>0?L=Ut(b+P,l[0][1]):!d&&P<0&&(L=Xt(b+C,l[1][1])),j=Math.max(j,A),B=Math.max(B,L)}if(i){if(h){const A=Nr(_/M,v,y)*M;if(j=Math.max(j,A),a){let L=0;!c&&!d||c&&!d&&m?L=Ut(b+z+_/M,a[1][1])*M:L=Xt(b+z+(c?D:-D)/M,a[0][1])*M,j=Math.max(j,L)}if(l){let L=0;!c&&!d||c&&!d&&m?L=Xt(b+_/M,l[1][1])*M:L=Ut(b+(c?D:-D)/M,l[0][1])*M,j=Math.max(j,L)}}if(f){const A=Nr(C*M,E,S)/M;if(B=Math.max(B,A),a){let L=0;!c&&!d||d&&!c&&m?L=Ut(p+C*M+$,a[1][0])/M:L=Xt(p+(d?P:-P)*M+$,a[0][0])/M,B=Math.max(B,L)}if(l){let L=0;!c&&!d||d&&!c&&m?L=Xt(p+C*M,l[1][0])/M:L=Ut(p+(d?P:-P)*M,l[0][0])/M,B=Math.max(B,L)}}}P=P+(P<0?B:-B),D=D+(D<0?j:-j),i&&(m?_>C*M?P=(Co(c,d)?-D:D)/M:D=(Co(c,d)?-P:P)*M:h?(P=D/M,d=c):(D=P*M,c=d));const R=c?p+D:p,T=d?b+P:b;return{width:N+(c?-D:D),height:w+(d?-P:P),x:o[0]*D*(c?-1:1)+R,y:o[1]*P*(d?-1:1)+T}}const ii={width:0,height:0,x:0,y:0},Ac={...ii,pointerX:0,pointerY:0,aspectRatio:1};function Lc(e){return[[0,0],[e.measured.width,e.measured.height]]}function Dc(e,n,s){const r=n.position.x+e.position.x,i=n.position.y+e.position.y,o=e.measured.width??0,a=e.measured.height??0,l=s[0]*o,c=s[1]*a;return[[r-l,i-c],[r+o-l,i+a-c]]}function Pc({domNode:e,nodeId:n,getStoreItems:s,onChange:r,onEnd:i}){const o=ht(e);let a={controlDirection:No("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:d,boundaries:h,keepAspectRatio:f,resizeDirection:m,onResizeStart:u,onResize:x,onResizeEnd:E,shouldResize:S}){let v={...ii},y={...Ac};a={boundaries:h,resizeDirection:m,keepAspectRatio:f,controlDirection:No(d)};let p,b=null,N=[],w,M,D,P=!1;const _=Ra().on("start",C=>{const{nodeLookup:$,transform:z,snapGrid:j,snapToGrid:B,nodeOrigin:R,paneDomNode:T}=s();if(p=$.get(n),!p)return;b=T?.getBoundingClientRect()??null;const{xSnapped:A,ySnapped:L}=Gn(C.sourceEvent,{transform:z,snapGrid:j,snapToGrid:B,containerBounds:b});v={width:p.measured.width??0,height:p.measured.height??0,x:p.position.x??0,y:p.position.y??0},y={...v,pointerX:A,pointerY:L,aspectRatio:v.width/v.height},w=void 0,p.parentId&&(p.extent==="parent"||p.expandParent)&&(w=$.get(p.parentId),M=w&&p.extent==="parent"?Lc(w):void 0),N=[],D=void 0;for(const[q,F]of $)if(F.parentId===n&&(N.push({id:q,position:{...F.position},extent:F.extent}),F.extent==="parent"||F.expandParent)){const Y=Dc(F,p,F.origin??R);D?D=[[Math.min(Y[0][0],D[0][0]),Math.min(Y[0][1],D[0][1])],[Math.max(Y[1][0],D[1][0]),Math.max(Y[1][1],D[1][1])]]:D=Y}u?.(C,{...v})}).on("drag",C=>{const{transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:B}=s(),R=Gn(C.sourceEvent,{transform:$,snapGrid:z,snapToGrid:j,containerBounds:b}),T=[];if(!p)return;const{x:A,y:L,width:q,height:F}=v,Y={},Q=p.origin??B,{width:O,height:I,x:H,y:V}=_c(y,a.controlDirection,R,a.boundaries,a.keepAspectRatio,Q,M,D),W=O!==q,X=I!==F,ee=H!==A&&W,se=V!==L&&X;if(!ee&&!se&&!W&&!X)return;if((ee||se||Q[0]===1||Q[1]===1)&&(Y.x=ee?H:v.x,Y.y=se?V:v.y,v.x=Y.x,v.y=Y.y,N.length>0)){const le=H-A,ie=V-L;for(const he of N)he.position={x:he.position.x-le+Q[0]*(O-q),y:he.position.y-ie+Q[1]*(I-F)},T.push(he)}if((W||X)&&(Y.width=W&&(!a.resizeDirection||a.resizeDirection==="horizontal")?O:v.width,Y.height=X&&(!a.resizeDirection||a.resizeDirection==="vertical")?I:v.height,v.width=Y.width,v.height=Y.height),w&&p.expandParent){const le=Q[0]*(Y.width??0);Y.x&&Y.x<le&&(v.x=le,y.x=y.x-(Y.x-le));const ie=Q[1]*(Y.height??0);Y.y&&Y.y<ie&&(v.y=ie,y.y=y.y-(Y.y-ie))}const J=Rc({width:v.width,prevWidth:q,height:v.height,prevHeight:F,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),U={...v,direction:J};S?.(C,U)!==!1&&(P=!0,x?.(C,U),r(Y,T))}).on("end",C=>{P&&(E?.(C,{...v}),i?.({...v}),P=!1)});o.call(_)}function c(){o.on(".drag",null)}return{update:l,destroy:c}}var os={exports:{}},as={};var So;function $c(){if(So)return as;So=1;var e=dl(),n=ul();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,l=e.useMemo,c=e.useDebugValue;return as.useSyncExternalStoreWithSelector=function(d,h,f,m,u){var x=o(null);if(x.current===null){var E={hasValue:!1,value:null};x.current=E}else E=x.current;x=l(function(){function v(w){if(!y){if(y=!0,p=w,w=m(w),u!==void 0&&E.hasValue){var M=E.value;if(u(M,w))return b=M}return b=w}if(M=b,r(p,w))return M;var D=m(w);return u!==void 0&&u(M,D)?(p=w,M):(p=w,b=D)}var y=!1,p,b,N=f===void 0?null:f;return[function(){return v(h())},N===null?void 0:function(){return v(N())}]},[h,f,m,u]);var S=i(d,x[0],x[1]);return a(function(){E.hasValue=!0,E.value=S},[S]),c(S),S},as}var Eo;function Bc(){return Eo||(Eo=1,os.exports=$c()),os.exports}var Oc=Bc();const zc=fl(Oc),Hc={},Mo=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(x=>x(n,u))}},i=()=>n,c={setState:r,getState:i,getInitialState:()=>d,subscribe:h=>(s.add(h),()=>s.delete(h)),destroy:()=>{(Hc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),s.clear()}},d=n=e(r,i,c);return c},qc=e=>e?Mo(e):Mo,{useDebugValue:Vc}=hl,{useSyncExternalStoreWithSelector:Wc}=zc,Fc=e=>e;function li(e,n=Fc,s){const r=Wc(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,s);return Vc(r),r}const Io=(e,n)=>{const s=qc(e),r=(i,o=n)=>li(s,i,o);return Object.assign(r,s),r},Yc=(e,n)=>e?Io(e,n):Io;function Oe(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 Hr=g.createContext(null),Gc=Hr.Provider,ci=Dt.error001();function Me(e,n){const s=g.useContext(Hr);if(s===null)throw new Error(ci);return li(s,e,n)}function Be(){const e=g.useContext(Hr);if(e===null)throw new Error(ci);return g.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const To={display:"none"},Zc={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},di="react-flow__node-desc",ui="react-flow__edge-desc",Xc="react-flow__aria-live",Uc=e=>e.ariaLiveMessage,Kc=e=>e.ariaLabelConfig;function Qc({rfId:e}){const n=Me(Uc);return t.jsx("div",{id:`${Xc}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Zc,children:n})}function Jc({rfId:e,disableKeyboardA11y:n}){const s=Me(Kc);return t.jsxs(t.Fragment,{children:[t.jsx("div",{id:`${di}-${e}`,style:To,children:n?s["node.a11yDescription.default"]:s["node.a11yDescription.keyboardDisabled"]}),t.jsx("div",{id:`${ui}-${e}`,style:To,children:s["edge.a11yDescription.default"]}),!n&&t.jsx(Qc,{rfId:e})]})}const qr=g.forwardRef(({position:e="top-left",children:n,className:s,style:r,...i},o)=>{const a=`${e}`.split("-");return t.jsx("div",{className:Ze(["react-flow__panel",s,...a]),style:r,ref:o,...i,children:n})});qr.displayName="Panel";function ed({proOptions:e,position:n="bottom-right"}){return e?.hideAttribution?null:t.jsx(qr,{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 td=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}},Cr=e=>e.id;function nd(e,n){return Oe(e.selectedNodes.map(Cr),n.selectedNodes.map(Cr))&&Oe(e.selectedEdges.map(Cr),n.selectedEdges.map(Cr))}function rd({onSelectionChange:e}){const n=Be(),{selectedNodes:s,selectedEdges:r}=Me(td,nd);return g.useEffect(()=>{const i={nodes:s,edges:r};e?.(i),n.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[s,r,e]),null}const sd=e=>!!e.onSelectionChangeHandlers;function od({onSelectionChange:e}){const n=Me(sd);return e||n?t.jsx(rd,{onSelectionChange:e}):null}const fi=[0,0],ad={x:0,y:0,zoom:1},id=["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"],Ro=[...id,"rfId"],ld=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}),_o={translateExtent:Kn,nodeOrigin:fi,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function cd(e){const{setNodes:n,setEdges:s,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:a,reset:l,setDefaultNodesAndEdges:c}=Me(ld,Oe),d=Be();g.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{h.current=_o,l()}),[]);const h=g.useRef(_o);return g.useEffect(()=>{for(const f of Ro){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:Zl(m)}):f==="fitView"?d.setState({fitViewQueued:m}):f==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[f]:m})))}h.current=e},Ro.map(f=>e[f])),null}function Ao(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function dd(e){const[n,s]=g.useState(e==="system"?null:e);return g.useEffect(()=>{if(e!=="system"){s(e);return}const r=Ao(),i=()=>s(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),n!==null?n:Ao()?.matches?"dark":"light"}const Lo=typeof document<"u"?document:null;function tr(e=null,n={target:Lo,actInsideInputWithModifier:!0}){const[s,r]=g.useState(!1),i=g.useRef(!1),o=g.useRef(new Set([])),[a,l]=g.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
1
+ import{ai as dl,aj as ul,F as fl,ak as hl,r as g,j as t,u as He,f as re,G as ml,a as rr,e as gl,B as pl,C as xl,b as cs,P as Ye,w as bt,aa as kt,D as vr,al as no,M as bl,J as Sn,n as Lt,t as Xn,am as yl,A as ws,a0 as ro,an as ds,ao as so,ap as us,aq as oo,ar as ao,as as io,Y as Ca,$ as Sa,Z as vl}from"./index-lNtr_En-.js";import{ContentRenderer as wl}from"./ContentRenderer-Ccoj5KhH.js";import{s as ht,e as Ea,f as ks,T as Kr,g as Qr,t as kl}from"./transform-CpIVI4vC.js";import{i as Jr}from"./value-DIujSiJ7.js";import{C as Ma}from"./CommentInput-ZW-2JyIg.js";function jl(e){let n;for(;n=e.sourceEvent;)e=n;return e}function jt(e,n){if(e=jl(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 Nl={passive:!1},Un={capture:!0,passive:!1};function es(e){e.stopImmediatePropagation()}function Tn(e){e.preventDefault(),e.stopImmediatePropagation()}function Ia(e){var n=e.document.documentElement,s=ht(e).on("dragstart.drag",Tn,Un);"onselectstart"in n?s.on("selectstart.drag",Tn,Un):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function Ta(e,n){var s=e.document.documentElement,r=ht(e).on("dragstart.drag",null);n&&(r.on("click.drag",Tn,Un),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 wr=e=>()=>e;function fs(e,{sourceEvent:n,subject:s,target:r,identifier:i,active:o,x:a,y:l,dx:c,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:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:h}})}fs.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Cl(e){return!e.ctrlKey&&!e.button}function Sl(){return this.parentNode}function El(e,n){return n??{x:e.x,y:e.y}}function Ml(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ra(){var e=Cl,n=Sl,s=El,r=Ml,i={},o=Ea("start","drag","end"),a=0,l,c,d,h,f=0;function m(b){b.on("mousedown.drag",u).filter(r).on("touchstart.drag",S).on("touchmove.drag",v,Nl).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(b,N){if(!(h||!e.call(this,b,N))){var w=p(this,n.call(this,b,N),b,N,"mouse");w&&(ht(b.view).on("mousemove.drag",x,Un).on("mouseup.drag",E,Un),Ia(b.view),es(b),d=!1,l=b.clientX,c=b.clientY,w("start",b))}}function x(b){if(Tn(b),!d){var N=b.clientX-l,w=b.clientY-c;d=N*N+w*w>f}i.mouse("drag",b)}function E(b){ht(b.view).on("mousemove.drag mouseup.drag",null),Ta(b.view,d),Tn(b),i.mouse("end",b)}function S(b,N){if(e.call(this,b,N)){var w=b.changedTouches,M=n.call(this,b,N),D=w.length,P,_;for(P=0;P<D;++P)(_=p(this,M,b,N,w[P].identifier,w[P]))&&(es(b),_("start",b,w[P]))}}function v(b){var N=b.changedTouches,w=N.length,M,D;for(M=0;M<w;++M)(D=i[N[M].identifier])&&(Tn(b),D("drag",b,N[M]))}function y(b){var N=b.changedTouches,w=N.length,M,D;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),M=0;M<w;++M)(D=i[N[M].identifier])&&(es(b),D("end",b,N[M]))}function p(b,N,w,M,D,P){var _=o.copy(),C=jt(P||w,N),$,z,j;if((j=s.call(b,new fs("beforestart",{sourceEvent:w,target:m,identifier:D,active:a,x:C[0],y:C[1],dx:0,dy:0,dispatch:_}),M))!=null)return $=j.x-C[0]||0,z=j.y-C[1]||0,function B(R,T,A){var L=C,q;switch(R){case"start":i[D]=B,q=a++;break;case"end":delete i[D],--a;case"drag":C=jt(A||T,N),q=a;break}_.call(R,b,new fs(R,{sourceEvent:T,subject:j,target:m,identifier:D,active:q,x:C[0]+$,y:C[1]+z,dx:C[0]-L[0],dy:C[1]-L[1],dispatch:_}),M)}}return m.filter=function(b){return arguments.length?(e=typeof b=="function"?b:wr(!!b),m):e},m.container=function(b){return arguments.length?(n=typeof b=="function"?b:wr(b),m):n},m.subject=function(b){return arguments.length?(s=typeof b=="function"?b:wr(b),m):s},m.touchable=function(b){return arguments.length?(r=typeof b=="function"?b:wr(!!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 Il=1e-12;function lo(e){return((e=Math.exp(e))+1/e)/2}function Tl(e){return((e=Math.exp(e))-1/e)/2}function Rl(e){return((e=Math.exp(2*e))-1)/(e+1)}const Rr=(function e(n,s,r){function i(o,a){var l=o[0],c=o[1],d=o[2],h=a[0],f=a[1],m=a[2],u=h-l,x=f-c,E=u*u+x*x,S,v;if(E<Il)v=Math.log(m/d)/n,S=function(M){return[l+M*u,c+M*x,d*Math.exp(n*M*v)]};else{var y=Math.sqrt(E),p=(m*m-d*d+r*E)/(2*d*s*y),b=(m*m-d*d-r*E)/(2*m*s*y),N=Math.log(Math.sqrt(p*p+1)-p),w=Math.log(Math.sqrt(b*b+1)-b);v=(w-N)/n,S=function(M){var D=M*v,P=lo(N),_=d/(s*y)*(P*Rl(n*D+N)-Tl(N));return[l+_*u,c+_*x,d*P/lo(n*D+N)]}}return S.duration=v*1e3*n/Math.SQRT2,S}return i.rho=function(o){var a=Math.max(.001,+o),l=a*a,c=l*l;return e(a,l,c)},i})(Math.SQRT2,2,4),kr=e=>()=>e;function _l(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 ts(e){e.stopImmediatePropagation()}function Fn(e){e.preventDefault(),e.stopImmediatePropagation()}function Al(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Ll(){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 co(){return this.__zoom||ks}function Dl(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Pl(){return navigator.maxTouchPoints||"ontouchstart"in this}function $l(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 _a(){var e=Al,n=Ll,s=$l,r=Dl,i=Pl,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],l=250,c=Rr,d=Ea("start","zoom","end"),h,f,m,u=500,x=150,E=0,S=10;function v(j){j.property("__zoom",co).on("wheel.zoom",D,{passive:!1}).on("mousedown.zoom",P).on("dblclick.zoom",_).filter(i).on("touchstart.zoom",C).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}v.transform=function(j,B,R,T){var A=j.selection?j.selection():j;A.property("__zoom",co),j!==A?N(j,B,R,T):A.interrupt().each(function(){w(this,arguments).event(T).start().zoom(null,typeof B=="function"?B.apply(this,arguments):B).end()})},v.scaleBy=function(j,B,R,T){v.scaleTo(j,function(){var A=this.__zoom.k,L=typeof B=="function"?B.apply(this,arguments):B;return A*L},R,T)},v.scaleTo=function(j,B,R,T){v.transform(j,function(){var A=n.apply(this,arguments),L=this.__zoom,q=R==null?b(A):typeof R=="function"?R.apply(this,arguments):R,F=L.invert(q),Y=typeof B=="function"?B.apply(this,arguments):B;return s(p(y(L,Y),q,F),A,a)},R,T)},v.translateBy=function(j,B,R,T){v.transform(j,function(){return s(this.__zoom.translate(typeof B=="function"?B.apply(this,arguments):B,typeof R=="function"?R.apply(this,arguments):R),n.apply(this,arguments),a)},null,T)},v.translateTo=function(j,B,R,T,A){v.transform(j,function(){var L=n.apply(this,arguments),q=this.__zoom,F=T==null?b(L):typeof T=="function"?T.apply(this,arguments):T;return s(ks.translate(F[0],F[1]).scale(q.k).translate(typeof B=="function"?-B.apply(this,arguments):-B,typeof R=="function"?-R.apply(this,arguments):-R),L,a)},T,A)};function y(j,B){return B=Math.max(o[0],Math.min(o[1],B)),B===j.k?j:new Kr(B,j.x,j.y)}function p(j,B,R){var T=B[0]-R[0]*j.k,A=B[1]-R[1]*j.k;return T===j.x&&A===j.y?j:new Kr(j.k,T,A)}function b(j){return[(+j[0][0]+ +j[1][0])/2,(+j[0][1]+ +j[1][1])/2]}function N(j,B,R,T){j.on("start.zoom",function(){w(this,arguments).event(T).start()}).on("interrupt.zoom end.zoom",function(){w(this,arguments).event(T).end()}).tween("zoom",function(){var A=this,L=arguments,q=w(A,L).event(T),F=n.apply(A,L),Y=R==null?b(F):typeof R=="function"?R.apply(A,L):R,Q=Math.max(F[1][0]-F[0][0],F[1][1]-F[0][1]),O=A.__zoom,I=typeof B=="function"?B.apply(A,L):B,H=c(O.invert(Y).concat(Q/O.k),I.invert(Y).concat(Q/I.k));return function(V){if(V===1)V=I;else{var W=H(V),X=Q/W[2];V=new Kr(X,Y[0]-W[0]*X,Y[1]-W[1]*X)}q.zoom(null,V)}})}function w(j,B,R){return!R&&j.__zooming||new M(j,B)}function M(j,B){this.that=j,this.args=B,this.active=0,this.sourceEvent=null,this.extent=n.apply(j,B),this.taps=0}M.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,B){return this.mouse&&j!=="mouse"&&(this.mouse[1]=B.invert(this.mouse[0])),this.touch0&&j!=="touch"&&(this.touch0[1]=B.invert(this.touch0[0])),this.touch1&&j!=="touch"&&(this.touch1[1]=B.invert(this.touch1[0])),this.that.__zoom=B,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(j){var B=ht(this.that).datum();d.call(j,this.that,new _l(j,{sourceEvent:this.sourceEvent,target:v,transform:this.that.__zoom,dispatch:d}),B)}};function D(j,...B){if(!e.apply(this,arguments))return;var R=w(this,B).event(j),T=this.__zoom,A=Math.max(o[0],Math.min(o[1],T.k*Math.pow(2,r.apply(this,arguments)))),L=jt(j);if(R.wheel)(R.mouse[0][0]!==L[0]||R.mouse[0][1]!==L[1])&&(R.mouse[1]=T.invert(R.mouse[0]=L)),clearTimeout(R.wheel);else{if(T.k===A)return;R.mouse=[L,T.invert(L)],Qr(this),R.start()}Fn(j),R.wheel=setTimeout(q,x),R.zoom("mouse",s(p(y(T,A),R.mouse[0],R.mouse[1]),R.extent,a));function q(){R.wheel=null,R.end()}}function P(j,...B){if(m||!e.apply(this,arguments))return;var R=j.currentTarget,T=w(this,B,!0).event(j),A=ht(j.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",Q,!0),L=jt(j,R),q=j.clientX,F=j.clientY;Ia(j.view),ts(j),T.mouse=[L,this.__zoom.invert(L)],Qr(this),T.start();function Y(O){if(Fn(O),!T.moved){var I=O.clientX-q,H=O.clientY-F;T.moved=I*I+H*H>E}T.event(O).zoom("mouse",s(p(T.that.__zoom,T.mouse[0]=jt(O,R),T.mouse[1]),T.extent,a))}function Q(O){A.on("mousemove.zoom mouseup.zoom",null),Ta(O.view,T.moved),Fn(O),T.event(O).end()}}function _(j,...B){if(e.apply(this,arguments)){var R=this.__zoom,T=jt(j.changedTouches?j.changedTouches[0]:j,this),A=R.invert(T),L=R.k*(j.shiftKey?.5:2),q=s(p(y(R,L),T,A),n.apply(this,B),a);Fn(j),l>0?ht(this).transition().duration(l).call(N,q,T,j):ht(this).call(v.transform,q,T,j)}}function C(j,...B){if(e.apply(this,arguments)){var R=j.touches,T=R.length,A=w(this,B,j.changedTouches.length===T).event(j),L,q,F,Y;for(ts(j),q=0;q<T;++q)F=R[q],Y=jt(F,this),Y=[Y,this.__zoom.invert(Y),F.identifier],A.touch0?!A.touch1&&A.touch0[2]!==Y[2]&&(A.touch1=Y,A.taps=0):(A.touch0=Y,L=!0,A.taps=1+!!h);h&&(h=clearTimeout(h)),L&&(A.taps<2&&(f=Y[0],h=setTimeout(function(){h=null},u)),Qr(this),A.start())}}function $(j,...B){if(this.__zooming){var R=w(this,B).event(j),T=j.changedTouches,A=T.length,L,q,F,Y;for(Fn(j),L=0;L<A;++L)q=T[L],F=jt(q,this),R.touch0&&R.touch0[2]===q.identifier?R.touch0[0]=F:R.touch1&&R.touch1[2]===q.identifier&&(R.touch1[0]=F);if(q=R.that.__zoom,R.touch1){var Q=R.touch0[0],O=R.touch0[1],I=R.touch1[0],H=R.touch1[1],V=(V=I[0]-Q[0])*V+(V=I[1]-Q[1])*V,W=(W=H[0]-O[0])*W+(W=H[1]-O[1])*W;q=y(q,Math.sqrt(V/W)),F=[(Q[0]+I[0])/2,(Q[1]+I[1])/2],Y=[(O[0]+H[0])/2,(O[1]+H[1])/2]}else if(R.touch0)F=R.touch0[0],Y=R.touch0[1];else return;R.zoom("touch",s(p(q,F,Y),R.extent,a))}}function z(j,...B){if(this.__zooming){var R=w(this,B).event(j),T=j.changedTouches,A=T.length,L,q;for(ts(j),m&&clearTimeout(m),m=setTimeout(function(){m=null},u),L=0;L<A;++L)q=T[L],R.touch0&&R.touch0[2]===q.identifier?delete R.touch0:R.touch1&&R.touch1[2]===q.identifier&&delete R.touch1;if(R.touch1&&!R.touch0&&(R.touch0=R.touch1,delete R.touch1),R.touch0)R.touch0[1]=this.__zoom.invert(R.touch0[0]);else if(R.end(),R.taps===2&&(q=jt(q,this),Math.hypot(f[0]-q[0],f[1]-q[1])<S)){var F=ht(this).on("dblclick.zoom");F&&F.apply(this,arguments)}}}return v.wheelDelta=function(j){return arguments.length?(r=typeof j=="function"?j:kr(+j),v):r},v.filter=function(j){return arguments.length?(e=typeof j=="function"?j:kr(!!j),v):e},v.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:kr(!!j),v):i},v.extent=function(j){return arguments.length?(n=typeof j=="function"?j:kr([[+j[0][0],+j[0][1]],[+j[1][0],+j[1][1]]]),v):n},v.scaleExtent=function(j){return arguments.length?(o[0]=+j[0],o[1]=+j[1],v):[o[0],o[1]]},v.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],v):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},v.constrain=function(j){return arguments.length?(s=j,v):s},v.duration=function(j){return arguments.length?(l=+j,v):l},v.interpolate=function(j){return arguments.length?(c=j,v):c},v.on=function(){var j=d.on.apply(d,arguments);return j===d?v:j},v.clickDistance=function(j){return arguments.length?(E=(j=+j)*j,v):Math.sqrt(E)},v.tapDistance=function(j){return arguments.length?(S=+j,v):S},v}function Ze(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=Ze(e[s]))!==""&&(n+=(n&&" ")+r);else for(let s in e)e[s]&&(n+=(n&&" ")+s);return n}const Dt={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."},Kn=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Aa=["Enter"," ","Escape"],La={"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 Rn;(function(e){e.Strict="strict",e.Loose="loose"})(Rn||(Rn={}));var un;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(un||(un={}));var Qn;(function(e){e.Partial="partial",e.Full="full"})(Qn||(Qn={}));const Da={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Kt;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Kt||(Kt={}));var _n;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(_n||(_n={}));var ye;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ye||(ye={}));const uo={[ye.Left]:ye.Right,[ye.Right]:ye.Left,[ye.Top]:ye.Bottom,[ye.Bottom]:ye.Top};function Pa(e){return e===null?null:e?"valid":"invalid"}const $a=e=>"id"in e&&"source"in e&&"target"in e,Bl=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),js=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),sr=(e,n=[0,0])=>{const{width:s,height:r}=Ft(e),i=e.origin??n,o=s*i[0],a=r*i[1];return{x:e.position.x-o,y:e.position.y-a}},Ol=(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):js(i)?i:n.nodeLookup.get(i.id));const l=a?Lr(a,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Br(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Or(s)},or=(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=Br(s,Lr(i)),r=!0)}),r?Or(s):{x:0,y:0,width:0,height:0}},Ns=(e,n,[s,r,i]=[0,0,1],o=!1,a=!1)=>{const l={...ir(n,[s,r,i]),width:n.width/i,height:n.height/i},c=[];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,x=h.height??d.height??d.initialHeight??null,E=Jn(l,Ln(d)),S=(u??0)*(x??0),v=o&&E>0;(!d.internals.handleBounds||v||E>=S||d.dragging)&&c.push(d)}return c},zl=(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 Hl(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 ql({nodes:e,width:n,height:s,panZoom:r,minZoom:i,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const l=Hl(e,a),c=or(l),d=Cs(c,n,s,a?.minZoom??i,a?.maxZoom??o,a?.padding??.1);return await r.setViewport(d,{duration:a?.duration,ease:a?.ease,interpolate:a?.interpolate}),Promise.resolve(!0)}function Ba({nodeId:e,nextPosition:n,nodeLookup:s,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const a=s.get(e),l=a.parentId?s.get(a.parentId):void 0,{x:c,y:d}=l?l.internals.positionAbsolute:{x:0,y:0},h=a.origin??r;let f=a.extent||i;if(a.extent==="parent"&&!a.expandParent)if(!l)o?.("005",Dt.error005());else{const u=l.measured.width,x=l.measured.height;u&&x&&(f=[[c,d],[c+u,d+x]])}else l&&Dn(a.extent)&&(f=[[a.extent[0][0]+c,a.extent[0][1]+d],[a.extent[1][0]+c,a.extent[1][1]+d]]);const m=Dn(f)?fn(n,f,a.measured):n;return(a.measured.width===void 0||a.measured.height===void 0)&&o?.("015",Dt.error015()),{position:{x:m.x-c+(a.measured.width??0)*h[0],y:m.y-d+(a.measured.height??0)*h[1]},positionAbsolute:m}}async function Vl({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),x=!u&&m.parentId&&a.find(E=>E.id===m.parentId);(u||x)&&a.push(m)}const l=new Set(n.map(m=>m.id)),c=r.filter(m=>m.deletable!==!1),h=zl(a,c);for(const m of c)l.has(m.id)&&!h.find(x=>x.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 An=(e,n=0,s=1)=>Math.min(Math.max(e,n),s),fn=(e={x:0,y:0},n,s)=>({x:An(e.x,n[0][0],n[1][0]-(s?.width??0)),y:An(e.y,n[0][1],n[1][1]-(s?.height??0))});function Oa(e,n,s){const{width:r,height:i}=Ft(s),{x:o,y:a}=s.internals.positionAbsolute;return fn(e,[[o,a],[o+r,a+i]],n)}const fo=(e,n,s)=>e<n?An(Math.abs(e-n),1,n)/n:e>s?-An(Math.abs(e-s),1,n)/n:0,za=(e,n,s=15,r=40)=>{const i=fo(e.x,r,n.width-r)*s,o=fo(e.y,r,n.height-r)*s;return[i,o]},Br=(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)}),hs=({x:e,y:n,width:s,height:r})=>({x:e,y:n,x2:e+s,y2:n+r}),Or=({x:e,y:n,x2:s,y2:r})=>({x:e,y:n,width:s-e,height:r-n}),Ln=(e,n=[0,0])=>{const{x:s,y:r}=js(e)?e.internals.positionAbsolute:sr(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}},Lr=(e,n=[0,0])=>{const{x:s,y:r}=js(e)?e.internals.positionAbsolute:sr(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)}},Ha=(e,n)=>Or(Br(hs(e),hs(n))),Jn=(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)},ho=e=>Nt(e.width)&&Nt(e.height)&&Nt(e.x)&&Nt(e.y),Nt=e=>!isNaN(e)&&isFinite(e),Wl=(e,n)=>{},ar=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),ir=({x:e,y:n},[s,r,i],o=!1,a=[1,1])=>{const l={x:(e-s)/i,y:(n-r)/i};return o?ar(l,a):l},Dr=({x:e,y:n},[s,r,i])=>({x:e*i+s,y:n*i+r});function Cn(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 Fl(e,n,s){if(typeof e=="string"||typeof e=="number"){const r=Cn(e,s),i=Cn(e,n);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=Cn(e.top??e.y??0,s),i=Cn(e.bottom??e.y??0,s),o=Cn(e.left??e.x??0,n),a=Cn(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 Yl(e,n,s,r,i,o){const{x:a,y:l}=Dr(e,[n,s,r]),{x:c,y:d}=Dr({x:e.x+e.width,y:e.y+e.height},[n,s,r]),h=i-c,f=o-d;return{left:Math.floor(a),top:Math.floor(l),right:Math.floor(h),bottom:Math.floor(f)}}const Cs=(e,n,s,r,i,o)=>{const a=Fl(o,n,s),l=(n-a.x)/e.width,c=(s-a.y)/e.height,d=Math.min(l,c),h=An(d,r,i),f=e.x+e.width/2,m=e.y+e.height/2,u=n/2-f*h,x=s/2-m*h,E=Yl(e,u,x,h,n,s),S={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-S.left+S.right,y:x-S.top+S.bottom,zoom:h}},er=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Dn(e){return e!=null&&e!=="parent"}function Ft(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function qa(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Va(e,n={width:0,height:0},s,r,i){const o={...e},a=r.get(s);if(a){const l=a.origin||i;o.x+=a.internals.positionAbsolute.x-(n.width??0)*l[0],o.y+=a.internals.positionAbsolute.y-(n.height??0)*l[1]}return o}function mo(e,n){if(e.size!==n.size)return!1;for(const s of e)if(!n.has(s))return!1;return!0}function Gl(){let e,n;return{promise:new Promise((r,i)=>{e=r,n=i}),resolve:e,reject:n}}function Zl(e){return{...La,...e||{}}}function Gn(e,{snapGrid:n=[0,0],snapToGrid:s=!1,transform:r,containerBounds:i}){const{x:o,y:a}=Ct(e),l=ir({x:o-(i?.left??0),y:a-(i?.top??0)},r),{x:c,y:d}=s?ar(l,n):l;return{xSnapped:c,ySnapped:d,...l}}const Ss=e=>({width:e.offsetWidth,height:e.offsetHeight}),Wa=e=>e?.getRootNode?.()||window?.document,Xl=["INPUT","SELECT","TEXTAREA"];function Fa(e){const n=e.composedPath?.()?.[0]||e.target;return n?.nodeType!==1?!1:Xl.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const Ya=e=>"clientX"in e,Ct=(e,n)=>{const s=Ya(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)}},go=(e,n,s,r,i)=>{const o=n.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const l=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:i,position:a.getAttribute("data-handlepos"),x:(l.left-s.left)/r,y:(l.top-s.top)/r,...Ss(a)}})};function Ga({sourceX:e,sourceY:n,targetX:s,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:a,targetControlY:l}){const c=e*.125+i*.375+a*.375+s*.125,d=n*.125+o*.375+l*.375+r*.125,h=Math.abs(c-e),f=Math.abs(d-n);return[c,d,h,f]}function jr(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function po({pos:e,x1:n,y1:s,x2:r,y2:i,c:o}){switch(e){case ye.Left:return[n-jr(n-r,o),s];case ye.Right:return[n+jr(r-n,o),s];case ye.Top:return[n,s-jr(s-i,o)];case ye.Bottom:return[n,s+jr(i-s,o)]}}function Za({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top,curvature:a=.25}){const[l,c]=po({pos:s,x1:e,y1:n,x2:r,y2:i,c:a}),[d,h]=po({pos:o,x1:r,y1:i,x2:e,y2:n,c:a}),[f,m,u,x]=Ga({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:l,sourceControlY:c,targetControlX:d,targetControlY:h});return[`M${e},${n} C${l},${c} ${d},${h} ${r},${i}`,f,m,u,x]}function Xa({sourceX:e,sourceY:n,targetX:s,targetY:r}){const i=Math.abs(s-e)/2,o=s<e?s+i:s-i,a=Math.abs(r-n)/2,l=r<n?r+a:r-a;return[o,l,i,a]}function Ul({sourceNode:e,targetNode:n,selected:s=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const a=i&&s?r+1e3:r,l=Math.max(e.parentId||i&&e.selected?e.internals.z:0,n.parentId||i&&n.selected?n.internals.z:0);return a+l}function Kl({sourceNode:e,targetNode:n,width:s,height:r,transform:i}){const o=Br(Lr(e),Lr(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 Jn(a,Or(o))>0}const Ql=({source:e,sourceHandle:n,target:s,targetHandle:r})=>`xy-edge__${e}${n||""}-${s}${r||""}`,Jl=(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)),ec=(e,n,s={})=>{if(!e.source||!e.target)return n;const r=s.getEdgeId||Ql;let i;return $a(e)?i={...e}:i={...e,id:r(e)},Jl(i,n)?n:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,n.concat(i))};function Ua({sourceX:e,sourceY:n,targetX:s,targetY:r}){const[i,o,a,l]=Xa({sourceX:e,sourceY:n,targetX:s,targetY:r});return[`M ${e},${n}L ${s},${r}`,i,o,a,l]}const xo={[ye.Left]:{x:-1,y:0},[ye.Right]:{x:1,y:0},[ye.Top]:{x:0,y:-1},[ye.Bottom]:{x:0,y:1}},tc=({source:e,sourcePosition:n=ye.Bottom,target:s})=>n===ye.Left||n===ye.Right?e.x<s.x?{x:1,y:0}:{x:-1,y:0}:e.y<s.y?{x:0,y:1}:{x:0,y:-1},bo=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function nc({source:e,sourcePosition:n=ye.Bottom,target:s,targetPosition:r=ye.Top,center:i,offset:o,stepPosition:a}){const l=xo[n],c=xo[r],d={x:e.x+l.x*o,y:e.y+l.y*o},h={x:s.x+c.x*o,y:s.y+c.y*o},f=tc({source:d,sourcePosition:n,target:h}),m=f.x!==0?"x":"y",u=f[m];let x=[],E,S;const v={x:0,y:0},y={x:0,y:0},[,,p,b]=Xa({sourceX:e.x,sourceY:e.y,targetX:s.x,targetY:s.y});if(l[m]*c[m]===-1){m==="x"?(E=i.x??d.x+(h.x-d.x)*a,S=i.y??(d.y+h.y)/2):(E=i.x??(d.x+h.x)/2,S=i.y??d.y+(h.y-d.y)*a);const w=[{x:E,y:d.y},{x:E,y:h.y}],M=[{x:d.x,y:S},{x:h.x,y:S}];l[m]===u?x=m==="x"?w:M:x=m==="x"?M:w}else{const w=[{x:d.x,y:h.y}],M=[{x:h.x,y:d.y}];if(m==="x"?x=l.x===u?M:w:x=l.y===u?w:M,n===r){const $=Math.abs(e[m]-s[m]);if($<=o){const z=Math.min(o-1,o-$);l[m]===u?v[m]=(d[m]>e[m]?-1:1)*z:y[m]=(h[m]>s[m]?-1:1)*z}}if(n!==r){const $=m==="x"?"y":"x",z=l[m]===c[$],j=d[$]>h[$],B=d[$]<h[$];(l[m]===1&&(!z&&j||z&&B)||l[m]!==1&&(!z&&B||z&&j))&&(x=m==="x"?w:M)}const D={x:d.x+v.x,y:d.y+v.y},P={x:h.x+y.x,y:h.y+y.y},_=Math.max(Math.abs(D.x-x[0].x),Math.abs(P.x-x[0].x)),C=Math.max(Math.abs(D.y-x[0].y),Math.abs(P.y-x[0].y));_>=C?(E=(D.x+P.x)/2,S=x[0].y):(E=x[0].x,S=(D.y+P.y)/2)}return[[e,{x:d.x+v.x,y:d.y+v.y},...x,{x:h.x+y.x,y:h.y+y.y},s],E,S,p,b]}function rc(e,n,s,r){const i=Math.min(bo(e,n)/2,bo(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 l=e.x<s.x?1:-1,c=e.y<s.y?-1:1;return`L ${o},${a+i*c}Q ${o},${a} ${o+i*l},${a}`}function ms({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top,borderRadius:a=5,centerX:l,centerY:c,offset:d=20,stepPosition:h=.5}){const[f,m,u,x,E]=nc({source:{x:e,y:n},sourcePosition:s,target:{x:r,y:i},targetPosition:o,center:{x:l,y:c},offset:d,stepPosition:h});return[f.reduce((v,y,p)=>{let b="";return p>0&&p<f.length-1?b=rc(f[p-1],y,f[p+1],a):b=`${p===0?"M":"L"}${y.x} ${y.y}`,v+=b,v},""),m,u,x,E]}function yo(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function sc(e){const{sourceNode:n,targetNode:s}=e;if(!yo(n)||!yo(s))return null;const r=n.internals.handleBounds||vo(n.handles),i=s.internals.handleBounds||vo(s.handles),o=wo(r?.source??[],e.sourceHandle),a=wo(e.connectionMode===Rn.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!a)return e.onError?.("008",Dt.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=o?.position||ye.Bottom,c=a?.position||ye.Top,d=hn(n,o,l),h=hn(s,a,c);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:l,targetPosition:c}}function vo(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 hn(e,n,s=ye.Left,r=!1){const i=(n?.x??0)+e.internals.positionAbsolute.x,o=(n?.y??0)+e.internals.positionAbsolute.y,{width:a,height:l}=n??Ft(e);if(r)return{x:i+a/2,y:o+l/2};switch(n?.position??s){case ye.Top:return{x:i+a/2,y:o};case ye.Right:return{x:i+a,y:o+l/2};case ye.Bottom:return{x:i+a/2,y:o+l};case ye.Left:return{x:i,y:o+l/2}}}function wo(e,n){return e&&(n?e.find(s=>s.id===n):e[0])||null}function gs(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function oc(e,{id:n,defaultColor:s,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((a,l)=>([l.markerStart||r,l.markerEnd||i].forEach(c=>{if(c&&typeof c=="object"){const d=gs(c,n);o.has(d)||(a.push({id:d,color:c.color||s,...c}),o.add(d))}}),a),[]).sort((a,l)=>a.id.localeCompare(l.id))}const Ka=1e3,ac=10,Es={nodeOrigin:[0,0],nodeExtent:Kn,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},ic={...Es,checkEquality:!0};function Ms(e,n){const s={...e};for(const r in n)n[r]!==void 0&&(s[r]=n[r]);return s}function lc(e,n,s){const r=Ms(Es,s);for(const i of e.values())if(i.parentId)Ts(i,e,n,r);else{const o=sr(i,r.nodeOrigin),a=Dn(i.extent)?i.extent:r.nodeExtent,l=fn(o,a,Ft(i));i.internals.positionAbsolute=l}}function cc(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 Is(e){return e==="manual"}function ps(e,n,s,r={}){const i=Ms(ic,r),o={i:0},a=new Map(n),l=i?.elevateNodesOnSelect&&!Is(i.zIndexMode)?Ka:0;let c=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=sr(d,i.nodeOrigin),m=Dn(d.extent)?d.extent:i.nodeExtent,u=fn(f,m,Ft(d));h={...i.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:u,handleBounds:cc(d,h),z:Qa(d,l,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&&(c=!1),d.parentId&&Ts(h,n,s,r,o)}return c}function dc(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 Ts(e,n,s,r,i){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:l,zIndexMode:c}=Ms(Es,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}dc(e,s),i&&!h.parentId&&h.internals.rootParentIndex===void 0&&c==="auto"&&(h.internals.rootParentIndex=++i.i,h.internals.z=h.internals.z+i.i*ac),i&&h.internals.rootParentIndex!==void 0&&(i.i=h.internals.rootParentIndex);const f=o&&!Is(c)?Ka:0,{x:m,y:u,z:x}=uc(e,h,a,l,f,c),{positionAbsolute:E}=e.internals,S=m!==E.x||u!==E.y;(S||x!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:S?{x:m,y:u}:E,z:x}})}function Qa(e,n,s){const r=Nt(e.zIndex)?e.zIndex:0;return Is(s)?r:r+(e.selected?n:0)}function uc(e,n,s,r,i,o){const{x:a,y:l}=n.internals.positionAbsolute,c=Ft(e),d=sr(e,s),h=Dn(e.extent)?fn(d,e.extent,c):d;let f=fn({x:a+h.x,y:l+h.y},r,c);e.extent==="parent"&&(f=Oa(f,c,n));const m=Qa(e,i,o),u=n.internals.z??0;return{x:f.x,y:f.y,z:u>=m?u+1:m}}function Rs(e,n,s,r=[0,0]){const i=[],o=new Map;for(const a of e){const l=n.get(a.parentId);if(!l)continue;const c=o.get(a.parentId)?.expandedRect??Ln(l),d=Ha(c,a.rect);o.set(a.parentId,{expandedRect:d,parent:l})}return o.size>0&&o.forEach(({expandedRect:a,parent:l},c)=>{const d=l.internals.positionAbsolute,h=Ft(l),f=l.origin??r,m=a.x<d.x?Math.round(Math.abs(d.x-a.x)):0,u=a.y<d.y?Math.round(Math.abs(d.y-a.y)):0,x=Math.max(h.width,Math.round(a.width)),E=Math.max(h.height,Math.round(a.height)),S=(x-h.width)*f[0],v=(E-h.height)*f[1];(m>0||u>0||S||v)&&(i.push({id:c,type:"position",position:{x:l.position.x-m+S,y:l.position.y-u+v}}),s.get(c)?.forEach(y=>{e.some(p=>p.id===y.id)||i.push({id:y.id,type:"position",position:{x:y.position.x+m,y:y.position.y+u}})})),(h.width<a.width||h.height<a.height||m||u)&&i.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:x+(m?f[0]*m-S:0),height:E+(u?f[1]*u-v:0)}})}),i}function fc(e,n,s,r,i,o,a){const l=r?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const d=[],h=window.getComputedStyle(l),{m22:f}=new window.DOMMatrixReadOnly(h.transform),m=[];for(const u of e.values()){const x=n.get(u.id);if(!x)continue;if(x.hidden){n.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),c=!0;continue}const E=Ss(u.nodeElement),S=x.measured.width!==E.width||x.measured.height!==E.height;if(!!(E.width&&E.height&&(S||!x.internals.handleBounds||u.force))){const y=u.nodeElement.getBoundingClientRect(),p=Dn(x.extent)?x.extent:o;let{positionAbsolute:b}=x.internals;x.parentId&&x.extent==="parent"?b=Oa(b,E,n.get(x.parentId)):p&&(b=fn(b,p,E));const N={...x,measured:E,internals:{...x.internals,positionAbsolute:b,handleBounds:{source:go("source",u.nodeElement,y,f,x.id),target:go("target",u.nodeElement,y,f,x.id)}}};n.set(x.id,N),x.parentId&&Ts(N,n,s,{nodeOrigin:i,zIndexMode:a}),c=!0,S&&(d.push({id:x.id,type:"dimensions",dimensions:E}),x.expandParent&&x.parentId&&m.push({id:x.id,parentId:x.parentId,rect:Ln(N,i)}))}}if(m.length>0){const u=Rs(m,n,s,i);d.push(...u)}return{changes:d,updatedInternals:c}}async function hc({delta:e,panZoom:n,transform:s,translateExtent:r,width:i,height:o}){if(!n||!e.x&&!e.y)return Promise.resolve(!1);const a=await n.setViewportConstrained({x:s[0]+e.x,y:s[1]+e.y,zoom:s[2]},[[0,0],[i,o]],r),l=!!a&&(a.x!==s[0]||a.y!==s[1]||a.k!==s[2]);return Promise.resolve(l)}function ko(e,n,s,r,i,o){let a=i;const l=r.get(a)||new Map;r.set(a,l.set(s,n)),a=`${i}-${e}`;const c=r.get(a)||new Map;if(r.set(a,c.set(s,n)),o){a=`${i}-${e}-${o}`;const d=r.get(a)||new Map;r.set(a,d.set(s,n))}}function Ja(e,n,s){e.clear(),n.clear();for(const r of s){const{source:i,target:o,sourceHandle:a=null,targetHandle:l=null}=r,c={edgeId:r.id,source:i,target:o,sourceHandle:a,targetHandle:l},d=`${i}-${a}--${o}-${l}`,h=`${o}-${l}--${i}-${a}`;ko("source",c,h,e,i,a),ko("target",c,d,e,o,l),n.set(r.id,r)}}function ei(e,n){if(!e.parentId)return!1;const s=n.get(e.parentId);return s?s.selected?!0:ei(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 mc(e,n,s,r){const i=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!ei(a,e))&&(a.draggable||n&&typeof a.draggable>"u")){const l=e.get(o);l&&i.set(o,{id:o,position:l.position||{x:0,y:0},distance:{x:s.x-l.internals.positionAbsolute.x,y:s.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return i}function ns({nodeId:e,dragItems:n,nodeLookup:s,dragging:r=!0}){const i=[];for(const[a,l]of n){const c=s.get(a)?.internals.userNode;c&&i.push({...c,position:l.position,dragging:r})}if(!e)return[i[0],i];const o=s.get(e)?.internals.userNode;return[o?{...o,position:n.get(e)?.position||o.position,dragging:r}:i[0],i]}function gc({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=ar(o,n);return{x:a.x-o.x,y:a.y-o.y}}function pc({onNodeMouseDown:e,getStoreItems:n,onDragStart:s,onDrag:r,onDragStop:i}){let o={x:null,y:null},a=0,l=new Map,c=!1,d={x:0,y:0},h=null,f=!1,m=null,u=!1,x=!1,E=null;function S({noDragClassName:y,handleSelector:p,domNode:b,isSelectable:N,nodeId:w,nodeClickDistance:M=0}){m=ht(b);function D({x:$,y:z}){const{nodeLookup:j,nodeExtent:B,snapGrid:R,snapToGrid:T,nodeOrigin:A,onNodeDrag:L,onSelectionDrag:q,onError:F,updateNodePositions:Y}=n();o={x:$,y:z};let Q=!1;const O=l.size>1,I=O&&B?hs(or(l)):null,H=O&&T?gc({dragItems:l,snapGrid:R,x:$,y:z}):null;for(const[V,W]of l){if(!j.has(V))continue;let X={x:$-W.distance.x,y:z-W.distance.y};T&&(X=H?{x:Math.round(X.x+H.x),y:Math.round(X.y+H.y)}:ar(X,R));let ee=null;if(O&&B&&!W.extent&&I){const{positionAbsolute:U}=W.internals,oe=U.x-I.x+B[0][0],le=U.x+W.measured.width-I.x2+B[1][0],ie=U.y-I.y+B[0][1],he=U.y+W.measured.height-I.y2+B[1][1];ee=[[oe,ie],[le,he]]}const{position:se,positionAbsolute:J}=Ba({nodeId:V,nextPosition:X,nodeLookup:j,nodeExtent:ee||B,nodeOrigin:A,onError:F});Q=Q||W.position.x!==se.x||W.position.y!==se.y,W.position=se,W.internals.positionAbsolute=J}if(x=x||Q,!!Q&&(Y(l,!0),E&&(r||L||!w&&q))){const[V,W]=ns({nodeId:w,dragItems:l,nodeLookup:j});r?.(E,l,V,W),L?.(E,V,W),w||q?.(E,W)}}async function P(){if(!h)return;const{transform:$,panBy:z,autoPanSpeed:j,autoPanOnNodeDrag:B}=n();if(!B){c=!1,cancelAnimationFrame(a);return}const[R,T]=za(d,h,j);(R!==0||T!==0)&&(o.x=(o.x??0)-R/$[2],o.y=(o.y??0)-T/$[2],await z({x:R,y:T})&&D(o)),a=requestAnimationFrame(P)}function _($){const{nodeLookup:z,multiSelectionActive:j,nodesDraggable:B,transform:R,snapGrid:T,snapToGrid:A,selectNodesOnDrag:L,onNodeDragStart:q,onSelectionDragStart:F,unselectNodesAndEdges:Y}=n();f=!0,(!L||!N)&&!j&&w&&(z.get(w)?.selected||Y()),N&&L&&w&&e?.(w);const Q=Gn($.sourceEvent,{transform:R,snapGrid:T,snapToGrid:A,containerBounds:h});if(o=Q,l=mc(z,B,Q,w),l.size>0&&(s||q||!w&&F)){const[O,I]=ns({nodeId:w,dragItems:l,nodeLookup:z});s?.($.sourceEvent,l,O,I),q?.($.sourceEvent,O,I),w||F?.($.sourceEvent,I)}}const C=Ra().clickDistance(M).on("start",$=>{const{domNode:z,nodeDragThreshold:j,transform:B,snapGrid:R,snapToGrid:T}=n();h=z?.getBoundingClientRect()||null,u=!1,x=!1,E=$.sourceEvent,j===0&&_($),o=Gn($.sourceEvent,{transform:B,snapGrid:R,snapToGrid:T,containerBounds:h}),d=Ct($.sourceEvent,h)}).on("drag",$=>{const{autoPanOnNodeDrag:z,transform:j,snapGrid:B,snapToGrid:R,nodeDragThreshold:T,nodeLookup:A}=n(),L=Gn($.sourceEvent,{transform:j,snapGrid:B,snapToGrid:R,containerBounds:h});if(E=$.sourceEvent,($.sourceEvent.type==="touchmove"&&$.sourceEvent.touches.length>1||w&&!A.has(w))&&(u=!0),!u){if(!c&&z&&f&&(c=!0,P()),!f){const q=Ct($.sourceEvent,h),F=q.x-d.x,Y=q.y-d.y;Math.sqrt(F*F+Y*Y)>T&&_($)}(o.x!==L.xSnapped||o.y!==L.ySnapped)&&l&&f&&(d=Ct($.sourceEvent,h),D(L))}}).on("end",$=>{if(!(!f||u)&&(c=!1,f=!1,cancelAnimationFrame(a),l.size>0)){const{nodeLookup:z,updateNodePositions:j,onNodeDragStop:B,onSelectionDragStop:R}=n();if(x&&(j(l,!1),x=!1),i||B||!w&&R){const[T,A]=ns({nodeId:w,dragItems:l,nodeLookup:z,dragging:!1});i?.($.sourceEvent,l,T,A),B?.($.sourceEvent,T,A),w||R?.($.sourceEvent,A)}}}).filter($=>{const z=$.target;return!$.button&&(!y||!jo(z,`.${y}`,b))&&(!p||jo(z,p,b))});m.call(C)}function v(){m?.on(".drag",null)}return{update:S,destroy:v}}function xc(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())Jn(i,Ln(o))>0&&r.push(o);return r}const bc=250;function yc(e,n,s,r){let i=[],o=1/0;const a=xc(e,s,n+bc);for(const l of a){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const d of c){if(r.nodeId===d.nodeId&&r.type===d.type&&r.id===d.id)continue;const{x:h,y:f}=hn(l,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 l=r.type==="source"?"target":"source";return i.find(c=>c.type===l)??i[0]}return i[0]}function ti(e,n,s,r,i,o=!1){const a=r.get(e);if(!a)return null;const l=i==="strict"?a.internals.handleBounds?.[n]:[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]],c=(s?l?.find(d=>d.id===s):l?.[0])??null;return c&&o?{...c,...hn(a,c,c.position,!0)}:c}function ni(e,n){return e||(n?.classList.contains("target")?"target":n?.classList.contains("source")?"source":null)}function vc(e,n){let s=null;return n?s=!0:e&&!n&&(s=!1),s}const ri=()=>!0;function wc(e,{connectionMode:n,connectionRadius:s,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:a,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:h,flowId:f,panBy:m,cancelConnection:u,onConnectStart:x,onConnect:E,onConnectEnd:S,isValidConnection:v=ri,onReconnectEnd:y,updateConnection:p,getTransform:b,getFromHandle:N,autoPanSpeed:w,dragThreshold:M=1,handleDomNode:D}){const P=Wa(e.target);let _=0,C;const{x:$,y:z}=Ct(e),j=ni(o,D),B=l?.getBoundingClientRect();let R=!1;if(!B||!j)return;const T=ti(i,j,r,c,n);if(!T)return;let A=Ct(e,B),L=!1,q=null,F=!1,Y=null;function Q(){if(!h||!B)return;const[se,J]=za(A,B,w);m({x:se,y:J}),_=requestAnimationFrame(Q)}const O={...T,nodeId:i,type:j,position:T.position},I=c.get(i);let V={inProgress:!0,isValid:null,from:hn(I,O,ye.Left,!0),fromHandle:O,fromPosition:O.position,fromNode:I,to:A,toHandle:null,toPosition:uo[O.position],toNode:null,pointer:A};function W(){R=!0,p(V),x?.(e,{nodeId:i,handleId:r,handleType:j})}M===0&&W();function X(se){if(!R){const{x:he,y:de}=Ct(se),Z=he-$,ae=de-z;if(!(Z*Z+ae*ae>M*M))return;W()}if(!N()||!O){ee(se);return}const J=b();A=Ct(se,B),C=yc(ir(A,J,!1,[1,1]),s,c,O),L||(Q(),L=!0);const U=si(se,{handle:C,connectionMode:n,fromNodeId:i,fromHandleId:r,fromType:a?"target":"source",isValidConnection:v,doc:P,lib:d,flowId:f,nodeLookup:c});Y=U.handleDomNode,q=U.connection,F=vc(!!C,U.isValid);const oe=c.get(i),le=oe?hn(oe,O,ye.Left,!0):V.from,ie={...V,from:le,isValid:F,to:U.toHandle&&F?Dr({x:U.toHandle.x,y:U.toHandle.y},J):A,toHandle:U.toHandle,toPosition:F&&U.toHandle?U.toHandle.position:uo[O.position],toNode:U.toHandle?c.get(U.toHandle.nodeId):null,pointer:A};p(ie),V=ie}function ee(se){if(!("touches"in se&&se.touches.length>0)){if(R){(C||Y)&&q&&F&&E?.(q);const{inProgress:J,...U}=V,oe={...U,toPosition:V.toHandle?V.toPosition:null};S?.(se,oe),o&&y?.(se,oe)}u(),cancelAnimationFrame(_),L=!1,F=!1,q=null,Y=null,P.removeEventListener("mousemove",X),P.removeEventListener("mouseup",ee),P.removeEventListener("touchmove",X),P.removeEventListener("touchend",ee)}}P.addEventListener("mousemove",X),P.addEventListener("mouseup",ee),P.addEventListener("touchmove",X),P.addEventListener("touchend",ee)}function si(e,{handle:n,connectionMode:s,fromNodeId:r,fromHandleId:i,fromType:o,doc:a,lib:l,flowId:c,isValidConnection:d=ri,nodeLookup:h}){const f=o==="target",m=n?a.querySelector(`.${l}-flow__handle[data-id="${c}-${n?.nodeId}-${n?.id}-${n?.type}"]`):null,{x:u,y:x}=Ct(e),E=a.elementFromPoint(u,x),S=E?.classList.contains(`${l}-flow__handle`)?E:m,v={handleDomNode:S,isValid:!1,connection:null,toHandle:null};if(S){const y=ni(void 0,S),p=S.getAttribute("data-nodeid"),b=S.getAttribute("data-handleid"),N=S.classList.contains("connectable"),w=S.classList.contains("connectableend");if(!p||!y)return v;const M={source:f?p:r,sourceHandle:f?b:i,target:f?r:p,targetHandle:f?i:b};v.connection=M;const P=N&&w&&(s===Rn.Strict?f&&y==="source"||!f&&y==="target":p!==r||b!==i);v.isValid=P&&d(M),v.toHandle=ti(p,y,b,h,s,!0)}return v}const xs={onPointerDown:wc,isValid:si};function kc({domNode:e,panZoom:n,getTransform:s,getViewScale:r}){const i=ht(e);function o({translateExtent:l,width:c,height:d,zoomStep:h=1,pannable:f=!0,zoomable:m=!0,inversePan:u=!1}){const x=p=>{if(p.sourceEvent.type!=="wheel"||!n)return;const b=s(),N=p.sourceEvent.ctrlKey&&er()?10:1,w=-p.sourceEvent.deltaY*(p.sourceEvent.deltaMode===1?.05:p.sourceEvent.deltaMode?1:.002)*h,M=b[2]*Math.pow(2,w*N);n.scaleTo(M)};let E=[0,0];const S=p=>{(p.sourceEvent.type==="mousedown"||p.sourceEvent.type==="touchstart")&&(E=[p.sourceEvent.clientX??p.sourceEvent.touches[0].clientX,p.sourceEvent.clientY??p.sourceEvent.touches[0].clientY])},v=p=>{const b=s();if(p.sourceEvent.type!=="mousemove"&&p.sourceEvent.type!=="touchmove"||!n)return;const N=[p.sourceEvent.clientX??p.sourceEvent.touches[0].clientX,p.sourceEvent.clientY??p.sourceEvent.touches[0].clientY],w=[N[0]-E[0],N[1]-E[1]];E=N;const M=r()*Math.max(b[2],Math.log(b[2]))*(u?-1:1),D={x:b[0]-w[0]*M,y:b[1]-w[1]*M},P=[[0,0],[c,d]];n.setViewportConstrained({x:D.x,y:D.y,zoom:b[2]},P,l)},y=_a().on("start",S).on("zoom",f?v:null).on("zoom.wheel",m?x:null);i.call(y,{})}function a(){i.on("zoom",null)}return{update:o,destroy:a,pointer:jt}}const zr=e=>({x:e.x,y:e.y,zoom:e.k}),rs=({x:e,y:n,zoom:s})=>ks.translate(e,n).scale(s),En=(e,n)=>e.target.closest(`.${n}`),oi=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),jc=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,ss=(e,n=0,s=jc,r=()=>{})=>{const i=typeof n=="number"&&n>0;return i||r(),i?e.transition().duration(n).ease(s).on("end",r):e},ai=e=>{const n=e.ctrlKey&&er()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function Nc({zoomPanValues:e,noWheelClassName:n,d3Selection:s,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return h=>{if(En(h,n))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const f=s.property("__zoom").k||1;if(h.ctrlKey&&a){const S=jt(h),v=ai(h),y=f*Math.pow(2,v);r.scaleTo(s,y,S,h);return}const m=h.deltaMode===1?20:1;let u=i===un.Vertical?0:h.deltaX*m,x=i===un.Horizontal?0:h.deltaY*m;!er()&&h.shiftKey&&i!==un.Vertical&&(u=h.deltaY*m,x=0),r.translateBy(s,-(u/f)*o,-(x/f)*o,{internal:!0});const E=zr(s.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(h,E),e.panScrollTimeout=setTimeout(()=>{d?.(h,E),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(h,E))}}function Cc({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:s}){return function(r,i){const o=r.type==="wheel",a=!n&&o&&!r.ctrlKey,l=En(r,e);if(r.ctrlKey&&o&&l&&r.preventDefault(),a||l)return null;r.preventDefault(),s.call(this,r,i)}}function Sc({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:s}){return r=>{if(r.sourceEvent?.internal)return;const i=zr(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 Ec({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:s,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(s&&oi(n,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,zr(o.transform))}}function Mc({zoomPanValues:e,panOnDrag:n,panOnScroll:s,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return a=>{if(!a.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&oi(n,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const l=zr(a.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(a.sourceEvent,l)},s?150:0)}}}function Ic({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:s,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:a,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:h}){return f=>{const m=e||n,u=s&&f.ctrlKey,x=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(En(f,`${d}-flow__node`)||En(f,`${d}-flow__edge`)))return!0;if(!r&&!m&&!i&&!o&&!s||a||h&&!x||En(f,l)&&x||En(f,c)&&(!x||i&&x&&!e)||!s&&f.ctrlKey&&x)return!1;if(!s&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!m&&!i&&!u&&x||!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||x)&&E}}function Tc({domNode:e,minZoom:n,maxZoom:s,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:l,onDraggingChange:c}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},h=e.getBoundingClientRect(),f=_a().scaleExtent([n,s]).translateExtent(r),m=ht(e).call(f);y({x:i.x,y:i.y,zoom:An(i.zoom,n,s)},[[0,0],[h.width,h.height]],r);const u=m.on("wheel.zoom"),x=m.on("dblclick.zoom");f.wheelDelta(ai);function E(C,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?Jr:Rr).transform(ss(m,$?.duration,$?.ease,()=>z(!0)),C)}):Promise.resolve(!1)}function S({noWheelClassName:C,noPanClassName:$,onPaneContextMenu:z,userSelectionActive:j,panOnScroll:B,panOnDrag:R,panOnScrollMode:T,panOnScrollSpeed:A,preventScrolling:L,zoomOnPinch:q,zoomOnScroll:F,zoomOnDoubleClick:Y,zoomActivationKeyPressed:Q,lib:O,onTransformChange:I,connectionInProgress:H,paneClickDistance:V,selectionOnDrag:W}){j&&!d.isZoomingOrPanning&&v();const X=B&&!Q&&!j;f.clickDistance(W?1/0:!Nt(V)||V<0?0:V);const ee=X?Nc({zoomPanValues:d,noWheelClassName:C,d3Selection:m,d3Zoom:f,panOnScrollMode:T,panOnScrollSpeed:A,zoomOnPinch:q,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:l}):Cc({noWheelClassName:C,preventScrolling:L,d3ZoomHandler:u});if(m.on("wheel.zoom",ee,{passive:!1}),!j){const J=Sc({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:a});f.on("start",J);const U=Ec({zoomPanValues:d,panOnDrag:R,onPaneContextMenu:!!z,onPanZoom:o,onTransformChange:I});f.on("zoom",U);const oe=Mc({zoomPanValues:d,panOnDrag:R,panOnScroll:B,onPaneContextMenu:z,onPanZoomEnd:l,onDraggingChange:c});f.on("end",oe)}const se=Ic({zoomActivationKeyPressed:Q,panOnDrag:R,zoomOnScroll:F,panOnScroll:B,zoomOnDoubleClick:Y,zoomOnPinch:q,userSelectionActive:j,noPanClassName:$,noWheelClassName:C,lib:O,connectionInProgress:H});f.filter(se),Y?m.on("dblclick.zoom",x):m.on("dblclick.zoom",null)}function v(){f.on("zoom",null)}async function y(C,$,z){const j=rs(C),B=f?.constrain()(j,$,z);return B&&await E(B),new Promise(R=>R(B))}async function p(C,$){const z=rs(C);return await E(z,$),new Promise(j=>j(z))}function b(C){if(m){const $=rs(C),z=m.property("__zoom");(z.k!==C.zoom||z.x!==C.x||z.y!==C.y)&&f?.transform(m,$,null,{sync:!0})}}function N(){const C=m?kl(m.node()):{x:0,y:0,k:1};return{x:C.x,y:C.y,zoom:C.k}}function w(C,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?Jr:Rr).scaleTo(ss(m,$?.duration,$?.ease,()=>z(!0)),C)}):Promise.resolve(!1)}function M(C,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?Jr:Rr).scaleBy(ss(m,$?.duration,$?.ease,()=>z(!0)),C)}):Promise.resolve(!1)}function D(C){f?.scaleExtent(C)}function P(C){f?.translateExtent(C)}function _(C){const $=!Nt(C)||C<0?0:C;f?.clickDistance($)}return{update:S,destroy:v,setViewport:p,setViewportConstrained:y,getViewport:N,scaleTo:w,scaleBy:M,setScaleExtent:D,setTranslateExtent:P,syncViewport:b,setClickDistance:_}}var Pn;(function(e){e.Line="line",e.Handle="handle"})(Pn||(Pn={}));function Rc({width:e,prevWidth:n,height:s,prevHeight:r,affectsX:i,affectsY:o}){const a=e-n,l=s-r,c=[a>0?1:a<0?-1:0,l>0?1:l<0?-1:0];return a&&i&&(c[0]=c[0]*-1),l&&o&&(c[1]=c[1]*-1),c}function No(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 Xt(e,n){return Math.max(0,n-e)}function Ut(e,n){return Math.max(0,e-n)}function Nr(e,n,s){return Math.max(0,n-e,e-s)}function Co(e,n){return e?!n:n}function _c(e,n,s,r,i,o,a,l){let{affectsX:c,affectsY:d}=n;const{isHorizontal:h,isVertical:f}=n,m=h&&f,{xSnapped:u,ySnapped:x}=s,{minWidth:E,maxWidth:S,minHeight:v,maxHeight:y}=r,{x:p,y:b,width:N,height:w,aspectRatio:M}=e;let D=Math.floor(h?u-e.pointerX:0),P=Math.floor(f?x-e.pointerY:0);const _=N+(c?-D:D),C=w+(d?-P:P),$=-o[0]*N,z=-o[1]*w;let j=Nr(_,E,S),B=Nr(C,v,y);if(a){let A=0,L=0;c&&D<0?A=Xt(p+D+$,a[0][0]):!c&&D>0&&(A=Ut(p+_+$,a[1][0])),d&&P<0?L=Xt(b+P+z,a[0][1]):!d&&P>0&&(L=Ut(b+C+z,a[1][1])),j=Math.max(j,A),B=Math.max(B,L)}if(l){let A=0,L=0;c&&D>0?A=Ut(p+D,l[0][0]):!c&&D<0&&(A=Xt(p+_,l[1][0])),d&&P>0?L=Ut(b+P,l[0][1]):!d&&P<0&&(L=Xt(b+C,l[1][1])),j=Math.max(j,A),B=Math.max(B,L)}if(i){if(h){const A=Nr(_/M,v,y)*M;if(j=Math.max(j,A),a){let L=0;!c&&!d||c&&!d&&m?L=Ut(b+z+_/M,a[1][1])*M:L=Xt(b+z+(c?D:-D)/M,a[0][1])*M,j=Math.max(j,L)}if(l){let L=0;!c&&!d||c&&!d&&m?L=Xt(b+_/M,l[1][1])*M:L=Ut(b+(c?D:-D)/M,l[0][1])*M,j=Math.max(j,L)}}if(f){const A=Nr(C*M,E,S)/M;if(B=Math.max(B,A),a){let L=0;!c&&!d||d&&!c&&m?L=Ut(p+C*M+$,a[1][0])/M:L=Xt(p+(d?P:-P)*M+$,a[0][0])/M,B=Math.max(B,L)}if(l){let L=0;!c&&!d||d&&!c&&m?L=Xt(p+C*M,l[1][0])/M:L=Ut(p+(d?P:-P)*M,l[0][0])/M,B=Math.max(B,L)}}}P=P+(P<0?B:-B),D=D+(D<0?j:-j),i&&(m?_>C*M?P=(Co(c,d)?-D:D)/M:D=(Co(c,d)?-P:P)*M:h?(P=D/M,d=c):(D=P*M,c=d));const R=c?p+D:p,T=d?b+P:b;return{width:N+(c?-D:D),height:w+(d?-P:P),x:o[0]*D*(c?-1:1)+R,y:o[1]*P*(d?-1:1)+T}}const ii={width:0,height:0,x:0,y:0},Ac={...ii,pointerX:0,pointerY:0,aspectRatio:1};function Lc(e){return[[0,0],[e.measured.width,e.measured.height]]}function Dc(e,n,s){const r=n.position.x+e.position.x,i=n.position.y+e.position.y,o=e.measured.width??0,a=e.measured.height??0,l=s[0]*o,c=s[1]*a;return[[r-l,i-c],[r+o-l,i+a-c]]}function Pc({domNode:e,nodeId:n,getStoreItems:s,onChange:r,onEnd:i}){const o=ht(e);let a={controlDirection:No("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:d,boundaries:h,keepAspectRatio:f,resizeDirection:m,onResizeStart:u,onResize:x,onResizeEnd:E,shouldResize:S}){let v={...ii},y={...Ac};a={boundaries:h,resizeDirection:m,keepAspectRatio:f,controlDirection:No(d)};let p,b=null,N=[],w,M,D,P=!1;const _=Ra().on("start",C=>{const{nodeLookup:$,transform:z,snapGrid:j,snapToGrid:B,nodeOrigin:R,paneDomNode:T}=s();if(p=$.get(n),!p)return;b=T?.getBoundingClientRect()??null;const{xSnapped:A,ySnapped:L}=Gn(C.sourceEvent,{transform:z,snapGrid:j,snapToGrid:B,containerBounds:b});v={width:p.measured.width??0,height:p.measured.height??0,x:p.position.x??0,y:p.position.y??0},y={...v,pointerX:A,pointerY:L,aspectRatio:v.width/v.height},w=void 0,p.parentId&&(p.extent==="parent"||p.expandParent)&&(w=$.get(p.parentId),M=w&&p.extent==="parent"?Lc(w):void 0),N=[],D=void 0;for(const[q,F]of $)if(F.parentId===n&&(N.push({id:q,position:{...F.position},extent:F.extent}),F.extent==="parent"||F.expandParent)){const Y=Dc(F,p,F.origin??R);D?D=[[Math.min(Y[0][0],D[0][0]),Math.min(Y[0][1],D[0][1])],[Math.max(Y[1][0],D[1][0]),Math.max(Y[1][1],D[1][1])]]:D=Y}u?.(C,{...v})}).on("drag",C=>{const{transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:B}=s(),R=Gn(C.sourceEvent,{transform:$,snapGrid:z,snapToGrid:j,containerBounds:b}),T=[];if(!p)return;const{x:A,y:L,width:q,height:F}=v,Y={},Q=p.origin??B,{width:O,height:I,x:H,y:V}=_c(y,a.controlDirection,R,a.boundaries,a.keepAspectRatio,Q,M,D),W=O!==q,X=I!==F,ee=H!==A&&W,se=V!==L&&X;if(!ee&&!se&&!W&&!X)return;if((ee||se||Q[0]===1||Q[1]===1)&&(Y.x=ee?H:v.x,Y.y=se?V:v.y,v.x=Y.x,v.y=Y.y,N.length>0)){const le=H-A,ie=V-L;for(const he of N)he.position={x:he.position.x-le+Q[0]*(O-q),y:he.position.y-ie+Q[1]*(I-F)},T.push(he)}if((W||X)&&(Y.width=W&&(!a.resizeDirection||a.resizeDirection==="horizontal")?O:v.width,Y.height=X&&(!a.resizeDirection||a.resizeDirection==="vertical")?I:v.height,v.width=Y.width,v.height=Y.height),w&&p.expandParent){const le=Q[0]*(Y.width??0);Y.x&&Y.x<le&&(v.x=le,y.x=y.x-(Y.x-le));const ie=Q[1]*(Y.height??0);Y.y&&Y.y<ie&&(v.y=ie,y.y=y.y-(Y.y-ie))}const J=Rc({width:v.width,prevWidth:q,height:v.height,prevHeight:F,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),U={...v,direction:J};S?.(C,U)!==!1&&(P=!0,x?.(C,U),r(Y,T))}).on("end",C=>{P&&(E?.(C,{...v}),i?.({...v}),P=!1)});o.call(_)}function c(){o.on(".drag",null)}return{update:l,destroy:c}}var os={exports:{}},as={};var So;function $c(){if(So)return as;So=1;var e=dl(),n=ul();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,l=e.useMemo,c=e.useDebugValue;return as.useSyncExternalStoreWithSelector=function(d,h,f,m,u){var x=o(null);if(x.current===null){var E={hasValue:!1,value:null};x.current=E}else E=x.current;x=l(function(){function v(w){if(!y){if(y=!0,p=w,w=m(w),u!==void 0&&E.hasValue){var M=E.value;if(u(M,w))return b=M}return b=w}if(M=b,r(p,w))return M;var D=m(w);return u!==void 0&&u(M,D)?(p=w,M):(p=w,b=D)}var y=!1,p,b,N=f===void 0?null:f;return[function(){return v(h())},N===null?void 0:function(){return v(N())}]},[h,f,m,u]);var S=i(d,x[0],x[1]);return a(function(){E.hasValue=!0,E.value=S},[S]),c(S),S},as}var Eo;function Bc(){return Eo||(Eo=1,os.exports=$c()),os.exports}var Oc=Bc();const zc=fl(Oc),Hc={},Mo=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(x=>x(n,u))}},i=()=>n,c={setState:r,getState:i,getInitialState:()=>d,subscribe:h=>(s.add(h),()=>s.delete(h)),destroy:()=>{(Hc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),s.clear()}},d=n=e(r,i,c);return c},qc=e=>e?Mo(e):Mo,{useDebugValue:Vc}=hl,{useSyncExternalStoreWithSelector:Wc}=zc,Fc=e=>e;function li(e,n=Fc,s){const r=Wc(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,s);return Vc(r),r}const Io=(e,n)=>{const s=qc(e),r=(i,o=n)=>li(s,i,o);return Object.assign(r,s),r},Yc=(e,n)=>e?Io(e,n):Io;function Oe(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 Hr=g.createContext(null),Gc=Hr.Provider,ci=Dt.error001();function Me(e,n){const s=g.useContext(Hr);if(s===null)throw new Error(ci);return li(s,e,n)}function Be(){const e=g.useContext(Hr);if(e===null)throw new Error(ci);return g.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const To={display:"none"},Zc={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},di="react-flow__node-desc",ui="react-flow__edge-desc",Xc="react-flow__aria-live",Uc=e=>e.ariaLiveMessage,Kc=e=>e.ariaLabelConfig;function Qc({rfId:e}){const n=Me(Uc);return t.jsx("div",{id:`${Xc}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Zc,children:n})}function Jc({rfId:e,disableKeyboardA11y:n}){const s=Me(Kc);return t.jsxs(t.Fragment,{children:[t.jsx("div",{id:`${di}-${e}`,style:To,children:n?s["node.a11yDescription.default"]:s["node.a11yDescription.keyboardDisabled"]}),t.jsx("div",{id:`${ui}-${e}`,style:To,children:s["edge.a11yDescription.default"]}),!n&&t.jsx(Qc,{rfId:e})]})}const qr=g.forwardRef(({position:e="top-left",children:n,className:s,style:r,...i},o)=>{const a=`${e}`.split("-");return t.jsx("div",{className:Ze(["react-flow__panel",s,...a]),style:r,ref:o,...i,children:n})});qr.displayName="Panel";function ed({proOptions:e,position:n="bottom-right"}){return e?.hideAttribution?null:t.jsx(qr,{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 td=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}},Cr=e=>e.id;function nd(e,n){return Oe(e.selectedNodes.map(Cr),n.selectedNodes.map(Cr))&&Oe(e.selectedEdges.map(Cr),n.selectedEdges.map(Cr))}function rd({onSelectionChange:e}){const n=Be(),{selectedNodes:s,selectedEdges:r}=Me(td,nd);return g.useEffect(()=>{const i={nodes:s,edges:r};e?.(i),n.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[s,r,e]),null}const sd=e=>!!e.onSelectionChangeHandlers;function od({onSelectionChange:e}){const n=Me(sd);return e||n?t.jsx(rd,{onSelectionChange:e}):null}const fi=[0,0],ad={x:0,y:0,zoom:1},id=["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"],Ro=[...id,"rfId"],ld=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}),_o={translateExtent:Kn,nodeOrigin:fi,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function cd(e){const{setNodes:n,setEdges:s,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:a,reset:l,setDefaultNodesAndEdges:c}=Me(ld,Oe),d=Be();g.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{h.current=_o,l()}),[]);const h=g.useRef(_o);return g.useEffect(()=>{for(const f of Ro){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:Zl(m)}):f==="fitView"?d.setState({fitViewQueued:m}):f==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[f]:m})))}h.current=e},Ro.map(f=>e[f])),null}function Ao(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function dd(e){const[n,s]=g.useState(e==="system"?null:e);return g.useEffect(()=>{if(e!=="system"){s(e);return}const r=Ao(),i=()=>s(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),n!==null?n:Ao()?.matches?"dark":"light"}const Lo=typeof document<"u"?document:null;function tr(e=null,n={target:Lo,actInsideInputWithModifier:!0}){const[s,r]=g.useState(!1),i=g.useRef(!1),o=g.useRef(new Set([])),[a,l]=g.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
2
2
  `).replace(`
3
3
 
4
4
  `,`
5
5
  +`).split(`
6
- `)),h=d.reduce((f,m)=>f.concat(...m),[]);return[d,h]}return[[],[]]},[e]);return g.useEffect(()=>{const c=n?.target??Lo,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)&&Fa(u))return!1;const E=Po(u.code,l);if(o.current.add(u[E]),Do(a,o.current,!1)){const S=u.composedPath?.()?.[0]||u.target,v=S?.nodeName==="BUTTON"||S?.nodeName==="A";n.preventDefault!==!1&&(i.current||!v)&&u.preventDefault(),r(!0)}},f=u=>{const x=Po(u.code,l);Do(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(u[x]),u.key==="Meta"&&o.current.clear(),i.current=!1},m=()=>{o.current.clear(),r(!1)};return c?.addEventListener("keydown",h),c?.addEventListener("keyup",f),window.addEventListener("blur",m),window.addEventListener("contextmenu",m),()=>{c?.removeEventListener("keydown",h),c?.removeEventListener("keyup",f),window.removeEventListener("blur",m),window.removeEventListener("contextmenu",m)}}},[e,r]),s}function Do(e,n,s){return e.filter(r=>s||r.length===n.size).some(r=>r.every(i=>n.has(i)))}function Po(e,n){return n.includes(e)?"code":"key"}const ud=()=>{const e=Be();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:l}=e.getState(),c=Cs(n,r,i,o,a,s?.padding??.1);return l?(await l.setViewport(c,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(n,s={})=>{const{transform:r,snapGrid:i,snapToGrid:o,domNode:a}=e.getState();if(!a)return n;const{x:l,y:c}=a.getBoundingClientRect(),d={x:n.x-l,y:n.y-c},h=s.snapGrid??i,f=s.snapToGrid??o;return ir(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=Dr(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 l={...o};for(const c of a)fd(c,l);s.push(l)}return i.length&&i.forEach(o=>{o.index!==void 0?s.splice(o.index,0,{...o.item}):s.push({...o.item})}),s}function fd(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 mi(e,n){return hi(e,n)}function gi(e,n){return hi(e,n)}function dn(e,n){return{id:e,type:"select",selected:n}}function Mn(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(dn(o.id,a)))}return r}function $o({items:e=[],lookup:n}){const s=[],r=new Map(e.map(i=>[i.id,i]));for(const[i,o]of e.entries()){const a=n.get(o.id),l=a?.internals?.userNode??a;l!==void 0&&l!==o&&s.push({id:o.id,item:o,type:"replace"}),l===void 0&&s.push({item:o,type:"add",index:i})}for(const[i]of n)r.get(i)===void 0&&s.push({id:i,type:"remove"});return s}function Bo(e){return{id:e.id,type:"remove"}}const Oo=e=>Bl(e),hd=e=>$a(e);function pi(e){return g.forwardRef(e)}const md=typeof window<"u"?g.useLayoutEffect:g.useEffect;function zo(e){const[n,s]=g.useState(BigInt(0)),[r]=g.useState(()=>gd(()=>s(i=>i+BigInt(1))));return md(()=>{const i=r.get();i.length&&(e(i),r.reset())},[n]),r}function gd(e){let n=[];return{get:()=>n,reset:()=>{n=[]},push:s=>{n.push(s),e()}}}const xi=g.createContext(null);function pd({children:e}){const n=Be(),s=g.useCallback(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:h,onNodesChange:f,nodeLookup:m,fitViewQueued:u,onNodesChangeMiddlewareMap:x}=n.getState();let E=c;for(const v of l)E=typeof v=="function"?v(E):v;let S=$o({items:E,lookup:m});for(const v of x.values())S=v(S);h&&d(E),S.length>0?f?.(S):u&&window.requestAnimationFrame(()=>{const{fitViewQueued:v,nodes:y,setNodes:p}=n.getState();v&&p(y)})},[]),r=zo(s),i=g.useCallback(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:h,onEdgesChange:f,edgeLookup:m}=n.getState();let u=c;for(const x of l)u=typeof x=="function"?x(u):x;h?d(u):f&&f($o({items:u,lookup:m}))},[]),o=zo(i),a=g.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return t.jsx(xi.Provider,{value:a,children:e})}function xd(){const e=g.useContext(xi);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const bd=e=>!!e.panZoom;function _s(){const e=ud(),n=Be(),s=xd(),r=Me(bd),i=g.useMemo(()=>{const o=f=>n.getState().nodeLookup.get(f),a=f=>{s.nodeQueue.push(f)},l=f=>{s.edgeQueue.push(f)},c=f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState(),x=Oo(f)?f:m.get(f.id),E=x.parentId?Va(x.position,x.measured,x.parentId,m,u):x.position,S={...x,position:E,width:x.measured?.width??x.width,height:x.measured?.height??x.height};return Ln(S)},d=(f,m,u={replace:!1})=>{a(x=>x.map(E=>{if(E.id===f){const S=typeof m=="function"?m(E):m;return u.replace&&Oo(S)?S:{...E,...S}}return E}))},h=(f,m,u={replace:!1})=>{l(x=>x.map(E=>{if(E.id===f){const S=typeof m=="function"?m(E):m;return u.replace&&hd(S)?S:{...E,...S}}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:l,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(),[x,E,S]=u;return{nodes:f.map(v=>({...v})),edges:m.map(v=>({...v})),viewport:{x,y:E,zoom:S}}},deleteElements:async({nodes:f=[],edges:m=[]})=>{const{nodes:u,edges:x,onNodesDelete:E,onEdgesDelete:S,triggerNodeChanges:v,triggerEdgeChanges:y,onDelete:p,onBeforeDelete:b}=n.getState(),{nodes:N,edges:w}=await Vl({nodesToRemove:f,edgesToRemove:m,nodes:u,edges:x,onBeforeDelete:b}),M=w.length>0,D=N.length>0;if(M){const P=w.map(Bo);S?.(w),y(P)}if(D){const P=N.map(Bo);E?.(N),v(P)}return(D||M)&&p?.({nodes:N,edges:w}),{deletedNodes:N,deletedEdges:w}},getIntersectingNodes:(f,m=!0,u)=>{const x=ho(f),E=x?f:c(f),S=u!==void 0;return E?(u||n.getState().nodes).filter(v=>{const y=n.getState().nodeLookup.get(v.id);if(y&&!x&&(v.id===f.id||!y.internals.positionAbsolute))return!1;const p=Ln(S?v:y),b=Jn(p,E);return m&&b>0||b>=p.width*p.height||b>=E.width*E.height}):[]},isNodeIntersecting:(f,m,u=!0)=>{const E=ho(f)?f:c(f);if(!E)return!1;const S=Jn(E,m);return u&&S>0||S>=m.width*m.height||S>=E.width*E.height},updateNode:d,updateNodeData:(f,m,u={replace:!1})=>{d(f,x=>{const E=typeof m=="function"?m(x):m;return u.replace?{...x,data:E}:{...x,data:{...x.data,...E}}},u)},updateEdge:h,updateEdgeData:(f,m,u={replace:!1})=>{h(f,x=>{const E=typeof m=="function"?m(x):m;return u.replace?{...x,data:E}:{...x,data:{...x.data,...E}}},u)},getNodesBounds:f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState();return Ol(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??Gl();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 Ho=e=>e.selected,yd=typeof window<"u"?window:void 0;function vd({deleteKeyCode:e,multiSelectionKeyCode:n}){const s=Be(),{deleteElements:r}=_s(),i=tr(e,{actInsideInputWithModifier:!1}),o=tr(n,{target:yd});g.useEffect(()=>{if(i){const{edges:a,nodes:l}=s.getState();r({nodes:l.filter(Ho),edges:a.filter(Ho)}),s.setState({nodesSelectionActive:!1})}},[i]),g.useEffect(()=>{s.setState({multiSelectionActive:o})},[o])}function wd(e){const n=Be();g.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=Ss(e.current);(r.height===0||r.width===0)&&n.getState().onError?.("004",Dt.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 Vr={position:"absolute",width:"100%",height:"100%",top:0,left:0},kd=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function jd({onPaneContextMenu:e,zoomOnScroll:n=!0,zoomOnPinch:s=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:o=un.Free,zoomOnDoubleClick:a=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:h,maxZoom:f,zoomActivationKeyCode:m,preventScrolling:u=!0,children:x,noWheelClassName:E,noPanClassName:S,onViewportChange:v,isControlledViewport:y,paneClickDistance:p,selectionOnDrag:b}){const N=Be(),w=g.useRef(null),{userSelectionActive:M,lib:D,connectionInProgress:P}=Me(kd,Oe),_=tr(m),C=g.useRef();wd(w);const $=g.useCallback(z=>{v?.({x:z[0],y:z[1],zoom:z[2]}),y||N.setState({transform:z})},[v,y]);return g.useEffect(()=>{if(w.current){C.current=Tc({domNode:w.current,minZoom:h,maxZoom:f,translateExtent:d,viewport:c,onDraggingChange:R=>N.setState(T=>T.paneDragging===R?T:{paneDragging:R}),onPanZoomStart:(R,T)=>{const{onViewportChangeStart:A,onMoveStart:L}=N.getState();L?.(R,T),A?.(T)},onPanZoom:(R,T)=>{const{onViewportChange:A,onMove:L}=N.getState();L?.(R,T),A?.(T)},onPanZoomEnd:(R,T)=>{const{onViewportChangeEnd:A,onMoveEnd:L}=N.getState();L?.(R,T),A?.(T)}});const{x:z,y:j,zoom:B}=C.current.getViewport();return N.setState({panZoom:C.current,transform:[z,j,B],domNode:w.current.closest(".react-flow")}),()=>{C.current?.destroy()}}},[]),g.useEffect(()=>{C.current?.update({onPaneContextMenu:e,zoomOnScroll:n,zoomOnPinch:s,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:l,zoomActivationKeyPressed:_,preventScrolling:u,noPanClassName:S,userSelectionActive:M,noWheelClassName:E,lib:D,onTransformChange:$,connectionInProgress:P,selectionOnDrag:b,paneClickDistance:p})},[e,n,s,r,i,o,a,l,_,u,S,M,E,D,$,P,b,p]),t.jsx("div",{className:"react-flow__renderer",ref:w,style:Vr,children:x})}const Nd=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function Cd(){const{userSelectionActive:e,userSelectionRect:n}=Me(Nd,Oe);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 is=(e,n)=>s=>{s.target===n.current&&e?.(s)},Sd=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function Ed({isSelecting:e,selectionKeyPressed:n,selectionMode:s=Qn.Full,panOnDrag:r,paneClickDistance:i,selectionOnDrag:o,onSelectionStart:a,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:h,onPaneMouseEnter:f,onPaneMouseMove:m,onPaneMouseLeave:u,children:x}){const E=Be(),{userSelectionActive:S,elementsSelectable:v,dragging:y,connectionInProgress:p}=Me(Sd,Oe),b=v&&(e||S),N=g.useRef(null),w=g.useRef(),M=g.useRef(new Set),D=g.useRef(new Set),P=g.useRef(!1),_=A=>{if(P.current||p){P.current=!1;return}c?.(A),E.getState().resetSelectedElements(),E.setState({nodesSelectionActive:!1})},C=A=>{if(Array.isArray(r)&&r?.includes(2)){A.preventDefault();return}d?.(A)},$=h?A=>h(A):void 0,z=A=>{P.current&&(A.stopPropagation(),P.current=!1)},j=A=>{const{domNode:L}=E.getState();if(w.current=L?.getBoundingClientRect(),!w.current)return;const q=A.target===N.current;if(!q&&!!A.target.closest(".nokey")||!e||!(o&&q||n)||A.button!==0||!A.isPrimary)return;A.target?.setPointerCapture?.(A.pointerId),P.current=!1;const{x:Q,y:O}=Ct(A.nativeEvent,w.current);E.setState({userSelectionRect:{width:0,height:0,startX:Q,startY:O,x:Q,y:O}}),q||(A.stopPropagation(),A.preventDefault())},B=A=>{const{userSelectionRect:L,transform:q,nodeLookup:F,edgeLookup:Y,connectionLookup:Q,triggerNodeChanges:O,triggerEdgeChanges:I,defaultEdgeOptions:H,resetSelectedElements:V}=E.getState();if(!w.current||!L)return;const{x:W,y:X}=Ct(A.nativeEvent,w.current),{startX:ee,startY:se}=L;if(!P.current){const ie=n?0:i;if(Math.hypot(W-ee,X-se)<=ie)return;V(),a?.(A)}P.current=!0;const J={startX:ee,startY:se,x:W<ee?W:ee,y:X<se?X:se,width:Math.abs(W-ee),height:Math.abs(X-se)},U=M.current,oe=D.current;M.current=new Set(Ns(F,J,q,s===Qn.Partial,!0).map(ie=>ie.id)),D.current=new Set;const le=H?.selectable??!0;for(const ie of M.current){const he=Q.get(ie);if(he)for(const{edgeId:de}of he.values()){const Z=Y.get(de);Z&&(Z.selectable??le)&&D.current.add(de)}}if(!mo(U,M.current)){const ie=Mn(F,M.current,!0);O(ie)}if(!mo(oe,D.current)){const ie=Mn(Y,D.current);I(ie)}E.setState({userSelectionRect:J,userSelectionActive:!0,nodesSelectionActive:!1})},R=A=>{A.button===0&&(A.target?.releasePointerCapture?.(A.pointerId),!S&&A.target===N.current&&E.getState().userSelectionRect&&_?.(A),E.setState({userSelectionActive:!1,userSelectionRect:null}),P.current&&(l?.(A),E.setState({nodesSelectionActive:M.current.size>0})))},T=r===!0||Array.isArray(r)&&r.includes(0);return t.jsxs("div",{className:Ze(["react-flow__pane",{draggable:T,dragging:y,selection:e}]),onClick:b?void 0:is(_,N),onContextMenu:is(C,N),onWheel:is($,N),onPointerEnter:b?void 0:f,onPointerMove:b?B:m,onPointerUp:b?R:void 0,onPointerDownCapture:b?j:void 0,onClickCapture:b?z:void 0,onPointerLeave:u,ref:N,style:Vr,children:[x,t.jsx(Cd,{})]})}function bs({id:e,store:n,unselect:s=!1,nodeRef:r}){const{addSelectedNodes:i,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:l,onError:c}=n.getState(),d=l.get(e);if(!d){c?.("012",Dt.error012(e));return}n.setState({nodesSelectionActive:!1}),d.selected?(s||d.selected&&a)&&(o({nodes:[d],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function bi({nodeRef:e,disabled:n=!1,noDragClassName:s,handleSelector:r,nodeId:i,isSelectable:o,nodeClickDistance:a}){const l=Be(),[c,d]=g.useState(!1),h=g.useRef();return g.useEffect(()=>{h.current=pc({getStoreItems:()=>l.getState(),onNodeMouseDown:f=>{bs({id:f,store:l,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]),c}const Md=e=>n=>n.selected&&(n.draggable||e&&typeof n.draggable>"u");function yi(){const e=Be();return g.useCallback(s=>{const{nodeExtent:r,snapToGrid:i,snapGrid:o,nodesDraggable:a,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:h}=e.getState(),f=new Map,m=Md(a),u=i?o[0]:5,x=i?o[1]:5,E=s.direction.x*u*s.factor,S=s.direction.y*x*s.factor;for(const[,v]of d){if(!m(v))continue;let y={x:v.internals.positionAbsolute.x+E,y:v.internals.positionAbsolute.y+S};i&&(y=ar(y,o));const{position:p,positionAbsolute:b}=Ba({nodeId:v.id,nextPosition:y,nodeLookup:d,nodeExtent:r,nodeOrigin:h,onError:l});v.position=p,v.internals.positionAbsolute=b,f.set(v.id,v)}c(f)},[])}const As=g.createContext(null),Id=As.Provider;As.Consumer;const vi=()=>g.useContext(As),Td=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Rd=(e,n,s)=>r=>{const{connectionClickStartHandle:i,connectionMode:o,connection:a}=r,{fromHandle:l,toHandle:c,isValid:d}=a,h=c?.nodeId===e&&c?.id===n&&c?.type===s;return{connectingFrom:l?.nodeId===e&&l?.id===n&&l?.type===s,connectingTo:h,clickConnecting:i?.nodeId===e&&i?.id===n&&i?.type===s,isPossibleEndHandle:o===Rn.Strict?l?.type!==s:e!==l?.nodeId||n!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!i,valid:h&&d}};function _d({type:e="source",position:n=ye.Top,isValidConnection:s,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,id:a,onConnect:l,children:c,className:d,onMouseDown:h,onTouchStart:f,...m},u){const x=a||null,E=e==="target",S=Be(),v=vi(),{connectOnClick:y,noPanClassName:p,rfId:b}=Me(Td,Oe),{connectingFrom:N,connectingTo:w,clickConnecting:M,isPossibleEndHandle:D,connectionInProcess:P,clickConnectionInProcess:_,valid:C}=Me(Rd(v,x,e),Oe);v||S.getState().onError?.("010",Dt.error010());const $=B=>{const{defaultEdgeOptions:R,onConnect:T,hasDefaultEdges:A}=S.getState(),L={...R,...B};if(A){const{edges:q,setEdges:F}=S.getState();F(ec(L,q))}T?.(L),l?.(L)},z=B=>{if(!v)return;const R=Ya(B.nativeEvent);if(i&&(R&&B.button===0||!R)){const T=S.getState();xs.onPointerDown(B.nativeEvent,{handleDomNode:B.currentTarget,autoPanOnConnect:T.autoPanOnConnect,connectionMode:T.connectionMode,connectionRadius:T.connectionRadius,domNode:T.domNode,nodeLookup:T.nodeLookup,lib:T.lib,isTarget:E,handleId:x,nodeId:v,flowId:T.rfId,panBy:T.panBy,cancelConnection:T.cancelConnection,onConnectStart:T.onConnectStart,onConnectEnd:(...A)=>S.getState().onConnectEnd?.(...A),updateConnection:T.updateConnection,onConnect:$,isValidConnection:s||((...A)=>S.getState().isValidConnection?.(...A)??!0),getTransform:()=>S.getState().transform,getFromHandle:()=>S.getState().connection.fromHandle,autoPanSpeed:T.autoPanSpeed,dragThreshold:T.connectionDragThreshold})}R?h?.(B):f?.(B)},j=B=>{const{onClickConnectStart:R,onClickConnectEnd:T,connectionClickStartHandle:A,connectionMode:L,isValidConnection:q,lib:F,rfId:Y,nodeLookup:Q,connection:O}=S.getState();if(!v||!A&&!i)return;if(!A){R?.(B.nativeEvent,{nodeId:v,handleId:x,handleType:e}),S.setState({connectionClickStartHandle:{nodeId:v,type:e,id:x}});return}const I=Wa(B.target),H=s||q,{connection:V,isValid:W}=xs.isValid(B.nativeEvent,{handle:{nodeId:v,id:x,type:e},connectionMode:L,fromNodeId:A.nodeId,fromHandleId:A.id||null,fromType:A.type,isValidConnection:H,flowId:Y,doc:I,lib:F,nodeLookup:Q});W&&V&&$(V);const X=structuredClone(O);delete X.inProgress,X.toPosition=X.toHandle?X.toHandle.position:null,T?.(B,X),S.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":x,"data-nodeid":v,"data-handlepos":n,"data-id":`${b}-${v}-${x}-${e}`,className:Ze(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",p,d,{source:!E,target:E,connectable:r,connectablestart:i,connectableend:o,clickconnecting:M,connectingfrom:N,connectingto:w,valid:C,connectionindicator:r&&(!P||D)&&(P||_?o:i)}]),onMouseDown:z,onTouchStart:z,onClick:y?j:void 0,ref:u,...m,children:c})}const Jt=g.memo(pi(_d));function Ad({data:e,isConnectable:n,sourcePosition:s=ye.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(Jt,{type:"source",position:s,isConnectable:n})]})}function Ld({data:e,isConnectable:n,targetPosition:s=ye.Top,sourcePosition:r=ye.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(Jt,{type:"target",position:s,isConnectable:n}),e?.label,t.jsx(Jt,{type:"source",position:r,isConnectable:n})]})}function Dd(){return null}function Pd({data:e,isConnectable:n,targetPosition:s=ye.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(Jt,{type:"target",position:s,isConnectable:n}),e?.label]})}const Pr={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},qo={input:Ad,default:Ld,output:Pd,group:Dd};function $d(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 Bd=e=>{const{width:n,height:s,x:r,y:i}=or(e.nodeLookup,{filter:o=>!!o.selected});return{width:Nt(n)?n:null,height:Nt(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 Od({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:s}){const r=Be(),{width:i,height:o,transformString:a,userSelectionActive:l}=Me(Bd,Oe),c=yi(),d=g.useRef(null);g.useEffect(()=>{s||d.current?.focus({preventScroll:!0})},[s]);const h=!l&&i!==null&&o!==null;if(bi({nodeRef:d,disabled:!h}),!h)return null;const f=e?u=>{const x=r.getState().nodes.filter(E=>E.selected);e(u,x)}:void 0,m=u=>{Object.prototype.hasOwnProperty.call(Pr,u.key)&&(u.preventDefault(),c({direction:Pr[u.key],factor:u.shiftKey?4:1}))};return t.jsx("div",{className:Ze(["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 Vo=typeof window<"u"?window:void 0,zd=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function wi({children:e,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:h,selectionMode:f,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:x,panActivationKeyCode:E,zoomActivationKeyCode:S,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:p,panOnScroll:b,panOnScrollSpeed:N,panOnScrollMode:w,zoomOnDoubleClick:M,panOnDrag:D,defaultViewport:P,translateExtent:_,minZoom:C,maxZoom:$,preventScrolling:z,onSelectionContextMenu:j,noWheelClassName:B,noPanClassName:R,disableKeyboardA11y:T,onViewportChange:A,isControlledViewport:L}){const{nodesSelectionActive:q,userSelectionActive:F}=Me(zd,Oe),Y=tr(d,{target:Vo}),Q=tr(E,{target:Vo}),O=Q||D,I=Q||b,H=h&&O!==!0,V=Y||F||H;return vd({deleteKeyCode:c,multiSelectionKeyCode:x}),t.jsx(jd,{onPaneContextMenu:o,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:p,panOnScroll:I,panOnScrollSpeed:N,panOnScrollMode:w,zoomOnDoubleClick:M,panOnDrag:!Y&&O,defaultViewport:P,translateExtent:_,minZoom:C,maxZoom:$,zoomActivationKeyCode:S,preventScrolling:z,noWheelClassName:B,noPanClassName:R,onViewportChange:A,isControlledViewport:L,paneClickDistance:l,selectionOnDrag:H,children:t.jsxs(Ed,{onSelectionStart:m,onSelectionEnd:u,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:O,isSelecting:!!V,selectionMode:f,selectionKeyPressed:Y,paneClickDistance:l,selectionOnDrag:H,children:[e,q&&t.jsx(Od,{onSelectionContextMenu:j,noPanClassName:R,disableKeyboardA11y:T})]})})}wi.displayName="FlowRenderer";const Hd=g.memo(wi),qd=e=>n=>e?Ns(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 Vd(e){return Me(g.useCallback(qd(e),[e]),Oe)}const Wd=e=>e.updateNodeInternals;function Fd(){const e=Me(Wd),[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 Yd({node:e,nodeType:n,hasDimensions:s,resizeObserver:r}){const i=Be(),o=g.useRef(null),a=g.useRef(null),l=g.useRef(e.sourcePosition),c=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=l.current!==e.sourcePosition,u=c.current!==e.targetPosition;(f||m||u)&&(d.current=n,l.current=e.sourcePosition,c.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:o.current,force:!0}]])))}},[e.id,n,e.sourcePosition,e.targetPosition]),o}function Gd({id:e,onClick:n,onMouseEnter:s,onMouseMove:r,onMouseLeave:i,onContextMenu:o,onDoubleClick:a,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:h,resizeObserver:f,noDragClassName:m,noPanClassName:u,disableKeyboardA11y:x,rfId:E,nodeTypes:S,nodeClickDistance:v,onError:y}){const{node:p,internals:b,isParent:N}=Me(W=>{const X=W.nodeLookup.get(e),ee=W.parentLookup.has(e);return{node:X,internals:X.internals,isParent:ee}},Oe);let w=p.type||"default",M=S?.[w]||qo[w];M===void 0&&(y?.("003",Dt.error003(w)),w="default",M=S?.default||qo.default);const D=!!(p.draggable||l&&typeof p.draggable>"u"),P=!!(p.selectable||c&&typeof p.selectable>"u"),_=!!(p.connectable||d&&typeof p.connectable>"u"),C=!!(p.focusable||h&&typeof p.focusable>"u"),$=Be(),z=qa(p),j=Yd({node:p,nodeType:w,hasDimensions:z,resizeObserver:f}),B=bi({nodeRef:j,disabled:p.hidden||!D,noDragClassName:m,handleSelector:p.dragHandle,nodeId:e,isSelectable:P,nodeClickDistance:v}),R=yi();if(p.hidden)return null;const T=Ft(p),A=$d(p),L=P||D||n||s||r||i,q=s?W=>s(W,{...b.userNode}):void 0,F=r?W=>r(W,{...b.userNode}):void 0,Y=i?W=>i(W,{...b.userNode}):void 0,Q=o?W=>o(W,{...b.userNode}):void 0,O=a?W=>a(W,{...b.userNode}):void 0,I=W=>{const{selectNodesOnDrag:X,nodeDragThreshold:ee}=$.getState();P&&(!X||!D||ee>0)&&bs({id:e,store:$,nodeRef:j}),n&&n(W,{...b.userNode})},H=W=>{if(!(Fa(W.nativeEvent)||x)){if(Aa.includes(W.key)&&P){const X=W.key==="Escape";bs({id:e,store:$,unselect:X,nodeRef:j})}else if(D&&p.selected&&Object.prototype.hasOwnProperty.call(Pr,W.key)){W.preventDefault();const{ariaLabelConfig:X}=$.getState();$.setState({ariaLiveMessage:X["node.a11yDescription.ariaLiveMessage"]({direction:W.key.replace("Arrow","").toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),R({direction:Pr[W.key],factor:W.shiftKey?4:1})}}},V=()=>{if(x||!j.current?.matches(":focus-visible"))return;const{transform:W,width:X,height:ee,autoPanOnNodeFocus:se,setCenter:J}=$.getState();if(!se)return;Ns(new Map([[e,p]]),{x:0,y:0,width:X,height:ee},W,!0).length>0||J(p.position.x+T.width/2,p.position.y+T.height/2,{zoom:W[2]})};return t.jsx("div",{className:Ze(["react-flow__node",`react-flow__node-${w}`,{[u]:D},p.className,{selected:p.selected,selectable:P,parent:N,draggable:D,dragging:B}]),ref:j,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:L?"all":"none",visibility:z?"visible":"hidden",...p.style,...A},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:q,onMouseMove:F,onMouseLeave:Y,onContextMenu:Q,onClick:I,onDoubleClick:O,onKeyDown:C?H:void 0,tabIndex:C?0:void 0,onFocus:C?V:void 0,role:p.ariaRole??(C?"group":void 0),"aria-roledescription":"node","aria-describedby":x?void 0:`${di}-${E}`,"aria-label":p.ariaLabel,...p.domAttributes,children:t.jsx(Id,{value:e,children:t.jsx(M,{id:e,data:p.data,type:w,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:p.selected??!1,selectable:P,draggable:D,deletable:p.deletable??!0,isConnectable:_,sourcePosition:p.sourcePosition,targetPosition:p.targetPosition,dragging:B,dragHandle:p.dragHandle,zIndex:b.z,parentId:p.parentId,...T})})})}var Zd=g.memo(Gd);const Xd=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function ki(e){const{nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,onError:o}=Me(Xd,Oe),a=Vd(e.onlyRenderVisibleElements),l=Fd();return t.jsx("div",{className:"react-flow__nodes",style:Vr,children:a.map(c=>t.jsx(Zd,{id:c,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:l,nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:o},c))})}ki.displayName="NodeRenderer";const Ud=g.memo(ki);function Kd(e){return Me(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&&Kl({sourceNode:o,targetNode:a,width:s.width,height:s.height,transform:s.transform})&&r.push(i.id)}return r},[e]),Oe)}const Qd=({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"})},Jd=({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"})},Wo={[_n.Arrow]:Qd,[_n.ArrowClosed]:Jd};function eu(e){const n=Be();return g.useMemo(()=>Object.prototype.hasOwnProperty.call(Wo,e)?Wo[e]:(n.getState().onError?.("009",Dt.error009(e)),null),[e])}const tu=({id:e,type:n,color:s,width:r=12.5,height:i=12.5,markerUnits:o="strokeWidth",strokeWidth:a,orient:l="auto-start-reverse"})=>{const c=eu(n);return c?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:l,refX:"0",refY:"0",children:t.jsx(c,{color:s,strokeWidth:a})}):null},ji=({defaultColor:e,rfId:n})=>{const s=Me(o=>o.edges),r=Me(o=>o.defaultEdgeOptions),i=g.useMemo(()=>oc(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(tu,{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};ji.displayName="MarkerDefinitions";var nu=g.memo(ji);function Ni({x:e,y:n,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:l=2,children:c,className:d,...h}){const[f,m]=g.useState({x:1,y:0,width:0,height:0}),u=Ze(["react-flow__edge-textwrapper",d]),x=g.useRef(null);return g.useEffect(()=>{if(x.current){const E=x.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:l,ry:l}),t.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:x,style:r,children:s}),c]}):null}Ni.displayName="EdgeText";const ru=g.memo(Ni);function Wr({path:e,labelX:n,labelY:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...h}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...h,d:e,fill:"none",className:Ze(["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&&Nt(n)&&Nt(s)?t.jsx(ru,{x:n,y:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Fo({pos:e,x1:n,y1:s,x2:r,y2:i}){return e===ye.Left||e===ye.Right?[.5*(n+r),s]:[n,.5*(s+i)]}function Ci({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top}){const[a,l]=Fo({pos:s,x1:e,y1:n,x2:r,y2:i}),[c,d]=Fo({pos:o,x1:r,y1:i,x2:e,y2:n}),[h,f,m,u]=Ga({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:a,sourceControlY:l,targetControlX:c,targetControlY:d});return[`M${e},${n} C${a},${l} ${c},${d} ${r},${i}`,h,f,m,u]}function Si(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a,targetPosition:l,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:S,interactionWidth:v})=>{const[y,p,b]=Ci({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:l}),N=e.isInternal?void 0:n;return t.jsx(Wr,{id:N,path:y,labelX:p,labelY:b,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:S,interactionWidth:v})})}const su=Si({isInternal:!1}),Ei=Si({isInternal:!0});su.displayName="SimpleBezierEdge";Ei.displayName="SimpleBezierEdgeInternal";function Mi(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,sourcePosition:u=ye.Bottom,targetPosition:x=ye.Top,markerEnd:E,markerStart:S,pathOptions:v,interactionWidth:y})=>{const[p,b,N]=ms({sourceX:s,sourceY:r,sourcePosition:u,targetX:i,targetY:o,targetPosition:x,borderRadius:v?.borderRadius,offset:v?.offset,stepPosition:v?.stepPosition}),w=e.isInternal?void 0:n;return t.jsx(Wr,{id:w,path:p,labelX:b,labelY:N,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:E,markerStart:S,interactionWidth:y})})}const Ii=Mi({isInternal:!1}),Ti=Mi({isInternal:!0});Ii.displayName="SmoothStepEdge";Ti.displayName="SmoothStepEdgeInternal";function Ri(e){return g.memo(({id:n,...s})=>{const r=e.isInternal?void 0:n;return t.jsx(Ii,{...s,id:r,pathOptions:g.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const ou=Ri({isInternal:!1}),_i=Ri({isInternal:!0});ou.displayName="StepEdge";_i.displayName="StepEdgeInternal";function Ai(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:x,interactionWidth:E})=>{const[S,v,y]=Ua({sourceX:s,sourceY:r,targetX:i,targetY:o}),p=e.isInternal?void 0:n;return t.jsx(Wr,{id:p,path:S,labelX:v,labelY:y,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:x,interactionWidth:E})})}const au=Ai({isInternal:!1}),Li=Ai({isInternal:!0});au.displayName="StraightEdge";Li.displayName="StraightEdgeInternal";function Di(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a=ye.Bottom,targetPosition:l=ye.Top,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:S,pathOptions:v,interactionWidth:y})=>{const[p,b,N]=Za({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:l,curvature:v?.curvature}),w=e.isInternal?void 0:n;return t.jsx(Wr,{id:w,path:p,labelX:b,labelY:N,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:S,interactionWidth:y})})}const iu=Di({isInternal:!1}),Pi=Di({isInternal:!0});iu.displayName="BezierEdge";Pi.displayName="BezierEdgeInternal";const Yo={default:Pi,straight:Li,step:_i,smoothstep:Ti,simplebezier:Ei},Go={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},lu=(e,n,s)=>s===ye.Left?e-n:s===ye.Right?e+n:e,cu=(e,n,s)=>s===ye.Top?e-n:s===ye.Bottom?e+n:e,Zo="react-flow__edgeupdater";function Xo({position:e,centerX:n,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:o,onMouseOut:a,type:l}){return t.jsx("circle",{onMouseDown:i,onMouseEnter:o,onMouseOut:a,className:Ze([Zo,`${Zo}-${l}`]),cx:lu(n,r,e),cy:cu(s,r,e),r,stroke:"transparent",fill:"transparent"})}function du({isReconnectable:e,reconnectRadius:n,edge:s,sourceX:r,sourceY:i,targetX:o,targetY:a,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:h,onReconnectEnd:f,setReconnecting:m,setUpdateHover:u}){const x=Be(),E=(b,N)=>{if(b.button!==0)return;const{autoPanOnConnect:w,domNode:M,connectionMode:D,connectionRadius:P,lib:_,onConnectStart:C,cancelConnection:$,nodeLookup:z,rfId:j,panBy:B,updateConnection:R}=x.getState(),T=N.type==="target",A=(F,Y)=>{m(!1),f?.(F,s,N.type,Y)},L=F=>d?.(s,F),q=(F,Y)=>{m(!0),h?.(b,s,N.type),C?.(F,Y)};xs.onPointerDown(b.nativeEvent,{autoPanOnConnect:w,connectionMode:D,connectionRadius:P,domNode:M,handleId:N.id,nodeId:N.nodeId,nodeLookup:z,isTarget:T,edgeUpdaterType:N.type,lib:_,flowId:j,cancelConnection:$,panBy:B,isValidConnection:(...F)=>x.getState().isValidConnection?.(...F)??!0,onConnect:L,onConnectStart:q,onConnectEnd:(...F)=>x.getState().onConnectEnd?.(...F),onReconnectEnd:A,updateConnection:R,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,dragThreshold:x.getState().connectionDragThreshold,handleDomNode:b.currentTarget})},S=b=>E(b,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),v=b=>E(b,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),y=()=>u(!0),p=()=>u(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(Xo,{position:l,centerX:r,centerY:i,radius:n,onMouseDown:S,onMouseEnter:y,onMouseOut:p,type:"source"}),(e===!0||e==="target")&&t.jsx(Xo,{position:c,centerX:o,centerY:a,radius:n,onMouseDown:v,onMouseEnter:y,onMouseOut:p,type:"target"})]})}function uu({id:e,edgesFocusable:n,edgesReconnectable:s,elementsSelectable:r,onClick:i,onDoubleClick:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,rfId:x,edgeTypes:E,noPanClassName:S,onError:v,disableKeyboardA11y:y}){let p=Me(J=>J.edgeLookup.get(e));const b=Me(J=>J.defaultEdgeOptions);p=b?{...b,...p}:p;let N=p.type||"default",w=E?.[N]||Yo[N];w===void 0&&(v?.("011",Dt.error011(N)),N="default",w=E?.default||Yo.default);const M=!!(p.focusable||n&&typeof p.focusable>"u"),D=typeof f<"u"&&(p.reconnectable||s&&typeof p.reconnectable>"u"),P=!!(p.selectable||r&&typeof p.selectable>"u"),_=g.useRef(null),[C,$]=g.useState(!1),[z,j]=g.useState(!1),B=Be(),{zIndex:R,sourceX:T,sourceY:A,targetX:L,targetY:q,sourcePosition:F,targetPosition:Y}=Me(g.useCallback(J=>{const U=J.nodeLookup.get(p.source),oe=J.nodeLookup.get(p.target);if(!U||!oe)return{zIndex:p.zIndex,...Go};const le=sc({id:e,sourceNode:U,targetNode:oe,sourceHandle:p.sourceHandle||null,targetHandle:p.targetHandle||null,connectionMode:J.connectionMode,onError:v});return{zIndex:Ul({selected:p.selected,zIndex:p.zIndex,sourceNode:U,targetNode:oe,elevateOnSelect:J.elevateEdgesOnSelect,zIndexMode:J.zIndexMode}),...le||Go}},[p.source,p.target,p.sourceHandle,p.targetHandle,p.selected,p.zIndex]),Oe),Q=g.useMemo(()=>p.markerStart?`url('#${gs(p.markerStart,x)}')`:void 0,[p.markerStart,x]),O=g.useMemo(()=>p.markerEnd?`url('#${gs(p.markerEnd,x)}')`:void 0,[p.markerEnd,x]);if(p.hidden||T===null||A===null||L===null||q===null)return null;const I=J=>{const{addSelectedEdges:U,unselectNodesAndEdges:oe,multiSelectionActive:le}=B.getState();P&&(B.setState({nodesSelectionActive:!1}),p.selected&&le?(oe({nodes:[],edges:[p]}),_.current?.blur()):U([e])),i&&i(J,p)},H=o?J=>{o(J,{...p})}:void 0,V=a?J=>{a(J,{...p})}:void 0,W=l?J=>{l(J,{...p})}:void 0,X=c?J=>{c(J,{...p})}:void 0,ee=d?J=>{d(J,{...p})}:void 0,se=J=>{if(!y&&Aa.includes(J.key)&&P){const{unselectNodesAndEdges:U,addSelectedEdges:oe}=B.getState();J.key==="Escape"?(_.current?.blur(),U({edges:[p]})):oe([e])}};return t.jsx("svg",{style:{zIndex:R},children:t.jsxs("g",{className:Ze(["react-flow__edge",`react-flow__edge-${N}`,p.className,S,{selected:p.selected,animated:p.animated,inactive:!P&&!i,updating:C,selectable:P}]),onClick:I,onDoubleClick:H,onContextMenu:V,onMouseEnter:W,onMouseMove:X,onMouseLeave:ee,onKeyDown:M?se:void 0,tabIndex:M?0:void 0,role:p.ariaRole??(M?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":p.ariaLabel===null?void 0:p.ariaLabel||`Edge from ${p.source} to ${p.target}`,"aria-describedby":M?`${ui}-${x}`:void 0,ref:_,...p.domAttributes,children:[!z&&t.jsx(w,{id:e,source:p.source,target:p.target,type:p.type,selected:p.selected,animated:p.animated,selectable:P,deletable:p.deletable??!0,label:p.label,labelStyle:p.labelStyle,labelShowBg:p.labelShowBg,labelBgStyle:p.labelBgStyle,labelBgPadding:p.labelBgPadding,labelBgBorderRadius:p.labelBgBorderRadius,sourceX:T,sourceY:A,targetX:L,targetY:q,sourcePosition:F,targetPosition:Y,data:p.data,style:p.style,sourceHandleId:p.sourceHandle,targetHandleId:p.targetHandle,markerStart:Q,markerEnd:O,pathOptions:"pathOptions"in p?p.pathOptions:void 0,interactionWidth:p.interactionWidth}),D&&t.jsx(du,{edge:p,isReconnectable:D,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,sourceX:T,sourceY:A,targetX:L,targetY:q,sourcePosition:F,targetPosition:Y,setUpdateHover:$,setReconnecting:j})]})})}var fu=g.memo(uu);const hu=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function $i({defaultMarkerColor:e,onlyRenderVisibleElements:n,rfId:s,edgeTypes:r,noPanClassName:i,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:h,reconnectRadius:f,onEdgeDoubleClick:m,onReconnectStart:u,onReconnectEnd:x,disableKeyboardA11y:E}){const{edgesFocusable:S,edgesReconnectable:v,elementsSelectable:y,onError:p}=Me(hu,Oe),b=Kd(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(nu,{defaultColor:e,rfId:s}),b.map(N=>t.jsx(fu,{id:N,edgesFocusable:S,edgesReconnectable:v,elementsSelectable:y,noPanClassName:i,onReconnect:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:h,reconnectRadius:f,onDoubleClick:m,onReconnectStart:u,onReconnectEnd:x,rfId:s,onError:p,edgeTypes:r,disableKeyboardA11y:E},N))]})}$i.displayName="EdgeRenderer";const mu=g.memo($i),gu=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function pu({children:e}){const n=Me(gu);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function xu(e){const n=_s(),s=g.useRef(!1);g.useEffect(()=>{!s.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),s.current=!0)},[e,n.viewportInitialized])}const bu=e=>e.panZoom?.syncViewport;function yu(e){const n=Me(bu),s=Be();return g.useEffect(()=>{e&&(n?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,n]),null}function vu(e){return e.connection.inProgress?{...e.connection,to:ir(e.connection.to,e.transform)}:{...e.connection}}function wu(e){return vu}function ku(e){const n=wu();return Me(n,Oe)}const ju=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function Nu({containerStyle:e,style:n,type:s,component:r}){const{nodesConnectable:i,width:o,height:a,isValid:l,inProgress:c}=Me(ju,Oe);return!(o&&i&&c)?null:t.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:Ze(["react-flow__connection",Pa(l)]),children:t.jsx(Bi,{style:n,type:s,CustomComponent:r,isValid:l})})})}const Bi=({style:e,type:n=Kt.Bezier,CustomComponent:s,isValid:r})=>{const{inProgress:i,from:o,fromNode:a,fromHandle:l,fromPosition:c,to:d,toNode:h,toHandle:f,toPosition:m,pointer:u}=ku();if(!i)return;if(s)return t.jsx(s,{connectionLineType:n,connectionLineStyle:e,fromNode:a,fromHandle:l,fromX:o.x,fromY:o.y,toX:d.x,toY:d.y,fromPosition:c,toPosition:m,connectionStatus:Pa(r),toNode:h,toHandle:f,pointer:u});let x="";const E={sourceX:o.x,sourceY:o.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:m};switch(n){case Kt.Bezier:[x]=Za(E);break;case Kt.SimpleBezier:[x]=Ci(E);break;case Kt.Step:[x]=ms({...E,borderRadius:0});break;case Kt.SmoothStep:[x]=ms(E);break;default:[x]=Ua(E)}return t.jsx("path",{d:x,fill:"none",className:"react-flow__connection-path",style:e})};Bi.displayName="ConnectionLine";const Cu={};function Uo(e=Cu){g.useRef(e),Be(),g.useEffect(()=>{},[e])}function Su(){Be(),g.useRef(!1),g.useEffect(()=>{},[])}function Oi({nodeTypes:e,edgeTypes:n,onInit:s,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,onSelectionContextMenu:f,onSelectionStart:m,onSelectionEnd:u,connectionLineType:x,connectionLineStyle:E,connectionLineComponent:S,connectionLineContainerStyle:v,selectionKeyCode:y,selectionOnDrag:p,selectionMode:b,multiSelectionKeyCode:N,panActivationKeyCode:w,zoomActivationKeyCode:M,deleteKeyCode:D,onlyRenderVisibleElements:P,elementsSelectable:_,defaultViewport:C,translateExtent:$,minZoom:z,maxZoom:j,preventScrolling:B,defaultMarkerColor:R,zoomOnScroll:T,zoomOnPinch:A,panOnScroll:L,panOnScrollSpeed:q,panOnScrollMode:F,zoomOnDoubleClick:Y,panOnDrag:Q,onPaneClick:O,onPaneMouseEnter:I,onPaneMouseMove:H,onPaneMouseLeave:V,onPaneScroll:W,onPaneContextMenu:X,paneClickDistance:ee,nodeClickDistance:se,onEdgeContextMenu:J,onEdgeMouseEnter:U,onEdgeMouseMove:oe,onEdgeMouseLeave:le,reconnectRadius:ie,onReconnect:he,onReconnectStart:de,onReconnectEnd:Z,noDragClassName:ae,noWheelClassName:me,noPanClassName:ve,disableKeyboardA11y:ce,nodeExtent:te,rfId:pe,viewport:Re,onViewportChange:be}){return Uo(e),Uo(n),Su(),xu(s),yu(Re),t.jsx(Hd,{onPaneClick:O,onPaneMouseEnter:I,onPaneMouseMove:H,onPaneMouseLeave:V,onPaneContextMenu:X,onPaneScroll:W,paneClickDistance:ee,deleteKeyCode:D,selectionKeyCode:y,selectionOnDrag:p,selectionMode:b,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:N,panActivationKeyCode:w,zoomActivationKeyCode:M,elementsSelectable:_,zoomOnScroll:T,zoomOnPinch:A,zoomOnDoubleClick:Y,panOnScroll:L,panOnScrollSpeed:q,panOnScrollMode:F,panOnDrag:Q,defaultViewport:C,translateExtent:$,minZoom:z,maxZoom:j,onSelectionContextMenu:f,preventScrolling:B,noDragClassName:ae,noWheelClassName:me,noPanClassName:ve,disableKeyboardA11y:ce,onViewportChange:be,isControlledViewport:!!Re,children:t.jsxs(pu,{children:[t.jsx(mu,{edgeTypes:n,onEdgeClick:i,onEdgeDoubleClick:a,onReconnect:he,onReconnectStart:de,onReconnectEnd:Z,onlyRenderVisibleElements:P,onEdgeContextMenu:J,onEdgeMouseEnter:U,onEdgeMouseMove:oe,onEdgeMouseLeave:le,reconnectRadius:ie,defaultMarkerColor:R,noPanClassName:ve,disableKeyboardA11y:ce,rfId:pe}),t.jsx(Nu,{style:E,type:x,component:S,containerStyle:v}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(Ud,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:se,onlyRenderVisibleElements:P,noPanClassName:ve,noDragClassName:ae,disableKeyboardA11y:ce,nodeExtent:te,rfId:pe}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}Oi.displayName="GraphView";const Eu=g.memo(Oi),Ko=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c=.5,maxZoom:d=2,nodeOrigin:h,nodeExtent:f,zIndexMode:m="basic"}={})=>{const u=new Map,x=new Map,E=new Map,S=new Map,v=r??n??[],y=s??e??[],p=h??[0,0],b=f??Kn;Ja(E,S,v);const N=ps(y,u,x,{nodeOrigin:p,nodeExtent:b,zIndexMode:m});let w=[0,0,1];if(a&&i&&o){const M=or(u,{filter:C=>!!((C.width||C.initialWidth)&&(C.height||C.initialHeight))}),{x:D,y:P,zoom:_}=Cs(M,i,o,c,d,l?.padding??.1);w=[D,P,_]}return{rfId:"1",width:i??0,height:o??0,transform:w,nodes:y,nodesInitialized:N,nodeLookup:u,parentLookup:x,edges:v,edgeLookup:S,connectionLookup:E,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:Kn,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Rn.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:p,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:a??!1,fitViewOptions:l,fitViewResolver:null,connection:{...Da},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Wl,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:La,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},Mu=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m})=>Yc((u,x)=>{async function E(){const{nodeLookup:S,panZoom:v,fitViewOptions:y,fitViewResolver:p,width:b,height:N,minZoom:w,maxZoom:M}=x();v&&(await ql({nodes:S,width:b,height:N,panZoom:v,minZoom:w,maxZoom:M},y),p?.resolve(!0),u({fitViewResolver:null}))}return{...Ko({nodes:e,edges:n,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:h,nodeExtent:f,defaultNodes:s,defaultEdges:r,zIndexMode:m}),setNodes:S=>{const{nodeLookup:v,parentLookup:y,nodeOrigin:p,elevateNodesOnSelect:b,fitViewQueued:N,zIndexMode:w}=x(),M=ps(S,v,y,{nodeOrigin:p,nodeExtent:f,elevateNodesOnSelect:b,checkEquality:!0,zIndexMode:w});N&&M?(E(),u({nodes:S,nodesInitialized:M,fitViewQueued:!1,fitViewOptions:void 0})):u({nodes:S,nodesInitialized:M})},setEdges:S=>{const{connectionLookup:v,edgeLookup:y}=x();Ja(v,y,S),u({edges:S})},setDefaultNodesAndEdges:(S,v)=>{if(S){const{setNodes:y}=x();y(S),u({hasDefaultNodes:!0})}if(v){const{setEdges:y}=x();y(v),u({hasDefaultEdges:!0})}},updateNodeInternals:S=>{const{triggerNodeChanges:v,nodeLookup:y,parentLookup:p,domNode:b,nodeOrigin:N,nodeExtent:w,debug:M,fitViewQueued:D,zIndexMode:P}=x(),{changes:_,updatedInternals:C}=fc(S,y,p,b,N,w,P);C&&(lc(y,p,{nodeOrigin:N,nodeExtent:w,zIndexMode:P}),D?(E(),u({fitViewQueued:!1,fitViewOptions:void 0})):u({}),_?.length>0&&(M&&console.log("React Flow: trigger node changes",_),v?.(_)))},updateNodePositions:(S,v=!1)=>{const y=[];let p=[];const{nodeLookup:b,triggerNodeChanges:N,connection:w,updateConnection:M,onNodesChangeMiddlewareMap:D}=x();for(const[P,_]of S){const C=b.get(P),$=!!(C?.expandParent&&C?.parentId&&_?.position),z={id:P,type:"position",position:$?{x:Math.max(0,_.position.x),y:Math.max(0,_.position.y)}:_.position,dragging:v};if(C&&w.inProgress&&w.fromNode.id===C.id){const j=hn(C,w.fromHandle,ye.Left,!0);M({...w,from:j})}$&&C.parentId&&y.push({id:P,parentId:C.parentId,rect:{..._.internals.positionAbsolute,width:_.measured.width??0,height:_.measured.height??0}}),p.push(z)}if(y.length>0){const{parentLookup:P,nodeOrigin:_}=x(),C=Rs(y,b,P,_);p.push(...C)}for(const P of D.values())p=P(p);N(p)},triggerNodeChanges:S=>{const{onNodesChange:v,setNodes:y,nodes:p,hasDefaultNodes:b,debug:N}=x();if(S?.length){if(b){const w=mi(S,p);y(w)}N&&console.log("React Flow: trigger node changes",S),v?.(S)}},triggerEdgeChanges:S=>{const{onEdgesChange:v,setEdges:y,edges:p,hasDefaultEdges:b,debug:N}=x();if(S?.length){if(b){const w=gi(S,p);y(w)}N&&console.log("React Flow: trigger edge changes",S),v?.(S)}},addSelectedNodes:S=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:p,triggerNodeChanges:b,triggerEdgeChanges:N}=x();if(v){const w=S.map(M=>dn(M,!0));b(w);return}b(Mn(p,new Set([...S]),!0)),N(Mn(y))},addSelectedEdges:S=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:p,triggerNodeChanges:b,triggerEdgeChanges:N}=x();if(v){const w=S.map(M=>dn(M,!0));N(w);return}N(Mn(y,new Set([...S]))),b(Mn(p,new Set,!0))},unselectNodesAndEdges:({nodes:S,edges:v}={})=>{const{edges:y,nodes:p,nodeLookup:b,triggerNodeChanges:N,triggerEdgeChanges:w}=x(),M=S||p,D=v||y,P=[];for(const C of M){if(!C.selected)continue;const $=b.get(C.id);$&&($.selected=!1),P.push(dn(C.id,!1))}const _=[];for(const C of D)C.selected&&_.push(dn(C.id,!1));N(P),w(_)},setMinZoom:S=>{const{panZoom:v,maxZoom:y}=x();v?.setScaleExtent([S,y]),u({minZoom:S})},setMaxZoom:S=>{const{panZoom:v,minZoom:y}=x();v?.setScaleExtent([y,S]),u({maxZoom:S})},setTranslateExtent:S=>{x().panZoom?.setTranslateExtent(S),u({translateExtent:S})},resetSelectedElements:()=>{const{edges:S,nodes:v,triggerNodeChanges:y,triggerEdgeChanges:p,elementsSelectable:b}=x();if(!b)return;const N=v.reduce((M,D)=>D.selected?[...M,dn(D.id,!1)]:M,[]),w=S.reduce((M,D)=>D.selected?[...M,dn(D.id,!1)]:M,[]);y(N),p(w)},setNodeExtent:S=>{const{nodes:v,nodeLookup:y,parentLookup:p,nodeOrigin:b,elevateNodesOnSelect:N,nodeExtent:w,zIndexMode:M}=x();S[0][0]===w[0][0]&&S[0][1]===w[0][1]&&S[1][0]===w[1][0]&&S[1][1]===w[1][1]||(ps(v,y,p,{nodeOrigin:b,nodeExtent:S,elevateNodesOnSelect:N,checkEquality:!1,zIndexMode:M}),u({nodeExtent:S}))},panBy:S=>{const{transform:v,width:y,height:p,panZoom:b,translateExtent:N}=x();return hc({delta:S,panZoom:b,transform:v,translateExtent:N,width:y,height:p})},setCenter:async(S,v,y)=>{const{width:p,height:b,maxZoom:N,panZoom:w}=x();if(!w)return Promise.resolve(!1);const M=typeof y?.zoom<"u"?y.zoom:N;return await w.setViewport({x:p/2-S*M,y:b/2-v*M,zoom:M},{duration:y?.duration,ease:y?.ease,interpolate:y?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{u({connection:{...Da}})},updateConnection:S=>{u({connection:S})},reset:()=>u({...Ko()})}},Object.is);function Iu({initialNodes:e,initialEdges:n,defaultNodes:s,defaultEdges:r,initialWidth:i,initialHeight:o,initialMinZoom:a,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m,children:u}){const[x]=g.useState(()=>Mu({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:d,minZoom:a,maxZoom:l,fitViewOptions:c,nodeOrigin:h,nodeExtent:f,zIndexMode:m}));return t.jsx(Gc,{value:x,children:t.jsx(pd,{children:u})})}function Tu({children:e,nodes:n,edges:s,defaultNodes:r,defaultEdges:i,width:o,height:a,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u}){return g.useContext(Hr)?t.jsx(t.Fragment,{children:e}):t.jsx(Iu,{initialNodes:n,initialEdges:s,defaultNodes:r,defaultEdges:i,initialWidth:o,initialHeight:a,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u,children:e})}const Ru={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function _u({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,className:i,nodeTypes:o,edgeTypes:a,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:h,onMoveStart:f,onMoveEnd:m,onConnect:u,onConnectStart:x,onConnectEnd:E,onClickConnectStart:S,onClickConnectEnd:v,onNodeMouseEnter:y,onNodeMouseMove:p,onNodeMouseLeave:b,onNodeContextMenu:N,onNodeDoubleClick:w,onNodeDragStart:M,onNodeDrag:D,onNodeDragStop:P,onNodesDelete:_,onEdgesDelete:C,onDelete:$,onSelectionChange:z,onSelectionDragStart:j,onSelectionDrag:B,onSelectionDragStop:R,onSelectionContextMenu:T,onSelectionStart:A,onSelectionEnd:L,onBeforeDelete:q,connectionMode:F,connectionLineType:Y=Kt.Bezier,connectionLineStyle:Q,connectionLineComponent:O,connectionLineContainerStyle:I,deleteKeyCode:H="Backspace",selectionKeyCode:V="Shift",selectionOnDrag:W=!1,selectionMode:X=Qn.Full,panActivationKeyCode:ee="Space",multiSelectionKeyCode:se=er()?"Meta":"Control",zoomActivationKeyCode:J=er()?"Meta":"Control",snapToGrid:U,snapGrid:oe,onlyRenderVisibleElements:le=!1,selectNodesOnDrag:ie,nodesDraggable:he,autoPanOnNodeFocus:de,nodesConnectable:Z,nodesFocusable:ae,nodeOrigin:me=fi,edgesFocusable:ve,edgesReconnectable:ce,elementsSelectable:te=!0,defaultViewport:pe=ad,minZoom:Re=.5,maxZoom:be=2,translateExtent:Ie=Kn,preventScrolling:mt=!0,nodeExtent:nt,defaultMarkerColor:yt="#b1b1b7",zoomOnScroll:ot=!0,zoomOnPinch:gt=!0,panOnScroll:Et=!1,panOnScrollSpeed:Ve=.5,panOnScrollMode:ze=un.Free,zoomOnDoubleClick:Pe=!0,panOnDrag:We=!0,onPaneClick:we,onPaneMouseEnter:Xe,onPaneMouseMove:_e,onPaneMouseLeave:Te,onPaneScroll:Le,onPaneContextMenu:lt,paneClickDistance:Pt=1,nodeClickDistance:Ee=0,children:Fe,onReconnect:rt,onReconnectStart:ct,onReconnectEnd:Mt,onEdgeContextMenu:mn,onEdgeDoubleClick:en,onEdgeMouseEnter:gn,onEdgeMouseMove:$t,onEdgeMouseLeave:tn,reconnectRadius:Yt=10,onNodesChange:nn,onEdgesChange:Ue,noDragClassName:Bt="nodrag",noWheelClassName:It="nowheel",noPanClassName:Tt="nopan",fitView:vt,fitViewOptions:pt,connectOnClick:Rt,attributionPosition:_t,proOptions:Ot,defaultEdgeOptions:Ke,elevateNodesOnSelect:dt=!0,elevateEdgesOnSelect:ut=!1,disableKeyboardA11y:at=!1,autoPanOnConnect:G,autoPanOnNodeDrag:ge,autoPanSpeed:Se,connectionRadius:je,isValidConnection:Ne,onError:Qe,style:ft,id:rn,nodeDragThreshold:pn,connectionDragThreshold:lr,viewport:At,onViewportChange:Bn,width:cr,height:dr,colorMode:Gt="light",debug:st,onScroll:tt,ariaLabelConfig:Fr,zIndexMode:zt="basic",...On},xn){const xt=rn||"1",Je=dd(Gt),sn=g.useCallback(zn=>{zn.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),tt?.(zn)},[tt]);return t.jsx("div",{"data-testid":"rf__wrapper",...On,onScroll:sn,style:{...ft,...Ru},ref:xn,className:Ze(["react-flow",i,Je]),id:rn,role:"application",children:t.jsxs(Tu,{nodes:e,edges:n,width:cr,height:dr,fitView:vt,fitViewOptions:pt,minZoom:Re,maxZoom:be,nodeOrigin:me,nodeExtent:nt,zIndexMode:zt,children:[t.jsx(Eu,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:p,onNodeMouseLeave:b,onNodeContextMenu:N,onNodeDoubleClick:w,nodeTypes:o,edgeTypes:a,connectionLineType:Y,connectionLineStyle:Q,connectionLineComponent:O,connectionLineContainerStyle:I,selectionKeyCode:V,selectionOnDrag:W,selectionMode:X,deleteKeyCode:H,multiSelectionKeyCode:se,panActivationKeyCode:ee,zoomActivationKeyCode:J,onlyRenderVisibleElements:le,defaultViewport:pe,translateExtent:Ie,minZoom:Re,maxZoom:be,preventScrolling:mt,zoomOnScroll:ot,zoomOnPinch:gt,zoomOnDoubleClick:Pe,panOnScroll:Et,panOnScrollSpeed:Ve,panOnScrollMode:ze,panOnDrag:We,onPaneClick:we,onPaneMouseEnter:Xe,onPaneMouseMove:_e,onPaneMouseLeave:Te,onPaneScroll:Le,onPaneContextMenu:lt,paneClickDistance:Pt,nodeClickDistance:Ee,onSelectionContextMenu:T,onSelectionStart:A,onSelectionEnd:L,onReconnect:rt,onReconnectStart:ct,onReconnectEnd:Mt,onEdgeContextMenu:mn,onEdgeDoubleClick:en,onEdgeMouseEnter:gn,onEdgeMouseMove:$t,onEdgeMouseLeave:tn,reconnectRadius:Yt,defaultMarkerColor:yt,noDragClassName:Bt,noWheelClassName:It,noPanClassName:Tt,rfId:xt,disableKeyboardA11y:at,nodeExtent:nt,viewport:At,onViewportChange:Bn}),t.jsx(cd,{nodes:e,edges:n,defaultNodes:s,defaultEdges:r,onConnect:u,onConnectStart:x,onConnectEnd:E,onClickConnectStart:S,onClickConnectEnd:v,nodesDraggable:he,autoPanOnNodeFocus:de,nodesConnectable:Z,nodesFocusable:ae,edgesFocusable:ve,edgesReconnectable:ce,elementsSelectable:te,elevateNodesOnSelect:dt,elevateEdgesOnSelect:ut,minZoom:Re,maxZoom:be,nodeExtent:nt,onNodesChange:nn,onEdgesChange:Ue,snapToGrid:U,snapGrid:oe,connectionMode:F,translateExtent:Ie,connectOnClick:Rt,defaultEdgeOptions:Ke,fitView:vt,fitViewOptions:pt,onNodesDelete:_,onEdgesDelete:C,onDelete:$,onNodeDragStart:M,onNodeDrag:D,onNodeDragStop:P,onSelectionDrag:B,onSelectionDragStart:j,onSelectionDragStop:R,onMove:h,onMoveStart:f,onMoveEnd:m,noPanClassName:Tt,nodeOrigin:me,rfId:xt,autoPanOnConnect:G,autoPanOnNodeDrag:ge,autoPanSpeed:Se,onError:Qe,connectionRadius:je,isValidConnection:Ne,selectNodesOnDrag:ie,nodeDragThreshold:pn,connectionDragThreshold:lr,onBeforeDelete:q,debug:st,ariaLabelConfig:Fr,zIndexMode:zt}),t.jsx(od,{onSelectionChange:z}),Fe,t.jsx(ed,{proOptions:Ot,position:_t}),t.jsx(Jc,{rfId:xt,disableKeyboardA11y:at})]})})}var Au=pi(_u);function Lu(){const e=Be();return g.useCallback(n=>{const{domNode:s,updateNodeInternals:r}=e.getState(),i=Array.isArray(n)?n:[n],o=new Map;i.forEach(a=>{const l=s?.querySelector(`.react-flow__node[data-id="${a}"]`);l&&o.set(a,{id:a,nodeElement:l,force:!0})}),requestAnimationFrame(()=>r(o,{triggerFitView:!1}))},[])}function Du(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>mi(i,o)),[]);return[n,s,r]}function Pu(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>gi(i,o)),[]);return[n,s,r]}function $u({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:Ze(["react-flow__background-pattern",s,r])})}function Bu({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Ze(["react-flow__background-pattern","dots",n])})}var Qt;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Qt||(Qt={}));const Ou={[Qt.Dots]:1,[Qt.Lines]:1,[Qt.Cross]:6},zu=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function zi({id:e,variant:n=Qt.Dots,gap:s=20,size:r,lineWidth:i=1,offset:o=0,color:a,bgColor:l,style:c,className:d,patternClassName:h}){const f=g.useRef(null),{transform:m,patternId:u}=Me(zu,Oe),x=r||Ou[n],E=n===Qt.Dots,S=n===Qt.Cross,v=Array.isArray(s)?s:[s,s],y=[v[0]*m[2]||1,v[1]*m[2]||1],p=x*m[2],b=Array.isArray(o)?o:[o,o],N=S?[p,p]:y,w=[b[0]*m[2]||1+N[0]/2,b[1]*m[2]||1+N[1]/2],M=`${u}${e||""}`;return t.jsxs("svg",{className:Ze(["react-flow__background",d]),style:{...c,...Vr,"--xy-background-color-props":l,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[t.jsx("pattern",{id:M,x:m[0]%y[0],y:m[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${w[0]},-${w[1]})`,children:E?t.jsx(Bu,{radius:p/2,className:h}):t.jsx($u,{dimensions:N,lineWidth:i,variant:n,className:h})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}zi.displayName="Background";const Hu=g.memo(zi);function qu(){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 Vu(){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 Wu(){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 Fu(){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 Yu(){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 Sr({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:Ze(["react-flow__controls-button",n]),...s,children:e})}const Gu=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Hi({style:e,showZoom:n=!0,showFitView:s=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:o,onZoomOut:a,onFitView:l,onInteractiveChange:c,className:d,children:h,position:f="bottom-left",orientation:m="vertical","aria-label":u}){const x=Be(),{isInteractive:E,minZoomReached:S,maxZoomReached:v,ariaLabelConfig:y}=Me(Gu,Oe),{zoomIn:p,zoomOut:b,fitView:N}=_s(),w=()=>{p(),o?.()},M=()=>{b(),a?.()},D=()=>{N(i),l?.()},P=()=>{x.setState({nodesDraggable:!E,nodesConnectable:!E,elementsSelectable:!E}),c?.(!E)},_=m==="horizontal"?"horizontal":"vertical";return t.jsxs(qr,{className:Ze(["react-flow__controls",_,d]),position:f,style:e,"data-testid":"rf__controls","aria-label":u??y["controls.ariaLabel"],children:[n&&t.jsxs(t.Fragment,{children:[t.jsx(Sr,{onClick:w,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:v,children:t.jsx(qu,{})}),t.jsx(Sr,{onClick:M,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:S,children:t.jsx(Vu,{})})]}),s&&t.jsx(Sr,{className:"react-flow__controls-fitview",onClick:D,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:t.jsx(Wu,{})}),r&&t.jsx(Sr,{className:"react-flow__controls-interactive",onClick:P,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:E?t.jsx(Yu,{}):t.jsx(Fu,{})}),h]})}Hi.displayName="Controls";const Zu=g.memo(Hi);function Xu({id:e,x:n,y:s,width:r,height:i,style:o,color:a,strokeColor:l,strokeWidth:c,className:d,borderRadius:h,shapeRendering:f,selected:m,onClick:u}){const{background:x,backgroundColor:E}=o||{},S=a||x||E;return t.jsx("rect",{className:Ze(["react-flow__minimap-node",{selected:m},d]),x:n,y:s,rx:h,ry:h,width:r,height:i,style:{fill:S,stroke:l,strokeWidth:c},shapeRendering:f,onClick:u?v=>u(v,e):void 0})}const Uu=g.memo(Xu),Ku=e=>e.nodes.map(n=>n.id),ls=e=>e instanceof Function?e:()=>e;function Qu({nodeStrokeColor:e,nodeColor:n,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:o=Uu,onClick:a}){const l=Me(Ku,Oe),c=ls(n),d=ls(e),h=ls(s),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:l.map(m=>t.jsx(ef,{id:m,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:o,onClick:a,shapeRendering:f},m))})}function Ju({id:e,nodeColorFunc:n,nodeStrokeColorFunc:s,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:o,shapeRendering:a,NodeComponent:l,onClick:c}){const{node:d,x:h,y:f,width:m,height:u}=Me(x=>{const E=x.nodeLookup.get(e);if(!E)return{node:void 0,x:0,y:0,width:0,height:0};const S=E.internals.userNode,{x:v,y}=E.internals.positionAbsolute,{width:p,height:b}=Ft(S);return{node:S,x:v,y,width:p,height:b}},Oe);return!d||d.hidden||!qa(d)?null:t.jsx(l,{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:c,id:d.id})}const ef=g.memo(Ju);var tf=g.memo(Qu);const nf=200,rf=150,sf=e=>!e.hidden,of=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?Ha(or(e.nodeLookup,{filter:sf}),n):n,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},af="react-flow__minimap-desc";function qi({style:e,className:n,nodeStrokeColor:s,nodeColor:r,nodeClassName:i="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:h,maskStrokeWidth:f,position:m="bottom-right",onClick:u,onNodeClick:x,pannable:E=!1,zoomable:S=!1,ariaLabel:v,inversePan:y,zoomStep:p=1,offsetScale:b=5}){const N=Be(),w=g.useRef(null),{boundingRect:M,viewBB:D,rfId:P,panZoom:_,translateExtent:C,flowWidth:$,flowHeight:z,ariaLabelConfig:j}=Me(of,Oe),B=e?.width??nf,R=e?.height??rf,T=M.width/B,A=M.height/R,L=Math.max(T,A),q=L*B,F=L*R,Y=b*L,Q=M.x-(q-M.width)/2-Y,O=M.y-(F-M.height)/2-Y,I=q+Y*2,H=F+Y*2,V=`${af}-${P}`,W=g.useRef(0),X=g.useRef();W.current=L,g.useEffect(()=>{if(w.current&&_)return X.current=kc({domNode:w.current,panZoom:_,getTransform:()=>N.getState().transform,getViewScale:()=>W.current}),()=>{X.current?.destroy()}},[_]),g.useEffect(()=>{X.current?.update({translateExtent:C,width:$,height:z,inversePan:y,pannable:E,zoomStep:p,zoomable:S})},[E,S,y,p,C,$,z]);const ee=u?U=>{const[oe,le]=X.current?.pointer(U)||[0,0];u(U,{x:oe,y:le})}:void 0,se=x?g.useCallback((U,oe)=>{const le=N.getState().nodeLookup.get(oe).internals.userNode;x(U,le)},[]):void 0,J=v??j["minimap.ariaLabel"];return t.jsx(qr,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*L: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:Ze(["react-flow__minimap",n]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:B,height:R,viewBox:`${Q} ${O} ${I} ${H}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":V,ref:w,onClick:ee,children:[J&&t.jsx("title",{id:V,children:J}),t.jsx(tf,{onClick:se,nodeColor:r,nodeStrokeColor:s,nodeBorderRadius:o,nodeClassName:i,nodeStrokeWidth:a,nodeComponent:l}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${Q-Y},${O-Y}h${I+Y*2}v${H+Y*2}h${-I-Y*2}z
7
- M${D.x},${D.y}h${D.width}v${D.height}h${-D.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}qi.displayName="MiniMap";const lf=g.memo(qi),cf=e=>n=>e?`${Math.max(1/n.transform[2],1)}`:void 0,df={[Pn.Line]:"right",[Pn.Handle]:"bottom-right"};function uf({nodeId:e,position:n,variant:s=Pn.Handle,className:r,style:i=void 0,children:o,color:a,minWidth:l=10,minHeight:c=10,maxWidth:d=Number.MAX_VALUE,maxHeight:h=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:m,autoScale:u=!0,shouldResize:x,onResizeStart:E,onResize:S,onResizeEnd:v}){const y=vi(),p=typeof e=="string"?e:y,b=Be(),N=g.useRef(null),w=s===Pn.Handle,M=Me(g.useCallback(cf(w&&u),[w,u]),Oe),D=g.useRef(null),P=n??df[s];g.useEffect(()=>{if(!(!N.current||!p))return D.current||(D.current=Pc({domNode:N.current,nodeId:p,getStoreItems:()=>{const{nodeLookup:C,transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:B,domNode:R}=b.getState();return{nodeLookup:C,transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:B,paneDomNode:R}},onChange:(C,$)=>{const{triggerNodeChanges:z,nodeLookup:j,parentLookup:B,nodeOrigin:R}=b.getState(),T=[],A={x:C.x,y:C.y},L=j.get(p);if(L&&L.expandParent&&L.parentId){const q=L.origin??R,F=C.width??L.measured.width??0,Y=C.height??L.measured.height??0,Q={id:L.id,parentId:L.parentId,rect:{width:F,height:Y,...Va({x:C.x??L.position.x,y:C.y??L.position.y},{width:F,height:Y},L.parentId,j,q)}},O=Rs([Q],j,B,R);T.push(...O),A.x=C.x?Math.max(q[0]*F,C.x):void 0,A.y=C.y?Math.max(q[1]*Y,C.y):void 0}if(A.x!==void 0&&A.y!==void 0){const q={id:p,type:"position",position:{...A}};T.push(q)}if(C.width!==void 0&&C.height!==void 0){const F={id:p,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:C.width,height:C.height}};T.push(F)}for(const q of $){const F={...q,type:"position"};T.push(F)}z(T)},onEnd:({width:C,height:$})=>{const z={id:p,type:"dimensions",resizing:!1,dimensions:{width:C,height:$}};b.getState().triggerNodeChanges([z])}})),D.current.update({controlPosition:P,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:h},keepAspectRatio:f,resizeDirection:m,onResizeStart:E,onResize:S,onResizeEnd:v,shouldResize:x}),()=>{D.current?.destroy()}},[P,l,c,d,h,f,E,S,v,x]);const _=P.split("-");return t.jsx("div",{className:Ze(["react-flow__resize-control","nodrag",..._,s,r]),ref:N,style:{...i,scale:M,...a&&{[w?"backgroundColor":"borderColor"]:a}},children:o})}g.memo(uf);var Ae=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),St=Ae((e,n)=>{var s=Object.defineProperty,r=(z,j,B)=>j in z?s(z,j,{enumerable:!0,configurable:!0,writable:!0,value:B}):z[j]=B,i=(z,j)=>()=>(j||z((j={exports:{}}).exports,j),j.exports),o=(z,j,B)=>r(z,typeof j!="symbol"?j+"":j,B),a=i((z,j)=>{var B="\0",R="\0",T="",A=class{constructor(O){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"),O&&(this._isDirected=Object.hasOwn(O,"directed")?O.directed:!0,this._isMultigraph=Object.hasOwn(O,"multigraph")?O.multigraph:!1,this._isCompound=Object.hasOwn(O,"compound")?O.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[R]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(O){return this._label=O,this}graph(){return this._label}setDefaultNodeLabel(O){return this._defaultNodeLabelFn=O,typeof O!="function"&&(this._defaultNodeLabelFn=()=>O),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var O=this;return this.nodes().filter(I=>Object.keys(O._in[I]).length===0)}sinks(){var O=this;return this.nodes().filter(I=>Object.keys(O._out[I]).length===0)}setNodes(O,I){var H=arguments,V=this;return O.forEach(function(W){H.length>1?V.setNode(W,I):V.setNode(W)}),this}setNode(O,I){return Object.hasOwn(this._nodes,O)?(arguments.length>1&&(this._nodes[O]=I),this):(this._nodes[O]=arguments.length>1?I:this._defaultNodeLabelFn(O),this._isCompound&&(this._parent[O]=R,this._children[O]={},this._children[R][O]=!0),this._in[O]={},this._preds[O]={},this._out[O]={},this._sucs[O]={},++this._nodeCount,this)}node(O){return this._nodes[O]}hasNode(O){return Object.hasOwn(this._nodes,O)}removeNode(O){var I=this;if(Object.hasOwn(this._nodes,O)){var H=V=>I.removeEdge(I._edgeObjs[V]);delete this._nodes[O],this._isCompound&&(this._removeFromParentsChildList(O),delete this._parent[O],this.children(O).forEach(function(V){I.setParent(V)}),delete this._children[O]),Object.keys(this._in[O]).forEach(H),delete this._in[O],delete this._preds[O],Object.keys(this._out[O]).forEach(H),delete this._out[O],delete this._sucs[O],--this._nodeCount}return this}setParent(O,I){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(I===void 0)I=R;else{I+="";for(var H=I;H!==void 0;H=this.parent(H))if(H===O)throw new Error("Setting "+I+" as parent of "+O+" would create a cycle");this.setNode(I)}return this.setNode(O),this._removeFromParentsChildList(O),this._parent[O]=I,this._children[I][O]=!0,this}_removeFromParentsChildList(O){delete this._children[this._parent[O]][O]}parent(O){if(this._isCompound){var I=this._parent[O];if(I!==R)return I}}children(O=R){if(this._isCompound){var I=this._children[O];if(I)return Object.keys(I)}else{if(O===R)return this.nodes();if(this.hasNode(O))return[]}}predecessors(O){var I=this._preds[O];if(I)return Object.keys(I)}successors(O){var I=this._sucs[O];if(I)return Object.keys(I)}neighbors(O){var I=this.predecessors(O);if(I){let V=new Set(I);for(var H of this.successors(O))V.add(H);return Array.from(V.values())}}isLeaf(O){var I;return this.isDirected()?I=this.successors(O):I=this.neighbors(O),I.length===0}filterNodes(O){var I=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});I.setGraph(this.graph());var H=this;Object.entries(this._nodes).forEach(function([X,ee]){O(X)&&I.setNode(X,ee)}),Object.values(this._edgeObjs).forEach(function(X){I.hasNode(X.v)&&I.hasNode(X.w)&&I.setEdge(X,H.edge(X))});var V={};function W(X){var ee=H.parent(X);return ee===void 0||I.hasNode(ee)?(V[X]=ee,ee):ee in V?V[ee]:W(ee)}return this._isCompound&&I.nodes().forEach(X=>I.setParent(X,W(X))),I}setDefaultEdgeLabel(O){return this._defaultEdgeLabelFn=O,typeof O!="function"&&(this._defaultEdgeLabelFn=()=>O),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(O,I){var H=this,V=arguments;return O.reduce(function(W,X){return V.length>1?H.setEdge(W,X,I):H.setEdge(W,X),X}),this}setEdge(){var O,I,H,V,W=!1,X=arguments[0];typeof X=="object"&&X!==null&&"v"in X?(O=X.v,I=X.w,H=X.name,arguments.length===2&&(V=arguments[1],W=!0)):(O=X,I=arguments[1],H=arguments[3],arguments.length>2&&(V=arguments[2],W=!0)),O=""+O,I=""+I,H!==void 0&&(H=""+H);var ee=F(this._isDirected,O,I,H);if(Object.hasOwn(this._edgeLabels,ee))return W&&(this._edgeLabels[ee]=V),this;if(H!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(O),this.setNode(I),this._edgeLabels[ee]=W?V:this._defaultEdgeLabelFn(O,I,H);var se=Y(this._isDirected,O,I,H);return O=se.v,I=se.w,Object.freeze(se),this._edgeObjs[ee]=se,L(this._preds[I],O),L(this._sucs[O],I),this._in[I][ee]=se,this._out[O][ee]=se,this._edgeCount++,this}edge(O,I,H){var V=arguments.length===1?Q(this._isDirected,arguments[0]):F(this._isDirected,O,I,H);return this._edgeLabels[V]}edgeAsObj(){let O=this.edge(...arguments);return typeof O!="object"?{label:O}:O}hasEdge(O,I,H){var V=arguments.length===1?Q(this._isDirected,arguments[0]):F(this._isDirected,O,I,H);return Object.hasOwn(this._edgeLabels,V)}removeEdge(O,I,H){var V=arguments.length===1?Q(this._isDirected,arguments[0]):F(this._isDirected,O,I,H),W=this._edgeObjs[V];return W&&(O=W.v,I=W.w,delete this._edgeLabels[V],delete this._edgeObjs[V],q(this._preds[I],O),q(this._sucs[O],I),delete this._in[I][V],delete this._out[O][V],this._edgeCount--),this}inEdges(O,I){return this.isDirected()?this.filterEdges(this._in[O],O,I):this.nodeEdges(O,I)}outEdges(O,I){return this.isDirected()?this.filterEdges(this._out[O],O,I):this.nodeEdges(O,I)}nodeEdges(O,I){if(O in this._nodes)return this.filterEdges({...this._in[O],...this._out[O]},O,I)}filterEdges(O,I,H){if(O){var V=Object.values(O);return H?V.filter(function(W){return W.v===I&&W.w===H||W.v===H&&W.w===I}):V}}};function L(O,I){O[I]?O[I]++:O[I]=1}function q(O,I){--O[I]||delete O[I]}function F(O,I,H,V){var W=""+I,X=""+H;if(!O&&W>X){var ee=W;W=X,X=ee}return W+T+X+T+(V===void 0?B:V)}function Y(O,I,H,V){var W=""+I,X=""+H;if(!O&&W>X){var ee=W;W=X,X=ee}var se={v:W,w:X};return V&&(se.name=V),se}function Q(O,I){return F(O,I.v,I.w,I.name)}j.exports=A}),l=i((z,j)=>{j.exports="3.0.2"}),c=i((z,j)=>{j.exports={Graph:a(),version:l()}}),d=i((z,j)=>{var B=a();j.exports={write:R,read:L};function R(q){var F={options:{directed:q.isDirected(),multigraph:q.isMultigraph(),compound:q.isCompound()},nodes:T(q),edges:A(q)};return q.graph()!==void 0&&(F.value=structuredClone(q.graph())),F}function T(q){return q.nodes().map(function(F){var Y=q.node(F),Q=q.parent(F),O={v:F};return Y!==void 0&&(O.value=Y),Q!==void 0&&(O.parent=Q),O})}function A(q){return q.edges().map(function(F){var Y=q.edge(F),Q={v:F.v,w:F.w};return F.name!==void 0&&(Q.name=F.name),Y!==void 0&&(Q.value=Y),Q})}function L(q){var F=new B(q.options).setGraph(q.value);return q.nodes.forEach(function(Y){F.setNode(Y.v,Y.value),Y.parent&&F.setParent(Y.v,Y.parent)}),q.edges.forEach(function(Y){F.setEdge({v:Y.v,w:Y.w,name:Y.name},Y.value)}),F}}),h=i((z,j)=>{j.exports=R;var B=()=>1;function R(A,L,q,F){return T(A,String(L),q||B,F||function(Y){return A.outEdges(Y)})}function T(A,L,q,F){var Y={},Q=!0,O=0,I=A.nodes(),H=function(ee){var se=q(ee);Y[ee.v].distance+se<Y[ee.w].distance&&(Y[ee.w]={distance:Y[ee.v].distance+se,predecessor:ee.v},Q=!0)},V=function(){I.forEach(function(ee){F(ee).forEach(function(se){var J=se.v===ee?se.v:se.w,U=J===se.v?se.w:se.v;H({v:J,w:U})})})};I.forEach(function(ee){var se=ee===L?0:Number.POSITIVE_INFINITY;Y[ee]={distance:se}});for(var W=I.length,X=1;X<W&&(Q=!1,O++,V(),!!Q);X++);if(O===W-1&&(Q=!1,V(),Q))throw new Error("The graph contains a negative weight cycle");return Y}}),f=i((z,j)=>{j.exports=B;function B(R){var T={},A=[],L;function q(F){Object.hasOwn(T,F)||(T[F]=!0,L.push(F),R.successors(F).forEach(q),R.predecessors(F).forEach(q))}return R.nodes().forEach(function(F){L=[],q(F),L.length&&A.push(L)}),A}}),m=i((z,j)=>{var B=class{constructor(){o(this,"_arr",[]),o(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(R){return R.key})}has(R){return Object.hasOwn(this._keyIndices,R)}priority(R){var T=this._keyIndices[R];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(R,T){var A=this._keyIndices;if(R=String(R),!Object.hasOwn(A,R)){var L=this._arr,q=L.length;return A[R]=q,L.push({key:R,priority:T}),this._decrease(q),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var R=this._arr.pop();return delete this._keyIndices[R.key],this._heapify(0),R.key}decrease(R,T){var A=this._keyIndices[R];if(T>this._arr[A].priority)throw new Error("New priority is greater than current priority. Key: "+R+" Old: "+this._arr[A].priority+" New: "+T);this._arr[A].priority=T,this._decrease(A)}_heapify(R){var T=this._arr,A=2*R,L=A+1,q=R;A<T.length&&(q=T[A].priority<T[q].priority?A:q,L<T.length&&(q=T[L].priority<T[q].priority?L:q),q!==R&&(this._swap(R,q),this._heapify(q)))}_decrease(R){for(var T=this._arr,A=T[R].priority,L;R!==0&&(L=R>>1,!(T[L].priority<A));)this._swap(R,L),R=L}_swap(R,T){var A=this._arr,L=this._keyIndices,q=A[R],F=A[T];A[R]=F,A[T]=q,L[F.key]=R,L[q.key]=T}};j.exports=B}),u=i((z,j)=>{var B=m();j.exports=T;var R=()=>1;function T(L,q,F,Y){var Q=function(O){return L.outEdges(O)};return A(L,String(q),F||R,Y||Q)}function A(L,q,F,Y){var Q={},O=new B,I,H,V=function(W){var X=W.v!==I?W.v:W.w,ee=Q[X],se=F(W),J=H.distance+se;if(se<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+W+" Weight: "+se);J<ee.distance&&(ee.distance=J,ee.predecessor=I,O.decrease(X,J))};for(L.nodes().forEach(function(W){var X=W===q?0:Number.POSITIVE_INFINITY;Q[W]={distance:X},O.add(W,X)});O.size()>0&&(I=O.removeMin(),H=Q[I],H.distance!==Number.POSITIVE_INFINITY);)Y(I).forEach(V);return Q}}),x=i((z,j)=>{var B=u();j.exports=R;function R(T,A,L){return T.nodes().reduce(function(q,F){return q[F]=B(T,F,A,L),q},{})}}),E=i((z,j)=>{j.exports=B;function B(T,A,L){if(T[A].predecessor!==void 0)throw new Error("Invalid source vertex");if(T[L].predecessor===void 0&&L!==A)throw new Error("Invalid destination vertex");return{weight:T[L].distance,path:R(T,A,L)}}function R(T,A,L){for(var q=[],F=L;F!==A;)q.push(F),F=T[F].predecessor;return q.push(A),q.reverse()}}),S=i((z,j)=>{j.exports=B;function B(R){var T=0,A=[],L={},q=[];function F(Y){var Q=L[Y]={onStack:!0,lowlink:T,index:T++};if(A.push(Y),R.successors(Y).forEach(function(H){Object.hasOwn(L,H)?L[H].onStack&&(Q.lowlink=Math.min(Q.lowlink,L[H].index)):(F(H),Q.lowlink=Math.min(Q.lowlink,L[H].lowlink))}),Q.lowlink===Q.index){var O=[],I;do I=A.pop(),L[I].onStack=!1,O.push(I);while(Y!==I);q.push(O)}}return R.nodes().forEach(function(Y){Object.hasOwn(L,Y)||F(Y)}),q}}),v=i((z,j)=>{var B=S();j.exports=R;function R(T){return B(T).filter(function(A){return A.length>1||A.length===1&&T.hasEdge(A[0],A[0])})}}),y=i((z,j)=>{j.exports=R;var B=()=>1;function R(A,L,q){return T(A,L||B,q||function(F){return A.outEdges(F)})}function T(A,L,q){var F={},Y=A.nodes();return Y.forEach(function(Q){F[Q]={},F[Q][Q]={distance:0},Y.forEach(function(O){Q!==O&&(F[Q][O]={distance:Number.POSITIVE_INFINITY})}),q(Q).forEach(function(O){var I=O.v===Q?O.w:O.v,H=L(O);F[Q][I]={distance:H,predecessor:Q}})}),Y.forEach(function(Q){var O=F[Q];Y.forEach(function(I){var H=F[I];Y.forEach(function(V){var W=H[Q],X=O[V],ee=H[V],se=W.distance+X.distance;se<ee.distance&&(ee.distance=se,ee.predecessor=X.predecessor)})})}),F}}),p=i((z,j)=>{function B(T){var A={},L={},q=[];function F(Y){if(Object.hasOwn(L,Y))throw new R;Object.hasOwn(A,Y)||(L[Y]=!0,A[Y]=!0,T.predecessors(Y).forEach(F),delete L[Y],q.push(Y))}if(T.sinks().forEach(F),Object.keys(A).length!==T.nodeCount())throw new R;return q}var R=class extends Error{constructor(){super(...arguments)}};j.exports=B,B.CycleException=R}),b=i((z,j)=>{var B=p();j.exports=R;function R(T){try{B(T)}catch(A){if(A instanceof B.CycleException)return!1;throw A}return!0}}),N=i((z,j)=>{j.exports=B;function B(T,A,L,q,F){Array.isArray(A)||(A=[A]);var Y=(T.isDirected()?T.successors:T.neighbors).bind(T),Q={};return A.forEach(function(O){if(!T.hasNode(O))throw new Error("Graph does not have node: "+O);F=R(T,O,L==="post",Q,Y,q,F)}),F}function R(T,A,L,q,F,Y,Q){return Object.hasOwn(q,A)||(q[A]=!0,L||(Q=Y(Q,A)),F(A).forEach(function(O){Q=R(T,O,L,q,F,Y,Q)}),L&&(Q=Y(Q,A))),Q}}),w=i((z,j)=>{var B=N();j.exports=R;function R(T,A,L){return B(T,A,L,function(q,F){return q.push(F),q},[])}}),M=i((z,j)=>{var B=w();j.exports=R;function R(T,A){return B(T,A,"post")}}),D=i((z,j)=>{var B=w();j.exports=R;function R(T,A){return B(T,A,"pre")}}),P=i((z,j)=>{var B=a(),R=m();j.exports=T;function T(A,L){var q=new B,F={},Y=new R,Q;function O(H){var V=H.v===Q?H.w:H.v,W=Y.priority(V);if(W!==void 0){var X=L(H);X<W&&(F[V]=Q,Y.decrease(V,X))}}if(A.nodeCount()===0)return q;A.nodes().forEach(function(H){Y.add(H,Number.POSITIVE_INFINITY),q.setNode(H)}),Y.decrease(A.nodes()[0],0);for(var I=!1;Y.size()>0;){if(Q=Y.removeMin(),Object.hasOwn(F,Q))q.setEdge(Q,F[Q]);else{if(I)throw new Error("Input graph is not connected: "+A);I=!0}A.nodeEdges(Q).forEach(O)}return q}}),_=i((z,j)=>{var B=u(),R=h();j.exports=T;function T(L,q,F,Y){return A(L,q,F,Y||function(Q){return L.outEdges(Q)})}function A(L,q,F,Y){if(F===void 0)return B(L,q,F,Y);for(var Q=!1,O=L.nodes(),I=0;I<O.length;I++){for(var H=Y(O[I]),V=0;V<H.length;V++){var W=H[V],X=W.v===O[I]?W.v:W.w,ee=X===W.v?W.w:W.v;F({v:X,w:ee})<0&&(Q=!0)}if(Q)return R(L,q,F,Y)}return B(L,q,F,Y)}}),C=i((z,j)=>{j.exports={bellmanFord:h(),components:f(),dijkstra:u(),dijkstraAll:x(),extractPath:E(),findCycles:v(),floydWarshall:y(),isAcyclic:b(),postorder:M(),preorder:D(),prim:P(),shortestPaths:_(),reduce:N(),tarjan:S(),topsort:p()}}),$=c();n.exports={Graph:$.Graph,json:d(),alg:C(),version:$.version}}),ff=Ae((e,n)=>{var s=class{constructor(){let o={};o._next=o._prev=o,this._sentinel=o}dequeue(){let o=this._sentinel,a=o._prev;if(a!==o)return r(a),a}enqueue(o){let a=this._sentinel;o._prev&&o._next&&r(o),o._next=a._next,a._next._prev=o,a._next=o,o._prev=a}toString(){let o=[],a=this._sentinel,l=a._prev;for(;l!==a;)o.push(JSON.stringify(l,i)),l=l._prev;return"["+o.join(", ")+"]"}};function r(o){o._prev._next=o._next,o._next._prev=o._prev,delete o._next,delete o._prev}function i(o,a){if(o!=="_next"&&o!=="_prev")return a}n.exports=s}),hf=Ae((e,n)=>{var s=St().Graph,r=ff();n.exports=o;var i=()=>1;function o(f,m){if(f.nodeCount()<=1)return[];let u=c(f,m||i);return a(u.graph,u.buckets,u.zeroIdx).flatMap(x=>f.outEdges(x.v,x.w))}function a(f,m,u){let x=[],E=m[m.length-1],S=m[0],v;for(;f.nodeCount();){for(;v=S.dequeue();)l(f,m,u,v);for(;v=E.dequeue();)l(f,m,u,v);if(f.nodeCount()){for(let y=m.length-2;y>0;--y)if(v=m[y].dequeue(),v){x=x.concat(l(f,m,u,v,!0));break}}}return x}function l(f,m,u,x,E){let S=E?[]:void 0;return f.inEdges(x.v).forEach(v=>{let y=f.edge(v),p=f.node(v.v);E&&S.push({v:v.v,w:v.w}),p.out-=y,d(m,u,p)}),f.outEdges(x.v).forEach(v=>{let y=f.edge(v),p=v.w,b=f.node(p);b.in-=y,d(m,u,b)}),f.removeNode(x.v),S}function c(f,m){let u=new s,x=0,E=0;f.nodes().forEach(y=>{u.setNode(y,{v:y,in:0,out:0})}),f.edges().forEach(y=>{let p=u.edge(y.v,y.w)||0,b=m(y),N=p+b;u.setEdge(y.v,y.w,N),E=Math.max(E,u.node(y.v).out+=b),x=Math.max(x,u.node(y.w).in+=b)});let S=h(E+x+3).map(()=>new r),v=x+1;return u.nodes().forEach(y=>{d(S,v,u.node(y))}),{graph:u,buckets:S,zeroIdx:v}}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=Ae((e,n)=>{var s=St().Graph;n.exports={addBorderNode:m,addDummyNode:r,applyWithChunking:E,asNonCompoundGraph:o,buildLayerMatrix:d,intersectRect:c,mapValues:D,maxRank:S,normalizeRanks:h,notime:p,partition:v,pick:M,predecessorWeights:l,range:w,removeEmptyRanks:f,simplify:i,successorWeights:a,time:y,uniqueId:N,zipObject:P};function r(_,C,$,z){for(var j=z;_.hasNode(j);)j=N(z);return $.dummy=C,_.setNode(j,$),j}function i(_){let C=new s().setGraph(_.graph());return _.nodes().forEach($=>C.setNode($,_.node($))),_.edges().forEach($=>{let z=C.edge($.v,$.w)||{weight:0,minlen:1},j=_.edge($);C.setEdge($.v,$.w,{weight:z.weight+j.weight,minlen:Math.max(z.minlen,j.minlen)})}),C}function o(_){let C=new s({multigraph:_.isMultigraph()}).setGraph(_.graph());return _.nodes().forEach($=>{_.children($).length||C.setNode($,_.node($))}),_.edges().forEach($=>{C.setEdge($,_.edge($))}),C}function a(_){let C=_.nodes().map($=>{let z={};return _.outEdges($).forEach(j=>{z[j.w]=(z[j.w]||0)+_.edge(j).weight}),z});return P(_.nodes(),C)}function l(_){let C=_.nodes().map($=>{let z={};return _.inEdges($).forEach(j=>{z[j.v]=(z[j.v]||0)+_.edge(j).weight}),z});return P(_.nodes(),C)}function c(_,C){let $=_.x,z=_.y,j=C.x-$,B=C.y-z,R=_.width/2,T=_.height/2;if(!j&&!B)throw new Error("Not possible to find intersection inside of the rectangle");let A,L;return Math.abs(B)*R>Math.abs(j)*T?(B<0&&(T=-T),A=T*j/B,L=T):(j<0&&(R=-R),A=R,L=R*B/j),{x:$+A,y:z+L}}function d(_){let C=w(S(_)+1).map(()=>[]);return _.nodes().forEach($=>{let z=_.node($),j=z.rank;j!==void 0&&(C[j][z.order]=$)}),C}function h(_){let C=_.nodes().map(z=>{let j=_.node(z).rank;return j===void 0?Number.MAX_VALUE:j}),$=E(Math.min,C);_.nodes().forEach(z=>{let j=_.node(z);Object.hasOwn(j,"rank")&&(j.rank-=$)})}function f(_){let C=_.nodes().map(R=>_.node(R).rank).filter(R=>R!==void 0),$=E(Math.min,C),z=[];_.nodes().forEach(R=>{let T=_.node(R).rank-$;z[T]||(z[T]=[]),z[T].push(R)});let j=0,B=_.graph().nodeRankFactor;Array.from(z).forEach((R,T)=>{R===void 0&&T%B!==0?--j:R!==void 0&&j&&R.forEach(A=>_.node(A).rank+=j)})}function m(_,C,$,z){let j={width:0,height:0};return arguments.length>=4&&(j.rank=$,j.order=z),r(_,"border",j,C)}function u(_,C=x){let $=[];for(let z=0;z<_.length;z+=C){let j=_.slice(z,z+C);$.push(j)}return $}var x=65535;function E(_,C){if(C.length>x){let $=u(C);return _.apply(null,$.map(z=>_.apply(null,z)))}else return _.apply(null,C)}function S(_){let C=_.nodes().map($=>{let z=_.node($).rank;return z===void 0?Number.MIN_VALUE:z});return E(Math.max,C)}function v(_,C){let $={lhs:[],rhs:[]};return _.forEach(z=>{C(z)?$.lhs.push(z):$.rhs.push(z)}),$}function y(_,C){let $=Date.now();try{return C()}finally{console.log(_+" time: "+(Date.now()-$)+"ms")}}function p(_,C){return C()}var b=0;function N(_){var C=++b;return _+(""+C)}function w(_,C,$=1){C==null&&(C=_,_=0);let z=B=>B<C;$<0&&(z=B=>C<B);let j=[];for(let B=_;z(B);B+=$)j.push(B);return j}function M(_,C){let $={};for(let z of C)_[z]!==void 0&&($[z]=_[z]);return $}function D(_,C){let $=C;return typeof C=="string"&&($=z=>z[C]),Object.entries(_).reduce((z,[j,B])=>(z[j]=$(B,j),z),{})}function P(_,C){return _.reduce(($,z,j)=>($[z]=C[j],$),{})}}),mf=Ae((e,n)=>{var s=hf(),r=Ge().uniqueId;n.exports={run:i,undo:a};function i(l){(l.graph().acyclicer==="greedy"?s(l,c(l)):o(l)).forEach(d=>{let h=l.edge(d);l.removeEdge(d),h.forwardName=d.name,h.reversed=!0,l.setEdge(d.w,d.v,h,r("rev"))});function c(d){return h=>d.edge(h).weight}}function o(l){let c=[],d={},h={};function f(m){Object.hasOwn(h,m)||(h[m]=!0,d[m]=!0,l.outEdges(m).forEach(u=>{Object.hasOwn(d,u.w)?c.push(u):f(u.w)}),delete d[m])}return l.nodes().forEach(f),c}function a(l){l.edges().forEach(c=>{let d=l.edge(c);if(d.reversed){l.removeEdge(c);let h=d.forwardName;delete d.reversed,delete d.forwardName,l.setEdge(c.w,c.v,d,h)}})}}),gf=Ae((e,n)=>{var s=Ge();n.exports={run:r,undo:o};function r(a){a.graph().dummyChains=[],a.edges().forEach(l=>i(a,l))}function i(a,l){let c=l.v,d=a.node(c).rank,h=l.w,f=a.node(h).rank,m=l.name,u=a.edge(l),x=u.labelRank;if(f===d+1)return;a.removeEdge(l);let E,S,v;for(v=0,++d;d<f;++v,++d)u.points=[],S={width:0,height:0,edgeLabel:u,edgeObj:l,rank:d},E=s.addDummyNode(a,"edge",S,"_d"),d===x&&(S.width=u.width,S.height=u.height,S.dummy="edge-label",S.labelpos=u.labelpos),a.setEdge(c,E,{weight:u.weight},m),v===0&&a.graph().dummyChains.push(E),c=E;a.setEdge(c,h,{weight:u.weight},m)}function o(a){a.graph().dummyChains.forEach(l=>{let c=a.node(l),d=c.edgeLabel,h;for(a.setEdge(c.edgeObj,d);c.dummy;)h=a.successors(l)[0],a.removeNode(l),d.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(d.x=c.x,d.y=c.y,d.width=c.width,d.height=c.height),l=h,c=a.node(l)})}}),$r=Ae((e,n)=>{var{applyWithChunking:s}=Ge();n.exports={longestPath:r,slack:i};function r(o){var a={};function l(c){var d=o.node(c);if(Object.hasOwn(a,c))return d.rank;a[c]=!0;let h=o.outEdges(c).map(m=>m==null?Number.POSITIVE_INFINITY:l(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(l)}function i(o,a){return o.node(a.w).rank-o.node(a.v).rank-o.edge(a).minlen}}),Vi=Ae((e,n)=>{var s=St().Graph,r=$r().slack;n.exports=i;function i(c){var d=new s({directed:!1}),h=c.nodes()[0],f=c.nodeCount();d.setNode(h,{});for(var m,u;o(d,c)<f;)m=a(d,c),u=d.hasNode(m.v)?r(c,m):-r(c,m),l(d,c,u);return d}function o(c,d){function h(f){d.nodeEdges(f).forEach(m=>{var u=m.v,x=f===u?m.w:u;!c.hasNode(x)&&!r(d,m)&&(c.setNode(x,{}),c.setEdge(f,x,{}),h(x))})}return c.nodes().forEach(h),c.nodeCount()}function a(c,d){return d.edges().reduce((h,f)=>{let m=Number.POSITIVE_INFINITY;return c.hasNode(f.v)!==c.hasNode(f.w)&&(m=r(d,f)),m<h[0]?[m,f]:h},[Number.POSITIVE_INFINITY,null])[1]}function l(c,d,h){c.nodes().forEach(f=>d.node(f).rank+=h)}}),pf=Ae((e,n)=>{var s=Vi(),r=$r().slack,i=$r().longestPath,o=St().alg.preorder,a=St().alg.postorder,l=Ge().simplify;n.exports=c,c.initLowLimValues=m,c.initCutValues=d,c.calcCutValue=f,c.leaveEdge=x,c.enterEdge=E,c.exchangeEdges=S;function c(b){b=l(b),i(b);var N=s(b);m(N),d(N,b);for(var w,M;w=x(N);)M=E(N,b,w),S(N,b,w,M)}function d(b,N){var w=a(b,b.nodes());w=w.slice(0,w.length-1),w.forEach(M=>h(b,N,M))}function h(b,N,w){var M=b.node(w),D=M.parent;b.edge(w,D).cutvalue=f(b,N,w)}function f(b,N,w){var M=b.node(w),D=M.parent,P=!0,_=N.edge(w,D),C=0;return _||(P=!1,_=N.edge(D,w)),C=_.weight,N.nodeEdges(w).forEach($=>{var z=$.v===w,j=z?$.w:$.v;if(j!==D){var B=z===P,R=N.edge($).weight;if(C+=B?R:-R,y(b,w,j)){var T=b.edge(w,j).cutvalue;C+=B?-T:T}}}),C}function m(b,N){arguments.length<2&&(N=b.nodes()[0]),u(b,{},1,N)}function u(b,N,w,M,D){var P=w,_=b.node(M);return N[M]=!0,b.neighbors(M).forEach(C=>{Object.hasOwn(N,C)||(w=u(b,N,w,C,M))}),_.low=P,_.lim=w++,D?_.parent=D:delete _.parent,w}function x(b){return b.edges().find(N=>b.edge(N).cutvalue<0)}function E(b,N,w){var M=w.v,D=w.w;N.hasEdge(M,D)||(M=w.w,D=w.v);var P=b.node(M),_=b.node(D),C=P,$=!1;P.lim>_.lim&&(C=_,$=!0);var z=N.edges().filter(j=>$===p(b,b.node(j.v),C)&&$!==p(b,b.node(j.w),C));return z.reduce((j,B)=>r(N,B)<r(N,j)?B:j)}function S(b,N,w,M){var D=w.v,P=w.w;b.removeEdge(D,P),b.setEdge(M.v,M.w,{}),m(b),d(b,N),v(b,N)}function v(b,N){var w=b.nodes().find(D=>!N.node(D).parent),M=o(b,w);M=M.slice(1),M.forEach(D=>{var P=b.node(D).parent,_=N.edge(D,P),C=!1;_||(_=N.edge(P,D),C=!0),N.node(D).rank=N.node(P).rank+(C?_.minlen:-_.minlen)})}function y(b,N,w){return b.hasEdge(N,w)}function p(b,N,w){return w.low<=N.lim&&N.lim<=w.lim}}),xf=Ae((e,n)=>{var s=$r(),r=s.longestPath,i=Vi(),o=pf();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":c(h);break;case"longest-path":l(h);break;case"none":break;default:d(h)}}var l=r;function c(h){r(h),i(h)}function d(h){o(h)}}),bf=Ae((e,n)=>{n.exports=s;function s(o){let a=i(o);o.graph().dummyChains.forEach(l=>{let c=o.node(l),d=c.edgeObj,h=r(o,a,d.v,d.w),f=h.path,m=h.lca,u=0,x=f[u],E=!0;for(;l!==d.w;){if(c=o.node(l),E){for(;(x=f[u])!==m&&o.node(x).maxRank<c.rank;)u++;x===m&&(E=!1)}if(!E){for(;u<f.length-1&&o.node(x=f[u+1]).minRank<=c.rank;)u++;x=f[u]}o.setParent(l,x),l=o.successors(l)[0]}})}function r(o,a,l,c){let d=[],h=[],f=Math.min(a[l].low,a[c].low),m=Math.max(a[l].lim,a[c].lim),u,x;u=l;do u=o.parent(u),d.push(u);while(u&&(a[u].low>f||m>a[u].lim));for(x=u,u=c;(u=o.parent(u))!==x;)h.push(u);return{path:d.concat(h.reverse()),lca:x}}function i(o){let a={},l=0;function c(d){let h=l;o.children(d).forEach(c),a[d]={low:h,lim:l++}}return o.children().forEach(c),a}}),yf=Ae((e,n)=>{var s=Ge();n.exports={run:r,cleanup:l};function r(c){let d=s.addDummyNode(c,"root",{},"_root"),h=o(c),f=Object.values(h),m=s.applyWithChunking(Math.max,f)-1,u=2*m+1;c.graph().nestingRoot=d,c.edges().forEach(E=>c.edge(E).minlen*=u);let x=a(c)+1;c.children().forEach(E=>i(c,d,u,x,m,h,E)),c.graph().nodeRankFactor=u}function i(c,d,h,f,m,u,x){let E=c.children(x);if(!E.length){x!==d&&c.setEdge(d,x,{weight:0,minlen:h});return}let S=s.addBorderNode(c,"_bt"),v=s.addBorderNode(c,"_bb"),y=c.node(x);c.setParent(S,x),y.borderTop=S,c.setParent(v,x),y.borderBottom=v,E.forEach(p=>{i(c,d,h,f,m,u,p);let b=c.node(p),N=b.borderTop?b.borderTop:p,w=b.borderBottom?b.borderBottom:p,M=b.borderTop?f:2*f,D=N!==w?1:m-u[x]+1;c.setEdge(S,N,{weight:M,minlen:D,nestingEdge:!0}),c.setEdge(w,v,{weight:M,minlen:D,nestingEdge:!0})}),c.parent(x)||c.setEdge(d,S,{weight:0,minlen:m+u[x]})}function o(c){var d={};function h(f,m){var u=c.children(f);u&&u.length&&u.forEach(x=>h(x,m+1)),d[f]=m}return c.children().forEach(f=>h(f,1)),d}function a(c){return c.edges().reduce((d,h)=>d+c.edge(h).weight,0)}function l(c){var d=c.graph();c.removeNode(d.nestingRoot),delete d.nestingRoot,c.edges().forEach(h=>{var f=c.edge(h);f.nestingEdge&&c.removeEdge(h)})}}),vf=Ae((e,n)=>{var s=Ge();n.exports=r;function r(o){function a(l){let c=o.children(l),d=o.node(l);if(c.length&&c.forEach(a),Object.hasOwn(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(let h=d.minRank,f=d.maxRank+1;h<f;++h)i(o,"borderLeft","_bl",l,d,h),i(o,"borderRight","_br",l,d,h)}}o.children().forEach(a)}function i(o,a,l,c,d,h){let f={width:0,height:0,rank:h,borderType:a},m=d[a][h-1],u=s.addDummyNode(o,"border",f,l);d[a][h]=u,o.setParent(u,c),m&&o.setEdge(m,u,{weight:1})}}),wf=Ae((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")&&(c(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=>l(h.node(f))),h.edges().forEach(f=>{let m=h.edge(f);m.points.forEach(l),Object.hasOwn(m,"y")&&l(m)})}function l(h){h.y=-h.y}function c(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}}),kf=Ae((e,n)=>{var s=Ge();n.exports=r;function r(i){let o={},a=i.nodes().filter(f=>!i.children(f).length),l=a.map(f=>i.node(f).rank),c=s.applyWithChunking(Math.max,l),d=s.range(c+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}}),jf=Ae((e,n)=>{var s=Ge().zipObject;n.exports=r;function r(o,a){let l=0;for(let c=1;c<a.length;++c)l+=i(o,a[c-1],a[c]);return l}function i(o,a,l){let c=s(l,l.map((x,E)=>E)),d=a.flatMap(x=>o.outEdges(x).map(E=>({pos:c[E.w],weight:o.edge(E).weight})).sort((E,S)=>E.pos-S.pos)),h=1;for(;h<l.length;)h<<=1;let f=2*h-1;h-=1;let m=new Array(f).fill(0),u=0;return d.forEach(x=>{let E=x.pos+h;m[E]+=x.weight;let S=0;for(;E>0;)E%2&&(S+=m[E+1]),E=E-1>>1,m[E]+=x.weight;u+=x.weight*S}),u}}),Nf=Ae((e,n)=>{n.exports=s;function s(r,i=[]){return i.map(o=>{let a=r.inEdges(o);if(a.length){let l=a.reduce((c,d)=>{let h=r.edge(d),f=r.node(d.v);return{sum:c.sum+h.weight*f.order,weight:c.weight+h.weight}},{sum:0,weight:0});return{v:o,barycenter:l.sum/l.weight,weight:l.weight}}else return{v:o}})}}),Cf=Ae((e,n)=>{var s=Ge();n.exports=r;function r(a,l){let c={};a.forEach((h,f)=>{let m=c[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:f};h.barycenter!==void 0&&(m.barycenter=h.barycenter,m.weight=h.weight)}),l.edges().forEach(h=>{let f=c[h.v],m=c[h.w];f!==void 0&&m!==void 0&&(m.indegree++,f.out.push(c[h.w]))});let d=Object.values(c).filter(h=>!h.indegree);return i(d)}function i(a){let l=[];function c(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();l.push(h),h.in.reverse().forEach(c(h)),h.out.forEach(d(h))}return l.filter(h=>!h.merged).map(h=>s.pick(h,["vs","i","barycenter","weight"]))}function o(a,l){let c=0,d=0;a.weight&&(c+=a.barycenter*a.weight,d+=a.weight),l.weight&&(c+=l.barycenter*l.weight,d+=l.weight),a.vs=l.vs.concat(a.vs),a.barycenter=c/d,a.weight=d,a.i=Math.min(l.i,a.i),l.merged=!0}}),Sf=Ae((e,n)=>{var s=Ge();n.exports=r;function r(a,l){let c=s.partition(a,S=>Object.hasOwn(S,"barycenter")),d=c.lhs,h=c.rhs.sort((S,v)=>v.i-S.i),f=[],m=0,u=0,x=0;d.sort(o(!!l)),x=i(f,h,x),d.forEach(S=>{x+=S.vs.length,f.push(S.vs),m+=S.barycenter*S.weight,u+=S.weight,x=i(f,h,x)});let E={vs:f.flat(!0)};return u&&(E.barycenter=m/u,E.weight=u),E}function i(a,l,c){let d;for(;l.length&&(d=l[l.length-1]).i<=c;)l.pop(),a.push(d.vs),c++;return c}function o(a){return(l,c)=>l.barycenter<c.barycenter?-1:l.barycenter>c.barycenter?1:a?c.i-l.i:l.i-c.i}}),Ef=Ae((e,n)=>{var s=Nf(),r=Cf(),i=Sf();n.exports=o;function o(c,d,h,f){let m=c.children(d),u=c.node(d),x=u?u.borderLeft:void 0,E=u?u.borderRight:void 0,S={};x&&(m=m.filter(b=>b!==x&&b!==E));let v=s(c,m);v.forEach(b=>{if(c.children(b.v).length){let N=o(c,b.v,h,f);S[b.v]=N,Object.hasOwn(N,"barycenter")&&l(b,N)}});let y=r(v,h);a(y,S);let p=i(y,f);if(x&&(p.vs=[x,p.vs,E].flat(!0),c.predecessors(x).length)){let b=c.node(c.predecessors(x)[0]),N=c.node(c.predecessors(E)[0]);Object.hasOwn(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+b.order+N.order)/(p.weight+2),p.weight+=2}return p}function a(c,d){c.forEach(h=>{h.vs=h.vs.flatMap(f=>d[f]?d[f].vs:f)})}function l(c,d){c.barycenter!==void 0?(c.barycenter=(c.barycenter*c.weight+d.barycenter*d.weight)/(c.weight+d.weight),c.weight+=d.weight):(c.barycenter=d.barycenter,c.weight=d.weight)}}),Mf=Ae((e,n)=>{var s=St().Graph,r=Ge();n.exports=i;function i(a,l,c,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),x=a.parent(m);(u.rank===l||u.minRank<=l&&l<=u.maxRank)&&(f.setNode(m),f.setParent(m,x||h),a[c](m).forEach(E=>{let S=E.v===m?E.w:E.v,v=f.edge(S,m),y=v!==void 0?v.weight:0;f.setEdge(S,m,{weight:a.edge(E).weight+y})}),Object.hasOwn(u,"minRank")&&f.setNode(m,{borderLeft:u.borderLeft[l],borderRight:u.borderRight[l]}))}),f}function o(a){for(var l;a.hasNode(l=r.uniqueId("_root")););return l}}),If=Ae((e,n)=>{n.exports=s;function s(r,i,o){let a={},l;o.forEach(c=>{let d=r.parent(c),h,f;for(;d;){if(h=r.parent(d),h?(f=a[h],a[h]=d):(f=l,l=d),f&&f!==d){i.setEdge(f,d);return}d=h}})}}),Tf=Ae((e,n)=>{var s=kf(),r=jf(),i=Ef(),o=Mf(),a=If(),l=St().Graph,c=Ge();n.exports=d;function d(u,x={}){if(typeof x.customOrder=="function"){x.customOrder(u,d);return}let E=c.maxRank(u),S=h(u,c.range(1,E+1),"inEdges"),v=h(u,c.range(E-1,-1,-1),"outEdges"),y=s(u);if(m(u,y),x.disableOptimalOrderHeuristic)return;let p=Number.POSITIVE_INFINITY,b,N=x.constraints||[];for(let w=0,M=0;M<4;++w,++M){f(w%2?S:v,w%4>=2,N),y=c.buildLayerMatrix(u);let D=r(u,y);D<p?(M=0,b=Object.assign({},y),p=D):D===p&&(b=structuredClone(y))}m(u,b)}function h(u,x,E){let S=new Map,v=(y,p)=>{S.has(y)||S.set(y,[]),S.get(y).push(p)};for(let y of u.nodes()){let p=u.node(y);if(typeof p.rank=="number"&&v(p.rank,y),typeof p.minRank=="number"&&typeof p.maxRank=="number")for(let b=p.minRank;b<=p.maxRank;b++)b!==p.rank&&v(b,y)}return x.map(function(y){return o(u,y,E,S.get(y)||[])})}function f(u,x,E){let S=new l;u.forEach(function(v){E.forEach(b=>S.setEdge(b.left,b.right));let y=v.graph().root,p=i(v,y,S,x);p.vs.forEach((b,N)=>v.node(b).order=N),a(v,S,p.vs)})}function m(u,x){Object.values(x).forEach(E=>E.forEach((S,v)=>u.node(S).order=v))}}),Rf=Ae((e,n)=>{var s=St().Graph,r=Ge();n.exports={positionX:E,findType1Conflicts:i,findType2Conflicts:o,addConflict:l,hasConflict:c,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:u,findSmallestWidthAlignment:m,balance:x};function i(y,p){let b={};function N(w,M){let D=0,P=0,_=w.length,C=M[M.length-1];return M.forEach(($,z)=>{let j=a(y,$),B=j?y.node(j).order:_;(j||$===C)&&(M.slice(P,z+1).forEach(R=>{y.predecessors(R).forEach(T=>{let A=y.node(T),L=A.order;(L<D||B<L)&&!(A.dummy&&y.node(R).dummy)&&l(b,T,R)})}),P=z+1,D=B)}),M}return p.length&&p.reduce(N),b}function o(y,p){let b={};function N(M,D,P,_,C){let $;r.range(D,P).forEach(z=>{$=M[z],y.node($).dummy&&y.predecessors($).forEach(j=>{let B=y.node(j);B.dummy&&(B.order<_||B.order>C)&&l(b,j,$)})})}function w(M,D){let P=-1,_,C=0;return D.forEach(($,z)=>{if(y.node($).dummy==="border"){let j=y.predecessors($);j.length&&(_=y.node(j[0]).order,N(D,C,z,P,_),C=z,P=_)}N(D,C,D.length,_,M.length)}),D}return p.length&&p.reduce(w),b}function a(y,p){if(y.node(p).dummy)return y.predecessors(p).find(b=>y.node(b).dummy)}function l(y,p,b){if(p>b){let w=p;p=b,b=w}let N=y[p];N||(y[p]=N={}),N[b]=!0}function c(y,p,b){if(p>b){let N=p;p=b,b=N}return!!y[p]&&Object.hasOwn(y[p],b)}function d(y,p,b,N){let w={},M={},D={};return p.forEach(P=>{P.forEach((_,C)=>{w[_]=_,M[_]=_,D[_]=C})}),p.forEach(P=>{let _=-1;P.forEach(C=>{let $=N(C);if($.length){$=$.sort((j,B)=>D[j]-D[B]);let z=($.length-1)/2;for(let j=Math.floor(z),B=Math.ceil(z);j<=B;++j){let R=$[j];M[C]===C&&_<D[R]&&!c(b,C,R)&&(M[R]=C,M[C]=w[C]=w[R],_=D[R])}}})}),{root:w,align:M}}function h(y,p,b,N,w){let M={},D=f(y,p,b,w),P=w?"borderLeft":"borderRight";function _(z,j){let B=D.nodes().slice(),R={},T=B.pop();for(;T;){if(R[T])z(T);else{R[T]=!0,B.push(T);for(let A of j(T))B.push(A)}T=B.pop()}}function C(z){M[z]=D.inEdges(z).reduce((j,B)=>Math.max(j,M[B.v]+D.edge(B)),0)}function $(z){let j=D.outEdges(z).reduce((R,T)=>Math.min(R,M[T.w]-D.edge(T)),Number.POSITIVE_INFINITY),B=y.node(z);j!==Number.POSITIVE_INFINITY&&B.borderType!==P&&(M[z]=Math.max(M[z],j))}return _(C,D.predecessors.bind(D)),_($,D.successors.bind(D)),Object.keys(N).forEach(z=>M[z]=M[b[z]]),M}function f(y,p,b,N){let w=new s,M=y.graph(),D=S(M.nodesep,M.edgesep,N);return p.forEach(P=>{let _;P.forEach(C=>{let $=b[C];if(w.setNode($),_){var z=b[_],j=w.edge(z,$);w.setEdge(z,$,Math.max(D(y,C,_),j||0))}_=C})}),w}function m(y,p){return Object.values(p).reduce((b,N)=>{let w=Number.NEGATIVE_INFINITY,M=Number.POSITIVE_INFINITY;Object.entries(N).forEach(([P,_])=>{let C=v(y,P)/2;w=Math.max(_+C,w),M=Math.min(_-C,M)});let D=w-M;return D<b[0]&&(b=[D,N]),b},[Number.POSITIVE_INFINITY,null])[1]}function u(y,p){let b=Object.values(p),N=r.applyWithChunking(Math.min,b),w=r.applyWithChunking(Math.max,b);["u","d"].forEach(M=>{["l","r"].forEach(D=>{let P=M+D,_=y[P];if(_===p)return;let C=Object.values(_),$=N-r.applyWithChunking(Math.min,C);D!=="l"&&($=w-r.applyWithChunking(Math.max,C)),$&&(y[P]=r.mapValues(_,z=>z+$))})})}function x(y,p){return r.mapValues(y.ul,(b,N)=>{if(p)return y[p.toLowerCase()][N];{let w=Object.values(y).map(M=>M[N]).sort((M,D)=>M-D);return(w[1]+w[2])/2}})}function E(y){let p=r.buildLayerMatrix(y),b=Object.assign(i(y,p),o(y,p)),N={},w;["u","d"].forEach(D=>{w=D==="u"?p:Object.values(p).reverse(),["l","r"].forEach(P=>{P==="r"&&(w=w.map(z=>Object.values(z).reverse()));let _=(D==="u"?y.predecessors:y.successors).bind(y),C=d(y,w,b,_),$=h(y,w,C.root,C.align,P==="r");P==="r"&&($=r.mapValues($,z=>-z)),N[D+P]=$})});let M=m(y,N);return u(N,M),x(N,y.graph().align)}function S(y,p,b){return(N,w,M)=>{let D=N.node(w),P=N.node(M),_=0,C;if(_+=D.width/2,Object.hasOwn(D,"labelpos"))switch(D.labelpos.toLowerCase()){case"l":C=-D.width/2;break;case"r":C=D.width/2;break}if(C&&(_+=b?C:-C),C=0,_+=(D.dummy?p:y)/2,_+=(P.dummy?p:y)/2,_+=P.width/2,Object.hasOwn(P,"labelpos"))switch(P.labelpos.toLowerCase()){case"l":C=P.width/2;break;case"r":C=-P.width/2;break}return C&&(_+=b?C:-C),C=0,_}}function v(y,p){return y.node(p).width}}),_f=Ae((e,n)=>{var s=Ge(),r=Rf().positionX;n.exports=i;function i(a){a=s.asNonCompoundGraph(a),o(a),Object.entries(r(a)).forEach(([l,c])=>a.node(l).x=c)}function o(a){let l=s.buildLayerMatrix(a),c=a.graph().ranksep,d=a.graph().rankalign,h=0;l.forEach(f=>{let m=f.reduce((u,x)=>{let E=a.node(x).height;return u>E?u:E},0);f.forEach(u=>{let x=a.node(u);d==="top"?x.y=h+x.height/2:d==="bottom"?x.y=h+m-x.height/2:x.y=h+m/2}),h+=m+c})}}),Af=Ae((e,n)=>{var s=mf(),r=gf(),i=xf(),o=Ge().normalizeRanks,a=bf(),l=Ge().removeEmptyRanks,c=yf(),d=vf(),h=wf(),f=Tf(),m=_f(),u=Ge(),x=St().Graph;n.exports=E;function E(I,H={}){let V=H.debugTiming?u.time:u.notime;return V("layout",()=>{let W=V(" buildLayoutGraph",()=>_(I));return V(" runLayout",()=>S(W,V,H)),V(" updateInputGraph",()=>v(I,W)),W})}function S(I,H,V){H(" makeSpaceForEdgeLabels",()=>C(I)),H(" removeSelfEdges",()=>q(I)),H(" acyclic",()=>s.run(I)),H(" nestingGraph.run",()=>c.run(I)),H(" rank",()=>i(u.asNonCompoundGraph(I))),H(" injectEdgeLabelProxies",()=>$(I)),H(" removeEmptyRanks",()=>l(I)),H(" nestingGraph.cleanup",()=>c.cleanup(I)),H(" normalizeRanks",()=>o(I)),H(" assignRankMinMax",()=>z(I)),H(" removeEdgeLabelProxies",()=>j(I)),H(" normalize.run",()=>r.run(I)),H(" parentDummyChains",()=>a(I)),H(" addBorderSegments",()=>d(I)),H(" order",()=>f(I,V)),H(" insertSelfEdges",()=>F(I)),H(" adjustCoordinateSystem",()=>h.adjust(I)),H(" position",()=>m(I)),H(" positionSelfEdges",()=>Y(I)),H(" removeBorderNodes",()=>L(I)),H(" normalize.undo",()=>r.undo(I)),H(" fixupEdgeLabelCoords",()=>T(I)),H(" undoCoordinateSystem",()=>h.undo(I)),H(" translateGraph",()=>B(I)),H(" assignNodeIntersects",()=>R(I)),H(" reversePoints",()=>A(I)),H(" acyclic.undo",()=>s.undo(I))}function v(I,H){I.nodes().forEach(V=>{let W=I.node(V),X=H.node(V);W&&(W.x=X.x,W.y=X.y,W.order=X.order,W.rank=X.rank,H.children(V).length&&(W.width=X.width,W.height=X.height))}),I.edges().forEach(V=>{let W=I.edge(V),X=H.edge(V);W.points=X.points,Object.hasOwn(X,"x")&&(W.x=X.x,W.y=X.y)}),I.graph().width=H.graph().width,I.graph().height=H.graph().height}var y=["nodesep","edgesep","ranksep","marginx","marginy"],p={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},b=["acyclicer","ranker","rankdir","align","rankalign"],N=["width","height","rank"],w={width:0,height:0},M=["minlen","weight","width","height","labeloffset"],D={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},P=["labelpos"];function _(I){let H=new x({multigraph:!0,compound:!0}),V=O(I.graph());return H.setGraph(Object.assign({},p,Q(V,y),u.pick(V,b))),I.nodes().forEach(W=>{let X=O(I.node(W)),ee=Q(X,N);Object.keys(w).forEach(se=>{ee[se]===void 0&&(ee[se]=w[se])}),H.setNode(W,ee),H.setParent(W,I.parent(W))}),I.edges().forEach(W=>{let X=O(I.edge(W));H.setEdge(W,Object.assign({},D,Q(X,M),u.pick(X,P)))}),H}function C(I){let H=I.graph();H.ranksep/=2,I.edges().forEach(V=>{let W=I.edge(V);W.minlen*=2,W.labelpos.toLowerCase()!=="c"&&(H.rankdir==="TB"||H.rankdir==="BT"?W.width+=W.labeloffset:W.height+=W.labeloffset)})}function $(I){I.edges().forEach(H=>{let V=I.edge(H);if(V.width&&V.height){let W=I.node(H.v),X={rank:(I.node(H.w).rank-W.rank)/2+W.rank,e:H};u.addDummyNode(I,"edge-proxy",X,"_ep")}})}function z(I){let H=0;I.nodes().forEach(V=>{let W=I.node(V);W.borderTop&&(W.minRank=I.node(W.borderTop).rank,W.maxRank=I.node(W.borderBottom).rank,H=Math.max(H,W.maxRank))}),I.graph().maxRank=H}function j(I){I.nodes().forEach(H=>{let V=I.node(H);V.dummy==="edge-proxy"&&(I.edge(V.e).labelRank=V.rank,I.removeNode(H))})}function B(I){let H=Number.POSITIVE_INFINITY,V=0,W=Number.POSITIVE_INFINITY,X=0,ee=I.graph(),se=ee.marginx||0,J=ee.marginy||0;function U(oe){let le=oe.x,ie=oe.y,he=oe.width,de=oe.height;H=Math.min(H,le-he/2),V=Math.max(V,le+he/2),W=Math.min(W,ie-de/2),X=Math.max(X,ie+de/2)}I.nodes().forEach(oe=>U(I.node(oe))),I.edges().forEach(oe=>{let le=I.edge(oe);Object.hasOwn(le,"x")&&U(le)}),H-=se,W-=J,I.nodes().forEach(oe=>{let le=I.node(oe);le.x-=H,le.y-=W}),I.edges().forEach(oe=>{let le=I.edge(oe);le.points.forEach(ie=>{ie.x-=H,ie.y-=W}),Object.hasOwn(le,"x")&&(le.x-=H),Object.hasOwn(le,"y")&&(le.y-=W)}),ee.width=V-H+se,ee.height=X-W+J}function R(I){I.edges().forEach(H=>{let V=I.edge(H),W=I.node(H.v),X=I.node(H.w),ee,se;V.points?(ee=V.points[0],se=V.points[V.points.length-1]):(V.points=[],ee=X,se=W),V.points.unshift(u.intersectRect(W,ee)),V.points.push(u.intersectRect(X,se))})}function T(I){I.edges().forEach(H=>{let V=I.edge(H);if(Object.hasOwn(V,"x"))switch((V.labelpos==="l"||V.labelpos==="r")&&(V.width-=V.labeloffset),V.labelpos){case"l":V.x-=V.width/2+V.labeloffset;break;case"r":V.x+=V.width/2+V.labeloffset;break}})}function A(I){I.edges().forEach(H=>{let V=I.edge(H);V.reversed&&V.points.reverse()})}function L(I){I.nodes().forEach(H=>{if(I.children(H).length){let V=I.node(H),W=I.node(V.borderTop),X=I.node(V.borderBottom),ee=I.node(V.borderLeft[V.borderLeft.length-1]),se=I.node(V.borderRight[V.borderRight.length-1]);V.width=Math.abs(se.x-ee.x),V.height=Math.abs(X.y-W.y),V.x=ee.x+V.width/2,V.y=W.y+V.height/2}}),I.nodes().forEach(H=>{I.node(H).dummy==="border"&&I.removeNode(H)})}function q(I){I.edges().forEach(H=>{if(H.v===H.w){var V=I.node(H.v);V.selfEdges||(V.selfEdges=[]),V.selfEdges.push({e:H,label:I.edge(H)}),I.removeEdge(H)}})}function F(I){var H=u.buildLayerMatrix(I);H.forEach(V=>{var W=0;V.forEach((X,ee)=>{var se=I.node(X);se.order=ee+W,(se.selfEdges||[]).forEach(J=>{u.addDummyNode(I,"selfedge",{width:J.label.width,height:J.label.height,rank:se.rank,order:ee+ ++W,e:J.e,label:J.label},"_se")}),delete se.selfEdges})})}function Y(I){I.nodes().forEach(H=>{var V=I.node(H);if(V.dummy==="selfedge"){var W=I.node(V.e.v),X=W.x+W.width/2,ee=W.y,se=V.x-X,J=W.height/2;I.setEdge(V.e,V.label),I.removeNode(H),V.label.points=[{x:X+2*se/3,y:ee-J},{x:X+5*se/6,y:ee-J},{x:X+se,y:ee},{x:X+5*se/6,y:ee+J},{x:X+2*se/3,y:ee+J}],V.label.x=V.x,V.label.y=V.y}})}function Q(I,H){return u.mapValues(u.pick(I,H),Number)}function O(I){var H={};return I&&Object.entries(I).forEach(([V,W])=>{typeof V=="string"&&(V=V.toLowerCase()),H[V]=W}),H}}),Lf=Ae((e,n)=>{var s=Ge(),r=St().Graph;n.exports={debugOrdering:i};function i(o){let a=s.buildLayerMatrix(o),l=new r({compound:!0,multigraph:!0}).setGraph({});return o.nodes().forEach(c=>{l.setNode(c,{label:c}),l.setParent(c,"layer"+o.node(c).rank)}),o.edges().forEach(c=>l.setEdge(c.v,c.w,{},c.name)),a.forEach((c,d)=>{let h="layer"+d;l.setNode(h,{rank:"same"}),c.reduce((f,m)=>(l.setEdge(f,m,{style:"invis"}),m))}),l}}),Df=Ae((e,n)=>{n.exports="2.0.4"}),Pf=Ae((e,n)=>{n.exports={graphlib:St(),layout:Af(),debug:Lf(),util:{time:Ge().time,notime:Ge().notime},version:Df()}});const Qo=Pf();const Jo={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"}},$f={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function Bf({data:e}){const{t:n}=He(["work","common"]),{task:s,agentName:r,selected:i,direction:o="TB",isExpandedRoot:a,onCollapse:l}=e,c=Jo[s.status]??Jo.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"?ye.Left:ye.Top,m=o==="LR"?ye.Right:ye.Bottom;return t.jsxs("div",{className:`relative rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${d?`${c.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${c.bg} ${c.border}`} ${i?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[t.jsx(Jt,{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 ${$f[s.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${c.text}`,children:n(`work:status.task.${s.status}`,{defaultValue:s.status.replace("_"," ")})}),d&&t.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/15 text-blue-600 ml-auto whitespace-nowrap inline-flex items-center gap-0.5",children:[t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})}),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(Jt,{type:"source",position:m,className:"!bg-border-default !w-2 !h-2"}),a&&l&&t.jsx("button",{onClick:u=>{u.stopPropagation(),l()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const ea={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"}},ta={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function Of({data:e}){const{t:n}=He(["work","common"]),{req:s,selected:r,direction:i="TB",isExpandedRoot:o,onCollapse:a}=e,l=ea[s.status]??ea.pending,c=i==="LR"?ye.Left:ye.Top,d=i==="LR"?ye.Right:ye.Bottom;return t.jsxs("div",{className:`relative rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${l.bg} ${l.border} ${r?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[t.jsx(Jt,{type:"target",position:c,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:n("work:dag.reqLabel")}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${l.text}`,children:n(`work:status.requirement.${s.status}`,{defaultValue:s.status.replace("_"," ")})})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:s.title}),s.taskIds.length>0&&t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:n("work:dag.taskCount",{count:s.taskIds.length})}),t.jsx(Jt,{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 zf={task:Bf,requirement:Of};function Hf({nodeIds:e,rfRef:n}){const s=Lu();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 qf=()=>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,Vf=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 Wf(){return g.useSyncExternalStore(Vf,qf,()=>!1)}const _r=200,Ar=80;function na(e,n,s="TB"){const r=o=>{const a=new Qo.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:o,nodesep:40,ranksep:60});for(const l of e)a.setNode(l.id,{width:_r,height:Ar});for(const l of n)a.setEdge(l.source,l.target);return Qo.layout(a),e.map(l=>{const c=a.node(l.id);return{...l,position:{x:(c?.x??0)-_r/2,y:(c?.y??0)-Ar/2}}})},i=r(s);if(n.length>0&&e.length>4){let o=1/0,a=-1/0,l=1/0,c=-1/0;for(const m of i)o=Math.min(o,m.position.x),a=Math.max(a,m.position.x+_r),l=Math.min(l,m.position.y),c=Math.max(c,m.position.y+Ar);const d=a-o,h=c-l,f=s==="TB"?"LR":"TB";if(d>h*3)return{nodes:r(f),direction:f}}return{nodes:i,direction:s}}function Ff(e,n){const s=new Map,r=new Map;for(const a of e)r.set(a.id,a),s.set(a.id,new Set);for(const a of n)s.get(a.source)?.add(a.target),s.get(a.target)?.add(a.source);const i=new Set,o=[];for(const a of e){if(i.has(a.id))continue;const l=new Set,c=[a.id];for(;c.length>0;){const d=c.pop();if(!i.has(d)){i.add(d),l.add(d);for(const h of s.get(d)??[])i.has(h)||c.push(h)}}o.push({nodes:e.filter(d=>l.has(d.id)),edges:n.filter(d=>l.has(d.source)&&l.has(d.target))})}return o}function ra(e,n){if(e.length===0)return{nodes:[],direction:"TB"};const s=Ff(e,n);if(s.length===1)return na(e,n);let r="TB";const i=s.map(m=>{const{nodes:u,direction:x}=na(m.nodes,m.edges);r=x;let E=1/0,S=-1/0,v=1/0,y=-1/0;for(const p of u)E=Math.min(E,p.position.x),S=Math.max(S,p.position.x+_r),v=Math.min(v,p.position.y),y=Math.max(y,p.position.y+Ar);for(const p of u)p.position.x-=E,p.position.y-=v;return{nodes:u,w:S-E,h:y-v}});i.sort((m,u)=>u.h-m.h);const o=60,a=i.reduce((m,u)=>m+(u.w+o)*(u.h+o),0),l=Math.sqrt(a)*1.1,c=[];let d=0,h=0,f=0;for(const m of i){d>0&&d+m.w>l&&(d=0,h+=f+o,f=0);for(const u of m.nodes)c.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:c,direction:r}}function Yf(e,n,s){const r=new Set,i=[n];for(;i.length>0;){const o=i.pop();if(o===s)return!0;if(r.has(o))continue;r.add(o);const a=e.get(o);if(a?.blockedBy)for(const l of a.blockedBy)i.push(l)}return!1}const In=[{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(In.map(e=>e.id));const Er=new Set(In.filter(e=>e.id!=="done").map(e=>e.id)),sa=e=>e.status==="archived";function Gf(e,n,s,r){const i=new Set,o=[e];for(;o.length>0;){const a=o.pop();if(!i.has(a))if(i.add(a),a.startsWith("req-")){const l=s.get(a.slice(4));if(l)for(const c of l.taskIds)o.push(c)}else{const l=n.get(a);if(l?.blockedBy)for(const c of l.blockedBy)o.push(c);l?.requirementId&&o.push(`req-${l.requirementId}`)}}for(const a of r)a.requirementId&&i.has(a.id)&&i.add(`req-${a.requirementId}`);return i}function Zf({tasks:e,requirements:n=[],agents:s,showArchived:r,onShowArchivedChange:i,onTaskClick:o,onReqClick:a,onCollapseDAG:l,onDependencyChange:c,selectedTaskId:d,selectedReqId:h,hasDetailPanel:f,defaultExpandedNodeId:m,previewMode:u}){const{t:x}=He(["work","common"]),E=Wf(),[S,v]=g.useState(null),[y,p]=g.useState(null),[b,N]=g.useState(()=>new Set(Er)),[w,M]=g.useState(m??null),[D,P]=g.useState(r??!1),_=r??D,C=g.useCallback(ce=>{const te=typeof ce=="function"?ce(_):ce;P(te),i?.(te)},[_,i]);g.useEffect(()=>{r!==void 0&&P(r)},[r]),g.useEffect(()=>{m&&M(m)},[m]);const $=g.useMemo(()=>e.filter(ce=>sa(ce)).length,[e]),z=g.useMemo(()=>{const ce=new Set;for(const te of In)if(b.has(te.id))for(const pe of te.statuses)ce.add(pe);return ce},[b]),j=g.useMemo(()=>{const ce=new Set;for(const te of e)for(const pe of In)if(pe.statuses.has(te.status)){ce.add(pe.id);break}for(const te of n){const pe=ta[te.status];pe&&ce.add(pe)}return In.filter(te=>ce.has(te.id))},[e,n]),B=g.useCallback(ce=>{N(te=>{const pe=new Set(te);return pe.has(ce)?pe.delete(ce):pe.add(ce),pe})},[]),R=g.useCallback((ce,te="success")=>{v({msg:ce,type:te}),setTimeout(()=>v(null),2500)},[]),T=g.useMemo(()=>{const ce=new Map;for(const te of s)ce.set(te.id,te.name);return ce},[s]),A=g.useMemo(()=>{const ce=new Map;for(const te of e)ce.set(te.id,te);return ce},[e]),L=g.useMemo(()=>{const ce=new Map;for(const te of n)ce.set(te.id,te);return ce},[n]),q=g.useRef(!1),F=g.useCallback(()=>{q.current=!1,M(null),l?.()},[l]),Y=E?"#94a3b8":"#6b7280",Q=g.useCallback((ce,te,pe)=>({id:`${ce}->${te}`,source:ce,target:te,animated:pe==="blocked",markerEnd:{type:_n.ArrowClosed,width:14,height:14,color:pe==="blocked"?"#ef4444":Y},style:{stroke:pe==="blocked"?"#ef4444":Y,strokeWidth:1.5,cursor:"pointer"}}),[Y]),{initialNodes:O,initialEdges:I,topLevelIds:H}=g.useMemo(()=>{const ce=(we,Xe)=>{const _e=new Set,Te=we.map(Ee=>(_e.add(Ee.id),{id:Ee.id,type:"task",data:{task:Ee,agentName:Ee.assignedAgentId?T.get(Ee.assignedAgentId):void 0,selected:Ee.id===d},position:{x:0,y:0}}));for(const Ee of Xe){const Fe=`req-${Ee.id}`;_e.add(Fe),Te.push({id:Fe,type:"requirement",data:{req:Ee,selected:Ee.id===h},position:{x:0,y:0}})}const Le=[];for(const Ee of we)if(Ee.blockedBy)for(const Fe of Ee.blockedBy)_e.has(Fe)&&Le.push(Q(Fe,Ee.id,Ee.status));const lt=new Set,Pt=(Ee,Fe)=>{const rt=`${Ee}->${Fe}`;lt.has(rt)||(lt.add(rt),Le.push({id:rt,source:Ee,target:Fe,markerEnd:{type:_n.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ee of Xe){const Fe=`req-${Ee.id}`;for(const rt of Ee.taskIds)_e.has(rt)&&Pt(Fe,rt)}for(const Ee of we)if(Ee.requirementId){const Fe=`req-${Ee.requirementId}`;_e.has(Fe)&&Pt(Fe,Ee.id)}return{nodes:Te,edges:Le}},te=e.filter(we=>z.has(we.status)&&(_||!sa(we))),pe=new Set;for(const we of In)b.has(we.id)&&pe.add(we.id);const Re=n.filter(we=>{const Xe=ta[we.status];return Xe&&pe.has(Xe)}),{nodes:be,edges:Ie}=ce(te,Re),mt=new Set;for(const we of Ie)mt.add(we.target);const nt=new Set(be.filter(we=>!mt.has(we.id)).map(we=>we.id));if(!w||!nt.has(w)){const we=be.filter(Le=>nt.has(Le.id)),{nodes:Xe,direction:_e}=ra(we,[]);return{initialNodes:Xe.map(Le=>({...Le,data:{...Le.data,direction:_e}})),initialEdges:[],topLevelIds:nt}}const{nodes:yt,edges:ot}=ce(e,n),gt=Gf(w,A,L,e),Et=yt.filter(we=>gt.has(we.id)).map(we=>we.id===w?{...we,data:{...we.data,isExpandedRoot:!0,onCollapse:F}}:we),Ve=ot.filter(we=>gt.has(we.source)&&gt.has(we.target)),{nodes:ze,direction:Pe}=ra(Et,Ve);return{initialNodes:ze.map(we=>({...we,data:{...we.data,direction:Pe}})),initialEdges:Ve,topLevelIds:nt}},[e,n,T,A,L,Q,z,b,_,d,h,w,F]),[V,W,X]=Du(O),[ee,se,J]=Pu(I),U=g.useRef(null),oe=g.useRef({groupFilter:b,showArchived:_});g.useEffect(()=>{const ce=oe.current;(ce.groupFilter!==b||ce.showArchived!==_)&&(q.current=!1,M(null),oe.current={groupFilter:b,showArchived:_})},[b,_]),g.useEffect(()=>{W(O),se(I),q.current||requestAnimationFrame(()=>{U.current?.fitView({padding:.2,duration:300})})},[O,I,W,se]),g.useEffect(()=>{const ce=setTimeout(()=>{U.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(ce)},[f]);const le=g.useCallback(ce=>{ce&&(q.current=!0)},[]),ie=g.useCallback((ce,te)=>{if(!w&&H.has(te.id)&&(q.current=!1,M(te.id)),te.id.startsWith("req-")){const pe=L.get(te.id.slice(4));pe&&a&&a(pe)}else{const pe=A.get(te.id);pe&&o&&o(pe)}},[A,L,o,a,H,w]),he=g.useCallback(async ce=>{const{source:te,target:pe}=ce;if(!te||!pe||te===pe)return;const Re=A.get(pe);if(!Re)return;if(Re.blockedBy?.includes(te)){R(x("work:dag.toast.dependencyExists"),"error");return}if(Yf(A,te,pe)){R(x("work:dag.toast.cycleError"),"error");return}const be=[...Re.blockedBy??[],te];try{await re.tasks.update(pe,{blockedBy:be}),R(x("work:dag.toast.dependencyAdded")),c?.()}catch(Ie){R(x("work:dag.toast.failed",{message:Ie instanceof Error?Ie.message:String(Ie)}),"error")}},[A,R,c,x]),de=g.useCallback((ce,te)=>{p(te)},[]),Z=g.useCallback(async()=>{if(!y)return;const ce=A.get(y.target);if(!ce){p(null);return}const te=(ce.blockedBy??[]).filter(pe=>pe!==y.source);try{await re.tasks.update(y.target,{blockedBy:te}),R(x("work:dag.toast.dependencyRemoved")),c?.()}catch(pe){R(x("work:dag.toast.failed",{message:pe instanceof Error?pe.message:String(pe)}),"error")}p(null)},[y,A,R,c,x]);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:x("work:task.dagEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:x("work:task.dagEmptyDesc")})]})});const ae=b.size===Er.size&&[...Er].every(ce=>b.has(ce))&&!_,me=y?A.get(y.source):null,ve=y?A.get(y.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(Au,{nodes:V,edges:ee,onNodesChange:X,onEdgesChange:J,onNodeClick:ie,onConnect:he,onEdgeClick:de,onMoveEnd:le,onInit:ce=>{U.current=ce},nodeTypes:zf,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[u&&t.jsx(Hf,{nodeIds:V.map(ce=>ce.id),rfRef:U}),t.jsx(Hu,{color:E?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(Zu,{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(lf,{nodeColor:ce=>{const te=ce.data?.task,pe=te?.status;return te?.taskType==="scheduled"?"#8b8fa3":pe==="completed"||pe==="accepted"?"#10b981":pe==="in_progress"?"#f59e0b":pe==="blocked"||pe==="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(ce=>{const te=b.has(ce.id);return t.jsx("button",{onClick:()=>B(ce.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${te?`${ce.color.bg} ${ce.color.border} ${ce.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:x(`work:dag.filter.${ce.id}`)},ce.id)}),$>0&&t.jsx("button",{onClick:()=>C(ce=>!ce),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${_?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:x("work:dag.archivedToggle",{count:$})}),!ae&&t.jsx("button",{onClick:()=>{N(new Set(Er)),C(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:x("work:dag.reset")})]}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[w?t.jsx("button",{onClick:F,className:"text-brand-500 hover:text-brand-400 transition-colors",children:x("work:dag.backToOverview")}):t.jsx("span",{children:x("work:dag.expandHint")}),t.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),t.jsx("span",{children:x("work:dag.dragHint")})]})]}),S&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${S.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:S.msg}),y&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>p(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:ce=>ce.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:x("work:dag.removeDependencyTitle")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:x("work:dag.removeDependencyBody",{target:ve?.title??y.target.slice(-8),source:me?.title??y.source.slice(-8)})}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>p(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:x("common:cancel")}),t.jsx("button",{onClick:Z,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:x("common:remove")})]})]})})]})}function Xf({orgId:e,onCreated:n,onClose:s}){const{t:r}=He(["work","common"]);ml(!0);const[i,o]=g.useState(""),[a,l]=g.useState(""),[c,d]=g.useState(""),[h,f]=g.useState("main"),[m,u]=g.useState([]),[x,E]=g.useState([]),[S,v]=g.useState(!1),[y,p]=g.useState(""),[b,N]=g.useState(!1),w=rr();g.useEffect(()=>{re.teams.list().then(P=>E(P.teams)).catch(()=>{})},[]),g.useEffect(()=>{const P=_=>{_.key==="Escape"&&s()};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[s]);const M=g.useCallback(async P=>{if(P?.preventDefault(),N(!0),!(!i.trim()||S)){v(!0),p("");try{const _=c.trim()?[{url:c.trim(),defaultBranch:h.trim()||"main"}]:[],C=await re.projects.create({name:i.trim(),description:a.trim()||void 0,repositories:_.length>0?_:void 0,teamIds:m.length>0?m:void 0,orgId:e??"default"});n(C.project)}catch(_){p(_ instanceof Error?_.message:r("project.failedToCreate"))}v(!1)}},[i,a,c,h,m,e,S,n,r]),D=b&&!i.trim();return gl.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 ${w?"w-full":"w-[520px]"}`,onClick:P=>P.stopPropagation(),onSubmit:M,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:P=>{o(P.target.value),p("")},onBlur:()=>N(!0),placeholder:r("project.projectNamePlaceholder"),className:`input ${D?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!w}),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:P=>l(P.target.value),placeholder:r("project.descriptionPlaceholder"),className:"input",rows:3})]}),x.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:x.map(P=>{const _=m.includes(P.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:_,onChange:()=>u(C=>_?C.filter($=>$!==P.id):[...C,P.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:P.name})]},P.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:c,onChange:P=>d(P.target.value),placeholder:r("project.repositoryPlaceholder"),className:"input"})]}),c.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:P=>f(P.target.value),placeholder:r("project.branchPlaceholder"),className:"input !w-24"})]})]}),y&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:y}),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()||S,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:r(S?"common:creating":"project.createProject")})]})]})]})}),document.body)}function Ls(e){const n=e.agentId,s=e.activityId;return!n||!s?null:Ca({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},s,n)}function Ds(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 Ps({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(vl,{entries:e,isActive:!0,onExpand:()=>s("full"),embedded:!0}):t.jsx(Sa,{entries:e,isActive:!0,onCollapse:()=>s("compact"),embedded:!0})})}function Wi(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,l=window.innerHeight-o.bottom-8,c=o.top-8,d=l<a&&c>l;r(d?{top:o.top-4,left:o.left,width:o.width,flipUp:!0}:{top:o.bottom+4,left:o.left,width:o.width,flipUp:!1})};return i(),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[n,e]),s}function Yn({options:e,value:n,onChange:s,placeholder:r,noMatchesText:i,className:o}){const[a,l]=g.useState(!1),[c,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),x=Wi(f,a);g.useEffect(()=>{const v=y=>{h.current&&!h.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const E=e.find(v=>v.value===n)?.label??"",S=c?e.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):e;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{l(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:c,onChange:v=>d(v.target.value),onClick:v=>v.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder: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&&x&&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:x.flipUp?{bottom:window.innerHeight-x.top,left:x.left,width:x.width}:{top:x.top,left:x.left,width:x.width},children:S.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):S.map(v=>t.jsx("div",{onClick:()=>{s(v.value),l(!1),d("")},className:`px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 ${v.value===n?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:v.label},v.value))})]})}function Uf({options:e,selected:n,onAdd:s,placeholder:r,noMatchesText:i,className:o}){const[a,l]=g.useState(!1),[c,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),x=Wi(f,a);g.useEffect(()=>{const v=y=>{h.current&&!h.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const E=e.filter(v=>!n.includes(v.value)),S=c?E.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):E;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{l(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:c,onChange:v=>d(v.target.value),onClick:v=>v.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:r,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&x&&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:x.flipUp?{bottom:window.innerHeight-x.top,left:x.left,width:x.width}:{top:x.top,left:x.left,width:x.width},children:S.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):S.map(v=>t.jsx("div",{onClick:()=>{s(v.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:v.label},v.value))})]})}function $n(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 oa({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=He(["work","common"]),[o,a]=g.useState(!1),[l,c]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{c(e)},[e]),g.useEffect(()=>{o&&d.current?.focus()},[o]);const h=async()=>{a(!1);const f=l.trim();if(f&&f!==e)try{await n(f)}catch{c(e)}else c(e)};return o?t.jsx("input",{ref:d,value:l,onChange:f=>c(f.target.value),onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&h(),f.key==="Escape"&&(c(e),a(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${s??""}`,placeholder:r}):t.jsx("span",{onClick:()=>a(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.clickToEdit")})})}function Kf({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=He(["work","common"]),[o,a]=g.useState(!1),[l,c]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{c(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=l.trim();if(f!==e)try{await n(f)}catch{c(e)}else c(e)};return o?t.jsx("textarea",{ref:d,value:l,onChange:f=>{c(f.target.value),f.target.style.height="auto",f.target.style.height=f.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Escape"&&(c(e),a(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${s??""}`,placeholder:r,rows:2}):t.jsx("p",{onClick:()=>a(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.addDescription")})})}const Qf=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function Fi(e){const n=e.match(Qf);return n?{timestamp:n[1].trim(),author:n[2]?.trim()??"System",content:n[3].trim()}:{timestamp:"",author:"",content:e}}function Jf(e,n){if(!e)return"";const s=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!s)return e;const r=new Date,i=+s[1],o=+s[2]-1,a=+s[3],l=+s[4],c=+s[5],d=new Date(i,o,a,l,c),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 eh(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 th({note:e,compact:n}){const{t:s}=He(["work","common"]),r=Fi(e),i=s("work:task.systemAuthor"),o=eh(r.author||i),a=r.author?r.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",l=Jf(r.timestamp,s),c=!r.author||r.author==="System";return n?t.jsxs("div",{className:"flex gap-2.5 group",children:[t.jsx("div",{className:`w-6 h-6 rounded-full ${o.bg} flex items-center justify-center text-[9px] font-bold ${o.text} shrink-0 mt-0.5`,children:a}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-tertiary":o.text}`,children:c?i:r.author}),l&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l})]}),t.jsx("div",{className:"text-xs text-fg-secondary",children:t.jsx(Xn,{content:r.content,className:"text-xs text-fg-secondary"})})]})]}):t.jsxs("div",{className:"flex gap-3 group",children:[t.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[t.jsx("div",{className:`w-7 h-7 rounded-full ${o.bg} flex items-center justify-center text-[10px] font-bold ${o.text}`,children:a}),t.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),t.jsx("div",{className:"flex-1 min-w-0 pb-4",children:t.jsxs("div",{className:`border ${o.border} rounded-lg overflow-hidden`,children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${o.bg} border-b ${o.border}`,children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-secondary":o.text}`,children:c?i:r.author}),l&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l})]}),t.jsx("div",{className:"px-3 py-2.5",children:t.jsx(Xn,{content:r.content,className:"text-xs text-fg-secondary"})})]})})]})}const nh=new Set(["rejected","cancelled","archived"]),$s=[{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"}],ia={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"},la={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"},ca={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"},da={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 Yi(e){return Object.keys(la).reduce((n,s)=>(n[s]={label:e(`work:status.task.${s}`),cls:la[s]},n),{})}function Gi(e){return Object.keys(ia).reduce((n,s)=>(n[s]={label:e(`work:status.sub.${s}`),cls:ia[s]},n),{})}function rh(e){return Object.keys(ca).reduce((n,s)=>(n[s]={label:e(`work:priority.${s}`),cls:ca[s]},n),{})}function Bs(e){return Object.keys(da).reduce((n,s)=>(n[s]={label:e(`work:status.requirement.${s}`),cls:da[s]},n),{})}const ua=["low","medium","high","urgent"],fa=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],ha=["pending","in_progress","completed","rejected","cancelled"],ma={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([])},ys={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},nr={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"},ga={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function sh({agent:e,anchorRect:n,onClose:s}){const{t:r}=He(["work","common"]),i=g.useRef(null);g.useEffect(()=>{const l=c=>{i.current&&!i.current.contains(c.target)&&s()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[s]);const o=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",a=e.status==="idle"?r("work:task.online"):e.status==="working"?r("work:task.working"):e.status==="error"?r("work:task.error"):r("work:task.offline");return t.jsxs("div",{ref:i,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:n.top+4,left:n.left},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[10px] font-bold text-brand-600 shrink-0",children:e.name.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),t.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o}`}),t.jsx("span",{className:"text-[10px] text-fg-secondary",children:a})]})]})]}),t.jsx("button",{onClick:()=>{s(),Lt.navigate(Ye.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 Zn({comment:e,agents:n,onReply:s}){const{t:r}=He(["work","common"]),i=e.authorType==="agent"||e.authorType==="system",o=new Date(e.createdAt),a=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),l=o.toLocaleDateString([],{month:"short",day:"numeric"}),[c,d]=g.useState(null),[h,f]=g.useState(!1),[m,u]=g.useState([]),[x,E]=g.useState(!1),S=g.useCallback((N,w)=>{const M=n.find(D=>D.name.toLowerCase()===N.toLowerCase());if(M){const D=w.target.getBoundingClientRect();d({agent:M,top:D.bottom,left:D.left})}},[n]),v=g.useMemo(()=>n.map(N=>N.name),[n]),y=g.useCallback(N=>{const w=n.find(M=>M.name.toLowerCase()===e.authorName.toLowerCase());if(w){const M=N.currentTarget.getBoundingClientRect();d({agent:w,top:M.bottom,left:M.left})}},[n,e.authorName]),p=g.useCallback(async()=>{if(h){f(!1);return}const N=e.activityId;if(N&&(f(!0),!(m.length>0))){E(!0);try{const{logs:w}=await re.agents.getActivityLogs(e.authorId,N),M=w.map(D=>Ca(D,N,e.authorId)).filter(D=>D!==null).map(D=>({...D,ts:new Date(D.createdAt).getTime()}));u(M)}catch{}E(!1)}},[h,m.length,e]),b=g.useMemo(()=>us(m.map(ds).filter(N=>N!==null)),[m]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[t.jsx("div",{onClick:y,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${i?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${i?"text-indigo-400":"text-blue-400"}`,onClick:y,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[l," ",a]}),s&&t.jsx("button",{onClick:()=>s(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r("work:task.reply")}),e.activityId&&i&&t.jsx("button",{onClick:p,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 N=document.getElementById(`comment-${e.replyTo}`);N&&(N.scrollIntoView({behavior:"smooth",block:"center"}),N.classList.add("bg-brand-500/10"),setTimeout(()=>N.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(Xn,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:S,knownNames:v}),e.attachments?.map((N,w)=>N.type==="image"?t.jsx("img",{src:N.url,alt:N.name,className:"mt-1 max-w-[200px] rounded"},w):null),h&&t.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:x?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(Sa,{entries:m,isActive:!1,onCollapse:()=>f(!1),embedded:!0})})]}),c&&t.jsx(sh,{agent:c.agent,anchorRect:{top:c.top,left:c.left},onClose:()=>d(null)})]})}function oh({task:e,agents:n,users:s,authUser:r}){const{t:i}=He(["work","common"]),[o,a]=g.useState([]),[l,c]=g.useState([]),d=g.useRef(null),[h,f]=g.useState(new Map);g.useEffect(()=>{c([]),f(new Map),d.current&&(clearTimeout(d.current),d.current=null),re.tasks.getComments(e.id).then(v=>a(v.comments)).catch(()=>{})},[e.id]),g.useEffect(()=>bt.on("task:comment",y=>{if(y.payload?.taskId===e.id&&y.payload.comment){const p=y.payload.comment;a(b=>b.some(N=>N.id===p.id)?b:[...b,p]),(p.authorType==="agent"||p.authorId?.startsWith("agt_"))&&(c(b=>{const N=b.filter(w=>w.id!==p.authorId);return N.length===0&&d.current&&(clearTimeout(d.current),d.current=null),N}),f(b=>{const N=new Map(b);return N.delete(p.authorId),N}))}}),[e.id]),g.useEffect(()=>{if(l.length===0)return;const v=new Set(l.map(p=>p.id));return bt.on("agent:activity_log",p=>{const b=p.payload;if(!b)return;const N=b.agentId;if(!v.has(N))return;const w=Ls(b);w&&f(M=>Ds(M,N,w))})},[l]);const m=g.useMemo(()=>{const v=[];for(const y of e.notes??[]){const p=Fi(y);let b;if(p.timestamp){const N=p.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);b=N?new Date(+N[1],+N[2]-1,+N[3],+N[4],+N[5],+(N[6]??0)):new Date(0)}else b=new Date(0);v.push({type:"note",note:y,ts:b})}for(const y of o)v.push({type:"comment",comment:y,ts:new Date(y.createdAt)});return v.sort((y,p)=>y.ts.getTime()-p.ts.getTime()),v},[e.notes,o]),[u,x]=g.useState(null),E=async(v,y,p,b)=>{let N;p.length>0&&(N=(await re.uploads.upload(p.map(_=>({dataUrl:_.dataUrl,name:_.name})),"comments")).files.map(_=>({type:"image",url:_.url,name:_.name}))),await re.tasks.addComment(e.id,v,r?.name,N,r?.id,y.length>0?y:void 0,b);const w=[],M=new Set,D=P=>{if(M.has(P)||P===r?.id)return;M.add(P);const _=n.find(C=>C.id===P);_&&w.push({id:_.id,name:_.name,avatarUrl:_.avatarUrl})};for(const P of y){const _=n.find(C=>C.name.toLowerCase()===P.toLowerCase());_&&D(_.id)}e.assignedAgentId&&D(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&D(e.createdBy),w.length>0&&(d.current&&clearTimeout(d.current),c(w),d.current=setTimeout(()=>c([]),12e4))},S=g.useCallback(v=>{x({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return t.jsxs("div",{className:"mt-5",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:i("work:task.activityCommentsHeading")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[m.length===0&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:i("work:task.noActivityYet")}),m.map((v,y)=>v.type==="note"?t.jsx(th,{note:v.note,compact:!0},`n-${y}`):t.jsx(Zn,{comment:v.comment,agents:n,onReply:S},`c-${v.comment.id}`)),l.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(v=>{const y=h.get(v.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Lt.navigate(Ye.TEAM,{agentId:v.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(ws,{name:v.name,avatarUrl:v.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:v.name}),y.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(Ps,{entries:y})})]},v.id)})})]}),t.jsx(Ma,{agents:n,humans:s,onSubmit:E,replyTo:u,onCancelReply:()=>x(null),placeholder:i("work:task.commentPlaceholder")})]})}function ah({task:e,isRunning:n,authUser:s,agents:r}){const i=e.id,{t:o}=He(["work","common"]),[a,l]=g.useState([]),[c,d]=g.useState(new Map),[h,f]=g.useState(new Set),[m,u]=g.useState([]),[x,E]=g.useState(""),[S,v]=g.useState(n),[y,p]=g.useState(!0),[b,N]=g.useState(new Set),[w,M]=g.useState(""),[D,P]=g.useState(!1),[_,C]=g.useState([]),$=g.useRef(null),[z,j]=g.useState(new Map),[B,R]=g.useState([]),[T,A]=g.useState([]),[L,q]=g.useState(!1),F=g.useRef(null),Y=g.useRef(null);g.useEffect(()=>{v(n)},[n]),g.useEffect(()=>{C([]),j(new Map),$.current&&(clearTimeout($.current),$.current=null)},[i]),g.useEffect(()=>{p(!0),Promise.all([re.tasks.getLogsSummary(i).catch(()=>({rounds:[]})),re.tasks.getComments(i).catch(()=>({comments:[]}))]).then(([U,oe])=>{const le=U.rounds;if(l(le),u(oe.comments),le.length===0){p(!1);return}const ie=le[le.length-1].round;N(new Set([ie])),re.tasks.getLogs(i,ie).catch(()=>({logs:[]})).then(he=>{d(new Map([[ie,he.logs]])),p(!1)})})},[i]),g.useEffect(()=>{const U=e.assignedAgentId;U&&(q(!0),re.agents.getActivities(U,{taskId:i,limit:20}).then(oe=>A(oe.activities)).catch(()=>A([])).finally(()=>q(!1)))},[i,e.assignedAgentId]);const Q=g.useCallback(U=>{c.has(U)||h.has(U)||(f(oe=>new Set(oe).add(U)),re.tasks.getLogs(i,U).catch(()=>({logs:[]})).then(oe=>{d(le=>new Map(le).set(U,oe.logs)),f(le=>{const ie=new Set(le);return ie.delete(U),ie})}))},[i,c,h]),O=g.useCallback(U=>{N(oe=>{const le=new Set(oe);return le.has(U)?le.delete(U):(le.add(U),c.has(U)||Q(U)),le})},[c,Q]);g.useEffect(()=>{const U=bt.on("task:log",ie=>{const he=ie.payload;if(he.taskId!==i)return;const de={id:he.id,taskId:he.taskId,agentId:he.agentId,seq:he.seq,type:he.logType,content:he.content,metadata:he.metadata,executionRound:he.executionRound,createdAt:he.createdAt},Z=de.executionRound??1;l(ae=>ae.find(ve=>ve.round===Z)?ae:[...ae,{round:Z,logCount:0,toolCount:0,firstAt:de.createdAt,lastAt:de.createdAt,status:"running"}]),N(ae=>ae.has(Z)?ae:new Set(ae).add(Z)),d(ae=>{const me=ae.get(Z)??[];return de.id&&me.some(ve=>ve.id===de.id)?ae:new Map(ae).set(Z,[...me,de])}),de.type==="text"&&E(""),de.type==="status"&&(de.content==="started"||de.content==="resumed"?v(!0):["completed","failed","cancelled","execution_finished"].includes(de.content)&&(v(!1),l(ae=>ae.map(me=>me.round===Z?{...me,status:de.content}:me)))),de.type==="error"&&v(!1)}),oe=bt.on("task:log:delta",ie=>{const he=ie.payload;he.taskId===i&&E(de=>de+he.text)}),le=bt.on("task:comment",ie=>{const he=ie.payload;if(he.taskId!==i)return;const de=he.comment;u(Z=>Z.some(ae=>ae.id===de.id)?Z:[...Z,de]),(de.authorType==="agent"||de.authorId?.startsWith("agt_"))&&(C(Z=>{const ae=Z.filter(me=>me.id!==de.authorId);return ae.length===0&&$.current&&(clearTimeout($.current),$.current=null),ae}),j(Z=>{const ae=new Map(Z);return ae.delete(de.authorId),ae}))});return()=>{U(),oe(),le()}},[i]),g.useEffect(()=>{if(_.length===0)return;const U=new Set(_.map(le=>le.id));return bt.on("agent:activity_log",le=>{const ie=le.payload;if(!ie)return;const he=ie.agentId;if(!U.has(he))return;const de=Ls(ie);de&&j(Z=>Ds(Z,he,de))})},[_]);const I=g.useMemo(()=>{const U=[];for(const[,oe]of c)U.push(...oe);return U.sort((oe,le)=>oe.seq-le.seq),U},[c]),H=g.useMemo(()=>I.map(U=>ro(U)),[I]),V=a.length>1,W=U=>{const oe=U.target.files;if(oe){for(const le of Array.from(oe)){if(!le.type.startsWith("image/"))continue;const ie=new FileReader;ie.onload=()=>{R(he=>[...he,{type:"image",url:ie.result,name:le.name}])},ie.readAsDataURL(le)}U.target.value=""}},X=async()=>{if(!(!w.trim()&&B.length===0)){P(!0);try{let U;B.length>0&&(U=(await re.uploads.upload(B.map(Z=>({dataUrl:Z.url,name:Z.name})),"comments")).files.map(Z=>({type:"image",url:Z.url,name:Z.name})));const oe=await re.tasks.addComment(i,w,s?.name,U,s?.id);oe.comment&&u(de=>de.some(Z=>Z.id===oe.comment.id)?de:[...de,oe.comment]),M(""),R([]);const le=[],ie=new Set,he=de=>{if(ie.has(de)||de===s?.id)return;ie.add(de);const Z=r.find(ae=>ae.id===de);Z&&le.push({id:Z.id,name:Z.name,avatarUrl:Z.avatarUrl})};e.assignedAgentId&&he(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&he(e.createdBy),le.length>0&&($.current&&clearTimeout($.current),C(le),$.current=setTimeout(()=>C([]),12e4))}catch{}P(!1)}},ee=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[B.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:B.map((U,oe)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:U.url,alt:U.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>R(le=>le.filter((ie,he)=>he!==oe)),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:"×"})]},oe))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:w,onChange:U=>M(U.target.value),onKeyDown:U=>{U.key==="Enter"&&!U.shiftKey&&(U.preventDefault(),X())},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:F,accept:"image/*",multiple:!0,onChange:W,className:"hidden"}),t.jsx("button",{onClick:()=>F.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:()=>{X()},disabled:D||!w.trim()&&B.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:o("common:send")})]})]});if(y)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:o("work:task.loadingLogs")});if(a.length===0&&!x){const U=e.assignedAgentId?r.find(ve=>ve.id===e.assignedAgentId):void 0,oe=T.length>0,le=U&&U.currentTaskId&&U.currentTaskId!==e.id,ie=e.status==="pending",he=e.status==="in_progress",de=!e.assignedAgentId;let Z="📋",ae=o("work:task.emptyLogs.default"),me=o("work:task.emptyLogs.defaultHint");return de?(Z="👤",ae=o("work:task.emptyLogs.noAgent"),me=o("work:task.emptyLogs.noAgentHint")):ie?(Z="⏳",ae=o("work:task.emptyLogs.pending"),me=o("work:task.emptyLogs.pendingHint")):he&&le?(Z="🔄",ae=o("work:task.emptyLogs.agentBusy",{agent:U?.name??e.assignedAgentId}),me=o("work:task.emptyLogs.agentBusyHint")):he&&(Z="⏳",ae=o("work:task.emptyLogs.starting"),me=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:L?t.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:o("work:task.loadingLogs")}):oe?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:U?.name??o("work:task.agent"),count:T.length})]}),t.jsx("div",{className:"space-y-1.5",children:T.map(ve=>{const ce=!ve.endedAt,te=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:()=>Lt.navigate(Ye.TEAM,{agentId:e.assignedAgentId}),children:[t.jsx("span",{className:"text-sm shrink-0",children:te}),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`:""]})]}),ce&&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")]}),!ce&&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:Z}),t.jsxs("div",{className:"text-xs",children:[ae,t.jsx("br",{}),t.jsx("span",{className:"text-fg-muted",children:me})]})]})})}),ee]})}if(!V){const U=H.map(ie=>ds(ie)).filter(ie=>ie!==null),oe=so(I,us(U)),le=[...oe.map(ie=>({kind:"entry",entry:ie,ts:ie.timestamp?new Date(ie.timestamp).getTime():0})),...m.map(ie=>({kind:"comment",comment:ie,ts:new Date(ie.createdAt).getTime()}))];return le.sort((ie,he)=>ie.ts-he.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:[le.map((ie,he)=>ie.kind==="comment"?t.jsx(Zn,{comment:ie.comment,agents:r},`c-${ie.comment.id}`):t.jsx(oo,{entry:ie.entry,showTime:!0,isLast:he===le.length-1},`e-${he}`)),S&&x&&t.jsx(ao,{content:x}),S&&!x&&oe.length>0&&t.jsx(io,{})]}),ee]})}const se=(U,oe)=>{const le=U.firstAt?new Date(U.firstAt).getTime():0,ie=oe?.firstAt?new Date(oe.firstAt).getTime():1/0;return m.filter(he=>{const de=new Date(he.createdAt).getTime();return de>=le&&de<ie})},J=a.length>0?m.filter(U=>new Date(U.createdAt).getTime()<new Date(a[0].firstAt).getTime()):[];return t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsx("div",{ref:Y}),t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[J.length>0&&t.jsx("div",{className:"space-y-0.5",children:J.map(U=>t.jsx(Zn,{comment:U,agents:r},U.id))}),a.map((U,oe)=>{const le=b.has(U.round),ie=U.round===a[a.length-1].round,he=c.get(U.round),de=h.has(U.round),Z=se(U,a[oe+1]),ae=U.status==="completed"||U.status==="execution_finished"?"✅":U.status==="failed"?"❌":U.status==="cancelled"?"⏹":"🔄",me=U.lastAt&&U.firstAt?Math.max(0,new Date(U.lastAt).getTime()-new Date(U.firstAt).getTime()):0,ve=me>=6e4?`${Math.floor(me/6e4)}m ${Math.floor(me%6e4/1e3)}s`:me>=1e3?`${Math.floor(me/1e3)}s`:"";return t.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[t.jsxs("button",{onClick:()=>O(U.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:ae}),t.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:o("work:task.roundHeader",{n:U.round})}),Z.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",Z.length]}),ie&&S&&t.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.toolCount",{count:U.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 ${le?"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"})})]})]}),le&&t.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[de&&t.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:o("work:task.loadingRound",{n:U.round})}),he&&(()=>{const te=he.map(be=>ro(be)).map(be=>ds(be)).filter(be=>be!==null),Re=[...so(he,us(te)).map(be=>({kind:"entry",entry:be,ts:be.timestamp?new Date(be.timestamp).getTime():0})),...Z.map(be=>({kind:"comment",comment:be,ts:new Date(be.createdAt).getTime()}))];return Re.sort((be,Ie)=>be.ts-Ie.ts),Re.map((be,Ie)=>be.kind==="comment"?t.jsx(Zn,{comment:be.comment,agents:r},`c-${be.comment.id}`):t.jsx(oo,{entry:be.entry,showTime:!0,isLast:Ie===Re.length-1},`e-${Ie}`))})(),ie&&S&&x&&t.jsx(ao,{content:x}),ie&&S&&!x&&!de&&t.jsx(io,{})]})]},U.round)}),_.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:_.map(U=>{const oe=z.get(U.id)??[];return t.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Lt.navigate(Ye.TEAM,{agentId:U.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(ws,{name:U.name,avatarUrl:U.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:U.name}),oe.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:"→"})]}),oe.length>0&&t.jsx("div",{className:"ml-9 mt-1",children:t.jsx(Ps,{entries:oe})})]},U.id)})})]}),ee]})}const pa=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 Mr(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function ih({filePath:e,onClose:n,onOpenExternal:s}){const{t:r}=He(["work","common"]),[i,o]=g.useState([e]),a=i[i.length-1],[l,c]=g.useState(null),[d,h]=g.useState(null),[f,m]=g.useState(!0);g.useEffect(()=>{m(!0),h(null),c(null),re.files.preview(a).then(N=>c(N)).catch(N=>h(String(N))).finally(()=>m(!1))},[a]);const u=N=>o(w=>[...w,N]),x=()=>o(N=>N.length>1?N.slice(0,-1):N),E=i.length>1,S=N=>{re.files.reveal(N).catch(()=>{})},v=N=>{N.isDirectory||pa.has(N.ext)?u(N.path):S(N.path)},y=a.split("/").pop()??a,p=l?.type==="directory",b=(N,w)=>{if(w)return"📁";const M=[".md",".markdown"],D=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return M.includes(N)?"📝":D.includes(N)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(N)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(N)?"💻":"📄"};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:N=>N.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:x,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"})})}),p?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:y}),p&&l.entries&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",l.entries.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[t.jsx("button",{onClick:()=>s?s():S(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}),l?.type==="directory"&&l.entries&&t.jsxs("div",{className:"divide-y divide-border-default/50",children:[l.entries.length===0&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.emptyDirectory")}),l.entries.map(N=>t.jsxs("button",{onClick:()=>v(N),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(N.ext,N.isDirectory)}),t.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:N.name}),!N.isDirectory&&N.size!=null&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Mr(N.size)}),N.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"})}),!N.isDirectory&&!pa.has(N.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"})]})]},N.path))]}),l&&l.type!=="directory"&&t.jsx("div",{className:"p-5",children:l.type==="image"&&l.content?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:`data:${l.mimeType};base64,${l.content}`,alt:l.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):l.type==="audio"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("audio",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?re.files.streamUrl(l.path):re.files.streamUrl(a)),className:"w-full"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${Mr(l.size)}`:""]})]}):l.type==="video"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("video",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?re.files.streamUrl(l.path):re.files.streamUrl(a)),className:"w-full max-h-[60vh] rounded-lg bg-black"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${Mr(l.size)}`:""]})]}):l.type==="binary"||l.content==null?t.jsxs("div",{className:"space-y-3 text-center py-6",children:[t.jsx("p",{className:"text-sm text-fg-secondary",children:r("work:task.cannotPreviewFile",{defaultValue:"This file type cannot be previewed."})}),t.jsxs("p",{className:"text-xs text-fg-tertiary font-mono",children:[l.name,l.extension?` (${l.extension})`:"",l.size!=null?` · ${Mr(l.size)}`:""]}),t.jsx("button",{onClick:()=>S(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(wl,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function xa({task:e,agents:n,projects:s,requirements:r,allTasks:i,users:o,onClose:a,onRefresh:l,authUser:c,scrollToComments:d,onScrollToCommentsDone:h,onReqClick:f,onProjectClick:m}){const{t:u}=He(["work","common"]),x=g.useMemo(()=>Yi(u),[u]),[E,S]=g.useState([]),[v,y]=g.useState(""),[p,b]=g.useState(!1),[N,w]=g.useState(!1),[M,D]=g.useState(null),[P,_]=g.useState(null),[C,$]=g.useState(!1),[z,j]=g.useState(!1),[B,R]=g.useState(!1),[T,A]=g.useState("every"),[L,q]=g.useState(""),[F,Y]=g.useState(""),[Q,O]=g.useState(""),[I,H]=g.useState(!1),[V,W]=g.useState("details"),X=g.useRef(null),[ee,se]=g.useState("none"),J=g.useCallback(G=>{W(G),requestAnimationFrame(()=>{X.current?.scrollTo({top:0,behavior:"instant"})})},[]),U=g.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),oe=cs(U,V,J);g.useEffect(()=>{const G=X.current;if(!G)return;const ge=()=>{const{scrollTop:je,scrollHeight:Ne,clientHeight:Qe}=G;if(!(Ne>Qe+50)){se("none");return}const rn=je<30,pn=je+Qe>=Ne-30;se(rn?"top":pn?"bottom":"middle")};ge(),G.addEventListener("scroll",ge,{passive:!0});const Se=new ResizeObserver(ge);return Se.observe(G),()=>{G.removeEventListener("scroll",ge),Se.disconnect()}},[V]),g.useEffect(()=>{if(!d)return;W("details");const G=setTimeout(()=>{const ge=X.current;ge&&ge.scrollTo({top:ge.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(G)},[d,h]);const[le,ie]=g.useState(null),[he,de]=g.useState(!1),[Z,ae]=g.useState(null),[me,ve]=g.useState(!1),[ce,te]=g.useState(e.description),pe=g.useRef(null),Re=g.useRef(null),be=g.useRef(80);g.useEffect(()=>{if(me&&Re.current){const G=Re.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,be.current)+"px",G.focus()}},[me]);const[Ie,mt]=g.useState(!1),[nt,yt]=g.useState(""),[ot,gt]=g.useState(1),[Et,Ve]=g.useState([]),ze=g.useCallback(async()=>{try{const{results:G}=await re.deliverables.search({taskId:e.id,limit:200});Ve(G.filter(ge=>ge.status!=="outdated"))}catch{}},[e.id]);g.useEffect(()=>{ze()},[ze]);const[Pe,We]=g.useState(!1),we=rr(),Xe=20,_e=g.useCallback(async()=>{try{const G=await re.tasks.listSubtasks(e.id);S(G.subtasks)}catch{}},[e.id]);g.useEffect(()=>{_e()},[_e]);const Te=async G=>{if(!I){H(!0);try{await G(),l(),await _e()}catch(ge){ie(String(ge).replace("Error: ",""))}finally{H(!1)}}},Le=G=>Te(()=>re.tasks.update(e.id,{priority:G})),lt=G=>Te(()=>re.tasks.assign(e.id,G||null)),Pt=G=>Te(()=>re.tasks.update(e.id,{projectId:G||null})),Ee=async()=>{if(!I){H(!0);try{await re.tasks.pause(e.id),l()}finally{H(!1)}}},Fe=async()=>{if(!I){H(!0),ie(null),J("logs");try{await re.tasks.resume(e.id),l()}catch(G){ie(String(G).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{H(!1)}}},rt=async()=>{v.trim()&&(await re.tasks.createSubtask(e.id,v.trim()),y(""),b(!1),_e(),l())},ct=async G=>{G.status==="completed"||G.status==="cancelled"?await re.tasks.cancelSubtask(e.id,G.id):await re.tasks.completeSubtask(e.id,G.id),_e(),l()},Mt=async G=>{await re.tasks.deleteSubtask(e.id,G.id),D(null),_e(),l()},mn=async()=>{if(!I){H(!0);try{await re.tasks.updateStatus(e.id,"in_progress"),l()}finally{H(!1)}}},en=async()=>{if(!I){H(!0),ie(null),J("logs");try{await re.tasks.retry(e.id),l()}catch(G){ie(String(G).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{H(!1)}}},gn=async()=>{if(!I){H(!0),ie(null),J("logs");try{await re.tasks.runNow(e.id),l()}catch(G){ie(String(G).replace("Error: API error: 400","Server error").replace("Error: ","")),l()}finally{H(!1)}}},$t=g.useRef(l);$t.current=l,g.useEffect(()=>bt.on("task:update",ge=>{ge.payload.taskId===e.id&&(_e(),$t.current())}),[e.id,_e]);const tn=E.filter(G=>G.status==="completed").length,Yt=E.filter(G=>G.status==="cancelled").length,nn=tn+Yt,Ue=e.status==="in_progress",Bt=e.status==="blocked",It=Bt&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(G=>{const ge=i.find(Se=>Se.id===G);return ge&&ge.status==="completed"})),Tt=e.status==="completed",vt=e.status==="failed",pt=e.status==="rejected",Rt=e.status==="cancelled",_t=e.status==="archived",Ot=Tt||vt||pt||Rt||_t,Ke=e.taskType==="scheduled"&&!!e.scheduleConfig,dt=Ke&&!!e.scheduleConfig?.paused,ut=(()=>{const G=s.find(ge=>ge.id===e.projectId);return G&&G.name!=="default"?G:void 0})(),at=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:[we&&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=x[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," ")})})(),It&&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:()=>J("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${V==="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:()=>J("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${V==="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:()=>J("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${V==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const G=Et.filter(ge=>typeof ge.reference=="string"&&ge.reference.length>0).length;return G>0?u("work:task.deliverablesCount",{count:G}):u("work:task.deliverables")})()}),t.jsx("button",{onClick:()=>J("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${V==="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:X,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:oe.onTouchStart,onTouchEnd:oe.onTouchEnd,children:[t.jsxs("div",{className:V==="logs"?"min-w-0 min-h-full":"hidden",children:[le&&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")})," ",le]}),t.jsx(ah,{task:e,isRunning:e.status==="in_progress",authUser:c,agents:n})]}),t.jsxs("div",{className:V==="details"?"":"hidden",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:me?t.jsx("textarea",{ref:Re,value:ce,onChange:G=>{te(G.target.value);const ge=G.target;ge.style.height="auto",ge.style.height=ge.scrollHeight+"px"},onBlur:()=>{ce!==e.description&&Te(()=>re.tasks.update(e.id,{description:ce})),ve(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),te(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:pe,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]")||(be.current=Math.max(pe.current?.offsetHeight??80,60),te(e.description),ve(!0))},role:"button",tabIndex:0,onKeyDown:G=>G.key==="Enter"&&(te(e.description),ve(!0)),children:e.description?t.jsxs("div",{children:[t.jsx("div",{className:we&&!Pe?"line-clamp-3":"",children:t.jsx(Xn,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),we&&e.description.length>150&&t.jsx("button",{onClick:G=>{G.stopPropagation(),We(!Pe)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:u(Pe?"work:task.collapse":"common:showMore")})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:u("work:task.noDescription")})})}),(ut||at)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[ut&&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(ut.id):void 0,role:m?"button":void 0,tabIndex:m?0:void 0,onKeyDown:m?G=>G.key==="Enter"&&m(ut.id):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.projectLabel")}),ut.name]}),at&&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(at):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?G=>G.key==="Enter"&&f(at):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.requirementLabel")}),at.title.length>40?at.title.slice(0,40)+"…":at.title]})]}),t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default",children:[t.jsx("div",{className:"flex items-center justify-between mb-1.5",children:t.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:u("work:task.dependencies")})}),e.blockedBy&&e.blockedBy.length>0?t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(G=>{const ge=i.find(je=>je.id===G),Se=ge&&(ge.status==="completed"||ge.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Se?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:Se?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${Se?"line-through opacity-60":""}`,children:ge?ge.title.slice(0,30):G.slice(-8)}),!Ot&&t.jsx("button",{onClick:async()=>{const je=(e.blockedBy??[]).filter(Ne=>Ne!==G);await re.tasks.update(e.id,{blockedBy:je}),l()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:u("work:task.removeDependency"),children:"×"})]},G)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:u("work:task.noDependencies")}),It&&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")})]}),!Ot&&t.jsxs("select",{value:"",onChange:async G=>{const ge=G.target.value;if(!ge)return;const Se=[...e.blockedBy??[],ge];await re.tasks.update(e.id,{blockedBy:Se}),l()},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:u("work:task.addDependency")}),i.filter(G=>G.id!==e.id&&!(e.blockedBy??[]).includes(G.id)).map(G=>t.jsx("option",{value:G.id,children:G.title},G.id))]})]}),t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.projectLabel")}),t.jsxs("select",{value:e.projectId??"",onChange:G=>{Pt(G.target.value)},disabled:I,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=>Te(()=>re.tasks.update(e.id,{requirementId:G.target.value||null})),disabled:I,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=>{lt(G.target.value)},disabled:I,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 ge=G.target.value;if(!ge)return;const Se=ge.startsWith("human:"),je=ge.replace(/^(human|agent):/,"");(je!==e.reviewerId||(Se?"human":"agent")!==(e.reviewerType??"agent"))&&Te(()=>re.tasks.update(e.id,{reviewerId:je,reviewerType:Se?"human":"agent"}))},disabled:I,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=>{Le(G.target.value)},disabled:I,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:$n(e.createdBy,n,o)??e.createdBy})}),e.updatedBy&&t.jsx("span",{children:u("work:task.updatedBy",{name:$n(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:tn,total:E.length-Yt}),Yt>0?` · ${Yt} cancelled`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[nn>0&&t.jsx("button",{onClick:()=>w(G=>!G),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${N?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:N?u("work:task.hideCompleted"):u("work:task.showCompleted",{count:nn})}),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=N?E:E.filter(ge=>ge.status!=="completed"&&ge.status!=="cancelled");return G.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:G.map(ge=>t.jsxs("div",{className:`group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors ${ge.status==="cancelled"?"opacity-50":""}`,children:[t.jsxs("button",{onClick:()=>{ct(ge)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${ge.status==="completed"?"bg-green-600 border-green-600 text-white":ge.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[ge.status==="completed"&&t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),ge.status==="cancelled"&&t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M3 3l6 6M9 3l-6 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),t.jsx("span",{className:`flex-1 text-sm ${ge.status==="completed"?"line-through text-fg-tertiary":ge.status==="cancelled"?"line-through text-fg-quaternary":"text-fg-secondary"}`,children:ge.title}),t.jsx("button",{onClick:()=>D(ge),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},ge.id))}):null})(),E.length===0&&!p&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:u("work:task.noSubtasksYet")}),p&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:v,onChange:G=>y(G.target.value),onKeyDown:G=>{G.key==="Enter"&&rt(),G.key==="Escape"&&(b(!1),y(""))},placeholder:u("work:task.subtaskTitlePlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{onClick:()=>{rt()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:u("work:task.add")}),t.jsx("button",{onClick:()=>{b(!1),y("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:u("common:cancel")})]}),(()=>{const G=Et.filter(je=>typeof je.reference=="string"&&je.reference.length>0);if(G.length===0)return null;const ge={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},Se=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:()=>J("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:Se.map(je=>{const Ne=/^https?:\/\//i.test(je.reference),Qe=Ne?je.summary||je.reference:je.reference.split("/").pop()??je.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${ge[je.type]??"bg-gray-500/15 text-fg-secondary"}`,children:je.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Ne?t.jsxs("a",{href:je.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:je.reference,children:[Qe," ",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:()=>ae(je.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:je.reference,children:Qe}),je.summary&&!Ne&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:je.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:je.reference})]})]},je.id)})})]})})(),t.jsx(oh,{task:e,agents:n,users:o,authUser:c})]})]}),t.jsx("div",{className:V==="history"?"":"hidden",children:t.jsx(Ui,{entityType:"task",entityId:e.id})}),t.jsx("div",{className:V==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const G=Et.filter(Ne=>typeof Ne.reference=="string"&&Ne.reference.length>0);if(G.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:u("work:task.noDeliverablesYet")});const ge={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},Se=Math.ceil(G.length/Xe),je=G.slice((ot-1)*Xe,ot*Xe);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})}),Se>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:ot<=1,onClick:()=>gt(Ne=>Ne-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[ot,"/",Se]}),t.jsx("button",{disabled:ot>=Se,onClick:()=>gt(Ne=>Ne+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:je.map(Ne=>{const Qe=/^https?:\/\//i.test(Ne.reference),ft=Qe?Ne.summary||Ne.reference:Ne.reference.split("/").pop()??Ne.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${ge[Ne.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Ne.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Qe?t.jsxs("a",{href:Ne.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:Ne.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:()=>ae(Ne.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ne.reference,children:ft}),Ne.summary&&!Qe&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Ne.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Ne.reference})]})]},Ne.id)})})]})})()})]}),ee!=="none"&&ee!=="top"&&t.jsx("button",{onClick:()=>X.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"})})}),ee!=="none"&&ee!=="bottom"&&t.jsx("button",{onClick:()=>{const G=X.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"})})})]}),Ke&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${dt?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Ue&&!B&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Ue||B||e.scheduleConfig?.runAt||(A(e.scheduleConfig?.cron?"cron":"every"),q(e.scheduleConfig?.every??"4h"),Y(e.scheduleConfig?.cron??""),O(e.scheduleConfig?.maxRuns&&e.scheduleConfig.maxRuns>0?String(e.scheduleConfig.maxRuns):""),R(!0))},children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:dt?"text-amber-600":"text-brand-500",children:dt?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")}),!dt&&e.scheduleConfig.nextRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-fg-tertiary",children:"·"}),t.jsx("span",{className:"text-fg-secondary",children:u("work:task.scheduleNext",{when:(()=>{const G=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(G<=0)return u("work:task.scheduleDueNow");const ge=Math.floor(G/6e4);if(ge<60)return u("work:task.scheduleInMinutes",{count:ge});const Se=Math.floor(ge/60);return Se<24?u("work:task.scheduleInHoursMinutes",{h:Se,m:ge%60}):u("work:task.scheduleInDaysHours",{d:Math.floor(Se/24),h:Se%24})})()})})]}),!Ue&&!B&&!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"})]})]}),B?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=>A(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:L,onChange:G=>q(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:F,onChange:G=>Y(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=>O(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=L:G.cron=F.trim(),Q&&(G.maxRuns=parseInt(Q,10)),await Te(()=>re.tasks.updateSchedule(e.id,G)),R(!1)},disabled:I,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:()=>R(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:u("common:cancel")})]})]}):t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[t.jsx("span",{children:u("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?u("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:u("work:task.scheduleLast",{when:(()=>{const G=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),ge=Math.floor(G/6e4);if(ge<1)return u("work:task.noteTimeJustNow");if(ge<60)return u("work:task.noteTimeMinutes",{count:ge});const Se=Math.floor(ge/60);return Se<24?u("work:task.noteTimeHours",{count:Se}):u("work:task.noteTimeDays",{count:Math.floor(Se/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(Ke){de(!0);return}Te(()=>re.tasks.approve(e.id))},disabled:I,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:()=>{Te(()=>re.tasks.cancel(e.id))},disabled:I,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:I,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:()=>{Te(()=>re.tasks.accept(e.id,c?.id))},disabled:I,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")}),Ie?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:nt,onChange:G=>yt(G.target.value),onKeyDown:G=>{G.key==="Enter"&&nt.trim()&&(Te(()=>re.tasks.revision(e.id,nt.trim(),c?.id)),mt(!1),yt(""))},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:()=>{Te(()=>re.tasks.revision(e.id,nt.trim()||u("work:task.revisionsNeededDefault"),c?.id)),mt(!1),yt("")},disabled:I,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:()=>{mt(!1),yt("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>mt(!0),disabled:I,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:()=>{Ee()},disabled:I,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:()=>{en()},disabled:I,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")]})]}),Bt&&t.jsx("button",{onClick:()=>{Fe()},disabled:I,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:I?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")]})}),vt&&!Ke&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{en()},disabled:I,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:()=>{mn()},disabled:I,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")]})]}),Ke&&(Tt||vt||Rt)&&!_t&&t.jsx("button",{onClick:()=>{gn()},disabled:I,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:I?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")]})}),Ke&&!Ue&&!_t&&!pt&&(dt?t.jsx("button",{onClick:()=>{Te(()=>re.tasks.resumeSchedule(e.id))},disabled:I,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:()=>{Te(()=>re.tasks.pauseSchedule(e.id))},disabled:I,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")})),(Tt||vt||pt||Rt)&&t.jsx("button",{onClick:()=>j(!0),disabled:I,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")}),Tt&&!Ke&&t.jsx("button",{onClick:()=>{mn()},disabled:I,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")}),!Ot&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:G}=await re.tasks.getDependentCount(e.id);_({dependentCount:G})},disabled:I,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")})]})}),M&&t.jsx(Sn,{title:u("work:task.deleteSubtaskTitle",{title:M.title}),message:u("work:task.deleteSubtaskMessage"),confirmLabel:u("common:delete"),onConfirm:()=>{Mt(M)},onCancel:()=>D(null)}),C&&t.jsx(Sn,{title:u("work:task.rejectConfirmTitle"),message:u("work:task.rejectConfirmMessage"),confirmLabel:u("work:task.reject"),onConfirm:()=>{$(!1),Te(()=>re.tasks.reject(e.id))},onCancel:()=>$(!1)}),z&&t.jsx(Sn,{title:u("work:task.archiveConfirmTitle"),message:u(Ke?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:u("work:task.archive"),onConfirm:()=>{j(!1),Te(()=>re.tasks.archive(e.id))},onCancel:()=>j(!1)}),P&&P.dependentCount>0?t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>_(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:[Ke&&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:P.dependentCount})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("button",{onClick:()=>{_(null),Te(()=>re.tasks.cancel(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-surface-elevated border border-border-default rounded-lg hover:bg-surface-overlay text-fg-primary text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelTaskOnly")}),t.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:u("work:task.cancelTaskOnlyHint")})]}),t.jsxs("button",{onClick:()=>{_(null),Te(()=>re.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelWithDependents")}),t.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:u("work:task.cancelWithDependentsHint",{count:P.dependentCount})})]}),t.jsx("button",{onClick:()=>_(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("work:task.keepTaskRunning")})]})]})}):P&&t.jsx(Sn,{title:u("work:task.cancelTaskModalTitle"),message:u(Ke?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:u("work:task.cancelTask"),onConfirm:()=>{_(null),Te(()=>re.tasks.cancel(e.id))},onCancel:()=>_(null)}),Z&&t.jsx(ih,{filePath:Z,onClose:()=>ae(null),onOpenExternal:()=>{ae(null),re.deliverables.search({taskId:e.id,limit:100}).then(({results:G})=>{const ge=G.find(Se=>Se.reference===Z);ge?Lt.navigate(Ye.DELIVERABLES,{openDeliverable:ge.id}):Lt.navigate(Ye.DELIVERABLES)}).catch(()=>Lt.navigate(Ye.DELIVERABLES))}}),he&&e.scheduleConfig&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>de(!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:I,onClick:()=>{de(!1),Te(()=>re.tasks.approve(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-green-600 hover:bg-green-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveRunNow")}),t.jsx("button",{disabled:I,onClick:()=>{de(!1),Te(()=>re.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveWait")}),t.jsx("button",{onClick:()=>de(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("common:cancel")})]})]})})]})}function ba({project:e,tasks:n,requirements:s,agents:r,onDeleteProject:i,onUpdateProject:o,onRefresh:a}){const l=g.useMemo(()=>n.filter(C=>C.projectId===e.id),[n,e.id]),c=g.useMemo(()=>s.filter(C=>C.projectId===e.id),[s,e.id]),d=g.useMemo(()=>{const C={total:l.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:c.length,reqsDone:0};for(const $ of l)$.status==="completed"||$.status==="accepted"?C.completed++:$.status==="in_progress"?C.inProgress++:$.status==="review"||$.status==="revision"?C.inReview++:$.status==="blocked"?C.blocked++:$.status==="failed"?C.failed++:C.pending++;for(const $ of c)$.status==="completed"&&C.reqsDone++;return C},[l,c]),h=g.useMemo(()=>new Set(l.map(C=>C.assignedAgentId).filter(Boolean)),[l]),f=g.useMemo(()=>r.filter(C=>h.has(C.id)),[r,h]),[m,u]=g.useState(!1),[x,E]=g.useState(""),[S,v]=g.useState("main"),[y,p]=g.useState(!1),[b,N]=g.useState(!1),{t:w}=He(["work","common"]),M=[{value:"active",label:w("work:project.statusActive"),desc:w("work:project.statusActiveDesc")},{value:"paused",label:w("work:project.statusPaused"),desc:w("work:project.statusPausedDesc")},{value:"archived",label:w("work:project.statusArchived"),desc:w("work:project.statusArchivedDesc")}],D=async C=>{if(C!==e.status){p(!0);try{await o({status:C}),a()}finally{p(!1)}}},P=async()=>{const C=x.trim();if(!C)return;const $=[...e.repositories??[],{url:"",localPath:C,defaultBranch:S||"main"}];await o({repositories:$}),E(""),v("main"),u(!1),a()},_=async C=>{const $=(e.repositories??[]).filter((z,j)=>j!==C);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(Kf,{value:e.description??"",onSave:async C=>{await o({description:C}),a()},className:"text-sm text-fg-secondary",placeholder:w("work:project.descriptionPlaceholderLong")}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&t.jsxs("span",{children:[w("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:[w("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:w("work:project.projectStatusHeading")}),t.jsx("div",{className:"flex gap-2",children:M.map(C=>t.jsxs("button",{disabled:y,onClick:()=>D(C.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===C.value?C.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":C.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${y?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:C.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:C.desc})]},C.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:w("work:project.taskOverview")}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(Wt,{label:w("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),t.jsx(Wt,{label:w("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),t.jsx(Wt,{label:w("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),t.jsx(Wt,{label:w("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),t.jsx(Wt,{label:w("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),t.jsx(Wt,{label:w("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:w("work:project.requirementsHeading")}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(Wt,{label:w("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),t.jsx(Wt,{label:w("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),t.jsx(Wt,{label:w("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:w("work:project.agentsHeading",{count:f.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(C=>{const $=l.filter(j=>j.assignedAgentId===C.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 ${C.status==="working"?"bg-blue-500":C.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:C.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:w("work:project.agentTaskCounts",{active:z.length,total:$.length})})]},C.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:w("work:project.repositories")}),t.jsx("button",{onClick:()=>u(!m),className:"text-[10px] text-brand-500 hover:text-brand-500",children:w(m?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!m&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:w("work:project.noReposLinked")}),(e.repositories??[]).map((C,$)=>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:C.url||C.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:C.defaultBranch}),t.jsx("button",{onClick:()=>_($),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:w("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:x,onChange:C=>E(C.target.value),placeholder:w("work:project.repoPathPlaceholder"),className:"w-full px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:S,onChange:C=>v(C.target.value),placeholder:w("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:P,disabled:!x.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:w("work:task.add")})]})]})]}),t.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:w("work:project.dangerZone")}),t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:w("work:project.dangerZoneDeleteHint")}),t.jsx("button",{onClick:()=>N(!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:w("work:project.deleteProject")})]}),b&&t.jsx(Sn,{title:w("work:project.deleteProjectConfirmTitle"),message:w("work:project.deleteProjectConfirmBody",{name:e.name,tasks:d.total,reqs:d.reqs}),confirmLabel:w("work:project.deleteProject"),onConfirm:()=>{N(!1),i()},onCancel:()=>N(!1)})]})}function Wt({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 Zi={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},Xi={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},lh={urgent:0,high:1,medium:2,low:3},ya={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},va={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"},ch={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"},dh=["pending","in_progress","completed","rejected","cancelled","archived"];function uh(e){for(const n of $s)if(n.statuses.includes(e))return n.id;return"closed"}function wa(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 Ir({value:e,options:n,onSelect:s,allowedValues:r}){const[i,o]=g.useState(!1),a=g.useRef(null),l=g.useRef(null),c=n.find(d=>d.value===e);return g.useEffect(()=>{if(!i)return;const d=h=>{l.current&&!l.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 ${c?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:c?.label??e}),i&&t.jsx("div",{ref:l,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:n.map(d=>{const 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 ka({row:e,idx:n,dragIdx:s,agentMap:r,projMap:i,onTaskClick:o,onReqClick:a,onRowDragStart:l,onRowDragEnd:c,handleStatusChange:d,handlePriorityChange:h,selected:f,isMobile:m,isAbnormalBlocked:u}){const{t:x}=He(["work","common"]),E=g.useMemo(()=>Yi(x),[x]),S=g.useMemo(()=>Bs(x),[x]),v=g.useMemo(()=>rh(x),[x]),y=e.data.status,p=e.data.priority,b=e.kind==="task"?r.get(e.data.assignedAgentId??""):void 0,N=(()=>{const M=i.get((e.kind==="task",e.data.projectId??""));return M&&M.name!=="default"?M:void 0})(),w=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:x("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:x("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:x("work:task.taskShort")});return m?t.jsxs("div",{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 ${va[e.group]??"border-l-gray-700"} ${f?"bg-brand-500/10 border-l-brand-500":"active:bg-surface-elevated/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[w,u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500",children:"⚠"}),t.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsx("div",{onClick:M=>M.stopPropagation(),children:t.jsx(Ir,{value:y,options:e.kind==="task"?fa.map(M=>({value:M,label:E[M]?.label??M,cls:E[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):ha.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?ma[y]:ys[y],onSelect:M=>{d(e,M)}})}),t.jsx("div",{onClick:M=>M.stopPropagation(),children:t.jsx(Ir,{value:p,options:ua.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{h(e,M)}})}),b&&t.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${nr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`${ga[b.status]??"text-fg-secondary"}`,children:b.name})]}),N?.name&&t.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:N.name}),t.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:wa(e.data.updatedAt??"",x)})]})]}):t.jsxs("div",{draggable:!0,onDragStart:M=>l(M,n),onDragEnd:c,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${va[e.group]??"border-l-gray-700"} ${s===n?"opacity-40":""} ${f?"bg-brand-500/10 border-l-brand-500 hover:bg-brand-500/15":"hover:bg-surface-elevated/50"}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:w}),t.jsxs("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate",children:e.data.title}),u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500 shrink-0",children:"⚠"})]}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:M=>M.stopPropagation(),children:t.jsx(Ir,{value:y,options:e.kind==="task"?fa.map(M=>({value:M,label:E[M]?.label??M,cls:E[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):ha.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?ma[y]:ys[y],onSelect:M=>{d(e,M)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:M=>M.stopPropagation(),children:t.jsx(Ir,{value:p,options:ua.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{h(e,M)}})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:b?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${nr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`font-medium ${ga[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:N?.name?t.jsx("span",{className:"text-brand-400/70",children:N.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:wa(e.data.updatedAt??"",x)})]})}function fh({tasks:e,requirements:n,agents:s,projects:r,onTaskClick:i,onReqClick:o,onRefresh:a,selectedTaskId:l,selectedReqId:c}){const{t:d}=He(["work","common"]),h=rr(),[f,m]=g.useState("status"),[u,x]=g.useState(null),[E,S]=g.useState(null),v=g.useMemo(()=>{const T=new Map;for(const A of e)T.set(A.id,A);return T},[e]),y=g.useCallback(T=>T.status!=="blocked"?!1:!T.blockedBy||T.blockedBy.length===0?!0:T.blockedBy.every(A=>{const L=v.get(A);return L&&L.status==="completed"}),[v]),p=g.useMemo(()=>{const T=[];for(const A of e){const L=uh(A.status);T.push({kind:"task",data:A,group:L,groupOrder:ya[L]??5})}for(const A of n){const L=Zi[A.status]??"todo";T.push({kind:"req",data:A,group:L,groupOrder:ya[L]??5})}if(f==="status")T.sort((A,L)=>{if(A.groupOrder!==L.groupOrder)return A.groupOrder-L.groupOrder;const q=new Date(A.data.updatedAt??0).getTime();return new Date(L.data.updatedAt??0).getTime()-q});else{const A=L=>lh[L.data.priority]??2;T.sort((L,q)=>{const F=A(L),Y=A(q);return F!==Y?F-Y:new Date(q.data.updatedAt??0).getTime()-new Date(L.data.updatedAt??0).getTime()})}return T},[e,n,f]),b=async(T,A)=>{try{T.kind==="task"?await re.tasks.updateStatus(T.data.id,A):await re.requirements.updateStatus(T.data.id,A),a()}catch{}},N=async(T,A)=>{try{T.kind==="task"?await re.tasks.update(T.data.id,{priority:A}):await re.requirements.update(T.data.id,{priority:A}),a()}catch{}},w=(T,A)=>{x(A),T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",String(A)),T.currentTarget.style.opacity="0.4"},M=T=>{T.currentTarget.style.opacity="1",x(null),S(null)},D=(T,A)=>{T.preventDefault(),T.dataTransfer.dropEffect="move",E!==A&&S(A)},P=async(T,A)=>{if(T.preventDefault(),S(null),u==null)return;const L=p[u];if(!L||L.group===A)return;const q=$s.find(F=>F.id===A);if(q){try{if(L.kind==="task"){if(L.data.status==="pending")return;await re.tasks.updateStatus(L.data.id,q.dropStatus)}else{const F=Xi[A];F&&await re.requirements.updateStatus(L.data.id,F)}a()}catch{}x(null)}},_=g.useMemo(()=>new Map(s.map(T=>[T.id,T])),[s]),C=g.useMemo(()=>new Map(r.map(T=>[T.id,T])),[r]),$=["todo","in_progress","review","done"],z=g.useMemo(()=>{const T={};for(const A of p)T[A.group]=(T[A.group]??0)+1;return T},[p]),{rowsByGroup:j,rowIndexMap:B}=g.useMemo(()=>{const T=new Map,A=new Map;for(let L=0;L<p.length;L++){const q=p[L];A.set(q,L);const F=T.get(q.group)??[];F.push(q),T.set(q.group,F)}return{rowsByGroup:T,rowIndexMap:A}},[p]),R=g.useMemo(()=>{if(f!=="status")return null;const T=new Set(p.map(q=>q.group)),A=[],L=new Set;T.has("failed")&&(A.push("failed"),L.add("failed"));for(const q of $)A.push(q),L.add(q);for(const q of p)L.has(q.group)||(A.push(q.group),L.add(q.group));return A},[p,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:p.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"&&R?R.map(T=>{const A=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 ${ch[T]??""} ${E===T?"ring-1 ring-brand-500/40":""}`,onDragOver:L=>D(L,T),onDragLeave:()=>S(null),onDrop:L=>{P(L,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})]}),A.map(L=>t.jsx(ka,{row:L,idx:B.get(L)??0,dragIdx:u,agentMap:_,projMap:C,onTaskClick:i,onReqClick:o,onRowDragStart:w,onRowDragEnd:M,handleStatusChange:b,handlePriorityChange:N,selected:L.kind==="task"?L.data.id===l:L.data.id===c,isMobile:h,isAbnormalBlocked:L.kind==="task"?y(L.data):!1},`${L.kind}-${L.data.id}`))]},T)}):p.map((T,A)=>t.jsx(ka,{row:T,idx:A,dragIdx:u,agentMap:_,projMap:C,onTaskClick:i,onReqClick:o,onRowDragStart:w,onRowDragEnd:M,handleStatusChange:b,handlePriorityChange:N,selected:T.kind==="task"?T.data.id===l:T.data.id===c,isMobile:h,isAbnormalBlocked:T.kind==="task"?y(T.data):!1},`${T.kind}-${T.data.id}`)),p.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 hh(e,n){const s=new Map,r=new Map(e.map(l=>[l.id,l])),i=new Set;for(const l of e){let c=vs(l.title).replace(/[^a-z0-9-]/g,"").slice(0,30)||"step";i.has(c)&&(c=`${c}-${l.id.slice(-4)}`),i.add(c),s.set(l.id,c)}const o=new Map,a=new Set;for(const l of e){const c=l.assignedAgentId;if(c&&!o.has(c)){const d=n[c]??"worker";let h=vs(d).replace(/[^a-z0-9-]/g,"")||"worker";a.has(h)&&(h=`${h}-${c.slice(-4)}`),a.add(h),o.set(c,h)}}return e.map(l=>({id:s.get(l.id),name:l.title,role:o.get(l.assignedAgentId)??"worker",prompt:l.description||l.title,depends_on:(l.blockedBy??[]).filter(c=>r.has(c)).map(c=>s.get(c)).filter(Boolean)}))}function Tr(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function mh(e,n,s){const r=[];r.push(`name: ${Tr(e)}`),r.push(`description: ${Tr(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: ${Tr(i.name)}`),r.push(" type: agent_task"),r.push(` role: ${Tr(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(`
6
+ `)),h=d.reduce((f,m)=>f.concat(...m),[]);return[d,h]}return[[],[]]},[e]);return g.useEffect(()=>{const c=n?.target??Lo,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)&&Fa(u))return!1;const E=Po(u.code,l);if(o.current.add(u[E]),Do(a,o.current,!1)){const S=u.composedPath?.()?.[0]||u.target,v=S?.nodeName==="BUTTON"||S?.nodeName==="A";n.preventDefault!==!1&&(i.current||!v)&&u.preventDefault(),r(!0)}},f=u=>{const x=Po(u.code,l);Do(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(u[x]),u.key==="Meta"&&o.current.clear(),i.current=!1},m=()=>{o.current.clear(),r(!1)};return c?.addEventListener("keydown",h),c?.addEventListener("keyup",f),window.addEventListener("blur",m),window.addEventListener("contextmenu",m),()=>{c?.removeEventListener("keydown",h),c?.removeEventListener("keyup",f),window.removeEventListener("blur",m),window.removeEventListener("contextmenu",m)}}},[e,r]),s}function Do(e,n,s){return e.filter(r=>s||r.length===n.size).some(r=>r.every(i=>n.has(i)))}function Po(e,n){return n.includes(e)?"code":"key"}const ud=()=>{const e=Be();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:l}=e.getState(),c=Cs(n,r,i,o,a,s?.padding??.1);return l?(await l.setViewport(c,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(n,s={})=>{const{transform:r,snapGrid:i,snapToGrid:o,domNode:a}=e.getState();if(!a)return n;const{x:l,y:c}=a.getBoundingClientRect(),d={x:n.x-l,y:n.y-c},h=s.snapGrid??i,f=s.snapToGrid??o;return ir(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=Dr(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 l={...o};for(const c of a)fd(c,l);s.push(l)}return i.length&&i.forEach(o=>{o.index!==void 0?s.splice(o.index,0,{...o.item}):s.push({...o.item})}),s}function fd(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 mi(e,n){return hi(e,n)}function gi(e,n){return hi(e,n)}function dn(e,n){return{id:e,type:"select",selected:n}}function Mn(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(dn(o.id,a)))}return r}function $o({items:e=[],lookup:n}){const s=[],r=new Map(e.map(i=>[i.id,i]));for(const[i,o]of e.entries()){const a=n.get(o.id),l=a?.internals?.userNode??a;l!==void 0&&l!==o&&s.push({id:o.id,item:o,type:"replace"}),l===void 0&&s.push({item:o,type:"add",index:i})}for(const[i]of n)r.get(i)===void 0&&s.push({id:i,type:"remove"});return s}function Bo(e){return{id:e.id,type:"remove"}}const Oo=e=>Bl(e),hd=e=>$a(e);function pi(e){return g.forwardRef(e)}const md=typeof window<"u"?g.useLayoutEffect:g.useEffect;function zo(e){const[n,s]=g.useState(BigInt(0)),[r]=g.useState(()=>gd(()=>s(i=>i+BigInt(1))));return md(()=>{const i=r.get();i.length&&(e(i),r.reset())},[n]),r}function gd(e){let n=[];return{get:()=>n,reset:()=>{n=[]},push:s=>{n.push(s),e()}}}const xi=g.createContext(null);function pd({children:e}){const n=Be(),s=g.useCallback(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:h,onNodesChange:f,nodeLookup:m,fitViewQueued:u,onNodesChangeMiddlewareMap:x}=n.getState();let E=c;for(const v of l)E=typeof v=="function"?v(E):v;let S=$o({items:E,lookup:m});for(const v of x.values())S=v(S);h&&d(E),S.length>0?f?.(S):u&&window.requestAnimationFrame(()=>{const{fitViewQueued:v,nodes:y,setNodes:p}=n.getState();v&&p(y)})},[]),r=zo(s),i=g.useCallback(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:h,onEdgesChange:f,edgeLookup:m}=n.getState();let u=c;for(const x of l)u=typeof x=="function"?x(u):x;h?d(u):f&&f($o({items:u,lookup:m}))},[]),o=zo(i),a=g.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return t.jsx(xi.Provider,{value:a,children:e})}function xd(){const e=g.useContext(xi);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const bd=e=>!!e.panZoom;function _s(){const e=ud(),n=Be(),s=xd(),r=Me(bd),i=g.useMemo(()=>{const o=f=>n.getState().nodeLookup.get(f),a=f=>{s.nodeQueue.push(f)},l=f=>{s.edgeQueue.push(f)},c=f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState(),x=Oo(f)?f:m.get(f.id),E=x.parentId?Va(x.position,x.measured,x.parentId,m,u):x.position,S={...x,position:E,width:x.measured?.width??x.width,height:x.measured?.height??x.height};return Ln(S)},d=(f,m,u={replace:!1})=>{a(x=>x.map(E=>{if(E.id===f){const S=typeof m=="function"?m(E):m;return u.replace&&Oo(S)?S:{...E,...S}}return E}))},h=(f,m,u={replace:!1})=>{l(x=>x.map(E=>{if(E.id===f){const S=typeof m=="function"?m(E):m;return u.replace&&hd(S)?S:{...E,...S}}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:l,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(),[x,E,S]=u;return{nodes:f.map(v=>({...v})),edges:m.map(v=>({...v})),viewport:{x,y:E,zoom:S}}},deleteElements:async({nodes:f=[],edges:m=[]})=>{const{nodes:u,edges:x,onNodesDelete:E,onEdgesDelete:S,triggerNodeChanges:v,triggerEdgeChanges:y,onDelete:p,onBeforeDelete:b}=n.getState(),{nodes:N,edges:w}=await Vl({nodesToRemove:f,edgesToRemove:m,nodes:u,edges:x,onBeforeDelete:b}),M=w.length>0,D=N.length>0;if(M){const P=w.map(Bo);S?.(w),y(P)}if(D){const P=N.map(Bo);E?.(N),v(P)}return(D||M)&&p?.({nodes:N,edges:w}),{deletedNodes:N,deletedEdges:w}},getIntersectingNodes:(f,m=!0,u)=>{const x=ho(f),E=x?f:c(f),S=u!==void 0;return E?(u||n.getState().nodes).filter(v=>{const y=n.getState().nodeLookup.get(v.id);if(y&&!x&&(v.id===f.id||!y.internals.positionAbsolute))return!1;const p=Ln(S?v:y),b=Jn(p,E);return m&&b>0||b>=p.width*p.height||b>=E.width*E.height}):[]},isNodeIntersecting:(f,m,u=!0)=>{const E=ho(f)?f:c(f);if(!E)return!1;const S=Jn(E,m);return u&&S>0||S>=m.width*m.height||S>=E.width*E.height},updateNode:d,updateNodeData:(f,m,u={replace:!1})=>{d(f,x=>{const E=typeof m=="function"?m(x):m;return u.replace?{...x,data:E}:{...x,data:{...x.data,...E}}},u)},updateEdge:h,updateEdgeData:(f,m,u={replace:!1})=>{h(f,x=>{const E=typeof m=="function"?m(x):m;return u.replace?{...x,data:E}:{...x,data:{...x.data,...E}}},u)},getNodesBounds:f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState();return Ol(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??Gl();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 Ho=e=>e.selected,yd=typeof window<"u"?window:void 0;function vd({deleteKeyCode:e,multiSelectionKeyCode:n}){const s=Be(),{deleteElements:r}=_s(),i=tr(e,{actInsideInputWithModifier:!1}),o=tr(n,{target:yd});g.useEffect(()=>{if(i){const{edges:a,nodes:l}=s.getState();r({nodes:l.filter(Ho),edges:a.filter(Ho)}),s.setState({nodesSelectionActive:!1})}},[i]),g.useEffect(()=>{s.setState({multiSelectionActive:o})},[o])}function wd(e){const n=Be();g.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=Ss(e.current);(r.height===0||r.width===0)&&n.getState().onError?.("004",Dt.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 Vr={position:"absolute",width:"100%",height:"100%",top:0,left:0},kd=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function jd({onPaneContextMenu:e,zoomOnScroll:n=!0,zoomOnPinch:s=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:o=un.Free,zoomOnDoubleClick:a=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:h,maxZoom:f,zoomActivationKeyCode:m,preventScrolling:u=!0,children:x,noWheelClassName:E,noPanClassName:S,onViewportChange:v,isControlledViewport:y,paneClickDistance:p,selectionOnDrag:b}){const N=Be(),w=g.useRef(null),{userSelectionActive:M,lib:D,connectionInProgress:P}=Me(kd,Oe),_=tr(m),C=g.useRef();wd(w);const $=g.useCallback(z=>{v?.({x:z[0],y:z[1],zoom:z[2]}),y||N.setState({transform:z})},[v,y]);return g.useEffect(()=>{if(w.current){C.current=Tc({domNode:w.current,minZoom:h,maxZoom:f,translateExtent:d,viewport:c,onDraggingChange:R=>N.setState(T=>T.paneDragging===R?T:{paneDragging:R}),onPanZoomStart:(R,T)=>{const{onViewportChangeStart:A,onMoveStart:L}=N.getState();L?.(R,T),A?.(T)},onPanZoom:(R,T)=>{const{onViewportChange:A,onMove:L}=N.getState();L?.(R,T),A?.(T)},onPanZoomEnd:(R,T)=>{const{onViewportChangeEnd:A,onMoveEnd:L}=N.getState();L?.(R,T),A?.(T)}});const{x:z,y:j,zoom:B}=C.current.getViewport();return N.setState({panZoom:C.current,transform:[z,j,B],domNode:w.current.closest(".react-flow")}),()=>{C.current?.destroy()}}},[]),g.useEffect(()=>{C.current?.update({onPaneContextMenu:e,zoomOnScroll:n,zoomOnPinch:s,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:l,zoomActivationKeyPressed:_,preventScrolling:u,noPanClassName:S,userSelectionActive:M,noWheelClassName:E,lib:D,onTransformChange:$,connectionInProgress:P,selectionOnDrag:b,paneClickDistance:p})},[e,n,s,r,i,o,a,l,_,u,S,M,E,D,$,P,b,p]),t.jsx("div",{className:"react-flow__renderer",ref:w,style:Vr,children:x})}const Nd=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function Cd(){const{userSelectionActive:e,userSelectionRect:n}=Me(Nd,Oe);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 is=(e,n)=>s=>{s.target===n.current&&e?.(s)},Sd=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function Ed({isSelecting:e,selectionKeyPressed:n,selectionMode:s=Qn.Full,panOnDrag:r,paneClickDistance:i,selectionOnDrag:o,onSelectionStart:a,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:h,onPaneMouseEnter:f,onPaneMouseMove:m,onPaneMouseLeave:u,children:x}){const E=Be(),{userSelectionActive:S,elementsSelectable:v,dragging:y,connectionInProgress:p}=Me(Sd,Oe),b=v&&(e||S),N=g.useRef(null),w=g.useRef(),M=g.useRef(new Set),D=g.useRef(new Set),P=g.useRef(!1),_=A=>{if(P.current||p){P.current=!1;return}c?.(A),E.getState().resetSelectedElements(),E.setState({nodesSelectionActive:!1})},C=A=>{if(Array.isArray(r)&&r?.includes(2)){A.preventDefault();return}d?.(A)},$=h?A=>h(A):void 0,z=A=>{P.current&&(A.stopPropagation(),P.current=!1)},j=A=>{const{domNode:L}=E.getState();if(w.current=L?.getBoundingClientRect(),!w.current)return;const q=A.target===N.current;if(!q&&!!A.target.closest(".nokey")||!e||!(o&&q||n)||A.button!==0||!A.isPrimary)return;A.target?.setPointerCapture?.(A.pointerId),P.current=!1;const{x:Q,y:O}=Ct(A.nativeEvent,w.current);E.setState({userSelectionRect:{width:0,height:0,startX:Q,startY:O,x:Q,y:O}}),q||(A.stopPropagation(),A.preventDefault())},B=A=>{const{userSelectionRect:L,transform:q,nodeLookup:F,edgeLookup:Y,connectionLookup:Q,triggerNodeChanges:O,triggerEdgeChanges:I,defaultEdgeOptions:H,resetSelectedElements:V}=E.getState();if(!w.current||!L)return;const{x:W,y:X}=Ct(A.nativeEvent,w.current),{startX:ee,startY:se}=L;if(!P.current){const ie=n?0:i;if(Math.hypot(W-ee,X-se)<=ie)return;V(),a?.(A)}P.current=!0;const J={startX:ee,startY:se,x:W<ee?W:ee,y:X<se?X:se,width:Math.abs(W-ee),height:Math.abs(X-se)},U=M.current,oe=D.current;M.current=new Set(Ns(F,J,q,s===Qn.Partial,!0).map(ie=>ie.id)),D.current=new Set;const le=H?.selectable??!0;for(const ie of M.current){const he=Q.get(ie);if(he)for(const{edgeId:de}of he.values()){const Z=Y.get(de);Z&&(Z.selectable??le)&&D.current.add(de)}}if(!mo(U,M.current)){const ie=Mn(F,M.current,!0);O(ie)}if(!mo(oe,D.current)){const ie=Mn(Y,D.current);I(ie)}E.setState({userSelectionRect:J,userSelectionActive:!0,nodesSelectionActive:!1})},R=A=>{A.button===0&&(A.target?.releasePointerCapture?.(A.pointerId),!S&&A.target===N.current&&E.getState().userSelectionRect&&_?.(A),E.setState({userSelectionActive:!1,userSelectionRect:null}),P.current&&(l?.(A),E.setState({nodesSelectionActive:M.current.size>0})))},T=r===!0||Array.isArray(r)&&r.includes(0);return t.jsxs("div",{className:Ze(["react-flow__pane",{draggable:T,dragging:y,selection:e}]),onClick:b?void 0:is(_,N),onContextMenu:is(C,N),onWheel:is($,N),onPointerEnter:b?void 0:f,onPointerMove:b?B:m,onPointerUp:b?R:void 0,onPointerDownCapture:b?j:void 0,onClickCapture:b?z:void 0,onPointerLeave:u,ref:N,style:Vr,children:[x,t.jsx(Cd,{})]})}function bs({id:e,store:n,unselect:s=!1,nodeRef:r}){const{addSelectedNodes:i,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:l,onError:c}=n.getState(),d=l.get(e);if(!d){c?.("012",Dt.error012(e));return}n.setState({nodesSelectionActive:!1}),d.selected?(s||d.selected&&a)&&(o({nodes:[d],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function bi({nodeRef:e,disabled:n=!1,noDragClassName:s,handleSelector:r,nodeId:i,isSelectable:o,nodeClickDistance:a}){const l=Be(),[c,d]=g.useState(!1),h=g.useRef();return g.useEffect(()=>{h.current=pc({getStoreItems:()=>l.getState(),onNodeMouseDown:f=>{bs({id:f,store:l,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]),c}const Md=e=>n=>n.selected&&(n.draggable||e&&typeof n.draggable>"u");function yi(){const e=Be();return g.useCallback(s=>{const{nodeExtent:r,snapToGrid:i,snapGrid:o,nodesDraggable:a,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:h}=e.getState(),f=new Map,m=Md(a),u=i?o[0]:5,x=i?o[1]:5,E=s.direction.x*u*s.factor,S=s.direction.y*x*s.factor;for(const[,v]of d){if(!m(v))continue;let y={x:v.internals.positionAbsolute.x+E,y:v.internals.positionAbsolute.y+S};i&&(y=ar(y,o));const{position:p,positionAbsolute:b}=Ba({nodeId:v.id,nextPosition:y,nodeLookup:d,nodeExtent:r,nodeOrigin:h,onError:l});v.position=p,v.internals.positionAbsolute=b,f.set(v.id,v)}c(f)},[])}const As=g.createContext(null),Id=As.Provider;As.Consumer;const vi=()=>g.useContext(As),Td=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Rd=(e,n,s)=>r=>{const{connectionClickStartHandle:i,connectionMode:o,connection:a}=r,{fromHandle:l,toHandle:c,isValid:d}=a,h=c?.nodeId===e&&c?.id===n&&c?.type===s;return{connectingFrom:l?.nodeId===e&&l?.id===n&&l?.type===s,connectingTo:h,clickConnecting:i?.nodeId===e&&i?.id===n&&i?.type===s,isPossibleEndHandle:o===Rn.Strict?l?.type!==s:e!==l?.nodeId||n!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!i,valid:h&&d}};function _d({type:e="source",position:n=ye.Top,isValidConnection:s,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,id:a,onConnect:l,children:c,className:d,onMouseDown:h,onTouchStart:f,...m},u){const x=a||null,E=e==="target",S=Be(),v=vi(),{connectOnClick:y,noPanClassName:p,rfId:b}=Me(Td,Oe),{connectingFrom:N,connectingTo:w,clickConnecting:M,isPossibleEndHandle:D,connectionInProcess:P,clickConnectionInProcess:_,valid:C}=Me(Rd(v,x,e),Oe);v||S.getState().onError?.("010",Dt.error010());const $=B=>{const{defaultEdgeOptions:R,onConnect:T,hasDefaultEdges:A}=S.getState(),L={...R,...B};if(A){const{edges:q,setEdges:F}=S.getState();F(ec(L,q))}T?.(L),l?.(L)},z=B=>{if(!v)return;const R=Ya(B.nativeEvent);if(i&&(R&&B.button===0||!R)){const T=S.getState();xs.onPointerDown(B.nativeEvent,{handleDomNode:B.currentTarget,autoPanOnConnect:T.autoPanOnConnect,connectionMode:T.connectionMode,connectionRadius:T.connectionRadius,domNode:T.domNode,nodeLookup:T.nodeLookup,lib:T.lib,isTarget:E,handleId:x,nodeId:v,flowId:T.rfId,panBy:T.panBy,cancelConnection:T.cancelConnection,onConnectStart:T.onConnectStart,onConnectEnd:(...A)=>S.getState().onConnectEnd?.(...A),updateConnection:T.updateConnection,onConnect:$,isValidConnection:s||((...A)=>S.getState().isValidConnection?.(...A)??!0),getTransform:()=>S.getState().transform,getFromHandle:()=>S.getState().connection.fromHandle,autoPanSpeed:T.autoPanSpeed,dragThreshold:T.connectionDragThreshold})}R?h?.(B):f?.(B)},j=B=>{const{onClickConnectStart:R,onClickConnectEnd:T,connectionClickStartHandle:A,connectionMode:L,isValidConnection:q,lib:F,rfId:Y,nodeLookup:Q,connection:O}=S.getState();if(!v||!A&&!i)return;if(!A){R?.(B.nativeEvent,{nodeId:v,handleId:x,handleType:e}),S.setState({connectionClickStartHandle:{nodeId:v,type:e,id:x}});return}const I=Wa(B.target),H=s||q,{connection:V,isValid:W}=xs.isValid(B.nativeEvent,{handle:{nodeId:v,id:x,type:e},connectionMode:L,fromNodeId:A.nodeId,fromHandleId:A.id||null,fromType:A.type,isValidConnection:H,flowId:Y,doc:I,lib:F,nodeLookup:Q});W&&V&&$(V);const X=structuredClone(O);delete X.inProgress,X.toPosition=X.toHandle?X.toHandle.position:null,T?.(B,X),S.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":x,"data-nodeid":v,"data-handlepos":n,"data-id":`${b}-${v}-${x}-${e}`,className:Ze(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",p,d,{source:!E,target:E,connectable:r,connectablestart:i,connectableend:o,clickconnecting:M,connectingfrom:N,connectingto:w,valid:C,connectionindicator:r&&(!P||D)&&(P||_?o:i)}]),onMouseDown:z,onTouchStart:z,onClick:y?j:void 0,ref:u,...m,children:c})}const Jt=g.memo(pi(_d));function Ad({data:e,isConnectable:n,sourcePosition:s=ye.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(Jt,{type:"source",position:s,isConnectable:n})]})}function Ld({data:e,isConnectable:n,targetPosition:s=ye.Top,sourcePosition:r=ye.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(Jt,{type:"target",position:s,isConnectable:n}),e?.label,t.jsx(Jt,{type:"source",position:r,isConnectable:n})]})}function Dd(){return null}function Pd({data:e,isConnectable:n,targetPosition:s=ye.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(Jt,{type:"target",position:s,isConnectable:n}),e?.label]})}const Pr={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},qo={input:Ad,default:Ld,output:Pd,group:Dd};function $d(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 Bd=e=>{const{width:n,height:s,x:r,y:i}=or(e.nodeLookup,{filter:o=>!!o.selected});return{width:Nt(n)?n:null,height:Nt(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 Od({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:s}){const r=Be(),{width:i,height:o,transformString:a,userSelectionActive:l}=Me(Bd,Oe),c=yi(),d=g.useRef(null);g.useEffect(()=>{s||d.current?.focus({preventScroll:!0})},[s]);const h=!l&&i!==null&&o!==null;if(bi({nodeRef:d,disabled:!h}),!h)return null;const f=e?u=>{const x=r.getState().nodes.filter(E=>E.selected);e(u,x)}:void 0,m=u=>{Object.prototype.hasOwnProperty.call(Pr,u.key)&&(u.preventDefault(),c({direction:Pr[u.key],factor:u.shiftKey?4:1}))};return t.jsx("div",{className:Ze(["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 Vo=typeof window<"u"?window:void 0,zd=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function wi({children:e,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:h,selectionMode:f,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:x,panActivationKeyCode:E,zoomActivationKeyCode:S,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:p,panOnScroll:b,panOnScrollSpeed:N,panOnScrollMode:w,zoomOnDoubleClick:M,panOnDrag:D,defaultViewport:P,translateExtent:_,minZoom:C,maxZoom:$,preventScrolling:z,onSelectionContextMenu:j,noWheelClassName:B,noPanClassName:R,disableKeyboardA11y:T,onViewportChange:A,isControlledViewport:L}){const{nodesSelectionActive:q,userSelectionActive:F}=Me(zd,Oe),Y=tr(d,{target:Vo}),Q=tr(E,{target:Vo}),O=Q||D,I=Q||b,H=h&&O!==!0,V=Y||F||H;return vd({deleteKeyCode:c,multiSelectionKeyCode:x}),t.jsx(jd,{onPaneContextMenu:o,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:p,panOnScroll:I,panOnScrollSpeed:N,panOnScrollMode:w,zoomOnDoubleClick:M,panOnDrag:!Y&&O,defaultViewport:P,translateExtent:_,minZoom:C,maxZoom:$,zoomActivationKeyCode:S,preventScrolling:z,noWheelClassName:B,noPanClassName:R,onViewportChange:A,isControlledViewport:L,paneClickDistance:l,selectionOnDrag:H,children:t.jsxs(Ed,{onSelectionStart:m,onSelectionEnd:u,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:O,isSelecting:!!V,selectionMode:f,selectionKeyPressed:Y,paneClickDistance:l,selectionOnDrag:H,children:[e,q&&t.jsx(Od,{onSelectionContextMenu:j,noPanClassName:R,disableKeyboardA11y:T})]})})}wi.displayName="FlowRenderer";const Hd=g.memo(wi),qd=e=>n=>e?Ns(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 Vd(e){return Me(g.useCallback(qd(e),[e]),Oe)}const Wd=e=>e.updateNodeInternals;function Fd(){const e=Me(Wd),[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 Yd({node:e,nodeType:n,hasDimensions:s,resizeObserver:r}){const i=Be(),o=g.useRef(null),a=g.useRef(null),l=g.useRef(e.sourcePosition),c=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=l.current!==e.sourcePosition,u=c.current!==e.targetPosition;(f||m||u)&&(d.current=n,l.current=e.sourcePosition,c.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:o.current,force:!0}]])))}},[e.id,n,e.sourcePosition,e.targetPosition]),o}function Gd({id:e,onClick:n,onMouseEnter:s,onMouseMove:r,onMouseLeave:i,onContextMenu:o,onDoubleClick:a,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:h,resizeObserver:f,noDragClassName:m,noPanClassName:u,disableKeyboardA11y:x,rfId:E,nodeTypes:S,nodeClickDistance:v,onError:y}){const{node:p,internals:b,isParent:N}=Me(W=>{const X=W.nodeLookup.get(e),ee=W.parentLookup.has(e);return{node:X,internals:X.internals,isParent:ee}},Oe);let w=p.type||"default",M=S?.[w]||qo[w];M===void 0&&(y?.("003",Dt.error003(w)),w="default",M=S?.default||qo.default);const D=!!(p.draggable||l&&typeof p.draggable>"u"),P=!!(p.selectable||c&&typeof p.selectable>"u"),_=!!(p.connectable||d&&typeof p.connectable>"u"),C=!!(p.focusable||h&&typeof p.focusable>"u"),$=Be(),z=qa(p),j=Yd({node:p,nodeType:w,hasDimensions:z,resizeObserver:f}),B=bi({nodeRef:j,disabled:p.hidden||!D,noDragClassName:m,handleSelector:p.dragHandle,nodeId:e,isSelectable:P,nodeClickDistance:v}),R=yi();if(p.hidden)return null;const T=Ft(p),A=$d(p),L=P||D||n||s||r||i,q=s?W=>s(W,{...b.userNode}):void 0,F=r?W=>r(W,{...b.userNode}):void 0,Y=i?W=>i(W,{...b.userNode}):void 0,Q=o?W=>o(W,{...b.userNode}):void 0,O=a?W=>a(W,{...b.userNode}):void 0,I=W=>{const{selectNodesOnDrag:X,nodeDragThreshold:ee}=$.getState();P&&(!X||!D||ee>0)&&bs({id:e,store:$,nodeRef:j}),n&&n(W,{...b.userNode})},H=W=>{if(!(Fa(W.nativeEvent)||x)){if(Aa.includes(W.key)&&P){const X=W.key==="Escape";bs({id:e,store:$,unselect:X,nodeRef:j})}else if(D&&p.selected&&Object.prototype.hasOwnProperty.call(Pr,W.key)){W.preventDefault();const{ariaLabelConfig:X}=$.getState();$.setState({ariaLiveMessage:X["node.a11yDescription.ariaLiveMessage"]({direction:W.key.replace("Arrow","").toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),R({direction:Pr[W.key],factor:W.shiftKey?4:1})}}},V=()=>{if(x||!j.current?.matches(":focus-visible"))return;const{transform:W,width:X,height:ee,autoPanOnNodeFocus:se,setCenter:J}=$.getState();if(!se)return;Ns(new Map([[e,p]]),{x:0,y:0,width:X,height:ee},W,!0).length>0||J(p.position.x+T.width/2,p.position.y+T.height/2,{zoom:W[2]})};return t.jsx("div",{className:Ze(["react-flow__node",`react-flow__node-${w}`,{[u]:D},p.className,{selected:p.selected,selectable:P,parent:N,draggable:D,dragging:B}]),ref:j,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:L?"all":"none",visibility:z?"visible":"hidden",...p.style,...A},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:q,onMouseMove:F,onMouseLeave:Y,onContextMenu:Q,onClick:I,onDoubleClick:O,onKeyDown:C?H:void 0,tabIndex:C?0:void 0,onFocus:C?V:void 0,role:p.ariaRole??(C?"group":void 0),"aria-roledescription":"node","aria-describedby":x?void 0:`${di}-${E}`,"aria-label":p.ariaLabel,...p.domAttributes,children:t.jsx(Id,{value:e,children:t.jsx(M,{id:e,data:p.data,type:w,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:p.selected??!1,selectable:P,draggable:D,deletable:p.deletable??!0,isConnectable:_,sourcePosition:p.sourcePosition,targetPosition:p.targetPosition,dragging:B,dragHandle:p.dragHandle,zIndex:b.z,parentId:p.parentId,...T})})})}var Zd=g.memo(Gd);const Xd=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function ki(e){const{nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,onError:o}=Me(Xd,Oe),a=Vd(e.onlyRenderVisibleElements),l=Fd();return t.jsx("div",{className:"react-flow__nodes",style:Vr,children:a.map(c=>t.jsx(Zd,{id:c,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:l,nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:o},c))})}ki.displayName="NodeRenderer";const Ud=g.memo(ki);function Kd(e){return Me(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&&Kl({sourceNode:o,targetNode:a,width:s.width,height:s.height,transform:s.transform})&&r.push(i.id)}return r},[e]),Oe)}const Qd=({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"})},Jd=({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"})},Wo={[_n.Arrow]:Qd,[_n.ArrowClosed]:Jd};function eu(e){const n=Be();return g.useMemo(()=>Object.prototype.hasOwnProperty.call(Wo,e)?Wo[e]:(n.getState().onError?.("009",Dt.error009(e)),null),[e])}const tu=({id:e,type:n,color:s,width:r=12.5,height:i=12.5,markerUnits:o="strokeWidth",strokeWidth:a,orient:l="auto-start-reverse"})=>{const c=eu(n);return c?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:l,refX:"0",refY:"0",children:t.jsx(c,{color:s,strokeWidth:a})}):null},ji=({defaultColor:e,rfId:n})=>{const s=Me(o=>o.edges),r=Me(o=>o.defaultEdgeOptions),i=g.useMemo(()=>oc(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(tu,{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};ji.displayName="MarkerDefinitions";var nu=g.memo(ji);function Ni({x:e,y:n,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:l=2,children:c,className:d,...h}){const[f,m]=g.useState({x:1,y:0,width:0,height:0}),u=Ze(["react-flow__edge-textwrapper",d]),x=g.useRef(null);return g.useEffect(()=>{if(x.current){const E=x.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:l,ry:l}),t.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:x,style:r,children:s}),c]}):null}Ni.displayName="EdgeText";const ru=g.memo(Ni);function Wr({path:e,labelX:n,labelY:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...h}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...h,d:e,fill:"none",className:Ze(["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&&Nt(n)&&Nt(s)?t.jsx(ru,{x:n,y:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Fo({pos:e,x1:n,y1:s,x2:r,y2:i}){return e===ye.Left||e===ye.Right?[.5*(n+r),s]:[n,.5*(s+i)]}function Ci({sourceX:e,sourceY:n,sourcePosition:s=ye.Bottom,targetX:r,targetY:i,targetPosition:o=ye.Top}){const[a,l]=Fo({pos:s,x1:e,y1:n,x2:r,y2:i}),[c,d]=Fo({pos:o,x1:r,y1:i,x2:e,y2:n}),[h,f,m,u]=Ga({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:a,sourceControlY:l,targetControlX:c,targetControlY:d});return[`M${e},${n} C${a},${l} ${c},${d} ${r},${i}`,h,f,m,u]}function Si(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a,targetPosition:l,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:S,interactionWidth:v})=>{const[y,p,b]=Ci({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:l}),N=e.isInternal?void 0:n;return t.jsx(Wr,{id:N,path:y,labelX:p,labelY:b,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:S,interactionWidth:v})})}const su=Si({isInternal:!1}),Ei=Si({isInternal:!0});su.displayName="SimpleBezierEdge";Ei.displayName="SimpleBezierEdgeInternal";function Mi(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,sourcePosition:u=ye.Bottom,targetPosition:x=ye.Top,markerEnd:E,markerStart:S,pathOptions:v,interactionWidth:y})=>{const[p,b,N]=ms({sourceX:s,sourceY:r,sourcePosition:u,targetX:i,targetY:o,targetPosition:x,borderRadius:v?.borderRadius,offset:v?.offset,stepPosition:v?.stepPosition}),w=e.isInternal?void 0:n;return t.jsx(Wr,{id:w,path:p,labelX:b,labelY:N,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:E,markerStart:S,interactionWidth:y})})}const Ii=Mi({isInternal:!1}),Ti=Mi({isInternal:!0});Ii.displayName="SmoothStepEdge";Ti.displayName="SmoothStepEdgeInternal";function Ri(e){return g.memo(({id:n,...s})=>{const r=e.isInternal?void 0:n;return t.jsx(Ii,{...s,id:r,pathOptions:g.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const ou=Ri({isInternal:!1}),_i=Ri({isInternal:!0});ou.displayName="StepEdge";_i.displayName="StepEdgeInternal";function Ai(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:x,interactionWidth:E})=>{const[S,v,y]=Ua({sourceX:s,sourceY:r,targetX:i,targetY:o}),p=e.isInternal?void 0:n;return t.jsx(Wr,{id:p,path:S,labelX:v,labelY:y,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:x,interactionWidth:E})})}const au=Ai({isInternal:!1}),Li=Ai({isInternal:!0});au.displayName="StraightEdge";Li.displayName="StraightEdgeInternal";function Di(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a=ye.Bottom,targetPosition:l=ye.Top,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:S,pathOptions:v,interactionWidth:y})=>{const[p,b,N]=Za({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:l,curvature:v?.curvature}),w=e.isInternal?void 0:n;return t.jsx(Wr,{id:w,path:p,labelX:b,labelY:N,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:S,interactionWidth:y})})}const iu=Di({isInternal:!1}),Pi=Di({isInternal:!0});iu.displayName="BezierEdge";Pi.displayName="BezierEdgeInternal";const Yo={default:Pi,straight:Li,step:_i,smoothstep:Ti,simplebezier:Ei},Go={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},lu=(e,n,s)=>s===ye.Left?e-n:s===ye.Right?e+n:e,cu=(e,n,s)=>s===ye.Top?e-n:s===ye.Bottom?e+n:e,Zo="react-flow__edgeupdater";function Xo({position:e,centerX:n,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:o,onMouseOut:a,type:l}){return t.jsx("circle",{onMouseDown:i,onMouseEnter:o,onMouseOut:a,className:Ze([Zo,`${Zo}-${l}`]),cx:lu(n,r,e),cy:cu(s,r,e),r,stroke:"transparent",fill:"transparent"})}function du({isReconnectable:e,reconnectRadius:n,edge:s,sourceX:r,sourceY:i,targetX:o,targetY:a,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:h,onReconnectEnd:f,setReconnecting:m,setUpdateHover:u}){const x=Be(),E=(b,N)=>{if(b.button!==0)return;const{autoPanOnConnect:w,domNode:M,connectionMode:D,connectionRadius:P,lib:_,onConnectStart:C,cancelConnection:$,nodeLookup:z,rfId:j,panBy:B,updateConnection:R}=x.getState(),T=N.type==="target",A=(F,Y)=>{m(!1),f?.(F,s,N.type,Y)},L=F=>d?.(s,F),q=(F,Y)=>{m(!0),h?.(b,s,N.type),C?.(F,Y)};xs.onPointerDown(b.nativeEvent,{autoPanOnConnect:w,connectionMode:D,connectionRadius:P,domNode:M,handleId:N.id,nodeId:N.nodeId,nodeLookup:z,isTarget:T,edgeUpdaterType:N.type,lib:_,flowId:j,cancelConnection:$,panBy:B,isValidConnection:(...F)=>x.getState().isValidConnection?.(...F)??!0,onConnect:L,onConnectStart:q,onConnectEnd:(...F)=>x.getState().onConnectEnd?.(...F),onReconnectEnd:A,updateConnection:R,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,dragThreshold:x.getState().connectionDragThreshold,handleDomNode:b.currentTarget})},S=b=>E(b,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),v=b=>E(b,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),y=()=>u(!0),p=()=>u(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(Xo,{position:l,centerX:r,centerY:i,radius:n,onMouseDown:S,onMouseEnter:y,onMouseOut:p,type:"source"}),(e===!0||e==="target")&&t.jsx(Xo,{position:c,centerX:o,centerY:a,radius:n,onMouseDown:v,onMouseEnter:y,onMouseOut:p,type:"target"})]})}function uu({id:e,edgesFocusable:n,edgesReconnectable:s,elementsSelectable:r,onClick:i,onDoubleClick:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,rfId:x,edgeTypes:E,noPanClassName:S,onError:v,disableKeyboardA11y:y}){let p=Me(J=>J.edgeLookup.get(e));const b=Me(J=>J.defaultEdgeOptions);p=b?{...b,...p}:p;let N=p.type||"default",w=E?.[N]||Yo[N];w===void 0&&(v?.("011",Dt.error011(N)),N="default",w=E?.default||Yo.default);const M=!!(p.focusable||n&&typeof p.focusable>"u"),D=typeof f<"u"&&(p.reconnectable||s&&typeof p.reconnectable>"u"),P=!!(p.selectable||r&&typeof p.selectable>"u"),_=g.useRef(null),[C,$]=g.useState(!1),[z,j]=g.useState(!1),B=Be(),{zIndex:R,sourceX:T,sourceY:A,targetX:L,targetY:q,sourcePosition:F,targetPosition:Y}=Me(g.useCallback(J=>{const U=J.nodeLookup.get(p.source),oe=J.nodeLookup.get(p.target);if(!U||!oe)return{zIndex:p.zIndex,...Go};const le=sc({id:e,sourceNode:U,targetNode:oe,sourceHandle:p.sourceHandle||null,targetHandle:p.targetHandle||null,connectionMode:J.connectionMode,onError:v});return{zIndex:Ul({selected:p.selected,zIndex:p.zIndex,sourceNode:U,targetNode:oe,elevateOnSelect:J.elevateEdgesOnSelect,zIndexMode:J.zIndexMode}),...le||Go}},[p.source,p.target,p.sourceHandle,p.targetHandle,p.selected,p.zIndex]),Oe),Q=g.useMemo(()=>p.markerStart?`url('#${gs(p.markerStart,x)}')`:void 0,[p.markerStart,x]),O=g.useMemo(()=>p.markerEnd?`url('#${gs(p.markerEnd,x)}')`:void 0,[p.markerEnd,x]);if(p.hidden||T===null||A===null||L===null||q===null)return null;const I=J=>{const{addSelectedEdges:U,unselectNodesAndEdges:oe,multiSelectionActive:le}=B.getState();P&&(B.setState({nodesSelectionActive:!1}),p.selected&&le?(oe({nodes:[],edges:[p]}),_.current?.blur()):U([e])),i&&i(J,p)},H=o?J=>{o(J,{...p})}:void 0,V=a?J=>{a(J,{...p})}:void 0,W=l?J=>{l(J,{...p})}:void 0,X=c?J=>{c(J,{...p})}:void 0,ee=d?J=>{d(J,{...p})}:void 0,se=J=>{if(!y&&Aa.includes(J.key)&&P){const{unselectNodesAndEdges:U,addSelectedEdges:oe}=B.getState();J.key==="Escape"?(_.current?.blur(),U({edges:[p]})):oe([e])}};return t.jsx("svg",{style:{zIndex:R},children:t.jsxs("g",{className:Ze(["react-flow__edge",`react-flow__edge-${N}`,p.className,S,{selected:p.selected,animated:p.animated,inactive:!P&&!i,updating:C,selectable:P}]),onClick:I,onDoubleClick:H,onContextMenu:V,onMouseEnter:W,onMouseMove:X,onMouseLeave:ee,onKeyDown:M?se:void 0,tabIndex:M?0:void 0,role:p.ariaRole??(M?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":p.ariaLabel===null?void 0:p.ariaLabel||`Edge from ${p.source} to ${p.target}`,"aria-describedby":M?`${ui}-${x}`:void 0,ref:_,...p.domAttributes,children:[!z&&t.jsx(w,{id:e,source:p.source,target:p.target,type:p.type,selected:p.selected,animated:p.animated,selectable:P,deletable:p.deletable??!0,label:p.label,labelStyle:p.labelStyle,labelShowBg:p.labelShowBg,labelBgStyle:p.labelBgStyle,labelBgPadding:p.labelBgPadding,labelBgBorderRadius:p.labelBgBorderRadius,sourceX:T,sourceY:A,targetX:L,targetY:q,sourcePosition:F,targetPosition:Y,data:p.data,style:p.style,sourceHandleId:p.sourceHandle,targetHandleId:p.targetHandle,markerStart:Q,markerEnd:O,pathOptions:"pathOptions"in p?p.pathOptions:void 0,interactionWidth:p.interactionWidth}),D&&t.jsx(du,{edge:p,isReconnectable:D,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,sourceX:T,sourceY:A,targetX:L,targetY:q,sourcePosition:F,targetPosition:Y,setUpdateHover:$,setReconnecting:j})]})})}var fu=g.memo(uu);const hu=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function $i({defaultMarkerColor:e,onlyRenderVisibleElements:n,rfId:s,edgeTypes:r,noPanClassName:i,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:h,reconnectRadius:f,onEdgeDoubleClick:m,onReconnectStart:u,onReconnectEnd:x,disableKeyboardA11y:E}){const{edgesFocusable:S,edgesReconnectable:v,elementsSelectable:y,onError:p}=Me(hu,Oe),b=Kd(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(nu,{defaultColor:e,rfId:s}),b.map(N=>t.jsx(fu,{id:N,edgesFocusable:S,edgesReconnectable:v,elementsSelectable:y,noPanClassName:i,onReconnect:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:h,reconnectRadius:f,onDoubleClick:m,onReconnectStart:u,onReconnectEnd:x,rfId:s,onError:p,edgeTypes:r,disableKeyboardA11y:E},N))]})}$i.displayName="EdgeRenderer";const mu=g.memo($i),gu=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function pu({children:e}){const n=Me(gu);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function xu(e){const n=_s(),s=g.useRef(!1);g.useEffect(()=>{!s.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),s.current=!0)},[e,n.viewportInitialized])}const bu=e=>e.panZoom?.syncViewport;function yu(e){const n=Me(bu),s=Be();return g.useEffect(()=>{e&&(n?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,n]),null}function vu(e){return e.connection.inProgress?{...e.connection,to:ir(e.connection.to,e.transform)}:{...e.connection}}function wu(e){return vu}function ku(e){const n=wu();return Me(n,Oe)}const ju=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function Nu({containerStyle:e,style:n,type:s,component:r}){const{nodesConnectable:i,width:o,height:a,isValid:l,inProgress:c}=Me(ju,Oe);return!(o&&i&&c)?null:t.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:Ze(["react-flow__connection",Pa(l)]),children:t.jsx(Bi,{style:n,type:s,CustomComponent:r,isValid:l})})})}const Bi=({style:e,type:n=Kt.Bezier,CustomComponent:s,isValid:r})=>{const{inProgress:i,from:o,fromNode:a,fromHandle:l,fromPosition:c,to:d,toNode:h,toHandle:f,toPosition:m,pointer:u}=ku();if(!i)return;if(s)return t.jsx(s,{connectionLineType:n,connectionLineStyle:e,fromNode:a,fromHandle:l,fromX:o.x,fromY:o.y,toX:d.x,toY:d.y,fromPosition:c,toPosition:m,connectionStatus:Pa(r),toNode:h,toHandle:f,pointer:u});let x="";const E={sourceX:o.x,sourceY:o.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:m};switch(n){case Kt.Bezier:[x]=Za(E);break;case Kt.SimpleBezier:[x]=Ci(E);break;case Kt.Step:[x]=ms({...E,borderRadius:0});break;case Kt.SmoothStep:[x]=ms(E);break;default:[x]=Ua(E)}return t.jsx("path",{d:x,fill:"none",className:"react-flow__connection-path",style:e})};Bi.displayName="ConnectionLine";const Cu={};function Uo(e=Cu){g.useRef(e),Be(),g.useEffect(()=>{},[e])}function Su(){Be(),g.useRef(!1),g.useEffect(()=>{},[])}function Oi({nodeTypes:e,edgeTypes:n,onInit:s,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,onSelectionContextMenu:f,onSelectionStart:m,onSelectionEnd:u,connectionLineType:x,connectionLineStyle:E,connectionLineComponent:S,connectionLineContainerStyle:v,selectionKeyCode:y,selectionOnDrag:p,selectionMode:b,multiSelectionKeyCode:N,panActivationKeyCode:w,zoomActivationKeyCode:M,deleteKeyCode:D,onlyRenderVisibleElements:P,elementsSelectable:_,defaultViewport:C,translateExtent:$,minZoom:z,maxZoom:j,preventScrolling:B,defaultMarkerColor:R,zoomOnScroll:T,zoomOnPinch:A,panOnScroll:L,panOnScrollSpeed:q,panOnScrollMode:F,zoomOnDoubleClick:Y,panOnDrag:Q,onPaneClick:O,onPaneMouseEnter:I,onPaneMouseMove:H,onPaneMouseLeave:V,onPaneScroll:W,onPaneContextMenu:X,paneClickDistance:ee,nodeClickDistance:se,onEdgeContextMenu:J,onEdgeMouseEnter:U,onEdgeMouseMove:oe,onEdgeMouseLeave:le,reconnectRadius:ie,onReconnect:he,onReconnectStart:de,onReconnectEnd:Z,noDragClassName:ae,noWheelClassName:me,noPanClassName:ve,disableKeyboardA11y:ce,nodeExtent:te,rfId:pe,viewport:Te,onViewportChange:be}){return Uo(e),Uo(n),Su(),xu(s),yu(Te),t.jsx(Hd,{onPaneClick:O,onPaneMouseEnter:I,onPaneMouseMove:H,onPaneMouseLeave:V,onPaneContextMenu:X,onPaneScroll:W,paneClickDistance:ee,deleteKeyCode:D,selectionKeyCode:y,selectionOnDrag:p,selectionMode:b,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:N,panActivationKeyCode:w,zoomActivationKeyCode:M,elementsSelectable:_,zoomOnScroll:T,zoomOnPinch:A,zoomOnDoubleClick:Y,panOnScroll:L,panOnScrollSpeed:q,panOnScrollMode:F,panOnDrag:Q,defaultViewport:C,translateExtent:$,minZoom:z,maxZoom:j,onSelectionContextMenu:f,preventScrolling:B,noDragClassName:ae,noWheelClassName:me,noPanClassName:ve,disableKeyboardA11y:ce,onViewportChange:be,isControlledViewport:!!Te,children:t.jsxs(pu,{children:[t.jsx(mu,{edgeTypes:n,onEdgeClick:i,onEdgeDoubleClick:a,onReconnect:he,onReconnectStart:de,onReconnectEnd:Z,onlyRenderVisibleElements:P,onEdgeContextMenu:J,onEdgeMouseEnter:U,onEdgeMouseMove:oe,onEdgeMouseLeave:le,reconnectRadius:ie,defaultMarkerColor:R,noPanClassName:ve,disableKeyboardA11y:ce,rfId:pe}),t.jsx(Nu,{style:E,type:x,component:S,containerStyle:v}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(Ud,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:se,onlyRenderVisibleElements:P,noPanClassName:ve,noDragClassName:ae,disableKeyboardA11y:ce,nodeExtent:te,rfId:pe}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}Oi.displayName="GraphView";const Eu=g.memo(Oi),Ko=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c=.5,maxZoom:d=2,nodeOrigin:h,nodeExtent:f,zIndexMode:m="basic"}={})=>{const u=new Map,x=new Map,E=new Map,S=new Map,v=r??n??[],y=s??e??[],p=h??[0,0],b=f??Kn;Ja(E,S,v);const N=ps(y,u,x,{nodeOrigin:p,nodeExtent:b,zIndexMode:m});let w=[0,0,1];if(a&&i&&o){const M=or(u,{filter:C=>!!((C.width||C.initialWidth)&&(C.height||C.initialHeight))}),{x:D,y:P,zoom:_}=Cs(M,i,o,c,d,l?.padding??.1);w=[D,P,_]}return{rfId:"1",width:i??0,height:o??0,transform:w,nodes:y,nodesInitialized:N,nodeLookup:u,parentLookup:x,edges:v,edgeLookup:S,connectionLookup:E,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:Kn,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Rn.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:p,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:a??!1,fitViewOptions:l,fitViewResolver:null,connection:{...Da},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Wl,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:La,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},Mu=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m})=>Yc((u,x)=>{async function E(){const{nodeLookup:S,panZoom:v,fitViewOptions:y,fitViewResolver:p,width:b,height:N,minZoom:w,maxZoom:M}=x();v&&(await ql({nodes:S,width:b,height:N,panZoom:v,minZoom:w,maxZoom:M},y),p?.resolve(!0),u({fitViewResolver:null}))}return{...Ko({nodes:e,edges:n,width:i,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:h,nodeExtent:f,defaultNodes:s,defaultEdges:r,zIndexMode:m}),setNodes:S=>{const{nodeLookup:v,parentLookup:y,nodeOrigin:p,elevateNodesOnSelect:b,fitViewQueued:N,zIndexMode:w}=x(),M=ps(S,v,y,{nodeOrigin:p,nodeExtent:f,elevateNodesOnSelect:b,checkEquality:!0,zIndexMode:w});N&&M?(E(),u({nodes:S,nodesInitialized:M,fitViewQueued:!1,fitViewOptions:void 0})):u({nodes:S,nodesInitialized:M})},setEdges:S=>{const{connectionLookup:v,edgeLookup:y}=x();Ja(v,y,S),u({edges:S})},setDefaultNodesAndEdges:(S,v)=>{if(S){const{setNodes:y}=x();y(S),u({hasDefaultNodes:!0})}if(v){const{setEdges:y}=x();y(v),u({hasDefaultEdges:!0})}},updateNodeInternals:S=>{const{triggerNodeChanges:v,nodeLookup:y,parentLookup:p,domNode:b,nodeOrigin:N,nodeExtent:w,debug:M,fitViewQueued:D,zIndexMode:P}=x(),{changes:_,updatedInternals:C}=fc(S,y,p,b,N,w,P);C&&(lc(y,p,{nodeOrigin:N,nodeExtent:w,zIndexMode:P}),D?(E(),u({fitViewQueued:!1,fitViewOptions:void 0})):u({}),_?.length>0&&(M&&console.log("React Flow: trigger node changes",_),v?.(_)))},updateNodePositions:(S,v=!1)=>{const y=[];let p=[];const{nodeLookup:b,triggerNodeChanges:N,connection:w,updateConnection:M,onNodesChangeMiddlewareMap:D}=x();for(const[P,_]of S){const C=b.get(P),$=!!(C?.expandParent&&C?.parentId&&_?.position),z={id:P,type:"position",position:$?{x:Math.max(0,_.position.x),y:Math.max(0,_.position.y)}:_.position,dragging:v};if(C&&w.inProgress&&w.fromNode.id===C.id){const j=hn(C,w.fromHandle,ye.Left,!0);M({...w,from:j})}$&&C.parentId&&y.push({id:P,parentId:C.parentId,rect:{..._.internals.positionAbsolute,width:_.measured.width??0,height:_.measured.height??0}}),p.push(z)}if(y.length>0){const{parentLookup:P,nodeOrigin:_}=x(),C=Rs(y,b,P,_);p.push(...C)}for(const P of D.values())p=P(p);N(p)},triggerNodeChanges:S=>{const{onNodesChange:v,setNodes:y,nodes:p,hasDefaultNodes:b,debug:N}=x();if(S?.length){if(b){const w=mi(S,p);y(w)}N&&console.log("React Flow: trigger node changes",S),v?.(S)}},triggerEdgeChanges:S=>{const{onEdgesChange:v,setEdges:y,edges:p,hasDefaultEdges:b,debug:N}=x();if(S?.length){if(b){const w=gi(S,p);y(w)}N&&console.log("React Flow: trigger edge changes",S),v?.(S)}},addSelectedNodes:S=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:p,triggerNodeChanges:b,triggerEdgeChanges:N}=x();if(v){const w=S.map(M=>dn(M,!0));b(w);return}b(Mn(p,new Set([...S]),!0)),N(Mn(y))},addSelectedEdges:S=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:p,triggerNodeChanges:b,triggerEdgeChanges:N}=x();if(v){const w=S.map(M=>dn(M,!0));N(w);return}N(Mn(y,new Set([...S]))),b(Mn(p,new Set,!0))},unselectNodesAndEdges:({nodes:S,edges:v}={})=>{const{edges:y,nodes:p,nodeLookup:b,triggerNodeChanges:N,triggerEdgeChanges:w}=x(),M=S||p,D=v||y,P=[];for(const C of M){if(!C.selected)continue;const $=b.get(C.id);$&&($.selected=!1),P.push(dn(C.id,!1))}const _=[];for(const C of D)C.selected&&_.push(dn(C.id,!1));N(P),w(_)},setMinZoom:S=>{const{panZoom:v,maxZoom:y}=x();v?.setScaleExtent([S,y]),u({minZoom:S})},setMaxZoom:S=>{const{panZoom:v,minZoom:y}=x();v?.setScaleExtent([y,S]),u({maxZoom:S})},setTranslateExtent:S=>{x().panZoom?.setTranslateExtent(S),u({translateExtent:S})},resetSelectedElements:()=>{const{edges:S,nodes:v,triggerNodeChanges:y,triggerEdgeChanges:p,elementsSelectable:b}=x();if(!b)return;const N=v.reduce((M,D)=>D.selected?[...M,dn(D.id,!1)]:M,[]),w=S.reduce((M,D)=>D.selected?[...M,dn(D.id,!1)]:M,[]);y(N),p(w)},setNodeExtent:S=>{const{nodes:v,nodeLookup:y,parentLookup:p,nodeOrigin:b,elevateNodesOnSelect:N,nodeExtent:w,zIndexMode:M}=x();S[0][0]===w[0][0]&&S[0][1]===w[0][1]&&S[1][0]===w[1][0]&&S[1][1]===w[1][1]||(ps(v,y,p,{nodeOrigin:b,nodeExtent:S,elevateNodesOnSelect:N,checkEquality:!1,zIndexMode:M}),u({nodeExtent:S}))},panBy:S=>{const{transform:v,width:y,height:p,panZoom:b,translateExtent:N}=x();return hc({delta:S,panZoom:b,transform:v,translateExtent:N,width:y,height:p})},setCenter:async(S,v,y)=>{const{width:p,height:b,maxZoom:N,panZoom:w}=x();if(!w)return Promise.resolve(!1);const M=typeof y?.zoom<"u"?y.zoom:N;return await w.setViewport({x:p/2-S*M,y:b/2-v*M,zoom:M},{duration:y?.duration,ease:y?.ease,interpolate:y?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{u({connection:{...Da}})},updateConnection:S=>{u({connection:S})},reset:()=>u({...Ko()})}},Object.is);function Iu({initialNodes:e,initialEdges:n,defaultNodes:s,defaultEdges:r,initialWidth:i,initialHeight:o,initialMinZoom:a,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m,children:u}){const[x]=g.useState(()=>Mu({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:d,minZoom:a,maxZoom:l,fitViewOptions:c,nodeOrigin:h,nodeExtent:f,zIndexMode:m}));return t.jsx(Gc,{value:x,children:t.jsx(pd,{children:u})})}function Tu({children:e,nodes:n,edges:s,defaultNodes:r,defaultEdges:i,width:o,height:a,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u}){return g.useContext(Hr)?t.jsx(t.Fragment,{children:e}):t.jsx(Iu,{initialNodes:n,initialEdges:s,defaultNodes:r,defaultEdges:i,initialWidth:o,initialHeight:a,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u,children:e})}const Ru={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function _u({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,className:i,nodeTypes:o,edgeTypes:a,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:h,onMoveStart:f,onMoveEnd:m,onConnect:u,onConnectStart:x,onConnectEnd:E,onClickConnectStart:S,onClickConnectEnd:v,onNodeMouseEnter:y,onNodeMouseMove:p,onNodeMouseLeave:b,onNodeContextMenu:N,onNodeDoubleClick:w,onNodeDragStart:M,onNodeDrag:D,onNodeDragStop:P,onNodesDelete:_,onEdgesDelete:C,onDelete:$,onSelectionChange:z,onSelectionDragStart:j,onSelectionDrag:B,onSelectionDragStop:R,onSelectionContextMenu:T,onSelectionStart:A,onSelectionEnd:L,onBeforeDelete:q,connectionMode:F,connectionLineType:Y=Kt.Bezier,connectionLineStyle:Q,connectionLineComponent:O,connectionLineContainerStyle:I,deleteKeyCode:H="Backspace",selectionKeyCode:V="Shift",selectionOnDrag:W=!1,selectionMode:X=Qn.Full,panActivationKeyCode:ee="Space",multiSelectionKeyCode:se=er()?"Meta":"Control",zoomActivationKeyCode:J=er()?"Meta":"Control",snapToGrid:U,snapGrid:oe,onlyRenderVisibleElements:le=!1,selectNodesOnDrag:ie,nodesDraggable:he,autoPanOnNodeFocus:de,nodesConnectable:Z,nodesFocusable:ae,nodeOrigin:me=fi,edgesFocusable:ve,edgesReconnectable:ce,elementsSelectable:te=!0,defaultViewport:pe=ad,minZoom:Te=.5,maxZoom:be=2,translateExtent:Ie=Kn,preventScrolling:mt=!0,nodeExtent:nt,defaultMarkerColor:yt="#b1b1b7",zoomOnScroll:ot=!0,zoomOnPinch:gt=!0,panOnScroll:Et=!1,panOnScrollSpeed:Ve=.5,panOnScrollMode:ze=un.Free,zoomOnDoubleClick:Pe=!0,panOnDrag:We=!0,onPaneClick:we,onPaneMouseEnter:Xe,onPaneMouseMove:_e,onPaneMouseLeave:Re,onPaneScroll:Le,onPaneContextMenu:lt,paneClickDistance:Pt=1,nodeClickDistance:Ee=0,children:Fe,onReconnect:rt,onReconnectStart:ct,onReconnectEnd:Mt,onEdgeContextMenu:mn,onEdgeDoubleClick:en,onEdgeMouseEnter:gn,onEdgeMouseMove:$t,onEdgeMouseLeave:tn,reconnectRadius:Yt=10,onNodesChange:nn,onEdgesChange:Ue,noDragClassName:Bt="nodrag",noWheelClassName:It="nowheel",noPanClassName:Tt="nopan",fitView:vt,fitViewOptions:pt,connectOnClick:Rt,attributionPosition:_t,proOptions:Ot,defaultEdgeOptions:Ke,elevateNodesOnSelect:dt=!0,elevateEdgesOnSelect:ut=!1,disableKeyboardA11y:at=!1,autoPanOnConnect:G,autoPanOnNodeDrag:ge,autoPanSpeed:Se,connectionRadius:je,isValidConnection:Ne,onError:Qe,style:ft,id:rn,nodeDragThreshold:pn,connectionDragThreshold:lr,viewport:At,onViewportChange:Bn,width:cr,height:dr,colorMode:Gt="light",debug:st,onScroll:tt,ariaLabelConfig:Fr,zIndexMode:zt="basic",...On},xn){const xt=rn||"1",Je=dd(Gt),sn=g.useCallback(zn=>{zn.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),tt?.(zn)},[tt]);return t.jsx("div",{"data-testid":"rf__wrapper",...On,onScroll:sn,style:{...ft,...Ru},ref:xn,className:Ze(["react-flow",i,Je]),id:rn,role:"application",children:t.jsxs(Tu,{nodes:e,edges:n,width:cr,height:dr,fitView:vt,fitViewOptions:pt,minZoom:Te,maxZoom:be,nodeOrigin:me,nodeExtent:nt,zIndexMode:zt,children:[t.jsx(Eu,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:p,onNodeMouseLeave:b,onNodeContextMenu:N,onNodeDoubleClick:w,nodeTypes:o,edgeTypes:a,connectionLineType:Y,connectionLineStyle:Q,connectionLineComponent:O,connectionLineContainerStyle:I,selectionKeyCode:V,selectionOnDrag:W,selectionMode:X,deleteKeyCode:H,multiSelectionKeyCode:se,panActivationKeyCode:ee,zoomActivationKeyCode:J,onlyRenderVisibleElements:le,defaultViewport:pe,translateExtent:Ie,minZoom:Te,maxZoom:be,preventScrolling:mt,zoomOnScroll:ot,zoomOnPinch:gt,zoomOnDoubleClick:Pe,panOnScroll:Et,panOnScrollSpeed:Ve,panOnScrollMode:ze,panOnDrag:We,onPaneClick:we,onPaneMouseEnter:Xe,onPaneMouseMove:_e,onPaneMouseLeave:Re,onPaneScroll:Le,onPaneContextMenu:lt,paneClickDistance:Pt,nodeClickDistance:Ee,onSelectionContextMenu:T,onSelectionStart:A,onSelectionEnd:L,onReconnect:rt,onReconnectStart:ct,onReconnectEnd:Mt,onEdgeContextMenu:mn,onEdgeDoubleClick:en,onEdgeMouseEnter:gn,onEdgeMouseMove:$t,onEdgeMouseLeave:tn,reconnectRadius:Yt,defaultMarkerColor:yt,noDragClassName:Bt,noWheelClassName:It,noPanClassName:Tt,rfId:xt,disableKeyboardA11y:at,nodeExtent:nt,viewport:At,onViewportChange:Bn}),t.jsx(cd,{nodes:e,edges:n,defaultNodes:s,defaultEdges:r,onConnect:u,onConnectStart:x,onConnectEnd:E,onClickConnectStart:S,onClickConnectEnd:v,nodesDraggable:he,autoPanOnNodeFocus:de,nodesConnectable:Z,nodesFocusable:ae,edgesFocusable:ve,edgesReconnectable:ce,elementsSelectable:te,elevateNodesOnSelect:dt,elevateEdgesOnSelect:ut,minZoom:Te,maxZoom:be,nodeExtent:nt,onNodesChange:nn,onEdgesChange:Ue,snapToGrid:U,snapGrid:oe,connectionMode:F,translateExtent:Ie,connectOnClick:Rt,defaultEdgeOptions:Ke,fitView:vt,fitViewOptions:pt,onNodesDelete:_,onEdgesDelete:C,onDelete:$,onNodeDragStart:M,onNodeDrag:D,onNodeDragStop:P,onSelectionDrag:B,onSelectionDragStart:j,onSelectionDragStop:R,onMove:h,onMoveStart:f,onMoveEnd:m,noPanClassName:Tt,nodeOrigin:me,rfId:xt,autoPanOnConnect:G,autoPanOnNodeDrag:ge,autoPanSpeed:Se,onError:Qe,connectionRadius:je,isValidConnection:Ne,selectNodesOnDrag:ie,nodeDragThreshold:pn,connectionDragThreshold:lr,onBeforeDelete:q,debug:st,ariaLabelConfig:Fr,zIndexMode:zt}),t.jsx(od,{onSelectionChange:z}),Fe,t.jsx(ed,{proOptions:Ot,position:_t}),t.jsx(Jc,{rfId:xt,disableKeyboardA11y:at})]})})}var Au=pi(_u);function Lu(){const e=Be();return g.useCallback(n=>{const{domNode:s,updateNodeInternals:r}=e.getState(),i=Array.isArray(n)?n:[n],o=new Map;i.forEach(a=>{const l=s?.querySelector(`.react-flow__node[data-id="${a}"]`);l&&o.set(a,{id:a,nodeElement:l,force:!0})}),requestAnimationFrame(()=>r(o,{triggerFitView:!1}))},[])}function Du(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>mi(i,o)),[]);return[n,s,r]}function Pu(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>gi(i,o)),[]);return[n,s,r]}function $u({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:Ze(["react-flow__background-pattern",s,r])})}function Bu({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Ze(["react-flow__background-pattern","dots",n])})}var Qt;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Qt||(Qt={}));const Ou={[Qt.Dots]:1,[Qt.Lines]:1,[Qt.Cross]:6},zu=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function zi({id:e,variant:n=Qt.Dots,gap:s=20,size:r,lineWidth:i=1,offset:o=0,color:a,bgColor:l,style:c,className:d,patternClassName:h}){const f=g.useRef(null),{transform:m,patternId:u}=Me(zu,Oe),x=r||Ou[n],E=n===Qt.Dots,S=n===Qt.Cross,v=Array.isArray(s)?s:[s,s],y=[v[0]*m[2]||1,v[1]*m[2]||1],p=x*m[2],b=Array.isArray(o)?o:[o,o],N=S?[p,p]:y,w=[b[0]*m[2]||1+N[0]/2,b[1]*m[2]||1+N[1]/2],M=`${u}${e||""}`;return t.jsxs("svg",{className:Ze(["react-flow__background",d]),style:{...c,...Vr,"--xy-background-color-props":l,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[t.jsx("pattern",{id:M,x:m[0]%y[0],y:m[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${w[0]},-${w[1]})`,children:E?t.jsx(Bu,{radius:p/2,className:h}):t.jsx($u,{dimensions:N,lineWidth:i,variant:n,className:h})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}zi.displayName="Background";const Hu=g.memo(zi);function qu(){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 Vu(){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 Wu(){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 Fu(){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 Yu(){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 Sr({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:Ze(["react-flow__controls-button",n]),...s,children:e})}const Gu=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Hi({style:e,showZoom:n=!0,showFitView:s=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:o,onZoomOut:a,onFitView:l,onInteractiveChange:c,className:d,children:h,position:f="bottom-left",orientation:m="vertical","aria-label":u}){const x=Be(),{isInteractive:E,minZoomReached:S,maxZoomReached:v,ariaLabelConfig:y}=Me(Gu,Oe),{zoomIn:p,zoomOut:b,fitView:N}=_s(),w=()=>{p(),o?.()},M=()=>{b(),a?.()},D=()=>{N(i),l?.()},P=()=>{x.setState({nodesDraggable:!E,nodesConnectable:!E,elementsSelectable:!E}),c?.(!E)},_=m==="horizontal"?"horizontal":"vertical";return t.jsxs(qr,{className:Ze(["react-flow__controls",_,d]),position:f,style:e,"data-testid":"rf__controls","aria-label":u??y["controls.ariaLabel"],children:[n&&t.jsxs(t.Fragment,{children:[t.jsx(Sr,{onClick:w,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:v,children:t.jsx(qu,{})}),t.jsx(Sr,{onClick:M,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:S,children:t.jsx(Vu,{})})]}),s&&t.jsx(Sr,{className:"react-flow__controls-fitview",onClick:D,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:t.jsx(Wu,{})}),r&&t.jsx(Sr,{className:"react-flow__controls-interactive",onClick:P,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:E?t.jsx(Yu,{}):t.jsx(Fu,{})}),h]})}Hi.displayName="Controls";const Zu=g.memo(Hi);function Xu({id:e,x:n,y:s,width:r,height:i,style:o,color:a,strokeColor:l,strokeWidth:c,className:d,borderRadius:h,shapeRendering:f,selected:m,onClick:u}){const{background:x,backgroundColor:E}=o||{},S=a||x||E;return t.jsx("rect",{className:Ze(["react-flow__minimap-node",{selected:m},d]),x:n,y:s,rx:h,ry:h,width:r,height:i,style:{fill:S,stroke:l,strokeWidth:c},shapeRendering:f,onClick:u?v=>u(v,e):void 0})}const Uu=g.memo(Xu),Ku=e=>e.nodes.map(n=>n.id),ls=e=>e instanceof Function?e:()=>e;function Qu({nodeStrokeColor:e,nodeColor:n,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:o=Uu,onClick:a}){const l=Me(Ku,Oe),c=ls(n),d=ls(e),h=ls(s),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:l.map(m=>t.jsx(ef,{id:m,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:o,onClick:a,shapeRendering:f},m))})}function Ju({id:e,nodeColorFunc:n,nodeStrokeColorFunc:s,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:o,shapeRendering:a,NodeComponent:l,onClick:c}){const{node:d,x:h,y:f,width:m,height:u}=Me(x=>{const E=x.nodeLookup.get(e);if(!E)return{node:void 0,x:0,y:0,width:0,height:0};const S=E.internals.userNode,{x:v,y}=E.internals.positionAbsolute,{width:p,height:b}=Ft(S);return{node:S,x:v,y,width:p,height:b}},Oe);return!d||d.hidden||!qa(d)?null:t.jsx(l,{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:c,id:d.id})}const ef=g.memo(Ju);var tf=g.memo(Qu);const nf=200,rf=150,sf=e=>!e.hidden,of=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?Ha(or(e.nodeLookup,{filter:sf}),n):n,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},af="react-flow__minimap-desc";function qi({style:e,className:n,nodeStrokeColor:s,nodeColor:r,nodeClassName:i="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:h,maskStrokeWidth:f,position:m="bottom-right",onClick:u,onNodeClick:x,pannable:E=!1,zoomable:S=!1,ariaLabel:v,inversePan:y,zoomStep:p=1,offsetScale:b=5}){const N=Be(),w=g.useRef(null),{boundingRect:M,viewBB:D,rfId:P,panZoom:_,translateExtent:C,flowWidth:$,flowHeight:z,ariaLabelConfig:j}=Me(of,Oe),B=e?.width??nf,R=e?.height??rf,T=M.width/B,A=M.height/R,L=Math.max(T,A),q=L*B,F=L*R,Y=b*L,Q=M.x-(q-M.width)/2-Y,O=M.y-(F-M.height)/2-Y,I=q+Y*2,H=F+Y*2,V=`${af}-${P}`,W=g.useRef(0),X=g.useRef();W.current=L,g.useEffect(()=>{if(w.current&&_)return X.current=kc({domNode:w.current,panZoom:_,getTransform:()=>N.getState().transform,getViewScale:()=>W.current}),()=>{X.current?.destroy()}},[_]),g.useEffect(()=>{X.current?.update({translateExtent:C,width:$,height:z,inversePan:y,pannable:E,zoomStep:p,zoomable:S})},[E,S,y,p,C,$,z]);const ee=u?U=>{const[oe,le]=X.current?.pointer(U)||[0,0];u(U,{x:oe,y:le})}:void 0,se=x?g.useCallback((U,oe)=>{const le=N.getState().nodeLookup.get(oe).internals.userNode;x(U,le)},[]):void 0,J=v??j["minimap.ariaLabel"];return t.jsx(qr,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*L: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:Ze(["react-flow__minimap",n]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:B,height:R,viewBox:`${Q} ${O} ${I} ${H}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":V,ref:w,onClick:ee,children:[J&&t.jsx("title",{id:V,children:J}),t.jsx(tf,{onClick:se,nodeColor:r,nodeStrokeColor:s,nodeBorderRadius:o,nodeClassName:i,nodeStrokeWidth:a,nodeComponent:l}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${Q-Y},${O-Y}h${I+Y*2}v${H+Y*2}h${-I-Y*2}z
7
+ M${D.x},${D.y}h${D.width}v${D.height}h${-D.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}qi.displayName="MiniMap";const lf=g.memo(qi),cf=e=>n=>e?`${Math.max(1/n.transform[2],1)}`:void 0,df={[Pn.Line]:"right",[Pn.Handle]:"bottom-right"};function uf({nodeId:e,position:n,variant:s=Pn.Handle,className:r,style:i=void 0,children:o,color:a,minWidth:l=10,minHeight:c=10,maxWidth:d=Number.MAX_VALUE,maxHeight:h=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:m,autoScale:u=!0,shouldResize:x,onResizeStart:E,onResize:S,onResizeEnd:v}){const y=vi(),p=typeof e=="string"?e:y,b=Be(),N=g.useRef(null),w=s===Pn.Handle,M=Me(g.useCallback(cf(w&&u),[w,u]),Oe),D=g.useRef(null),P=n??df[s];g.useEffect(()=>{if(!(!N.current||!p))return D.current||(D.current=Pc({domNode:N.current,nodeId:p,getStoreItems:()=>{const{nodeLookup:C,transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:B,domNode:R}=b.getState();return{nodeLookup:C,transform:$,snapGrid:z,snapToGrid:j,nodeOrigin:B,paneDomNode:R}},onChange:(C,$)=>{const{triggerNodeChanges:z,nodeLookup:j,parentLookup:B,nodeOrigin:R}=b.getState(),T=[],A={x:C.x,y:C.y},L=j.get(p);if(L&&L.expandParent&&L.parentId){const q=L.origin??R,F=C.width??L.measured.width??0,Y=C.height??L.measured.height??0,Q={id:L.id,parentId:L.parentId,rect:{width:F,height:Y,...Va({x:C.x??L.position.x,y:C.y??L.position.y},{width:F,height:Y},L.parentId,j,q)}},O=Rs([Q],j,B,R);T.push(...O),A.x=C.x?Math.max(q[0]*F,C.x):void 0,A.y=C.y?Math.max(q[1]*Y,C.y):void 0}if(A.x!==void 0&&A.y!==void 0){const q={id:p,type:"position",position:{...A}};T.push(q)}if(C.width!==void 0&&C.height!==void 0){const F={id:p,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:C.width,height:C.height}};T.push(F)}for(const q of $){const F={...q,type:"position"};T.push(F)}z(T)},onEnd:({width:C,height:$})=>{const z={id:p,type:"dimensions",resizing:!1,dimensions:{width:C,height:$}};b.getState().triggerNodeChanges([z])}})),D.current.update({controlPosition:P,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:h},keepAspectRatio:f,resizeDirection:m,onResizeStart:E,onResize:S,onResizeEnd:v,shouldResize:x}),()=>{D.current?.destroy()}},[P,l,c,d,h,f,E,S,v,x]);const _=P.split("-");return t.jsx("div",{className:Ze(["react-flow__resize-control","nodrag",..._,s,r]),ref:N,style:{...i,scale:M,...a&&{[w?"backgroundColor":"borderColor"]:a}},children:o})}g.memo(uf);var Ae=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),St=Ae((e,n)=>{var s=Object.defineProperty,r=(z,j,B)=>j in z?s(z,j,{enumerable:!0,configurable:!0,writable:!0,value:B}):z[j]=B,i=(z,j)=>()=>(j||z((j={exports:{}}).exports,j),j.exports),o=(z,j,B)=>r(z,typeof j!="symbol"?j+"":j,B),a=i((z,j)=>{var B="\0",R="\0",T="",A=class{constructor(O){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"),O&&(this._isDirected=Object.hasOwn(O,"directed")?O.directed:!0,this._isMultigraph=Object.hasOwn(O,"multigraph")?O.multigraph:!1,this._isCompound=Object.hasOwn(O,"compound")?O.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[R]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(O){return this._label=O,this}graph(){return this._label}setDefaultNodeLabel(O){return this._defaultNodeLabelFn=O,typeof O!="function"&&(this._defaultNodeLabelFn=()=>O),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var O=this;return this.nodes().filter(I=>Object.keys(O._in[I]).length===0)}sinks(){var O=this;return this.nodes().filter(I=>Object.keys(O._out[I]).length===0)}setNodes(O,I){var H=arguments,V=this;return O.forEach(function(W){H.length>1?V.setNode(W,I):V.setNode(W)}),this}setNode(O,I){return Object.hasOwn(this._nodes,O)?(arguments.length>1&&(this._nodes[O]=I),this):(this._nodes[O]=arguments.length>1?I:this._defaultNodeLabelFn(O),this._isCompound&&(this._parent[O]=R,this._children[O]={},this._children[R][O]=!0),this._in[O]={},this._preds[O]={},this._out[O]={},this._sucs[O]={},++this._nodeCount,this)}node(O){return this._nodes[O]}hasNode(O){return Object.hasOwn(this._nodes,O)}removeNode(O){var I=this;if(Object.hasOwn(this._nodes,O)){var H=V=>I.removeEdge(I._edgeObjs[V]);delete this._nodes[O],this._isCompound&&(this._removeFromParentsChildList(O),delete this._parent[O],this.children(O).forEach(function(V){I.setParent(V)}),delete this._children[O]),Object.keys(this._in[O]).forEach(H),delete this._in[O],delete this._preds[O],Object.keys(this._out[O]).forEach(H),delete this._out[O],delete this._sucs[O],--this._nodeCount}return this}setParent(O,I){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(I===void 0)I=R;else{I+="";for(var H=I;H!==void 0;H=this.parent(H))if(H===O)throw new Error("Setting "+I+" as parent of "+O+" would create a cycle");this.setNode(I)}return this.setNode(O),this._removeFromParentsChildList(O),this._parent[O]=I,this._children[I][O]=!0,this}_removeFromParentsChildList(O){delete this._children[this._parent[O]][O]}parent(O){if(this._isCompound){var I=this._parent[O];if(I!==R)return I}}children(O=R){if(this._isCompound){var I=this._children[O];if(I)return Object.keys(I)}else{if(O===R)return this.nodes();if(this.hasNode(O))return[]}}predecessors(O){var I=this._preds[O];if(I)return Object.keys(I)}successors(O){var I=this._sucs[O];if(I)return Object.keys(I)}neighbors(O){var I=this.predecessors(O);if(I){let V=new Set(I);for(var H of this.successors(O))V.add(H);return Array.from(V.values())}}isLeaf(O){var I;return this.isDirected()?I=this.successors(O):I=this.neighbors(O),I.length===0}filterNodes(O){var I=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});I.setGraph(this.graph());var H=this;Object.entries(this._nodes).forEach(function([X,ee]){O(X)&&I.setNode(X,ee)}),Object.values(this._edgeObjs).forEach(function(X){I.hasNode(X.v)&&I.hasNode(X.w)&&I.setEdge(X,H.edge(X))});var V={};function W(X){var ee=H.parent(X);return ee===void 0||I.hasNode(ee)?(V[X]=ee,ee):ee in V?V[ee]:W(ee)}return this._isCompound&&I.nodes().forEach(X=>I.setParent(X,W(X))),I}setDefaultEdgeLabel(O){return this._defaultEdgeLabelFn=O,typeof O!="function"&&(this._defaultEdgeLabelFn=()=>O),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(O,I){var H=this,V=arguments;return O.reduce(function(W,X){return V.length>1?H.setEdge(W,X,I):H.setEdge(W,X),X}),this}setEdge(){var O,I,H,V,W=!1,X=arguments[0];typeof X=="object"&&X!==null&&"v"in X?(O=X.v,I=X.w,H=X.name,arguments.length===2&&(V=arguments[1],W=!0)):(O=X,I=arguments[1],H=arguments[3],arguments.length>2&&(V=arguments[2],W=!0)),O=""+O,I=""+I,H!==void 0&&(H=""+H);var ee=F(this._isDirected,O,I,H);if(Object.hasOwn(this._edgeLabels,ee))return W&&(this._edgeLabels[ee]=V),this;if(H!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(O),this.setNode(I),this._edgeLabels[ee]=W?V:this._defaultEdgeLabelFn(O,I,H);var se=Y(this._isDirected,O,I,H);return O=se.v,I=se.w,Object.freeze(se),this._edgeObjs[ee]=se,L(this._preds[I],O),L(this._sucs[O],I),this._in[I][ee]=se,this._out[O][ee]=se,this._edgeCount++,this}edge(O,I,H){var V=arguments.length===1?Q(this._isDirected,arguments[0]):F(this._isDirected,O,I,H);return this._edgeLabels[V]}edgeAsObj(){let O=this.edge(...arguments);return typeof O!="object"?{label:O}:O}hasEdge(O,I,H){var V=arguments.length===1?Q(this._isDirected,arguments[0]):F(this._isDirected,O,I,H);return Object.hasOwn(this._edgeLabels,V)}removeEdge(O,I,H){var V=arguments.length===1?Q(this._isDirected,arguments[0]):F(this._isDirected,O,I,H),W=this._edgeObjs[V];return W&&(O=W.v,I=W.w,delete this._edgeLabels[V],delete this._edgeObjs[V],q(this._preds[I],O),q(this._sucs[O],I),delete this._in[I][V],delete this._out[O][V],this._edgeCount--),this}inEdges(O,I){return this.isDirected()?this.filterEdges(this._in[O],O,I):this.nodeEdges(O,I)}outEdges(O,I){return this.isDirected()?this.filterEdges(this._out[O],O,I):this.nodeEdges(O,I)}nodeEdges(O,I){if(O in this._nodes)return this.filterEdges({...this._in[O],...this._out[O]},O,I)}filterEdges(O,I,H){if(O){var V=Object.values(O);return H?V.filter(function(W){return W.v===I&&W.w===H||W.v===H&&W.w===I}):V}}};function L(O,I){O[I]?O[I]++:O[I]=1}function q(O,I){--O[I]||delete O[I]}function F(O,I,H,V){var W=""+I,X=""+H;if(!O&&W>X){var ee=W;W=X,X=ee}return W+T+X+T+(V===void 0?B:V)}function Y(O,I,H,V){var W=""+I,X=""+H;if(!O&&W>X){var ee=W;W=X,X=ee}var se={v:W,w:X};return V&&(se.name=V),se}function Q(O,I){return F(O,I.v,I.w,I.name)}j.exports=A}),l=i((z,j)=>{j.exports="3.0.2"}),c=i((z,j)=>{j.exports={Graph:a(),version:l()}}),d=i((z,j)=>{var B=a();j.exports={write:R,read:L};function R(q){var F={options:{directed:q.isDirected(),multigraph:q.isMultigraph(),compound:q.isCompound()},nodes:T(q),edges:A(q)};return q.graph()!==void 0&&(F.value=structuredClone(q.graph())),F}function T(q){return q.nodes().map(function(F){var Y=q.node(F),Q=q.parent(F),O={v:F};return Y!==void 0&&(O.value=Y),Q!==void 0&&(O.parent=Q),O})}function A(q){return q.edges().map(function(F){var Y=q.edge(F),Q={v:F.v,w:F.w};return F.name!==void 0&&(Q.name=F.name),Y!==void 0&&(Q.value=Y),Q})}function L(q){var F=new B(q.options).setGraph(q.value);return q.nodes.forEach(function(Y){F.setNode(Y.v,Y.value),Y.parent&&F.setParent(Y.v,Y.parent)}),q.edges.forEach(function(Y){F.setEdge({v:Y.v,w:Y.w,name:Y.name},Y.value)}),F}}),h=i((z,j)=>{j.exports=R;var B=()=>1;function R(A,L,q,F){return T(A,String(L),q||B,F||function(Y){return A.outEdges(Y)})}function T(A,L,q,F){var Y={},Q=!0,O=0,I=A.nodes(),H=function(ee){var se=q(ee);Y[ee.v].distance+se<Y[ee.w].distance&&(Y[ee.w]={distance:Y[ee.v].distance+se,predecessor:ee.v},Q=!0)},V=function(){I.forEach(function(ee){F(ee).forEach(function(se){var J=se.v===ee?se.v:se.w,U=J===se.v?se.w:se.v;H({v:J,w:U})})})};I.forEach(function(ee){var se=ee===L?0:Number.POSITIVE_INFINITY;Y[ee]={distance:se}});for(var W=I.length,X=1;X<W&&(Q=!1,O++,V(),!!Q);X++);if(O===W-1&&(Q=!1,V(),Q))throw new Error("The graph contains a negative weight cycle");return Y}}),f=i((z,j)=>{j.exports=B;function B(R){var T={},A=[],L;function q(F){Object.hasOwn(T,F)||(T[F]=!0,L.push(F),R.successors(F).forEach(q),R.predecessors(F).forEach(q))}return R.nodes().forEach(function(F){L=[],q(F),L.length&&A.push(L)}),A}}),m=i((z,j)=>{var B=class{constructor(){o(this,"_arr",[]),o(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(R){return R.key})}has(R){return Object.hasOwn(this._keyIndices,R)}priority(R){var T=this._keyIndices[R];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(R,T){var A=this._keyIndices;if(R=String(R),!Object.hasOwn(A,R)){var L=this._arr,q=L.length;return A[R]=q,L.push({key:R,priority:T}),this._decrease(q),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var R=this._arr.pop();return delete this._keyIndices[R.key],this._heapify(0),R.key}decrease(R,T){var A=this._keyIndices[R];if(T>this._arr[A].priority)throw new Error("New priority is greater than current priority. Key: "+R+" Old: "+this._arr[A].priority+" New: "+T);this._arr[A].priority=T,this._decrease(A)}_heapify(R){var T=this._arr,A=2*R,L=A+1,q=R;A<T.length&&(q=T[A].priority<T[q].priority?A:q,L<T.length&&(q=T[L].priority<T[q].priority?L:q),q!==R&&(this._swap(R,q),this._heapify(q)))}_decrease(R){for(var T=this._arr,A=T[R].priority,L;R!==0&&(L=R>>1,!(T[L].priority<A));)this._swap(R,L),R=L}_swap(R,T){var A=this._arr,L=this._keyIndices,q=A[R],F=A[T];A[R]=F,A[T]=q,L[F.key]=R,L[q.key]=T}};j.exports=B}),u=i((z,j)=>{var B=m();j.exports=T;var R=()=>1;function T(L,q,F,Y){var Q=function(O){return L.outEdges(O)};return A(L,String(q),F||R,Y||Q)}function A(L,q,F,Y){var Q={},O=new B,I,H,V=function(W){var X=W.v!==I?W.v:W.w,ee=Q[X],se=F(W),J=H.distance+se;if(se<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+W+" Weight: "+se);J<ee.distance&&(ee.distance=J,ee.predecessor=I,O.decrease(X,J))};for(L.nodes().forEach(function(W){var X=W===q?0:Number.POSITIVE_INFINITY;Q[W]={distance:X},O.add(W,X)});O.size()>0&&(I=O.removeMin(),H=Q[I],H.distance!==Number.POSITIVE_INFINITY);)Y(I).forEach(V);return Q}}),x=i((z,j)=>{var B=u();j.exports=R;function R(T,A,L){return T.nodes().reduce(function(q,F){return q[F]=B(T,F,A,L),q},{})}}),E=i((z,j)=>{j.exports=B;function B(T,A,L){if(T[A].predecessor!==void 0)throw new Error("Invalid source vertex");if(T[L].predecessor===void 0&&L!==A)throw new Error("Invalid destination vertex");return{weight:T[L].distance,path:R(T,A,L)}}function R(T,A,L){for(var q=[],F=L;F!==A;)q.push(F),F=T[F].predecessor;return q.push(A),q.reverse()}}),S=i((z,j)=>{j.exports=B;function B(R){var T=0,A=[],L={},q=[];function F(Y){var Q=L[Y]={onStack:!0,lowlink:T,index:T++};if(A.push(Y),R.successors(Y).forEach(function(H){Object.hasOwn(L,H)?L[H].onStack&&(Q.lowlink=Math.min(Q.lowlink,L[H].index)):(F(H),Q.lowlink=Math.min(Q.lowlink,L[H].lowlink))}),Q.lowlink===Q.index){var O=[],I;do I=A.pop(),L[I].onStack=!1,O.push(I);while(Y!==I);q.push(O)}}return R.nodes().forEach(function(Y){Object.hasOwn(L,Y)||F(Y)}),q}}),v=i((z,j)=>{var B=S();j.exports=R;function R(T){return B(T).filter(function(A){return A.length>1||A.length===1&&T.hasEdge(A[0],A[0])})}}),y=i((z,j)=>{j.exports=R;var B=()=>1;function R(A,L,q){return T(A,L||B,q||function(F){return A.outEdges(F)})}function T(A,L,q){var F={},Y=A.nodes();return Y.forEach(function(Q){F[Q]={},F[Q][Q]={distance:0},Y.forEach(function(O){Q!==O&&(F[Q][O]={distance:Number.POSITIVE_INFINITY})}),q(Q).forEach(function(O){var I=O.v===Q?O.w:O.v,H=L(O);F[Q][I]={distance:H,predecessor:Q}})}),Y.forEach(function(Q){var O=F[Q];Y.forEach(function(I){var H=F[I];Y.forEach(function(V){var W=H[Q],X=O[V],ee=H[V],se=W.distance+X.distance;se<ee.distance&&(ee.distance=se,ee.predecessor=X.predecessor)})})}),F}}),p=i((z,j)=>{function B(T){var A={},L={},q=[];function F(Y){if(Object.hasOwn(L,Y))throw new R;Object.hasOwn(A,Y)||(L[Y]=!0,A[Y]=!0,T.predecessors(Y).forEach(F),delete L[Y],q.push(Y))}if(T.sinks().forEach(F),Object.keys(A).length!==T.nodeCount())throw new R;return q}var R=class extends Error{constructor(){super(...arguments)}};j.exports=B,B.CycleException=R}),b=i((z,j)=>{var B=p();j.exports=R;function R(T){try{B(T)}catch(A){if(A instanceof B.CycleException)return!1;throw A}return!0}}),N=i((z,j)=>{j.exports=B;function B(T,A,L,q,F){Array.isArray(A)||(A=[A]);var Y=(T.isDirected()?T.successors:T.neighbors).bind(T),Q={};return A.forEach(function(O){if(!T.hasNode(O))throw new Error("Graph does not have node: "+O);F=R(T,O,L==="post",Q,Y,q,F)}),F}function R(T,A,L,q,F,Y,Q){return Object.hasOwn(q,A)||(q[A]=!0,L||(Q=Y(Q,A)),F(A).forEach(function(O){Q=R(T,O,L,q,F,Y,Q)}),L&&(Q=Y(Q,A))),Q}}),w=i((z,j)=>{var B=N();j.exports=R;function R(T,A,L){return B(T,A,L,function(q,F){return q.push(F),q},[])}}),M=i((z,j)=>{var B=w();j.exports=R;function R(T,A){return B(T,A,"post")}}),D=i((z,j)=>{var B=w();j.exports=R;function R(T,A){return B(T,A,"pre")}}),P=i((z,j)=>{var B=a(),R=m();j.exports=T;function T(A,L){var q=new B,F={},Y=new R,Q;function O(H){var V=H.v===Q?H.w:H.v,W=Y.priority(V);if(W!==void 0){var X=L(H);X<W&&(F[V]=Q,Y.decrease(V,X))}}if(A.nodeCount()===0)return q;A.nodes().forEach(function(H){Y.add(H,Number.POSITIVE_INFINITY),q.setNode(H)}),Y.decrease(A.nodes()[0],0);for(var I=!1;Y.size()>0;){if(Q=Y.removeMin(),Object.hasOwn(F,Q))q.setEdge(Q,F[Q]);else{if(I)throw new Error("Input graph is not connected: "+A);I=!0}A.nodeEdges(Q).forEach(O)}return q}}),_=i((z,j)=>{var B=u(),R=h();j.exports=T;function T(L,q,F,Y){return A(L,q,F,Y||function(Q){return L.outEdges(Q)})}function A(L,q,F,Y){if(F===void 0)return B(L,q,F,Y);for(var Q=!1,O=L.nodes(),I=0;I<O.length;I++){for(var H=Y(O[I]),V=0;V<H.length;V++){var W=H[V],X=W.v===O[I]?W.v:W.w,ee=X===W.v?W.w:W.v;F({v:X,w:ee})<0&&(Q=!0)}if(Q)return R(L,q,F,Y)}return B(L,q,F,Y)}}),C=i((z,j)=>{j.exports={bellmanFord:h(),components:f(),dijkstra:u(),dijkstraAll:x(),extractPath:E(),findCycles:v(),floydWarshall:y(),isAcyclic:b(),postorder:M(),preorder:D(),prim:P(),shortestPaths:_(),reduce:N(),tarjan:S(),topsort:p()}}),$=c();n.exports={Graph:$.Graph,json:d(),alg:C(),version:$.version}}),ff=Ae((e,n)=>{var s=class{constructor(){let o={};o._next=o._prev=o,this._sentinel=o}dequeue(){let o=this._sentinel,a=o._prev;if(a!==o)return r(a),a}enqueue(o){let a=this._sentinel;o._prev&&o._next&&r(o),o._next=a._next,a._next._prev=o,a._next=o,o._prev=a}toString(){let o=[],a=this._sentinel,l=a._prev;for(;l!==a;)o.push(JSON.stringify(l,i)),l=l._prev;return"["+o.join(", ")+"]"}};function r(o){o._prev._next=o._next,o._next._prev=o._prev,delete o._next,delete o._prev}function i(o,a){if(o!=="_next"&&o!=="_prev")return a}n.exports=s}),hf=Ae((e,n)=>{var s=St().Graph,r=ff();n.exports=o;var i=()=>1;function o(f,m){if(f.nodeCount()<=1)return[];let u=c(f,m||i);return a(u.graph,u.buckets,u.zeroIdx).flatMap(x=>f.outEdges(x.v,x.w))}function a(f,m,u){let x=[],E=m[m.length-1],S=m[0],v;for(;f.nodeCount();){for(;v=S.dequeue();)l(f,m,u,v);for(;v=E.dequeue();)l(f,m,u,v);if(f.nodeCount()){for(let y=m.length-2;y>0;--y)if(v=m[y].dequeue(),v){x=x.concat(l(f,m,u,v,!0));break}}}return x}function l(f,m,u,x,E){let S=E?[]:void 0;return f.inEdges(x.v).forEach(v=>{let y=f.edge(v),p=f.node(v.v);E&&S.push({v:v.v,w:v.w}),p.out-=y,d(m,u,p)}),f.outEdges(x.v).forEach(v=>{let y=f.edge(v),p=v.w,b=f.node(p);b.in-=y,d(m,u,b)}),f.removeNode(x.v),S}function c(f,m){let u=new s,x=0,E=0;f.nodes().forEach(y=>{u.setNode(y,{v:y,in:0,out:0})}),f.edges().forEach(y=>{let p=u.edge(y.v,y.w)||0,b=m(y),N=p+b;u.setEdge(y.v,y.w,N),E=Math.max(E,u.node(y.v).out+=b),x=Math.max(x,u.node(y.w).in+=b)});let S=h(E+x+3).map(()=>new r),v=x+1;return u.nodes().forEach(y=>{d(S,v,u.node(y))}),{graph:u,buckets:S,zeroIdx:v}}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=Ae((e,n)=>{var s=St().Graph;n.exports={addBorderNode:m,addDummyNode:r,applyWithChunking:E,asNonCompoundGraph:o,buildLayerMatrix:d,intersectRect:c,mapValues:D,maxRank:S,normalizeRanks:h,notime:p,partition:v,pick:M,predecessorWeights:l,range:w,removeEmptyRanks:f,simplify:i,successorWeights:a,time:y,uniqueId:N,zipObject:P};function r(_,C,$,z){for(var j=z;_.hasNode(j);)j=N(z);return $.dummy=C,_.setNode(j,$),j}function i(_){let C=new s().setGraph(_.graph());return _.nodes().forEach($=>C.setNode($,_.node($))),_.edges().forEach($=>{let z=C.edge($.v,$.w)||{weight:0,minlen:1},j=_.edge($);C.setEdge($.v,$.w,{weight:z.weight+j.weight,minlen:Math.max(z.minlen,j.minlen)})}),C}function o(_){let C=new s({multigraph:_.isMultigraph()}).setGraph(_.graph());return _.nodes().forEach($=>{_.children($).length||C.setNode($,_.node($))}),_.edges().forEach($=>{C.setEdge($,_.edge($))}),C}function a(_){let C=_.nodes().map($=>{let z={};return _.outEdges($).forEach(j=>{z[j.w]=(z[j.w]||0)+_.edge(j).weight}),z});return P(_.nodes(),C)}function l(_){let C=_.nodes().map($=>{let z={};return _.inEdges($).forEach(j=>{z[j.v]=(z[j.v]||0)+_.edge(j).weight}),z});return P(_.nodes(),C)}function c(_,C){let $=_.x,z=_.y,j=C.x-$,B=C.y-z,R=_.width/2,T=_.height/2;if(!j&&!B)throw new Error("Not possible to find intersection inside of the rectangle");let A,L;return Math.abs(B)*R>Math.abs(j)*T?(B<0&&(T=-T),A=T*j/B,L=T):(j<0&&(R=-R),A=R,L=R*B/j),{x:$+A,y:z+L}}function d(_){let C=w(S(_)+1).map(()=>[]);return _.nodes().forEach($=>{let z=_.node($),j=z.rank;j!==void 0&&(C[j][z.order]=$)}),C}function h(_){let C=_.nodes().map(z=>{let j=_.node(z).rank;return j===void 0?Number.MAX_VALUE:j}),$=E(Math.min,C);_.nodes().forEach(z=>{let j=_.node(z);Object.hasOwn(j,"rank")&&(j.rank-=$)})}function f(_){let C=_.nodes().map(R=>_.node(R).rank).filter(R=>R!==void 0),$=E(Math.min,C),z=[];_.nodes().forEach(R=>{let T=_.node(R).rank-$;z[T]||(z[T]=[]),z[T].push(R)});let j=0,B=_.graph().nodeRankFactor;Array.from(z).forEach((R,T)=>{R===void 0&&T%B!==0?--j:R!==void 0&&j&&R.forEach(A=>_.node(A).rank+=j)})}function m(_,C,$,z){let j={width:0,height:0};return arguments.length>=4&&(j.rank=$,j.order=z),r(_,"border",j,C)}function u(_,C=x){let $=[];for(let z=0;z<_.length;z+=C){let j=_.slice(z,z+C);$.push(j)}return $}var x=65535;function E(_,C){if(C.length>x){let $=u(C);return _.apply(null,$.map(z=>_.apply(null,z)))}else return _.apply(null,C)}function S(_){let C=_.nodes().map($=>{let z=_.node($).rank;return z===void 0?Number.MIN_VALUE:z});return E(Math.max,C)}function v(_,C){let $={lhs:[],rhs:[]};return _.forEach(z=>{C(z)?$.lhs.push(z):$.rhs.push(z)}),$}function y(_,C){let $=Date.now();try{return C()}finally{console.log(_+" time: "+(Date.now()-$)+"ms")}}function p(_,C){return C()}var b=0;function N(_){var C=++b;return _+(""+C)}function w(_,C,$=1){C==null&&(C=_,_=0);let z=B=>B<C;$<0&&(z=B=>C<B);let j=[];for(let B=_;z(B);B+=$)j.push(B);return j}function M(_,C){let $={};for(let z of C)_[z]!==void 0&&($[z]=_[z]);return $}function D(_,C){let $=C;return typeof C=="string"&&($=z=>z[C]),Object.entries(_).reduce((z,[j,B])=>(z[j]=$(B,j),z),{})}function P(_,C){return _.reduce(($,z,j)=>($[z]=C[j],$),{})}}),mf=Ae((e,n)=>{var s=hf(),r=Ge().uniqueId;n.exports={run:i,undo:a};function i(l){(l.graph().acyclicer==="greedy"?s(l,c(l)):o(l)).forEach(d=>{let h=l.edge(d);l.removeEdge(d),h.forwardName=d.name,h.reversed=!0,l.setEdge(d.w,d.v,h,r("rev"))});function c(d){return h=>d.edge(h).weight}}function o(l){let c=[],d={},h={};function f(m){Object.hasOwn(h,m)||(h[m]=!0,d[m]=!0,l.outEdges(m).forEach(u=>{Object.hasOwn(d,u.w)?c.push(u):f(u.w)}),delete d[m])}return l.nodes().forEach(f),c}function a(l){l.edges().forEach(c=>{let d=l.edge(c);if(d.reversed){l.removeEdge(c);let h=d.forwardName;delete d.reversed,delete d.forwardName,l.setEdge(c.w,c.v,d,h)}})}}),gf=Ae((e,n)=>{var s=Ge();n.exports={run:r,undo:o};function r(a){a.graph().dummyChains=[],a.edges().forEach(l=>i(a,l))}function i(a,l){let c=l.v,d=a.node(c).rank,h=l.w,f=a.node(h).rank,m=l.name,u=a.edge(l),x=u.labelRank;if(f===d+1)return;a.removeEdge(l);let E,S,v;for(v=0,++d;d<f;++v,++d)u.points=[],S={width:0,height:0,edgeLabel:u,edgeObj:l,rank:d},E=s.addDummyNode(a,"edge",S,"_d"),d===x&&(S.width=u.width,S.height=u.height,S.dummy="edge-label",S.labelpos=u.labelpos),a.setEdge(c,E,{weight:u.weight},m),v===0&&a.graph().dummyChains.push(E),c=E;a.setEdge(c,h,{weight:u.weight},m)}function o(a){a.graph().dummyChains.forEach(l=>{let c=a.node(l),d=c.edgeLabel,h;for(a.setEdge(c.edgeObj,d);c.dummy;)h=a.successors(l)[0],a.removeNode(l),d.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(d.x=c.x,d.y=c.y,d.width=c.width,d.height=c.height),l=h,c=a.node(l)})}}),$r=Ae((e,n)=>{var{applyWithChunking:s}=Ge();n.exports={longestPath:r,slack:i};function r(o){var a={};function l(c){var d=o.node(c);if(Object.hasOwn(a,c))return d.rank;a[c]=!0;let h=o.outEdges(c).map(m=>m==null?Number.POSITIVE_INFINITY:l(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(l)}function i(o,a){return o.node(a.w).rank-o.node(a.v).rank-o.edge(a).minlen}}),Vi=Ae((e,n)=>{var s=St().Graph,r=$r().slack;n.exports=i;function i(c){var d=new s({directed:!1}),h=c.nodes()[0],f=c.nodeCount();d.setNode(h,{});for(var m,u;o(d,c)<f;)m=a(d,c),u=d.hasNode(m.v)?r(c,m):-r(c,m),l(d,c,u);return d}function o(c,d){function h(f){d.nodeEdges(f).forEach(m=>{var u=m.v,x=f===u?m.w:u;!c.hasNode(x)&&!r(d,m)&&(c.setNode(x,{}),c.setEdge(f,x,{}),h(x))})}return c.nodes().forEach(h),c.nodeCount()}function a(c,d){return d.edges().reduce((h,f)=>{let m=Number.POSITIVE_INFINITY;return c.hasNode(f.v)!==c.hasNode(f.w)&&(m=r(d,f)),m<h[0]?[m,f]:h},[Number.POSITIVE_INFINITY,null])[1]}function l(c,d,h){c.nodes().forEach(f=>d.node(f).rank+=h)}}),pf=Ae((e,n)=>{var s=Vi(),r=$r().slack,i=$r().longestPath,o=St().alg.preorder,a=St().alg.postorder,l=Ge().simplify;n.exports=c,c.initLowLimValues=m,c.initCutValues=d,c.calcCutValue=f,c.leaveEdge=x,c.enterEdge=E,c.exchangeEdges=S;function c(b){b=l(b),i(b);var N=s(b);m(N),d(N,b);for(var w,M;w=x(N);)M=E(N,b,w),S(N,b,w,M)}function d(b,N){var w=a(b,b.nodes());w=w.slice(0,w.length-1),w.forEach(M=>h(b,N,M))}function h(b,N,w){var M=b.node(w),D=M.parent;b.edge(w,D).cutvalue=f(b,N,w)}function f(b,N,w){var M=b.node(w),D=M.parent,P=!0,_=N.edge(w,D),C=0;return _||(P=!1,_=N.edge(D,w)),C=_.weight,N.nodeEdges(w).forEach($=>{var z=$.v===w,j=z?$.w:$.v;if(j!==D){var B=z===P,R=N.edge($).weight;if(C+=B?R:-R,y(b,w,j)){var T=b.edge(w,j).cutvalue;C+=B?-T:T}}}),C}function m(b,N){arguments.length<2&&(N=b.nodes()[0]),u(b,{},1,N)}function u(b,N,w,M,D){var P=w,_=b.node(M);return N[M]=!0,b.neighbors(M).forEach(C=>{Object.hasOwn(N,C)||(w=u(b,N,w,C,M))}),_.low=P,_.lim=w++,D?_.parent=D:delete _.parent,w}function x(b){return b.edges().find(N=>b.edge(N).cutvalue<0)}function E(b,N,w){var M=w.v,D=w.w;N.hasEdge(M,D)||(M=w.w,D=w.v);var P=b.node(M),_=b.node(D),C=P,$=!1;P.lim>_.lim&&(C=_,$=!0);var z=N.edges().filter(j=>$===p(b,b.node(j.v),C)&&$!==p(b,b.node(j.w),C));return z.reduce((j,B)=>r(N,B)<r(N,j)?B:j)}function S(b,N,w,M){var D=w.v,P=w.w;b.removeEdge(D,P),b.setEdge(M.v,M.w,{}),m(b),d(b,N),v(b,N)}function v(b,N){var w=b.nodes().find(D=>!N.node(D).parent),M=o(b,w);M=M.slice(1),M.forEach(D=>{var P=b.node(D).parent,_=N.edge(D,P),C=!1;_||(_=N.edge(P,D),C=!0),N.node(D).rank=N.node(P).rank+(C?_.minlen:-_.minlen)})}function y(b,N,w){return b.hasEdge(N,w)}function p(b,N,w){return w.low<=N.lim&&N.lim<=w.lim}}),xf=Ae((e,n)=>{var s=$r(),r=s.longestPath,i=Vi(),o=pf();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":c(h);break;case"longest-path":l(h);break;case"none":break;default:d(h)}}var l=r;function c(h){r(h),i(h)}function d(h){o(h)}}),bf=Ae((e,n)=>{n.exports=s;function s(o){let a=i(o);o.graph().dummyChains.forEach(l=>{let c=o.node(l),d=c.edgeObj,h=r(o,a,d.v,d.w),f=h.path,m=h.lca,u=0,x=f[u],E=!0;for(;l!==d.w;){if(c=o.node(l),E){for(;(x=f[u])!==m&&o.node(x).maxRank<c.rank;)u++;x===m&&(E=!1)}if(!E){for(;u<f.length-1&&o.node(x=f[u+1]).minRank<=c.rank;)u++;x=f[u]}o.setParent(l,x),l=o.successors(l)[0]}})}function r(o,a,l,c){let d=[],h=[],f=Math.min(a[l].low,a[c].low),m=Math.max(a[l].lim,a[c].lim),u,x;u=l;do u=o.parent(u),d.push(u);while(u&&(a[u].low>f||m>a[u].lim));for(x=u,u=c;(u=o.parent(u))!==x;)h.push(u);return{path:d.concat(h.reverse()),lca:x}}function i(o){let a={},l=0;function c(d){let h=l;o.children(d).forEach(c),a[d]={low:h,lim:l++}}return o.children().forEach(c),a}}),yf=Ae((e,n)=>{var s=Ge();n.exports={run:r,cleanup:l};function r(c){let d=s.addDummyNode(c,"root",{},"_root"),h=o(c),f=Object.values(h),m=s.applyWithChunking(Math.max,f)-1,u=2*m+1;c.graph().nestingRoot=d,c.edges().forEach(E=>c.edge(E).minlen*=u);let x=a(c)+1;c.children().forEach(E=>i(c,d,u,x,m,h,E)),c.graph().nodeRankFactor=u}function i(c,d,h,f,m,u,x){let E=c.children(x);if(!E.length){x!==d&&c.setEdge(d,x,{weight:0,minlen:h});return}let S=s.addBorderNode(c,"_bt"),v=s.addBorderNode(c,"_bb"),y=c.node(x);c.setParent(S,x),y.borderTop=S,c.setParent(v,x),y.borderBottom=v,E.forEach(p=>{i(c,d,h,f,m,u,p);let b=c.node(p),N=b.borderTop?b.borderTop:p,w=b.borderBottom?b.borderBottom:p,M=b.borderTop?f:2*f,D=N!==w?1:m-u[x]+1;c.setEdge(S,N,{weight:M,minlen:D,nestingEdge:!0}),c.setEdge(w,v,{weight:M,minlen:D,nestingEdge:!0})}),c.parent(x)||c.setEdge(d,S,{weight:0,minlen:m+u[x]})}function o(c){var d={};function h(f,m){var u=c.children(f);u&&u.length&&u.forEach(x=>h(x,m+1)),d[f]=m}return c.children().forEach(f=>h(f,1)),d}function a(c){return c.edges().reduce((d,h)=>d+c.edge(h).weight,0)}function l(c){var d=c.graph();c.removeNode(d.nestingRoot),delete d.nestingRoot,c.edges().forEach(h=>{var f=c.edge(h);f.nestingEdge&&c.removeEdge(h)})}}),vf=Ae((e,n)=>{var s=Ge();n.exports=r;function r(o){function a(l){let c=o.children(l),d=o.node(l);if(c.length&&c.forEach(a),Object.hasOwn(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(let h=d.minRank,f=d.maxRank+1;h<f;++h)i(o,"borderLeft","_bl",l,d,h),i(o,"borderRight","_br",l,d,h)}}o.children().forEach(a)}function i(o,a,l,c,d,h){let f={width:0,height:0,rank:h,borderType:a},m=d[a][h-1],u=s.addDummyNode(o,"border",f,l);d[a][h]=u,o.setParent(u,c),m&&o.setEdge(m,u,{weight:1})}}),wf=Ae((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")&&(c(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=>l(h.node(f))),h.edges().forEach(f=>{let m=h.edge(f);m.points.forEach(l),Object.hasOwn(m,"y")&&l(m)})}function l(h){h.y=-h.y}function c(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}}),kf=Ae((e,n)=>{var s=Ge();n.exports=r;function r(i){let o={},a=i.nodes().filter(f=>!i.children(f).length),l=a.map(f=>i.node(f).rank),c=s.applyWithChunking(Math.max,l),d=s.range(c+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}}),jf=Ae((e,n)=>{var s=Ge().zipObject;n.exports=r;function r(o,a){let l=0;for(let c=1;c<a.length;++c)l+=i(o,a[c-1],a[c]);return l}function i(o,a,l){let c=s(l,l.map((x,E)=>E)),d=a.flatMap(x=>o.outEdges(x).map(E=>({pos:c[E.w],weight:o.edge(E).weight})).sort((E,S)=>E.pos-S.pos)),h=1;for(;h<l.length;)h<<=1;let f=2*h-1;h-=1;let m=new Array(f).fill(0),u=0;return d.forEach(x=>{let E=x.pos+h;m[E]+=x.weight;let S=0;for(;E>0;)E%2&&(S+=m[E+1]),E=E-1>>1,m[E]+=x.weight;u+=x.weight*S}),u}}),Nf=Ae((e,n)=>{n.exports=s;function s(r,i=[]){return i.map(o=>{let a=r.inEdges(o);if(a.length){let l=a.reduce((c,d)=>{let h=r.edge(d),f=r.node(d.v);return{sum:c.sum+h.weight*f.order,weight:c.weight+h.weight}},{sum:0,weight:0});return{v:o,barycenter:l.sum/l.weight,weight:l.weight}}else return{v:o}})}}),Cf=Ae((e,n)=>{var s=Ge();n.exports=r;function r(a,l){let c={};a.forEach((h,f)=>{let m=c[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:f};h.barycenter!==void 0&&(m.barycenter=h.barycenter,m.weight=h.weight)}),l.edges().forEach(h=>{let f=c[h.v],m=c[h.w];f!==void 0&&m!==void 0&&(m.indegree++,f.out.push(c[h.w]))});let d=Object.values(c).filter(h=>!h.indegree);return i(d)}function i(a){let l=[];function c(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();l.push(h),h.in.reverse().forEach(c(h)),h.out.forEach(d(h))}return l.filter(h=>!h.merged).map(h=>s.pick(h,["vs","i","barycenter","weight"]))}function o(a,l){let c=0,d=0;a.weight&&(c+=a.barycenter*a.weight,d+=a.weight),l.weight&&(c+=l.barycenter*l.weight,d+=l.weight),a.vs=l.vs.concat(a.vs),a.barycenter=c/d,a.weight=d,a.i=Math.min(l.i,a.i),l.merged=!0}}),Sf=Ae((e,n)=>{var s=Ge();n.exports=r;function r(a,l){let c=s.partition(a,S=>Object.hasOwn(S,"barycenter")),d=c.lhs,h=c.rhs.sort((S,v)=>v.i-S.i),f=[],m=0,u=0,x=0;d.sort(o(!!l)),x=i(f,h,x),d.forEach(S=>{x+=S.vs.length,f.push(S.vs),m+=S.barycenter*S.weight,u+=S.weight,x=i(f,h,x)});let E={vs:f.flat(!0)};return u&&(E.barycenter=m/u,E.weight=u),E}function i(a,l,c){let d;for(;l.length&&(d=l[l.length-1]).i<=c;)l.pop(),a.push(d.vs),c++;return c}function o(a){return(l,c)=>l.barycenter<c.barycenter?-1:l.barycenter>c.barycenter?1:a?c.i-l.i:l.i-c.i}}),Ef=Ae((e,n)=>{var s=Nf(),r=Cf(),i=Sf();n.exports=o;function o(c,d,h,f){let m=c.children(d),u=c.node(d),x=u?u.borderLeft:void 0,E=u?u.borderRight:void 0,S={};x&&(m=m.filter(b=>b!==x&&b!==E));let v=s(c,m);v.forEach(b=>{if(c.children(b.v).length){let N=o(c,b.v,h,f);S[b.v]=N,Object.hasOwn(N,"barycenter")&&l(b,N)}});let y=r(v,h);a(y,S);let p=i(y,f);if(x&&(p.vs=[x,p.vs,E].flat(!0),c.predecessors(x).length)){let b=c.node(c.predecessors(x)[0]),N=c.node(c.predecessors(E)[0]);Object.hasOwn(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+b.order+N.order)/(p.weight+2),p.weight+=2}return p}function a(c,d){c.forEach(h=>{h.vs=h.vs.flatMap(f=>d[f]?d[f].vs:f)})}function l(c,d){c.barycenter!==void 0?(c.barycenter=(c.barycenter*c.weight+d.barycenter*d.weight)/(c.weight+d.weight),c.weight+=d.weight):(c.barycenter=d.barycenter,c.weight=d.weight)}}),Mf=Ae((e,n)=>{var s=St().Graph,r=Ge();n.exports=i;function i(a,l,c,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),x=a.parent(m);(u.rank===l||u.minRank<=l&&l<=u.maxRank)&&(f.setNode(m),f.setParent(m,x||h),a[c](m).forEach(E=>{let S=E.v===m?E.w:E.v,v=f.edge(S,m),y=v!==void 0?v.weight:0;f.setEdge(S,m,{weight:a.edge(E).weight+y})}),Object.hasOwn(u,"minRank")&&f.setNode(m,{borderLeft:u.borderLeft[l],borderRight:u.borderRight[l]}))}),f}function o(a){for(var l;a.hasNode(l=r.uniqueId("_root")););return l}}),If=Ae((e,n)=>{n.exports=s;function s(r,i,o){let a={},l;o.forEach(c=>{let d=r.parent(c),h,f;for(;d;){if(h=r.parent(d),h?(f=a[h],a[h]=d):(f=l,l=d),f&&f!==d){i.setEdge(f,d);return}d=h}})}}),Tf=Ae((e,n)=>{var s=kf(),r=jf(),i=Ef(),o=Mf(),a=If(),l=St().Graph,c=Ge();n.exports=d;function d(u,x={}){if(typeof x.customOrder=="function"){x.customOrder(u,d);return}let E=c.maxRank(u),S=h(u,c.range(1,E+1),"inEdges"),v=h(u,c.range(E-1,-1,-1),"outEdges"),y=s(u);if(m(u,y),x.disableOptimalOrderHeuristic)return;let p=Number.POSITIVE_INFINITY,b,N=x.constraints||[];for(let w=0,M=0;M<4;++w,++M){f(w%2?S:v,w%4>=2,N),y=c.buildLayerMatrix(u);let D=r(u,y);D<p?(M=0,b=Object.assign({},y),p=D):D===p&&(b=structuredClone(y))}m(u,b)}function h(u,x,E){let S=new Map,v=(y,p)=>{S.has(y)||S.set(y,[]),S.get(y).push(p)};for(let y of u.nodes()){let p=u.node(y);if(typeof p.rank=="number"&&v(p.rank,y),typeof p.minRank=="number"&&typeof p.maxRank=="number")for(let b=p.minRank;b<=p.maxRank;b++)b!==p.rank&&v(b,y)}return x.map(function(y){return o(u,y,E,S.get(y)||[])})}function f(u,x,E){let S=new l;u.forEach(function(v){E.forEach(b=>S.setEdge(b.left,b.right));let y=v.graph().root,p=i(v,y,S,x);p.vs.forEach((b,N)=>v.node(b).order=N),a(v,S,p.vs)})}function m(u,x){Object.values(x).forEach(E=>E.forEach((S,v)=>u.node(S).order=v))}}),Rf=Ae((e,n)=>{var s=St().Graph,r=Ge();n.exports={positionX:E,findType1Conflicts:i,findType2Conflicts:o,addConflict:l,hasConflict:c,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:u,findSmallestWidthAlignment:m,balance:x};function i(y,p){let b={};function N(w,M){let D=0,P=0,_=w.length,C=M[M.length-1];return M.forEach(($,z)=>{let j=a(y,$),B=j?y.node(j).order:_;(j||$===C)&&(M.slice(P,z+1).forEach(R=>{y.predecessors(R).forEach(T=>{let A=y.node(T),L=A.order;(L<D||B<L)&&!(A.dummy&&y.node(R).dummy)&&l(b,T,R)})}),P=z+1,D=B)}),M}return p.length&&p.reduce(N),b}function o(y,p){let b={};function N(M,D,P,_,C){let $;r.range(D,P).forEach(z=>{$=M[z],y.node($).dummy&&y.predecessors($).forEach(j=>{let B=y.node(j);B.dummy&&(B.order<_||B.order>C)&&l(b,j,$)})})}function w(M,D){let P=-1,_,C=0;return D.forEach(($,z)=>{if(y.node($).dummy==="border"){let j=y.predecessors($);j.length&&(_=y.node(j[0]).order,N(D,C,z,P,_),C=z,P=_)}N(D,C,D.length,_,M.length)}),D}return p.length&&p.reduce(w),b}function a(y,p){if(y.node(p).dummy)return y.predecessors(p).find(b=>y.node(b).dummy)}function l(y,p,b){if(p>b){let w=p;p=b,b=w}let N=y[p];N||(y[p]=N={}),N[b]=!0}function c(y,p,b){if(p>b){let N=p;p=b,b=N}return!!y[p]&&Object.hasOwn(y[p],b)}function d(y,p,b,N){let w={},M={},D={};return p.forEach(P=>{P.forEach((_,C)=>{w[_]=_,M[_]=_,D[_]=C})}),p.forEach(P=>{let _=-1;P.forEach(C=>{let $=N(C);if($.length){$=$.sort((j,B)=>D[j]-D[B]);let z=($.length-1)/2;for(let j=Math.floor(z),B=Math.ceil(z);j<=B;++j){let R=$[j];M[C]===C&&_<D[R]&&!c(b,C,R)&&(M[R]=C,M[C]=w[C]=w[R],_=D[R])}}})}),{root:w,align:M}}function h(y,p,b,N,w){let M={},D=f(y,p,b,w),P=w?"borderLeft":"borderRight";function _(z,j){let B=D.nodes().slice(),R={},T=B.pop();for(;T;){if(R[T])z(T);else{R[T]=!0,B.push(T);for(let A of j(T))B.push(A)}T=B.pop()}}function C(z){M[z]=D.inEdges(z).reduce((j,B)=>Math.max(j,M[B.v]+D.edge(B)),0)}function $(z){let j=D.outEdges(z).reduce((R,T)=>Math.min(R,M[T.w]-D.edge(T)),Number.POSITIVE_INFINITY),B=y.node(z);j!==Number.POSITIVE_INFINITY&&B.borderType!==P&&(M[z]=Math.max(M[z],j))}return _(C,D.predecessors.bind(D)),_($,D.successors.bind(D)),Object.keys(N).forEach(z=>M[z]=M[b[z]]),M}function f(y,p,b,N){let w=new s,M=y.graph(),D=S(M.nodesep,M.edgesep,N);return p.forEach(P=>{let _;P.forEach(C=>{let $=b[C];if(w.setNode($),_){var z=b[_],j=w.edge(z,$);w.setEdge(z,$,Math.max(D(y,C,_),j||0))}_=C})}),w}function m(y,p){return Object.values(p).reduce((b,N)=>{let w=Number.NEGATIVE_INFINITY,M=Number.POSITIVE_INFINITY;Object.entries(N).forEach(([P,_])=>{let C=v(y,P)/2;w=Math.max(_+C,w),M=Math.min(_-C,M)});let D=w-M;return D<b[0]&&(b=[D,N]),b},[Number.POSITIVE_INFINITY,null])[1]}function u(y,p){let b=Object.values(p),N=r.applyWithChunking(Math.min,b),w=r.applyWithChunking(Math.max,b);["u","d"].forEach(M=>{["l","r"].forEach(D=>{let P=M+D,_=y[P];if(_===p)return;let C=Object.values(_),$=N-r.applyWithChunking(Math.min,C);D!=="l"&&($=w-r.applyWithChunking(Math.max,C)),$&&(y[P]=r.mapValues(_,z=>z+$))})})}function x(y,p){return r.mapValues(y.ul,(b,N)=>{if(p)return y[p.toLowerCase()][N];{let w=Object.values(y).map(M=>M[N]).sort((M,D)=>M-D);return(w[1]+w[2])/2}})}function E(y){let p=r.buildLayerMatrix(y),b=Object.assign(i(y,p),o(y,p)),N={},w;["u","d"].forEach(D=>{w=D==="u"?p:Object.values(p).reverse(),["l","r"].forEach(P=>{P==="r"&&(w=w.map(z=>Object.values(z).reverse()));let _=(D==="u"?y.predecessors:y.successors).bind(y),C=d(y,w,b,_),$=h(y,w,C.root,C.align,P==="r");P==="r"&&($=r.mapValues($,z=>-z)),N[D+P]=$})});let M=m(y,N);return u(N,M),x(N,y.graph().align)}function S(y,p,b){return(N,w,M)=>{let D=N.node(w),P=N.node(M),_=0,C;if(_+=D.width/2,Object.hasOwn(D,"labelpos"))switch(D.labelpos.toLowerCase()){case"l":C=-D.width/2;break;case"r":C=D.width/2;break}if(C&&(_+=b?C:-C),C=0,_+=(D.dummy?p:y)/2,_+=(P.dummy?p:y)/2,_+=P.width/2,Object.hasOwn(P,"labelpos"))switch(P.labelpos.toLowerCase()){case"l":C=P.width/2;break;case"r":C=-P.width/2;break}return C&&(_+=b?C:-C),C=0,_}}function v(y,p){return y.node(p).width}}),_f=Ae((e,n)=>{var s=Ge(),r=Rf().positionX;n.exports=i;function i(a){a=s.asNonCompoundGraph(a),o(a),Object.entries(r(a)).forEach(([l,c])=>a.node(l).x=c)}function o(a){let l=s.buildLayerMatrix(a),c=a.graph().ranksep,d=a.graph().rankalign,h=0;l.forEach(f=>{let m=f.reduce((u,x)=>{let E=a.node(x).height;return u>E?u:E},0);f.forEach(u=>{let x=a.node(u);d==="top"?x.y=h+x.height/2:d==="bottom"?x.y=h+m-x.height/2:x.y=h+m/2}),h+=m+c})}}),Af=Ae((e,n)=>{var s=mf(),r=gf(),i=xf(),o=Ge().normalizeRanks,a=bf(),l=Ge().removeEmptyRanks,c=yf(),d=vf(),h=wf(),f=Tf(),m=_f(),u=Ge(),x=St().Graph;n.exports=E;function E(I,H={}){let V=H.debugTiming?u.time:u.notime;return V("layout",()=>{let W=V(" buildLayoutGraph",()=>_(I));return V(" runLayout",()=>S(W,V,H)),V(" updateInputGraph",()=>v(I,W)),W})}function S(I,H,V){H(" makeSpaceForEdgeLabels",()=>C(I)),H(" removeSelfEdges",()=>q(I)),H(" acyclic",()=>s.run(I)),H(" nestingGraph.run",()=>c.run(I)),H(" rank",()=>i(u.asNonCompoundGraph(I))),H(" injectEdgeLabelProxies",()=>$(I)),H(" removeEmptyRanks",()=>l(I)),H(" nestingGraph.cleanup",()=>c.cleanup(I)),H(" normalizeRanks",()=>o(I)),H(" assignRankMinMax",()=>z(I)),H(" removeEdgeLabelProxies",()=>j(I)),H(" normalize.run",()=>r.run(I)),H(" parentDummyChains",()=>a(I)),H(" addBorderSegments",()=>d(I)),H(" order",()=>f(I,V)),H(" insertSelfEdges",()=>F(I)),H(" adjustCoordinateSystem",()=>h.adjust(I)),H(" position",()=>m(I)),H(" positionSelfEdges",()=>Y(I)),H(" removeBorderNodes",()=>L(I)),H(" normalize.undo",()=>r.undo(I)),H(" fixupEdgeLabelCoords",()=>T(I)),H(" undoCoordinateSystem",()=>h.undo(I)),H(" translateGraph",()=>B(I)),H(" assignNodeIntersects",()=>R(I)),H(" reversePoints",()=>A(I)),H(" acyclic.undo",()=>s.undo(I))}function v(I,H){I.nodes().forEach(V=>{let W=I.node(V),X=H.node(V);W&&(W.x=X.x,W.y=X.y,W.order=X.order,W.rank=X.rank,H.children(V).length&&(W.width=X.width,W.height=X.height))}),I.edges().forEach(V=>{let W=I.edge(V),X=H.edge(V);W.points=X.points,Object.hasOwn(X,"x")&&(W.x=X.x,W.y=X.y)}),I.graph().width=H.graph().width,I.graph().height=H.graph().height}var y=["nodesep","edgesep","ranksep","marginx","marginy"],p={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},b=["acyclicer","ranker","rankdir","align","rankalign"],N=["width","height","rank"],w={width:0,height:0},M=["minlen","weight","width","height","labeloffset"],D={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},P=["labelpos"];function _(I){let H=new x({multigraph:!0,compound:!0}),V=O(I.graph());return H.setGraph(Object.assign({},p,Q(V,y),u.pick(V,b))),I.nodes().forEach(W=>{let X=O(I.node(W)),ee=Q(X,N);Object.keys(w).forEach(se=>{ee[se]===void 0&&(ee[se]=w[se])}),H.setNode(W,ee),H.setParent(W,I.parent(W))}),I.edges().forEach(W=>{let X=O(I.edge(W));H.setEdge(W,Object.assign({},D,Q(X,M),u.pick(X,P)))}),H}function C(I){let H=I.graph();H.ranksep/=2,I.edges().forEach(V=>{let W=I.edge(V);W.minlen*=2,W.labelpos.toLowerCase()!=="c"&&(H.rankdir==="TB"||H.rankdir==="BT"?W.width+=W.labeloffset:W.height+=W.labeloffset)})}function $(I){I.edges().forEach(H=>{let V=I.edge(H);if(V.width&&V.height){let W=I.node(H.v),X={rank:(I.node(H.w).rank-W.rank)/2+W.rank,e:H};u.addDummyNode(I,"edge-proxy",X,"_ep")}})}function z(I){let H=0;I.nodes().forEach(V=>{let W=I.node(V);W.borderTop&&(W.minRank=I.node(W.borderTop).rank,W.maxRank=I.node(W.borderBottom).rank,H=Math.max(H,W.maxRank))}),I.graph().maxRank=H}function j(I){I.nodes().forEach(H=>{let V=I.node(H);V.dummy==="edge-proxy"&&(I.edge(V.e).labelRank=V.rank,I.removeNode(H))})}function B(I){let H=Number.POSITIVE_INFINITY,V=0,W=Number.POSITIVE_INFINITY,X=0,ee=I.graph(),se=ee.marginx||0,J=ee.marginy||0;function U(oe){let le=oe.x,ie=oe.y,he=oe.width,de=oe.height;H=Math.min(H,le-he/2),V=Math.max(V,le+he/2),W=Math.min(W,ie-de/2),X=Math.max(X,ie+de/2)}I.nodes().forEach(oe=>U(I.node(oe))),I.edges().forEach(oe=>{let le=I.edge(oe);Object.hasOwn(le,"x")&&U(le)}),H-=se,W-=J,I.nodes().forEach(oe=>{let le=I.node(oe);le.x-=H,le.y-=W}),I.edges().forEach(oe=>{let le=I.edge(oe);le.points.forEach(ie=>{ie.x-=H,ie.y-=W}),Object.hasOwn(le,"x")&&(le.x-=H),Object.hasOwn(le,"y")&&(le.y-=W)}),ee.width=V-H+se,ee.height=X-W+J}function R(I){I.edges().forEach(H=>{let V=I.edge(H),W=I.node(H.v),X=I.node(H.w),ee,se;V.points?(ee=V.points[0],se=V.points[V.points.length-1]):(V.points=[],ee=X,se=W),V.points.unshift(u.intersectRect(W,ee)),V.points.push(u.intersectRect(X,se))})}function T(I){I.edges().forEach(H=>{let V=I.edge(H);if(Object.hasOwn(V,"x"))switch((V.labelpos==="l"||V.labelpos==="r")&&(V.width-=V.labeloffset),V.labelpos){case"l":V.x-=V.width/2+V.labeloffset;break;case"r":V.x+=V.width/2+V.labeloffset;break}})}function A(I){I.edges().forEach(H=>{let V=I.edge(H);V.reversed&&V.points.reverse()})}function L(I){I.nodes().forEach(H=>{if(I.children(H).length){let V=I.node(H),W=I.node(V.borderTop),X=I.node(V.borderBottom),ee=I.node(V.borderLeft[V.borderLeft.length-1]),se=I.node(V.borderRight[V.borderRight.length-1]);V.width=Math.abs(se.x-ee.x),V.height=Math.abs(X.y-W.y),V.x=ee.x+V.width/2,V.y=W.y+V.height/2}}),I.nodes().forEach(H=>{I.node(H).dummy==="border"&&I.removeNode(H)})}function q(I){I.edges().forEach(H=>{if(H.v===H.w){var V=I.node(H.v);V.selfEdges||(V.selfEdges=[]),V.selfEdges.push({e:H,label:I.edge(H)}),I.removeEdge(H)}})}function F(I){var H=u.buildLayerMatrix(I);H.forEach(V=>{var W=0;V.forEach((X,ee)=>{var se=I.node(X);se.order=ee+W,(se.selfEdges||[]).forEach(J=>{u.addDummyNode(I,"selfedge",{width:J.label.width,height:J.label.height,rank:se.rank,order:ee+ ++W,e:J.e,label:J.label},"_se")}),delete se.selfEdges})})}function Y(I){I.nodes().forEach(H=>{var V=I.node(H);if(V.dummy==="selfedge"){var W=I.node(V.e.v),X=W.x+W.width/2,ee=W.y,se=V.x-X,J=W.height/2;I.setEdge(V.e,V.label),I.removeNode(H),V.label.points=[{x:X+2*se/3,y:ee-J},{x:X+5*se/6,y:ee-J},{x:X+se,y:ee},{x:X+5*se/6,y:ee+J},{x:X+2*se/3,y:ee+J}],V.label.x=V.x,V.label.y=V.y}})}function Q(I,H){return u.mapValues(u.pick(I,H),Number)}function O(I){var H={};return I&&Object.entries(I).forEach(([V,W])=>{typeof V=="string"&&(V=V.toLowerCase()),H[V]=W}),H}}),Lf=Ae((e,n)=>{var s=Ge(),r=St().Graph;n.exports={debugOrdering:i};function i(o){let a=s.buildLayerMatrix(o),l=new r({compound:!0,multigraph:!0}).setGraph({});return o.nodes().forEach(c=>{l.setNode(c,{label:c}),l.setParent(c,"layer"+o.node(c).rank)}),o.edges().forEach(c=>l.setEdge(c.v,c.w,{},c.name)),a.forEach((c,d)=>{let h="layer"+d;l.setNode(h,{rank:"same"}),c.reduce((f,m)=>(l.setEdge(f,m,{style:"invis"}),m))}),l}}),Df=Ae((e,n)=>{n.exports="2.0.4"}),Pf=Ae((e,n)=>{n.exports={graphlib:St(),layout:Af(),debug:Lf(),util:{time:Ge().time,notime:Ge().notime},version:Df()}});const Qo=Pf();const Jo={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"}},$f={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function Bf({data:e}){const{t:n}=He(["work","common"]),{task:s,agentName:r,selected:i,direction:o="TB",isExpandedRoot:a,onCollapse:l}=e,c=Jo[s.status]??Jo.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"?ye.Left:ye.Top,m=o==="LR"?ye.Right:ye.Bottom;return t.jsxs("div",{className:`relative rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${d?`${c.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${c.bg} ${c.border}`} ${i?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[t.jsx(Jt,{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 ${$f[s.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${c.text}`,children:n(`work:status.task.${s.status}`,{defaultValue:s.status.replace("_"," ")})}),d&&t.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/15 text-blue-600 ml-auto whitespace-nowrap inline-flex items-center gap-0.5",children:[t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})}),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(Jt,{type:"source",position:m,className:"!bg-border-default !w-2 !h-2"}),a&&l&&t.jsx("button",{onClick:u=>{u.stopPropagation(),l()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const ea={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"}},ta={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function Of({data:e}){const{t:n}=He(["work","common"]),{req:s,selected:r,direction:i="TB",isExpandedRoot:o,onCollapse:a}=e,l=ea[s.status]??ea.pending,c=i==="LR"?ye.Left:ye.Top,d=i==="LR"?ye.Right:ye.Bottom;return t.jsxs("div",{className:`relative rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${l.bg} ${l.border} ${r?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[t.jsx(Jt,{type:"target",position:c,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:n("work:dag.reqLabel")}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${l.text}`,children:n(`work:status.requirement.${s.status}`,{defaultValue:s.status.replace("_"," ")})})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:s.title}),s.taskIds.length>0&&t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:n("work:dag.taskCount",{count:s.taskIds.length})}),t.jsx(Jt,{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 zf={task:Bf,requirement:Of};function Hf({nodeIds:e,rfRef:n}){const s=Lu();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 qf=()=>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,Vf=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 Wf(){return g.useSyncExternalStore(Vf,qf,()=>!1)}const _r=200,Ar=80;function na(e,n,s="TB"){const r=o=>{const a=new Qo.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:o,nodesep:40,ranksep:60});for(const l of e)a.setNode(l.id,{width:_r,height:Ar});for(const l of n)a.setEdge(l.source,l.target);return Qo.layout(a),e.map(l=>{const c=a.node(l.id);return{...l,position:{x:(c?.x??0)-_r/2,y:(c?.y??0)-Ar/2}}})},i=r(s);if(n.length>0&&e.length>4){let o=1/0,a=-1/0,l=1/0,c=-1/0;for(const m of i)o=Math.min(o,m.position.x),a=Math.max(a,m.position.x+_r),l=Math.min(l,m.position.y),c=Math.max(c,m.position.y+Ar);const d=a-o,h=c-l,f=s==="TB"?"LR":"TB";if(d>h*3)return{nodes:r(f),direction:f}}return{nodes:i,direction:s}}function Ff(e,n){const s=new Map,r=new Map;for(const a of e)r.set(a.id,a),s.set(a.id,new Set);for(const a of n)s.get(a.source)?.add(a.target),s.get(a.target)?.add(a.source);const i=new Set,o=[];for(const a of e){if(i.has(a.id))continue;const l=new Set,c=[a.id];for(;c.length>0;){const d=c.pop();if(!i.has(d)){i.add(d),l.add(d);for(const h of s.get(d)??[])i.has(h)||c.push(h)}}o.push({nodes:e.filter(d=>l.has(d.id)),edges:n.filter(d=>l.has(d.source)&&l.has(d.target))})}return o}function ra(e,n){if(e.length===0)return{nodes:[],direction:"TB"};const s=Ff(e,n);if(s.length===1)return na(e,n);let r="TB";const i=s.map(m=>{const{nodes:u,direction:x}=na(m.nodes,m.edges);r=x;let E=1/0,S=-1/0,v=1/0,y=-1/0;for(const p of u)E=Math.min(E,p.position.x),S=Math.max(S,p.position.x+_r),v=Math.min(v,p.position.y),y=Math.max(y,p.position.y+Ar);for(const p of u)p.position.x-=E,p.position.y-=v;return{nodes:u,w:S-E,h:y-v}});i.sort((m,u)=>u.h-m.h);const o=60,a=i.reduce((m,u)=>m+(u.w+o)*(u.h+o),0),l=Math.sqrt(a)*1.1,c=[];let d=0,h=0,f=0;for(const m of i){d>0&&d+m.w>l&&(d=0,h+=f+o,f=0);for(const u of m.nodes)c.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:c,direction:r}}function Yf(e,n,s){const r=new Set,i=[n];for(;i.length>0;){const o=i.pop();if(o===s)return!0;if(r.has(o))continue;r.add(o);const a=e.get(o);if(a?.blockedBy)for(const l of a.blockedBy)i.push(l)}return!1}const In=[{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(In.map(e=>e.id));const Er=new Set(In.filter(e=>e.id!=="done").map(e=>e.id)),sa=e=>e.status==="archived";function Gf(e,n,s,r){const i=new Set,o=[e];for(;o.length>0;){const a=o.pop();if(!i.has(a))if(i.add(a),a.startsWith("req-")){const l=s.get(a.slice(4));if(l)for(const c of l.taskIds)o.push(c)}else{const l=n.get(a);if(l?.blockedBy)for(const c of l.blockedBy)o.push(c);l?.requirementId&&o.push(`req-${l.requirementId}`)}}for(const a of r)a.requirementId&&i.has(a.id)&&i.add(`req-${a.requirementId}`);return i}function Zf({tasks:e,requirements:n=[],agents:s,showArchived:r,onShowArchivedChange:i,onTaskClick:o,onReqClick:a,onCollapseDAG:l,onDependencyChange:c,selectedTaskId:d,selectedReqId:h,hasDetailPanel:f,defaultExpandedNodeId:m,previewMode:u}){const{t:x}=He(["work","common"]),E=Wf(),[S,v]=g.useState(null),[y,p]=g.useState(null),[b,N]=g.useState(()=>new Set(Er)),[w,M]=g.useState(m??null),[D,P]=g.useState(r??!1),_=r??D,C=g.useCallback(ce=>{const te=typeof ce=="function"?ce(_):ce;P(te),i?.(te)},[_,i]);g.useEffect(()=>{r!==void 0&&P(r)},[r]),g.useEffect(()=>{m&&M(m)},[m]);const $=g.useMemo(()=>e.filter(ce=>sa(ce)).length,[e]),z=g.useMemo(()=>{const ce=new Set;for(const te of In)if(b.has(te.id))for(const pe of te.statuses)ce.add(pe);return ce},[b]),j=g.useMemo(()=>{const ce=new Set;for(const te of e)for(const pe of In)if(pe.statuses.has(te.status)){ce.add(pe.id);break}for(const te of n){const pe=ta[te.status];pe&&ce.add(pe)}return In.filter(te=>ce.has(te.id))},[e,n]),B=g.useCallback(ce=>{N(te=>{const pe=new Set(te);return pe.has(ce)?pe.delete(ce):pe.add(ce),pe})},[]),R=g.useCallback((ce,te="success")=>{v({msg:ce,type:te}),setTimeout(()=>v(null),2500)},[]),T=g.useMemo(()=>{const ce=new Map;for(const te of s)ce.set(te.id,te.name);return ce},[s]),A=g.useMemo(()=>{const ce=new Map;for(const te of e)ce.set(te.id,te);return ce},[e]),L=g.useMemo(()=>{const ce=new Map;for(const te of n)ce.set(te.id,te);return ce},[n]),q=g.useRef(!1),F=g.useCallback(()=>{q.current=!1,M(null),l?.()},[l]),Y=E?"#94a3b8":"#6b7280",Q=g.useCallback((ce,te,pe)=>({id:`${ce}->${te}`,source:ce,target:te,animated:pe==="blocked",markerEnd:{type:_n.ArrowClosed,width:14,height:14,color:pe==="blocked"?"#ef4444":Y},style:{stroke:pe==="blocked"?"#ef4444":Y,strokeWidth:1.5,cursor:"pointer"}}),[Y]),{initialNodes:O,initialEdges:I,topLevelIds:H}=g.useMemo(()=>{const ce=(we,Xe)=>{const _e=new Set,Re=we.map(Ee=>(_e.add(Ee.id),{id:Ee.id,type:"task",data:{task:Ee,agentName:Ee.assignedAgentId?T.get(Ee.assignedAgentId):void 0,selected:Ee.id===d},position:{x:0,y:0}}));for(const Ee of Xe){const Fe=`req-${Ee.id}`;_e.add(Fe),Re.push({id:Fe,type:"requirement",data:{req:Ee,selected:Ee.id===h},position:{x:0,y:0}})}const Le=[];for(const Ee of we)if(Ee.blockedBy)for(const Fe of Ee.blockedBy)_e.has(Fe)&&Le.push(Q(Fe,Ee.id,Ee.status));const lt=new Set,Pt=(Ee,Fe)=>{const rt=`${Ee}->${Fe}`;lt.has(rt)||(lt.add(rt),Le.push({id:rt,source:Ee,target:Fe,markerEnd:{type:_n.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ee of Xe){const Fe=`req-${Ee.id}`;for(const rt of Ee.taskIds)_e.has(rt)&&Pt(Fe,rt)}for(const Ee of we)if(Ee.requirementId){const Fe=`req-${Ee.requirementId}`;_e.has(Fe)&&Pt(Fe,Ee.id)}return{nodes:Re,edges:Le}},te=e.filter(we=>z.has(we.status)&&(_||!sa(we))),pe=new Set;for(const we of In)b.has(we.id)&&pe.add(we.id);const Te=n.filter(we=>{const Xe=ta[we.status];return Xe&&pe.has(Xe)}),{nodes:be,edges:Ie}=ce(te,Te),mt=new Set;for(const we of Ie)mt.add(we.target);const nt=new Set(be.filter(we=>!mt.has(we.id)).map(we=>we.id));if(!w||!nt.has(w)){const we=be.filter(Le=>nt.has(Le.id)),{nodes:Xe,direction:_e}=ra(we,[]);return{initialNodes:Xe.map(Le=>({...Le,data:{...Le.data,direction:_e}})),initialEdges:[],topLevelIds:nt}}const{nodes:yt,edges:ot}=ce(e,n),gt=Gf(w,A,L,e),Et=yt.filter(we=>gt.has(we.id)).map(we=>we.id===w?{...we,data:{...we.data,isExpandedRoot:!0,onCollapse:F}}:we),Ve=ot.filter(we=>gt.has(we.source)&&gt.has(we.target)),{nodes:ze,direction:Pe}=ra(Et,Ve);return{initialNodes:ze.map(we=>({...we,data:{...we.data,direction:Pe}})),initialEdges:Ve,topLevelIds:nt}},[e,n,T,A,L,Q,z,b,_,d,h,w,F]),[V,W,X]=Du(O),[ee,se,J]=Pu(I),U=g.useRef(null),oe=g.useRef({groupFilter:b,showArchived:_});g.useEffect(()=>{const ce=oe.current;(ce.groupFilter!==b||ce.showArchived!==_)&&(q.current=!1,M(null),oe.current={groupFilter:b,showArchived:_})},[b,_]),g.useEffect(()=>{W(O),se(I),q.current||requestAnimationFrame(()=>{U.current?.fitView({padding:.2,duration:300})})},[O,I,W,se]),g.useEffect(()=>{const ce=setTimeout(()=>{U.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(ce)},[f]);const le=g.useCallback(ce=>{ce&&(q.current=!0)},[]),ie=g.useCallback((ce,te)=>{if(!w&&H.has(te.id)&&(q.current=!1,M(te.id)),te.id.startsWith("req-")){const pe=L.get(te.id.slice(4));pe&&a&&a(pe)}else{const pe=A.get(te.id);pe&&o&&o(pe)}},[A,L,o,a,H,w]),he=g.useCallback(async ce=>{const{source:te,target:pe}=ce;if(!te||!pe||te===pe)return;const Te=A.get(pe);if(!Te)return;if(Te.blockedBy?.includes(te)){R(x("work:dag.toast.dependencyExists"),"error");return}if(Yf(A,te,pe)){R(x("work:dag.toast.cycleError"),"error");return}const be=[...Te.blockedBy??[],te];try{await re.tasks.update(pe,{blockedBy:be}),R(x("work:dag.toast.dependencyAdded")),c?.()}catch(Ie){R(x("work:dag.toast.failed",{message:Ie instanceof Error?Ie.message:String(Ie)}),"error")}},[A,R,c,x]),de=g.useCallback((ce,te)=>{p(te)},[]),Z=g.useCallback(async()=>{if(!y)return;const ce=A.get(y.target);if(!ce){p(null);return}const te=(ce.blockedBy??[]).filter(pe=>pe!==y.source);try{await re.tasks.update(y.target,{blockedBy:te}),R(x("work:dag.toast.dependencyRemoved")),c?.()}catch(pe){R(x("work:dag.toast.failed",{message:pe instanceof Error?pe.message:String(pe)}),"error")}p(null)},[y,A,R,c,x]);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:x("work:task.dagEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:x("work:task.dagEmptyDesc")})]})});const ae=b.size===Er.size&&[...Er].every(ce=>b.has(ce))&&!_,me=y?A.get(y.source):null,ve=y?A.get(y.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(Au,{nodes:V,edges:ee,onNodesChange:X,onEdgesChange:J,onNodeClick:ie,onConnect:he,onEdgeClick:de,onMoveEnd:le,onInit:ce=>{U.current=ce},nodeTypes:zf,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[u&&t.jsx(Hf,{nodeIds:V.map(ce=>ce.id),rfRef:U}),t.jsx(Hu,{color:E?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(Zu,{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(lf,{nodeColor:ce=>{const te=ce.data?.task,pe=te?.status;return te?.taskType==="scheduled"?"#8b8fa3":pe==="completed"||pe==="accepted"?"#10b981":pe==="in_progress"?"#f59e0b":pe==="blocked"||pe==="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(ce=>{const te=b.has(ce.id);return t.jsx("button",{onClick:()=>B(ce.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${te?`${ce.color.bg} ${ce.color.border} ${ce.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:x(`work:dag.filter.${ce.id}`)},ce.id)}),$>0&&t.jsx("button",{onClick:()=>C(ce=>!ce),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${_?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:x("work:dag.archivedToggle",{count:$})}),!ae&&t.jsx("button",{onClick:()=>{N(new Set(Er)),C(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:x("work:dag.reset")})]}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[w?t.jsx("button",{onClick:F,className:"text-brand-500 hover:text-brand-400 transition-colors",children:x("work:dag.backToOverview")}):t.jsx("span",{children:x("work:dag.expandHint")}),t.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),t.jsx("span",{children:x("work:dag.dragHint")})]})]}),S&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${S.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:S.msg}),y&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>p(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:ce=>ce.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:x("work:dag.removeDependencyTitle")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:x("work:dag.removeDependencyBody",{target:ve?.title??y.target.slice(-8),source:me?.title??y.source.slice(-8)})}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>p(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:x("common:cancel")}),t.jsx("button",{onClick:Z,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:x("common:remove")})]})]})})]})}function Xf({orgId:e,onCreated:n,onClose:s}){const{t:r}=He(["work","common"]);ml(!0);const[i,o]=g.useState(""),[a,l]=g.useState(""),[c,d]=g.useState(""),[h,f]=g.useState("main"),[m,u]=g.useState([]),[x,E]=g.useState([]),[S,v]=g.useState(!1),[y,p]=g.useState(""),[b,N]=g.useState(!1),w=rr();g.useEffect(()=>{re.teams.list().then(P=>E(P.teams)).catch(()=>{})},[]),g.useEffect(()=>{const P=_=>{_.key==="Escape"&&s()};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[s]);const M=g.useCallback(async P=>{if(P?.preventDefault(),N(!0),!(!i.trim()||S)){v(!0),p("");try{const _=c.trim()?[{url:c.trim(),defaultBranch:h.trim()||"main"}]:[],C=await re.projects.create({name:i.trim(),description:a.trim()||void 0,repositories:_.length>0?_:void 0,teamIds:m.length>0?m:void 0,orgId:e??"default"});n(C.project)}catch(_){p(_ instanceof Error?_.message:r("project.failedToCreate"))}v(!1)}},[i,a,c,h,m,e,S,n,r]),D=b&&!i.trim();return gl.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 ${w?"w-full":"w-[520px]"}`,onClick:P=>P.stopPropagation(),onSubmit:M,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:P=>{o(P.target.value),p("")},onBlur:()=>N(!0),placeholder:r("project.projectNamePlaceholder"),className:`input ${D?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!w}),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:P=>l(P.target.value),placeholder:r("project.descriptionPlaceholder"),className:"input",rows:3})]}),x.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:x.map(P=>{const _=m.includes(P.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:_,onChange:()=>u(C=>_?C.filter($=>$!==P.id):[...C,P.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:P.name})]},P.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:c,onChange:P=>d(P.target.value),placeholder:r("project.repositoryPlaceholder"),className:"input"})]}),c.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:P=>f(P.target.value),placeholder:r("project.branchPlaceholder"),className:"input !w-24"})]})]}),y&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:y}),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()||S,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:r(S?"common:creating":"project.createProject")})]})]})]})}),document.body)}function Ls(e){const n=e.agentId,s=e.activityId;return!n||!s?null:Ca({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},s,n)}function Ds(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 Ps({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(vl,{entries:e,isActive:!0,onExpand:()=>s("full"),embedded:!0}):t.jsx(Sa,{entries:e,isActive:!0,onCollapse:()=>s("compact"),embedded:!0})})}function Wi(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,l=window.innerHeight-o.bottom-8,c=o.top-8,d=l<a&&c>l;r(d?{top:o.top-4,left:o.left,width:o.width,flipUp:!0}:{top:o.bottom+4,left:o.left,width:o.width,flipUp:!1})};return i(),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[n,e]),s}function Yn({options:e,value:n,onChange:s,placeholder:r,noMatchesText:i,className:o}){const[a,l]=g.useState(!1),[c,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),x=Wi(f,a);g.useEffect(()=>{const v=y=>{h.current&&!h.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const E=e.find(v=>v.value===n)?.label??"",S=c?e.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):e;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{l(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:c,onChange:v=>d(v.target.value),onClick:v=>v.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder: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&&x&&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:x.flipUp?{bottom:window.innerHeight-x.top,left:x.left,width:x.width}:{top:x.top,left:x.left,width:x.width},children:S.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):S.map(v=>t.jsx("div",{onClick:()=>{s(v.value),l(!1),d("")},className:`px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 ${v.value===n?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:v.label},v.value))})]})}function Uf({options:e,selected:n,onAdd:s,placeholder:r,noMatchesText:i,className:o}){const[a,l]=g.useState(!1),[c,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),x=Wi(f,a);g.useEffect(()=>{const v=y=>{h.current&&!h.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const E=e.filter(v=>!n.includes(v.value)),S=c?E.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):E;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{l(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:c,onChange:v=>d(v.target.value),onClick:v=>v.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:r,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&x&&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:x.flipUp?{bottom:window.innerHeight-x.top,left:x.left,width:x.width}:{top:x.top,left:x.left,width:x.width},children:S.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):S.map(v=>t.jsx("div",{onClick:()=>{s(v.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:v.label},v.value))})]})}function $n(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 oa({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=He(["work","common"]),[o,a]=g.useState(!1),[l,c]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{c(e)},[e]),g.useEffect(()=>{o&&d.current?.focus()},[o]);const h=async()=>{a(!1);const f=l.trim();if(f&&f!==e)try{await n(f)}catch{c(e)}else c(e)};return o?t.jsx("input",{ref:d,value:l,onChange:f=>c(f.target.value),onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&h(),f.key==="Escape"&&(c(e),a(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${s??""}`,placeholder:r}):t.jsx("span",{onClick:()=>a(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.clickToEdit")})})}function Kf({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=He(["work","common"]),[o,a]=g.useState(!1),[l,c]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{c(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=l.trim();if(f!==e)try{await n(f)}catch{c(e)}else c(e)};return o?t.jsx("textarea",{ref:d,value:l,onChange:f=>{c(f.target.value),f.target.style.height="auto",f.target.style.height=f.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Escape"&&(c(e),a(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${s??""}`,placeholder:r,rows:2}):t.jsx("p",{onClick:()=>a(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.addDescription")})})}const Qf=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function Fi(e){const n=e.match(Qf);return n?{timestamp:n[1].trim(),author:n[2]?.trim()??"System",content:n[3].trim()}:{timestamp:"",author:"",content:e}}function Jf(e,n){if(!e)return"";const s=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!s)return e;const r=new Date,i=+s[1],o=+s[2]-1,a=+s[3],l=+s[4],c=+s[5],d=new Date(i,o,a,l,c),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 eh(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 th({note:e,compact:n}){const{t:s}=He(["work","common"]),r=Fi(e),i=s("work:task.systemAuthor"),o=eh(r.author||i),a=r.author?r.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",l=Jf(r.timestamp,s),c=!r.author||r.author==="System";return n?t.jsxs("div",{className:"flex gap-2.5 group",children:[t.jsx("div",{className:`w-6 h-6 rounded-full ${o.bg} flex items-center justify-center text-[9px] font-bold ${o.text} shrink-0 mt-0.5`,children:a}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-tertiary":o.text}`,children:c?i:r.author}),l&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l})]}),t.jsx("div",{className:"text-xs text-fg-secondary",children:t.jsx(Xn,{content:r.content,className:"text-xs text-fg-secondary"})})]})]}):t.jsxs("div",{className:"flex gap-3 group",children:[t.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[t.jsx("div",{className:`w-7 h-7 rounded-full ${o.bg} flex items-center justify-center text-[10px] font-bold ${o.text}`,children:a}),t.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),t.jsx("div",{className:"flex-1 min-w-0 pb-4",children:t.jsxs("div",{className:`border ${o.border} rounded-lg overflow-hidden`,children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${o.bg} border-b ${o.border}`,children:[t.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-secondary":o.text}`,children:c?i:r.author}),l&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l})]}),t.jsx("div",{className:"px-3 py-2.5",children:t.jsx(Xn,{content:r.content,className:"text-xs text-fg-secondary"})})]})})]})}const nh=new Set(["rejected","cancelled","archived"]),$s=[{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"}],ia={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"},la={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"},ca={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"},da={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 Yi(e){return Object.keys(la).reduce((n,s)=>(n[s]={label:e(`work:status.task.${s}`),cls:la[s]},n),{})}function Gi(e){return Object.keys(ia).reduce((n,s)=>(n[s]={label:e(`work:status.sub.${s}`),cls:ia[s]},n),{})}function rh(e){return Object.keys(ca).reduce((n,s)=>(n[s]={label:e(`work:priority.${s}`),cls:ca[s]},n),{})}function Bs(e){return Object.keys(da).reduce((n,s)=>(n[s]={label:e(`work:status.requirement.${s}`),cls:da[s]},n),{})}const ua=["low","medium","high","urgent"],fa=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],ha=["pending","in_progress","completed","rejected","cancelled"],ma={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([])},ys={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},nr={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"},ga={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function sh({agent:e,anchorRect:n,onClose:s}){const{t:r}=He(["work","common"]),i=g.useRef(null);g.useEffect(()=>{const l=c=>{i.current&&!i.current.contains(c.target)&&s()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[s]);const o=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",a=e.status==="idle"?r("work:task.online"):e.status==="working"?r("work:task.working"):e.status==="error"?r("work:task.error"):r("work:task.offline");return t.jsxs("div",{ref:i,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:n.top+4,left:n.left},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[10px] font-bold text-brand-600 shrink-0",children:e.name.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),t.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o}`}),t.jsx("span",{className:"text-[10px] text-fg-secondary",children:a})]})]})]}),t.jsx("button",{onClick:()=>{s(),Lt.navigate(Ye.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 Zn({comment:e,agents:n,onReply:s}){const{t:r}=He(["work","common"]),i=e.authorType==="agent"||e.authorType==="system",o=new Date(e.createdAt),a=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),l=o.toLocaleDateString([],{month:"short",day:"numeric"}),[c,d]=g.useState(null),[h,f]=g.useState(!1),[m,u]=g.useState([]),[x,E]=g.useState(!1),S=g.useCallback((N,w)=>{const M=n.find(D=>D.name.toLowerCase()===N.toLowerCase());if(M){const D=w.target.getBoundingClientRect();d({agent:M,top:D.bottom,left:D.left})}},[n]),v=g.useMemo(()=>n.map(N=>N.name),[n]),y=g.useCallback(N=>{const w=n.find(M=>M.name.toLowerCase()===e.authorName.toLowerCase());if(w){const M=N.currentTarget.getBoundingClientRect();d({agent:w,top:M.bottom,left:M.left})}},[n,e.authorName]),p=g.useCallback(async()=>{if(h){f(!1);return}const N=e.activityId;if(N&&(f(!0),!(m.length>0))){E(!0);try{const{logs:w}=await re.agents.getActivityLogs(e.authorId,N),M=w.map(D=>Ca(D,N,e.authorId)).filter(D=>D!==null).map(D=>({...D,ts:new Date(D.createdAt).getTime()}));u(M)}catch{}E(!1)}},[h,m.length,e]),b=g.useMemo(()=>us(m.map(ds).filter(N=>N!==null)),[m]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[t.jsx("div",{onClick:y,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${i?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${i?"text-indigo-400":"text-blue-400"}`,onClick:y,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[l," ",a]}),s&&t.jsx("button",{onClick:()=>s(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r("work:task.reply")}),e.activityId&&i&&t.jsx("button",{onClick:p,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 N=document.getElementById(`comment-${e.replyTo}`);N&&(N.scrollIntoView({behavior:"smooth",block:"center"}),N.classList.add("bg-brand-500/10"),setTimeout(()=>N.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(Xn,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:S,knownNames:v}),e.attachments?.map((N,w)=>N.type==="image"?t.jsx("img",{src:N.url,alt:N.name,className:"mt-1 max-w-[200px] rounded"},w):null),h&&t.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:x?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(Sa,{entries:m,isActive:!1,onCollapse:()=>f(!1),embedded:!0})})]}),c&&t.jsx(sh,{agent:c.agent,anchorRect:{top:c.top,left:c.left},onClose:()=>d(null)})]})}function oh({task:e,agents:n,users:s,authUser:r}){const{t:i}=He(["work","common"]),[o,a]=g.useState([]),[l,c]=g.useState([]),d=g.useRef(null),[h,f]=g.useState(new Map);g.useEffect(()=>{c([]),f(new Map),d.current&&(clearTimeout(d.current),d.current=null),re.tasks.getComments(e.id).then(v=>a(v.comments)).catch(()=>{})},[e.id]),g.useEffect(()=>bt.on("task:comment",y=>{if(y.payload?.taskId===e.id&&y.payload.comment){const p=y.payload.comment;a(b=>b.some(N=>N.id===p.id)?b:[...b,p]),(p.authorType==="agent"||p.authorId?.startsWith("agt_"))&&(c(b=>{const N=b.filter(w=>w.id!==p.authorId);return N.length===0&&d.current&&(clearTimeout(d.current),d.current=null),N}),f(b=>{const N=new Map(b);return N.delete(p.authorId),N}))}}),[e.id]),g.useEffect(()=>{if(l.length===0)return;const v=new Set(l.map(p=>p.id));return bt.on("agent:activity_log",p=>{const b=p.payload;if(!b)return;const N=b.agentId;if(!v.has(N))return;const w=Ls(b);w&&f(M=>Ds(M,N,w))})},[l]);const m=g.useMemo(()=>{const v=[];for(const y of e.notes??[]){const p=Fi(y);let b;if(p.timestamp){const N=p.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);b=N?new Date(+N[1],+N[2]-1,+N[3],+N[4],+N[5],+(N[6]??0)):new Date(0)}else b=new Date(0);v.push({type:"note",note:y,ts:b})}for(const y of o)v.push({type:"comment",comment:y,ts:new Date(y.createdAt)});return v.sort((y,p)=>y.ts.getTime()-p.ts.getTime()),v},[e.notes,o]),[u,x]=g.useState(null),E=async(v,y,p,b)=>{let N;p.length>0&&(N=(await re.uploads.upload(p.map(_=>({dataUrl:_.dataUrl,name:_.name})),"comments")).files.map(_=>({type:"image",url:_.url,name:_.name}))),await re.tasks.addComment(e.id,v,r?.name,N,r?.id,y.length>0?y:void 0,b);const w=[],M=new Set,D=P=>{if(M.has(P)||P===r?.id)return;M.add(P);const _=n.find(C=>C.id===P);_&&w.push({id:_.id,name:_.name,avatarUrl:_.avatarUrl})};for(const P of y){const _=n.find(C=>C.name.toLowerCase()===P.toLowerCase());_&&D(_.id)}e.assignedAgentId&&D(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&D(e.createdBy),w.length>0&&(d.current&&clearTimeout(d.current),c(w),d.current=setTimeout(()=>c([]),12e4))},S=g.useCallback(v=>{x({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return t.jsxs("div",{className:"mt-5",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:i("work:task.activityCommentsHeading")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[m.length===0&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:i("work:task.noActivityYet")}),m.map((v,y)=>v.type==="note"?t.jsx(th,{note:v.note,compact:!0},`n-${y}`):t.jsx(Zn,{comment:v.comment,agents:n,onReply:S},`c-${v.comment.id}`)),l.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(v=>{const y=h.get(v.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Lt.navigate(Ye.TEAM,{agentId:v.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(ws,{name:v.name,avatarUrl:v.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:v.name}),y.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(Ps,{entries:y})})]},v.id)})})]}),t.jsx(Ma,{agents:n,humans:s,onSubmit:E,replyTo:u,onCancelReply:()=>x(null),placeholder:i("work:task.commentPlaceholder")})]})}function ah({task:e,isRunning:n,authUser:s,agents:r}){const i=e.id,{t:o}=He(["work","common"]),[a,l]=g.useState([]),[c,d]=g.useState(new Map),[h,f]=g.useState(new Set),[m,u]=g.useState([]),[x,E]=g.useState(""),[S,v]=g.useState(n),[y,p]=g.useState(!0),[b,N]=g.useState(new Set),[w,M]=g.useState(""),[D,P]=g.useState(!1),[_,C]=g.useState([]),$=g.useRef(null),[z,j]=g.useState(new Map),[B,R]=g.useState([]),[T,A]=g.useState([]),[L,q]=g.useState(!1),F=g.useRef(null),Y=g.useRef(null);g.useEffect(()=>{v(n)},[n]),g.useEffect(()=>{C([]),j(new Map),$.current&&(clearTimeout($.current),$.current=null)},[i]),g.useEffect(()=>{p(!0),Promise.all([re.tasks.getLogsSummary(i).catch(()=>({rounds:[]})),re.tasks.getComments(i).catch(()=>({comments:[]}))]).then(([U,oe])=>{const le=U.rounds;if(l(le),u(oe.comments),le.length===0){p(!1);return}const ie=le[le.length-1].round;N(new Set([ie])),re.tasks.getLogs(i,ie).catch(()=>({logs:[]})).then(he=>{d(new Map([[ie,he.logs]])),p(!1)})})},[i]),g.useEffect(()=>{const U=e.assignedAgentId;U&&(q(!0),re.agents.getActivities(U,{taskId:i,limit:20}).then(oe=>A(oe.activities)).catch(()=>A([])).finally(()=>q(!1)))},[i,e.assignedAgentId]);const Q=g.useCallback(U=>{c.has(U)||h.has(U)||(f(oe=>new Set(oe).add(U)),re.tasks.getLogs(i,U).catch(()=>({logs:[]})).then(oe=>{d(le=>new Map(le).set(U,oe.logs)),f(le=>{const ie=new Set(le);return ie.delete(U),ie})}))},[i,c,h]),O=g.useCallback(U=>{N(oe=>{const le=new Set(oe);return le.has(U)?le.delete(U):(le.add(U),c.has(U)||Q(U)),le})},[c,Q]);g.useEffect(()=>{const U=bt.on("task:log",ie=>{const he=ie.payload;if(he.taskId!==i)return;const de={id:he.id,taskId:he.taskId,agentId:he.agentId,seq:he.seq,type:he.logType,content:he.content,metadata:he.metadata,executionRound:he.executionRound,createdAt:he.createdAt},Z=de.executionRound??1;l(ae=>ae.find(ve=>ve.round===Z)?ae:[...ae,{round:Z,logCount:0,toolCount:0,firstAt:de.createdAt,lastAt:de.createdAt,status:"running"}]),N(ae=>ae.has(Z)?ae:new Set(ae).add(Z)),d(ae=>{const me=ae.get(Z)??[];return de.id&&me.some(ve=>ve.id===de.id)?ae:new Map(ae).set(Z,[...me,de])}),de.type==="text"&&E(""),de.type==="status"&&(de.content==="started"||de.content==="resumed"?v(!0):["completed","failed","cancelled","execution_finished"].includes(de.content)&&(v(!1),l(ae=>ae.map(me=>me.round===Z?{...me,status:de.content}:me)))),de.type==="error"&&v(!1)}),oe=bt.on("task:log:delta",ie=>{const he=ie.payload;he.taskId===i&&E(de=>de+he.text)}),le=bt.on("task:comment",ie=>{const he=ie.payload;if(he.taskId!==i)return;const de=he.comment;u(Z=>Z.some(ae=>ae.id===de.id)?Z:[...Z,de]),(de.authorType==="agent"||de.authorId?.startsWith("agt_"))&&(C(Z=>{const ae=Z.filter(me=>me.id!==de.authorId);return ae.length===0&&$.current&&(clearTimeout($.current),$.current=null),ae}),j(Z=>{const ae=new Map(Z);return ae.delete(de.authorId),ae}))});return()=>{U(),oe(),le()}},[i]),g.useEffect(()=>{if(_.length===0)return;const U=new Set(_.map(le=>le.id));return bt.on("agent:activity_log",le=>{const ie=le.payload;if(!ie)return;const he=ie.agentId;if(!U.has(he))return;const de=Ls(ie);de&&j(Z=>Ds(Z,he,de))})},[_]);const I=g.useMemo(()=>{const U=[];for(const[,oe]of c)U.push(...oe);return U.sort((oe,le)=>oe.seq-le.seq),U},[c]),H=g.useMemo(()=>I.map(U=>ro(U)),[I]),V=a.length>1,W=U=>{const oe=U.target.files;if(oe){for(const le of Array.from(oe)){if(!le.type.startsWith("image/"))continue;const ie=new FileReader;ie.onload=()=>{R(he=>[...he,{type:"image",url:ie.result,name:le.name}])},ie.readAsDataURL(le)}U.target.value=""}},X=async()=>{if(!(!w.trim()&&B.length===0)){P(!0);try{let U;B.length>0&&(U=(await re.uploads.upload(B.map(Z=>({dataUrl:Z.url,name:Z.name})),"comments")).files.map(Z=>({type:"image",url:Z.url,name:Z.name})));const oe=await re.tasks.addComment(i,w,s?.name,U,s?.id);oe.comment&&u(de=>de.some(Z=>Z.id===oe.comment.id)?de:[...de,oe.comment]),M(""),R([]);const le=[],ie=new Set,he=de=>{if(ie.has(de)||de===s?.id)return;ie.add(de);const Z=r.find(ae=>ae.id===de);Z&&le.push({id:Z.id,name:Z.name,avatarUrl:Z.avatarUrl})};e.assignedAgentId&&he(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&he(e.createdBy),le.length>0&&($.current&&clearTimeout($.current),C(le),$.current=setTimeout(()=>C([]),12e4))}catch{}P(!1)}},ee=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[B.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:B.map((U,oe)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:U.url,alt:U.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>R(le=>le.filter((ie,he)=>he!==oe)),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:"×"})]},oe))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:w,onChange:U=>M(U.target.value),onKeyDown:U=>{U.key==="Enter"&&!U.shiftKey&&(U.preventDefault(),X())},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:F,accept:"image/*",multiple:!0,onChange:W,className:"hidden"}),t.jsx("button",{onClick:()=>F.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:()=>{X()},disabled:D||!w.trim()&&B.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:o("common:send")})]})]});if(y)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:o("work:task.loadingLogs")});if(a.length===0&&!x){const U=e.assignedAgentId?r.find(ve=>ve.id===e.assignedAgentId):void 0,oe=T.length>0,le=U&&U.currentTaskId&&U.currentTaskId!==e.id,ie=e.status==="pending",he=e.status==="in_progress",de=!e.assignedAgentId;let Z="📋",ae=o("work:task.emptyLogs.default"),me=o("work:task.emptyLogs.defaultHint");return de?(Z="👤",ae=o("work:task.emptyLogs.noAgent"),me=o("work:task.emptyLogs.noAgentHint")):ie?(Z="⏳",ae=o("work:task.emptyLogs.pending"),me=o("work:task.emptyLogs.pendingHint")):he&&le?(Z="🔄",ae=o("work:task.emptyLogs.agentBusy",{agent:U?.name??e.assignedAgentId}),me=o("work:task.emptyLogs.agentBusyHint")):he&&(Z="⏳",ae=o("work:task.emptyLogs.starting"),me=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:L?t.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:o("work:task.loadingLogs")}):oe?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:U?.name??o("work:task.agent"),count:T.length})]}),t.jsx("div",{className:"space-y-1.5",children:T.map(ve=>{const ce=!ve.endedAt,te=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:()=>Lt.navigate(Ye.TEAM,{agentId:e.assignedAgentId}),children:[t.jsx("span",{className:"text-sm shrink-0",children:te}),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`:""]})]}),ce&&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")]}),!ce&&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:Z}),t.jsxs("div",{className:"text-xs",children:[ae,t.jsx("br",{}),t.jsx("span",{className:"text-fg-muted",children:me})]})]})})}),ee]})}if(!V){const U=H.map(ie=>ds(ie)).filter(ie=>ie!==null),oe=so(I,us(U)),le=[...oe.map(ie=>({kind:"entry",entry:ie,ts:ie.timestamp?new Date(ie.timestamp).getTime():0})),...m.map(ie=>({kind:"comment",comment:ie,ts:new Date(ie.createdAt).getTime()}))];return le.sort((ie,he)=>ie.ts-he.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:[le.map((ie,he)=>ie.kind==="comment"?t.jsx(Zn,{comment:ie.comment,agents:r},`c-${ie.comment.id}`):t.jsx(oo,{entry:ie.entry,showTime:!0,isLast:he===le.length-1},`e-${he}`)),S&&x&&t.jsx(ao,{content:x}),S&&!x&&oe.length>0&&t.jsx(io,{})]}),ee]})}const se=(U,oe)=>{const le=U.firstAt?new Date(U.firstAt).getTime():0,ie=oe?.firstAt?new Date(oe.firstAt).getTime():1/0;return m.filter(he=>{const de=new Date(he.createdAt).getTime();return de>=le&&de<ie})},J=a.length>0?m.filter(U=>new Date(U.createdAt).getTime()<new Date(a[0].firstAt).getTime()):[];return t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsx("div",{ref:Y}),t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[J.length>0&&t.jsx("div",{className:"space-y-0.5",children:J.map(U=>t.jsx(Zn,{comment:U,agents:r},U.id))}),a.map((U,oe)=>{const le=b.has(U.round),ie=U.round===a[a.length-1].round,he=c.get(U.round),de=h.has(U.round),Z=se(U,a[oe+1]),ae=U.status==="completed"||U.status==="execution_finished"?"✅":U.status==="failed"?"❌":U.status==="cancelled"?"⏹":"🔄",me=U.lastAt&&U.firstAt?Math.max(0,new Date(U.lastAt).getTime()-new Date(U.firstAt).getTime()):0,ve=me>=6e4?`${Math.floor(me/6e4)}m ${Math.floor(me%6e4/1e3)}s`:me>=1e3?`${Math.floor(me/1e3)}s`:"";return t.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[t.jsxs("button",{onClick:()=>O(U.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:ae}),t.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:o("work:task.roundHeader",{n:U.round})}),Z.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",Z.length]}),ie&&S&&t.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.toolCount",{count:U.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 ${le?"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"})})]})]}),le&&t.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[de&&t.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:o("work:task.loadingRound",{n:U.round})}),he&&(()=>{const te=he.map(be=>ro(be)).map(be=>ds(be)).filter(be=>be!==null),Te=[...so(he,us(te)).map(be=>({kind:"entry",entry:be,ts:be.timestamp?new Date(be.timestamp).getTime():0})),...Z.map(be=>({kind:"comment",comment:be,ts:new Date(be.createdAt).getTime()}))];return Te.sort((be,Ie)=>be.ts-Ie.ts),Te.map((be,Ie)=>be.kind==="comment"?t.jsx(Zn,{comment:be.comment,agents:r},`c-${be.comment.id}`):t.jsx(oo,{entry:be.entry,showTime:!0,isLast:Ie===Te.length-1},`e-${Ie}`))})(),ie&&S&&x&&t.jsx(ao,{content:x}),ie&&S&&!x&&!de&&t.jsx(io,{})]})]},U.round)}),_.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:_.map(U=>{const oe=z.get(U.id)??[];return t.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Lt.navigate(Ye.TEAM,{agentId:U.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(ws,{name:U.name,avatarUrl:U.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:U.name}),oe.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:"→"})]}),oe.length>0&&t.jsx("div",{className:"ml-9 mt-1",children:t.jsx(Ps,{entries:oe})})]},U.id)})})]}),ee]})}const pa=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 Mr(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function ih({filePath:e,onClose:n,onOpenExternal:s}){const{t:r}=He(["work","common"]),[i,o]=g.useState([e]),a=i[i.length-1],[l,c]=g.useState(null),[d,h]=g.useState(null),[f,m]=g.useState(!0);g.useEffect(()=>{m(!0),h(null),c(null),re.files.preview(a).then(N=>c(N)).catch(N=>h(String(N))).finally(()=>m(!1))},[a]);const u=N=>o(w=>[...w,N]),x=()=>o(N=>N.length>1?N.slice(0,-1):N),E=i.length>1,S=N=>{re.files.reveal(N).catch(()=>{})},v=N=>{N.isDirectory||pa.has(N.ext)?u(N.path):S(N.path)},y=a.split("/").pop()??a,p=l?.type==="directory",b=(N,w)=>{if(w)return"📁";const M=[".md",".markdown"],D=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return M.includes(N)?"📝":D.includes(N)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(N)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(N)?"💻":"📄"};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:N=>N.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:x,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"})})}),p?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:y}),p&&l.entries&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",l.entries.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[t.jsx("button",{onClick:()=>s?s():S(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}),l?.type==="directory"&&l.entries&&t.jsxs("div",{className:"divide-y divide-border-default/50",children:[l.entries.length===0&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.emptyDirectory")}),l.entries.map(N=>t.jsxs("button",{onClick:()=>v(N),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(N.ext,N.isDirectory)}),t.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:N.name}),!N.isDirectory&&N.size!=null&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Mr(N.size)}),N.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"})}),!N.isDirectory&&!pa.has(N.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"})]})]},N.path))]}),l&&l.type!=="directory"&&t.jsx("div",{className:"p-5",children:l.type==="image"&&l.content?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:`data:${l.mimeType};base64,${l.content}`,alt:l.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):l.type==="audio"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("audio",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?re.files.streamUrl(l.path):re.files.streamUrl(a)),className:"w-full"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${Mr(l.size)}`:""]})]}):l.type==="video"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("video",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?re.files.streamUrl(l.path):re.files.streamUrl(a)),className:"w-full max-h-[60vh] rounded-lg bg-black"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${Mr(l.size)}`:""]})]}):l.type==="binary"||l.content==null?t.jsxs("div",{className:"space-y-3 text-center py-6",children:[t.jsx("p",{className:"text-sm text-fg-secondary",children:r("work:task.cannotPreviewFile",{defaultValue:"This file type cannot be previewed."})}),t.jsxs("p",{className:"text-xs text-fg-tertiary font-mono",children:[l.name,l.extension?` (${l.extension})`:"",l.size!=null?` · ${Mr(l.size)}`:""]}),t.jsx("button",{onClick:()=>S(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(wl,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function xa({task:e,agents:n,projects:s,requirements:r,allTasks:i,users:o,onClose:a,onRefresh:l,authUser:c,scrollToComments:d,onScrollToCommentsDone:h,onReqClick:f,onProjectClick:m}){const{t:u}=He(["work","common"]),x=g.useMemo(()=>Yi(u),[u]),[E,S]=g.useState([]),[v,y]=g.useState(""),[p,b]=g.useState(!1),[N,w]=g.useState(!1),[M,D]=g.useState(null),[P,_]=g.useState(null),[C,$]=g.useState(!1),[z,j]=g.useState(!1),[B,R]=g.useState(!1),[T,A]=g.useState("every"),[L,q]=g.useState(""),[F,Y]=g.useState(""),[Q,O]=g.useState(""),[I,H]=g.useState(!1),[V,W]=g.useState("details"),X=g.useRef(null),[ee,se]=g.useState("none"),J=g.useCallback(G=>{W(G),requestAnimationFrame(()=>{X.current?.scrollTo({top:0,behavior:"instant"})})},[]),U=g.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),oe=cs(U,V,J);g.useEffect(()=>{const G=X.current;if(!G)return;const ge=()=>{const{scrollTop:je,scrollHeight:Ne,clientHeight:Qe}=G;if(!(Ne>Qe+50)){se("none");return}const rn=je<30,pn=je+Qe>=Ne-30;se(rn?"top":pn?"bottom":"middle")};ge(),G.addEventListener("scroll",ge,{passive:!0});const Se=new ResizeObserver(ge);return Se.observe(G),()=>{G.removeEventListener("scroll",ge),Se.disconnect()}},[V]),g.useEffect(()=>{if(!d)return;W("details");const G=setTimeout(()=>{const ge=X.current;ge&&ge.scrollTo({top:ge.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(G)},[d,h]);const[le,ie]=g.useState(null),[he,de]=g.useState(!1),[Z,ae]=g.useState(null),[me,ve]=g.useState(!1),[ce,te]=g.useState(e.description),pe=g.useRef(null),Te=g.useRef(null),be=g.useRef(80);g.useEffect(()=>{if(me&&Te.current){const G=Te.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,be.current)+"px",G.focus()}},[me]);const[Ie,mt]=g.useState(!1),[nt,yt]=g.useState(""),[ot,gt]=g.useState(1),[Et,Ve]=g.useState([]),ze=g.useCallback(async()=>{try{const{results:G}=await re.deliverables.search({taskId:e.id,limit:200});Ve(G.filter(ge=>ge.status!=="outdated"))}catch{}},[e.id]);g.useEffect(()=>{ze()},[ze]);const[Pe,We]=g.useState(!1),we=rr(),Xe=20,_e=g.useCallback(async()=>{try{const G=await re.tasks.listSubtasks(e.id);S(G.subtasks)}catch{}},[e.id]);g.useEffect(()=>{_e()},[_e]);const Re=async G=>{if(!I){H(!0);try{await G(),l(),await _e()}catch(ge){ie(String(ge).replace("Error: ",""))}finally{H(!1)}}},Le=G=>Re(()=>re.tasks.update(e.id,{priority:G})),lt=G=>Re(()=>re.tasks.assign(e.id,G||null)),Pt=G=>Re(()=>re.tasks.update(e.id,{projectId:G||null})),Ee=async()=>{if(!I){H(!0);try{await re.tasks.pause(e.id),l()}finally{H(!1)}}},Fe=async()=>{if(!I){H(!0),ie(null),J("logs");try{await re.tasks.resume(e.id),l()}catch(G){ie(String(G).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{H(!1)}}},rt=async()=>{v.trim()&&(await re.tasks.createSubtask(e.id,v.trim()),y(""),b(!1),_e(),l())},ct=async G=>{G.status==="completed"||G.status==="cancelled"?await re.tasks.cancelSubtask(e.id,G.id):await re.tasks.completeSubtask(e.id,G.id),_e(),l()},Mt=async G=>{await re.tasks.deleteSubtask(e.id,G.id),D(null),_e(),l()},mn=async()=>{if(!I){H(!0);try{await re.tasks.updateStatus(e.id,"in_progress"),l()}finally{H(!1)}}},en=async()=>{if(!I){H(!0),ie(null),J("logs");try{await re.tasks.retry(e.id),l()}catch(G){ie(String(G).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{H(!1)}}},gn=async()=>{if(!I){H(!0),ie(null),J("logs");try{await re.tasks.runNow(e.id),l()}catch(G){ie(String(G).replace("Error: API error: 400","Server error").replace("Error: ","")),l()}finally{H(!1)}}},$t=g.useRef(l);$t.current=l,g.useEffect(()=>bt.on("task:update",ge=>{ge.payload.taskId===e.id&&(_e(),$t.current())}),[e.id,_e]);const tn=E.filter(G=>G.status==="completed").length,Yt=E.filter(G=>G.status==="cancelled").length,nn=tn+Yt,Ue=e.status==="in_progress",Bt=e.status==="blocked",It=Bt&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(G=>{const ge=i.find(Se=>Se.id===G);return ge&&ge.status==="completed"})),Tt=e.status==="completed",vt=e.status==="failed",pt=e.status==="rejected",Rt=e.status==="cancelled",_t=e.status==="archived",Ot=Tt||vt||pt||Rt||_t,Ke=e.taskType==="scheduled"&&!!e.scheduleConfig,dt=Ke&&!!e.scheduleConfig?.paused,ut=(()=>{const G=s.find(ge=>ge.id===e.projectId);return G&&G.name!=="default"?G:void 0})(),at=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:[we&&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=x[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," ")})})(),It&&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:()=>J("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${V==="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:()=>J("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${V==="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:()=>J("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${V==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const G=Et.filter(ge=>typeof ge.reference=="string"&&ge.reference.length>0).length;return G>0?u("work:task.deliverablesCount",{count:G}):u("work:task.deliverables")})()}),t.jsx("button",{onClick:()=>J("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${V==="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:X,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:oe.onTouchStart,onTouchEnd:oe.onTouchEnd,children:[t.jsxs("div",{className:V==="logs"?"min-w-0 min-h-full":"hidden",children:[le&&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")})," ",le]}),t.jsx(ah,{task:e,isRunning:e.status==="in_progress",authUser:c,agents:n})]}),t.jsxs("div",{className:V==="details"?"":"hidden",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:me?t.jsx("textarea",{ref:Te,value:ce,onChange:G=>{te(G.target.value);const ge=G.target;ge.style.height="auto",ge.style.height=ge.scrollHeight+"px"},onBlur:()=>{ce!==e.description&&Re(()=>re.tasks.update(e.id,{description:ce})),ve(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),te(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:pe,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]")||(be.current=Math.max(pe.current?.offsetHeight??80,60),te(e.description),ve(!0))},role:"button",tabIndex:0,onKeyDown:G=>G.key==="Enter"&&(te(e.description),ve(!0)),children:e.description?t.jsxs("div",{children:[t.jsx("div",{className:we&&!Pe?"line-clamp-3":"",children:t.jsx(Xn,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),we&&e.description.length>150&&t.jsx("button",{onClick:G=>{G.stopPropagation(),We(!Pe)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:u(Pe?"work:task.collapse":"common:showMore")})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:u("work:task.noDescription")})})}),(ut||at)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[ut&&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(ut.id):void 0,role:m?"button":void 0,tabIndex:m?0:void 0,onKeyDown:m?G=>G.key==="Enter"&&m(ut.id):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.projectLabel")}),ut.name]}),at&&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(at):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?G=>G.key==="Enter"&&f(at):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.requirementLabel")}),at.title.length>40?at.title.slice(0,40)+"…":at.title]})]}),t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default",children:[t.jsx("div",{className:"flex items-center justify-between mb-1.5",children:t.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:u("work:task.dependencies")})}),e.blockedBy&&e.blockedBy.length>0?t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(G=>{const ge=i.find(je=>je.id===G),Se=ge&&(ge.status==="completed"||ge.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Se?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:Se?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${Se?"line-through opacity-60":""}`,children:ge?ge.title.slice(0,30):G.slice(-8)}),!Ot&&t.jsx("button",{onClick:async()=>{const je=(e.blockedBy??[]).filter(Ne=>Ne!==G);await re.tasks.update(e.id,{blockedBy:je}),l()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:u("work:task.removeDependency"),children:"×"})]},G)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:u("work:task.noDependencies")}),It&&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")})]}),!Ot&&t.jsxs("select",{value:"",onChange:async G=>{const ge=G.target.value;if(!ge)return;const Se=[...e.blockedBy??[],ge];await re.tasks.update(e.id,{blockedBy:Se}),l()},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:u("work:task.addDependency")}),i.filter(G=>G.id!==e.id&&!(e.blockedBy??[]).includes(G.id)).map(G=>t.jsx("option",{value:G.id,children:G.title},G.id))]})]}),t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.projectLabel")}),t.jsxs("select",{value:e.projectId??"",onChange:G=>{Pt(G.target.value)},disabled:I,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=>Re(()=>re.tasks.update(e.id,{requirementId:G.target.value||null})),disabled:I,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=>{lt(G.target.value)},disabled:I,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 ge=G.target.value;if(!ge)return;const Se=ge.startsWith("human:"),je=ge.replace(/^(human|agent):/,"");(je!==e.reviewerId||(Se?"human":"agent")!==(e.reviewerType??"agent"))&&Re(()=>re.tasks.update(e.id,{reviewerId:je,reviewerType:Se?"human":"agent"}))},disabled:I,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=>{Le(G.target.value)},disabled:I,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:$n(e.createdBy,n,o)??e.createdBy})}),e.updatedBy&&t.jsx("span",{children:u("work:task.updatedBy",{name:$n(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:tn,total:E.length-Yt}),Yt>0?` · ${Yt} cancelled`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[nn>0&&t.jsx("button",{onClick:()=>w(G=>!G),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${N?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:N?u("work:task.hideCompleted"):u("work:task.showCompleted",{count:nn})}),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=N?E:E.filter(ge=>ge.status!=="completed"&&ge.status!=="cancelled");return G.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:G.map(ge=>t.jsxs("div",{className:`group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors ${ge.status==="cancelled"?"opacity-50":""}`,children:[t.jsxs("button",{onClick:()=>{ct(ge)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${ge.status==="completed"?"bg-green-600 border-green-600 text-white":ge.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[ge.status==="completed"&&t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),ge.status==="cancelled"&&t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M3 3l6 6M9 3l-6 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),t.jsx("span",{className:`flex-1 text-sm ${ge.status==="completed"?"line-through text-fg-tertiary":ge.status==="cancelled"?"line-through text-fg-quaternary":"text-fg-secondary"}`,children:ge.title}),t.jsx("button",{onClick:()=>D(ge),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},ge.id))}):null})(),E.length===0&&!p&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:u("work:task.noSubtasksYet")}),p&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:v,onChange:G=>y(G.target.value),onKeyDown:G=>{G.key==="Enter"&&rt(),G.key==="Escape"&&(b(!1),y(""))},placeholder:u("work:task.subtaskTitlePlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{onClick:()=>{rt()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:u("work:task.add")}),t.jsx("button",{onClick:()=>{b(!1),y("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:u("common:cancel")})]}),(()=>{const G=Et.filter(je=>typeof je.reference=="string"&&je.reference.length>0);if(G.length===0)return null;const ge={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},Se=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:()=>J("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:Se.map(je=>{const Ne=/^https?:\/\//i.test(je.reference),Qe=Ne?je.summary||je.reference:je.reference.split("/").pop()??je.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${ge[je.type]??"bg-gray-500/15 text-fg-secondary"}`,children:je.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Ne?t.jsxs("a",{href:je.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:je.reference,children:[Qe," ",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:()=>ae(je.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:je.reference,children:Qe}),je.summary&&!Ne&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:je.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:je.reference})]})]},je.id)})})]})})(),t.jsx(oh,{task:e,agents:n,users:o,authUser:c})]})]}),t.jsx("div",{className:V==="history"?"":"hidden",children:t.jsx(Ui,{entityType:"task",entityId:e.id})}),t.jsx("div",{className:V==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const G=Et.filter(Ne=>typeof Ne.reference=="string"&&Ne.reference.length>0);if(G.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:u("work:task.noDeliverablesYet")});const ge={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},Se=Math.ceil(G.length/Xe),je=G.slice((ot-1)*Xe,ot*Xe);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})}),Se>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:ot<=1,onClick:()=>gt(Ne=>Ne-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[ot,"/",Se]}),t.jsx("button",{disabled:ot>=Se,onClick:()=>gt(Ne=>Ne+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:je.map(Ne=>{const Qe=/^https?:\/\//i.test(Ne.reference),ft=Qe?Ne.summary||Ne.reference:Ne.reference.split("/").pop()??Ne.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${ge[Ne.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Ne.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Qe?t.jsxs("a",{href:Ne.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:Ne.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:()=>ae(Ne.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ne.reference,children:ft}),Ne.summary&&!Qe&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Ne.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Ne.reference})]})]},Ne.id)})})]})})()})]}),ee!=="none"&&ee!=="top"&&t.jsx("button",{onClick:()=>X.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"})})}),ee!=="none"&&ee!=="bottom"&&t.jsx("button",{onClick:()=>{const G=X.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"})})})]}),Ke&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${dt?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Ue&&!B&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Ue||B||e.scheduleConfig?.runAt||(A(e.scheduleConfig?.cron?"cron":"every"),q(e.scheduleConfig?.every??"4h"),Y(e.scheduleConfig?.cron??""),O(e.scheduleConfig?.maxRuns&&e.scheduleConfig.maxRuns>0?String(e.scheduleConfig.maxRuns):""),R(!0))},children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:dt?"text-amber-600":"text-brand-500",children:dt?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")}),!dt&&e.scheduleConfig.nextRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-fg-tertiary",children:"·"}),t.jsx("span",{className:"text-fg-secondary",children:u("work:task.scheduleNext",{when:(()=>{const G=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(G<=0)return u("work:task.scheduleDueNow");const ge=Math.floor(G/6e4);if(ge<60)return u("work:task.scheduleInMinutes",{count:ge});const Se=Math.floor(ge/60);return Se<24?u("work:task.scheduleInHoursMinutes",{h:Se,m:ge%60}):u("work:task.scheduleInDaysHours",{d:Math.floor(Se/24),h:Se%24})})()})})]}),!Ue&&!B&&!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"})]})]}),B?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=>A(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:L,onChange:G=>q(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:F,onChange:G=>Y(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=>O(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=L:G.cron=F.trim(),Q&&(G.maxRuns=parseInt(Q,10)),await Re(()=>re.tasks.updateSchedule(e.id,G)),R(!1)},disabled:I,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:()=>R(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:u("common:cancel")})]})]}):t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[t.jsx("span",{children:u("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?u("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:u("work:task.scheduleLast",{when:(()=>{const G=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),ge=Math.floor(G/6e4);if(ge<1)return u("work:task.noteTimeJustNow");if(ge<60)return u("work:task.noteTimeMinutes",{count:ge});const Se=Math.floor(ge/60);return Se<24?u("work:task.noteTimeHours",{count:Se}):u("work:task.noteTimeDays",{count:Math.floor(Se/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(Ke){de(!0);return}Re(()=>re.tasks.approve(e.id))},disabled:I,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:e.createdBy&&!e.createdBy.startsWith("agt_")?u("work:task.startExecution"):u("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?t.jsx("button",{onClick:async()=>{const{count:G}=await re.tasks.getDependentCount(e.id);_({dependentCount:G})},disabled:I,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:I,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:()=>{Re(()=>re.tasks.accept(e.id,c?.id))},disabled:I,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")}),Ie?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:nt,onChange:G=>yt(G.target.value),onKeyDown:G=>{G.key==="Enter"&&nt.trim()&&(Re(()=>re.tasks.revision(e.id,nt.trim(),c?.id)),mt(!1),yt(""))},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:()=>{Re(()=>re.tasks.revision(e.id,nt.trim()||u("work:task.revisionsNeededDefault"),c?.id)),mt(!1),yt("")},disabled:I,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:()=>{mt(!1),yt("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>mt(!0),disabled:I,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:()=>{Ee()},disabled:I,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:()=>{en()},disabled:I,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")]})]}),Bt&&t.jsx("button",{onClick:()=>{Fe()},disabled:I,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:I?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")]})}),vt&&!Ke&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{en()},disabled:I,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:()=>{mn()},disabled:I,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")]})]}),Ke&&(Tt||vt||Rt)&&!_t&&t.jsx("button",{onClick:()=>{gn()},disabled:I,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:I?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")]})}),Ke&&!Ue&&!_t&&!pt&&(dt?t.jsx("button",{onClick:()=>{Re(()=>re.tasks.resumeSchedule(e.id))},disabled:I,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:()=>{Re(()=>re.tasks.pauseSchedule(e.id))},disabled:I,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")})),(Tt||vt||pt||Rt)&&t.jsx("button",{onClick:()=>j(!0),disabled:I,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")}),Tt&&!Ke&&t.jsx("button",{onClick:()=>{mn()},disabled:I,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")}),!Ot&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:G}=await re.tasks.getDependentCount(e.id);_({dependentCount:G})},disabled:I,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")})]})}),M&&t.jsx(Sn,{title:u("work:task.deleteSubtaskTitle",{title:M.title}),message:u("work:task.deleteSubtaskMessage"),confirmLabel:u("common:delete"),onConfirm:()=>{Mt(M)},onCancel:()=>D(null)}),C&&t.jsx(Sn,{title:u("work:task.rejectConfirmTitle"),message:u("work:task.rejectConfirmMessage"),confirmLabel:u("work:task.reject"),onConfirm:()=>{$(!1),Re(()=>re.tasks.reject(e.id))},onCancel:()=>$(!1)}),z&&t.jsx(Sn,{title:u("work:task.archiveConfirmTitle"),message:u(Ke?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:u("work:task.archive"),onConfirm:()=>{j(!1),Re(()=>re.tasks.archive(e.id))},onCancel:()=>j(!1)}),P&&P.dependentCount>0?t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>_(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:[Ke&&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:P.dependentCount})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("button",{onClick:()=>{_(null),Re(()=>re.tasks.cancel(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-surface-elevated border border-border-default rounded-lg hover:bg-surface-overlay text-fg-primary text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelTaskOnly")}),t.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:u("work:task.cancelTaskOnlyHint")})]}),t.jsxs("button",{onClick:()=>{_(null),Re(()=>re.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelWithDependents")}),t.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:u("work:task.cancelWithDependentsHint",{count:P.dependentCount})})]}),t.jsx("button",{onClick:()=>_(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("work:task.keepTaskRunning")})]})]})}):P&&t.jsx(Sn,{title:u("work:task.cancelTaskModalTitle"),message:u(Ke?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:u("work:task.cancelTask"),onConfirm:()=>{_(null),Re(()=>re.tasks.cancel(e.id))},onCancel:()=>_(null)}),Z&&t.jsx(ih,{filePath:Z,onClose:()=>ae(null),onOpenExternal:()=>{ae(null),re.deliverables.search({taskId:e.id,limit:100}).then(({results:G})=>{const ge=G.find(Se=>Se.reference===Z);ge?Lt.navigate(Ye.DELIVERABLES,{openDeliverable:ge.id}):Lt.navigate(Ye.DELIVERABLES)}).catch(()=>Lt.navigate(Ye.DELIVERABLES))}}),he&&e.scheduleConfig&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>de(!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:I,onClick:()=>{de(!1),Re(()=>re.tasks.approve(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-green-600 hover:bg-green-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveRunNow")}),t.jsx("button",{disabled:I,onClick:()=>{de(!1),Re(()=>re.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveWait")}),t.jsx("button",{onClick:()=>de(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("common:cancel")})]})]})})]})}function ba({project:e,tasks:n,requirements:s,agents:r,onDeleteProject:i,onUpdateProject:o,onRefresh:a}){const l=g.useMemo(()=>n.filter(C=>C.projectId===e.id),[n,e.id]),c=g.useMemo(()=>s.filter(C=>C.projectId===e.id),[s,e.id]),d=g.useMemo(()=>{const C={total:l.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:c.length,reqsDone:0};for(const $ of l)$.status==="completed"||$.status==="accepted"?C.completed++:$.status==="in_progress"?C.inProgress++:$.status==="review"||$.status==="revision"?C.inReview++:$.status==="blocked"?C.blocked++:$.status==="failed"?C.failed++:C.pending++;for(const $ of c)$.status==="completed"&&C.reqsDone++;return C},[l,c]),h=g.useMemo(()=>new Set(l.map(C=>C.assignedAgentId).filter(Boolean)),[l]),f=g.useMemo(()=>r.filter(C=>h.has(C.id)),[r,h]),[m,u]=g.useState(!1),[x,E]=g.useState(""),[S,v]=g.useState("main"),[y,p]=g.useState(!1),[b,N]=g.useState(!1),{t:w}=He(["work","common"]),M=[{value:"active",label:w("work:project.statusActive"),desc:w("work:project.statusActiveDesc")},{value:"paused",label:w("work:project.statusPaused"),desc:w("work:project.statusPausedDesc")},{value:"archived",label:w("work:project.statusArchived"),desc:w("work:project.statusArchivedDesc")}],D=async C=>{if(C!==e.status){p(!0);try{await o({status:C}),a()}finally{p(!1)}}},P=async()=>{const C=x.trim();if(!C)return;const $=[...e.repositories??[],{url:"",localPath:C,defaultBranch:S||"main"}];await o({repositories:$}),E(""),v("main"),u(!1),a()},_=async C=>{const $=(e.repositories??[]).filter((z,j)=>j!==C);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(Kf,{value:e.description??"",onSave:async C=>{await o({description:C}),a()},className:"text-sm text-fg-secondary",placeholder:w("work:project.descriptionPlaceholderLong")}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&t.jsxs("span",{children:[w("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:[w("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:w("work:project.projectStatusHeading")}),t.jsx("div",{className:"flex gap-2",children:M.map(C=>t.jsxs("button",{disabled:y,onClick:()=>D(C.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===C.value?C.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":C.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${y?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:C.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:C.desc})]},C.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:w("work:project.taskOverview")}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(Wt,{label:w("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),t.jsx(Wt,{label:w("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),t.jsx(Wt,{label:w("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),t.jsx(Wt,{label:w("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),t.jsx(Wt,{label:w("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),t.jsx(Wt,{label:w("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:w("work:project.requirementsHeading")}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(Wt,{label:w("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),t.jsx(Wt,{label:w("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),t.jsx(Wt,{label:w("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:w("work:project.agentsHeading",{count:f.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(C=>{const $=l.filter(j=>j.assignedAgentId===C.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 ${C.status==="working"?"bg-blue-500":C.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:C.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:w("work:project.agentTaskCounts",{active:z.length,total:$.length})})]},C.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:w("work:project.repositories")}),t.jsx("button",{onClick:()=>u(!m),className:"text-[10px] text-brand-500 hover:text-brand-500",children:w(m?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!m&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:w("work:project.noReposLinked")}),(e.repositories??[]).map((C,$)=>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:C.url||C.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:C.defaultBranch}),t.jsx("button",{onClick:()=>_($),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:w("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:x,onChange:C=>E(C.target.value),placeholder:w("work:project.repoPathPlaceholder"),className:"w-full px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:S,onChange:C=>v(C.target.value),placeholder:w("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:P,disabled:!x.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:w("work:task.add")})]})]})]}),t.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:w("work:project.dangerZone")}),t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:w("work:project.dangerZoneDeleteHint")}),t.jsx("button",{onClick:()=>N(!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:w("work:project.deleteProject")})]}),b&&t.jsx(Sn,{title:w("work:project.deleteProjectConfirmTitle"),message:w("work:project.deleteProjectConfirmBody",{name:e.name,tasks:d.total,reqs:d.reqs}),confirmLabel:w("work:project.deleteProject"),onConfirm:()=>{N(!1),i()},onCancel:()=>N(!1)})]})}function Wt({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 Zi={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},Xi={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},lh={urgent:0,high:1,medium:2,low:3},ya={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},va={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"},ch={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"},dh=["pending","in_progress","completed","rejected","cancelled","archived"];function uh(e){for(const n of $s)if(n.statuses.includes(e))return n.id;return"closed"}function wa(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 Ir({value:e,options:n,onSelect:s,allowedValues:r}){const[i,o]=g.useState(!1),a=g.useRef(null),l=g.useRef(null),c=n.find(d=>d.value===e);return g.useEffect(()=>{if(!i)return;const d=h=>{l.current&&!l.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 ${c?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:c?.label??e}),i&&t.jsx("div",{ref:l,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:n.map(d=>{const 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 ka({row:e,idx:n,dragIdx:s,agentMap:r,projMap:i,onTaskClick:o,onReqClick:a,onRowDragStart:l,onRowDragEnd:c,handleStatusChange:d,handlePriorityChange:h,selected:f,isMobile:m,isAbnormalBlocked:u}){const{t:x}=He(["work","common"]),E=g.useMemo(()=>Yi(x),[x]),S=g.useMemo(()=>Bs(x),[x]),v=g.useMemo(()=>rh(x),[x]),y=e.data.status,p=e.data.priority,b=e.kind==="task"?r.get(e.data.assignedAgentId??""):void 0,N=(()=>{const M=i.get((e.kind==="task",e.data.projectId??""));return M&&M.name!=="default"?M:void 0})(),w=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:x("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:x("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:x("work:task.taskShort")});return m?t.jsxs("div",{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 ${va[e.group]??"border-l-gray-700"} ${f?"bg-brand-500/10 border-l-brand-500":"active:bg-surface-elevated/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[w,u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500",children:"⚠"}),t.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsx("div",{onClick:M=>M.stopPropagation(),children:t.jsx(Ir,{value:y,options:e.kind==="task"?fa.map(M=>({value:M,label:E[M]?.label??M,cls:E[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):ha.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?ma[y]:ys[y],onSelect:M=>{d(e,M)}})}),t.jsx("div",{onClick:M=>M.stopPropagation(),children:t.jsx(Ir,{value:p,options:ua.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{h(e,M)}})}),b&&t.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${nr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`${ga[b.status]??"text-fg-secondary"}`,children:b.name})]}),N?.name&&t.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:N.name}),t.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:wa(e.data.updatedAt??"",x)})]})]}):t.jsxs("div",{draggable:!0,onDragStart:M=>l(M,n),onDragEnd:c,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${va[e.group]??"border-l-gray-700"} ${s===n?"opacity-40":""} ${f?"bg-brand-500/10 border-l-brand-500 hover:bg-brand-500/15":"hover:bg-surface-elevated/50"}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:w}),t.jsxs("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate",children:e.data.title}),u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500 shrink-0",children:"⚠"})]}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:M=>M.stopPropagation(),children:t.jsx(Ir,{value:y,options:e.kind==="task"?fa.map(M=>({value:M,label:E[M]?.label??M,cls:E[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):ha.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?ma[y]:ys[y],onSelect:M=>{d(e,M)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:M=>M.stopPropagation(),children:t.jsx(Ir,{value:p,options:ua.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{h(e,M)}})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:b?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${nr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`font-medium ${ga[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:N?.name?t.jsx("span",{className:"text-brand-400/70",children:N.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:wa(e.data.updatedAt??"",x)})]})}function fh({tasks:e,requirements:n,agents:s,projects:r,onTaskClick:i,onReqClick:o,onRefresh:a,selectedTaskId:l,selectedReqId:c}){const{t:d}=He(["work","common"]),h=rr(),[f,m]=g.useState("status"),[u,x]=g.useState(null),[E,S]=g.useState(null),v=g.useMemo(()=>{const T=new Map;for(const A of e)T.set(A.id,A);return T},[e]),y=g.useCallback(T=>T.status!=="blocked"?!1:!T.blockedBy||T.blockedBy.length===0?!0:T.blockedBy.every(A=>{const L=v.get(A);return L&&L.status==="completed"}),[v]),p=g.useMemo(()=>{const T=[];for(const A of e){const L=uh(A.status);T.push({kind:"task",data:A,group:L,groupOrder:ya[L]??5})}for(const A of n){const L=Zi[A.status]??"todo";T.push({kind:"req",data:A,group:L,groupOrder:ya[L]??5})}if(f==="status")T.sort((A,L)=>{if(A.groupOrder!==L.groupOrder)return A.groupOrder-L.groupOrder;const q=new Date(A.data.updatedAt??0).getTime();return new Date(L.data.updatedAt??0).getTime()-q});else{const A=L=>lh[L.data.priority]??2;T.sort((L,q)=>{const F=A(L),Y=A(q);return F!==Y?F-Y:new Date(q.data.updatedAt??0).getTime()-new Date(L.data.updatedAt??0).getTime()})}return T},[e,n,f]),b=async(T,A)=>{try{T.kind==="task"?await re.tasks.updateStatus(T.data.id,A):await re.requirements.updateStatus(T.data.id,A),a()}catch{}},N=async(T,A)=>{try{T.kind==="task"?await re.tasks.update(T.data.id,{priority:A}):await re.requirements.update(T.data.id,{priority:A}),a()}catch{}},w=(T,A)=>{x(A),T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",String(A)),T.currentTarget.style.opacity="0.4"},M=T=>{T.currentTarget.style.opacity="1",x(null),S(null)},D=(T,A)=>{T.preventDefault(),T.dataTransfer.dropEffect="move",E!==A&&S(A)},P=async(T,A)=>{if(T.preventDefault(),S(null),u==null)return;const L=p[u];if(!L||L.group===A)return;const q=$s.find(F=>F.id===A);if(q){try{if(L.kind==="task"){if(L.data.status==="pending")return;await re.tasks.updateStatus(L.data.id,q.dropStatus)}else{const F=Xi[A];F&&await re.requirements.updateStatus(L.data.id,F)}a()}catch{}x(null)}},_=g.useMemo(()=>new Map(s.map(T=>[T.id,T])),[s]),C=g.useMemo(()=>new Map(r.map(T=>[T.id,T])),[r]),$=["todo","in_progress","review","done"],z=g.useMemo(()=>{const T={};for(const A of p)T[A.group]=(T[A.group]??0)+1;return T},[p]),{rowsByGroup:j,rowIndexMap:B}=g.useMemo(()=>{const T=new Map,A=new Map;for(let L=0;L<p.length;L++){const q=p[L];A.set(q,L);const F=T.get(q.group)??[];F.push(q),T.set(q.group,F)}return{rowsByGroup:T,rowIndexMap:A}},[p]),R=g.useMemo(()=>{if(f!=="status")return null;const T=new Set(p.map(q=>q.group)),A=[],L=new Set;T.has("failed")&&(A.push("failed"),L.add("failed"));for(const q of $)A.push(q),L.add(q);for(const q of p)L.has(q.group)||(A.push(q.group),L.add(q.group));return A},[p,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:p.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"&&R?R.map(T=>{const A=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 ${ch[T]??""} ${E===T?"ring-1 ring-brand-500/40":""}`,onDragOver:L=>D(L,T),onDragLeave:()=>S(null),onDrop:L=>{P(L,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})]}),A.map(L=>t.jsx(ka,{row:L,idx:B.get(L)??0,dragIdx:u,agentMap:_,projMap:C,onTaskClick:i,onReqClick:o,onRowDragStart:w,onRowDragEnd:M,handleStatusChange:b,handlePriorityChange:N,selected:L.kind==="task"?L.data.id===l:L.data.id===c,isMobile:h,isAbnormalBlocked:L.kind==="task"?y(L.data):!1},`${L.kind}-${L.data.id}`))]},T)}):p.map((T,A)=>t.jsx(ka,{row:T,idx:A,dragIdx:u,agentMap:_,projMap:C,onTaskClick:i,onReqClick:o,onRowDragStart:w,onRowDragEnd:M,handleStatusChange:b,handlePriorityChange:N,selected:T.kind==="task"?T.data.id===l:T.data.id===c,isMobile:h,isAbnormalBlocked:T.kind==="task"?y(T.data):!1},`${T.kind}-${T.data.id}`)),p.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 hh(e,n){const s=new Map,r=new Map(e.map(l=>[l.id,l])),i=new Set;for(const l of e){let c=vs(l.title).replace(/[^a-z0-9-]/g,"").slice(0,30)||"step";i.has(c)&&(c=`${c}-${l.id.slice(-4)}`),i.add(c),s.set(l.id,c)}const o=new Map,a=new Set;for(const l of e){const c=l.assignedAgentId;if(c&&!o.has(c)){const d=n[c]??"worker";let h=vs(d).replace(/[^a-z0-9-]/g,"")||"worker";a.has(h)&&(h=`${h}-${c.slice(-4)}`),a.add(h),o.set(c,h)}}return e.map(l=>({id:s.get(l.id),name:l.title,role:o.get(l.assignedAgentId)??"worker",prompt:l.description||l.title,depends_on:(l.blockedBy??[]).filter(c=>r.has(c)).map(c=>s.get(c)).filter(Boolean)}))}function Tr(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function mh(e,n,s){const r=[];r.push(`name: ${Tr(e)}`),r.push(`description: ${Tr(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: ${Tr(i.name)}`),r.push(" type: agent_task"),r.push(` role: ${Tr(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
8
  `))r.push(` ${o}`);r.push("")}return r.join(`
9
- `)}function gh({req:e,tasks:n,agents:s,teamId:r,onClose:i,onSaved:o}){const{t:a}=He(["work"]),l=g.useMemo(()=>{const P={};for(const _ of s)P[_.id]=_.name;return P},[s]),c=g.useMemo(()=>hh(n,l),[n,l]),[d,h]=g.useState(()=>vs(e.title)),[f,m]=g.useState(e.description||e.title),[u,x]=g.useState(c),[E,S]=g.useState(!1),[v,y]=g.useState(null),p=(P,_,C)=>{x($=>$.map((z,j)=>j===P?{...z,[_]:C}:z))},b=P=>{const _=u[P]?.id;x(C=>C.filter(($,z)=>z!==P).map($=>({...$,depends_on:$.depends_on.filter(z=>z!==_)})))},[N,w]=g.useState(!1),M=async()=>{if(d.trim()){S(!0),y(null);try{const P=mh(d.trim(),f,u);await re.workflows.create(r,d.trim(),P),w(!0),setTimeout(()=>o(),800)}catch(P){y(String(P))}S(!1)}},D=g.useMemo(()=>[...new Set(u.map(P=>P.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:P=>P.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:P=>h(P.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(P=>t.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:P},P))})]})]}),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:P=>m(P.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((P,_)=>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:_+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:P.name,onChange:C=>p(_,"name",C.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:P.role,onChange:C=>p(_,"role",C.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")})]}),P.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"),":"]}),P.depends_on.map(C=>{const $=u.find(z=>z.id===C);return t.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:$?.name??C},C)})]}),t.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:P.prompt})]}),t.jsx("button",{onClick:()=>b(_),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"})})})]})},P.id))})]}),v&&t.jsx("p",{className:"text-xs text-red-500",children:v}),N&&t.jsx("p",{className:"text-xs text-green-500 font-medium",children:a("work:task.workflowSavedSuccess","Workflow saved successfully")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default",children:[t.jsx("button",{onClick:i,className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated rounded-lg transition-colors",children:a("work:task.cancel","Cancel")}),t.jsx("button",{onClick:M,disabled:E||N||!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..."):N?a("work:task.workflowSavedSuccess","Saved!"):a("work:task.saveWorkflow","Save Workflow")})]})]})})}function ja({teamId:e,agents:n,compact:s}){const{t:r}=He(["work"]),i=g.useMemo(()=>e?n.find(a=>a.teamId===e&&a.agentRole==="manager"):n.find(a=>a.agentRole==="manager"),[n,e]),o=()=>{i&&Lt.navigate(Ye.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 ph({teamId:e,projectId:n,agents:s,projects:r,onViewRunTasks:i}){const{t:o}=He(["work"]),[a,l]=g.useState([]),[c,d]=g.useState({}),[h,f]=g.useState(!1),[m,u]=g.useState(null),[x,E]=g.useState({}),[S,v]=g.useState(!1),[y,p]=g.useState(null),[b,N]=g.useState([]),[w,M]=g.useState(null),[D,P]=g.useState(null),[_,C]=g.useState({}),[$,z]=g.useState(null),[j,B]=g.useState(null),[R,T]=g.useState(null),[A,L]=g.useState([]),[q,F]=g.useState({}),[Y,Q]=g.useState(null),[O,I]=g.useState({}),[H,V]=g.useState(new Set),W=e??w;g.useEffect(()=>{e||re.teams.list().then(({teams:Z})=>{N(Z.map(ae=>({id:ae.id,name:ae.name})))}).catch(()=>{})},[e]),g.useMemo(()=>{const Z={};for(const ae of s)Z[ae.id]=ae.name;return Z},[s]);const X=g.useCallback(async()=>{const Z=W?[W]:b.map(ae=>ae.id);if(Z.length!==0){f(!0);try{const ae=[],me={},ve={};await Promise.all(Z.map(async ce=>{try{const{workflows:te}=await re.workflows.list(ce);for(const pe of te)ve[pe.name]=ce;ae.push(...te),await Promise.all(te.map(async pe=>{try{const{runs:Re}=await re.workflows.listRuns(ce,pe.name,5);me[pe.name]=Re}catch{}}))}catch{}})),l(ae),d(me),I(ve)}catch{}f(!1)}},[W,b]);g.useEffect(()=>{X()},[X]);const ee=Z=>W??O[Z],se=async Z=>{if(D===Z.name){P(null);return}P(Z.name);const ae=ee(Z.name);if(!_[Z.name]&&ae)try{const{template:me}=await re.workflows.get(ae,Z.name);C(ve=>({...ve,[Z.name]:me}))}catch{}},J=Z=>{const ae={};for(const te of Z.params??[])te.default&&(ae[te.name]=te.default);E(ae),p(null),L([]),F({});const me=localStorage.getItem(`markus_wf_project_${Z.name}`)??localStorage.getItem("markus_wf_project_last"),ve=me&&r.some(te=>te.id===me)?me:null;Q(n??ve??r[0]?.id??null),u(Z);const ce=ee(Z.name);ce&&re.workflows.roles(ce,Z.name).then(({roles:te})=>L(te)).catch(()=>{})},U=async()=>{const Z=Y??r[0]?.id,ae=m?ee(m.name):void 0;if(!m||!ae||!Z){p(Z?o("work:task.workflowNoTeam","Cannot determine team for this workflow"):o("work:task.workflowNoProject","Please select a project"));return}v(!0),p(null);try{let me;if(A.length>0){me={};for(const ve of A)me[ve.role]=q[ve.role]??ve.recommended??""}await re.workflows.startRun(ae,m.name,Z,x,me),localStorage.setItem(`markus_wf_project_${m.name}`,Z),localStorage.setItem("markus_wf_project_last",Z),u(null),X()}catch(me){p(String(me))}v(!1)};if(!W&&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 oe=async Z=>{z(Z),B(null);try{await re.workflows.cancelRun(Z),X()}catch{}z(null)},le=async Z=>{T(Z.id);try{Z.status==="running"?await re.workflows.pauseRun(Z.id):Z.status==="paused"&&await re.workflows.resumeRun(Z.id),X()}catch{}T(null)},ie=Z=>{Z.requirementId&&i&&i(Z.requirementId)},he=Z=>{const ae={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 ${ae[Z]??"bg-gray-500/20 text-gray-400"}`,children:Z})},de=m&&(m.params??[]).some(Z=>Z.required&&!x[Z.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:()=>{w!==null&&(M(null),l([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${w===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(Z=>t.jsx("button",{onClick:()=>{w!==Z.id&&(M(Z.id),l([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${w===Z.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:Z.name},Z.id))]}),a.length===0&&!h?t.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:t.jsx(ja,{teamId:W,agents:s})}):t.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[a.map(Z=>{const ae=D===Z.name,me=_[Z.name],ce=(c[Z.name]??[]).some(te=>te.status==="running"||te.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:()=>se(Z),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 ${ae?"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:Z.displayName||Z.name}),t.jsx("span",{className:"text-[11px] text-fg-tertiary",children:o("work:task.workflowStepsCount","{{count}} steps",{count:Z.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:te=>{te.stopPropagation();const pe=ee(Z.name),be=(pe?s.find(Ie=>Ie.teamId===pe&&Ie.agentRole==="manager"):void 0)?.id??s.find(Ie=>Ie.agentRole==="manager")?.id??s[0]?.id;be&&Lt.navigate(Ye.TEAM,{agentId:be,prefillMessage:`@[${Z.displayName||Z.name}](workflow:${Z.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"})}),Z.name]}),Z.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",Z.version]}),ce?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:te=>{te.stopPropagation(),J(Z)},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")})]})]}),ae&&me&&t.jsxs("div",{className:"border-t border-border-default/30 pt-3 mt-1 ml-5 space-y-3",children:[Z.description&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:Z.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:me.steps.map((te,pe)=>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:pe+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:te.name}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary",children:te.role}),te.depends_on&&te.depends_on.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["← ",te.depends_on.join(", ")]})]}),t.jsx("p",{className:"text-[10px] text-fg-tertiary line-clamp-1 mt-0.5",children:te.prompt})]})]},te.id))})]}),me.steps.some(te=>te.depends_on&&te.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:me.steps.map((te,pe)=>{const Re=te.depends_on&&te.depends_on.length>0;return t.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[Re&&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:te.name})]},te.id)})})]}),me.params&&me.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:me.params.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:me.params.map(te=>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:te.label||te.name}),t.jsxs("span",{className:"text-fg-quaternary",children:["(",te.type||"string",")"]}),te.required&&t.jsx("span",{className:"text-red-400",children:"*"})]},te.name))})]}),me.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:[me.schedule.cron&&`cron: ${me.schedule.cron}`,me.schedule.interval&&`every: ${me.schedule.interval}`]})]})]}),(()=>{const te=c[Z.name]??[];if(te.length===0)return null;const pe=H.has(Z.name),Re=pe?te:te.slice(0,1);return t.jsxs("div",{className:"border-t border-border-default/30 pt-2 mt-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 cursor-pointer select-none",onClick:()=>V(be=>{const Ie=new Set(be);return Ie.has(Z.name)?Ie.delete(Z.name):Ie.add(Z.name),Ie}),children:[t.jsx("svg",{className:`w-3 h-3 text-fg-quaternary transition-transform ${pe?"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")}),te.length>1&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["(",te.length,")"]})]}),t.jsx("div",{className:"space-y-1",children:Re.map(be=>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:["#",be.runNumber]}),he(be.status),t.jsxs("span",{className:"text-fg-tertiary",children:[be.taskIds.length," tasks"]}),t.jsx("span",{className:"text-fg-tertiary",children:new Date(be.startedAt).toLocaleDateString()}),be.triggeredBy==="schedule"&&t.jsx("span",{className:"text-[10px] text-purple-400",children:"auto"}),t.jsx("span",{className:"flex-1"}),(be.status==="running"||be.status==="paused")&&t.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),le(be)},disabled:R===be.id,className:`px-2.5 py-0.5 text-[10px] rounded-lg font-medium transition-colors ${be.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:R===be.id?"...":be.status==="running"?o("work:task.workflowPause","Pause"):o("work:task.workflowResume","Resume")}),(be.status==="running"||be.status==="paused")&&t.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),B(be.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:()=>ie(be),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")})]},be.id))})]})})()]},Z.name)}),t.jsx(ja,{teamId:W,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:Z=>Z.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(Z=>t.jsxs("div",{children:[t.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[Z.label||Z.name,Z.required&&t.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),Z.type==="enum"&&Z.options?t.jsxs("select",{value:x[Z.name]??"",onChange:ae=>E(me=>({...me,[Z.name]:ae.target.value})),className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:"—"}),Z.options.map(ae=>t.jsx("option",{value:ae,children:ae},ae))]}):t.jsx("textarea",{value:x[Z.name]??"",onChange:ae=>{E(ce=>({...ce,[Z.name]:ae.target.value}));const me=ae.target;me.style.height="auto";const ve=parseFloat(getComputedStyle(me).lineHeight)||18;me.style.height=Math.min(me.scrollHeight,ve*7)+"px"},placeholder:Z.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},Z.name))}),A.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:A.map(Z=>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:Z.role}),t.jsx("select",{value:q[Z.role]??Z.recommended??"",onChange:ae=>F(me=>({...me,[Z.role]:ae.target.value})),className:"input-field text-xs flex-1",children:Z.candidates.map(ae=>t.jsxs("option",{value:ae.agentId,children:[ae.agentName,ae.agentId===Z.recommended?" ★":""]},ae.agentId))})]},Z.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:Y??"",onChange:Z=>{const ae=Z.target.value||null;Q(ae),p(null),ae&&localStorage.setItem("markus_wf_project_last",ae)},className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:o("work:task.workflowSelectProject","— Select a project —")}),r.map(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.id))]})]}),y&&t.jsx("p",{className:"text-xs text-red-400 mb-3",children:y}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>u(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowCancel","Cancel")}),t.jsx("button",{onClick:U,disabled:S||!!de,className:"btn-primary text-xs px-4 py-1.5",children:S?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:()=>B(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:Z=>Z.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:()=>B(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowNo","No")}),t.jsx("button",{onClick:()=>oe(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 jh({authUser:e,previewMode:n,previewData:s}={}){const{t:r}=He(["work","common"]),i=pl(Ye.WORK),o=g.useMemo(()=>$s.map(k=>({...k,label:r(`work:boardColumn.${k.id}`)})),[r]),a=g.useMemo(()=>Gi(r),[r]),l=g.useMemo(()=>Bs(r),[r]),c=rr(),d=g.useRef(null),[h,f]=g.useState(0);g.useEffect(()=>{const k=d.current;if(!k)return;const K=new ResizeObserver(([ne])=>f(ne.contentRect.width));return K.observe(k),f(k.clientWidth),()=>K.disconnect()},[]);const m=h||window.innerWidth,u=g.useRef(!1),x=xl({side:"right",defaultWidth:Math.round(m/2),minWidth:380,maxWidth:Math.round(m*.8),storageKey:"markus_projects_detail_v4"});g.useEffect(()=>{h>0&&!u.current&&(u.current=!0,x.setWidth(Math.round(h/2)))},[h]);const[E,S]=g.useState(!1),v=g.useRef(E);v.current=E;const[y,p]=g.useState(s?.projects??[]),[b,N]=g.useState("all"),[w,M]=g.useState(null),[D,P]=g.useState(s?.board??{}),[_,C]=g.useState(s?.agents??[]),[$,z]=g.useState([]),[j,B]=g.useState(s?.users??[]),[R,T]=g.useState(s?.allRequirements??[]),[A,L]=g.useState(!s),[q,F]=g.useState(""),[Y,Q]=g.useState(!1),[O,I]=g.useState(null),H=g.useCallback(()=>{Ne(w??""),Ke(!0)},[w]),[V,W]=g.useState(!1),[X,ee]=g.useState(!1),[se,J]=g.useState(""),[U,oe]=g.useState(""),[le,ie]=g.useState("medium"),[he,de]=g.useState(""),[Z,ae]=g.useState(""),[me,ve]=g.useState(""),[ce,te]=g.useState(""),[pe,Re]=g.useState([]),[be,Ie]=g.useState("standard"),[mt,nt]=g.useState("4h"),[yt,ot]=g.useState(""),[gt,Et]=g.useState(!1),[Ve,ze]=g.useState(null),[Pe,We]=g.useState(()=>s?.initialSelectedReqId&&s.allRequirements?s.allRequirements.find(k=>k.id===s.initialSelectedReqId)??null:null),[we,Xe]=g.useState(new Set),[_e,Te]=g.useState(!1),[Le,lt]=g.useState(new Set),Pt=g.useRef(new Set),Ee=g.useRef(new Set),[Fe,rt]=g.useState(null),[ct,Mt]=g.useState(s?.initialBoardType??"backlog"),[mn,en]=g.useState(null),gn=g.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"},{id:"workflows"}],[]),$t=cs(gn,ct,Mt),tn=g.useRef(null),Yt=g.useMemo(()=>({scrollContainerRef:tn}),[]),nn=cs(gn,ct,Mt,Yt),[Ue,Bt]=g.useState(!1),[It,Tt]=g.useState(null),[vt,pt]=g.useState(!1),Rt=g.useRef(null),_t=g.useRef(null),[Ot,Ke]=g.useState(!1),[dt,ut]=g.useState(""),[at,G]=g.useState(""),[ge,Se]=g.useState("medium"),[je,Ne]=g.useState(""),[Qe,ft]=g.useState(null),[rn,pn]=g.useState(""),[lr,At]=g.useState(""),[Bn,cr]=g.useState(!1),[dr,Gt]=g.useState(""),st=k=>{F(k),setTimeout(()=>F(""),3e3)};g.useEffect(()=>{const k=K=>{K.key==="Escape"&&(Qe?(ft(null),Gt("")):X?(ee(!1),ot("")):Ot?(Ke(!1),ut(""),G(""),At("")):vt&&pt(!1))};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[Qe,X,Ot,vt]);const tt=y.find(k=>k.id===w)??null,Fr=tt?.teamIds?.[0]??null,zt=tt??y.find(k=>k.id===O)??null,On=g.useCallback(()=>{Q(!1),I(null)},[]),xn=g.useCallback(k=>{if(Y&&(w===k||O===k)){On();return}w||I(k),Q(!0)},[Y,w,O,On]);g.useEffect(()=>{Ee.current=Le},[Le]);const xt=g.useCallback(async()=>{try{const{projects:k}=await re.projects.list();p(k)}catch{}},[]),Je=g.useCallback(async()=>{const k={};b==="project"&&w&&(k.projectId=w);try{const{board:K}=await re.tasks.board(k);P(K)}catch{}},[b,w]),sn=g.useCallback(async()=>{try{const{agents:k}=await re.agents.list();C(k)}catch{}},[]),zn=g.useCallback(async()=>{try{const{teams:k}=await re.teams.list();z(k.map(K=>({id:K.id,name:K.name})))}catch{}},[]),Os=g.useCallback(async()=>{try{const{users:k}=await re.users.list(e?.orgId);B(k)}catch{}},[e?.orgId]),wt=g.useCallback(async()=>{try{const{requirements:k}=await re.requirements.list({});T(k)}catch{}},[]),zs=g.useCallback(async()=>{await Promise.all([xt(),Je(),sn(),Os(),wt(),zn()]),L(!1)},[xt,Je,sn,Os,wt,zn]);g.useEffect(()=>{n||zs()},[n,zs]),g.useEffect(()=>{!n||!s||(p(s.projects??[]),P(s.board??{}),C(s.agents??[]),B(s.users??[]),T(s.allRequirements??[]))},[n,s]);const ur=g.useCallback(k=>{ze(K=>K?.id===k.id?(c&&v.current&&S(!1),null):(c&&(S(!0),history.pushState({mobileDetail:Ye.WORK},"",window.location.hash)),k)),We(null)},[c]),fr=g.useCallback(k=>{We(K=>K?.id===k.id?(c&&v.current&&S(!1),null):(c&&(S(!0),history.pushState({mobileDetail:Ye.WORK},"",window.location.hash)),k)),ze(null)},[c]),Yr=g.useCallback(()=>{ze(null),We(null),c&&v.current&&S(!1)},[c]),Ki=g.useCallback(()=>{ze(null),!an.current&&c&&v.current&&S(!1)},[c]);g.useEffect(()=>{if(!c)return;const k=()=>{v.current&&(S(!1),ze(null),We(null))};return window.addEventListener("popstate",k),()=>window.removeEventListener("popstate",k)},[c]);const on=g.useRef(Ve);on.current=Ve;const an=g.useRef(Pe);an.current=Pe,g.useEffect(()=>{const k=K=>{if(K.key!=="Escape")return;const ne=K.target?.tagName;if(!(ne==="INPUT"||ne==="TEXTAREA"||ne==="SELECT")){if(on.current){ze(null);return}if(an.current){We(null);return}}};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[]),g.useEffect(()=>{if(n||!i)return;Je(),sn(),wt();const k=on.current?12e4:45e3,K=setInterval(()=>{Je(),sn(),wt()},k);let ne=null;const ue=()=>{ne||(ne=setTimeout(()=>{ne=null,Je()},800))};let xe=null;const Ce=()=>{xe||(xe=setTimeout(()=>{xe=null,wt()},800))},ke=bt.on("task:update",qe=>{kt("/taskboard"),ue();const $e=qe?.payload;$e?.taskId&&(ze(et=>{if(!et||et.id!==$e.taskId)return et;const De={};return typeof $e.status=="string"&&(De.status=$e.status),Array.isArray($e.deliverables)&&(De.deliverables=$e.deliverables),Array.isArray($e.notes)&&(De.notes=$e.notes),$e.result!==void 0&&(De.result=$e.result),{...et,...De}}),on.current?.id===$e.taskId&&(kt("/tasks/"+$e.taskId),re.tasks.get($e.taskId).then(et=>{et.task&&ze(De=>De?.id===et.task.id?et.task:De)}).catch(()=>{})))}),fe=bt.on("task:create",()=>{ue()}),qt=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(qe=>bt.on(qe,$e=>{kt("/requirements"),Ce();const et=$e?.payload,De=et?.id??et?.requirementId;De&&an.current?.id===De&&(kt("/requirements/"+De),re.requirements.get(De).then(cn=>{cn.requirement&&We(br=>br?.id===cn.requirement.id?cn.requirement:br)}).catch(()=>{}))})),Vt=()=>{kt("/taskboard"),kt("/tasks"),kt("/requirements"),Je(),wt(),on.current&&re.tasks.get(on.current.id).then(qe=>{qe.task&&ze($e=>$e?.id===qe.task.id?qe.task:$e)}).catch(()=>{}),an.current&&re.requirements.get(an.current.id).then(qe=>{qe.requirement&&We($e=>$e?.id===qe.requirement.id?qe.requirement:$e)}).catch(()=>{})};return window.addEventListener("markus:data-changed",Vt),()=>{clearInterval(K),ke(),fe(),qt.forEach(qe=>qe()),window.removeEventListener("markus:data-changed",Vt),ne&&clearTimeout(ne),xe&&clearTimeout(xe)}},[n,i,Je,sn,wt]);const Hs=g.useRef(D);Hs.current=D;const qs=g.useRef(R);qs.current=R,g.useEffect(()=>{const k=on.current;if(!k)return;const ne=Object.values(D).flat().find(ue=>ue.id===k.id);ne&&ne.updatedAt!==k.updatedAt&&ze(ne)},[D]),g.useEffect(()=>{const k=an.current;if(!k)return;const K=R.find(ne=>ne.id===k.id);K&&K.updatedAt!==k.updatedAt&&We(K)},[R]);const Zt=g.useCallback(k=>{if(!k)return;const K=Ee.current;K.size>0&&!K.has(k)&&lt(ne=>new Set([...ne,k]))},[]),[Gr,Hn]=g.useState(!1),qn=g.useCallback((k,K)=>{ze(k),We(null),K?.scrollToComments&&Hn(!0),c&&S(!0)},[c]),bn=g.useCallback((k,K)=>{We(k),ze(null),K?.scrollToComments&&Hn(!0),c&&S(!0)},[c]),yn=g.useRef(null);g.useEffect(()=>{const k=yn.current||localStorage.getItem("markus_nav_openTask");if(!k)return;const ne=Object.values(D).flat().find(ue=>ue.id===k);ne?(yn.current=null,Zt(ne.projectId),qn(ne),localStorage.removeItem("markus_nav_openTask")):yn.current||(yn.current=k,localStorage.removeItem("markus_nav_openTask"),re.tasks.get(k).then(ue=>{ue.task&&(yn.current=null,Zt(ue.task.projectId),qn(ue.task))}).catch(()=>{yn.current=null}))},[D,qn,Zt]);const vn=g.useRef(null);g.useEffect(()=>{const k=vn.current||localStorage.getItem("markus_nav_openRequirement");if(!k)return;const K=R.find(ne=>ne.id===k);K?(vn.current=null,Zt(K.projectId),bn(K),localStorage.removeItem("markus_nav_openRequirement")):vn.current||(vn.current=k,localStorage.removeItem("markus_nav_openRequirement"),re.requirements.get(k).then(ne=>{ne.requirement&&(vn.current=null,Zt(ne.requirement.projectId),bn(ne.requirement))}).catch(()=>{vn.current=null}))},[R,bn,Zt]),g.useEffect(()=>{const k=window.location.hash.slice(1).split("/");if(vr(k[0])===Ye.WORK&&k[1])wn(k[1]);else{const K=localStorage.getItem("markus_nav_projectId");K&&(localStorage.removeItem("markus_nav_projectId"),wn(K))}},[]);const Vs=g.useRef(vr(window.location.hash.slice(1).split("/")[0]));g.useEffect(()=>{if(n)return;const k=()=>{const ne=window.location.hash.slice(1).split("/"),ue=vr(ne[0]),xe=Vs.current===Ye.WORK;Vs.current=ue,ue===Ye.WORK&&(ue===Ye.WORK&&ne[1]?wn(ne[1]):xe&&hr())},K=async ne=>{const ue=ne.detail;if(vr(ue.page)===Ye.WORK){if(ue.params?.openTask){const xe=ue.params.openTask,Ce=ue.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let ke=Object.values(Hs.current).flat().find(fe=>fe.id===xe);if(!ke)try{ke=(await re.tasks.get(xe)).task}catch{}ke&&(Zt(ke.projectId),qn(ke,{scrollToComments:Ce}))}if(ue.params?.openRequirement){const xe=ue.params.openRequirement,Ce=ue.params.scrollToComments==="true";let ke=qs.current.find(fe=>fe.id===xe);if(!ke)try{ke=(await re.requirements.get(xe)).requirement}catch{}ke&&(Zt(ke.projectId),bn(ke,{scrollToComments:Ce}))}if(ue.params?.projectId&&wn(ue.params.projectId),ue.params?.statusFilter){const xe=ue.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),nh.has(xe)&&Bt(!0),Tt(xe)}}};return window.addEventListener("markus:navigate",K),window.addEventListener("hashchange",k),()=>{window.removeEventListener("markus:navigate",K),window.removeEventListener("hashchange",k)}},[n]);const wn=k=>{Ee.current.size>0&&(Pt.current=new Set(Ee.current)),lt(new Set),M(k),N("project"),I(null),Q(!1),history.replaceState(null,"",no(Ye.WORK,k))},hr=()=>{lt(Pt.current),M(null),N("all"),I(null),Q(!1),history.replaceState(null,"",no(Ye.WORK))},Qi=()=>{W(!1),st(r("work:task.projectCreated")),xt()},Ws=async k=>{try{await re.projects.delete(k),w===k&&hr(),st(r("work:task.projectDeleted")),xt(),Je()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},Fs=async()=>{if(!se||!he||!Z||gt)return;ot("");const k=Z.startsWith("human:"),K=Z.replace(/^(human|agent):/,"");if(he===K&&!k){st(r("work:task.assignedReviewerDifferent"));return}const ne=me||void 0,ue=ce||void 0;Et(!0);try{const{task:xe}=await re.tasks.create(se,U,he,K,le,ne,pe.length>0?pe:void 0,ue,be!=="standard"?be:void 0,be==="scheduled"?{every:mt}:void 0,k?"human":"agent");J(""),oe(""),Re([]),te(""),Ie("standard"),nt("4h"),ee(!1),Je(),xe&&qn(xe)}catch(xe){const ke=`work:task.errorCode_${(xe instanceof yl?xe.code:void 0)||"unknown"}`,fe=r(ke,{defaultValue:""});ot(fe||r("work:task.errorCreatingTask",{message:xe instanceof Error?xe.message:String(xe)}))}finally{Et(!1)}},kn=k=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:k}))},Ys=()=>{kt("/taskboard"),Je(),Ve&&(kn({taskId:Ve.id}),kt("/tasks/"+Ve.id),re.tasks.get(Ve.id).then(k=>{k.task&&ze(K=>K?.id===k.task.id?k.task:K)}).catch(()=>{}))},ln=()=>{kt("/requirements"),wt(),Pe&&(kt("/requirements/"+Pe.id),re.requirements.get(Pe.id).then(k=>{k.requirement&&We(K=>K?.id===k.requirement.id?k.requirement:K)}).catch(()=>{}))},Gs=async()=>{if(!Bn){if(!dt.trim()){At(r("work:task.pleaseReqTitle"));return}if(!at.trim()){At(r("work:task.pleaseReqDesc"));return}if(!je){At(r("work:task.pleaseReqProject"));return}At(""),cr(!0);try{const{requirement:k}=await re.requirements.create({title:dt.trim(),description:at.trim(),priority:ge,projectId:je});st(r("work:task.requirementCreated")),ut(""),G(""),Ke(!1),wt(),k&&bn(k)}catch(k){At(k instanceof Error?k.message:String(k))}finally{cr(!1)}}},Zr=async k=>{try{await re.requirements.approve(k),st(r("work:task.requirementApproved")),kn({requirementId:k}),ln(),Je()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},Ji=async()=>{if(Qe){Gt("");try{await re.requirements.reject(Qe,rn),st(r("work:task.requirementRejected")),kn({requirementId:Qe}),ft(null),pn(""),Gt(""),ln()}catch(k){Gt(k instanceof Error?k.message:String(k))}}},Zs=async k=>{try{await re.requirements.cancel(k),st(r("work:task.requirementCancelled")),kn({requirementId:k}),ln()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},el=(k,K)=>{Rt.current=K,_t.current=null,k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/plain",`task:${K.id}`),k.currentTarget.style.opacity="0.4"},tl=(k,K)=>{_t.current=K,Rt.current=null,k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/plain",`req:${K.id}`),k.currentTarget.style.opacity="0.4"},Xs=k=>{k.currentTarget.style.opacity="1",Rt.current=null,_t.current=null,rt(null)},nl=(k,K)=>{k.preventDefault(),k.dataTransfer.dropEffect="move",Fe!==K&&rt(K)},rl=(k,K)=>{const ne=k.currentTarget.getBoundingClientRect(),{clientX:ue,clientY:xe}=k;(ue<ne.left||ue>ne.right||xe<ne.top||xe>ne.bottom)&&Fe===K&&rt(null)},sl=async(k,K)=>{k.preventDefault(),rt(null);const ne=Rt.current,ue=_t.current;if(ne){const xe=o.find(ke=>ke.id===K);if(!xe)return;const Ce=xe.dropStatus;if(ne.status===Ce||ne.status==="pending")return;try{await re.tasks.updateStatus(ne.id,Ce),Je()}catch{}}else if(ue){const xe=Xi[K];if(!xe||ue.status===xe)return;try{await re.requirements.updateStatus(ue.id,xe),wt()}catch{}}},Us=k=>{Xe(K=>{const ne=new Set(K);return ne.has(k)?ne.delete(k):ne.add(k),ne})},jn=k=>{b==="project"?w===k?hr():wn(k):lt(K=>{const ne=new Set(K);return ne.has(k)?ne.delete(k):ne.add(k),ne})},ol=new Set(["rejected","cancelled","archived"]),mr=k=>ol.has(k.status),Xr=(k,K=!1)=>{let ne=k.filter(ue=>Ue||!mr(ue));return It&&(ne=ne.filter(ue=>ue.status===It)),b==="project"&&w&&(ne=ne.filter(ue=>ue.projectId===w)),Le.size>0&&(ne=ne.filter(ue=>ue.projectId&&Le.has(ue.projectId))),we.size>0&&(ne=ne.filter(ue=>ue.assignedAgentId&&we.has(ue.assignedAgentId))),_e&&e?.id&&(ne=ne.filter(ue=>ue.createdBy===e.id)),ne},al=g.useMemo(()=>{const k=new Map;for(const K of Object.values(D))for(const ne of K)k.set(ne.id,ne);return k},[D]),il=g.useMemo(()=>new Set(_.map(k=>k.id)),[_]),Ks=k=>k.statuses.flatMap(K=>Xr(D[K]??[])),Nn=g.useMemo(()=>{let k=R;return Ue||(k=k.filter(K=>!mr(K))),b==="project"&&w&&(k=k.filter(K=>K.projectId===w)),Le.size>0&&(k=k.filter(K=>K.projectId&&Le.has(K.projectId))),we.size>0&&(k=k.filter(K=>we.has(K.createdBy))),_e&&e?.id&&(k=k.filter(K=>K.createdBy===e.id)),k},[R,Ue,b,w,Le,we,_e,e?.id,il]),Qs=g.useCallback(k=>Nn.filter(K=>Zi[K.status]===k.id),[Nn]),ll=o.filter(k=>{if(k.id==="failed"||k.id==="closed"){const K=Ks(k),ne=Qs(k);return K.length+ne.length>0}return!0}),Vn=Object.values(D).flat().filter(k=>mr(k)).length+R.filter(k=>mr(k)).length,Js=g.useMemo(()=>{const k=new Set(["completed","failed","cancelled","archived"]),K=Object.values(D).flat(),ne=new Set;for(const ue of K)ue.assignedAgentId&&!k.has(ue.status)&&(!w||ue.projectId===w)&&ne.add(ue.assignedAgentId);return[..._].sort((ue,xe)=>{const Ce=ne.has(ue.id)?0:1,ke=ne.has(xe.id)?0:1;return Ce-ke})},[_,D,w]),gr=g.useMemo(()=>{const k=new Map,K=[];for(const ue of Js)if(ue.teamId){const xe=k.get(ue.teamId)??[];xe.push(ue.id),k.set(ue.teamId,xe)}else K.push(ue);const ne=[];for(const ue of K)ne.push({kind:"agent",agent:ue});for(const ue of $){const xe=k.get(ue.id);xe&&xe.length>0&&ne.push({kind:"team",id:ue.id,name:ue.name,agentIds:xe})}return ne},[Js,$]),eo=g.useMemo(()=>{const k=new Set(["completed","failed","cancelled","archived"]),K=Object.values(D).flat(),ne=new Set;for(const xe of K)xe.projectId&&!k.has(xe.status)&&ne.add(xe.projectId);return[...Ue?y:y.filter(xe=>xe.status!=="archived")].sort((xe,Ce)=>{const ke=xe.status==="archived"?1:0,fe=Ce.status==="archived"?1:0;if(ke!==fe)return ke-fe;const Ht=ne.has(xe.id)?0:1,qt=ne.has(Ce.id)?0:1;return Ht!==qt?Ht-qt:xe.name.localeCompare(Ce.name)})},[y,D,Ue]),Ur=g.useMemo(()=>{const k={};for(const K of Object.values(D))for(const ne of K){const ue=ne.projectId??"__none__";k[ue]=(k[ue]??0)+1}return k},[D]),pr=Object.values(Ur).reduce((k,K)=>k+K,0);if(A)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:r("work:task.loadingPage")});const Wn=!!(Ve||Pe),xr=!c&&!!(Ve&&Pe);return t.jsxs("div",{ref:d,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[t.jsxs("div",{className:`${c?"flex-1 min-w-0":Wn?"shrink-0 min-w-0":"flex-1"} overflow-hidden flex flex-col bg-surface-primary`,style:c?E?{display:"none"}:void 0:xr?{width:0}:Wn?{width:`calc(100% - ${x.width}px - 4px)`}:void 0,children:[q&&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:q}),c?t.jsxs("div",{className:"shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[t.jsx(bl,{}),tt?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:tt.name}),t.jsx("button",{onClick:()=>xn(tt.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${Y?"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:y.length===1?y[0].name:r("work:task.projectsCount",{count:y.length})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>W(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortProject")}),t.jsx("button",{onClick:H,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortReq")}),t.jsx("button",{onClick:()=>{ve(w??""),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(k=>t.jsx("button",{onClick:()=>Mt(k),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${ct===k?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:r(k==="backlog"?"work:task.backlog":k==="kanban"?"work:task.kanban":"work:task.dag")},k))}),Vn>0&&t.jsx("button",{onClick:()=>Bt(k=>!k),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ue?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Ue?r("work:task.hideArchived"):r("work:task.archivedCount",{count:Vn})}),t.jsx("div",{className:"flex-1"}),It&&t.jsxs("button",{onClick:()=>Tt(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.${It==="in_progress"?"inProgress":It}`),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"})]})]}),(Le.size>0||we.size>0||_e||y.length>1||_.length>0)&&t.jsxs("button",{onClick:()=>pt(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${Le.size>0||we.size>0||_e?"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"})}),Le.size+we.size+(_e?1:0)>0?r("work:task.filterWithCount",{count:Le.size+we.size+(_e?1:0)}):r("work:task.filter")]})]})]}):t.jsxs("div",{className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[tt?t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(oa,{value:tt.name,onSave:async k=>{await re.projects.update(tt.id,{name:k}),xt()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:()=>xn(tt.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${Y?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:r("work:project.settingsTitle"),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:y.length===1?y[0].name:r("work:task.projectsCount",{count:y.length})}),Vn>0&&t.jsx("button",{onClick:()=>Bt(k=>!k),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ue?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Ue?r("work:task.hideArchivedWithCount",{count:Vn}):r("work:task.archivedCount",{count:Vn})}),t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(k=>t.jsx("button",{onClick:()=>Mt(k),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${ct===k?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:k==="backlog"?r("work:task.backlog"):k==="kanban"?r("work:task.kanban"):k==="dag"?r("work:task.dag"):r("work:task.workflows","Workflows")},k))}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:()=>W(!0),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.shortProject")}),t.jsx("button",{onClick:H,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:()=>{ve(w??""),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"})]}),!c&&ct!=="workflows"&&y.length>1&&!w&&!Y&&(pr>0||R.length>0)&&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",{onClick:()=>lt(new Set),className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${Le.size>0?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),eo.map(k=>{const K=Le.has(k.id),ne=Ur[k.id]??0,ue=Y&&O===k.id;return t.jsxs("div",{className:`flex items-center shrink-0 rounded-md overflow-hidden transition-all ${K?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[t.jsxs("button",{onClick:()=>jn(k.id),className:`flex items-center gap-1.5 px-2.5 py-1 text-[11px] shrink-0 transition-all ${K?"text-brand-600":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${K?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:k.name[0]?.toUpperCase()}),k.name,ne>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:ne})]}),K&&t.jsx("button",{onClick:()=>xn(k.id),className:`px-1.5 py-1 self-stretch flex items-center border-l border-brand-500/20 transition-colors ${ue?"text-fg-primary bg-surface-overlay":"text-fg-tertiary hover:text-brand-600 hover:bg-brand-500/10"}`,title:r("work:project.editProject"),children:t.jsxs("svg",{width:"11",height:"11",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"})]})})]},k.id)})]}),!c&&ct!=="workflows"&&(gr.length>0||e?.id)&&!Y&&(pr>0||R.length>0)&&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:()=>{Xe(new Set),Te(!1)},className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${we.size>0||_e?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),e?.id&&t.jsx("button",{type:"button",onClick:()=>Te(k=>!k),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${_e?"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")}),gr.map(k=>{if(k.kind==="team"){const ue=k.agentIds.every(Ce=>we.has(Ce)),xe=!ue&&k.agentIds.some(Ce=>we.has(Ce));return t.jsxs("button",{onClick:()=>{Xe(Ce=>{const ke=new Set(Ce);if(ue)for(const fe of k.agentIds)ke.delete(fe);else for(const fe of k.agentIds)ke.add(fe);return ke})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ue?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":xe?"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"})}),k.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:k.agentIds.length})]},`team-${k.id}`)}const K=k.agent,ne=we.has(K.id);return t.jsxs("button",{onClick:()=>Us(K.id),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":"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 ${ne?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:K.name[0]?.toUpperCase()}),K.name]},K.id)})]}),Y&&zt?t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!tt&&t.jsxs("div",{className:"px-6 py-2 flex items-center gap-2 border-b border-border-default/60 shrink-0",children:[t.jsxs("button",{onClick:On,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1 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("polyline",{points:"15 18 9 12 15 6"})}),r("common:back")]}),t.jsx(oa,{value:zt.name,onSave:async k=>{await re.projects.update(zt.id,{name:k}),xt()},className:"text-sm font-semibold text-fg-primary truncate min-w-0"})]}),t.jsx(ba,{project:zt,tasks:Object.values(D).flat(),requirements:R,agents:_,onDeleteProject:()=>Ws(zt.id),onUpdateProject:async k=>{await re.projects.update(zt.id,k)},onRefresh:()=>{xt()}})]}):pr===0&&Nn.length===0&&b==="project"&&tt?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-y-auto",children:[t.jsx("div",{className:"px-6 py-2 flex items-center gap-2 border-b border-border-default/60 shrink-0 sticky top-0 bg-surface-primary z-10",children:t.jsxs("button",{onClick:hr,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1 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("polyline",{points:"15 18 9 12 15 6"})}),r("common:back")]})}),t.jsx(ba,{project:tt,tasks:[],requirements:[],agents:_,onDeleteProject:()=>Ws(tt.id),onUpdateProject:async k=>{await re.projects.update(tt.id,k)},onRefresh:()=>{xt()}})]}):pr===0&&Nn.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:y.length===0?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:()=>W(!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")})]}):t.jsxs("div",{className:"w-full max-w-2xl mx-auto space-y-4",children:[t.jsx("p",{className:"text-xs text-fg-tertiary text-center",children:r("work:task.emptyNoReqsHint")}),t.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:y.map(k=>t.jsxs("button",{onClick:()=>wn(k.id),className:"group flex items-start gap-3 p-4 rounded-xl border border-border-default bg-surface-elevated hover:border-brand-500/50 hover:bg-brand-500/5 transition-all text-left",children:[t.jsx("div",{className:"w-9 h-9 shrink-0 rounded-lg bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"18",height:"18",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.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary group-hover:text-brand-500 truncate transition-colors",children:k.name}),k.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 line-clamp-2",children:k.description}),t.jsx("div",{className:"text-[10px] text-fg-quaternary mt-1.5",children:new Date(k.createdAt).toLocaleDateString()})]}),t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-quaternary group-hover:text-brand-500 shrink-0 mt-1 transition-colors",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})]},k.id))}),t.jsx("div",{className:"text-center pt-2",children:t.jsx("button",{onClick:H,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")})})]})}):ct==="backlog"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:c?$t.onTouchStart:void 0,onTouchEnd:c?$t.onTouchEnd:void 0,children:t.jsx(fh,{tasks:Xr(Object.values(D).flat()),requirements:Nn,agents:_,projects:y,onTaskClick:k=>ur(k),onReqClick:k=>fr(k),onRefresh:()=>{Je(),wt()},selectedTaskId:Ve?.id,selectedReqId:Pe?.id})}):ct==="workflows"?t.jsx(ph,{teamId:Fr,projectId:w,agents:_,projects:y,onViewRunTasks:k=>{const K=ue=>{bn(ue),en(`req-${ue.id}`),Mt("dag")},ne=R.find(ue=>ue.id===k);ne?K(ne):re.requirements.get(k).then(ue=>{ue.requirement&&(T(xe=>[...xe,ue.requirement]),K(ue.requirement))}).catch(()=>{})}}):ct==="dag"?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:c?$t.onTouchStart:void 0,onTouchEnd:c?$t.onTouchEnd:void 0,children:[t.jsx(Zf,{tasks:(()=>{const k=Xr(Object.values(D).flat(),!0);if(n&&Pe){const K=new Set(Pe.taskIds??[]);return k.filter(ne=>K.has(ne.id))}return k})(),requirements:n&&Pe?[Pe]:Nn,agents:_,showArchived:Ue,onShowArchivedChange:Bt,onTaskClick:k=>ur(k),onReqClick:k=>fr(k),onCollapseDAG:()=>{ze(null),We(null),en(null)},onDependencyChange:Je,selectedTaskId:Ve?.id,selectedReqId:Pe?.id,hasDetailPanel:Wn,defaultExpandedNodeId:mn??(n&&Pe?`req-${Pe.id}`:void 0),previewMode:n}),c&&t.jsx("button",{onClick:()=>Mt("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:tn,className:"flex-1 min-h-0 overflow-auto px-4 py-5",onTouchStart:c?nn.onTouchStart:void 0,onTouchEnd:c?nn.onTouchEnd:void 0,children:t.jsx("div",{className:"flex gap-3 items-stretch",children:ll.map(k=>{const K=Ks(k),ne=Qs(k),ue=K.length+ne.length,xe=Fe===k.id;return t.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col transition-colors ${xe?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:Ce=>nl(Ce,k.id),onDragLeave:Ce=>rl(Ce,k.id),onDrop:Ce=>{sl(Ce,k.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 ${xe?"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 ${k.accent.replace("border-t-","bg-")}`}),t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:k.label})]}),t.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:ue})]}),t.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const Ce=[...ne.map(ke=>({kind:"req",data:ke,time:new Date(ke.updatedAt??ke.createdAt).getTime()})),...K.map(ke=>({kind:"task",data:ke,time:new Date(ke.updatedAt??ke.createdAt??0).getTime()}))];return Ce.sort((ke,fe)=>fe.time-ke.time),Ce.map(ke=>{if(ke.kind==="req"){const fe=ke.data,Ht=l[fe.status]??{label:fe.status,cls:"bg-gray-500/15 text-fg-secondary"},Vt=fe.source==="agent"&&fe.status==="pending",qe=b==="all"&&fe.projectId?y.find(De=>De.id===fe.projectId):null,$e=$n(fe.createdBy,_,j)??fe.createdBy.slice(0,10),et=Pe?.id===fe.id;return t.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:De=>tl(De,fe),onDragEnd:Xs,onClick:()=>fr(fe),onKeyDown:De=>De.key==="Enter"&&fr(fe),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
9
+ `)}function gh({req:e,tasks:n,agents:s,teamId:r,onClose:i,onSaved:o}){const{t:a}=He(["work"]),l=g.useMemo(()=>{const P={};for(const _ of s)P[_.id]=_.name;return P},[s]),c=g.useMemo(()=>hh(n,l),[n,l]),[d,h]=g.useState(()=>vs(e.title)),[f,m]=g.useState(e.description||e.title),[u,x]=g.useState(c),[E,S]=g.useState(!1),[v,y]=g.useState(null),p=(P,_,C)=>{x($=>$.map((z,j)=>j===P?{...z,[_]:C}:z))},b=P=>{const _=u[P]?.id;x(C=>C.filter(($,z)=>z!==P).map($=>({...$,depends_on:$.depends_on.filter(z=>z!==_)})))},[N,w]=g.useState(!1),M=async()=>{if(d.trim()){S(!0),y(null);try{const P=mh(d.trim(),f,u);await re.workflows.create(r,d.trim(),P),w(!0),setTimeout(()=>o(),800)}catch(P){y(String(P))}S(!1)}},D=g.useMemo(()=>[...new Set(u.map(P=>P.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:P=>P.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:P=>h(P.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(P=>t.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:P},P))})]})]}),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:P=>m(P.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((P,_)=>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:_+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:P.name,onChange:C=>p(_,"name",C.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:P.role,onChange:C=>p(_,"role",C.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")})]}),P.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"),":"]}),P.depends_on.map(C=>{const $=u.find(z=>z.id===C);return t.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:$?.name??C},C)})]}),t.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:P.prompt})]}),t.jsx("button",{onClick:()=>b(_),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"})})})]})},P.id))})]}),v&&t.jsx("p",{className:"text-xs text-red-500",children:v}),N&&t.jsx("p",{className:"text-xs text-green-500 font-medium",children:a("work:task.workflowSavedSuccess","Workflow saved successfully")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default",children:[t.jsx("button",{onClick:i,className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated rounded-lg transition-colors",children:a("work:task.cancel","Cancel")}),t.jsx("button",{onClick:M,disabled:E||N||!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..."):N?a("work:task.workflowSavedSuccess","Saved!"):a("work:task.saveWorkflow","Save Workflow")})]})]})})}function ja({teamId:e,agents:n,compact:s}){const{t:r}=He(["work"]),i=g.useMemo(()=>e?n.find(a=>a.teamId===e&&a.agentRole==="manager"):n.find(a=>a.agentRole==="manager"),[n,e]),o=()=>{i&&Lt.navigate(Ye.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 ph({teamId:e,projectId:n,agents:s,projects:r,onViewRunTasks:i}){const{t:o}=He(["work"]),[a,l]=g.useState([]),[c,d]=g.useState({}),[h,f]=g.useState(!1),[m,u]=g.useState(null),[x,E]=g.useState({}),[S,v]=g.useState(!1),[y,p]=g.useState(null),[b,N]=g.useState([]),[w,M]=g.useState(null),[D,P]=g.useState(null),[_,C]=g.useState({}),[$,z]=g.useState(null),[j,B]=g.useState(null),[R,T]=g.useState(null),[A,L]=g.useState([]),[q,F]=g.useState({}),[Y,Q]=g.useState(null),[O,I]=g.useState({}),[H,V]=g.useState(new Set),W=e??w;g.useEffect(()=>{e||re.teams.list().then(({teams:Z})=>{N(Z.map(ae=>({id:ae.id,name:ae.name})))}).catch(()=>{})},[e]),g.useMemo(()=>{const Z={};for(const ae of s)Z[ae.id]=ae.name;return Z},[s]);const X=g.useCallback(async()=>{const Z=W?[W]:b.map(ae=>ae.id);if(Z.length!==0){f(!0);try{const ae=[],me={},ve={};await Promise.all(Z.map(async ce=>{try{const{workflows:te}=await re.workflows.list(ce);for(const pe of te)ve[pe.name]=ce;ae.push(...te),await Promise.all(te.map(async pe=>{try{const{runs:Te}=await re.workflows.listRuns(ce,pe.name,5);me[pe.name]=Te}catch{}}))}catch{}})),l(ae),d(me),I(ve)}catch{}f(!1)}},[W,b]);g.useEffect(()=>{X()},[X]);const ee=Z=>W??O[Z],se=async Z=>{if(D===Z.name){P(null);return}P(Z.name);const ae=ee(Z.name);if(!_[Z.name]&&ae)try{const{template:me}=await re.workflows.get(ae,Z.name);C(ve=>({...ve,[Z.name]:me}))}catch{}},J=Z=>{const ae={};for(const te of Z.params??[])te.default&&(ae[te.name]=te.default);E(ae),p(null),L([]),F({});const me=localStorage.getItem(`markus_wf_project_${Z.name}`)??localStorage.getItem("markus_wf_project_last"),ve=me&&r.some(te=>te.id===me)?me:null;Q(n??ve??r[0]?.id??null),u(Z);const ce=ee(Z.name);ce&&re.workflows.roles(ce,Z.name).then(({roles:te})=>L(te)).catch(()=>{})},U=async()=>{const Z=Y??r[0]?.id,ae=m?ee(m.name):void 0;if(!m||!ae||!Z){p(Z?o("work:task.workflowNoTeam","Cannot determine team for this workflow"):o("work:task.workflowNoProject","Please select a project"));return}v(!0),p(null);try{let me;if(A.length>0){me={};for(const ve of A)me[ve.role]=q[ve.role]??ve.recommended??""}await re.workflows.startRun(ae,m.name,Z,x,me),localStorage.setItem(`markus_wf_project_${m.name}`,Z),localStorage.setItem("markus_wf_project_last",Z),u(null),X()}catch(me){p(String(me))}v(!1)};if(!W&&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 oe=async Z=>{z(Z),B(null);try{await re.workflows.cancelRun(Z),X()}catch{}z(null)},le=async Z=>{T(Z.id);try{Z.status==="running"?await re.workflows.pauseRun(Z.id):Z.status==="paused"&&await re.workflows.resumeRun(Z.id),X()}catch{}T(null)},ie=Z=>{Z.requirementId&&i&&i(Z.requirementId)},he=Z=>{const ae={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 ${ae[Z]??"bg-gray-500/20 text-gray-400"}`,children:Z})},de=m&&(m.params??[]).some(Z=>Z.required&&!x[Z.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:()=>{w!==null&&(M(null),l([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${w===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(Z=>t.jsx("button",{onClick:()=>{w!==Z.id&&(M(Z.id),l([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${w===Z.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:Z.name},Z.id))]}),a.length===0&&!h?t.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:t.jsx(ja,{teamId:W,agents:s})}):t.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[a.map(Z=>{const ae=D===Z.name,me=_[Z.name],ce=(c[Z.name]??[]).some(te=>te.status==="running"||te.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:()=>se(Z),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 ${ae?"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:Z.displayName||Z.name}),t.jsx("span",{className:"text-[11px] text-fg-tertiary",children:o("work:task.workflowStepsCount","{{count}} steps",{count:Z.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:te=>{te.stopPropagation();const pe=ee(Z.name),be=(pe?s.find(Ie=>Ie.teamId===pe&&Ie.agentRole==="manager"):void 0)?.id??s.find(Ie=>Ie.agentRole==="manager")?.id??s[0]?.id;be&&Lt.navigate(Ye.TEAM,{agentId:be,prefillMessage:`@[${Z.displayName||Z.name}](workflow:${Z.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"})}),Z.name]}),Z.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",Z.version]}),ce?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:te=>{te.stopPropagation(),J(Z)},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")})]})]}),ae&&me&&t.jsxs("div",{className:"border-t border-border-default/30 pt-3 mt-1 ml-5 space-y-3",children:[Z.description&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:Z.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:me.steps.map((te,pe)=>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:pe+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:te.name}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary",children:te.role}),te.depends_on&&te.depends_on.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["← ",te.depends_on.join(", ")]})]}),t.jsx("p",{className:"text-[10px] text-fg-tertiary line-clamp-1 mt-0.5",children:te.prompt})]})]},te.id))})]}),me.steps.some(te=>te.depends_on&&te.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:me.steps.map((te,pe)=>{const Te=te.depends_on&&te.depends_on.length>0;return t.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[Te&&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:te.name})]},te.id)})})]}),me.params&&me.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:me.params.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:me.params.map(te=>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:te.label||te.name}),t.jsxs("span",{className:"text-fg-quaternary",children:["(",te.type||"string",")"]}),te.required&&t.jsx("span",{className:"text-red-400",children:"*"})]},te.name))})]}),me.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:[me.schedule.cron&&`cron: ${me.schedule.cron}`,me.schedule.interval&&`every: ${me.schedule.interval}`]})]})]}),(()=>{const te=c[Z.name]??[];if(te.length===0)return null;const pe=H.has(Z.name),Te=pe?te:te.slice(0,1);return t.jsxs("div",{className:"border-t border-border-default/30 pt-2 mt-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 cursor-pointer select-none",onClick:()=>V(be=>{const Ie=new Set(be);return Ie.has(Z.name)?Ie.delete(Z.name):Ie.add(Z.name),Ie}),children:[t.jsx("svg",{className:`w-3 h-3 text-fg-quaternary transition-transform ${pe?"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")}),te.length>1&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["(",te.length,")"]})]}),t.jsx("div",{className:"space-y-1",children:Te.map(be=>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:["#",be.runNumber]}),he(be.status),t.jsxs("span",{className:"text-fg-tertiary",children:[be.taskIds.length," tasks"]}),t.jsx("span",{className:"text-fg-tertiary",children:new Date(be.startedAt).toLocaleDateString()}),be.triggeredBy==="schedule"&&t.jsx("span",{className:"text-[10px] text-purple-400",children:"auto"}),t.jsx("span",{className:"flex-1"}),(be.status==="running"||be.status==="paused")&&t.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),le(be)},disabled:R===be.id,className:`px-2.5 py-0.5 text-[10px] rounded-lg font-medium transition-colors ${be.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:R===be.id?"...":be.status==="running"?o("work:task.workflowPause","Pause"):o("work:task.workflowResume","Resume")}),(be.status==="running"||be.status==="paused")&&t.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),B(be.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:()=>ie(be),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")})]},be.id))})]})})()]},Z.name)}),t.jsx(ja,{teamId:W,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:Z=>Z.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(Z=>t.jsxs("div",{children:[t.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[Z.label||Z.name,Z.required&&t.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),Z.type==="enum"&&Z.options?t.jsxs("select",{value:x[Z.name]??"",onChange:ae=>E(me=>({...me,[Z.name]:ae.target.value})),className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:"—"}),Z.options.map(ae=>t.jsx("option",{value:ae,children:ae},ae))]}):t.jsx("textarea",{value:x[Z.name]??"",onChange:ae=>{E(ce=>({...ce,[Z.name]:ae.target.value}));const me=ae.target;me.style.height="auto";const ve=parseFloat(getComputedStyle(me).lineHeight)||18;me.style.height=Math.min(me.scrollHeight,ve*7)+"px"},placeholder:Z.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},Z.name))}),A.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:A.map(Z=>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:Z.role}),t.jsx("select",{value:q[Z.role]??Z.recommended??"",onChange:ae=>F(me=>({...me,[Z.role]:ae.target.value})),className:"input-field text-xs flex-1",children:Z.candidates.map(ae=>t.jsxs("option",{value:ae.agentId,children:[ae.agentName,ae.agentId===Z.recommended?" ★":""]},ae.agentId))})]},Z.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:Y??"",onChange:Z=>{const ae=Z.target.value||null;Q(ae),p(null),ae&&localStorage.setItem("markus_wf_project_last",ae)},className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:o("work:task.workflowSelectProject","— Select a project —")}),r.map(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.id))]})]}),y&&t.jsx("p",{className:"text-xs text-red-400 mb-3",children:y}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>u(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowCancel","Cancel")}),t.jsx("button",{onClick:U,disabled:S||!!de,className:"btn-primary text-xs px-4 py-1.5",children:S?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:()=>B(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:Z=>Z.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:()=>B(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowNo","No")}),t.jsx("button",{onClick:()=>oe(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 jh({authUser:e,previewMode:n,previewData:s}={}){const{t:r}=He(["work","common"]),i=pl(Ye.WORK),o=g.useMemo(()=>$s.map(k=>({...k,label:r(`work:boardColumn.${k.id}`)})),[r]),a=g.useMemo(()=>Gi(r),[r]),l=g.useMemo(()=>Bs(r),[r]),c=rr(),d=g.useRef(null),[h,f]=g.useState(0);g.useEffect(()=>{const k=d.current;if(!k)return;const K=new ResizeObserver(([ne])=>f(ne.contentRect.width));return K.observe(k),f(k.clientWidth),()=>K.disconnect()},[]);const m=h||window.innerWidth,u=g.useRef(!1),x=xl({side:"right",defaultWidth:Math.round(m/2),minWidth:380,maxWidth:Math.round(m*.8),storageKey:"markus_projects_detail_v4"});g.useEffect(()=>{h>0&&!u.current&&(u.current=!0,x.setWidth(Math.round(h/2)))},[h]);const[E,S]=g.useState(!1),v=g.useRef(E);v.current=E;const[y,p]=g.useState(s?.projects??[]),[b,N]=g.useState("all"),[w,M]=g.useState(null),[D,P]=g.useState(s?.board??{}),[_,C]=g.useState(s?.agents??[]),[$,z]=g.useState([]),[j,B]=g.useState(s?.users??[]),[R,T]=g.useState(s?.allRequirements??[]),[A,L]=g.useState(!s),[q,F]=g.useState(""),[Y,Q]=g.useState(!1),[O,I]=g.useState(null),H=g.useCallback(()=>{Ne(w??""),Ke(!0)},[w]),[V,W]=g.useState(!1),[X,ee]=g.useState(!1),[se,J]=g.useState(""),[U,oe]=g.useState(""),[le,ie]=g.useState("medium"),[he,de]=g.useState(""),[Z,ae]=g.useState(""),[me,ve]=g.useState(""),[ce,te]=g.useState(""),[pe,Te]=g.useState([]),[be,Ie]=g.useState("standard"),[mt,nt]=g.useState("4h"),[yt,ot]=g.useState(""),[gt,Et]=g.useState(!1),[Ve,ze]=g.useState(null),[Pe,We]=g.useState(()=>s?.initialSelectedReqId&&s.allRequirements?s.allRequirements.find(k=>k.id===s.initialSelectedReqId)??null:null),[we,Xe]=g.useState(new Set),[_e,Re]=g.useState(!1),[Le,lt]=g.useState(new Set),Pt=g.useRef(new Set),Ee=g.useRef(new Set),[Fe,rt]=g.useState(null),[ct,Mt]=g.useState(s?.initialBoardType??"backlog"),[mn,en]=g.useState(null),gn=g.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"},{id:"workflows"}],[]),$t=cs(gn,ct,Mt),tn=g.useRef(null),Yt=g.useMemo(()=>({scrollContainerRef:tn}),[]),nn=cs(gn,ct,Mt,Yt),[Ue,Bt]=g.useState(!1),[It,Tt]=g.useState(null),[vt,pt]=g.useState(!1),Rt=g.useRef(null),_t=g.useRef(null),[Ot,Ke]=g.useState(!1),[dt,ut]=g.useState(""),[at,G]=g.useState(""),[ge,Se]=g.useState("medium"),[je,Ne]=g.useState(""),[Qe,ft]=g.useState(null),[rn,pn]=g.useState(""),[lr,At]=g.useState(""),[Bn,cr]=g.useState(!1),[dr,Gt]=g.useState(""),st=k=>{F(k),setTimeout(()=>F(""),3e3)};g.useEffect(()=>{const k=K=>{K.key==="Escape"&&(Qe?(ft(null),Gt("")):X?(ee(!1),ot("")):Ot?(Ke(!1),ut(""),G(""),At("")):vt&&pt(!1))};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[Qe,X,Ot,vt]);const tt=y.find(k=>k.id===w)??null,Fr=tt?.teamIds?.[0]??null,zt=tt??y.find(k=>k.id===O)??null,On=g.useCallback(()=>{Q(!1),I(null)},[]),xn=g.useCallback(k=>{if(Y&&(w===k||O===k)){On();return}w||I(k),Q(!0)},[Y,w,O,On]);g.useEffect(()=>{Ee.current=Le},[Le]);const xt=g.useCallback(async()=>{try{const{projects:k}=await re.projects.list();p(k)}catch{}},[]),Je=g.useCallback(async()=>{const k={};b==="project"&&w&&(k.projectId=w);try{const{board:K}=await re.tasks.board(k);P(K)}catch{}},[b,w]),sn=g.useCallback(async()=>{try{const{agents:k}=await re.agents.list();C(k)}catch{}},[]),zn=g.useCallback(async()=>{try{const{teams:k}=await re.teams.list();z(k.map(K=>({id:K.id,name:K.name})))}catch{}},[]),Os=g.useCallback(async()=>{try{const{users:k}=await re.users.list(e?.orgId);B(k)}catch{}},[e?.orgId]),wt=g.useCallback(async()=>{try{const{requirements:k}=await re.requirements.list({});T(k)}catch{}},[]),zs=g.useCallback(async()=>{await Promise.all([xt(),Je(),sn(),Os(),wt(),zn()]),L(!1)},[xt,Je,sn,Os,wt,zn]);g.useEffect(()=>{n||zs()},[n,zs]),g.useEffect(()=>{!n||!s||(p(s.projects??[]),P(s.board??{}),C(s.agents??[]),B(s.users??[]),T(s.allRequirements??[]))},[n,s]);const ur=g.useCallback(k=>{ze(K=>K?.id===k.id?(c&&v.current&&S(!1),null):(c&&(S(!0),history.pushState({mobileDetail:Ye.WORK},"",window.location.hash)),k)),We(null)},[c]),fr=g.useCallback(k=>{We(K=>K?.id===k.id?(c&&v.current&&S(!1),null):(c&&(S(!0),history.pushState({mobileDetail:Ye.WORK},"",window.location.hash)),k)),ze(null)},[c]),Yr=g.useCallback(()=>{ze(null),We(null),c&&v.current&&S(!1)},[c]),Ki=g.useCallback(()=>{ze(null),!an.current&&c&&v.current&&S(!1)},[c]);g.useEffect(()=>{if(!c)return;const k=()=>{v.current&&(S(!1),ze(null),We(null))};return window.addEventListener("popstate",k),()=>window.removeEventListener("popstate",k)},[c]);const on=g.useRef(Ve);on.current=Ve;const an=g.useRef(Pe);an.current=Pe,g.useEffect(()=>{const k=K=>{if(K.key!=="Escape")return;const ne=K.target?.tagName;if(!(ne==="INPUT"||ne==="TEXTAREA"||ne==="SELECT")){if(on.current){ze(null);return}if(an.current){We(null);return}}};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[]),g.useEffect(()=>{if(n||!i)return;Je(),sn(),wt();const k=on.current?12e4:45e3,K=setInterval(()=>{Je(),sn(),wt()},k);let ne=null;const ue=()=>{ne||(ne=setTimeout(()=>{ne=null,Je()},800))};let xe=null;const Ce=()=>{xe||(xe=setTimeout(()=>{xe=null,wt()},800))},ke=bt.on("task:update",qe=>{kt("/taskboard"),ue();const $e=qe?.payload;$e?.taskId&&(ze(et=>{if(!et||et.id!==$e.taskId)return et;const De={};return typeof $e.status=="string"&&(De.status=$e.status),Array.isArray($e.deliverables)&&(De.deliverables=$e.deliverables),Array.isArray($e.notes)&&(De.notes=$e.notes),$e.result!==void 0&&(De.result=$e.result),{...et,...De}}),on.current?.id===$e.taskId&&(kt("/tasks/"+$e.taskId),re.tasks.get($e.taskId).then(et=>{et.task&&ze(De=>De?.id===et.task.id?et.task:De)}).catch(()=>{})))}),fe=bt.on("task:create",()=>{ue()}),qt=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(qe=>bt.on(qe,$e=>{kt("/requirements"),Ce();const et=$e?.payload,De=et?.id??et?.requirementId;De&&an.current?.id===De&&(kt("/requirements/"+De),re.requirements.get(De).then(cn=>{cn.requirement&&We(br=>br?.id===cn.requirement.id?cn.requirement:br)}).catch(()=>{}))})),Vt=()=>{kt("/taskboard"),kt("/tasks"),kt("/requirements"),Je(),wt(),on.current&&re.tasks.get(on.current.id).then(qe=>{qe.task&&ze($e=>$e?.id===qe.task.id?qe.task:$e)}).catch(()=>{}),an.current&&re.requirements.get(an.current.id).then(qe=>{qe.requirement&&We($e=>$e?.id===qe.requirement.id?qe.requirement:$e)}).catch(()=>{})};return window.addEventListener("markus:data-changed",Vt),()=>{clearInterval(K),ke(),fe(),qt.forEach(qe=>qe()),window.removeEventListener("markus:data-changed",Vt),ne&&clearTimeout(ne),xe&&clearTimeout(xe)}},[n,i,Je,sn,wt]);const Hs=g.useRef(D);Hs.current=D;const qs=g.useRef(R);qs.current=R,g.useEffect(()=>{const k=on.current;if(!k)return;const ne=Object.values(D).flat().find(ue=>ue.id===k.id);ne&&ne.updatedAt!==k.updatedAt&&ze(ne)},[D]),g.useEffect(()=>{const k=an.current;if(!k)return;const K=R.find(ne=>ne.id===k.id);K&&K.updatedAt!==k.updatedAt&&We(K)},[R]);const Zt=g.useCallback(k=>{if(!k)return;const K=Ee.current;K.size>0&&!K.has(k)&&lt(ne=>new Set([...ne,k]))},[]),[Gr,Hn]=g.useState(!1),qn=g.useCallback((k,K)=>{ze(k),We(null),K?.scrollToComments&&Hn(!0),c&&S(!0)},[c]),bn=g.useCallback((k,K)=>{We(k),ze(null),K?.scrollToComments&&Hn(!0),c&&S(!0)},[c]),yn=g.useRef(null);g.useEffect(()=>{const k=yn.current||localStorage.getItem("markus_nav_openTask");if(!k)return;const ne=Object.values(D).flat().find(ue=>ue.id===k);ne?(yn.current=null,Zt(ne.projectId),qn(ne),localStorage.removeItem("markus_nav_openTask")):yn.current||(yn.current=k,localStorage.removeItem("markus_nav_openTask"),re.tasks.get(k).then(ue=>{ue.task&&(yn.current=null,Zt(ue.task.projectId),qn(ue.task))}).catch(()=>{yn.current=null}))},[D,qn,Zt]);const vn=g.useRef(null);g.useEffect(()=>{const k=vn.current||localStorage.getItem("markus_nav_openRequirement");if(!k)return;const K=R.find(ne=>ne.id===k);K?(vn.current=null,Zt(K.projectId),bn(K),localStorage.removeItem("markus_nav_openRequirement")):vn.current||(vn.current=k,localStorage.removeItem("markus_nav_openRequirement"),re.requirements.get(k).then(ne=>{ne.requirement&&(vn.current=null,Zt(ne.requirement.projectId),bn(ne.requirement))}).catch(()=>{vn.current=null}))},[R,bn,Zt]),g.useEffect(()=>{const k=window.location.hash.slice(1).split("/");if(vr(k[0])===Ye.WORK&&k[1])wn(k[1]);else{const K=localStorage.getItem("markus_nav_projectId");K&&(localStorage.removeItem("markus_nav_projectId"),wn(K))}},[]);const Vs=g.useRef(vr(window.location.hash.slice(1).split("/")[0]));g.useEffect(()=>{if(n)return;const k=()=>{const ne=window.location.hash.slice(1).split("/"),ue=vr(ne[0]),xe=Vs.current===Ye.WORK;Vs.current=ue,ue===Ye.WORK&&(ue===Ye.WORK&&ne[1]?wn(ne[1]):xe&&hr())},K=async ne=>{const ue=ne.detail;if(vr(ue.page)===Ye.WORK){if(ue.params?.openTask){const xe=ue.params.openTask,Ce=ue.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let ke=Object.values(Hs.current).flat().find(fe=>fe.id===xe);if(!ke)try{ke=(await re.tasks.get(xe)).task}catch{}ke&&(Zt(ke.projectId),qn(ke,{scrollToComments:Ce}))}if(ue.params?.openRequirement){const xe=ue.params.openRequirement,Ce=ue.params.scrollToComments==="true";let ke=qs.current.find(fe=>fe.id===xe);if(!ke)try{ke=(await re.requirements.get(xe)).requirement}catch{}ke&&(Zt(ke.projectId),bn(ke,{scrollToComments:Ce}))}if(ue.params?.projectId&&wn(ue.params.projectId),ue.params?.statusFilter){const xe=ue.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),nh.has(xe)&&Bt(!0),Tt(xe)}}};return window.addEventListener("markus:navigate",K),window.addEventListener("hashchange",k),()=>{window.removeEventListener("markus:navigate",K),window.removeEventListener("hashchange",k)}},[n]);const wn=k=>{Ee.current.size>0&&(Pt.current=new Set(Ee.current)),lt(new Set),M(k),N("project"),I(null),Q(!1),history.replaceState(null,"",no(Ye.WORK,k))},hr=()=>{lt(Pt.current),M(null),N("all"),I(null),Q(!1),history.replaceState(null,"",no(Ye.WORK))},Qi=()=>{W(!1),st(r("work:task.projectCreated")),xt()},Ws=async k=>{try{await re.projects.delete(k),w===k&&hr(),st(r("work:task.projectDeleted")),xt(),Je()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},Fs=async()=>{if(!se||!he||!Z||gt)return;ot("");const k=Z.startsWith("human:"),K=Z.replace(/^(human|agent):/,"");if(he===K&&!k){st(r("work:task.assignedReviewerDifferent"));return}const ne=me||void 0,ue=ce||void 0;Et(!0);try{const{task:xe}=await re.tasks.create(se,U,he,K,le,ne,pe.length>0?pe:void 0,ue,be!=="standard"?be:void 0,be==="scheduled"?{every:mt}:void 0,k?"human":"agent");J(""),oe(""),Te([]),te(""),Ie("standard"),nt("4h"),ee(!1),Je(),xe&&qn(xe)}catch(xe){const ke=`work:task.errorCode_${(xe instanceof yl?xe.code:void 0)||"unknown"}`,fe=r(ke,{defaultValue:""});ot(fe||r("work:task.errorCreatingTask",{message:xe instanceof Error?xe.message:String(xe)}))}finally{Et(!1)}},kn=k=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:k}))},Ys=()=>{kt("/taskboard"),Je(),Ve&&(kn({taskId:Ve.id}),kt("/tasks/"+Ve.id),re.tasks.get(Ve.id).then(k=>{k.task&&ze(K=>K?.id===k.task.id?k.task:K)}).catch(()=>{}))},ln=()=>{kt("/requirements"),wt(),Pe&&(kt("/requirements/"+Pe.id),re.requirements.get(Pe.id).then(k=>{k.requirement&&We(K=>K?.id===k.requirement.id?k.requirement:K)}).catch(()=>{}))},Gs=async()=>{if(!Bn){if(!dt.trim()){At(r("work:task.pleaseReqTitle"));return}if(!at.trim()){At(r("work:task.pleaseReqDesc"));return}if(!je){At(r("work:task.pleaseReqProject"));return}At(""),cr(!0);try{const{requirement:k}=await re.requirements.create({title:dt.trim(),description:at.trim(),priority:ge,projectId:je});st(r("work:task.requirementCreated")),ut(""),G(""),Ke(!1),wt(),k&&bn(k)}catch(k){At(k instanceof Error?k.message:String(k))}finally{cr(!1)}}},Zr=async k=>{try{await re.requirements.approve(k),st(r("work:task.requirementApproved")),kn({requirementId:k}),ln(),Je()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},Ji=async()=>{if(Qe){Gt("");try{await re.requirements.reject(Qe,rn),st(r("work:task.requirementRejected")),kn({requirementId:Qe}),ft(null),pn(""),Gt(""),ln()}catch(k){Gt(k instanceof Error?k.message:String(k))}}},Zs=async k=>{try{await re.requirements.cancel(k),st(r("work:task.requirementCancelled")),kn({requirementId:k}),ln()}catch(K){st(r("work:task.errorGeneric",{message:String(K)}))}},el=(k,K)=>{Rt.current=K,_t.current=null,k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/plain",`task:${K.id}`),k.currentTarget.style.opacity="0.4"},tl=(k,K)=>{_t.current=K,Rt.current=null,k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/plain",`req:${K.id}`),k.currentTarget.style.opacity="0.4"},Xs=k=>{k.currentTarget.style.opacity="1",Rt.current=null,_t.current=null,rt(null)},nl=(k,K)=>{k.preventDefault(),k.dataTransfer.dropEffect="move",Fe!==K&&rt(K)},rl=(k,K)=>{const ne=k.currentTarget.getBoundingClientRect(),{clientX:ue,clientY:xe}=k;(ue<ne.left||ue>ne.right||xe<ne.top||xe>ne.bottom)&&Fe===K&&rt(null)},sl=async(k,K)=>{k.preventDefault(),rt(null);const ne=Rt.current,ue=_t.current;if(ne){const xe=o.find(ke=>ke.id===K);if(!xe)return;const Ce=xe.dropStatus;if(ne.status===Ce||ne.status==="pending")return;try{await re.tasks.updateStatus(ne.id,Ce),Je()}catch{}}else if(ue){const xe=Xi[K];if(!xe||ue.status===xe)return;try{await re.requirements.updateStatus(ue.id,xe),wt()}catch{}}},Us=k=>{Xe(K=>{const ne=new Set(K);return ne.has(k)?ne.delete(k):ne.add(k),ne})},jn=k=>{b==="project"?w===k?hr():wn(k):lt(K=>{const ne=new Set(K);return ne.has(k)?ne.delete(k):ne.add(k),ne})},ol=new Set(["rejected","cancelled","archived"]),mr=k=>ol.has(k.status),Xr=(k,K=!1)=>{let ne=k.filter(ue=>Ue||!mr(ue));return It&&(ne=ne.filter(ue=>ue.status===It)),b==="project"&&w&&(ne=ne.filter(ue=>ue.projectId===w)),Le.size>0&&(ne=ne.filter(ue=>ue.projectId&&Le.has(ue.projectId))),we.size>0&&(ne=ne.filter(ue=>ue.assignedAgentId&&we.has(ue.assignedAgentId))),_e&&e?.id&&(ne=ne.filter(ue=>ue.createdBy===e.id)),ne},al=g.useMemo(()=>{const k=new Map;for(const K of Object.values(D))for(const ne of K)k.set(ne.id,ne);return k},[D]),il=g.useMemo(()=>new Set(_.map(k=>k.id)),[_]),Ks=k=>k.statuses.flatMap(K=>Xr(D[K]??[])),Nn=g.useMemo(()=>{let k=R;return Ue||(k=k.filter(K=>!mr(K))),b==="project"&&w&&(k=k.filter(K=>K.projectId===w)),Le.size>0&&(k=k.filter(K=>K.projectId&&Le.has(K.projectId))),we.size>0&&(k=k.filter(K=>we.has(K.createdBy))),_e&&e?.id&&(k=k.filter(K=>K.createdBy===e.id)),k},[R,Ue,b,w,Le,we,_e,e?.id,il]),Qs=g.useCallback(k=>Nn.filter(K=>Zi[K.status]===k.id),[Nn]),ll=o.filter(k=>{if(k.id==="failed"||k.id==="closed"){const K=Ks(k),ne=Qs(k);return K.length+ne.length>0}return!0}),Vn=Object.values(D).flat().filter(k=>mr(k)).length+R.filter(k=>mr(k)).length,Js=g.useMemo(()=>{const k=new Set(["completed","failed","cancelled","archived"]),K=Object.values(D).flat(),ne=new Set;for(const ue of K)ue.assignedAgentId&&!k.has(ue.status)&&(!w||ue.projectId===w)&&ne.add(ue.assignedAgentId);return[..._].sort((ue,xe)=>{const Ce=ne.has(ue.id)?0:1,ke=ne.has(xe.id)?0:1;return Ce-ke})},[_,D,w]),gr=g.useMemo(()=>{const k=new Map,K=[];for(const ue of Js)if(ue.teamId){const xe=k.get(ue.teamId)??[];xe.push(ue.id),k.set(ue.teamId,xe)}else K.push(ue);const ne=[];for(const ue of K)ne.push({kind:"agent",agent:ue});for(const ue of $){const xe=k.get(ue.id);xe&&xe.length>0&&ne.push({kind:"team",id:ue.id,name:ue.name,agentIds:xe})}return ne},[Js,$]),eo=g.useMemo(()=>{const k=new Set(["completed","failed","cancelled","archived"]),K=Object.values(D).flat(),ne=new Set;for(const xe of K)xe.projectId&&!k.has(xe.status)&&ne.add(xe.projectId);return[...Ue?y:y.filter(xe=>xe.status!=="archived")].sort((xe,Ce)=>{const ke=xe.status==="archived"?1:0,fe=Ce.status==="archived"?1:0;if(ke!==fe)return ke-fe;const Ht=ne.has(xe.id)?0:1,qt=ne.has(Ce.id)?0:1;return Ht!==qt?Ht-qt:xe.name.localeCompare(Ce.name)})},[y,D,Ue]),Ur=g.useMemo(()=>{const k={};for(const K of Object.values(D))for(const ne of K){const ue=ne.projectId??"__none__";k[ue]=(k[ue]??0)+1}return k},[D]),pr=Object.values(Ur).reduce((k,K)=>k+K,0);if(A)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:r("work:task.loadingPage")});const Wn=!!(Ve||Pe),xr=!c&&!!(Ve&&Pe);return t.jsxs("div",{ref:d,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[t.jsxs("div",{className:`${c?"flex-1 min-w-0":Wn?"shrink-0 min-w-0":"flex-1"} overflow-hidden flex flex-col bg-surface-primary`,style:c?E?{display:"none"}:void 0:xr?{width:0}:Wn?{width:`calc(100% - ${x.width}px - 4px)`}:void 0,children:[q&&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:q}),c?t.jsxs("div",{className:"shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[t.jsx(bl,{}),tt?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:tt.name}),t.jsx("button",{onClick:()=>xn(tt.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${Y?"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:y.length===1?y[0].name:r("work:task.projectsCount",{count:y.length})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>W(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortProject")}),t.jsx("button",{onClick:H,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortReq")}),t.jsx("button",{onClick:()=>{ve(w??""),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(k=>t.jsx("button",{onClick:()=>Mt(k),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${ct===k?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:r(k==="backlog"?"work:task.backlog":k==="kanban"?"work:task.kanban":"work:task.dag")},k))}),Vn>0&&t.jsx("button",{onClick:()=>Bt(k=>!k),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ue?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Ue?r("work:task.hideArchived"):r("work:task.archivedCount",{count:Vn})}),t.jsx("div",{className:"flex-1"}),It&&t.jsxs("button",{onClick:()=>Tt(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.${It==="in_progress"?"inProgress":It}`),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"})]})]}),(Le.size>0||we.size>0||_e||y.length>1||_.length>0)&&t.jsxs("button",{onClick:()=>pt(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${Le.size>0||we.size>0||_e?"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"})}),Le.size+we.size+(_e?1:0)>0?r("work:task.filterWithCount",{count:Le.size+we.size+(_e?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:[tt?t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0",children:[t.jsx(oa,{value:tt.name,onSave:async k=>{await re.projects.update(tt.id,{name:k}),xt()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:()=>xn(tt.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${Y?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:r("work:project.settingsTitle"),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:y.length===1?y[0].name:r("work:task.projectsCount",{count:y.length})}),Vn>0&&t.jsx("button",{onClick:()=>Bt(k=>!k),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ue?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Ue?r("work:task.hideArchivedWithCount",{count:Vn}):r("work:task.archivedCount",{count:Vn})}),t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(k=>t.jsx("button",{onClick:()=>Mt(k),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${ct===k?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:k==="backlog"?r("work:task.backlog"):k==="kanban"?r("work:task.kanban"):k==="dag"?r("work:task.dag"):r("work:task.workflows","Workflows")},k))}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:()=>W(!0),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.shortProject")}),t.jsx("button",{onClick:H,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:()=>{ve(w??""),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"})]}),!c&&ct!=="workflows"&&y.length>1&&!w&&!Y&&(pr>0||R.length>0)&&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",{onClick:()=>lt(new Set),className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${Le.size>0?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),eo.map(k=>{const K=Le.has(k.id),ne=Ur[k.id]??0,ue=Y&&O===k.id;return t.jsxs("div",{className:`flex items-center shrink-0 rounded-md overflow-hidden transition-all ${K?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[t.jsxs("button",{onClick:()=>jn(k.id),className:`flex items-center gap-1.5 px-2.5 py-1 text-[11px] shrink-0 transition-all ${K?"text-brand-600":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${K?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:k.name[0]?.toUpperCase()}),k.name,ne>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:ne})]}),K&&t.jsx("button",{onClick:()=>xn(k.id),className:`px-1.5 py-1 self-stretch flex items-center border-l border-brand-500/20 transition-colors ${ue?"text-fg-primary bg-surface-overlay":"text-fg-tertiary hover:text-brand-600 hover:bg-brand-500/10"}`,title:r("work:project.editProject"),children:t.jsxs("svg",{width:"11",height:"11",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"})]})})]},k.id)})]}),!c&&ct!=="workflows"&&(gr.length>0||e?.id)&&!Y&&(pr>0||R.length>0)&&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:()=>{Xe(new Set),Re(!1)},className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${we.size>0||_e?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),e?.id&&t.jsx("button",{type:"button",onClick:()=>Re(k=>!k),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${_e?"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")}),gr.map(k=>{if(k.kind==="team"){const ue=k.agentIds.every(Ce=>we.has(Ce)),xe=!ue&&k.agentIds.some(Ce=>we.has(Ce));return t.jsxs("button",{onClick:()=>{Xe(Ce=>{const ke=new Set(Ce);if(ue)for(const fe of k.agentIds)ke.delete(fe);else for(const fe of k.agentIds)ke.add(fe);return ke})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ue?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":xe?"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"})}),k.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:k.agentIds.length})]},`team-${k.id}`)}const K=k.agent,ne=we.has(K.id);return t.jsxs("button",{onClick:()=>Us(K.id),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":"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 ${ne?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:K.name[0]?.toUpperCase()}),K.name]},K.id)})]}),Y&&zt?t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!tt&&t.jsxs("div",{className:"px-6 py-2 flex items-center gap-2 border-b border-border-default/60 shrink-0",children:[t.jsxs("button",{onClick:On,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1 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("polyline",{points:"15 18 9 12 15 6"})}),r("common:back")]}),t.jsx(oa,{value:zt.name,onSave:async k=>{await re.projects.update(zt.id,{name:k}),xt()},className:"text-sm font-semibold text-fg-primary truncate min-w-0"})]}),t.jsx(ba,{project:zt,tasks:Object.values(D).flat(),requirements:R,agents:_,onDeleteProject:()=>Ws(zt.id),onUpdateProject:async k=>{await re.projects.update(zt.id,k)},onRefresh:()=>{xt()}})]}):pr===0&&Nn.length===0&&b==="project"&&tt?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-y-auto",children:[t.jsx("div",{className:"px-6 py-2 flex items-center gap-2 border-b border-border-default/60 shrink-0 sticky top-0 bg-surface-primary z-10",children:t.jsxs("button",{onClick:hr,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1 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("polyline",{points:"15 18 9 12 15 6"})}),r("common:back")]})}),t.jsx(ba,{project:tt,tasks:[],requirements:[],agents:_,onDeleteProject:()=>Ws(tt.id),onUpdateProject:async k=>{await re.projects.update(tt.id,k)},onRefresh:()=>{xt()}})]}):pr===0&&Nn.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:y.length===0?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:()=>W(!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")})]}):t.jsxs("div",{className:"w-full max-w-2xl mx-auto space-y-4",children:[t.jsx("p",{className:"text-xs text-fg-tertiary text-center",children:r("work:task.emptyNoReqsHint")}),t.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:y.map(k=>t.jsxs("button",{onClick:()=>wn(k.id),className:"group flex items-start gap-3 p-4 rounded-xl border border-border-default bg-surface-elevated hover:border-brand-500/50 hover:bg-brand-500/5 transition-all text-left",children:[t.jsx("div",{className:"w-9 h-9 shrink-0 rounded-lg bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"18",height:"18",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.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-sm font-medium text-fg-primary group-hover:text-brand-500 truncate transition-colors",children:k.name}),k.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 line-clamp-2",children:k.description}),t.jsx("div",{className:"text-[10px] text-fg-quaternary mt-1.5",children:new Date(k.createdAt).toLocaleDateString()})]}),t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-quaternary group-hover:text-brand-500 shrink-0 mt-1 transition-colors",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})]},k.id))}),t.jsx("div",{className:"text-center pt-2",children:t.jsx("button",{onClick:H,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")})})]})}):ct==="backlog"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:c?$t.onTouchStart:void 0,onTouchEnd:c?$t.onTouchEnd:void 0,children:t.jsx(fh,{tasks:Xr(Object.values(D).flat()),requirements:Nn,agents:_,projects:y,onTaskClick:k=>ur(k),onReqClick:k=>fr(k),onRefresh:()=>{Je(),wt()},selectedTaskId:Ve?.id,selectedReqId:Pe?.id})}):ct==="workflows"?t.jsx(ph,{teamId:Fr,projectId:w,agents:_,projects:y,onViewRunTasks:k=>{const K=ue=>{bn(ue),en(`req-${ue.id}`),Mt("dag")},ne=R.find(ue=>ue.id===k);ne?K(ne):re.requirements.get(k).then(ue=>{ue.requirement&&(T(xe=>[...xe,ue.requirement]),K(ue.requirement))}).catch(()=>{})}}):ct==="dag"?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:c?$t.onTouchStart:void 0,onTouchEnd:c?$t.onTouchEnd:void 0,children:[t.jsx(Zf,{tasks:(()=>{const k=Xr(Object.values(D).flat(),!0);if(n&&Pe){const K=new Set(Pe.taskIds??[]);return k.filter(ne=>K.has(ne.id))}return k})(),requirements:n&&Pe?[Pe]:Nn,agents:_,showArchived:Ue,onShowArchivedChange:Bt,onTaskClick:k=>ur(k),onReqClick:k=>fr(k),onCollapseDAG:()=>{ze(null),We(null),en(null)},onDependencyChange:Je,selectedTaskId:Ve?.id,selectedReqId:Pe?.id,hasDetailPanel:Wn,defaultExpandedNodeId:mn??(n&&Pe?`req-${Pe.id}`:void 0),previewMode:n}),c&&t.jsx("button",{onClick:()=>Mt("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:tn,className:"flex-1 min-h-0 overflow-auto px-4 py-5",onTouchStart:c?nn.onTouchStart:void 0,onTouchEnd:c?nn.onTouchEnd:void 0,children:t.jsx("div",{className:"flex gap-3 items-stretch",children:ll.map(k=>{const K=Ks(k),ne=Qs(k),ue=K.length+ne.length,xe=Fe===k.id;return t.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col transition-colors ${xe?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:Ce=>nl(Ce,k.id),onDragLeave:Ce=>rl(Ce,k.id),onDrop:Ce=>{sl(Ce,k.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 ${xe?"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 ${k.accent.replace("border-t-","bg-")}`}),t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:k.label})]}),t.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:ue})]}),t.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const Ce=[...ne.map(ke=>({kind:"req",data:ke,time:new Date(ke.updatedAt??ke.createdAt).getTime()})),...K.map(ke=>({kind:"task",data:ke,time:new Date(ke.updatedAt??ke.createdAt??0).getTime()}))];return Ce.sort((ke,fe)=>fe.time-ke.time),Ce.map(ke=>{if(ke.kind==="req"){const fe=ke.data,Ht=l[fe.status]??{label:fe.status,cls:"bg-gray-500/15 text-fg-secondary"},Vt=fe.source==="agent"&&fe.status==="pending",qe=b==="all"&&fe.projectId?y.find(De=>De.id===fe.projectId):null,$e=$n(fe.createdBy,_,j)??fe.createdBy.slice(0,10),et=Pe?.id===fe.id;return t.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:De=>tl(De,fe),onDragEnd:Xs,onClick:()=>fr(fe),onKeyDown:De=>De.key==="Enter"&&fr(fe),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
10
10
  ${Vt?"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
- ${et?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),t.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:r("work:task.requirementShort")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${Ht.cls}`,children:Ht.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:fe.title}),fe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:fe.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:[qe&&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:qe.name,children:qe.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:fe.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",$e]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[fe.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:fe.goalConfig.completionCriteria,children:["🎯 ",fe.goalConfig.currentIteration,"/",fe.goalConfig.maxIterations]}),fe.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:["📋 ",fe.taskIds.length]})]})]}),Vt&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:De=>{De.stopPropagation(),Zr(fe.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:De=>{De.stopPropagation(),ft(fe.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-${fe.id}`)}else{const fe=ke.data,Ht=fe.subtasks?.length??0,qt=a[fe.status],Vt=fe.status==="pending",qe=fe.taskType==="scheduled"&&!!fe.scheduleConfig,$e=qe?fe.scheduleConfig.every?r("work:task.everyInterval",{interval:fe.scheduleConfig.every}):fe.scheduleConfig.cron?r("work:task.cronLabel"):r("work:task.scheduledShort"):null,et=b==="all"&&fe.projectId?(()=>{const it=y.find(yr=>yr.id===fe.projectId)?.name;return it&&it!=="default"?it:null})():null,De=fe.requirementId?R.find(it=>it.id===fe.requirementId)?.title:null,cn=fe.createdBy?$n(fe.createdBy,_,j)??fe.createdBy:null,br=Ve?.id===fe.id,cl={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},to=fe.status==="blocked"&&(!fe.blockedBy||fe.blockedBy.length===0||fe.blockedBy.every(it=>{const yr=al.get(it);return yr&&yr.status==="completed"}));return t.jsxs("div",{role:"button",tabIndex:0,"aria-label":fe.title,draggable:!Vt,onDragStart:it=>!Vt&&el(it,fe),onDragEnd:Xs,onClick:()=>ur(fe),onKeyDown:it=>it.key==="Enter"&&ur(fe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${to?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":Vt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":qe?"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"} ${br?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${cl[fe.priority]??"bg-gray-400"}`,title:fe.priority}),qe&&t.jsx("span",{className:"text-blue-500 shrink-0",title:$e??"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"})})}),qe&&$e&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:$e}),qt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${qt.cls}`,children:qt.label}),to&&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:fe.title}),fe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:fe.description}),(et||De||fe.blockedBy&&fe.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[et&&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:et,children:et}),De&&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:De,children:["# ",De]}),fe.blockedBy&&fe.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:["⏳ ",fe.blockedBy.length," dep",fe.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:cn&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${cn}`,children:["by ",cn]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[Ht>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ht]}),fe.notes&&fe.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",fe.notes.length]}),fe.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 ${nr[_.find(it=>it.id===fe.assignedAgentId)?.status??""]??"bg-gray-500"}`}),_.find(it=>it.id===fe.assignedAgentId)?.name??fe.assignedAgentId.slice(0,8)]})]})]})]},fe.id)}})})()}),xe&&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")})})]},k.id)})})})]}),!c&&Wn&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:x.onResizeStart,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"})}),(!c||E)&&Wn&&t.jsx("div",{className:`${c||xr?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex`,style:c||xr?void 0:{width:x.width},children:xr?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(Na,{req:Pe,agents:_,projects:y,allTasks:Object.values(D).flat(),users:j,onClose:()=>{We(null)},onApprove:k=>{Zr(k)},onReject:k=>{ft(k)},onCancel:k=>{Zs(k),We(null)},onStatusChange:async(k,K)=>{try{await re.requirements.updateStatus(k,K),st(`Requirement status → ${K}`),kn({requirementId:k}),ln(),Je()}catch(ne){st(`Error: ${ne}`)}},onRefresh:ln,authUser:e,onTaskClick:k=>{ze(k)},onCreateTask:(k,K)=>{te(k),K&&ve(K),ee(!0)},onProjectClick:jn,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(xa,{task:Ve,agents:_,projects:y,requirements:R,allTasks:Object.values(D).flat(),users:j,onClose:Ki,onRefresh:Ys,authUser:e,scrollToComments:Gr,onScrollToCommentsDone:()=>Hn(!1),onReqClick:k=>{We(K=>K?.id===k.id?null:k)},onProjectClick:jn})})]}):Ve?t.jsx(xa,{task:Ve,agents:_,projects:y,requirements:R,allTasks:Object.values(D).flat(),users:j,onClose:Yr,onRefresh:Ys,authUser:e,scrollToComments:Gr,onScrollToCommentsDone:()=>Hn(!1),onReqClick:k=>{We(K=>K?.id===k.id?null:k)},onProjectClick:jn}):Pe?t.jsx(Na,{req:Pe,agents:_,projects:y,allTasks:Object.values(D).flat(),users:j,onClose:Yr,onApprove:k=>{Zr(k)},onReject:k=>{ft(k)},onCancel:k=>{Zs(k),Yr()},onStatusChange:async(k,K)=>{try{await re.requirements.updateStatus(k,K),st(`Requirement status → ${K}`),kn({requirementId:k}),ln(),Je()}catch(ne){st(`Error: ${ne}`)}},scrollToComments:Gr,onScrollToCommentsDone:()=>Hn(!1),onRefresh:ln,authUser:e,onTaskClick:k=>{ze(k),c&&(S(!0),history.pushState({mobileDetail:Ye.WORK},"",window.location.hash))},onCreateTask:(k,K)=>{te(k),K&&ve(K),ee(!0)},onProjectClick:jn,previewMode:n}):null}),V&&t.jsx(Xf,{orgId:e?.orgId,onCreated:Qi,onClose:()=>W(!1)}),X&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{ee(!1),ot("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:k=>k.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:!c,value:se,onChange:k=>J(k.target.value),onKeyDown:k=>{k.key==="Enter"&&Fs()},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:U,onChange:k=>oe(k.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(Yn,{options:[{value:"",label:r("work:task.noProject")},...y.map(k=>({value:k.id,label:k.name}))],value:me,onChange:k=>{ve(k),te("")},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(Yn,{options:[{value:"",label:r("work:task.selectRequirement")},...R.filter(k=>k.status==="in_progress"&&(!me||k.projectId===me)).map(k=>({value:k.id,label:k.title}))],value:ce,onChange:te,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(Yn,{options:_.map(k=>({value:k.id,label:`${k.name} (${k.status})`})),value:he,onChange:de,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(Yn,{options:[...j.map(k=>({value:`human:${k.id}`,label:k.name})),..._.filter(k=>k.id!==he).map(k=>({value:`agent:${k.id}`,label:`${k.name} (${k.status})`}))],value:Z,onChange:ae,placeholder:r("work:task.selectReviewer"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:`grid gap-4 ${be==="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:le,onChange:k=>ie(k.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:be,onChange:k=>Ie(k.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")})]})]}),be==="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:mt,onChange:k=>nt(k.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(Uf,{options:Object.values(D).flat().filter(k=>k.status!=="completed"&&k.status!=="cancelled").map(k=>({value:k.id,label:k.title})),selected:pe,onAdd:k=>Re([...pe,k]),placeholder:r("work:task.selectDependency"),noMatchesText:r("work:task.noMatches")}),pe.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:pe.map(k=>{const K=Object.values(D).flat().find(ne=>ne.id===k);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:[K?K.title.slice(0,30):k.slice(-8),t.jsx("button",{onClick:()=>Re(pe.filter(ne=>ne!==k)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},k)})})]}),yt&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:yt}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{ee(!1),ot("")},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:()=>{Fs()},disabled:!se.trim()||!he||!Z||gt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:r(gt?"common:creating":"common:create")})]})]})}),Ot&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ke(!1),ut(""),G(""),At("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:k=>k.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(Yn,{options:y.map(k=>({value:k.id,label:k.name})),value:je,onChange:Ne,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:dt,onChange:k=>ut(k.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:!c,onKeyDown:k=>{k.key==="Enter"&&dt.trim()&&Gs()}})]}),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:at,onChange:k=>G(k.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:ge,onChange:k=>Se(k.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",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")})]})]}),lr&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:lr}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{Ke(!1),ut(""),G(""),At("")},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:()=>{Gs()},disabled:!dt.trim()||!at.trim()||!je||Bn,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(Bn?"common:creating":"common:create")})]})]})}),Qe&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{ft(null),Gt("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${c?"w-full":"w-96"}`,onClick:k=>k.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:rn,onChange:k=>pn(k.target.value),placeholder:r("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!c})]}),dr&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:dr}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>{ft(null),Gt("")},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:()=>{Ji()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:r("work:task.reject")})]})]})}),vt&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>pt(!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:k=>k.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:[(Le.size>0||we.size>0||_e)&&t.jsx("button",{onClick:()=>{lt(new Set),Xe(new Set),Te(!1)},className:"text-[11px] text-brand-500 font-medium",children:r("work:task.clearAll")}),t.jsx("button",{onClick:()=>pt(!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"})]})})]})]}),y.length>1&&t.jsxs("div",{className:"px-4 py-3",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:r("work:task.projectsFilterGroup")}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:eo.map(k=>{const K=Le.has(k.id),ne=Ur[k.id]??0;return t.jsxs("div",{className:`flex items-center rounded-lg overflow-hidden transition-all ${K?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[t.jsxs("button",{onClick:()=>jn(k.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] transition-all ${K?"text-brand-600":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${K?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:k.name[0]?.toUpperCase()}),k.name,ne>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:ne})]}),K&&t.jsx("button",{onClick:()=>{pt(!1),xn(k.id)},className:"px-2 py-1.5 self-stretch flex items-center border-l border-brand-500/20 text-fg-tertiary hover:text-brand-600",title:r("work:project.editProject"),children:t.jsxs("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:"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"})]})})]},k.id)})})]}),e?.id&&t.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:t.jsx("button",{type:"button",onClick:()=>Te(k=>!k),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${_e?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:r("work:task.myTasks")})}),gr.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:gr.map(k=>{if(k.kind==="team"){const ue=k.agentIds.every(Ce=>we.has(Ce)),xe=!ue&&k.agentIds.some(Ce=>we.has(Ce));return t.jsxs("button",{onClick:()=>{Xe(Ce=>{const ke=new Set(Ce);if(ue)for(const fe of k.agentIds)ke.delete(fe);else for(const fe of k.agentIds)ke.add(fe);return ke})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ue?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":xe?"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"})}),k.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:k.agentIds.length})]},`team-${k.id}`)}const K=k.agent,ne=we.has(K.id);return t.jsxs("button",{onClick:()=>Us(K.id),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":"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 ${ne?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:K.name[0]?.toUpperCase()}),K.name]},K.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function xh({requirementId:e,createdBy:n,agents:s,users:r,authUser:i}){const{t:o}=He(["work","common"]),[a,l]=g.useState([]),[c,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),re.requirements.getComments(e).then(v=>l(v.comments)).catch(()=>{})},[e]),g.useEffect(()=>bt.on("requirement:comment",y=>{if(y.payload?.requirementId===e&&y.payload.comment){const p=y.payload.comment;l(b=>b.some(N=>N.id===p.id)?b:[...b,p]),(p.authorType==="agent"||p.authorId?.startsWith("agt_"))&&(d(b=>{const N=b.filter(w=>w.id!==p.authorId);return N.length===0&&h.current&&(clearTimeout(h.current),h.current=null),N}),m(b=>{const N=new Map(b);return N.delete(p.authorId),N}))}}),[e]),g.useEffect(()=>{if(c.length===0)return;const v=new Set(c.map(p=>p.id));return bt.on("agent:activity_log",p=>{const b=p.payload;if(!b)return;const N=b.agentId;if(!v.has(N))return;const w=Ls(b);w&&m(M=>Ds(M,N,w))})},[c]);const[u,x]=g.useState(null),E=async(v,y,p,b)=>{let N;p.length>0&&(N=(await re.uploads.upload(p.map(_=>({dataUrl:_.dataUrl,name:_.name})),"comments")).files.map(_=>({type:"image",url:_.url,name:_.name}))),await re.requirements.addComment(e,v,i?.name,N,i?.id,y.length>0?y:void 0,b);const w=[],M=new Set,D=P=>{if(M.has(P)||P===i?.id)return;M.add(P);const _=s.find(C=>C.id===P);_&&w.push({id:_.id,name:_.name,avatarUrl:_.avatarUrl})};for(const P of y){const _=s.find(C=>C.name.toLowerCase()===P.toLowerCase());_&&D(_.id)}n?.startsWith("agt_")&&D(n),w.length>0&&(h.current&&clearTimeout(h.current),d(w),h.current=setTimeout(()=>d([]),12e4))},S=g.useCallback(v=>{x({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:a.length>0?o("work:task.commentsWithCount",{count:a.length}):o("work:task.comments")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[a.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:o("work:task.noCommentsYet")}),a.map(v=>t.jsx(Zn,{comment:v,agents:s,onReply:S},v.id)),c.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(v=>{const y=f.get(v.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Lt.navigate(Ye.TEAM,{agentId:v.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(ws,{name:v.name,avatarUrl:v.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:v.name}),y.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(Ps,{entries:y})})]},v.id)})})]}),t.jsx(Ma,{agents:s,humans:r,onSubmit:E,replyTo:u,onCancelReply:()=>x(null)})]})}function Na({req:e,agents:n,projects:s,allTasks:r,users:i,onClose:o,onApprove:a,onReject:l,onCancel:c,onStatusChange:d,onRefresh:h,authUser:f,scrollToComments:m,onScrollToCommentsDone:u,onTaskClick:x,onCreateTask:E,onProjectClick:S,previewMode:v}){const{t:y}=He(["work","common"]),p=g.useMemo(()=>Bs(y),[y]),b=g.useMemo(()=>Gi(y),[y]),N=rr(),[w,M]=g.useState(!1),[D,P]=g.useState(e.description),[_,C]=g.useState(!1),[$,z]=g.useState(!1),[j,B]=g.useState(!1),R=g.useRef(null),[T,A]=g.useState("none"),L=g.useRef(null),q=g.useRef(null),F=g.useRef(80);g.useEffect(()=>{const J=R.current;if(!J)return;const U=()=>{const{scrollTop:le,scrollHeight:ie,clientHeight:he}=J;if(!(ie>he+50)){A("none");return}const Z=le<30,ae=le+he>=ie-30;A(Z?"top":ae?"bottom":"middle")};U(),J.addEventListener("scroll",U,{passive:!0});const oe=new ResizeObserver(U);return oe.observe(J),()=>{J.removeEventListener("scroll",U),oe.disconnect()}},[]),g.useEffect(()=>{if(w&&q.current){const J=q.current;J.style.height="auto",J.style.height=Math.max(J.scrollHeight,F.current)+"px",J.focus()}},[w]),g.useEffect(()=>{if(!m)return;const J=setTimeout(()=>{const U=R.current;U&&U.scrollTo({top:U.scrollHeight,behavior:"smooth"}),u?.()},300);return()=>clearTimeout(J)},[m,u]);const Y=p[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},Q=e.source==="agent",O=Q&&e.status==="pending",I=e.status==="pending"||e.status==="in_progress",H=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",V=e.projectId?s.find(J=>J.id===e.projectId):null,W=$n(e.createdBy,n,i)??e.createdBy.slice(0,12),X=r.filter(J=>e.taskIds.includes(J.id)),ee=V?.teamIds?.[0]??null;g.useMemo(()=>new Map(X.map(J=>[J.id,J])),[X]);const se=X.length>=2;return g.useEffect(()=>{P(e.description),M(!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:[N&&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:y("work:task.requirementShort")})," ",t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${Y.cls}`,children:Y.label})," ",e.priority==="high"||e.priority==="urgent"?t.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:y("common:priority."+e.priority,{defaultValue:e.priority})}):t.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:y("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),t.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:R,className:"h-full overflow-y-auto p-5 space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:y("work:task.requirementDetailDescription")}),w?t.jsx("textarea",{ref:q,value:D,onChange:J=>{P(J.target.value);const U=J.target;U.style.height="auto",U.style.height=U.scrollHeight+"px"},onBlur:async()=>{if(D!==e.description){C(!0);try{await re.requirements.update(e.id,{description:D}),h?.()}catch{}finally{C(!1)}}M(!1)},onKeyDown:J=>{J.key==="Escape"&&(J.preventDefault(),P(e.description),M(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:y("work:task.requirementDetailDescription")}):t.jsx("div",{ref:L,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${H?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:H?void 0:J=>{J.target.closest("a, button, [data-entity-link]")||(F.current=Math.max(L.current?.offsetHeight??80,60),P(e.description),M(!0))},role:H?void 0:"button",tabIndex:H?void 0:0,onKeyDown:H?void 0:J=>J.key==="Enter"&&(P(e.description),M(!0)),children:e.description?t.jsx(Xn,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:y("work:task.requirementNoDescription")})})]}),t.jsxs("div",{className:"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:y("work:task.createdByLabel")}),t.jsx("span",{className:"text-fg-secondary",children:W}),Q&&t.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:y("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:y("work:task.createdLabel")}),t.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),V&&t.jsxs("div",{className:`bg-surface-elevated/60 rounded-lg p-2.5 ${S?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:S?()=>S(V.id):void 0,role:S?"button":void 0,tabIndex:S?0:void 0,onKeyDown:S?J=>J.key==="Enter"&&S(V.id):void 0,children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:y("work:task.projectLabel")}),t.jsx("span",{className:"text-fg-secondary",children:V.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:y("work:task.approvedBy")}),t.jsx("span",{className:"text-fg-secondary",children:$n(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:y("work:task.rejectionReason")}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.goalConfig?.loopEnabled&&t.jsxs("div",{className:"bg-brand-500/8 border border-brand-500/20 rounded-lg p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("span",{className:"text-[10px] font-semibold text-brand-500 uppercase tracking-wider",children:y("work:requirement.goal")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${e.goalConfig.currentIteration>=e.goalConfig.maxIterations?"bg-amber-500/15 text-amber-600":"bg-green-500/15 text-green-600"}`,children:e.goalConfig.currentIteration>=e.goalConfig.maxIterations?y("work:requirement.goalMaxReached"):y("work:requirement.goalActive")})]}),t.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:e.goalConfig.completionCriteria}),t.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary",children:[t.jsx("span",{children:y("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&t.jsx("span",{children:y("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&t.jsx("span",{className:"text-brand-500",children:y("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(J=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",J]},J))}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:y("work:task.linkedTasks",{count:X.length})}),t.jsxs("div",{className:"flex items-center gap-2",children:[se&&ee&&t.jsxs("button",{onClick:()=>B(!0),className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),y("work:task.saveAsWorkflow")]}),!H&&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"})}),y("work:requirement.createTask")]})]})]}),X.length>0?(()=>{const J=new Map(X.map(de=>[de.id,de]));if(!X.some(de=>de.blockedBy?.some(Z=>J.has(Z))))return t.jsx("div",{className:"space-y-1.5",children:X.map(de=>{const Z=b[de.status];return t.jsxs("div",{onClick:()=>x?.(de),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${x?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${nr[de.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:de.title}),Z&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Z.cls}`,children:Z.label})]},de.id)})});const oe=new Map,le=new Set;for(const de of X)for(const Z of de.blockedBy??[])if(J.has(Z)){le.add(de.id);const ae=oe.get(Z)??[];ae.push(de.id),oe.set(Z,ae)}const ie=X.filter(de=>!le.has(de.id)),he=(de,Z)=>{const ae=b[de.status],me=(oe.get(de.id)??[]).map(ve=>J.get(ve)).filter(Boolean);return t.jsxs("div",{children:[t.jsxs("div",{onClick:()=>x?.(de),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${x?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:Z>0?{marginLeft:Z*20}:void 0,children:[Z>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 ${nr[de.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:de.title}),ae&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${ae.cls}`,children:ae.label})]}),me.map(ve=>he(ve,Z+1))]},de.id)};return t.jsx("div",{className:"space-y-1.5",children:ie.map(de=>he(de,0))})})():t.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:y("work:requirement.noLinkedTasks")})]}),!v&&t.jsx(xh,{requirementId:e.id,createdBy:e.createdBy,agents:n,users:i,authUser:f}),!v&&t.jsx(Ui,{entityType:"requirement",entityId:e.id})]}),T!=="none"&&T!=="top"&&t.jsx("button",{onClick:()=>R.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),T!=="none"&&T!=="bottom"&&t.jsx("button",{onClick:()=>{const J=R.current;J&&J.scrollTo({top:J.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[O&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>a(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.approveRequirement")}),t.jsx("button",{onClick:()=>l(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.rejectRequirement")})]}),!O&&d&&!H&&t.jsx("select",{value:e.status,onChange:J=>{J.target.value!==e.status&&d(e.id,J.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:dh.map(J=>{const U=p[J],oe=J===e.status||(ys[e.status]?.has(J)??!1);return t.jsx("option",{value:J,disabled:!oe,children:U?.label??J},J)})}),H&&d&&t.jsx("button",{onClick:()=>d(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:y("work:task.reopen")}),t.jsx("div",{className:"flex-1"}),I&&!O&&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:y("work:task.cancelRequirement")})]}),$&&t.jsx(Sn,{title:y("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:y("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:y("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{z(!1),c(e.id)},onCancel:()=>z(!1)}),j&&ee&&t.jsx(gh,{req:e,tasks:X,agents:n,teamId:ee,onClose:()=>B(!1),onSaved:()=>B(!1)})]})}function Ui({entityType:e,entityId:n}){const{t:s}=He(["work"]),[r,i]=g.useState([]),[o,a]=g.useState(!0),[l,c]=g.useState(!1);if(g.useEffect(()=>{a(!0),(e==="task"?re.tasks.getHistory:re.requirements.getHistory)(n).then(u=>i(u.history)).catch(()=>i([])).finally(()=>a(!1))},[e,n]),o)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:s("work:task.loadingHistory","Loading history...")});if(r.length===0)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:s("work:task.noHistory","No status change history.")});const d=l?r:r.slice(-5),h=r.length>5&&!l,f=m=>{const u=m.changedByName||m.changedById||(m.changedByType==="human"?"User":m.changedByType==="agent"?"Agent":"System"),x=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 ${x}`,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:()=>c(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:s("work:task.showAllHistory",{count:r.length})}),t.jsxs("div",{className:"relative ml-2",children:[t.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),t.jsx("div",{className:"space-y-3",children:d.map(m=>t.jsxs("div",{className:"flex items-start gap-3 relative",children:[t.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:m.changedByType==="human"?"#3b82f6":m.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[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{jh as WorkPage};
11
+ ${et?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),t.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:r("work:task.requirementShort")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${Ht.cls}`,children:Ht.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:fe.title}),fe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:fe.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:[qe&&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:qe.name,children:qe.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:fe.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",$e]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[fe.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:fe.goalConfig.completionCriteria,children:["🎯 ",fe.goalConfig.currentIteration,"/",fe.goalConfig.maxIterations]}),fe.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:["📋 ",fe.taskIds.length]})]})]}),Vt&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:De=>{De.stopPropagation(),Zr(fe.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:De=>{De.stopPropagation(),ft(fe.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-${fe.id}`)}else{const fe=ke.data,Ht=fe.subtasks?.length??0,qt=a[fe.status],Vt=fe.status==="pending",qe=fe.taskType==="scheduled"&&!!fe.scheduleConfig,$e=qe?fe.scheduleConfig.every?r("work:task.everyInterval",{interval:fe.scheduleConfig.every}):fe.scheduleConfig.cron?r("work:task.cronLabel"):r("work:task.scheduledShort"):null,et=b==="all"&&fe.projectId?(()=>{const it=y.find(yr=>yr.id===fe.projectId)?.name;return it&&it!=="default"?it:null})():null,De=fe.requirementId?R.find(it=>it.id===fe.requirementId)?.title:null,cn=fe.createdBy?$n(fe.createdBy,_,j)??fe.createdBy:null,br=Ve?.id===fe.id,cl={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},to=fe.status==="blocked"&&(!fe.blockedBy||fe.blockedBy.length===0||fe.blockedBy.every(it=>{const yr=al.get(it);return yr&&yr.status==="completed"}));return t.jsxs("div",{role:"button",tabIndex:0,"aria-label":fe.title,draggable:!Vt,onDragStart:it=>!Vt&&el(it,fe),onDragEnd:Xs,onClick:()=>ur(fe),onKeyDown:it=>it.key==="Enter"&&ur(fe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${to?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":Vt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":qe?"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"} ${br?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${cl[fe.priority]??"bg-gray-400"}`,title:fe.priority}),qe&&t.jsx("span",{className:"text-blue-500 shrink-0",title:$e??"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"})})}),qe&&$e&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:$e}),qt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${qt.cls}`,children:qt.label}),to&&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:fe.title}),fe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:fe.description}),(et||De||fe.blockedBy&&fe.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[et&&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:et,children:et}),De&&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:De,children:["# ",De]}),fe.blockedBy&&fe.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:["⏳ ",fe.blockedBy.length," dep",fe.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:cn&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${cn}`,children:["by ",cn]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[Ht>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ht]}),fe.notes&&fe.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",fe.notes.length]}),fe.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 ${nr[_.find(it=>it.id===fe.assignedAgentId)?.status??""]??"bg-gray-500"}`}),_.find(it=>it.id===fe.assignedAgentId)?.name??fe.assignedAgentId.slice(0,8)]})]})]})]},fe.id)}})})()}),xe&&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")})})]},k.id)})})})]}),!c&&Wn&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:x.onResizeStart,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"})}),(!c||E)&&Wn&&t.jsx("div",{className:`${c||xr?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex`,style:c||xr?void 0:{width:x.width},children:xr?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(Na,{req:Pe,agents:_,projects:y,allTasks:Object.values(D).flat(),users:j,onClose:()=>{We(null)},onApprove:k=>{Zr(k)},onReject:k=>{ft(k)},onCancel:k=>{Zs(k),We(null)},onStatusChange:async(k,K)=>{try{await re.requirements.updateStatus(k,K),st(`Requirement status → ${K}`),kn({requirementId:k}),ln(),Je()}catch(ne){st(`Error: ${ne}`)}},onRefresh:ln,authUser:e,onTaskClick:k=>{ze(k)},onCreateTask:(k,K)=>{te(k),K&&ve(K),ee(!0)},onProjectClick:jn,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(xa,{task:Ve,agents:_,projects:y,requirements:R,allTasks:Object.values(D).flat(),users:j,onClose:Ki,onRefresh:Ys,authUser:e,scrollToComments:Gr,onScrollToCommentsDone:()=>Hn(!1),onReqClick:k=>{We(K=>K?.id===k.id?null:k)},onProjectClick:jn})})]}):Ve?t.jsx(xa,{task:Ve,agents:_,projects:y,requirements:R,allTasks:Object.values(D).flat(),users:j,onClose:Yr,onRefresh:Ys,authUser:e,scrollToComments:Gr,onScrollToCommentsDone:()=>Hn(!1),onReqClick:k=>{We(K=>K?.id===k.id?null:k)},onProjectClick:jn}):Pe?t.jsx(Na,{req:Pe,agents:_,projects:y,allTasks:Object.values(D).flat(),users:j,onClose:Yr,onApprove:k=>{Zr(k)},onReject:k=>{ft(k)},onCancel:k=>{Zs(k),Yr()},onStatusChange:async(k,K)=>{try{await re.requirements.updateStatus(k,K),st(`Requirement status → ${K}`),kn({requirementId:k}),ln(),Je()}catch(ne){st(`Error: ${ne}`)}},scrollToComments:Gr,onScrollToCommentsDone:()=>Hn(!1),onRefresh:ln,authUser:e,onTaskClick:k=>{ze(k),c&&(S(!0),history.pushState({mobileDetail:Ye.WORK},"",window.location.hash))},onCreateTask:(k,K)=>{te(k),K&&ve(K),ee(!0)},onProjectClick:jn,previewMode:n}):null}),V&&t.jsx(Xf,{orgId:e?.orgId,onCreated:Qi,onClose:()=>W(!1)}),X&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{ee(!1),ot("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:k=>k.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:!c,value:se,onChange:k=>J(k.target.value),onKeyDown:k=>{k.key==="Enter"&&Fs()},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:U,onChange:k=>oe(k.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(Yn,{options:[{value:"",label:r("work:task.noProject")},...y.map(k=>({value:k.id,label:k.name}))],value:me,onChange:k=>{ve(k),te("")},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(Yn,{options:[{value:"",label:r("work:task.selectRequirement")},...R.filter(k=>k.status==="in_progress"&&(!me||k.projectId===me)).map(k=>({value:k.id,label:k.title}))],value:ce,onChange:te,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(Yn,{options:_.map(k=>({value:k.id,label:`${k.name} (${k.status})`})),value:he,onChange:de,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(Yn,{options:[...j.map(k=>({value:`human:${k.id}`,label:k.name})),..._.filter(k=>k.id!==he).map(k=>({value:`agent:${k.id}`,label:`${k.name} (${k.status})`}))],value:Z,onChange:ae,placeholder:r("work:task.selectReviewer"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:`grid gap-4 ${be==="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:le,onChange:k=>ie(k.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:be,onChange:k=>Ie(k.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")})]})]}),be==="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:mt,onChange:k=>nt(k.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(Uf,{options:Object.values(D).flat().filter(k=>k.status!=="completed"&&k.status!=="cancelled").map(k=>({value:k.id,label:k.title})),selected:pe,onAdd:k=>Te([...pe,k]),placeholder:r("work:task.selectDependency"),noMatchesText:r("work:task.noMatches")}),pe.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:pe.map(k=>{const K=Object.values(D).flat().find(ne=>ne.id===k);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:[K?K.title.slice(0,30):k.slice(-8),t.jsx("button",{onClick:()=>Te(pe.filter(ne=>ne!==k)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},k)})})]}),yt&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:yt}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{ee(!1),ot("")},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:()=>{Fs()},disabled:!se.trim()||!he||!Z||gt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:r(gt?"common:creating":"common:create")})]})]})}),Ot&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ke(!1),ut(""),G(""),At("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:k=>k.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(Yn,{options:y.map(k=>({value:k.id,label:k.name})),value:je,onChange:Ne,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:dt,onChange:k=>ut(k.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:!c,onKeyDown:k=>{k.key==="Enter"&&dt.trim()&&Gs()}})]}),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:at,onChange:k=>G(k.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:ge,onChange:k=>Se(k.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",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")})]})]}),lr&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:lr}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{Ke(!1),ut(""),G(""),At("")},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:()=>{Gs()},disabled:!dt.trim()||!at.trim()||!je||Bn,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(Bn?"common:creating":"common:create")})]})]})}),Qe&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{ft(null),Gt("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${c?"w-full":"w-96"}`,onClick:k=>k.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:rn,onChange:k=>pn(k.target.value),placeholder:r("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!c})]}),dr&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:dr}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>{ft(null),Gt("")},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:()=>{Ji()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:r("work:task.reject")})]})]})}),vt&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>pt(!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:k=>k.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:[(Le.size>0||we.size>0||_e)&&t.jsx("button",{onClick:()=>{lt(new Set),Xe(new Set),Re(!1)},className:"text-[11px] text-brand-500 font-medium",children:r("work:task.clearAll")}),t.jsx("button",{onClick:()=>pt(!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"})]})})]})]}),y.length>1&&t.jsxs("div",{className:"px-4 py-3",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:r("work:task.projectsFilterGroup")}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:eo.map(k=>{const K=Le.has(k.id),ne=Ur[k.id]??0;return t.jsxs("div",{className:`flex items-center rounded-lg overflow-hidden transition-all ${K?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[t.jsxs("button",{onClick:()=>jn(k.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] transition-all ${K?"text-brand-600":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${K?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:k.name[0]?.toUpperCase()}),k.name,ne>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:ne})]}),K&&t.jsx("button",{onClick:()=>{pt(!1),xn(k.id)},className:"px-2 py-1.5 self-stretch flex items-center border-l border-brand-500/20 text-fg-tertiary hover:text-brand-600",title:r("work:project.editProject"),children:t.jsxs("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:"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"})]})})]},k.id)})})]}),e?.id&&t.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:t.jsx("button",{type:"button",onClick:()=>Re(k=>!k),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${_e?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:r("work:task.myTasks")})}),gr.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:gr.map(k=>{if(k.kind==="team"){const ue=k.agentIds.every(Ce=>we.has(Ce)),xe=!ue&&k.agentIds.some(Ce=>we.has(Ce));return t.jsxs("button",{onClick:()=>{Xe(Ce=>{const ke=new Set(Ce);if(ue)for(const fe of k.agentIds)ke.delete(fe);else for(const fe of k.agentIds)ke.add(fe);return ke})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ue?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":xe?"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"})}),k.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:k.agentIds.length})]},`team-${k.id}`)}const K=k.agent,ne=we.has(K.id);return t.jsxs("button",{onClick:()=>Us(K.id),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":"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 ${ne?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:K.name[0]?.toUpperCase()}),K.name]},K.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function xh({requirementId:e,createdBy:n,agents:s,users:r,authUser:i}){const{t:o}=He(["work","common"]),[a,l]=g.useState([]),[c,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),re.requirements.getComments(e).then(v=>l(v.comments)).catch(()=>{})},[e]),g.useEffect(()=>bt.on("requirement:comment",y=>{if(y.payload?.requirementId===e&&y.payload.comment){const p=y.payload.comment;l(b=>b.some(N=>N.id===p.id)?b:[...b,p]),(p.authorType==="agent"||p.authorId?.startsWith("agt_"))&&(d(b=>{const N=b.filter(w=>w.id!==p.authorId);return N.length===0&&h.current&&(clearTimeout(h.current),h.current=null),N}),m(b=>{const N=new Map(b);return N.delete(p.authorId),N}))}}),[e]),g.useEffect(()=>{if(c.length===0)return;const v=new Set(c.map(p=>p.id));return bt.on("agent:activity_log",p=>{const b=p.payload;if(!b)return;const N=b.agentId;if(!v.has(N))return;const w=Ls(b);w&&m(M=>Ds(M,N,w))})},[c]);const[u,x]=g.useState(null),E=async(v,y,p,b)=>{let N;p.length>0&&(N=(await re.uploads.upload(p.map(_=>({dataUrl:_.dataUrl,name:_.name})),"comments")).files.map(_=>({type:"image",url:_.url,name:_.name}))),await re.requirements.addComment(e,v,i?.name,N,i?.id,y.length>0?y:void 0,b);const w=[],M=new Set,D=P=>{if(M.has(P)||P===i?.id)return;M.add(P);const _=s.find(C=>C.id===P);_&&w.push({id:_.id,name:_.name,avatarUrl:_.avatarUrl})};for(const P of y){const _=s.find(C=>C.name.toLowerCase()===P.toLowerCase());_&&D(_.id)}n?.startsWith("agt_")&&D(n),w.length>0&&(h.current&&clearTimeout(h.current),d(w),h.current=setTimeout(()=>d([]),12e4))},S=g.useCallback(v=>{x({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:a.length>0?o("work:task.commentsWithCount",{count:a.length}):o("work:task.comments")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[a.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:o("work:task.noCommentsYet")}),a.map(v=>t.jsx(Zn,{comment:v,agents:s,onReply:S},v.id)),c.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(v=>{const y=f.get(v.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Lt.navigate(Ye.TEAM,{agentId:v.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(ws,{name:v.name,avatarUrl:v.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:v.name}),y.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(Ps,{entries:y})})]},v.id)})})]}),t.jsx(Ma,{agents:s,humans:r,onSubmit:E,replyTo:u,onCancelReply:()=>x(null)})]})}function Na({req:e,agents:n,projects:s,allTasks:r,users:i,onClose:o,onApprove:a,onReject:l,onCancel:c,onStatusChange:d,onRefresh:h,authUser:f,scrollToComments:m,onScrollToCommentsDone:u,onTaskClick:x,onCreateTask:E,onProjectClick:S,previewMode:v}){const{t:y}=He(["work","common"]),p=g.useMemo(()=>Bs(y),[y]),b=g.useMemo(()=>Gi(y),[y]),N=rr(),[w,M]=g.useState(!1),[D,P]=g.useState(e.description),[_,C]=g.useState(!1),[$,z]=g.useState(!1),[j,B]=g.useState(!1),R=g.useRef(null),[T,A]=g.useState("none"),L=g.useRef(null),q=g.useRef(null),F=g.useRef(80);g.useEffect(()=>{const J=R.current;if(!J)return;const U=()=>{const{scrollTop:le,scrollHeight:ie,clientHeight:he}=J;if(!(ie>he+50)){A("none");return}const Z=le<30,ae=le+he>=ie-30;A(Z?"top":ae?"bottom":"middle")};U(),J.addEventListener("scroll",U,{passive:!0});const oe=new ResizeObserver(U);return oe.observe(J),()=>{J.removeEventListener("scroll",U),oe.disconnect()}},[]),g.useEffect(()=>{if(w&&q.current){const J=q.current;J.style.height="auto",J.style.height=Math.max(J.scrollHeight,F.current)+"px",J.focus()}},[w]),g.useEffect(()=>{if(!m)return;const J=setTimeout(()=>{const U=R.current;U&&U.scrollTo({top:U.scrollHeight,behavior:"smooth"}),u?.()},300);return()=>clearTimeout(J)},[m,u]);const Y=p[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},Q=e.source==="agent",O=Q&&e.status==="pending",I=e.status==="pending"||e.status==="in_progress",H=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",V=e.projectId?s.find(J=>J.id===e.projectId):null,W=$n(e.createdBy,n,i)??e.createdBy.slice(0,12),X=r.filter(J=>e.taskIds.includes(J.id)),ee=V?.teamIds?.[0]??null;g.useMemo(()=>new Map(X.map(J=>[J.id,J])),[X]);const se=X.length>=2;return g.useEffect(()=>{P(e.description),M(!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:[N&&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:y("work:task.requirementShort")})," ",t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${Y.cls}`,children:Y.label})," ",e.priority==="high"||e.priority==="urgent"?t.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:y("common:priority."+e.priority,{defaultValue:e.priority})}):t.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:y("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),t.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:R,className:"h-full overflow-y-auto p-5 space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:y("work:task.requirementDetailDescription")}),w?t.jsx("textarea",{ref:q,value:D,onChange:J=>{P(J.target.value);const U=J.target;U.style.height="auto",U.style.height=U.scrollHeight+"px"},onBlur:async()=>{if(D!==e.description){C(!0);try{await re.requirements.update(e.id,{description:D}),h?.()}catch{}finally{C(!1)}}M(!1)},onKeyDown:J=>{J.key==="Escape"&&(J.preventDefault(),P(e.description),M(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:y("work:task.requirementDetailDescription")}):t.jsx("div",{ref:L,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${H?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:H?void 0:J=>{J.target.closest("a, button, [data-entity-link]")||(F.current=Math.max(L.current?.offsetHeight??80,60),P(e.description),M(!0))},role:H?void 0:"button",tabIndex:H?void 0:0,onKeyDown:H?void 0:J=>J.key==="Enter"&&(P(e.description),M(!0)),children:e.description?t.jsx(Xn,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:y("work:task.requirementNoDescription")})})]}),t.jsxs("div",{className:"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:y("work:task.createdByLabel")}),t.jsx("span",{className:"text-fg-secondary",children:W}),Q&&t.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:y("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:y("work:task.createdLabel")}),t.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),V&&t.jsxs("div",{className:`bg-surface-elevated/60 rounded-lg p-2.5 ${S?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:S?()=>S(V.id):void 0,role:S?"button":void 0,tabIndex:S?0:void 0,onKeyDown:S?J=>J.key==="Enter"&&S(V.id):void 0,children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:y("work:task.projectLabel")}),t.jsx("span",{className:"text-fg-secondary",children:V.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:y("work:task.approvedBy")}),t.jsx("span",{className:"text-fg-secondary",children:$n(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:y("work:task.rejectionReason")}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.goalConfig?.loopEnabled&&t.jsxs("div",{className:"bg-brand-500/8 border border-brand-500/20 rounded-lg p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("span",{className:"text-[10px] font-semibold text-brand-500 uppercase tracking-wider",children:y("work:requirement.goal")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${e.goalConfig.currentIteration>=e.goalConfig.maxIterations?"bg-amber-500/15 text-amber-600":"bg-green-500/15 text-green-600"}`,children:e.goalConfig.currentIteration>=e.goalConfig.maxIterations?y("work:requirement.goalMaxReached"):y("work:requirement.goalActive")})]}),t.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:e.goalConfig.completionCriteria}),t.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary",children:[t.jsx("span",{children:y("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&t.jsx("span",{children:y("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&t.jsx("span",{className:"text-brand-500",children:y("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(J=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",J]},J))}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:y("work:task.linkedTasks",{count:X.length})}),t.jsxs("div",{className:"flex items-center gap-2",children:[se&&ee&&t.jsxs("button",{onClick:()=>B(!0),className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),y("work:task.saveAsWorkflow")]}),!H&&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"})}),y("work:requirement.createTask")]})]})]}),X.length>0?(()=>{const J=new Map(X.map(de=>[de.id,de]));if(!X.some(de=>de.blockedBy?.some(Z=>J.has(Z))))return t.jsx("div",{className:"space-y-1.5",children:X.map(de=>{const Z=b[de.status];return t.jsxs("div",{onClick:()=>x?.(de),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${x?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${nr[de.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:de.title}),Z&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Z.cls}`,children:Z.label})]},de.id)})});const oe=new Map,le=new Set;for(const de of X)for(const Z of de.blockedBy??[])if(J.has(Z)){le.add(de.id);const ae=oe.get(Z)??[];ae.push(de.id),oe.set(Z,ae)}const ie=X.filter(de=>!le.has(de.id)),he=(de,Z)=>{const ae=b[de.status],me=(oe.get(de.id)??[]).map(ve=>J.get(ve)).filter(Boolean);return t.jsxs("div",{children:[t.jsxs("div",{onClick:()=>x?.(de),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${x?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:Z>0?{marginLeft:Z*20}:void 0,children:[Z>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 ${nr[de.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:de.title}),ae&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${ae.cls}`,children:ae.label})]}),me.map(ve=>he(ve,Z+1))]},de.id)};return t.jsx("div",{className:"space-y-1.5",children:ie.map(de=>he(de,0))})})():t.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:y("work:requirement.noLinkedTasks")})]}),!v&&t.jsx(xh,{requirementId:e.id,createdBy:e.createdBy,agents:n,users:i,authUser:f}),!v&&t.jsx(Ui,{entityType:"requirement",entityId:e.id})]}),T!=="none"&&T!=="top"&&t.jsx("button",{onClick:()=>R.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),T!=="none"&&T!=="bottom"&&t.jsx("button",{onClick:()=>{const J=R.current;J&&J.scrollTo({top:J.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[O&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>a(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.approveRequirement")}),t.jsx("button",{onClick:()=>l(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.rejectRequirement")})]}),!O&&d&&!H&&t.jsx("select",{value:e.status,onChange:J=>{J.target.value!==e.status&&d(e.id,J.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:dh.map(J=>{const U=p[J],oe=J===e.status||(ys[e.status]?.has(J)??!1);return t.jsx("option",{value:J,disabled:!oe,children:U?.label??J},J)})}),H&&d&&t.jsx("button",{onClick:()=>d(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:y("work:task.reopen")}),t.jsx("div",{className:"flex-1"}),I&&!O&&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:y("work:task.cancelRequirement")})]}),$&&t.jsx(Sn,{title:y("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:y("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:y("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{z(!1),c(e.id)},onCancel:()=>z(!1)}),j&&ee&&t.jsx(gh,{req:e,tasks:X,agents:n,teamId:ee,onClose:()=>B(!1),onSaved:()=>B(!1)})]})}function Ui({entityType:e,entityId:n}){const{t:s}=He(["work"]),[r,i]=g.useState([]),[o,a]=g.useState(!0),[l,c]=g.useState(!1);if(g.useEffect(()=>{a(!0),(e==="task"?re.tasks.getHistory:re.requirements.getHistory)(n).then(u=>i(u.history)).catch(()=>i([])).finally(()=>a(!1))},[e,n]),o)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:s("work:task.loadingHistory","Loading history...")});if(r.length===0)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:s("work:task.noHistory","No status change history.")});const d=l?r:r.slice(-5),h=r.length>5&&!l,f=m=>{const u=m.changedByName||m.changedById||(m.changedByType==="human"?"User":m.changedByType==="agent"?"Agent":"System"),x=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 ${x}`,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:()=>c(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:s("work:task.showAllHistory",{count:r.length})}),t.jsxs("div",{className:"relative ml-2",children:[t.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),t.jsx("div",{className:"space-y-3",children:d.map(m=>t.jsxs("div",{className:"flex items-start gap-3 relative",children:[t.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:m.changedByType==="human"?"#3b82f6":m.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[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{jh as WorkPage};