@markus-global/cli 0.9.7 → 0.9.8

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 (66) hide show
  1. package/dist/markus.mjs +8 -5
  2. package/dist/web-ui/assets/{CommentInput-JPZATTdP.js → CommentInput-CcU4x-2w.js} +1 -1
  3. package/dist/web-ui/assets/{ContentRenderer-gaxBn1N9.js → ContentRenderer-C28LBAOD.js} +2 -2
  4. package/dist/web-ui/assets/DeliverableShareModal-DAR6-GIg.js +1 -0
  5. package/dist/web-ui/assets/Deliverables-BuFmzt8Q.js +3 -0
  6. package/dist/web-ui/assets/{Notifications-W-Mx_v6q.js → Notifications-DfEPEYXi.js} +1 -1
  7. package/dist/web-ui/assets/{Search-Cxtd9r1S.js → Search-DVngYDXA.js} +1 -1
  8. package/dist/web-ui/assets/{Settings-Q87nTBy5.js → Settings-DL8i8fbx.js} +1 -1
  9. package/dist/web-ui/assets/{Store-BK54Nx60.js → Store-C5bIowl-.js} +1 -1
  10. package/dist/web-ui/assets/{Team-CWRLD5sM.js → Team-BPirIx0q.js} +30 -30
  11. package/dist/web-ui/assets/{Work-xejZ7HCT.js → Work-CjgHtG8z.js} +5 -5
  12. package/dist/web-ui/assets/{arc-BqhlYS08.js → arc-BT_F7CX9.js} +1 -1
  13. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-C8fUeKGJ.js → architectureDiagram-3BPJPVTR-BgRvj0-5.js} +1 -1
  14. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-eILAtQzQ.js → blockDiagram-GPEHLZMM-BHGe_N_M.js} +1 -1
  15. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-DdV7TyX_.js → c4Diagram-AAUBKEIU-Bf3z_oHk.js} +1 -1
  16. package/dist/web-ui/assets/channel-BDoV60FN.js +1 -0
  17. package/dist/web-ui/assets/{chunk-2J33WTMH-BwuewEg2.js → chunk-2J33WTMH-DUOJv34F.js} +1 -1
  18. package/dist/web-ui/assets/{chunk-4BX2VUAB-Bv26FANh.js → chunk-4BX2VUAB-BnGMN5aR.js} +1 -1
  19. package/dist/web-ui/assets/{chunk-55IACEB6-DFTeZroI.js → chunk-55IACEB6-cUvrWf3P.js} +1 -1
  20. package/dist/web-ui/assets/{chunk-727SXJPM-i7IiTNSf.js → chunk-727SXJPM-DAIeVGil.js} +1 -1
  21. package/dist/web-ui/assets/{chunk-AQP2D5EJ-BoPcIU1Z.js → chunk-AQP2D5EJ-CvHiJGw_.js} +1 -1
  22. package/dist/web-ui/assets/{chunk-FMBD7UC4-DTXl3WfT.js → chunk-FMBD7UC4-CuFNK3C8.js} +1 -1
  23. package/dist/web-ui/assets/{chunk-ND2GUHAM-DdzR-Jnl.js → chunk-ND2GUHAM-DvQAnLZh.js} +1 -1
  24. package/dist/web-ui/assets/{chunk-QZHKN3VN-DqSW43I1.js → chunk-QZHKN3VN-Aoa5sIU7.js} +1 -1
  25. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-CsLOGMTv.js +1 -0
  26. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-CsLOGMTv.js +1 -0
  27. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-C-UFRPSb.js → cose-bilkent-S5V4N54A-Uuy7nGWb.js} +1 -1
  28. package/dist/web-ui/assets/{dagre-BM42HDAG-92ucBloh.js → dagre-BM42HDAG-CF97s255.js} +1 -1
  29. package/dist/web-ui/assets/{diagram-2AECGRRQ-B8zRoWWP.js → diagram-2AECGRRQ-Cf3bRRU7.js} +1 -1
  30. package/dist/web-ui/assets/{diagram-5GNKFQAL-CM3pWtYN.js → diagram-5GNKFQAL-DeWiUo-B.js} +1 -1
  31. package/dist/web-ui/assets/{diagram-KO2AKTUF-V7UmwGTe.js → diagram-KO2AKTUF-g2SF4uuK.js} +1 -1
  32. package/dist/web-ui/assets/{diagram-LMA3HP47-DG1RtUeD.js → diagram-LMA3HP47-jfceMN5q.js} +1 -1
  33. package/dist/web-ui/assets/{diagram-OG6HWLK6-BTwLdZJw.js → diagram-OG6HWLK6-CRN8tK4z.js} +1 -1
  34. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-BNXeXKHH.js → erDiagram-TEJ5UH35-DUTClqO1.js} +1 -1
  35. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-VP_sRWgd.js → flowDiagram-I6XJVG4X-miwyCuKa.js} +1 -1
  36. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CvnpoufX.js → ganttDiagram-6RSMTGT7-Co8Oe3L4.js} +1 -1
  37. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-zO7DNQqQ.js → gitGraphDiagram-PVQCEYII-VmIpxXAL.js} +1 -1
  38. package/dist/web-ui/assets/index-DegyOQC4.css +1 -0
  39. package/dist/web-ui/assets/{index-B1VN5yM1.js → index-sjnbPgLJ.js} +67 -67
  40. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-BSGbaVLq.js → infoDiagram-5YYISTIA-C4omrfgp.js} +1 -1
  41. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-BatvAQOH.js → ishikawaDiagram-YF4QCWOH-Ty2P769k.js} +1 -1
  42. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-Cajy4fZr.js → journeyDiagram-JHISSGLW-BKjERdBC.js} +1 -1
  43. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-DLpKR4E5.js → kanban-definition-UN3LZRKU-CKepooo8.js} +1 -1
  44. package/dist/web-ui/assets/{mermaid.core-B4fv65oQ.js → mermaid.core-86q0lHkP.js} +5 -5
  45. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-C2HVqxfu.js → mindmap-definition-RKZ34NQL-DHWtWZRN.js} +1 -1
  46. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-Bswg7SQl.js → pieDiagram-4H26LBE5-DkU1SDIf.js} +1 -1
  47. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-CyYiDqNE.js → quadrantDiagram-W4KKPZXB-DJHQgFEW.js} +1 -1
  48. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-BWZmKUo8.js → requirementDiagram-4Y6WPE33-D0PXuzjM.js} +1 -1
  49. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-C3imZVxk.js → sankeyDiagram-5OEKKPKP-D8ZU245D.js} +1 -1
  50. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-BrySebCt.js → sequenceDiagram-3UESZ5HK-BKUzkb7M.js} +1 -1
  51. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-0Lp5CycE.js → stateDiagram-AJRCARHV-hRMrLG3O.js} +1 -1
  52. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-CS0Tx8JL.js +1 -0
  53. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-BIGJbkoS.js → timeline-definition-PNZ67QCA-CDok_Xbq.js} +1 -1
  54. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-CS9GEvPk.js → vennDiagram-CIIHVFJN-BYWGyJ9q.js} +1 -1
  55. package/dist/web-ui/assets/{wardley-L42UT6IY-BSNtMxtd.js → wardley-L42UT6IY-DnhUtsUo.js} +1 -1
  56. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-CaEGOjwH.js → wardleyDiagram-YWT4CUSO-B--QBlgZ.js} +1 -1
  57. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-Cr_pwOHb.js → xychartDiagram-2RQKCTM6-CgFIWd7_.js} +1 -1
  58. package/dist/web-ui/index.html +2 -2
  59. package/package.json +1 -1
  60. package/dist/web-ui/assets/DeliverableShareModal-B6qqZgFc.js +0 -1
  61. package/dist/web-ui/assets/Deliverables-BUi9KGwf.js +0 -3
  62. package/dist/web-ui/assets/channel-C-TW97LX.js +0 -1
  63. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-C92nY4nN.js +0 -1
  64. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-C92nY4nN.js +0 -1
  65. package/dist/web-ui/assets/index-BbQpGkiM.css +0 -1
  66. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-QVZbqffU.js +0 -1
@@ -1,11 +1,11 @@
1
- import{x as Bl,y as zl,v as Hl,R as ql,r as g,j as t,u as We,l as ae,z as Wl,a as vr,k as Vl,b as Fl,c as Yl,m as Gl,d as _s,P as Fe,w as jt,B as _t,C as ys,p as Br,M as Kl,i as Zl,n as Bt,D as Hn,q as fr,E as Xl,A as Vs,F as Lo,G as Ls,H as Ao,J as As,K as Do,L as Po,O as $o,Q as Qa,U as Ja,V as Ul}from"./index-B1VN5yM1.js";import{ContentRenderer as Ql}from"./ContentRenderer-gaxBn1N9.js";import{s as gt,e as ei,f as Fs,T as vs,g as ws,t as Jl}from"./transform-CpIVI4vC.js";import{i as ks}from"./value-DIujSiJ7.js";import{C as ti}from"./CommentInput-JPZATTdP.js";function ec(e){let n;for(;n=e.sourceEvent;)e=n;return e}function Lt(e,n){if(e=ec(e),n===void 0&&(n=e.currentTarget),n){var s=n.ownerSVGElement||n;if(s.createSVGPoint){var r=s.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(n.getScreenCTM().inverse()),[r.x,r.y]}if(n.getBoundingClientRect){var i=n.getBoundingClientRect();return[e.clientX-i.left-n.clientLeft,e.clientY-i.top-n.clientTop]}}return[e.pageX,e.pageY]}const tc={passive:!1},hr={capture:!0,passive:!1};function js(e){e.stopImmediatePropagation()}function Fn(e){e.preventDefault(),e.stopImmediatePropagation()}function ni(e){var n=e.document.documentElement,s=gt(e).on("dragstart.drag",Fn,hr);"onselectstart"in n?s.on("selectstart.drag",Fn,hr):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function ri(e,n){var s=e.document.documentElement,r=gt(e).on("dragstart.drag",null);n&&(r.on("click.drag",Fn,hr),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in s?r.on("selectstart.drag",null):(s.style.MozUserSelect=s.__noselect,delete s.__noselect)}const zr=e=>()=>e;function Ds(e,{sourceEvent:n,subject:s,target:r,identifier:i,active:o,x:a,y:c,dx:l,dy:d,dispatch:h}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:s,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:a,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:h}})}Ds.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function nc(e){return!e.ctrlKey&&!e.button}function rc(){return this.parentNode}function sc(e,n){return n??{x:e.x,y:e.y}}function oc(){return navigator.maxTouchPoints||"ontouchstart"in this}function si(){var e=nc,n=rc,s=sc,r=oc,i={},o=ei("start","drag","end"),a=0,c,l,d,h,f=0;function m(b){b.on("mousedown.drag",u).filter(r).on("touchstart.drag",C).on("touchmove.drag",y,tc).on("touchend.drag touchcancel.drag",v).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(b,k){if(!(h||!e.call(this,b,k))){var N=x(this,n.call(this,b,k),b,k,"mouse");N&&(gt(b.view).on("mousemove.drag",p,hr).on("mouseup.drag",M,hr),ni(b.view),js(b),d=!1,c=b.clientX,l=b.clientY,N("start",b))}}function p(b){if(Fn(b),!d){var k=b.clientX-c,N=b.clientY-l;d=k*k+N*N>f}i.mouse("drag",b)}function M(b){gt(b.view).on("mousemove.drag mouseup.drag",null),ri(b.view,d),Fn(b),i.mouse("end",b)}function C(b,k){if(e.call(this,b,k)){var N=b.changedTouches,I=n.call(this,b,k),B=N.length,D,L;for(D=0;D<B;++D)(L=x(this,I,b,k,N[D].identifier,N[D]))&&(js(b),L("start",b,N[D]))}}function y(b){var k=b.changedTouches,N=k.length,I,B;for(I=0;I<N;++I)(B=i[k[I].identifier])&&(Fn(b),B("drag",b,k[I]))}function v(b){var k=b.changedTouches,N=k.length,I,B;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),I=0;I<N;++I)(B=i[k[I].identifier])&&(js(b),B("end",b,k[I]))}function x(b,k,N,I,B,D){var L=o.copy(),E=Lt(D||N,k),P,z,j;if((j=s.call(b,new Ds("beforestart",{sourceEvent:N,target:m,identifier:B,active:a,x:E[0],y:E[1],dx:0,dy:0,dispatch:L}),I))!=null)return P=j.x-E[0]||0,z=j.y-E[1]||0,function O(_,T,R){var A=E,q;switch(_){case"start":i[B]=O,q=a++;break;case"end":delete i[B],--a;case"drag":E=Lt(R||T,k),q=a;break}L.call(_,b,new Ds(_,{sourceEvent:T,subject:j,target:m,identifier:B,active:q,x:E[0]+P,y:E[1]+z,dx:E[0]-A[0],dy:E[1]-A[1],dispatch:L}),I)}}return m.filter=function(b){return arguments.length?(e=typeof b=="function"?b:zr(!!b),m):e},m.container=function(b){return arguments.length?(n=typeof b=="function"?b:zr(b),m):n},m.subject=function(b){return arguments.length?(s=typeof b=="function"?b:zr(b),m):s},m.touchable=function(b){return arguments.length?(r=typeof b=="function"?b:zr(!!b),m):r},m.on=function(){var b=o.on.apply(o,arguments);return b===o?m:b},m.clickDistance=function(b){return arguments.length?(f=(b=+b)*b,m):Math.sqrt(f)},m}var ac=1e-12;function Oo(e){return((e=Math.exp(e))+1/e)/2}function ic(e){return((e=Math.exp(e))-1/e)/2}function lc(e){return((e=Math.exp(2*e))-1)/(e+1)}const Xr=(function e(n,s,r){function i(o,a){var c=o[0],l=o[1],d=o[2],h=a[0],f=a[1],m=a[2],u=h-c,p=f-l,M=u*u+p*p,C,y;if(M<ac)y=Math.log(m/d)/n,C=function(I){return[c+I*u,l+I*p,d*Math.exp(n*I*y)]};else{var v=Math.sqrt(M),x=(m*m-d*d+r*M)/(2*d*s*v),b=(m*m-d*d-r*M)/(2*m*s*v),k=Math.log(Math.sqrt(x*x+1)-x),N=Math.log(Math.sqrt(b*b+1)-b);y=(N-k)/n,C=function(I){var B=I*y,D=Oo(k),L=d/(s*v)*(D*lc(n*B+k)-ic(k));return[c+L*u,l+L*p,d*D/Oo(n*B+k)]}}return C.duration=y*1e3*n/Math.SQRT2,C}return i.rho=function(o){var a=Math.max(.001,+o),c=a*a,l=c*c;return e(a,c,l)},i})(Math.SQRT2,2,4),Hr=e=>()=>e;function cc(e,{sourceEvent:n,target:s,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:s,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function Ns(e){e.stopImmediatePropagation()}function lr(e){e.preventDefault(),e.stopImmediatePropagation()}function dc(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function uc(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Bo(){return this.__zoom||Fs}function fc(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function hc(){return navigator.maxTouchPoints||"ontouchstart"in this}function mc(e,n,s){var r=e.invertX(n[0][0])-s[0][0],i=e.invertX(n[1][0])-s[1][0],o=e.invertY(n[0][1])-s[0][1],a=e.invertY(n[1][1])-s[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),a>o?(o+a)/2:Math.min(0,o)||Math.max(0,a))}function oi(){var e=dc,n=uc,s=mc,r=fc,i=hc,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],c=250,l=Xr,d=ei("start","zoom","end"),h,f,m,u=500,p=150,M=0,C=10;function y(j){j.property("__zoom",Bo).on("wheel.zoom",B,{passive:!1}).on("mousedown.zoom",D).on("dblclick.zoom",L).filter(i).on("touchstart.zoom",E).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}y.transform=function(j,O,_,T){var R=j.selection?j.selection():j;R.property("__zoom",Bo),j!==R?k(j,O,_,T):R.interrupt().each(function(){N(this,arguments).event(T).start().zoom(null,typeof O=="function"?O.apply(this,arguments):O).end()})},y.scaleBy=function(j,O,_,T){y.scaleTo(j,function(){var R=this.__zoom.k,A=typeof O=="function"?O.apply(this,arguments):O;return R*A},_,T)},y.scaleTo=function(j,O,_,T){y.transform(j,function(){var R=n.apply(this,arguments),A=this.__zoom,q=_==null?b(R):typeof _=="function"?_.apply(this,arguments):_,Y=A.invert(q),F=typeof O=="function"?O.apply(this,arguments):O;return s(x(v(A,F),q,Y),R,a)},_,T)},y.translateBy=function(j,O,_,T){y.transform(j,function(){return s(this.__zoom.translate(typeof O=="function"?O.apply(this,arguments):O,typeof _=="function"?_.apply(this,arguments):_),n.apply(this,arguments),a)},null,T)},y.translateTo=function(j,O,_,T,R){y.transform(j,function(){var A=n.apply(this,arguments),q=this.__zoom,Y=T==null?b(A):typeof T=="function"?T.apply(this,arguments):T;return s(Fs.translate(Y[0],Y[1]).scale(q.k).translate(typeof O=="function"?-O.apply(this,arguments):-O,typeof _=="function"?-_.apply(this,arguments):-_),A,a)},T,R)};function v(j,O){return O=Math.max(o[0],Math.min(o[1],O)),O===j.k?j:new vs(O,j.x,j.y)}function x(j,O,_){var T=O[0]-_[0]*j.k,R=O[1]-_[1]*j.k;return T===j.x&&R===j.y?j:new vs(j.k,T,R)}function b(j){return[(+j[0][0]+ +j[1][0])/2,(+j[0][1]+ +j[1][1])/2]}function k(j,O,_,T){j.on("start.zoom",function(){N(this,arguments).event(T).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(T).end()}).tween("zoom",function(){var R=this,A=arguments,q=N(R,A).event(T),Y=n.apply(R,A),F=_==null?b(Y):typeof _=="function"?_.apply(R,A):_,Q=Math.max(Y[1][0]-Y[0][0],Y[1][1]-Y[0][1]),$=R.__zoom,S=typeof O=="function"?O.apply(R,A):O,V=l($.invert(F).concat(Q/$.k),S.invert(F).concat(Q/S.k));return function(W){if(W===1)W=S;else{var H=V(W),Z=Q/H[2];W=new vs(Z,F[0]-H[0]*Z,F[1]-H[1]*Z)}q.zoom(null,W)}})}function N(j,O,_){return!_&&j.__zooming||new I(j,O)}function I(j,O){this.that=j,this.args=O,this.active=0,this.sourceEvent=null,this.extent=n.apply(j,O),this.taps=0}I.prototype={event:function(j){return j&&(this.sourceEvent=j),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(j,O){return this.mouse&&j!=="mouse"&&(this.mouse[1]=O.invert(this.mouse[0])),this.touch0&&j!=="touch"&&(this.touch0[1]=O.invert(this.touch0[0])),this.touch1&&j!=="touch"&&(this.touch1[1]=O.invert(this.touch1[0])),this.that.__zoom=O,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(j){var O=gt(this.that).datum();d.call(j,this.that,new cc(j,{sourceEvent:this.sourceEvent,target:y,transform:this.that.__zoom,dispatch:d}),O)}};function B(j,...O){if(!e.apply(this,arguments))return;var _=N(this,O).event(j),T=this.__zoom,R=Math.max(o[0],Math.min(o[1],T.k*Math.pow(2,r.apply(this,arguments)))),A=Lt(j);if(_.wheel)(_.mouse[0][0]!==A[0]||_.mouse[0][1]!==A[1])&&(_.mouse[1]=T.invert(_.mouse[0]=A)),clearTimeout(_.wheel);else{if(T.k===R)return;_.mouse=[A,T.invert(A)],ws(this),_.start()}lr(j),_.wheel=setTimeout(q,p),_.zoom("mouse",s(x(v(T,R),_.mouse[0],_.mouse[1]),_.extent,a));function q(){_.wheel=null,_.end()}}function D(j,...O){if(m||!e.apply(this,arguments))return;var _=j.currentTarget,T=N(this,O,!0).event(j),R=gt(j.view).on("mousemove.zoom",F,!0).on("mouseup.zoom",Q,!0),A=Lt(j,_),q=j.clientX,Y=j.clientY;ni(j.view),Ns(j),T.mouse=[A,this.__zoom.invert(A)],ws(this),T.start();function F($){if(lr($),!T.moved){var S=$.clientX-q,V=$.clientY-Y;T.moved=S*S+V*V>M}T.event($).zoom("mouse",s(x(T.that.__zoom,T.mouse[0]=Lt($,_),T.mouse[1]),T.extent,a))}function Q($){R.on("mousemove.zoom mouseup.zoom",null),ri($.view,T.moved),lr($),T.event($).end()}}function L(j,...O){if(e.apply(this,arguments)){var _=this.__zoom,T=Lt(j.changedTouches?j.changedTouches[0]:j,this),R=_.invert(T),A=_.k*(j.shiftKey?.5:2),q=s(x(v(_,A),T,R),n.apply(this,O),a);lr(j),c>0?gt(this).transition().duration(c).call(k,q,T,j):gt(this).call(y.transform,q,T,j)}}function E(j,...O){if(e.apply(this,arguments)){var _=j.touches,T=_.length,R=N(this,O,j.changedTouches.length===T).event(j),A,q,Y,F;for(Ns(j),q=0;q<T;++q)Y=_[q],F=Lt(Y,this),F=[F,this.__zoom.invert(F),Y.identifier],R.touch0?!R.touch1&&R.touch0[2]!==F[2]&&(R.touch1=F,R.taps=0):(R.touch0=F,A=!0,R.taps=1+!!h);h&&(h=clearTimeout(h)),A&&(R.taps<2&&(f=F[0],h=setTimeout(function(){h=null},u)),ws(this),R.start())}}function P(j,...O){if(this.__zooming){var _=N(this,O).event(j),T=j.changedTouches,R=T.length,A,q,Y,F;for(lr(j),A=0;A<R;++A)q=T[A],Y=Lt(q,this),_.touch0&&_.touch0[2]===q.identifier?_.touch0[0]=Y:_.touch1&&_.touch1[2]===q.identifier&&(_.touch1[0]=Y);if(q=_.that.__zoom,_.touch1){var Q=_.touch0[0],$=_.touch0[1],S=_.touch1[0],V=_.touch1[1],W=(W=S[0]-Q[0])*W+(W=S[1]-Q[1])*W,H=(H=V[0]-$[0])*H+(H=V[1]-$[1])*H;q=v(q,Math.sqrt(W/H)),Y=[(Q[0]+S[0])/2,(Q[1]+S[1])/2],F=[($[0]+V[0])/2,($[1]+V[1])/2]}else if(_.touch0)Y=_.touch0[0],F=_.touch0[1];else return;_.zoom("touch",s(x(q,Y,F),_.extent,a))}}function z(j,...O){if(this.__zooming){var _=N(this,O).event(j),T=j.changedTouches,R=T.length,A,q;for(Ns(j),m&&clearTimeout(m),m=setTimeout(function(){m=null},u),A=0;A<R;++A)q=T[A],_.touch0&&_.touch0[2]===q.identifier?delete _.touch0:_.touch1&&_.touch1[2]===q.identifier&&delete _.touch1;if(_.touch1&&!_.touch0&&(_.touch0=_.touch1,delete _.touch1),_.touch0)_.touch0[1]=this.__zoom.invert(_.touch0[0]);else if(_.end(),_.taps===2&&(q=Lt(q,this),Math.hypot(f[0]-q[0],f[1]-q[1])<C)){var Y=gt(this).on("dblclick.zoom");Y&&Y.apply(this,arguments)}}}return y.wheelDelta=function(j){return arguments.length?(r=typeof j=="function"?j:Hr(+j),y):r},y.filter=function(j){return arguments.length?(e=typeof j=="function"?j:Hr(!!j),y):e},y.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:Hr(!!j),y):i},y.extent=function(j){return arguments.length?(n=typeof j=="function"?j:Hr([[+j[0][0],+j[0][1]],[+j[1][0],+j[1][1]]]),y):n},y.scaleExtent=function(j){return arguments.length?(o[0]=+j[0],o[1]=+j[1],y):[o[0],o[1]]},y.translateExtent=function(j){return arguments.length?(a[0][0]=+j[0][0],a[1][0]=+j[1][0],a[0][1]=+j[0][1],a[1][1]=+j[1][1],y):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},y.constrain=function(j){return arguments.length?(s=j,y):s},y.duration=function(j){return arguments.length?(c=+j,y):c},y.interpolate=function(j){return arguments.length?(l=j,y):l},y.on=function(){var j=d.on.apply(d,arguments);return j===d?y:j},y.clickDistance=function(j){return arguments.length?(M=(j=+j)*j,y):Math.sqrt(M)},y.tapDistance=function(j){return arguments.length?(C=+j,y):C},y}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 zt={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:n,sourceHandle:s,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?s:r}", edge id: ${n}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},mr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ai=["Enter"," ","Escape"],ii={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:n,y:s})=>`Moved selected node ${e}. New position, x: ${n}, y: ${s}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Yn;(function(e){e.Strict="strict",e.Loose="loose"})(Yn||(Yn={}));var Cn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Cn||(Cn={}));var gr;(function(e){e.Partial="partial",e.Full="full"})(gr||(gr={}));const li={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var ln;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(ln||(ln={}));var Gn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Gn||(Gn={}));var be;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(be||(be={}));const zo={[be.Left]:be.Right,[be.Right]:be.Left,[be.Top]:be.Bottom,[be.Bottom]:be.Top};function ci(e){return e===null?null:e?"valid":"invalid"}const di=e=>"id"in e&&"source"in e&&"target"in e,gc=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Ys=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),wr=(e,n=[0,0])=>{const{width:s,height:r}=Qt(e),i=e.origin??n,o=s*i[0],a=r*i[1];return{x:e.position.x-o,y:e.position.y-a}},pc=(e,n={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const s=e.reduce((r,i)=>{const o=typeof i=="string";let a=!n.nodeLookup&&!o?i:void 0;n.nodeLookup&&(a=o?n.nodeLookup.get(i):Ys(i)?i:n.nodeLookup.get(i.id));const c=a?es(a,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return as(r,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return is(s)},kr=(e,n={})=>{let s={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(i=>{(n.filter===void 0||n.filter(i))&&(s=as(s,es(i)),r=!0)}),r?is(s):{x:0,y:0,width:0,height:0}},Gs=(e,n,[s,r,i]=[0,0,1],o=!1,a=!1)=>{const c={...Nr(n,[s,r,i]),width:n.width/i,height:n.height/i},l=[];for(const d of e.values()){const{measured:h,selectable:f=!0,hidden:m=!1}=d;if(a&&!f||m)continue;const u=h.width??d.width??d.initialWidth??null,p=h.height??d.height??d.initialHeight??null,M=pr(c,Zn(d)),C=(u??0)*(p??0),y=o&&M>0;(!d.internals.handleBounds||y||M>=C||d.dragging)&&l.push(d)}return l},xc=(e,n)=>{const s=new Set;return e.forEach(r=>{s.add(r.id)}),n.filter(r=>s.has(r.source)||s.has(r.target))};function bc(e,n){const s=new Map,r=n?.nodes?new Set(n.nodes.map(i=>i.id)):null;return e.forEach(i=>{i.measured.width&&i.measured.height&&(n?.includeHiddenNodes||!i.hidden)&&(!r||r.has(i.id))&&s.set(i.id,i)}),s}async function yc({nodes:e,width:n,height:s,panZoom:r,minZoom:i,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const c=bc(e,a),l=kr(c),d=Ks(l,n,s,a?.minZoom??i,a?.maxZoom??o,a?.padding??.1);return await r.setViewport(d,{duration:a?.duration,ease:a?.ease,interpolate:a?.interpolate}),Promise.resolve(!0)}function ui({nodeId:e,nextPosition:n,nodeLookup:s,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const a=s.get(e),c=a.parentId?s.get(a.parentId):void 0,{x:l,y:d}=c?c.internals.positionAbsolute:{x:0,y:0},h=a.origin??r;let f=a.extent||i;if(a.extent==="parent"&&!a.expandParent)if(!c)o?.("005",zt.error005());else{const u=c.measured.width,p=c.measured.height;u&&p&&(f=[[l,d],[l+u,d+p]])}else c&&Xn(a.extent)&&(f=[[a.extent[0][0]+l,a.extent[0][1]+d],[a.extent[1][0]+l,a.extent[1][1]+d]]);const m=Xn(f)?Sn(n,f,a.measured):n;return(a.measured.width===void 0||a.measured.height===void 0)&&o?.("015",zt.error015()),{position:{x:m.x-l+(a.measured.width??0)*h[0],y:m.y-d+(a.measured.height??0)*h[1]},positionAbsolute:m}}async function vc({nodesToRemove:e=[],edgesToRemove:n=[],nodes:s,edges:r,onBeforeDelete:i}){const o=new Set(e.map(m=>m.id)),a=[];for(const m of s){if(m.deletable===!1)continue;const u=o.has(m.id),p=!u&&m.parentId&&a.find(M=>M.id===m.parentId);(u||p)&&a.push(m)}const c=new Set(n.map(m=>m.id)),l=r.filter(m=>m.deletable!==!1),h=xc(a,l);for(const m of l)c.has(m.id)&&!h.find(p=>p.id===m.id)&&h.push(m);if(!i)return{edges:h,nodes:a};const f=await i({nodes:a,edges:h});return typeof f=="boolean"?f?{edges:h,nodes:a}:{edges:[],nodes:[]}:f}const Kn=(e,n=0,s=1)=>Math.min(Math.max(e,n),s),Sn=(e={x:0,y:0},n,s)=>({x:Kn(e.x,n[0][0],n[1][0]-(s?.width??0)),y:Kn(e.y,n[0][1],n[1][1]-(s?.height??0))});function fi(e,n,s){const{width:r,height:i}=Qt(s),{x:o,y:a}=s.internals.positionAbsolute;return Sn(e,[[o,a],[o+r,a+i]],n)}const Ho=(e,n,s)=>e<n?Kn(Math.abs(e-n),1,n)/n:e>s?-Kn(Math.abs(e-s),1,n)/n:0,hi=(e,n,s=15,r=40)=>{const i=Ho(e.x,r,n.width-r)*s,o=Ho(e.y,r,n.height-r)*s;return[i,o]},as=(e,n)=>({x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),x2:Math.max(e.x2,n.x2),y2:Math.max(e.y2,n.y2)}),Ps=({x:e,y:n,width:s,height:r})=>({x:e,y:n,x2:e+s,y2:n+r}),is=({x:e,y:n,x2:s,y2:r})=>({x:e,y:n,width:s-e,height:r-n}),Zn=(e,n=[0,0])=>{const{x:s,y:r}=Ys(e)?e.internals.positionAbsolute:wr(e,n);return{x:s,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},es=(e,n=[0,0])=>{const{x:s,y:r}=Ys(e)?e.internals.positionAbsolute:wr(e,n);return{x:s,y:r,x2:s+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},mi=(e,n)=>is(as(Ps(e),Ps(n))),pr=(e,n)=>{const s=Math.max(0,Math.min(e.x+e.width,n.x+n.width)-Math.max(e.x,n.x)),r=Math.max(0,Math.min(e.y+e.height,n.y+n.height)-Math.max(e.y,n.y));return Math.ceil(s*r)},qo=e=>At(e.width)&&At(e.height)&&At(e.x)&&At(e.y),At=e=>!isNaN(e)&&isFinite(e),wc=(e,n)=>{},jr=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),Nr=({x:e,y:n},[s,r,i],o=!1,a=[1,1])=>{const c={x:(e-s)/i,y:(n-r)/i};return o?jr(c,a):c},ts=({x:e,y:n},[s,r,i])=>({x:e*i+s,y:n*i+r});function zn(e,n){if(typeof e=="number")return Math.floor((n-n/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const s=parseFloat(e);if(!Number.isNaN(s))return Math.floor(s)}if(typeof e=="string"&&e.endsWith("%")){const s=parseFloat(e);if(!Number.isNaN(s))return Math.floor(n*s*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function kc(e,n,s){if(typeof e=="string"||typeof e=="number"){const r=zn(e,s),i=zn(e,n);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=zn(e.top??e.y??0,s),i=zn(e.bottom??e.y??0,s),o=zn(e.left??e.x??0,n),a=zn(e.right??e.x??0,n);return{top:r,right:a,bottom:i,left:o,x:o+a,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function jc(e,n,s,r,i,o){const{x:a,y:c}=ts(e,[n,s,r]),{x:l,y:d}=ts({x:e.x+e.width,y:e.y+e.height},[n,s,r]),h=i-l,f=o-d;return{left:Math.floor(a),top:Math.floor(c),right:Math.floor(h),bottom:Math.floor(f)}}const Ks=(e,n,s,r,i,o)=>{const a=kc(o,n,s),c=(n-a.x)/e.width,l=(s-a.y)/e.height,d=Math.min(c,l),h=Kn(d,r,i),f=e.x+e.width/2,m=e.y+e.height/2,u=n/2-f*h,p=s/2-m*h,M=jc(e,u,p,h,n,s),C={left:Math.min(M.left-a.left,0),top:Math.min(M.top-a.top,0),right:Math.min(M.right-a.right,0),bottom:Math.min(M.bottom-a.bottom,0)};return{x:u-C.left+C.right,y:p-C.top+C.bottom,zoom:h}},xr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Xn(e){return e!=null&&e!=="parent"}function Qt(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function gi(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function pi(e,n={width:0,height:0},s,r,i){const o={...e},a=r.get(s);if(a){const c=a.origin||i;o.x+=a.internals.positionAbsolute.x-(n.width??0)*c[0],o.y+=a.internals.positionAbsolute.y-(n.height??0)*c[1]}return o}function Wo(e,n){if(e.size!==n.size)return!1;for(const s of e)if(!n.has(s))return!1;return!0}function Nc(){let e,n;return{promise:new Promise((r,i)=>{e=r,n=i}),resolve:e,reject:n}}function Cc(e){return{...ii,...e||{}}}function dr(e,{snapGrid:n=[0,0],snapToGrid:s=!1,transform:r,containerBounds:i}){const{x:o,y:a}=Dt(e),c=Nr({x:o-(i?.left??0),y:a-(i?.top??0)},r),{x:l,y:d}=s?jr(c,n):c;return{xSnapped:l,ySnapped:d,...c}}const Zs=e=>({width:e.offsetWidth,height:e.offsetHeight}),xi=e=>e?.getRootNode?.()||window?.document,Sc=["INPUT","SELECT","TEXTAREA"];function bi(e){const n=e.composedPath?.()?.[0]||e.target;return n?.nodeType!==1?!1:Sc.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const yi=e=>"clientX"in e,Dt=(e,n)=>{const s=yi(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)}},Vo=(e,n,s,r,i)=>{const o=n.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const c=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:i,position:a.getAttribute("data-handlepos"),x:(c.left-s.left)/r,y:(c.top-s.top)/r,...Zs(a)}})};function vi({sourceX:e,sourceY:n,targetX:s,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:a,targetControlY:c}){const l=e*.125+i*.375+a*.375+s*.125,d=n*.125+o*.375+c*.375+r*.125,h=Math.abs(l-e),f=Math.abs(d-n);return[l,d,h,f]}function qr(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function Fo({pos:e,x1:n,y1:s,x2:r,y2:i,c:o}){switch(e){case be.Left:return[n-qr(n-r,o),s];case be.Right:return[n+qr(r-n,o),s];case be.Top:return[n,s-qr(s-i,o)];case be.Bottom:return[n,s+qr(i-s,o)]}}function wi({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top,curvature:a=.25}){const[c,l]=Fo({pos:s,x1:e,y1:n,x2:r,y2:i,c:a}),[d,h]=Fo({pos:o,x1:r,y1:i,x2:e,y2:n,c:a}),[f,m,u,p]=vi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:c,sourceControlY:l,targetControlX:d,targetControlY:h});return[`M${e},${n} C${c},${l} ${d},${h} ${r},${i}`,f,m,u,p]}function ki({sourceX:e,sourceY:n,targetX:s,targetY:r}){const i=Math.abs(s-e)/2,o=s<e?s+i:s-i,a=Math.abs(r-n)/2,c=r<n?r+a:r-a;return[o,c,i,a]}function Ec({sourceNode:e,targetNode:n,selected:s=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const a=i&&s?r+1e3:r,c=Math.max(e.parentId||i&&e.selected?e.internals.z:0,n.parentId||i&&n.selected?n.internals.z:0);return a+c}function Mc({sourceNode:e,targetNode:n,width:s,height:r,transform:i}){const o=as(es(e),es(n));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const a={x:-i[0]/i[2],y:-i[1]/i[2],width:s/i[2],height:r/i[2]};return pr(a,is(o))>0}const Ic=({source:e,sourceHandle:n,target:s,targetHandle:r})=>`xy-edge__${e}${n||""}-${s}${r||""}`,Tc=(e,n)=>n.some(s=>s.source===e.source&&s.target===e.target&&(s.sourceHandle===e.sourceHandle||!s.sourceHandle&&!e.sourceHandle)&&(s.targetHandle===e.targetHandle||!s.targetHandle&&!e.targetHandle)),Rc=(e,n,s={})=>{if(!e.source||!e.target)return n;const r=s.getEdgeId||Ic;let i;return di(e)?i={...e}:i={...e,id:r(e)},Tc(i,n)?n:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,n.concat(i))};function ji({sourceX:e,sourceY:n,targetX:s,targetY:r}){const[i,o,a,c]=ki({sourceX:e,sourceY:n,targetX:s,targetY:r});return[`M ${e},${n}L ${s},${r}`,i,o,a,c]}const Yo={[be.Left]:{x:-1,y:0},[be.Right]:{x:1,y:0},[be.Top]:{x:0,y:-1},[be.Bottom]:{x:0,y:1}},_c=({source:e,sourcePosition:n=be.Bottom,target:s})=>n===be.Left||n===be.Right?e.x<s.x?{x:1,y:0}:{x:-1,y:0}:e.y<s.y?{x:0,y:1}:{x:0,y:-1},Go=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function Lc({source:e,sourcePosition:n=be.Bottom,target:s,targetPosition:r=be.Top,center:i,offset:o,stepPosition:a}){const c=Yo[n],l=Yo[r],d={x:e.x+c.x*o,y:e.y+c.y*o},h={x:s.x+l.x*o,y:s.y+l.y*o},f=_c({source:d,sourcePosition:n,target:h}),m=f.x!==0?"x":"y",u=f[m];let p=[],M,C;const y={x:0,y:0},v={x:0,y:0},[,,x,b]=ki({sourceX:e.x,sourceY:e.y,targetX:s.x,targetY:s.y});if(c[m]*l[m]===-1){m==="x"?(M=i.x??d.x+(h.x-d.x)*a,C=i.y??(d.y+h.y)/2):(M=i.x??(d.x+h.x)/2,C=i.y??d.y+(h.y-d.y)*a);const N=[{x:M,y:d.y},{x:M,y:h.y}],I=[{x:d.x,y:C},{x:h.x,y:C}];c[m]===u?p=m==="x"?N:I:p=m==="x"?I:N}else{const N=[{x:d.x,y:h.y}],I=[{x:h.x,y:d.y}];if(m==="x"?p=c.x===u?I:N:p=c.y===u?N:I,n===r){const P=Math.abs(e[m]-s[m]);if(P<=o){const z=Math.min(o-1,o-P);c[m]===u?y[m]=(d[m]>e[m]?-1:1)*z:v[m]=(h[m]>s[m]?-1:1)*z}}if(n!==r){const P=m==="x"?"y":"x",z=c[m]===l[P],j=d[P]>h[P],O=d[P]<h[P];(c[m]===1&&(!z&&j||z&&O)||c[m]!==1&&(!z&&O||z&&j))&&(p=m==="x"?N:I)}const B={x:d.x+y.x,y:d.y+y.y},D={x:h.x+v.x,y:h.y+v.y},L=Math.max(Math.abs(B.x-p[0].x),Math.abs(D.x-p[0].x)),E=Math.max(Math.abs(B.y-p[0].y),Math.abs(D.y-p[0].y));L>=E?(M=(B.x+D.x)/2,C=p[0].y):(M=p[0].x,C=(B.y+D.y)/2)}return[[e,{x:d.x+y.x,y:d.y+y.y},...p,{x:h.x+v.x,y:h.y+v.y},s],M,C,x,b]}function Ac(e,n,s,r){const i=Math.min(Go(e,n)/2,Go(n,s)/2,r),{x:o,y:a}=n;if(e.x===o&&o===s.x||e.y===a&&a===s.y)return`L${o} ${a}`;if(e.y===a){const d=e.x<s.x?-1:1,h=e.y<s.y?1:-1;return`L ${o+i*d},${a}Q ${o},${a} ${o},${a+i*h}`}const c=e.x<s.x?1:-1,l=e.y<s.y?-1:1;return`L ${o},${a+i*l}Q ${o},${a} ${o+i*c},${a}`}function $s({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top,borderRadius:a=5,centerX:c,centerY:l,offset:d=20,stepPosition:h=.5}){const[f,m,u,p,M]=Lc({source:{x:e,y:n},sourcePosition:s,target:{x:r,y:i},targetPosition:o,center:{x:c,y:l},offset:d,stepPosition:h});return[f.reduce((y,v,x)=>{let b="";return x>0&&x<f.length-1?b=Ac(f[x-1],v,f[x+1],a):b=`${x===0?"M":"L"}${v.x} ${v.y}`,y+=b,y},""),m,u,p,M]}function Ko(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Dc(e){const{sourceNode:n,targetNode:s}=e;if(!Ko(n)||!Ko(s))return null;const r=n.internals.handleBounds||Zo(n.handles),i=s.internals.handleBounds||Zo(s.handles),o=Xo(r?.source??[],e.sourceHandle),a=Xo(e.connectionMode===Yn.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!a)return e.onError?.("008",zt.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const c=o?.position||be.Bottom,l=a?.position||be.Top,d=En(n,o,c),h=En(s,a,l);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:c,targetPosition:l}}function Zo(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 En(e,n,s=be.Left,r=!1){const i=(n?.x??0)+e.internals.positionAbsolute.x,o=(n?.y??0)+e.internals.positionAbsolute.y,{width:a,height:c}=n??Qt(e);if(r)return{x:i+a/2,y:o+c/2};switch(n?.position??s){case be.Top:return{x:i+a/2,y:o};case be.Right:return{x:i+a,y:o+c/2};case be.Bottom:return{x:i+a/2,y:o+c};case be.Left:return{x:i,y:o+c/2}}}function Xo(e,n){return e&&(n?e.find(s=>s.id===n):e[0])||null}function Os(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function Pc(e,{id:n,defaultColor:s,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((a,c)=>([c.markerStart||r,c.markerEnd||i].forEach(l=>{if(l&&typeof l=="object"){const d=Os(l,n);o.has(d)||(a.push({id:d,color:l.color||s,...l}),o.add(d))}}),a),[]).sort((a,c)=>a.id.localeCompare(c.id))}const Ni=1e3,$c=10,Xs={nodeOrigin:[0,0],nodeExtent:mr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Oc={...Xs,checkEquality:!0};function Us(e,n){const s={...e};for(const r in n)n[r]!==void 0&&(s[r]=n[r]);return s}function Bc(e,n,s){const r=Us(Xs,s);for(const i of e.values())if(i.parentId)Js(i,e,n,r);else{const o=wr(i,r.nodeOrigin),a=Xn(i.extent)?i.extent:r.nodeExtent,c=Sn(o,a,Qt(i));i.internals.positionAbsolute=c}}function zc(e,n){if(!e.handles)return e.measured?n?.internals.handleBounds:void 0;const s=[],r=[];for(const i of e.handles){const o={id:i.id,width:i.width??1,height:i.height??1,nodeId:e.id,x:i.x,y:i.y,position:i.position,type:i.type};i.type==="source"?s.push(o):i.type==="target"&&r.push(o)}return{source:s,target:r}}function Qs(e){return e==="manual"}function Bs(e,n,s,r={}){const i=Us(Oc,r),o={i:0},a=new Map(n),c=i?.elevateNodesOnSelect&&!Qs(i.zIndexMode)?Ni:0;let l=e.length>0;n.clear(),s.clear();for(const d of e){let h=a.get(d.id);if(i.checkEquality&&d===h?.internals.userNode)n.set(d.id,h);else{const f=wr(d,i.nodeOrigin),m=Xn(d.extent)?d.extent:i.nodeExtent,u=Sn(f,m,Qt(d));h={...i.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:u,handleBounds:zc(d,h),z:Ci(d,c,i.zIndexMode),userNode:d}},n.set(d.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(l=!1),d.parentId&&Js(h,n,s,r,o)}return l}function Hc(e,n){if(!e.parentId)return;const s=n.get(e.parentId);s?s.set(e.id,e):n.set(e.parentId,new Map([[e.id,e]]))}function Js(e,n,s,r,i){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:c,zIndexMode:l}=Us(Xs,r),d=e.parentId,h=n.get(d);if(!h){console.warn(`Parent node ${d} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Hc(e,s),i&&!h.parentId&&h.internals.rootParentIndex===void 0&&l==="auto"&&(h.internals.rootParentIndex=++i.i,h.internals.z=h.internals.z+i.i*$c),i&&h.internals.rootParentIndex!==void 0&&(i.i=h.internals.rootParentIndex);const f=o&&!Qs(l)?Ni:0,{x:m,y:u,z:p}=qc(e,h,a,c,f,l),{positionAbsolute:M}=e.internals,C=m!==M.x||u!==M.y;(C||p!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:C?{x:m,y:u}:M,z:p}})}function Ci(e,n,s){const r=At(e.zIndex)?e.zIndex:0;return Qs(s)?r:r+(e.selected?n:0)}function qc(e,n,s,r,i,o){const{x:a,y:c}=n.internals.positionAbsolute,l=Qt(e),d=wr(e,s),h=Xn(e.extent)?Sn(d,e.extent,l):d;let f=Sn({x:a+h.x,y:c+h.y},r,l);e.extent==="parent"&&(f=fi(f,l,n));const m=Ci(e,i,o),u=n.internals.z??0;return{x:f.x,y:f.y,z:u>=m?u+1:m}}function eo(e,n,s,r=[0,0]){const i=[],o=new Map;for(const a of e){const c=n.get(a.parentId);if(!c)continue;const l=o.get(a.parentId)?.expandedRect??Zn(c),d=mi(l,a.rect);o.set(a.parentId,{expandedRect:d,parent:c})}return o.size>0&&o.forEach(({expandedRect:a,parent:c},l)=>{const d=c.internals.positionAbsolute,h=Qt(c),f=c.origin??r,m=a.x<d.x?Math.round(Math.abs(d.x-a.x)):0,u=a.y<d.y?Math.round(Math.abs(d.y-a.y)):0,p=Math.max(h.width,Math.round(a.width)),M=Math.max(h.height,Math.round(a.height)),C=(p-h.width)*f[0],y=(M-h.height)*f[1];(m>0||u>0||C||y)&&(i.push({id:l,type:"position",position:{x:c.position.x-m+C,y:c.position.y-u+y}}),s.get(l)?.forEach(v=>{e.some(x=>x.id===v.id)||i.push({id:v.id,type:"position",position:{x:v.position.x+m,y:v.position.y+u}})})),(h.width<a.width||h.height<a.height||m||u)&&i.push({id:l,type:"dimensions",setAttributes:!0,dimensions:{width:p+(m?f[0]*m-C:0),height:M+(u?f[1]*u-y:0)}})}),i}function Wc(e,n,s,r,i,o,a){const c=r?.querySelector(".xyflow__viewport");let l=!1;if(!c)return{changes:[],updatedInternals:l};const d=[],h=window.getComputedStyle(c),{m22:f}=new window.DOMMatrixReadOnly(h.transform),m=[];for(const u of e.values()){const p=n.get(u.id);if(!p)continue;if(p.hidden){n.set(p.id,{...p,internals:{...p.internals,handleBounds:void 0}}),l=!0;continue}const M=Zs(u.nodeElement),C=p.measured.width!==M.width||p.measured.height!==M.height;if(!!(M.width&&M.height&&(C||!p.internals.handleBounds||u.force))){const v=u.nodeElement.getBoundingClientRect(),x=Xn(p.extent)?p.extent:o;let{positionAbsolute:b}=p.internals;p.parentId&&p.extent==="parent"?b=fi(b,M,n.get(p.parentId)):x&&(b=Sn(b,x,M));const k={...p,measured:M,internals:{...p.internals,positionAbsolute:b,handleBounds:{source:Vo("source",u.nodeElement,v,f,p.id),target:Vo("target",u.nodeElement,v,f,p.id)}}};n.set(p.id,k),p.parentId&&Js(k,n,s,{nodeOrigin:i,zIndexMode:a}),l=!0,C&&(d.push({id:p.id,type:"dimensions",dimensions:M}),p.expandParent&&p.parentId&&m.push({id:p.id,parentId:p.parentId,rect:Zn(k,i)}))}}if(m.length>0){const u=eo(m,n,s,i);d.push(...u)}return{changes:d,updatedInternals:l}}async function Vc({delta:e,panZoom:n,transform:s,translateExtent:r,width:i,height:o}){if(!n||!e.x&&!e.y)return Promise.resolve(!1);const a=await n.setViewportConstrained({x:s[0]+e.x,y:s[1]+e.y,zoom:s[2]},[[0,0],[i,o]],r),c=!!a&&(a.x!==s[0]||a.y!==s[1]||a.k!==s[2]);return Promise.resolve(c)}function Uo(e,n,s,r,i,o){let a=i;const c=r.get(a)||new Map;r.set(a,c.set(s,n)),a=`${i}-${e}`;const l=r.get(a)||new Map;if(r.set(a,l.set(s,n)),o){a=`${i}-${e}-${o}`;const d=r.get(a)||new Map;r.set(a,d.set(s,n))}}function Si(e,n,s){e.clear(),n.clear();for(const r of s){const{source:i,target:o,sourceHandle:a=null,targetHandle:c=null}=r,l={edgeId:r.id,source:i,target:o,sourceHandle:a,targetHandle:c},d=`${i}-${a}--${o}-${c}`,h=`${o}-${c}--${i}-${a}`;Uo("source",l,h,e,i,a),Uo("target",l,d,e,o,c),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 Qo(e,n,s){let r=e;do{if(r?.matches?.(n))return!0;if(r===s)return!1;r=r?.parentElement}while(r);return!1}function Fc(e,n,s,r){const i=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!Ei(a,e))&&(a.draggable||n&&typeof a.draggable>"u")){const c=e.get(o);c&&i.set(o,{id:o,position:c.position||{x:0,y:0},distance:{x:s.x-c.internals.positionAbsolute.x,y:s.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:c.measured.width??0,height:c.measured.height??0}})}return i}function Cs({nodeId:e,dragItems:n,nodeLookup:s,dragging:r=!0}){const i=[];for(const[a,c]of n){const l=s.get(a)?.internals.userNode;l&&i.push({...l,position:c.position,dragging:r})}if(!e)return[i[0],i];const o=s.get(e)?.internals.userNode;return[o?{...o,position:n.get(e)?.position||o.position,dragging:r}:i[0],i]}function Yc({dragItems:e,snapGrid:n,x:s,y:r}){const i=e.values().next().value;if(!i)return null;const o={x:s-i.distance.x,y:r-i.distance.y},a=jr(o,n);return{x:a.x-o.x,y:a.y-o.y}}function Gc({onNodeMouseDown:e,getStoreItems:n,onDragStart:s,onDrag:r,onDragStop:i}){let o={x:null,y:null},a=0,c=new Map,l=!1,d={x:0,y:0},h=null,f=!1,m=null,u=!1,p=!1,M=null;function C({noDragClassName:v,handleSelector:x,domNode:b,isSelectable:k,nodeId:N,nodeClickDistance:I=0}){m=gt(b);function B({x:P,y:z}){const{nodeLookup:j,nodeExtent:O,snapGrid:_,snapToGrid:T,nodeOrigin:R,onNodeDrag:A,onSelectionDrag:q,onError:Y,updateNodePositions:F}=n();o={x:P,y:z};let Q=!1;const $=c.size>1,S=$&&O?Ps(kr(c)):null,V=$&&T?Yc({dragItems:c,snapGrid:_,x:P,y:z}):null;for(const[W,H]of c){if(!j.has(W))continue;let Z={x:P-H.distance.x,y:z-H.distance.y};T&&(Z=V?{x:Math.round(Z.x+V.x),y:Math.round(Z.y+V.y)}:jr(Z,_));let J=null;if($&&O&&!H.extent&&S){const{positionAbsolute:X}=H.internals,ie=X.x-S.x+O[0][0],de=X.x+H.measured.width-S.x2+O[1][0],se=X.y-S.y+O[0][1],me=X.y+H.measured.height-S.y2+O[1][1];J=[[ie,se],[de,me]]}const{position:le,positionAbsolute:te}=ui({nodeId:W,nextPosition:Z,nodeLookup:j,nodeExtent:J||O,nodeOrigin:R,onError:Y});Q=Q||H.position.x!==le.x||H.position.y!==le.y,H.position=le,H.internals.positionAbsolute=te}if(p=p||Q,!!Q&&(F(c,!0),M&&(r||A||!N&&q))){const[W,H]=Cs({nodeId:N,dragItems:c,nodeLookup:j});r?.(M,c,W,H),A?.(M,W,H),N||q?.(M,H)}}async function D(){if(!h)return;const{transform:P,panBy:z,autoPanSpeed:j,autoPanOnNodeDrag:O}=n();if(!O){l=!1,cancelAnimationFrame(a);return}const[_,T]=hi(d,h,j);(_!==0||T!==0)&&(o.x=(o.x??0)-_/P[2],o.y=(o.y??0)-T/P[2],await z({x:_,y:T})&&B(o)),a=requestAnimationFrame(D)}function L(P){const{nodeLookup:z,multiSelectionActive:j,nodesDraggable:O,transform:_,snapGrid:T,snapToGrid:R,selectNodesOnDrag:A,onNodeDragStart:q,onSelectionDragStart:Y,unselectNodesAndEdges:F}=n();f=!0,(!A||!k)&&!j&&N&&(z.get(N)?.selected||F()),k&&A&&N&&e?.(N);const Q=dr(P.sourceEvent,{transform:_,snapGrid:T,snapToGrid:R,containerBounds:h});if(o=Q,c=Fc(z,O,Q,N),c.size>0&&(s||q||!N&&Y)){const[$,S]=Cs({nodeId:N,dragItems:c,nodeLookup:z});s?.(P.sourceEvent,c,$,S),q?.(P.sourceEvent,$,S),N||Y?.(P.sourceEvent,S)}}const E=si().clickDistance(I).on("start",P=>{const{domNode:z,nodeDragThreshold:j,transform:O,snapGrid:_,snapToGrid:T}=n();h=z?.getBoundingClientRect()||null,u=!1,p=!1,M=P.sourceEvent,j===0&&L(P),o=dr(P.sourceEvent,{transform:O,snapGrid:_,snapToGrid:T,containerBounds:h}),d=Dt(P.sourceEvent,h)}).on("drag",P=>{const{autoPanOnNodeDrag:z,transform:j,snapGrid:O,snapToGrid:_,nodeDragThreshold:T,nodeLookup:R}=n(),A=dr(P.sourceEvent,{transform:j,snapGrid:O,snapToGrid:_,containerBounds:h});if(M=P.sourceEvent,(P.sourceEvent.type==="touchmove"&&P.sourceEvent.touches.length>1||N&&!R.has(N))&&(u=!0),!u){if(!l&&z&&f&&(l=!0,D()),!f){const q=Dt(P.sourceEvent,h),Y=q.x-d.x,F=q.y-d.y;Math.sqrt(Y*Y+F*F)>T&&L(P)}(o.x!==A.xSnapped||o.y!==A.ySnapped)&&c&&f&&(d=Dt(P.sourceEvent,h),B(A))}}).on("end",P=>{if(!(!f||u)&&(l=!1,f=!1,cancelAnimationFrame(a),c.size>0)){const{nodeLookup:z,updateNodePositions:j,onNodeDragStop:O,onSelectionDragStop:_}=n();if(p&&(j(c,!1),p=!1),i||O||!N&&_){const[T,R]=Cs({nodeId:N,dragItems:c,nodeLookup:z,dragging:!1});i?.(P.sourceEvent,c,T,R),O?.(P.sourceEvent,T,R),N||_?.(P.sourceEvent,R)}}}).filter(P=>{const z=P.target;return!P.button&&(!v||!Qo(z,`.${v}`,b))&&(!x||Qo(z,x,b))});m.call(E)}function y(){m?.on(".drag",null)}return{update:C,destroy:y}}function Kc(e,n,s){const r=[],i={x:e.x-s,y:e.y-s,width:s*2,height:s*2};for(const o of n.values())pr(i,Zn(o))>0&&r.push(o);return r}const Zc=250;function Xc(e,n,s,r){let i=[],o=1/0;const a=Kc(e,s,n+Zc);for(const c of a){const l=[...c.internals.handleBounds?.source??[],...c.internals.handleBounds?.target??[]];for(const d of l){if(r.nodeId===d.nodeId&&r.type===d.type&&r.id===d.id)continue;const{x:h,y:f}=En(c,d,d.position,!0),m=Math.sqrt(Math.pow(h-e.x,2)+Math.pow(f-e.y,2));m>n||(m<o?(i=[{...d,x:h,y:f}],o=m):m===o&&i.push({...d,x:h,y:f}))}}if(!i.length)return null;if(i.length>1){const c=r.type==="source"?"target":"source";return i.find(l=>l.type===c)??i[0]}return i[0]}function Mi(e,n,s,r,i,o=!1){const a=r.get(e);if(!a)return null;const c=i==="strict"?a.internals.handleBounds?.[n]:[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]],l=(s?c?.find(d=>d.id===s):c?.[0])??null;return l&&o?{...l,...En(a,l,l.position,!0)}:l}function Ii(e,n){return e||(n?.classList.contains("target")?"target":n?.classList.contains("source")?"source":null)}function Uc(e,n){let s=null;return n?s=!0:e&&!n&&(s=!1),s}const Ti=()=>!0;function Qc(e,{connectionMode:n,connectionRadius:s,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:a,domNode:c,nodeLookup:l,lib:d,autoPanOnConnect:h,flowId:f,panBy:m,cancelConnection:u,onConnectStart:p,onConnect:M,onConnectEnd:C,isValidConnection:y=Ti,onReconnectEnd:v,updateConnection:x,getTransform:b,getFromHandle:k,autoPanSpeed:N,dragThreshold:I=1,handleDomNode:B}){const D=xi(e.target);let L=0,E;const{x:P,y:z}=Dt(e),j=Ii(o,B),O=c?.getBoundingClientRect();let _=!1;if(!O||!j)return;const T=Mi(i,j,r,l,n);if(!T)return;let R=Dt(e,O),A=!1,q=null,Y=!1,F=null;function Q(){if(!h||!O)return;const[le,te]=hi(R,O,N);m({x:le,y:te}),L=requestAnimationFrame(Q)}const $={...T,nodeId:i,type:j,position:T.position},S=l.get(i);let W={inProgress:!0,isValid:null,from:En(S,$,be.Left,!0),fromHandle:$,fromPosition:$.position,fromNode:S,to:R,toHandle:null,toPosition:zo[$.position],toNode:null,pointer:R};function H(){_=!0,x(W),p?.(e,{nodeId:i,handleId:r,handleType:j})}I===0&&H();function Z(le){if(!_){const{x:me,y:ue}=Dt(le),K=me-P,ce=ue-z;if(!(K*K+ce*ce>I*I))return;H()}if(!k()||!$){J(le);return}const te=b();R=Dt(le,O),E=Xc(Nr(R,te,!1,[1,1]),s,l,$),A||(Q(),A=!0);const X=Ri(le,{handle:E,connectionMode:n,fromNodeId:i,fromHandleId:r,fromType:a?"target":"source",isValidConnection:y,doc:D,lib:d,flowId:f,nodeLookup:l});F=X.handleDomNode,q=X.connection,Y=Uc(!!E,X.isValid);const ie=l.get(i),de=ie?En(ie,$,be.Left,!0):W.from,se={...W,from:de,isValid:Y,to:X.toHandle&&Y?ts({x:X.toHandle.x,y:X.toHandle.y},te):R,toHandle:X.toHandle,toPosition:Y&&X.toHandle?X.toHandle.position:zo[$.position],toNode:X.toHandle?l.get(X.toHandle.nodeId):null,pointer:R};x(se),W=se}function J(le){if(!("touches"in le&&le.touches.length>0)){if(_){(E||F)&&q&&Y&&M?.(q);const{inProgress:te,...X}=W,ie={...X,toPosition:W.toHandle?W.toPosition:null};C?.(le,ie),o&&v?.(le,ie)}u(),cancelAnimationFrame(L),A=!1,Y=!1,q=null,F=null,D.removeEventListener("mousemove",Z),D.removeEventListener("mouseup",J),D.removeEventListener("touchmove",Z),D.removeEventListener("touchend",J)}}D.addEventListener("mousemove",Z),D.addEventListener("mouseup",J),D.addEventListener("touchmove",Z),D.addEventListener("touchend",J)}function Ri(e,{handle:n,connectionMode:s,fromNodeId:r,fromHandleId:i,fromType:o,doc:a,lib:c,flowId:l,isValidConnection:d=Ti,nodeLookup:h}){const f=o==="target",m=n?a.querySelector(`.${c}-flow__handle[data-id="${l}-${n?.nodeId}-${n?.id}-${n?.type}"]`):null,{x:u,y:p}=Dt(e),M=a.elementFromPoint(u,p),C=M?.classList.contains(`${c}-flow__handle`)?M:m,y={handleDomNode:C,isValid:!1,connection:null,toHandle:null};if(C){const v=Ii(void 0,C),x=C.getAttribute("data-nodeid"),b=C.getAttribute("data-handleid"),k=C.classList.contains("connectable"),N=C.classList.contains("connectableend");if(!x||!v)return y;const I={source:f?x:r,sourceHandle:f?b:i,target:f?r:x,targetHandle:f?i:b};y.connection=I;const D=k&&N&&(s===Yn.Strict?f&&v==="source"||!f&&v==="target":x!==r||b!==i);y.isValid=D&&d(I),y.toHandle=Mi(x,v,b,h,s,!0)}return y}const zs={onPointerDown:Qc,isValid:Ri};function Jc({domNode:e,panZoom:n,getTransform:s,getViewScale:r}){const i=gt(e);function o({translateExtent:c,width:l,height:d,zoomStep:h=1,pannable:f=!0,zoomable:m=!0,inversePan:u=!1}){const p=x=>{if(x.sourceEvent.type!=="wheel"||!n)return;const b=s(),k=x.sourceEvent.ctrlKey&&xr()?10:1,N=-x.sourceEvent.deltaY*(x.sourceEvent.deltaMode===1?.05:x.sourceEvent.deltaMode?1:.002)*h,I=b[2]*Math.pow(2,N*k);n.scaleTo(I)};let M=[0,0];const C=x=>{(x.sourceEvent.type==="mousedown"||x.sourceEvent.type==="touchstart")&&(M=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY])},y=x=>{const b=s();if(x.sourceEvent.type!=="mousemove"&&x.sourceEvent.type!=="touchmove"||!n)return;const k=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY],N=[k[0]-M[0],k[1]-M[1]];M=k;const I=r()*Math.max(b[2],Math.log(b[2]))*(u?-1:1),B={x:b[0]-N[0]*I,y:b[1]-N[1]*I},D=[[0,0],[l,d]];n.setViewportConstrained({x:B.x,y:B.y,zoom:b[2]},D,c)},v=oi().on("start",C).on("zoom",f?y:null).on("zoom.wheel",m?p:null);i.call(v,{})}function a(){i.on("zoom",null)}return{update:o,destroy:a,pointer:Lt}}const ls=e=>({x:e.x,y:e.y,zoom:e.k}),Ss=({x:e,y:n,zoom:s})=>Fs.translate(e,n).scale(s),qn=(e,n)=>e.target.closest(`.${n}`),_i=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),ed=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Es=(e,n=0,s=ed,r=()=>{})=>{const i=typeof n=="number"&&n>0;return i||r(),i?e.transition().duration(n).ease(s).on("end",r):e},Li=e=>{const n=e.ctrlKey&&xr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function td({zoomPanValues:e,noWheelClassName:n,d3Selection:s,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:c,onPanZoom:l,onPanZoomEnd:d}){return h=>{if(qn(h,n))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const f=s.property("__zoom").k||1;if(h.ctrlKey&&a){const C=Lt(h),y=Li(h),v=f*Math.pow(2,y);r.scaleTo(s,v,C,h);return}const m=h.deltaMode===1?20:1;let u=i===Cn.Vertical?0:h.deltaX*m,p=i===Cn.Horizontal?0:h.deltaY*m;!xr()&&h.shiftKey&&i!==Cn.Vertical&&(u=h.deltaY*m,p=0),r.translateBy(s,-(u/f)*o,-(p/f)*o,{internal:!0});const M=ls(s.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(l?.(h,M),e.panScrollTimeout=setTimeout(()=>{d?.(h,M),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c?.(h,M))}}function nd({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:s}){return function(r,i){const o=r.type==="wheel",a=!n&&o&&!r.ctrlKey,c=qn(r,e);if(r.ctrlKey&&o&&c&&r.preventDefault(),a||c)return null;r.preventDefault(),s.call(this,r,i)}}function rd({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:s}){return r=>{if(r.sourceEvent?.internal)return;const i=ls(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type==="mousedown"&&n(!0),s&&s?.(r.sourceEvent,i)}}function sd({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:s,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(s&&_i(n,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,ls(o.transform))}}function od({zoomPanValues:e,panOnDrag:n,panOnScroll:s,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return a=>{if(!a.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&_i(n,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const c=ls(a.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(a.sourceEvent,c)},s?150:0)}}}function ad({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:s,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:a,noWheelClassName:c,noPanClassName:l,lib:d,connectionInProgress:h}){return f=>{const m=e||n,u=s&&f.ctrlKey,p=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(qn(f,`${d}-flow__node`)||qn(f,`${d}-flow__edge`)))return!0;if(!r&&!m&&!i&&!o&&!s||a||h&&!p||qn(f,c)&&p||qn(f,l)&&(!p||i&&p&&!e)||!s&&f.ctrlKey&&p)return!1;if(!s&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!m&&!i&&!u&&p||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const M=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||p)&&M}}function id({domNode:e,minZoom:n,maxZoom:s,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:c,onDraggingChange:l}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},h=e.getBoundingClientRect(),f=oi().scaleExtent([n,s]).translateExtent(r),m=gt(e).call(f);v({x:i.x,y:i.y,zoom:Kn(i.zoom,n,s)},[[0,0],[h.width,h.height]],r);const u=m.on("wheel.zoom"),p=m.on("dblclick.zoom");f.wheelDelta(Li);function M(E,P){return m?new Promise(z=>{f?.interpolate(P?.interpolate==="linear"?ks:Xr).transform(Es(m,P?.duration,P?.ease,()=>z(!0)),E)}):Promise.resolve(!1)}function C({noWheelClassName:E,noPanClassName:P,onPaneContextMenu:z,userSelectionActive:j,panOnScroll:O,panOnDrag:_,panOnScrollMode:T,panOnScrollSpeed:R,preventScrolling:A,zoomOnPinch:q,zoomOnScroll:Y,zoomOnDoubleClick:F,zoomActivationKeyPressed:Q,lib:$,onTransformChange:S,connectionInProgress:V,paneClickDistance:W,selectionOnDrag:H}){j&&!d.isZoomingOrPanning&&y();const Z=O&&!Q&&!j;f.clickDistance(H?1/0:!At(W)||W<0?0:W);const J=Z?td({zoomPanValues:d,noWheelClassName:E,d3Selection:m,d3Zoom:f,panOnScrollMode:T,panOnScrollSpeed:R,zoomOnPinch:q,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:c}):nd({noWheelClassName:E,preventScrolling:A,d3ZoomHandler:u});if(m.on("wheel.zoom",J,{passive:!1}),!j){const te=rd({zoomPanValues:d,onDraggingChange:l,onPanZoomStart:a});f.on("start",te);const X=sd({zoomPanValues:d,panOnDrag:_,onPaneContextMenu:!!z,onPanZoom:o,onTransformChange:S});f.on("zoom",X);const ie=od({zoomPanValues:d,panOnDrag:_,panOnScroll:O,onPaneContextMenu:z,onPanZoomEnd:c,onDraggingChange:l});f.on("end",ie)}const le=ad({zoomActivationKeyPressed:Q,panOnDrag:_,zoomOnScroll:Y,panOnScroll:O,zoomOnDoubleClick:F,zoomOnPinch:q,userSelectionActive:j,noPanClassName:P,noWheelClassName:E,lib:$,connectionInProgress:V});f.filter(le),F?m.on("dblclick.zoom",p):m.on("dblclick.zoom",null)}function y(){f.on("zoom",null)}async function v(E,P,z){const j=Ss(E),O=f?.constrain()(j,P,z);return O&&await M(O),new Promise(_=>_(O))}async function x(E,P){const z=Ss(E);return await M(z,P),new Promise(j=>j(z))}function b(E){if(m){const P=Ss(E),z=m.property("__zoom");(z.k!==E.zoom||z.x!==E.x||z.y!==E.y)&&f?.transform(m,P,null,{sync:!0})}}function k(){const E=m?Jl(m.node()):{x:0,y:0,k:1};return{x:E.x,y:E.y,zoom:E.k}}function N(E,P){return m?new Promise(z=>{f?.interpolate(P?.interpolate==="linear"?ks:Xr).scaleTo(Es(m,P?.duration,P?.ease,()=>z(!0)),E)}):Promise.resolve(!1)}function I(E,P){return m?new Promise(z=>{f?.interpolate(P?.interpolate==="linear"?ks:Xr).scaleBy(Es(m,P?.duration,P?.ease,()=>z(!0)),E)}):Promise.resolve(!1)}function B(E){f?.scaleExtent(E)}function D(E){f?.translateExtent(E)}function L(E){const P=!At(E)||E<0?0:E;f?.clickDistance(P)}return{update:C,destroy:y,setViewport:x,setViewportConstrained:v,getViewport:k,scaleTo:N,scaleBy:I,setScaleExtent:B,setTranslateExtent:D,syncViewport:b,setClickDistance:L}}var Un;(function(e){e.Line="line",e.Handle="handle"})(Un||(Un={}));function ld({width:e,prevWidth:n,height:s,prevHeight:r,affectsX:i,affectsY:o}){const a=e-n,c=s-r,l=[a>0?1:a<0?-1:0,c>0?1:c<0?-1:0];return a&&i&&(l[0]=l[0]*-1),c&&o&&(l[1]=l[1]*-1),l}function Jo(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 on(e,n){return Math.max(0,n-e)}function an(e,n){return Math.max(0,e-n)}function Wr(e,n,s){return Math.max(0,n-e,e-s)}function ea(e,n){return e?!n:n}function cd(e,n,s,r,i,o,a,c){let{affectsX:l,affectsY:d}=n;const{isHorizontal:h,isVertical:f}=n,m=h&&f,{xSnapped:u,ySnapped:p}=s,{minWidth:M,maxWidth:C,minHeight:y,maxHeight:v}=r,{x,y:b,width:k,height:N,aspectRatio:I}=e;let B=Math.floor(h?u-e.pointerX:0),D=Math.floor(f?p-e.pointerY:0);const L=k+(l?-B:B),E=N+(d?-D:D),P=-o[0]*k,z=-o[1]*N;let j=Wr(L,M,C),O=Wr(E,y,v);if(a){let R=0,A=0;l&&B<0?R=on(x+B+P,a[0][0]):!l&&B>0&&(R=an(x+L+P,a[1][0])),d&&D<0?A=on(b+D+z,a[0][1]):!d&&D>0&&(A=an(b+E+z,a[1][1])),j=Math.max(j,R),O=Math.max(O,A)}if(c){let R=0,A=0;l&&B>0?R=an(x+B,c[0][0]):!l&&B<0&&(R=on(x+L,c[1][0])),d&&D>0?A=an(b+D,c[0][1]):!d&&D<0&&(A=on(b+E,c[1][1])),j=Math.max(j,R),O=Math.max(O,A)}if(i){if(h){const R=Wr(L/I,y,v)*I;if(j=Math.max(j,R),a){let A=0;!l&&!d||l&&!d&&m?A=an(b+z+L/I,a[1][1])*I:A=on(b+z+(l?B:-B)/I,a[0][1])*I,j=Math.max(j,A)}if(c){let A=0;!l&&!d||l&&!d&&m?A=on(b+L/I,c[1][1])*I:A=an(b+(l?B:-B)/I,c[0][1])*I,j=Math.max(j,A)}}if(f){const R=Wr(E*I,M,C)/I;if(O=Math.max(O,R),a){let A=0;!l&&!d||d&&!l&&m?A=an(x+E*I+P,a[1][0])/I:A=on(x+(d?D:-D)*I+P,a[0][0])/I,O=Math.max(O,A)}if(c){let A=0;!l&&!d||d&&!l&&m?A=on(x+E*I,c[1][0])/I:A=an(x+(d?D:-D)*I,c[0][0])/I,O=Math.max(O,A)}}}D=D+(D<0?O:-O),B=B+(B<0?j:-j),i&&(m?L>E*I?D=(ea(l,d)?-B:B)/I:B=(ea(l,d)?-D:D)*I:h?(D=B/I,d=l):(B=D*I,l=d));const _=l?x+B:x,T=d?b+D:b;return{width:k+(l?-B:B),height:N+(d?-D:D),x:o[0]*B*(l?-1:1)+_,y:o[1]*D*(d?-1:1)+T}}const Ai={width:0,height:0,x:0,y:0},dd={...Ai,pointerX:0,pointerY:0,aspectRatio:1};function ud(e){return[[0,0],[e.measured.width,e.measured.height]]}function fd(e,n,s){const r=n.position.x+e.position.x,i=n.position.y+e.position.y,o=e.measured.width??0,a=e.measured.height??0,c=s[0]*o,l=s[1]*a;return[[r-c,i-l],[r+o-c,i+a-l]]}function hd({domNode:e,nodeId:n,getStoreItems:s,onChange:r,onEnd:i}){const o=gt(e);let a={controlDirection:Jo("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:d,boundaries:h,keepAspectRatio:f,resizeDirection:m,onResizeStart:u,onResize:p,onResizeEnd:M,shouldResize:C}){let y={...Ai},v={...dd};a={boundaries:h,resizeDirection:m,keepAspectRatio:f,controlDirection:Jo(d)};let x,b=null,k=[],N,I,B,D=!1;const L=si().on("start",E=>{const{nodeLookup:P,transform:z,snapGrid:j,snapToGrid:O,nodeOrigin:_,paneDomNode:T}=s();if(x=P.get(n),!x)return;b=T?.getBoundingClientRect()??null;const{xSnapped:R,ySnapped:A}=dr(E.sourceEvent,{transform:z,snapGrid:j,snapToGrid:O,containerBounds:b});y={width:x.measured.width??0,height:x.measured.height??0,x:x.position.x??0,y:x.position.y??0},v={...y,pointerX:R,pointerY:A,aspectRatio:y.width/y.height},N=void 0,x.parentId&&(x.extent==="parent"||x.expandParent)&&(N=P.get(x.parentId),I=N&&x.extent==="parent"?ud(N):void 0),k=[],B=void 0;for(const[q,Y]of P)if(Y.parentId===n&&(k.push({id:q,position:{...Y.position},extent:Y.extent}),Y.extent==="parent"||Y.expandParent)){const F=fd(Y,x,Y.origin??_);B?B=[[Math.min(F[0][0],B[0][0]),Math.min(F[0][1],B[0][1])],[Math.max(F[1][0],B[1][0]),Math.max(F[1][1],B[1][1])]]:B=F}u?.(E,{...y})}).on("drag",E=>{const{transform:P,snapGrid:z,snapToGrid:j,nodeOrigin:O}=s(),_=dr(E.sourceEvent,{transform:P,snapGrid:z,snapToGrid:j,containerBounds:b}),T=[];if(!x)return;const{x:R,y:A,width:q,height:Y}=y,F={},Q=x.origin??O,{width:$,height:S,x:V,y:W}=cd(v,a.controlDirection,_,a.boundaries,a.keepAspectRatio,Q,I,B),H=$!==q,Z=S!==Y,J=V!==R&&H,le=W!==A&&Z;if(!J&&!le&&!H&&!Z)return;if((J||le||Q[0]===1||Q[1]===1)&&(F.x=J?V:y.x,F.y=le?W:y.y,y.x=F.x,y.y=F.y,k.length>0)){const de=V-R,se=W-A;for(const me of k)me.position={x:me.position.x-de+Q[0]*($-q),y:me.position.y-se+Q[1]*(S-Y)},T.push(me)}if((H||Z)&&(F.width=H&&(!a.resizeDirection||a.resizeDirection==="horizontal")?$:y.width,F.height=Z&&(!a.resizeDirection||a.resizeDirection==="vertical")?S:y.height,y.width=F.width,y.height=F.height),N&&x.expandParent){const de=Q[0]*(F.width??0);F.x&&F.x<de&&(y.x=de,v.x=v.x-(F.x-de));const se=Q[1]*(F.height??0);F.y&&F.y<se&&(y.y=se,v.y=v.y-(F.y-se))}const te=ld({width:y.width,prevWidth:q,height:y.height,prevHeight:Y,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),X={...y,direction:te};C?.(E,X)!==!1&&(D=!0,p?.(E,X),r(F,T))}).on("end",E=>{D&&(M?.(E,{...y}),i?.({...y}),D=!1)});o.call(L)}function l(){o.on(".drag",null)}return{update:c,destroy:l}}var Ms={exports:{}},Is={};var ta;function md(){if(ta)return Is;ta=1;var e=Bl(),n=zl();function s(d,h){return d===h&&(d!==0||1/d===1/h)||d!==d&&h!==h}var r=typeof Object.is=="function"?Object.is:s,i=n.useSyncExternalStore,o=e.useRef,a=e.useEffect,c=e.useMemo,l=e.useDebugValue;return Is.useSyncExternalStoreWithSelector=function(d,h,f,m,u){var p=o(null);if(p.current===null){var M={hasValue:!1,value:null};p.current=M}else M=p.current;p=c(function(){function y(N){if(!v){if(v=!0,x=N,N=m(N),u!==void 0&&M.hasValue){var I=M.value;if(u(I,N))return b=I}return b=N}if(I=b,r(x,N))return I;var B=m(N);return u!==void 0&&u(I,B)?(x=N,I):(x=N,b=B)}var v=!1,x,b,k=f===void 0?null:f;return[function(){return y(h())},k===null?void 0:function(){return y(k())}]},[h,f,m,u]);var C=i(d,p[0],p[1]);return a(function(){M.hasValue=!0,M.value=C},[C]),l(C),C},Is}var na;function gd(){return na||(na=1,Ms.exports=md()),Ms.exports}var pd=gd();const xd=Hl(pd),bd={},ra=e=>{let n;const s=new Set,r=(h,f)=>{const m=typeof h=="function"?h(n):h;if(!Object.is(m,n)){const u=n;n=f??(typeof m!="object"||m===null)?m:Object.assign({},n,m),s.forEach(p=>p(n,u))}},i=()=>n,l={setState:r,getState:i,getInitialState:()=>d,subscribe:h=>(s.add(h),()=>s.delete(h)),destroy:()=>{(bd?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),s.clear()}},d=n=e(r,i,l);return l},yd=e=>e?ra(e):ra,{useDebugValue:vd}=ql,{useSyncExternalStoreWithSelector:wd}=xd,kd=e=>e;function Di(e,n=kd,s){const r=wd(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,s);return vd(r),r}const sa=(e,n)=>{const s=yd(e),r=(i,o=n)=>Di(s,i,o);return Object.assign(r,s),r},jd=(e,n)=>e?sa(e,n):sa;function qe(e,n){if(Object.is(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;if(e instanceof Map&&n instanceof Map){if(e.size!==n.size)return!1;for(const[r,i]of e)if(!Object.is(i,n.get(r)))return!1;return!0}if(e instanceof Set&&n instanceof Set){if(e.size!==n.size)return!1;for(const r of e)if(!n.has(r))return!1;return!0}const s=Object.keys(e);if(s.length!==Object.keys(n).length)return!1;for(const r of s)if(!Object.prototype.hasOwnProperty.call(n,r)||!Object.is(e[r],n[r]))return!1;return!0}const cs=g.createContext(null),Nd=cs.Provider,Pi=zt.error001();function Te(e,n){const s=g.useContext(cs);if(s===null)throw new Error(Pi);return Di(s,e,n)}function Be(){const e=g.useContext(cs);if(e===null)throw new Error(Pi);return g.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const oa={display:"none"},Cd={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},$i="react-flow__node-desc",Oi="react-flow__edge-desc",Sd="react-flow__aria-live",Ed=e=>e.ariaLiveMessage,Md=e=>e.ariaLabelConfig;function Id({rfId:e}){const n=Te(Ed);return t.jsx("div",{id:`${Sd}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Cd,children:n})}function Td({rfId:e,disableKeyboardA11y:n}){const s=Te(Md);return t.jsxs(t.Fragment,{children:[t.jsx("div",{id:`${$i}-${e}`,style:oa,children:n?s["node.a11yDescription.default"]:s["node.a11yDescription.keyboardDisabled"]}),t.jsx("div",{id:`${Oi}-${e}`,style:oa,children:s["edge.a11yDescription.default"]}),!n&&t.jsx(Id,{rfId:e})]})}const ds=g.forwardRef(({position:e="top-left",children:n,className:s,style:r,...i},o)=>{const a=`${e}`.split("-");return t.jsx("div",{className:Ze(["react-flow__panel",s,...a]),style:r,ref:o,...i,children:n})});ds.displayName="Panel";function Rd({proOptions:e,position:n="bottom-right"}){return e?.hideAttribution?null:t.jsx(ds,{position:n,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:t.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const _d=e=>{const n=[],s=[];for(const[,r]of e.nodeLookup)r.selected&&n.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&s.push(r);return{selectedNodes:n,selectedEdges:s}},Vr=e=>e.id;function Ld(e,n){return qe(e.selectedNodes.map(Vr),n.selectedNodes.map(Vr))&&qe(e.selectedEdges.map(Vr),n.selectedEdges.map(Vr))}function Ad({onSelectionChange:e}){const n=Be(),{selectedNodes:s,selectedEdges:r}=Te(_d,Ld);return g.useEffect(()=>{const i={nodes:s,edges:r};e?.(i),n.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[s,r,e]),null}const Dd=e=>!!e.onSelectionChangeHandlers;function Pd({onSelectionChange:e}){const n=Te(Dd);return e||n?t.jsx(Ad,{onSelectionChange:e}):null}const Bi=[0,0],$d={x:0,y:0,zoom:1},Od=["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"],aa=[...Od,"rfId"],Bd=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}),ia={translateExtent:mr,nodeOrigin:Bi,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function zd(e){const{setNodes:n,setEdges:s,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:a,reset:c,setDefaultNodesAndEdges:l}=Te(Bd,qe),d=Be();g.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{h.current=ia,c()}),[]);const h=g.useRef(ia);return g.useEffect(()=>{for(const f of aa){const m=e[f],u=h.current[f];m!==u&&(typeof e[f]>"u"||(f==="nodes"?n(m):f==="edges"?s(m):f==="minZoom"?r(m):f==="maxZoom"?i(m):f==="translateExtent"?o(m):f==="nodeExtent"?a(m):f==="ariaLabelConfig"?d.setState({ariaLabelConfig:Cc(m)}):f==="fitView"?d.setState({fitViewQueued:m}):f==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[f]:m})))}h.current=e},aa.map(f=>e[f])),null}function la(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Hd(e){const[n,s]=g.useState(e==="system"?null:e);return g.useEffect(()=>{if(e!=="system"){s(e);return}const r=la(),i=()=>s(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),n!==null?n:la()?.matches?"dark":"light"}const ca=typeof document<"u"?document:null;function br(e=null,n={target:ca,actInsideInputWithModifier:!0}){const[s,r]=g.useState(!1),i=g.useRef(!1),o=g.useRef(new Set([])),[a,c]=g.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
1
+ import{x as Bl,y as zl,v as Hl,R as ql,r as g,j as t,u as We,l as ae,z as Wl,a as vr,k as Vl,b as Fl,c as Yl,m as Gl,d as _s,P as Fe,w as jt,B as _t,C as ys,p as Br,M as Kl,i as Zl,n as Bt,D as Hn,q as fr,E as Xl,A as Vs,F as Lo,G as Ls,H as Ao,J as As,K as Do,L as Po,O as $o,Q as Qa,U as Ja,V as Ul}from"./index-sjnbPgLJ.js";import{ContentRenderer as Ql}from"./ContentRenderer-C28LBAOD.js";import{s as gt,e as ei,f as Fs,T as vs,g as ws,t as Jl}from"./transform-CpIVI4vC.js";import{i as ks}from"./value-DIujSiJ7.js";import{C as ti}from"./CommentInput-CcU4x-2w.js";function ec(e){let n;for(;n=e.sourceEvent;)e=n;return e}function Lt(e,n){if(e=ec(e),n===void 0&&(n=e.currentTarget),n){var s=n.ownerSVGElement||n;if(s.createSVGPoint){var r=s.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(n.getScreenCTM().inverse()),[r.x,r.y]}if(n.getBoundingClientRect){var i=n.getBoundingClientRect();return[e.clientX-i.left-n.clientLeft,e.clientY-i.top-n.clientTop]}}return[e.pageX,e.pageY]}const tc={passive:!1},hr={capture:!0,passive:!1};function js(e){e.stopImmediatePropagation()}function Fn(e){e.preventDefault(),e.stopImmediatePropagation()}function ni(e){var n=e.document.documentElement,s=gt(e).on("dragstart.drag",Fn,hr);"onselectstart"in n?s.on("selectstart.drag",Fn,hr):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function ri(e,n){var s=e.document.documentElement,r=gt(e).on("dragstart.drag",null);n&&(r.on("click.drag",Fn,hr),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in s?r.on("selectstart.drag",null):(s.style.MozUserSelect=s.__noselect,delete s.__noselect)}const zr=e=>()=>e;function Ds(e,{sourceEvent:n,subject:s,target:r,identifier:i,active:o,x:a,y:c,dx:l,dy:d,dispatch:h}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:s,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:a,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:h}})}Ds.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function nc(e){return!e.ctrlKey&&!e.button}function rc(){return this.parentNode}function sc(e,n){return n??{x:e.x,y:e.y}}function oc(){return navigator.maxTouchPoints||"ontouchstart"in this}function si(){var e=nc,n=rc,s=sc,r=oc,i={},o=ei("start","drag","end"),a=0,c,l,d,h,f=0;function m(b){b.on("mousedown.drag",u).filter(r).on("touchstart.drag",C).on("touchmove.drag",y,tc).on("touchend.drag touchcancel.drag",v).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(b,k){if(!(h||!e.call(this,b,k))){var N=x(this,n.call(this,b,k),b,k,"mouse");N&&(gt(b.view).on("mousemove.drag",p,hr).on("mouseup.drag",M,hr),ni(b.view),js(b),d=!1,c=b.clientX,l=b.clientY,N("start",b))}}function p(b){if(Fn(b),!d){var k=b.clientX-c,N=b.clientY-l;d=k*k+N*N>f}i.mouse("drag",b)}function M(b){gt(b.view).on("mousemove.drag mouseup.drag",null),ri(b.view,d),Fn(b),i.mouse("end",b)}function C(b,k){if(e.call(this,b,k)){var N=b.changedTouches,I=n.call(this,b,k),B=N.length,D,L;for(D=0;D<B;++D)(L=x(this,I,b,k,N[D].identifier,N[D]))&&(js(b),L("start",b,N[D]))}}function y(b){var k=b.changedTouches,N=k.length,I,B;for(I=0;I<N;++I)(B=i[k[I].identifier])&&(Fn(b),B("drag",b,k[I]))}function v(b){var k=b.changedTouches,N=k.length,I,B;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),I=0;I<N;++I)(B=i[k[I].identifier])&&(js(b),B("end",b,k[I]))}function x(b,k,N,I,B,D){var L=o.copy(),E=Lt(D||N,k),P,z,j;if((j=s.call(b,new Ds("beforestart",{sourceEvent:N,target:m,identifier:B,active:a,x:E[0],y:E[1],dx:0,dy:0,dispatch:L}),I))!=null)return P=j.x-E[0]||0,z=j.y-E[1]||0,function O(_,T,R){var A=E,W;switch(_){case"start":i[B]=O,W=a++;break;case"end":delete i[B],--a;case"drag":E=Lt(R||T,k),W=a;break}L.call(_,b,new Ds(_,{sourceEvent:T,subject:j,target:m,identifier:B,active:W,x:E[0]+P,y:E[1]+z,dx:E[0]-A[0],dy:E[1]-A[1],dispatch:L}),I)}}return m.filter=function(b){return arguments.length?(e=typeof b=="function"?b:zr(!!b),m):e},m.container=function(b){return arguments.length?(n=typeof b=="function"?b:zr(b),m):n},m.subject=function(b){return arguments.length?(s=typeof b=="function"?b:zr(b),m):s},m.touchable=function(b){return arguments.length?(r=typeof b=="function"?b:zr(!!b),m):r},m.on=function(){var b=o.on.apply(o,arguments);return b===o?m:b},m.clickDistance=function(b){return arguments.length?(f=(b=+b)*b,m):Math.sqrt(f)},m}var ac=1e-12;function Oo(e){return((e=Math.exp(e))+1/e)/2}function ic(e){return((e=Math.exp(e))-1/e)/2}function lc(e){return((e=Math.exp(2*e))-1)/(e+1)}const Xr=(function e(n,s,r){function i(o,a){var c=o[0],l=o[1],d=o[2],h=a[0],f=a[1],m=a[2],u=h-c,p=f-l,M=u*u+p*p,C,y;if(M<ac)y=Math.log(m/d)/n,C=function(I){return[c+I*u,l+I*p,d*Math.exp(n*I*y)]};else{var v=Math.sqrt(M),x=(m*m-d*d+r*M)/(2*d*s*v),b=(m*m-d*d-r*M)/(2*m*s*v),k=Math.log(Math.sqrt(x*x+1)-x),N=Math.log(Math.sqrt(b*b+1)-b);y=(N-k)/n,C=function(I){var B=I*y,D=Oo(k),L=d/(s*v)*(D*lc(n*B+k)-ic(k));return[c+L*u,l+L*p,d*D/Oo(n*B+k)]}}return C.duration=y*1e3*n/Math.SQRT2,C}return i.rho=function(o){var a=Math.max(.001,+o),c=a*a,l=c*c;return e(a,c,l)},i})(Math.SQRT2,2,4),Hr=e=>()=>e;function cc(e,{sourceEvent:n,target:s,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:s,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function Ns(e){e.stopImmediatePropagation()}function lr(e){e.preventDefault(),e.stopImmediatePropagation()}function dc(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function uc(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Bo(){return this.__zoom||Fs}function fc(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function hc(){return navigator.maxTouchPoints||"ontouchstart"in this}function mc(e,n,s){var r=e.invertX(n[0][0])-s[0][0],i=e.invertX(n[1][0])-s[1][0],o=e.invertY(n[0][1])-s[0][1],a=e.invertY(n[1][1])-s[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),a>o?(o+a)/2:Math.min(0,o)||Math.max(0,a))}function oi(){var e=dc,n=uc,s=mc,r=fc,i=hc,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],c=250,l=Xr,d=ei("start","zoom","end"),h,f,m,u=500,p=150,M=0,C=10;function y(j){j.property("__zoom",Bo).on("wheel.zoom",B,{passive:!1}).on("mousedown.zoom",D).on("dblclick.zoom",L).filter(i).on("touchstart.zoom",E).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}y.transform=function(j,O,_,T){var R=j.selection?j.selection():j;R.property("__zoom",Bo),j!==R?k(j,O,_,T):R.interrupt().each(function(){N(this,arguments).event(T).start().zoom(null,typeof O=="function"?O.apply(this,arguments):O).end()})},y.scaleBy=function(j,O,_,T){y.scaleTo(j,function(){var R=this.__zoom.k,A=typeof O=="function"?O.apply(this,arguments):O;return R*A},_,T)},y.scaleTo=function(j,O,_,T){y.transform(j,function(){var R=n.apply(this,arguments),A=this.__zoom,W=_==null?b(R):typeof _=="function"?_.apply(this,arguments):_,Y=A.invert(W),F=typeof O=="function"?O.apply(this,arguments):O;return s(x(v(A,F),W,Y),R,a)},_,T)},y.translateBy=function(j,O,_,T){y.transform(j,function(){return s(this.__zoom.translate(typeof O=="function"?O.apply(this,arguments):O,typeof _=="function"?_.apply(this,arguments):_),n.apply(this,arguments),a)},null,T)},y.translateTo=function(j,O,_,T,R){y.transform(j,function(){var A=n.apply(this,arguments),W=this.__zoom,Y=T==null?b(A):typeof T=="function"?T.apply(this,arguments):T;return s(Fs.translate(Y[0],Y[1]).scale(W.k).translate(typeof O=="function"?-O.apply(this,arguments):-O,typeof _=="function"?-_.apply(this,arguments):-_),A,a)},T,R)};function v(j,O){return O=Math.max(o[0],Math.min(o[1],O)),O===j.k?j:new vs(O,j.x,j.y)}function x(j,O,_){var T=O[0]-_[0]*j.k,R=O[1]-_[1]*j.k;return T===j.x&&R===j.y?j:new vs(j.k,T,R)}function b(j){return[(+j[0][0]+ +j[1][0])/2,(+j[0][1]+ +j[1][1])/2]}function k(j,O,_,T){j.on("start.zoom",function(){N(this,arguments).event(T).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(T).end()}).tween("zoom",function(){var R=this,A=arguments,W=N(R,A).event(T),Y=n.apply(R,A),F=_==null?b(Y):typeof _=="function"?_.apply(R,A):_,Q=Math.max(Y[1][0]-Y[0][0],Y[1][1]-Y[0][1]),$=R.__zoom,S=typeof O=="function"?O.apply(R,A):O,V=l($.invert(F).concat(Q/$.k),S.invert(F).concat(Q/S.k));return function(q){if(q===1)q=S;else{var H=V(q),Z=Q/H[2];q=new vs(Z,F[0]-H[0]*Z,F[1]-H[1]*Z)}W.zoom(null,q)}})}function N(j,O,_){return!_&&j.__zooming||new I(j,O)}function I(j,O){this.that=j,this.args=O,this.active=0,this.sourceEvent=null,this.extent=n.apply(j,O),this.taps=0}I.prototype={event:function(j){return j&&(this.sourceEvent=j),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(j,O){return this.mouse&&j!=="mouse"&&(this.mouse[1]=O.invert(this.mouse[0])),this.touch0&&j!=="touch"&&(this.touch0[1]=O.invert(this.touch0[0])),this.touch1&&j!=="touch"&&(this.touch1[1]=O.invert(this.touch1[0])),this.that.__zoom=O,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(j){var O=gt(this.that).datum();d.call(j,this.that,new cc(j,{sourceEvent:this.sourceEvent,target:y,transform:this.that.__zoom,dispatch:d}),O)}};function B(j,...O){if(!e.apply(this,arguments))return;var _=N(this,O).event(j),T=this.__zoom,R=Math.max(o[0],Math.min(o[1],T.k*Math.pow(2,r.apply(this,arguments)))),A=Lt(j);if(_.wheel)(_.mouse[0][0]!==A[0]||_.mouse[0][1]!==A[1])&&(_.mouse[1]=T.invert(_.mouse[0]=A)),clearTimeout(_.wheel);else{if(T.k===R)return;_.mouse=[A,T.invert(A)],ws(this),_.start()}lr(j),_.wheel=setTimeout(W,p),_.zoom("mouse",s(x(v(T,R),_.mouse[0],_.mouse[1]),_.extent,a));function W(){_.wheel=null,_.end()}}function D(j,...O){if(m||!e.apply(this,arguments))return;var _=j.currentTarget,T=N(this,O,!0).event(j),R=gt(j.view).on("mousemove.zoom",F,!0).on("mouseup.zoom",Q,!0),A=Lt(j,_),W=j.clientX,Y=j.clientY;ni(j.view),Ns(j),T.mouse=[A,this.__zoom.invert(A)],ws(this),T.start();function F($){if(lr($),!T.moved){var S=$.clientX-W,V=$.clientY-Y;T.moved=S*S+V*V>M}T.event($).zoom("mouse",s(x(T.that.__zoom,T.mouse[0]=Lt($,_),T.mouse[1]),T.extent,a))}function Q($){R.on("mousemove.zoom mouseup.zoom",null),ri($.view,T.moved),lr($),T.event($).end()}}function L(j,...O){if(e.apply(this,arguments)){var _=this.__zoom,T=Lt(j.changedTouches?j.changedTouches[0]:j,this),R=_.invert(T),A=_.k*(j.shiftKey?.5:2),W=s(x(v(_,A),T,R),n.apply(this,O),a);lr(j),c>0?gt(this).transition().duration(c).call(k,W,T,j):gt(this).call(y.transform,W,T,j)}}function E(j,...O){if(e.apply(this,arguments)){var _=j.touches,T=_.length,R=N(this,O,j.changedTouches.length===T).event(j),A,W,Y,F;for(Ns(j),W=0;W<T;++W)Y=_[W],F=Lt(Y,this),F=[F,this.__zoom.invert(F),Y.identifier],R.touch0?!R.touch1&&R.touch0[2]!==F[2]&&(R.touch1=F,R.taps=0):(R.touch0=F,A=!0,R.taps=1+!!h);h&&(h=clearTimeout(h)),A&&(R.taps<2&&(f=F[0],h=setTimeout(function(){h=null},u)),ws(this),R.start())}}function P(j,...O){if(this.__zooming){var _=N(this,O).event(j),T=j.changedTouches,R=T.length,A,W,Y,F;for(lr(j),A=0;A<R;++A)W=T[A],Y=Lt(W,this),_.touch0&&_.touch0[2]===W.identifier?_.touch0[0]=Y:_.touch1&&_.touch1[2]===W.identifier&&(_.touch1[0]=Y);if(W=_.that.__zoom,_.touch1){var Q=_.touch0[0],$=_.touch0[1],S=_.touch1[0],V=_.touch1[1],q=(q=S[0]-Q[0])*q+(q=S[1]-Q[1])*q,H=(H=V[0]-$[0])*H+(H=V[1]-$[1])*H;W=v(W,Math.sqrt(q/H)),Y=[(Q[0]+S[0])/2,(Q[1]+S[1])/2],F=[($[0]+V[0])/2,($[1]+V[1])/2]}else if(_.touch0)Y=_.touch0[0],F=_.touch0[1];else return;_.zoom("touch",s(x(W,Y,F),_.extent,a))}}function z(j,...O){if(this.__zooming){var _=N(this,O).event(j),T=j.changedTouches,R=T.length,A,W;for(Ns(j),m&&clearTimeout(m),m=setTimeout(function(){m=null},u),A=0;A<R;++A)W=T[A],_.touch0&&_.touch0[2]===W.identifier?delete _.touch0:_.touch1&&_.touch1[2]===W.identifier&&delete _.touch1;if(_.touch1&&!_.touch0&&(_.touch0=_.touch1,delete _.touch1),_.touch0)_.touch0[1]=this.__zoom.invert(_.touch0[0]);else if(_.end(),_.taps===2&&(W=Lt(W,this),Math.hypot(f[0]-W[0],f[1]-W[1])<C)){var Y=gt(this).on("dblclick.zoom");Y&&Y.apply(this,arguments)}}}return y.wheelDelta=function(j){return arguments.length?(r=typeof j=="function"?j:Hr(+j),y):r},y.filter=function(j){return arguments.length?(e=typeof j=="function"?j:Hr(!!j),y):e},y.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:Hr(!!j),y):i},y.extent=function(j){return arguments.length?(n=typeof j=="function"?j:Hr([[+j[0][0],+j[0][1]],[+j[1][0],+j[1][1]]]),y):n},y.scaleExtent=function(j){return arguments.length?(o[0]=+j[0],o[1]=+j[1],y):[o[0],o[1]]},y.translateExtent=function(j){return arguments.length?(a[0][0]=+j[0][0],a[1][0]=+j[1][0],a[0][1]=+j[0][1],a[1][1]=+j[1][1],y):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},y.constrain=function(j){return arguments.length?(s=j,y):s},y.duration=function(j){return arguments.length?(c=+j,y):c},y.interpolate=function(j){return arguments.length?(l=j,y):l},y.on=function(){var j=d.on.apply(d,arguments);return j===d?y:j},y.clickDistance=function(j){return arguments.length?(M=(j=+j)*j,y):Math.sqrt(M)},y.tapDistance=function(j){return arguments.length?(C=+j,y):C},y}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 zt={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:n,sourceHandle:s,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?s:r}", edge id: ${n}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},mr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ai=["Enter"," ","Escape"],ii={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:n,y:s})=>`Moved selected node ${e}. New position, x: ${n}, y: ${s}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Yn;(function(e){e.Strict="strict",e.Loose="loose"})(Yn||(Yn={}));var Cn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Cn||(Cn={}));var gr;(function(e){e.Partial="partial",e.Full="full"})(gr||(gr={}));const li={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var ln;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(ln||(ln={}));var Gn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Gn||(Gn={}));var be;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(be||(be={}));const zo={[be.Left]:be.Right,[be.Right]:be.Left,[be.Top]:be.Bottom,[be.Bottom]:be.Top};function ci(e){return e===null?null:e?"valid":"invalid"}const di=e=>"id"in e&&"source"in e&&"target"in e,gc=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Ys=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),wr=(e,n=[0,0])=>{const{width:s,height:r}=Qt(e),i=e.origin??n,o=s*i[0],a=r*i[1];return{x:e.position.x-o,y:e.position.y-a}},pc=(e,n={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const s=e.reduce((r,i)=>{const o=typeof i=="string";let a=!n.nodeLookup&&!o?i:void 0;n.nodeLookup&&(a=o?n.nodeLookup.get(i):Ys(i)?i:n.nodeLookup.get(i.id));const c=a?es(a,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return as(r,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return is(s)},kr=(e,n={})=>{let s={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(i=>{(n.filter===void 0||n.filter(i))&&(s=as(s,es(i)),r=!0)}),r?is(s):{x:0,y:0,width:0,height:0}},Gs=(e,n,[s,r,i]=[0,0,1],o=!1,a=!1)=>{const c={...Nr(n,[s,r,i]),width:n.width/i,height:n.height/i},l=[];for(const d of e.values()){const{measured:h,selectable:f=!0,hidden:m=!1}=d;if(a&&!f||m)continue;const u=h.width??d.width??d.initialWidth??null,p=h.height??d.height??d.initialHeight??null,M=pr(c,Zn(d)),C=(u??0)*(p??0),y=o&&M>0;(!d.internals.handleBounds||y||M>=C||d.dragging)&&l.push(d)}return l},xc=(e,n)=>{const s=new Set;return e.forEach(r=>{s.add(r.id)}),n.filter(r=>s.has(r.source)||s.has(r.target))};function bc(e,n){const s=new Map,r=n?.nodes?new Set(n.nodes.map(i=>i.id)):null;return e.forEach(i=>{i.measured.width&&i.measured.height&&(n?.includeHiddenNodes||!i.hidden)&&(!r||r.has(i.id))&&s.set(i.id,i)}),s}async function yc({nodes:e,width:n,height:s,panZoom:r,minZoom:i,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const c=bc(e,a),l=kr(c),d=Ks(l,n,s,a?.minZoom??i,a?.maxZoom??o,a?.padding??.1);return await r.setViewport(d,{duration:a?.duration,ease:a?.ease,interpolate:a?.interpolate}),Promise.resolve(!0)}function ui({nodeId:e,nextPosition:n,nodeLookup:s,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const a=s.get(e),c=a.parentId?s.get(a.parentId):void 0,{x:l,y:d}=c?c.internals.positionAbsolute:{x:0,y:0},h=a.origin??r;let f=a.extent||i;if(a.extent==="parent"&&!a.expandParent)if(!c)o?.("005",zt.error005());else{const u=c.measured.width,p=c.measured.height;u&&p&&(f=[[l,d],[l+u,d+p]])}else c&&Xn(a.extent)&&(f=[[a.extent[0][0]+l,a.extent[0][1]+d],[a.extent[1][0]+l,a.extent[1][1]+d]]);const m=Xn(f)?Sn(n,f,a.measured):n;return(a.measured.width===void 0||a.measured.height===void 0)&&o?.("015",zt.error015()),{position:{x:m.x-l+(a.measured.width??0)*h[0],y:m.y-d+(a.measured.height??0)*h[1]},positionAbsolute:m}}async function vc({nodesToRemove:e=[],edgesToRemove:n=[],nodes:s,edges:r,onBeforeDelete:i}){const o=new Set(e.map(m=>m.id)),a=[];for(const m of s){if(m.deletable===!1)continue;const u=o.has(m.id),p=!u&&m.parentId&&a.find(M=>M.id===m.parentId);(u||p)&&a.push(m)}const c=new Set(n.map(m=>m.id)),l=r.filter(m=>m.deletable!==!1),h=xc(a,l);for(const m of l)c.has(m.id)&&!h.find(p=>p.id===m.id)&&h.push(m);if(!i)return{edges:h,nodes:a};const f=await i({nodes:a,edges:h});return typeof f=="boolean"?f?{edges:h,nodes:a}:{edges:[],nodes:[]}:f}const Kn=(e,n=0,s=1)=>Math.min(Math.max(e,n),s),Sn=(e={x:0,y:0},n,s)=>({x:Kn(e.x,n[0][0],n[1][0]-(s?.width??0)),y:Kn(e.y,n[0][1],n[1][1]-(s?.height??0))});function fi(e,n,s){const{width:r,height:i}=Qt(s),{x:o,y:a}=s.internals.positionAbsolute;return Sn(e,[[o,a],[o+r,a+i]],n)}const Ho=(e,n,s)=>e<n?Kn(Math.abs(e-n),1,n)/n:e>s?-Kn(Math.abs(e-s),1,n)/n:0,hi=(e,n,s=15,r=40)=>{const i=Ho(e.x,r,n.width-r)*s,o=Ho(e.y,r,n.height-r)*s;return[i,o]},as=(e,n)=>({x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),x2:Math.max(e.x2,n.x2),y2:Math.max(e.y2,n.y2)}),Ps=({x:e,y:n,width:s,height:r})=>({x:e,y:n,x2:e+s,y2:n+r}),is=({x:e,y:n,x2:s,y2:r})=>({x:e,y:n,width:s-e,height:r-n}),Zn=(e,n=[0,0])=>{const{x:s,y:r}=Ys(e)?e.internals.positionAbsolute:wr(e,n);return{x:s,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},es=(e,n=[0,0])=>{const{x:s,y:r}=Ys(e)?e.internals.positionAbsolute:wr(e,n);return{x:s,y:r,x2:s+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},mi=(e,n)=>is(as(Ps(e),Ps(n))),pr=(e,n)=>{const s=Math.max(0,Math.min(e.x+e.width,n.x+n.width)-Math.max(e.x,n.x)),r=Math.max(0,Math.min(e.y+e.height,n.y+n.height)-Math.max(e.y,n.y));return Math.ceil(s*r)},qo=e=>At(e.width)&&At(e.height)&&At(e.x)&&At(e.y),At=e=>!isNaN(e)&&isFinite(e),wc=(e,n)=>{},jr=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),Nr=({x:e,y:n},[s,r,i],o=!1,a=[1,1])=>{const c={x:(e-s)/i,y:(n-r)/i};return o?jr(c,a):c},ts=({x:e,y:n},[s,r,i])=>({x:e*i+s,y:n*i+r});function zn(e,n){if(typeof e=="number")return Math.floor((n-n/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const s=parseFloat(e);if(!Number.isNaN(s))return Math.floor(s)}if(typeof e=="string"&&e.endsWith("%")){const s=parseFloat(e);if(!Number.isNaN(s))return Math.floor(n*s*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function kc(e,n,s){if(typeof e=="string"||typeof e=="number"){const r=zn(e,s),i=zn(e,n);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=zn(e.top??e.y??0,s),i=zn(e.bottom??e.y??0,s),o=zn(e.left??e.x??0,n),a=zn(e.right??e.x??0,n);return{top:r,right:a,bottom:i,left:o,x:o+a,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function jc(e,n,s,r,i,o){const{x:a,y:c}=ts(e,[n,s,r]),{x:l,y:d}=ts({x:e.x+e.width,y:e.y+e.height},[n,s,r]),h=i-l,f=o-d;return{left:Math.floor(a),top:Math.floor(c),right:Math.floor(h),bottom:Math.floor(f)}}const Ks=(e,n,s,r,i,o)=>{const a=kc(o,n,s),c=(n-a.x)/e.width,l=(s-a.y)/e.height,d=Math.min(c,l),h=Kn(d,r,i),f=e.x+e.width/2,m=e.y+e.height/2,u=n/2-f*h,p=s/2-m*h,M=jc(e,u,p,h,n,s),C={left:Math.min(M.left-a.left,0),top:Math.min(M.top-a.top,0),right:Math.min(M.right-a.right,0),bottom:Math.min(M.bottom-a.bottom,0)};return{x:u-C.left+C.right,y:p-C.top+C.bottom,zoom:h}},xr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Xn(e){return e!=null&&e!=="parent"}function Qt(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function gi(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function pi(e,n={width:0,height:0},s,r,i){const o={...e},a=r.get(s);if(a){const c=a.origin||i;o.x+=a.internals.positionAbsolute.x-(n.width??0)*c[0],o.y+=a.internals.positionAbsolute.y-(n.height??0)*c[1]}return o}function Wo(e,n){if(e.size!==n.size)return!1;for(const s of e)if(!n.has(s))return!1;return!0}function Nc(){let e,n;return{promise:new Promise((r,i)=>{e=r,n=i}),resolve:e,reject:n}}function Cc(e){return{...ii,...e||{}}}function dr(e,{snapGrid:n=[0,0],snapToGrid:s=!1,transform:r,containerBounds:i}){const{x:o,y:a}=Dt(e),c=Nr({x:o-(i?.left??0),y:a-(i?.top??0)},r),{x:l,y:d}=s?jr(c,n):c;return{xSnapped:l,ySnapped:d,...c}}const Zs=e=>({width:e.offsetWidth,height:e.offsetHeight}),xi=e=>e?.getRootNode?.()||window?.document,Sc=["INPUT","SELECT","TEXTAREA"];function bi(e){const n=e.composedPath?.()?.[0]||e.target;return n?.nodeType!==1?!1:Sc.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const yi=e=>"clientX"in e,Dt=(e,n)=>{const s=yi(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)}},Vo=(e,n,s,r,i)=>{const o=n.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const c=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:i,position:a.getAttribute("data-handlepos"),x:(c.left-s.left)/r,y:(c.top-s.top)/r,...Zs(a)}})};function vi({sourceX:e,sourceY:n,targetX:s,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:a,targetControlY:c}){const l=e*.125+i*.375+a*.375+s*.125,d=n*.125+o*.375+c*.375+r*.125,h=Math.abs(l-e),f=Math.abs(d-n);return[l,d,h,f]}function qr(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function Fo({pos:e,x1:n,y1:s,x2:r,y2:i,c:o}){switch(e){case be.Left:return[n-qr(n-r,o),s];case be.Right:return[n+qr(r-n,o),s];case be.Top:return[n,s-qr(s-i,o)];case be.Bottom:return[n,s+qr(i-s,o)]}}function wi({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top,curvature:a=.25}){const[c,l]=Fo({pos:s,x1:e,y1:n,x2:r,y2:i,c:a}),[d,h]=Fo({pos:o,x1:r,y1:i,x2:e,y2:n,c:a}),[f,m,u,p]=vi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:c,sourceControlY:l,targetControlX:d,targetControlY:h});return[`M${e},${n} C${c},${l} ${d},${h} ${r},${i}`,f,m,u,p]}function ki({sourceX:e,sourceY:n,targetX:s,targetY:r}){const i=Math.abs(s-e)/2,o=s<e?s+i:s-i,a=Math.abs(r-n)/2,c=r<n?r+a:r-a;return[o,c,i,a]}function Ec({sourceNode:e,targetNode:n,selected:s=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const a=i&&s?r+1e3:r,c=Math.max(e.parentId||i&&e.selected?e.internals.z:0,n.parentId||i&&n.selected?n.internals.z:0);return a+c}function Mc({sourceNode:e,targetNode:n,width:s,height:r,transform:i}){const o=as(es(e),es(n));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const a={x:-i[0]/i[2],y:-i[1]/i[2],width:s/i[2],height:r/i[2]};return pr(a,is(o))>0}const Ic=({source:e,sourceHandle:n,target:s,targetHandle:r})=>`xy-edge__${e}${n||""}-${s}${r||""}`,Tc=(e,n)=>n.some(s=>s.source===e.source&&s.target===e.target&&(s.sourceHandle===e.sourceHandle||!s.sourceHandle&&!e.sourceHandle)&&(s.targetHandle===e.targetHandle||!s.targetHandle&&!e.targetHandle)),Rc=(e,n,s={})=>{if(!e.source||!e.target)return n;const r=s.getEdgeId||Ic;let i;return di(e)?i={...e}:i={...e,id:r(e)},Tc(i,n)?n:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,n.concat(i))};function ji({sourceX:e,sourceY:n,targetX:s,targetY:r}){const[i,o,a,c]=ki({sourceX:e,sourceY:n,targetX:s,targetY:r});return[`M ${e},${n}L ${s},${r}`,i,o,a,c]}const Yo={[be.Left]:{x:-1,y:0},[be.Right]:{x:1,y:0},[be.Top]:{x:0,y:-1},[be.Bottom]:{x:0,y:1}},_c=({source:e,sourcePosition:n=be.Bottom,target:s})=>n===be.Left||n===be.Right?e.x<s.x?{x:1,y:0}:{x:-1,y:0}:e.y<s.y?{x:0,y:1}:{x:0,y:-1},Go=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function Lc({source:e,sourcePosition:n=be.Bottom,target:s,targetPosition:r=be.Top,center:i,offset:o,stepPosition:a}){const c=Yo[n],l=Yo[r],d={x:e.x+c.x*o,y:e.y+c.y*o},h={x:s.x+l.x*o,y:s.y+l.y*o},f=_c({source:d,sourcePosition:n,target:h}),m=f.x!==0?"x":"y",u=f[m];let p=[],M,C;const y={x:0,y:0},v={x:0,y:0},[,,x,b]=ki({sourceX:e.x,sourceY:e.y,targetX:s.x,targetY:s.y});if(c[m]*l[m]===-1){m==="x"?(M=i.x??d.x+(h.x-d.x)*a,C=i.y??(d.y+h.y)/2):(M=i.x??(d.x+h.x)/2,C=i.y??d.y+(h.y-d.y)*a);const N=[{x:M,y:d.y},{x:M,y:h.y}],I=[{x:d.x,y:C},{x:h.x,y:C}];c[m]===u?p=m==="x"?N:I:p=m==="x"?I:N}else{const N=[{x:d.x,y:h.y}],I=[{x:h.x,y:d.y}];if(m==="x"?p=c.x===u?I:N:p=c.y===u?N:I,n===r){const P=Math.abs(e[m]-s[m]);if(P<=o){const z=Math.min(o-1,o-P);c[m]===u?y[m]=(d[m]>e[m]?-1:1)*z:v[m]=(h[m]>s[m]?-1:1)*z}}if(n!==r){const P=m==="x"?"y":"x",z=c[m]===l[P],j=d[P]>h[P],O=d[P]<h[P];(c[m]===1&&(!z&&j||z&&O)||c[m]!==1&&(!z&&O||z&&j))&&(p=m==="x"?N:I)}const B={x:d.x+y.x,y:d.y+y.y},D={x:h.x+v.x,y:h.y+v.y},L=Math.max(Math.abs(B.x-p[0].x),Math.abs(D.x-p[0].x)),E=Math.max(Math.abs(B.y-p[0].y),Math.abs(D.y-p[0].y));L>=E?(M=(B.x+D.x)/2,C=p[0].y):(M=p[0].x,C=(B.y+D.y)/2)}return[[e,{x:d.x+y.x,y:d.y+y.y},...p,{x:h.x+v.x,y:h.y+v.y},s],M,C,x,b]}function Ac(e,n,s,r){const i=Math.min(Go(e,n)/2,Go(n,s)/2,r),{x:o,y:a}=n;if(e.x===o&&o===s.x||e.y===a&&a===s.y)return`L${o} ${a}`;if(e.y===a){const d=e.x<s.x?-1:1,h=e.y<s.y?1:-1;return`L ${o+i*d},${a}Q ${o},${a} ${o},${a+i*h}`}const c=e.x<s.x?1:-1,l=e.y<s.y?-1:1;return`L ${o},${a+i*l}Q ${o},${a} ${o+i*c},${a}`}function $s({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top,borderRadius:a=5,centerX:c,centerY:l,offset:d=20,stepPosition:h=.5}){const[f,m,u,p,M]=Lc({source:{x:e,y:n},sourcePosition:s,target:{x:r,y:i},targetPosition:o,center:{x:c,y:l},offset:d,stepPosition:h});return[f.reduce((y,v,x)=>{let b="";return x>0&&x<f.length-1?b=Ac(f[x-1],v,f[x+1],a):b=`${x===0?"M":"L"}${v.x} ${v.y}`,y+=b,y},""),m,u,p,M]}function Ko(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Dc(e){const{sourceNode:n,targetNode:s}=e;if(!Ko(n)||!Ko(s))return null;const r=n.internals.handleBounds||Zo(n.handles),i=s.internals.handleBounds||Zo(s.handles),o=Xo(r?.source??[],e.sourceHandle),a=Xo(e.connectionMode===Yn.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!a)return e.onError?.("008",zt.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const c=o?.position||be.Bottom,l=a?.position||be.Top,d=En(n,o,c),h=En(s,a,l);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:c,targetPosition:l}}function Zo(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 En(e,n,s=be.Left,r=!1){const i=(n?.x??0)+e.internals.positionAbsolute.x,o=(n?.y??0)+e.internals.positionAbsolute.y,{width:a,height:c}=n??Qt(e);if(r)return{x:i+a/2,y:o+c/2};switch(n?.position??s){case be.Top:return{x:i+a/2,y:o};case be.Right:return{x:i+a,y:o+c/2};case be.Bottom:return{x:i+a/2,y:o+c};case be.Left:return{x:i,y:o+c/2}}}function Xo(e,n){return e&&(n?e.find(s=>s.id===n):e[0])||null}function Os(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function Pc(e,{id:n,defaultColor:s,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((a,c)=>([c.markerStart||r,c.markerEnd||i].forEach(l=>{if(l&&typeof l=="object"){const d=Os(l,n);o.has(d)||(a.push({id:d,color:l.color||s,...l}),o.add(d))}}),a),[]).sort((a,c)=>a.id.localeCompare(c.id))}const Ni=1e3,$c=10,Xs={nodeOrigin:[0,0],nodeExtent:mr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Oc={...Xs,checkEquality:!0};function Us(e,n){const s={...e};for(const r in n)n[r]!==void 0&&(s[r]=n[r]);return s}function Bc(e,n,s){const r=Us(Xs,s);for(const i of e.values())if(i.parentId)Js(i,e,n,r);else{const o=wr(i,r.nodeOrigin),a=Xn(i.extent)?i.extent:r.nodeExtent,c=Sn(o,a,Qt(i));i.internals.positionAbsolute=c}}function zc(e,n){if(!e.handles)return e.measured?n?.internals.handleBounds:void 0;const s=[],r=[];for(const i of e.handles){const o={id:i.id,width:i.width??1,height:i.height??1,nodeId:e.id,x:i.x,y:i.y,position:i.position,type:i.type};i.type==="source"?s.push(o):i.type==="target"&&r.push(o)}return{source:s,target:r}}function Qs(e){return e==="manual"}function Bs(e,n,s,r={}){const i=Us(Oc,r),o={i:0},a=new Map(n),c=i?.elevateNodesOnSelect&&!Qs(i.zIndexMode)?Ni:0;let l=e.length>0;n.clear(),s.clear();for(const d of e){let h=a.get(d.id);if(i.checkEquality&&d===h?.internals.userNode)n.set(d.id,h);else{const f=wr(d,i.nodeOrigin),m=Xn(d.extent)?d.extent:i.nodeExtent,u=Sn(f,m,Qt(d));h={...i.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:u,handleBounds:zc(d,h),z:Ci(d,c,i.zIndexMode),userNode:d}},n.set(d.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(l=!1),d.parentId&&Js(h,n,s,r,o)}return l}function Hc(e,n){if(!e.parentId)return;const s=n.get(e.parentId);s?s.set(e.id,e):n.set(e.parentId,new Map([[e.id,e]]))}function Js(e,n,s,r,i){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:c,zIndexMode:l}=Us(Xs,r),d=e.parentId,h=n.get(d);if(!h){console.warn(`Parent node ${d} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Hc(e,s),i&&!h.parentId&&h.internals.rootParentIndex===void 0&&l==="auto"&&(h.internals.rootParentIndex=++i.i,h.internals.z=h.internals.z+i.i*$c),i&&h.internals.rootParentIndex!==void 0&&(i.i=h.internals.rootParentIndex);const f=o&&!Qs(l)?Ni:0,{x:m,y:u,z:p}=qc(e,h,a,c,f,l),{positionAbsolute:M}=e.internals,C=m!==M.x||u!==M.y;(C||p!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:C?{x:m,y:u}:M,z:p}})}function Ci(e,n,s){const r=At(e.zIndex)?e.zIndex:0;return Qs(s)?r:r+(e.selected?n:0)}function qc(e,n,s,r,i,o){const{x:a,y:c}=n.internals.positionAbsolute,l=Qt(e),d=wr(e,s),h=Xn(e.extent)?Sn(d,e.extent,l):d;let f=Sn({x:a+h.x,y:c+h.y},r,l);e.extent==="parent"&&(f=fi(f,l,n));const m=Ci(e,i,o),u=n.internals.z??0;return{x:f.x,y:f.y,z:u>=m?u+1:m}}function eo(e,n,s,r=[0,0]){const i=[],o=new Map;for(const a of e){const c=n.get(a.parentId);if(!c)continue;const l=o.get(a.parentId)?.expandedRect??Zn(c),d=mi(l,a.rect);o.set(a.parentId,{expandedRect:d,parent:c})}return o.size>0&&o.forEach(({expandedRect:a,parent:c},l)=>{const d=c.internals.positionAbsolute,h=Qt(c),f=c.origin??r,m=a.x<d.x?Math.round(Math.abs(d.x-a.x)):0,u=a.y<d.y?Math.round(Math.abs(d.y-a.y)):0,p=Math.max(h.width,Math.round(a.width)),M=Math.max(h.height,Math.round(a.height)),C=(p-h.width)*f[0],y=(M-h.height)*f[1];(m>0||u>0||C||y)&&(i.push({id:l,type:"position",position:{x:c.position.x-m+C,y:c.position.y-u+y}}),s.get(l)?.forEach(v=>{e.some(x=>x.id===v.id)||i.push({id:v.id,type:"position",position:{x:v.position.x+m,y:v.position.y+u}})})),(h.width<a.width||h.height<a.height||m||u)&&i.push({id:l,type:"dimensions",setAttributes:!0,dimensions:{width:p+(m?f[0]*m-C:0),height:M+(u?f[1]*u-y:0)}})}),i}function Wc(e,n,s,r,i,o,a){const c=r?.querySelector(".xyflow__viewport");let l=!1;if(!c)return{changes:[],updatedInternals:l};const d=[],h=window.getComputedStyle(c),{m22:f}=new window.DOMMatrixReadOnly(h.transform),m=[];for(const u of e.values()){const p=n.get(u.id);if(!p)continue;if(p.hidden){n.set(p.id,{...p,internals:{...p.internals,handleBounds:void 0}}),l=!0;continue}const M=Zs(u.nodeElement),C=p.measured.width!==M.width||p.measured.height!==M.height;if(!!(M.width&&M.height&&(C||!p.internals.handleBounds||u.force))){const v=u.nodeElement.getBoundingClientRect(),x=Xn(p.extent)?p.extent:o;let{positionAbsolute:b}=p.internals;p.parentId&&p.extent==="parent"?b=fi(b,M,n.get(p.parentId)):x&&(b=Sn(b,x,M));const k={...p,measured:M,internals:{...p.internals,positionAbsolute:b,handleBounds:{source:Vo("source",u.nodeElement,v,f,p.id),target:Vo("target",u.nodeElement,v,f,p.id)}}};n.set(p.id,k),p.parentId&&Js(k,n,s,{nodeOrigin:i,zIndexMode:a}),l=!0,C&&(d.push({id:p.id,type:"dimensions",dimensions:M}),p.expandParent&&p.parentId&&m.push({id:p.id,parentId:p.parentId,rect:Zn(k,i)}))}}if(m.length>0){const u=eo(m,n,s,i);d.push(...u)}return{changes:d,updatedInternals:l}}async function Vc({delta:e,panZoom:n,transform:s,translateExtent:r,width:i,height:o}){if(!n||!e.x&&!e.y)return Promise.resolve(!1);const a=await n.setViewportConstrained({x:s[0]+e.x,y:s[1]+e.y,zoom:s[2]},[[0,0],[i,o]],r),c=!!a&&(a.x!==s[0]||a.y!==s[1]||a.k!==s[2]);return Promise.resolve(c)}function Uo(e,n,s,r,i,o){let a=i;const c=r.get(a)||new Map;r.set(a,c.set(s,n)),a=`${i}-${e}`;const l=r.get(a)||new Map;if(r.set(a,l.set(s,n)),o){a=`${i}-${e}-${o}`;const d=r.get(a)||new Map;r.set(a,d.set(s,n))}}function Si(e,n,s){e.clear(),n.clear();for(const r of s){const{source:i,target:o,sourceHandle:a=null,targetHandle:c=null}=r,l={edgeId:r.id,source:i,target:o,sourceHandle:a,targetHandle:c},d=`${i}-${a}--${o}-${c}`,h=`${o}-${c}--${i}-${a}`;Uo("source",l,h,e,i,a),Uo("target",l,d,e,o,c),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 Qo(e,n,s){let r=e;do{if(r?.matches?.(n))return!0;if(r===s)return!1;r=r?.parentElement}while(r);return!1}function Fc(e,n,s,r){const i=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!Ei(a,e))&&(a.draggable||n&&typeof a.draggable>"u")){const c=e.get(o);c&&i.set(o,{id:o,position:c.position||{x:0,y:0},distance:{x:s.x-c.internals.positionAbsolute.x,y:s.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:c.measured.width??0,height:c.measured.height??0}})}return i}function Cs({nodeId:e,dragItems:n,nodeLookup:s,dragging:r=!0}){const i=[];for(const[a,c]of n){const l=s.get(a)?.internals.userNode;l&&i.push({...l,position:c.position,dragging:r})}if(!e)return[i[0],i];const o=s.get(e)?.internals.userNode;return[o?{...o,position:n.get(e)?.position||o.position,dragging:r}:i[0],i]}function Yc({dragItems:e,snapGrid:n,x:s,y:r}){const i=e.values().next().value;if(!i)return null;const o={x:s-i.distance.x,y:r-i.distance.y},a=jr(o,n);return{x:a.x-o.x,y:a.y-o.y}}function Gc({onNodeMouseDown:e,getStoreItems:n,onDragStart:s,onDrag:r,onDragStop:i}){let o={x:null,y:null},a=0,c=new Map,l=!1,d={x:0,y:0},h=null,f=!1,m=null,u=!1,p=!1,M=null;function C({noDragClassName:v,handleSelector:x,domNode:b,isSelectable:k,nodeId:N,nodeClickDistance:I=0}){m=gt(b);function B({x:P,y:z}){const{nodeLookup:j,nodeExtent:O,snapGrid:_,snapToGrid:T,nodeOrigin:R,onNodeDrag:A,onSelectionDrag:W,onError:Y,updateNodePositions:F}=n();o={x:P,y:z};let Q=!1;const $=c.size>1,S=$&&O?Ps(kr(c)):null,V=$&&T?Yc({dragItems:c,snapGrid:_,x:P,y:z}):null;for(const[q,H]of c){if(!j.has(q))continue;let Z={x:P-H.distance.x,y:z-H.distance.y};T&&(Z=V?{x:Math.round(Z.x+V.x),y:Math.round(Z.y+V.y)}:jr(Z,_));let J=null;if($&&O&&!H.extent&&S){const{positionAbsolute:X}=H.internals,ie=X.x-S.x+O[0][0],de=X.x+H.measured.width-S.x2+O[1][0],se=X.y-S.y+O[0][1],me=X.y+H.measured.height-S.y2+O[1][1];J=[[ie,se],[de,me]]}const{position:le,positionAbsolute:te}=ui({nodeId:q,nextPosition:Z,nodeLookup:j,nodeExtent:J||O,nodeOrigin:R,onError:Y});Q=Q||H.position.x!==le.x||H.position.y!==le.y,H.position=le,H.internals.positionAbsolute=te}if(p=p||Q,!!Q&&(F(c,!0),M&&(r||A||!N&&W))){const[q,H]=Cs({nodeId:N,dragItems:c,nodeLookup:j});r?.(M,c,q,H),A?.(M,q,H),N||W?.(M,H)}}async function D(){if(!h)return;const{transform:P,panBy:z,autoPanSpeed:j,autoPanOnNodeDrag:O}=n();if(!O){l=!1,cancelAnimationFrame(a);return}const[_,T]=hi(d,h,j);(_!==0||T!==0)&&(o.x=(o.x??0)-_/P[2],o.y=(o.y??0)-T/P[2],await z({x:_,y:T})&&B(o)),a=requestAnimationFrame(D)}function L(P){const{nodeLookup:z,multiSelectionActive:j,nodesDraggable:O,transform:_,snapGrid:T,snapToGrid:R,selectNodesOnDrag:A,onNodeDragStart:W,onSelectionDragStart:Y,unselectNodesAndEdges:F}=n();f=!0,(!A||!k)&&!j&&N&&(z.get(N)?.selected||F()),k&&A&&N&&e?.(N);const Q=dr(P.sourceEvent,{transform:_,snapGrid:T,snapToGrid:R,containerBounds:h});if(o=Q,c=Fc(z,O,Q,N),c.size>0&&(s||W||!N&&Y)){const[$,S]=Cs({nodeId:N,dragItems:c,nodeLookup:z});s?.(P.sourceEvent,c,$,S),W?.(P.sourceEvent,$,S),N||Y?.(P.sourceEvent,S)}}const E=si().clickDistance(I).on("start",P=>{const{domNode:z,nodeDragThreshold:j,transform:O,snapGrid:_,snapToGrid:T}=n();h=z?.getBoundingClientRect()||null,u=!1,p=!1,M=P.sourceEvent,j===0&&L(P),o=dr(P.sourceEvent,{transform:O,snapGrid:_,snapToGrid:T,containerBounds:h}),d=Dt(P.sourceEvent,h)}).on("drag",P=>{const{autoPanOnNodeDrag:z,transform:j,snapGrid:O,snapToGrid:_,nodeDragThreshold:T,nodeLookup:R}=n(),A=dr(P.sourceEvent,{transform:j,snapGrid:O,snapToGrid:_,containerBounds:h});if(M=P.sourceEvent,(P.sourceEvent.type==="touchmove"&&P.sourceEvent.touches.length>1||N&&!R.has(N))&&(u=!0),!u){if(!l&&z&&f&&(l=!0,D()),!f){const W=Dt(P.sourceEvent,h),Y=W.x-d.x,F=W.y-d.y;Math.sqrt(Y*Y+F*F)>T&&L(P)}(o.x!==A.xSnapped||o.y!==A.ySnapped)&&c&&f&&(d=Dt(P.sourceEvent,h),B(A))}}).on("end",P=>{if(!(!f||u)&&(l=!1,f=!1,cancelAnimationFrame(a),c.size>0)){const{nodeLookup:z,updateNodePositions:j,onNodeDragStop:O,onSelectionDragStop:_}=n();if(p&&(j(c,!1),p=!1),i||O||!N&&_){const[T,R]=Cs({nodeId:N,dragItems:c,nodeLookup:z,dragging:!1});i?.(P.sourceEvent,c,T,R),O?.(P.sourceEvent,T,R),N||_?.(P.sourceEvent,R)}}}).filter(P=>{const z=P.target;return!P.button&&(!v||!Qo(z,`.${v}`,b))&&(!x||Qo(z,x,b))});m.call(E)}function y(){m?.on(".drag",null)}return{update:C,destroy:y}}function Kc(e,n,s){const r=[],i={x:e.x-s,y:e.y-s,width:s*2,height:s*2};for(const o of n.values())pr(i,Zn(o))>0&&r.push(o);return r}const Zc=250;function Xc(e,n,s,r){let i=[],o=1/0;const a=Kc(e,s,n+Zc);for(const c of a){const l=[...c.internals.handleBounds?.source??[],...c.internals.handleBounds?.target??[]];for(const d of l){if(r.nodeId===d.nodeId&&r.type===d.type&&r.id===d.id)continue;const{x:h,y:f}=En(c,d,d.position,!0),m=Math.sqrt(Math.pow(h-e.x,2)+Math.pow(f-e.y,2));m>n||(m<o?(i=[{...d,x:h,y:f}],o=m):m===o&&i.push({...d,x:h,y:f}))}}if(!i.length)return null;if(i.length>1){const c=r.type==="source"?"target":"source";return i.find(l=>l.type===c)??i[0]}return i[0]}function Mi(e,n,s,r,i,o=!1){const a=r.get(e);if(!a)return null;const c=i==="strict"?a.internals.handleBounds?.[n]:[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]],l=(s?c?.find(d=>d.id===s):c?.[0])??null;return l&&o?{...l,...En(a,l,l.position,!0)}:l}function Ii(e,n){return e||(n?.classList.contains("target")?"target":n?.classList.contains("source")?"source":null)}function Uc(e,n){let s=null;return n?s=!0:e&&!n&&(s=!1),s}const Ti=()=>!0;function Qc(e,{connectionMode:n,connectionRadius:s,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:a,domNode:c,nodeLookup:l,lib:d,autoPanOnConnect:h,flowId:f,panBy:m,cancelConnection:u,onConnectStart:p,onConnect:M,onConnectEnd:C,isValidConnection:y=Ti,onReconnectEnd:v,updateConnection:x,getTransform:b,getFromHandle:k,autoPanSpeed:N,dragThreshold:I=1,handleDomNode:B}){const D=xi(e.target);let L=0,E;const{x:P,y:z}=Dt(e),j=Ii(o,B),O=c?.getBoundingClientRect();let _=!1;if(!O||!j)return;const T=Mi(i,j,r,l,n);if(!T)return;let R=Dt(e,O),A=!1,W=null,Y=!1,F=null;function Q(){if(!h||!O)return;const[le,te]=hi(R,O,N);m({x:le,y:te}),L=requestAnimationFrame(Q)}const $={...T,nodeId:i,type:j,position:T.position},S=l.get(i);let q={inProgress:!0,isValid:null,from:En(S,$,be.Left,!0),fromHandle:$,fromPosition:$.position,fromNode:S,to:R,toHandle:null,toPosition:zo[$.position],toNode:null,pointer:R};function H(){_=!0,x(q),p?.(e,{nodeId:i,handleId:r,handleType:j})}I===0&&H();function Z(le){if(!_){const{x:me,y:ue}=Dt(le),K=me-P,ce=ue-z;if(!(K*K+ce*ce>I*I))return;H()}if(!k()||!$){J(le);return}const te=b();R=Dt(le,O),E=Xc(Nr(R,te,!1,[1,1]),s,l,$),A||(Q(),A=!0);const X=Ri(le,{handle:E,connectionMode:n,fromNodeId:i,fromHandleId:r,fromType:a?"target":"source",isValidConnection:y,doc:D,lib:d,flowId:f,nodeLookup:l});F=X.handleDomNode,W=X.connection,Y=Uc(!!E,X.isValid);const ie=l.get(i),de=ie?En(ie,$,be.Left,!0):q.from,se={...q,from:de,isValid:Y,to:X.toHandle&&Y?ts({x:X.toHandle.x,y:X.toHandle.y},te):R,toHandle:X.toHandle,toPosition:Y&&X.toHandle?X.toHandle.position:zo[$.position],toNode:X.toHandle?l.get(X.toHandle.nodeId):null,pointer:R};x(se),q=se}function J(le){if(!("touches"in le&&le.touches.length>0)){if(_){(E||F)&&W&&Y&&M?.(W);const{inProgress:te,...X}=q,ie={...X,toPosition:q.toHandle?q.toPosition:null};C?.(le,ie),o&&v?.(le,ie)}u(),cancelAnimationFrame(L),A=!1,Y=!1,W=null,F=null,D.removeEventListener("mousemove",Z),D.removeEventListener("mouseup",J),D.removeEventListener("touchmove",Z),D.removeEventListener("touchend",J)}}D.addEventListener("mousemove",Z),D.addEventListener("mouseup",J),D.addEventListener("touchmove",Z),D.addEventListener("touchend",J)}function Ri(e,{handle:n,connectionMode:s,fromNodeId:r,fromHandleId:i,fromType:o,doc:a,lib:c,flowId:l,isValidConnection:d=Ti,nodeLookup:h}){const f=o==="target",m=n?a.querySelector(`.${c}-flow__handle[data-id="${l}-${n?.nodeId}-${n?.id}-${n?.type}"]`):null,{x:u,y:p}=Dt(e),M=a.elementFromPoint(u,p),C=M?.classList.contains(`${c}-flow__handle`)?M:m,y={handleDomNode:C,isValid:!1,connection:null,toHandle:null};if(C){const v=Ii(void 0,C),x=C.getAttribute("data-nodeid"),b=C.getAttribute("data-handleid"),k=C.classList.contains("connectable"),N=C.classList.contains("connectableend");if(!x||!v)return y;const I={source:f?x:r,sourceHandle:f?b:i,target:f?r:x,targetHandle:f?i:b};y.connection=I;const D=k&&N&&(s===Yn.Strict?f&&v==="source"||!f&&v==="target":x!==r||b!==i);y.isValid=D&&d(I),y.toHandle=Mi(x,v,b,h,s,!0)}return y}const zs={onPointerDown:Qc,isValid:Ri};function Jc({domNode:e,panZoom:n,getTransform:s,getViewScale:r}){const i=gt(e);function o({translateExtent:c,width:l,height:d,zoomStep:h=1,pannable:f=!0,zoomable:m=!0,inversePan:u=!1}){const p=x=>{if(x.sourceEvent.type!=="wheel"||!n)return;const b=s(),k=x.sourceEvent.ctrlKey&&xr()?10:1,N=-x.sourceEvent.deltaY*(x.sourceEvent.deltaMode===1?.05:x.sourceEvent.deltaMode?1:.002)*h,I=b[2]*Math.pow(2,N*k);n.scaleTo(I)};let M=[0,0];const C=x=>{(x.sourceEvent.type==="mousedown"||x.sourceEvent.type==="touchstart")&&(M=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY])},y=x=>{const b=s();if(x.sourceEvent.type!=="mousemove"&&x.sourceEvent.type!=="touchmove"||!n)return;const k=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY],N=[k[0]-M[0],k[1]-M[1]];M=k;const I=r()*Math.max(b[2],Math.log(b[2]))*(u?-1:1),B={x:b[0]-N[0]*I,y:b[1]-N[1]*I},D=[[0,0],[l,d]];n.setViewportConstrained({x:B.x,y:B.y,zoom:b[2]},D,c)},v=oi().on("start",C).on("zoom",f?y:null).on("zoom.wheel",m?p:null);i.call(v,{})}function a(){i.on("zoom",null)}return{update:o,destroy:a,pointer:Lt}}const ls=e=>({x:e.x,y:e.y,zoom:e.k}),Ss=({x:e,y:n,zoom:s})=>Fs.translate(e,n).scale(s),qn=(e,n)=>e.target.closest(`.${n}`),_i=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),ed=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Es=(e,n=0,s=ed,r=()=>{})=>{const i=typeof n=="number"&&n>0;return i||r(),i?e.transition().duration(n).ease(s).on("end",r):e},Li=e=>{const n=e.ctrlKey&&xr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function td({zoomPanValues:e,noWheelClassName:n,d3Selection:s,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:c,onPanZoom:l,onPanZoomEnd:d}){return h=>{if(qn(h,n))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const f=s.property("__zoom").k||1;if(h.ctrlKey&&a){const C=Lt(h),y=Li(h),v=f*Math.pow(2,y);r.scaleTo(s,v,C,h);return}const m=h.deltaMode===1?20:1;let u=i===Cn.Vertical?0:h.deltaX*m,p=i===Cn.Horizontal?0:h.deltaY*m;!xr()&&h.shiftKey&&i!==Cn.Vertical&&(u=h.deltaY*m,p=0),r.translateBy(s,-(u/f)*o,-(p/f)*o,{internal:!0});const M=ls(s.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(l?.(h,M),e.panScrollTimeout=setTimeout(()=>{d?.(h,M),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c?.(h,M))}}function nd({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:s}){return function(r,i){const o=r.type==="wheel",a=!n&&o&&!r.ctrlKey,c=qn(r,e);if(r.ctrlKey&&o&&c&&r.preventDefault(),a||c)return null;r.preventDefault(),s.call(this,r,i)}}function rd({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:s}){return r=>{if(r.sourceEvent?.internal)return;const i=ls(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type==="mousedown"&&n(!0),s&&s?.(r.sourceEvent,i)}}function sd({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:s,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(s&&_i(n,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,ls(o.transform))}}function od({zoomPanValues:e,panOnDrag:n,panOnScroll:s,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return a=>{if(!a.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&_i(n,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const c=ls(a.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(a.sourceEvent,c)},s?150:0)}}}function ad({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:s,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:a,noWheelClassName:c,noPanClassName:l,lib:d,connectionInProgress:h}){return f=>{const m=e||n,u=s&&f.ctrlKey,p=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(qn(f,`${d}-flow__node`)||qn(f,`${d}-flow__edge`)))return!0;if(!r&&!m&&!i&&!o&&!s||a||h&&!p||qn(f,c)&&p||qn(f,l)&&(!p||i&&p&&!e)||!s&&f.ctrlKey&&p)return!1;if(!s&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!m&&!i&&!u&&p||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const M=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||p)&&M}}function id({domNode:e,minZoom:n,maxZoom:s,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:c,onDraggingChange:l}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},h=e.getBoundingClientRect(),f=oi().scaleExtent([n,s]).translateExtent(r),m=gt(e).call(f);v({x:i.x,y:i.y,zoom:Kn(i.zoom,n,s)},[[0,0],[h.width,h.height]],r);const u=m.on("wheel.zoom"),p=m.on("dblclick.zoom");f.wheelDelta(Li);function M(E,P){return m?new Promise(z=>{f?.interpolate(P?.interpolate==="linear"?ks:Xr).transform(Es(m,P?.duration,P?.ease,()=>z(!0)),E)}):Promise.resolve(!1)}function C({noWheelClassName:E,noPanClassName:P,onPaneContextMenu:z,userSelectionActive:j,panOnScroll:O,panOnDrag:_,panOnScrollMode:T,panOnScrollSpeed:R,preventScrolling:A,zoomOnPinch:W,zoomOnScroll:Y,zoomOnDoubleClick:F,zoomActivationKeyPressed:Q,lib:$,onTransformChange:S,connectionInProgress:V,paneClickDistance:q,selectionOnDrag:H}){j&&!d.isZoomingOrPanning&&y();const Z=O&&!Q&&!j;f.clickDistance(H?1/0:!At(q)||q<0?0:q);const J=Z?td({zoomPanValues:d,noWheelClassName:E,d3Selection:m,d3Zoom:f,panOnScrollMode:T,panOnScrollSpeed:R,zoomOnPinch:W,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:c}):nd({noWheelClassName:E,preventScrolling:A,d3ZoomHandler:u});if(m.on("wheel.zoom",J,{passive:!1}),!j){const te=rd({zoomPanValues:d,onDraggingChange:l,onPanZoomStart:a});f.on("start",te);const X=sd({zoomPanValues:d,panOnDrag:_,onPaneContextMenu:!!z,onPanZoom:o,onTransformChange:S});f.on("zoom",X);const ie=od({zoomPanValues:d,panOnDrag:_,panOnScroll:O,onPaneContextMenu:z,onPanZoomEnd:c,onDraggingChange:l});f.on("end",ie)}const le=ad({zoomActivationKeyPressed:Q,panOnDrag:_,zoomOnScroll:Y,panOnScroll:O,zoomOnDoubleClick:F,zoomOnPinch:W,userSelectionActive:j,noPanClassName:P,noWheelClassName:E,lib:$,connectionInProgress:V});f.filter(le),F?m.on("dblclick.zoom",p):m.on("dblclick.zoom",null)}function y(){f.on("zoom",null)}async function v(E,P,z){const j=Ss(E),O=f?.constrain()(j,P,z);return O&&await M(O),new Promise(_=>_(O))}async function x(E,P){const z=Ss(E);return await M(z,P),new Promise(j=>j(z))}function b(E){if(m){const P=Ss(E),z=m.property("__zoom");(z.k!==E.zoom||z.x!==E.x||z.y!==E.y)&&f?.transform(m,P,null,{sync:!0})}}function k(){const E=m?Jl(m.node()):{x:0,y:0,k:1};return{x:E.x,y:E.y,zoom:E.k}}function N(E,P){return m?new Promise(z=>{f?.interpolate(P?.interpolate==="linear"?ks:Xr).scaleTo(Es(m,P?.duration,P?.ease,()=>z(!0)),E)}):Promise.resolve(!1)}function I(E,P){return m?new Promise(z=>{f?.interpolate(P?.interpolate==="linear"?ks:Xr).scaleBy(Es(m,P?.duration,P?.ease,()=>z(!0)),E)}):Promise.resolve(!1)}function B(E){f?.scaleExtent(E)}function D(E){f?.translateExtent(E)}function L(E){const P=!At(E)||E<0?0:E;f?.clickDistance(P)}return{update:C,destroy:y,setViewport:x,setViewportConstrained:v,getViewport:k,scaleTo:N,scaleBy:I,setScaleExtent:B,setTranslateExtent:D,syncViewport:b,setClickDistance:L}}var Un;(function(e){e.Line="line",e.Handle="handle"})(Un||(Un={}));function ld({width:e,prevWidth:n,height:s,prevHeight:r,affectsX:i,affectsY:o}){const a=e-n,c=s-r,l=[a>0?1:a<0?-1:0,c>0?1:c<0?-1:0];return a&&i&&(l[0]=l[0]*-1),c&&o&&(l[1]=l[1]*-1),l}function Jo(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 on(e,n){return Math.max(0,n-e)}function an(e,n){return Math.max(0,e-n)}function Wr(e,n,s){return Math.max(0,n-e,e-s)}function ea(e,n){return e?!n:n}function cd(e,n,s,r,i,o,a,c){let{affectsX:l,affectsY:d}=n;const{isHorizontal:h,isVertical:f}=n,m=h&&f,{xSnapped:u,ySnapped:p}=s,{minWidth:M,maxWidth:C,minHeight:y,maxHeight:v}=r,{x,y:b,width:k,height:N,aspectRatio:I}=e;let B=Math.floor(h?u-e.pointerX:0),D=Math.floor(f?p-e.pointerY:0);const L=k+(l?-B:B),E=N+(d?-D:D),P=-o[0]*k,z=-o[1]*N;let j=Wr(L,M,C),O=Wr(E,y,v);if(a){let R=0,A=0;l&&B<0?R=on(x+B+P,a[0][0]):!l&&B>0&&(R=an(x+L+P,a[1][0])),d&&D<0?A=on(b+D+z,a[0][1]):!d&&D>0&&(A=an(b+E+z,a[1][1])),j=Math.max(j,R),O=Math.max(O,A)}if(c){let R=0,A=0;l&&B>0?R=an(x+B,c[0][0]):!l&&B<0&&(R=on(x+L,c[1][0])),d&&D>0?A=an(b+D,c[0][1]):!d&&D<0&&(A=on(b+E,c[1][1])),j=Math.max(j,R),O=Math.max(O,A)}if(i){if(h){const R=Wr(L/I,y,v)*I;if(j=Math.max(j,R),a){let A=0;!l&&!d||l&&!d&&m?A=an(b+z+L/I,a[1][1])*I:A=on(b+z+(l?B:-B)/I,a[0][1])*I,j=Math.max(j,A)}if(c){let A=0;!l&&!d||l&&!d&&m?A=on(b+L/I,c[1][1])*I:A=an(b+(l?B:-B)/I,c[0][1])*I,j=Math.max(j,A)}}if(f){const R=Wr(E*I,M,C)/I;if(O=Math.max(O,R),a){let A=0;!l&&!d||d&&!l&&m?A=an(x+E*I+P,a[1][0])/I:A=on(x+(d?D:-D)*I+P,a[0][0])/I,O=Math.max(O,A)}if(c){let A=0;!l&&!d||d&&!l&&m?A=on(x+E*I,c[1][0])/I:A=an(x+(d?D:-D)*I,c[0][0])/I,O=Math.max(O,A)}}}D=D+(D<0?O:-O),B=B+(B<0?j:-j),i&&(m?L>E*I?D=(ea(l,d)?-B:B)/I:B=(ea(l,d)?-D:D)*I:h?(D=B/I,d=l):(B=D*I,l=d));const _=l?x+B:x,T=d?b+D:b;return{width:k+(l?-B:B),height:N+(d?-D:D),x:o[0]*B*(l?-1:1)+_,y:o[1]*D*(d?-1:1)+T}}const Ai={width:0,height:0,x:0,y:0},dd={...Ai,pointerX:0,pointerY:0,aspectRatio:1};function ud(e){return[[0,0],[e.measured.width,e.measured.height]]}function fd(e,n,s){const r=n.position.x+e.position.x,i=n.position.y+e.position.y,o=e.measured.width??0,a=e.measured.height??0,c=s[0]*o,l=s[1]*a;return[[r-c,i-l],[r+o-c,i+a-l]]}function hd({domNode:e,nodeId:n,getStoreItems:s,onChange:r,onEnd:i}){const o=gt(e);let a={controlDirection:Jo("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:d,boundaries:h,keepAspectRatio:f,resizeDirection:m,onResizeStart:u,onResize:p,onResizeEnd:M,shouldResize:C}){let y={...Ai},v={...dd};a={boundaries:h,resizeDirection:m,keepAspectRatio:f,controlDirection:Jo(d)};let x,b=null,k=[],N,I,B,D=!1;const L=si().on("start",E=>{const{nodeLookup:P,transform:z,snapGrid:j,snapToGrid:O,nodeOrigin:_,paneDomNode:T}=s();if(x=P.get(n),!x)return;b=T?.getBoundingClientRect()??null;const{xSnapped:R,ySnapped:A}=dr(E.sourceEvent,{transform:z,snapGrid:j,snapToGrid:O,containerBounds:b});y={width:x.measured.width??0,height:x.measured.height??0,x:x.position.x??0,y:x.position.y??0},v={...y,pointerX:R,pointerY:A,aspectRatio:y.width/y.height},N=void 0,x.parentId&&(x.extent==="parent"||x.expandParent)&&(N=P.get(x.parentId),I=N&&x.extent==="parent"?ud(N):void 0),k=[],B=void 0;for(const[W,Y]of P)if(Y.parentId===n&&(k.push({id:W,position:{...Y.position},extent:Y.extent}),Y.extent==="parent"||Y.expandParent)){const F=fd(Y,x,Y.origin??_);B?B=[[Math.min(F[0][0],B[0][0]),Math.min(F[0][1],B[0][1])],[Math.max(F[1][0],B[1][0]),Math.max(F[1][1],B[1][1])]]:B=F}u?.(E,{...y})}).on("drag",E=>{const{transform:P,snapGrid:z,snapToGrid:j,nodeOrigin:O}=s(),_=dr(E.sourceEvent,{transform:P,snapGrid:z,snapToGrid:j,containerBounds:b}),T=[];if(!x)return;const{x:R,y:A,width:W,height:Y}=y,F={},Q=x.origin??O,{width:$,height:S,x:V,y:q}=cd(v,a.controlDirection,_,a.boundaries,a.keepAspectRatio,Q,I,B),H=$!==W,Z=S!==Y,J=V!==R&&H,le=q!==A&&Z;if(!J&&!le&&!H&&!Z)return;if((J||le||Q[0]===1||Q[1]===1)&&(F.x=J?V:y.x,F.y=le?q:y.y,y.x=F.x,y.y=F.y,k.length>0)){const de=V-R,se=q-A;for(const me of k)me.position={x:me.position.x-de+Q[0]*($-W),y:me.position.y-se+Q[1]*(S-Y)},T.push(me)}if((H||Z)&&(F.width=H&&(!a.resizeDirection||a.resizeDirection==="horizontal")?$:y.width,F.height=Z&&(!a.resizeDirection||a.resizeDirection==="vertical")?S:y.height,y.width=F.width,y.height=F.height),N&&x.expandParent){const de=Q[0]*(F.width??0);F.x&&F.x<de&&(y.x=de,v.x=v.x-(F.x-de));const se=Q[1]*(F.height??0);F.y&&F.y<se&&(y.y=se,v.y=v.y-(F.y-se))}const te=ld({width:y.width,prevWidth:W,height:y.height,prevHeight:Y,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),X={...y,direction:te};C?.(E,X)!==!1&&(D=!0,p?.(E,X),r(F,T))}).on("end",E=>{D&&(M?.(E,{...y}),i?.({...y}),D=!1)});o.call(L)}function l(){o.on(".drag",null)}return{update:c,destroy:l}}var Ms={exports:{}},Is={};var ta;function md(){if(ta)return Is;ta=1;var e=Bl(),n=zl();function s(d,h){return d===h&&(d!==0||1/d===1/h)||d!==d&&h!==h}var r=typeof Object.is=="function"?Object.is:s,i=n.useSyncExternalStore,o=e.useRef,a=e.useEffect,c=e.useMemo,l=e.useDebugValue;return Is.useSyncExternalStoreWithSelector=function(d,h,f,m,u){var p=o(null);if(p.current===null){var M={hasValue:!1,value:null};p.current=M}else M=p.current;p=c(function(){function y(N){if(!v){if(v=!0,x=N,N=m(N),u!==void 0&&M.hasValue){var I=M.value;if(u(I,N))return b=I}return b=N}if(I=b,r(x,N))return I;var B=m(N);return u!==void 0&&u(I,B)?(x=N,I):(x=N,b=B)}var v=!1,x,b,k=f===void 0?null:f;return[function(){return y(h())},k===null?void 0:function(){return y(k())}]},[h,f,m,u]);var C=i(d,p[0],p[1]);return a(function(){M.hasValue=!0,M.value=C},[C]),l(C),C},Is}var na;function gd(){return na||(na=1,Ms.exports=md()),Ms.exports}var pd=gd();const xd=Hl(pd),bd={},ra=e=>{let n;const s=new Set,r=(h,f)=>{const m=typeof h=="function"?h(n):h;if(!Object.is(m,n)){const u=n;n=f??(typeof m!="object"||m===null)?m:Object.assign({},n,m),s.forEach(p=>p(n,u))}},i=()=>n,l={setState:r,getState:i,getInitialState:()=>d,subscribe:h=>(s.add(h),()=>s.delete(h)),destroy:()=>{(bd?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),s.clear()}},d=n=e(r,i,l);return l},yd=e=>e?ra(e):ra,{useDebugValue:vd}=ql,{useSyncExternalStoreWithSelector:wd}=xd,kd=e=>e;function Di(e,n=kd,s){const r=wd(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,s);return vd(r),r}const sa=(e,n)=>{const s=yd(e),r=(i,o=n)=>Di(s,i,o);return Object.assign(r,s),r},jd=(e,n)=>e?sa(e,n):sa;function qe(e,n){if(Object.is(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;if(e instanceof Map&&n instanceof Map){if(e.size!==n.size)return!1;for(const[r,i]of e)if(!Object.is(i,n.get(r)))return!1;return!0}if(e instanceof Set&&n instanceof Set){if(e.size!==n.size)return!1;for(const r of e)if(!n.has(r))return!1;return!0}const s=Object.keys(e);if(s.length!==Object.keys(n).length)return!1;for(const r of s)if(!Object.prototype.hasOwnProperty.call(n,r)||!Object.is(e[r],n[r]))return!1;return!0}const cs=g.createContext(null),Nd=cs.Provider,Pi=zt.error001();function Te(e,n){const s=g.useContext(cs);if(s===null)throw new Error(Pi);return Di(s,e,n)}function Be(){const e=g.useContext(cs);if(e===null)throw new Error(Pi);return g.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const oa={display:"none"},Cd={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},$i="react-flow__node-desc",Oi="react-flow__edge-desc",Sd="react-flow__aria-live",Ed=e=>e.ariaLiveMessage,Md=e=>e.ariaLabelConfig;function Id({rfId:e}){const n=Te(Ed);return t.jsx("div",{id:`${Sd}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Cd,children:n})}function Td({rfId:e,disableKeyboardA11y:n}){const s=Te(Md);return t.jsxs(t.Fragment,{children:[t.jsx("div",{id:`${$i}-${e}`,style:oa,children:n?s["node.a11yDescription.default"]:s["node.a11yDescription.keyboardDisabled"]}),t.jsx("div",{id:`${Oi}-${e}`,style:oa,children:s["edge.a11yDescription.default"]}),!n&&t.jsx(Id,{rfId:e})]})}const ds=g.forwardRef(({position:e="top-left",children:n,className:s,style:r,...i},o)=>{const a=`${e}`.split("-");return t.jsx("div",{className:Ze(["react-flow__panel",s,...a]),style:r,ref:o,...i,children:n})});ds.displayName="Panel";function Rd({proOptions:e,position:n="bottom-right"}){return e?.hideAttribution?null:t.jsx(ds,{position:n,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:t.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const _d=e=>{const n=[],s=[];for(const[,r]of e.nodeLookup)r.selected&&n.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&s.push(r);return{selectedNodes:n,selectedEdges:s}},Vr=e=>e.id;function Ld(e,n){return qe(e.selectedNodes.map(Vr),n.selectedNodes.map(Vr))&&qe(e.selectedEdges.map(Vr),n.selectedEdges.map(Vr))}function Ad({onSelectionChange:e}){const n=Be(),{selectedNodes:s,selectedEdges:r}=Te(_d,Ld);return g.useEffect(()=>{const i={nodes:s,edges:r};e?.(i),n.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[s,r,e]),null}const Dd=e=>!!e.onSelectionChangeHandlers;function Pd({onSelectionChange:e}){const n=Te(Dd);return e||n?t.jsx(Ad,{onSelectionChange:e}):null}const Bi=[0,0],$d={x:0,y:0,zoom:1},Od=["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"],aa=[...Od,"rfId"],Bd=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}),ia={translateExtent:mr,nodeOrigin:Bi,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function zd(e){const{setNodes:n,setEdges:s,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:a,reset:c,setDefaultNodesAndEdges:l}=Te(Bd,qe),d=Be();g.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{h.current=ia,c()}),[]);const h=g.useRef(ia);return g.useEffect(()=>{for(const f of aa){const m=e[f],u=h.current[f];m!==u&&(typeof e[f]>"u"||(f==="nodes"?n(m):f==="edges"?s(m):f==="minZoom"?r(m):f==="maxZoom"?i(m):f==="translateExtent"?o(m):f==="nodeExtent"?a(m):f==="ariaLabelConfig"?d.setState({ariaLabelConfig:Cc(m)}):f==="fitView"?d.setState({fitViewQueued:m}):f==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[f]:m})))}h.current=e},aa.map(f=>e[f])),null}function la(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Hd(e){const[n,s]=g.useState(e==="system"?null:e);return g.useEffect(()=>{if(e!=="system"){s(e);return}const r=la(),i=()=>s(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),n!==null?n:la()?.matches?"dark":"light"}const ca=typeof document<"u"?document:null;function br(e=null,n={target:ca,actInsideInputWithModifier:!0}){const[s,r]=g.useState(!1),i=g.useRef(!1),o=g.useRef(new Set([])),[a,c]=g.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
2
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 l=n?.target??ca,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)&&bi(u))return!1;const M=ua(u.code,c);if(o.current.add(u[M]),da(a,o.current,!1)){const C=u.composedPath?.()?.[0]||u.target,y=C?.nodeName==="BUTTON"||C?.nodeName==="A";n.preventDefault!==!1&&(i.current||!y)&&u.preventDefault(),r(!0)}},f=u=>{const p=ua(u.code,c);da(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(u[p]),u.key==="Meta"&&o.current.clear(),i.current=!1},m=()=>{o.current.clear(),r(!1)};return l?.addEventListener("keydown",h),l?.addEventListener("keyup",f),window.addEventListener("blur",m),window.addEventListener("contextmenu",m),()=>{l?.removeEventListener("keydown",h),l?.removeEventListener("keyup",f),window.removeEventListener("blur",m),window.removeEventListener("contextmenu",m)}}},[e,r]),s}function da(e,n,s){return e.filter(r=>s||r.length===n.size).some(r=>r.every(i=>n.has(i)))}function ua(e,n){return n.includes(e)?"code":"key"}const qd=()=>{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:c}=e.getState(),l=Ks(n,r,i,o,a,s?.padding??.1);return c?(await c.setViewport(l,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(n,s={})=>{const{transform:r,snapGrid:i,snapToGrid:o,domNode:a}=e.getState();if(!a)return n;const{x:c,y:l}=a.getBoundingClientRect(),d={x:n.x-c,y:n.y-l},h=s.snapGrid??i,f=s.snapToGrid??o;return Nr(d,r,f,h)},flowToScreenPosition:n=>{const{transform:s,domNode:r}=e.getState();if(!r)return n;const{x:i,y:o}=r.getBoundingClientRect(),a=ts(n,s);return{x:a.x+i,y:a.y+o}}}),[])};function zi(e,n){const s=[],r=new Map,i=[];for(const o of e)if(o.type==="add"){i.push(o);continue}else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const a=r.get(o.id);a?a.push(o):r.set(o.id,[o])}for(const o of n){const a=r.get(o.id);if(!a){s.push(o);continue}if(a[0].type==="remove")continue;if(a[0].type==="replace"){s.push({...a[0].item});continue}const c={...o};for(const l of a)Wd(l,c);s.push(c)}return i.length&&i.forEach(o=>{o.index!==void 0?s.splice(o.index,0,{...o.item}):s.push({...o.item})}),s}function Wd(e,n){switch(e.type){case"select":{n.selected=e.selected;break}case"position":{typeof e.position<"u"&&(n.position=e.position),typeof e.dragging<"u"&&(n.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(n.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(n.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(n.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(n.resizing=e.resizing);break}}}function Hi(e,n){return zi(e,n)}function qi(e,n){return zi(e,n)}function Nn(e,n){return{id:e,type:"select",selected:n}}function Wn(e,n=new Set,s=!1){const r=[];for(const[i,o]of e){const a=n.has(i);!(o.selected===void 0&&!a)&&o.selected!==a&&(s&&(o.selected=a),r.push(Nn(o.id,a)))}return r}function fa({items:e=[],lookup:n}){const s=[],r=new Map(e.map(i=>[i.id,i]));for(const[i,o]of e.entries()){const a=n.get(o.id),c=a?.internals?.userNode??a;c!==void 0&&c!==o&&s.push({id:o.id,item:o,type:"replace"}),c===void 0&&s.push({item:o,type:"add",index:i})}for(const[i]of n)r.get(i)===void 0&&s.push({id:i,type:"remove"});return s}function ha(e){return{id:e.id,type:"remove"}}const ma=e=>gc(e),Vd=e=>di(e);function Wi(e){return g.forwardRef(e)}const Fd=typeof window<"u"?g.useLayoutEffect:g.useEffect;function ga(e){const[n,s]=g.useState(BigInt(0)),[r]=g.useState(()=>Yd(()=>s(i=>i+BigInt(1))));return Fd(()=>{const i=r.get();i.length&&(e(i),r.reset())},[n]),r}function Yd(e){let n=[];return{get:()=>n,reset:()=>{n=[]},push:s=>{n.push(s),e()}}}const Vi=g.createContext(null);function Gd({children:e}){const n=Be(),s=g.useCallback(c=>{const{nodes:l=[],setNodes:d,hasDefaultNodes:h,onNodesChange:f,nodeLookup:m,fitViewQueued:u,onNodesChangeMiddlewareMap:p}=n.getState();let M=l;for(const y of c)M=typeof y=="function"?y(M):y;let C=fa({items:M,lookup:m});for(const y of p.values())C=y(C);h&&d(M),C.length>0?f?.(C):u&&window.requestAnimationFrame(()=>{const{fitViewQueued:y,nodes:v,setNodes:x}=n.getState();y&&x(v)})},[]),r=ga(s),i=g.useCallback(c=>{const{edges:l=[],setEdges:d,hasDefaultEdges:h,onEdgesChange:f,edgeLookup:m}=n.getState();let u=l;for(const p of c)u=typeof p=="function"?p(u):p;h?d(u):f&&f(fa({items:u,lookup:m}))},[]),o=ga(i),a=g.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return t.jsx(Vi.Provider,{value:a,children:e})}function Kd(){const e=g.useContext(Vi);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Zd=e=>!!e.panZoom;function to(){const e=qd(),n=Be(),s=Kd(),r=Te(Zd),i=g.useMemo(()=>{const o=f=>n.getState().nodeLookup.get(f),a=f=>{s.nodeQueue.push(f)},c=f=>{s.edgeQueue.push(f)},l=f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState(),p=ma(f)?f:m.get(f.id),M=p.parentId?pi(p.position,p.measured,p.parentId,m,u):p.position,C={...p,position:M,width:p.measured?.width??p.width,height:p.measured?.height??p.height};return Zn(C)},d=(f,m,u={replace:!1})=>{a(p=>p.map(M=>{if(M.id===f){const C=typeof m=="function"?m(M):m;return u.replace&&ma(C)?C:{...M,...C}}return M}))},h=(f,m,u={replace:!1})=>{c(p=>p.map(M=>{if(M.id===f){const C=typeof m=="function"?m(M):m;return u.replace&&Vd(C)?C:{...M,...C}}return M}))};return{getNodes:()=>n.getState().nodes.map(f=>({...f})),getNode:f=>o(f)?.internals.userNode,getInternalNode:o,getEdges:()=>{const{edges:f=[]}=n.getState();return f.map(m=>({...m}))},getEdge:f=>n.getState().edgeLookup.get(f),setNodes:a,setEdges:c,addNodes:f=>{const m=Array.isArray(f)?f:[f];s.nodeQueue.push(u=>[...u,...m])},addEdges:f=>{const m=Array.isArray(f)?f:[f];s.edgeQueue.push(u=>[...u,...m])},toObject:()=>{const{nodes:f=[],edges:m=[],transform:u}=n.getState(),[p,M,C]=u;return{nodes:f.map(y=>({...y})),edges:m.map(y=>({...y})),viewport:{x:p,y:M,zoom:C}}},deleteElements:async({nodes:f=[],edges:m=[]})=>{const{nodes:u,edges:p,onNodesDelete:M,onEdgesDelete:C,triggerNodeChanges:y,triggerEdgeChanges:v,onDelete:x,onBeforeDelete:b}=n.getState(),{nodes:k,edges:N}=await vc({nodesToRemove:f,edgesToRemove:m,nodes:u,edges:p,onBeforeDelete:b}),I=N.length>0,B=k.length>0;if(I){const D=N.map(ha);C?.(N),v(D)}if(B){const D=k.map(ha);M?.(k),y(D)}return(B||I)&&x?.({nodes:k,edges:N}),{deletedNodes:k,deletedEdges:N}},getIntersectingNodes:(f,m=!0,u)=>{const p=qo(f),M=p?f:l(f),C=u!==void 0;return M?(u||n.getState().nodes).filter(y=>{const v=n.getState().nodeLookup.get(y.id);if(v&&!p&&(y.id===f.id||!v.internals.positionAbsolute))return!1;const x=Zn(C?y:v),b=pr(x,M);return m&&b>0||b>=x.width*x.height||b>=M.width*M.height}):[]},isNodeIntersecting:(f,m,u=!0)=>{const M=qo(f)?f:l(f);if(!M)return!1;const C=pr(M,m);return u&&C>0||C>=m.width*m.height||C>=M.width*M.height},updateNode:d,updateNodeData:(f,m,u={replace:!1})=>{d(f,p=>{const M=typeof m=="function"?m(p):m;return u.replace?{...p,data:M}:{...p,data:{...p.data,...M}}},u)},updateEdge:h,updateEdgeData:(f,m,u={replace:!1})=>{h(f,p=>{const M=typeof m=="function"?m(p):m;return u.replace?{...p,data:M}:{...p,data:{...p.data,...M}}},u)},getNodesBounds:f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState();return pc(f,{nodeLookup:m,nodeOrigin:u})},getHandleConnections:({type:f,id:m,nodeId:u})=>Array.from(n.getState().connectionLookup.get(`${u}-${f}${m?`-${m}`:""}`)?.values()??[]),getNodeConnections:({type:f,handleId:m,nodeId:u})=>Array.from(n.getState().connectionLookup.get(`${u}${f?m?`-${f}-${m}`:`-${f}`:""}`)?.values()??[]),fitView:async f=>{const m=n.getState().fitViewResolver??Nc();return n.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:m}),s.nodeQueue.push(u=>[...u]),m.promise}}},[]);return g.useMemo(()=>({...i,...e,viewportInitialized:r}),[r])}const pa=e=>e.selected,Xd=typeof window<"u"?window:void 0;function Ud({deleteKeyCode:e,multiSelectionKeyCode:n}){const s=Be(),{deleteElements:r}=to(),i=br(e,{actInsideInputWithModifier:!1}),o=br(n,{target:Xd});g.useEffect(()=>{if(i){const{edges:a,nodes:c}=s.getState();r({nodes:c.filter(pa),edges:a.filter(pa)}),s.setState({nodesSelectionActive:!1})}},[i]),g.useEffect(()=>{s.setState({multiSelectionActive:o})},[o])}function Qd(e){const n=Be();g.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=Zs(e.current);(r.height===0||r.width===0)&&n.getState().onError?.("004",zt.error004()),n.setState({width:r.width||500,height:r.height||500})};if(e.current){s(),window.addEventListener("resize",s);const r=new ResizeObserver(()=>s());return r.observe(e.current),()=>{window.removeEventListener("resize",s),r&&e.current&&r.unobserve(e.current)}}},[])}const us={position:"absolute",width:"100%",height:"100%",top:0,left:0},Jd=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function eu({onPaneContextMenu:e,zoomOnScroll:n=!0,zoomOnPinch:s=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:o=Cn.Free,zoomOnDoubleClick:a=!0,panOnDrag:c=!0,defaultViewport:l,translateExtent:d,minZoom:h,maxZoom:f,zoomActivationKeyCode:m,preventScrolling:u=!0,children:p,noWheelClassName:M,noPanClassName:C,onViewportChange:y,isControlledViewport:v,paneClickDistance:x,selectionOnDrag:b}){const k=Be(),N=g.useRef(null),{userSelectionActive:I,lib:B,connectionInProgress:D}=Te(Jd,qe),L=br(m),E=g.useRef();Qd(N);const P=g.useCallback(z=>{y?.({x:z[0],y:z[1],zoom:z[2]}),v||k.setState({transform:z})},[y,v]);return g.useEffect(()=>{if(N.current){E.current=id({domNode:N.current,minZoom:h,maxZoom:f,translateExtent:d,viewport:l,onDraggingChange:_=>k.setState(T=>T.paneDragging===_?T:{paneDragging:_}),onPanZoomStart:(_,T)=>{const{onViewportChangeStart:R,onMoveStart:A}=k.getState();A?.(_,T),R?.(T)},onPanZoom:(_,T)=>{const{onViewportChange:R,onMove:A}=k.getState();A?.(_,T),R?.(T)},onPanZoomEnd:(_,T)=>{const{onViewportChangeEnd:R,onMoveEnd:A}=k.getState();A?.(_,T),R?.(T)}});const{x:z,y:j,zoom:O}=E.current.getViewport();return k.setState({panZoom:E.current,transform:[z,j,O],domNode:N.current.closest(".react-flow")}),()=>{E.current?.destroy()}}},[]),g.useEffect(()=>{E.current?.update({onPaneContextMenu:e,zoomOnScroll:n,zoomOnPinch:s,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:c,zoomActivationKeyPressed:L,preventScrolling:u,noPanClassName:C,userSelectionActive:I,noWheelClassName:M,lib:B,onTransformChange:P,connectionInProgress:D,selectionOnDrag:b,paneClickDistance:x})},[e,n,s,r,i,o,a,c,L,u,C,I,M,B,P,D,b,x]),t.jsx("div",{className:"react-flow__renderer",ref:N,style:us,children:p})}const tu=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function nu(){const{userSelectionActive:e,userSelectionRect:n}=Te(tu,qe);return e&&n?t.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:n.width,height:n.height,transform:`translate(${n.x}px, ${n.y}px)`}}):null}const Ts=(e,n)=>s=>{s.target===n.current&&e?.(s)},ru=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function su({isSelecting:e,selectionKeyPressed:n,selectionMode:s=gr.Full,panOnDrag:r,paneClickDistance:i,selectionOnDrag:o,onSelectionStart:a,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:d,onPaneScroll:h,onPaneMouseEnter:f,onPaneMouseMove:m,onPaneMouseLeave:u,children:p}){const M=Be(),{userSelectionActive:C,elementsSelectable:y,dragging:v,connectionInProgress:x}=Te(ru,qe),b=y&&(e||C),k=g.useRef(null),N=g.useRef(),I=g.useRef(new Set),B=g.useRef(new Set),D=g.useRef(!1),L=R=>{if(D.current||x){D.current=!1;return}l?.(R),M.getState().resetSelectedElements(),M.setState({nodesSelectionActive:!1})},E=R=>{if(Array.isArray(r)&&r?.includes(2)){R.preventDefault();return}d?.(R)},P=h?R=>h(R):void 0,z=R=>{D.current&&(R.stopPropagation(),D.current=!1)},j=R=>{const{domNode:A}=M.getState();if(N.current=A?.getBoundingClientRect(),!N.current)return;const q=R.target===k.current;if(!q&&!!R.target.closest(".nokey")||!e||!(o&&q||n)||R.button!==0||!R.isPrimary)return;R.target?.setPointerCapture?.(R.pointerId),D.current=!1;const{x:Q,y:$}=Dt(R.nativeEvent,N.current);M.setState({userSelectionRect:{width:0,height:0,startX:Q,startY:$,x:Q,y:$}}),q||(R.stopPropagation(),R.preventDefault())},O=R=>{const{userSelectionRect:A,transform:q,nodeLookup:Y,edgeLookup:F,connectionLookup:Q,triggerNodeChanges:$,triggerEdgeChanges:S,defaultEdgeOptions:V,resetSelectedElements:W}=M.getState();if(!N.current||!A)return;const{x:H,y:Z}=Dt(R.nativeEvent,N.current),{startX:J,startY:le}=A;if(!D.current){const se=n?0:i;if(Math.hypot(H-J,Z-le)<=se)return;W(),a?.(R)}D.current=!0;const te={startX:J,startY:le,x:H<J?H:J,y:Z<le?Z:le,width:Math.abs(H-J),height:Math.abs(Z-le)},X=I.current,ie=B.current;I.current=new Set(Gs(Y,te,q,s===gr.Partial,!0).map(se=>se.id)),B.current=new Set;const de=V?.selectable??!0;for(const se of I.current){const me=Q.get(se);if(me)for(const{edgeId:ue}of me.values()){const K=F.get(ue);K&&(K.selectable??de)&&B.current.add(ue)}}if(!Wo(X,I.current)){const se=Wn(Y,I.current,!0);$(se)}if(!Wo(ie,B.current)){const se=Wn(F,B.current);S(se)}M.setState({userSelectionRect:te,userSelectionActive:!0,nodesSelectionActive:!1})},_=R=>{R.button===0&&(R.target?.releasePointerCapture?.(R.pointerId),!C&&R.target===k.current&&M.getState().userSelectionRect&&L?.(R),M.setState({userSelectionActive:!1,userSelectionRect:null}),D.current&&(c?.(R),M.setState({nodesSelectionActive:I.current.size>0})))},T=r===!0||Array.isArray(r)&&r.includes(0);return t.jsxs("div",{className:Ze(["react-flow__pane",{draggable:T,dragging:v,selection:e}]),onClick:b?void 0:Ts(L,k),onContextMenu:Ts(E,k),onWheel:Ts(P,k),onPointerEnter:b?void 0:f,onPointerMove:b?O:m,onPointerUp:b?_:void 0,onPointerDownCapture:b?j:void 0,onClickCapture:b?z:void 0,onPointerLeave:u,ref:k,style:us,children:[p,t.jsx(nu,{})]})}function Hs({id:e,store:n,unselect:s=!1,nodeRef:r}){const{addSelectedNodes:i,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:c,onError:l}=n.getState(),d=c.get(e);if(!d){l?.("012",zt.error012(e));return}n.setState({nodesSelectionActive:!1}),d.selected?(s||d.selected&&a)&&(o({nodes:[d],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function Fi({nodeRef:e,disabled:n=!1,noDragClassName:s,handleSelector:r,nodeId:i,isSelectable:o,nodeClickDistance:a}){const c=Be(),[l,d]=g.useState(!1),h=g.useRef();return g.useEffect(()=>{h.current=Gc({getStoreItems:()=>c.getState(),onNodeMouseDown:f=>{Hs({id:f,store:c,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),g.useEffect(()=>{if(!(n||!e.current||!h.current))return h.current.update({noDragClassName:s,handleSelector:r,domNode:e.current,isSelectable:o,nodeId:i,nodeClickDistance:a}),()=>{h.current?.destroy()}},[s,r,n,o,e,i,a]),l}const ou=e=>n=>n.selected&&(n.draggable||e&&typeof n.draggable>"u");function Yi(){const e=Be();return g.useCallback(s=>{const{nodeExtent:r,snapToGrid:i,snapGrid:o,nodesDraggable:a,onError:c,updateNodePositions:l,nodeLookup:d,nodeOrigin:h}=e.getState(),f=new Map,m=ou(a),u=i?o[0]:5,p=i?o[1]:5,M=s.direction.x*u*s.factor,C=s.direction.y*p*s.factor;for(const[,y]of d){if(!m(y))continue;let v={x:y.internals.positionAbsolute.x+M,y:y.internals.positionAbsolute.y+C};i&&(v=jr(v,o));const{position:x,positionAbsolute:b}=ui({nodeId:y.id,nextPosition:v,nodeLookup:d,nodeExtent:r,nodeOrigin:h,onError:c});y.position=x,y.internals.positionAbsolute=b,f.set(y.id,y)}l(f)},[])}const no=g.createContext(null),au=no.Provider;no.Consumer;const Gi=()=>g.useContext(no),iu=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),lu=(e,n,s)=>r=>{const{connectionClickStartHandle:i,connectionMode:o,connection:a}=r,{fromHandle:c,toHandle:l,isValid:d}=a,h=l?.nodeId===e&&l?.id===n&&l?.type===s;return{connectingFrom:c?.nodeId===e&&c?.id===n&&c?.type===s,connectingTo:h,clickConnecting:i?.nodeId===e&&i?.id===n&&i?.type===s,isPossibleEndHandle:o===Yn.Strict?c?.type!==s:e!==c?.nodeId||n!==c?.id,connectionInProcess:!!c,clickConnectionInProcess:!!i,valid:h&&d}};function cu({type:e="source",position:n=be.Top,isValidConnection:s,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,id:a,onConnect:c,children:l,className:d,onMouseDown:h,onTouchStart:f,...m},u){const p=a||null,M=e==="target",C=Be(),y=Gi(),{connectOnClick:v,noPanClassName:x,rfId:b}=Te(iu,qe),{connectingFrom:k,connectingTo:N,clickConnecting:I,isPossibleEndHandle:B,connectionInProcess:D,clickConnectionInProcess:L,valid:E}=Te(lu(y,p,e),qe);y||C.getState().onError?.("010",zt.error010());const P=O=>{const{defaultEdgeOptions:_,onConnect:T,hasDefaultEdges:R}=C.getState(),A={..._,...O};if(R){const{edges:q,setEdges:Y}=C.getState();Y(Rc(A,q))}T?.(A),c?.(A)},z=O=>{if(!y)return;const _=yi(O.nativeEvent);if(i&&(_&&O.button===0||!_)){const T=C.getState();zs.onPointerDown(O.nativeEvent,{handleDomNode:O.currentTarget,autoPanOnConnect:T.autoPanOnConnect,connectionMode:T.connectionMode,connectionRadius:T.connectionRadius,domNode:T.domNode,nodeLookup:T.nodeLookup,lib:T.lib,isTarget:M,handleId:p,nodeId:y,flowId:T.rfId,panBy:T.panBy,cancelConnection:T.cancelConnection,onConnectStart:T.onConnectStart,onConnectEnd:(...R)=>C.getState().onConnectEnd?.(...R),updateConnection:T.updateConnection,onConnect:P,isValidConnection:s||((...R)=>C.getState().isValidConnection?.(...R)??!0),getTransform:()=>C.getState().transform,getFromHandle:()=>C.getState().connection.fromHandle,autoPanSpeed:T.autoPanSpeed,dragThreshold:T.connectionDragThreshold})}_?h?.(O):f?.(O)},j=O=>{const{onClickConnectStart:_,onClickConnectEnd:T,connectionClickStartHandle:R,connectionMode:A,isValidConnection:q,lib:Y,rfId:F,nodeLookup:Q,connection:$}=C.getState();if(!y||!R&&!i)return;if(!R){_?.(O.nativeEvent,{nodeId:y,handleId:p,handleType:e}),C.setState({connectionClickStartHandle:{nodeId:y,type:e,id:p}});return}const S=xi(O.target),V=s||q,{connection:W,isValid:H}=zs.isValid(O.nativeEvent,{handle:{nodeId:y,id:p,type:e},connectionMode:A,fromNodeId:R.nodeId,fromHandleId:R.id||null,fromType:R.type,isValidConnection:V,flowId:F,doc:S,lib:Y,nodeLookup:Q});H&&W&&P(W);const Z=structuredClone($);delete Z.inProgress,Z.toPosition=Z.toHandle?Z.toHandle.position:null,T?.(O,Z),C.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":p,"data-nodeid":y,"data-handlepos":n,"data-id":`${b}-${y}-${p}-${e}`,className:Ze(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",x,d,{source:!M,target:M,connectable:r,connectablestart:i,connectableend:o,clickconnecting:I,connectingfrom:k,connectingto:N,valid:E,connectionindicator:r&&(!D||B)&&(D||L?o:i)}]),onMouseDown:z,onTouchStart:z,onClick:v?j:void 0,ref:u,...m,children:l})}const dn=g.memo(Wi(cu));function du({data:e,isConnectable:n,sourcePosition:s=be.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(dn,{type:"source",position:s,isConnectable:n})]})}function uu({data:e,isConnectable:n,targetPosition:s=be.Top,sourcePosition:r=be.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(dn,{type:"target",position:s,isConnectable:n}),e?.label,t.jsx(dn,{type:"source",position:r,isConnectable:n})]})}function fu(){return null}function hu({data:e,isConnectable:n,targetPosition:s=be.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(dn,{type:"target",position:s,isConnectable:n}),e?.label]})}const ns={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},xa={input:du,default:uu,output:hu,group:fu};function mu(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}const gu=e=>{const{width:n,height:s,x:r,y:i}=kr(e.nodeLookup,{filter:o=>!!o.selected});return{width:At(n)?n:null,height:At(s)?s:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${i}px)`}};function pu({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:s}){const r=Be(),{width:i,height:o,transformString:a,userSelectionActive:c}=Te(gu,qe),l=Yi(),d=g.useRef(null);g.useEffect(()=>{s||d.current?.focus({preventScroll:!0})},[s]);const h=!c&&i!==null&&o!==null;if(Fi({nodeRef:d,disabled:!h}),!h)return null;const f=e?u=>{const p=r.getState().nodes.filter(M=>M.selected);e(u,p)}:void 0,m=u=>{Object.prototype.hasOwnProperty.call(ns,u.key)&&(u.preventDefault(),l({direction:ns[u.key],factor:u.shiftKey?4:1}))};return t.jsx("div",{className: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 ba=typeof window<"u"?window:void 0,xu=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Ki({children:e,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,paneClickDistance:c,deleteKeyCode:l,selectionKeyCode:d,selectionOnDrag:h,selectionMode:f,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:p,panActivationKeyCode:M,zoomActivationKeyCode:C,elementsSelectable:y,zoomOnScroll:v,zoomOnPinch:x,panOnScroll:b,panOnScrollSpeed:k,panOnScrollMode:N,zoomOnDoubleClick:I,panOnDrag:B,defaultViewport:D,translateExtent:L,minZoom:E,maxZoom:P,preventScrolling:z,onSelectionContextMenu:j,noWheelClassName:O,noPanClassName:_,disableKeyboardA11y:T,onViewportChange:R,isControlledViewport:A}){const{nodesSelectionActive:q,userSelectionActive:Y}=Te(xu,qe),F=br(d,{target:ba}),Q=br(M,{target:ba}),$=Q||B,S=Q||b,V=h&&$!==!0,W=F||Y||V;return Ud({deleteKeyCode:l,multiSelectionKeyCode:p}),t.jsx(eu,{onPaneContextMenu:o,elementsSelectable:y,zoomOnScroll:v,zoomOnPinch:x,panOnScroll:S,panOnScrollSpeed:k,panOnScrollMode:N,zoomOnDoubleClick:I,panOnDrag:!F&&$,defaultViewport:D,translateExtent:L,minZoom:E,maxZoom:P,zoomActivationKeyCode:C,preventScrolling:z,noWheelClassName:O,noPanClassName:_,onViewportChange:R,isControlledViewport:A,paneClickDistance:c,selectionOnDrag:V,children:t.jsxs(su,{onSelectionStart:m,onSelectionEnd:u,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:$,isSelecting:!!W,selectionMode:f,selectionKeyPressed:F,paneClickDistance:c,selectionOnDrag:V,children:[e,q&&t.jsx(pu,{onSelectionContextMenu:j,noPanClassName:_,disableKeyboardA11y:T})]})})}Ki.displayName="FlowRenderer";const bu=g.memo(Ki),yu=e=>n=>e?Gs(n.nodeLookup,{x:0,y:0,width:n.width,height:n.height},n.transform,!0).map(s=>s.id):Array.from(n.nodeLookup.keys());function vu(e){return Te(g.useCallback(yu(e),[e]),qe)}const wu=e=>e.updateNodeInternals;function ku(){const e=Te(wu),[n]=g.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const r=new Map;s.forEach(i=>{const o=i.target.getAttribute("data-id");r.set(o,{id:o,nodeElement:i.target,force:!0})}),e(r)}));return g.useEffect(()=>()=>{n?.disconnect()},[n]),n}function ju({node:e,nodeType:n,hasDimensions:s,resizeObserver:r}){const i=Be(),o=g.useRef(null),a=g.useRef(null),c=g.useRef(e.sourcePosition),l=g.useRef(e.targetPosition),d=g.useRef(n),h=s&&!!e.internals.handleBounds;return g.useEffect(()=>{o.current&&!e.hidden&&(!h||a.current!==o.current)&&(a.current&&r?.unobserve(a.current),r?.observe(o.current),a.current=o.current)},[h,e.hidden]),g.useEffect(()=>()=>{a.current&&(r?.unobserve(a.current),a.current=null)},[]),g.useEffect(()=>{if(o.current){const f=d.current!==n,m=c.current!==e.sourcePosition,u=l.current!==e.targetPosition;(f||m||u)&&(d.current=n,c.current=e.sourcePosition,l.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:o.current,force:!0}]])))}},[e.id,n,e.sourcePosition,e.targetPosition]),o}function Nu({id:e,onClick:n,onMouseEnter:s,onMouseMove:r,onMouseLeave:i,onContextMenu:o,onDoubleClick:a,nodesDraggable:c,elementsSelectable:l,nodesConnectable:d,nodesFocusable:h,resizeObserver:f,noDragClassName:m,noPanClassName:u,disableKeyboardA11y:p,rfId:M,nodeTypes:C,nodeClickDistance:y,onError:v}){const{node:x,internals:b,isParent:k}=Te(H=>{const Z=H.nodeLookup.get(e),J=H.parentLookup.has(e);return{node:Z,internals:Z.internals,isParent:J}},qe);let N=x.type||"default",I=C?.[N]||xa[N];I===void 0&&(v?.("003",zt.error003(N)),N="default",I=C?.default||xa.default);const B=!!(x.draggable||c&&typeof x.draggable>"u"),D=!!(x.selectable||l&&typeof x.selectable>"u"),L=!!(x.connectable||d&&typeof x.connectable>"u"),E=!!(x.focusable||h&&typeof x.focusable>"u"),P=Be(),z=gi(x),j=ju({node:x,nodeType:N,hasDimensions:z,resizeObserver:f}),O=Fi({nodeRef:j,disabled:x.hidden||!B,noDragClassName:m,handleSelector:x.dragHandle,nodeId:e,isSelectable:D,nodeClickDistance:y}),_=Yi();if(x.hidden)return null;const T=Qt(x),R=mu(x),A=D||B||n||s||r||i,q=s?H=>s(H,{...b.userNode}):void 0,Y=r?H=>r(H,{...b.userNode}):void 0,F=i?H=>i(H,{...b.userNode}):void 0,Q=o?H=>o(H,{...b.userNode}):void 0,$=a?H=>a(H,{...b.userNode}):void 0,S=H=>{const{selectNodesOnDrag:Z,nodeDragThreshold:J}=P.getState();D&&(!Z||!B||J>0)&&Hs({id:e,store:P,nodeRef:j}),n&&n(H,{...b.userNode})},V=H=>{if(!(bi(H.nativeEvent)||p)){if(ai.includes(H.key)&&D){const Z=H.key==="Escape";Hs({id:e,store:P,unselect:Z,nodeRef:j})}else if(B&&x.selected&&Object.prototype.hasOwnProperty.call(ns,H.key)){H.preventDefault();const{ariaLabelConfig:Z}=P.getState();P.setState({ariaLiveMessage:Z["node.a11yDescription.ariaLiveMessage"]({direction:H.key.replace("Arrow","").toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),_({direction:ns[H.key],factor:H.shiftKey?4:1})}}},W=()=>{if(p||!j.current?.matches(":focus-visible"))return;const{transform:H,width:Z,height:J,autoPanOnNodeFocus:le,setCenter:te}=P.getState();if(!le)return;Gs(new Map([[e,x]]),{x:0,y:0,width:Z,height:J},H,!0).length>0||te(x.position.x+T.width/2,x.position.y+T.height/2,{zoom:H[2]})};return t.jsx("div",{className:Ze(["react-flow__node",`react-flow__node-${N}`,{[u]:B},x.className,{selected:x.selected,selectable:D,parent:k,draggable:B,dragging:O}]),ref:j,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:A?"all":"none",visibility:z?"visible":"hidden",...x.style,...R},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:q,onMouseMove:Y,onMouseLeave:F,onContextMenu:Q,onClick:S,onDoubleClick:$,onKeyDown:E?V:void 0,tabIndex:E?0:void 0,onFocus:E?W:void 0,role:x.ariaRole??(E?"group":void 0),"aria-roledescription":"node","aria-describedby":p?void 0:`${$i}-${M}`,"aria-label":x.ariaLabel,...x.domAttributes,children:t.jsx(au,{value:e,children:t.jsx(I,{id:e,data:x.data,type:N,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:x.selected??!1,selectable:D,draggable:B,deletable:x.deletable??!0,isConnectable:L,sourcePosition:x.sourcePosition,targetPosition:x.targetPosition,dragging:O,dragHandle:x.dragHandle,zIndex:b.z,parentId:x.parentId,...T})})})}var Cu=g.memo(Nu);const Su=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Zi(e){const{nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,onError:o}=Te(Su,qe),a=vu(e.onlyRenderVisibleElements),c=ku();return t.jsx("div",{className:"react-flow__nodes",style:us,children:a.map(l=>t.jsx(Cu,{id:l,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:c,nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:o},l))})}Zi.displayName="NodeRenderer";const Eu=g.memo(Zi);function Mu(e){return Te(g.useCallback(s=>{if(!e)return s.edges.map(i=>i.id);const r=[];if(s.width&&s.height)for(const i of s.edges){const o=s.nodeLookup.get(i.source),a=s.nodeLookup.get(i.target);o&&a&&Mc({sourceNode:o,targetNode:a,width:s.width,height:s.height,transform:s.transform})&&r.push(i.id)}return r},[e]),qe)}const Iu=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...e&&{stroke:e}};return t.jsx("polyline",{className:"arrow",style:s,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Tu=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...e&&{stroke:e,fill:e}};return t.jsx("polyline",{className:"arrowclosed",style:s,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},ya={[Gn.Arrow]:Iu,[Gn.ArrowClosed]:Tu};function Ru(e){const n=Be();return g.useMemo(()=>Object.prototype.hasOwnProperty.call(ya,e)?ya[e]:(n.getState().onError?.("009",zt.error009(e)),null),[e])}const _u=({id:e,type:n,color:s,width:r=12.5,height:i=12.5,markerUnits:o="strokeWidth",strokeWidth:a,orient:c="auto-start-reverse"})=>{const l=Ru(n);return l?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:c,refX:"0",refY:"0",children:t.jsx(l,{color:s,strokeWidth:a})}):null},Xi=({defaultColor:e,rfId:n})=>{const s=Te(o=>o.edges),r=Te(o=>o.defaultEdgeOptions),i=g.useMemo(()=>Pc(s,{id:n,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[s,r,n,e]);return i.length?t.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:t.jsx("defs",{children:i.map(o=>t.jsx(_u,{id:o.id,type:o.type,color:o.color,width:o.width,height:o.height,markerUnits:o.markerUnits,strokeWidth:o.strokeWidth,orient:o.orient},o.id))})}):null};Xi.displayName="MarkerDefinitions";var Lu=g.memo(Xi);function Ui({x:e,y:n,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:c=2,children:l,className:d,...h}){const[f,m]=g.useState({x:1,y:0,width:0,height:0}),u=Ze(["react-flow__edge-textwrapper",d]),p=g.useRef(null);return g.useEffect(()=>{if(p.current){const M=p.current.getBBox();m({x:M.x,y:M.y,width:M.width,height:M.height})}},[s]),s?t.jsxs("g",{transform:`translate(${e-f.width/2} ${n-f.height/2})`,className:u,visibility:f.width?"visible":"hidden",...h,children:[i&&t.jsx("rect",{width:f.width+2*a[0],x:-a[0],y:-a[1],height:f.height+2*a[1],className:"react-flow__edge-textbg",style:o,rx:c,ry:c}),t.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:p,style:r,children:s}),l]}):null}Ui.displayName="EdgeText";const Au=g.memo(Ui);function fs({path:e,labelX:n,labelY:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,interactionWidth:d=20,...h}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...h,d:e,fill:"none",className: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&&At(n)&&At(s)?t.jsx(Au,{x:n,y:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null]})}function va({pos:e,x1:n,y1:s,x2:r,y2:i}){return e===be.Left||e===be.Right?[.5*(n+r),s]:[n,.5*(s+i)]}function Qi({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top}){const[a,c]=va({pos:s,x1:e,y1:n,x2:r,y2:i}),[l,d]=va({pos:o,x1:r,y1:i,x2:e,y2:n}),[h,f,m,u]=vi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:d});return[`M${e},${n} C${a},${c} ${l},${d} ${r},${i}`,h,f,m,u]}function Ji(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a,targetPosition:c,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:M,markerStart:C,interactionWidth:y})=>{const[v,x,b]=Qi({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:c}),k=e.isInternal?void 0:n;return t.jsx(fs,{id:k,path:v,labelX:x,labelY:b,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:M,markerStart:C,interactionWidth:y})})}const Du=Ji({isInternal:!1}),el=Ji({isInternal:!0});Du.displayName="SimpleBezierEdge";el.displayName="SimpleBezierEdgeInternal";function tl(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,sourcePosition:u=be.Bottom,targetPosition:p=be.Top,markerEnd:M,markerStart:C,pathOptions:y,interactionWidth:v})=>{const[x,b,k]=$s({sourceX:s,sourceY:r,sourcePosition:u,targetX:i,targetY:o,targetPosition:p,borderRadius:y?.borderRadius,offset:y?.offset,stepPosition:y?.stepPosition}),N=e.isInternal?void 0:n;return t.jsx(fs,{id:N,path:x,labelX:b,labelY:k,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:M,markerStart:C,interactionWidth:v})})}const nl=tl({isInternal:!1}),rl=tl({isInternal:!0});nl.displayName="SmoothStepEdge";rl.displayName="SmoothStepEdgeInternal";function sl(e){return g.memo(({id:n,...s})=>{const r=e.isInternal?void 0:n;return t.jsx(nl,{...s,id:r,pathOptions:g.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const Pu=sl({isInternal:!1}),ol=sl({isInternal:!0});Pu.displayName="StepEdge";ol.displayName="StepEdgeInternal";function al(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:p,interactionWidth:M})=>{const[C,y,v]=ji({sourceX:s,sourceY:r,targetX:i,targetY:o}),x=e.isInternal?void 0:n;return t.jsx(fs,{id:x,path:C,labelX:y,labelY:v,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:p,interactionWidth:M})})}const $u=al({isInternal:!1}),il=al({isInternal:!0});$u.displayName="StraightEdge";il.displayName="StraightEdgeInternal";function ll(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a=be.Bottom,targetPosition:c=be.Top,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:M,markerStart:C,pathOptions:y,interactionWidth:v})=>{const[x,b,k]=wi({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:c,curvature:y?.curvature}),N=e.isInternal?void 0:n;return t.jsx(fs,{id:N,path:x,labelX:b,labelY:k,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:M,markerStart:C,interactionWidth:v})})}const Ou=ll({isInternal:!1}),cl=ll({isInternal:!0});Ou.displayName="BezierEdge";cl.displayName="BezierEdgeInternal";const wa={default:cl,straight:il,step:ol,smoothstep:rl,simplebezier:el},ka={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},Bu=(e,n,s)=>s===be.Left?e-n:s===be.Right?e+n:e,zu=(e,n,s)=>s===be.Top?e-n:s===be.Bottom?e+n:e,ja="react-flow__edgeupdater";function Na({position:e,centerX:n,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:o,onMouseOut:a,type:c}){return t.jsx("circle",{onMouseDown:i,onMouseEnter:o,onMouseOut:a,className:Ze([ja,`${ja}-${c}`]),cx:Bu(n,r,e),cy:zu(s,r,e),r,stroke:"transparent",fill:"transparent"})}function Hu({isReconnectable:e,reconnectRadius:n,edge:s,sourceX:r,sourceY:i,targetX:o,targetY:a,sourcePosition:c,targetPosition:l,onReconnect:d,onReconnectStart:h,onReconnectEnd:f,setReconnecting:m,setUpdateHover:u}){const p=Be(),M=(b,k)=>{if(b.button!==0)return;const{autoPanOnConnect:N,domNode:I,connectionMode:B,connectionRadius:D,lib:L,onConnectStart:E,cancelConnection:P,nodeLookup:z,rfId:j,panBy:O,updateConnection:_}=p.getState(),T=k.type==="target",R=(Y,F)=>{m(!1),f?.(Y,s,k.type,F)},A=Y=>d?.(s,Y),q=(Y,F)=>{m(!0),h?.(b,s,k.type),E?.(Y,F)};zs.onPointerDown(b.nativeEvent,{autoPanOnConnect:N,connectionMode:B,connectionRadius:D,domNode:I,handleId:k.id,nodeId:k.nodeId,nodeLookup:z,isTarget:T,edgeUpdaterType:k.type,lib:L,flowId:j,cancelConnection:P,panBy:O,isValidConnection:(...Y)=>p.getState().isValidConnection?.(...Y)??!0,onConnect:A,onConnectStart:q,onConnectEnd:(...Y)=>p.getState().onConnectEnd?.(...Y),onReconnectEnd:R,updateConnection:_,getTransform:()=>p.getState().transform,getFromHandle:()=>p.getState().connection.fromHandle,dragThreshold:p.getState().connectionDragThreshold,handleDomNode:b.currentTarget})},C=b=>M(b,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),y=b=>M(b,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),v=()=>u(!0),x=()=>u(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(Na,{position:c,centerX:r,centerY:i,radius:n,onMouseDown:C,onMouseEnter:v,onMouseOut:x,type:"source"}),(e===!0||e==="target")&&t.jsx(Na,{position:l,centerX:o,centerY:a,radius:n,onMouseDown:y,onMouseEnter:v,onMouseOut:x,type:"target"})]})}function qu({id:e,edgesFocusable:n,edgesReconnectable:s,elementsSelectable:r,onClick:i,onDoubleClick:o,onContextMenu:a,onMouseEnter:c,onMouseMove:l,onMouseLeave:d,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,rfId:p,edgeTypes:M,noPanClassName:C,onError:y,disableKeyboardA11y:v}){let x=Te(te=>te.edgeLookup.get(e));const b=Te(te=>te.defaultEdgeOptions);x=b?{...b,...x}:x;let k=x.type||"default",N=M?.[k]||wa[k];N===void 0&&(y?.("011",zt.error011(k)),k="default",N=M?.default||wa.default);const I=!!(x.focusable||n&&typeof x.focusable>"u"),B=typeof f<"u"&&(x.reconnectable||s&&typeof x.reconnectable>"u"),D=!!(x.selectable||r&&typeof x.selectable>"u"),L=g.useRef(null),[E,P]=g.useState(!1),[z,j]=g.useState(!1),O=Be(),{zIndex:_,sourceX:T,sourceY:R,targetX:A,targetY:q,sourcePosition:Y,targetPosition:F}=Te(g.useCallback(te=>{const X=te.nodeLookup.get(x.source),ie=te.nodeLookup.get(x.target);if(!X||!ie)return{zIndex:x.zIndex,...ka};const de=Dc({id:e,sourceNode:X,targetNode:ie,sourceHandle:x.sourceHandle||null,targetHandle:x.targetHandle||null,connectionMode:te.connectionMode,onError:y});return{zIndex:Ec({selected:x.selected,zIndex:x.zIndex,sourceNode:X,targetNode:ie,elevateOnSelect:te.elevateEdgesOnSelect,zIndexMode:te.zIndexMode}),...de||ka}},[x.source,x.target,x.sourceHandle,x.targetHandle,x.selected,x.zIndex]),qe),Q=g.useMemo(()=>x.markerStart?`url('#${Os(x.markerStart,p)}')`:void 0,[x.markerStart,p]),$=g.useMemo(()=>x.markerEnd?`url('#${Os(x.markerEnd,p)}')`:void 0,[x.markerEnd,p]);if(x.hidden||T===null||R===null||A===null||q===null)return null;const S=te=>{const{addSelectedEdges:X,unselectNodesAndEdges:ie,multiSelectionActive:de}=O.getState();D&&(O.setState({nodesSelectionActive:!1}),x.selected&&de?(ie({nodes:[],edges:[x]}),L.current?.blur()):X([e])),i&&i(te,x)},V=o?te=>{o(te,{...x})}:void 0,W=a?te=>{a(te,{...x})}:void 0,H=c?te=>{c(te,{...x})}:void 0,Z=l?te=>{l(te,{...x})}:void 0,J=d?te=>{d(te,{...x})}:void 0,le=te=>{if(!v&&ai.includes(te.key)&&D){const{unselectNodesAndEdges:X,addSelectedEdges:ie}=O.getState();te.key==="Escape"?(L.current?.blur(),X({edges:[x]})):ie([e])}};return t.jsx("svg",{style:{zIndex:_},children:t.jsxs("g",{className:Ze(["react-flow__edge",`react-flow__edge-${k}`,x.className,C,{selected:x.selected,animated:x.animated,inactive:!D&&!i,updating:E,selectable:D}]),onClick:S,onDoubleClick:V,onContextMenu:W,onMouseEnter:H,onMouseMove:Z,onMouseLeave:J,onKeyDown:I?le:void 0,tabIndex:I?0:void 0,role:x.ariaRole??(I?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":x.ariaLabel===null?void 0:x.ariaLabel||`Edge from ${x.source} to ${x.target}`,"aria-describedby":I?`${Oi}-${p}`:void 0,ref:L,...x.domAttributes,children:[!z&&t.jsx(N,{id:e,source:x.source,target:x.target,type:x.type,selected:x.selected,animated:x.animated,selectable:D,deletable:x.deletable??!0,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,sourceX:T,sourceY:R,targetX:A,targetY:q,sourcePosition:Y,targetPosition:F,data:x.data,style:x.style,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerStart:Q,markerEnd:$,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth}),B&&t.jsx(Hu,{edge:x,isReconnectable:B,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,sourceX:T,sourceY:R,targetX:A,targetY:q,sourcePosition:Y,targetPosition:F,setUpdateHover:P,setReconnecting:j})]})})}var Wu=g.memo(qu);const Vu=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function dl({defaultMarkerColor:e,onlyRenderVisibleElements:n,rfId:s,edgeTypes:r,noPanClassName:i,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:c,onEdgeMouseMove:l,onEdgeMouseLeave:d,onEdgeClick:h,reconnectRadius:f,onEdgeDoubleClick:m,onReconnectStart:u,onReconnectEnd:p,disableKeyboardA11y:M}){const{edgesFocusable:C,edgesReconnectable:y,elementsSelectable:v,onError:x}=Te(Vu,qe),b=Mu(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(Lu,{defaultColor:e,rfId:s}),b.map(k=>t.jsx(Wu,{id:k,edgesFocusable:C,edgesReconnectable:y,elementsSelectable:v,noPanClassName:i,onReconnect:o,onContextMenu:a,onMouseEnter:c,onMouseMove:l,onMouseLeave:d,onClick:h,reconnectRadius:f,onDoubleClick:m,onReconnectStart:u,onReconnectEnd:p,rfId:s,onError:x,edgeTypes:r,disableKeyboardA11y:M},k))]})}dl.displayName="EdgeRenderer";const Fu=g.memo(dl),Yu=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Gu({children:e}){const n=Te(Yu);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function Ku(e){const n=to(),s=g.useRef(!1);g.useEffect(()=>{!s.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),s.current=!0)},[e,n.viewportInitialized])}const Zu=e=>e.panZoom?.syncViewport;function Xu(e){const n=Te(Zu),s=Be();return g.useEffect(()=>{e&&(n?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,n]),null}function Uu(e){return e.connection.inProgress?{...e.connection,to:Nr(e.connection.to,e.transform)}:{...e.connection}}function Qu(e){return Uu}function Ju(e){const n=Qu();return Te(n,qe)}const ef=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function tf({containerStyle:e,style:n,type:s,component:r}){const{nodesConnectable:i,width:o,height:a,isValid:c,inProgress:l}=Te(ef,qe);return!(o&&i&&l)?null:t.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:Ze(["react-flow__connection",ci(c)]),children:t.jsx(ul,{style:n,type:s,CustomComponent:r,isValid:c})})})}const ul=({style:e,type:n=ln.Bezier,CustomComponent:s,isValid:r})=>{const{inProgress:i,from:o,fromNode:a,fromHandle:c,fromPosition:l,to:d,toNode:h,toHandle:f,toPosition:m,pointer:u}=Ju();if(!i)return;if(s)return t.jsx(s,{connectionLineType:n,connectionLineStyle:e,fromNode:a,fromHandle:c,fromX:o.x,fromY:o.y,toX:d.x,toY:d.y,fromPosition:l,toPosition:m,connectionStatus:ci(r),toNode:h,toHandle:f,pointer:u});let p="";const M={sourceX:o.x,sourceY:o.y,sourcePosition:l,targetX:d.x,targetY:d.y,targetPosition:m};switch(n){case ln.Bezier:[p]=wi(M);break;case ln.SimpleBezier:[p]=Qi(M);break;case ln.Step:[p]=$s({...M,borderRadius:0});break;case ln.SmoothStep:[p]=$s(M);break;default:[p]=ji(M)}return t.jsx("path",{d:p,fill:"none",className:"react-flow__connection-path",style:e})};ul.displayName="ConnectionLine";const nf={};function Ca(e=nf){g.useRef(e),Be(),g.useEffect(()=>{},[e])}function rf(){Be(),g.useRef(!1),g.useEffect(()=>{},[])}function fl({nodeTypes:e,edgeTypes:n,onInit:s,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:c,onNodeMouseMove:l,onNodeMouseLeave:d,onNodeContextMenu:h,onSelectionContextMenu:f,onSelectionStart:m,onSelectionEnd:u,connectionLineType:p,connectionLineStyle:M,connectionLineComponent:C,connectionLineContainerStyle:y,selectionKeyCode:v,selectionOnDrag:x,selectionMode:b,multiSelectionKeyCode:k,panActivationKeyCode:N,zoomActivationKeyCode:I,deleteKeyCode:B,onlyRenderVisibleElements:D,elementsSelectable:L,defaultViewport:E,translateExtent:P,minZoom:z,maxZoom:j,preventScrolling:O,defaultMarkerColor:_,zoomOnScroll:T,zoomOnPinch:R,panOnScroll:A,panOnScrollSpeed:q,panOnScrollMode:Y,zoomOnDoubleClick:F,panOnDrag:Q,onPaneClick:$,onPaneMouseEnter:S,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneScroll:H,onPaneContextMenu:Z,paneClickDistance:J,nodeClickDistance:le,onEdgeContextMenu:te,onEdgeMouseEnter:X,onEdgeMouseMove:ie,onEdgeMouseLeave:de,reconnectRadius:se,onReconnect:me,onReconnectStart:ue,onReconnectEnd:K,noDragClassName:ce,noWheelClassName:ge,noPanClassName:ve,disableKeyboardA11y:fe,nodeExtent:re,rfId:xe,viewport:Ee,onViewportChange:ye}){return Ca(e),Ca(n),rf(),Ku(s),Xu(Ee),t.jsx(bu,{onPaneClick:$,onPaneMouseEnter:S,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneContextMenu:Z,onPaneScroll:H,paneClickDistance:J,deleteKeyCode:B,selectionKeyCode:v,selectionOnDrag:x,selectionMode:b,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:k,panActivationKeyCode:N,zoomActivationKeyCode:I,elementsSelectable:L,zoomOnScroll:T,zoomOnPinch:R,zoomOnDoubleClick:F,panOnScroll:A,panOnScrollSpeed:q,panOnScrollMode:Y,panOnDrag:Q,defaultViewport:E,translateExtent:P,minZoom:z,maxZoom:j,onSelectionContextMenu:f,preventScrolling:O,noDragClassName:ce,noWheelClassName:ge,noPanClassName:ve,disableKeyboardA11y:fe,onViewportChange:ye,isControlledViewport:!!Ee,children:t.jsxs(Gu,{children:[t.jsx(Fu,{edgeTypes:n,onEdgeClick:i,onEdgeDoubleClick:a,onReconnect:me,onReconnectStart:ue,onReconnectEnd:K,onlyRenderVisibleElements:D,onEdgeContextMenu:te,onEdgeMouseEnter:X,onEdgeMouseMove:ie,onEdgeMouseLeave:de,reconnectRadius:se,defaultMarkerColor:_,noPanClassName:ve,disableKeyboardA11y:fe,rfId:xe}),t.jsx(tf,{style:M,type:p,component:C,containerStyle:y}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(Eu,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:c,onNodeMouseMove:l,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:le,onlyRenderVisibleElements:D,noPanClassName:ve,noDragClassName:ce,disableKeyboardA11y:fe,nodeExtent:re,rfId:xe}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}fl.displayName="GraphView";const sf=g.memo(fl),Sa=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l=.5,maxZoom:d=2,nodeOrigin:h,nodeExtent:f,zIndexMode:m="basic"}={})=>{const u=new Map,p=new Map,M=new Map,C=new Map,y=r??n??[],v=s??e??[],x=h??[0,0],b=f??mr;Si(M,C,y);const k=Bs(v,u,p,{nodeOrigin:x,nodeExtent:b,zIndexMode:m});let N=[0,0,1];if(a&&i&&o){const I=kr(u,{filter:E=>!!((E.width||E.initialWidth)&&(E.height||E.initialHeight))}),{x:B,y:D,zoom:L}=Ks(I,i,o,l,d,c?.padding??.1);N=[B,D,L]}return{rfId:"1",width:i??0,height:o??0,transform:N,nodes:v,nodesInitialized:k,nodeLookup:u,parentLookup:p,edges:y,edgeLookup:C,connectionLookup:M,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:l,maxZoom:d,translateExtent:mr,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Yn.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:x,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:a??!1,fitViewOptions:c,fitViewResolver:null,connection:{...li},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:wc,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:ii,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},of=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m})=>jd((u,p)=>{async function M(){const{nodeLookup:C,panZoom:y,fitViewOptions:v,fitViewResolver:x,width:b,height:k,minZoom:N,maxZoom:I}=p();y&&(await yc({nodes:C,width:b,height:k,panZoom:y,minZoom:N,maxZoom:I},v),x?.resolve(!0),u({fitViewResolver:null}))}return{...Sa({nodes:e,edges:n,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:d,nodeOrigin:h,nodeExtent:f,defaultNodes:s,defaultEdges:r,zIndexMode:m}),setNodes:C=>{const{nodeLookup:y,parentLookup:v,nodeOrigin:x,elevateNodesOnSelect:b,fitViewQueued:k,zIndexMode:N}=p(),I=Bs(C,y,v,{nodeOrigin:x,nodeExtent:f,elevateNodesOnSelect:b,checkEquality:!0,zIndexMode:N});k&&I?(M(),u({nodes:C,nodesInitialized:I,fitViewQueued:!1,fitViewOptions:void 0})):u({nodes:C,nodesInitialized:I})},setEdges:C=>{const{connectionLookup:y,edgeLookup:v}=p();Si(y,v,C),u({edges:C})},setDefaultNodesAndEdges:(C,y)=>{if(C){const{setNodes:v}=p();v(C),u({hasDefaultNodes:!0})}if(y){const{setEdges:v}=p();v(y),u({hasDefaultEdges:!0})}},updateNodeInternals:C=>{const{triggerNodeChanges:y,nodeLookup:v,parentLookup:x,domNode:b,nodeOrigin:k,nodeExtent:N,debug:I,fitViewQueued:B,zIndexMode:D}=p(),{changes:L,updatedInternals:E}=Wc(C,v,x,b,k,N,D);E&&(Bc(v,x,{nodeOrigin:k,nodeExtent:N,zIndexMode:D}),B?(M(),u({fitViewQueued:!1,fitViewOptions:void 0})):u({}),L?.length>0&&(I&&console.log("React Flow: trigger node changes",L),y?.(L)))},updateNodePositions:(C,y=!1)=>{const v=[];let x=[];const{nodeLookup:b,triggerNodeChanges:k,connection:N,updateConnection:I,onNodesChangeMiddlewareMap:B}=p();for(const[D,L]of C){const E=b.get(D),P=!!(E?.expandParent&&E?.parentId&&L?.position),z={id:D,type:"position",position:P?{x:Math.max(0,L.position.x),y:Math.max(0,L.position.y)}:L.position,dragging:y};if(E&&N.inProgress&&N.fromNode.id===E.id){const j=En(E,N.fromHandle,be.Left,!0);I({...N,from:j})}P&&E.parentId&&v.push({id:D,parentId:E.parentId,rect:{...L.internals.positionAbsolute,width:L.measured.width??0,height:L.measured.height??0}}),x.push(z)}if(v.length>0){const{parentLookup:D,nodeOrigin:L}=p(),E=eo(v,b,D,L);x.push(...E)}for(const D of B.values())x=D(x);k(x)},triggerNodeChanges:C=>{const{onNodesChange:y,setNodes:v,nodes:x,hasDefaultNodes:b,debug:k}=p();if(C?.length){if(b){const N=Hi(C,x);v(N)}k&&console.log("React Flow: trigger node changes",C),y?.(C)}},triggerEdgeChanges:C=>{const{onEdgesChange:y,setEdges:v,edges:x,hasDefaultEdges:b,debug:k}=p();if(C?.length){if(b){const N=qi(C,x);v(N)}k&&console.log("React Flow: trigger edge changes",C),y?.(C)}},addSelectedNodes:C=>{const{multiSelectionActive:y,edgeLookup:v,nodeLookup:x,triggerNodeChanges:b,triggerEdgeChanges:k}=p();if(y){const N=C.map(I=>Nn(I,!0));b(N);return}b(Wn(x,new Set([...C]),!0)),k(Wn(v))},addSelectedEdges:C=>{const{multiSelectionActive:y,edgeLookup:v,nodeLookup:x,triggerNodeChanges:b,triggerEdgeChanges:k}=p();if(y){const N=C.map(I=>Nn(I,!0));k(N);return}k(Wn(v,new Set([...C]))),b(Wn(x,new Set,!0))},unselectNodesAndEdges:({nodes:C,edges:y}={})=>{const{edges:v,nodes:x,nodeLookup:b,triggerNodeChanges:k,triggerEdgeChanges:N}=p(),I=C||x,B=y||v,D=[];for(const E of I){if(!E.selected)continue;const P=b.get(E.id);P&&(P.selected=!1),D.push(Nn(E.id,!1))}const L=[];for(const E of B)E.selected&&L.push(Nn(E.id,!1));k(D),N(L)},setMinZoom:C=>{const{panZoom:y,maxZoom:v}=p();y?.setScaleExtent([C,v]),u({minZoom:C})},setMaxZoom:C=>{const{panZoom:y,minZoom:v}=p();y?.setScaleExtent([v,C]),u({maxZoom:C})},setTranslateExtent:C=>{p().panZoom?.setTranslateExtent(C),u({translateExtent:C})},resetSelectedElements:()=>{const{edges:C,nodes:y,triggerNodeChanges:v,triggerEdgeChanges:x,elementsSelectable:b}=p();if(!b)return;const k=y.reduce((I,B)=>B.selected?[...I,Nn(B.id,!1)]:I,[]),N=C.reduce((I,B)=>B.selected?[...I,Nn(B.id,!1)]:I,[]);v(k),x(N)},setNodeExtent:C=>{const{nodes:y,nodeLookup:v,parentLookup:x,nodeOrigin:b,elevateNodesOnSelect:k,nodeExtent:N,zIndexMode:I}=p();C[0][0]===N[0][0]&&C[0][1]===N[0][1]&&C[1][0]===N[1][0]&&C[1][1]===N[1][1]||(Bs(y,v,x,{nodeOrigin:b,nodeExtent:C,elevateNodesOnSelect:k,checkEquality:!1,zIndexMode:I}),u({nodeExtent:C}))},panBy:C=>{const{transform:y,width:v,height:x,panZoom:b,translateExtent:k}=p();return Vc({delta:C,panZoom:b,transform:y,translateExtent:k,width:v,height:x})},setCenter:async(C,y,v)=>{const{width:x,height:b,maxZoom:k,panZoom:N}=p();if(!N)return Promise.resolve(!1);const I=typeof v?.zoom<"u"?v.zoom:k;return await N.setViewport({x:x/2-C*I,y:b/2-y*I,zoom:I},{duration:v?.duration,ease:v?.ease,interpolate:v?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{u({connection:{...li}})},updateConnection:C=>{u({connection:C})},reset:()=>u({...Sa()})}},Object.is);function af({initialNodes:e,initialEdges:n,defaultNodes:s,defaultEdges:r,initialWidth:i,initialHeight:o,initialMinZoom:a,initialMaxZoom:c,initialFitViewOptions:l,fitView:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m,children:u}){const[p]=g.useState(()=>of({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:d,minZoom:a,maxZoom:c,fitViewOptions:l,nodeOrigin:h,nodeExtent:f,zIndexMode:m}));return t.jsx(Nd,{value:p,children:t.jsx(Gd,{children:u})})}function lf({children:e,nodes:n,edges:s,defaultNodes:r,defaultEdges:i,width:o,height:a,fitView:c,fitViewOptions:l,minZoom:d,maxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u}){return g.useContext(cs)?t.jsx(t.Fragment,{children:e}):t.jsx(af,{initialNodes:n,initialEdges:s,defaultNodes:r,defaultEdges:i,initialWidth:o,initialHeight:a,fitView:c,initialFitViewOptions:l,initialMinZoom:d,initialMaxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u,children:e})}const cf={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function df({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,className:i,nodeTypes:o,edgeTypes:a,onNodeClick:c,onEdgeClick:l,onInit:d,onMove:h,onMoveStart:f,onMoveEnd:m,onConnect:u,onConnectStart:p,onConnectEnd:M,onClickConnectStart:C,onClickConnectEnd:y,onNodeMouseEnter:v,onNodeMouseMove:x,onNodeMouseLeave:b,onNodeContextMenu:k,onNodeDoubleClick:N,onNodeDragStart:I,onNodeDrag:B,onNodeDragStop:D,onNodesDelete:L,onEdgesDelete:E,onDelete:P,onSelectionChange:z,onSelectionDragStart:j,onSelectionDrag:O,onSelectionDragStop:_,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:A,onBeforeDelete:q,connectionMode:Y,connectionLineType:F=ln.Bezier,connectionLineStyle:Q,connectionLineComponent:$,connectionLineContainerStyle:S,deleteKeyCode:V="Backspace",selectionKeyCode:W="Shift",selectionOnDrag:H=!1,selectionMode:Z=gr.Full,panActivationKeyCode:J="Space",multiSelectionKeyCode:le=xr()?"Meta":"Control",zoomActivationKeyCode:te=xr()?"Meta":"Control",snapToGrid:X,snapGrid:ie,onlyRenderVisibleElements:de=!1,selectNodesOnDrag:se,nodesDraggable:me,autoPanOnNodeFocus:ue,nodesConnectable:K,nodesFocusable:ce,nodeOrigin:ge=Bi,edgesFocusable:ve,edgesReconnectable:fe,elementsSelectable:re=!0,defaultViewport:xe=$d,minZoom:Ee=.5,maxZoom:ye=2,translateExtent:Ie=mr,preventScrolling:pt=!0,nodeExtent:rt,defaultMarkerColor:Nt="#b1b1b7",zoomOnScroll:Ct=!0,zoomOnPinch:st=!0,panOnScroll:Ht=!1,panOnScrollSpeed:xt=.5,panOnScrollMode:Jt=Cn.Free,zoomOnDoubleClick:bt=!0,panOnDrag:yt=!0,onPaneClick:Ce,onPaneMouseEnter:Xe,onPaneMouseMove:$e,onPaneMouseLeave:Le,onPaneScroll:et,onPaneContextMenu:qt,paneClickDistance:Wt=1,nodeClickDistance:_e=0,children:Ye,onReconnect:tt,onReconnectStart:un,onReconnectEnd:Mn,onEdgeContextMenu:Ge,onEdgeDoubleClick:Ae,onEdgeMouseEnter:ze,onEdgeMouseMove:De,onEdgeMouseLeave:He,reconnectRadius:dt=10,onNodesChange:Qe,onEdgesChange:it,noDragClassName:ut="nodrag",noWheelClassName:en="nowheel",noPanClassName:Vt="nopan",fitView:St,fitViewOptions:Et,connectOnClick:Je,attributionPosition:ft,proOptions:fn,defaultEdgeOptions:ot,elevateNodesOnSelect:$t=!0,elevateEdgesOnSelect:vt=!1,disableKeyboardA11y:ht=!1,autoPanOnConnect:G,autoPanOnNodeDrag:pe,autoPanSpeed:Ne,connectionRadius:Me,isValidConnection:Se,onError:lt,style:Ft,id:Mt,nodeDragThreshold:tn,connectionDragThreshold:In,viewport:Jn,onViewportChange:hn,width:mn,height:gn,colorMode:Tn="light",debug:pn,onScroll:er,ariaLabelConfig:hs,zIndexMode:xn="basic",...Cr},nn){const It=Mt||"1",Sr=Hd(Tn),Er=g.useCallback(tr=>{tr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),er?.(tr)},[er]);return t.jsx("div",{"data-testid":"rf__wrapper",...Cr,onScroll:Er,style:{...Ft,...cf},ref:nn,className:Ze(["react-flow",i,Sr]),id:Mt,role:"application",children:t.jsxs(lf,{nodes:e,edges:n,width:mn,height:gn,fitView:St,fitViewOptions:Et,minZoom:Ee,maxZoom:ye,nodeOrigin:ge,nodeExtent:rt,zIndexMode:xn,children:[t.jsx(sf,{onInit:d,onNodeClick:c,onEdgeClick:l,onNodeMouseEnter:v,onNodeMouseMove:x,onNodeMouseLeave:b,onNodeContextMenu:k,onNodeDoubleClick:N,nodeTypes:o,edgeTypes:a,connectionLineType:F,connectionLineStyle:Q,connectionLineComponent:$,connectionLineContainerStyle:S,selectionKeyCode:W,selectionOnDrag:H,selectionMode:Z,deleteKeyCode:V,multiSelectionKeyCode:le,panActivationKeyCode:J,zoomActivationKeyCode:te,onlyRenderVisibleElements:de,defaultViewport:xe,translateExtent:Ie,minZoom:Ee,maxZoom:ye,preventScrolling:pt,zoomOnScroll:Ct,zoomOnPinch:st,zoomOnDoubleClick:bt,panOnScroll:Ht,panOnScrollSpeed:xt,panOnScrollMode:Jt,panOnDrag:yt,onPaneClick:Ce,onPaneMouseEnter:Xe,onPaneMouseMove:$e,onPaneMouseLeave:Le,onPaneScroll:et,onPaneContextMenu:qt,paneClickDistance:Wt,nodeClickDistance:_e,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:A,onReconnect:tt,onReconnectStart:un,onReconnectEnd:Mn,onEdgeContextMenu:Ge,onEdgeDoubleClick:Ae,onEdgeMouseEnter:ze,onEdgeMouseMove:De,onEdgeMouseLeave:He,reconnectRadius:dt,defaultMarkerColor:Nt,noDragClassName:ut,noWheelClassName:en,noPanClassName:Vt,rfId:It,disableKeyboardA11y:ht,nodeExtent:rt,viewport:Jn,onViewportChange:hn}),t.jsx(zd,{nodes:e,edges:n,defaultNodes:s,defaultEdges:r,onConnect:u,onConnectStart:p,onConnectEnd:M,onClickConnectStart:C,onClickConnectEnd:y,nodesDraggable:me,autoPanOnNodeFocus:ue,nodesConnectable:K,nodesFocusable:ce,edgesFocusable:ve,edgesReconnectable:fe,elementsSelectable:re,elevateNodesOnSelect:$t,elevateEdgesOnSelect:vt,minZoom:Ee,maxZoom:ye,nodeExtent:rt,onNodesChange:Qe,onEdgesChange:it,snapToGrid:X,snapGrid:ie,connectionMode:Y,translateExtent:Ie,connectOnClick:Je,defaultEdgeOptions:ot,fitView:St,fitViewOptions:Et,onNodesDelete:L,onEdgesDelete:E,onDelete:P,onNodeDragStart:I,onNodeDrag:B,onNodeDragStop:D,onSelectionDrag:O,onSelectionDragStart:j,onSelectionDragStop:_,onMove:h,onMoveStart:f,onMoveEnd:m,noPanClassName:Vt,nodeOrigin:ge,rfId:It,autoPanOnConnect:G,autoPanOnNodeDrag:pe,autoPanSpeed:Ne,onError:lt,connectionRadius:Me,isValidConnection:Se,selectNodesOnDrag:se,nodeDragThreshold:tn,connectionDragThreshold:In,onBeforeDelete:q,debug:pn,ariaLabelConfig:hs,zIndexMode:xn}),t.jsx(Pd,{onSelectionChange:z}),Ye,t.jsx(Rd,{proOptions:fn,position:ft}),t.jsx(Td,{rfId:It,disableKeyboardA11y:ht})]})})}var uf=Wi(df);function ff(){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 c=s?.querySelector(`.react-flow__node[data-id="${a}"]`);c&&o.set(a,{id:a,nodeElement:c,force:!0})}),requestAnimationFrame(()=>r(o,{triggerFitView:!1}))},[])}function hf(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>Hi(i,o)),[]);return[n,s,r]}function mf(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>qi(i,o)),[]);return[n,s,r]}function gf({dimensions:e,lineWidth:n,variant:s,className:r}){return t.jsx("path",{strokeWidth:n,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Ze(["react-flow__background-pattern",s,r])})}function pf({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Ze(["react-flow__background-pattern","dots",n])})}var cn;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(cn||(cn={}));const xf={[cn.Dots]:1,[cn.Lines]:1,[cn.Cross]:6},bf=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function hl({id:e,variant:n=cn.Dots,gap:s=20,size:r,lineWidth:i=1,offset:o=0,color:a,bgColor:c,style:l,className:d,patternClassName:h}){const f=g.useRef(null),{transform:m,patternId:u}=Te(bf,qe),p=r||xf[n],M=n===cn.Dots,C=n===cn.Cross,y=Array.isArray(s)?s:[s,s],v=[y[0]*m[2]||1,y[1]*m[2]||1],x=p*m[2],b=Array.isArray(o)?o:[o,o],k=C?[x,x]:v,N=[b[0]*m[2]||1+k[0]/2,b[1]*m[2]||1+k[1]/2],I=`${u}${e||""}`;return t.jsxs("svg",{className:Ze(["react-flow__background",d]),style:{...l,...us,"--xy-background-color-props":c,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[t.jsx("pattern",{id:I,x:m[0]%v[0],y:m[1]%v[1],width:v[0],height:v[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${N[0]},-${N[1]})`,children:M?t.jsx(pf,{radius:x/2,className:h}):t.jsx(gf,{dimensions:k,lineWidth:i,variant:n,className:h})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${I})`})]})}hl.displayName="Background";const yf=g.memo(hl);function vf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:t.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function wf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:t.jsx("path",{d:"M0 0h32v4.2H0z"})})}function kf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:t.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function jf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function Nf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Fr({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:Ze(["react-flow__controls-button",n]),...s,children:e})}const Cf=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function ml({style:e,showZoom:n=!0,showFitView:s=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:o,onZoomOut:a,onFitView:c,onInteractiveChange:l,className:d,children:h,position:f="bottom-left",orientation:m="vertical","aria-label":u}){const p=Be(),{isInteractive:M,minZoomReached:C,maxZoomReached:y,ariaLabelConfig:v}=Te(Cf,qe),{zoomIn:x,zoomOut:b,fitView:k}=to(),N=()=>{x(),o?.()},I=()=>{b(),a?.()},B=()=>{k(i),c?.()},D=()=>{p.setState({nodesDraggable:!M,nodesConnectable:!M,elementsSelectable:!M}),l?.(!M)},L=m==="horizontal"?"horizontal":"vertical";return t.jsxs(ds,{className:Ze(["react-flow__controls",L,d]),position:f,style:e,"data-testid":"rf__controls","aria-label":u??v["controls.ariaLabel"],children:[n&&t.jsxs(t.Fragment,{children:[t.jsx(Fr,{onClick:N,className:"react-flow__controls-zoomin",title:v["controls.zoomIn.ariaLabel"],"aria-label":v["controls.zoomIn.ariaLabel"],disabled:y,children:t.jsx(vf,{})}),t.jsx(Fr,{onClick:I,className:"react-flow__controls-zoomout",title:v["controls.zoomOut.ariaLabel"],"aria-label":v["controls.zoomOut.ariaLabel"],disabled:C,children:t.jsx(wf,{})})]}),s&&t.jsx(Fr,{className:"react-flow__controls-fitview",onClick:B,title:v["controls.fitView.ariaLabel"],"aria-label":v["controls.fitView.ariaLabel"],children:t.jsx(kf,{})}),r&&t.jsx(Fr,{className:"react-flow__controls-interactive",onClick:D,title:v["controls.interactive.ariaLabel"],"aria-label":v["controls.interactive.ariaLabel"],children:M?t.jsx(Nf,{}):t.jsx(jf,{})}),h]})}ml.displayName="Controls";const Sf=g.memo(ml);function Ef({id:e,x:n,y:s,width:r,height:i,style:o,color:a,strokeColor:c,strokeWidth:l,className:d,borderRadius:h,shapeRendering:f,selected:m,onClick:u}){const{background:p,backgroundColor:M}=o||{},C=a||p||M;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:C,stroke:c,strokeWidth:l},shapeRendering:f,onClick:u?y=>u(y,e):void 0})}const Mf=g.memo(Ef),If=e=>e.nodes.map(n=>n.id),Rs=e=>e instanceof Function?e:()=>e;function Tf({nodeStrokeColor:e,nodeColor:n,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:o=Mf,onClick:a}){const c=Te(If,qe),l=Rs(n),d=Rs(e),h=Rs(s),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:c.map(m=>t.jsx(_f,{id:m,nodeColorFunc:l,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:o,onClick:a,shapeRendering:f},m))})}function Rf({id:e,nodeColorFunc:n,nodeStrokeColorFunc:s,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:o,shapeRendering:a,NodeComponent:c,onClick:l}){const{node:d,x:h,y:f,width:m,height:u}=Te(p=>{const M=p.nodeLookup.get(e);if(!M)return{node:void 0,x:0,y:0,width:0,height:0};const C=M.internals.userNode,{x:y,y:v}=M.internals.positionAbsolute,{width:x,height:b}=Qt(C);return{node:C,x:y,y:v,width:x,height:b}},qe);return!d||d.hidden||!gi(d)?null:t.jsx(c,{x:h,y:f,width:m,height:u,style:d.style,selected:!!d.selected,className:r(d),color:n(d),borderRadius:i,strokeColor:s(d),strokeWidth:o,shapeRendering:a,onClick:l,id:d.id})}const _f=g.memo(Rf);var Lf=g.memo(Tf);const Af=200,Df=150,Pf=e=>!e.hidden,$f=e=>{const n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:e.nodeLookup.size>0?mi(kr(e.nodeLookup,{filter:Pf}),n):n,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Of="react-flow__minimap-desc";function gl({style:e,className:n,nodeStrokeColor:s,nodeColor:r,nodeClassName:i="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:c,bgColor:l,maskColor:d,maskStrokeColor:h,maskStrokeWidth:f,position:m="bottom-right",onClick:u,onNodeClick:p,pannable:M=!1,zoomable:C=!1,ariaLabel:y,inversePan:v,zoomStep:x=1,offsetScale:b=5}){const k=Be(),N=g.useRef(null),{boundingRect:I,viewBB:B,rfId:D,panZoom:L,translateExtent:E,flowWidth:P,flowHeight:z,ariaLabelConfig:j}=Te($f,qe),O=e?.width??Af,_=e?.height??Df,T=I.width/O,R=I.height/_,A=Math.max(T,R),q=A*O,Y=A*_,F=b*A,Q=I.x-(q-I.width)/2-F,$=I.y-(Y-I.height)/2-F,S=q+F*2,V=Y+F*2,W=`${Of}-${D}`,H=g.useRef(0),Z=g.useRef();H.current=A,g.useEffect(()=>{if(N.current&&L)return Z.current=Jc({domNode:N.current,panZoom:L,getTransform:()=>k.getState().transform,getViewScale:()=>H.current}),()=>{Z.current?.destroy()}},[L]),g.useEffect(()=>{Z.current?.update({translateExtent:E,width:P,height:z,inversePan:v,pannable:M,zoomStep:x,zoomable:C})},[M,C,v,x,E,P,z]);const J=u?X=>{const[ie,de]=Z.current?.pointer(X)||[0,0];u(X,{x:ie,y:de})}:void 0,le=p?g.useCallback((X,ie)=>{const de=k.getState().nodeLookup.get(ie).internals.userNode;p(X,de)},[]):void 0,te=y??j["minimap.ariaLabel"];return t.jsx(ds,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*A: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:O,height:_,viewBox:`${Q} ${$} ${S} ${V}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":W,ref:N,onClick:J,children:[te&&t.jsx("title",{id:W,children:te}),t.jsx(Lf,{onClick:le,nodeColor:r,nodeStrokeColor:s,nodeBorderRadius:o,nodeClassName:i,nodeStrokeWidth:a,nodeComponent:c}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${Q-F},${$-F}h${S+F*2}v${V+F*2}h${-S-F*2}z
7
- M${B.x},${B.y}h${B.width}v${B.height}h${-B.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}gl.displayName="MiniMap";const Bf=g.memo(gl),zf=e=>n=>e?`${Math.max(1/n.transform[2],1)}`:void 0,Hf={[Un.Line]:"right",[Un.Handle]:"bottom-right"};function qf({nodeId:e,position:n,variant:s=Un.Handle,className:r,style:i=void 0,children:o,color:a,minWidth:c=10,minHeight:l=10,maxWidth:d=Number.MAX_VALUE,maxHeight:h=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:m,autoScale:u=!0,shouldResize:p,onResizeStart:M,onResize:C,onResizeEnd:y}){const v=Gi(),x=typeof e=="string"?e:v,b=Be(),k=g.useRef(null),N=s===Un.Handle,I=Te(g.useCallback(zf(N&&u),[N,u]),qe),B=g.useRef(null),D=n??Hf[s];g.useEffect(()=>{if(!(!k.current||!x))return B.current||(B.current=hd({domNode:k.current,nodeId:x,getStoreItems:()=>{const{nodeLookup:E,transform:P,snapGrid:z,snapToGrid:j,nodeOrigin:O,domNode:_}=b.getState();return{nodeLookup:E,transform:P,snapGrid:z,snapToGrid:j,nodeOrigin:O,paneDomNode:_}},onChange:(E,P)=>{const{triggerNodeChanges:z,nodeLookup:j,parentLookup:O,nodeOrigin:_}=b.getState(),T=[],R={x:E.x,y:E.y},A=j.get(x);if(A&&A.expandParent&&A.parentId){const q=A.origin??_,Y=E.width??A.measured.width??0,F=E.height??A.measured.height??0,Q={id:A.id,parentId:A.parentId,rect:{width:Y,height:F,...pi({x:E.x??A.position.x,y:E.y??A.position.y},{width:Y,height:F},A.parentId,j,q)}},$=eo([Q],j,O,_);T.push(...$),R.x=E.x?Math.max(q[0]*Y,E.x):void 0,R.y=E.y?Math.max(q[1]*F,E.y):void 0}if(R.x!==void 0&&R.y!==void 0){const q={id:x,type:"position",position:{...R}};T.push(q)}if(E.width!==void 0&&E.height!==void 0){const Y={id:x,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:E.width,height:E.height}};T.push(Y)}for(const q of P){const Y={...q,type:"position"};T.push(Y)}z(T)},onEnd:({width:E,height:P})=>{const z={id:x,type:"dimensions",resizing:!1,dimensions:{width:E,height:P}};b.getState().triggerNodeChanges([z])}})),B.current.update({controlPosition:D,boundaries:{minWidth:c,minHeight:l,maxWidth:d,maxHeight:h},keepAspectRatio:f,resizeDirection:m,onResizeStart:M,onResize:C,onResizeEnd:y,shouldResize:p}),()=>{B.current?.destroy()}},[D,c,l,d,h,f,M,C,y,p]);const L=D.split("-");return t.jsx("div",{className:Ze(["react-flow__resize-control","nodrag",...L,s,r]),ref:k,style:{...i,scale:I,...a&&{[N?"backgroundColor":"borderColor"]:a}},children:o})}g.memo(qf);var Pe=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),Pt=Pe((e,n)=>{var s=Object.defineProperty,r=(z,j,O)=>j in z?s(z,j,{enumerable:!0,configurable:!0,writable:!0,value:O}):z[j]=O,i=(z,j)=>()=>(j||z((j={exports:{}}).exports,j),j.exports),o=(z,j,O)=>r(z,typeof j!="symbol"?j+"":j,O),a=i((z,j)=>{var O="\0",_="\0",T="",R=class{constructor($){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"),$&&(this._isDirected=Object.hasOwn($,"directed")?$.directed:!0,this._isMultigraph=Object.hasOwn($,"multigraph")?$.multigraph:!1,this._isCompound=Object.hasOwn($,"compound")?$.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[_]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph($){return this._label=$,this}graph(){return this._label}setDefaultNodeLabel($){return this._defaultNodeLabelFn=$,typeof $!="function"&&(this._defaultNodeLabelFn=()=>$),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var $=this;return this.nodes().filter(S=>Object.keys($._in[S]).length===0)}sinks(){var $=this;return this.nodes().filter(S=>Object.keys($._out[S]).length===0)}setNodes($,S){var V=arguments,W=this;return $.forEach(function(H){V.length>1?W.setNode(H,S):W.setNode(H)}),this}setNode($,S){return Object.hasOwn(this._nodes,$)?(arguments.length>1&&(this._nodes[$]=S),this):(this._nodes[$]=arguments.length>1?S:this._defaultNodeLabelFn($),this._isCompound&&(this._parent[$]=_,this._children[$]={},this._children[_][$]=!0),this._in[$]={},this._preds[$]={},this._out[$]={},this._sucs[$]={},++this._nodeCount,this)}node($){return this._nodes[$]}hasNode($){return Object.hasOwn(this._nodes,$)}removeNode($){var S=this;if(Object.hasOwn(this._nodes,$)){var V=W=>S.removeEdge(S._edgeObjs[W]);delete this._nodes[$],this._isCompound&&(this._removeFromParentsChildList($),delete this._parent[$],this.children($).forEach(function(W){S.setParent(W)}),delete this._children[$]),Object.keys(this._in[$]).forEach(V),delete this._in[$],delete this._preds[$],Object.keys(this._out[$]).forEach(V),delete this._out[$],delete this._sucs[$],--this._nodeCount}return this}setParent($,S){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(S===void 0)S=_;else{S+="";for(var V=S;V!==void 0;V=this.parent(V))if(V===$)throw new Error("Setting "+S+" as parent of "+$+" would create a cycle");this.setNode(S)}return this.setNode($),this._removeFromParentsChildList($),this._parent[$]=S,this._children[S][$]=!0,this}_removeFromParentsChildList($){delete this._children[this._parent[$]][$]}parent($){if(this._isCompound){var S=this._parent[$];if(S!==_)return S}}children($=_){if(this._isCompound){var S=this._children[$];if(S)return Object.keys(S)}else{if($===_)return this.nodes();if(this.hasNode($))return[]}}predecessors($){var S=this._preds[$];if(S)return Object.keys(S)}successors($){var S=this._sucs[$];if(S)return Object.keys(S)}neighbors($){var S=this.predecessors($);if(S){let W=new Set(S);for(var V of this.successors($))W.add(V);return Array.from(W.values())}}isLeaf($){var S;return this.isDirected()?S=this.successors($):S=this.neighbors($),S.length===0}filterNodes($){var S=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});S.setGraph(this.graph());var V=this;Object.entries(this._nodes).forEach(function([Z,J]){$(Z)&&S.setNode(Z,J)}),Object.values(this._edgeObjs).forEach(function(Z){S.hasNode(Z.v)&&S.hasNode(Z.w)&&S.setEdge(Z,V.edge(Z))});var W={};function H(Z){var J=V.parent(Z);return J===void 0||S.hasNode(J)?(W[Z]=J,J):J in W?W[J]:H(J)}return this._isCompound&&S.nodes().forEach(Z=>S.setParent(Z,H(Z))),S}setDefaultEdgeLabel($){return this._defaultEdgeLabelFn=$,typeof $!="function"&&(this._defaultEdgeLabelFn=()=>$),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath($,S){var V=this,W=arguments;return $.reduce(function(H,Z){return W.length>1?V.setEdge(H,Z,S):V.setEdge(H,Z),Z}),this}setEdge(){var $,S,V,W,H=!1,Z=arguments[0];typeof Z=="object"&&Z!==null&&"v"in Z?($=Z.v,S=Z.w,V=Z.name,arguments.length===2&&(W=arguments[1],H=!0)):($=Z,S=arguments[1],V=arguments[3],arguments.length>2&&(W=arguments[2],H=!0)),$=""+$,S=""+S,V!==void 0&&(V=""+V);var J=Y(this._isDirected,$,S,V);if(Object.hasOwn(this._edgeLabels,J))return H&&(this._edgeLabels[J]=W),this;if(V!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode($),this.setNode(S),this._edgeLabels[J]=H?W:this._defaultEdgeLabelFn($,S,V);var le=F(this._isDirected,$,S,V);return $=le.v,S=le.w,Object.freeze(le),this._edgeObjs[J]=le,A(this._preds[S],$),A(this._sucs[$],S),this._in[S][J]=le,this._out[$][J]=le,this._edgeCount++,this}edge($,S,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,S,V);return this._edgeLabels[W]}edgeAsObj(){let $=this.edge(...arguments);return typeof $!="object"?{label:$}:$}hasEdge($,S,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,S,V);return Object.hasOwn(this._edgeLabels,W)}removeEdge($,S,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,S,V),H=this._edgeObjs[W];return H&&($=H.v,S=H.w,delete this._edgeLabels[W],delete this._edgeObjs[W],q(this._preds[S],$),q(this._sucs[$],S),delete this._in[S][W],delete this._out[$][W],this._edgeCount--),this}inEdges($,S){return this.isDirected()?this.filterEdges(this._in[$],$,S):this.nodeEdges($,S)}outEdges($,S){return this.isDirected()?this.filterEdges(this._out[$],$,S):this.nodeEdges($,S)}nodeEdges($,S){if($ in this._nodes)return this.filterEdges({...this._in[$],...this._out[$]},$,S)}filterEdges($,S,V){if($){var W=Object.values($);return V?W.filter(function(H){return H.v===S&&H.w===V||H.v===V&&H.w===S}):W}}};function A($,S){$[S]?$[S]++:$[S]=1}function q($,S){--$[S]||delete $[S]}function Y($,S,V,W){var H=""+S,Z=""+V;if(!$&&H>Z){var J=H;H=Z,Z=J}return H+T+Z+T+(W===void 0?O:W)}function F($,S,V,W){var H=""+S,Z=""+V;if(!$&&H>Z){var J=H;H=Z,Z=J}var le={v:H,w:Z};return W&&(le.name=W),le}function Q($,S){return Y($,S.v,S.w,S.name)}j.exports=R}),c=i((z,j)=>{j.exports="3.0.2"}),l=i((z,j)=>{j.exports={Graph:a(),version:c()}}),d=i((z,j)=>{var O=a();j.exports={write:_,read:A};function _(q){var Y={options:{directed:q.isDirected(),multigraph:q.isMultigraph(),compound:q.isCompound()},nodes:T(q),edges:R(q)};return q.graph()!==void 0&&(Y.value=structuredClone(q.graph())),Y}function T(q){return q.nodes().map(function(Y){var F=q.node(Y),Q=q.parent(Y),$={v:Y};return F!==void 0&&($.value=F),Q!==void 0&&($.parent=Q),$})}function R(q){return q.edges().map(function(Y){var F=q.edge(Y),Q={v:Y.v,w:Y.w};return Y.name!==void 0&&(Q.name=Y.name),F!==void 0&&(Q.value=F),Q})}function A(q){var Y=new O(q.options).setGraph(q.value);return q.nodes.forEach(function(F){Y.setNode(F.v,F.value),F.parent&&Y.setParent(F.v,F.parent)}),q.edges.forEach(function(F){Y.setEdge({v:F.v,w:F.w,name:F.name},F.value)}),Y}}),h=i((z,j)=>{j.exports=_;var O=()=>1;function _(R,A,q,Y){return T(R,String(A),q||O,Y||function(F){return R.outEdges(F)})}function T(R,A,q,Y){var F={},Q=!0,$=0,S=R.nodes(),V=function(J){var le=q(J);F[J.v].distance+le<F[J.w].distance&&(F[J.w]={distance:F[J.v].distance+le,predecessor:J.v},Q=!0)},W=function(){S.forEach(function(J){Y(J).forEach(function(le){var te=le.v===J?le.v:le.w,X=te===le.v?le.w:le.v;V({v:te,w:X})})})};S.forEach(function(J){var le=J===A?0:Number.POSITIVE_INFINITY;F[J]={distance:le}});for(var H=S.length,Z=1;Z<H&&(Q=!1,$++,W(),!!Q);Z++);if($===H-1&&(Q=!1,W(),Q))throw new Error("The graph contains a negative weight cycle");return F}}),f=i((z,j)=>{j.exports=O;function O(_){var T={},R=[],A;function q(Y){Object.hasOwn(T,Y)||(T[Y]=!0,A.push(Y),_.successors(Y).forEach(q),_.predecessors(Y).forEach(q))}return _.nodes().forEach(function(Y){A=[],q(Y),A.length&&R.push(A)}),R}}),m=i((z,j)=>{var O=class{constructor(){o(this,"_arr",[]),o(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(_){return _.key})}has(_){return Object.hasOwn(this._keyIndices,_)}priority(_){var T=this._keyIndices[_];if(T!==void 0)return this._arr[T].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(_,T){var R=this._keyIndices;if(_=String(_),!Object.hasOwn(R,_)){var A=this._arr,q=A.length;return R[_]=q,A.push({key:_,priority:T}),this._decrease(q),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var _=this._arr.pop();return delete this._keyIndices[_.key],this._heapify(0),_.key}decrease(_,T){var R=this._keyIndices[_];if(T>this._arr[R].priority)throw new Error("New priority is greater than current priority. Key: "+_+" Old: "+this._arr[R].priority+" New: "+T);this._arr[R].priority=T,this._decrease(R)}_heapify(_){var T=this._arr,R=2*_,A=R+1,q=_;R<T.length&&(q=T[R].priority<T[q].priority?R:q,A<T.length&&(q=T[A].priority<T[q].priority?A:q),q!==_&&(this._swap(_,q),this._heapify(q)))}_decrease(_){for(var T=this._arr,R=T[_].priority,A;_!==0&&(A=_>>1,!(T[A].priority<R));)this._swap(_,A),_=A}_swap(_,T){var R=this._arr,A=this._keyIndices,q=R[_],Y=R[T];R[_]=Y,R[T]=q,A[Y.key]=_,A[q.key]=T}};j.exports=O}),u=i((z,j)=>{var O=m();j.exports=T;var _=()=>1;function T(A,q,Y,F){var Q=function($){return A.outEdges($)};return R(A,String(q),Y||_,F||Q)}function R(A,q,Y,F){var Q={},$=new O,S,V,W=function(H){var Z=H.v!==S?H.v:H.w,J=Q[Z],le=Y(H),te=V.distance+le;if(le<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+H+" Weight: "+le);te<J.distance&&(J.distance=te,J.predecessor=S,$.decrease(Z,te))};for(A.nodes().forEach(function(H){var Z=H===q?0:Number.POSITIVE_INFINITY;Q[H]={distance:Z},$.add(H,Z)});$.size()>0&&(S=$.removeMin(),V=Q[S],V.distance!==Number.POSITIVE_INFINITY);)F(S).forEach(W);return Q}}),p=i((z,j)=>{var O=u();j.exports=_;function _(T,R,A){return T.nodes().reduce(function(q,Y){return q[Y]=O(T,Y,R,A),q},{})}}),M=i((z,j)=>{j.exports=O;function O(T,R,A){if(T[R].predecessor!==void 0)throw new Error("Invalid source vertex");if(T[A].predecessor===void 0&&A!==R)throw new Error("Invalid destination vertex");return{weight:T[A].distance,path:_(T,R,A)}}function _(T,R,A){for(var q=[],Y=A;Y!==R;)q.push(Y),Y=T[Y].predecessor;return q.push(R),q.reverse()}}),C=i((z,j)=>{j.exports=O;function O(_){var T=0,R=[],A={},q=[];function Y(F){var Q=A[F]={onStack:!0,lowlink:T,index:T++};if(R.push(F),_.successors(F).forEach(function(V){Object.hasOwn(A,V)?A[V].onStack&&(Q.lowlink=Math.min(Q.lowlink,A[V].index)):(Y(V),Q.lowlink=Math.min(Q.lowlink,A[V].lowlink))}),Q.lowlink===Q.index){var $=[],S;do S=R.pop(),A[S].onStack=!1,$.push(S);while(F!==S);q.push($)}}return _.nodes().forEach(function(F){Object.hasOwn(A,F)||Y(F)}),q}}),y=i((z,j)=>{var O=C();j.exports=_;function _(T){return O(T).filter(function(R){return R.length>1||R.length===1&&T.hasEdge(R[0],R[0])})}}),v=i((z,j)=>{j.exports=_;var O=()=>1;function _(R,A,q){return T(R,A||O,q||function(Y){return R.outEdges(Y)})}function T(R,A,q){var Y={},F=R.nodes();return F.forEach(function(Q){Y[Q]={},Y[Q][Q]={distance:0},F.forEach(function($){Q!==$&&(Y[Q][$]={distance:Number.POSITIVE_INFINITY})}),q(Q).forEach(function($){var S=$.v===Q?$.w:$.v,V=A($);Y[Q][S]={distance:V,predecessor:Q}})}),F.forEach(function(Q){var $=Y[Q];F.forEach(function(S){var V=Y[S];F.forEach(function(W){var H=V[Q],Z=$[W],J=V[W],le=H.distance+Z.distance;le<J.distance&&(J.distance=le,J.predecessor=Z.predecessor)})})}),Y}}),x=i((z,j)=>{function O(T){var R={},A={},q=[];function Y(F){if(Object.hasOwn(A,F))throw new _;Object.hasOwn(R,F)||(A[F]=!0,R[F]=!0,T.predecessors(F).forEach(Y),delete A[F],q.push(F))}if(T.sinks().forEach(Y),Object.keys(R).length!==T.nodeCount())throw new _;return q}var _=class extends Error{constructor(){super(...arguments)}};j.exports=O,O.CycleException=_}),b=i((z,j)=>{var O=x();j.exports=_;function _(T){try{O(T)}catch(R){if(R instanceof O.CycleException)return!1;throw R}return!0}}),k=i((z,j)=>{j.exports=O;function O(T,R,A,q,Y){Array.isArray(R)||(R=[R]);var F=(T.isDirected()?T.successors:T.neighbors).bind(T),Q={};return R.forEach(function($){if(!T.hasNode($))throw new Error("Graph does not have node: "+$);Y=_(T,$,A==="post",Q,F,q,Y)}),Y}function _(T,R,A,q,Y,F,Q){return Object.hasOwn(q,R)||(q[R]=!0,A||(Q=F(Q,R)),Y(R).forEach(function($){Q=_(T,$,A,q,Y,F,Q)}),A&&(Q=F(Q,R))),Q}}),N=i((z,j)=>{var O=k();j.exports=_;function _(T,R,A){return O(T,R,A,function(q,Y){return q.push(Y),q},[])}}),I=i((z,j)=>{var O=N();j.exports=_;function _(T,R){return O(T,R,"post")}}),B=i((z,j)=>{var O=N();j.exports=_;function _(T,R){return O(T,R,"pre")}}),D=i((z,j)=>{var O=a(),_=m();j.exports=T;function T(R,A){var q=new O,Y={},F=new _,Q;function $(V){var W=V.v===Q?V.w:V.v,H=F.priority(W);if(H!==void 0){var Z=A(V);Z<H&&(Y[W]=Q,F.decrease(W,Z))}}if(R.nodeCount()===0)return q;R.nodes().forEach(function(V){F.add(V,Number.POSITIVE_INFINITY),q.setNode(V)}),F.decrease(R.nodes()[0],0);for(var S=!1;F.size()>0;){if(Q=F.removeMin(),Object.hasOwn(Y,Q))q.setEdge(Q,Y[Q]);else{if(S)throw new Error("Input graph is not connected: "+R);S=!0}R.nodeEdges(Q).forEach($)}return q}}),L=i((z,j)=>{var O=u(),_=h();j.exports=T;function T(A,q,Y,F){return R(A,q,Y,F||function(Q){return A.outEdges(Q)})}function R(A,q,Y,F){if(Y===void 0)return O(A,q,Y,F);for(var Q=!1,$=A.nodes(),S=0;S<$.length;S++){for(var V=F($[S]),W=0;W<V.length;W++){var H=V[W],Z=H.v===$[S]?H.v:H.w,J=Z===H.v?H.w:H.v;Y({v:Z,w:J})<0&&(Q=!0)}if(Q)return _(A,q,Y,F)}return O(A,q,Y,F)}}),E=i((z,j)=>{j.exports={bellmanFord:h(),components:f(),dijkstra:u(),dijkstraAll:p(),extractPath:M(),findCycles:y(),floydWarshall:v(),isAcyclic:b(),postorder:I(),preorder:B(),prim:D(),shortestPaths:L(),reduce:k(),tarjan:C(),topsort:x()}}),P=l();n.exports={Graph:P.Graph,json:d(),alg:E(),version:P.version}}),Wf=Pe((e,n)=>{var s=class{constructor(){let o={};o._next=o._prev=o,this._sentinel=o}dequeue(){let o=this._sentinel,a=o._prev;if(a!==o)return r(a),a}enqueue(o){let a=this._sentinel;o._prev&&o._next&&r(o),o._next=a._next,a._next._prev=o,a._next=o,o._prev=a}toString(){let o=[],a=this._sentinel,c=a._prev;for(;c!==a;)o.push(JSON.stringify(c,i)),c=c._prev;return"["+o.join(", ")+"]"}};function r(o){o._prev._next=o._next,o._next._prev=o._prev,delete o._next,delete o._prev}function i(o,a){if(o!=="_next"&&o!=="_prev")return a}n.exports=s}),Vf=Pe((e,n)=>{var s=Pt().Graph,r=Wf();n.exports=o;var i=()=>1;function o(f,m){if(f.nodeCount()<=1)return[];let u=l(f,m||i);return a(u.graph,u.buckets,u.zeroIdx).flatMap(p=>f.outEdges(p.v,p.w))}function a(f,m,u){let p=[],M=m[m.length-1],C=m[0],y;for(;f.nodeCount();){for(;y=C.dequeue();)c(f,m,u,y);for(;y=M.dequeue();)c(f,m,u,y);if(f.nodeCount()){for(let v=m.length-2;v>0;--v)if(y=m[v].dequeue(),y){p=p.concat(c(f,m,u,y,!0));break}}}return p}function c(f,m,u,p,M){let C=M?[]:void 0;return f.inEdges(p.v).forEach(y=>{let v=f.edge(y),x=f.node(y.v);M&&C.push({v:y.v,w:y.w}),x.out-=v,d(m,u,x)}),f.outEdges(p.v).forEach(y=>{let v=f.edge(y),x=y.w,b=f.node(x);b.in-=v,d(m,u,b)}),f.removeNode(p.v),C}function l(f,m){let u=new s,p=0,M=0;f.nodes().forEach(v=>{u.setNode(v,{v,in:0,out:0})}),f.edges().forEach(v=>{let x=u.edge(v.v,v.w)||0,b=m(v),k=x+b;u.setEdge(v.v,v.w,k),M=Math.max(M,u.node(v.v).out+=b),p=Math.max(p,u.node(v.w).in+=b)});let C=h(M+p+3).map(()=>new r),y=p+1;return u.nodes().forEach(v=>{d(C,y,u.node(v))}),{graph:u,buckets:C,zeroIdx:y}}function d(f,m,u){u.out?u.in?f[u.out-u.in+m].enqueue(u):f[f.length-1].enqueue(u):f[0].enqueue(u)}function h(f){let m=[];for(let u=0;u<f;u++)m.push(u);return m}}),Ke=Pe((e,n)=>{var s=Pt().Graph;n.exports={addBorderNode:m,addDummyNode:r,applyWithChunking:M,asNonCompoundGraph:o,buildLayerMatrix:d,intersectRect:l,mapValues:B,maxRank:C,normalizeRanks:h,notime:x,partition:y,pick:I,predecessorWeights:c,range:N,removeEmptyRanks:f,simplify:i,successorWeights:a,time:v,uniqueId:k,zipObject:D};function r(L,E,P,z){for(var j=z;L.hasNode(j);)j=k(z);return P.dummy=E,L.setNode(j,P),j}function i(L){let E=new s().setGraph(L.graph());return L.nodes().forEach(P=>E.setNode(P,L.node(P))),L.edges().forEach(P=>{let z=E.edge(P.v,P.w)||{weight:0,minlen:1},j=L.edge(P);E.setEdge(P.v,P.w,{weight:z.weight+j.weight,minlen:Math.max(z.minlen,j.minlen)})}),E}function o(L){let E=new s({multigraph:L.isMultigraph()}).setGraph(L.graph());return L.nodes().forEach(P=>{L.children(P).length||E.setNode(P,L.node(P))}),L.edges().forEach(P=>{E.setEdge(P,L.edge(P))}),E}function a(L){let E=L.nodes().map(P=>{let z={};return L.outEdges(P).forEach(j=>{z[j.w]=(z[j.w]||0)+L.edge(j).weight}),z});return D(L.nodes(),E)}function c(L){let E=L.nodes().map(P=>{let z={};return L.inEdges(P).forEach(j=>{z[j.v]=(z[j.v]||0)+L.edge(j).weight}),z});return D(L.nodes(),E)}function l(L,E){let P=L.x,z=L.y,j=E.x-P,O=E.y-z,_=L.width/2,T=L.height/2;if(!j&&!O)throw new Error("Not possible to find intersection inside of the rectangle");let R,A;return Math.abs(O)*_>Math.abs(j)*T?(O<0&&(T=-T),R=T*j/O,A=T):(j<0&&(_=-_),R=_,A=_*O/j),{x:P+R,y:z+A}}function d(L){let E=N(C(L)+1).map(()=>[]);return L.nodes().forEach(P=>{let z=L.node(P),j=z.rank;j!==void 0&&(E[j][z.order]=P)}),E}function h(L){let E=L.nodes().map(z=>{let j=L.node(z).rank;return j===void 0?Number.MAX_VALUE:j}),P=M(Math.min,E);L.nodes().forEach(z=>{let j=L.node(z);Object.hasOwn(j,"rank")&&(j.rank-=P)})}function f(L){let E=L.nodes().map(_=>L.node(_).rank).filter(_=>_!==void 0),P=M(Math.min,E),z=[];L.nodes().forEach(_=>{let T=L.node(_).rank-P;z[T]||(z[T]=[]),z[T].push(_)});let j=0,O=L.graph().nodeRankFactor;Array.from(z).forEach((_,T)=>{_===void 0&&T%O!==0?--j:_!==void 0&&j&&_.forEach(R=>L.node(R).rank+=j)})}function m(L,E,P,z){let j={width:0,height:0};return arguments.length>=4&&(j.rank=P,j.order=z),r(L,"border",j,E)}function u(L,E=p){let P=[];for(let z=0;z<L.length;z+=E){let j=L.slice(z,z+E);P.push(j)}return P}var p=65535;function M(L,E){if(E.length>p){let P=u(E);return L.apply(null,P.map(z=>L.apply(null,z)))}else return L.apply(null,E)}function C(L){let E=L.nodes().map(P=>{let z=L.node(P).rank;return z===void 0?Number.MIN_VALUE:z});return M(Math.max,E)}function y(L,E){let P={lhs:[],rhs:[]};return L.forEach(z=>{E(z)?P.lhs.push(z):P.rhs.push(z)}),P}function v(L,E){let P=Date.now();try{return E()}finally{console.log(L+" time: "+(Date.now()-P)+"ms")}}function x(L,E){return E()}var b=0;function k(L){var E=++b;return L+(""+E)}function N(L,E,P=1){E==null&&(E=L,L=0);let z=O=>O<E;P<0&&(z=O=>E<O);let j=[];for(let O=L;z(O);O+=P)j.push(O);return j}function I(L,E){let P={};for(let z of E)L[z]!==void 0&&(P[z]=L[z]);return P}function B(L,E){let P=E;return typeof E=="string"&&(P=z=>z[E]),Object.entries(L).reduce((z,[j,O])=>(z[j]=P(O,j),z),{})}function D(L,E){return L.reduce((P,z,j)=>(P[z]=E[j],P),{})}}),Ff=Pe((e,n)=>{var s=Vf(),r=Ke().uniqueId;n.exports={run:i,undo:a};function i(c){(c.graph().acyclicer==="greedy"?s(c,l(c)):o(c)).forEach(d=>{let h=c.edge(d);c.removeEdge(d),h.forwardName=d.name,h.reversed=!0,c.setEdge(d.w,d.v,h,r("rev"))});function l(d){return h=>d.edge(h).weight}}function o(c){let l=[],d={},h={};function f(m){Object.hasOwn(h,m)||(h[m]=!0,d[m]=!0,c.outEdges(m).forEach(u=>{Object.hasOwn(d,u.w)?l.push(u):f(u.w)}),delete d[m])}return c.nodes().forEach(f),l}function a(c){c.edges().forEach(l=>{let d=c.edge(l);if(d.reversed){c.removeEdge(l);let h=d.forwardName;delete d.reversed,delete d.forwardName,c.setEdge(l.w,l.v,d,h)}})}}),Yf=Pe((e,n)=>{var s=Ke();n.exports={run:r,undo:o};function r(a){a.graph().dummyChains=[],a.edges().forEach(c=>i(a,c))}function i(a,c){let l=c.v,d=a.node(l).rank,h=c.w,f=a.node(h).rank,m=c.name,u=a.edge(c),p=u.labelRank;if(f===d+1)return;a.removeEdge(c);let M,C,y;for(y=0,++d;d<f;++y,++d)u.points=[],C={width:0,height:0,edgeLabel:u,edgeObj:c,rank:d},M=s.addDummyNode(a,"edge",C,"_d"),d===p&&(C.width=u.width,C.height=u.height,C.dummy="edge-label",C.labelpos=u.labelpos),a.setEdge(l,M,{weight:u.weight},m),y===0&&a.graph().dummyChains.push(M),l=M;a.setEdge(l,h,{weight:u.weight},m)}function o(a){a.graph().dummyChains.forEach(c=>{let l=a.node(c),d=l.edgeLabel,h;for(a.setEdge(l.edgeObj,d);l.dummy;)h=a.successors(c)[0],a.removeNode(c),d.points.push({x:l.x,y:l.y}),l.dummy==="edge-label"&&(d.x=l.x,d.y=l.y,d.width=l.width,d.height=l.height),c=h,l=a.node(c)})}}),rs=Pe((e,n)=>{var{applyWithChunking:s}=Ke();n.exports={longestPath:r,slack:i};function r(o){var a={};function c(l){var d=o.node(l);if(Object.hasOwn(a,l))return d.rank;a[l]=!0;let h=o.outEdges(l).map(m=>m==null?Number.POSITIVE_INFINITY:c(m.w)-o.edge(m).minlen);var f=s(Math.min,h);return f===Number.POSITIVE_INFINITY&&(f=0),d.rank=f}o.sources().forEach(c)}function i(o,a){return o.node(a.w).rank-o.node(a.v).rank-o.edge(a).minlen}}),pl=Pe((e,n)=>{var s=Pt().Graph,r=rs().slack;n.exports=i;function i(l){var d=new s({directed:!1}),h=l.nodes()[0],f=l.nodeCount();d.setNode(h,{});for(var m,u;o(d,l)<f;)m=a(d,l),u=d.hasNode(m.v)?r(l,m):-r(l,m),c(d,l,u);return d}function o(l,d){function h(f){d.nodeEdges(f).forEach(m=>{var u=m.v,p=f===u?m.w:u;!l.hasNode(p)&&!r(d,m)&&(l.setNode(p,{}),l.setEdge(f,p,{}),h(p))})}return l.nodes().forEach(h),l.nodeCount()}function a(l,d){return d.edges().reduce((h,f)=>{let m=Number.POSITIVE_INFINITY;return l.hasNode(f.v)!==l.hasNode(f.w)&&(m=r(d,f)),m<h[0]?[m,f]:h},[Number.POSITIVE_INFINITY,null])[1]}function c(l,d,h){l.nodes().forEach(f=>d.node(f).rank+=h)}}),Gf=Pe((e,n)=>{var s=pl(),r=rs().slack,i=rs().longestPath,o=Pt().alg.preorder,a=Pt().alg.postorder,c=Ke().simplify;n.exports=l,l.initLowLimValues=m,l.initCutValues=d,l.calcCutValue=f,l.leaveEdge=p,l.enterEdge=M,l.exchangeEdges=C;function l(b){b=c(b),i(b);var k=s(b);m(k),d(k,b);for(var N,I;N=p(k);)I=M(k,b,N),C(k,b,N,I)}function d(b,k){var N=a(b,b.nodes());N=N.slice(0,N.length-1),N.forEach(I=>h(b,k,I))}function h(b,k,N){var I=b.node(N),B=I.parent;b.edge(N,B).cutvalue=f(b,k,N)}function f(b,k,N){var I=b.node(N),B=I.parent,D=!0,L=k.edge(N,B),E=0;return L||(D=!1,L=k.edge(B,N)),E=L.weight,k.nodeEdges(N).forEach(P=>{var z=P.v===N,j=z?P.w:P.v;if(j!==B){var O=z===D,_=k.edge(P).weight;if(E+=O?_:-_,v(b,N,j)){var T=b.edge(N,j).cutvalue;E+=O?-T:T}}}),E}function m(b,k){arguments.length<2&&(k=b.nodes()[0]),u(b,{},1,k)}function u(b,k,N,I,B){var D=N,L=b.node(I);return k[I]=!0,b.neighbors(I).forEach(E=>{Object.hasOwn(k,E)||(N=u(b,k,N,E,I))}),L.low=D,L.lim=N++,B?L.parent=B:delete L.parent,N}function p(b){return b.edges().find(k=>b.edge(k).cutvalue<0)}function M(b,k,N){var I=N.v,B=N.w;k.hasEdge(I,B)||(I=N.w,B=N.v);var D=b.node(I),L=b.node(B),E=D,P=!1;D.lim>L.lim&&(E=L,P=!0);var z=k.edges().filter(j=>P===x(b,b.node(j.v),E)&&P!==x(b,b.node(j.w),E));return z.reduce((j,O)=>r(k,O)<r(k,j)?O:j)}function C(b,k,N,I){var B=N.v,D=N.w;b.removeEdge(B,D),b.setEdge(I.v,I.w,{}),m(b),d(b,k),y(b,k)}function y(b,k){var N=b.nodes().find(B=>!k.node(B).parent),I=o(b,N);I=I.slice(1),I.forEach(B=>{var D=b.node(B).parent,L=k.edge(B,D),E=!1;L||(L=k.edge(D,B),E=!0),k.node(B).rank=k.node(D).rank+(E?L.minlen:-L.minlen)})}function v(b,k,N){return b.hasEdge(k,N)}function x(b,k,N){return N.low<=k.lim&&k.lim<=N.lim}}),Kf=Pe((e,n)=>{var s=rs(),r=s.longestPath,i=pl(),o=Gf();n.exports=a;function a(h){var f=h.graph().ranker;if(f instanceof Function)return f(h);switch(h.graph().ranker){case"network-simplex":d(h);break;case"tight-tree":l(h);break;case"longest-path":c(h);break;case"none":break;default:d(h)}}var c=r;function l(h){r(h),i(h)}function d(h){o(h)}}),Zf=Pe((e,n)=>{n.exports=s;function s(o){let a=i(o);o.graph().dummyChains.forEach(c=>{let l=o.node(c),d=l.edgeObj,h=r(o,a,d.v,d.w),f=h.path,m=h.lca,u=0,p=f[u],M=!0;for(;c!==d.w;){if(l=o.node(c),M){for(;(p=f[u])!==m&&o.node(p).maxRank<l.rank;)u++;p===m&&(M=!1)}if(!M){for(;u<f.length-1&&o.node(p=f[u+1]).minRank<=l.rank;)u++;p=f[u]}o.setParent(c,p),c=o.successors(c)[0]}})}function r(o,a,c,l){let d=[],h=[],f=Math.min(a[c].low,a[l].low),m=Math.max(a[c].lim,a[l].lim),u,p;u=c;do u=o.parent(u),d.push(u);while(u&&(a[u].low>f||m>a[u].lim));for(p=u,u=l;(u=o.parent(u))!==p;)h.push(u);return{path:d.concat(h.reverse()),lca:p}}function i(o){let a={},c=0;function l(d){let h=c;o.children(d).forEach(l),a[d]={low:h,lim:c++}}return o.children().forEach(l),a}}),Xf=Pe((e,n)=>{var s=Ke();n.exports={run:r,cleanup:c};function r(l){let d=s.addDummyNode(l,"root",{},"_root"),h=o(l),f=Object.values(h),m=s.applyWithChunking(Math.max,f)-1,u=2*m+1;l.graph().nestingRoot=d,l.edges().forEach(M=>l.edge(M).minlen*=u);let p=a(l)+1;l.children().forEach(M=>i(l,d,u,p,m,h,M)),l.graph().nodeRankFactor=u}function i(l,d,h,f,m,u,p){let M=l.children(p);if(!M.length){p!==d&&l.setEdge(d,p,{weight:0,minlen:h});return}let C=s.addBorderNode(l,"_bt"),y=s.addBorderNode(l,"_bb"),v=l.node(p);l.setParent(C,p),v.borderTop=C,l.setParent(y,p),v.borderBottom=y,M.forEach(x=>{i(l,d,h,f,m,u,x);let b=l.node(x),k=b.borderTop?b.borderTop:x,N=b.borderBottom?b.borderBottom:x,I=b.borderTop?f:2*f,B=k!==N?1:m-u[p]+1;l.setEdge(C,k,{weight:I,minlen:B,nestingEdge:!0}),l.setEdge(N,y,{weight:I,minlen:B,nestingEdge:!0})}),l.parent(p)||l.setEdge(d,C,{weight:0,minlen:m+u[p]})}function o(l){var d={};function h(f,m){var u=l.children(f);u&&u.length&&u.forEach(p=>h(p,m+1)),d[f]=m}return l.children().forEach(f=>h(f,1)),d}function a(l){return l.edges().reduce((d,h)=>d+l.edge(h).weight,0)}function c(l){var d=l.graph();l.removeNode(d.nestingRoot),delete d.nestingRoot,l.edges().forEach(h=>{var f=l.edge(h);f.nestingEdge&&l.removeEdge(h)})}}),Uf=Pe((e,n)=>{var s=Ke();n.exports=r;function r(o){function a(c){let l=o.children(c),d=o.node(c);if(l.length&&l.forEach(a),Object.hasOwn(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(let h=d.minRank,f=d.maxRank+1;h<f;++h)i(o,"borderLeft","_bl",c,d,h),i(o,"borderRight","_br",c,d,h)}}o.children().forEach(a)}function i(o,a,c,l,d,h){let f={width:0,height:0,rank:h,borderType:a},m=d[a][h-1],u=s.addDummyNode(o,"border",f,c);d[a][h]=u,o.setParent(u,l),m&&o.setEdge(m,u,{weight:1})}}),Qf=Pe((e,n)=>{n.exports={adjust:s,undo:r};function s(h){let f=h.graph().rankdir.toLowerCase();(f==="lr"||f==="rl")&&i(h)}function r(h){let f=h.graph().rankdir.toLowerCase();(f==="bt"||f==="rl")&&a(h),(f==="lr"||f==="rl")&&(l(h),i(h))}function i(h){h.nodes().forEach(f=>o(h.node(f))),h.edges().forEach(f=>o(h.edge(f)))}function o(h){let f=h.width;h.width=h.height,h.height=f}function a(h){h.nodes().forEach(f=>c(h.node(f))),h.edges().forEach(f=>{let m=h.edge(f);m.points.forEach(c),Object.hasOwn(m,"y")&&c(m)})}function c(h){h.y=-h.y}function l(h){h.nodes().forEach(f=>d(h.node(f))),h.edges().forEach(f=>{let m=h.edge(f);m.points.forEach(d),Object.hasOwn(m,"x")&&d(m)})}function d(h){let f=h.x;h.x=h.y,h.y=f}}),Jf=Pe((e,n)=>{var s=Ke();n.exports=r;function r(i){let o={},a=i.nodes().filter(f=>!i.children(f).length),c=a.map(f=>i.node(f).rank),l=s.applyWithChunking(Math.max,c),d=s.range(l+1).map(()=>[]);function h(f){if(o[f])return;o[f]=!0;let m=i.node(f);d[m.rank].push(f),i.successors(f).forEach(h)}return a.sort((f,m)=>i.node(f).rank-i.node(m).rank).forEach(h),d}}),eh=Pe((e,n)=>{var s=Ke().zipObject;n.exports=r;function r(o,a){let c=0;for(let l=1;l<a.length;++l)c+=i(o,a[l-1],a[l]);return c}function i(o,a,c){let l=s(c,c.map((p,M)=>M)),d=a.flatMap(p=>o.outEdges(p).map(M=>({pos:l[M.w],weight:o.edge(M).weight})).sort((M,C)=>M.pos-C.pos)),h=1;for(;h<c.length;)h<<=1;let f=2*h-1;h-=1;let m=new Array(f).fill(0),u=0;return d.forEach(p=>{let M=p.pos+h;m[M]+=p.weight;let C=0;for(;M>0;)M%2&&(C+=m[M+1]),M=M-1>>1,m[M]+=p.weight;u+=p.weight*C}),u}}),th=Pe((e,n)=>{n.exports=s;function s(r,i=[]){return i.map(o=>{let a=r.inEdges(o);if(a.length){let c=a.reduce((l,d)=>{let h=r.edge(d),f=r.node(d.v);return{sum:l.sum+h.weight*f.order,weight:l.weight+h.weight}},{sum:0,weight:0});return{v:o,barycenter:c.sum/c.weight,weight:c.weight}}else return{v:o}})}}),nh=Pe((e,n)=>{var s=Ke();n.exports=r;function r(a,c){let l={};a.forEach((h,f)=>{let m=l[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:f};h.barycenter!==void 0&&(m.barycenter=h.barycenter,m.weight=h.weight)}),c.edges().forEach(h=>{let f=l[h.v],m=l[h.w];f!==void 0&&m!==void 0&&(m.indegree++,f.out.push(l[h.w]))});let d=Object.values(l).filter(h=>!h.indegree);return i(d)}function i(a){let c=[];function l(h){return f=>{f.merged||(f.barycenter===void 0||h.barycenter===void 0||f.barycenter>=h.barycenter)&&o(h,f)}}function d(h){return f=>{f.in.push(h),--f.indegree===0&&a.push(f)}}for(;a.length;){let h=a.pop();c.push(h),h.in.reverse().forEach(l(h)),h.out.forEach(d(h))}return c.filter(h=>!h.merged).map(h=>s.pick(h,["vs","i","barycenter","weight"]))}function o(a,c){let l=0,d=0;a.weight&&(l+=a.barycenter*a.weight,d+=a.weight),c.weight&&(l+=c.barycenter*c.weight,d+=c.weight),a.vs=c.vs.concat(a.vs),a.barycenter=l/d,a.weight=d,a.i=Math.min(c.i,a.i),c.merged=!0}}),rh=Pe((e,n)=>{var s=Ke();n.exports=r;function r(a,c){let l=s.partition(a,C=>Object.hasOwn(C,"barycenter")),d=l.lhs,h=l.rhs.sort((C,y)=>y.i-C.i),f=[],m=0,u=0,p=0;d.sort(o(!!c)),p=i(f,h,p),d.forEach(C=>{p+=C.vs.length,f.push(C.vs),m+=C.barycenter*C.weight,u+=C.weight,p=i(f,h,p)});let M={vs:f.flat(!0)};return u&&(M.barycenter=m/u,M.weight=u),M}function i(a,c,l){let d;for(;c.length&&(d=c[c.length-1]).i<=l;)c.pop(),a.push(d.vs),l++;return l}function o(a){return(c,l)=>c.barycenter<l.barycenter?-1:c.barycenter>l.barycenter?1:a?l.i-c.i:c.i-l.i}}),sh=Pe((e,n)=>{var s=th(),r=nh(),i=rh();n.exports=o;function o(l,d,h,f){let m=l.children(d),u=l.node(d),p=u?u.borderLeft:void 0,M=u?u.borderRight:void 0,C={};p&&(m=m.filter(b=>b!==p&&b!==M));let y=s(l,m);y.forEach(b=>{if(l.children(b.v).length){let k=o(l,b.v,h,f);C[b.v]=k,Object.hasOwn(k,"barycenter")&&c(b,k)}});let v=r(y,h);a(v,C);let x=i(v,f);if(p&&(x.vs=[p,x.vs,M].flat(!0),l.predecessors(p).length)){let b=l.node(l.predecessors(p)[0]),k=l.node(l.predecessors(M)[0]);Object.hasOwn(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+b.order+k.order)/(x.weight+2),x.weight+=2}return x}function a(l,d){l.forEach(h=>{h.vs=h.vs.flatMap(f=>d[f]?d[f].vs:f)})}function c(l,d){l.barycenter!==void 0?(l.barycenter=(l.barycenter*l.weight+d.barycenter*d.weight)/(l.weight+d.weight),l.weight+=d.weight):(l.barycenter=d.barycenter,l.weight=d.weight)}}),oh=Pe((e,n)=>{var s=Pt().Graph,r=Ke();n.exports=i;function i(a,c,l,d){d||(d=a.nodes());let h=o(a),f=new s({compound:!0}).setGraph({root:h}).setDefaultNodeLabel(m=>a.node(m));return d.forEach(m=>{let u=a.node(m),p=a.parent(m);(u.rank===c||u.minRank<=c&&c<=u.maxRank)&&(f.setNode(m),f.setParent(m,p||h),a[l](m).forEach(M=>{let C=M.v===m?M.w:M.v,y=f.edge(C,m),v=y!==void 0?y.weight:0;f.setEdge(C,m,{weight:a.edge(M).weight+v})}),Object.hasOwn(u,"minRank")&&f.setNode(m,{borderLeft:u.borderLeft[c],borderRight:u.borderRight[c]}))}),f}function o(a){for(var c;a.hasNode(c=r.uniqueId("_root")););return c}}),ah=Pe((e,n)=>{n.exports=s;function s(r,i,o){let a={},c;o.forEach(l=>{let d=r.parent(l),h,f;for(;d;){if(h=r.parent(d),h?(f=a[h],a[h]=d):(f=c,c=d),f&&f!==d){i.setEdge(f,d);return}d=h}})}}),ih=Pe((e,n)=>{var s=Jf(),r=eh(),i=sh(),o=oh(),a=ah(),c=Pt().Graph,l=Ke();n.exports=d;function d(u,p={}){if(typeof p.customOrder=="function"){p.customOrder(u,d);return}let M=l.maxRank(u),C=h(u,l.range(1,M+1),"inEdges"),y=h(u,l.range(M-1,-1,-1),"outEdges"),v=s(u);if(m(u,v),p.disableOptimalOrderHeuristic)return;let x=Number.POSITIVE_INFINITY,b,k=p.constraints||[];for(let N=0,I=0;I<4;++N,++I){f(N%2?C:y,N%4>=2,k),v=l.buildLayerMatrix(u);let B=r(u,v);B<x?(I=0,b=Object.assign({},v),x=B):B===x&&(b=structuredClone(v))}m(u,b)}function h(u,p,M){let C=new Map,y=(v,x)=>{C.has(v)||C.set(v,[]),C.get(v).push(x)};for(let v of u.nodes()){let x=u.node(v);if(typeof x.rank=="number"&&y(x.rank,v),typeof x.minRank=="number"&&typeof x.maxRank=="number")for(let b=x.minRank;b<=x.maxRank;b++)b!==x.rank&&y(b,v)}return p.map(function(v){return o(u,v,M,C.get(v)||[])})}function f(u,p,M){let C=new c;u.forEach(function(y){M.forEach(b=>C.setEdge(b.left,b.right));let v=y.graph().root,x=i(y,v,C,p);x.vs.forEach((b,k)=>y.node(b).order=k),a(y,C,x.vs)})}function m(u,p){Object.values(p).forEach(M=>M.forEach((C,y)=>u.node(C).order=y))}}),lh=Pe((e,n)=>{var s=Pt().Graph,r=Ke();n.exports={positionX:M,findType1Conflicts:i,findType2Conflicts:o,addConflict:c,hasConflict:l,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:u,findSmallestWidthAlignment:m,balance:p};function i(v,x){let b={};function k(N,I){let B=0,D=0,L=N.length,E=I[I.length-1];return I.forEach((P,z)=>{let j=a(v,P),O=j?v.node(j).order:L;(j||P===E)&&(I.slice(D,z+1).forEach(_=>{v.predecessors(_).forEach(T=>{let R=v.node(T),A=R.order;(A<B||O<A)&&!(R.dummy&&v.node(_).dummy)&&c(b,T,_)})}),D=z+1,B=O)}),I}return x.length&&x.reduce(k),b}function o(v,x){let b={};function k(I,B,D,L,E){let P;r.range(B,D).forEach(z=>{P=I[z],v.node(P).dummy&&v.predecessors(P).forEach(j=>{let O=v.node(j);O.dummy&&(O.order<L||O.order>E)&&c(b,j,P)})})}function N(I,B){let D=-1,L,E=0;return B.forEach((P,z)=>{if(v.node(P).dummy==="border"){let j=v.predecessors(P);j.length&&(L=v.node(j[0]).order,k(B,E,z,D,L),E=z,D=L)}k(B,E,B.length,L,I.length)}),B}return x.length&&x.reduce(N),b}function a(v,x){if(v.node(x).dummy)return v.predecessors(x).find(b=>v.node(b).dummy)}function c(v,x,b){if(x>b){let N=x;x=b,b=N}let k=v[x];k||(v[x]=k={}),k[b]=!0}function l(v,x,b){if(x>b){let k=x;x=b,b=k}return!!v[x]&&Object.hasOwn(v[x],b)}function d(v,x,b,k){let N={},I={},B={};return x.forEach(D=>{D.forEach((L,E)=>{N[L]=L,I[L]=L,B[L]=E})}),x.forEach(D=>{let L=-1;D.forEach(E=>{let P=k(E);if(P.length){P=P.sort((j,O)=>B[j]-B[O]);let z=(P.length-1)/2;for(let j=Math.floor(z),O=Math.ceil(z);j<=O;++j){let _=P[j];I[E]===E&&L<B[_]&&!l(b,E,_)&&(I[_]=E,I[E]=N[E]=N[_],L=B[_])}}})}),{root:N,align:I}}function h(v,x,b,k,N){let I={},B=f(v,x,b,N),D=N?"borderLeft":"borderRight";function L(z,j){let O=B.nodes().slice(),_={},T=O.pop();for(;T;){if(_[T])z(T);else{_[T]=!0,O.push(T);for(let R of j(T))O.push(R)}T=O.pop()}}function E(z){I[z]=B.inEdges(z).reduce((j,O)=>Math.max(j,I[O.v]+B.edge(O)),0)}function P(z){let j=B.outEdges(z).reduce((_,T)=>Math.min(_,I[T.w]-B.edge(T)),Number.POSITIVE_INFINITY),O=v.node(z);j!==Number.POSITIVE_INFINITY&&O.borderType!==D&&(I[z]=Math.max(I[z],j))}return L(E,B.predecessors.bind(B)),L(P,B.successors.bind(B)),Object.keys(k).forEach(z=>I[z]=I[b[z]]),I}function f(v,x,b,k){let N=new s,I=v.graph(),B=C(I.nodesep,I.edgesep,k);return x.forEach(D=>{let L;D.forEach(E=>{let P=b[E];if(N.setNode(P),L){var z=b[L],j=N.edge(z,P);N.setEdge(z,P,Math.max(B(v,E,L),j||0))}L=E})}),N}function m(v,x){return Object.values(x).reduce((b,k)=>{let N=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;Object.entries(k).forEach(([D,L])=>{let E=y(v,D)/2;N=Math.max(L+E,N),I=Math.min(L-E,I)});let B=N-I;return B<b[0]&&(b=[B,k]),b},[Number.POSITIVE_INFINITY,null])[1]}function u(v,x){let b=Object.values(x),k=r.applyWithChunking(Math.min,b),N=r.applyWithChunking(Math.max,b);["u","d"].forEach(I=>{["l","r"].forEach(B=>{let D=I+B,L=v[D];if(L===x)return;let E=Object.values(L),P=k-r.applyWithChunking(Math.min,E);B!=="l"&&(P=N-r.applyWithChunking(Math.max,E)),P&&(v[D]=r.mapValues(L,z=>z+P))})})}function p(v,x){return r.mapValues(v.ul,(b,k)=>{if(x)return v[x.toLowerCase()][k];{let N=Object.values(v).map(I=>I[k]).sort((I,B)=>I-B);return(N[1]+N[2])/2}})}function M(v){let x=r.buildLayerMatrix(v),b=Object.assign(i(v,x),o(v,x)),k={},N;["u","d"].forEach(B=>{N=B==="u"?x:Object.values(x).reverse(),["l","r"].forEach(D=>{D==="r"&&(N=N.map(z=>Object.values(z).reverse()));let L=(B==="u"?v.predecessors:v.successors).bind(v),E=d(v,N,b,L),P=h(v,N,E.root,E.align,D==="r");D==="r"&&(P=r.mapValues(P,z=>-z)),k[B+D]=P})});let I=m(v,k);return u(k,I),p(k,v.graph().align)}function C(v,x,b){return(k,N,I)=>{let B=k.node(N),D=k.node(I),L=0,E;if(L+=B.width/2,Object.hasOwn(B,"labelpos"))switch(B.labelpos.toLowerCase()){case"l":E=-B.width/2;break;case"r":E=B.width/2;break}if(E&&(L+=b?E:-E),E=0,L+=(B.dummy?x:v)/2,L+=(D.dummy?x:v)/2,L+=D.width/2,Object.hasOwn(D,"labelpos"))switch(D.labelpos.toLowerCase()){case"l":E=D.width/2;break;case"r":E=-D.width/2;break}return E&&(L+=b?E:-E),E=0,L}}function y(v,x){return v.node(x).width}}),ch=Pe((e,n)=>{var s=Ke(),r=lh().positionX;n.exports=i;function i(a){a=s.asNonCompoundGraph(a),o(a),Object.entries(r(a)).forEach(([c,l])=>a.node(c).x=l)}function o(a){let c=s.buildLayerMatrix(a),l=a.graph().ranksep,d=a.graph().rankalign,h=0;c.forEach(f=>{let m=f.reduce((u,p)=>{let M=a.node(p).height;return u>M?u:M},0);f.forEach(u=>{let p=a.node(u);d==="top"?p.y=h+p.height/2:d==="bottom"?p.y=h+m-p.height/2:p.y=h+m/2}),h+=m+l})}}),dh=Pe((e,n)=>{var s=Ff(),r=Yf(),i=Kf(),o=Ke().normalizeRanks,a=Zf(),c=Ke().removeEmptyRanks,l=Xf(),d=Uf(),h=Qf(),f=ih(),m=ch(),u=Ke(),p=Pt().Graph;n.exports=M;function M(S,V={}){let W=V.debugTiming?u.time:u.notime;return W("layout",()=>{let H=W(" buildLayoutGraph",()=>L(S));return W(" runLayout",()=>C(H,W,V)),W(" updateInputGraph",()=>y(S,H)),H})}function C(S,V,W){V(" makeSpaceForEdgeLabels",()=>E(S)),V(" removeSelfEdges",()=>q(S)),V(" acyclic",()=>s.run(S)),V(" nestingGraph.run",()=>l.run(S)),V(" rank",()=>i(u.asNonCompoundGraph(S))),V(" injectEdgeLabelProxies",()=>P(S)),V(" removeEmptyRanks",()=>c(S)),V(" nestingGraph.cleanup",()=>l.cleanup(S)),V(" normalizeRanks",()=>o(S)),V(" assignRankMinMax",()=>z(S)),V(" removeEdgeLabelProxies",()=>j(S)),V(" normalize.run",()=>r.run(S)),V(" parentDummyChains",()=>a(S)),V(" addBorderSegments",()=>d(S)),V(" order",()=>f(S,W)),V(" insertSelfEdges",()=>Y(S)),V(" adjustCoordinateSystem",()=>h.adjust(S)),V(" position",()=>m(S)),V(" positionSelfEdges",()=>F(S)),V(" removeBorderNodes",()=>A(S)),V(" normalize.undo",()=>r.undo(S)),V(" fixupEdgeLabelCoords",()=>T(S)),V(" undoCoordinateSystem",()=>h.undo(S)),V(" translateGraph",()=>O(S)),V(" assignNodeIntersects",()=>_(S)),V(" reversePoints",()=>R(S)),V(" acyclic.undo",()=>s.undo(S))}function y(S,V){S.nodes().forEach(W=>{let H=S.node(W),Z=V.node(W);H&&(H.x=Z.x,H.y=Z.y,H.order=Z.order,H.rank=Z.rank,V.children(W).length&&(H.width=Z.width,H.height=Z.height))}),S.edges().forEach(W=>{let H=S.edge(W),Z=V.edge(W);H.points=Z.points,Object.hasOwn(Z,"x")&&(H.x=Z.x,H.y=Z.y)}),S.graph().width=V.graph().width,S.graph().height=V.graph().height}var v=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},b=["acyclicer","ranker","rankdir","align","rankalign"],k=["width","height","rank"],N={width:0,height:0},I=["minlen","weight","width","height","labeloffset"],B={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},D=["labelpos"];function L(S){let V=new p({multigraph:!0,compound:!0}),W=$(S.graph());return V.setGraph(Object.assign({},x,Q(W,v),u.pick(W,b))),S.nodes().forEach(H=>{let Z=$(S.node(H)),J=Q(Z,k);Object.keys(N).forEach(le=>{J[le]===void 0&&(J[le]=N[le])}),V.setNode(H,J),V.setParent(H,S.parent(H))}),S.edges().forEach(H=>{let Z=$(S.edge(H));V.setEdge(H,Object.assign({},B,Q(Z,I),u.pick(Z,D)))}),V}function E(S){let V=S.graph();V.ranksep/=2,S.edges().forEach(W=>{let H=S.edge(W);H.minlen*=2,H.labelpos.toLowerCase()!=="c"&&(V.rankdir==="TB"||V.rankdir==="BT"?H.width+=H.labeloffset:H.height+=H.labeloffset)})}function P(S){S.edges().forEach(V=>{let W=S.edge(V);if(W.width&&W.height){let H=S.node(V.v),Z={rank:(S.node(V.w).rank-H.rank)/2+H.rank,e:V};u.addDummyNode(S,"edge-proxy",Z,"_ep")}})}function z(S){let V=0;S.nodes().forEach(W=>{let H=S.node(W);H.borderTop&&(H.minRank=S.node(H.borderTop).rank,H.maxRank=S.node(H.borderBottom).rank,V=Math.max(V,H.maxRank))}),S.graph().maxRank=V}function j(S){S.nodes().forEach(V=>{let W=S.node(V);W.dummy==="edge-proxy"&&(S.edge(W.e).labelRank=W.rank,S.removeNode(V))})}function O(S){let V=Number.POSITIVE_INFINITY,W=0,H=Number.POSITIVE_INFINITY,Z=0,J=S.graph(),le=J.marginx||0,te=J.marginy||0;function X(ie){let de=ie.x,se=ie.y,me=ie.width,ue=ie.height;V=Math.min(V,de-me/2),W=Math.max(W,de+me/2),H=Math.min(H,se-ue/2),Z=Math.max(Z,se+ue/2)}S.nodes().forEach(ie=>X(S.node(ie))),S.edges().forEach(ie=>{let de=S.edge(ie);Object.hasOwn(de,"x")&&X(de)}),V-=le,H-=te,S.nodes().forEach(ie=>{let de=S.node(ie);de.x-=V,de.y-=H}),S.edges().forEach(ie=>{let de=S.edge(ie);de.points.forEach(se=>{se.x-=V,se.y-=H}),Object.hasOwn(de,"x")&&(de.x-=V),Object.hasOwn(de,"y")&&(de.y-=H)}),J.width=W-V+le,J.height=Z-H+te}function _(S){S.edges().forEach(V=>{let W=S.edge(V),H=S.node(V.v),Z=S.node(V.w),J,le;W.points?(J=W.points[0],le=W.points[W.points.length-1]):(W.points=[],J=Z,le=H),W.points.unshift(u.intersectRect(H,J)),W.points.push(u.intersectRect(Z,le))})}function T(S){S.edges().forEach(V=>{let W=S.edge(V);if(Object.hasOwn(W,"x"))switch((W.labelpos==="l"||W.labelpos==="r")&&(W.width-=W.labeloffset),W.labelpos){case"l":W.x-=W.width/2+W.labeloffset;break;case"r":W.x+=W.width/2+W.labeloffset;break}})}function R(S){S.edges().forEach(V=>{let W=S.edge(V);W.reversed&&W.points.reverse()})}function A(S){S.nodes().forEach(V=>{if(S.children(V).length){let W=S.node(V),H=S.node(W.borderTop),Z=S.node(W.borderBottom),J=S.node(W.borderLeft[W.borderLeft.length-1]),le=S.node(W.borderRight[W.borderRight.length-1]);W.width=Math.abs(le.x-J.x),W.height=Math.abs(Z.y-H.y),W.x=J.x+W.width/2,W.y=H.y+W.height/2}}),S.nodes().forEach(V=>{S.node(V).dummy==="border"&&S.removeNode(V)})}function q(S){S.edges().forEach(V=>{if(V.v===V.w){var W=S.node(V.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:V,label:S.edge(V)}),S.removeEdge(V)}})}function Y(S){var V=u.buildLayerMatrix(S);V.forEach(W=>{var H=0;W.forEach((Z,J)=>{var le=S.node(Z);le.order=J+H,(le.selfEdges||[]).forEach(te=>{u.addDummyNode(S,"selfedge",{width:te.label.width,height:te.label.height,rank:le.rank,order:J+ ++H,e:te.e,label:te.label},"_se")}),delete le.selfEdges})})}function F(S){S.nodes().forEach(V=>{var W=S.node(V);if(W.dummy==="selfedge"){var H=S.node(W.e.v),Z=H.x+H.width/2,J=H.y,le=W.x-Z,te=H.height/2;S.setEdge(W.e,W.label),S.removeNode(V),W.label.points=[{x:Z+2*le/3,y:J-te},{x:Z+5*le/6,y:J-te},{x:Z+le,y:J},{x:Z+5*le/6,y:J+te},{x:Z+2*le/3,y:J+te}],W.label.x=W.x,W.label.y=W.y}})}function Q(S,V){return u.mapValues(u.pick(S,V),Number)}function $(S){var V={};return S&&Object.entries(S).forEach(([W,H])=>{typeof W=="string"&&(W=W.toLowerCase()),V[W]=H}),V}}),uh=Pe((e,n)=>{var s=Ke(),r=Pt().Graph;n.exports={debugOrdering:i};function i(o){let a=s.buildLayerMatrix(o),c=new r({compound:!0,multigraph:!0}).setGraph({});return o.nodes().forEach(l=>{c.setNode(l,{label:l}),c.setParent(l,"layer"+o.node(l).rank)}),o.edges().forEach(l=>c.setEdge(l.v,l.w,{},l.name)),a.forEach((l,d)=>{let h="layer"+d;c.setNode(h,{rank:"same"}),l.reduce((f,m)=>(c.setEdge(f,m,{style:"invis"}),m))}),c}}),fh=Pe((e,n)=>{n.exports="2.0.4"}),hh=Pe((e,n)=>{n.exports={graphlib:Pt(),layout:dh(),debug:uh(),util:{time:Ke().time,notime:Ke().notime},version:fh()}});const Ea=hh();const Ma={pending:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},in_progress:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},blocked:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},review:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},failed:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},rejected:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"},archived:{bg:"bg-gray-500/5",border:"border-gray-500/15",text:"text-fg-tertiary"}},mh={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function gh({data:e}){const{t:n}=We(["work","common"]),{task:s,agentName:r,selected:i,direction:o="TB",isExpandedRoot:a,onCollapse:c}=e,l=Ma[s.status]??Ma.pending,d=s.taskType==="scheduled"&&!!s.scheduleConfig,h=d?s.scheduleConfig.every?n("work:task.everyInterval",{interval:s.scheduleConfig.every}):s.scheduleConfig.cron?n("work:task.cronLabel"):"":"",f=o==="LR"?be.Left:be.Top,m=o==="LR"?be.Right:be.Bottom;return t.jsxs("div",{className:`relative rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${d?`${l.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${l.bg} ${l.border}`} ${i?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[t.jsx(dn,{type:"target",position:f,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${mh[s.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${l.text}`,children:n(`work:status.task.${s.status}`,{defaultValue:s.status.replace("_"," ")})}),d&&t.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/15 text-blue-600 ml-auto whitespace-nowrap inline-flex items-center gap-0.5",children:[t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})}),h]})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:s.title}),r&&t.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:r}),s.blockedBy&&s.blockedBy.length>0&&t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:n("work:dag.depCount",{count:s.blockedBy.length})}),t.jsx(dn,{type:"source",position:m,className:"!bg-border-default !w-2 !h-2"}),a&&c&&t.jsx("button",{onClick:u=>{u.stopPropagation(),c()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const Ia={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 ph({data:e}){const{t:n}=We(["work","common"]),{req:s,selected:r,direction:i="TB",isExpandedRoot:o,onCollapse:a}=e,c=Ia[s.status]??Ia.pending,l=i==="LR"?be.Left:be.Top,d=i==="LR"?be.Right:be.Bottom;return t.jsxs("div",{className:`relative rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${c.bg} ${c.border} ${r?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[t.jsx(dn,{type:"target",position:l,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:n("work:dag.reqLabel")}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${c.text}`,children:n(`work:status.requirement.${s.status}`,{defaultValue:s.status.replace("_"," ")})})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:s.title}),s.taskIds.length>0&&t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:n("work:dag.taskCount",{count:s.taskIds.length})}),t.jsx(dn,{type:"source",position:d,className:"!bg-border-default !w-2 !h-2"}),o&&a&&t.jsx("button",{onClick:h=>{h.stopPropagation(),a()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const xh={task:gh,requirement:ph};function bh({nodeIds:e,rfRef:n}){const s=ff();return g.useEffect(()=>{if(e.length===0)return;const r=setTimeout(()=>{s(e),requestAnimationFrame(()=>{n.current?.fitView({padding:.2})})},300);return()=>clearTimeout(r)},[e.length]),null}const yh=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&!document.documentElement.classList.contains("cyberpunk")&&!document.documentElement.classList.contains("mono")&&window.matchMedia("(prefers-color-scheme: light)").matches,vh=e=>{const n=new MutationObserver(e);n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const s=window.matchMedia("(prefers-color-scheme: light)");return s.addEventListener("change",e),()=>{n.disconnect(),s.removeEventListener("change",e)}};function wh(){return g.useSyncExternalStore(vh,yh,()=>!1)}const Ur=200,Qr=80;function Ra(e,n,s="TB"){const r=o=>{const a=new Ea.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:o,nodesep:40,ranksep:60});for(const c of e)a.setNode(c.id,{width:Ur,height:Qr});for(const c of n)a.setEdge(c.source,c.target);return Ea.layout(a),e.map(c=>{const l=a.node(c.id);return{...c,position:{x:(l?.x??0)-Ur/2,y:(l?.y??0)-Qr/2}}})},i=r(s);if(n.length>0&&e.length>4){let o=1/0,a=-1/0,c=1/0,l=-1/0;for(const m of i)o=Math.min(o,m.position.x),a=Math.max(a,m.position.x+Ur),c=Math.min(c,m.position.y),l=Math.max(l,m.position.y+Qr);const d=a-o,h=l-c,f=s==="TB"?"LR":"TB";if(d>h*3)return{nodes:r(f),direction:f}}return{nodes:i,direction:s}}function kh(e,n){const s=new Map,r=new Map;for(const a of e)r.set(a.id,a),s.set(a.id,new Set);for(const a of n)s.get(a.source)?.add(a.target),s.get(a.target)?.add(a.source);const i=new Set,o=[];for(const a of e){if(i.has(a.id))continue;const c=new Set,l=[a.id];for(;l.length>0;){const d=l.pop();if(!i.has(d)){i.add(d),c.add(d);for(const h of s.get(d)??[])i.has(h)||l.push(h)}}o.push({nodes:e.filter(d=>c.has(d.id)),edges:n.filter(d=>c.has(d.source)&&c.has(d.target))})}return o}function _a(e,n){if(e.length===0)return{nodes:[],direction:"TB"};const s=kh(e,n);if(s.length===1)return Ra(e,n);let r="TB";const i=s.map(m=>{const{nodes:u,direction:p}=Ra(m.nodes,m.edges);r=p;let M=1/0,C=-1/0,y=1/0,v=-1/0;for(const x of u)M=Math.min(M,x.position.x),C=Math.max(C,x.position.x+Ur),y=Math.min(y,x.position.y),v=Math.max(v,x.position.y+Qr);for(const x of u)x.position.x-=M,x.position.y-=y;return{nodes:u,w:C-M,h:v-y}});i.sort((m,u)=>u.h-m.h);const o=60,a=i.reduce((m,u)=>m+(u.w+o)*(u.h+o),0),c=Math.sqrt(a)*1.1,l=[];let d=0,h=0,f=0;for(const m of i){d>0&&d+m.w>c&&(d=0,h+=f+o,f=0);for(const u of m.nodes)l.push({...u,position:{x:u.position.x+d,y:u.position.y+h}});d+=m.w+o,f=Math.max(f,m.h)}return{nodes:l,direction:r}}function jh(e,n,s){const r=new Set,i=[n];for(;i.length>0;){const o=i.pop();if(o===s)return!0;if(r.has(o))continue;r.add(o);const a=e.get(o);if(a?.blockedBy)for(const c of a.blockedBy)i.push(c)}return!1}const Vn=[{id:"todo",statuses:new Set(["pending"]),color:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"}},{id:"in_progress",statuses:new Set(["in_progress","blocked"]),color:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"}},{id:"review",statuses:new Set(["review"]),color:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"}},{id:"done",statuses:new Set(["completed","failed","rejected","cancelled","archived"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}];new Set(Vn.map(e=>e.id));const Yr=new Set(Vn.filter(e=>e.id!=="done").map(e=>e.id)),La=e=>e.status==="archived";function Nh(e,n,s,r){const i=new Set,o=[e];for(;o.length>0;){const a=o.pop();if(!i.has(a))if(i.add(a),a.startsWith("req-")){const c=s.get(a.slice(4));if(c)for(const l of c.taskIds)o.push(l)}else{const c=n.get(a);if(c?.blockedBy)for(const l of c.blockedBy)o.push(l);c?.requirementId&&o.push(`req-${c.requirementId}`)}}for(const a of r)a.requirementId&&i.has(a.id)&&i.add(`req-${a.requirementId}`);return i}function Ch({tasks:e,requirements:n=[],agents:s,showArchived:r,onShowArchivedChange:i,onTaskClick:o,onReqClick:a,onCollapseDAG:c,onDependencyChange:l,selectedTaskId:d,selectedReqId:h,hasDetailPanel:f,defaultExpandedNodeId:m,previewMode:u}){const{t:p}=We(["work","common"]),M=wh(),[C,y]=g.useState(null),[v,x]=g.useState(null),[b,k]=g.useState(()=>new Set(Yr)),[N,I]=g.useState(m??null),[B,D]=g.useState(r??!1),L=r??B,E=g.useCallback(fe=>{const re=typeof fe=="function"?fe(L):fe;D(re),i?.(re)},[L,i]);g.useEffect(()=>{r!==void 0&&D(r)},[r]),g.useEffect(()=>{m&&I(m)},[m]);const P=g.useMemo(()=>e.filter(fe=>La(fe)).length,[e]),z=g.useMemo(()=>{const fe=new Set;for(const re of Vn)if(b.has(re.id))for(const xe of re.statuses)fe.add(xe);return fe},[b]),j=g.useMemo(()=>{const fe=new Set;for(const re of e)for(const xe of Vn)if(xe.statuses.has(re.status)){fe.add(xe.id);break}for(const re of n){const xe=Ta[re.status];xe&&fe.add(xe)}return Vn.filter(re=>fe.has(re.id))},[e,n]),O=g.useCallback(fe=>{k(re=>{const xe=new Set(re);return xe.has(fe)?xe.delete(fe):xe.add(fe),xe})},[]),_=g.useCallback((fe,re="success")=>{y({msg:fe,type:re}),setTimeout(()=>y(null),2500)},[]),T=g.useMemo(()=>{const fe=new Map;for(const re of s)fe.set(re.id,re.name);return fe},[s]),R=g.useMemo(()=>{const fe=new Map;for(const re of e)fe.set(re.id,re);return fe},[e]),A=g.useMemo(()=>{const fe=new Map;for(const re of n)fe.set(re.id,re);return fe},[n]),q=g.useRef(!1),Y=g.useCallback(()=>{q.current=!1,I(null),c?.()},[c]),F=M?"#94a3b8":"#6b7280",Q=g.useCallback((fe,re,xe)=>({id:`${fe}->${re}`,source:fe,target:re,animated:xe==="blocked",markerEnd:{type:Gn.ArrowClosed,width:14,height:14,color:xe==="blocked"?"#ef4444":F},style:{stroke:xe==="blocked"?"#ef4444":F,strokeWidth:1.5,cursor:"pointer"}}),[F]),{initialNodes:$,initialEdges:S,topLevelIds:V}=g.useMemo(()=>{const fe=(Ce,Xe)=>{const $e=new Set,Le=Ce.map(_e=>($e.add(_e.id),{id:_e.id,type:"task",data:{task:_e,agentName:_e.assignedAgentId?T.get(_e.assignedAgentId):void 0,selected:_e.id===d},position:{x:0,y:0}}));for(const _e of Xe){const Ye=`req-${_e.id}`;$e.add(Ye),Le.push({id:Ye,type:"requirement",data:{req:_e,selected:_e.id===h},position:{x:0,y:0}})}const et=[];for(const _e of Ce)if(_e.blockedBy)for(const Ye of _e.blockedBy)$e.has(Ye)&&et.push(Q(Ye,_e.id,_e.status));const qt=new Set,Wt=(_e,Ye)=>{const tt=`${_e}->${Ye}`;qt.has(tt)||(qt.add(tt),et.push({id:tt,source:_e,target:Ye,markerEnd:{type:Gn.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const _e of Xe){const Ye=`req-${_e.id}`;for(const tt of _e.taskIds)$e.has(tt)&&Wt(Ye,tt)}for(const _e of Ce)if(_e.requirementId){const Ye=`req-${_e.requirementId}`;$e.has(Ye)&&Wt(Ye,_e.id)}return{nodes:Le,edges:et}},re=e.filter(Ce=>z.has(Ce.status)&&(L||!La(Ce))),xe=new Set;for(const Ce of Vn)b.has(Ce.id)&&xe.add(Ce.id);const Ee=n.filter(Ce=>{const Xe=Ta[Ce.status];return Xe&&xe.has(Xe)}),{nodes:ye,edges:Ie}=fe(re,Ee),pt=new Set;for(const Ce of Ie)pt.add(Ce.target);const rt=new Set(ye.filter(Ce=>!pt.has(Ce.id)).map(Ce=>Ce.id));if(!N||!rt.has(N)){const Ce=ye,{nodes:Xe,direction:$e}=_a(Ce,Ie);return{initialNodes:Xe.map(et=>({...et,data:{...et.data,direction:$e}})),initialEdges:Ie,topLevelIds:rt}}const{nodes:Nt,edges:Ct}=fe(e,n),st=Nh(N,R,A,e),Ht=Nt.filter(Ce=>st.has(Ce.id)).map(Ce=>Ce.id===N?{...Ce,data:{...Ce.data,isExpandedRoot:!0,onCollapse:Y}}:Ce),xt=Ct.filter(Ce=>st.has(Ce.source)&&st.has(Ce.target)),{nodes:Jt,direction:bt}=_a(Ht,xt);return{initialNodes:Jt.map(Ce=>({...Ce,data:{...Ce.data,direction:bt}})),initialEdges:xt,topLevelIds:rt}},[e,n,T,R,A,Q,z,b,L,d,h,N,Y]),[W,H,Z]=hf($),[J,le,te]=mf(S),X=g.useRef(null),ie=g.useRef({groupFilter:b,showArchived:L});g.useEffect(()=>{const fe=ie.current;(fe.groupFilter!==b||fe.showArchived!==L)&&(q.current=!1,I(null),ie.current={groupFilter:b,showArchived:L})},[b,L]),g.useEffect(()=>{H($),le(S),q.current||requestAnimationFrame(()=>{X.current?.fitView({padding:.2,duration:300})})},[$,S,H,le]),g.useEffect(()=>{const fe=setTimeout(()=>{X.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(fe)},[f]);const de=g.useCallback(fe=>{fe&&(q.current=!0)},[]),se=g.useCallback((fe,re)=>{if(!N&&V.has(re.id)&&(q.current=!1,I(re.id)),re.id.startsWith("req-")){const xe=A.get(re.id.slice(4));xe&&a&&a(xe)}else{const xe=R.get(re.id);xe&&o&&o(xe)}},[R,A,o,a,V,N]),me=g.useCallback(async fe=>{const{source:re,target:xe}=fe;if(!re||!xe||re===xe)return;const Ee=R.get(xe);if(!Ee)return;if(Ee.blockedBy?.includes(re)){_(p("work:dag.toast.dependencyExists"),"error");return}if(jh(R,re,xe)){_(p("work:dag.toast.cycleError"),"error");return}const ye=[...Ee.blockedBy??[],re];try{await ae.tasks.update(xe,{blockedBy:ye}),_(p("work:dag.toast.dependencyAdded")),l?.()}catch(Ie){_(p("work:dag.toast.failed",{message:Ie instanceof Error?Ie.message:String(Ie)}),"error")}},[R,_,l,p]),ue=g.useCallback((fe,re)=>{x(re)},[]),K=g.useCallback(async()=>{if(!v)return;const fe=R.get(v.target);if(!fe){x(null);return}const re=(fe.blockedBy??[]).filter(xe=>xe!==v.source);try{await ae.tasks.update(v.target,{blockedBy:re}),_(p("work:dag.toast.dependencyRemoved")),l?.()}catch(xe){_(p("work:dag.toast.failed",{message:xe instanceof Error?xe.message:String(xe)}),"error")}x(null)},[v,R,_,l,p]);if(e.length===0)return t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"flex flex-col items-center gap-3 max-w-sm text-center",children:[t.jsx("svg",{className:"w-10 h-10 text-fg-quaternary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:p("work:task.dagEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:p("work:task.dagEmptyDesc")})]})});const ce=b.size===Yr.size&&[...Yr].every(fe=>b.has(fe))&&!L,ge=v?R.get(v.source):null,ve=v?R.get(v.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(uf,{nodes:W,edges:J,onNodesChange:Z,onEdgesChange:te,onNodeClick:se,onConnect:me,onEdgeClick:ue,onMoveEnd:de,onInit:fe=>{X.current=fe},nodeTypes:xh,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[u&&t.jsx(bh,{nodeIds:W.map(fe=>fe.id),rfRef:X}),t.jsx(yf,{color:M?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(Sf,{showInteractive:!1,className:"!bg-surface-secondary !border-border-default !shadow-xl [&>button]:!bg-surface-elevated [&>button]:!border-border-default [&>button]:!text-fg-secondary [&>button:hover]:!bg-surface-overlay"}),t.jsx(Bf,{nodeColor:fe=>{const re=fe.data?.task,xe=re?.status;return re?.taskType==="scheduled"?"#8b8fa3":xe==="completed"||xe==="accepted"?"#10b981":xe==="in_progress"?"#f59e0b":xe==="blocked"||xe==="failed"?"#ef4444":M?"#94a3b8":"#6b7280"},maskColor:M?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),t.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-surface-secondary/90 border border-border-default rounded-lg backdrop-blur-sm z-10 flex flex-col items-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[j.map(fe=>{const re=b.has(fe.id);return t.jsx("button",{onClick:()=>O(fe.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${re?`${fe.color.bg} ${fe.color.border} ${fe.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:p(`work:dag.filter.${fe.id}`)},fe.id)}),P>0&&t.jsx("button",{onClick:()=>E(fe=>!fe),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${L?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:p("work:dag.archivedToggle",{count:P})}),!ce&&t.jsx("button",{onClick:()=>{k(new Set(Yr)),E(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:p("work:dag.reset")})]}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[N?t.jsx("button",{onClick:Y,className:"text-brand-500 hover:text-brand-400 transition-colors",children:p("work:dag.backToOverview")}):t.jsx("span",{children:p("work:dag.expandHint")}),t.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),t.jsx("span",{children:p("work:dag.dragHint")})]})]}),C&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${C.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:C.msg}),v&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>x(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:fe=>fe.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:p("work:dag.removeDependencyTitle")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:p("work:dag.removeDependencyBody",{target:ve?.title??v.target.slice(-8),source:ge?.title??v.source.slice(-8)})}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>x(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:p("common:cancel")}),t.jsx("button",{onClick:K,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:p("common:remove")})]})]})})]})}function Sh({orgId:e,onCreated:n,onClose:s}){const{t:r}=We(["work","common"]);Wl(!0);const[i,o]=g.useState(""),[a,c]=g.useState(""),[l,d]=g.useState(""),[h,f]=g.useState("main"),[m,u]=g.useState([]),[p,M]=g.useState([]),[C,y]=g.useState(!1),[v,x]=g.useState(""),[b,k]=g.useState(!1),N=vr();g.useEffect(()=>{ae.teams.list().then(D=>M(D.teams)).catch(()=>{})},[]),g.useEffect(()=>{const D=L=>{L.key==="Escape"&&s()};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[s]);const I=g.useCallback(async D=>{if(D?.preventDefault(),k(!0),!(!i.trim()||C)){y(!0),x("");try{const L=l.trim()?[{url:l.trim(),defaultBranch:h.trim()||"main"}]:[],E=await ae.projects.create({name:i.trim(),description:a.trim()||void 0,repositories:L.length>0?L:void 0,teamIds:m.length>0?m:void 0,orgId:e??"default"});n(E.project)}catch(L){x(L instanceof Error?L.message:r("project.failedToCreate"))}y(!1)}},[i,a,l,h,m,e,C,n,r]),B=b&&!i.trim();return Vl.createPortal(t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:s,children:t.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto ${N?"w-full":"w-[520px]"}`,onClick:D=>D.stopPropagation(),onSubmit:I,children:[t.jsx("h3",{className:"text-base font-semibold mb-5",children:r("project.newProject")}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.projectName")}),t.jsx("input",{value:i,onChange:D=>{o(D.target.value),x("")},onBlur:()=>k(!0),placeholder:r("project.projectNamePlaceholder"),className:`input ${B?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!N}),B&&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:D=>c(D.target.value),placeholder:r("project.descriptionPlaceholder"),className:"input",rows:3})]}),p.length>0&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.assignTeams")}),t.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:p.map(D=>{const L=m.includes(D.id);return t.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer hover:text-fg-primary py-0.5",children:[t.jsx("input",{type:"checkbox",checked:L,onChange:()=>u(E=>L?E.filter(P=>P!==D.id):[...E,D.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:D.name})]},D.id)})})]}),t.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.repositoryUrl")}),t.jsx("input",{value:l,onChange:D=>d(D.target.value),placeholder:r("project.repositoryPlaceholder"),className:"input"})]}),l.trim()&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.branch")}),t.jsx("input",{value:h,onChange:D=>f(D.target.value),placeholder:r("project.branchPlaceholder"),className:"input !w-24"})]})]}),v&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:v}),t.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||C,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:r(C?"common:creating":"project.createProject")})]})]})]})}),document.body)}function Eh({projects:e,selectedProjectId:n,allSelected:s,taskCounts:r,totalTaskCount:i,onSelectAll:o,onSelectProject:a,onCreateProject:c,onCollapse:l,width:d,onResizeStart:h,hidden:f,focused:m,onActivate:u}){const{t:p}=We(["work","common"]),M=s??n==null;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-keyboard-pane":"l1",onPointerDown:()=>u?.(),className:"bg-surface-primary flex flex-col shrink-0 border-r border-border-default/60",style:f?{display:"none"}:d!=null?{width:d}:void 0,children:[t.jsxs("div",{"data-electron-drag":!0,className:"px-3 h-14 flex items-center shrink-0 gap-2",children:[l&&t.jsx("button",{type:"button","data-no-drag":!0,onClick:l,className:"w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 bg-brand-500/15 text-brand-500 hover:bg-brand-500/25",title:p("common:shortcuts.toggleLeft"),children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),t.jsx("h2",{className:"text-sm font-semibold text-fg-primary truncate",children:p("work:task.projects",{defaultValue:"Projects"})}),t.jsx("button",{type:"button","data-no-drag":!0,onClick:c,className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:p("work:project.newProject"),children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:e.length===0?t.jsxs("div",{className:"px-2 py-8 text-center space-y-3",children:[t.jsx("div",{className:"w-10 h-10 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),t.jsx("p",{className:"text-[11px] text-fg-tertiary leading-relaxed px-1",children:p("work:task.emptyNoProjectsHint")}),t.jsx("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:p("work:project.newProject")})]}):t.jsxs(t.Fragment,{children:[o&&t.jsxs("button",{type:"button","data-project-id":"__all__",onClick:o,className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors ${M?m?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[t.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center shrink-0 ${M?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),t.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),t.jsx("span",{className:"min-w-0 flex-1",children:t.jsx("span",{className:"block text-[12px] font-medium truncate",children:p("work:task.all")})}),(i??0)>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:i})]}),e.map(C=>{const y=!M&&C.id===n,v=r[C.id]??0,x=C.status==="paused";return t.jsxs("button",{type:"button","data-project-id":C.id,onClick:()=>a(C.id),className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors ${y?m?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[t.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center text-[11px] font-bold shrink-0 ${y?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:C.name[0]?.toUpperCase()??"?"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block text-[12px] font-medium truncate",children:C.name}),x&&t.jsx("span",{className:"block text-[10px] text-amber-500/80",children:p("work:project.statusPaused")})]}),v>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:v})]},C.id)})]})})]}),!f&&h&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:h,children:t.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})})]})}const Aa="markus_work_l1_collapsed",Mh=["backlog","kanban","dag","workflows"];function ro(e){const n=e.agentId,s=e.activityId;return!n||!s?null:Qa({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},s,n)}function so(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 oo({entries:e}){const[n,s]=g.useState("compact");return e.length===0?null:t.jsx("div",{onClick:r=>r.stopPropagation(),children:n==="compact"?t.jsx(Ul,{entries:e,isActive:!0,onExpand:()=>s("full"),embedded:!0}):t.jsx(Ja,{entries:e,isActive:!0,onCollapse:()=>s("compact"),embedded:!0})})}function ao(e,n){const[s,r]=g.useState(null);return g.useEffect(()=>{if(!n||!e.current){r(null);return}const i=()=>{const o=e.current?.getBoundingClientRect();if(!o)return;const a=240,c=window.innerHeight-o.bottom-8,l=o.top-8,d=c<a&&l>c;r(d?{top:o.top-4,left:o.left,width:o.width,flipUp:!0}:{top:o.bottom+4,left:o.left,width:o.width,flipUp:!1})};return i(),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[n,e]),s}function cr({options:e,value:n,onChange:s,placeholder:r,noMatchesText:i,className:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=ao(f,a);g.useEffect(()=>{const y=v=>{h.current&&!h.current.contains(v.target)&&u.current&&!u.current.contains(v.target)&&c(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]);const M=e.find(y=>y.value===n)?.label??"",C=l?e.filter(y=>y.label.toLowerCase().includes(l.toLowerCase())):e;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:l,onChange:y=>d(y.target.value),onClick:y=>y.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:M||r,autoFocus:!0}):t.jsx("span",{className:M?"text-fg-primary":"text-fg-tertiary",children:M||r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&p&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:C.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):C.map(y=>t.jsx("div",{onClick:()=>{s(y.value),c(!1),d("")},className:`px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 ${y.value===n?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:y.label},y.value))})]})}function Ih({options:e,selected:n,onAdd:s,placeholder:r,noMatchesText:i,className:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=ao(f,a);g.useEffect(()=>{const y=v=>{h.current&&!h.current.contains(v.target)&&u.current&&!u.current.contains(v.target)&&c(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]);const M=e.filter(y=>!n.includes(y.value)),C=l?M.filter(y=>y.label.toLowerCase().includes(l.toLowerCase())):M;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:l,onChange:y=>d(y.target.value),onClick:y=>y.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:r,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&p&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:C.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):C.map(y=>t.jsx("div",{onClick:()=>{s(y.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:y.label},y.value))})]})}function Th({options:e,onSelect:n,placeholder:s,noMatchesText:r,className:i,itemSuffix:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=ao(f,a);g.useEffect(()=>{const C=y=>{h.current&&!h.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&c(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]);const M=l?e.filter(C=>C.label.toLowerCase().includes(l.toLowerCase())):e;return t.jsxs("div",{ref:h,className:i??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:l,onChange:C=>d(C.target.value),onClick:C=>C.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-[11px]",placeholder:s,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:s}),t.jsx("svg",{className:"w-3.5 h-3.5 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&p&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:M.length===0?t.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:r??"No matches"}):M.map(C=>t.jsxs("div",{onClick:()=>{n(C.value),c(!1),d("")},className:"px-3 py-2 text-xs cursor-pointer hover:bg-brand-500/10 text-fg-primary flex items-center justify-between gap-2",children:[t.jsx("span",{className:"truncate",children:C.label}),o?.(C)]},C.value))})]})}function Qn(e,n,s,r="Admin"){if(!e)return null;const i=n.find(a=>a.id===e);if(i)return i.name;const o=s.find(a=>a.id===e);return o?o.name:e==="anonymous"?r:null}function Rh({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=We(["work","common"]),[o,a]=g.useState(!1),[c,l]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{l(e)},[e]),g.useEffect(()=>{o&&d.current?.focus()},[o]);const h=async()=>{a(!1);const f=c.trim();if(f&&f!==e)try{await n(f)}catch{l(e)}else l(e)};return o?t.jsx("input",{ref:d,value:c,onChange:f=>l(f.target.value),onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&h(),f.key==="Escape"&&(l(e),a(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${s??""}`,placeholder:r}):t.jsx("span",{onClick:()=>a(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.clickToEdit")})})}function _h({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=We(["work","common"]),[o,a]=g.useState(!1),[c,l]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{l(e)},[e]),g.useEffect(()=>{o&&d.current&&(d.current.focus(),d.current.style.height="auto",d.current.style.height=d.current.scrollHeight+"px")},[o]);const h=async()=>{a(!1);const f=c.trim();if(f!==e)try{await n(f)}catch{l(e)}else l(e)};return o?t.jsx("textarea",{ref:d,value:c,onChange:f=>{l(f.target.value),f.target.style.height="auto",f.target.style.height=f.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Escape"&&(l(e),a(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${s??""}`,placeholder:r,rows:2}):t.jsx("p",{onClick:()=>a(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.addDescription")})})}const Lh=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function xl(e){const n=e.match(Lh);return n?{timestamp:n[1].trim(),author:n[2]?.trim()??"System",content:n[3].trim()}:{timestamp:"",author:"",content:e}}function Ah(e,n){if(!e)return"";const s=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!s)return e;const r=new Date,i=+s[1],o=+s[2]-1,a=+s[3],c=+s[4],l=+s[5],d=new Date(i,o,a,c,l),h=r.getTime()-d.getTime();return h<6e4?n("work:relative.justNow"):h<36e5?n("work:relative.minutesAgo",{count:Math.floor(h/6e4)}):h<864e5?n("work:relative.hoursAgo",{count:Math.floor(h/36e5)}):h<6048e5?n("work:relative.daysAgo",{count:Math.floor(h/864e5)}):`${i}-${String(o+1).padStart(2,"0")}-${String(a).padStart(2,"0")}`}const Da=[{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 Dh(e){let n=0;for(let s=0;s<e.length;s++)n=(n<<5)-n+e.charCodeAt(s)|0;return Da[Math.abs(n)%Da.length]}function Ph({note:e,compact:n}){const{t:s}=We(["work","common"]),r=xl(e),i=s("work:task.systemAuthor"),o=Dh(r.author||i),a=r.author?r.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",c=Ah(r.timestamp,s),l=!r.author||r.author==="System";return n?t.jsxs("div",{className:"flex gap-2.5 group",children:[t.jsx("div",{className:`w-6 h-6 rounded-full ${o.bg} flex items-center justify-center text-[9px] font-bold ${o.text} shrink-0 mt-0.5`,children:a}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium ${l?"text-fg-tertiary":o.text}`,children:l?i:r.author}),c&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:c})]}),t.jsx("div",{className:"text-xs text-fg-secondary",children:t.jsx(fr,{content:r.content,className:"text-xs text-fg-secondary"})})]})]}):t.jsxs("div",{className:"flex gap-3 group",children:[t.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[t.jsx("div",{className:`w-7 h-7 rounded-full ${o.bg} flex items-center justify-center text-[10px] font-bold ${o.text}`,children:a}),t.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),t.jsx("div",{className:"flex-1 min-w-0 pb-4",children:t.jsxs("div",{className:`border ${o.border} rounded-lg overflow-hidden`,children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${o.bg} border-b ${o.border}`,children:[t.jsx("span",{className:`text-[11px] font-medium ${l?"text-fg-secondary":o.text}`,children:l?i:r.author}),c&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:c})]}),t.jsx("div",{className:"px-3 py-2.5",children:t.jsx(fr,{content:r.content,className:"text-xs text-fg-secondary"})})]})})]})}const $h=new Set(["rejected","cancelled","archived"]),ss=[{id:"failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",statuses:["pending"],accent:"border-t-amber-500",dropStatus:"pending"},{id:"in_progress",statuses:["in_progress","blocked"],accent:"border-t-brand-500",dropStatus:"in_progress"},{id:"review",statuses:["review"],accent:"border-t-purple-500",dropStatus:"review"},{id:"done",statuses:["completed"],accent:"border-t-green-500",dropStatus:"completed"},{id:"closed",statuses:["rejected","cancelled","archived"],accent:"border-t-gray-500",dropStatus:"cancelled"}],Pa={pending:"bg-amber-500/15 text-amber-600",blocked:"bg-amber-500/15 text-amber-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500"},$a={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-blue-500/15 text-blue-500",blocked:"bg-orange-500/15 text-orange-500",review:"bg-purple-500/15 text-purple-500",revision:"bg-amber-500/15 text-amber-600",completed:"bg-green-500/15 text-green-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-500/15 text-fg-tertiary",archived:"bg-gray-500/15 text-fg-tertiary"},Oa={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"},Ba={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 bl(e){return Object.keys($a).reduce((n,s)=>(n[s]={label:e(`work:status.task.${s}`),cls:$a[s]},n),{})}function yl(e){return Object.keys(Pa).reduce((n,s)=>(n[s]={label:e(`work:status.sub.${s}`),cls:Pa[s]},n),{})}function Oh(e){return Object.keys(Oa).reduce((n,s)=>(n[s]={label:e(`work:priority.${s}`),cls:Oa[s]},n),{})}function io(e){return Object.keys(Ba).reduce((n,s)=>(n[s]={label:e(`work:status.requirement.${s}`),cls:Ba[s]},n),{})}const za=["low","medium","high","urgent"],Ha=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],qa=["pending","in_progress","completed","rejected","cancelled"],Wa={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived"]),archived:new Set([])},qs={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},yr={idle:"bg-green-400",working:"bg-blue-400",error:"bg-red-400",paused:"bg-amber-400",offline:"bg-gray-600",pending:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",rejected:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},Va={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function Bh({agent:e,anchorRect:n,onClose:s}){const{t:r}=We(["work","common"]),i=g.useRef(null);g.useEffect(()=>{const c=l=>{i.current&&!i.current.contains(l.target)&&s()};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s]);const o=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",a=e.status==="idle"?r("work:task.online"):e.status==="working"?r("work:task.working"):e.status==="error"?r("work:task.error"):r("work:task.offline");return t.jsxs("div",{ref:i,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:n.top+4,left:n.left},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[10px] font-bold text-brand-600 shrink-0",children:e.name.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),t.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o}`}),t.jsx("span",{className:"text-[10px] text-fg-secondary",children:a})]})]})]}),t.jsx("button",{onClick:()=>{s(),Bt.navigate(Fe.TEAM,{selectAgent:e.id})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1 transition-colors",children:r("work:task.viewProfile")})]})}function ur({comment:e,agents:n,onReply:s}){const{t:r}=We(["work","common"]),i=e.authorType==="agent"||e.authorType==="system",o=new Date(e.createdAt),a=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),c=o.toLocaleDateString([],{month:"short",day:"numeric"}),[l,d]=g.useState(null),[h,f]=g.useState(!1),[m,u]=g.useState([]),[p,M]=g.useState(!1),C=g.useCallback((k,N)=>{const I=n.find(B=>B.name.toLowerCase()===k.toLowerCase());if(I){const B=N.target.getBoundingClientRect();d({agent:I,top:B.bottom,left:B.left})}},[n]),y=g.useMemo(()=>n.map(k=>k.name),[n]),v=g.useCallback(k=>{const N=n.find(I=>I.name.toLowerCase()===e.authorName.toLowerCase());if(N){const I=k.currentTarget.getBoundingClientRect();d({agent:N,top:I.bottom,left:I.left})}},[n,e.authorName]),x=g.useCallback(async()=>{if(h){f(!1);return}const k=e.activityId;if(k&&(f(!0),!(m.length>0))){M(!0);try{const{logs:N}=await ae.agents.getActivityLogs(e.authorId,k),I=N.map(B=>Qa(B,k,e.authorId)).filter(B=>B!==null).map(B=>({...B,ts:new Date(B.createdAt).getTime()}));u(I)}catch{}M(!1)}},[h,m.length,e]),b=g.useMemo(()=>As(m.map(Ls).filter(k=>k!==null)),[m]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[t.jsx("div",{onClick:v,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${i?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${i?"text-indigo-400":"text-blue-400"}`,onClick:v,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[c," ",a]}),s&&t.jsx("button",{onClick:()=>s(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r("work:task.reply")}),e.activityId&&i&&t.jsx("button",{onClick:x,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r(h?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&t.jsxs("button",{onClick:()=>{const k=document.getElementById(`comment-${e.replyTo}`);k&&(k.scrollIntoView({behavior:"smooth",block:"center"}),k.classList.add("bg-brand-500/10"),setTimeout(()=>k.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[t.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),t.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),t.jsx(fr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:C,knownNames:y}),e.attachments?.map((k,N)=>k.type==="image"?t.jsx("img",{src:k.url,alt:k.name,className:"mt-1 max-w-[200px] rounded"},N):null),h&&t.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:p?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:r("work:task.loadingExecutionLog")}):b.length===0?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:r("work:task.noExecutionLogAvailable")}):t.jsx(Ja,{entries:m,isActive:!1,onCollapse:()=>f(!1),embedded:!0})})]}),l&&t.jsx(Bh,{agent:l.agent,anchorRect:{top:l.top,left:l.left},onClose:()=>d(null)})]})}function zh({task:e,agents:n,users:s,authUser:r}){const{t:i}=We(["work","common"]),[o,a]=g.useState([]),[c,l]=g.useState([]),d=g.useRef(null),[h,f]=g.useState(new Map);g.useEffect(()=>{l([]),f(new Map),d.current&&(clearTimeout(d.current),d.current=null),ae.tasks.getComments(e.id).then(y=>a(y.comments)).catch(()=>{})},[e.id]),g.useEffect(()=>jt.on("task:comment",v=>{if(v.payload?.taskId===e.id&&v.payload.comment){const x=v.payload.comment;a(b=>b.some(k=>k.id===x.id)?b:[...b,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(l(b=>{const k=b.filter(N=>N.id!==x.authorId);return k.length===0&&d.current&&(clearTimeout(d.current),d.current=null),k}),f(b=>{const k=new Map(b);return k.delete(x.authorId),k}))}}),[e.id]),g.useEffect(()=>{if(c.length===0)return;const y=new Set(c.map(x=>x.id));return jt.on("agent:activity_log",x=>{const b=x.payload;if(!b)return;const k=b.agentId;if(!y.has(k))return;const N=ro(b);N&&f(I=>so(I,k,N))})},[c]);const m=g.useMemo(()=>{const y=[];for(const v of e.notes??[]){const x=xl(v);let b;if(x.timestamp){const k=x.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);b=k?new Date(+k[1],+k[2]-1,+k[3],+k[4],+k[5],+(k[6]??0)):new Date(0)}else b=new Date(0);y.push({type:"note",note:v,ts:b})}for(const v of o)y.push({type:"comment",comment:v,ts:new Date(v.createdAt)});return y.sort((v,x)=>v.ts.getTime()-x.ts.getTime()),y},[e.notes,o]),[u,p]=g.useState(null),M=async(y,v,x,b)=>{let k;x.length>0&&(k=(await ae.uploads.upload(x.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await ae.tasks.addComment(e.id,y,r?.name,k,r?.id,v.length>0?v:void 0,b);const N=[],I=new Set,B=D=>{if(I.has(D)||D===r?.id)return;I.add(D);const L=n.find(E=>E.id===D);L&&N.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const D of v){const L=n.find(E=>E.name.toLowerCase()===D.toLowerCase());L&&B(L.id)}e.assignedAgentId&&B(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&B(e.createdBy),N.length>0&&(d.current&&clearTimeout(d.current),l(N),d.current=setTimeout(()=>l([]),12e4))},C=g.useCallback(y=>{p({id:y.id,authorName:y.authorName,content:y.content.slice(0,100)})},[]);return t.jsxs("div",{className:"mt-5",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:i("work:task.activityCommentsHeading")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[m.length===0&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:i("work:task.noActivityYet")}),m.map((y,v)=>y.type==="note"?t.jsx(Ph,{note:y.note,compact:!0},`n-${v}`):t.jsx(ur,{comment:y.comment,agents:n,onReply:C},`c-${y.comment.id}`)),c.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(y=>{const v=h.get(y.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(Fe.TEAM,{agentId:y.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Vs,{name:y.name,avatarUrl:y.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:y.name}),v.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),v.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(oo,{entries:v})})]},y.id)})})]}),t.jsx(ti,{agents:n,humans:s,onSubmit:M,replyTo:u,onCancelReply:()=>p(null),placeholder:i("work:task.commentPlaceholder")})]})}function Hh({task:e,isRunning:n,authUser:s,agents:r}){const i=e.id,{t:o}=We(["work","common"]),[a,c]=g.useState([]),[l,d]=g.useState(new Map),[h,f]=g.useState(new Set),[m,u]=g.useState([]),[p,M]=g.useState(""),[C,y]=g.useState(n),[v,x]=g.useState(!0),[b,k]=g.useState(new Set),[N,I]=g.useState(""),[B,D]=g.useState(!1),[L,E]=g.useState([]),P=g.useRef(null),[z,j]=g.useState(new Map),[O,_]=g.useState([]),[T,R]=g.useState([]),[A,q]=g.useState(!1),Y=g.useRef(null),F=g.useRef(null);g.useEffect(()=>{y(n)},[n]),g.useEffect(()=>{E([]),j(new Map),P.current&&(clearTimeout(P.current),P.current=null)},[i]),g.useEffect(()=>{x(!0),Promise.all([ae.tasks.getLogsSummary(i).catch(()=>({rounds:[]})),ae.tasks.getComments(i).catch(()=>({comments:[]}))]).then(([X,ie])=>{const de=X.rounds;if(c(de),u(ie.comments),de.length===0){x(!1);return}const se=de[de.length-1].round;k(new Set([se])),ae.tasks.getLogs(i,se).catch(()=>({logs:[]})).then(me=>{d(new Map([[se,me.logs]])),x(!1)})})},[i]),g.useEffect(()=>{const X=e.assignedAgentId;X&&(q(!0),ae.agents.getActivities(X,{taskId:i,limit:20}).then(ie=>R(ie.activities)).catch(()=>R([])).finally(()=>q(!1)))},[i,e.assignedAgentId]);const Q=g.useCallback(X=>{l.has(X)||h.has(X)||(f(ie=>new Set(ie).add(X)),ae.tasks.getLogs(i,X).catch(()=>({logs:[]})).then(ie=>{d(de=>new Map(de).set(X,ie.logs)),f(de=>{const se=new Set(de);return se.delete(X),se})}))},[i,l,h]),$=g.useCallback(X=>{k(ie=>{const de=new Set(ie);return de.has(X)?de.delete(X):(de.add(X),l.has(X)||Q(X)),de})},[l,Q]);g.useEffect(()=>{const X=jt.on("task:log",se=>{const me=se.payload;if(me.taskId!==i)return;const ue={id:me.id,taskId:me.taskId,agentId:me.agentId,seq:me.seq,type:me.logType,content:me.content,metadata:me.metadata,executionRound:me.executionRound,createdAt:me.createdAt},K=ue.executionRound??1;c(ce=>ce.find(ve=>ve.round===K)?ce:[...ce,{round:K,logCount:0,toolCount:0,firstAt:ue.createdAt,lastAt:ue.createdAt,status:"running"}]),k(ce=>ce.has(K)?ce:new Set(ce).add(K)),d(ce=>{const ge=ce.get(K)??[];return ue.id&&ge.some(ve=>ve.id===ue.id)?ce:new Map(ce).set(K,[...ge,ue])}),ue.type==="text"&&M(""),ue.type==="status"&&(ue.content==="started"||ue.content==="resumed"?y(!0):["completed","failed","cancelled","execution_finished"].includes(ue.content)&&(y(!1),c(ce=>ce.map(ge=>ge.round===K?{...ge,status:ue.content}:ge)))),ue.type==="error"&&y(!1)}),ie=jt.on("task:log:delta",se=>{const me=se.payload;me.taskId===i&&M(ue=>ue+me.text)}),de=jt.on("task:comment",se=>{const me=se.payload;if(me.taskId!==i)return;const ue=me.comment;u(K=>K.some(ce=>ce.id===ue.id)?K:[...K,ue]),(ue.authorType==="agent"||ue.authorId?.startsWith("agt_"))&&(E(K=>{const ce=K.filter(ge=>ge.id!==ue.authorId);return ce.length===0&&P.current&&(clearTimeout(P.current),P.current=null),ce}),j(K=>{const ce=new Map(K);return ce.delete(ue.authorId),ce}))});return()=>{X(),ie(),de()}},[i]),g.useEffect(()=>{if(L.length===0)return;const X=new Set(L.map(de=>de.id));return jt.on("agent:activity_log",de=>{const se=de.payload;if(!se)return;const me=se.agentId;if(!X.has(me))return;const ue=ro(se);ue&&j(K=>so(K,me,ue))})},[L]);const S=g.useMemo(()=>{const X=[];for(const[,ie]of l)X.push(...ie);return X.sort((ie,de)=>ie.seq-de.seq),X},[l]),V=g.useMemo(()=>S.map(X=>Lo(X)),[S]),W=a.length>1,H=X=>{const ie=X.target.files;if(ie){for(const de of Array.from(ie)){if(!de.type.startsWith("image/"))continue;const se=new FileReader;se.onload=()=>{_(me=>[...me,{type:"image",url:se.result,name:de.name}])},se.readAsDataURL(de)}X.target.value=""}},Z=async()=>{if(!(!N.trim()&&O.length===0)){D(!0);try{let X;O.length>0&&(X=(await ae.uploads.upload(O.map(K=>({dataUrl:K.url,name:K.name})),"comments")).files.map(K=>({type:"image",url:K.url,name:K.name})));const ie=await ae.tasks.addComment(i,N,s?.name,X,s?.id);ie.comment&&u(ue=>ue.some(K=>K.id===ie.comment.id)?ue:[...ue,ie.comment]),I(""),_([]);const de=[],se=new Set,me=ue=>{if(se.has(ue)||ue===s?.id)return;se.add(ue);const K=r.find(ce=>ce.id===ue);K&&de.push({id:K.id,name:K.name,avatarUrl:K.avatarUrl})};e.assignedAgentId&&me(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&me(e.createdBy),de.length>0&&(P.current&&clearTimeout(P.current),E(de),P.current=setTimeout(()=>E([]),12e4))}catch{}D(!1)}},J=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[O.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:O.map((X,ie)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:X.url,alt:X.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>_(de=>de.filter((se,me)=>me!==ie)),className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-600 text-white text-[10px] flex items-center justify-center opacity-0 group-hover:opacity-100",children:"×"})]},ie))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:N,onChange:X=>I(X.target.value),onKeyDown:X=>{X.key==="Enter"&&!X.shiftKey&&(X.preventDefault(),Z())},placeholder:o("work:task.commentInstructionPlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-blue-500 outline-none text-fg-primary placeholder-gray-600"}),t.jsx("input",{type:"file",ref:Y,accept:"image/*",multiple:!0,onChange:H,className:"hidden"}),t.jsx("button",{onClick:()=>Y.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:o("work:task.attachImage"),children:"📎"}),t.jsx("button",{onClick:()=>{Z()},disabled:B||!N.trim()&&O.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:o("common:send")})]})]});if(v)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:o("work:task.loadingLogs")});if(a.length===0&&!p){const X=e.assignedAgentId?r.find(ve=>ve.id===e.assignedAgentId):void 0,ie=T.length>0,de=X&&X.currentTaskId&&X.currentTaskId!==e.id,se=e.status==="pending",me=e.status==="in_progress",ue=!e.assignedAgentId;let K="📋",ce=o("work:task.emptyLogs.default"),ge=o("work:task.emptyLogs.defaultHint");return ue?(K="👤",ce=o("work:task.emptyLogs.noAgent"),ge=o("work:task.emptyLogs.noAgentHint")):se?(K="⏳",ce=o("work:task.emptyLogs.pending"),ge=o("work:task.emptyLogs.pendingHint")):me&&de?(K="🔄",ce=o("work:task.emptyLogs.agentBusy",{agent:X?.name??e.assignedAgentId}),ge=o("work:task.emptyLogs.agentBusyHint")):me&&(K="⏳",ce=o("work:task.emptyLogs.starting"),ge=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:A?t.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:o("work:task.loadingLogs")}):ie?t.jsxs("div",{className:"px-4 py-4",children:[t.jsxs("div",{className:"text-xs text-fg-secondary mb-3 flex items-center gap-1.5",children:[t.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-blue-500"}),o("work:task.relatedSessions",{agent:X?.name??o("work:task.agent"),count:T.length})]}),t.jsx("div",{className:"space-y-1.5",children:T.map(ve=>{const fe=!ve.endedAt,re=ve.type==="task"?"🔧":ve.type==="chat"||ve.type==="respond_in_session"?"💬":ve.type==="heartbeat"?"💓":"📋";return t.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default/50 text-left transition-colors group",onClick:()=>Bt.navigate(Fe.TEAM,{agentId:e.assignedAgentId}),children:[t.jsx("span",{className:"text-sm shrink-0",children:re}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary truncate",children:ve.label}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(ve.startedAt).toLocaleString(),ve.endedAt?` — ${ve.totalTools} tools, ${ve.totalTokens.toLocaleString()} tokens`:""]})]}),fe&&t.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10px] text-green-500 font-medium",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"}),o("work:task.sessionLive")]}),!fe&&t.jsx("span",{className:`shrink-0 text-[10px] ${ve.success?"text-fg-tertiary":"text-red-400"}`,children:ve.success?"✓":"✗"}),t.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},ve.id)})})]}):t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsxs("div",{className:"text-center text-fg-tertiary",children:[t.jsx("div",{className:"text-2xl mb-2",children:K}),t.jsxs("div",{className:"text-xs",children:[ce,t.jsx("br",{}),t.jsx("span",{className:"text-fg-muted",children:ge})]})]})})}),J]})}if(!W){const X=V.map(se=>Ls(se)).filter(se=>se!==null),ie=Ao(S,As(X)),de=[...ie.map(se=>({kind:"entry",entry:se,ts:se.timestamp?new Date(se.timestamp).getTime():0})),...m.map(se=>({kind:"comment",comment:se,ts:new Date(se.createdAt).getTime()}))];return de.sort((se,me)=>se.ts-me.ts),t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-0.5",children:[de.map((se,me)=>se.kind==="comment"?t.jsx(ur,{comment:se.comment,agents:r},`c-${se.comment.id}`):t.jsx(Do,{entry:se.entry,showTime:!0,isLast:me===de.length-1},`e-${me}`)),C&&p&&t.jsx(Po,{content:p}),C&&!p&&ie.length>0&&t.jsx($o,{})]}),J]})}const le=(X,ie)=>{const de=X.firstAt?new Date(X.firstAt).getTime():0,se=ie?.firstAt?new Date(ie.firstAt).getTime():1/0;return m.filter(me=>{const ue=new Date(me.createdAt).getTime();return ue>=de&&ue<se})},te=a.length>0?m.filter(X=>new Date(X.createdAt).getTime()<new Date(a[0].firstAt).getTime()):[];return t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsx("div",{ref:F}),t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[te.length>0&&t.jsx("div",{className:"space-y-0.5",children:te.map(X=>t.jsx(ur,{comment:X,agents:r},X.id))}),a.map((X,ie)=>{const de=b.has(X.round),se=X.round===a[a.length-1].round,me=l.get(X.round),ue=h.has(X.round),K=le(X,a[ie+1]),ce=X.status==="completed"||X.status==="execution_finished"?"✅":X.status==="failed"?"❌":X.status==="cancelled"?"⏹":"🔄",ge=X.lastAt&&X.firstAt?Math.max(0,new Date(X.lastAt).getTime()-new Date(X.firstAt).getTime()):0,ve=ge>=6e4?`${Math.floor(ge/6e4)}m ${Math.floor(ge%6e4/1e3)}s`:ge>=1e3?`${Math.floor(ge/1e3)}s`:"";return t.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[t.jsxs("button",{onClick:()=>$(X.round),className:"w-full flex items-center justify-between px-3 py-2 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm",children:ce}),t.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:o("work:task.roundHeader",{n:X.round})}),K.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",K.length]}),se&&C&&t.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.toolCount",{count:X.toolCount})}),ve&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:ve}),t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${de?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})]}),de&&t.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[ue&&t.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:o("work:task.loadingRound",{n:X.round})}),me&&(()=>{const re=me.map(ye=>Lo(ye)).map(ye=>Ls(ye)).filter(ye=>ye!==null),Ee=[...Ao(me,As(re)).map(ye=>({kind:"entry",entry:ye,ts:ye.timestamp?new Date(ye.timestamp).getTime():0})),...K.map(ye=>({kind:"comment",comment:ye,ts:new Date(ye.createdAt).getTime()}))];return Ee.sort((ye,Ie)=>ye.ts-Ie.ts),Ee.map((ye,Ie)=>ye.kind==="comment"?t.jsx(ur,{comment:ye.comment,agents:r},`c-${ye.comment.id}`):t.jsx(Do,{entry:ye.entry,showTime:!0,isLast:Ie===Ee.length-1},`e-${Ie}`))})(),se&&C&&p&&t.jsx(Po,{content:p}),se&&C&&!p&&!ue&&t.jsx($o,{})]})]},X.round)}),L.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:L.map(X=>{const ie=z.get(X.id)??[];return t.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(Fe.TEAM,{agentId:X.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Vs,{name:X.name,avatarUrl:X.avatarUrl,size:24,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx("span",{className:"text-xs font-medium text-fg-secondary truncate",children:X.name}),ie.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")})]}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),ie.length>0&&t.jsx("div",{className:"ml-9 mt-1",children:t.jsx(oo,{entries:ie})})]},X.id)})})]}),J]})}const Fa=new Set([".md",".markdown",".txt",".json",".yaml",".yml",".toml",".csv",".xml",".html",".htm",".css",".js",".ts",".jsx",".tsx",".py",".sh",".log",".env",".cfg",".ini",".png",".jpg",".jpeg",".gif",".webp",".svg",".mp3",".wav",".ogg",".flac",".aac",".m4a",".opus",".mp4",".webm",".mov",".mkv",".m4v"]);function Gr(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function qh({filePath:e,onClose:n,onOpenExternal:s}){const{t:r}=We(["work","common"]),[i,o]=g.useState([e]),a=i[i.length-1],[c,l]=g.useState(null),[d,h]=g.useState(null),[f,m]=g.useState(!0);g.useEffect(()=>{m(!0),h(null),l(null),ae.files.preview(a).then(k=>l(k)).catch(k=>h(String(k))).finally(()=>m(!1))},[a]);const u=k=>o(N=>[...N,k]),p=()=>o(k=>k.length>1?k.slice(0,-1):k),M=i.length>1,C=k=>{ae.files.reveal(k).catch(()=>{})},y=k=>{k.isDirectory||Fa.has(k.ext)?u(k.path):C(k.path)},v=a.split("/").pop()??a,x=c?.type==="directory",b=(k,N)=>{if(N)return"📁";const I=[".md",".markdown"],B=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return I.includes(k)?"📝":B.includes(k)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(k)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(k)?"💻":"📄"};return t.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",onClick:n,children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl w-[720px] max-w-[92vw] max-h-[85vh] flex flex-col shadow-2xl",onClick:k=>k.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[M&&t.jsx("button",{onClick:p,className:"text-fg-tertiary hover:text-fg-primary text-sm shrink-0 p-1 -ml-1 rounded hover:bg-surface-elevated/60 transition-colors",title:r("common:back"),children:t.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),x?t.jsx("svg",{className:"w-4 h-4 text-amber-500 shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l.872.87A.5.5 0 008.665 3.5H13.5A1.5 1.5 0 0115 5v8.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-10z"})}):t.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),t.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),t.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:v}),x&&c.entries&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",c.entries.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[t.jsx("button",{onClick:()=>s?s():C(a),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:r(s?"work:task.openInDeliverables":"work:task.openInFinder"),children:t.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),t.jsx("button",{onClick:n,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]})]}),t.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:a})}),t.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[f&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.filePreviewLoading")}),d&&t.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:d}),c?.type==="directory"&&c.entries&&t.jsxs("div",{className:"divide-y divide-border-default/50",children:[c.entries.length===0&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.emptyDirectory")}),c.entries.map(k=>t.jsxs("button",{onClick:()=>y(k),className:"w-full flex items-center gap-3 px-5 py-2.5 hover:bg-surface-elevated/40 transition-colors text-left group",children:[t.jsx("span",{className:"text-sm shrink-0",children:b(k.ext,k.isDirectory)}),t.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:k.name}),!k.isDirectory&&k.size!=null&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Gr(k.size)}),k.isDirectory&&t.jsx("svg",{className:"w-3.5 h-3.5 text-fg-tertiary shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})}),!k.isDirectory&&!Fa.has(k.ext)&&t.jsxs("svg",{className:"w-3 h-3 text-fg-tertiary shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})]},k.path))]}),c&&c.type!=="directory"&&t.jsx("div",{className:"p-5",children:c.type==="image"&&c.content?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:`data:${c.mimeType};base64,${c.content}`,alt:c.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):c.type==="audio"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("audio",{controls:!0,preload:"metadata",src:c.streamUrl||(c.path?ae.files.streamUrl(c.path):ae.files.streamUrl(a)),className:"w-full"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[c.name,c.size!=null?` · ${Gr(c.size)}`:""]})]}):c.type==="video"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("video",{controls:!0,preload:"metadata",src:c.streamUrl||(c.path?ae.files.streamUrl(c.path):ae.files.streamUrl(a)),className:"w-full max-h-[60vh] rounded-lg bg-black"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[c.name,c.size!=null?` · ${Gr(c.size)}`:""]})]}):c.type==="binary"||c.content==null?t.jsxs("div",{className:"space-y-3 text-center py-6",children:[t.jsx("p",{className:"text-sm text-fg-secondary",children:r("work:task.cannotPreviewFile",{defaultValue:"This file type cannot be previewed."})}),t.jsxs("p",{className:"text-xs text-fg-tertiary font-mono",children:[c.name,c.extension?` (${c.extension})`:"",c.size!=null?` · ${Gr(c.size)}`:""]}),t.jsx("button",{onClick:()=>C(a),className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",children:r("work:task.openInFinder")})]}):t.jsx(Ql,{content:c.content,format:c.type==="text"?"text":c.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function Ya({task:e,agents:n,projects:s,requirements:r,allTasks:i,users:o,onClose:a,onRefresh:c,authUser:l,scrollToComments:d,onScrollToCommentsDone:h,onReqClick:f,onProjectClick:m}){const{t:u}=We(["work","common"]),p=g.useMemo(()=>bl(u),[u]),[M,C]=g.useState([]),[y,v]=g.useState(""),[x,b]=g.useState(!1),[k,N]=g.useState(!1),[I,B]=g.useState(null),[D,L]=g.useState(null),[E,P]=g.useState(!1),[z,j]=g.useState(!1),[O,_]=g.useState(!1),[T,R]=g.useState("every"),[A,q]=g.useState(""),[Y,F]=g.useState(""),[Q,$]=g.useState(""),[S,V]=g.useState(!1),[W,H]=g.useState("details"),Z=g.useRef(null),[J,le]=g.useState("none"),te=g.useCallback(G=>{H(G),requestAnimationFrame(()=>{Z.current?.scrollTo({top:0,behavior:"instant"})})},[]),X=g.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),ie=_s(X,W,te);g.useEffect(()=>{const G=Z.current;if(!G)return;const pe=()=>{const{scrollTop:Me,scrollHeight:Se,clientHeight:lt}=G;if(!(Se>lt+50)){le("none");return}const Mt=Me<30,tn=Me+lt>=Se-30;le(Mt?"top":tn?"bottom":"middle")};pe(),G.addEventListener("scroll",pe,{passive:!0});const Ne=new ResizeObserver(pe);return Ne.observe(G),()=>{G.removeEventListener("scroll",pe),Ne.disconnect()}},[W]),g.useEffect(()=>{if(!d)return;H("details");const G=setTimeout(()=>{const pe=Z.current;pe&&pe.scrollTo({top:pe.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(G)},[d,h]);const[de,se]=g.useState(null),[me,ue]=g.useState(!1),[K,ce]=g.useState(null),[ge,ve]=g.useState(!1),[fe,re]=g.useState(e.description),xe=g.useRef(null),Ee=g.useRef(null),ye=g.useRef(80);g.useEffect(()=>{if(ge&&Ee.current){const G=Ee.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,ye.current)+"px",G.focus()}},[ge]);const[Ie,pt]=g.useState(!1),[rt,Nt]=g.useState(""),[Ct,st]=g.useState(1),[Ht,xt]=g.useState([]),Jt=g.useCallback(async()=>{try{const{results:G}=await ae.deliverables.search({taskId:e.id,limit:200});xt(G.filter(pe=>pe.status!=="outdated"))}catch{}},[e.id]);g.useEffect(()=>{Jt()},[Jt]);const[bt,yt]=g.useState(!1),Ce=vr(),Xe=20,$e=g.useCallback(async()=>{try{const G=await ae.tasks.listSubtasks(e.id);C(G.subtasks)}catch{}},[e.id]);g.useEffect(()=>{$e()},[$e]);const Le=async G=>{if(!S){V(!0);try{await G(),c(),await $e()}catch(pe){se(String(pe).replace("Error: ",""))}finally{V(!1)}}},et=G=>Le(()=>ae.tasks.update(e.id,{priority:G})),qt=G=>Le(()=>ae.tasks.assign(e.id,G||null)),Wt=G=>Le(()=>ae.tasks.update(e.id,{projectId:G||null})),_e=async()=>{if(!S){V(!0);try{await ae.tasks.pause(e.id),c()}finally{V(!1)}}},Ye=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.resume(e.id),c()}catch(G){se(String(G).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{V(!1)}}},tt=async()=>{y.trim()&&(await ae.tasks.createSubtask(e.id,y.trim()),v(""),b(!1),$e(),c())},un=async G=>{G.status==="completed"||G.status==="cancelled"?await ae.tasks.cancelSubtask(e.id,G.id):await ae.tasks.completeSubtask(e.id,G.id),$e(),c()},Mn=async G=>{await ae.tasks.deleteSubtask(e.id,G.id),B(null),$e(),c()},Ge=async()=>{if(!S){V(!0);try{await ae.tasks.updateStatus(e.id,"in_progress"),c()}finally{V(!1)}}},Ae=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.retry(e.id),c()}catch(G){se(String(G).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{V(!1)}}},ze=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.runNow(e.id),c()}catch(G){se(String(G).replace("Error: API error: 400","Server error").replace("Error: ","")),c()}finally{V(!1)}}},De=g.useRef(c);De.current=c,g.useEffect(()=>jt.on("task:update",pe=>{pe.payload.taskId===e.id&&($e(),De.current())}),[e.id,$e]);const He=M.filter(G=>G.status==="completed").length,dt=M.filter(G=>G.status==="cancelled").length,Qe=He+dt,it=e.status==="in_progress",ut=e.status==="blocked",en=ut&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(G=>{const pe=i.find(Ne=>Ne.id===G);return pe&&pe.status==="completed"})),Vt=e.status==="completed",St=e.status==="failed",Et=e.status==="rejected",Je=e.status==="cancelled",ft=e.status==="archived",fn=Vt||St||Et||Je||ft,ot=e.taskType==="scheduled"&&!!e.scheduleConfig,$t=ot&&!!e.scheduleConfig?.paused,vt=(()=>{const G=s.find(pe=>pe.id===e.projectId);return G&&G.name!=="default"?G:void 0})(),ht=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:[Ce&&t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("h3",{className:"flex-1 min-w-0 text-base font-semibold leading-snug text-fg-primary",children:[e.title," ",(()=>{const G=p[e.status];return G?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${G.cls}`,children:G.label}):t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium bg-gray-500/15 text-fg-tertiary whitespace-nowrap align-middle",children:e.status.replace(/_/g," ")})})(),en&&t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle bg-red-500/15 text-red-500",children:u("work:task.abnormalBlock")})]})]}),t.jsx("button",{onClick:a,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),t.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[t.jsx("button",{onClick:()=>te("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${W==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:u("work:task.detailsTab")}),t.jsxs("button",{onClick:()=>te("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${W==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("work:task.executionLogTab"),it&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsx("button",{onClick:()=>te("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${W==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const G=Ht.filter(pe=>typeof pe.reference=="string"&&pe.reference.length>0).length;return G>0?u("work:task.deliverablesCount",{count:G}):u("work:task.deliverables")})()}),t.jsx("button",{onClick:()=>te("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${W==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:u("work:task.historyTab")})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:Z,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:ie.onTouchStart,onTouchEnd:ie.onTouchEnd,children:[t.jsxs("div",{className:W==="logs"?"min-w-0 min-h-full":"hidden",children:[de&&t.jsxs("div",{className:"mx-4 mt-3 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:[t.jsx("span",{className:"font-medium",children:u("work:task.failedToStart")})," ",de]}),t.jsx(Hh,{task:e,isRunning:e.status==="in_progress",authUser:l,agents:n})]}),t.jsxs("div",{className:W==="details"?"":"hidden",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:ge?t.jsx("textarea",{ref:Ee,value:fe,onChange:G=>{re(G.target.value);const pe=G.target;pe.style.height="auto",pe.style.height=pe.scrollHeight+"px"},onBlur:()=>{fe!==e.description&&Le(()=>ae.tasks.update(e.id,{description:fe})),ve(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),re(e.description),ve(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:u("work:task.addDescription")}):t.jsx("div",{ref:xe,className:"group relative cursor-pointer rounded-lg -mx-2 px-2 -my-1 py-1 hover:bg-surface-elevated/50 transition-colors",onClick:G=>{G.target.closest("a, button, [data-entity-link]")||(ye.current=Math.max(xe.current?.offsetHeight??80,60),re(e.description),ve(!0))},role:"button",tabIndex:0,onKeyDown:G=>G.key==="Enter"&&(re(e.description),ve(!0)),children:e.description?t.jsxs("div",{children:[t.jsx("div",{className:Ce&&!bt?"line-clamp-3":"",children:t.jsx(fr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),Ce&&e.description.length>150&&t.jsx("button",{onClick:G=>{G.stopPropagation(),yt(!bt)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:u(bt?"work:task.collapse":"common:showMore")})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:u("work:task.noDescription")})})}),(vt||ht)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[vt&&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(vt.id):void 0,role:m?"button":void 0,tabIndex:m?0:void 0,onKeyDown:m?G=>G.key==="Enter"&&m(vt.id):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.projectLabel")}),vt.name]}),ht&&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(ht):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?G=>G.key==="Enter"&&f(ht):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.requirementLabel")}),ht.title.length>40?ht.title.slice(0,40)+"…":ht.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 pe=i.find(Me=>Me.id===G),Ne=pe&&(pe.status==="completed"||pe.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Ne?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:Ne?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${Ne?"line-through opacity-60":""}`,children:pe?pe.title.slice(0,30):G.slice(-8)}),!fn&&t.jsx("button",{onClick:async()=>{const Me=(e.blockedBy??[]).filter(Se=>Se!==G);await ae.tasks.update(e.id,{blockedBy:Me}),c()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:u("work:task.removeDependency"),children:"×"})]},G)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:u("work:task.noDependencies")}),en&&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")})]}),!fn&&t.jsx(Th,{options:i.filter(G=>G.id!==e.id&&!(e.blockedBy??[]).includes(G.id)).map(G=>({value:G.id,label:G.title,status:G.status})),placeholder:u("work:task.addDependency"),noMatchesText:u("work:task.noMatches"),itemSuffix:G=>G.status==="completed"||G.status==="archived"?t.jsx("span",{className:"text-[9px] text-green-600 shrink-0",children:"✓"}):G.status==="cancelled"?t.jsx("span",{className:"text-[9px] text-fg-tertiary shrink-0",children:"✕"}):null,onSelect:async G=>{if(!G)return;const pe=[...e.blockedBy??[],G];await ae.tasks.update(e.id,{blockedBy:pe}),c()}})]}),t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.projectLabel")}),t.jsxs("select",{value:e.projectId??"",onChange:G=>{Wt(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.noProject")}),s.map(G=>t.jsx("option",{value:G.id,children:G.name},G.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.requirementLabel")}),t.jsxs("select",{value:e.requirementId??"",onChange:G=>Le(()=>ae.tasks.update(e.id,{requirementId:G.target.value||null})),disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.noRequirement")}),r.filter(G=>!e.projectId||G.projectId===e.projectId).map(G=>t.jsx("option",{value:G.id,children:G.title},G.id))]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.assignee")}),t.jsxs("select",{value:e.assignedAgentId??"",onChange:G=>{qt(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.unassigned")}),n.map(G=>t.jsxs("option",{value:G.id,children:[G.name," (",G.status,")"]},G.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.reviewer")}),t.jsxs("select",{value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:G=>{const pe=G.target.value;if(!pe)return;const Ne=pe.startsWith("human:"),Me=pe.replace(/^(human|agent):/,"");(Me!==e.reviewerId||(Ne?"human":"agent")!==(e.reviewerType??"agent"))&&Le(()=>ae.tasks.update(e.id,{reviewerId:Me,reviewerType:Ne?"human":"agent"}))},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[o.map(G=>t.jsx("option",{value:`human:${G.id}`,children:G.name},`human:${G.id}`)),n.map(G=>t.jsx("option",{value:`agent:${G.id}`,children:G.name},`agent:${G.id}`))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.priority")}),t.jsxs("select",{value:e.priority,onChange:G=>{et(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"low",children:u("work:priority.low")}),t.jsx("option",{value:"medium",children:u("work:priority.medium")}),t.jsx("option",{value:"high",children:u("work:priority.high")}),t.jsx("option",{value:"urgent",children:u("work:priority.urgent")})]})]})]})]}),t.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&t.jsx("span",{children:u("work:task.createdBy",{name:Qn(e.createdBy,n,o)??e.createdBy})}),e.updatedBy&&t.jsx("span",{children:u("work:task.updatedBy",{name:Qn(e.updatedBy,n,o)??e.updatedBy})}),e.createdAt&&t.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&t.jsx("span",{children:u("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&t.jsx("span",{children:u("work:task.updatedMeta",{date:new Date(e.updatedAt).toLocaleDateString()})}),e.projectId&&t.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&t.jsx("span",{className:"text-amber-600",children:u("work:task.executionRound",{n:e.executionRound})})]}),t.jsxs("div",{className:"px-6 py-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:[u("work:task.subtasks")," ",M.length>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[u("work:task.subtasksProgress",{done:He,total:M.length-dt}),dt>0?` · ${dt} cancelled`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[Qe>0&&t.jsx("button",{onClick:()=>N(G=>!G),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${k?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:k?u("work:task.hideCompleted"):u("work:task.showCompleted",{count:Qe})}),t.jsx("button",{onClick:()=>b(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:u("work:task.addSubtask")})]})]}),(()=>{const G=k?M:M.filter(pe=>pe.status!=="completed"&&pe.status!=="cancelled");return G.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:G.map(pe=>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 ${pe.status==="cancelled"?"opacity-50":""}`,children:[t.jsxs("button",{onClick:()=>{un(pe)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${pe.status==="completed"?"bg-green-600 border-green-600 text-white":pe.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[pe.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"})}),pe.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 ${pe.status==="completed"?"line-through text-fg-tertiary":pe.status==="cancelled"?"line-through text-fg-quaternary":"text-fg-secondary"}`,children:pe.title}),t.jsx("button",{onClick:()=>B(pe),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},pe.id))}):null})(),M.length===0&&!x&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:u("work:task.noSubtasksYet")}),x&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:y,onChange:G=>v(G.target.value),onKeyDown:G=>{G.key==="Enter"&&tt(),G.key==="Escape"&&(b(!1),v(""))},placeholder:u("work:task.subtaskTitlePlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{onClick:()=>{tt()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:u("work:task.add")}),t.jsx("button",{onClick:()=>{b(!1),v("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:u("common:cancel")})]}),(()=>{const G=Ht.filter(Me=>typeof Me.reference=="string"&&Me.reference.length>0);if(G.length===0)return null;const pe={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"},Ne=G.slice(0,3);return t.jsxs("div",{className:"mt-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:u("work:task.deliverablesCount",{count:G.length})}),G.length>3&&t.jsx("button",{onClick:()=>te("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:u("work:task.viewAll")})]}),t.jsx("div",{className:"space-y-1.5",children:Ne.map(Me=>{const Se=/^https?:\/\//i.test(Me.reference),lt=Se?Me.summary||Me.reference:Me.reference.split("/").pop()??Me.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${pe[Me.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Me.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Se?t.jsxs("a",{href:Me.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Me.reference,children:[lt," ",t.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),t.jsx("path",{d:"M7 2h3v3"}),t.jsx("path",{d:"M5 7 10 2"})]})]}):t.jsx("button",{onClick:()=>ce(Me.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Me.reference,children:lt}),Me.summary&&!Se&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Me.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Me.reference})]})]},Me.id)})})]})})(),t.jsx(zh,{task:e,agents:n,users:o,authUser:l})]})]}),t.jsx("div",{className:W==="history"?"":"hidden",children:t.jsx(kl,{entityType:"task",entityId:e.id})}),t.jsx("div",{className:W==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const G=Ht.filter(Se=>typeof Se.reference=="string"&&Se.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 pe={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"},Ne=Math.ceil(G.length/Xe),Me=G.slice((Ct-1)*Xe,Ct*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})}),Ne>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:Ct<=1,onClick:()=>st(Se=>Se-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[Ct,"/",Ne]}),t.jsx("button",{disabled:Ct>=Ne,onClick:()=>st(Se=>Se+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),t.jsx("div",{className:"space-y-1.5",children:Me.map(Se=>{const lt=/^https?:\/\//i.test(Se.reference),Ft=lt?Se.summary||Se.reference:Se.reference.split("/").pop()??Se.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 ${pe[Se.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Se.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[lt?t.jsxs("a",{href:Se.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:Se.reference,children:[Ft," ",t.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),t.jsx("path",{d:"M7 2h3v3"}),t.jsx("path",{d:"M5 7 10 2"})]})]}):t.jsx("button",{onClick:()=>ce(Se.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Se.reference,children:Ft}),Se.summary&&!lt&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Se.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Se.reference})]})]},Se.id)})})]})})()})]}),J!=="none"&&J!=="top"&&t.jsx("button",{onClick:()=>Z.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-36 right-4 md:bottom-28 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:u("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),J!=="none"&&J!=="bottom"&&t.jsx("button",{onClick:()=>{const G=Z.current;G&&G.scrollTo({top:G.scrollHeight,behavior:"smooth"})},className:"absolute bottom-22 right-4 md:bottom-18 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:u("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),ot&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${$t?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!it&&!O&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{it||O||e.scheduleConfig?.runAt||(R(e.scheduleConfig?.cron?"cron":"every"),q(e.scheduleConfig?.every??"4h"),F(e.scheduleConfig?.cron??""),$(e.scheduleConfig?.maxRuns&&e.scheduleConfig.maxRuns>0?String(e.scheduleConfig.maxRuns):""),_(!0))},children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:$t?"text-amber-600":"text-brand-500",children:$t?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")}),!$t&&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 pe=Math.floor(G/6e4);if(pe<60)return u("work:task.scheduleInMinutes",{count:pe});const Ne=Math.floor(pe/60);return Ne<24?u("work:task.scheduleInHoursMinutes",{h:Ne,m:pe%60}):u("work:task.scheduleInDaysHours",{d:Math.floor(Ne/24),h:Ne%24})})()})})]}),!it&&!O&&!e.scheduleConfig.runAt&&t.jsxs("svg",{className:"w-3 h-3 text-brand-500 ml-auto shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})]}),O?t.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:G=>G.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("select",{value:T,onChange:G=>R(G.target.value),className:"px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[t.jsx("option",{value:"every",children:u("work:task.scheduleEveryMode")}),t.jsx("option",{value:"cron",children:u("work:task.scheduleCronMode")})]}),T==="every"?t.jsxs("select",{value:A,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:Y,onChange:G=>F(G.target.value),placeholder:"0 9 * * 1-5",className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("label",{className:"text-fg-tertiary shrink-0",children:u("work:task.scheduleMaxRuns")}),t.jsx("input",{value:Q,onChange:G=>$(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=A:G.cron=Y.trim(),Q&&(G.maxRuns=parseInt(Q,10)),await Le(()=>ae.tasks.updateSchedule(e.id,G)),_(!1)},disabled:S,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:u("common:save")}),t.jsx("button",{onClick:()=>_(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:u("common:cancel")})]})]}):t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[t.jsx("span",{children:u("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?u("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:u("work:task.scheduleLast",{when:(()=>{const G=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),pe=Math.floor(G/6e4);if(pe<1)return u("work:task.noteTimeJustNow");if(pe<60)return u("work:task.noteTimeMinutes",{count:pe});const Ne=Math.floor(pe/60);return Ne<24?u("work:task.noteTimeHours",{count:Ne}):u("work:task.noteTimeDays",{count:Math.floor(Ne/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(ot){ue(!0);return}Le(()=>ae.tasks.approve(e.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:e.createdBy&&!e.createdBy.startsWith("agt_")?u("work:task.startExecution"):u("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?t.jsx("button",{onClick:async()=>{const{count:G}=await ae.tasks.getDependentCount(e.id);L({dependentCount:G})},disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")}):t.jsx("button",{onClick:()=>P(!0),disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.reject")})]}),e.status==="review"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{Le(()=>ae.tasks.accept(e.id,l?.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.approveCheck")}),Ie?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:rt,onChange:G=>Nt(G.target.value),onKeyDown:G=>{G.key==="Enter"&&rt.trim()&&(Le(()=>ae.tasks.revision(e.id,rt.trim(),l?.id)),pt(!1),Nt(""))},placeholder:u("work:task.revisionReasonPlaceholder"),autoFocus:!0,className:"px-2 py-1 text-xs bg-surface-elevated border border-amber-500/40 rounded-lg text-fg-primary focus:border-amber-400 outline-none w-48"}),t.jsx("button",{onClick:()=>{Le(()=>ae.tasks.revision(e.id,rt.trim()||u("work:task.revisionsNeededDefault"),l?.id)),pt(!1),Nt("")},disabled:S,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:u("common:send")}),t.jsx("button",{onClick:()=>{pt(!1),Nt("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>pt(!0),disabled:S,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.requestRevision")})]}),it&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{_e()},disabled:S,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[t.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),t.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),u("work:task.pause")]}),t.jsxs("button",{onClick:()=>{Ae()},disabled:S,className:"px-3 py-1.5 text-xs border border-blue-500/30 text-blue-600 rounded-lg hover:bg-blue-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),u("work:task.retry")]})]}),ut&&t.jsx("button",{onClick:()=>{Ye()},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:S?t.jsx(t.Fragment,{children:u("work:task.resuming")}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.resume")]})}),St&&!ot&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{Ae()},disabled:S,className:"px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),u("work:task.retry")]}),t.jsxs("button",{onClick:()=>{Ge()},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.continueTask")]})]}),ot&&(Vt||St||Je)&&!ft&&t.jsx("button",{onClick:()=>{ze()},disabled:S,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1.5",children:S?t.jsx(t.Fragment,{children:u("work:task.running")}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.runNow")]})}),ot&&!it&&!ft&&!Et&&($t?t.jsx("button",{onClick:()=>{Le(()=>ae.tasks.resumeSchedule(e.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.resumeSchedule")}):t.jsx("button",{onClick:()=>{Le(()=>ae.tasks.pauseSchedule(e.id))},disabled:S,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50",children:u("work:task.pauseSchedule")})),(Vt||St||Et||Je)&&t.jsx("button",{onClick:()=>j(!0),disabled:S,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.archive")}),Vt&&!ot&&t.jsx("button",{onClick:()=>{Ge()},disabled:S,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary disabled:opacity-50",children:u("work:task.reopen")}),!fn&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:G}=await ae.tasks.getDependentCount(e.id);L({dependentCount:G})},disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")})]})}),I&&t.jsx(Hn,{title:u("work:task.deleteSubtaskTitle",{title:I.title}),message:u("work:task.deleteSubtaskMessage"),confirmLabel:u("common:delete"),onConfirm:()=>{Mn(I)},onCancel:()=>B(null)}),E&&t.jsx(Hn,{title:u("work:task.rejectConfirmTitle"),message:u("work:task.rejectConfirmMessage"),confirmLabel:u("work:task.reject"),onConfirm:()=>{P(!1),Le(()=>ae.tasks.reject(e.id))},onCancel:()=>P(!1)}),z&&t.jsx(Hn,{title:u("work:task.archiveConfirmTitle"),message:u(ot?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:u("work:task.archive"),onConfirm:()=>{j(!1),Le(()=>ae.tasks.archive(e.id))},onCancel:()=>j(!1)}),D&&D.dependentCount>0?t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>L(null),children:t.jsxs("div",{className:"bg-surface-default border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:G=>G.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:u("work:task.cancelTaskModalTitle")}),t.jsxs("p",{className:"text-sm text-fg-secondary mb-4",children:[ot&&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:D.dependentCount})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("button",{onClick:()=>{L(null),Le(()=>ae.tasks.cancel(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-surface-elevated border border-border-default rounded-lg hover:bg-surface-overlay text-fg-primary text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelTaskOnly")}),t.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:u("work:task.cancelTaskOnlyHint")})]}),t.jsxs("button",{onClick:()=>{L(null),Le(()=>ae.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelWithDependents")}),t.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:u("work:task.cancelWithDependentsHint",{count:D.dependentCount})})]}),t.jsx("button",{onClick:()=>L(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("work:task.keepTaskRunning")})]})]})}):D&&t.jsx(Hn,{title:u("work:task.cancelTaskModalTitle"),message:u(ot?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:u("work:task.cancelTask"),onConfirm:()=>{L(null),Le(()=>ae.tasks.cancel(e.id))},onCancel:()=>L(null)}),K&&t.jsx(qh,{filePath:K,onClose:()=>ce(null),onOpenExternal:()=>{ce(null),ae.deliverables.search({taskId:e.id,limit:100}).then(({results:G})=>{const pe=G.find(Ne=>Ne.reference===K);pe?Bt.navigate(Fe.DELIVERABLES,{openDeliverable:pe.id}):Bt.navigate(Fe.DELIVERABLES)}).catch(()=>Bt.navigate(Fe.DELIVERABLES))}}),me&&e.scheduleConfig&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>ue(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:G=>G.stopPropagation(),children:[t.jsx("h3",{className:"font-semibold text-base mb-2",children:u("work:task.scheduleApproveTitle")}),t.jsx("p",{className:"text-sm text-fg-secondary mb-5 leading-relaxed",children:u("work:task.scheduleApproveDesc",{schedule:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.every?u("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):"",nextRun:e.scheduleConfig.nextRunAt?new Date(e.scheduleConfig.nextRunAt).toLocaleString():u("work:task.scheduleNA")})}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("button",{disabled:S,onClick:()=>{ue(!1),Le(()=>ae.tasks.approve(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-green-600 hover:bg-green-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveRunNow")}),t.jsx("button",{disabled:S,onClick:()=>{ue(!1),Le(()=>ae.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveWait")}),t.jsx("button",{onClick:()=>ue(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("common:cancel")})]})]})})]})}function Wh({project:e,tasks:n,requirements:s,agents:r,onDeleteProject:i,onUpdateProject:o,onRefresh:a}){const c=g.useMemo(()=>n.filter(E=>E.projectId===e.id),[n,e.id]),l=g.useMemo(()=>s.filter(E=>E.projectId===e.id),[s,e.id]),d=g.useMemo(()=>{const E={total:c.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:l.length,reqsDone:0};for(const P of c)P.status==="completed"||P.status==="accepted"?E.completed++:P.status==="in_progress"?E.inProgress++:P.status==="review"||P.status==="revision"?E.inReview++:P.status==="blocked"?E.blocked++:P.status==="failed"?E.failed++:E.pending++;for(const P of l)P.status==="completed"&&E.reqsDone++;return E},[c,l]),h=g.useMemo(()=>new Set(c.map(E=>E.assignedAgentId).filter(Boolean)),[c]),f=g.useMemo(()=>r.filter(E=>h.has(E.id)),[r,h]),[m,u]=g.useState(!1),[p,M]=g.useState(""),[C,y]=g.useState("main"),[v,x]=g.useState(!1),[b,k]=g.useState(!1),{t:N}=We(["work","common"]),I=[{value:"active",label:N("work:project.statusActive"),desc:N("work:project.statusActiveDesc")},{value:"paused",label:N("work:project.statusPaused"),desc:N("work:project.statusPausedDesc")},{value:"archived",label:N("work:project.statusArchived"),desc:N("work:project.statusArchivedDesc")}],B=async E=>{if(E!==e.status){x(!0);try{await o({status:E}),a()}finally{x(!1)}}},D=async()=>{const E=p.trim();if(!E)return;const P=[...e.repositories??[],{url:"",localPath:E,defaultBranch:C||"main"}];await o({repositories:P}),M(""),y("main"),u(!1),a()},L=async E=>{const P=(e.repositories??[]).filter((z,j)=>j!==E);await o({repositories:P}),a()};return t.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx(_h,{value:e.description??"",onSave:async E=>{await o({description:E}),a()},className:"text-sm text-fg-secondary",placeholder:N("work:project.descriptionPlaceholderLong")}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&t.jsxs("span",{children:[N("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:[N("work:project.updatedLabel")," ",new Date(e.updatedAt).toLocaleDateString()]})]})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:N("work:project.projectStatusHeading")}),t.jsx("div",{className:"flex gap-2",children:I.map(E=>t.jsxs("button",{disabled:v,onClick:()=>B(E.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===E.value?E.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":E.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${v?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:E.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:E.desc})]},E.value))})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:N("work:project.taskOverview")}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(Ut,{label:N("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),t.jsx(Ut,{label:N("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),t.jsx(Ut,{label:N("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),t.jsx(Ut,{label:N("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),t.jsx(Ut,{label:N("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),t.jsx(Ut,{label:N("work:project.statFailed"),value:d.failed,color:"text-red-500"})]}),d.total>0&&t.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[d.completed>0&&t.jsx("div",{className:"bg-green-500",style:{width:`${d.completed/d.total*100}%`}}),d.inProgress>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${d.inProgress/d.total*100}%`}}),d.inReview>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${d.inReview/d.total*100}%`}}),d.blocked>0&&t.jsx("div",{className:"bg-amber-500",style:{width:`${d.blocked/d.total*100}%`}}),d.pending>0&&t.jsx("div",{className:"bg-blue-500/40",style:{width:`${d.pending/d.total*100}%`}}),d.failed>0&&t.jsx("div",{className:"bg-red-500",style:{width:`${d.failed/d.total*100}%`}})]})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:N("work:project.requirementsHeading")}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(Ut,{label:N("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),t.jsx(Ut,{label:N("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),t.jsx(Ut,{label:N("work:project.statActive"),value:d.reqs-d.reqsDone,color:"text-brand-500"})]})]}),f.length>0&&t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:N("work:project.agentsHeading",{count:f.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(E=>{const P=c.filter(j=>j.assignedAgentId===E.id),z=P.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 ${E.status==="working"?"bg-blue-500":E.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:E.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:N("work:project.agentTaskCounts",{active:z.length,total:P.length})})]},E.id)})})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:N("work:project.repositories")}),t.jsx("button",{onClick:()=>u(!m),className:"text-[10px] text-brand-500 hover:text-brand-500",children:N(m?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!m&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:N("work:project.noReposLinked")}),(e.repositories??[]).map((E,P)=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:[t.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),t.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate",children:E.url||E.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:E.defaultBranch}),t.jsx("button",{onClick:()=>L(P),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:N("work:project.removeRepo"),children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},P)),m&&t.jsxs("div",{className:"mt-2 space-y-2 p-3 bg-surface-elevated rounded-lg border border-border-default",children:[t.jsx("input",{value:p,onChange:E=>M(E.target.value),placeholder:N("work:project.repoPathPlaceholder"),className:"w-full px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:C,onChange:E=>y(E.target.value),placeholder:N("work:project.repoBranchPlaceholder"),className:"flex-1 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsx("button",{onClick:D,disabled:!p.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:N("work:task.add")})]})]})]}),t.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:N("work:project.dangerZone")}),t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:N("work:project.dangerZoneDeleteHint")}),t.jsx("button",{onClick:()=>k(!0),className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 hover:bg-red-500/10 rounded-lg transition-colors",children:N("work:project.deleteProject")})]}),b&&t.jsx(Hn,{title:N("work:project.deleteProjectConfirmTitle"),message:N("work:project.deleteProjectConfirmBody",{name:e.name,tasks:d.total,reqs:d.reqs}),confirmLabel:N("work:project.deleteProject"),onConfirm:()=>{k(!1),i()},onCancel:()=>k(!1)})]})}function Ut({label:e,value:n,color:s}){return t.jsxs("div",{className:"text-center py-2",children:[t.jsx("div",{className:`text-xl font-bold ${s}`,children:n}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const Jr={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},vl={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Vh={urgent:0,high:1,medium:2,low:3},os={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Ga={failed:"border-l-red-500 bg-red-500/5",todo:"border-l-blue-500 bg-blue-500/5",in_progress:"border-l-brand-500 bg-brand-500/5",review:"border-l-purple-500 bg-brand-500/5",done:"border-l-green-500 bg-green-500/5",closed:"border-l-gray-500 bg-gray-500/5"},Fh={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"},Yh=["pending","in_progress","completed","rejected","cancelled","archived"];function wl(e){for(const n of ss)if(n.statuses.includes(e))return n.id;return"closed"}function Ka(e,n){const s=Date.now()-new Date(e).getTime(),r=Math.floor(s/6e4);if(r<1)return n("work:relative.justNow");if(r<60)return n("work:relative.minutesAgo",{count:r});const i=Math.floor(r/60);if(i<24)return n("work:relative.hoursAgo",{count:i});const o=Math.floor(i/24);return n("work:relative.daysAgo",{count:o})}function Kr({value:e,options:n,onSelect:s,allowedValues:r}){const[i,o]=g.useState(!1),a=g.useRef(null),c=g.useRef(null),l=n.find(d=>d.value===e);return g.useEffect(()=>{if(!i)return;const d=h=>{c.current&&!c.current.contains(h.target)&&a.current&&!a.current.contains(h.target)&&o(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[i]),t.jsxs("div",{className:"relative",children:[t.jsx("button",{ref:a,onClick:()=>o(d=>!d),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${l?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:l?.label??e}),i&&t.jsx("div",{ref:c,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:n.map(d=>{const h=d.value===e,f=h||!r||r.has(d.value);return t.jsxs("button",{disabled:!f,onClick:()=>{!h&&f&&s(d.value),o(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${h?"bg-surface-elevated":f?"hover:bg-surface-elevated/60":"opacity-35 cursor-not-allowed"}`,children:[t.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 ${f?d.cls.split(" ")[0]:"bg-gray-600"}`}),t.jsx("span",{className:`font-medium ${h?"text-fg-primary":f?"text-fg-secondary":"text-fg-muted"}`,children:d.label}),h&&t.jsx("svg",{className:"w-3 h-3 ml-auto text-brand-500",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},d.value)})})]})}function Za({row:e,idx:n,dragIdx:s,agentMap:r,projMap:i,onTaskClick:o,onReqClick:a,onRowDragStart:c,onRowDragEnd:l,handleStatusChange:d,handlePriorityChange:h,selected:f,isMobile:m,isAbnormalBlocked:u}){const{t:p}=We(["work","common"]),M=g.useMemo(()=>bl(p),[p]),C=g.useMemo(()=>io(p),[p]),y=g.useMemo(()=>Oh(p),[p]),v=e.data.status,x=e.data.priority,b=e.kind==="task"?r.get(e.data.assignedAgentId??""):void 0,k=(()=>{const I=i.get((e.kind==="task",e.data.projectId??""));return I&&I.name!=="default"?I:void 0})(),N=e.kind==="req"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:p("work:task.requirementShort")}):e.data.taskType==="scheduled"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600",children:p("work:task.schedShort")}):t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:p("work:task.taskShort")});return m?t.jsxs("div",{"data-work-item-id":e.data.id,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`px-3 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${Ga[e.group]??"border-l-gray-700"} ${f?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35":"active:bg-surface-elevated/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[N,u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500",children:"⚠"}),t.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsx("div",{onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:v,options:e.kind==="task"?Ha.map(I=>({value:I,label:M[I]?.label??I,cls:M[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):qa.map(I=>({value:I,label:C[I]?.label??I,cls:C[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Wa[v]:qs[v],onSelect:I=>{d(e,I)}})}),t.jsx("div",{onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:x,options:za.map(I=>({value:I,label:y[I]?.label??I,cls:y[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:I=>{h(e,I)}})}),b&&t.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`${Va[b.status]??"text-fg-secondary"}`,children:b.name})]}),k?.name&&t.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:k.name}),t.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:Ka(e.data.updatedAt??"",p)})]})]}):t.jsxs("div",{"data-work-item-id":e.data.id,draggable:!0,onDragStart:I=>c(I,n),onDragEnd:l,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${Ga[e.group]??"border-l-gray-700"} ${s===n?"opacity-40":""} ${f?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35 hover:bg-brand-500/30":"hover:bg-surface-elevated/50"}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:N}),t.jsxs("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate",children:e.data.title}),u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500 shrink-0",children:"⚠"})]}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:v,options:e.kind==="task"?Ha.map(I=>({value:I,label:M[I]?.label??I,cls:M[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):qa.map(I=>({value:I,label:C[I]?.label??I,cls:C[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Wa[v]:qs[v],onSelect:I=>{d(e,I)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:x,options:za.map(I=>({value:I,label:y[I]?.label??I,cls:y[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:I=>{h(e,I)}})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:b?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`font-medium ${Va[b.status]??"text-fg-secondary"}`,children:b.name})]}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:k?.name?t.jsx("span",{className:"text-brand-400/70",children:k.name}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-muted text-right",children:Ka(e.data.updatedAt??"",p)})]})}function Gh({tasks:e,requirements:n,agents:s,projects:r,onTaskClick:i,onReqClick:o,onRefresh:a,selectedTaskId:c,selectedReqId:l}){const{t:d}=We(["work","common"]),h=vr(),[f,m]=g.useState("status"),[u,p]=g.useState(null),[M,C]=g.useState(null),y=g.useMemo(()=>{const T=new Map;for(const R of e)T.set(R.id,R);return T},[e]),v=g.useCallback(T=>T.status!=="blocked"?!1:!T.blockedBy||T.blockedBy.length===0?!0:T.blockedBy.every(R=>{const A=y.get(R);return A&&A.status==="completed"}),[y]),x=g.useMemo(()=>{const T=[];for(const R of e){const A=wl(R.status);T.push({kind:"task",data:R,group:A,groupOrder:os[A]??5})}for(const R of n){const A=Jr[R.status]??"todo";T.push({kind:"req",data:R,group:A,groupOrder:os[A]??5})}if(f==="status")T.sort((R,A)=>{if(R.groupOrder!==A.groupOrder)return R.groupOrder-A.groupOrder;const q=new Date(R.data.updatedAt??0).getTime();return new Date(A.data.updatedAt??0).getTime()-q});else{const R=A=>Vh[A.data.priority]??2;T.sort((A,q)=>{const Y=R(A),F=R(q);return Y!==F?Y-F:new Date(q.data.updatedAt??0).getTime()-new Date(A.data.updatedAt??0).getTime()})}return T},[e,n,f]),b=async(T,R)=>{try{T.kind==="task"?await ae.tasks.updateStatus(T.data.id,R):await ae.requirements.updateStatus(T.data.id,R),a()}catch{}},k=async(T,R)=>{try{T.kind==="task"?await ae.tasks.update(T.data.id,{priority:R}):await ae.requirements.update(T.data.id,{priority:R}),a()}catch{}},N=(T,R)=>{p(R),T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",String(R)),T.currentTarget.style.opacity="0.4"},I=T=>{T.currentTarget.style.opacity="1",p(null),C(null)},B=(T,R)=>{T.preventDefault(),T.dataTransfer.dropEffect="move",M!==R&&C(R)},D=async(T,R)=>{if(T.preventDefault(),C(null),u==null)return;const A=x[u];if(!A||A.group===R)return;const q=ss.find(Y=>Y.id===R);if(q){try{if(A.kind==="task"){if(A.data.status==="pending")return;await ae.tasks.updateStatus(A.data.id,q.dropStatus)}else{const Y=vl[R];Y&&await ae.requirements.updateStatus(A.data.id,Y)}a()}catch{}p(null)}},L=g.useMemo(()=>new Map(s.map(T=>[T.id,T])),[s]),E=g.useMemo(()=>new Map(r.map(T=>[T.id,T])),[r]),P=["todo","in_progress","review","done"],z=g.useMemo(()=>{const T={};for(const R of x)T[R.group]=(T[R.group]??0)+1;return T},[x]),{rowsByGroup:j,rowIndexMap:O}=g.useMemo(()=>{const T=new Map,R=new Map;for(let A=0;A<x.length;A++){const q=x[A];R.set(q,A);const Y=T.get(q.group)??[];Y.push(q),T.set(q.group,Y)}return{rowsByGroup:T,rowIndexMap:R}},[x]),_=g.useMemo(()=>{if(f!=="status")return null;const T=new Set(x.map(q=>q.group)),R=[],A=new Set;T.has("failed")&&(R.push("failed"),A.add("failed"));for(const q of P)R.push(q),A.add(q);for(const q of x)A.has(q.group)||(R.push(q.group),A.add(q.group));return R},[x,f]);return t.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${h?"overflow-x-hidden w-full":""}`,children:t.jsxs("div",{className:h?"w-full":"w-fit min-w-full",children:[!h&&t.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider sticky top-0 z-20 bg-surface-primary",children:[t.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:x.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:d("work:task.backlogTitle")}),t.jsxs("button",{onClick:()=>m("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[d("work:filters.status")," ",f==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>m("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[d("work:filters.priority")," ",f==="priority"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsx("div",{className:"w-[120px] shrink-0",children:d("work:filters.assignee")}),t.jsx("div",{className:"w-[120px] shrink-0",children:d("work:task.projectLabel")}),t.jsx("div",{className:"w-[90px] shrink-0 text-right",children:d("work:task.backlogUpdated")})]}),t.jsxs("div",{children:[f==="status"&&_?_.map(T=>{const R=j.get(T)??[];return t.jsxs("div",{children:[t.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-primary/80 sticky top-0 z-10 ${Fh[T]??""} ${M===T?"ring-1 ring-brand-500/40":""}`,onDragOver:A=>B(A,T),onDragLeave:()=>C(null),onDrop:A=>{D(A,T)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:d(`work:boardColumn.${T}`)}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:z[T]??0})]}),R.map(A=>t.jsx(Za,{row:A,idx:O.get(A)??0,dragIdx:u,agentMap:L,projMap:E,onTaskClick:i,onReqClick:o,onRowDragStart:N,onRowDragEnd:I,handleStatusChange:b,handlePriorityChange:k,selected:A.kind==="task"?A.data.id===c:A.data.id===l,isMobile:h,isAbnormalBlocked:A.kind==="task"?v(A.data):!1},`${A.kind}-${A.data.id}`))]},T)}):x.map((T,R)=>t.jsx(Za,{row:T,idx:R,dragIdx:u,agentMap:L,projMap:E,onTaskClick:i,onReqClick:o,onRowDragStart:N,onRowDragEnd:I,handleStatusChange:b,handlePriorityChange:k,selected:T.kind==="task"?T.data.id===c:T.data.id===l,isMobile:h,isAbnormalBlocked:T.kind==="task"?v(T.data):!1},`${T.kind}-${T.data.id}`)),x.length===0&&t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3 max-w-sm mx-auto text-center",children:[t.jsx("svg",{className:"w-10 h-10 text-fg-quaternary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),t.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:d("work:task.backlogEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:d("work:task.backlogEmptyDesc")})]})]})]})})}function Ws(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function Kh(e,n){const s=new Map,r=new Map(e.map(c=>[c.id,c])),i=new Set;for(const c of e){let l=Ws(c.title).replace(/[^a-z0-9-]/g,"").slice(0,30)||"step";i.has(l)&&(l=`${l}-${c.id.slice(-4)}`),i.add(l),s.set(c.id,l)}const o=new Map,a=new Set;for(const c of e){const l=c.assignedAgentId;if(l&&!o.has(l)){const d=n[l]??"worker";let h=Ws(d).replace(/[^a-z0-9-]/g,"")||"worker";a.has(h)&&(h=`${h}-${l.slice(-4)}`),a.add(h),o.set(l,h)}}return e.map(c=>({id:s.get(c.id),name:c.title,role:o.get(c.assignedAgentId)??"worker",prompt:c.description||c.title,depends_on:(c.blockedBy??[]).filter(l=>r.has(l)).map(l=>s.get(l)).filter(Boolean)}))}function Zr(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function Zh(e,n,s){const r=[];r.push(`name: ${Zr(e)}`),r.push(`description: ${Zr(n.replace(/\n/g," ").slice(0,200))}`),r.push('version: "1.0.0"'),r.push(""),r.push("steps:");for(const i of s){if(r.push(` - id: ${i.id}`),r.push(` name: ${Zr(i.name)}`),r.push(" type: agent_task"),r.push(` role: ${Zr(i.role)}`),i.depends_on.length>0&&r.push(` depends_on: [${i.depends_on.join(", ")}]`),i.depends_on.length>0){r.push(" inputs:");for(const o of i.depends_on)r.push(` - from: ${o}`),r.push(` as: ${o}_output`)}r.push(" prompt: |");for(const o of i.prompt.split(`
6
+ `)),h=d.reduce((f,m)=>f.concat(...m),[]);return[d,h]}return[[],[]]},[e]);return g.useEffect(()=>{const l=n?.target??ca,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)&&bi(u))return!1;const M=ua(u.code,c);if(o.current.add(u[M]),da(a,o.current,!1)){const C=u.composedPath?.()?.[0]||u.target,y=C?.nodeName==="BUTTON"||C?.nodeName==="A";n.preventDefault!==!1&&(i.current||!y)&&u.preventDefault(),r(!0)}},f=u=>{const p=ua(u.code,c);da(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(u[p]),u.key==="Meta"&&o.current.clear(),i.current=!1},m=()=>{o.current.clear(),r(!1)};return l?.addEventListener("keydown",h),l?.addEventListener("keyup",f),window.addEventListener("blur",m),window.addEventListener("contextmenu",m),()=>{l?.removeEventListener("keydown",h),l?.removeEventListener("keyup",f),window.removeEventListener("blur",m),window.removeEventListener("contextmenu",m)}}},[e,r]),s}function da(e,n,s){return e.filter(r=>s||r.length===n.size).some(r=>r.every(i=>n.has(i)))}function ua(e,n){return n.includes(e)?"code":"key"}const qd=()=>{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:c}=e.getState(),l=Ks(n,r,i,o,a,s?.padding??.1);return c?(await c.setViewport(l,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(n,s={})=>{const{transform:r,snapGrid:i,snapToGrid:o,domNode:a}=e.getState();if(!a)return n;const{x:c,y:l}=a.getBoundingClientRect(),d={x:n.x-c,y:n.y-l},h=s.snapGrid??i,f=s.snapToGrid??o;return Nr(d,r,f,h)},flowToScreenPosition:n=>{const{transform:s,domNode:r}=e.getState();if(!r)return n;const{x:i,y:o}=r.getBoundingClientRect(),a=ts(n,s);return{x:a.x+i,y:a.y+o}}}),[])};function zi(e,n){const s=[],r=new Map,i=[];for(const o of e)if(o.type==="add"){i.push(o);continue}else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const a=r.get(o.id);a?a.push(o):r.set(o.id,[o])}for(const o of n){const a=r.get(o.id);if(!a){s.push(o);continue}if(a[0].type==="remove")continue;if(a[0].type==="replace"){s.push({...a[0].item});continue}const c={...o};for(const l of a)Wd(l,c);s.push(c)}return i.length&&i.forEach(o=>{o.index!==void 0?s.splice(o.index,0,{...o.item}):s.push({...o.item})}),s}function Wd(e,n){switch(e.type){case"select":{n.selected=e.selected;break}case"position":{typeof e.position<"u"&&(n.position=e.position),typeof e.dragging<"u"&&(n.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(n.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(n.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(n.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(n.resizing=e.resizing);break}}}function Hi(e,n){return zi(e,n)}function qi(e,n){return zi(e,n)}function Nn(e,n){return{id:e,type:"select",selected:n}}function Wn(e,n=new Set,s=!1){const r=[];for(const[i,o]of e){const a=n.has(i);!(o.selected===void 0&&!a)&&o.selected!==a&&(s&&(o.selected=a),r.push(Nn(o.id,a)))}return r}function fa({items:e=[],lookup:n}){const s=[],r=new Map(e.map(i=>[i.id,i]));for(const[i,o]of e.entries()){const a=n.get(o.id),c=a?.internals?.userNode??a;c!==void 0&&c!==o&&s.push({id:o.id,item:o,type:"replace"}),c===void 0&&s.push({item:o,type:"add",index:i})}for(const[i]of n)r.get(i)===void 0&&s.push({id:i,type:"remove"});return s}function ha(e){return{id:e.id,type:"remove"}}const ma=e=>gc(e),Vd=e=>di(e);function Wi(e){return g.forwardRef(e)}const Fd=typeof window<"u"?g.useLayoutEffect:g.useEffect;function ga(e){const[n,s]=g.useState(BigInt(0)),[r]=g.useState(()=>Yd(()=>s(i=>i+BigInt(1))));return Fd(()=>{const i=r.get();i.length&&(e(i),r.reset())},[n]),r}function Yd(e){let n=[];return{get:()=>n,reset:()=>{n=[]},push:s=>{n.push(s),e()}}}const Vi=g.createContext(null);function Gd({children:e}){const n=Be(),s=g.useCallback(c=>{const{nodes:l=[],setNodes:d,hasDefaultNodes:h,onNodesChange:f,nodeLookup:m,fitViewQueued:u,onNodesChangeMiddlewareMap:p}=n.getState();let M=l;for(const y of c)M=typeof y=="function"?y(M):y;let C=fa({items:M,lookup:m});for(const y of p.values())C=y(C);h&&d(M),C.length>0?f?.(C):u&&window.requestAnimationFrame(()=>{const{fitViewQueued:y,nodes:v,setNodes:x}=n.getState();y&&x(v)})},[]),r=ga(s),i=g.useCallback(c=>{const{edges:l=[],setEdges:d,hasDefaultEdges:h,onEdgesChange:f,edgeLookup:m}=n.getState();let u=l;for(const p of c)u=typeof p=="function"?p(u):p;h?d(u):f&&f(fa({items:u,lookup:m}))},[]),o=ga(i),a=g.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return t.jsx(Vi.Provider,{value:a,children:e})}function Kd(){const e=g.useContext(Vi);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Zd=e=>!!e.panZoom;function to(){const e=qd(),n=Be(),s=Kd(),r=Te(Zd),i=g.useMemo(()=>{const o=f=>n.getState().nodeLookup.get(f),a=f=>{s.nodeQueue.push(f)},c=f=>{s.edgeQueue.push(f)},l=f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState(),p=ma(f)?f:m.get(f.id),M=p.parentId?pi(p.position,p.measured,p.parentId,m,u):p.position,C={...p,position:M,width:p.measured?.width??p.width,height:p.measured?.height??p.height};return Zn(C)},d=(f,m,u={replace:!1})=>{a(p=>p.map(M=>{if(M.id===f){const C=typeof m=="function"?m(M):m;return u.replace&&ma(C)?C:{...M,...C}}return M}))},h=(f,m,u={replace:!1})=>{c(p=>p.map(M=>{if(M.id===f){const C=typeof m=="function"?m(M):m;return u.replace&&Vd(C)?C:{...M,...C}}return M}))};return{getNodes:()=>n.getState().nodes.map(f=>({...f})),getNode:f=>o(f)?.internals.userNode,getInternalNode:o,getEdges:()=>{const{edges:f=[]}=n.getState();return f.map(m=>({...m}))},getEdge:f=>n.getState().edgeLookup.get(f),setNodes:a,setEdges:c,addNodes:f=>{const m=Array.isArray(f)?f:[f];s.nodeQueue.push(u=>[...u,...m])},addEdges:f=>{const m=Array.isArray(f)?f:[f];s.edgeQueue.push(u=>[...u,...m])},toObject:()=>{const{nodes:f=[],edges:m=[],transform:u}=n.getState(),[p,M,C]=u;return{nodes:f.map(y=>({...y})),edges:m.map(y=>({...y})),viewport:{x:p,y:M,zoom:C}}},deleteElements:async({nodes:f=[],edges:m=[]})=>{const{nodes:u,edges:p,onNodesDelete:M,onEdgesDelete:C,triggerNodeChanges:y,triggerEdgeChanges:v,onDelete:x,onBeforeDelete:b}=n.getState(),{nodes:k,edges:N}=await vc({nodesToRemove:f,edgesToRemove:m,nodes:u,edges:p,onBeforeDelete:b}),I=N.length>0,B=k.length>0;if(I){const D=N.map(ha);C?.(N),v(D)}if(B){const D=k.map(ha);M?.(k),y(D)}return(B||I)&&x?.({nodes:k,edges:N}),{deletedNodes:k,deletedEdges:N}},getIntersectingNodes:(f,m=!0,u)=>{const p=qo(f),M=p?f:l(f),C=u!==void 0;return M?(u||n.getState().nodes).filter(y=>{const v=n.getState().nodeLookup.get(y.id);if(v&&!p&&(y.id===f.id||!v.internals.positionAbsolute))return!1;const x=Zn(C?y:v),b=pr(x,M);return m&&b>0||b>=x.width*x.height||b>=M.width*M.height}):[]},isNodeIntersecting:(f,m,u=!0)=>{const M=qo(f)?f:l(f);if(!M)return!1;const C=pr(M,m);return u&&C>0||C>=m.width*m.height||C>=M.width*M.height},updateNode:d,updateNodeData:(f,m,u={replace:!1})=>{d(f,p=>{const M=typeof m=="function"?m(p):m;return u.replace?{...p,data:M}:{...p,data:{...p.data,...M}}},u)},updateEdge:h,updateEdgeData:(f,m,u={replace:!1})=>{h(f,p=>{const M=typeof m=="function"?m(p):m;return u.replace?{...p,data:M}:{...p,data:{...p.data,...M}}},u)},getNodesBounds:f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState();return pc(f,{nodeLookup:m,nodeOrigin:u})},getHandleConnections:({type:f,id:m,nodeId:u})=>Array.from(n.getState().connectionLookup.get(`${u}-${f}${m?`-${m}`:""}`)?.values()??[]),getNodeConnections:({type:f,handleId:m,nodeId:u})=>Array.from(n.getState().connectionLookup.get(`${u}${f?m?`-${f}-${m}`:`-${f}`:""}`)?.values()??[]),fitView:async f=>{const m=n.getState().fitViewResolver??Nc();return n.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:m}),s.nodeQueue.push(u=>[...u]),m.promise}}},[]);return g.useMemo(()=>({...i,...e,viewportInitialized:r}),[r])}const pa=e=>e.selected,Xd=typeof window<"u"?window:void 0;function Ud({deleteKeyCode:e,multiSelectionKeyCode:n}){const s=Be(),{deleteElements:r}=to(),i=br(e,{actInsideInputWithModifier:!1}),o=br(n,{target:Xd});g.useEffect(()=>{if(i){const{edges:a,nodes:c}=s.getState();r({nodes:c.filter(pa),edges:a.filter(pa)}),s.setState({nodesSelectionActive:!1})}},[i]),g.useEffect(()=>{s.setState({multiSelectionActive:o})},[o])}function Qd(e){const n=Be();g.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=Zs(e.current);(r.height===0||r.width===0)&&n.getState().onError?.("004",zt.error004()),n.setState({width:r.width||500,height:r.height||500})};if(e.current){s(),window.addEventListener("resize",s);const r=new ResizeObserver(()=>s());return r.observe(e.current),()=>{window.removeEventListener("resize",s),r&&e.current&&r.unobserve(e.current)}}},[])}const us={position:"absolute",width:"100%",height:"100%",top:0,left:0},Jd=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function eu({onPaneContextMenu:e,zoomOnScroll:n=!0,zoomOnPinch:s=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:o=Cn.Free,zoomOnDoubleClick:a=!0,panOnDrag:c=!0,defaultViewport:l,translateExtent:d,minZoom:h,maxZoom:f,zoomActivationKeyCode:m,preventScrolling:u=!0,children:p,noWheelClassName:M,noPanClassName:C,onViewportChange:y,isControlledViewport:v,paneClickDistance:x,selectionOnDrag:b}){const k=Be(),N=g.useRef(null),{userSelectionActive:I,lib:B,connectionInProgress:D}=Te(Jd,qe),L=br(m),E=g.useRef();Qd(N);const P=g.useCallback(z=>{y?.({x:z[0],y:z[1],zoom:z[2]}),v||k.setState({transform:z})},[y,v]);return g.useEffect(()=>{if(N.current){E.current=id({domNode:N.current,minZoom:h,maxZoom:f,translateExtent:d,viewport:l,onDraggingChange:_=>k.setState(T=>T.paneDragging===_?T:{paneDragging:_}),onPanZoomStart:(_,T)=>{const{onViewportChangeStart:R,onMoveStart:A}=k.getState();A?.(_,T),R?.(T)},onPanZoom:(_,T)=>{const{onViewportChange:R,onMove:A}=k.getState();A?.(_,T),R?.(T)},onPanZoomEnd:(_,T)=>{const{onViewportChangeEnd:R,onMoveEnd:A}=k.getState();A?.(_,T),R?.(T)}});const{x:z,y:j,zoom:O}=E.current.getViewport();return k.setState({panZoom:E.current,transform:[z,j,O],domNode:N.current.closest(".react-flow")}),()=>{E.current?.destroy()}}},[]),g.useEffect(()=>{E.current?.update({onPaneContextMenu:e,zoomOnScroll:n,zoomOnPinch:s,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:c,zoomActivationKeyPressed:L,preventScrolling:u,noPanClassName:C,userSelectionActive:I,noWheelClassName:M,lib:B,onTransformChange:P,connectionInProgress:D,selectionOnDrag:b,paneClickDistance:x})},[e,n,s,r,i,o,a,c,L,u,C,I,M,B,P,D,b,x]),t.jsx("div",{className:"react-flow__renderer",ref:N,style:us,children:p})}const tu=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function nu(){const{userSelectionActive:e,userSelectionRect:n}=Te(tu,qe);return e&&n?t.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:n.width,height:n.height,transform:`translate(${n.x}px, ${n.y}px)`}}):null}const Ts=(e,n)=>s=>{s.target===n.current&&e?.(s)},ru=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function su({isSelecting:e,selectionKeyPressed:n,selectionMode:s=gr.Full,panOnDrag:r,paneClickDistance:i,selectionOnDrag:o,onSelectionStart:a,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:d,onPaneScroll:h,onPaneMouseEnter:f,onPaneMouseMove:m,onPaneMouseLeave:u,children:p}){const M=Be(),{userSelectionActive:C,elementsSelectable:y,dragging:v,connectionInProgress:x}=Te(ru,qe),b=y&&(e||C),k=g.useRef(null),N=g.useRef(),I=g.useRef(new Set),B=g.useRef(new Set),D=g.useRef(!1),L=R=>{if(D.current||x){D.current=!1;return}l?.(R),M.getState().resetSelectedElements(),M.setState({nodesSelectionActive:!1})},E=R=>{if(Array.isArray(r)&&r?.includes(2)){R.preventDefault();return}d?.(R)},P=h?R=>h(R):void 0,z=R=>{D.current&&(R.stopPropagation(),D.current=!1)},j=R=>{const{domNode:A}=M.getState();if(N.current=A?.getBoundingClientRect(),!N.current)return;const W=R.target===k.current;if(!W&&!!R.target.closest(".nokey")||!e||!(o&&W||n)||R.button!==0||!R.isPrimary)return;R.target?.setPointerCapture?.(R.pointerId),D.current=!1;const{x:Q,y:$}=Dt(R.nativeEvent,N.current);M.setState({userSelectionRect:{width:0,height:0,startX:Q,startY:$,x:Q,y:$}}),W||(R.stopPropagation(),R.preventDefault())},O=R=>{const{userSelectionRect:A,transform:W,nodeLookup:Y,edgeLookup:F,connectionLookup:Q,triggerNodeChanges:$,triggerEdgeChanges:S,defaultEdgeOptions:V,resetSelectedElements:q}=M.getState();if(!N.current||!A)return;const{x:H,y:Z}=Dt(R.nativeEvent,N.current),{startX:J,startY:le}=A;if(!D.current){const se=n?0:i;if(Math.hypot(H-J,Z-le)<=se)return;q(),a?.(R)}D.current=!0;const te={startX:J,startY:le,x:H<J?H:J,y:Z<le?Z:le,width:Math.abs(H-J),height:Math.abs(Z-le)},X=I.current,ie=B.current;I.current=new Set(Gs(Y,te,W,s===gr.Partial,!0).map(se=>se.id)),B.current=new Set;const de=V?.selectable??!0;for(const se of I.current){const me=Q.get(se);if(me)for(const{edgeId:ue}of me.values()){const K=F.get(ue);K&&(K.selectable??de)&&B.current.add(ue)}}if(!Wo(X,I.current)){const se=Wn(Y,I.current,!0);$(se)}if(!Wo(ie,B.current)){const se=Wn(F,B.current);S(se)}M.setState({userSelectionRect:te,userSelectionActive:!0,nodesSelectionActive:!1})},_=R=>{R.button===0&&(R.target?.releasePointerCapture?.(R.pointerId),!C&&R.target===k.current&&M.getState().userSelectionRect&&L?.(R),M.setState({userSelectionActive:!1,userSelectionRect:null}),D.current&&(c?.(R),M.setState({nodesSelectionActive:I.current.size>0})))},T=r===!0||Array.isArray(r)&&r.includes(0);return t.jsxs("div",{className:Ze(["react-flow__pane",{draggable:T,dragging:v,selection:e}]),onClick:b?void 0:Ts(L,k),onContextMenu:Ts(E,k),onWheel:Ts(P,k),onPointerEnter:b?void 0:f,onPointerMove:b?O:m,onPointerUp:b?_:void 0,onPointerDownCapture:b?j:void 0,onClickCapture:b?z:void 0,onPointerLeave:u,ref:k,style:us,children:[p,t.jsx(nu,{})]})}function Hs({id:e,store:n,unselect:s=!1,nodeRef:r}){const{addSelectedNodes:i,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:c,onError:l}=n.getState(),d=c.get(e);if(!d){l?.("012",zt.error012(e));return}n.setState({nodesSelectionActive:!1}),d.selected?(s||d.selected&&a)&&(o({nodes:[d],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function Fi({nodeRef:e,disabled:n=!1,noDragClassName:s,handleSelector:r,nodeId:i,isSelectable:o,nodeClickDistance:a}){const c=Be(),[l,d]=g.useState(!1),h=g.useRef();return g.useEffect(()=>{h.current=Gc({getStoreItems:()=>c.getState(),onNodeMouseDown:f=>{Hs({id:f,store:c,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),g.useEffect(()=>{if(!(n||!e.current||!h.current))return h.current.update({noDragClassName:s,handleSelector:r,domNode:e.current,isSelectable:o,nodeId:i,nodeClickDistance:a}),()=>{h.current?.destroy()}},[s,r,n,o,e,i,a]),l}const ou=e=>n=>n.selected&&(n.draggable||e&&typeof n.draggable>"u");function Yi(){const e=Be();return g.useCallback(s=>{const{nodeExtent:r,snapToGrid:i,snapGrid:o,nodesDraggable:a,onError:c,updateNodePositions:l,nodeLookup:d,nodeOrigin:h}=e.getState(),f=new Map,m=ou(a),u=i?o[0]:5,p=i?o[1]:5,M=s.direction.x*u*s.factor,C=s.direction.y*p*s.factor;for(const[,y]of d){if(!m(y))continue;let v={x:y.internals.positionAbsolute.x+M,y:y.internals.positionAbsolute.y+C};i&&(v=jr(v,o));const{position:x,positionAbsolute:b}=ui({nodeId:y.id,nextPosition:v,nodeLookup:d,nodeExtent:r,nodeOrigin:h,onError:c});y.position=x,y.internals.positionAbsolute=b,f.set(y.id,y)}l(f)},[])}const no=g.createContext(null),au=no.Provider;no.Consumer;const Gi=()=>g.useContext(no),iu=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),lu=(e,n,s)=>r=>{const{connectionClickStartHandle:i,connectionMode:o,connection:a}=r,{fromHandle:c,toHandle:l,isValid:d}=a,h=l?.nodeId===e&&l?.id===n&&l?.type===s;return{connectingFrom:c?.nodeId===e&&c?.id===n&&c?.type===s,connectingTo:h,clickConnecting:i?.nodeId===e&&i?.id===n&&i?.type===s,isPossibleEndHandle:o===Yn.Strict?c?.type!==s:e!==c?.nodeId||n!==c?.id,connectionInProcess:!!c,clickConnectionInProcess:!!i,valid:h&&d}};function cu({type:e="source",position:n=be.Top,isValidConnection:s,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,id:a,onConnect:c,children:l,className:d,onMouseDown:h,onTouchStart:f,...m},u){const p=a||null,M=e==="target",C=Be(),y=Gi(),{connectOnClick:v,noPanClassName:x,rfId:b}=Te(iu,qe),{connectingFrom:k,connectingTo:N,clickConnecting:I,isPossibleEndHandle:B,connectionInProcess:D,clickConnectionInProcess:L,valid:E}=Te(lu(y,p,e),qe);y||C.getState().onError?.("010",zt.error010());const P=O=>{const{defaultEdgeOptions:_,onConnect:T,hasDefaultEdges:R}=C.getState(),A={..._,...O};if(R){const{edges:W,setEdges:Y}=C.getState();Y(Rc(A,W))}T?.(A),c?.(A)},z=O=>{if(!y)return;const _=yi(O.nativeEvent);if(i&&(_&&O.button===0||!_)){const T=C.getState();zs.onPointerDown(O.nativeEvent,{handleDomNode:O.currentTarget,autoPanOnConnect:T.autoPanOnConnect,connectionMode:T.connectionMode,connectionRadius:T.connectionRadius,domNode:T.domNode,nodeLookup:T.nodeLookup,lib:T.lib,isTarget:M,handleId:p,nodeId:y,flowId:T.rfId,panBy:T.panBy,cancelConnection:T.cancelConnection,onConnectStart:T.onConnectStart,onConnectEnd:(...R)=>C.getState().onConnectEnd?.(...R),updateConnection:T.updateConnection,onConnect:P,isValidConnection:s||((...R)=>C.getState().isValidConnection?.(...R)??!0),getTransform:()=>C.getState().transform,getFromHandle:()=>C.getState().connection.fromHandle,autoPanSpeed:T.autoPanSpeed,dragThreshold:T.connectionDragThreshold})}_?h?.(O):f?.(O)},j=O=>{const{onClickConnectStart:_,onClickConnectEnd:T,connectionClickStartHandle:R,connectionMode:A,isValidConnection:W,lib:Y,rfId:F,nodeLookup:Q,connection:$}=C.getState();if(!y||!R&&!i)return;if(!R){_?.(O.nativeEvent,{nodeId:y,handleId:p,handleType:e}),C.setState({connectionClickStartHandle:{nodeId:y,type:e,id:p}});return}const S=xi(O.target),V=s||W,{connection:q,isValid:H}=zs.isValid(O.nativeEvent,{handle:{nodeId:y,id:p,type:e},connectionMode:A,fromNodeId:R.nodeId,fromHandleId:R.id||null,fromType:R.type,isValidConnection:V,flowId:F,doc:S,lib:Y,nodeLookup:Q});H&&q&&P(q);const Z=structuredClone($);delete Z.inProgress,Z.toPosition=Z.toHandle?Z.toHandle.position:null,T?.(O,Z),C.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":p,"data-nodeid":y,"data-handlepos":n,"data-id":`${b}-${y}-${p}-${e}`,className:Ze(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",x,d,{source:!M,target:M,connectable:r,connectablestart:i,connectableend:o,clickconnecting:I,connectingfrom:k,connectingto:N,valid:E,connectionindicator:r&&(!D||B)&&(D||L?o:i)}]),onMouseDown:z,onTouchStart:z,onClick:v?j:void 0,ref:u,...m,children:l})}const dn=g.memo(Wi(cu));function du({data:e,isConnectable:n,sourcePosition:s=be.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(dn,{type:"source",position:s,isConnectable:n})]})}function uu({data:e,isConnectable:n,targetPosition:s=be.Top,sourcePosition:r=be.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(dn,{type:"target",position:s,isConnectable:n}),e?.label,t.jsx(dn,{type:"source",position:r,isConnectable:n})]})}function fu(){return null}function hu({data:e,isConnectable:n,targetPosition:s=be.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(dn,{type:"target",position:s,isConnectable:n}),e?.label]})}const ns={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},xa={input:du,default:uu,output:hu,group:fu};function mu(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}const gu=e=>{const{width:n,height:s,x:r,y:i}=kr(e.nodeLookup,{filter:o=>!!o.selected});return{width:At(n)?n:null,height:At(s)?s:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${i}px)`}};function pu({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:s}){const r=Be(),{width:i,height:o,transformString:a,userSelectionActive:c}=Te(gu,qe),l=Yi(),d=g.useRef(null);g.useEffect(()=>{s||d.current?.focus({preventScroll:!0})},[s]);const h=!c&&i!==null&&o!==null;if(Fi({nodeRef:d,disabled:!h}),!h)return null;const f=e?u=>{const p=r.getState().nodes.filter(M=>M.selected);e(u,p)}:void 0,m=u=>{Object.prototype.hasOwnProperty.call(ns,u.key)&&(u.preventDefault(),l({direction:ns[u.key],factor:u.shiftKey?4:1}))};return t.jsx("div",{className: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 ba=typeof window<"u"?window:void 0,xu=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Ki({children:e,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,paneClickDistance:c,deleteKeyCode:l,selectionKeyCode:d,selectionOnDrag:h,selectionMode:f,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:p,panActivationKeyCode:M,zoomActivationKeyCode:C,elementsSelectable:y,zoomOnScroll:v,zoomOnPinch:x,panOnScroll:b,panOnScrollSpeed:k,panOnScrollMode:N,zoomOnDoubleClick:I,panOnDrag:B,defaultViewport:D,translateExtent:L,minZoom:E,maxZoom:P,preventScrolling:z,onSelectionContextMenu:j,noWheelClassName:O,noPanClassName:_,disableKeyboardA11y:T,onViewportChange:R,isControlledViewport:A}){const{nodesSelectionActive:W,userSelectionActive:Y}=Te(xu,qe),F=br(d,{target:ba}),Q=br(M,{target:ba}),$=Q||B,S=Q||b,V=h&&$!==!0,q=F||Y||V;return Ud({deleteKeyCode:l,multiSelectionKeyCode:p}),t.jsx(eu,{onPaneContextMenu:o,elementsSelectable:y,zoomOnScroll:v,zoomOnPinch:x,panOnScroll:S,panOnScrollSpeed:k,panOnScrollMode:N,zoomOnDoubleClick:I,panOnDrag:!F&&$,defaultViewport:D,translateExtent:L,minZoom:E,maxZoom:P,zoomActivationKeyCode:C,preventScrolling:z,noWheelClassName:O,noPanClassName:_,onViewportChange:R,isControlledViewport:A,paneClickDistance:c,selectionOnDrag:V,children:t.jsxs(su,{onSelectionStart:m,onSelectionEnd:u,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:$,isSelecting:!!q,selectionMode:f,selectionKeyPressed:F,paneClickDistance:c,selectionOnDrag:V,children:[e,W&&t.jsx(pu,{onSelectionContextMenu:j,noPanClassName:_,disableKeyboardA11y:T})]})})}Ki.displayName="FlowRenderer";const bu=g.memo(Ki),yu=e=>n=>e?Gs(n.nodeLookup,{x:0,y:0,width:n.width,height:n.height},n.transform,!0).map(s=>s.id):Array.from(n.nodeLookup.keys());function vu(e){return Te(g.useCallback(yu(e),[e]),qe)}const wu=e=>e.updateNodeInternals;function ku(){const e=Te(wu),[n]=g.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const r=new Map;s.forEach(i=>{const o=i.target.getAttribute("data-id");r.set(o,{id:o,nodeElement:i.target,force:!0})}),e(r)}));return g.useEffect(()=>()=>{n?.disconnect()},[n]),n}function ju({node:e,nodeType:n,hasDimensions:s,resizeObserver:r}){const i=Be(),o=g.useRef(null),a=g.useRef(null),c=g.useRef(e.sourcePosition),l=g.useRef(e.targetPosition),d=g.useRef(n),h=s&&!!e.internals.handleBounds;return g.useEffect(()=>{o.current&&!e.hidden&&(!h||a.current!==o.current)&&(a.current&&r?.unobserve(a.current),r?.observe(o.current),a.current=o.current)},[h,e.hidden]),g.useEffect(()=>()=>{a.current&&(r?.unobserve(a.current),a.current=null)},[]),g.useEffect(()=>{if(o.current){const f=d.current!==n,m=c.current!==e.sourcePosition,u=l.current!==e.targetPosition;(f||m||u)&&(d.current=n,c.current=e.sourcePosition,l.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:o.current,force:!0}]])))}},[e.id,n,e.sourcePosition,e.targetPosition]),o}function Nu({id:e,onClick:n,onMouseEnter:s,onMouseMove:r,onMouseLeave:i,onContextMenu:o,onDoubleClick:a,nodesDraggable:c,elementsSelectable:l,nodesConnectable:d,nodesFocusable:h,resizeObserver:f,noDragClassName:m,noPanClassName:u,disableKeyboardA11y:p,rfId:M,nodeTypes:C,nodeClickDistance:y,onError:v}){const{node:x,internals:b,isParent:k}=Te(H=>{const Z=H.nodeLookup.get(e),J=H.parentLookup.has(e);return{node:Z,internals:Z.internals,isParent:J}},qe);let N=x.type||"default",I=C?.[N]||xa[N];I===void 0&&(v?.("003",zt.error003(N)),N="default",I=C?.default||xa.default);const B=!!(x.draggable||c&&typeof x.draggable>"u"),D=!!(x.selectable||l&&typeof x.selectable>"u"),L=!!(x.connectable||d&&typeof x.connectable>"u"),E=!!(x.focusable||h&&typeof x.focusable>"u"),P=Be(),z=gi(x),j=ju({node:x,nodeType:N,hasDimensions:z,resizeObserver:f}),O=Fi({nodeRef:j,disabled:x.hidden||!B,noDragClassName:m,handleSelector:x.dragHandle,nodeId:e,isSelectable:D,nodeClickDistance:y}),_=Yi();if(x.hidden)return null;const T=Qt(x),R=mu(x),A=D||B||n||s||r||i,W=s?H=>s(H,{...b.userNode}):void 0,Y=r?H=>r(H,{...b.userNode}):void 0,F=i?H=>i(H,{...b.userNode}):void 0,Q=o?H=>o(H,{...b.userNode}):void 0,$=a?H=>a(H,{...b.userNode}):void 0,S=H=>{const{selectNodesOnDrag:Z,nodeDragThreshold:J}=P.getState();D&&(!Z||!B||J>0)&&Hs({id:e,store:P,nodeRef:j}),n&&n(H,{...b.userNode})},V=H=>{if(!(bi(H.nativeEvent)||p)){if(ai.includes(H.key)&&D){const Z=H.key==="Escape";Hs({id:e,store:P,unselect:Z,nodeRef:j})}else if(B&&x.selected&&Object.prototype.hasOwnProperty.call(ns,H.key)){H.preventDefault();const{ariaLabelConfig:Z}=P.getState();P.setState({ariaLiveMessage:Z["node.a11yDescription.ariaLiveMessage"]({direction:H.key.replace("Arrow","").toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),_({direction:ns[H.key],factor:H.shiftKey?4:1})}}},q=()=>{if(p||!j.current?.matches(":focus-visible"))return;const{transform:H,width:Z,height:J,autoPanOnNodeFocus:le,setCenter:te}=P.getState();if(!le)return;Gs(new Map([[e,x]]),{x:0,y:0,width:Z,height:J},H,!0).length>0||te(x.position.x+T.width/2,x.position.y+T.height/2,{zoom:H[2]})};return t.jsx("div",{className:Ze(["react-flow__node",`react-flow__node-${N}`,{[u]:B},x.className,{selected:x.selected,selectable:D,parent:k,draggable:B,dragging:O}]),ref:j,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:A?"all":"none",visibility:z?"visible":"hidden",...x.style,...R},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:W,onMouseMove:Y,onMouseLeave:F,onContextMenu:Q,onClick:S,onDoubleClick:$,onKeyDown:E?V:void 0,tabIndex:E?0:void 0,onFocus:E?q:void 0,role:x.ariaRole??(E?"group":void 0),"aria-roledescription":"node","aria-describedby":p?void 0:`${$i}-${M}`,"aria-label":x.ariaLabel,...x.domAttributes,children:t.jsx(au,{value:e,children:t.jsx(I,{id:e,data:x.data,type:N,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:x.selected??!1,selectable:D,draggable:B,deletable:x.deletable??!0,isConnectable:L,sourcePosition:x.sourcePosition,targetPosition:x.targetPosition,dragging:O,dragHandle:x.dragHandle,zIndex:b.z,parentId:x.parentId,...T})})})}var Cu=g.memo(Nu);const Su=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Zi(e){const{nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,onError:o}=Te(Su,qe),a=vu(e.onlyRenderVisibleElements),c=ku();return t.jsx("div",{className:"react-flow__nodes",style:us,children:a.map(l=>t.jsx(Cu,{id:l,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:c,nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:o},l))})}Zi.displayName="NodeRenderer";const Eu=g.memo(Zi);function Mu(e){return Te(g.useCallback(s=>{if(!e)return s.edges.map(i=>i.id);const r=[];if(s.width&&s.height)for(const i of s.edges){const o=s.nodeLookup.get(i.source),a=s.nodeLookup.get(i.target);o&&a&&Mc({sourceNode:o,targetNode:a,width:s.width,height:s.height,transform:s.transform})&&r.push(i.id)}return r},[e]),qe)}const Iu=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...e&&{stroke:e}};return t.jsx("polyline",{className:"arrow",style:s,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Tu=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...e&&{stroke:e,fill:e}};return t.jsx("polyline",{className:"arrowclosed",style:s,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},ya={[Gn.Arrow]:Iu,[Gn.ArrowClosed]:Tu};function Ru(e){const n=Be();return g.useMemo(()=>Object.prototype.hasOwnProperty.call(ya,e)?ya[e]:(n.getState().onError?.("009",zt.error009(e)),null),[e])}const _u=({id:e,type:n,color:s,width:r=12.5,height:i=12.5,markerUnits:o="strokeWidth",strokeWidth:a,orient:c="auto-start-reverse"})=>{const l=Ru(n);return l?t.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:c,refX:"0",refY:"0",children:t.jsx(l,{color:s,strokeWidth:a})}):null},Xi=({defaultColor:e,rfId:n})=>{const s=Te(o=>o.edges),r=Te(o=>o.defaultEdgeOptions),i=g.useMemo(()=>Pc(s,{id:n,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[s,r,n,e]);return i.length?t.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:t.jsx("defs",{children:i.map(o=>t.jsx(_u,{id:o.id,type:o.type,color:o.color,width:o.width,height:o.height,markerUnits:o.markerUnits,strokeWidth:o.strokeWidth,orient:o.orient},o.id))})}):null};Xi.displayName="MarkerDefinitions";var Lu=g.memo(Xi);function Ui({x:e,y:n,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:c=2,children:l,className:d,...h}){const[f,m]=g.useState({x:1,y:0,width:0,height:0}),u=Ze(["react-flow__edge-textwrapper",d]),p=g.useRef(null);return g.useEffect(()=>{if(p.current){const M=p.current.getBBox();m({x:M.x,y:M.y,width:M.width,height:M.height})}},[s]),s?t.jsxs("g",{transform:`translate(${e-f.width/2} ${n-f.height/2})`,className:u,visibility:f.width?"visible":"hidden",...h,children:[i&&t.jsx("rect",{width:f.width+2*a[0],x:-a[0],y:-a[1],height:f.height+2*a[1],className:"react-flow__edge-textbg",style:o,rx:c,ry:c}),t.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:p,style:r,children:s}),l]}):null}Ui.displayName="EdgeText";const Au=g.memo(Ui);function fs({path:e,labelX:n,labelY:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,interactionWidth:d=20,...h}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...h,d:e,fill:"none",className: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&&At(n)&&At(s)?t.jsx(Au,{x:n,y:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null]})}function va({pos:e,x1:n,y1:s,x2:r,y2:i}){return e===be.Left||e===be.Right?[.5*(n+r),s]:[n,.5*(s+i)]}function Qi({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top}){const[a,c]=va({pos:s,x1:e,y1:n,x2:r,y2:i}),[l,d]=va({pos:o,x1:r,y1:i,x2:e,y2:n}),[h,f,m,u]=vi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:d});return[`M${e},${n} C${a},${c} ${l},${d} ${r},${i}`,h,f,m,u]}function Ji(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a,targetPosition:c,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:M,markerStart:C,interactionWidth:y})=>{const[v,x,b]=Qi({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:c}),k=e.isInternal?void 0:n;return t.jsx(fs,{id:k,path:v,labelX:x,labelY:b,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:M,markerStart:C,interactionWidth:y})})}const Du=Ji({isInternal:!1}),el=Ji({isInternal:!0});Du.displayName="SimpleBezierEdge";el.displayName="SimpleBezierEdgeInternal";function tl(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,sourcePosition:u=be.Bottom,targetPosition:p=be.Top,markerEnd:M,markerStart:C,pathOptions:y,interactionWidth:v})=>{const[x,b,k]=$s({sourceX:s,sourceY:r,sourcePosition:u,targetX:i,targetY:o,targetPosition:p,borderRadius:y?.borderRadius,offset:y?.offset,stepPosition:y?.stepPosition}),N=e.isInternal?void 0:n;return t.jsx(fs,{id:N,path:x,labelX:b,labelY:k,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:M,markerStart:C,interactionWidth:v})})}const nl=tl({isInternal:!1}),rl=tl({isInternal:!0});nl.displayName="SmoothStepEdge";rl.displayName="SmoothStepEdgeInternal";function sl(e){return g.memo(({id:n,...s})=>{const r=e.isInternal?void 0:n;return t.jsx(nl,{...s,id:r,pathOptions:g.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const Pu=sl({isInternal:!1}),ol=sl({isInternal:!0});Pu.displayName="StepEdge";ol.displayName="StepEdgeInternal";function al(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:p,interactionWidth:M})=>{const[C,y,v]=ji({sourceX:s,sourceY:r,targetX:i,targetY:o}),x=e.isInternal?void 0:n;return t.jsx(fs,{id:x,path:C,labelX:y,labelY:v,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:p,interactionWidth:M})})}const $u=al({isInternal:!1}),il=al({isInternal:!0});$u.displayName="StraightEdge";il.displayName="StraightEdgeInternal";function ll(e){return g.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a=be.Bottom,targetPosition:c=be.Top,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:M,markerStart:C,pathOptions:y,interactionWidth:v})=>{const[x,b,k]=wi({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:c,curvature:y?.curvature}),N=e.isInternal?void 0:n;return t.jsx(fs,{id:N,path:x,labelX:b,labelY:k,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:p,markerEnd:M,markerStart:C,interactionWidth:v})})}const Ou=ll({isInternal:!1}),cl=ll({isInternal:!0});Ou.displayName="BezierEdge";cl.displayName="BezierEdgeInternal";const wa={default:cl,straight:il,step:ol,smoothstep:rl,simplebezier:el},ka={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},Bu=(e,n,s)=>s===be.Left?e-n:s===be.Right?e+n:e,zu=(e,n,s)=>s===be.Top?e-n:s===be.Bottom?e+n:e,ja="react-flow__edgeupdater";function Na({position:e,centerX:n,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:o,onMouseOut:a,type:c}){return t.jsx("circle",{onMouseDown:i,onMouseEnter:o,onMouseOut:a,className:Ze([ja,`${ja}-${c}`]),cx:Bu(n,r,e),cy:zu(s,r,e),r,stroke:"transparent",fill:"transparent"})}function Hu({isReconnectable:e,reconnectRadius:n,edge:s,sourceX:r,sourceY:i,targetX:o,targetY:a,sourcePosition:c,targetPosition:l,onReconnect:d,onReconnectStart:h,onReconnectEnd:f,setReconnecting:m,setUpdateHover:u}){const p=Be(),M=(b,k)=>{if(b.button!==0)return;const{autoPanOnConnect:N,domNode:I,connectionMode:B,connectionRadius:D,lib:L,onConnectStart:E,cancelConnection:P,nodeLookup:z,rfId:j,panBy:O,updateConnection:_}=p.getState(),T=k.type==="target",R=(Y,F)=>{m(!1),f?.(Y,s,k.type,F)},A=Y=>d?.(s,Y),W=(Y,F)=>{m(!0),h?.(b,s,k.type),E?.(Y,F)};zs.onPointerDown(b.nativeEvent,{autoPanOnConnect:N,connectionMode:B,connectionRadius:D,domNode:I,handleId:k.id,nodeId:k.nodeId,nodeLookup:z,isTarget:T,edgeUpdaterType:k.type,lib:L,flowId:j,cancelConnection:P,panBy:O,isValidConnection:(...Y)=>p.getState().isValidConnection?.(...Y)??!0,onConnect:A,onConnectStart:W,onConnectEnd:(...Y)=>p.getState().onConnectEnd?.(...Y),onReconnectEnd:R,updateConnection:_,getTransform:()=>p.getState().transform,getFromHandle:()=>p.getState().connection.fromHandle,dragThreshold:p.getState().connectionDragThreshold,handleDomNode:b.currentTarget})},C=b=>M(b,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),y=b=>M(b,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),v=()=>u(!0),x=()=>u(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(Na,{position:c,centerX:r,centerY:i,radius:n,onMouseDown:C,onMouseEnter:v,onMouseOut:x,type:"source"}),(e===!0||e==="target")&&t.jsx(Na,{position:l,centerX:o,centerY:a,radius:n,onMouseDown:y,onMouseEnter:v,onMouseOut:x,type:"target"})]})}function qu({id:e,edgesFocusable:n,edgesReconnectable:s,elementsSelectable:r,onClick:i,onDoubleClick:o,onContextMenu:a,onMouseEnter:c,onMouseMove:l,onMouseLeave:d,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,rfId:p,edgeTypes:M,noPanClassName:C,onError:y,disableKeyboardA11y:v}){let x=Te(te=>te.edgeLookup.get(e));const b=Te(te=>te.defaultEdgeOptions);x=b?{...b,...x}:x;let k=x.type||"default",N=M?.[k]||wa[k];N===void 0&&(y?.("011",zt.error011(k)),k="default",N=M?.default||wa.default);const I=!!(x.focusable||n&&typeof x.focusable>"u"),B=typeof f<"u"&&(x.reconnectable||s&&typeof x.reconnectable>"u"),D=!!(x.selectable||r&&typeof x.selectable>"u"),L=g.useRef(null),[E,P]=g.useState(!1),[z,j]=g.useState(!1),O=Be(),{zIndex:_,sourceX:T,sourceY:R,targetX:A,targetY:W,sourcePosition:Y,targetPosition:F}=Te(g.useCallback(te=>{const X=te.nodeLookup.get(x.source),ie=te.nodeLookup.get(x.target);if(!X||!ie)return{zIndex:x.zIndex,...ka};const de=Dc({id:e,sourceNode:X,targetNode:ie,sourceHandle:x.sourceHandle||null,targetHandle:x.targetHandle||null,connectionMode:te.connectionMode,onError:y});return{zIndex:Ec({selected:x.selected,zIndex:x.zIndex,sourceNode:X,targetNode:ie,elevateOnSelect:te.elevateEdgesOnSelect,zIndexMode:te.zIndexMode}),...de||ka}},[x.source,x.target,x.sourceHandle,x.targetHandle,x.selected,x.zIndex]),qe),Q=g.useMemo(()=>x.markerStart?`url('#${Os(x.markerStart,p)}')`:void 0,[x.markerStart,p]),$=g.useMemo(()=>x.markerEnd?`url('#${Os(x.markerEnd,p)}')`:void 0,[x.markerEnd,p]);if(x.hidden||T===null||R===null||A===null||W===null)return null;const S=te=>{const{addSelectedEdges:X,unselectNodesAndEdges:ie,multiSelectionActive:de}=O.getState();D&&(O.setState({nodesSelectionActive:!1}),x.selected&&de?(ie({nodes:[],edges:[x]}),L.current?.blur()):X([e])),i&&i(te,x)},V=o?te=>{o(te,{...x})}:void 0,q=a?te=>{a(te,{...x})}:void 0,H=c?te=>{c(te,{...x})}:void 0,Z=l?te=>{l(te,{...x})}:void 0,J=d?te=>{d(te,{...x})}:void 0,le=te=>{if(!v&&ai.includes(te.key)&&D){const{unselectNodesAndEdges:X,addSelectedEdges:ie}=O.getState();te.key==="Escape"?(L.current?.blur(),X({edges:[x]})):ie([e])}};return t.jsx("svg",{style:{zIndex:_},children:t.jsxs("g",{className:Ze(["react-flow__edge",`react-flow__edge-${k}`,x.className,C,{selected:x.selected,animated:x.animated,inactive:!D&&!i,updating:E,selectable:D}]),onClick:S,onDoubleClick:V,onContextMenu:q,onMouseEnter:H,onMouseMove:Z,onMouseLeave:J,onKeyDown:I?le:void 0,tabIndex:I?0:void 0,role:x.ariaRole??(I?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":x.ariaLabel===null?void 0:x.ariaLabel||`Edge from ${x.source} to ${x.target}`,"aria-describedby":I?`${Oi}-${p}`:void 0,ref:L,...x.domAttributes,children:[!z&&t.jsx(N,{id:e,source:x.source,target:x.target,type:x.type,selected:x.selected,animated:x.animated,selectable:D,deletable:x.deletable??!0,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,sourceX:T,sourceY:R,targetX:A,targetY:W,sourcePosition:Y,targetPosition:F,data:x.data,style:x.style,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerStart:Q,markerEnd:$,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth}),B&&t.jsx(Hu,{edge:x,isReconnectable:B,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,sourceX:T,sourceY:R,targetX:A,targetY:W,sourcePosition:Y,targetPosition:F,setUpdateHover:P,setReconnecting:j})]})})}var Wu=g.memo(qu);const Vu=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function dl({defaultMarkerColor:e,onlyRenderVisibleElements:n,rfId:s,edgeTypes:r,noPanClassName:i,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:c,onEdgeMouseMove:l,onEdgeMouseLeave:d,onEdgeClick:h,reconnectRadius:f,onEdgeDoubleClick:m,onReconnectStart:u,onReconnectEnd:p,disableKeyboardA11y:M}){const{edgesFocusable:C,edgesReconnectable:y,elementsSelectable:v,onError:x}=Te(Vu,qe),b=Mu(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(Lu,{defaultColor:e,rfId:s}),b.map(k=>t.jsx(Wu,{id:k,edgesFocusable:C,edgesReconnectable:y,elementsSelectable:v,noPanClassName:i,onReconnect:o,onContextMenu:a,onMouseEnter:c,onMouseMove:l,onMouseLeave:d,onClick:h,reconnectRadius:f,onDoubleClick:m,onReconnectStart:u,onReconnectEnd:p,rfId:s,onError:x,edgeTypes:r,disableKeyboardA11y:M},k))]})}dl.displayName="EdgeRenderer";const Fu=g.memo(dl),Yu=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Gu({children:e}){const n=Te(Yu);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function Ku(e){const n=to(),s=g.useRef(!1);g.useEffect(()=>{!s.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),s.current=!0)},[e,n.viewportInitialized])}const Zu=e=>e.panZoom?.syncViewport;function Xu(e){const n=Te(Zu),s=Be();return g.useEffect(()=>{e&&(n?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,n]),null}function Uu(e){return e.connection.inProgress?{...e.connection,to:Nr(e.connection.to,e.transform)}:{...e.connection}}function Qu(e){return Uu}function Ju(e){const n=Qu();return Te(n,qe)}const ef=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function tf({containerStyle:e,style:n,type:s,component:r}){const{nodesConnectable:i,width:o,height:a,isValid:c,inProgress:l}=Te(ef,qe);return!(o&&i&&l)?null:t.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:Ze(["react-flow__connection",ci(c)]),children:t.jsx(ul,{style:n,type:s,CustomComponent:r,isValid:c})})})}const ul=({style:e,type:n=ln.Bezier,CustomComponent:s,isValid:r})=>{const{inProgress:i,from:o,fromNode:a,fromHandle:c,fromPosition:l,to:d,toNode:h,toHandle:f,toPosition:m,pointer:u}=Ju();if(!i)return;if(s)return t.jsx(s,{connectionLineType:n,connectionLineStyle:e,fromNode:a,fromHandle:c,fromX:o.x,fromY:o.y,toX:d.x,toY:d.y,fromPosition:l,toPosition:m,connectionStatus:ci(r),toNode:h,toHandle:f,pointer:u});let p="";const M={sourceX:o.x,sourceY:o.y,sourcePosition:l,targetX:d.x,targetY:d.y,targetPosition:m};switch(n){case ln.Bezier:[p]=wi(M);break;case ln.SimpleBezier:[p]=Qi(M);break;case ln.Step:[p]=$s({...M,borderRadius:0});break;case ln.SmoothStep:[p]=$s(M);break;default:[p]=ji(M)}return t.jsx("path",{d:p,fill:"none",className:"react-flow__connection-path",style:e})};ul.displayName="ConnectionLine";const nf={};function Ca(e=nf){g.useRef(e),Be(),g.useEffect(()=>{},[e])}function rf(){Be(),g.useRef(!1),g.useEffect(()=>{},[])}function fl({nodeTypes:e,edgeTypes:n,onInit:s,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:c,onNodeMouseMove:l,onNodeMouseLeave:d,onNodeContextMenu:h,onSelectionContextMenu:f,onSelectionStart:m,onSelectionEnd:u,connectionLineType:p,connectionLineStyle:M,connectionLineComponent:C,connectionLineContainerStyle:y,selectionKeyCode:v,selectionOnDrag:x,selectionMode:b,multiSelectionKeyCode:k,panActivationKeyCode:N,zoomActivationKeyCode:I,deleteKeyCode:B,onlyRenderVisibleElements:D,elementsSelectable:L,defaultViewport:E,translateExtent:P,minZoom:z,maxZoom:j,preventScrolling:O,defaultMarkerColor:_,zoomOnScroll:T,zoomOnPinch:R,panOnScroll:A,panOnScrollSpeed:W,panOnScrollMode:Y,zoomOnDoubleClick:F,panOnDrag:Q,onPaneClick:$,onPaneMouseEnter:S,onPaneMouseMove:V,onPaneMouseLeave:q,onPaneScroll:H,onPaneContextMenu:Z,paneClickDistance:J,nodeClickDistance:le,onEdgeContextMenu:te,onEdgeMouseEnter:X,onEdgeMouseMove:ie,onEdgeMouseLeave:de,reconnectRadius:se,onReconnect:me,onReconnectStart:ue,onReconnectEnd:K,noDragClassName:ce,noWheelClassName:ge,noPanClassName:ve,disableKeyboardA11y:fe,nodeExtent:re,rfId:xe,viewport:Ee,onViewportChange:ye}){return Ca(e),Ca(n),rf(),Ku(s),Xu(Ee),t.jsx(bu,{onPaneClick:$,onPaneMouseEnter:S,onPaneMouseMove:V,onPaneMouseLeave:q,onPaneContextMenu:Z,onPaneScroll:H,paneClickDistance:J,deleteKeyCode:B,selectionKeyCode:v,selectionOnDrag:x,selectionMode:b,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:k,panActivationKeyCode:N,zoomActivationKeyCode:I,elementsSelectable:L,zoomOnScroll:T,zoomOnPinch:R,zoomOnDoubleClick:F,panOnScroll:A,panOnScrollSpeed:W,panOnScrollMode:Y,panOnDrag:Q,defaultViewport:E,translateExtent:P,minZoom:z,maxZoom:j,onSelectionContextMenu:f,preventScrolling:O,noDragClassName:ce,noWheelClassName:ge,noPanClassName:ve,disableKeyboardA11y:fe,onViewportChange:ye,isControlledViewport:!!Ee,children:t.jsxs(Gu,{children:[t.jsx(Fu,{edgeTypes:n,onEdgeClick:i,onEdgeDoubleClick:a,onReconnect:me,onReconnectStart:ue,onReconnectEnd:K,onlyRenderVisibleElements:D,onEdgeContextMenu:te,onEdgeMouseEnter:X,onEdgeMouseMove:ie,onEdgeMouseLeave:de,reconnectRadius:se,defaultMarkerColor:_,noPanClassName:ve,disableKeyboardA11y:fe,rfId:xe}),t.jsx(tf,{style:M,type:p,component:C,containerStyle:y}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(Eu,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:c,onNodeMouseMove:l,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:le,onlyRenderVisibleElements:D,noPanClassName:ve,noDragClassName:ce,disableKeyboardA11y:fe,nodeExtent:re,rfId:xe}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}fl.displayName="GraphView";const sf=g.memo(fl),Sa=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l=.5,maxZoom:d=2,nodeOrigin:h,nodeExtent:f,zIndexMode:m="basic"}={})=>{const u=new Map,p=new Map,M=new Map,C=new Map,y=r??n??[],v=s??e??[],x=h??[0,0],b=f??mr;Si(M,C,y);const k=Bs(v,u,p,{nodeOrigin:x,nodeExtent:b,zIndexMode:m});let N=[0,0,1];if(a&&i&&o){const I=kr(u,{filter:E=>!!((E.width||E.initialWidth)&&(E.height||E.initialHeight))}),{x:B,y:D,zoom:L}=Ks(I,i,o,l,d,c?.padding??.1);N=[B,D,L]}return{rfId:"1",width:i??0,height:o??0,transform:N,nodes:v,nodesInitialized:k,nodeLookup:u,parentLookup:p,edges:y,edgeLookup:C,connectionLookup:M,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:l,maxZoom:d,translateExtent:mr,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Yn.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:x,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:a??!1,fitViewOptions:c,fitViewResolver:null,connection:{...li},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:wc,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:ii,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},of=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m})=>jd((u,p)=>{async function M(){const{nodeLookup:C,panZoom:y,fitViewOptions:v,fitViewResolver:x,width:b,height:k,minZoom:N,maxZoom:I}=p();y&&(await yc({nodes:C,width:b,height:k,panZoom:y,minZoom:N,maxZoom:I},v),x?.resolve(!0),u({fitViewResolver:null}))}return{...Sa({nodes:e,edges:n,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:d,nodeOrigin:h,nodeExtent:f,defaultNodes:s,defaultEdges:r,zIndexMode:m}),setNodes:C=>{const{nodeLookup:y,parentLookup:v,nodeOrigin:x,elevateNodesOnSelect:b,fitViewQueued:k,zIndexMode:N}=p(),I=Bs(C,y,v,{nodeOrigin:x,nodeExtent:f,elevateNodesOnSelect:b,checkEquality:!0,zIndexMode:N});k&&I?(M(),u({nodes:C,nodesInitialized:I,fitViewQueued:!1,fitViewOptions:void 0})):u({nodes:C,nodesInitialized:I})},setEdges:C=>{const{connectionLookup:y,edgeLookup:v}=p();Si(y,v,C),u({edges:C})},setDefaultNodesAndEdges:(C,y)=>{if(C){const{setNodes:v}=p();v(C),u({hasDefaultNodes:!0})}if(y){const{setEdges:v}=p();v(y),u({hasDefaultEdges:!0})}},updateNodeInternals:C=>{const{triggerNodeChanges:y,nodeLookup:v,parentLookup:x,domNode:b,nodeOrigin:k,nodeExtent:N,debug:I,fitViewQueued:B,zIndexMode:D}=p(),{changes:L,updatedInternals:E}=Wc(C,v,x,b,k,N,D);E&&(Bc(v,x,{nodeOrigin:k,nodeExtent:N,zIndexMode:D}),B?(M(),u({fitViewQueued:!1,fitViewOptions:void 0})):u({}),L?.length>0&&(I&&console.log("React Flow: trigger node changes",L),y?.(L)))},updateNodePositions:(C,y=!1)=>{const v=[];let x=[];const{nodeLookup:b,triggerNodeChanges:k,connection:N,updateConnection:I,onNodesChangeMiddlewareMap:B}=p();for(const[D,L]of C){const E=b.get(D),P=!!(E?.expandParent&&E?.parentId&&L?.position),z={id:D,type:"position",position:P?{x:Math.max(0,L.position.x),y:Math.max(0,L.position.y)}:L.position,dragging:y};if(E&&N.inProgress&&N.fromNode.id===E.id){const j=En(E,N.fromHandle,be.Left,!0);I({...N,from:j})}P&&E.parentId&&v.push({id:D,parentId:E.parentId,rect:{...L.internals.positionAbsolute,width:L.measured.width??0,height:L.measured.height??0}}),x.push(z)}if(v.length>0){const{parentLookup:D,nodeOrigin:L}=p(),E=eo(v,b,D,L);x.push(...E)}for(const D of B.values())x=D(x);k(x)},triggerNodeChanges:C=>{const{onNodesChange:y,setNodes:v,nodes:x,hasDefaultNodes:b,debug:k}=p();if(C?.length){if(b){const N=Hi(C,x);v(N)}k&&console.log("React Flow: trigger node changes",C),y?.(C)}},triggerEdgeChanges:C=>{const{onEdgesChange:y,setEdges:v,edges:x,hasDefaultEdges:b,debug:k}=p();if(C?.length){if(b){const N=qi(C,x);v(N)}k&&console.log("React Flow: trigger edge changes",C),y?.(C)}},addSelectedNodes:C=>{const{multiSelectionActive:y,edgeLookup:v,nodeLookup:x,triggerNodeChanges:b,triggerEdgeChanges:k}=p();if(y){const N=C.map(I=>Nn(I,!0));b(N);return}b(Wn(x,new Set([...C]),!0)),k(Wn(v))},addSelectedEdges:C=>{const{multiSelectionActive:y,edgeLookup:v,nodeLookup:x,triggerNodeChanges:b,triggerEdgeChanges:k}=p();if(y){const N=C.map(I=>Nn(I,!0));k(N);return}k(Wn(v,new Set([...C]))),b(Wn(x,new Set,!0))},unselectNodesAndEdges:({nodes:C,edges:y}={})=>{const{edges:v,nodes:x,nodeLookup:b,triggerNodeChanges:k,triggerEdgeChanges:N}=p(),I=C||x,B=y||v,D=[];for(const E of I){if(!E.selected)continue;const P=b.get(E.id);P&&(P.selected=!1),D.push(Nn(E.id,!1))}const L=[];for(const E of B)E.selected&&L.push(Nn(E.id,!1));k(D),N(L)},setMinZoom:C=>{const{panZoom:y,maxZoom:v}=p();y?.setScaleExtent([C,v]),u({minZoom:C})},setMaxZoom:C=>{const{panZoom:y,minZoom:v}=p();y?.setScaleExtent([v,C]),u({maxZoom:C})},setTranslateExtent:C=>{p().panZoom?.setTranslateExtent(C),u({translateExtent:C})},resetSelectedElements:()=>{const{edges:C,nodes:y,triggerNodeChanges:v,triggerEdgeChanges:x,elementsSelectable:b}=p();if(!b)return;const k=y.reduce((I,B)=>B.selected?[...I,Nn(B.id,!1)]:I,[]),N=C.reduce((I,B)=>B.selected?[...I,Nn(B.id,!1)]:I,[]);v(k),x(N)},setNodeExtent:C=>{const{nodes:y,nodeLookup:v,parentLookup:x,nodeOrigin:b,elevateNodesOnSelect:k,nodeExtent:N,zIndexMode:I}=p();C[0][0]===N[0][0]&&C[0][1]===N[0][1]&&C[1][0]===N[1][0]&&C[1][1]===N[1][1]||(Bs(y,v,x,{nodeOrigin:b,nodeExtent:C,elevateNodesOnSelect:k,checkEquality:!1,zIndexMode:I}),u({nodeExtent:C}))},panBy:C=>{const{transform:y,width:v,height:x,panZoom:b,translateExtent:k}=p();return Vc({delta:C,panZoom:b,transform:y,translateExtent:k,width:v,height:x})},setCenter:async(C,y,v)=>{const{width:x,height:b,maxZoom:k,panZoom:N}=p();if(!N)return Promise.resolve(!1);const I=typeof v?.zoom<"u"?v.zoom:k;return await N.setViewport({x:x/2-C*I,y:b/2-y*I,zoom:I},{duration:v?.duration,ease:v?.ease,interpolate:v?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{u({connection:{...li}})},updateConnection:C=>{u({connection:C})},reset:()=>u({...Sa()})}},Object.is);function af({initialNodes:e,initialEdges:n,defaultNodes:s,defaultEdges:r,initialWidth:i,initialHeight:o,initialMinZoom:a,initialMaxZoom:c,initialFitViewOptions:l,fitView:d,nodeOrigin:h,nodeExtent:f,zIndexMode:m,children:u}){const[p]=g.useState(()=>of({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:d,minZoom:a,maxZoom:c,fitViewOptions:l,nodeOrigin:h,nodeExtent:f,zIndexMode:m}));return t.jsx(Nd,{value:p,children:t.jsx(Gd,{children:u})})}function lf({children:e,nodes:n,edges:s,defaultNodes:r,defaultEdges:i,width:o,height:a,fitView:c,fitViewOptions:l,minZoom:d,maxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u}){return g.useContext(cs)?t.jsx(t.Fragment,{children:e}):t.jsx(af,{initialNodes:n,initialEdges:s,defaultNodes:r,defaultEdges:i,initialWidth:o,initialHeight:a,fitView:c,initialFitViewOptions:l,initialMinZoom:d,initialMaxZoom:h,nodeOrigin:f,nodeExtent:m,zIndexMode:u,children:e})}const cf={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function df({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,className:i,nodeTypes:o,edgeTypes:a,onNodeClick:c,onEdgeClick:l,onInit:d,onMove:h,onMoveStart:f,onMoveEnd:m,onConnect:u,onConnectStart:p,onConnectEnd:M,onClickConnectStart:C,onClickConnectEnd:y,onNodeMouseEnter:v,onNodeMouseMove:x,onNodeMouseLeave:b,onNodeContextMenu:k,onNodeDoubleClick:N,onNodeDragStart:I,onNodeDrag:B,onNodeDragStop:D,onNodesDelete:L,onEdgesDelete:E,onDelete:P,onSelectionChange:z,onSelectionDragStart:j,onSelectionDrag:O,onSelectionDragStop:_,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:A,onBeforeDelete:W,connectionMode:Y,connectionLineType:F=ln.Bezier,connectionLineStyle:Q,connectionLineComponent:$,connectionLineContainerStyle:S,deleteKeyCode:V="Backspace",selectionKeyCode:q="Shift",selectionOnDrag:H=!1,selectionMode:Z=gr.Full,panActivationKeyCode:J="Space",multiSelectionKeyCode:le=xr()?"Meta":"Control",zoomActivationKeyCode:te=xr()?"Meta":"Control",snapToGrid:X,snapGrid:ie,onlyRenderVisibleElements:de=!1,selectNodesOnDrag:se,nodesDraggable:me,autoPanOnNodeFocus:ue,nodesConnectable:K,nodesFocusable:ce,nodeOrigin:ge=Bi,edgesFocusable:ve,edgesReconnectable:fe,elementsSelectable:re=!0,defaultViewport:xe=$d,minZoom:Ee=.5,maxZoom:ye=2,translateExtent:Ie=mr,preventScrolling:pt=!0,nodeExtent:rt,defaultMarkerColor:Nt="#b1b1b7",zoomOnScroll:Ct=!0,zoomOnPinch:st=!0,panOnScroll:Ht=!1,panOnScrollSpeed:xt=.5,panOnScrollMode:Jt=Cn.Free,zoomOnDoubleClick:bt=!0,panOnDrag:yt=!0,onPaneClick:Ce,onPaneMouseEnter:Xe,onPaneMouseMove:$e,onPaneMouseLeave:Le,onPaneScroll:et,onPaneContextMenu:qt,paneClickDistance:Wt=1,nodeClickDistance:_e=0,children:Ye,onReconnect:tt,onReconnectStart:un,onReconnectEnd:Mn,onEdgeContextMenu:Ge,onEdgeDoubleClick:Ae,onEdgeMouseEnter:ze,onEdgeMouseMove:De,onEdgeMouseLeave:He,reconnectRadius:dt=10,onNodesChange:Qe,onEdgesChange:it,noDragClassName:ut="nodrag",noWheelClassName:en="nowheel",noPanClassName:Vt="nopan",fitView:St,fitViewOptions:Et,connectOnClick:Je,attributionPosition:ft,proOptions:fn,defaultEdgeOptions:ot,elevateNodesOnSelect:$t=!0,elevateEdgesOnSelect:vt=!1,disableKeyboardA11y:ht=!1,autoPanOnConnect:G,autoPanOnNodeDrag:pe,autoPanSpeed:Ne,connectionRadius:Me,isValidConnection:Se,onError:lt,style:Ft,id:Mt,nodeDragThreshold:tn,connectionDragThreshold:In,viewport:Jn,onViewportChange:hn,width:mn,height:gn,colorMode:Tn="light",debug:pn,onScroll:er,ariaLabelConfig:hs,zIndexMode:xn="basic",...Cr},nn){const It=Mt||"1",Sr=Hd(Tn),Er=g.useCallback(tr=>{tr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),er?.(tr)},[er]);return t.jsx("div",{"data-testid":"rf__wrapper",...Cr,onScroll:Er,style:{...Ft,...cf},ref:nn,className:Ze(["react-flow",i,Sr]),id:Mt,role:"application",children:t.jsxs(lf,{nodes:e,edges:n,width:mn,height:gn,fitView:St,fitViewOptions:Et,minZoom:Ee,maxZoom:ye,nodeOrigin:ge,nodeExtent:rt,zIndexMode:xn,children:[t.jsx(sf,{onInit:d,onNodeClick:c,onEdgeClick:l,onNodeMouseEnter:v,onNodeMouseMove:x,onNodeMouseLeave:b,onNodeContextMenu:k,onNodeDoubleClick:N,nodeTypes:o,edgeTypes:a,connectionLineType:F,connectionLineStyle:Q,connectionLineComponent:$,connectionLineContainerStyle:S,selectionKeyCode:q,selectionOnDrag:H,selectionMode:Z,deleteKeyCode:V,multiSelectionKeyCode:le,panActivationKeyCode:J,zoomActivationKeyCode:te,onlyRenderVisibleElements:de,defaultViewport:xe,translateExtent:Ie,minZoom:Ee,maxZoom:ye,preventScrolling:pt,zoomOnScroll:Ct,zoomOnPinch:st,zoomOnDoubleClick:bt,panOnScroll:Ht,panOnScrollSpeed:xt,panOnScrollMode:Jt,panOnDrag:yt,onPaneClick:Ce,onPaneMouseEnter:Xe,onPaneMouseMove:$e,onPaneMouseLeave:Le,onPaneScroll:et,onPaneContextMenu:qt,paneClickDistance:Wt,nodeClickDistance:_e,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:A,onReconnect:tt,onReconnectStart:un,onReconnectEnd:Mn,onEdgeContextMenu:Ge,onEdgeDoubleClick:Ae,onEdgeMouseEnter:ze,onEdgeMouseMove:De,onEdgeMouseLeave:He,reconnectRadius:dt,defaultMarkerColor:Nt,noDragClassName:ut,noWheelClassName:en,noPanClassName:Vt,rfId:It,disableKeyboardA11y:ht,nodeExtent:rt,viewport:Jn,onViewportChange:hn}),t.jsx(zd,{nodes:e,edges:n,defaultNodes:s,defaultEdges:r,onConnect:u,onConnectStart:p,onConnectEnd:M,onClickConnectStart:C,onClickConnectEnd:y,nodesDraggable:me,autoPanOnNodeFocus:ue,nodesConnectable:K,nodesFocusable:ce,edgesFocusable:ve,edgesReconnectable:fe,elementsSelectable:re,elevateNodesOnSelect:$t,elevateEdgesOnSelect:vt,minZoom:Ee,maxZoom:ye,nodeExtent:rt,onNodesChange:Qe,onEdgesChange:it,snapToGrid:X,snapGrid:ie,connectionMode:Y,translateExtent:Ie,connectOnClick:Je,defaultEdgeOptions:ot,fitView:St,fitViewOptions:Et,onNodesDelete:L,onEdgesDelete:E,onDelete:P,onNodeDragStart:I,onNodeDrag:B,onNodeDragStop:D,onSelectionDrag:O,onSelectionDragStart:j,onSelectionDragStop:_,onMove:h,onMoveStart:f,onMoveEnd:m,noPanClassName:Vt,nodeOrigin:ge,rfId:It,autoPanOnConnect:G,autoPanOnNodeDrag:pe,autoPanSpeed:Ne,onError:lt,connectionRadius:Me,isValidConnection:Se,selectNodesOnDrag:se,nodeDragThreshold:tn,connectionDragThreshold:In,onBeforeDelete:W,debug:pn,ariaLabelConfig:hs,zIndexMode:xn}),t.jsx(Pd,{onSelectionChange:z}),Ye,t.jsx(Rd,{proOptions:fn,position:ft}),t.jsx(Td,{rfId:It,disableKeyboardA11y:ht})]})})}var uf=Wi(df);function ff(){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 c=s?.querySelector(`.react-flow__node[data-id="${a}"]`);c&&o.set(a,{id:a,nodeElement:c,force:!0})}),requestAnimationFrame(()=>r(o,{triggerFitView:!1}))},[])}function hf(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>Hi(i,o)),[]);return[n,s,r]}function mf(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>qi(i,o)),[]);return[n,s,r]}function gf({dimensions:e,lineWidth:n,variant:s,className:r}){return t.jsx("path",{strokeWidth:n,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Ze(["react-flow__background-pattern",s,r])})}function pf({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Ze(["react-flow__background-pattern","dots",n])})}var cn;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(cn||(cn={}));const xf={[cn.Dots]:1,[cn.Lines]:1,[cn.Cross]:6},bf=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function hl({id:e,variant:n=cn.Dots,gap:s=20,size:r,lineWidth:i=1,offset:o=0,color:a,bgColor:c,style:l,className:d,patternClassName:h}){const f=g.useRef(null),{transform:m,patternId:u}=Te(bf,qe),p=r||xf[n],M=n===cn.Dots,C=n===cn.Cross,y=Array.isArray(s)?s:[s,s],v=[y[0]*m[2]||1,y[1]*m[2]||1],x=p*m[2],b=Array.isArray(o)?o:[o,o],k=C?[x,x]:v,N=[b[0]*m[2]||1+k[0]/2,b[1]*m[2]||1+k[1]/2],I=`${u}${e||""}`;return t.jsxs("svg",{className:Ze(["react-flow__background",d]),style:{...l,...us,"--xy-background-color-props":c,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[t.jsx("pattern",{id:I,x:m[0]%v[0],y:m[1]%v[1],width:v[0],height:v[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${N[0]},-${N[1]})`,children:M?t.jsx(pf,{radius:x/2,className:h}):t.jsx(gf,{dimensions:k,lineWidth:i,variant:n,className:h})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${I})`})]})}hl.displayName="Background";const yf=g.memo(hl);function vf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:t.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function wf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:t.jsx("path",{d:"M0 0h32v4.2H0z"})})}function kf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:t.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function jf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function Nf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Fr({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:Ze(["react-flow__controls-button",n]),...s,children:e})}const Cf=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function ml({style:e,showZoom:n=!0,showFitView:s=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:o,onZoomOut:a,onFitView:c,onInteractiveChange:l,className:d,children:h,position:f="bottom-left",orientation:m="vertical","aria-label":u}){const p=Be(),{isInteractive:M,minZoomReached:C,maxZoomReached:y,ariaLabelConfig:v}=Te(Cf,qe),{zoomIn:x,zoomOut:b,fitView:k}=to(),N=()=>{x(),o?.()},I=()=>{b(),a?.()},B=()=>{k(i),c?.()},D=()=>{p.setState({nodesDraggable:!M,nodesConnectable:!M,elementsSelectable:!M}),l?.(!M)},L=m==="horizontal"?"horizontal":"vertical";return t.jsxs(ds,{className:Ze(["react-flow__controls",L,d]),position:f,style:e,"data-testid":"rf__controls","aria-label":u??v["controls.ariaLabel"],children:[n&&t.jsxs(t.Fragment,{children:[t.jsx(Fr,{onClick:N,className:"react-flow__controls-zoomin",title:v["controls.zoomIn.ariaLabel"],"aria-label":v["controls.zoomIn.ariaLabel"],disabled:y,children:t.jsx(vf,{})}),t.jsx(Fr,{onClick:I,className:"react-flow__controls-zoomout",title:v["controls.zoomOut.ariaLabel"],"aria-label":v["controls.zoomOut.ariaLabel"],disabled:C,children:t.jsx(wf,{})})]}),s&&t.jsx(Fr,{className:"react-flow__controls-fitview",onClick:B,title:v["controls.fitView.ariaLabel"],"aria-label":v["controls.fitView.ariaLabel"],children:t.jsx(kf,{})}),r&&t.jsx(Fr,{className:"react-flow__controls-interactive",onClick:D,title:v["controls.interactive.ariaLabel"],"aria-label":v["controls.interactive.ariaLabel"],children:M?t.jsx(Nf,{}):t.jsx(jf,{})}),h]})}ml.displayName="Controls";const Sf=g.memo(ml);function Ef({id:e,x:n,y:s,width:r,height:i,style:o,color:a,strokeColor:c,strokeWidth:l,className:d,borderRadius:h,shapeRendering:f,selected:m,onClick:u}){const{background:p,backgroundColor:M}=o||{},C=a||p||M;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:C,stroke:c,strokeWidth:l},shapeRendering:f,onClick:u?y=>u(y,e):void 0})}const Mf=g.memo(Ef),If=e=>e.nodes.map(n=>n.id),Rs=e=>e instanceof Function?e:()=>e;function Tf({nodeStrokeColor:e,nodeColor:n,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:o=Mf,onClick:a}){const c=Te(If,qe),l=Rs(n),d=Rs(e),h=Rs(s),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return t.jsx(t.Fragment,{children:c.map(m=>t.jsx(_f,{id:m,nodeColorFunc:l,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:o,onClick:a,shapeRendering:f},m))})}function Rf({id:e,nodeColorFunc:n,nodeStrokeColorFunc:s,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:o,shapeRendering:a,NodeComponent:c,onClick:l}){const{node:d,x:h,y:f,width:m,height:u}=Te(p=>{const M=p.nodeLookup.get(e);if(!M)return{node:void 0,x:0,y:0,width:0,height:0};const C=M.internals.userNode,{x:y,y:v}=M.internals.positionAbsolute,{width:x,height:b}=Qt(C);return{node:C,x:y,y:v,width:x,height:b}},qe);return!d||d.hidden||!gi(d)?null:t.jsx(c,{x:h,y:f,width:m,height:u,style:d.style,selected:!!d.selected,className:r(d),color:n(d),borderRadius:i,strokeColor:s(d),strokeWidth:o,shapeRendering:a,onClick:l,id:d.id})}const _f=g.memo(Rf);var Lf=g.memo(Tf);const Af=200,Df=150,Pf=e=>!e.hidden,$f=e=>{const n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:e.nodeLookup.size>0?mi(kr(e.nodeLookup,{filter:Pf}),n):n,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Of="react-flow__minimap-desc";function gl({style:e,className:n,nodeStrokeColor:s,nodeColor:r,nodeClassName:i="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:c,bgColor:l,maskColor:d,maskStrokeColor:h,maskStrokeWidth:f,position:m="bottom-right",onClick:u,onNodeClick:p,pannable:M=!1,zoomable:C=!1,ariaLabel:y,inversePan:v,zoomStep:x=1,offsetScale:b=5}){const k=Be(),N=g.useRef(null),{boundingRect:I,viewBB:B,rfId:D,panZoom:L,translateExtent:E,flowWidth:P,flowHeight:z,ariaLabelConfig:j}=Te($f,qe),O=e?.width??Af,_=e?.height??Df,T=I.width/O,R=I.height/_,A=Math.max(T,R),W=A*O,Y=A*_,F=b*A,Q=I.x-(W-I.width)/2-F,$=I.y-(Y-I.height)/2-F,S=W+F*2,V=Y+F*2,q=`${Of}-${D}`,H=g.useRef(0),Z=g.useRef();H.current=A,g.useEffect(()=>{if(N.current&&L)return Z.current=Jc({domNode:N.current,panZoom:L,getTransform:()=>k.getState().transform,getViewScale:()=>H.current}),()=>{Z.current?.destroy()}},[L]),g.useEffect(()=>{Z.current?.update({translateExtent:E,width:P,height:z,inversePan:v,pannable:M,zoomStep:x,zoomable:C})},[M,C,v,x,E,P,z]);const J=u?X=>{const[ie,de]=Z.current?.pointer(X)||[0,0];u(X,{x:ie,y:de})}:void 0,le=p?g.useCallback((X,ie)=>{const de=k.getState().nodeLookup.get(ie).internals.userNode;p(X,de)},[]):void 0,te=y??j["minimap.ariaLabel"];return t.jsx(ds,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*A: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:O,height:_,viewBox:`${Q} ${$} ${S} ${V}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":q,ref:N,onClick:J,children:[te&&t.jsx("title",{id:q,children:te}),t.jsx(Lf,{onClick:le,nodeColor:r,nodeStrokeColor:s,nodeBorderRadius:o,nodeClassName:i,nodeStrokeWidth:a,nodeComponent:c}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${Q-F},${$-F}h${S+F*2}v${V+F*2}h${-S-F*2}z
7
+ M${B.x},${B.y}h${B.width}v${B.height}h${-B.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}gl.displayName="MiniMap";const Bf=g.memo(gl),zf=e=>n=>e?`${Math.max(1/n.transform[2],1)}`:void 0,Hf={[Un.Line]:"right",[Un.Handle]:"bottom-right"};function qf({nodeId:e,position:n,variant:s=Un.Handle,className:r,style:i=void 0,children:o,color:a,minWidth:c=10,minHeight:l=10,maxWidth:d=Number.MAX_VALUE,maxHeight:h=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:m,autoScale:u=!0,shouldResize:p,onResizeStart:M,onResize:C,onResizeEnd:y}){const v=Gi(),x=typeof e=="string"?e:v,b=Be(),k=g.useRef(null),N=s===Un.Handle,I=Te(g.useCallback(zf(N&&u),[N,u]),qe),B=g.useRef(null),D=n??Hf[s];g.useEffect(()=>{if(!(!k.current||!x))return B.current||(B.current=hd({domNode:k.current,nodeId:x,getStoreItems:()=>{const{nodeLookup:E,transform:P,snapGrid:z,snapToGrid:j,nodeOrigin:O,domNode:_}=b.getState();return{nodeLookup:E,transform:P,snapGrid:z,snapToGrid:j,nodeOrigin:O,paneDomNode:_}},onChange:(E,P)=>{const{triggerNodeChanges:z,nodeLookup:j,parentLookup:O,nodeOrigin:_}=b.getState(),T=[],R={x:E.x,y:E.y},A=j.get(x);if(A&&A.expandParent&&A.parentId){const W=A.origin??_,Y=E.width??A.measured.width??0,F=E.height??A.measured.height??0,Q={id:A.id,parentId:A.parentId,rect:{width:Y,height:F,...pi({x:E.x??A.position.x,y:E.y??A.position.y},{width:Y,height:F},A.parentId,j,W)}},$=eo([Q],j,O,_);T.push(...$),R.x=E.x?Math.max(W[0]*Y,E.x):void 0,R.y=E.y?Math.max(W[1]*F,E.y):void 0}if(R.x!==void 0&&R.y!==void 0){const W={id:x,type:"position",position:{...R}};T.push(W)}if(E.width!==void 0&&E.height!==void 0){const Y={id:x,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:E.width,height:E.height}};T.push(Y)}for(const W of P){const Y={...W,type:"position"};T.push(Y)}z(T)},onEnd:({width:E,height:P})=>{const z={id:x,type:"dimensions",resizing:!1,dimensions:{width:E,height:P}};b.getState().triggerNodeChanges([z])}})),B.current.update({controlPosition:D,boundaries:{minWidth:c,minHeight:l,maxWidth:d,maxHeight:h},keepAspectRatio:f,resizeDirection:m,onResizeStart:M,onResize:C,onResizeEnd:y,shouldResize:p}),()=>{B.current?.destroy()}},[D,c,l,d,h,f,M,C,y,p]);const L=D.split("-");return t.jsx("div",{className:Ze(["react-flow__resize-control","nodrag",...L,s,r]),ref:k,style:{...i,scale:I,...a&&{[N?"backgroundColor":"borderColor"]:a}},children:o})}g.memo(qf);var Pe=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),Pt=Pe((e,n)=>{var s=Object.defineProperty,r=(z,j,O)=>j in z?s(z,j,{enumerable:!0,configurable:!0,writable:!0,value:O}):z[j]=O,i=(z,j)=>()=>(j||z((j={exports:{}}).exports,j),j.exports),o=(z,j,O)=>r(z,typeof j!="symbol"?j+"":j,O),a=i((z,j)=>{var O="\0",_="\0",T="",R=class{constructor($){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"),$&&(this._isDirected=Object.hasOwn($,"directed")?$.directed:!0,this._isMultigraph=Object.hasOwn($,"multigraph")?$.multigraph:!1,this._isCompound=Object.hasOwn($,"compound")?$.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[_]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph($){return this._label=$,this}graph(){return this._label}setDefaultNodeLabel($){return this._defaultNodeLabelFn=$,typeof $!="function"&&(this._defaultNodeLabelFn=()=>$),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var $=this;return this.nodes().filter(S=>Object.keys($._in[S]).length===0)}sinks(){var $=this;return this.nodes().filter(S=>Object.keys($._out[S]).length===0)}setNodes($,S){var V=arguments,q=this;return $.forEach(function(H){V.length>1?q.setNode(H,S):q.setNode(H)}),this}setNode($,S){return Object.hasOwn(this._nodes,$)?(arguments.length>1&&(this._nodes[$]=S),this):(this._nodes[$]=arguments.length>1?S:this._defaultNodeLabelFn($),this._isCompound&&(this._parent[$]=_,this._children[$]={},this._children[_][$]=!0),this._in[$]={},this._preds[$]={},this._out[$]={},this._sucs[$]={},++this._nodeCount,this)}node($){return this._nodes[$]}hasNode($){return Object.hasOwn(this._nodes,$)}removeNode($){var S=this;if(Object.hasOwn(this._nodes,$)){var V=q=>S.removeEdge(S._edgeObjs[q]);delete this._nodes[$],this._isCompound&&(this._removeFromParentsChildList($),delete this._parent[$],this.children($).forEach(function(q){S.setParent(q)}),delete this._children[$]),Object.keys(this._in[$]).forEach(V),delete this._in[$],delete this._preds[$],Object.keys(this._out[$]).forEach(V),delete this._out[$],delete this._sucs[$],--this._nodeCount}return this}setParent($,S){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(S===void 0)S=_;else{S+="";for(var V=S;V!==void 0;V=this.parent(V))if(V===$)throw new Error("Setting "+S+" as parent of "+$+" would create a cycle");this.setNode(S)}return this.setNode($),this._removeFromParentsChildList($),this._parent[$]=S,this._children[S][$]=!0,this}_removeFromParentsChildList($){delete this._children[this._parent[$]][$]}parent($){if(this._isCompound){var S=this._parent[$];if(S!==_)return S}}children($=_){if(this._isCompound){var S=this._children[$];if(S)return Object.keys(S)}else{if($===_)return this.nodes();if(this.hasNode($))return[]}}predecessors($){var S=this._preds[$];if(S)return Object.keys(S)}successors($){var S=this._sucs[$];if(S)return Object.keys(S)}neighbors($){var S=this.predecessors($);if(S){let q=new Set(S);for(var V of this.successors($))q.add(V);return Array.from(q.values())}}isLeaf($){var S;return this.isDirected()?S=this.successors($):S=this.neighbors($),S.length===0}filterNodes($){var S=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});S.setGraph(this.graph());var V=this;Object.entries(this._nodes).forEach(function([Z,J]){$(Z)&&S.setNode(Z,J)}),Object.values(this._edgeObjs).forEach(function(Z){S.hasNode(Z.v)&&S.hasNode(Z.w)&&S.setEdge(Z,V.edge(Z))});var q={};function H(Z){var J=V.parent(Z);return J===void 0||S.hasNode(J)?(q[Z]=J,J):J in q?q[J]:H(J)}return this._isCompound&&S.nodes().forEach(Z=>S.setParent(Z,H(Z))),S}setDefaultEdgeLabel($){return this._defaultEdgeLabelFn=$,typeof $!="function"&&(this._defaultEdgeLabelFn=()=>$),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath($,S){var V=this,q=arguments;return $.reduce(function(H,Z){return q.length>1?V.setEdge(H,Z,S):V.setEdge(H,Z),Z}),this}setEdge(){var $,S,V,q,H=!1,Z=arguments[0];typeof Z=="object"&&Z!==null&&"v"in Z?($=Z.v,S=Z.w,V=Z.name,arguments.length===2&&(q=arguments[1],H=!0)):($=Z,S=arguments[1],V=arguments[3],arguments.length>2&&(q=arguments[2],H=!0)),$=""+$,S=""+S,V!==void 0&&(V=""+V);var J=Y(this._isDirected,$,S,V);if(Object.hasOwn(this._edgeLabels,J))return H&&(this._edgeLabels[J]=q),this;if(V!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode($),this.setNode(S),this._edgeLabels[J]=H?q:this._defaultEdgeLabelFn($,S,V);var le=F(this._isDirected,$,S,V);return $=le.v,S=le.w,Object.freeze(le),this._edgeObjs[J]=le,A(this._preds[S],$),A(this._sucs[$],S),this._in[S][J]=le,this._out[$][J]=le,this._edgeCount++,this}edge($,S,V){var q=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,S,V);return this._edgeLabels[q]}edgeAsObj(){let $=this.edge(...arguments);return typeof $!="object"?{label:$}:$}hasEdge($,S,V){var q=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,S,V);return Object.hasOwn(this._edgeLabels,q)}removeEdge($,S,V){var q=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,S,V),H=this._edgeObjs[q];return H&&($=H.v,S=H.w,delete this._edgeLabels[q],delete this._edgeObjs[q],W(this._preds[S],$),W(this._sucs[$],S),delete this._in[S][q],delete this._out[$][q],this._edgeCount--),this}inEdges($,S){return this.isDirected()?this.filterEdges(this._in[$],$,S):this.nodeEdges($,S)}outEdges($,S){return this.isDirected()?this.filterEdges(this._out[$],$,S):this.nodeEdges($,S)}nodeEdges($,S){if($ in this._nodes)return this.filterEdges({...this._in[$],...this._out[$]},$,S)}filterEdges($,S,V){if($){var q=Object.values($);return V?q.filter(function(H){return H.v===S&&H.w===V||H.v===V&&H.w===S}):q}}};function A($,S){$[S]?$[S]++:$[S]=1}function W($,S){--$[S]||delete $[S]}function Y($,S,V,q){var H=""+S,Z=""+V;if(!$&&H>Z){var J=H;H=Z,Z=J}return H+T+Z+T+(q===void 0?O:q)}function F($,S,V,q){var H=""+S,Z=""+V;if(!$&&H>Z){var J=H;H=Z,Z=J}var le={v:H,w:Z};return q&&(le.name=q),le}function Q($,S){return Y($,S.v,S.w,S.name)}j.exports=R}),c=i((z,j)=>{j.exports="3.0.2"}),l=i((z,j)=>{j.exports={Graph:a(),version:c()}}),d=i((z,j)=>{var O=a();j.exports={write:_,read:A};function _(W){var Y={options:{directed:W.isDirected(),multigraph:W.isMultigraph(),compound:W.isCompound()},nodes:T(W),edges:R(W)};return W.graph()!==void 0&&(Y.value=structuredClone(W.graph())),Y}function T(W){return W.nodes().map(function(Y){var F=W.node(Y),Q=W.parent(Y),$={v:Y};return F!==void 0&&($.value=F),Q!==void 0&&($.parent=Q),$})}function R(W){return W.edges().map(function(Y){var F=W.edge(Y),Q={v:Y.v,w:Y.w};return Y.name!==void 0&&(Q.name=Y.name),F!==void 0&&(Q.value=F),Q})}function A(W){var Y=new O(W.options).setGraph(W.value);return W.nodes.forEach(function(F){Y.setNode(F.v,F.value),F.parent&&Y.setParent(F.v,F.parent)}),W.edges.forEach(function(F){Y.setEdge({v:F.v,w:F.w,name:F.name},F.value)}),Y}}),h=i((z,j)=>{j.exports=_;var O=()=>1;function _(R,A,W,Y){return T(R,String(A),W||O,Y||function(F){return R.outEdges(F)})}function T(R,A,W,Y){var F={},Q=!0,$=0,S=R.nodes(),V=function(J){var le=W(J);F[J.v].distance+le<F[J.w].distance&&(F[J.w]={distance:F[J.v].distance+le,predecessor:J.v},Q=!0)},q=function(){S.forEach(function(J){Y(J).forEach(function(le){var te=le.v===J?le.v:le.w,X=te===le.v?le.w:le.v;V({v:te,w:X})})})};S.forEach(function(J){var le=J===A?0:Number.POSITIVE_INFINITY;F[J]={distance:le}});for(var H=S.length,Z=1;Z<H&&(Q=!1,$++,q(),!!Q);Z++);if($===H-1&&(Q=!1,q(),Q))throw new Error("The graph contains a negative weight cycle");return F}}),f=i((z,j)=>{j.exports=O;function O(_){var T={},R=[],A;function W(Y){Object.hasOwn(T,Y)||(T[Y]=!0,A.push(Y),_.successors(Y).forEach(W),_.predecessors(Y).forEach(W))}return _.nodes().forEach(function(Y){A=[],W(Y),A.length&&R.push(A)}),R}}),m=i((z,j)=>{var O=class{constructor(){o(this,"_arr",[]),o(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(_){return _.key})}has(_){return Object.hasOwn(this._keyIndices,_)}priority(_){var T=this._keyIndices[_];if(T!==void 0)return this._arr[T].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(_,T){var R=this._keyIndices;if(_=String(_),!Object.hasOwn(R,_)){var A=this._arr,W=A.length;return R[_]=W,A.push({key:_,priority:T}),this._decrease(W),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var _=this._arr.pop();return delete this._keyIndices[_.key],this._heapify(0),_.key}decrease(_,T){var R=this._keyIndices[_];if(T>this._arr[R].priority)throw new Error("New priority is greater than current priority. Key: "+_+" Old: "+this._arr[R].priority+" New: "+T);this._arr[R].priority=T,this._decrease(R)}_heapify(_){var T=this._arr,R=2*_,A=R+1,W=_;R<T.length&&(W=T[R].priority<T[W].priority?R:W,A<T.length&&(W=T[A].priority<T[W].priority?A:W),W!==_&&(this._swap(_,W),this._heapify(W)))}_decrease(_){for(var T=this._arr,R=T[_].priority,A;_!==0&&(A=_>>1,!(T[A].priority<R));)this._swap(_,A),_=A}_swap(_,T){var R=this._arr,A=this._keyIndices,W=R[_],Y=R[T];R[_]=Y,R[T]=W,A[Y.key]=_,A[W.key]=T}};j.exports=O}),u=i((z,j)=>{var O=m();j.exports=T;var _=()=>1;function T(A,W,Y,F){var Q=function($){return A.outEdges($)};return R(A,String(W),Y||_,F||Q)}function R(A,W,Y,F){var Q={},$=new O,S,V,q=function(H){var Z=H.v!==S?H.v:H.w,J=Q[Z],le=Y(H),te=V.distance+le;if(le<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+H+" Weight: "+le);te<J.distance&&(J.distance=te,J.predecessor=S,$.decrease(Z,te))};for(A.nodes().forEach(function(H){var Z=H===W?0:Number.POSITIVE_INFINITY;Q[H]={distance:Z},$.add(H,Z)});$.size()>0&&(S=$.removeMin(),V=Q[S],V.distance!==Number.POSITIVE_INFINITY);)F(S).forEach(q);return Q}}),p=i((z,j)=>{var O=u();j.exports=_;function _(T,R,A){return T.nodes().reduce(function(W,Y){return W[Y]=O(T,Y,R,A),W},{})}}),M=i((z,j)=>{j.exports=O;function O(T,R,A){if(T[R].predecessor!==void 0)throw new Error("Invalid source vertex");if(T[A].predecessor===void 0&&A!==R)throw new Error("Invalid destination vertex");return{weight:T[A].distance,path:_(T,R,A)}}function _(T,R,A){for(var W=[],Y=A;Y!==R;)W.push(Y),Y=T[Y].predecessor;return W.push(R),W.reverse()}}),C=i((z,j)=>{j.exports=O;function O(_){var T=0,R=[],A={},W=[];function Y(F){var Q=A[F]={onStack:!0,lowlink:T,index:T++};if(R.push(F),_.successors(F).forEach(function(V){Object.hasOwn(A,V)?A[V].onStack&&(Q.lowlink=Math.min(Q.lowlink,A[V].index)):(Y(V),Q.lowlink=Math.min(Q.lowlink,A[V].lowlink))}),Q.lowlink===Q.index){var $=[],S;do S=R.pop(),A[S].onStack=!1,$.push(S);while(F!==S);W.push($)}}return _.nodes().forEach(function(F){Object.hasOwn(A,F)||Y(F)}),W}}),y=i((z,j)=>{var O=C();j.exports=_;function _(T){return O(T).filter(function(R){return R.length>1||R.length===1&&T.hasEdge(R[0],R[0])})}}),v=i((z,j)=>{j.exports=_;var O=()=>1;function _(R,A,W){return T(R,A||O,W||function(Y){return R.outEdges(Y)})}function T(R,A,W){var Y={},F=R.nodes();return F.forEach(function(Q){Y[Q]={},Y[Q][Q]={distance:0},F.forEach(function($){Q!==$&&(Y[Q][$]={distance:Number.POSITIVE_INFINITY})}),W(Q).forEach(function($){var S=$.v===Q?$.w:$.v,V=A($);Y[Q][S]={distance:V,predecessor:Q}})}),F.forEach(function(Q){var $=Y[Q];F.forEach(function(S){var V=Y[S];F.forEach(function(q){var H=V[Q],Z=$[q],J=V[q],le=H.distance+Z.distance;le<J.distance&&(J.distance=le,J.predecessor=Z.predecessor)})})}),Y}}),x=i((z,j)=>{function O(T){var R={},A={},W=[];function Y(F){if(Object.hasOwn(A,F))throw new _;Object.hasOwn(R,F)||(A[F]=!0,R[F]=!0,T.predecessors(F).forEach(Y),delete A[F],W.push(F))}if(T.sinks().forEach(Y),Object.keys(R).length!==T.nodeCount())throw new _;return W}var _=class extends Error{constructor(){super(...arguments)}};j.exports=O,O.CycleException=_}),b=i((z,j)=>{var O=x();j.exports=_;function _(T){try{O(T)}catch(R){if(R instanceof O.CycleException)return!1;throw R}return!0}}),k=i((z,j)=>{j.exports=O;function O(T,R,A,W,Y){Array.isArray(R)||(R=[R]);var F=(T.isDirected()?T.successors:T.neighbors).bind(T),Q={};return R.forEach(function($){if(!T.hasNode($))throw new Error("Graph does not have node: "+$);Y=_(T,$,A==="post",Q,F,W,Y)}),Y}function _(T,R,A,W,Y,F,Q){return Object.hasOwn(W,R)||(W[R]=!0,A||(Q=F(Q,R)),Y(R).forEach(function($){Q=_(T,$,A,W,Y,F,Q)}),A&&(Q=F(Q,R))),Q}}),N=i((z,j)=>{var O=k();j.exports=_;function _(T,R,A){return O(T,R,A,function(W,Y){return W.push(Y),W},[])}}),I=i((z,j)=>{var O=N();j.exports=_;function _(T,R){return O(T,R,"post")}}),B=i((z,j)=>{var O=N();j.exports=_;function _(T,R){return O(T,R,"pre")}}),D=i((z,j)=>{var O=a(),_=m();j.exports=T;function T(R,A){var W=new O,Y={},F=new _,Q;function $(V){var q=V.v===Q?V.w:V.v,H=F.priority(q);if(H!==void 0){var Z=A(V);Z<H&&(Y[q]=Q,F.decrease(q,Z))}}if(R.nodeCount()===0)return W;R.nodes().forEach(function(V){F.add(V,Number.POSITIVE_INFINITY),W.setNode(V)}),F.decrease(R.nodes()[0],0);for(var S=!1;F.size()>0;){if(Q=F.removeMin(),Object.hasOwn(Y,Q))W.setEdge(Q,Y[Q]);else{if(S)throw new Error("Input graph is not connected: "+R);S=!0}R.nodeEdges(Q).forEach($)}return W}}),L=i((z,j)=>{var O=u(),_=h();j.exports=T;function T(A,W,Y,F){return R(A,W,Y,F||function(Q){return A.outEdges(Q)})}function R(A,W,Y,F){if(Y===void 0)return O(A,W,Y,F);for(var Q=!1,$=A.nodes(),S=0;S<$.length;S++){for(var V=F($[S]),q=0;q<V.length;q++){var H=V[q],Z=H.v===$[S]?H.v:H.w,J=Z===H.v?H.w:H.v;Y({v:Z,w:J})<0&&(Q=!0)}if(Q)return _(A,W,Y,F)}return O(A,W,Y,F)}}),E=i((z,j)=>{j.exports={bellmanFord:h(),components:f(),dijkstra:u(),dijkstraAll:p(),extractPath:M(),findCycles:y(),floydWarshall:v(),isAcyclic:b(),postorder:I(),preorder:B(),prim:D(),shortestPaths:L(),reduce:k(),tarjan:C(),topsort:x()}}),P=l();n.exports={Graph:P.Graph,json:d(),alg:E(),version:P.version}}),Wf=Pe((e,n)=>{var s=class{constructor(){let o={};o._next=o._prev=o,this._sentinel=o}dequeue(){let o=this._sentinel,a=o._prev;if(a!==o)return r(a),a}enqueue(o){let a=this._sentinel;o._prev&&o._next&&r(o),o._next=a._next,a._next._prev=o,a._next=o,o._prev=a}toString(){let o=[],a=this._sentinel,c=a._prev;for(;c!==a;)o.push(JSON.stringify(c,i)),c=c._prev;return"["+o.join(", ")+"]"}};function r(o){o._prev._next=o._next,o._next._prev=o._prev,delete o._next,delete o._prev}function i(o,a){if(o!=="_next"&&o!=="_prev")return a}n.exports=s}),Vf=Pe((e,n)=>{var s=Pt().Graph,r=Wf();n.exports=o;var i=()=>1;function o(f,m){if(f.nodeCount()<=1)return[];let u=l(f,m||i);return a(u.graph,u.buckets,u.zeroIdx).flatMap(p=>f.outEdges(p.v,p.w))}function a(f,m,u){let p=[],M=m[m.length-1],C=m[0],y;for(;f.nodeCount();){for(;y=C.dequeue();)c(f,m,u,y);for(;y=M.dequeue();)c(f,m,u,y);if(f.nodeCount()){for(let v=m.length-2;v>0;--v)if(y=m[v].dequeue(),y){p=p.concat(c(f,m,u,y,!0));break}}}return p}function c(f,m,u,p,M){let C=M?[]:void 0;return f.inEdges(p.v).forEach(y=>{let v=f.edge(y),x=f.node(y.v);M&&C.push({v:y.v,w:y.w}),x.out-=v,d(m,u,x)}),f.outEdges(p.v).forEach(y=>{let v=f.edge(y),x=y.w,b=f.node(x);b.in-=v,d(m,u,b)}),f.removeNode(p.v),C}function l(f,m){let u=new s,p=0,M=0;f.nodes().forEach(v=>{u.setNode(v,{v,in:0,out:0})}),f.edges().forEach(v=>{let x=u.edge(v.v,v.w)||0,b=m(v),k=x+b;u.setEdge(v.v,v.w,k),M=Math.max(M,u.node(v.v).out+=b),p=Math.max(p,u.node(v.w).in+=b)});let C=h(M+p+3).map(()=>new r),y=p+1;return u.nodes().forEach(v=>{d(C,y,u.node(v))}),{graph:u,buckets:C,zeroIdx:y}}function d(f,m,u){u.out?u.in?f[u.out-u.in+m].enqueue(u):f[f.length-1].enqueue(u):f[0].enqueue(u)}function h(f){let m=[];for(let u=0;u<f;u++)m.push(u);return m}}),Ke=Pe((e,n)=>{var s=Pt().Graph;n.exports={addBorderNode:m,addDummyNode:r,applyWithChunking:M,asNonCompoundGraph:o,buildLayerMatrix:d,intersectRect:l,mapValues:B,maxRank:C,normalizeRanks:h,notime:x,partition:y,pick:I,predecessorWeights:c,range:N,removeEmptyRanks:f,simplify:i,successorWeights:a,time:v,uniqueId:k,zipObject:D};function r(L,E,P,z){for(var j=z;L.hasNode(j);)j=k(z);return P.dummy=E,L.setNode(j,P),j}function i(L){let E=new s().setGraph(L.graph());return L.nodes().forEach(P=>E.setNode(P,L.node(P))),L.edges().forEach(P=>{let z=E.edge(P.v,P.w)||{weight:0,minlen:1},j=L.edge(P);E.setEdge(P.v,P.w,{weight:z.weight+j.weight,minlen:Math.max(z.minlen,j.minlen)})}),E}function o(L){let E=new s({multigraph:L.isMultigraph()}).setGraph(L.graph());return L.nodes().forEach(P=>{L.children(P).length||E.setNode(P,L.node(P))}),L.edges().forEach(P=>{E.setEdge(P,L.edge(P))}),E}function a(L){let E=L.nodes().map(P=>{let z={};return L.outEdges(P).forEach(j=>{z[j.w]=(z[j.w]||0)+L.edge(j).weight}),z});return D(L.nodes(),E)}function c(L){let E=L.nodes().map(P=>{let z={};return L.inEdges(P).forEach(j=>{z[j.v]=(z[j.v]||0)+L.edge(j).weight}),z});return D(L.nodes(),E)}function l(L,E){let P=L.x,z=L.y,j=E.x-P,O=E.y-z,_=L.width/2,T=L.height/2;if(!j&&!O)throw new Error("Not possible to find intersection inside of the rectangle");let R,A;return Math.abs(O)*_>Math.abs(j)*T?(O<0&&(T=-T),R=T*j/O,A=T):(j<0&&(_=-_),R=_,A=_*O/j),{x:P+R,y:z+A}}function d(L){let E=N(C(L)+1).map(()=>[]);return L.nodes().forEach(P=>{let z=L.node(P),j=z.rank;j!==void 0&&(E[j][z.order]=P)}),E}function h(L){let E=L.nodes().map(z=>{let j=L.node(z).rank;return j===void 0?Number.MAX_VALUE:j}),P=M(Math.min,E);L.nodes().forEach(z=>{let j=L.node(z);Object.hasOwn(j,"rank")&&(j.rank-=P)})}function f(L){let E=L.nodes().map(_=>L.node(_).rank).filter(_=>_!==void 0),P=M(Math.min,E),z=[];L.nodes().forEach(_=>{let T=L.node(_).rank-P;z[T]||(z[T]=[]),z[T].push(_)});let j=0,O=L.graph().nodeRankFactor;Array.from(z).forEach((_,T)=>{_===void 0&&T%O!==0?--j:_!==void 0&&j&&_.forEach(R=>L.node(R).rank+=j)})}function m(L,E,P,z){let j={width:0,height:0};return arguments.length>=4&&(j.rank=P,j.order=z),r(L,"border",j,E)}function u(L,E=p){let P=[];for(let z=0;z<L.length;z+=E){let j=L.slice(z,z+E);P.push(j)}return P}var p=65535;function M(L,E){if(E.length>p){let P=u(E);return L.apply(null,P.map(z=>L.apply(null,z)))}else return L.apply(null,E)}function C(L){let E=L.nodes().map(P=>{let z=L.node(P).rank;return z===void 0?Number.MIN_VALUE:z});return M(Math.max,E)}function y(L,E){let P={lhs:[],rhs:[]};return L.forEach(z=>{E(z)?P.lhs.push(z):P.rhs.push(z)}),P}function v(L,E){let P=Date.now();try{return E()}finally{console.log(L+" time: "+(Date.now()-P)+"ms")}}function x(L,E){return E()}var b=0;function k(L){var E=++b;return L+(""+E)}function N(L,E,P=1){E==null&&(E=L,L=0);let z=O=>O<E;P<0&&(z=O=>E<O);let j=[];for(let O=L;z(O);O+=P)j.push(O);return j}function I(L,E){let P={};for(let z of E)L[z]!==void 0&&(P[z]=L[z]);return P}function B(L,E){let P=E;return typeof E=="string"&&(P=z=>z[E]),Object.entries(L).reduce((z,[j,O])=>(z[j]=P(O,j),z),{})}function D(L,E){return L.reduce((P,z,j)=>(P[z]=E[j],P),{})}}),Ff=Pe((e,n)=>{var s=Vf(),r=Ke().uniqueId;n.exports={run:i,undo:a};function i(c){(c.graph().acyclicer==="greedy"?s(c,l(c)):o(c)).forEach(d=>{let h=c.edge(d);c.removeEdge(d),h.forwardName=d.name,h.reversed=!0,c.setEdge(d.w,d.v,h,r("rev"))});function l(d){return h=>d.edge(h).weight}}function o(c){let l=[],d={},h={};function f(m){Object.hasOwn(h,m)||(h[m]=!0,d[m]=!0,c.outEdges(m).forEach(u=>{Object.hasOwn(d,u.w)?l.push(u):f(u.w)}),delete d[m])}return c.nodes().forEach(f),l}function a(c){c.edges().forEach(l=>{let d=c.edge(l);if(d.reversed){c.removeEdge(l);let h=d.forwardName;delete d.reversed,delete d.forwardName,c.setEdge(l.w,l.v,d,h)}})}}),Yf=Pe((e,n)=>{var s=Ke();n.exports={run:r,undo:o};function r(a){a.graph().dummyChains=[],a.edges().forEach(c=>i(a,c))}function i(a,c){let l=c.v,d=a.node(l).rank,h=c.w,f=a.node(h).rank,m=c.name,u=a.edge(c),p=u.labelRank;if(f===d+1)return;a.removeEdge(c);let M,C,y;for(y=0,++d;d<f;++y,++d)u.points=[],C={width:0,height:0,edgeLabel:u,edgeObj:c,rank:d},M=s.addDummyNode(a,"edge",C,"_d"),d===p&&(C.width=u.width,C.height=u.height,C.dummy="edge-label",C.labelpos=u.labelpos),a.setEdge(l,M,{weight:u.weight},m),y===0&&a.graph().dummyChains.push(M),l=M;a.setEdge(l,h,{weight:u.weight},m)}function o(a){a.graph().dummyChains.forEach(c=>{let l=a.node(c),d=l.edgeLabel,h;for(a.setEdge(l.edgeObj,d);l.dummy;)h=a.successors(c)[0],a.removeNode(c),d.points.push({x:l.x,y:l.y}),l.dummy==="edge-label"&&(d.x=l.x,d.y=l.y,d.width=l.width,d.height=l.height),c=h,l=a.node(c)})}}),rs=Pe((e,n)=>{var{applyWithChunking:s}=Ke();n.exports={longestPath:r,slack:i};function r(o){var a={};function c(l){var d=o.node(l);if(Object.hasOwn(a,l))return d.rank;a[l]=!0;let h=o.outEdges(l).map(m=>m==null?Number.POSITIVE_INFINITY:c(m.w)-o.edge(m).minlen);var f=s(Math.min,h);return f===Number.POSITIVE_INFINITY&&(f=0),d.rank=f}o.sources().forEach(c)}function i(o,a){return o.node(a.w).rank-o.node(a.v).rank-o.edge(a).minlen}}),pl=Pe((e,n)=>{var s=Pt().Graph,r=rs().slack;n.exports=i;function i(l){var d=new s({directed:!1}),h=l.nodes()[0],f=l.nodeCount();d.setNode(h,{});for(var m,u;o(d,l)<f;)m=a(d,l),u=d.hasNode(m.v)?r(l,m):-r(l,m),c(d,l,u);return d}function o(l,d){function h(f){d.nodeEdges(f).forEach(m=>{var u=m.v,p=f===u?m.w:u;!l.hasNode(p)&&!r(d,m)&&(l.setNode(p,{}),l.setEdge(f,p,{}),h(p))})}return l.nodes().forEach(h),l.nodeCount()}function a(l,d){return d.edges().reduce((h,f)=>{let m=Number.POSITIVE_INFINITY;return l.hasNode(f.v)!==l.hasNode(f.w)&&(m=r(d,f)),m<h[0]?[m,f]:h},[Number.POSITIVE_INFINITY,null])[1]}function c(l,d,h){l.nodes().forEach(f=>d.node(f).rank+=h)}}),Gf=Pe((e,n)=>{var s=pl(),r=rs().slack,i=rs().longestPath,o=Pt().alg.preorder,a=Pt().alg.postorder,c=Ke().simplify;n.exports=l,l.initLowLimValues=m,l.initCutValues=d,l.calcCutValue=f,l.leaveEdge=p,l.enterEdge=M,l.exchangeEdges=C;function l(b){b=c(b),i(b);var k=s(b);m(k),d(k,b);for(var N,I;N=p(k);)I=M(k,b,N),C(k,b,N,I)}function d(b,k){var N=a(b,b.nodes());N=N.slice(0,N.length-1),N.forEach(I=>h(b,k,I))}function h(b,k,N){var I=b.node(N),B=I.parent;b.edge(N,B).cutvalue=f(b,k,N)}function f(b,k,N){var I=b.node(N),B=I.parent,D=!0,L=k.edge(N,B),E=0;return L||(D=!1,L=k.edge(B,N)),E=L.weight,k.nodeEdges(N).forEach(P=>{var z=P.v===N,j=z?P.w:P.v;if(j!==B){var O=z===D,_=k.edge(P).weight;if(E+=O?_:-_,v(b,N,j)){var T=b.edge(N,j).cutvalue;E+=O?-T:T}}}),E}function m(b,k){arguments.length<2&&(k=b.nodes()[0]),u(b,{},1,k)}function u(b,k,N,I,B){var D=N,L=b.node(I);return k[I]=!0,b.neighbors(I).forEach(E=>{Object.hasOwn(k,E)||(N=u(b,k,N,E,I))}),L.low=D,L.lim=N++,B?L.parent=B:delete L.parent,N}function p(b){return b.edges().find(k=>b.edge(k).cutvalue<0)}function M(b,k,N){var I=N.v,B=N.w;k.hasEdge(I,B)||(I=N.w,B=N.v);var D=b.node(I),L=b.node(B),E=D,P=!1;D.lim>L.lim&&(E=L,P=!0);var z=k.edges().filter(j=>P===x(b,b.node(j.v),E)&&P!==x(b,b.node(j.w),E));return z.reduce((j,O)=>r(k,O)<r(k,j)?O:j)}function C(b,k,N,I){var B=N.v,D=N.w;b.removeEdge(B,D),b.setEdge(I.v,I.w,{}),m(b),d(b,k),y(b,k)}function y(b,k){var N=b.nodes().find(B=>!k.node(B).parent),I=o(b,N);I=I.slice(1),I.forEach(B=>{var D=b.node(B).parent,L=k.edge(B,D),E=!1;L||(L=k.edge(D,B),E=!0),k.node(B).rank=k.node(D).rank+(E?L.minlen:-L.minlen)})}function v(b,k,N){return b.hasEdge(k,N)}function x(b,k,N){return N.low<=k.lim&&k.lim<=N.lim}}),Kf=Pe((e,n)=>{var s=rs(),r=s.longestPath,i=pl(),o=Gf();n.exports=a;function a(h){var f=h.graph().ranker;if(f instanceof Function)return f(h);switch(h.graph().ranker){case"network-simplex":d(h);break;case"tight-tree":l(h);break;case"longest-path":c(h);break;case"none":break;default:d(h)}}var c=r;function l(h){r(h),i(h)}function d(h){o(h)}}),Zf=Pe((e,n)=>{n.exports=s;function s(o){let a=i(o);o.graph().dummyChains.forEach(c=>{let l=o.node(c),d=l.edgeObj,h=r(o,a,d.v,d.w),f=h.path,m=h.lca,u=0,p=f[u],M=!0;for(;c!==d.w;){if(l=o.node(c),M){for(;(p=f[u])!==m&&o.node(p).maxRank<l.rank;)u++;p===m&&(M=!1)}if(!M){for(;u<f.length-1&&o.node(p=f[u+1]).minRank<=l.rank;)u++;p=f[u]}o.setParent(c,p),c=o.successors(c)[0]}})}function r(o,a,c,l){let d=[],h=[],f=Math.min(a[c].low,a[l].low),m=Math.max(a[c].lim,a[l].lim),u,p;u=c;do u=o.parent(u),d.push(u);while(u&&(a[u].low>f||m>a[u].lim));for(p=u,u=l;(u=o.parent(u))!==p;)h.push(u);return{path:d.concat(h.reverse()),lca:p}}function i(o){let a={},c=0;function l(d){let h=c;o.children(d).forEach(l),a[d]={low:h,lim:c++}}return o.children().forEach(l),a}}),Xf=Pe((e,n)=>{var s=Ke();n.exports={run:r,cleanup:c};function r(l){let d=s.addDummyNode(l,"root",{},"_root"),h=o(l),f=Object.values(h),m=s.applyWithChunking(Math.max,f)-1,u=2*m+1;l.graph().nestingRoot=d,l.edges().forEach(M=>l.edge(M).minlen*=u);let p=a(l)+1;l.children().forEach(M=>i(l,d,u,p,m,h,M)),l.graph().nodeRankFactor=u}function i(l,d,h,f,m,u,p){let M=l.children(p);if(!M.length){p!==d&&l.setEdge(d,p,{weight:0,minlen:h});return}let C=s.addBorderNode(l,"_bt"),y=s.addBorderNode(l,"_bb"),v=l.node(p);l.setParent(C,p),v.borderTop=C,l.setParent(y,p),v.borderBottom=y,M.forEach(x=>{i(l,d,h,f,m,u,x);let b=l.node(x),k=b.borderTop?b.borderTop:x,N=b.borderBottom?b.borderBottom:x,I=b.borderTop?f:2*f,B=k!==N?1:m-u[p]+1;l.setEdge(C,k,{weight:I,minlen:B,nestingEdge:!0}),l.setEdge(N,y,{weight:I,minlen:B,nestingEdge:!0})}),l.parent(p)||l.setEdge(d,C,{weight:0,minlen:m+u[p]})}function o(l){var d={};function h(f,m){var u=l.children(f);u&&u.length&&u.forEach(p=>h(p,m+1)),d[f]=m}return l.children().forEach(f=>h(f,1)),d}function a(l){return l.edges().reduce((d,h)=>d+l.edge(h).weight,0)}function c(l){var d=l.graph();l.removeNode(d.nestingRoot),delete d.nestingRoot,l.edges().forEach(h=>{var f=l.edge(h);f.nestingEdge&&l.removeEdge(h)})}}),Uf=Pe((e,n)=>{var s=Ke();n.exports=r;function r(o){function a(c){let l=o.children(c),d=o.node(c);if(l.length&&l.forEach(a),Object.hasOwn(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(let h=d.minRank,f=d.maxRank+1;h<f;++h)i(o,"borderLeft","_bl",c,d,h),i(o,"borderRight","_br",c,d,h)}}o.children().forEach(a)}function i(o,a,c,l,d,h){let f={width:0,height:0,rank:h,borderType:a},m=d[a][h-1],u=s.addDummyNode(o,"border",f,c);d[a][h]=u,o.setParent(u,l),m&&o.setEdge(m,u,{weight:1})}}),Qf=Pe((e,n)=>{n.exports={adjust:s,undo:r};function s(h){let f=h.graph().rankdir.toLowerCase();(f==="lr"||f==="rl")&&i(h)}function r(h){let f=h.graph().rankdir.toLowerCase();(f==="bt"||f==="rl")&&a(h),(f==="lr"||f==="rl")&&(l(h),i(h))}function i(h){h.nodes().forEach(f=>o(h.node(f))),h.edges().forEach(f=>o(h.edge(f)))}function o(h){let f=h.width;h.width=h.height,h.height=f}function a(h){h.nodes().forEach(f=>c(h.node(f))),h.edges().forEach(f=>{let m=h.edge(f);m.points.forEach(c),Object.hasOwn(m,"y")&&c(m)})}function c(h){h.y=-h.y}function l(h){h.nodes().forEach(f=>d(h.node(f))),h.edges().forEach(f=>{let m=h.edge(f);m.points.forEach(d),Object.hasOwn(m,"x")&&d(m)})}function d(h){let f=h.x;h.x=h.y,h.y=f}}),Jf=Pe((e,n)=>{var s=Ke();n.exports=r;function r(i){let o={},a=i.nodes().filter(f=>!i.children(f).length),c=a.map(f=>i.node(f).rank),l=s.applyWithChunking(Math.max,c),d=s.range(l+1).map(()=>[]);function h(f){if(o[f])return;o[f]=!0;let m=i.node(f);d[m.rank].push(f),i.successors(f).forEach(h)}return a.sort((f,m)=>i.node(f).rank-i.node(m).rank).forEach(h),d}}),eh=Pe((e,n)=>{var s=Ke().zipObject;n.exports=r;function r(o,a){let c=0;for(let l=1;l<a.length;++l)c+=i(o,a[l-1],a[l]);return c}function i(o,a,c){let l=s(c,c.map((p,M)=>M)),d=a.flatMap(p=>o.outEdges(p).map(M=>({pos:l[M.w],weight:o.edge(M).weight})).sort((M,C)=>M.pos-C.pos)),h=1;for(;h<c.length;)h<<=1;let f=2*h-1;h-=1;let m=new Array(f).fill(0),u=0;return d.forEach(p=>{let M=p.pos+h;m[M]+=p.weight;let C=0;for(;M>0;)M%2&&(C+=m[M+1]),M=M-1>>1,m[M]+=p.weight;u+=p.weight*C}),u}}),th=Pe((e,n)=>{n.exports=s;function s(r,i=[]){return i.map(o=>{let a=r.inEdges(o);if(a.length){let c=a.reduce((l,d)=>{let h=r.edge(d),f=r.node(d.v);return{sum:l.sum+h.weight*f.order,weight:l.weight+h.weight}},{sum:0,weight:0});return{v:o,barycenter:c.sum/c.weight,weight:c.weight}}else return{v:o}})}}),nh=Pe((e,n)=>{var s=Ke();n.exports=r;function r(a,c){let l={};a.forEach((h,f)=>{let m=l[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:f};h.barycenter!==void 0&&(m.barycenter=h.barycenter,m.weight=h.weight)}),c.edges().forEach(h=>{let f=l[h.v],m=l[h.w];f!==void 0&&m!==void 0&&(m.indegree++,f.out.push(l[h.w]))});let d=Object.values(l).filter(h=>!h.indegree);return i(d)}function i(a){let c=[];function l(h){return f=>{f.merged||(f.barycenter===void 0||h.barycenter===void 0||f.barycenter>=h.barycenter)&&o(h,f)}}function d(h){return f=>{f.in.push(h),--f.indegree===0&&a.push(f)}}for(;a.length;){let h=a.pop();c.push(h),h.in.reverse().forEach(l(h)),h.out.forEach(d(h))}return c.filter(h=>!h.merged).map(h=>s.pick(h,["vs","i","barycenter","weight"]))}function o(a,c){let l=0,d=0;a.weight&&(l+=a.barycenter*a.weight,d+=a.weight),c.weight&&(l+=c.barycenter*c.weight,d+=c.weight),a.vs=c.vs.concat(a.vs),a.barycenter=l/d,a.weight=d,a.i=Math.min(c.i,a.i),c.merged=!0}}),rh=Pe((e,n)=>{var s=Ke();n.exports=r;function r(a,c){let l=s.partition(a,C=>Object.hasOwn(C,"barycenter")),d=l.lhs,h=l.rhs.sort((C,y)=>y.i-C.i),f=[],m=0,u=0,p=0;d.sort(o(!!c)),p=i(f,h,p),d.forEach(C=>{p+=C.vs.length,f.push(C.vs),m+=C.barycenter*C.weight,u+=C.weight,p=i(f,h,p)});let M={vs:f.flat(!0)};return u&&(M.barycenter=m/u,M.weight=u),M}function i(a,c,l){let d;for(;c.length&&(d=c[c.length-1]).i<=l;)c.pop(),a.push(d.vs),l++;return l}function o(a){return(c,l)=>c.barycenter<l.barycenter?-1:c.barycenter>l.barycenter?1:a?l.i-c.i:c.i-l.i}}),sh=Pe((e,n)=>{var s=th(),r=nh(),i=rh();n.exports=o;function o(l,d,h,f){let m=l.children(d),u=l.node(d),p=u?u.borderLeft:void 0,M=u?u.borderRight:void 0,C={};p&&(m=m.filter(b=>b!==p&&b!==M));let y=s(l,m);y.forEach(b=>{if(l.children(b.v).length){let k=o(l,b.v,h,f);C[b.v]=k,Object.hasOwn(k,"barycenter")&&c(b,k)}});let v=r(y,h);a(v,C);let x=i(v,f);if(p&&(x.vs=[p,x.vs,M].flat(!0),l.predecessors(p).length)){let b=l.node(l.predecessors(p)[0]),k=l.node(l.predecessors(M)[0]);Object.hasOwn(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+b.order+k.order)/(x.weight+2),x.weight+=2}return x}function a(l,d){l.forEach(h=>{h.vs=h.vs.flatMap(f=>d[f]?d[f].vs:f)})}function c(l,d){l.barycenter!==void 0?(l.barycenter=(l.barycenter*l.weight+d.barycenter*d.weight)/(l.weight+d.weight),l.weight+=d.weight):(l.barycenter=d.barycenter,l.weight=d.weight)}}),oh=Pe((e,n)=>{var s=Pt().Graph,r=Ke();n.exports=i;function i(a,c,l,d){d||(d=a.nodes());let h=o(a),f=new s({compound:!0}).setGraph({root:h}).setDefaultNodeLabel(m=>a.node(m));return d.forEach(m=>{let u=a.node(m),p=a.parent(m);(u.rank===c||u.minRank<=c&&c<=u.maxRank)&&(f.setNode(m),f.setParent(m,p||h),a[l](m).forEach(M=>{let C=M.v===m?M.w:M.v,y=f.edge(C,m),v=y!==void 0?y.weight:0;f.setEdge(C,m,{weight:a.edge(M).weight+v})}),Object.hasOwn(u,"minRank")&&f.setNode(m,{borderLeft:u.borderLeft[c],borderRight:u.borderRight[c]}))}),f}function o(a){for(var c;a.hasNode(c=r.uniqueId("_root")););return c}}),ah=Pe((e,n)=>{n.exports=s;function s(r,i,o){let a={},c;o.forEach(l=>{let d=r.parent(l),h,f;for(;d;){if(h=r.parent(d),h?(f=a[h],a[h]=d):(f=c,c=d),f&&f!==d){i.setEdge(f,d);return}d=h}})}}),ih=Pe((e,n)=>{var s=Jf(),r=eh(),i=sh(),o=oh(),a=ah(),c=Pt().Graph,l=Ke();n.exports=d;function d(u,p={}){if(typeof p.customOrder=="function"){p.customOrder(u,d);return}let M=l.maxRank(u),C=h(u,l.range(1,M+1),"inEdges"),y=h(u,l.range(M-1,-1,-1),"outEdges"),v=s(u);if(m(u,v),p.disableOptimalOrderHeuristic)return;let x=Number.POSITIVE_INFINITY,b,k=p.constraints||[];for(let N=0,I=0;I<4;++N,++I){f(N%2?C:y,N%4>=2,k),v=l.buildLayerMatrix(u);let B=r(u,v);B<x?(I=0,b=Object.assign({},v),x=B):B===x&&(b=structuredClone(v))}m(u,b)}function h(u,p,M){let C=new Map,y=(v,x)=>{C.has(v)||C.set(v,[]),C.get(v).push(x)};for(let v of u.nodes()){let x=u.node(v);if(typeof x.rank=="number"&&y(x.rank,v),typeof x.minRank=="number"&&typeof x.maxRank=="number")for(let b=x.minRank;b<=x.maxRank;b++)b!==x.rank&&y(b,v)}return p.map(function(v){return o(u,v,M,C.get(v)||[])})}function f(u,p,M){let C=new c;u.forEach(function(y){M.forEach(b=>C.setEdge(b.left,b.right));let v=y.graph().root,x=i(y,v,C,p);x.vs.forEach((b,k)=>y.node(b).order=k),a(y,C,x.vs)})}function m(u,p){Object.values(p).forEach(M=>M.forEach((C,y)=>u.node(C).order=y))}}),lh=Pe((e,n)=>{var s=Pt().Graph,r=Ke();n.exports={positionX:M,findType1Conflicts:i,findType2Conflicts:o,addConflict:c,hasConflict:l,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:u,findSmallestWidthAlignment:m,balance:p};function i(v,x){let b={};function k(N,I){let B=0,D=0,L=N.length,E=I[I.length-1];return I.forEach((P,z)=>{let j=a(v,P),O=j?v.node(j).order:L;(j||P===E)&&(I.slice(D,z+1).forEach(_=>{v.predecessors(_).forEach(T=>{let R=v.node(T),A=R.order;(A<B||O<A)&&!(R.dummy&&v.node(_).dummy)&&c(b,T,_)})}),D=z+1,B=O)}),I}return x.length&&x.reduce(k),b}function o(v,x){let b={};function k(I,B,D,L,E){let P;r.range(B,D).forEach(z=>{P=I[z],v.node(P).dummy&&v.predecessors(P).forEach(j=>{let O=v.node(j);O.dummy&&(O.order<L||O.order>E)&&c(b,j,P)})})}function N(I,B){let D=-1,L,E=0;return B.forEach((P,z)=>{if(v.node(P).dummy==="border"){let j=v.predecessors(P);j.length&&(L=v.node(j[0]).order,k(B,E,z,D,L),E=z,D=L)}k(B,E,B.length,L,I.length)}),B}return x.length&&x.reduce(N),b}function a(v,x){if(v.node(x).dummy)return v.predecessors(x).find(b=>v.node(b).dummy)}function c(v,x,b){if(x>b){let N=x;x=b,b=N}let k=v[x];k||(v[x]=k={}),k[b]=!0}function l(v,x,b){if(x>b){let k=x;x=b,b=k}return!!v[x]&&Object.hasOwn(v[x],b)}function d(v,x,b,k){let N={},I={},B={};return x.forEach(D=>{D.forEach((L,E)=>{N[L]=L,I[L]=L,B[L]=E})}),x.forEach(D=>{let L=-1;D.forEach(E=>{let P=k(E);if(P.length){P=P.sort((j,O)=>B[j]-B[O]);let z=(P.length-1)/2;for(let j=Math.floor(z),O=Math.ceil(z);j<=O;++j){let _=P[j];I[E]===E&&L<B[_]&&!l(b,E,_)&&(I[_]=E,I[E]=N[E]=N[_],L=B[_])}}})}),{root:N,align:I}}function h(v,x,b,k,N){let I={},B=f(v,x,b,N),D=N?"borderLeft":"borderRight";function L(z,j){let O=B.nodes().slice(),_={},T=O.pop();for(;T;){if(_[T])z(T);else{_[T]=!0,O.push(T);for(let R of j(T))O.push(R)}T=O.pop()}}function E(z){I[z]=B.inEdges(z).reduce((j,O)=>Math.max(j,I[O.v]+B.edge(O)),0)}function P(z){let j=B.outEdges(z).reduce((_,T)=>Math.min(_,I[T.w]-B.edge(T)),Number.POSITIVE_INFINITY),O=v.node(z);j!==Number.POSITIVE_INFINITY&&O.borderType!==D&&(I[z]=Math.max(I[z],j))}return L(E,B.predecessors.bind(B)),L(P,B.successors.bind(B)),Object.keys(k).forEach(z=>I[z]=I[b[z]]),I}function f(v,x,b,k){let N=new s,I=v.graph(),B=C(I.nodesep,I.edgesep,k);return x.forEach(D=>{let L;D.forEach(E=>{let P=b[E];if(N.setNode(P),L){var z=b[L],j=N.edge(z,P);N.setEdge(z,P,Math.max(B(v,E,L),j||0))}L=E})}),N}function m(v,x){return Object.values(x).reduce((b,k)=>{let N=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;Object.entries(k).forEach(([D,L])=>{let E=y(v,D)/2;N=Math.max(L+E,N),I=Math.min(L-E,I)});let B=N-I;return B<b[0]&&(b=[B,k]),b},[Number.POSITIVE_INFINITY,null])[1]}function u(v,x){let b=Object.values(x),k=r.applyWithChunking(Math.min,b),N=r.applyWithChunking(Math.max,b);["u","d"].forEach(I=>{["l","r"].forEach(B=>{let D=I+B,L=v[D];if(L===x)return;let E=Object.values(L),P=k-r.applyWithChunking(Math.min,E);B!=="l"&&(P=N-r.applyWithChunking(Math.max,E)),P&&(v[D]=r.mapValues(L,z=>z+P))})})}function p(v,x){return r.mapValues(v.ul,(b,k)=>{if(x)return v[x.toLowerCase()][k];{let N=Object.values(v).map(I=>I[k]).sort((I,B)=>I-B);return(N[1]+N[2])/2}})}function M(v){let x=r.buildLayerMatrix(v),b=Object.assign(i(v,x),o(v,x)),k={},N;["u","d"].forEach(B=>{N=B==="u"?x:Object.values(x).reverse(),["l","r"].forEach(D=>{D==="r"&&(N=N.map(z=>Object.values(z).reverse()));let L=(B==="u"?v.predecessors:v.successors).bind(v),E=d(v,N,b,L),P=h(v,N,E.root,E.align,D==="r");D==="r"&&(P=r.mapValues(P,z=>-z)),k[B+D]=P})});let I=m(v,k);return u(k,I),p(k,v.graph().align)}function C(v,x,b){return(k,N,I)=>{let B=k.node(N),D=k.node(I),L=0,E;if(L+=B.width/2,Object.hasOwn(B,"labelpos"))switch(B.labelpos.toLowerCase()){case"l":E=-B.width/2;break;case"r":E=B.width/2;break}if(E&&(L+=b?E:-E),E=0,L+=(B.dummy?x:v)/2,L+=(D.dummy?x:v)/2,L+=D.width/2,Object.hasOwn(D,"labelpos"))switch(D.labelpos.toLowerCase()){case"l":E=D.width/2;break;case"r":E=-D.width/2;break}return E&&(L+=b?E:-E),E=0,L}}function y(v,x){return v.node(x).width}}),ch=Pe((e,n)=>{var s=Ke(),r=lh().positionX;n.exports=i;function i(a){a=s.asNonCompoundGraph(a),o(a),Object.entries(r(a)).forEach(([c,l])=>a.node(c).x=l)}function o(a){let c=s.buildLayerMatrix(a),l=a.graph().ranksep,d=a.graph().rankalign,h=0;c.forEach(f=>{let m=f.reduce((u,p)=>{let M=a.node(p).height;return u>M?u:M},0);f.forEach(u=>{let p=a.node(u);d==="top"?p.y=h+p.height/2:d==="bottom"?p.y=h+m-p.height/2:p.y=h+m/2}),h+=m+l})}}),dh=Pe((e,n)=>{var s=Ff(),r=Yf(),i=Kf(),o=Ke().normalizeRanks,a=Zf(),c=Ke().removeEmptyRanks,l=Xf(),d=Uf(),h=Qf(),f=ih(),m=ch(),u=Ke(),p=Pt().Graph;n.exports=M;function M(S,V={}){let q=V.debugTiming?u.time:u.notime;return q("layout",()=>{let H=q(" buildLayoutGraph",()=>L(S));return q(" runLayout",()=>C(H,q,V)),q(" updateInputGraph",()=>y(S,H)),H})}function C(S,V,q){V(" makeSpaceForEdgeLabels",()=>E(S)),V(" removeSelfEdges",()=>W(S)),V(" acyclic",()=>s.run(S)),V(" nestingGraph.run",()=>l.run(S)),V(" rank",()=>i(u.asNonCompoundGraph(S))),V(" injectEdgeLabelProxies",()=>P(S)),V(" removeEmptyRanks",()=>c(S)),V(" nestingGraph.cleanup",()=>l.cleanup(S)),V(" normalizeRanks",()=>o(S)),V(" assignRankMinMax",()=>z(S)),V(" removeEdgeLabelProxies",()=>j(S)),V(" normalize.run",()=>r.run(S)),V(" parentDummyChains",()=>a(S)),V(" addBorderSegments",()=>d(S)),V(" order",()=>f(S,q)),V(" insertSelfEdges",()=>Y(S)),V(" adjustCoordinateSystem",()=>h.adjust(S)),V(" position",()=>m(S)),V(" positionSelfEdges",()=>F(S)),V(" removeBorderNodes",()=>A(S)),V(" normalize.undo",()=>r.undo(S)),V(" fixupEdgeLabelCoords",()=>T(S)),V(" undoCoordinateSystem",()=>h.undo(S)),V(" translateGraph",()=>O(S)),V(" assignNodeIntersects",()=>_(S)),V(" reversePoints",()=>R(S)),V(" acyclic.undo",()=>s.undo(S))}function y(S,V){S.nodes().forEach(q=>{let H=S.node(q),Z=V.node(q);H&&(H.x=Z.x,H.y=Z.y,H.order=Z.order,H.rank=Z.rank,V.children(q).length&&(H.width=Z.width,H.height=Z.height))}),S.edges().forEach(q=>{let H=S.edge(q),Z=V.edge(q);H.points=Z.points,Object.hasOwn(Z,"x")&&(H.x=Z.x,H.y=Z.y)}),S.graph().width=V.graph().width,S.graph().height=V.graph().height}var v=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},b=["acyclicer","ranker","rankdir","align","rankalign"],k=["width","height","rank"],N={width:0,height:0},I=["minlen","weight","width","height","labeloffset"],B={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},D=["labelpos"];function L(S){let V=new p({multigraph:!0,compound:!0}),q=$(S.graph());return V.setGraph(Object.assign({},x,Q(q,v),u.pick(q,b))),S.nodes().forEach(H=>{let Z=$(S.node(H)),J=Q(Z,k);Object.keys(N).forEach(le=>{J[le]===void 0&&(J[le]=N[le])}),V.setNode(H,J),V.setParent(H,S.parent(H))}),S.edges().forEach(H=>{let Z=$(S.edge(H));V.setEdge(H,Object.assign({},B,Q(Z,I),u.pick(Z,D)))}),V}function E(S){let V=S.graph();V.ranksep/=2,S.edges().forEach(q=>{let H=S.edge(q);H.minlen*=2,H.labelpos.toLowerCase()!=="c"&&(V.rankdir==="TB"||V.rankdir==="BT"?H.width+=H.labeloffset:H.height+=H.labeloffset)})}function P(S){S.edges().forEach(V=>{let q=S.edge(V);if(q.width&&q.height){let H=S.node(V.v),Z={rank:(S.node(V.w).rank-H.rank)/2+H.rank,e:V};u.addDummyNode(S,"edge-proxy",Z,"_ep")}})}function z(S){let V=0;S.nodes().forEach(q=>{let H=S.node(q);H.borderTop&&(H.minRank=S.node(H.borderTop).rank,H.maxRank=S.node(H.borderBottom).rank,V=Math.max(V,H.maxRank))}),S.graph().maxRank=V}function j(S){S.nodes().forEach(V=>{let q=S.node(V);q.dummy==="edge-proxy"&&(S.edge(q.e).labelRank=q.rank,S.removeNode(V))})}function O(S){let V=Number.POSITIVE_INFINITY,q=0,H=Number.POSITIVE_INFINITY,Z=0,J=S.graph(),le=J.marginx||0,te=J.marginy||0;function X(ie){let de=ie.x,se=ie.y,me=ie.width,ue=ie.height;V=Math.min(V,de-me/2),q=Math.max(q,de+me/2),H=Math.min(H,se-ue/2),Z=Math.max(Z,se+ue/2)}S.nodes().forEach(ie=>X(S.node(ie))),S.edges().forEach(ie=>{let de=S.edge(ie);Object.hasOwn(de,"x")&&X(de)}),V-=le,H-=te,S.nodes().forEach(ie=>{let de=S.node(ie);de.x-=V,de.y-=H}),S.edges().forEach(ie=>{let de=S.edge(ie);de.points.forEach(se=>{se.x-=V,se.y-=H}),Object.hasOwn(de,"x")&&(de.x-=V),Object.hasOwn(de,"y")&&(de.y-=H)}),J.width=q-V+le,J.height=Z-H+te}function _(S){S.edges().forEach(V=>{let q=S.edge(V),H=S.node(V.v),Z=S.node(V.w),J,le;q.points?(J=q.points[0],le=q.points[q.points.length-1]):(q.points=[],J=Z,le=H),q.points.unshift(u.intersectRect(H,J)),q.points.push(u.intersectRect(Z,le))})}function T(S){S.edges().forEach(V=>{let q=S.edge(V);if(Object.hasOwn(q,"x"))switch((q.labelpos==="l"||q.labelpos==="r")&&(q.width-=q.labeloffset),q.labelpos){case"l":q.x-=q.width/2+q.labeloffset;break;case"r":q.x+=q.width/2+q.labeloffset;break}})}function R(S){S.edges().forEach(V=>{let q=S.edge(V);q.reversed&&q.points.reverse()})}function A(S){S.nodes().forEach(V=>{if(S.children(V).length){let q=S.node(V),H=S.node(q.borderTop),Z=S.node(q.borderBottom),J=S.node(q.borderLeft[q.borderLeft.length-1]),le=S.node(q.borderRight[q.borderRight.length-1]);q.width=Math.abs(le.x-J.x),q.height=Math.abs(Z.y-H.y),q.x=J.x+q.width/2,q.y=H.y+q.height/2}}),S.nodes().forEach(V=>{S.node(V).dummy==="border"&&S.removeNode(V)})}function W(S){S.edges().forEach(V=>{if(V.v===V.w){var q=S.node(V.v);q.selfEdges||(q.selfEdges=[]),q.selfEdges.push({e:V,label:S.edge(V)}),S.removeEdge(V)}})}function Y(S){var V=u.buildLayerMatrix(S);V.forEach(q=>{var H=0;q.forEach((Z,J)=>{var le=S.node(Z);le.order=J+H,(le.selfEdges||[]).forEach(te=>{u.addDummyNode(S,"selfedge",{width:te.label.width,height:te.label.height,rank:le.rank,order:J+ ++H,e:te.e,label:te.label},"_se")}),delete le.selfEdges})})}function F(S){S.nodes().forEach(V=>{var q=S.node(V);if(q.dummy==="selfedge"){var H=S.node(q.e.v),Z=H.x+H.width/2,J=H.y,le=q.x-Z,te=H.height/2;S.setEdge(q.e,q.label),S.removeNode(V),q.label.points=[{x:Z+2*le/3,y:J-te},{x:Z+5*le/6,y:J-te},{x:Z+le,y:J},{x:Z+5*le/6,y:J+te},{x:Z+2*le/3,y:J+te}],q.label.x=q.x,q.label.y=q.y}})}function Q(S,V){return u.mapValues(u.pick(S,V),Number)}function $(S){var V={};return S&&Object.entries(S).forEach(([q,H])=>{typeof q=="string"&&(q=q.toLowerCase()),V[q]=H}),V}}),uh=Pe((e,n)=>{var s=Ke(),r=Pt().Graph;n.exports={debugOrdering:i};function i(o){let a=s.buildLayerMatrix(o),c=new r({compound:!0,multigraph:!0}).setGraph({});return o.nodes().forEach(l=>{c.setNode(l,{label:l}),c.setParent(l,"layer"+o.node(l).rank)}),o.edges().forEach(l=>c.setEdge(l.v,l.w,{},l.name)),a.forEach((l,d)=>{let h="layer"+d;c.setNode(h,{rank:"same"}),l.reduce((f,m)=>(c.setEdge(f,m,{style:"invis"}),m))}),c}}),fh=Pe((e,n)=>{n.exports="2.0.4"}),hh=Pe((e,n)=>{n.exports={graphlib:Pt(),layout:dh(),debug:uh(),util:{time:Ke().time,notime:Ke().notime},version:fh()}});const Ea=hh();const Ma={pending:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},in_progress:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},blocked:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},review:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},failed:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},rejected:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"},archived:{bg:"bg-gray-500/5",border:"border-gray-500/15",text:"text-fg-tertiary"}},mh={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function gh({data:e}){const{t:n}=We(["work","common"]),{task:s,agentName:r,selected:i,direction:o="TB",isExpandedRoot:a,onCollapse:c}=e,l=Ma[s.status]??Ma.pending,d=s.taskType==="scheduled"&&!!s.scheduleConfig,h=d?s.scheduleConfig.every?n("work:task.everyInterval",{interval:s.scheduleConfig.every}):s.scheduleConfig.cron?n("work:task.cronLabel"):"":"",f=o==="LR"?be.Left:be.Top,m=o==="LR"?be.Right:be.Bottom;return t.jsxs("div",{className:`relative rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${d?`${l.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${l.bg} ${l.border}`} ${i?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[t.jsx(dn,{type:"target",position:f,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${mh[s.priority]??"bg-gray-500"}`}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${l.text}`,children:n(`work:status.task.${s.status}`,{defaultValue:s.status.replace("_"," ")})}),d&&t.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/15 text-blue-600 ml-auto whitespace-nowrap inline-flex items-center gap-0.5",children:[t.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})}),h]})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:s.title}),r&&t.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:r}),s.blockedBy&&s.blockedBy.length>0&&t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:n("work:dag.depCount",{count:s.blockedBy.length})}),t.jsx(dn,{type:"source",position:m,className:"!bg-border-default !w-2 !h-2"}),a&&c&&t.jsx("button",{onClick:u=>{u.stopPropagation(),c()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const Ia={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 ph({data:e}){const{t:n}=We(["work","common"]),{req:s,selected:r,direction:i="TB",isExpandedRoot:o,onCollapse:a}=e,c=Ia[s.status]??Ia.pending,l=i==="LR"?be.Left:be.Top,d=i==="LR"?be.Right:be.Bottom;return t.jsxs("div",{className:`relative rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${c.bg} ${c.border} ${r?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[t.jsx(dn,{type:"target",position:l,className:"!bg-border-default !w-2 !h-2"}),t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:n("work:dag.reqLabel")}),t.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${c.text}`,children:n(`work:status.requirement.${s.status}`,{defaultValue:s.status.replace("_"," ")})})]}),t.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:s.title}),s.taskIds.length>0&&t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:n("work:dag.taskCount",{count:s.taskIds.length})}),t.jsx(dn,{type:"source",position:d,className:"!bg-border-default !w-2 !h-2"}),o&&a&&t.jsx("button",{onClick:h=>{h.stopPropagation(),a()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const xh={task:gh,requirement:ph};function bh({nodeIds:e,rfRef:n}){const s=ff();return g.useEffect(()=>{if(e.length===0)return;const r=setTimeout(()=>{s(e),requestAnimationFrame(()=>{n.current?.fitView({padding:.2})})},300);return()=>clearTimeout(r)},[e.length]),null}const yh=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&!document.documentElement.classList.contains("cyberpunk")&&!document.documentElement.classList.contains("mono")&&window.matchMedia("(prefers-color-scheme: light)").matches,vh=e=>{const n=new MutationObserver(e);n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const s=window.matchMedia("(prefers-color-scheme: light)");return s.addEventListener("change",e),()=>{n.disconnect(),s.removeEventListener("change",e)}};function wh(){return g.useSyncExternalStore(vh,yh,()=>!1)}const Ur=200,Qr=80;function Ra(e,n,s="TB"){const r=o=>{const a=new Ea.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:o,nodesep:40,ranksep:60});for(const c of e)a.setNode(c.id,{width:Ur,height:Qr});for(const c of n)a.setEdge(c.source,c.target);return Ea.layout(a),e.map(c=>{const l=a.node(c.id);return{...c,position:{x:(l?.x??0)-Ur/2,y:(l?.y??0)-Qr/2}}})},i=r(s);if(n.length>0&&e.length>4){let o=1/0,a=-1/0,c=1/0,l=-1/0;for(const m of i)o=Math.min(o,m.position.x),a=Math.max(a,m.position.x+Ur),c=Math.min(c,m.position.y),l=Math.max(l,m.position.y+Qr);const d=a-o,h=l-c,f=s==="TB"?"LR":"TB";if(d>h*3)return{nodes:r(f),direction:f}}return{nodes:i,direction:s}}function kh(e,n){const s=new Map,r=new Map;for(const a of e)r.set(a.id,a),s.set(a.id,new Set);for(const a of n)s.get(a.source)?.add(a.target),s.get(a.target)?.add(a.source);const i=new Set,o=[];for(const a of e){if(i.has(a.id))continue;const c=new Set,l=[a.id];for(;l.length>0;){const d=l.pop();if(!i.has(d)){i.add(d),c.add(d);for(const h of s.get(d)??[])i.has(h)||l.push(h)}}o.push({nodes:e.filter(d=>c.has(d.id)),edges:n.filter(d=>c.has(d.source)&&c.has(d.target))})}return o}function _a(e,n){if(e.length===0)return{nodes:[],direction:"TB"};const s=kh(e,n);if(s.length===1)return Ra(e,n);let r="TB";const i=s.map(m=>{const{nodes:u,direction:p}=Ra(m.nodes,m.edges);r=p;let M=1/0,C=-1/0,y=1/0,v=-1/0;for(const x of u)M=Math.min(M,x.position.x),C=Math.max(C,x.position.x+Ur),y=Math.min(y,x.position.y),v=Math.max(v,x.position.y+Qr);for(const x of u)x.position.x-=M,x.position.y-=y;return{nodes:u,w:C-M,h:v-y}});i.sort((m,u)=>u.h-m.h);const o=60,a=i.reduce((m,u)=>m+(u.w+o)*(u.h+o),0),c=Math.sqrt(a)*1.1,l=[];let d=0,h=0,f=0;for(const m of i){d>0&&d+m.w>c&&(d=0,h+=f+o,f=0);for(const u of m.nodes)l.push({...u,position:{x:u.position.x+d,y:u.position.y+h}});d+=m.w+o,f=Math.max(f,m.h)}return{nodes:l,direction:r}}function jh(e,n,s){const r=new Set,i=[n];for(;i.length>0;){const o=i.pop();if(o===s)return!0;if(r.has(o))continue;r.add(o);const a=e.get(o);if(a?.blockedBy)for(const c of a.blockedBy)i.push(c)}return!1}const Vn=[{id:"todo",statuses:new Set(["pending"]),color:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"}},{id:"in_progress",statuses:new Set(["in_progress","blocked"]),color:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"}},{id:"review",statuses:new Set(["review"]),color:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"}},{id:"done",statuses:new Set(["completed","failed","rejected","cancelled","archived"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}];new Set(Vn.map(e=>e.id));const Yr=new Set(Vn.filter(e=>e.id!=="done").map(e=>e.id)),La=e=>e.status==="archived";function Nh(e,n,s,r){const i=new Set,o=[e];for(;o.length>0;){const a=o.pop();if(!i.has(a))if(i.add(a),a.startsWith("req-")){const c=s.get(a.slice(4));if(c)for(const l of c.taskIds)o.push(l)}else{const c=n.get(a);if(c?.blockedBy)for(const l of c.blockedBy)o.push(l);c?.requirementId&&o.push(`req-${c.requirementId}`)}}for(const a of r)a.requirementId&&i.has(a.id)&&i.add(`req-${a.requirementId}`);return i}function Ch({tasks:e,requirements:n=[],agents:s,showArchived:r,onShowArchivedChange:i,onTaskClick:o,onReqClick:a,onCollapseDAG:c,onDependencyChange:l,selectedTaskId:d,selectedReqId:h,hasDetailPanel:f,defaultExpandedNodeId:m,previewMode:u}){const{t:p}=We(["work","common"]),M=wh(),[C,y]=g.useState(null),[v,x]=g.useState(null),[b,k]=g.useState(()=>new Set(Yr)),[N,I]=g.useState(m??null),[B,D]=g.useState(r??!1),L=r??B,E=g.useCallback(fe=>{const re=typeof fe=="function"?fe(L):fe;D(re),i?.(re)},[L,i]);g.useEffect(()=>{r!==void 0&&D(r)},[r]),g.useEffect(()=>{m&&I(m)},[m]);const P=g.useMemo(()=>e.filter(fe=>La(fe)).length,[e]),z=g.useMemo(()=>{const fe=new Set;for(const re of Vn)if(b.has(re.id))for(const xe of re.statuses)fe.add(xe);return fe},[b]),j=g.useMemo(()=>{const fe=new Set;for(const re of e)for(const xe of Vn)if(xe.statuses.has(re.status)){fe.add(xe.id);break}for(const re of n){const xe=Ta[re.status];xe&&fe.add(xe)}return Vn.filter(re=>fe.has(re.id))},[e,n]),O=g.useCallback(fe=>{k(re=>{const xe=new Set(re);return xe.has(fe)?xe.delete(fe):xe.add(fe),xe})},[]),_=g.useCallback((fe,re="success")=>{y({msg:fe,type:re}),setTimeout(()=>y(null),2500)},[]),T=g.useMemo(()=>{const fe=new Map;for(const re of s)fe.set(re.id,re.name);return fe},[s]),R=g.useMemo(()=>{const fe=new Map;for(const re of e)fe.set(re.id,re);return fe},[e]),A=g.useMemo(()=>{const fe=new Map;for(const re of n)fe.set(re.id,re);return fe},[n]),W=g.useRef(!1),Y=g.useCallback(()=>{W.current=!1,I(null),c?.()},[c]),F=M?"#94a3b8":"#6b7280",Q=g.useCallback((fe,re,xe)=>({id:`${fe}->${re}`,source:fe,target:re,animated:xe==="blocked",markerEnd:{type:Gn.ArrowClosed,width:14,height:14,color:xe==="blocked"?"#ef4444":F},style:{stroke:xe==="blocked"?"#ef4444":F,strokeWidth:1.5,cursor:"pointer"}}),[F]),{initialNodes:$,initialEdges:S,topLevelIds:V}=g.useMemo(()=>{const fe=(Ce,Xe)=>{const $e=new Set,Le=Ce.map(_e=>($e.add(_e.id),{id:_e.id,type:"task",data:{task:_e,agentName:_e.assignedAgentId?T.get(_e.assignedAgentId):void 0,selected:_e.id===d},position:{x:0,y:0}}));for(const _e of Xe){const Ye=`req-${_e.id}`;$e.add(Ye),Le.push({id:Ye,type:"requirement",data:{req:_e,selected:_e.id===h},position:{x:0,y:0}})}const et=[];for(const _e of Ce)if(_e.blockedBy)for(const Ye of _e.blockedBy)$e.has(Ye)&&et.push(Q(Ye,_e.id,_e.status));const qt=new Set,Wt=(_e,Ye)=>{const tt=`${_e}->${Ye}`;qt.has(tt)||(qt.add(tt),et.push({id:tt,source:_e,target:Ye,markerEnd:{type:Gn.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const _e of Xe){const Ye=`req-${_e.id}`;for(const tt of _e.taskIds)$e.has(tt)&&Wt(Ye,tt)}for(const _e of Ce)if(_e.requirementId){const Ye=`req-${_e.requirementId}`;$e.has(Ye)&&Wt(Ye,_e.id)}return{nodes:Le,edges:et}},re=e.filter(Ce=>z.has(Ce.status)&&(L||!La(Ce))),xe=new Set;for(const Ce of Vn)b.has(Ce.id)&&xe.add(Ce.id);const Ee=n.filter(Ce=>{const Xe=Ta[Ce.status];return Xe&&xe.has(Xe)}),{nodes:ye,edges:Ie}=fe(re,Ee),pt=new Set;for(const Ce of Ie)pt.add(Ce.target);const rt=new Set(ye.filter(Ce=>!pt.has(Ce.id)).map(Ce=>Ce.id));if(!N||!rt.has(N)){const Ce=ye,{nodes:Xe,direction:$e}=_a(Ce,Ie);return{initialNodes:Xe.map(et=>({...et,data:{...et.data,direction:$e}})),initialEdges:Ie,topLevelIds:rt}}const{nodes:Nt,edges:Ct}=fe(e,n),st=Nh(N,R,A,e),Ht=Nt.filter(Ce=>st.has(Ce.id)).map(Ce=>Ce.id===N?{...Ce,data:{...Ce.data,isExpandedRoot:!0,onCollapse:Y}}:Ce),xt=Ct.filter(Ce=>st.has(Ce.source)&&st.has(Ce.target)),{nodes:Jt,direction:bt}=_a(Ht,xt);return{initialNodes:Jt.map(Ce=>({...Ce,data:{...Ce.data,direction:bt}})),initialEdges:xt,topLevelIds:rt}},[e,n,T,R,A,Q,z,b,L,d,h,N,Y]),[q,H,Z]=hf($),[J,le,te]=mf(S),X=g.useRef(null),ie=g.useRef({groupFilter:b,showArchived:L});g.useEffect(()=>{const fe=ie.current;(fe.groupFilter!==b||fe.showArchived!==L)&&(W.current=!1,I(null),ie.current={groupFilter:b,showArchived:L})},[b,L]),g.useEffect(()=>{H($),le(S),W.current||requestAnimationFrame(()=>{X.current?.fitView({padding:.2,duration:300})})},[$,S,H,le]),g.useEffect(()=>{const fe=setTimeout(()=>{X.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(fe)},[f]);const de=g.useCallback(fe=>{fe&&(W.current=!0)},[]),se=g.useCallback((fe,re)=>{if(!N&&V.has(re.id)&&(W.current=!1,I(re.id)),re.id.startsWith("req-")){const xe=A.get(re.id.slice(4));xe&&a&&a(xe)}else{const xe=R.get(re.id);xe&&o&&o(xe)}},[R,A,o,a,V,N]),me=g.useCallback(async fe=>{const{source:re,target:xe}=fe;if(!re||!xe||re===xe)return;const Ee=R.get(xe);if(!Ee)return;if(Ee.blockedBy?.includes(re)){_(p("work:dag.toast.dependencyExists"),"error");return}if(jh(R,re,xe)){_(p("work:dag.toast.cycleError"),"error");return}const ye=[...Ee.blockedBy??[],re];try{await ae.tasks.update(xe,{blockedBy:ye}),_(p("work:dag.toast.dependencyAdded")),l?.()}catch(Ie){_(p("work:dag.toast.failed",{message:Ie instanceof Error?Ie.message:String(Ie)}),"error")}},[R,_,l,p]),ue=g.useCallback((fe,re)=>{x(re)},[]),K=g.useCallback(async()=>{if(!v)return;const fe=R.get(v.target);if(!fe){x(null);return}const re=(fe.blockedBy??[]).filter(xe=>xe!==v.source);try{await ae.tasks.update(v.target,{blockedBy:re}),_(p("work:dag.toast.dependencyRemoved")),l?.()}catch(xe){_(p("work:dag.toast.failed",{message:xe instanceof Error?xe.message:String(xe)}),"error")}x(null)},[v,R,_,l,p]);if(e.length===0)return t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"flex flex-col items-center gap-3 max-w-sm text-center",children:[t.jsx("svg",{className:"w-10 h-10 text-fg-quaternary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:p("work:task.dagEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:p("work:task.dagEmptyDesc")})]})});const ce=b.size===Yr.size&&[...Yr].every(fe=>b.has(fe))&&!L,ge=v?R.get(v.source):null,ve=v?R.get(v.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(uf,{nodes:q,edges:J,onNodesChange:Z,onEdgesChange:te,onNodeClick:se,onConnect:me,onEdgeClick:ue,onMoveEnd:de,onInit:fe=>{X.current=fe},nodeTypes:xh,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[u&&t.jsx(bh,{nodeIds:q.map(fe=>fe.id),rfRef:X}),t.jsx(yf,{color:M?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(Sf,{showInteractive:!1,className:"!bg-surface-secondary !border-border-default !shadow-xl [&>button]:!bg-surface-elevated [&>button]:!border-border-default [&>button]:!text-fg-secondary [&>button:hover]:!bg-surface-overlay"}),t.jsx(Bf,{nodeColor:fe=>{const re=fe.data?.task,xe=re?.status;return re?.taskType==="scheduled"?"#8b8fa3":xe==="completed"||xe==="accepted"?"#10b981":xe==="in_progress"?"#f59e0b":xe==="blocked"||xe==="failed"?"#ef4444":M?"#94a3b8":"#6b7280"},maskColor:M?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),t.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-surface-secondary/90 border border-border-default rounded-lg backdrop-blur-sm z-10 flex flex-col items-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[j.map(fe=>{const re=b.has(fe.id);return t.jsx("button",{onClick:()=>O(fe.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${re?`${fe.color.bg} ${fe.color.border} ${fe.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:p(`work:dag.filter.${fe.id}`)},fe.id)}),P>0&&t.jsx("button",{onClick:()=>E(fe=>!fe),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${L?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:p("work:dag.archivedToggle",{count:P})}),!ce&&t.jsx("button",{onClick:()=>{k(new Set(Yr)),E(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:p("work:dag.reset")})]}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[N?t.jsx("button",{onClick:Y,className:"text-brand-500 hover:text-brand-400 transition-colors",children:p("work:dag.backToOverview")}):t.jsx("span",{children:p("work:dag.expandHint")}),t.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),t.jsx("span",{children:p("work:dag.dragHint")})]})]}),C&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${C.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:C.msg}),v&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>x(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:fe=>fe.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:p("work:dag.removeDependencyTitle")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:p("work:dag.removeDependencyBody",{target:ve?.title??v.target.slice(-8),source:ge?.title??v.source.slice(-8)})}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>x(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:p("common:cancel")}),t.jsx("button",{onClick:K,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:p("common:remove")})]})]})})]})}function Sh({orgId:e,onCreated:n,onClose:s}){const{t:r}=We(["work","common"]);Wl(!0);const[i,o]=g.useState(""),[a,c]=g.useState(""),[l,d]=g.useState(""),[h,f]=g.useState("main"),[m,u]=g.useState([]),[p,M]=g.useState([]),[C,y]=g.useState(!1),[v,x]=g.useState(""),[b,k]=g.useState(!1),N=vr();g.useEffect(()=>{ae.teams.list().then(D=>M(D.teams)).catch(()=>{})},[]),g.useEffect(()=>{const D=L=>{L.key==="Escape"&&s()};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[s]);const I=g.useCallback(async D=>{if(D?.preventDefault(),k(!0),!(!i.trim()||C)){y(!0),x("");try{const L=l.trim()?[{url:l.trim(),defaultBranch:h.trim()||"main"}]:[],E=await ae.projects.create({name:i.trim(),description:a.trim()||void 0,repositories:L.length>0?L:void 0,teamIds:m.length>0?m:void 0,orgId:e??"default"});n(E.project)}catch(L){x(L instanceof Error?L.message:r("project.failedToCreate"))}y(!1)}},[i,a,l,h,m,e,C,n,r]),B=b&&!i.trim();return Vl.createPortal(t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:s,children:t.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto ${N?"w-full":"w-[520px]"}`,onClick:D=>D.stopPropagation(),onSubmit:I,children:[t.jsx("h3",{className:"text-base font-semibold mb-5",children:r("project.newProject")}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.projectName")}),t.jsx("input",{value:i,onChange:D=>{o(D.target.value),x("")},onBlur:()=>k(!0),placeholder:r("project.projectNamePlaceholder"),className:`input ${B?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!N}),B&&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:D=>c(D.target.value),placeholder:r("project.descriptionPlaceholder"),className:"input",rows:3})]}),p.length>0&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.assignTeams")}),t.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:p.map(D=>{const L=m.includes(D.id);return t.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer hover:text-fg-primary py-0.5",children:[t.jsx("input",{type:"checkbox",checked:L,onChange:()=>u(E=>L?E.filter(P=>P!==D.id):[...E,D.id]),className:"accent-brand-500"}),t.jsx("span",{className:"truncate",children:D.name})]},D.id)})})]}),t.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.repositoryUrl")}),t.jsx("input",{value:l,onChange:D=>d(D.target.value),placeholder:r("project.repositoryPlaceholder"),className:"input"})]}),l.trim()&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.branch")}),t.jsx("input",{value:h,onChange:D=>f(D.target.value),placeholder:r("project.branchPlaceholder"),className:"input !w-24"})]})]}),v&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:v}),t.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||C,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:r(C?"common:creating":"project.createProject")})]})]})]})}),document.body)}function Eh({projects:e,selectedProjectId:n,allSelected:s,taskCounts:r,totalTaskCount:i,onSelectAll:o,onSelectProject:a,onCreateProject:c,onCollapse:l,width:d,onResizeStart:h,hidden:f,focused:m,onActivate:u}){const{t:p}=We(["work","common"]),M=s??n==null;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-keyboard-pane":"l1",onPointerDown:()=>u?.(),className:"bg-surface-primary flex flex-col shrink-0 border-r border-border-default/60",style:f?{display:"none"}:d!=null?{width:d}:void 0,children:[t.jsxs("div",{"data-electron-drag":!0,className:"px-3 h-14 flex items-center shrink-0 gap-2",children:[l&&t.jsx("button",{type:"button","data-no-drag":!0,onClick:l,className:"w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 bg-brand-500/15 text-brand-500 hover:bg-brand-500/25",title:p("common:shortcuts.toggleLeft"),children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),t.jsx("h2",{className:"text-sm font-semibold text-fg-primary truncate",children:p("work:task.projects",{defaultValue:"Projects"})}),t.jsx("button",{type:"button","data-no-drag":!0,onClick:c,className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:p("work:project.newProject"),children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:e.length===0?t.jsxs("div",{className:"px-2 py-8 text-center space-y-3",children:[t.jsx("div",{className:"w-10 h-10 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),t.jsx("p",{className:"text-[11px] text-fg-tertiary leading-relaxed px-1",children:p("work:task.emptyNoProjectsHint")}),t.jsx("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:p("work:project.newProject")})]}):t.jsxs(t.Fragment,{children:[o&&t.jsxs("button",{type:"button","data-project-id":"__all__",onClick:o,className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors ${M?m?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[t.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center shrink-0 ${M?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),t.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),t.jsx("span",{className:"min-w-0 flex-1",children:t.jsx("span",{className:"block text-[12px] font-medium truncate",children:p("work:task.all")})}),(i??0)>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:i})]}),e.map(C=>{const y=!M&&C.id===n,v=r[C.id]??0,x=C.status==="paused";return t.jsxs("button",{type:"button","data-project-id":C.id,onClick:()=>a(C.id),className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors ${y?m?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[t.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center text-[11px] font-bold shrink-0 ${y?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:C.name[0]?.toUpperCase()??"?"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block text-[12px] font-medium truncate",children:C.name}),x&&t.jsx("span",{className:"block text-[10px] text-amber-500/80",children:p("work:project.statusPaused")})]}),v>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:v})]},C.id)})]})})]}),!f&&h&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:h,children:t.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})})]})}const Aa="markus_work_l1_collapsed",Mh=["backlog","kanban","dag","workflows"];function ro(e){const n=e.agentId,s=e.activityId;return!n||!s?null:Qa({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},s,n)}function so(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 oo({entries:e}){const[n,s]=g.useState("compact");return e.length===0?null:t.jsx("div",{onClick:r=>r.stopPropagation(),children:n==="compact"?t.jsx(Ul,{entries:e,isActive:!0,onExpand:()=>s("full"),embedded:!0}):t.jsx(Ja,{entries:e,isActive:!0,onCollapse:()=>s("compact"),embedded:!0})})}function ao(e,n){const[s,r]=g.useState(null);return g.useEffect(()=>{if(!n||!e.current){r(null);return}const i=()=>{const o=e.current?.getBoundingClientRect();if(!o)return;const a=240,c=window.innerHeight-o.bottom-8,l=o.top-8,d=c<a&&l>c;r(d?{top:o.top-4,left:o.left,width:o.width,flipUp:!0}:{top:o.bottom+4,left:o.left,width:o.width,flipUp:!1})};return i(),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[n,e]),s}function cr({options:e,value:n,onChange:s,placeholder:r,noMatchesText:i,className:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=ao(f,a);g.useEffect(()=>{const y=v=>{h.current&&!h.current.contains(v.target)&&u.current&&!u.current.contains(v.target)&&c(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]);const M=e.find(y=>y.value===n)?.label??"",C=l?e.filter(y=>y.label.toLowerCase().includes(l.toLowerCase())):e;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:l,onChange:y=>d(y.target.value),onClick:y=>y.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:M||r,autoFocus:!0}):t.jsx("span",{className:M?"text-fg-primary":"text-fg-tertiary",children:M||r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&p&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:C.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):C.map(y=>t.jsx("div",{onClick:()=>{s(y.value),c(!1),d("")},className:`px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 ${y.value===n?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:y.label},y.value))})]})}function Ih({options:e,selected:n,onAdd:s,placeholder:r,noMatchesText:i,className:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=ao(f,a);g.useEffect(()=>{const y=v=>{h.current&&!h.current.contains(v.target)&&u.current&&!u.current.contains(v.target)&&c(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]);const M=e.filter(y=>!n.includes(y.value)),C=l?M.filter(y=>y.label.toLowerCase().includes(l.toLowerCase())):M;return t.jsxs("div",{ref:h,className:o??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:l,onChange:y=>d(y.target.value),onClick:y=>y.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:r,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&p&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:C.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):C.map(y=>t.jsx("div",{onClick:()=>{s(y.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:y.label},y.value))})]})}function Th({options:e,onSelect:n,placeholder:s,noMatchesText:r,className:i,itemSuffix:o}){const[a,c]=g.useState(!1),[l,d]=g.useState(""),h=g.useRef(null),f=g.useRef(null),m=g.useRef(null),u=g.useRef(null),p=ao(f,a);g.useEffect(()=>{const C=y=>{h.current&&!h.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&c(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]);const M=l?e.filter(C=>C.label.toLowerCase().includes(l.toLowerCase())):e;return t.jsxs("div",{ref:h,className:i??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:l,onChange:C=>d(C.target.value),onClick:C=>C.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-[11px]",placeholder:s,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:s}),t.jsx("svg",{className:"w-3.5 h-3.5 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&p&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:p.flipUp?{bottom:window.innerHeight-p.top,left:p.left,width:p.width}:{top:p.top,left:p.left,width:p.width},children:M.length===0?t.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:r??"No matches"}):M.map(C=>t.jsxs("div",{onClick:()=>{n(C.value),c(!1),d("")},className:"px-3 py-2 text-xs cursor-pointer hover:bg-brand-500/10 text-fg-primary flex items-center justify-between gap-2",children:[t.jsx("span",{className:"truncate",children:C.label}),o?.(C)]},C.value))})]})}function Qn(e,n,s,r="Admin"){if(!e)return null;const i=n.find(a=>a.id===e);if(i)return i.name;const o=s.find(a=>a.id===e);return o?o.name:e==="anonymous"?r:null}function Rh({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=We(["work","common"]),[o,a]=g.useState(!1),[c,l]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{l(e)},[e]),g.useEffect(()=>{o&&d.current?.focus()},[o]);const h=async()=>{a(!1);const f=c.trim();if(f&&f!==e)try{await n(f)}catch{l(e)}else l(e)};return o?t.jsx("input",{ref:d,value:c,onChange:f=>l(f.target.value),onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&h(),f.key==="Escape"&&(l(e),a(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${s??""}`,placeholder:r}):t.jsx("span",{onClick:()=>a(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.clickToEdit")})})}function _h({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=We(["work","common"]),[o,a]=g.useState(!1),[c,l]=g.useState(e),d=g.useRef(null);g.useEffect(()=>{l(e)},[e]),g.useEffect(()=>{o&&d.current&&(d.current.focus(),d.current.style.height="auto",d.current.style.height=d.current.scrollHeight+"px")},[o]);const h=async()=>{a(!1);const f=c.trim();if(f!==e)try{await n(f)}catch{l(e)}else l(e)};return o?t.jsx("textarea",{ref:d,value:c,onChange:f=>{l(f.target.value),f.target.style.height="auto",f.target.style.height=f.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Escape"&&(l(e),a(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${s??""}`,placeholder:r,rows:2}):t.jsx("p",{onClick:()=>a(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${s??""}`,title:i("work:task.clickToEdit"),children:e||t.jsx("span",{className:"text-fg-tertiary italic",children:r??i("work:task.addDescription")})})}const Lh=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function xl(e){const n=e.match(Lh);return n?{timestamp:n[1].trim(),author:n[2]?.trim()??"System",content:n[3].trim()}:{timestamp:"",author:"",content:e}}function Ah(e,n){if(!e)return"";const s=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!s)return e;const r=new Date,i=+s[1],o=+s[2]-1,a=+s[3],c=+s[4],l=+s[5],d=new Date(i,o,a,c,l),h=r.getTime()-d.getTime();return h<6e4?n("work:relative.justNow"):h<36e5?n("work:relative.minutesAgo",{count:Math.floor(h/6e4)}):h<864e5?n("work:relative.hoursAgo",{count:Math.floor(h/36e5)}):h<6048e5?n("work:relative.daysAgo",{count:Math.floor(h/864e5)}):`${i}-${String(o+1).padStart(2,"0")}-${String(a).padStart(2,"0")}`}const Da=[{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 Dh(e){let n=0;for(let s=0;s<e.length;s++)n=(n<<5)-n+e.charCodeAt(s)|0;return Da[Math.abs(n)%Da.length]}function Ph({note:e,compact:n}){const{t:s}=We(["work","common"]),r=xl(e),i=s("work:task.systemAuthor"),o=Dh(r.author||i),a=r.author?r.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",c=Ah(r.timestamp,s),l=!r.author||r.author==="System";return n?t.jsxs("div",{className:"flex gap-2.5 group",children:[t.jsx("div",{className:`w-6 h-6 rounded-full ${o.bg} flex items-center justify-center text-[9px] font-bold ${o.text} shrink-0 mt-0.5`,children:a}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium ${l?"text-fg-tertiary":o.text}`,children:l?i:r.author}),c&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:c})]}),t.jsx("div",{className:"text-xs text-fg-secondary",children:t.jsx(fr,{content:r.content,className:"text-xs text-fg-secondary"})})]})]}):t.jsxs("div",{className:"flex gap-3 group",children:[t.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[t.jsx("div",{className:`w-7 h-7 rounded-full ${o.bg} flex items-center justify-center text-[10px] font-bold ${o.text}`,children:a}),t.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),t.jsx("div",{className:"flex-1 min-w-0 pb-4",children:t.jsxs("div",{className:`border ${o.border} rounded-lg overflow-hidden`,children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${o.bg} border-b ${o.border}`,children:[t.jsx("span",{className:`text-[11px] font-medium ${l?"text-fg-secondary":o.text}`,children:l?i:r.author}),c&&t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:c})]}),t.jsx("div",{className:"px-3 py-2.5",children:t.jsx(fr,{content:r.content,className:"text-xs text-fg-secondary"})})]})})]})}const $h=new Set(["rejected","cancelled","archived"]),ss=[{id:"failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",statuses:["pending"],accent:"border-t-amber-500",dropStatus:"pending"},{id:"in_progress",statuses:["in_progress","blocked"],accent:"border-t-brand-500",dropStatus:"in_progress"},{id:"review",statuses:["review"],accent:"border-t-purple-500",dropStatus:"review"},{id:"done",statuses:["completed"],accent:"border-t-green-500",dropStatus:"completed"},{id:"closed",statuses:["rejected","cancelled","archived"],accent:"border-t-gray-500",dropStatus:"cancelled"}],Pa={pending:"bg-amber-500/15 text-amber-600",blocked:"bg-amber-500/15 text-amber-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500"},$a={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-blue-500/15 text-blue-500",blocked:"bg-orange-500/15 text-orange-500",review:"bg-purple-500/15 text-purple-500",revision:"bg-amber-500/15 text-amber-600",completed:"bg-green-500/15 text-green-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-500/15 text-fg-tertiary",archived:"bg-gray-500/15 text-fg-tertiary"},Oa={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"},Ba={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 bl(e){return Object.keys($a).reduce((n,s)=>(n[s]={label:e(`work:status.task.${s}`),cls:$a[s]},n),{})}function yl(e){return Object.keys(Pa).reduce((n,s)=>(n[s]={label:e(`work:status.sub.${s}`),cls:Pa[s]},n),{})}function Oh(e){return Object.keys(Oa).reduce((n,s)=>(n[s]={label:e(`work:priority.${s}`),cls:Oa[s]},n),{})}function io(e){return Object.keys(Ba).reduce((n,s)=>(n[s]={label:e(`work:status.requirement.${s}`),cls:Ba[s]},n),{})}const za=["low","medium","high","urgent"],Ha=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],qa=["pending","in_progress","completed","rejected","cancelled"],Wa={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived"]),archived:new Set([])},qs={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},yr={idle:"bg-green-400",working:"bg-blue-400",error:"bg-red-400",paused:"bg-amber-400",offline:"bg-gray-600",pending:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",rejected:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},Va={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function Bh({agent:e,anchorRect:n,onClose:s}){const{t:r}=We(["work","common"]),i=g.useRef(null);g.useEffect(()=>{const c=l=>{i.current&&!i.current.contains(l.target)&&s()};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s]);const o=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",a=e.status==="idle"?r("work:task.online"):e.status==="working"?r("work:task.working"):e.status==="error"?r("work:task.error"):r("work:task.offline");return t.jsxs("div",{ref:i,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:n.top+4,left:n.left},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[10px] font-bold text-brand-600 shrink-0",children:e.name.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),t.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),t.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o}`}),t.jsx("span",{className:"text-[10px] text-fg-secondary",children:a})]})]})]}),t.jsx("button",{onClick:()=>{s(),Bt.navigate(Fe.TEAM,{selectAgent:e.id})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1 transition-colors",children:r("work:task.viewProfile")})]})}function ur({comment:e,agents:n,onReply:s}){const{t:r}=We(["work","common"]),i=e.authorType==="agent"||e.authorType==="system",o=new Date(e.createdAt),a=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),c=o.toLocaleDateString([],{month:"short",day:"numeric"}),[l,d]=g.useState(null),[h,f]=g.useState(!1),[m,u]=g.useState([]),[p,M]=g.useState(!1),C=g.useCallback((k,N)=>{const I=n.find(B=>B.name.toLowerCase()===k.toLowerCase());if(I){const B=N.target.getBoundingClientRect();d({agent:I,top:B.bottom,left:B.left})}},[n]),y=g.useMemo(()=>n.map(k=>k.name),[n]),v=g.useCallback(k=>{const N=n.find(I=>I.name.toLowerCase()===e.authorName.toLowerCase());if(N){const I=k.currentTarget.getBoundingClientRect();d({agent:N,top:I.bottom,left:I.left})}},[n,e.authorName]),x=g.useCallback(async()=>{if(h){f(!1);return}const k=e.activityId;if(k&&(f(!0),!(m.length>0))){M(!0);try{const{logs:N}=await ae.agents.getActivityLogs(e.authorId,k),I=N.map(B=>Qa(B,k,e.authorId)).filter(B=>B!==null).map(B=>({...B,ts:new Date(B.createdAt).getTime()}));u(I)}catch{}M(!1)}},[h,m.length,e]),b=g.useMemo(()=>As(m.map(Ls).filter(k=>k!==null)),[m]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[t.jsx("div",{onClick:v,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${i?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${i?"text-indigo-400":"text-blue-400"}`,onClick:v,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[c," ",a]}),s&&t.jsx("button",{onClick:()=>s(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r("work:task.reply")}),e.activityId&&i&&t.jsx("button",{onClick:x,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r(h?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&t.jsxs("button",{onClick:()=>{const k=document.getElementById(`comment-${e.replyTo}`);k&&(k.scrollIntoView({behavior:"smooth",block:"center"}),k.classList.add("bg-brand-500/10"),setTimeout(()=>k.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[t.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),t.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),t.jsx(fr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:C,knownNames:y}),e.attachments?.map((k,N)=>k.type==="image"?t.jsx("img",{src:k.url,alt:k.name,className:"mt-1 max-w-[200px] rounded"},N):null),h&&t.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:p?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:r("work:task.loadingExecutionLog")}):b.length===0?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:r("work:task.noExecutionLogAvailable")}):t.jsx(Ja,{entries:m,isActive:!1,onCollapse:()=>f(!1),embedded:!0})})]}),l&&t.jsx(Bh,{agent:l.agent,anchorRect:{top:l.top,left:l.left},onClose:()=>d(null)})]})}function zh({task:e,agents:n,users:s,authUser:r}){const{t:i}=We(["work","common"]),[o,a]=g.useState([]),[c,l]=g.useState([]),d=g.useRef(null),[h,f]=g.useState(new Map);g.useEffect(()=>{l([]),f(new Map),d.current&&(clearTimeout(d.current),d.current=null),ae.tasks.getComments(e.id).then(y=>a(y.comments)).catch(()=>{})},[e.id]),g.useEffect(()=>jt.on("task:comment",v=>{if(v.payload?.taskId===e.id&&v.payload.comment){const x=v.payload.comment;a(b=>b.some(k=>k.id===x.id)?b:[...b,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(l(b=>{const k=b.filter(N=>N.id!==x.authorId);return k.length===0&&d.current&&(clearTimeout(d.current),d.current=null),k}),f(b=>{const k=new Map(b);return k.delete(x.authorId),k}))}}),[e.id]),g.useEffect(()=>{if(c.length===0)return;const y=new Set(c.map(x=>x.id));return jt.on("agent:activity_log",x=>{const b=x.payload;if(!b)return;const k=b.agentId;if(!y.has(k))return;const N=ro(b);N&&f(I=>so(I,k,N))})},[c]);const m=g.useMemo(()=>{const y=[];for(const v of e.notes??[]){const x=xl(v);let b;if(x.timestamp){const k=x.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);b=k?new Date(+k[1],+k[2]-1,+k[3],+k[4],+k[5],+(k[6]??0)):new Date(0)}else b=new Date(0);y.push({type:"note",note:v,ts:b})}for(const v of o)y.push({type:"comment",comment:v,ts:new Date(v.createdAt)});return y.sort((v,x)=>v.ts.getTime()-x.ts.getTime()),y},[e.notes,o]),[u,p]=g.useState(null),M=async(y,v,x,b)=>{let k;x.length>0&&(k=(await ae.uploads.upload(x.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await ae.tasks.addComment(e.id,y,r?.name,k,r?.id,v.length>0?v:void 0,b);const N=[],I=new Set,B=D=>{if(I.has(D)||D===r?.id)return;I.add(D);const L=n.find(E=>E.id===D);L&&N.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const D of v){const L=n.find(E=>E.name.toLowerCase()===D.toLowerCase());L&&B(L.id)}e.assignedAgentId&&B(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&B(e.createdBy),N.length>0&&(d.current&&clearTimeout(d.current),l(N),d.current=setTimeout(()=>l([]),12e4))},C=g.useCallback(y=>{p({id:y.id,authorName:y.authorName,content:y.content.slice(0,100)})},[]);return t.jsxs("div",{className:"mt-5",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:i("work:task.activityCommentsHeading")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[m.length===0&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:i("work:task.noActivityYet")}),m.map((y,v)=>y.type==="note"?t.jsx(Ph,{note:y.note,compact:!0},`n-${v}`):t.jsx(ur,{comment:y.comment,agents:n,onReply:C},`c-${y.comment.id}`)),c.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(y=>{const v=h.get(y.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(Fe.TEAM,{agentId:y.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Vs,{name:y.name,avatarUrl:y.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:y.name}),v.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),v.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(oo,{entries:v})})]},y.id)})})]}),t.jsx(ti,{agents:n,humans:s,onSubmit:M,replyTo:u,onCancelReply:()=>p(null),placeholder:i("work:task.commentPlaceholder")})]})}function Hh({task:e,isRunning:n,authUser:s,agents:r}){const i=e.id,{t:o}=We(["work","common"]),[a,c]=g.useState([]),[l,d]=g.useState(new Map),[h,f]=g.useState(new Set),[m,u]=g.useState([]),[p,M]=g.useState(""),[C,y]=g.useState(n),[v,x]=g.useState(!0),[b,k]=g.useState(new Set),[N,I]=g.useState(""),[B,D]=g.useState(!1),[L,E]=g.useState([]),P=g.useRef(null),[z,j]=g.useState(new Map),[O,_]=g.useState([]),[T,R]=g.useState([]),[A,W]=g.useState(!1),Y=g.useRef(null),F=g.useRef(null);g.useEffect(()=>{y(n)},[n]),g.useEffect(()=>{E([]),j(new Map),P.current&&(clearTimeout(P.current),P.current=null)},[i]),g.useEffect(()=>{x(!0),Promise.all([ae.tasks.getLogsSummary(i).catch(()=>({rounds:[]})),ae.tasks.getComments(i).catch(()=>({comments:[]}))]).then(([X,ie])=>{const de=X.rounds;if(c(de),u(ie.comments),de.length===0){x(!1);return}const se=de[de.length-1].round;k(new Set([se])),ae.tasks.getLogs(i,se).catch(()=>({logs:[]})).then(me=>{d(new Map([[se,me.logs]])),x(!1)})})},[i]),g.useEffect(()=>{const X=e.assignedAgentId;X&&(W(!0),ae.agents.getActivities(X,{taskId:i,limit:20}).then(ie=>R(ie.activities)).catch(()=>R([])).finally(()=>W(!1)))},[i,e.assignedAgentId]);const Q=g.useCallback(X=>{l.has(X)||h.has(X)||(f(ie=>new Set(ie).add(X)),ae.tasks.getLogs(i,X).catch(()=>({logs:[]})).then(ie=>{d(de=>new Map(de).set(X,ie.logs)),f(de=>{const se=new Set(de);return se.delete(X),se})}))},[i,l,h]),$=g.useCallback(X=>{k(ie=>{const de=new Set(ie);return de.has(X)?de.delete(X):(de.add(X),l.has(X)||Q(X)),de})},[l,Q]);g.useEffect(()=>{const X=jt.on("task:log",se=>{const me=se.payload;if(me.taskId!==i)return;const ue={id:me.id,taskId:me.taskId,agentId:me.agentId,seq:me.seq,type:me.logType,content:me.content,metadata:me.metadata,executionRound:me.executionRound,createdAt:me.createdAt},K=ue.executionRound??1;c(ce=>ce.find(ve=>ve.round===K)?ce:[...ce,{round:K,logCount:0,toolCount:0,firstAt:ue.createdAt,lastAt:ue.createdAt,status:"running"}]),k(ce=>ce.has(K)?ce:new Set(ce).add(K)),d(ce=>{const ge=ce.get(K)??[];return ue.id&&ge.some(ve=>ve.id===ue.id)?ce:new Map(ce).set(K,[...ge,ue])}),ue.type==="text"&&M(""),ue.type==="status"&&(ue.content==="started"||ue.content==="resumed"?y(!0):["completed","failed","cancelled","execution_finished"].includes(ue.content)&&(y(!1),c(ce=>ce.map(ge=>ge.round===K?{...ge,status:ue.content}:ge)))),ue.type==="error"&&y(!1)}),ie=jt.on("task:log:delta",se=>{const me=se.payload;me.taskId===i&&M(ue=>ue+me.text)}),de=jt.on("task:comment",se=>{const me=se.payload;if(me.taskId!==i)return;const ue=me.comment;u(K=>K.some(ce=>ce.id===ue.id)?K:[...K,ue]),(ue.authorType==="agent"||ue.authorId?.startsWith("agt_"))&&(E(K=>{const ce=K.filter(ge=>ge.id!==ue.authorId);return ce.length===0&&P.current&&(clearTimeout(P.current),P.current=null),ce}),j(K=>{const ce=new Map(K);return ce.delete(ue.authorId),ce}))});return()=>{X(),ie(),de()}},[i]),g.useEffect(()=>{if(L.length===0)return;const X=new Set(L.map(de=>de.id));return jt.on("agent:activity_log",de=>{const se=de.payload;if(!se)return;const me=se.agentId;if(!X.has(me))return;const ue=ro(se);ue&&j(K=>so(K,me,ue))})},[L]);const S=g.useMemo(()=>{const X=[];for(const[,ie]of l)X.push(...ie);return X.sort((ie,de)=>ie.seq-de.seq),X},[l]),V=g.useMemo(()=>S.map(X=>Lo(X)),[S]),q=a.length>1,H=X=>{const ie=X.target.files;if(ie){for(const de of Array.from(ie)){if(!de.type.startsWith("image/"))continue;const se=new FileReader;se.onload=()=>{_(me=>[...me,{type:"image",url:se.result,name:de.name}])},se.readAsDataURL(de)}X.target.value=""}},Z=async()=>{if(!(!N.trim()&&O.length===0)){D(!0);try{let X;O.length>0&&(X=(await ae.uploads.upload(O.map(K=>({dataUrl:K.url,name:K.name})),"comments")).files.map(K=>({type:"image",url:K.url,name:K.name})));const ie=await ae.tasks.addComment(i,N,s?.name,X,s?.id);ie.comment&&u(ue=>ue.some(K=>K.id===ie.comment.id)?ue:[...ue,ie.comment]),I(""),_([]);const de=[],se=new Set,me=ue=>{if(se.has(ue)||ue===s?.id)return;se.add(ue);const K=r.find(ce=>ce.id===ue);K&&de.push({id:K.id,name:K.name,avatarUrl:K.avatarUrl})};e.assignedAgentId&&me(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&me(e.createdBy),de.length>0&&(P.current&&clearTimeout(P.current),E(de),P.current=setTimeout(()=>E([]),12e4))}catch{}D(!1)}},J=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[O.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:O.map((X,ie)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:X.url,alt:X.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>_(de=>de.filter((se,me)=>me!==ie)),className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-600 text-white text-[10px] flex items-center justify-center opacity-0 group-hover:opacity-100",children:"×"})]},ie))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:N,onChange:X=>I(X.target.value),onKeyDown:X=>{X.key==="Enter"&&!X.shiftKey&&(X.preventDefault(),Z())},placeholder:o("work:task.commentInstructionPlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-blue-500 outline-none text-fg-primary placeholder-gray-600"}),t.jsx("input",{type:"file",ref:Y,accept:"image/*",multiple:!0,onChange:H,className:"hidden"}),t.jsx("button",{onClick:()=>Y.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:o("work:task.attachImage"),children:"📎"}),t.jsx("button",{onClick:()=>{Z()},disabled:B||!N.trim()&&O.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:o("common:send")})]})]});if(v)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:o("work:task.loadingLogs")});if(a.length===0&&!p){const X=e.assignedAgentId?r.find(ve=>ve.id===e.assignedAgentId):void 0,ie=T.length>0,de=X&&X.currentTaskId&&X.currentTaskId!==e.id,se=e.status==="pending",me=e.status==="in_progress",ue=!e.assignedAgentId;let K="📋",ce=o("work:task.emptyLogs.default"),ge=o("work:task.emptyLogs.defaultHint");return ue?(K="👤",ce=o("work:task.emptyLogs.noAgent"),ge=o("work:task.emptyLogs.noAgentHint")):se?(K="⏳",ce=o("work:task.emptyLogs.pending"),ge=o("work:task.emptyLogs.pendingHint")):me&&de?(K="🔄",ce=o("work:task.emptyLogs.agentBusy",{agent:X?.name??e.assignedAgentId}),ge=o("work:task.emptyLogs.agentBusyHint")):me&&(K="⏳",ce=o("work:task.emptyLogs.starting"),ge=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:A?t.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:o("work:task.loadingLogs")}):ie?t.jsxs("div",{className:"px-4 py-4",children:[t.jsxs("div",{className:"text-xs text-fg-secondary mb-3 flex items-center gap-1.5",children:[t.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-blue-500"}),o("work:task.relatedSessions",{agent:X?.name??o("work:task.agent"),count:T.length})]}),t.jsx("div",{className:"space-y-1.5",children:T.map(ve=>{const fe=!ve.endedAt,re=ve.type==="task"?"🔧":ve.type==="chat"||ve.type==="respond_in_session"?"💬":ve.type==="heartbeat"?"💓":"📋";return t.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default/50 text-left transition-colors group",onClick:()=>Bt.navigate(Fe.TEAM,{agentId:e.assignedAgentId}),children:[t.jsx("span",{className:"text-sm shrink-0",children:re}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary truncate",children:ve.label}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(ve.startedAt).toLocaleString(),ve.endedAt?` — ${ve.totalTools} tools, ${ve.totalTokens.toLocaleString()} tokens`:""]})]}),fe&&t.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10px] text-green-500 font-medium",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"}),o("work:task.sessionLive")]}),!fe&&t.jsx("span",{className:`shrink-0 text-[10px] ${ve.success?"text-fg-tertiary":"text-red-400"}`,children:ve.success?"✓":"✗"}),t.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},ve.id)})})]}):t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsxs("div",{className:"text-center text-fg-tertiary",children:[t.jsx("div",{className:"text-2xl mb-2",children:K}),t.jsxs("div",{className:"text-xs",children:[ce,t.jsx("br",{}),t.jsx("span",{className:"text-fg-muted",children:ge})]})]})})}),J]})}if(!q){const X=V.map(se=>Ls(se)).filter(se=>se!==null),ie=Ao(S,As(X)),de=[...ie.map(se=>({kind:"entry",entry:se,ts:se.timestamp?new Date(se.timestamp).getTime():0})),...m.map(se=>({kind:"comment",comment:se,ts:new Date(se.createdAt).getTime()}))];return de.sort((se,me)=>se.ts-me.ts),t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-0.5",children:[de.map((se,me)=>se.kind==="comment"?t.jsx(ur,{comment:se.comment,agents:r},`c-${se.comment.id}`):t.jsx(Do,{entry:se.entry,showTime:!0,isLast:me===de.length-1},`e-${me}`)),C&&p&&t.jsx(Po,{content:p}),C&&!p&&ie.length>0&&t.jsx($o,{})]}),J]})}const le=(X,ie)=>{const de=X.firstAt?new Date(X.firstAt).getTime():0,se=ie?.firstAt?new Date(ie.firstAt).getTime():1/0;return m.filter(me=>{const ue=new Date(me.createdAt).getTime();return ue>=de&&ue<se})},te=a.length>0?m.filter(X=>new Date(X.createdAt).getTime()<new Date(a[0].firstAt).getTime()):[];return t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsx("div",{ref:F}),t.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[te.length>0&&t.jsx("div",{className:"space-y-0.5",children:te.map(X=>t.jsx(ur,{comment:X,agents:r},X.id))}),a.map((X,ie)=>{const de=b.has(X.round),se=X.round===a[a.length-1].round,me=l.get(X.round),ue=h.has(X.round),K=le(X,a[ie+1]),ce=X.status==="completed"||X.status==="execution_finished"?"✅":X.status==="failed"?"❌":X.status==="cancelled"?"⏹":"🔄",ge=X.lastAt&&X.firstAt?Math.max(0,new Date(X.lastAt).getTime()-new Date(X.firstAt).getTime()):0,ve=ge>=6e4?`${Math.floor(ge/6e4)}m ${Math.floor(ge%6e4/1e3)}s`:ge>=1e3?`${Math.floor(ge/1e3)}s`:"";return t.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[t.jsxs("button",{onClick:()=>$(X.round),className:"w-full flex items-center justify-between px-3 py-2 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm",children:ce}),t.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:o("work:task.roundHeader",{n:X.round})}),K.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",K.length]}),se&&C&&t.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.toolCount",{count:X.toolCount})}),ve&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:ve}),t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${de?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})]}),de&&t.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[ue&&t.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:o("work:task.loadingRound",{n:X.round})}),me&&(()=>{const re=me.map(ye=>Lo(ye)).map(ye=>Ls(ye)).filter(ye=>ye!==null),Ee=[...Ao(me,As(re)).map(ye=>({kind:"entry",entry:ye,ts:ye.timestamp?new Date(ye.timestamp).getTime():0})),...K.map(ye=>({kind:"comment",comment:ye,ts:new Date(ye.createdAt).getTime()}))];return Ee.sort((ye,Ie)=>ye.ts-Ie.ts),Ee.map((ye,Ie)=>ye.kind==="comment"?t.jsx(ur,{comment:ye.comment,agents:r},`c-${ye.comment.id}`):t.jsx(Do,{entry:ye.entry,showTime:!0,isLast:Ie===Ee.length-1},`e-${Ie}`))})(),se&&C&&p&&t.jsx(Po,{content:p}),se&&C&&!p&&!ue&&t.jsx($o,{})]})]},X.round)}),L.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:L.map(X=>{const ie=z.get(X.id)??[];return t.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(Fe.TEAM,{agentId:X.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Vs,{name:X.name,avatarUrl:X.avatarUrl,size:24,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx("span",{className:"text-xs font-medium text-fg-secondary truncate",children:X.name}),ie.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")})]}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),ie.length>0&&t.jsx("div",{className:"ml-9 mt-1",children:t.jsx(oo,{entries:ie})})]},X.id)})})]}),J]})}const Fa=new Set([".md",".markdown",".txt",".json",".yaml",".yml",".toml",".csv",".xml",".html",".htm",".css",".js",".ts",".jsx",".tsx",".py",".sh",".log",".env",".cfg",".ini",".png",".jpg",".jpeg",".gif",".webp",".svg",".mp3",".wav",".ogg",".flac",".aac",".m4a",".opus",".mp4",".webm",".mov",".mkv",".m4v"]);function Gr(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function qh({filePath:e,onClose:n,onOpenExternal:s}){const{t:r}=We(["work","common"]),[i,o]=g.useState([e]),a=i[i.length-1],[c,l]=g.useState(null),[d,h]=g.useState(null),[f,m]=g.useState(!0);g.useEffect(()=>{m(!0),h(null),l(null),ae.files.preview(a).then(k=>l(k)).catch(k=>h(String(k))).finally(()=>m(!1))},[a]);const u=k=>o(N=>[...N,k]),p=()=>o(k=>k.length>1?k.slice(0,-1):k),M=i.length>1,C=k=>{ae.files.reveal(k).catch(()=>{})},y=k=>{k.isDirectory||Fa.has(k.ext)?u(k.path):C(k.path)},v=a.split("/").pop()??a,x=c?.type==="directory",b=(k,N)=>{if(N)return"📁";const I=[".md",".markdown"],B=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return I.includes(k)?"📝":B.includes(k)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(k)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(k)?"💻":"📄"};return t.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",onClick:n,children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl w-[720px] max-w-[92vw] max-h-[85vh] flex flex-col shadow-2xl",onClick:k=>k.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[M&&t.jsx("button",{onClick:p,className:"text-fg-tertiary hover:text-fg-primary text-sm shrink-0 p-1 -ml-1 rounded hover:bg-surface-elevated/60 transition-colors",title:r("common:back"),children:t.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),x?t.jsx("svg",{className:"w-4 h-4 text-amber-500 shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l.872.87A.5.5 0 008.665 3.5H13.5A1.5 1.5 0 0115 5v8.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-10z"})}):t.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),t.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),t.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:v}),x&&c.entries&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",c.entries.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[t.jsx("button",{onClick:()=>s?s():C(a),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:r(s?"work:task.openInDeliverables":"work:task.openInFinder"),children:t.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),t.jsx("button",{onClick:n,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]})]}),t.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:a})}),t.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[f&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.filePreviewLoading")}),d&&t.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:d}),c?.type==="directory"&&c.entries&&t.jsxs("div",{className:"divide-y divide-border-default/50",children:[c.entries.length===0&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.emptyDirectory")}),c.entries.map(k=>t.jsxs("button",{onClick:()=>y(k),className:"w-full flex items-center gap-3 px-5 py-2.5 hover:bg-surface-elevated/40 transition-colors text-left group",children:[t.jsx("span",{className:"text-sm shrink-0",children:b(k.ext,k.isDirectory)}),t.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:k.name}),!k.isDirectory&&k.size!=null&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Gr(k.size)}),k.isDirectory&&t.jsx("svg",{className:"w-3.5 h-3.5 text-fg-tertiary shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})}),!k.isDirectory&&!Fa.has(k.ext)&&t.jsxs("svg",{className:"w-3 h-3 text-fg-tertiary shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})]},k.path))]}),c&&c.type!=="directory"&&t.jsx("div",{className:"p-5",children:c.type==="image"&&c.content?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:`data:${c.mimeType};base64,${c.content}`,alt:c.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):c.type==="audio"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("audio",{controls:!0,preload:"metadata",src:c.streamUrl||(c.path?ae.files.streamUrl(c.path):ae.files.streamUrl(a)),className:"w-full"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[c.name,c.size!=null?` · ${Gr(c.size)}`:""]})]}):c.type==="video"?t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("video",{controls:!0,preload:"metadata",src:c.streamUrl||(c.path?ae.files.streamUrl(c.path):ae.files.streamUrl(a)),className:"w-full max-h-[60vh] rounded-lg bg-black"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[c.name,c.size!=null?` · ${Gr(c.size)}`:""]})]}):c.type==="binary"||c.content==null?t.jsxs("div",{className:"space-y-3 text-center py-6",children:[t.jsx("p",{className:"text-sm text-fg-secondary",children:r("work:task.cannotPreviewFile",{defaultValue:"This file type cannot be previewed."})}),t.jsxs("p",{className:"text-xs text-fg-tertiary font-mono",children:[c.name,c.extension?` (${c.extension})`:"",c.size!=null?` · ${Gr(c.size)}`:""]}),t.jsx("button",{onClick:()=>C(a),className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",children:r("work:task.openInFinder")})]}):t.jsx(Ql,{content:c.content,format:c.type==="text"?"text":c.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function Ya({task:e,agents:n,projects:s,requirements:r,allTasks:i,users:o,onClose:a,onRefresh:c,authUser:l,scrollToComments:d,onScrollToCommentsDone:h,onReqClick:f,onProjectClick:m}){const{t:u}=We(["work","common"]),p=g.useMemo(()=>bl(u),[u]),[M,C]=g.useState([]),[y,v]=g.useState(""),[x,b]=g.useState(!1),[k,N]=g.useState(!1),[I,B]=g.useState(null),[D,L]=g.useState(null),[E,P]=g.useState(!1),[z,j]=g.useState(!1),[O,_]=g.useState(!1),[T,R]=g.useState("every"),[A,W]=g.useState(""),[Y,F]=g.useState(""),[Q,$]=g.useState(""),[S,V]=g.useState(!1),[q,H]=g.useState("details"),Z=g.useRef(null),[J,le]=g.useState("none"),te=g.useCallback(G=>{H(G),requestAnimationFrame(()=>{Z.current?.scrollTo({top:0,behavior:"instant"})})},[]),X=g.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),ie=_s(X,q,te);g.useEffect(()=>{const G=Z.current;if(!G)return;const pe=()=>{const{scrollTop:Me,scrollHeight:Se,clientHeight:lt}=G;if(!(Se>lt+50)){le("none");return}const Mt=Me<30,tn=Me+lt>=Se-30;le(Mt?"top":tn?"bottom":"middle")};pe(),G.addEventListener("scroll",pe,{passive:!0});const Ne=new ResizeObserver(pe);return Ne.observe(G),()=>{G.removeEventListener("scroll",pe),Ne.disconnect()}},[q]),g.useEffect(()=>{if(!d)return;H("details");const G=setTimeout(()=>{const pe=Z.current;pe&&pe.scrollTo({top:pe.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(G)},[d,h]);const[de,se]=g.useState(null),[me,ue]=g.useState(!1),[K,ce]=g.useState(null),[ge,ve]=g.useState(!1),[fe,re]=g.useState(e.description),xe=g.useRef(null),Ee=g.useRef(null),ye=g.useRef(80);g.useEffect(()=>{if(ge&&Ee.current){const G=Ee.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,ye.current)+"px",G.focus()}},[ge]);const[Ie,pt]=g.useState(!1),[rt,Nt]=g.useState(""),[Ct,st]=g.useState(1),[Ht,xt]=g.useState([]),Jt=g.useCallback(async()=>{try{const{results:G}=await ae.deliverables.search({taskId:e.id,limit:200});xt(G.filter(pe=>pe.status!=="outdated"))}catch{}},[e.id]);g.useEffect(()=>{Jt()},[Jt]);const[bt,yt]=g.useState(!1),Ce=vr(),Xe=20,$e=g.useCallback(async()=>{try{const G=await ae.tasks.listSubtasks(e.id);C(G.subtasks)}catch{}},[e.id]);g.useEffect(()=>{$e()},[$e]);const Le=async G=>{if(!S){V(!0);try{await G(),c(),await $e()}catch(pe){se(String(pe).replace("Error: ",""))}finally{V(!1)}}},et=G=>Le(()=>ae.tasks.update(e.id,{priority:G})),qt=G=>Le(()=>ae.tasks.assign(e.id,G||null)),Wt=G=>Le(()=>ae.tasks.update(e.id,{projectId:G||null})),_e=async()=>{if(!S){V(!0);try{await ae.tasks.pause(e.id),c()}finally{V(!1)}}},Ye=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.resume(e.id),c()}catch(G){se(String(G).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{V(!1)}}},tt=async()=>{y.trim()&&(await ae.tasks.createSubtask(e.id,y.trim()),v(""),b(!1),$e(),c())},un=async G=>{G.status==="completed"||G.status==="cancelled"?await ae.tasks.cancelSubtask(e.id,G.id):await ae.tasks.completeSubtask(e.id,G.id),$e(),c()},Mn=async G=>{await ae.tasks.deleteSubtask(e.id,G.id),B(null),$e(),c()},Ge=async()=>{if(!S){V(!0);try{await ae.tasks.updateStatus(e.id,"in_progress"),c()}finally{V(!1)}}},Ae=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.retry(e.id),c()}catch(G){se(String(G).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{V(!1)}}},ze=async()=>{if(!S){V(!0),se(null),te("logs");try{await ae.tasks.runNow(e.id),c()}catch(G){se(String(G).replace("Error: API error: 400","Server error").replace("Error: ","")),c()}finally{V(!1)}}},De=g.useRef(c);De.current=c,g.useEffect(()=>jt.on("task:update",pe=>{pe.payload.taskId===e.id&&($e(),De.current())}),[e.id,$e]);const He=M.filter(G=>G.status==="completed").length,dt=M.filter(G=>G.status==="cancelled").length,Qe=He+dt,it=e.status==="in_progress",ut=e.status==="blocked",en=ut&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(G=>{const pe=i.find(Ne=>Ne.id===G);return pe&&pe.status==="completed"})),Vt=e.status==="completed",St=e.status==="failed",Et=e.status==="rejected",Je=e.status==="cancelled",ft=e.status==="archived",fn=Vt||St||Et||Je||ft,ot=e.taskType==="scheduled"&&!!e.scheduleConfig,$t=ot&&!!e.scheduleConfig?.paused,vt=(()=>{const G=s.find(pe=>pe.id===e.projectId);return G&&G.name!=="default"?G:void 0})(),ht=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:[Ce&&t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("h3",{className:"flex-1 min-w-0 text-base font-semibold leading-snug text-fg-primary",children:[e.title," ",(()=>{const G=p[e.status];return G?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${G.cls}`,children:G.label}):t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium bg-gray-500/15 text-fg-tertiary whitespace-nowrap align-middle",children:e.status.replace(/_/g," ")})})(),en&&t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle bg-red-500/15 text-red-500",children:u("work:task.abnormalBlock")})]})]}),t.jsx("button",{onClick:a,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),t.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[t.jsx("button",{onClick:()=>te("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${q==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:u("work:task.detailsTab")}),t.jsxs("button",{onClick:()=>te("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${q==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("work:task.executionLogTab"),it&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsx("button",{onClick:()=>te("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${q==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const G=Ht.filter(pe=>typeof pe.reference=="string"&&pe.reference.length>0).length;return G>0?u("work:task.deliverablesCount",{count:G}):u("work:task.deliverables")})()}),t.jsx("button",{onClick:()=>te("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${q==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:u("work:task.historyTab")})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:Z,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:ie.onTouchStart,onTouchEnd:ie.onTouchEnd,children:[t.jsxs("div",{className:q==="logs"?"min-w-0 min-h-full":"hidden",children:[de&&t.jsxs("div",{className:"mx-4 mt-3 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:[t.jsx("span",{className:"font-medium",children:u("work:task.failedToStart")})," ",de]}),t.jsx(Hh,{task:e,isRunning:e.status==="in_progress",authUser:l,agents:n})]}),t.jsxs("div",{className:q==="details"?"":"hidden",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:ge?t.jsx("textarea",{ref:Ee,value:fe,onChange:G=>{re(G.target.value);const pe=G.target;pe.style.height="auto",pe.style.height=pe.scrollHeight+"px"},onBlur:()=>{fe!==e.description&&Le(()=>ae.tasks.update(e.id,{description:fe})),ve(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),re(e.description),ve(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:u("work:task.addDescription")}):t.jsx("div",{ref:xe,className:"group relative cursor-pointer rounded-lg -mx-2 px-2 -my-1 py-1 hover:bg-surface-elevated/50 transition-colors",onClick:G=>{G.target.closest("a, button, [data-entity-link]")||(ye.current=Math.max(xe.current?.offsetHeight??80,60),re(e.description),ve(!0))},role:"button",tabIndex:0,onKeyDown:G=>G.key==="Enter"&&(re(e.description),ve(!0)),children:e.description?t.jsxs("div",{children:[t.jsx("div",{className:Ce&&!bt?"line-clamp-3":"",children:t.jsx(fr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),Ce&&e.description.length>150&&t.jsx("button",{onClick:G=>{G.stopPropagation(),yt(!bt)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:u(bt?"work:task.collapse":"common:showMore")})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:u("work:task.noDescription")})})}),(vt||ht)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[vt&&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(vt.id):void 0,role:m?"button":void 0,tabIndex:m?0:void 0,onKeyDown:m?G=>G.key==="Enter"&&m(vt.id):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.projectLabel")}),vt.name]}),ht&&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(ht):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?G=>G.key==="Enter"&&f(ht):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.requirementLabel")}),ht.title.length>40?ht.title.slice(0,40)+"…":ht.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 pe=i.find(Me=>Me.id===G),Ne=pe&&(pe.status==="completed"||pe.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Ne?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:Ne?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${Ne?"line-through opacity-60":""}`,children:pe?pe.title.slice(0,30):G.slice(-8)}),!fn&&t.jsx("button",{onClick:async()=>{const Me=(e.blockedBy??[]).filter(Se=>Se!==G);await ae.tasks.update(e.id,{blockedBy:Me}),c()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:u("work:task.removeDependency"),children:"×"})]},G)})}):t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:u("work:task.noDependencies")}),en&&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")})]}),!fn&&t.jsx(Th,{options:i.filter(G=>G.id!==e.id&&!(e.blockedBy??[]).includes(G.id)).map(G=>({value:G.id,label:G.title,status:G.status})),placeholder:u("work:task.addDependency"),noMatchesText:u("work:task.noMatches"),itemSuffix:G=>G.status==="completed"||G.status==="archived"?t.jsx("span",{className:"text-[9px] text-green-600 shrink-0",children:"✓"}):G.status==="cancelled"?t.jsx("span",{className:"text-[9px] text-fg-tertiary shrink-0",children:"✕"}):null,onSelect:async G=>{if(!G)return;const pe=[...e.blockedBy??[],G];await ae.tasks.update(e.id,{blockedBy:pe}),c()}})]}),t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.projectLabel")}),t.jsxs("select",{value:e.projectId??"",onChange:G=>{Wt(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.noProject")}),s.map(G=>t.jsx("option",{value:G.id,children:G.name},G.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.requirementLabel")}),t.jsxs("select",{value:e.requirementId??"",onChange:G=>Le(()=>ae.tasks.update(e.id,{requirementId:G.target.value||null})),disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.noRequirement")}),r.filter(G=>!e.projectId||G.projectId===e.projectId).map(G=>t.jsx("option",{value:G.id,children:G.title},G.id))]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.assignee")}),t.jsxs("select",{value:e.assignedAgentId??"",onChange:G=>{qt(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"",children:u("work:task.unassigned")}),n.map(G=>t.jsxs("option",{value:G.id,children:[G.name," (",G.status,")"]},G.id))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.reviewer")}),t.jsxs("select",{value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:G=>{const pe=G.target.value;if(!pe)return;const Ne=pe.startsWith("human:"),Me=pe.replace(/^(human|agent):/,"");(Me!==e.reviewerId||(Ne?"human":"agent")!==(e.reviewerType??"agent"))&&Le(()=>ae.tasks.update(e.id,{reviewerId:Me,reviewerType:Ne?"human":"agent"}))},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[o.map(G=>t.jsx("option",{value:`human:${G.id}`,children:G.name},`human:${G.id}`)),n.map(G=>t.jsx("option",{value:`agent:${G.id}`,children:G.name},`agent:${G.id}`))]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.priority")}),t.jsxs("select",{value:e.priority,onChange:G=>{et(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"low",children:u("work:priority.low")}),t.jsx("option",{value:"medium",children:u("work:priority.medium")}),t.jsx("option",{value:"high",children:u("work:priority.high")}),t.jsx("option",{value:"urgent",children:u("work:priority.urgent")})]})]})]})]}),t.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&t.jsx("span",{children:u("work:task.createdBy",{name:Qn(e.createdBy,n,o)??e.createdBy})}),e.updatedBy&&t.jsx("span",{children:u("work:task.updatedBy",{name:Qn(e.updatedBy,n,o)??e.updatedBy})}),e.createdAt&&t.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&t.jsx("span",{children:u("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&t.jsx("span",{children:u("work:task.updatedMeta",{date:new Date(e.updatedAt).toLocaleDateString()})}),e.projectId&&t.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&t.jsx("span",{className:"text-amber-600",children:u("work:task.executionRound",{n:e.executionRound})})]}),t.jsxs("div",{className:"px-6 py-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:[u("work:task.subtasks")," ",M.length>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[u("work:task.subtasksProgress",{done:He,total:M.length-dt}),dt>0?` · ${dt} cancelled`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[Qe>0&&t.jsx("button",{onClick:()=>N(G=>!G),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${k?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:k?u("work:task.hideCompleted"):u("work:task.showCompleted",{count:Qe})}),t.jsx("button",{onClick:()=>b(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:u("work:task.addSubtask")})]})]}),(()=>{const G=k?M:M.filter(pe=>pe.status!=="completed"&&pe.status!=="cancelled");return G.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:G.map(pe=>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 ${pe.status==="cancelled"?"opacity-50":""}`,children:[t.jsxs("button",{onClick:()=>{un(pe)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${pe.status==="completed"?"bg-green-600 border-green-600 text-white":pe.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[pe.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"})}),pe.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 ${pe.status==="completed"?"line-through text-fg-tertiary":pe.status==="cancelled"?"line-through text-fg-quaternary":"text-fg-secondary"}`,children:pe.title}),t.jsx("button",{onClick:()=>B(pe),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},pe.id))}):null})(),M.length===0&&!x&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:u("work:task.noSubtasksYet")}),x&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:y,onChange:G=>v(G.target.value),onKeyDown:G=>{G.key==="Enter"&&tt(),G.key==="Escape"&&(b(!1),v(""))},placeholder:u("work:task.subtaskTitlePlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{onClick:()=>{tt()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:u("work:task.add")}),t.jsx("button",{onClick:()=>{b(!1),v("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:u("common:cancel")})]}),(()=>{const G=Ht.filter(Me=>typeof Me.reference=="string"&&Me.reference.length>0);if(G.length===0)return null;const pe={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"},Ne=G.slice(0,3);return t.jsxs("div",{className:"mt-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:u("work:task.deliverablesCount",{count:G.length})}),G.length>3&&t.jsx("button",{onClick:()=>te("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:u("work:task.viewAll")})]}),t.jsx("div",{className:"space-y-1.5",children:Ne.map(Me=>{const Se=/^https?:\/\//i.test(Me.reference),lt=Se?Me.summary||Me.reference:Me.reference.split("/").pop()??Me.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${pe[Me.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Me.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Se?t.jsxs("a",{href:Me.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Me.reference,children:[lt," ",t.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),t.jsx("path",{d:"M7 2h3v3"}),t.jsx("path",{d:"M5 7 10 2"})]})]}):t.jsx("button",{onClick:()=>ce(Me.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Me.reference,children:lt}),Me.summary&&!Se&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Me.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Me.reference})]})]},Me.id)})})]})})(),t.jsx(zh,{task:e,agents:n,users:o,authUser:l})]})]}),t.jsx("div",{className:q==="history"?"":"hidden",children:t.jsx(kl,{entityType:"task",entityId:e.id})}),t.jsx("div",{className:q==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const G=Ht.filter(Se=>typeof Se.reference=="string"&&Se.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 pe={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"},Ne=Math.ceil(G.length/Xe),Me=G.slice((Ct-1)*Xe,Ct*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})}),Ne>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:Ct<=1,onClick:()=>st(Se=>Se-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[Ct,"/",Ne]}),t.jsx("button",{disabled:Ct>=Ne,onClick:()=>st(Se=>Se+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),t.jsx("div",{className:"space-y-1.5",children:Me.map(Se=>{const lt=/^https?:\/\//i.test(Se.reference),Ft=lt?Se.summary||Se.reference:Se.reference.split("/").pop()??Se.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 ${pe[Se.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Se.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[lt?t.jsxs("a",{href:Se.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:Se.reference,children:[Ft," ",t.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),t.jsx("path",{d:"M7 2h3v3"}),t.jsx("path",{d:"M5 7 10 2"})]})]}):t.jsx("button",{onClick:()=>ce(Se.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Se.reference,children:Ft}),Se.summary&&!lt&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Se.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Se.reference})]})]},Se.id)})})]})})()})]}),J!=="none"&&J!=="top"&&t.jsx("button",{onClick:()=>Z.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-36 right-4 md:bottom-28 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:u("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),J!=="none"&&J!=="bottom"&&t.jsx("button",{onClick:()=>{const G=Z.current;G&&G.scrollTo({top:G.scrollHeight,behavior:"smooth"})},className:"absolute bottom-22 right-4 md:bottom-18 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:u("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),ot&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${$t?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!it&&!O&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{it||O||e.scheduleConfig?.runAt||(R(e.scheduleConfig?.cron?"cron":"every"),W(e.scheduleConfig?.every??"4h"),F(e.scheduleConfig?.cron??""),$(e.scheduleConfig?.maxRuns&&e.scheduleConfig.maxRuns>0?String(e.scheduleConfig.maxRuns):""),_(!0))},children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:$t?"text-amber-600":"text-brand-500",children:$t?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")}),!$t&&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 pe=Math.floor(G/6e4);if(pe<60)return u("work:task.scheduleInMinutes",{count:pe});const Ne=Math.floor(pe/60);return Ne<24?u("work:task.scheduleInHoursMinutes",{h:Ne,m:pe%60}):u("work:task.scheduleInDaysHours",{d:Math.floor(Ne/24),h:Ne%24})})()})})]}),!it&&!O&&!e.scheduleConfig.runAt&&t.jsxs("svg",{className:"w-3 h-3 text-brand-500 ml-auto shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})]}),O?t.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:G=>G.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("select",{value:T,onChange:G=>R(G.target.value),className:"px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[t.jsx("option",{value:"every",children:u("work:task.scheduleEveryMode")}),t.jsx("option",{value:"cron",children:u("work:task.scheduleCronMode")})]}),T==="every"?t.jsxs("select",{value:A,onChange:G=>W(G.target.value),className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[t.jsx("option",{value:"30m",children:u("work:task.freq30m")}),t.jsx("option",{value:"1h",children:u("work:task.freq1h")}),t.jsx("option",{value:"2h",children:u("work:task.freq2h")}),t.jsx("option",{value:"4h",children:u("work:task.freq4h")}),t.jsx("option",{value:"8h",children:u("work:task.freq8h")}),t.jsx("option",{value:"12h",children:u("work:task.freq12h")}),t.jsx("option",{value:"1d",children:u("work:task.freq1d")}),t.jsx("option",{value:"1w",children:u("work:task.freq1w")})]}):t.jsx("input",{value:Y,onChange:G=>F(G.target.value),placeholder:"0 9 * * 1-5",className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("label",{className:"text-fg-tertiary shrink-0",children:u("work:task.scheduleMaxRuns")}),t.jsx("input",{value:Q,onChange:G=>$(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=A:G.cron=Y.trim(),Q&&(G.maxRuns=parseInt(Q,10)),await Le(()=>ae.tasks.updateSchedule(e.id,G)),_(!1)},disabled:S,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:u("common:save")}),t.jsx("button",{onClick:()=>_(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:u("common:cancel")})]})]}):t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[t.jsx("span",{children:u("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?u("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:u("work:task.scheduleLast",{when:(()=>{const G=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),pe=Math.floor(G/6e4);if(pe<1)return u("work:task.noteTimeJustNow");if(pe<60)return u("work:task.noteTimeMinutes",{count:pe});const Ne=Math.floor(pe/60);return Ne<24?u("work:task.noteTimeHours",{count:Ne}):u("work:task.noteTimeDays",{count:Math.floor(Ne/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(ot){ue(!0);return}Le(()=>ae.tasks.approve(e.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:e.createdBy&&!e.createdBy.startsWith("agt_")?u("work:task.startExecution"):u("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?t.jsx("button",{onClick:async()=>{const{count:G}=await ae.tasks.getDependentCount(e.id);L({dependentCount:G})},disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")}):t.jsx("button",{onClick:()=>P(!0),disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.reject")})]}),e.status==="review"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{Le(()=>ae.tasks.accept(e.id,l?.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.approveCheck")}),Ie?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:rt,onChange:G=>Nt(G.target.value),onKeyDown:G=>{G.key==="Enter"&&rt.trim()&&(Le(()=>ae.tasks.revision(e.id,rt.trim(),l?.id)),pt(!1),Nt(""))},placeholder:u("work:task.revisionReasonPlaceholder"),autoFocus:!0,className:"px-2 py-1 text-xs bg-surface-elevated border border-amber-500/40 rounded-lg text-fg-primary focus:border-amber-400 outline-none w-48"}),t.jsx("button",{onClick:()=>{Le(()=>ae.tasks.revision(e.id,rt.trim()||u("work:task.revisionsNeededDefault"),l?.id)),pt(!1),Nt("")},disabled:S,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:u("common:send")}),t.jsx("button",{onClick:()=>{pt(!1),Nt("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>pt(!0),disabled:S,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.requestRevision")})]}),it&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{_e()},disabled:S,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[t.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),t.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),u("work:task.pause")]}),t.jsxs("button",{onClick:()=>{Ae()},disabled:S,className:"px-3 py-1.5 text-xs border border-blue-500/30 text-blue-600 rounded-lg hover:bg-blue-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),u("work:task.retry")]})]}),ut&&t.jsx("button",{onClick:()=>{Ye()},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:S?t.jsx(t.Fragment,{children:u("work:task.resuming")}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.resume")]})}),St&&!ot&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{Ae()},disabled:S,className:"px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),u("work:task.retry")]}),t.jsxs("button",{onClick:()=>{Ge()},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.continueTask")]})]}),ot&&(Vt||St||Je)&&!ft&&t.jsx("button",{onClick:()=>{ze()},disabled:S,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1.5",children:S?t.jsx(t.Fragment,{children:u("work:task.running")}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.runNow")]})}),ot&&!it&&!ft&&!Et&&($t?t.jsx("button",{onClick:()=>{Le(()=>ae.tasks.resumeSchedule(e.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.resumeSchedule")}):t.jsx("button",{onClick:()=>{Le(()=>ae.tasks.pauseSchedule(e.id))},disabled:S,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50",children:u("work:task.pauseSchedule")})),(Vt||St||Et||Je)&&t.jsx("button",{onClick:()=>j(!0),disabled:S,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.archive")}),Vt&&!ot&&t.jsx("button",{onClick:()=>{Ge()},disabled:S,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary disabled:opacity-50",children:u("work:task.reopen")}),!fn&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:G}=await ae.tasks.getDependentCount(e.id);L({dependentCount:G})},disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")})]})}),I&&t.jsx(Hn,{title:u("work:task.deleteSubtaskTitle",{title:I.title}),message:u("work:task.deleteSubtaskMessage"),confirmLabel:u("common:delete"),onConfirm:()=>{Mn(I)},onCancel:()=>B(null)}),E&&t.jsx(Hn,{title:u("work:task.rejectConfirmTitle"),message:u("work:task.rejectConfirmMessage"),confirmLabel:u("work:task.reject"),onConfirm:()=>{P(!1),Le(()=>ae.tasks.reject(e.id))},onCancel:()=>P(!1)}),z&&t.jsx(Hn,{title:u("work:task.archiveConfirmTitle"),message:u(ot?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:u("work:task.archive"),onConfirm:()=>{j(!1),Le(()=>ae.tasks.archive(e.id))},onCancel:()=>j(!1)}),D&&D.dependentCount>0?t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>L(null),children:t.jsxs("div",{className:"bg-surface-default border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:G=>G.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:u("work:task.cancelTaskModalTitle")}),t.jsxs("p",{className:"text-sm text-fg-secondary mb-4",children:[ot&&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:D.dependentCount})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("button",{onClick:()=>{L(null),Le(()=>ae.tasks.cancel(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-surface-elevated border border-border-default rounded-lg hover:bg-surface-overlay text-fg-primary text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelTaskOnly")}),t.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:u("work:task.cancelTaskOnlyHint")})]}),t.jsxs("button",{onClick:()=>{L(null),Le(()=>ae.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[t.jsx("span",{className:"font-medium",children:u("work:task.cancelWithDependents")}),t.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:u("work:task.cancelWithDependentsHint",{count:D.dependentCount})})]}),t.jsx("button",{onClick:()=>L(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("work:task.keepTaskRunning")})]})]})}):D&&t.jsx(Hn,{title:u("work:task.cancelTaskModalTitle"),message:u(ot?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:u("work:task.cancelTask"),onConfirm:()=>{L(null),Le(()=>ae.tasks.cancel(e.id))},onCancel:()=>L(null)}),K&&t.jsx(qh,{filePath:K,onClose:()=>ce(null),onOpenExternal:()=>{ce(null),ae.deliverables.search({taskId:e.id,limit:100}).then(({results:G})=>{const pe=G.find(Ne=>Ne.reference===K);pe?Bt.navigate(Fe.DELIVERABLES,{openDeliverable:pe.id}):Bt.navigate(Fe.DELIVERABLES)}).catch(()=>Bt.navigate(Fe.DELIVERABLES))}}),me&&e.scheduleConfig&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>ue(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:G=>G.stopPropagation(),children:[t.jsx("h3",{className:"font-semibold text-base mb-2",children:u("work:task.scheduleApproveTitle")}),t.jsx("p",{className:"text-sm text-fg-secondary mb-5 leading-relaxed",children:u("work:task.scheduleApproveDesc",{schedule:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.every?u("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):"",nextRun:e.scheduleConfig.nextRunAt?new Date(e.scheduleConfig.nextRunAt).toLocaleString():u("work:task.scheduleNA")})}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("button",{disabled:S,onClick:()=>{ue(!1),Le(()=>ae.tasks.approve(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-green-600 hover:bg-green-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveRunNow")}),t.jsx("button",{disabled:S,onClick:()=>{ue(!1),Le(()=>ae.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveWait")}),t.jsx("button",{onClick:()=>ue(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("common:cancel")})]})]})})]})}function Wh({project:e,tasks:n,requirements:s,agents:r,onDeleteProject:i,onUpdateProject:o,onRefresh:a}){const c=g.useMemo(()=>n.filter(E=>E.projectId===e.id),[n,e.id]),l=g.useMemo(()=>s.filter(E=>E.projectId===e.id),[s,e.id]),d=g.useMemo(()=>{const E={total:c.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:l.length,reqsDone:0};for(const P of c)P.status==="completed"||P.status==="accepted"?E.completed++:P.status==="in_progress"?E.inProgress++:P.status==="review"||P.status==="revision"?E.inReview++:P.status==="blocked"?E.blocked++:P.status==="failed"?E.failed++:E.pending++;for(const P of l)P.status==="completed"&&E.reqsDone++;return E},[c,l]),h=g.useMemo(()=>new Set(c.map(E=>E.assignedAgentId).filter(Boolean)),[c]),f=g.useMemo(()=>r.filter(E=>h.has(E.id)),[r,h]),[m,u]=g.useState(!1),[p,M]=g.useState(""),[C,y]=g.useState("main"),[v,x]=g.useState(!1),[b,k]=g.useState(!1),{t:N}=We(["work","common"]),I=[{value:"active",label:N("work:project.statusActive"),desc:N("work:project.statusActiveDesc")},{value:"paused",label:N("work:project.statusPaused"),desc:N("work:project.statusPausedDesc")},{value:"archived",label:N("work:project.statusArchived"),desc:N("work:project.statusArchivedDesc")}],B=async E=>{if(E!==e.status){x(!0);try{await o({status:E}),a()}finally{x(!1)}}},D=async()=>{const E=p.trim();if(!E)return;const P=[...e.repositories??[],{url:"",localPath:E,defaultBranch:C||"main"}];await o({repositories:P}),M(""),y("main"),u(!1),a()},L=async E=>{const P=(e.repositories??[]).filter((z,j)=>j!==E);await o({repositories:P}),a()};return t.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx(_h,{value:e.description??"",onSave:async E=>{await o({description:E}),a()},className:"text-sm text-fg-secondary",placeholder:N("work:project.descriptionPlaceholderLong")}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&t.jsxs("span",{children:[N("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:[N("work:project.updatedLabel")," ",new Date(e.updatedAt).toLocaleDateString()]})]})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:N("work:project.projectStatusHeading")}),t.jsx("div",{className:"flex gap-2",children:I.map(E=>t.jsxs("button",{disabled:v,onClick:()=>B(E.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===E.value?E.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":E.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${v?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:E.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:E.desc})]},E.value))})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:N("work:project.taskOverview")}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(Ut,{label:N("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),t.jsx(Ut,{label:N("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),t.jsx(Ut,{label:N("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),t.jsx(Ut,{label:N("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),t.jsx(Ut,{label:N("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),t.jsx(Ut,{label:N("work:project.statFailed"),value:d.failed,color:"text-red-500"})]}),d.total>0&&t.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[d.completed>0&&t.jsx("div",{className:"bg-green-500",style:{width:`${d.completed/d.total*100}%`}}),d.inProgress>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${d.inProgress/d.total*100}%`}}),d.inReview>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${d.inReview/d.total*100}%`}}),d.blocked>0&&t.jsx("div",{className:"bg-amber-500",style:{width:`${d.blocked/d.total*100}%`}}),d.pending>0&&t.jsx("div",{className:"bg-blue-500/40",style:{width:`${d.pending/d.total*100}%`}}),d.failed>0&&t.jsx("div",{className:"bg-red-500",style:{width:`${d.failed/d.total*100}%`}})]})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:N("work:project.requirementsHeading")}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(Ut,{label:N("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),t.jsx(Ut,{label:N("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),t.jsx(Ut,{label:N("work:project.statActive"),value:d.reqs-d.reqsDone,color:"text-brand-500"})]})]}),f.length>0&&t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:N("work:project.agentsHeading",{count:f.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(E=>{const P=c.filter(j=>j.assignedAgentId===E.id),z=P.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 ${E.status==="working"?"bg-blue-500":E.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:E.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:N("work:project.agentTaskCounts",{active:z.length,total:P.length})})]},E.id)})})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:N("work:project.repositories")}),t.jsx("button",{onClick:()=>u(!m),className:"text-[10px] text-brand-500 hover:text-brand-500",children:N(m?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!m&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:N("work:project.noReposLinked")}),(e.repositories??[]).map((E,P)=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:[t.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),t.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate",children:E.url||E.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:E.defaultBranch}),t.jsx("button",{onClick:()=>L(P),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:N("work:project.removeRepo"),children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},P)),m&&t.jsxs("div",{className:"mt-2 space-y-2 p-3 bg-surface-elevated rounded-lg border border-border-default",children:[t.jsx("input",{value:p,onChange:E=>M(E.target.value),placeholder:N("work:project.repoPathPlaceholder"),className:"w-full px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:C,onChange:E=>y(E.target.value),placeholder:N("work:project.repoBranchPlaceholder"),className:"flex-1 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsx("button",{onClick:D,disabled:!p.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:N("work:task.add")})]})]})]}),t.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:N("work:project.dangerZone")}),t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:N("work:project.dangerZoneDeleteHint")}),t.jsx("button",{onClick:()=>k(!0),className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 hover:bg-red-500/10 rounded-lg transition-colors",children:N("work:project.deleteProject")})]}),b&&t.jsx(Hn,{title:N("work:project.deleteProjectConfirmTitle"),message:N("work:project.deleteProjectConfirmBody",{name:e.name,tasks:d.total,reqs:d.reqs}),confirmLabel:N("work:project.deleteProject"),onConfirm:()=>{k(!1),i()},onCancel:()=>k(!1)})]})}function Ut({label:e,value:n,color:s}){return t.jsxs("div",{className:"text-center py-2",children:[t.jsx("div",{className:`text-xl font-bold ${s}`,children:n}),t.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const Jr={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},vl={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Vh={urgent:0,high:1,medium:2,low:3},os={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Ga={failed:"border-l-red-500 bg-red-500/5",todo:"border-l-blue-500 bg-blue-500/5",in_progress:"border-l-brand-500 bg-brand-500/5",review:"border-l-purple-500 bg-brand-500/5",done:"border-l-green-500 bg-green-500/5",closed:"border-l-gray-500 bg-gray-500/5"},Fh={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"},Yh=["pending","in_progress","completed","rejected","cancelled","archived"];function wl(e){for(const n of ss)if(n.statuses.includes(e))return n.id;return"closed"}function Ka(e,n){const s=Date.now()-new Date(e).getTime(),r=Math.floor(s/6e4);if(r<1)return n("work:relative.justNow");if(r<60)return n("work:relative.minutesAgo",{count:r});const i=Math.floor(r/60);if(i<24)return n("work:relative.hoursAgo",{count:i});const o=Math.floor(i/24);return n("work:relative.daysAgo",{count:o})}function Kr({value:e,options:n,onSelect:s,allowedValues:r}){const[i,o]=g.useState(!1),a=g.useRef(null),c=g.useRef(null),l=n.find(d=>d.value===e);return g.useEffect(()=>{if(!i)return;const d=h=>{c.current&&!c.current.contains(h.target)&&a.current&&!a.current.contains(h.target)&&o(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[i]),t.jsxs("div",{className:"relative",children:[t.jsx("button",{ref:a,onClick:()=>o(d=>!d),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${l?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:l?.label??e}),i&&t.jsx("div",{ref:c,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:n.map(d=>{const h=d.value===e,f=h||!r||r.has(d.value);return t.jsxs("button",{disabled:!f,onClick:()=>{!h&&f&&s(d.value),o(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${h?"bg-surface-elevated":f?"hover:bg-surface-elevated/60":"opacity-35 cursor-not-allowed"}`,children:[t.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 ${f?d.cls.split(" ")[0]:"bg-gray-600"}`}),t.jsx("span",{className:`font-medium ${h?"text-fg-primary":f?"text-fg-secondary":"text-fg-muted"}`,children:d.label}),h&&t.jsx("svg",{className:"w-3 h-3 ml-auto text-brand-500",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},d.value)})})]})}function Za({row:e,idx:n,dragIdx:s,agentMap:r,projMap:i,onTaskClick:o,onReqClick:a,onRowDragStart:c,onRowDragEnd:l,handleStatusChange:d,handlePriorityChange:h,selected:f,isMobile:m,isAbnormalBlocked:u}){const{t:p}=We(["work","common"]),M=g.useMemo(()=>bl(p),[p]),C=g.useMemo(()=>io(p),[p]),y=g.useMemo(()=>Oh(p),[p]),v=e.data.status,x=e.data.priority,b=e.kind==="task"?r.get(e.data.assignedAgentId??""):void 0,k=(()=>{const I=i.get((e.kind==="task",e.data.projectId??""));return I&&I.name!=="default"?I:void 0})(),N=e.kind==="req"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:p("work:task.requirementShort")}):e.data.taskType==="scheduled"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600",children:p("work:task.schedShort")}):t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:p("work:task.taskShort")});return m?t.jsxs("div",{"data-work-item-id":e.data.id,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`px-3 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${Ga[e.group]??"border-l-gray-700"} ${f?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35":"active:bg-surface-elevated/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[N,u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500",children:"⚠"}),t.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsx("div",{onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:v,options:e.kind==="task"?Ha.map(I=>({value:I,label:M[I]?.label??I,cls:M[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):qa.map(I=>({value:I,label:C[I]?.label??I,cls:C[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Wa[v]:qs[v],onSelect:I=>{d(e,I)}})}),t.jsx("div",{onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:x,options:za.map(I=>({value:I,label:y[I]?.label??I,cls:y[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:I=>{h(e,I)}})}),b&&t.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`${Va[b.status]??"text-fg-secondary"}`,children:b.name})]}),k?.name&&t.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:k.name}),t.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:Ka(e.data.updatedAt??"",p)})]})]}):t.jsxs("div",{"data-work-item-id":e.data.id,draggable:!0,onDragStart:I=>c(I,n),onDragEnd:l,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${Ga[e.group]??"border-l-gray-700"} ${s===n?"opacity-40":""} ${f?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35 hover:bg-brand-500/30":"hover:bg-surface-elevated/50"}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:N}),t.jsxs("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate",children:e.data.title}),u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500 shrink-0",children:"⚠"})]}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:v,options:e.kind==="task"?Ha.map(I=>({value:I,label:M[I]?.label??I,cls:M[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):qa.map(I=>({value:I,label:C[I]?.label??I,cls:C[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Wa[v]:qs[v],onSelect:I=>{d(e,I)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:I=>I.stopPropagation(),children:t.jsx(Kr,{value:x,options:za.map(I=>({value:I,label:y[I]?.label??I,cls:y[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:I=>{h(e,I)}})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:b?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`font-medium ${Va[b.status]??"text-fg-secondary"}`,children:b.name})]}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:k?.name?t.jsx("span",{className:"text-brand-400/70",children:k.name}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-muted text-right",children:Ka(e.data.updatedAt??"",p)})]})}function Gh({tasks:e,requirements:n,agents:s,projects:r,onTaskClick:i,onReqClick:o,onRefresh:a,selectedTaskId:c,selectedReqId:l}){const{t:d}=We(["work","common"]),h=vr(),[f,m]=g.useState("status"),[u,p]=g.useState(null),[M,C]=g.useState(null),y=g.useMemo(()=>{const T=new Map;for(const R of e)T.set(R.id,R);return T},[e]),v=g.useCallback(T=>T.status!=="blocked"?!1:!T.blockedBy||T.blockedBy.length===0?!0:T.blockedBy.every(R=>{const A=y.get(R);return A&&A.status==="completed"}),[y]),x=g.useMemo(()=>{const T=[];for(const R of e){const A=wl(R.status);T.push({kind:"task",data:R,group:A,groupOrder:os[A]??5})}for(const R of n){const A=Jr[R.status]??"todo";T.push({kind:"req",data:R,group:A,groupOrder:os[A]??5})}if(f==="status")T.sort((R,A)=>{if(R.groupOrder!==A.groupOrder)return R.groupOrder-A.groupOrder;const W=new Date(R.data.updatedAt??0).getTime();return new Date(A.data.updatedAt??0).getTime()-W});else{const R=A=>Vh[A.data.priority]??2;T.sort((A,W)=>{const Y=R(A),F=R(W);return Y!==F?Y-F:new Date(W.data.updatedAt??0).getTime()-new Date(A.data.updatedAt??0).getTime()})}return T},[e,n,f]),b=async(T,R)=>{try{T.kind==="task"?await ae.tasks.updateStatus(T.data.id,R):await ae.requirements.updateStatus(T.data.id,R),a()}catch{}},k=async(T,R)=>{try{T.kind==="task"?await ae.tasks.update(T.data.id,{priority:R}):await ae.requirements.update(T.data.id,{priority:R}),a()}catch{}},N=(T,R)=>{p(R),T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",String(R)),T.currentTarget.style.opacity="0.4"},I=T=>{T.currentTarget.style.opacity="1",p(null),C(null)},B=(T,R)=>{T.preventDefault(),T.dataTransfer.dropEffect="move",M!==R&&C(R)},D=async(T,R)=>{if(T.preventDefault(),C(null),u==null)return;const A=x[u];if(!A||A.group===R)return;const W=ss.find(Y=>Y.id===R);if(W){try{if(A.kind==="task"){if(A.data.status==="pending")return;await ae.tasks.updateStatus(A.data.id,W.dropStatus)}else{const Y=vl[R];Y&&await ae.requirements.updateStatus(A.data.id,Y)}a()}catch{}p(null)}},L=g.useMemo(()=>new Map(s.map(T=>[T.id,T])),[s]),E=g.useMemo(()=>new Map(r.map(T=>[T.id,T])),[r]),P=["todo","in_progress","review","done"],z=g.useMemo(()=>{const T={};for(const R of x)T[R.group]=(T[R.group]??0)+1;return T},[x]),{rowsByGroup:j,rowIndexMap:O}=g.useMemo(()=>{const T=new Map,R=new Map;for(let A=0;A<x.length;A++){const W=x[A];R.set(W,A);const Y=T.get(W.group)??[];Y.push(W),T.set(W.group,Y)}return{rowsByGroup:T,rowIndexMap:R}},[x]),_=g.useMemo(()=>{if(f!=="status")return null;const T=new Set(x.map(W=>W.group)),R=[],A=new Set;T.has("failed")&&(R.push("failed"),A.add("failed"));for(const W of P)R.push(W),A.add(W);for(const W of x)A.has(W.group)||(R.push(W.group),A.add(W.group));return R},[x,f]);return t.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${h?"overflow-x-hidden w-full":""}`,children:t.jsxs("div",{className:h?"w-full":"w-fit min-w-full",children:[!h&&t.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider sticky top-0 z-20 bg-surface-primary",children:[t.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:x.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:d("work:task.backlogTitle")}),t.jsxs("button",{onClick:()=>m("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[d("work:filters.status")," ",f==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>m("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[d("work:filters.priority")," ",f==="priority"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsx("div",{className:"w-[120px] shrink-0",children:d("work:filters.assignee")}),t.jsx("div",{className:"w-[120px] shrink-0",children:d("work:task.projectLabel")}),t.jsx("div",{className:"w-[90px] shrink-0 text-right",children:d("work:task.backlogUpdated")})]}),t.jsxs("div",{children:[f==="status"&&_?_.map(T=>{const R=j.get(T)??[];return t.jsxs("div",{children:[t.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-primary/80 sticky top-0 z-10 ${Fh[T]??""} ${M===T?"ring-1 ring-brand-500/40":""}`,onDragOver:A=>B(A,T),onDragLeave:()=>C(null),onDrop:A=>{D(A,T)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:d(`work:boardColumn.${T}`)}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:z[T]??0})]}),R.map(A=>t.jsx(Za,{row:A,idx:O.get(A)??0,dragIdx:u,agentMap:L,projMap:E,onTaskClick:i,onReqClick:o,onRowDragStart:N,onRowDragEnd:I,handleStatusChange:b,handlePriorityChange:k,selected:A.kind==="task"?A.data.id===c:A.data.id===l,isMobile:h,isAbnormalBlocked:A.kind==="task"?v(A.data):!1},`${A.kind}-${A.data.id}`))]},T)}):x.map((T,R)=>t.jsx(Za,{row:T,idx:R,dragIdx:u,agentMap:L,projMap:E,onTaskClick:i,onReqClick:o,onRowDragStart:N,onRowDragEnd:I,handleStatusChange:b,handlePriorityChange:k,selected:T.kind==="task"?T.data.id===c:T.data.id===l,isMobile:h,isAbnormalBlocked:T.kind==="task"?v(T.data):!1},`${T.kind}-${T.data.id}`)),x.length===0&&t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3 max-w-sm mx-auto text-center",children:[t.jsx("svg",{className:"w-10 h-10 text-fg-quaternary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),t.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:d("work:task.backlogEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:d("work:task.backlogEmptyDesc")})]})]})]})})}function Ws(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function Kh(e,n){const s=new Map,r=new Map(e.map(c=>[c.id,c])),i=new Set;for(const c of e){let l=Ws(c.title).replace(/[^a-z0-9-]/g,"").slice(0,30)||"step";i.has(l)&&(l=`${l}-${c.id.slice(-4)}`),i.add(l),s.set(c.id,l)}const o=new Map,a=new Set;for(const c of e){const l=c.assignedAgentId;if(l&&!o.has(l)){const d=n[l]??"worker";let h=Ws(d).replace(/[^a-z0-9-]/g,"")||"worker";a.has(h)&&(h=`${h}-${l.slice(-4)}`),a.add(h),o.set(l,h)}}return e.map(c=>({id:s.get(c.id),name:c.title,role:o.get(c.assignedAgentId)??"worker",prompt:c.description||c.title,depends_on:(c.blockedBy??[]).filter(l=>r.has(l)).map(l=>s.get(l)).filter(Boolean)}))}function Zr(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function Zh(e,n,s){const r=[];r.push(`name: ${Zr(e)}`),r.push(`description: ${Zr(n.replace(/\n/g," ").slice(0,200))}`),r.push('version: "1.0.0"'),r.push(""),r.push("steps:");for(const i of s){if(r.push(` - id: ${i.id}`),r.push(` name: ${Zr(i.name)}`),r.push(" type: agent_task"),r.push(` role: ${Zr(i.role)}`),i.depends_on.length>0&&r.push(` depends_on: [${i.depends_on.join(", ")}]`),i.depends_on.length>0){r.push(" inputs:");for(const o of i.depends_on)r.push(` - from: ${o}`),r.push(` as: ${o}_output`)}r.push(" prompt: |");for(const o of i.prompt.split(`
8
8
  `))r.push(` ${o}`);r.push("")}return r.join(`
9
- `)}function Xh({req:e,tasks:n,agents:s,teamId:r,onClose:i,onSaved:o}){const{t:a}=We(["work"]),c=g.useMemo(()=>{const D={};for(const L of s)D[L.id]=L.name;return D},[s]),l=g.useMemo(()=>Kh(n,c),[n,c]),[d,h]=g.useState(()=>Ws(e.title)),[f,m]=g.useState(e.description||e.title),[u,p]=g.useState(l),[M,C]=g.useState(!1),[y,v]=g.useState(null),x=(D,L,E)=>{p(P=>P.map((z,j)=>j===D?{...z,[L]:E}:z))},b=D=>{const L=u[D]?.id;p(E=>E.filter((P,z)=>z!==D).map(P=>({...P,depends_on:P.depends_on.filter(z=>z!==L)})))},[k,N]=g.useState(!1),I=async()=>{if(d.trim()){C(!0),v(null);try{const D=Zh(d.trim(),f,u);await ae.workflows.create(r,d.trim(),D),N(!0),setTimeout(()=>o(),800)}catch(D){v(String(D))}C(!1)}},B=g.useMemo(()=>[...new Set(u.map(D=>D.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:D=>D.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:D=>h(D.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:B.map(D=>t.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:D},D))})]})]}),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:D=>m(D.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((D,L)=>t.jsx("div",{className:"bg-surface-secondary border border-border-default/40 rounded-xl p-3 group",children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500 mt-0.5",children:L+1}),t.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{value:D.name,onChange:E=>x(L,"name",E.target.value),className:"flex-1 text-sm font-medium bg-transparent border-b border-transparent hover:border-border-default focus:border-brand-500 text-fg-primary focus:outline-none px-0 py-0.5 transition-colors"}),t.jsx("input",{value:D.role,onChange:E=>x(L,"role",E.target.value),className:"w-28 text-[10px] bg-surface-elevated border border-border-default/40 rounded-md px-2 py-1 text-fg-secondary focus:outline-none focus:ring-1 focus:ring-brand-500",title:a("work:task.role","Role")})]}),D.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"),":"]}),D.depends_on.map(E=>{const P=u.find(z=>z.id===E);return t.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:P?.name??E},E)})]}),t.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:D.prompt})]}),t.jsx("button",{onClick:()=>b(L),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-quaternary hover:text-red-500 p-1 rounded transition-all",title:a("work:task.removeStep","Remove step"),children:t.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},D.id))})]}),y&&t.jsx("p",{className:"text-xs text-red-500",children:y}),k&&t.jsx("p",{className:"text-xs text-green-500 font-medium",children:a("work:task.workflowSavedSuccess","Workflow saved successfully")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default",children:[t.jsx("button",{onClick:i,className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated rounded-lg transition-colors",children:a("work:task.cancel","Cancel")}),t.jsx("button",{onClick:I,disabled:M||k||!d.trim()||u.length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm rounded-lg font-medium transition-colors",children:M?a("work:task.saving","Saving..."):k?a("work:task.workflowSavedSuccess","Saved!"):a("work:task.saveWorkflow","Save Workflow")})]})]})})}function Xa({teamId:e,agents:n,compact:s}){const{t:r}=We(["work"]),i=g.useMemo(()=>e?n.find(a=>a.teamId===e&&a.agentRole==="manager"):n.find(a=>a.agentRole==="manager"),[n,e]),o=()=>{i&&Bt.navigate(Fe.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 Uh({teamId:e,projectId:n,agents:s,projects:r,onViewRunTasks:i}){const{t:o}=We(["work"]),[a,c]=g.useState([]),[l,d]=g.useState({}),[h,f]=g.useState(!1),[m,u]=g.useState(null),[p,M]=g.useState({}),[C,y]=g.useState(!1),[v,x]=g.useState(null),[b,k]=g.useState([]),[N,I]=g.useState(null),[B,D]=g.useState(null),[L,E]=g.useState({}),[P,z]=g.useState(null),[j,O]=g.useState(null),[_,T]=g.useState(null),[R,A]=g.useState([]),[q,Y]=g.useState({}),[F,Q]=g.useState(null),[$,S]=g.useState({}),[V,W]=g.useState(new Set),H=e??N;g.useEffect(()=>{e||ae.teams.list().then(({teams:K})=>{k(K.map(ce=>({id:ce.id,name:ce.name})))}).catch(()=>{})},[e]),g.useMemo(()=>{const K={};for(const ce of s)K[ce.id]=ce.name;return K},[s]);const Z=g.useCallback(async()=>{const K=H?[H]:b.map(ce=>ce.id);if(K.length!==0){f(!0);try{const ce=[],ge={},ve={};await Promise.all(K.map(async fe=>{try{const{workflows:re}=await ae.workflows.list(fe);for(const xe of re)ve[xe.name]=fe;ce.push(...re),await Promise.all(re.map(async xe=>{try{const{runs:Ee}=await ae.workflows.listRuns(fe,xe.name,5);ge[xe.name]=Ee}catch{}}))}catch{}})),c(ce),d(ge),S(ve)}catch{}f(!1)}},[H,b]);g.useEffect(()=>{Z()},[Z]);const J=K=>H??$[K],le=async K=>{if(B===K.name){D(null);return}D(K.name);const ce=J(K.name);if(!L[K.name]&&ce)try{const{template:ge}=await ae.workflows.get(ce,K.name);E(ve=>({...ve,[K.name]:ge}))}catch{}},te=K=>{const ce={};for(const re of K.params??[])re.default&&(ce[re.name]=re.default);M(ce),x(null),A([]),Y({});const ge=localStorage.getItem(`markus_wf_project_${K.name}`)??localStorage.getItem("markus_wf_project_last"),ve=ge&&r.some(re=>re.id===ge)?ge:null;Q(n??ve??r[0]?.id??null),u(K);const fe=J(K.name);fe&&ae.workflows.roles(fe,K.name).then(({roles:re})=>A(re)).catch(()=>{})},X=async()=>{const K=F??r[0]?.id,ce=m?J(m.name):void 0;if(!m||!ce||!K){x(K?o("work:task.workflowNoTeam","Cannot determine team for this workflow"):o("work:task.workflowNoProject","Please select a project"));return}y(!0),x(null);try{let ge;if(R.length>0){ge={};for(const ve of R)ge[ve.role]=q[ve.role]??ve.recommended??""}await ae.workflows.startRun(ce,m.name,K,p,ge),localStorage.setItem(`markus_wf_project_${m.name}`,K),localStorage.setItem("markus_wf_project_last",K),u(null),Z()}catch(ge){x(String(ge))}y(!1)};if(!H&&b.length===0&&!e)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:o("work:task.selectProjectForWorkflows","Select a project with a team to view workflows")});if(h&&a.length===0)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:o("work:task.workflowLoading","Loading...")});const ie=async K=>{z(K),O(null);try{await ae.workflows.cancelRun(K),Z()}catch{}z(null)},de=async K=>{T(K.id);try{K.status==="running"?await ae.workflows.pauseRun(K.id):K.status==="paused"&&await ae.workflows.resumeRun(K.id),Z()}catch{}T(null)},se=K=>{K.requirementId&&i&&i(K.requirementId)},me=K=>{const ce={running:"bg-blue-500/20 text-blue-400",paused:"bg-amber-500/20 text-amber-400",completed:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",cancelled:"bg-gray-500/20 text-gray-400"};return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${ce[K]??"bg-gray-500/20 text-gray-400"}`,children:K})},ue=m&&(m.params??[]).some(K=>K.required&&!p[K.name]?.trim());return t.jsxs("div",{className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:[!e&&b.length>0&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-4",children:[t.jsx("button",{onClick:()=>{N!==null&&(I(null),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${N===null?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:o("work:task.all","All")}),b.map(K=>t.jsx("button",{onClick:()=>{N!==K.id&&(I(K.id),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${N===K.id?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:K.name},K.id))]}),a.length===0&&!h?t.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:t.jsx(Xa,{teamId:H,agents:s})}):t.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[a.map(K=>{const ce=B===K.name,ge=L[K.name],fe=(l[K.name]??[]).some(re=>re.status==="running"||re.status==="paused");return t.jsxs("div",{className:"bg-surface-secondary border border-border-default/50 rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2 cursor-pointer",onClick:()=>le(K),children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("svg",{className:`w-3.5 h-3.5 text-fg-tertiary shrink-0 transition-transform ${ce?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:K.displayName||K.name}),t.jsx("span",{className:"text-[11px] text-fg-tertiary",children:o("work:task.workflowStepsCount","{{count}} steps",{count:K.stepCount})})]})}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t.jsxs("span",{className:"text-[10px] text-fg-quaternary font-mono cursor-pointer hover:text-fg-tertiary transition-colors",title:o("work:task.workflowSendToAgent","Send to agent chat"),onClick:re=>{re.stopPropagation();const xe=J(K.name),ye=(xe?s.find(Ie=>Ie.teamId===xe&&Ie.agentRole==="manager"):void 0)?.id??s.find(Ie=>Ie.agentRole==="manager")?.id??s[0]?.id;ye&&Bt.navigate(Fe.TEAM,{agentId:ye,prefillMessage:`@[${K.displayName||K.name}](workflow:${K.name}) `})},children:[t.jsx("svg",{className:"w-3.5 h-3.5 inline mr-0.5 -mt-px",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),K.name]}),K.hasSchedule&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-500/20 text-purple-400",children:o("work:task.workflowScheduled","Scheduled")}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["v",K.version]}),fe?t.jsxs("span",{className:"px-3 py-1 bg-blue-500/20 text-blue-400 text-xs rounded-lg font-medium inline-flex items-center gap-1.5",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 animate-pulse"}),o("work:task.workflowRunning","Running")]}):t.jsx("button",{onClick:re=>{re.stopPropagation(),te(K)},className:"px-3 py-1 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:o("work:task.workflowRun","Run")})]})]}),ce&&ge&&t.jsxs("div",{className:"border-t border-border-default/30 pt-3 mt-1 ml-5 space-y-3",children:[K.description&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:K.description}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:o("work:task.workflowSteps","Steps")}),t.jsx("div",{className:"space-y-1.5",children:ge.steps.map((re,xe)=>t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"shrink-0 w-5 h-5 rounded-full bg-brand-500/15 flex items-center justify-center text-[9px] font-bold text-brand-500 mt-0.5",children:xe+1}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-medium text-fg-primary",children:re.name}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary",children:re.role}),re.depends_on&&re.depends_on.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["← ",re.depends_on.join(", ")]})]}),t.jsx("p",{className:"text-[10px] text-fg-tertiary line-clamp-1 mt-0.5",children:re.prompt})]})]},re.id))})]}),ge.steps.some(re=>re.depends_on&&re.depends_on.length>0)&&t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-1.5 uppercase tracking-wider",children:"DAG"}),t.jsx("div",{className:"flex items-center gap-1 flex-wrap text-[10px]",children:ge.steps.map((re,xe)=>{const Ee=re.depends_on&&re.depends_on.length>0;return t.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[Ee&&t.jsx("span",{className:"text-fg-quaternary",children:"→"}),t.jsx("span",{className:"px-1.5 py-0.5 rounded bg-surface-elevated text-fg-secondary font-medium",children:re.name})]},re.id)})})]}),ge.params&&ge.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:ge.params.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:ge.params.map(re=>t.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-[10px] rounded bg-surface-elevated border border-border-default/30",children:[t.jsx("span",{className:"font-medium text-fg-secondary",children:re.label||re.name}),t.jsxs("span",{className:"text-fg-quaternary",children:["(",re.type||"string",")"]}),re.required&&t.jsx("span",{className:"text-red-400",children:"*"})]},re.name))})]}),ge.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:[ge.schedule.cron&&`cron: ${ge.schedule.cron}`,ge.schedule.interval&&`every: ${ge.schedule.interval}`]})]})]}),(()=>{const re=l[K.name]??[];if(re.length===0)return null;const xe=V.has(K.name),Ee=xe?re:re.slice(0,1);return t.jsxs("div",{className:"border-t border-border-default/30 pt-2 mt-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 cursor-pointer select-none",onClick:()=>W(ye=>{const Ie=new Set(ye);return Ie.has(K.name)?Ie.delete(K.name):Ie.add(K.name),Ie}),children:[t.jsx("svg",{className:`w-3 h-3 text-fg-quaternary transition-transform ${xe?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium uppercase tracking-wider",children:o("work:task.workflowRecentRuns","Recent Runs")}),re.length>1&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["(",re.length,")"]})]}),t.jsx("div",{className:"space-y-1",children:Ee.map(ye=>t.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs px-2 py-1.5 rounded hover:bg-surface-elevated/50",children:[t.jsxs("span",{className:"text-fg-secondary font-medium",children:["#",ye.runNumber]}),me(ye.status),t.jsxs("span",{className:"text-fg-tertiary",children:[ye.taskIds.length," tasks"]}),t.jsx("span",{className:"text-fg-tertiary",children:new Date(ye.startedAt).toLocaleDateString()}),ye.triggeredBy==="schedule"&&t.jsx("span",{className:"text-[10px] text-purple-400",children:"auto"}),t.jsx("span",{className:"flex-1"}),(ye.status==="running"||ye.status==="paused")&&t.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),de(ye)},disabled:_===ye.id,className:`px-2.5 py-0.5 text-[10px] rounded-lg font-medium transition-colors ${ye.status==="running"?"bg-amber-500/20 text-amber-400 hover:bg-amber-500/30":"bg-green-500/20 text-green-400 hover:bg-green-500/30"}`,children:_===ye.id?"...":ye.status==="running"?o("work:task.workflowPause","Pause"):o("work:task.workflowResume","Resume")}),(ye.status==="running"||ye.status==="paused")&&t.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),O(ye.id)},className:"px-2.5 py-0.5 text-[10px] rounded-lg font-medium bg-red-500/20 text-red-400 hover:bg-red-500/30 transition-colors",children:o("work:task.workflowCancelRun","Cancel Run")}),t.jsx("button",{onClick:()=>se(ye),className:"px-2.5 py-0.5 text-[10px] rounded-lg font-medium bg-brand-500/20 text-brand-400 hover:bg-brand-500/30 transition-colors",children:o("work:task.workflowViewTasks","View Tasks")})]},ye.id))})]})})()]},K.name)}),t.jsx(Xa,{teamId:H,agents:s,compact:!0})]}),m&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>u(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-md shadow-2xl",onClick:K=>K.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-1",children:o("work:task.workflowRunTitle","Run: {{name}}",{name:m.displayName||m.name})}),t.jsx("p",{className:"text-xs text-fg-tertiary mb-4",children:m.description}),(m.params??[]).length>0&&t.jsx("div",{className:"space-y-3 mb-4",children:(m.params??[]).map(K=>t.jsxs("div",{children:[t.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[K.label||K.name,K.required&&t.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),K.type==="enum"&&K.options?t.jsxs("select",{value:p[K.name]??"",onChange:ce=>M(ge=>({...ge,[K.name]:ce.target.value})),className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:"—"}),K.options.map(ce=>t.jsx("option",{value:ce,children:ce},ce))]}):t.jsx("textarea",{value:p[K.name]??"",onChange:ce=>{M(fe=>({...fe,[K.name]:ce.target.value}));const ge=ce.target;ge.style.height="auto";const ve=parseFloat(getComputedStyle(ge).lineHeight)||18;ge.style.height=Math.min(ge.scrollHeight,ve*7)+"px"},placeholder:K.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},K.name))}),R.length>0&&t.jsxs("div",{className:"mb-4",children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:o("work:task.roles","Roles")}),t.jsx("div",{className:"space-y-2",children:R.map(K=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs text-fg-secondary w-24 shrink-0 font-medium",children:K.role}),t.jsx("select",{value:q[K.role]??K.recommended??"",onChange:ce=>Y(ge=>({...ge,[K.role]:ce.target.value})),className:"input-field text-xs flex-1",children:K.candidates.map(ce=>t.jsxs("option",{value:ce.agentId,children:[ce.agentName,ce.agentId===K.recommended?" ★":""]},ce.agentId))})]},K.role))})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1",children:o("work:task.workflowProject","Project")}),t.jsxs("select",{value:F??"",onChange:K=>{const ce=K.target.value||null;Q(ce),x(null),ce&&localStorage.setItem("markus_wf_project_last",ce)},className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:o("work:task.workflowSelectProject","— Select a project —")}),r.map(K=>t.jsx("option",{value:K.id,children:K.name},K.id))]})]}),v&&t.jsx("p",{className:"text-xs text-red-400 mb-3",children:v}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>u(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowCancel","Cancel")}),t.jsx("button",{onClick:X,disabled:C||!!ue,className:"btn-primary text-xs px-4 py-1.5",children:C?o("work:task.workflowStarting","Starting..."):o("work:task.workflowStartRun","Start Run")})]})]})}),j&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>O(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:K=>K.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-2",children:o("work:task.workflowConfirmCancelTitle","Cancel Workflow Run")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-5",children:o("work:task.workflowConfirmCancelDesc","This will cancel all running and pending tasks in this workflow run. This action cannot be undone.")}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>O(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowNo","No")}),t.jsx("button",{onClick:()=>ie(j),disabled:P===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:P===j?o("work:task.workflowCancelling","Cancelling..."):o("work:task.workflowConfirmCancelBtn","Confirm Cancel")})]})]})})]})}function sm({authUser:e,previewMode:n,previewData:s}={}){const{t:r}=We(["work","common"]),i=Fl(Fe.WORK),o=g.useMemo(()=>ss.map(w=>({...w,label:r(`work:boardColumn.${w.id}`)})),[r]),a=g.useMemo(()=>yl(r),[r]),c=g.useMemo(()=>io(r),[r]),l=vr(),d=Yl(),h=d?.leftCollapsed??!1,f=g.useRef(null),[m,u]=g.useState(0);g.useEffect(()=>{const w=f.current;if(!w)return;const U=new ResizeObserver(([ee])=>u(ee.contentRect.width));return U.observe(w),u(w.clientWidth),()=>U.disconnect()},[]);const[p,M]=g.useState(()=>{if(n)return!1;try{return localStorage.getItem(Aa)==="1"}catch{return!1}}),C=g.useCallback(w=>{M(w);try{localStorage.setItem(Aa,w?"1":"0")}catch{}},[]),y=g.useRef(h);g.useEffect(()=>{n||l||y.current!==h&&(y.current=h,M(h))},[h,n,l]);const v=Gl({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),x=6,b=!l&&!p?v.width+x:0,k=Math.max(0,(m||window.innerWidth)-b-x-8),N=Math.max(320,Math.round(k/2)),[I,B]=g.useState("auto"),D=Math.max(320,k-280),L=I==="auto"?Math.min(N,D):I,E=Math.max(320,Math.min(L,D)),P=g.useRef(E);P.current=E;const z=g.useRef(D);z.current=D;const j=g.useCallback(w=>{w.preventDefault();const U=w.clientX,ee=P.current,ne=je=>{const we=Math.max(320,Math.min(z.current,ee+(U-je.clientX)));B(we)},he=()=>{document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",he),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ne),document.addEventListener("mouseup",he),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[O,_]=g.useState(!1),T=g.useRef(O);T.current=O;const[R,A]=g.useState(s?.projects??[]),[q,Y]=g.useState("all"),[F,Q]=g.useState(null),[$,S]=g.useState("closed"),[V,W]=g.useState("projects"),[H,Z]=g.useState(s?.board??{}),[J,le]=g.useState(s?.agents??[]),[te,X]=g.useState([]),[ie,de]=g.useState(s?.users??[]),[se,me]=g.useState(s?.allRequirements??[]),[ue,K]=g.useState(!s),[ce,ge]=g.useState(""),ve=g.useCallback(()=>{Cr(F??""),hn(!0)},[F]),[fe,re]=g.useState(!1),[xe,Ee]=g.useState(!1),[ye,Ie]=g.useState(""),[pt,rt]=g.useState(""),[Nt,Ct]=g.useState("medium"),[st,Ht]=g.useState(""),[xt,Jt]=g.useState(""),[bt,yt]=g.useState(""),[Ce,Xe]=g.useState(""),[$e,Le]=g.useState([]),[et,qt]=g.useState("standard"),[Wt,_e]=g.useState("4h"),[Ye,tt]=g.useState(""),[un,Mn]=g.useState(!1),[Ge,Ae]=g.useState(null),[ze,De]=g.useState(()=>s?.initialSelectedReqId&&s.allRequirements?s.allRequirements.find(w=>w.id===s.initialSelectedReqId)??null:null);g.useEffect(()=>{s?.initialSelectedReqId&&ze&&S("item")},[]);const[He,dt]=g.useState(new Set),[Qe,it]=g.useState(!1),[ut,en]=g.useState(new Set),Vt=g.useRef(new Set),[St,Et]=g.useState(null),[Je,ft]=g.useState(s?.initialBoardType??"backlog"),[fn,ot]=g.useState(null),$t=g.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"},{id:"workflows"}],[]),vt=_s($t,Je,ft),ht=g.useRef(null),G=g.useMemo(()=>({scrollContainerRef:ht}),[]),pe=_s($t,Je,ft,G),[Ne,Me]=g.useState(!1),[Se,lt]=g.useState(null),[Ft,Mt]=g.useState(!1),tn=g.useRef(null),In=g.useRef(null),[Jn,hn]=g.useState(!1),[mn,gn]=g.useState(""),[Tn,pn]=g.useState(""),[er,hs]=g.useState("medium"),[xn,Cr]=g.useState(""),[nn,It]=g.useState(null),[Sr,Er]=g.useState(""),[tr,rn]=g.useState(""),[ms,lo]=g.useState(!1),[co,Rn]=g.useState(""),ct=w=>{ge(w),setTimeout(()=>ge(""),3e3)};g.useEffect(()=>{const w=U=>{U.key==="Escape"&&(nn?(It(null),Rn("")):xe?(Ee(!1),tt("")):Jn?(hn(!1),gn(""),pn(""),rn("")):Ft?Mt(!1):$!=="closed"&&(S("closed"),Ae(null),De(null),l&&T.current&&_(!1)))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[nn,xe,Jn,Ft,$,l]);const wt=R.find(w=>w.id===F)??null,jl=wt?.teamIds?.[0]??null,Tt=g.useMemo(()=>R.filter(w=>w.status!=="archived"),[R]),uo=g.useCallback(()=>{F&&(Ae(null),De(null),S("project"),B("auto"),l&&_(!0))},[F,l]),Mr=g.useCallback(()=>{if($==="project"){S("closed"),l&&_(!1);return}uo()},[$,uo,l]);g.useEffect(()=>{Vt.current=ut},[ut]);const bn=g.useCallback(async()=>{try{const{projects:w}=await ae.projects.list();A(w)}catch{}},[]),nt=g.useCallback(async()=>{const w={};q==="project"&&F&&(w.projectId=F);try{const{board:U}=await ae.tasks.board(w);Z(U)}catch{}},[q,F]),nr=g.useCallback(async()=>{try{const{agents:w}=await ae.agents.list();le(w)}catch{}},[]),fo=g.useCallback(async()=>{try{const{teams:w}=await ae.teams.list();X(w.map(U=>({id:U.id,name:U.name})))}catch{}},[]),ho=g.useCallback(async()=>{try{const{users:w}=await ae.users.list(e?.orgId);de(w)}catch{}},[e?.orgId]),Rt=g.useCallback(async()=>{try{const{requirements:w}=await ae.requirements.list({});me(w)}catch{}},[]),mo=g.useCallback(async()=>{await Promise.all([bn(),nt(),nr(),ho(),Rt(),fo()]),K(!1)},[bn,nt,nr,ho,Rt,fo]);g.useEffect(()=>{n||mo()},[n,mo]),g.useEffect(()=>{!n||!s||(A(s.projects??[]),Z(s.board??{}),le(s.agents??[]),de(s.users??[]),me(s.allRequirements??[]))},[n,s]);const Ir=g.useCallback(w=>{W("items"),Ae(U=>U?.id===w.id&&$==="item"?(S("closed"),l&&T.current&&_(!1),null):(S("item"),B("auto"),l&&(_(!0),history.pushState({mobileDetail:Fe.WORK},"",window.location.hash)),w)),De(null)},[l,$]),Tr=g.useCallback(w=>{W("items"),De(U=>U?.id===w.id&&$==="item"?(S("closed"),l&&T.current&&_(!1),null):(S("item"),B("auto"),l&&(_(!0),history.pushState({mobileDetail:Fe.WORK},"",window.location.hash)),w)),Ae(null)},[l,$]),yn=g.useCallback(()=>{Ae(null),De(null),S("closed"),l&&T.current&&_(!1)},[l]),Yt=g.useRef(Ge);Yt.current=Ge;const Gt=g.useRef(ze);Gt.current=ze;const vn=g.useRef($);vn.current=$;const _n=g.useRef(V);_n.current=V;const Ln=g.useRef(p);Ln.current=p;const gs=g.useRef(Je);gs.current=Je;const Nl=g.useCallback(()=>{Ae(null),Gt.current||(S("closed"),l&&T.current&&_(!1))},[l]);g.useEffect(()=>{if(!l)return;const w=()=>{T.current&&(_(!1),Ae(null),De(null),S("closed"))};return window.addEventListener("popstate",w),()=>window.removeEventListener("popstate",w)},[l]),g.useEffect(()=>{if(n||!i)return;nt(),nr(),Rt();const w=Yt.current?12e4:45e3,U=setInterval(()=>{nt(),nr(),Rt()},w);let ee=null;const ne=()=>{ee||(ee=setTimeout(()=>{ee=null,nt()},800))};let he=null;const je=()=>{he||(he=setTimeout(()=>{he=null,Rt()},800))},we=jt.on("task:update",Oe=>{_t("/taskboard"),ne();const ke=Oe?.payload;ke?.taskId&&(Ae(Ve=>{if(!Ve||Ve.id!==ke.taskId)return Ve;const Re={};return typeof ke.status=="string"&&(Re.status=ke.status),Array.isArray(ke.deliverables)&&(Re.deliverables=ke.deliverables),Array.isArray(ke.notes)&&(Re.notes=ke.notes),ke.result!==void 0&&(Re.result=ke.result),{...Ve,...Re}}),Yt.current?.id===ke.taskId&&(_t("/tasks/"+ke.taskId),ae.tasks.get(ke.taskId).then(Ve=>{Ve.task&&Ae(Re=>Re?.id===Ve.task.id?Ve.task:Re)}).catch(()=>{})))}),oe=jt.on("task:create",()=>{ne()}),kt=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(Oe=>jt.on(Oe,ke=>{_t("/requirements"),je();const Ve=ke?.payload,Re=Ve?.id??Ve?.requirementId;Re&&Gt.current?.id===Re&&(_t("/requirements/"+Re),ae.requirements.get(Re).then(Xt=>{Xt.requirement&&De(jn=>jn?.id===Xt.requirement.id?Xt.requirement:jn)}).catch(()=>{}))})),mt=()=>{_t("/taskboard"),_t("/tasks"),_t("/requirements"),nt(),Rt(),Yt.current&&ae.tasks.get(Yt.current.id).then(Oe=>{Oe.task&&Ae(ke=>ke?.id===Oe.task.id?Oe.task:ke)}).catch(()=>{}),Gt.current&&ae.requirements.get(Gt.current.id).then(Oe=>{Oe.requirement&&De(ke=>ke?.id===Oe.requirement.id?Oe.requirement:ke)}).catch(()=>{})};return window.addEventListener("markus:data-changed",mt),()=>{clearInterval(U),we(),oe(),kt.forEach(Oe=>Oe()),window.removeEventListener("markus:data-changed",mt),ee&&clearTimeout(ee),he&&clearTimeout(he)}},[n,i,nt,nr,Rt]);const go=g.useRef(H);go.current=H;const po=g.useRef(se);po.current=se,g.useEffect(()=>{const w=Yt.current;if(!w)return;const ee=Object.values(H).flat().find(ne=>ne.id===w.id);ee&&ee.updatedAt!==w.updatedAt&&Ae(ee)},[H]),g.useEffect(()=>{const w=Gt.current;if(!w)return;const U=se.find(ee=>ee.id===w.id);U&&U.updatedAt!==w.updatedAt&&De(U)},[se]);const sn=g.useCallback(w=>{w&&(Q(w),Y("project"),en(new Set),history.replaceState(null,"",ys(Fe.WORK,w)))},[]),[ps,rr]=g.useState(!1),sr=g.useCallback((w,U)=>{Ae(w),De(null),S("item"),W("items"),B("auto"),U?.scrollToComments&&rr(!0),l&&_(!0)},[l]),An=g.useCallback((w,U)=>{De(w),Ae(null),S("item"),W("items"),B("auto"),U?.scrollToComments&&rr(!0),l&&_(!0)},[l]),Dn=g.useRef(null);g.useEffect(()=>{const w=Dn.current||localStorage.getItem("markus_nav_openTask");if(!w)return;const ee=Object.values(H).flat().find(ne=>ne.id===w);ee?(Dn.current=null,sn(ee.projectId),sr(ee),localStorage.removeItem("markus_nav_openTask")):Dn.current||(Dn.current=w,localStorage.removeItem("markus_nav_openTask"),ae.tasks.get(w).then(ne=>{ne.task&&(Dn.current=null,sn(ne.task.projectId),sr(ne.task))}).catch(()=>{Dn.current=null}))},[H,sr,sn]);const Pn=g.useRef(null);g.useEffect(()=>{const w=Pn.current||localStorage.getItem("markus_nav_openRequirement");if(!w)return;const U=se.find(ee=>ee.id===w);U?(Pn.current=null,sn(U.projectId),An(U),localStorage.removeItem("markus_nav_openRequirement")):Pn.current||(Pn.current=w,localStorage.removeItem("markus_nav_openRequirement"),ae.requirements.get(w).then(ee=>{ee.requirement&&(Pn.current=null,sn(ee.requirement.projectId),An(ee.requirement))}).catch(()=>{Pn.current=null}))},[se,An,sn]);const Ot=g.useCallback((w,U)=>{en(new Set),Q(w),Y("project"),W(p?"items":"projects"),U?.keepItemDetail||(Ae(null),De(null),S(ee=>ee==="closed"?ee:"project")),history.replaceState(null,"",ys(Fe.WORK,w))},[p]),Kt=g.useCallback(w=>{en(new Set),Q(null),Y("all"),W(p?"items":"projects"),w?.keepItemDetail||(Ae(null),De(null),S(U=>U==="closed"?U:U==="project"?"closed":"empty")),history.replaceState(null,"",ys(Fe.WORK))},[p]),wn=g.useRef(!1);g.useEffect(()=>{if(wn.current)return;const w=window.location.hash.slice(1).split("/");if(Br(w[0])===Fe.WORK&&w[1]){wn.current=!0,Ot(w[1],{keepItemDetail:!0});return}const U=localStorage.getItem("markus_nav_projectId");if(U){wn.current=!0,localStorage.removeItem("markus_nav_projectId"),Ot(U,{keepItemDetail:!0});return}wn.current=!0,Kt({keepItemDetail:!0})},[]),g.useEffect(()=>{if(!ue){if(!F){wn.current=!0,q!=="all"&&Y("all");return}if(Tt.some(w=>w.id===F)){wn.current=!0;return}wn.current=!0,Kt({keepItemDetail:!0})}},[ue,Tt,F,Kt,q]);const Cl=g.useRef(Br(window.location.hash.slice(1).split("/")[0]));g.useEffect(()=>{if(n)return;const w=()=>{const ee=window.location.hash.slice(1).split("/"),ne=Br(ee[0]);Cl.current=ne,ne===Fe.WORK&&(ee[1]?Ot(ee[1],{keepItemDetail:!0}):Kt({keepItemDetail:!0}))},U=async ee=>{const ne=ee.detail;if(Br(ne.page)===Fe.WORK){if(ne.params?.openTask){const he=ne.params.openTask,je=ne.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let we=Object.values(go.current).flat().find(oe=>oe.id===he);if(!we)try{we=(await ae.tasks.get(he)).task}catch{}we&&(sn(we.projectId),sr(we,{scrollToComments:je}))}if(ne.params?.openRequirement){const he=ne.params.openRequirement,je=ne.params.scrollToComments==="true";let we=po.current.find(oe=>oe.id===he);if(!we)try{we=(await ae.requirements.get(he)).requirement}catch{}we&&(sn(we.projectId),An(we,{scrollToComments:je}))}if(ne.params?.projectId&&Ot(ne.params.projectId),ne.params?.statusFilter){const he=ne.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),$h.has(he)&&Me(!0),lt(he)}}};return window.addEventListener("markus:navigate",U),window.addEventListener("hashchange",w),()=>{window.removeEventListener("markus:navigate",U),window.removeEventListener("hashchange",w)}},[n]);const Sl=w=>{re(!1),ct(r("work:task.projectCreated")),A(U=>U.some(ee=>ee.id===w.id)?U:[...U,w]),Ot(w.id),bn()},El=async w=>{try{await ae.projects.delete(w),F===w&&Kt(),ct(r("work:task.projectDeleted")),bn(),nt()}catch(U){ct(r("work:task.errorGeneric",{message:String(U)}))}},xo=async()=>{if(!ye||!st||!xt||un)return;tt("");const w=xt.startsWith("human:"),U=xt.replace(/^(human|agent):/,"");if(st===U&&!w){ct(r("work:task.assignedReviewerDifferent"));return}const ee=bt||void 0,ne=Ce||void 0;Mn(!0);try{const{task:he}=await ae.tasks.create(ye,pt,st,U,Nt,ee,$e.length>0?$e:void 0,ne,et!=="standard"?et:void 0,et==="scheduled"?{every:Wt}:void 0,w?"human":"agent");Ie(""),rt(""),Le([]),Xe(""),qt("standard"),_e("4h"),Ee(!1),nt(),he&&sr(he)}catch(he){const we=`work:task.errorCode_${(he instanceof Xl?he.code:void 0)||"unknown"}`,oe=r(we,{defaultValue:""});tt(oe||r("work:task.errorCreatingTask",{message:he instanceof Error?he.message:String(he)}))}finally{Mn(!1)}},$n=w=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:w}))},bo=()=>{_t("/taskboard"),nt(),Ge&&($n({taskId:Ge.id}),_t("/tasks/"+Ge.id),ae.tasks.get(Ge.id).then(w=>{w.task&&Ae(U=>U?.id===w.task.id?w.task:U)}).catch(()=>{}))},kn=()=>{_t("/requirements"),Rt(),ze&&(_t("/requirements/"+ze.id),ae.requirements.get(ze.id).then(w=>{w.requirement&&De(U=>U?.id===w.requirement.id?w.requirement:U)}).catch(()=>{}))},yo=async()=>{if(!ms){if(!mn.trim()){rn(r("work:task.pleaseReqTitle"));return}if(!Tn.trim()){rn(r("work:task.pleaseReqDesc"));return}if(!xn){rn(r("work:task.pleaseReqProject"));return}rn(""),lo(!0);try{const{requirement:w}=await ae.requirements.create({title:mn.trim(),description:Tn.trim(),priority:er,projectId:xn});ct(r("work:task.requirementCreated")),gn(""),pn(""),hn(!1),Rt(),w&&An(w)}catch(w){rn(w instanceof Error?w.message:String(w))}finally{lo(!1)}}},xs=async w=>{try{await ae.requirements.approve(w),ct(r("work:task.requirementApproved")),$n({requirementId:w}),kn(),nt()}catch(U){ct(r("work:task.errorGeneric",{message:String(U)}))}},Ml=async()=>{if(nn){Rn("");try{await ae.requirements.reject(nn,Sr),ct(r("work:task.requirementRejected")),$n({requirementId:nn}),It(null),Er(""),Rn(""),kn()}catch(w){Rn(w instanceof Error?w.message:String(w))}}},vo=async w=>{try{await ae.requirements.cancel(w),ct(r("work:task.requirementCancelled")),$n({requirementId:w}),kn()}catch(U){ct(r("work:task.errorGeneric",{message:String(U)}))}},Il=(w,U)=>{tn.current=U,In.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`task:${U.id}`),w.currentTarget.style.opacity="0.4"},Tl=(w,U)=>{In.current=U,tn.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`req:${U.id}`),w.currentTarget.style.opacity="0.4"},wo=w=>{w.currentTarget.style.opacity="1",tn.current=null,In.current=null,Et(null)},Rl=(w,U)=>{w.preventDefault(),w.dataTransfer.dropEffect="move",St!==U&&Et(U)},_l=(w,U)=>{const ee=w.currentTarget.getBoundingClientRect(),{clientX:ne,clientY:he}=w;(ne<ee.left||ne>ee.right||he<ee.top||he>ee.bottom)&&St===U&&Et(null)},Ll=async(w,U)=>{w.preventDefault(),Et(null);const ee=tn.current,ne=In.current;if(ee){const he=o.find(we=>we.id===U);if(!he)return;const je=he.dropStatus;if(ee.status===je||ee.status==="pending")return;try{await ae.tasks.updateStatus(ee.id,je),nt()}catch{}}else if(ne){const he=vl[U];if(!he||ne.status===he)return;try{await ae.requirements.updateStatus(ne.id,he),Rt()}catch{}}},ko=w=>{dt(U=>{const ee=new Set(U);return ee.has(w)?ee.delete(w):ee.add(w),ee})},Rr=w=>{Ot(w)},Al=new Set(["rejected","cancelled","archived"]),_r=w=>Al.has(w.status),or=(w,U=!1)=>{let ee=w.filter(ne=>Ne||!_r(ne));return Se&&(ee=ee.filter(ne=>ne.status===Se)),q==="project"&&F&&(ee=ee.filter(ne=>ne.projectId===F)),ut.size>0&&(ee=ee.filter(ne=>ne.projectId&&ut.has(ne.projectId))),He.size>0&&(ee=ee.filter(ne=>ne.assignedAgentId&&He.has(ne.assignedAgentId))),Qe&&e?.id&&(ee=ee.filter(ne=>ne.createdBy===e.id)),ee},Dl=g.useMemo(()=>{const w=new Map;for(const U of Object.values(H))for(const ee of U)w.set(ee.id,ee);return w},[H]),Pl=g.useMemo(()=>new Set(J.map(w=>w.id)),[J]),jo=w=>w.statuses.flatMap(U=>or(H[U]??[])),Zt=g.useMemo(()=>{let w=se;return Ne||(w=w.filter(U=>!_r(U))),q==="project"&&F&&(w=w.filter(U=>U.projectId===F)),ut.size>0&&(w=w.filter(U=>U.projectId&&ut.has(U.projectId))),He.size>0&&(w=w.filter(U=>He.has(U.createdBy))),Qe&&e?.id&&(w=w.filter(U=>U.createdBy===e.id)),w},[se,Ne,q,F,ut,He,Qe,e?.id,Pl]),No=g.useCallback(w=>Zt.filter(U=>Jr[U.status]===w.id),[Zt]),$l=o.filter(w=>{if(w.id==="failed"||w.id==="closed"){const U=jo(w),ee=No(w);return U.length+ee.length>0}return!0}),ar=Object.values(H).flat().filter(w=>_r(w)).length+se.filter(w=>_r(w)).length,Co=g.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),U=Object.values(H).flat(),ee=new Set;for(const ne of U)ne.assignedAgentId&&!w.has(ne.status)&&(!F||ne.projectId===F)&&ee.add(ne.assignedAgentId);return[...J].sort((ne,he)=>{const je=ee.has(ne.id)?0:1,we=ee.has(he.id)?0:1;return je-we})},[J,H,F]),Lr=g.useMemo(()=>{const w=new Map,U=[];for(const ne of Co)if(ne.teamId){const he=w.get(ne.teamId)??[];he.push(ne.id),w.set(ne.teamId,he)}else U.push(ne);const ee=[];for(const ne of U)ee.push({kind:"agent",agent:ne});for(const ne of te){const he=w.get(ne.id);he&&he.length>0&&ee.push({kind:"team",id:ne.id,name:ne.name,agentIds:he})}return ee},[Co,te]);g.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),U=Object.values(H).flat(),ee=new Set;for(const he of U)he.projectId&&!w.has(he.status)&&ee.add(he.projectId);return[...Ne?R:R.filter(he=>he.status!=="archived")].sort((he,je)=>{const we=he.status==="archived"?1:0,oe=je.status==="archived"?1:0;if(we!==oe)return we-oe;const Ue=ee.has(he.id)?0:1,kt=ee.has(je.id)?0:1;return Ue!==kt?Ue-kt:he.name.localeCompare(je.name)})},[R,H,Ne]);const Ar=g.useMemo(()=>{const w={};for(const U of Object.values(H))for(const ee of U){const ne=ee.projectId??"__none__";w[ne]=(w[ne]??0)+1}return w},[H]),Dr=Object.values(Ar).reduce((w,U)=>w+U,0),Ol=F?Ar[F]??0:Dr,So=g.useMemo(()=>{const w=or(Object.values(H).flat()),U=[];if(Je==="kanban"){for(const ne of ss){const he=ne.statuses.flatMap(oe=>w.filter(Ue=>Ue.status===oe)),we=[...Zt.filter(oe=>Jr[oe.status]===ne.id).map(oe=>({kind:"req",data:oe,time:new Date(oe.updatedAt??oe.createdAt).getTime()})),...he.map(oe=>({kind:"task",data:oe,time:new Date(oe.updatedAt??oe.createdAt??0).getTime()}))];we.sort((oe,Ue)=>Ue.time-oe.time);for(const oe of we)oe.kind==="req"?U.push({kind:"req",data:oe.data}):U.push({kind:"task",data:oe.data})}return U}const ee=[];for(const ne of w){const he=wl(ne.status);ee.push({kind:"task",data:ne,groupOrder:os[he]??5,time:new Date(ne.updatedAt??ne.createdAt??0).getTime()})}for(const ne of Zt){const he=Jr[ne.status]??"todo";ee.push({kind:"req",data:ne,groupOrder:os[he]??5,time:new Date(ne.updatedAt??ne.createdAt).getTime()})}return ee.sort((ne,he)=>ne.groupOrder!==he.groupOrder?ne.groupOrder-he.groupOrder:he.time-ne.time),ee.map(ne=>ne.kind==="req"?{kind:"req",data:ne.data}:{kind:"task",data:ne.data})},[H,Zt,Je,Ne,Se,F,ut,He,Qe,e?.id,q]),Pr=g.useRef(So);Pr.current=So;const Eo=g.useRef(Tt);Eo.current=Tt;const bs=g.useRef(F);bs.current=F;const On=g.useCallback(w=>{w.kind==="req"?(De(w.data),Ae(null)):(Ae(w.data),De(null)),S("item"),B("auto"),W("items")},[]),Mo=g.useCallback(()=>{if(vn.current==="item"||vn.current==="empty"){S("closed"),Ae(null),De(null);return}if(Yt.current||Gt.current){S("item"),B("auto"),W("items");return}const w=Pr.current;if(w.length>0){On(w[0]);return}Ae(null),De(null),S("empty"),B("auto")},[On]);g.useEffect(()=>{if(!l)if(p){if(W("items"),vn.current==="project")if(Yt.current||Gt.current)S("item");else{const w=Pr.current;w.length>0?On(w[0]):S("closed")}}else _n.current==="items"&&vn.current==="closed"||!p&&vn.current==="closed"&&W("projects")},[p,l,On]);const ir=d?.keyboardPane??"content",Io=g.useRef(ir);if(g.useEffect(()=>{if(n||l||!i)return;const w=Io.current;Io.current=ir,ir==="l1"&&(W("projects"),w!=="l1"&&Ln.current&&(C(!1),d?.setLeftCollapsed(!1)))},[ir,n,l,i,C,d]),g.useEffect(()=>{if(n||l||!i)return;const w=navigator.platform.toUpperCase().includes("MAC"),U=ee=>{if(d?.keyboardPane==="l0")return;const ne=w?ee.metaKey&&!ee.ctrlKey:ee.ctrlKey&&!ee.metaKey;if(ee.ctrlKey&&!ee.metaKey&&ee.key==="Tab"){ee.preventDefault();const ke=Mh,Ve=ke.indexOf(gs.current),Re=ee.shiftKey?ke[(Ve-1+ke.length)%ke.length]:ke[(Ve+1)%ke.length];ft(Re);return}if(ne&&!ee.altKey&&!ee.shiftKey){const ke=ee.key.toLowerCase();if(ke==="j"){ee.preventDefault(),Mr();return}if(ke==="l"){ee.preventDefault(),Mo();return}}if(ne||ee.altKey||ee.ctrlKey||ee.metaKey||Zl(ee.target))return;const he=ee.key.length===1?ee.key.toLowerCase():ee.key;if(he==="h"||he==="ArrowLeft"){if(Ln.current){ee.preventDefault(),C(!1),d?.setLeftCollapsed(!1),W("projects"),d?.setKeyboardPane("l1");return}if(_n.current==="items"){ee.preventDefault(),W("projects"),d?.setKeyboardPane("l1");return}ee.preventDefault(),d?.setL0FocusPageId(Fe.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((he==="l"||he==="ArrowRight"||he==="Tab"&&!ee.shiftKey)&&!Ln.current&&_n.current==="projects"){ee.preventDefault(),W("items"),d?.setKeyboardPane("content");return}if((he==="l"||he==="ArrowRight")&&(Ln.current||_n.current==="items")){ee.preventDefault();return}const je=he==="j"||he==="ArrowDown"?1:he==="k"||he==="ArrowUp"?-1:0;if(!je)return;if((Ln.current?"items":_n.current)==="projects"){ee.preventDefault(),d?.setKeyboardPane("l1");const ke=Eo.current,Ve=ke.length+1;if(ke.length===0)return;const Re=bs.current==null?0:ke.findIndex(Bn=>Bn.id===bs.current)+1,Xt=Re<0?0:Re,jn=Math.max(0,Math.min(Ve-1,Xt+je));if(jn===0)Kt(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const Bn=ke[jn-1];Ot(Bn.id),vn.current!=="closed"&&(S("project"),Ae(null),De(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${Bn.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const oe=gs.current;if(oe!=="backlog"&&oe!=="kanban")return;ee.preventDefault(),d?.setKeyboardPane("content");const Ue=Pr.current;if(Ue.length===0){S(ke=>ke==="closed"?"empty":ke);return}const kt=Yt.current?.id??Gt.current?.id??null;let mt=kt?Ue.findIndex(ke=>ke.data.id===kt):-1;mt<0&&(mt=je>0?-1:0);const Oe=Math.max(0,Math.min(Ue.length-1,mt+je));On(Ue[Oe]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${Ue[Oe].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",U,!0),()=>document.removeEventListener("keydown",U,!0)},[n,l,i,Mr,Mo,Ot,Kt,On,C,d]),ue)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:r("work:task.loadingPage")});const To=$!=="closed"||!!(Ge||ze),$r=!l&&!!(Ge&&ze)&&$==="item",Ro=l?O:To;return t.jsxs("div",{ref:f,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!l&&t.jsx(Eh,{projects:Tt,selectedProjectId:F,allSelected:q==="all"&&!F,taskCounts:Ar,totalTaskCount:Dr,onSelectAll:()=>{Kt(),W("projects")},onSelectProject:w=>{Ot(w),W("projects")},onCreateProject:()=>re(!0),onCollapse:()=>{const w=!p;C(w),d?.setLeftCollapsed(w)},width:v.width,onResizeStart:v.onResizeStart,hidden:p,focused:ir==="l1"&&V==="projects"&&!p,onActivate:()=>W("projects")}),t.jsxs("div",{"data-keyboard-pane":"content",onPointerDown:()=>W("items"),className:`${l?"flex-1 min-w-0":$r?"w-0 shrink-0 overflow-hidden":"flex-1 min-w-0"} overflow-hidden flex flex-col bg-surface-primary`,style:l&&O?{display:"none"}:void 0,children:[ce&&t.jsx("div",{className:"mx-6 mt-2 px-3 py-1.5 bg-green-500/15 text-green-600 text-xs rounded-lg",children:ce}),l?t.jsxs("div",{className:"shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[t.jsx(Kl,{}),wt?t.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[t.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:wt.name}),t.jsx("button",{onClick:Mr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${$==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:r("work:task.projectsCount",{count:Tt.length})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>re(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortProject")}),t.jsx("button",{onClick:ve,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortReq")}),t.jsx("button",{onClick:()=>{yt(F??""),Ee(!0)},className:"px-2 py-1 text-[11px] border border-amber-500/60 text-amber-600 rounded-md",children:r("work:task.shortTask")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 px-3 h-9",children:[t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(w=>t.jsx("button",{onClick:()=>ft(w),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${Je===w?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:r(w==="backlog"?"work:task.backlog":w==="kanban"?"work:task.kanban":"work:task.dag")},w))}),ar>0&&t.jsx("button",{onClick:()=>Me(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ne?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Ne?r("work:task.hideArchived"):r("work:task.archivedCount",{count:ar})}),t.jsx("div",{className:"flex-1"}),Se&&t.jsxs("button",{onClick:()=>lt(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.${Se==="in_progress"?"inProgress":Se}`),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"})]})]}),(Tt.length>1||J.length>0||e?.id)&&t.jsxs("button",{onClick:()=>Mt(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${He.size>0||Qe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),He.size+(Qe?1:0)>0?r("work:task.filterWithCount",{count:He.size+(Qe?1:0)}):r("work:task.filter")]})]})]}):t.jsxs("div",{"data-electron-drag":!0,className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[wt?t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[t.jsx(Rh,{value:wt.name,onSave:async w=>{await ae.projects.update(wt.id,{name:w}),bn()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:Mr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${$==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:`${r("work:project.settingsTitle")} (⌘J)`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:r("work:task.projectsCount",{count:Tt.length})}),ar>0&&t.jsx("button",{onClick:()=>Me(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ne?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Ne?r("work:task.hideArchivedWithCount",{count:ar}):r("work:task.archivedCount",{count:ar})}),t.jsx("div",{"data-no-drag":!0,className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(w=>t.jsx("button",{onClick:()=>ft(w),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Je===w?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:w==="backlog"?r("work:task.backlog"):w==="kanban"?r("work:task.kanban"):w==="dag"?r("work:task.dag"):r("work:task.workflows","Workflows")},w))}),t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:ve,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:r("work:task.newRequirement")}),t.jsx("button",{onClick:()=>{yt(F??""),Ee(!0)},className:"px-3 py-1.5 border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 text-xs rounded-lg font-medium transition-colors",children:r("work:task.newTaskBtn")})]}),t.jsx("div",{className:"flex-1"})]}),!l&&Je!=="workflows"&&(Lr.length>0||e?.id)&&(Ol>0||Zt.length>0||He.size>0||Qe)&&t.jsxs("div",{className:"px-6 py-1.5 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[t.jsx("button",{type:"button",onClick:()=>{dt(new Set),it(!1)},className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${He.size>0||Qe?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),e?.id&&t.jsx("button",{type:"button",onClick:()=>it(w=>!w),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Qe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:r("work:task.myTasks")}),Lr.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(je=>He.has(je)),he=!ne&&w.agentIds.some(je=>He.has(je));return t.jsxs("button",{onClick:()=>{dt(je=>{const we=new Set(je);if(ne)for(const oe of w.agentIds)we.delete(oe);else for(const oe of w.agentIds)we.add(oe);return we})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ne?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})}),w.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:w.agentIds.length})]},`team-${w.id}`)}const U=w.agent,ee=He.has(U.id);return t.jsxs("button",{onClick:()=>ko(U.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ee?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${ee?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:U.name[0]?.toUpperCase()}),U.name]},U.id)})]}),Tt.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyNoProjectsTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyNoProjectsHint")}),t.jsx("button",{onClick:()=>re(!0),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:r("work:project.newProject")})]})}):or(Object.values(H).flat()).length===0&&Zt.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:[t.jsx("path",{d:"M9 11l3 3L22 4"}),t.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}),He.size>0||Qe?t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyFilteredTitle",{defaultValue:"No matching work"})}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyFilteredHint",{defaultValue:"Nothing matches the current assignee filter. Clear filters to see all items in this project."})}),t.jsx("button",{type:"button",onClick:()=>{dt(new Set),it(!1)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg font-medium transition-colors",children:r("work:task.clear")})]}):t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyNoReqsTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed whitespace-pre-line",children:r("work:task.emptyNoReqsHint")}),t.jsxs("div",{className:"flex items-center justify-center gap-2 pt-1",children:[t.jsx("button",{onClick:ve,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:r("work:task.createRequirementCta")}),t.jsx("button",{onClick:()=>{yt(F??""),Ee(!0)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 rounded-lg font-medium transition-colors",children:r("work:task.newTaskBtn")})]})]})]})}):Je==="backlog"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:l?vt.onTouchStart:void 0,onTouchEnd:l?vt.onTouchEnd:void 0,children:t.jsx(Gh,{tasks:or(Object.values(H).flat()),requirements:Zt,agents:J,projects:R,onTaskClick:w=>Ir(w),onReqClick:w=>Tr(w),onRefresh:()=>{nt(),Rt()},selectedTaskId:Ge?.id,selectedReqId:ze?.id})}):Je==="workflows"?t.jsx(Uh,{teamId:jl,projectId:F,agents:J,projects:R,onViewRunTasks:w=>{const U=ne=>{An(ne),ot(`req-${ne.id}`),ft("dag")},ee=se.find(ne=>ne.id===w);ee?U(ee):ae.requirements.get(w).then(ne=>{ne.requirement&&(me(he=>[...he,ne.requirement]),U(ne.requirement))}).catch(()=>{})}}):Je==="dag"?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:l?vt.onTouchStart:void 0,onTouchEnd:l?vt.onTouchEnd:void 0,children:[t.jsx(Ch,{tasks:(()=>{const w=or(Object.values(H).flat(),!0);if(n&&ze){const U=new Set(ze.taskIds??[]);return w.filter(ee=>U.has(ee.id))}return w})(),requirements:n&&ze?[ze]:Zt,agents:J,showArchived:Ne,onShowArchivedChange:Me,onTaskClick:w=>Ir(w),onReqClick:w=>Tr(w),onCollapseDAG:()=>{Ae(null),De(null),ot(null)},onDependencyChange:nt,selectedTaskId:Ge?.id,selectedReqId:ze?.id,hasDetailPanel:To,defaultExpandedNodeId:fn??(n&&ze?`req-${ze.id}`:void 0),previewMode:n}),l&&t.jsx("button",{onClick:()=>ft("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:ht,className:"flex-1 min-h-0 overflow-auto px-4 py-5",onTouchStart:l?pe.onTouchStart:void 0,onTouchEnd:l?pe.onTouchEnd:void 0,children:t.jsx("div",{className:"flex gap-3 items-stretch",children:$l.map(w=>{const U=jo(w),ee=No(w),ne=U.length+ee.length,he=St===w.id;return t.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col transition-colors ${he?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:je=>Rl(je,w.id),onDragLeave:je=>_l(je,w.id),onDrop:je=>{Ll(je,w.id)},children:[t.jsxs("div",{className:`flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30 sticky top-0 z-10 rounded-t-xl ${he?"bg-surface-elevated/60":"bg-surface-secondary/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${w.accent.replace("border-t-","bg-")}`}),t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:w.label})]}),t.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:ne})]}),t.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const je=[...ee.map(we=>({kind:"req",data:we,time:new Date(we.updatedAt??we.createdAt).getTime()})),...U.map(we=>({kind:"task",data:we,time:new Date(we.updatedAt??we.createdAt??0).getTime()}))];return je.sort((we,oe)=>oe.time-we.time),je.map(we=>{if(we.kind==="req"){const oe=we.data,Ue=c[oe.status]??{label:oe.status,cls:"bg-gray-500/15 text-fg-secondary"},mt=oe.source==="agent"&&oe.status==="pending",Oe=q==="all"&&oe.projectId?R.find(Re=>Re.id===oe.projectId):null,ke=Qn(oe.createdBy,J,ie)??oe.createdBy.slice(0,10),Ve=ze?.id===oe.id;return t.jsxs("div",{"data-work-item-id":oe.id,role:"button",tabIndex:0,draggable:!0,onDragStart:Re=>Tl(Re,oe),onDragEnd:wo,onClick:()=>Tr(oe),onKeyDown:Re=>Re.key==="Enter"&&Tr(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
9
+ `)}function Xh({req:e,tasks:n,agents:s,teamId:r,onClose:i,onSaved:o}){const{t:a}=We(["work"]),c=g.useMemo(()=>{const D={};for(const L of s)D[L.id]=L.name;return D},[s]),l=g.useMemo(()=>Kh(n,c),[n,c]),[d,h]=g.useState(()=>Ws(e.title)),[f,m]=g.useState(e.description||e.title),[u,p]=g.useState(l),[M,C]=g.useState(!1),[y,v]=g.useState(null),x=(D,L,E)=>{p(P=>P.map((z,j)=>j===D?{...z,[L]:E}:z))},b=D=>{const L=u[D]?.id;p(E=>E.filter((P,z)=>z!==D).map(P=>({...P,depends_on:P.depends_on.filter(z=>z!==L)})))},[k,N]=g.useState(!1),I=async()=>{if(d.trim()){C(!0),v(null);try{const D=Zh(d.trim(),f,u);await ae.workflows.create(r,d.trim(),D),N(!0),setTimeout(()=>o(),800)}catch(D){v(String(D))}C(!1)}},B=g.useMemo(()=>[...new Set(u.map(D=>D.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:D=>D.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:D=>h(D.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:B.map(D=>t.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:D},D))})]})]}),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:D=>m(D.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((D,L)=>t.jsx("div",{className:"bg-surface-secondary border border-border-default/40 rounded-xl p-3 group",children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500 mt-0.5",children:L+1}),t.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{value:D.name,onChange:E=>x(L,"name",E.target.value),className:"flex-1 text-sm font-medium bg-transparent border-b border-transparent hover:border-border-default focus:border-brand-500 text-fg-primary focus:outline-none px-0 py-0.5 transition-colors"}),t.jsx("input",{value:D.role,onChange:E=>x(L,"role",E.target.value),className:"w-28 text-[10px] bg-surface-elevated border border-border-default/40 rounded-md px-2 py-1 text-fg-secondary focus:outline-none focus:ring-1 focus:ring-brand-500",title:a("work:task.role","Role")})]}),D.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"),":"]}),D.depends_on.map(E=>{const P=u.find(z=>z.id===E);return t.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:P?.name??E},E)})]}),t.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:D.prompt})]}),t.jsx("button",{onClick:()=>b(L),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-quaternary hover:text-red-500 p-1 rounded transition-all",title:a("work:task.removeStep","Remove step"),children:t.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},D.id))})]}),y&&t.jsx("p",{className:"text-xs text-red-500",children:y}),k&&t.jsx("p",{className:"text-xs text-green-500 font-medium",children:a("work:task.workflowSavedSuccess","Workflow saved successfully")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default",children:[t.jsx("button",{onClick:i,className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated rounded-lg transition-colors",children:a("work:task.cancel","Cancel")}),t.jsx("button",{onClick:I,disabled:M||k||!d.trim()||u.length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm rounded-lg font-medium transition-colors",children:M?a("work:task.saving","Saving..."):k?a("work:task.workflowSavedSuccess","Saved!"):a("work:task.saveWorkflow","Save Workflow")})]})]})})}function Xa({teamId:e,agents:n,compact:s}){const{t:r}=We(["work"]),i=g.useMemo(()=>e?n.find(a=>a.teamId===e&&a.agentRole==="manager"):n.find(a=>a.agentRole==="manager"),[n,e]),o=()=>{i&&Bt.navigate(Fe.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 Uh({teamId:e,projectId:n,agents:s,projects:r,onViewRunTasks:i}){const{t:o}=We(["work"]),[a,c]=g.useState([]),[l,d]=g.useState({}),[h,f]=g.useState(!1),[m,u]=g.useState(null),[p,M]=g.useState({}),[C,y]=g.useState(!1),[v,x]=g.useState(null),[b,k]=g.useState([]),[N,I]=g.useState(null),[B,D]=g.useState(null),[L,E]=g.useState({}),[P,z]=g.useState(null),[j,O]=g.useState(null),[_,T]=g.useState(null),[R,A]=g.useState([]),[W,Y]=g.useState({}),[F,Q]=g.useState(null),[$,S]=g.useState({}),[V,q]=g.useState(new Set),H=e??N;g.useEffect(()=>{e||ae.teams.list().then(({teams:K})=>{k(K.map(ce=>({id:ce.id,name:ce.name})))}).catch(()=>{})},[e]),g.useMemo(()=>{const K={};for(const ce of s)K[ce.id]=ce.name;return K},[s]);const Z=g.useCallback(async()=>{const K=H?[H]:b.map(ce=>ce.id);if(K.length!==0){f(!0);try{const ce=[],ge={},ve={};await Promise.all(K.map(async fe=>{try{const{workflows:re}=await ae.workflows.list(fe);for(const xe of re)ve[xe.name]=fe;ce.push(...re),await Promise.all(re.map(async xe=>{try{const{runs:Ee}=await ae.workflows.listRuns(fe,xe.name,5);ge[xe.name]=Ee}catch{}}))}catch{}})),c(ce),d(ge),S(ve)}catch{}f(!1)}},[H,b]);g.useEffect(()=>{Z()},[Z]);const J=K=>H??$[K],le=async K=>{if(B===K.name){D(null);return}D(K.name);const ce=J(K.name);if(!L[K.name]&&ce)try{const{template:ge}=await ae.workflows.get(ce,K.name);E(ve=>({...ve,[K.name]:ge}))}catch{}},te=K=>{const ce={};for(const re of K.params??[])re.default&&(ce[re.name]=re.default);M(ce),x(null),A([]),Y({});const ge=localStorage.getItem(`markus_wf_project_${K.name}`)??localStorage.getItem("markus_wf_project_last"),ve=ge&&r.some(re=>re.id===ge)?ge:null;Q(n??ve??r[0]?.id??null),u(K);const fe=J(K.name);fe&&ae.workflows.roles(fe,K.name).then(({roles:re})=>A(re)).catch(()=>{})},X=async()=>{const K=F??r[0]?.id,ce=m?J(m.name):void 0;if(!m||!ce||!K){x(K?o("work:task.workflowNoTeam","Cannot determine team for this workflow"):o("work:task.workflowNoProject","Please select a project"));return}y(!0),x(null);try{let ge;if(R.length>0){ge={};for(const ve of R)ge[ve.role]=W[ve.role]??ve.recommended??""}await ae.workflows.startRun(ce,m.name,K,p,ge),localStorage.setItem(`markus_wf_project_${m.name}`,K),localStorage.setItem("markus_wf_project_last",K),u(null),Z()}catch(ge){x(String(ge))}y(!1)};if(!H&&b.length===0&&!e)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:o("work:task.selectProjectForWorkflows","Select a project with a team to view workflows")});if(h&&a.length===0)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:o("work:task.workflowLoading","Loading...")});const ie=async K=>{z(K),O(null);try{await ae.workflows.cancelRun(K),Z()}catch{}z(null)},de=async K=>{T(K.id);try{K.status==="running"?await ae.workflows.pauseRun(K.id):K.status==="paused"&&await ae.workflows.resumeRun(K.id),Z()}catch{}T(null)},se=K=>{K.requirementId&&i&&i(K.requirementId)},me=K=>{const ce={running:"bg-blue-500/20 text-blue-400",paused:"bg-amber-500/20 text-amber-400",completed:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",cancelled:"bg-gray-500/20 text-gray-400"};return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${ce[K]??"bg-gray-500/20 text-gray-400"}`,children:K})},ue=m&&(m.params??[]).some(K=>K.required&&!p[K.name]?.trim());return t.jsxs("div",{className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:[!e&&b.length>0&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-4",children:[t.jsx("button",{onClick:()=>{N!==null&&(I(null),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${N===null?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:o("work:task.all","All")}),b.map(K=>t.jsx("button",{onClick:()=>{N!==K.id&&(I(K.id),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${N===K.id?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:K.name},K.id))]}),a.length===0&&!h?t.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:t.jsx(Xa,{teamId:H,agents:s})}):t.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[a.map(K=>{const ce=B===K.name,ge=L[K.name],fe=(l[K.name]??[]).some(re=>re.status==="running"||re.status==="paused");return t.jsxs("div",{className:"bg-surface-secondary border border-border-default/50 rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2 cursor-pointer",onClick:()=>le(K),children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("svg",{className:`w-3.5 h-3.5 text-fg-tertiary shrink-0 transition-transform ${ce?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:K.displayName||K.name}),t.jsx("span",{className:"text-[11px] text-fg-tertiary",children:o("work:task.workflowStepsCount","{{count}} steps",{count:K.stepCount})})]})}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t.jsxs("span",{className:"text-[10px] text-fg-quaternary font-mono cursor-pointer hover:text-fg-tertiary transition-colors",title:o("work:task.workflowSendToAgent","Send to agent chat"),onClick:re=>{re.stopPropagation();const xe=J(K.name),ye=(xe?s.find(Ie=>Ie.teamId===xe&&Ie.agentRole==="manager"):void 0)?.id??s.find(Ie=>Ie.agentRole==="manager")?.id??s[0]?.id;ye&&Bt.navigate(Fe.TEAM,{agentId:ye,prefillMessage:`@[${K.displayName||K.name}](workflow:${K.name}) `})},children:[t.jsx("svg",{className:"w-3.5 h-3.5 inline mr-0.5 -mt-px",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),K.name]}),K.hasSchedule&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-500/20 text-purple-400",children:o("work:task.workflowScheduled","Scheduled")}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["v",K.version]}),fe?t.jsxs("span",{className:"px-3 py-1 bg-blue-500/20 text-blue-400 text-xs rounded-lg font-medium inline-flex items-center gap-1.5",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 animate-pulse"}),o("work:task.workflowRunning","Running")]}):t.jsx("button",{onClick:re=>{re.stopPropagation(),te(K)},className:"px-3 py-1 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:o("work:task.workflowRun","Run")})]})]}),ce&&ge&&t.jsxs("div",{className:"border-t border-border-default/30 pt-3 mt-1 ml-5 space-y-3",children:[K.description&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:K.description}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:o("work:task.workflowSteps","Steps")}),t.jsx("div",{className:"space-y-1.5",children:ge.steps.map((re,xe)=>t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"shrink-0 w-5 h-5 rounded-full bg-brand-500/15 flex items-center justify-center text-[9px] font-bold text-brand-500 mt-0.5",children:xe+1}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-medium text-fg-primary",children:re.name}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary",children:re.role}),re.depends_on&&re.depends_on.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["← ",re.depends_on.join(", ")]})]}),t.jsx("p",{className:"text-[10px] text-fg-tertiary line-clamp-1 mt-0.5",children:re.prompt})]})]},re.id))})]}),ge.steps.some(re=>re.depends_on&&re.depends_on.length>0)&&t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-1.5 uppercase tracking-wider",children:"DAG"}),t.jsx("div",{className:"flex items-center gap-1 flex-wrap text-[10px]",children:ge.steps.map((re,xe)=>{const Ee=re.depends_on&&re.depends_on.length>0;return t.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[Ee&&t.jsx("span",{className:"text-fg-quaternary",children:"→"}),t.jsx("span",{className:"px-1.5 py-0.5 rounded bg-surface-elevated text-fg-secondary font-medium",children:re.name})]},re.id)})})]}),ge.params&&ge.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:ge.params.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:ge.params.map(re=>t.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-[10px] rounded bg-surface-elevated border border-border-default/30",children:[t.jsx("span",{className:"font-medium text-fg-secondary",children:re.label||re.name}),t.jsxs("span",{className:"text-fg-quaternary",children:["(",re.type||"string",")"]}),re.required&&t.jsx("span",{className:"text-red-400",children:"*"})]},re.name))})]}),ge.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:[ge.schedule.cron&&`cron: ${ge.schedule.cron}`,ge.schedule.interval&&`every: ${ge.schedule.interval}`]})]})]}),(()=>{const re=l[K.name]??[];if(re.length===0)return null;const xe=V.has(K.name),Ee=xe?re:re.slice(0,1);return t.jsxs("div",{className:"border-t border-border-default/30 pt-2 mt-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 cursor-pointer select-none",onClick:()=>q(ye=>{const Ie=new Set(ye);return Ie.has(K.name)?Ie.delete(K.name):Ie.add(K.name),Ie}),children:[t.jsx("svg",{className:`w-3 h-3 text-fg-quaternary transition-transform ${xe?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium uppercase tracking-wider",children:o("work:task.workflowRecentRuns","Recent Runs")}),re.length>1&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["(",re.length,")"]})]}),t.jsx("div",{className:"space-y-1",children:Ee.map(ye=>t.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs px-2 py-1.5 rounded hover:bg-surface-elevated/50",children:[t.jsxs("span",{className:"text-fg-secondary font-medium",children:["#",ye.runNumber]}),me(ye.status),t.jsxs("span",{className:"text-fg-tertiary",children:[ye.taskIds.length," tasks"]}),t.jsx("span",{className:"text-fg-tertiary",children:new Date(ye.startedAt).toLocaleDateString()}),ye.triggeredBy==="schedule"&&t.jsx("span",{className:"text-[10px] text-purple-400",children:"auto"}),t.jsx("span",{className:"flex-1"}),(ye.status==="running"||ye.status==="paused")&&t.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),de(ye)},disabled:_===ye.id,className:`px-2.5 py-0.5 text-[10px] rounded-lg font-medium transition-colors ${ye.status==="running"?"bg-amber-500/20 text-amber-400 hover:bg-amber-500/30":"bg-green-500/20 text-green-400 hover:bg-green-500/30"}`,children:_===ye.id?"...":ye.status==="running"?o("work:task.workflowPause","Pause"):o("work:task.workflowResume","Resume")}),(ye.status==="running"||ye.status==="paused")&&t.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),O(ye.id)},className:"px-2.5 py-0.5 text-[10px] rounded-lg font-medium bg-red-500/20 text-red-400 hover:bg-red-500/30 transition-colors",children:o("work:task.workflowCancelRun","Cancel Run")}),t.jsx("button",{onClick:()=>se(ye),className:"px-2.5 py-0.5 text-[10px] rounded-lg font-medium bg-brand-500/20 text-brand-400 hover:bg-brand-500/30 transition-colors",children:o("work:task.workflowViewTasks","View Tasks")})]},ye.id))})]})})()]},K.name)}),t.jsx(Xa,{teamId:H,agents:s,compact:!0})]}),m&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>u(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-md shadow-2xl",onClick:K=>K.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-1",children:o("work:task.workflowRunTitle","Run: {{name}}",{name:m.displayName||m.name})}),t.jsx("p",{className:"text-xs text-fg-tertiary mb-4",children:m.description}),(m.params??[]).length>0&&t.jsx("div",{className:"space-y-3 mb-4",children:(m.params??[]).map(K=>t.jsxs("div",{children:[t.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[K.label||K.name,K.required&&t.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),K.type==="enum"&&K.options?t.jsxs("select",{value:p[K.name]??"",onChange:ce=>M(ge=>({...ge,[K.name]:ce.target.value})),className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:"—"}),K.options.map(ce=>t.jsx("option",{value:ce,children:ce},ce))]}):t.jsx("textarea",{value:p[K.name]??"",onChange:ce=>{M(fe=>({...fe,[K.name]:ce.target.value}));const ge=ce.target;ge.style.height="auto";const ve=parseFloat(getComputedStyle(ge).lineHeight)||18;ge.style.height=Math.min(ge.scrollHeight,ve*7)+"px"},placeholder:K.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},K.name))}),R.length>0&&t.jsxs("div",{className:"mb-4",children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:o("work:task.roles","Roles")}),t.jsx("div",{className:"space-y-2",children:R.map(K=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs text-fg-secondary w-24 shrink-0 font-medium",children:K.role}),t.jsx("select",{value:W[K.role]??K.recommended??"",onChange:ce=>Y(ge=>({...ge,[K.role]:ce.target.value})),className:"input-field text-xs flex-1",children:K.candidates.map(ce=>t.jsxs("option",{value:ce.agentId,children:[ce.agentName,ce.agentId===K.recommended?" ★":""]},ce.agentId))})]},K.role))})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1",children:o("work:task.workflowProject","Project")}),t.jsxs("select",{value:F??"",onChange:K=>{const ce=K.target.value||null;Q(ce),x(null),ce&&localStorage.setItem("markus_wf_project_last",ce)},className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:o("work:task.workflowSelectProject","— Select a project —")}),r.map(K=>t.jsx("option",{value:K.id,children:K.name},K.id))]})]}),v&&t.jsx("p",{className:"text-xs text-red-400 mb-3",children:v}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>u(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowCancel","Cancel")}),t.jsx("button",{onClick:X,disabled:C||!!ue,className:"btn-primary text-xs px-4 py-1.5",children:C?o("work:task.workflowStarting","Starting..."):o("work:task.workflowStartRun","Start Run")})]})]})}),j&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>O(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:K=>K.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-2",children:o("work:task.workflowConfirmCancelTitle","Cancel Workflow Run")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-5",children:o("work:task.workflowConfirmCancelDesc","This will cancel all running and pending tasks in this workflow run. This action cannot be undone.")}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>O(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowNo","No")}),t.jsx("button",{onClick:()=>ie(j),disabled:P===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:P===j?o("work:task.workflowCancelling","Cancelling..."):o("work:task.workflowConfirmCancelBtn","Confirm Cancel")})]})]})})]})}function sm({authUser:e,previewMode:n,previewData:s}={}){const{t:r}=We(["work","common"]),i=Fl(Fe.WORK),o=g.useMemo(()=>ss.map(w=>({...w,label:r(`work:boardColumn.${w.id}`)})),[r]),a=g.useMemo(()=>yl(r),[r]),c=g.useMemo(()=>io(r),[r]),l=vr(),d=Yl(),h=d?.leftCollapsed??!1,f=g.useRef(null),[m,u]=g.useState(0);g.useEffect(()=>{const w=f.current;if(!w)return;const U=new ResizeObserver(([ee])=>u(ee.contentRect.width));return U.observe(w),u(w.clientWidth),()=>U.disconnect()},[]);const[p,M]=g.useState(()=>{if(n)return!1;try{return localStorage.getItem(Aa)==="1"}catch{return!1}}),C=g.useCallback(w=>{M(w);try{localStorage.setItem(Aa,w?"1":"0")}catch{}},[]),y=g.useRef(h);g.useEffect(()=>{n||l||y.current!==h&&(y.current=h,M(h))},[h,n,l]);const v=Gl({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),x=6,b=!l&&!p?v.width+x:0,k=Math.max(0,(m||window.innerWidth)-b-x-8),N=Math.max(320,Math.round(k/2)),[I,B]=g.useState("auto"),D=Math.max(320,k-280),L=I==="auto"?Math.min(N,D):I,E=Math.max(320,Math.min(L,D)),P=g.useRef(E);P.current=E;const z=g.useRef(D);z.current=D;const j=g.useCallback(w=>{w.preventDefault();const U=w.clientX,ee=P.current,ne=je=>{const we=Math.max(320,Math.min(z.current,ee+(U-je.clientX)));B(we)},he=()=>{document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",he),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ne),document.addEventListener("mouseup",he),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[O,_]=g.useState(!1),T=g.useRef(O);T.current=O;const[R,A]=g.useState(s?.projects??[]),[W,Y]=g.useState("all"),[F,Q]=g.useState(null),[$,S]=g.useState("closed"),[V,q]=g.useState("projects"),[H,Z]=g.useState(s?.board??{}),[J,le]=g.useState(s?.agents??[]),[te,X]=g.useState([]),[ie,de]=g.useState(s?.users??[]),[se,me]=g.useState(s?.allRequirements??[]),[ue,K]=g.useState(!s),[ce,ge]=g.useState(""),ve=g.useCallback(()=>{Cr(F??""),hn(!0)},[F]),[fe,re]=g.useState(!1),[xe,Ee]=g.useState(!1),[ye,Ie]=g.useState(""),[pt,rt]=g.useState(""),[Nt,Ct]=g.useState("medium"),[st,Ht]=g.useState(""),[xt,Jt]=g.useState(""),[bt,yt]=g.useState(""),[Ce,Xe]=g.useState(""),[$e,Le]=g.useState([]),[et,qt]=g.useState("standard"),[Wt,_e]=g.useState("4h"),[Ye,tt]=g.useState(""),[un,Mn]=g.useState(!1),[Ge,Ae]=g.useState(null),[ze,De]=g.useState(()=>s?.initialSelectedReqId&&s.allRequirements?s.allRequirements.find(w=>w.id===s.initialSelectedReqId)??null:null);g.useEffect(()=>{s?.initialSelectedReqId&&ze&&S("item")},[]);const[He,dt]=g.useState(new Set),[Qe,it]=g.useState(!1),[ut,en]=g.useState(new Set),Vt=g.useRef(new Set),[St,Et]=g.useState(null),[Je,ft]=g.useState(s?.initialBoardType??"backlog"),[fn,ot]=g.useState(null),$t=g.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"},{id:"workflows"}],[]),vt=_s($t,Je,ft),ht=g.useRef(null),G=g.useMemo(()=>({scrollContainerRef:ht}),[]),pe=_s($t,Je,ft,G),[Ne,Me]=g.useState(!1),[Se,lt]=g.useState(null),[Ft,Mt]=g.useState(!1),tn=g.useRef(null),In=g.useRef(null),[Jn,hn]=g.useState(!1),[mn,gn]=g.useState(""),[Tn,pn]=g.useState(""),[er,hs]=g.useState("medium"),[xn,Cr]=g.useState(""),[nn,It]=g.useState(null),[Sr,Er]=g.useState(""),[tr,rn]=g.useState(""),[ms,lo]=g.useState(!1),[co,Rn]=g.useState(""),ct=w=>{ge(w),setTimeout(()=>ge(""),3e3)};g.useEffect(()=>{const w=U=>{U.key==="Escape"&&(nn?(It(null),Rn("")):xe?(Ee(!1),tt("")):Jn?(hn(!1),gn(""),pn(""),rn("")):Ft?Mt(!1):$!=="closed"&&(S("closed"),Ae(null),De(null),l&&T.current&&_(!1)))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[nn,xe,Jn,Ft,$,l]);const wt=R.find(w=>w.id===F)??null,jl=wt?.teamIds?.[0]??null,Tt=g.useMemo(()=>R.filter(w=>w.status!=="archived"),[R]),uo=g.useCallback(()=>{F&&(Ae(null),De(null),S("project"),B("auto"),l&&_(!0))},[F,l]),Mr=g.useCallback(()=>{if($==="project"){S("closed"),l&&_(!1);return}uo()},[$,uo,l]);g.useEffect(()=>{Vt.current=ut},[ut]);const bn=g.useCallback(async()=>{try{const{projects:w}=await ae.projects.list();A(w)}catch{}},[]),nt=g.useCallback(async()=>{const w={};W==="project"&&F&&(w.projectId=F);try{const{board:U}=await ae.tasks.board(w);Z(U)}catch{}},[W,F]),nr=g.useCallback(async()=>{try{const{agents:w}=await ae.agents.list();le(w)}catch{}},[]),fo=g.useCallback(async()=>{try{const{teams:w}=await ae.teams.list();X(w.map(U=>({id:U.id,name:U.name})))}catch{}},[]),ho=g.useCallback(async()=>{try{const{users:w}=await ae.users.list(e?.orgId);de(w)}catch{}},[e?.orgId]),Rt=g.useCallback(async()=>{try{const{requirements:w}=await ae.requirements.list({});me(w)}catch{}},[]),mo=g.useCallback(async()=>{await Promise.all([bn(),nt(),nr(),ho(),Rt(),fo()]),K(!1)},[bn,nt,nr,ho,Rt,fo]);g.useEffect(()=>{n||mo()},[n,mo]),g.useEffect(()=>{!n||!s||(A(s.projects??[]),Z(s.board??{}),le(s.agents??[]),de(s.users??[]),me(s.allRequirements??[]))},[n,s]);const Ir=g.useCallback(w=>{q("items"),Ae(U=>U?.id===w.id&&$==="item"?(S("closed"),l&&T.current&&_(!1),null):(S("item"),B("auto"),l&&(_(!0),history.pushState({mobileDetail:Fe.WORK},"",window.location.hash)),w)),De(null)},[l,$]),Tr=g.useCallback(w=>{q("items"),De(U=>U?.id===w.id&&$==="item"?(S("closed"),l&&T.current&&_(!1),null):(S("item"),B("auto"),l&&(_(!0),history.pushState({mobileDetail:Fe.WORK},"",window.location.hash)),w)),Ae(null)},[l,$]),yn=g.useCallback(()=>{Ae(null),De(null),S("closed"),l&&T.current&&_(!1)},[l]),Yt=g.useRef(Ge);Yt.current=Ge;const Gt=g.useRef(ze);Gt.current=ze;const vn=g.useRef($);vn.current=$;const _n=g.useRef(V);_n.current=V;const Ln=g.useRef(p);Ln.current=p;const gs=g.useRef(Je);gs.current=Je;const Nl=g.useCallback(()=>{Ae(null),Gt.current||(S("closed"),l&&T.current&&_(!1))},[l]);g.useEffect(()=>{if(!l)return;const w=()=>{T.current&&(_(!1),Ae(null),De(null),S("closed"))};return window.addEventListener("popstate",w),()=>window.removeEventListener("popstate",w)},[l]),g.useEffect(()=>{if(n||!i)return;nt(),nr(),Rt();const w=Yt.current?12e4:45e3,U=setInterval(()=>{nt(),nr(),Rt()},w);let ee=null;const ne=()=>{ee||(ee=setTimeout(()=>{ee=null,nt()},800))};let he=null;const je=()=>{he||(he=setTimeout(()=>{he=null,Rt()},800))},we=jt.on("task:update",Oe=>{_t("/taskboard"),ne();const ke=Oe?.payload;ke?.taskId&&(Ae(Ve=>{if(!Ve||Ve.id!==ke.taskId)return Ve;const Re={};return typeof ke.status=="string"&&(Re.status=ke.status),Array.isArray(ke.deliverables)&&(Re.deliverables=ke.deliverables),Array.isArray(ke.notes)&&(Re.notes=ke.notes),ke.result!==void 0&&(Re.result=ke.result),{...Ve,...Re}}),Yt.current?.id===ke.taskId&&(_t("/tasks/"+ke.taskId),ae.tasks.get(ke.taskId).then(Ve=>{Ve.task&&Ae(Re=>Re?.id===Ve.task.id?Ve.task:Re)}).catch(()=>{})))}),oe=jt.on("task:create",()=>{ne()}),kt=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(Oe=>jt.on(Oe,ke=>{_t("/requirements"),je();const Ve=ke?.payload,Re=Ve?.id??Ve?.requirementId;Re&&Gt.current?.id===Re&&(_t("/requirements/"+Re),ae.requirements.get(Re).then(Xt=>{Xt.requirement&&De(jn=>jn?.id===Xt.requirement.id?Xt.requirement:jn)}).catch(()=>{}))})),mt=()=>{_t("/taskboard"),_t("/tasks"),_t("/requirements"),nt(),Rt(),Yt.current&&ae.tasks.get(Yt.current.id).then(Oe=>{Oe.task&&Ae(ke=>ke?.id===Oe.task.id?Oe.task:ke)}).catch(()=>{}),Gt.current&&ae.requirements.get(Gt.current.id).then(Oe=>{Oe.requirement&&De(ke=>ke?.id===Oe.requirement.id?Oe.requirement:ke)}).catch(()=>{})};return window.addEventListener("markus:data-changed",mt),()=>{clearInterval(U),we(),oe(),kt.forEach(Oe=>Oe()),window.removeEventListener("markus:data-changed",mt),ee&&clearTimeout(ee),he&&clearTimeout(he)}},[n,i,nt,nr,Rt]);const go=g.useRef(H);go.current=H;const po=g.useRef(se);po.current=se,g.useEffect(()=>{const w=Yt.current;if(!w)return;const ee=Object.values(H).flat().find(ne=>ne.id===w.id);ee&&ee.updatedAt!==w.updatedAt&&Ae(ee)},[H]),g.useEffect(()=>{const w=Gt.current;if(!w)return;const U=se.find(ee=>ee.id===w.id);U&&U.updatedAt!==w.updatedAt&&De(U)},[se]);const sn=g.useCallback(w=>{w&&(Q(w),Y("project"),en(new Set),history.replaceState(null,"",ys(Fe.WORK,w)))},[]),[ps,rr]=g.useState(!1),sr=g.useCallback((w,U)=>{Ae(w),De(null),S("item"),q("items"),B("auto"),U?.scrollToComments&&rr(!0),l&&_(!0)},[l]),An=g.useCallback((w,U)=>{De(w),Ae(null),S("item"),q("items"),B("auto"),U?.scrollToComments&&rr(!0),l&&_(!0)},[l]),Dn=g.useRef(null);g.useEffect(()=>{const w=Dn.current||localStorage.getItem("markus_nav_openTask");if(!w)return;const ee=Object.values(H).flat().find(ne=>ne.id===w);ee?(Dn.current=null,sn(ee.projectId),sr(ee),localStorage.removeItem("markus_nav_openTask")):Dn.current||(Dn.current=w,localStorage.removeItem("markus_nav_openTask"),ae.tasks.get(w).then(ne=>{ne.task&&(Dn.current=null,sn(ne.task.projectId),sr(ne.task))}).catch(()=>{Dn.current=null}))},[H,sr,sn]);const Pn=g.useRef(null);g.useEffect(()=>{const w=Pn.current||localStorage.getItem("markus_nav_openRequirement");if(!w)return;const U=se.find(ee=>ee.id===w);U?(Pn.current=null,sn(U.projectId),An(U),localStorage.removeItem("markus_nav_openRequirement")):Pn.current||(Pn.current=w,localStorage.removeItem("markus_nav_openRequirement"),ae.requirements.get(w).then(ee=>{ee.requirement&&(Pn.current=null,sn(ee.requirement.projectId),An(ee.requirement))}).catch(()=>{Pn.current=null}))},[se,An,sn]);const Ot=g.useCallback((w,U)=>{en(new Set),Q(w),Y("project"),q(p?"items":"projects"),U?.keepItemDetail||(Ae(null),De(null),S(ee=>ee==="closed"?ee:"project")),history.replaceState(null,"",ys(Fe.WORK,w))},[p]),Kt=g.useCallback(w=>{en(new Set),Q(null),Y("all"),q(p?"items":"projects"),w?.keepItemDetail||(Ae(null),De(null),S(U=>U==="closed"?U:U==="project"?"closed":"empty")),history.replaceState(null,"",ys(Fe.WORK))},[p]),wn=g.useRef(!1);g.useEffect(()=>{if(wn.current)return;const w=window.location.hash.slice(1).split("/");if(Br(w[0])===Fe.WORK&&w[1]){wn.current=!0,Ot(w[1],{keepItemDetail:!0});return}const U=localStorage.getItem("markus_nav_projectId");if(U){wn.current=!0,localStorage.removeItem("markus_nav_projectId"),Ot(U,{keepItemDetail:!0});return}wn.current=!0,Kt({keepItemDetail:!0})},[]),g.useEffect(()=>{if(!ue){if(!F){wn.current=!0,W!=="all"&&Y("all");return}if(Tt.some(w=>w.id===F)){wn.current=!0;return}wn.current=!0,Kt({keepItemDetail:!0})}},[ue,Tt,F,Kt,W]);const Cl=g.useRef(Br(window.location.hash.slice(1).split("/")[0]));g.useEffect(()=>{if(n)return;const w=()=>{const ee=window.location.hash.slice(1).split("/"),ne=Br(ee[0]);Cl.current=ne,ne===Fe.WORK&&(ee[1]?Ot(ee[1],{keepItemDetail:!0}):Kt({keepItemDetail:!0}))},U=async ee=>{const ne=ee.detail;if(Br(ne.page)===Fe.WORK){if(ne.params?.openTask){const he=ne.params.openTask,je=ne.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let we=Object.values(go.current).flat().find(oe=>oe.id===he);if(!we)try{we=(await ae.tasks.get(he)).task}catch{}we&&(sn(we.projectId),sr(we,{scrollToComments:je}))}if(ne.params?.openRequirement){const he=ne.params.openRequirement,je=ne.params.scrollToComments==="true";let we=po.current.find(oe=>oe.id===he);if(!we)try{we=(await ae.requirements.get(he)).requirement}catch{}we&&(sn(we.projectId),An(we,{scrollToComments:je}))}if(ne.params?.projectId&&Ot(ne.params.projectId),ne.params?.statusFilter){const he=ne.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),$h.has(he)&&Me(!0),lt(he)}}};return window.addEventListener("markus:navigate",U),window.addEventListener("hashchange",w),()=>{window.removeEventListener("markus:navigate",U),window.removeEventListener("hashchange",w)}},[n]);const Sl=w=>{re(!1),ct(r("work:task.projectCreated")),A(U=>U.some(ee=>ee.id===w.id)?U:[...U,w]),Ot(w.id),bn()},El=async w=>{try{await ae.projects.delete(w),F===w&&Kt(),ct(r("work:task.projectDeleted")),bn(),nt()}catch(U){ct(r("work:task.errorGeneric",{message:String(U)}))}},xo=async()=>{if(!ye||!st||!xt||un)return;tt("");const w=xt.startsWith("human:"),U=xt.replace(/^(human|agent):/,"");if(st===U&&!w){ct(r("work:task.assignedReviewerDifferent"));return}const ee=bt||void 0,ne=Ce||void 0;Mn(!0);try{const{task:he}=await ae.tasks.create(ye,pt,st,U,Nt,ee,$e.length>0?$e:void 0,ne,et!=="standard"?et:void 0,et==="scheduled"?{every:Wt}:void 0,w?"human":"agent");Ie(""),rt(""),Le([]),Xe(""),qt("standard"),_e("4h"),Ee(!1),nt(),he&&sr(he)}catch(he){const we=`work:task.errorCode_${(he instanceof Xl?he.code:void 0)||"unknown"}`,oe=r(we,{defaultValue:""});tt(oe||r("work:task.errorCreatingTask",{message:he instanceof Error?he.message:String(he)}))}finally{Mn(!1)}},$n=w=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:w}))},bo=()=>{_t("/taskboard"),nt(),Ge&&($n({taskId:Ge.id}),_t("/tasks/"+Ge.id),ae.tasks.get(Ge.id).then(w=>{w.task&&Ae(U=>U?.id===w.task.id?w.task:U)}).catch(()=>{}))},kn=()=>{_t("/requirements"),Rt(),ze&&(_t("/requirements/"+ze.id),ae.requirements.get(ze.id).then(w=>{w.requirement&&De(U=>U?.id===w.requirement.id?w.requirement:U)}).catch(()=>{}))},yo=async()=>{if(!ms){if(!mn.trim()){rn(r("work:task.pleaseReqTitle"));return}if(!Tn.trim()){rn(r("work:task.pleaseReqDesc"));return}if(!xn){rn(r("work:task.pleaseReqProject"));return}rn(""),lo(!0);try{const{requirement:w}=await ae.requirements.create({title:mn.trim(),description:Tn.trim(),priority:er,projectId:xn});ct(r("work:task.requirementCreated")),gn(""),pn(""),hn(!1),Rt(),w&&An(w)}catch(w){rn(w instanceof Error?w.message:String(w))}finally{lo(!1)}}},xs=async w=>{try{await ae.requirements.approve(w),ct(r("work:task.requirementApproved")),$n({requirementId:w}),kn(),nt()}catch(U){ct(r("work:task.errorGeneric",{message:String(U)}))}},Ml=async()=>{if(nn){Rn("");try{await ae.requirements.reject(nn,Sr),ct(r("work:task.requirementRejected")),$n({requirementId:nn}),It(null),Er(""),Rn(""),kn()}catch(w){Rn(w instanceof Error?w.message:String(w))}}},vo=async w=>{try{await ae.requirements.cancel(w),ct(r("work:task.requirementCancelled")),$n({requirementId:w}),kn()}catch(U){ct(r("work:task.errorGeneric",{message:String(U)}))}},Il=(w,U)=>{tn.current=U,In.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`task:${U.id}`),w.currentTarget.style.opacity="0.4"},Tl=(w,U)=>{In.current=U,tn.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`req:${U.id}`),w.currentTarget.style.opacity="0.4"},wo=w=>{w.currentTarget.style.opacity="1",tn.current=null,In.current=null,Et(null)},Rl=(w,U)=>{w.preventDefault(),w.dataTransfer.dropEffect="move",St!==U&&Et(U)},_l=(w,U)=>{const ee=w.currentTarget.getBoundingClientRect(),{clientX:ne,clientY:he}=w;(ne<ee.left||ne>ee.right||he<ee.top||he>ee.bottom)&&St===U&&Et(null)},Ll=async(w,U)=>{w.preventDefault(),Et(null);const ee=tn.current,ne=In.current;if(ee){const he=o.find(we=>we.id===U);if(!he)return;const je=he.dropStatus;if(ee.status===je||ee.status==="pending")return;try{await ae.tasks.updateStatus(ee.id,je),nt()}catch{}}else if(ne){const he=vl[U];if(!he||ne.status===he)return;try{await ae.requirements.updateStatus(ne.id,he),Rt()}catch{}}},ko=w=>{dt(U=>{const ee=new Set(U);return ee.has(w)?ee.delete(w):ee.add(w),ee})},Rr=w=>{Ot(w)},Al=new Set(["rejected","cancelled","archived"]),_r=w=>Al.has(w.status),or=(w,U=!1)=>{let ee=w.filter(ne=>Ne||!_r(ne));return Se&&(ee=ee.filter(ne=>ne.status===Se)),W==="project"&&F&&(ee=ee.filter(ne=>ne.projectId===F)),ut.size>0&&(ee=ee.filter(ne=>ne.projectId&&ut.has(ne.projectId))),He.size>0&&(ee=ee.filter(ne=>ne.assignedAgentId&&He.has(ne.assignedAgentId))),Qe&&e?.id&&(ee=ee.filter(ne=>ne.createdBy===e.id)),ee},Dl=g.useMemo(()=>{const w=new Map;for(const U of Object.values(H))for(const ee of U)w.set(ee.id,ee);return w},[H]),Pl=g.useMemo(()=>new Set(J.map(w=>w.id)),[J]),jo=w=>w.statuses.flatMap(U=>or(H[U]??[])),Zt=g.useMemo(()=>{let w=se;return Ne||(w=w.filter(U=>!_r(U))),W==="project"&&F&&(w=w.filter(U=>U.projectId===F)),ut.size>0&&(w=w.filter(U=>U.projectId&&ut.has(U.projectId))),He.size>0&&(w=w.filter(U=>He.has(U.createdBy))),Qe&&e?.id&&(w=w.filter(U=>U.createdBy===e.id)),w},[se,Ne,W,F,ut,He,Qe,e?.id,Pl]),No=g.useCallback(w=>Zt.filter(U=>Jr[U.status]===w.id),[Zt]),$l=o.filter(w=>{if(w.id==="failed"||w.id==="closed"){const U=jo(w),ee=No(w);return U.length+ee.length>0}return!0}),ar=Object.values(H).flat().filter(w=>_r(w)).length+se.filter(w=>_r(w)).length,Co=g.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),U=Object.values(H).flat(),ee=new Set;for(const ne of U)ne.assignedAgentId&&!w.has(ne.status)&&(!F||ne.projectId===F)&&ee.add(ne.assignedAgentId);return[...J].sort((ne,he)=>{const je=ee.has(ne.id)?0:1,we=ee.has(he.id)?0:1;return je-we})},[J,H,F]),Lr=g.useMemo(()=>{const w=new Map,U=[];for(const ne of Co)if(ne.teamId){const he=w.get(ne.teamId)??[];he.push(ne.id),w.set(ne.teamId,he)}else U.push(ne);const ee=[];for(const ne of U)ee.push({kind:"agent",agent:ne});for(const ne of te){const he=w.get(ne.id);he&&he.length>0&&ee.push({kind:"team",id:ne.id,name:ne.name,agentIds:he})}return ee},[Co,te]);g.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),U=Object.values(H).flat(),ee=new Set;for(const he of U)he.projectId&&!w.has(he.status)&&ee.add(he.projectId);return[...Ne?R:R.filter(he=>he.status!=="archived")].sort((he,je)=>{const we=he.status==="archived"?1:0,oe=je.status==="archived"?1:0;if(we!==oe)return we-oe;const Ue=ee.has(he.id)?0:1,kt=ee.has(je.id)?0:1;return Ue!==kt?Ue-kt:he.name.localeCompare(je.name)})},[R,H,Ne]);const Ar=g.useMemo(()=>{const w={};for(const U of Object.values(H))for(const ee of U){const ne=ee.projectId??"__none__";w[ne]=(w[ne]??0)+1}return w},[H]),Dr=Object.values(Ar).reduce((w,U)=>w+U,0),Ol=F?Ar[F]??0:Dr,So=g.useMemo(()=>{const w=or(Object.values(H).flat()),U=[];if(Je==="kanban"){for(const ne of ss){const he=ne.statuses.flatMap(oe=>w.filter(Ue=>Ue.status===oe)),we=[...Zt.filter(oe=>Jr[oe.status]===ne.id).map(oe=>({kind:"req",data:oe,time:new Date(oe.updatedAt??oe.createdAt).getTime()})),...he.map(oe=>({kind:"task",data:oe,time:new Date(oe.updatedAt??oe.createdAt??0).getTime()}))];we.sort((oe,Ue)=>Ue.time-oe.time);for(const oe of we)oe.kind==="req"?U.push({kind:"req",data:oe.data}):U.push({kind:"task",data:oe.data})}return U}const ee=[];for(const ne of w){const he=wl(ne.status);ee.push({kind:"task",data:ne,groupOrder:os[he]??5,time:new Date(ne.updatedAt??ne.createdAt??0).getTime()})}for(const ne of Zt){const he=Jr[ne.status]??"todo";ee.push({kind:"req",data:ne,groupOrder:os[he]??5,time:new Date(ne.updatedAt??ne.createdAt).getTime()})}return ee.sort((ne,he)=>ne.groupOrder!==he.groupOrder?ne.groupOrder-he.groupOrder:he.time-ne.time),ee.map(ne=>ne.kind==="req"?{kind:"req",data:ne.data}:{kind:"task",data:ne.data})},[H,Zt,Je,Ne,Se,F,ut,He,Qe,e?.id,W]),Pr=g.useRef(So);Pr.current=So;const Eo=g.useRef(Tt);Eo.current=Tt;const bs=g.useRef(F);bs.current=F;const On=g.useCallback(w=>{w.kind==="req"?(De(w.data),Ae(null)):(Ae(w.data),De(null)),S("item"),B("auto"),q("items")},[]),Mo=g.useCallback(()=>{if(vn.current==="item"||vn.current==="empty"){S("closed"),Ae(null),De(null);return}if(Yt.current||Gt.current){S("item"),B("auto"),q("items");return}const w=Pr.current;if(w.length>0){On(w[0]);return}Ae(null),De(null),S("empty"),B("auto")},[On]);g.useEffect(()=>{if(!l)if(p){if(q("items"),vn.current==="project")if(Yt.current||Gt.current)S("item");else{const w=Pr.current;w.length>0?On(w[0]):S("closed")}}else _n.current==="items"&&vn.current==="closed"||!p&&vn.current==="closed"&&q("projects")},[p,l,On]);const ir=d?.keyboardPane??"content",Io=g.useRef(ir);if(g.useEffect(()=>{if(n||l||!i)return;const w=Io.current;Io.current=ir,ir==="l1"&&(q("projects"),w!=="l1"&&Ln.current&&(C(!1),d?.setLeftCollapsed(!1)))},[ir,n,l,i,C,d]),g.useEffect(()=>{if(n||l||!i)return;const w=navigator.platform.toUpperCase().includes("MAC"),U=ee=>{if(d?.keyboardPane==="l0")return;const ne=w?ee.metaKey&&!ee.ctrlKey:ee.ctrlKey&&!ee.metaKey;if(ee.ctrlKey&&!ee.metaKey&&ee.key==="Tab"){ee.preventDefault();const ke=Mh,Ve=ke.indexOf(gs.current),Re=ee.shiftKey?ke[(Ve-1+ke.length)%ke.length]:ke[(Ve+1)%ke.length];ft(Re);return}if(ne&&!ee.altKey&&!ee.shiftKey){const ke=ee.key.toLowerCase();if(ke==="j"){ee.preventDefault(),Mr();return}if(ke==="l"){ee.preventDefault(),Mo();return}}if(ne||ee.altKey||ee.ctrlKey||ee.metaKey||Zl(ee.target))return;const he=ee.key.length===1?ee.key.toLowerCase():ee.key;if(he==="h"||he==="ArrowLeft"){if(Ln.current){ee.preventDefault(),C(!1),d?.setLeftCollapsed(!1),q("projects"),d?.setKeyboardPane("l1");return}if(_n.current==="items"){ee.preventDefault(),q("projects"),d?.setKeyboardPane("l1");return}ee.preventDefault(),d?.setL0FocusPageId(Fe.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((he==="l"||he==="ArrowRight"||he==="Tab"&&!ee.shiftKey)&&!Ln.current&&_n.current==="projects"){ee.preventDefault(),q("items"),d?.setKeyboardPane("content");return}if((he==="l"||he==="ArrowRight")&&(Ln.current||_n.current==="items")){ee.preventDefault();return}const je=he==="j"||he==="ArrowDown"?1:he==="k"||he==="ArrowUp"?-1:0;if(!je)return;if((Ln.current?"items":_n.current)==="projects"){ee.preventDefault(),d?.setKeyboardPane("l1");const ke=Eo.current,Ve=ke.length+1;if(ke.length===0)return;const Re=bs.current==null?0:ke.findIndex(Bn=>Bn.id===bs.current)+1,Xt=Re<0?0:Re,jn=Math.max(0,Math.min(Ve-1,Xt+je));if(jn===0)Kt(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const Bn=ke[jn-1];Ot(Bn.id),vn.current!=="closed"&&(S("project"),Ae(null),De(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${Bn.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const oe=gs.current;if(oe!=="backlog"&&oe!=="kanban")return;ee.preventDefault(),d?.setKeyboardPane("content");const Ue=Pr.current;if(Ue.length===0){S(ke=>ke==="closed"?"empty":ke);return}const kt=Yt.current?.id??Gt.current?.id??null;let mt=kt?Ue.findIndex(ke=>ke.data.id===kt):-1;mt<0&&(mt=je>0?-1:0);const Oe=Math.max(0,Math.min(Ue.length-1,mt+je));On(Ue[Oe]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${Ue[Oe].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",U,!0),()=>document.removeEventListener("keydown",U,!0)},[n,l,i,Mr,Mo,Ot,Kt,On,C,d]),ue)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:r("work:task.loadingPage")});const To=$!=="closed"||!!(Ge||ze),$r=!l&&!!(Ge&&ze)&&$==="item",Ro=l?O:To;return t.jsxs("div",{ref:f,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!l&&t.jsx(Eh,{projects:Tt,selectedProjectId:F,allSelected:W==="all"&&!F,taskCounts:Ar,totalTaskCount:Dr,onSelectAll:()=>{Kt(),q("projects")},onSelectProject:w=>{Ot(w),q("projects")},onCreateProject:()=>re(!0),onCollapse:()=>{const w=!p;C(w),d?.setLeftCollapsed(w)},width:v.width,onResizeStart:v.onResizeStart,hidden:p,focused:ir==="l1"&&V==="projects"&&!p,onActivate:()=>q("projects")}),t.jsxs("div",{"data-keyboard-pane":"content",onPointerDown:()=>q("items"),className:`${l?"flex-1 min-w-0":$r?"w-0 shrink-0 overflow-hidden":"flex-1 min-w-0"} overflow-hidden flex flex-col bg-surface-primary`,style:l&&O?{display:"none"}:void 0,children:[ce&&t.jsx("div",{className:"mx-6 mt-2 px-3 py-1.5 bg-green-500/15 text-green-600 text-xs rounded-lg",children:ce}),l?t.jsxs("div",{className:"shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[t.jsx(Kl,{}),wt?t.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[t.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:wt.name}),t.jsx("button",{onClick:Mr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${$==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:r("work:task.projectsCount",{count:Tt.length})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>re(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortProject")}),t.jsx("button",{onClick:ve,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortReq")}),t.jsx("button",{onClick:()=>{yt(F??""),Ee(!0)},className:"px-2 py-1 text-[11px] border border-amber-500/60 text-amber-600 rounded-md",children:r("work:task.shortTask")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 px-3 h-9",children:[t.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(w=>t.jsx("button",{onClick:()=>ft(w),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${Je===w?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:r(w==="backlog"?"work:task.backlog":w==="kanban"?"work:task.kanban":"work:task.dag")},w))}),ar>0&&t.jsx("button",{onClick:()=>Me(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ne?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Ne?r("work:task.hideArchived"):r("work:task.archivedCount",{count:ar})}),t.jsx("div",{className:"flex-1"}),Se&&t.jsxs("button",{onClick:()=>lt(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.${Se==="in_progress"?"inProgress":Se}`),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"})]})]}),(Tt.length>1||J.length>0||e?.id)&&t.jsxs("button",{onClick:()=>Mt(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${He.size>0||Qe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),He.size+(Qe?1:0)>0?r("work:task.filterWithCount",{count:He.size+(Qe?1:0)}):r("work:task.filter")]})]})]}):t.jsxs("div",{"data-electron-drag":!0,className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[t.jsx("button",{"data-no-drag":!0,type:"button",onClick:()=>{const w=!p;C(w),d?.setLeftCollapsed(w),q("projects")},className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors shrink-0 ${p?"bg-brand-500/15 text-brand-500 hover:bg-brand-500/25":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,title:r(p?"work:task.expand":"work:task.collapse"),children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),wt?t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[t.jsx(Rh,{value:wt.name,onSave:async w=>{await ae.projects.update(wt.id,{name:w}),bn()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:Mr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${$==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:`${r("work:project.settingsTitle")} (⌘J)`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:r("work:task.projectsCount",{count:Tt.length})}),ar>0&&t.jsx("button",{onClick:()=>Me(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Ne?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Ne?r("work:task.hideArchivedWithCount",{count:ar}):r("work:task.archivedCount",{count:ar})}),t.jsx("div",{"data-no-drag":!0,className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(w=>t.jsx("button",{onClick:()=>ft(w),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Je===w?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:w==="backlog"?r("work:task.backlog"):w==="kanban"?r("work:task.kanban"):w==="dag"?r("work:task.dag"):r("work:task.workflows","Workflows")},w))}),t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1.5 shrink-0",children:[t.jsx("button",{onClick:ve,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:r("work:task.newRequirement")}),t.jsx("button",{onClick:()=>{yt(F??""),Ee(!0)},className:"px-3 py-1.5 border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 text-xs rounded-lg font-medium transition-colors",children:r("work:task.newTaskBtn")})]}),t.jsx("div",{className:"flex-1"})]}),!l&&Je!=="workflows"&&(Lr.length>0||e?.id)&&(Ol>0||Zt.length>0||He.size>0||Qe)&&t.jsxs("div",{className:"px-6 py-1.5 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[t.jsx("button",{type:"button",onClick:()=>{dt(new Set),it(!1)},className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${He.size>0||Qe?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),e?.id&&t.jsx("button",{type:"button",onClick:()=>it(w=>!w),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Qe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:r("work:task.myTasks")}),Lr.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(je=>He.has(je)),he=!ne&&w.agentIds.some(je=>He.has(je));return t.jsxs("button",{onClick:()=>{dt(je=>{const we=new Set(je);if(ne)for(const oe of w.agentIds)we.delete(oe);else for(const oe of w.agentIds)we.add(oe);return we})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ne?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})}),w.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:w.agentIds.length})]},`team-${w.id}`)}const U=w.agent,ee=He.has(U.id);return t.jsxs("button",{onClick:()=>ko(U.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ee?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${ee?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:U.name[0]?.toUpperCase()}),U.name]},U.id)})]}),Tt.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyNoProjectsTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyNoProjectsHint")}),t.jsx("button",{onClick:()=>re(!0),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:r("work:project.newProject")})]})}):or(Object.values(H).flat()).length===0&&Zt.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:[t.jsx("path",{d:"M9 11l3 3L22 4"}),t.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}),He.size>0||Qe?t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyFilteredTitle",{defaultValue:"No matching work"})}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyFilteredHint",{defaultValue:"Nothing matches the current assignee filter. Clear filters to see all items in this project."})}),t.jsx("button",{type:"button",onClick:()=>{dt(new Set),it(!1)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg font-medium transition-colors",children:r("work:task.clear")})]}):t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyNoReqsTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed whitespace-pre-line",children:r("work:task.emptyNoReqsHint")}),t.jsxs("div",{className:"flex items-center justify-center gap-2 pt-1",children:[t.jsx("button",{onClick:ve,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:r("work:task.createRequirementCta")}),t.jsx("button",{onClick:()=>{yt(F??""),Ee(!0)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 rounded-lg font-medium transition-colors",children:r("work:task.newTaskBtn")})]})]})]})}):Je==="backlog"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:l?vt.onTouchStart:void 0,onTouchEnd:l?vt.onTouchEnd:void 0,children:t.jsx(Gh,{tasks:or(Object.values(H).flat()),requirements:Zt,agents:J,projects:R,onTaskClick:w=>Ir(w),onReqClick:w=>Tr(w),onRefresh:()=>{nt(),Rt()},selectedTaskId:Ge?.id,selectedReqId:ze?.id})}):Je==="workflows"?t.jsx(Uh,{teamId:jl,projectId:F,agents:J,projects:R,onViewRunTasks:w=>{const U=ne=>{An(ne),ot(`req-${ne.id}`),ft("dag")},ee=se.find(ne=>ne.id===w);ee?U(ee):ae.requirements.get(w).then(ne=>{ne.requirement&&(me(he=>[...he,ne.requirement]),U(ne.requirement))}).catch(()=>{})}}):Je==="dag"?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:l?vt.onTouchStart:void 0,onTouchEnd:l?vt.onTouchEnd:void 0,children:[t.jsx(Ch,{tasks:(()=>{const w=or(Object.values(H).flat(),!0);if(n&&ze){const U=new Set(ze.taskIds??[]);return w.filter(ee=>U.has(ee.id))}return w})(),requirements:n&&ze?[ze]:Zt,agents:J,showArchived:Ne,onShowArchivedChange:Me,onTaskClick:w=>Ir(w),onReqClick:w=>Tr(w),onCollapseDAG:()=>{Ae(null),De(null),ot(null)},onDependencyChange:nt,selectedTaskId:Ge?.id,selectedReqId:ze?.id,hasDetailPanel:To,defaultExpandedNodeId:fn??(n&&ze?`req-${ze.id}`:void 0),previewMode:n}),l&&t.jsx("button",{onClick:()=>ft("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:ht,className:"flex-1 min-h-0 overflow-auto px-4 py-5",onTouchStart:l?pe.onTouchStart:void 0,onTouchEnd:l?pe.onTouchEnd:void 0,children:t.jsx("div",{className:"flex gap-3 items-stretch",children:$l.map(w=>{const U=jo(w),ee=No(w),ne=U.length+ee.length,he=St===w.id;return t.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col transition-colors ${he?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:je=>Rl(je,w.id),onDragLeave:je=>_l(je,w.id),onDrop:je=>{Ll(je,w.id)},children:[t.jsxs("div",{className:`flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30 sticky top-0 z-10 rounded-t-xl ${he?"bg-surface-elevated/60":"bg-surface-secondary/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${w.accent.replace("border-t-","bg-")}`}),t.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:w.label})]}),t.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:ne})]}),t.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const je=[...ee.map(we=>({kind:"req",data:we,time:new Date(we.updatedAt??we.createdAt).getTime()})),...U.map(we=>({kind:"task",data:we,time:new Date(we.updatedAt??we.createdAt??0).getTime()}))];return je.sort((we,oe)=>oe.time-we.time),je.map(we=>{if(we.kind==="req"){const oe=we.data,Ue=c[oe.status]??{label:oe.status,cls:"bg-gray-500/15 text-fg-secondary"},mt=oe.source==="agent"&&oe.status==="pending",Oe=W==="all"&&oe.projectId?R.find(Re=>Re.id===oe.projectId):null,ke=Qn(oe.createdBy,J,ie)??oe.createdBy.slice(0,10),Ve=ze?.id===oe.id;return t.jsxs("div",{"data-work-item-id":oe.id,role:"button",tabIndex:0,draggable:!0,onDragStart:Re=>Tl(Re,oe),onDragEnd:wo,onClick:()=>Tr(oe),onKeyDown:Re=>Re.key==="Enter"&&Tr(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
10
10
  ${mt?"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
- ${Ve?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),t.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:r("work:task.requirementShort")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${Ue.cls}`,children:Ue.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:oe.title}),oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:oe.description}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[Oe&&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:Oe.name,children:Oe.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:oe.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",ke]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[oe.goalConfig?.loopEnabled&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",title:oe.goalConfig.completionCriteria,children:["🎯 ",oe.goalConfig.currentIteration,"/",oe.goalConfig.maxIterations]}),oe.taskIds.length>0&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",oe.taskIds.length]})]})]}),mt&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:Re=>{Re.stopPropagation(),xs(oe.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:r("work:task.approve")}),t.jsx("button",{onClick:Re=>{Re.stopPropagation(),It(oe.id)},className:"flex-1 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:r("work:task.reject")})]})]},`req-${oe.id}`)}else{const oe=we.data,Ue=oe.subtasks?.length??0,kt=a[oe.status],mt=oe.status==="pending",Oe=oe.taskType==="scheduled"&&!!oe.scheduleConfig,ke=Oe?oe.scheduleConfig.every?r("work:task.everyInterval",{interval:oe.scheduleConfig.every}):oe.scheduleConfig.cron?r("work:task.cronLabel"):r("work:task.scheduledShort"):null,Ve=q==="all"&&oe.projectId?(()=>{const at=R.find(Or=>Or.id===oe.projectId)?.name;return at&&at!=="default"?at:null})():null,Re=oe.requirementId?se.find(at=>at.id===oe.requirementId)?.title:null,Xt=oe.createdBy?Qn(oe.createdBy,J,ie)??oe.createdBy:null,jn=Ge?.id===oe.id,Bn={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},_o=oe.status==="blocked"&&(!oe.blockedBy||oe.blockedBy.length===0||oe.blockedBy.every(at=>{const Or=Dl.get(at);return Or&&Or.status==="completed"}));return t.jsxs("div",{"data-work-item-id":oe.id,role:"button",tabIndex:0,"aria-label":oe.title,draggable:!mt,onDragStart:at=>!mt&&Il(at,oe),onDragEnd:wo,onClick:()=>Ir(oe),onKeyDown:at=>at.key==="Enter"&&Ir(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${_o?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":mt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Oe?"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"} ${jn?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Bn[oe.priority]??"bg-gray-400"}`,title:oe.priority}),Oe&&t.jsx("span",{className:"text-blue-500 shrink-0",title:ke??"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"})})}),Oe&&ke&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:ke}),kt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${kt.cls}`,children:kt.label}),_o&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md shrink-0 bg-red-500/15 text-red-500 font-medium",children:"⚠"})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:oe.title}),oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:oe.description}),(Ve||Re||oe.blockedBy&&oe.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[Ve&&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:Ve,children:Ve}),Re&&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:Re,children:["# ",Re]}),oe.blockedBy&&oe.blockedBy.length>0&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",oe.blockedBy.length," dep",oe.blockedBy.length>1?"s":""]})]}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:Xt&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Xt}`,children:["by ",Xt]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[Ue>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ue]}),oe.notes&&oe.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",oe.notes.length]}),oe.assignedAgentId&&t.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${yr[J.find(at=>at.id===oe.assignedAgentId)?.status??""]??"bg-gray-500"}`}),J.find(at=>at.id===oe.assignedAgentId)?.name??oe.assignedAgentId.slice(0,8)]})]})]})]},oe.id)}})})()}),he&&t.jsx("div",{className:"sticky bottom-2 mx-2 mb-2 border-2 border-dashed border-brand-500/25 rounded-lg h-10 flex items-center justify-center shrink-0 bg-surface-secondary/80 backdrop-blur-sm",children:t.jsx("span",{className:"text-[11px] text-brand-500/50",children:r("work:task.dropHere")})})]},w.id)})})})]}),!l&&Ro&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:j,children:t.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),Ro&&t.jsx("div",{className:`${l||$r?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:l||$r?void 0:{width:E},children:$==="project"&&wt?t.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[t.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 border-b border-border-default/60 sticky top-0 bg-surface-primary z-10",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary truncate flex-1",children:r("work:project.settingsTitle")}),t.jsx("button",{type:"button",onClick:yn,className:"w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated","aria-label":r("common:close"),children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),t.jsx(Wh,{project:wt,tasks:Object.values(H).flat().filter(w=>w.projectId===wt.id),requirements:se.filter(w=>w.projectId===wt.id),agents:J,onDeleteProject:()=>El(wt.id),onUpdateProject:async w=>{await ae.projects.update(wt.id,w),bn()},onRefresh:()=>{bn()}})]}):$==="empty"?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-surface-elevated flex items-center justify-center",children:t.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),t.jsx("path",{d:"M9 12h6"})]})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyDetailTitle",{defaultValue:"No item selected"})}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyDetailHint",{defaultValue:"Select a requirement or task from the list, or create one to get started."})}),t.jsxs("div",{className:"flex items-center justify-center gap-2",children:[t.jsx("button",{onClick:ve,className:"px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:r("work:task.newRequirement")}),t.jsx("button",{onClick:()=>{yt(F??""),Ee(!0)},className:"px-3 py-1.5 text-[11px] border border-amber-500/60 text-amber-600 rounded-lg font-medium",children:r("work:task.newTaskBtn")})]}),t.jsx("button",{type:"button",onClick:yn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})}):$r?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(Ua,{req:ze,agents:J,projects:R,allTasks:Object.values(H).flat(),users:ie,onClose:()=>{De(null),Ge||yn()},onApprove:w=>{xs(w)},onReject:w=>{It(w)},onCancel:w=>{vo(w),De(null)},onStatusChange:async(w,U)=>{try{await ae.requirements.updateStatus(w,U),ct(`Requirement status → ${U}`),$n({requirementId:w}),kn(),nt()}catch(ee){ct(`Error: ${ee}`)}},onRefresh:kn,authUser:e,onTaskClick:w=>{Ae(w),S("item")},onCreateTask:(w,U)=>{Xe(w),U&&yt(U),Ee(!0)},onProjectClick:Rr,previewMode:n})}),t.jsx("div",{className:"w-px shrink-0 bg-border-default"}),t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(Ya,{task:Ge,agents:J,projects:R,requirements:se,allTasks:Object.values(H).flat(),users:ie,onClose:Nl,onRefresh:bo,authUser:e,scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{De(U=>U?.id===w.id?null:w),S("item")},onProjectClick:Rr})})]}):Ge?t.jsx(Ya,{task:Ge,agents:J,projects:R,requirements:se,allTasks:Object.values(H).flat(),users:ie,onClose:yn,onRefresh:bo,authUser:e,scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{De(w),Ae(null),S("item")},onProjectClick:Rr}):ze?t.jsx(Ua,{req:ze,agents:J,projects:R,allTasks:Object.values(H).flat(),users:ie,onClose:yn,onApprove:w=>{xs(w)},onReject:w=>{It(w)},onCancel:w=>{vo(w),yn()},onStatusChange:async(w,U)=>{try{await ae.requirements.updateStatus(w,U),ct(`Requirement status → ${U}`),$n({requirementId:w}),kn(),nt()}catch(ee){ct(`Error: ${ee}`)}},scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onRefresh:kn,authUser:e,onTaskClick:w=>{Ae(w),De(null),S("item"),l&&(_(!0),history.pushState({mobileDetail:Fe.WORK},"",window.location.hash))},onCreateTask:(w,U)=>{Xe(w),U&&yt(U),Ee(!0)},onProjectClick:Rr,previewMode:n}):t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyDetailTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyDetailHint")}),t.jsx("button",{type:"button",onClick:yn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})})}),fe&&t.jsx(Sh,{orgId:e?.orgId,onCreated:Sl,onClose:()=>re(!1)}),xe&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ee(!1),tt("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${l?"w-full":"w-[28rem]"}`,onClick:w=>w.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.newTask")}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.titleLabel")}),t.jsx("input",{autoFocus:!l,value:ye,onChange:w=>Ie(w.target.value),onKeyDown:w=>{w.key==="Enter"&&xo()},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:pt,onChange:w=>rt(w.target.value),rows:2,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.projectLabel")}),t.jsx(cr,{options:[{value:"",label:r("work:task.noProject")},...R.map(w=>({value:w.id,label:w.name}))],value:bt,onChange:w=>{yt(w),Xe("")},placeholder:r("work:task.noProject"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.requirementLabel")}),t.jsx(cr,{options:[{value:"",label:r("work:task.selectRequirement")},...se.filter(w=>w.status==="in_progress"&&(!bt||w.projectId===bt)).map(w=>({value:w.id,label:w.title}))],value:Ce,onChange:Xe,placeholder:r("work:task.selectRequirement"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.assignToRequired")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:J.map(w=>({value:w.id,label:`${w.name} (${w.status})`})),value:st,onChange:Ht,placeholder:r("work:task.selectAgent"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.reviewerRequired")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:[...ie.map(w=>({value:`human:${w.id}`,label:w.name})),...J.filter(w=>w.id!==st).map(w=>({value:`agent:${w.id}`,label:`${w.name} (${w.status})`}))],value:xt,onChange:Jt,placeholder:r("work:task.selectReviewer"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:`grid gap-4 ${et==="scheduled"?"grid-cols-3":"grid-cols-2"}`,children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.priorityField")}),t.jsxs("select",{value:Nt,onChange:w=>Ct(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:r("work:priority.low")}),t.jsx("option",{value:"medium",children:r("work:priority.medium")}),t.jsx("option",{value:"high",children:r("work:priority.high")}),t.jsx("option",{value:"urgent",children:r("work:priority.urgent")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.taskType")}),t.jsxs("select",{value:et,onChange:w=>qt(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"standard",children:r("work:task.taskTypeStandard")}),t.jsx("option",{value:"scheduled",children:r("work:task.taskTypeScheduled")})]})]}),et==="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:Wt,onChange:w=>_e(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"30m",children:r("work:task.freq30m")}),t.jsx("option",{value:"1h",children:r("work:task.freq1h")}),t.jsx("option",{value:"2h",children:r("work:task.freq2h")}),t.jsx("option",{value:"4h",children:r("work:task.freq4h")}),t.jsx("option",{value:"8h",children:r("work:task.freq8h")}),t.jsx("option",{value:"12h",children:r("work:task.freq12h")}),t.jsx("option",{value:"1d",children:r("work:task.freq1d")}),t.jsx("option",{value:"1w",children:r("work:task.freq1w")})]})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.blockedBy")}),t.jsx(Ih,{options:Object.values(H).flat().filter(w=>w.status!=="completed"&&w.status!=="cancelled").map(w=>({value:w.id,label:w.title})),selected:$e,onAdd:w=>Le([...$e,w]),placeholder:r("work:task.selectDependency"),noMatchesText:r("work:task.noMatches")}),$e.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:$e.map(w=>{const U=Object.values(H).flat().find(ee=>ee.id===w);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:[U?U.title.slice(0,30):w.slice(-8),t.jsx("button",{onClick:()=>Le($e.filter(ee=>ee!==w)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},w)})})]}),Ye&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Ye}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{Ee(!1),tt("")},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:()=>{xo()},disabled:!ye.trim()||!st||!xt||un,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:r(un?"common:creating":"common:create")})]})]})}),Jn&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{hn(!1),gn(""),pn(""),rn("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${l?"w-full":"w-[28rem]"}`,onClick:w=>w.stopPropagation(),children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.newRequirementModalTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:r("work:task.newRequirementModalHint")})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.projectLabel")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:R.map(w=>({value:w.id,label:w.name})),value:xn,onChange:Cr,placeholder:r("work:task.selectProject"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.titleField")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("input",{value:mn,onChange:w=>gn(w.target.value),placeholder:r("work:task.reqTitleExample"),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!l,onKeyDown:w=>{w.key==="Enter"&&mn.trim()&&yo()}})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.descriptionField")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("textarea",{value:Tn,onChange:w=>pn(w.target.value),placeholder:r("work:task.reqDescPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.priorityField")}),t.jsxs("select",{value:er,onChange:w=>hs(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:r("work:priority.low")}),t.jsx("option",{value:"medium",children:r("work:priority.medium")}),t.jsx("option",{value:"high",children:r("work:priority.high")}),t.jsx("option",{value:"urgent",children:r("work:priority.urgent")})]})]}),tr&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:tr}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{hn(!1),gn(""),pn(""),rn("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{yo()},disabled:!mn.trim()||!Tn.trim()||!xn||ms,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40 disabled:cursor-not-allowed",children:r(ms?"common:creating":"common:create")})]})]})}),nn&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{It(null),Rn("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${l?"w-full":"w-96"}`,onClick:w=>w.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.rejectRequirementTitle")}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.rejectReasonLabel")}),t.jsx("textarea",{value:Sr,onChange:w=>Er(w.target.value),placeholder:r("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!l})]}),co&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:co}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>{It(null),Rn("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{Ml()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:r("work:task.reject")})]})]})}),Ft&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Mt(!1),children:[t.jsx("div",{className:"absolute inset-0 bg-black/50"}),t.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:w=>w.stopPropagation(),children:[t.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:r("work:task.filtersSheetTitle")}),t.jsxs("div",{className:"flex items-center gap-2",children:[(He.size>0||Qe)&&t.jsx("button",{onClick:()=>{dt(new Set),it(!1)},className:"text-[11px] text-brand-500 font-medium",children:r("work:task.clearAll")}),t.jsx("button",{onClick:()=>Mt(!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"})]})})]})]}),Tt.length>0&&t.jsxs("div",{className:"px-4 py-3",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:r("work:task.projectsFilterGroup")}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{Kt(),Mt(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${q==="all"&&!F?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[r("work:task.all"),Dr>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Dr})]}),Tt.map(w=>{const U=F===w.id,ee=Ar[w.id]??0;return t.jsxs("button",{type:"button",onClick:()=>{Ot(w.id),Mt(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${U?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${U?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:w.name[0]?.toUpperCase()}),w.name,ee>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:ee})]},w.id)})]})]}),e?.id&&t.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:t.jsx("button",{type:"button",onClick:()=>it(w=>!w),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Qe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:r("work:task.myTasks")})}),Lr.length>0&&t.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:r("work:task.agentsFilterGroup")}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Lr.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(je=>He.has(je)),he=!ne&&w.agentIds.some(je=>He.has(je));return t.jsxs("button",{onClick:()=>{dt(je=>{const we=new Set(je);if(ne)for(const oe of w.agentIds)we.delete(oe);else for(const oe of w.agentIds)we.add(oe);return we})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ne?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})}),w.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:w.agentIds.length})]},`team-${w.id}`)}const U=w.agent,ee=He.has(U.id);return t.jsxs("button",{onClick:()=>ko(U.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ee?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${ee?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:U.name[0]?.toUpperCase()}),U.name]},U.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Qh({requirementId:e,createdBy:n,agents:s,users:r,authUser:i}){const{t:o}=We(["work","common"]),[a,c]=g.useState([]),[l,d]=g.useState([]),h=g.useRef(null),[f,m]=g.useState(new Map);g.useEffect(()=>{d([]),m(new Map),h.current&&(clearTimeout(h.current),h.current=null),ae.requirements.getComments(e).then(y=>c(y.comments)).catch(()=>{})},[e]),g.useEffect(()=>jt.on("requirement:comment",v=>{if(v.payload?.requirementId===e&&v.payload.comment){const x=v.payload.comment;c(b=>b.some(k=>k.id===x.id)?b:[...b,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(d(b=>{const k=b.filter(N=>N.id!==x.authorId);return k.length===0&&h.current&&(clearTimeout(h.current),h.current=null),k}),m(b=>{const k=new Map(b);return k.delete(x.authorId),k}))}}),[e]),g.useEffect(()=>{if(l.length===0)return;const y=new Set(l.map(x=>x.id));return jt.on("agent:activity_log",x=>{const b=x.payload;if(!b)return;const k=b.agentId;if(!y.has(k))return;const N=ro(b);N&&m(I=>so(I,k,N))})},[l]);const[u,p]=g.useState(null),M=async(y,v,x,b)=>{let k;x.length>0&&(k=(await ae.uploads.upload(x.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await ae.requirements.addComment(e,y,i?.name,k,i?.id,v.length>0?v:void 0,b);const N=[],I=new Set,B=D=>{if(I.has(D)||D===i?.id)return;I.add(D);const L=s.find(E=>E.id===D);L&&N.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const D of v){const L=s.find(E=>E.name.toLowerCase()===D.toLowerCase());L&&B(L.id)}n?.startsWith("agt_")&&B(n),N.length>0&&(h.current&&clearTimeout(h.current),d(N),h.current=setTimeout(()=>d([]),12e4))},C=g.useCallback(y=>{p({id:y.id,authorName:y.authorName,content:y.content.slice(0,100)})},[]);return t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:a.length>0?o("work:task.commentsWithCount",{count:a.length}):o("work:task.comments")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[a.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:o("work:task.noCommentsYet")}),a.map(y=>t.jsx(ur,{comment:y,agents:s,onReply:C},y.id)),l.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(y=>{const v=f.get(y.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(Fe.TEAM,{agentId:y.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Vs,{name:y.name,avatarUrl:y.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:y.name}),v.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),v.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(oo,{entries:v})})]},y.id)})})]}),t.jsx(ti,{agents:s,humans:r,onSubmit:M,replyTo:u,onCancelReply:()=>p(null)})]})}function Ua({req:e,agents:n,projects:s,allTasks:r,users:i,onClose:o,onApprove:a,onReject:c,onCancel:l,onStatusChange:d,onRefresh:h,authUser:f,scrollToComments:m,onScrollToCommentsDone:u,onTaskClick:p,onCreateTask:M,onProjectClick:C,previewMode:y}){const{t:v}=We(["work","common"]),x=g.useMemo(()=>io(v),[v]),b=g.useMemo(()=>yl(v),[v]),k=vr(),[N,I]=g.useState(!1),[B,D]=g.useState(e.description),[L,E]=g.useState(!1),[P,z]=g.useState(!1),[j,O]=g.useState(!1),_=g.useRef(null),[T,R]=g.useState("none"),A=g.useRef(null),q=g.useRef(null),Y=g.useRef(80);g.useEffect(()=>{const te=_.current;if(!te)return;const X=()=>{const{scrollTop:de,scrollHeight:se,clientHeight:me}=te;if(!(se>me+50)){R("none");return}const K=de<30,ce=de+me>=se-30;R(K?"top":ce?"bottom":"middle")};X(),te.addEventListener("scroll",X,{passive:!0});const ie=new ResizeObserver(X);return ie.observe(te),()=>{te.removeEventListener("scroll",X),ie.disconnect()}},[]),g.useEffect(()=>{if(N&&q.current){const te=q.current;te.style.height="auto",te.style.height=Math.max(te.scrollHeight,Y.current)+"px",te.focus()}},[N]),g.useEffect(()=>{if(!m)return;const te=setTimeout(()=>{const X=_.current;X&&X.scrollTo({top:X.scrollHeight,behavior:"smooth"}),u?.()},300);return()=>clearTimeout(te)},[m,u]);const F=x[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},Q=e.source==="agent",$=Q&&e.status==="pending",S=e.status==="pending"||e.status==="in_progress",V=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",W=e.projectId?s.find(te=>te.id===e.projectId):null,H=Qn(e.createdBy,n,i)??e.createdBy.slice(0,12),Z=r.filter(te=>e.taskIds.includes(te.id)),J=W?.teamIds?.[0]??null;g.useMemo(()=>new Map(Z.map(te=>[te.id,te])),[Z]);const le=Z.length>=2;return g.useEffect(()=>{D(e.description),I(!1)},[e.id,e.description]),t.jsxs("div",{className:"flex flex-col w-full h-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[k&&t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("h2",{className:"flex-1 min-w-0 pb-4 text-lg font-semibold text-fg-primary leading-snug",children:[e.title," ",t.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded align-middle",children:v("work:task.requirementShort")})," ",t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${F.cls}`,children:F.label})," ",e.priority==="high"||e.priority==="urgent"?t.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:v("common:priority."+e.priority,{defaultValue:e.priority})}):t.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:v("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),t.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:_,className:"h-full overflow-y-auto p-5 space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:v("work:task.requirementDetailDescription")}),N?t.jsx("textarea",{ref:q,value:B,onChange:te=>{D(te.target.value);const X=te.target;X.style.height="auto",X.style.height=X.scrollHeight+"px"},onBlur:async()=>{if(B!==e.description){E(!0);try{await ae.requirements.update(e.id,{description:B}),h?.()}catch{}finally{E(!1)}}I(!1)},onKeyDown:te=>{te.key==="Escape"&&(te.preventDefault(),D(e.description),I(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:v("work:task.requirementDetailDescription")}):t.jsx("div",{ref:A,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${V?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:V?void 0:te=>{te.target.closest("a, button, [data-entity-link]")||(Y.current=Math.max(A.current?.offsetHeight??80,60),D(e.description),I(!0))},role:V?void 0:"button",tabIndex:V?void 0:0,onKeyDown:V?void 0:te=>te.key==="Enter"&&(D(e.description),I(!0)),children:e.description?t.jsx(fr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:v("work:task.requirementNoDescription")})})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.createdByLabel")}),t.jsx("span",{className:"text-fg-secondary",children:H}),Q&&t.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:v("work:task.agentTag")})]}),t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.createdLabel")}),t.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),W&&t.jsxs("div",{className:`bg-surface-elevated/60 rounded-lg p-2.5 ${C?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:C?()=>C(W.id):void 0,role:C?"button":void 0,tabIndex:C?0:void 0,onKeyDown:C?te=>te.key==="Enter"&&C(W.id):void 0,children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.projectLabel")}),t.jsx("span",{className:"text-fg-secondary",children:W.name})]}),e.approvedBy&&t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.approvedBy")}),t.jsx("span",{className:"text-fg-secondary",children:Qn(e.approvedBy,n,i)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:v("work:task.rejectionReason")}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.goalConfig?.loopEnabled&&t.jsxs("div",{className:"bg-brand-500/8 border border-brand-500/20 rounded-lg p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("span",{className:"text-[10px] font-semibold text-brand-500 uppercase tracking-wider",children:v("work:requirement.goal")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${e.goalConfig.currentIteration>=e.goalConfig.maxIterations?"bg-amber-500/15 text-amber-600":"bg-green-500/15 text-green-600"}`,children:e.goalConfig.currentIteration>=e.goalConfig.maxIterations?v("work:requirement.goalMaxReached"):v("work:requirement.goalActive")})]}),t.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:e.goalConfig.completionCriteria}),t.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary",children:[t.jsx("span",{children:v("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&t.jsx("span",{children:v("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&t.jsx("span",{className:"text-brand-500",children:v("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(te=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",te]},te))}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:v("work:task.linkedTasks",{count:Z.length})}),t.jsxs("div",{className:"flex items-center gap-2",children:[le&&J&&t.jsxs("button",{onClick:()=>O(!0),className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),v("work:task.saveAsWorkflow")]}),!V&&M&&t.jsxs("button",{onClick:()=>M(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),v("work:requirement.createTask")]})]})]}),Z.length>0?(()=>{const te=new Map(Z.map(ue=>[ue.id,ue]));if(!Z.some(ue=>ue.blockedBy?.some(K=>te.has(K))))return t.jsx("div",{className:"space-y-1.5",children:Z.map(ue=>{const K=b[ue.status];return t.jsxs("div",{onClick:()=>p?.(ue),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${p?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[ue.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ue.title}),K&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${K.cls}`,children:K.label})]},ue.id)})});const ie=new Map,de=new Set;for(const ue of Z)for(const K of ue.blockedBy??[])if(te.has(K)){de.add(ue.id);const ce=ie.get(K)??[];ce.push(ue.id),ie.set(K,ce)}const se=Z.filter(ue=>!de.has(ue.id)),me=(ue,K)=>{const ce=b[ue.status],ge=(ie.get(ue.id)??[]).map(ve=>te.get(ve)).filter(Boolean);return t.jsxs("div",{children:[t.jsxs("div",{onClick:()=>p?.(ue),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${p?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:K>0?{marginLeft:K*20}:void 0,children:[K>0&&t.jsx("span",{className:"text-fg-quaternary text-[10px] shrink-0",children:"↳"}),t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[ue.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ue.title}),ce&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${ce.cls}`,children:ce.label})]}),ge.map(ve=>me(ve,K+1))]},ue.id)};return t.jsx("div",{className:"space-y-1.5",children:se.map(ue=>me(ue,0))})})():t.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:v("work:requirement.noLinkedTasks")})]}),!y&&t.jsx(Qh,{requirementId:e.id,createdBy:e.createdBy,agents:n,users:i,authUser:f}),!y&&t.jsx(kl,{entityType:"requirement",entityId:e.id})]}),T!=="none"&&T!=="top"&&t.jsx("button",{onClick:()=>_.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:v("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),T!=="none"&&T!=="bottom"&&t.jsx("button",{onClick:()=>{const te=_.current;te&&te.scrollTo({top:te.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:v("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[$&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>a(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:v("work:requirement.approveRequirement")}),t.jsx("button",{onClick:()=>c(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:v("work:requirement.rejectRequirement")})]}),!$&&d&&!V&&t.jsx("select",{value:e.status,onChange:te=>{te.target.value!==e.status&&d(e.id,te.target.value)},className:"px-2 py-1.5 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-secondary cursor-pointer hover:border-gray-500 transition-colors",children:Yh.map(te=>{const X=x[te],ie=te===e.status||(qs[e.status]?.has(te)??!1);return t.jsx("option",{value:te,disabled:!ie,children:X?.label??te},te)})}),V&&d&&t.jsx("button",{onClick:()=>d(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:v("work:task.reopen")}),t.jsx("div",{className:"flex-1"}),S&&!$&&t.jsx("button",{onClick:()=>z(!0),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:v("work:task.cancelRequirement")})]}),P&&t.jsx(Hn,{title:v("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:v("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:v("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{z(!1),l(e.id)},onCancel:()=>z(!1)}),j&&J&&t.jsx(Xh,{req:e,tasks:Z,agents:n,teamId:J,onClose:()=>O(!1),onSaved:()=>O(!1)})]})}function kl({entityType:e,entityId:n}){const{t:s}=We(["work"]),[r,i]=g.useState([]),[o,a]=g.useState(!0),[c,l]=g.useState(!1);if(g.useEffect(()=>{a(!0),(e==="task"?ae.tasks.getHistory:ae.requirements.getHistory)(n).then(u=>i(u.history)).catch(()=>i([])).finally(()=>a(!1))},[e,n]),o)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:s("work:task.loadingHistory","Loading history...")});if(r.length===0)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:s("work:task.noHistory","No status change history.")});const d=c?r:r.slice(-5),h=r.length>5&&!c,f=m=>{const u=m.changedByName||m.changedById||(m.changedByType==="human"?"User":m.changedByType==="agent"?"Agent":"System"),p=m.changedByType==="human"?"bg-blue-500/20 text-blue-500":m.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${p}`,children:u})};return t.jsxs("div",{className:"px-6 py-4",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:s("work:task.statusHistory","Status History")}),h&&t.jsx("button",{onClick:()=>l(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:s("work:task.showAllHistory",{count:r.length})}),t.jsxs("div",{className:"relative ml-2",children:[t.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),t.jsx("div",{className:"space-y-3",children:d.map(m=>t.jsxs("div",{className:"flex items-start gap-3 relative",children:[t.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:m.changedByType==="human"?"#3b82f6":m.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[f(m),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:m.fromStatus}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:m.toStatus})]}),m.reason&&t.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:m.reason}),t.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(m.createdAt).toLocaleString()})]})]},m.id))})]})]})}export{sm as WorkPage};
11
+ ${Ve?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),t.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:r("work:task.requirementShort")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${Ue.cls}`,children:Ue.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:oe.title}),oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:oe.description}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[Oe&&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:Oe.name,children:Oe.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:oe.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",ke]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[oe.goalConfig?.loopEnabled&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",title:oe.goalConfig.completionCriteria,children:["🎯 ",oe.goalConfig.currentIteration,"/",oe.goalConfig.maxIterations]}),oe.taskIds.length>0&&t.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",oe.taskIds.length]})]})]}),mt&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:Re=>{Re.stopPropagation(),xs(oe.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:r("work:task.approve")}),t.jsx("button",{onClick:Re=>{Re.stopPropagation(),It(oe.id)},className:"flex-1 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:r("work:task.reject")})]})]},`req-${oe.id}`)}else{const oe=we.data,Ue=oe.subtasks?.length??0,kt=a[oe.status],mt=oe.status==="pending",Oe=oe.taskType==="scheduled"&&!!oe.scheduleConfig,ke=Oe?oe.scheduleConfig.every?r("work:task.everyInterval",{interval:oe.scheduleConfig.every}):oe.scheduleConfig.cron?r("work:task.cronLabel"):r("work:task.scheduledShort"):null,Ve=W==="all"&&oe.projectId?(()=>{const at=R.find(Or=>Or.id===oe.projectId)?.name;return at&&at!=="default"?at:null})():null,Re=oe.requirementId?se.find(at=>at.id===oe.requirementId)?.title:null,Xt=oe.createdBy?Qn(oe.createdBy,J,ie)??oe.createdBy:null,jn=Ge?.id===oe.id,Bn={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},_o=oe.status==="blocked"&&(!oe.blockedBy||oe.blockedBy.length===0||oe.blockedBy.every(at=>{const Or=Dl.get(at);return Or&&Or.status==="completed"}));return t.jsxs("div",{"data-work-item-id":oe.id,role:"button",tabIndex:0,"aria-label":oe.title,draggable:!mt,onDragStart:at=>!mt&&Il(at,oe),onDragEnd:wo,onClick:()=>Ir(oe),onKeyDown:at=>at.key==="Enter"&&Ir(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${_o?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":mt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Oe?"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"} ${jn?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Bn[oe.priority]??"bg-gray-400"}`,title:oe.priority}),Oe&&t.jsx("span",{className:"text-blue-500 shrink-0",title:ke??"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"})})}),Oe&&ke&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:ke}),kt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${kt.cls}`,children:kt.label}),_o&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md shrink-0 bg-red-500/15 text-red-500 font-medium",children:"⚠"})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:oe.title}),oe.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:oe.description}),(Ve||Re||oe.blockedBy&&oe.blockedBy.length>0)&&t.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[Ve&&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:Ve,children:Ve}),Re&&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:Re,children:["# ",Re]}),oe.blockedBy&&oe.blockedBy.length>0&&t.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",oe.blockedBy.length," dep",oe.blockedBy.length>1?"s":""]})]}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:Xt&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Xt}`,children:["by ",Xt]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[Ue>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ue]}),oe.notes&&oe.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",oe.notes.length]}),oe.assignedAgentId&&t.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${yr[J.find(at=>at.id===oe.assignedAgentId)?.status??""]??"bg-gray-500"}`}),J.find(at=>at.id===oe.assignedAgentId)?.name??oe.assignedAgentId.slice(0,8)]})]})]})]},oe.id)}})})()}),he&&t.jsx("div",{className:"sticky bottom-2 mx-2 mb-2 border-2 border-dashed border-brand-500/25 rounded-lg h-10 flex items-center justify-center shrink-0 bg-surface-secondary/80 backdrop-blur-sm",children:t.jsx("span",{className:"text-[11px] text-brand-500/50",children:r("work:task.dropHere")})})]},w.id)})})})]}),!l&&Ro&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:j,children:t.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),Ro&&t.jsx("div",{className:`${l||$r?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:l||$r?void 0:{width:E},children:$==="project"&&wt?t.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[t.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 border-b border-border-default/60 sticky top-0 bg-surface-primary z-10",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary truncate flex-1",children:r("work:project.settingsTitle")}),t.jsx("button",{type:"button",onClick:yn,className:"w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated","aria-label":r("common:close"),children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),t.jsx(Wh,{project:wt,tasks:Object.values(H).flat().filter(w=>w.projectId===wt.id),requirements:se.filter(w=>w.projectId===wt.id),agents:J,onDeleteProject:()=>El(wt.id),onUpdateProject:async w=>{await ae.projects.update(wt.id,w),bn()},onRefresh:()=>{bn()}})]}):$==="empty"?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-surface-elevated flex items-center justify-center",children:t.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),t.jsx("path",{d:"M9 12h6"})]})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyDetailTitle",{defaultValue:"No item selected"})}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyDetailHint",{defaultValue:"Select a requirement or task from the list, or create one to get started."})}),t.jsxs("div",{className:"flex items-center justify-center gap-2",children:[t.jsx("button",{onClick:ve,className:"px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:r("work:task.newRequirement")}),t.jsx("button",{onClick:()=>{yt(F??""),Ee(!0)},className:"px-3 py-1.5 text-[11px] border border-amber-500/60 text-amber-600 rounded-lg font-medium",children:r("work:task.newTaskBtn")})]}),t.jsx("button",{type:"button",onClick:yn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})}):$r?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(Ua,{req:ze,agents:J,projects:R,allTasks:Object.values(H).flat(),users:ie,onClose:()=>{De(null),Ge||yn()},onApprove:w=>{xs(w)},onReject:w=>{It(w)},onCancel:w=>{vo(w),De(null)},onStatusChange:async(w,U)=>{try{await ae.requirements.updateStatus(w,U),ct(`Requirement status → ${U}`),$n({requirementId:w}),kn(),nt()}catch(ee){ct(`Error: ${ee}`)}},onRefresh:kn,authUser:e,onTaskClick:w=>{Ae(w),S("item")},onCreateTask:(w,U)=>{Xe(w),U&&yt(U),Ee(!0)},onProjectClick:Rr,previewMode:n})}),t.jsx("div",{className:"w-px shrink-0 bg-border-default"}),t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(Ya,{task:Ge,agents:J,projects:R,requirements:se,allTasks:Object.values(H).flat(),users:ie,onClose:Nl,onRefresh:bo,authUser:e,scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{De(U=>U?.id===w.id?null:w),S("item")},onProjectClick:Rr})})]}):Ge?t.jsx(Ya,{task:Ge,agents:J,projects:R,requirements:se,allTasks:Object.values(H).flat(),users:ie,onClose:yn,onRefresh:bo,authUser:e,scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{De(w),Ae(null),S("item")},onProjectClick:Rr}):ze?t.jsx(Ua,{req:ze,agents:J,projects:R,allTasks:Object.values(H).flat(),users:ie,onClose:yn,onApprove:w=>{xs(w)},onReject:w=>{It(w)},onCancel:w=>{vo(w),yn()},onStatusChange:async(w,U)=>{try{await ae.requirements.updateStatus(w,U),ct(`Requirement status → ${U}`),$n({requirementId:w}),kn(),nt()}catch(ee){ct(`Error: ${ee}`)}},scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onRefresh:kn,authUser:e,onTaskClick:w=>{Ae(w),De(null),S("item"),l&&(_(!0),history.pushState({mobileDetail:Fe.WORK},"",window.location.hash))},onCreateTask:(w,U)=>{Xe(w),U&&yt(U),Ee(!0)},onProjectClick:Rr,previewMode:n}):t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyDetailTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyDetailHint")}),t.jsx("button",{type:"button",onClick:yn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})})}),fe&&t.jsx(Sh,{orgId:e?.orgId,onCreated:Sl,onClose:()=>re(!1)}),xe&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Ee(!1),tt("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${l?"w-full":"w-[28rem]"}`,onClick:w=>w.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.newTask")}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.titleLabel")}),t.jsx("input",{autoFocus:!l,value:ye,onChange:w=>Ie(w.target.value),onKeyDown:w=>{w.key==="Enter"&&xo()},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:pt,onChange:w=>rt(w.target.value),rows:2,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.projectLabel")}),t.jsx(cr,{options:[{value:"",label:r("work:task.noProject")},...R.map(w=>({value:w.id,label:w.name}))],value:bt,onChange:w=>{yt(w),Xe("")},placeholder:r("work:task.noProject"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.requirementLabel")}),t.jsx(cr,{options:[{value:"",label:r("work:task.selectRequirement")},...se.filter(w=>w.status==="in_progress"&&(!bt||w.projectId===bt)).map(w=>({value:w.id,label:w.title}))],value:Ce,onChange:Xe,placeholder:r("work:task.selectRequirement"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.assignToRequired")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:J.map(w=>({value:w.id,label:`${w.name} (${w.status})`})),value:st,onChange:Ht,placeholder:r("work:task.selectAgent"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.reviewerRequired")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:[...ie.map(w=>({value:`human:${w.id}`,label:w.name})),...J.filter(w=>w.id!==st).map(w=>({value:`agent:${w.id}`,label:`${w.name} (${w.status})`}))],value:xt,onChange:Jt,placeholder:r("work:task.selectReviewer"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:`grid gap-4 ${et==="scheduled"?"grid-cols-3":"grid-cols-2"}`,children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.priorityField")}),t.jsxs("select",{value:Nt,onChange:w=>Ct(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:r("work:priority.low")}),t.jsx("option",{value:"medium",children:r("work:priority.medium")}),t.jsx("option",{value:"high",children:r("work:priority.high")}),t.jsx("option",{value:"urgent",children:r("work:priority.urgent")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.taskType")}),t.jsxs("select",{value:et,onChange:w=>qt(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"standard",children:r("work:task.taskTypeStandard")}),t.jsx("option",{value:"scheduled",children:r("work:task.taskTypeScheduled")})]})]}),et==="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:Wt,onChange:w=>_e(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"30m",children:r("work:task.freq30m")}),t.jsx("option",{value:"1h",children:r("work:task.freq1h")}),t.jsx("option",{value:"2h",children:r("work:task.freq2h")}),t.jsx("option",{value:"4h",children:r("work:task.freq4h")}),t.jsx("option",{value:"8h",children:r("work:task.freq8h")}),t.jsx("option",{value:"12h",children:r("work:task.freq12h")}),t.jsx("option",{value:"1d",children:r("work:task.freq1d")}),t.jsx("option",{value:"1w",children:r("work:task.freq1w")})]})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.blockedBy")}),t.jsx(Ih,{options:Object.values(H).flat().filter(w=>w.status!=="completed"&&w.status!=="cancelled").map(w=>({value:w.id,label:w.title})),selected:$e,onAdd:w=>Le([...$e,w]),placeholder:r("work:task.selectDependency"),noMatchesText:r("work:task.noMatches")}),$e.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:$e.map(w=>{const U=Object.values(H).flat().find(ee=>ee.id===w);return t.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:[U?U.title.slice(0,30):w.slice(-8),t.jsx("button",{onClick:()=>Le($e.filter(ee=>ee!==w)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},w)})})]}),Ye&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Ye}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{Ee(!1),tt("")},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:()=>{xo()},disabled:!ye.trim()||!st||!xt||un,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:r(un?"common:creating":"common:create")})]})]})}),Jn&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{hn(!1),gn(""),pn(""),rn("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${l?"w-full":"w-[28rem]"}`,onClick:w=>w.stopPropagation(),children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.newRequirementModalTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:r("work:task.newRequirementModalHint")})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.projectLabel")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx(cr,{options:R.map(w=>({value:w.id,label:w.name})),value:xn,onChange:Cr,placeholder:r("work:task.selectProject"),noMatchesText:r("work:task.noMatches")})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.titleField")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("input",{value:mn,onChange:w=>gn(w.target.value),placeholder:r("work:task.reqTitleExample"),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!l,onKeyDown:w=>{w.key==="Enter"&&mn.trim()&&yo()}})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.descriptionField")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("textarea",{value:Tn,onChange:w=>pn(w.target.value),placeholder:r("work:task.reqDescPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.priorityField")}),t.jsxs("select",{value:er,onChange:w=>hs(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"low",children:r("work:priority.low")}),t.jsx("option",{value:"medium",children:r("work:priority.medium")}),t.jsx("option",{value:"high",children:r("work:priority.high")}),t.jsx("option",{value:"urgent",children:r("work:priority.urgent")})]})]}),tr&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:tr}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{hn(!1),gn(""),pn(""),rn("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{yo()},disabled:!mn.trim()||!Tn.trim()||!xn||ms,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40 disabled:cursor-not-allowed",children:r(ms?"common:creating":"common:create")})]})]})}),nn&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{It(null),Rn("")},children:t.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${l?"w-full":"w-96"}`,onClick:w=>w.stopPropagation(),children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:r("work:task.rejectRequirementTitle")}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.rejectReasonLabel")}),t.jsx("textarea",{value:Sr,onChange:w=>Er(w.target.value),placeholder:r("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!l})]}),co&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:co}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>{It(null),Rn("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{Ml()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:r("work:task.reject")})]})]})}),Ft&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Mt(!1),children:[t.jsx("div",{className:"absolute inset-0 bg-black/50"}),t.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:w=>w.stopPropagation(),children:[t.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:r("work:task.filtersSheetTitle")}),t.jsxs("div",{className:"flex items-center gap-2",children:[(He.size>0||Qe)&&t.jsx("button",{onClick:()=>{dt(new Set),it(!1)},className:"text-[11px] text-brand-500 font-medium",children:r("work:task.clearAll")}),t.jsx("button",{onClick:()=>Mt(!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"})]})})]})]}),Tt.length>0&&t.jsxs("div",{className:"px-4 py-3",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:r("work:task.projectsFilterGroup")}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{Kt(),Mt(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${W==="all"&&!F?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[r("work:task.all"),Dr>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Dr})]}),Tt.map(w=>{const U=F===w.id,ee=Ar[w.id]??0;return t.jsxs("button",{type:"button",onClick:()=>{Ot(w.id),Mt(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${U?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${U?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:w.name[0]?.toUpperCase()}),w.name,ee>0&&t.jsx("span",{className:"text-[9px] text-fg-tertiary",children:ee})]},w.id)})]})]}),e?.id&&t.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:t.jsx("button",{type:"button",onClick:()=>it(w=>!w),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Qe?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:r("work:task.myTasks")})}),Lr.length>0&&t.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[t.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:r("work:task.agentsFilterGroup")}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Lr.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(je=>He.has(je)),he=!ne&&w.agentIds.some(je=>He.has(je));return t.jsxs("button",{onClick:()=>{dt(je=>{const we=new Set(je);if(ne)for(const oe of w.agentIds)we.delete(oe);else for(const oe of w.agentIds)we.add(oe);return we})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ne?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})}),w.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:w.agentIds.length})]},`team-${w.id}`)}const U=w.agent,ee=He.has(U.id);return t.jsxs("button",{onClick:()=>ko(U.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ee?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${ee?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:U.name[0]?.toUpperCase()}),U.name]},U.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Qh({requirementId:e,createdBy:n,agents:s,users:r,authUser:i}){const{t:o}=We(["work","common"]),[a,c]=g.useState([]),[l,d]=g.useState([]),h=g.useRef(null),[f,m]=g.useState(new Map);g.useEffect(()=>{d([]),m(new Map),h.current&&(clearTimeout(h.current),h.current=null),ae.requirements.getComments(e).then(y=>c(y.comments)).catch(()=>{})},[e]),g.useEffect(()=>jt.on("requirement:comment",v=>{if(v.payload?.requirementId===e&&v.payload.comment){const x=v.payload.comment;c(b=>b.some(k=>k.id===x.id)?b:[...b,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(d(b=>{const k=b.filter(N=>N.id!==x.authorId);return k.length===0&&h.current&&(clearTimeout(h.current),h.current=null),k}),m(b=>{const k=new Map(b);return k.delete(x.authorId),k}))}}),[e]),g.useEffect(()=>{if(l.length===0)return;const y=new Set(l.map(x=>x.id));return jt.on("agent:activity_log",x=>{const b=x.payload;if(!b)return;const k=b.agentId;if(!y.has(k))return;const N=ro(b);N&&m(I=>so(I,k,N))})},[l]);const[u,p]=g.useState(null),M=async(y,v,x,b)=>{let k;x.length>0&&(k=(await ae.uploads.upload(x.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await ae.requirements.addComment(e,y,i?.name,k,i?.id,v.length>0?v:void 0,b);const N=[],I=new Set,B=D=>{if(I.has(D)||D===i?.id)return;I.add(D);const L=s.find(E=>E.id===D);L&&N.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const D of v){const L=s.find(E=>E.name.toLowerCase()===D.toLowerCase());L&&B(L.id)}n?.startsWith("agt_")&&B(n),N.length>0&&(h.current&&clearTimeout(h.current),d(N),h.current=setTimeout(()=>d([]),12e4))},C=g.useCallback(y=>{p({id:y.id,authorName:y.authorName,content:y.content.slice(0,100)})},[]);return t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:a.length>0?o("work:task.commentsWithCount",{count:a.length}):o("work:task.comments")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[a.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:o("work:task.noCommentsYet")}),a.map(y=>t.jsx(ur,{comment:y,agents:s,onReply:C},y.id)),l.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(y=>{const v=f.get(y.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Bt.navigate(Fe.TEAM,{agentId:y.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Vs,{name:y.name,avatarUrl:y.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:y.name}),v.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),v.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(oo,{entries:v})})]},y.id)})})]}),t.jsx(ti,{agents:s,humans:r,onSubmit:M,replyTo:u,onCancelReply:()=>p(null)})]})}function Ua({req:e,agents:n,projects:s,allTasks:r,users:i,onClose:o,onApprove:a,onReject:c,onCancel:l,onStatusChange:d,onRefresh:h,authUser:f,scrollToComments:m,onScrollToCommentsDone:u,onTaskClick:p,onCreateTask:M,onProjectClick:C,previewMode:y}){const{t:v}=We(["work","common"]),x=g.useMemo(()=>io(v),[v]),b=g.useMemo(()=>yl(v),[v]),k=vr(),[N,I]=g.useState(!1),[B,D]=g.useState(e.description),[L,E]=g.useState(!1),[P,z]=g.useState(!1),[j,O]=g.useState(!1),_=g.useRef(null),[T,R]=g.useState("none"),A=g.useRef(null),W=g.useRef(null),Y=g.useRef(80);g.useEffect(()=>{const te=_.current;if(!te)return;const X=()=>{const{scrollTop:de,scrollHeight:se,clientHeight:me}=te;if(!(se>me+50)){R("none");return}const K=de<30,ce=de+me>=se-30;R(K?"top":ce?"bottom":"middle")};X(),te.addEventListener("scroll",X,{passive:!0});const ie=new ResizeObserver(X);return ie.observe(te),()=>{te.removeEventListener("scroll",X),ie.disconnect()}},[]),g.useEffect(()=>{if(N&&W.current){const te=W.current;te.style.height="auto",te.style.height=Math.max(te.scrollHeight,Y.current)+"px",te.focus()}},[N]),g.useEffect(()=>{if(!m)return;const te=setTimeout(()=>{const X=_.current;X&&X.scrollTo({top:X.scrollHeight,behavior:"smooth"}),u?.()},300);return()=>clearTimeout(te)},[m,u]);const F=x[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},Q=e.source==="agent",$=Q&&e.status==="pending",S=e.status==="pending"||e.status==="in_progress",V=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",q=e.projectId?s.find(te=>te.id===e.projectId):null,H=Qn(e.createdBy,n,i)??e.createdBy.slice(0,12),Z=r.filter(te=>e.taskIds.includes(te.id)),J=q?.teamIds?.[0]??null;g.useMemo(()=>new Map(Z.map(te=>[te.id,te])),[Z]);const le=Z.length>=2;return g.useEffect(()=>{D(e.description),I(!1)},[e.id,e.description]),t.jsxs("div",{className:"flex flex-col w-full h-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[k&&t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("h2",{className:"flex-1 min-w-0 pb-4 text-lg font-semibold text-fg-primary leading-snug",children:[e.title," ",t.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded align-middle",children:v("work:task.requirementShort")})," ",t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${F.cls}`,children:F.label})," ",e.priority==="high"||e.priority==="urgent"?t.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:v("common:priority."+e.priority,{defaultValue:e.priority})}):t.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:v("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),t.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:_,className:"h-full overflow-y-auto p-5 space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:v("work:task.requirementDetailDescription")}),N?t.jsx("textarea",{ref:W,value:B,onChange:te=>{D(te.target.value);const X=te.target;X.style.height="auto",X.style.height=X.scrollHeight+"px"},onBlur:async()=>{if(B!==e.description){E(!0);try{await ae.requirements.update(e.id,{description:B}),h?.()}catch{}finally{E(!1)}}I(!1)},onKeyDown:te=>{te.key==="Escape"&&(te.preventDefault(),D(e.description),I(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:v("work:task.requirementDetailDescription")}):t.jsx("div",{ref:A,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${V?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:V?void 0:te=>{te.target.closest("a, button, [data-entity-link]")||(Y.current=Math.max(A.current?.offsetHeight??80,60),D(e.description),I(!0))},role:V?void 0:"button",tabIndex:V?void 0:0,onKeyDown:V?void 0:te=>te.key==="Enter"&&(D(e.description),I(!0)),children:e.description?t.jsx(fr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:v("work:task.requirementNoDescription")})})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.createdByLabel")}),t.jsx("span",{className:"text-fg-secondary",children:H}),Q&&t.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:v("work:task.agentTag")})]}),t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.createdLabel")}),t.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),q&&t.jsxs("div",{className:`bg-surface-elevated/60 rounded-lg p-2.5 ${C?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:C?()=>C(q.id):void 0,role:C?"button":void 0,tabIndex:C?0:void 0,onKeyDown:C?te=>te.key==="Enter"&&C(q.id):void 0,children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.projectLabel")}),t.jsx("span",{className:"text-fg-secondary",children:q.name})]}),e.approvedBy&&t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:v("work:task.approvedBy")}),t.jsx("span",{className:"text-fg-secondary",children:Qn(e.approvedBy,n,i)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:v("work:task.rejectionReason")}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.goalConfig?.loopEnabled&&t.jsxs("div",{className:"bg-brand-500/8 border border-brand-500/20 rounded-lg p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("span",{className:"text-[10px] font-semibold text-brand-500 uppercase tracking-wider",children:v("work:requirement.goal")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${e.goalConfig.currentIteration>=e.goalConfig.maxIterations?"bg-amber-500/15 text-amber-600":"bg-green-500/15 text-green-600"}`,children:e.goalConfig.currentIteration>=e.goalConfig.maxIterations?v("work:requirement.goalMaxReached"):v("work:requirement.goalActive")})]}),t.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:e.goalConfig.completionCriteria}),t.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary",children:[t.jsx("span",{children:v("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&t.jsx("span",{children:v("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&t.jsx("span",{className:"text-brand-500",children:v("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(te=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",te]},te))}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:v("work:task.linkedTasks",{count:Z.length})}),t.jsxs("div",{className:"flex items-center gap-2",children:[le&&J&&t.jsxs("button",{onClick:()=>O(!0),className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),v("work:task.saveAsWorkflow")]}),!V&&M&&t.jsxs("button",{onClick:()=>M(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),v("work:requirement.createTask")]})]})]}),Z.length>0?(()=>{const te=new Map(Z.map(ue=>[ue.id,ue]));if(!Z.some(ue=>ue.blockedBy?.some(K=>te.has(K))))return t.jsx("div",{className:"space-y-1.5",children:Z.map(ue=>{const K=b[ue.status];return t.jsxs("div",{onClick:()=>p?.(ue),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${p?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[ue.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ue.title}),K&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${K.cls}`,children:K.label})]},ue.id)})});const ie=new Map,de=new Set;for(const ue of Z)for(const K of ue.blockedBy??[])if(te.has(K)){de.add(ue.id);const ce=ie.get(K)??[];ce.push(ue.id),ie.set(K,ce)}const se=Z.filter(ue=>!de.has(ue.id)),me=(ue,K)=>{const ce=b[ue.status],ge=(ie.get(ue.id)??[]).map(ve=>te.get(ve)).filter(Boolean);return t.jsxs("div",{children:[t.jsxs("div",{onClick:()=>p?.(ue),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${p?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:K>0?{marginLeft:K*20}:void 0,children:[K>0&&t.jsx("span",{className:"text-fg-quaternary text-[10px] shrink-0",children:"↳"}),t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[ue.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ue.title}),ce&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${ce.cls}`,children:ce.label})]}),ge.map(ve=>me(ve,K+1))]},ue.id)};return t.jsx("div",{className:"space-y-1.5",children:se.map(ue=>me(ue,0))})})():t.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:v("work:requirement.noLinkedTasks")})]}),!y&&t.jsx(Qh,{requirementId:e.id,createdBy:e.createdBy,agents:n,users:i,authUser:f}),!y&&t.jsx(kl,{entityType:"requirement",entityId:e.id})]}),T!=="none"&&T!=="top"&&t.jsx("button",{onClick:()=>_.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:v("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),T!=="none"&&T!=="bottom"&&t.jsx("button",{onClick:()=>{const te=_.current;te&&te.scrollTo({top:te.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:v("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[$&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>a(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:v("work:requirement.approveRequirement")}),t.jsx("button",{onClick:()=>c(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:v("work:requirement.rejectRequirement")})]}),!$&&d&&!V&&t.jsx("select",{value:e.status,onChange:te=>{te.target.value!==e.status&&d(e.id,te.target.value)},className:"px-2 py-1.5 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-secondary cursor-pointer hover:border-gray-500 transition-colors",children:Yh.map(te=>{const X=x[te],ie=te===e.status||(qs[e.status]?.has(te)??!1);return t.jsx("option",{value:te,disabled:!ie,children:X?.label??te},te)})}),V&&d&&t.jsx("button",{onClick:()=>d(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:v("work:task.reopen")}),t.jsx("div",{className:"flex-1"}),S&&!$&&t.jsx("button",{onClick:()=>z(!0),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:v("work:task.cancelRequirement")})]}),P&&t.jsx(Hn,{title:v("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:v("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:v("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{z(!1),l(e.id)},onCancel:()=>z(!1)}),j&&J&&t.jsx(Xh,{req:e,tasks:Z,agents:n,teamId:J,onClose:()=>O(!1),onSaved:()=>O(!1)})]})}function kl({entityType:e,entityId:n}){const{t:s}=We(["work"]),[r,i]=g.useState([]),[o,a]=g.useState(!0),[c,l]=g.useState(!1);if(g.useEffect(()=>{a(!0),(e==="task"?ae.tasks.getHistory:ae.requirements.getHistory)(n).then(u=>i(u.history)).catch(()=>i([])).finally(()=>a(!1))},[e,n]),o)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:s("work:task.loadingHistory","Loading history...")});if(r.length===0)return t.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:s("work:task.noHistory","No status change history.")});const d=c?r:r.slice(-5),h=r.length>5&&!c,f=m=>{const u=m.changedByName||m.changedById||(m.changedByType==="human"?"User":m.changedByType==="agent"?"Agent":"System"),p=m.changedByType==="human"?"bg-blue-500/20 text-blue-500":m.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${p}`,children:u})};return t.jsxs("div",{className:"px-6 py-4",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:s("work:task.statusHistory","Status History")}),h&&t.jsx("button",{onClick:()=>l(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:s("work:task.showAllHistory",{count:r.length})}),t.jsxs("div",{className:"relative ml-2",children:[t.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),t.jsx("div",{className:"space-y-3",children:d.map(m=>t.jsxs("div",{className:"flex items-start gap-3 relative",children:[t.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:m.changedByType==="human"?"#3b82f6":m.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[f(m),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:m.fromStatus}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:m.toStatus})]}),m.reason&&t.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:m.reason}),t.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(m.createdAt).toLocaleString()})]})]},m.id))})]})]})}export{sm as WorkPage};