@markus-global/cli 0.9.6 → 0.9.7-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/skill.d.ts +3 -0
  3. package/dist/commands/skill.d.ts.map +1 -0
  4. package/dist/commands/skill.js +148 -0
  5. package/dist/commands/skill.js.map +1 -0
  6. package/dist/commands/start.d.ts.map +1 -1
  7. package/dist/commands/start.js +17 -1
  8. package/dist/commands/start.js.map +1 -1
  9. package/dist/index.js +2 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/markus.mjs +5302 -2735
  12. package/dist/web-ui/assets/{CommentInput-CBNbViJY.js → CommentInput-Dvlq2svZ.js} +1 -1
  13. package/dist/web-ui/assets/{ContentRenderer-DE3pZgeX.js → ContentRenderer-BfnvpFM7.js} +2 -2
  14. package/dist/web-ui/assets/DeliverableShareModal-DkGpQmZ8.js +1 -0
  15. package/dist/web-ui/assets/Deliverables-CtPvquKO.js +3 -0
  16. package/dist/web-ui/assets/{Notifications-DnOdXHNc.js → Notifications-C_e9_V74.js} +1 -1
  17. package/dist/web-ui/assets/{Search-BxFLlgcf.js → Search-DZBGpN3c.js} +1 -1
  18. package/dist/web-ui/assets/Settings-6xm2sHhm.js +8 -0
  19. package/dist/web-ui/assets/{Store-BELkjEqO.js → Store-dbJSFCFw.js} +1 -1
  20. package/dist/web-ui/assets/Team-vmqHkmh8.js +81 -0
  21. package/dist/web-ui/assets/Work-Ds7q6pZg.js +11 -0
  22. package/dist/web-ui/assets/{arc-CyhYnNcy.js → arc-BLoofCdL.js} +1 -1
  23. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-BYIYNrCP.js → architectureDiagram-3BPJPVTR-BGO4nFRN.js} +1 -1
  24. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-Tj8Yz066.js → blockDiagram-GPEHLZMM-Cn1E0037.js} +1 -1
  25. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-Ifa4IAJa.js → c4Diagram-AAUBKEIU-DXFAnq3E.js} +1 -1
  26. package/dist/web-ui/assets/channel-Cw25sYRm.js +1 -0
  27. package/dist/web-ui/assets/{chunk-2J33WTMH-CNSbz4EK.js → chunk-2J33WTMH-BXCSmrWD.js} +1 -1
  28. package/dist/web-ui/assets/{chunk-4BX2VUAB-DhNtaIHh.js → chunk-4BX2VUAB-CIWJeena.js} +1 -1
  29. package/dist/web-ui/assets/{chunk-55IACEB6-WUpOSLP9.js → chunk-55IACEB6-BuQ5-tdz.js} +1 -1
  30. package/dist/web-ui/assets/{chunk-727SXJPM-BJV_Jz1H.js → chunk-727SXJPM-q9Yx_12l.js} +1 -1
  31. package/dist/web-ui/assets/{chunk-AQP2D5EJ-BHu_5o0Y.js → chunk-AQP2D5EJ-DqaehwKB.js} +1 -1
  32. package/dist/web-ui/assets/{chunk-FMBD7UC4-CfxugWTK.js → chunk-FMBD7UC4-BFs2IYjK.js} +1 -1
  33. package/dist/web-ui/assets/{chunk-ND2GUHAM-hIFBUDLZ.js → chunk-ND2GUHAM-DyYGWpbj.js} +1 -1
  34. package/dist/web-ui/assets/{chunk-QZHKN3VN-DF0OYrsG.js → chunk-QZHKN3VN-DmbA4AU_.js} +1 -1
  35. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-CDWjvgnK.js +1 -0
  36. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-CDWjvgnK.js +1 -0
  37. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-C3LM31P0.js → cose-bilkent-S5V4N54A-BLWm27gv.js} +1 -1
  38. package/dist/web-ui/assets/{dagre-BM42HDAG-C_m79Kes.js → dagre-BM42HDAG-Cb2YgHjF.js} +1 -1
  39. package/dist/web-ui/assets/{diagram-2AECGRRQ-D8liSSSE.js → diagram-2AECGRRQ-hMyyF4SK.js} +1 -1
  40. package/dist/web-ui/assets/{diagram-5GNKFQAL-DqtsU-bB.js → diagram-5GNKFQAL-DQvYRI_z.js} +1 -1
  41. package/dist/web-ui/assets/{diagram-KO2AKTUF-C6zkMDRo.js → diagram-KO2AKTUF-CPOv2Kga.js} +1 -1
  42. package/dist/web-ui/assets/{diagram-LMA3HP47-Dx2JnYqj.js → diagram-LMA3HP47-DvgOU39M.js} +1 -1
  43. package/dist/web-ui/assets/{diagram-OG6HWLK6-ZI_lN3Ui.js → diagram-OG6HWLK6-DhLJ9Bog.js} +1 -1
  44. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-DQ5VepuZ.js → erDiagram-TEJ5UH35-C4MKvJYc.js} +1 -1
  45. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-6GiDnWFL.js → flowDiagram-I6XJVG4X-C4KiUPBX.js} +1 -1
  46. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-D6HROKP8.js → ganttDiagram-6RSMTGT7-CFiAe8nx.js} +1 -1
  47. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-CXm0stFt.js → gitGraphDiagram-PVQCEYII-y6rZo1sT.js} +1 -1
  48. package/dist/web-ui/assets/index-BbQpGkiM.css +1 -0
  49. package/dist/web-ui/assets/index-CcppNtga.js +672 -0
  50. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-C1RxESvu.js → infoDiagram-5YYISTIA-LLlnmiVb.js} +1 -1
  51. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-K65PlAf9.js → ishikawaDiagram-YF4QCWOH-Brs-NT84.js} +1 -1
  52. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-_Rs_Vudv.js → journeyDiagram-JHISSGLW-um06-20P.js} +1 -1
  53. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-Jf6WnoNW.js → kanban-definition-UN3LZRKU-yws0Rgw8.js} +1 -1
  54. package/dist/web-ui/assets/{mermaid.core-C6jfI8lj.js → mermaid.core-C0Q8mcc_.js} +5 -5
  55. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-CuVR_m6C.js → mindmap-definition-RKZ34NQL-xCtHajk4.js} +1 -1
  56. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-BiPJBXLU.js → pieDiagram-4H26LBE5-BhKiwY7r.js} +1 -1
  57. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-C4hoAfNv.js → quadrantDiagram-W4KKPZXB-CGmxw13s.js} +1 -1
  58. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-BmjjjPuK.js → requirementDiagram-4Y6WPE33-CYJRHrZE.js} +1 -1
  59. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-ts7xFx2o.js → sankeyDiagram-5OEKKPKP-CgkdSCTc.js} +1 -1
  60. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-C3je_x5z.js → sequenceDiagram-3UESZ5HK-BD2dXCDe.js} +1 -1
  61. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-CREzVZ-3.js → stateDiagram-AJRCARHV-DdEvCrm2.js} +1 -1
  62. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-DKPteYMC.js +1 -0
  63. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-CriALCTC.js → timeline-definition-PNZ67QCA-CWfdKPN1.js} +1 -1
  64. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-Bc9NNe3M.js → vennDiagram-CIIHVFJN-BTiDdRt6.js} +1 -1
  65. package/dist/web-ui/assets/{wardley-L42UT6IY-psF9We_q.js → wardley-L42UT6IY-eDkltTBC.js} +1 -1
  66. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-DNZ9Jdgm.js → wardleyDiagram-YWT4CUSO-DLOZOKTX.js} +1 -1
  67. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-COezi66E.js → xychartDiagram-2RQKCTM6-RU8GlPu6.js} +1 -1
  68. package/dist/web-ui/index.html +2 -2
  69. package/package.json +2 -2
  70. package/templates/roles/{SHARED.md → HANDBOOK.md} +17 -7
  71. package/templates/roles/org-manager/ROLE.md +1 -5
  72. package/templates/roles/skill-architect/ROLE.md +1 -1
  73. package/templates/skills/agent-building/SKILL.md +109 -11
  74. package/templates/skills/skill-building/SKILL.md +61 -0
  75. package/templates/skills/team-building/SKILL.md +110 -4
  76. package/dist/web-ui/assets/Deliverables-Cx97uG2f.js +0 -6
  77. package/dist/web-ui/assets/Settings-D0i8Lnsk.js +0 -8
  78. package/dist/web-ui/assets/Team-D_C3tvWh.js +0 -80
  79. package/dist/web-ui/assets/Work-DpRdSwD5.js +0 -11
  80. package/dist/web-ui/assets/channel-B33xJsNY.js +0 -1
  81. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BePK-BYt.js +0 -1
  82. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BePK-BYt.js +0 -1
  83. package/dist/web-ui/assets/index-BMzsi3-i.js +0 -670
  84. package/dist/web-ui/assets/index-C9gwAZYM.css +0 -1
  85. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-CZU51KZ-.js +0 -1
@@ -1,11 +0,0 @@
1
- import{J as Bl,K as zl,H as Hl,L as ql,r as g,j as t,u as We,l as ae,O as Wl,a as vr,k as Vl,b as Fl,c as Yl,E as Gl,d as _s,P as Fe,w as jt,Q as _t,U as ys,F as Br,M as Zl,i as Kl,n as Bt,V as Hn,y as fr,W as Xl,A as Vs,X as _o,Y as As,Z as Ao,$ as Ls,a0 as Lo,a1 as Do,a2 as Po,a3 as Ua,a4 as Qa,a5 as Ul}from"./index-BMzsi3-i.js";import{ContentRenderer as Ql}from"./ContentRenderer-DE3pZgeX.js";import{s as gt,e as Ja,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 ei}from"./CommentInput-CBNbViJY.js";function ec(e){let n;for(;n=e.sourceEvent;)e=n;return e}function At(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 ti(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 ni(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 ri(){var e=nc,n=rc,s=sc,r=oc,i={},o=Ja("start","drag","end"),a=0,c,l,d,h,f=0;function m(b){b.on("mousedown.drag",u).filter(r).on("touchstart.drag",S).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=p(this,n.call(this,b,k),b,k,"mouse");N&&(gt(b.view).on("mousemove.drag",x,hr).on("mouseup.drag",M,hr),ti(b.view),js(b),d=!1,c=b.clientX,l=b.clientY,N("start",b))}}function x(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),ni(b.view,d),Fn(b),i.mouse("end",b)}function S(b,k){if(e.call(this,b,k)){var N=b.changedTouches,I=n.call(this,b,k),B=N.length,D,A;for(D=0;D<B;++D)(A=p(this,I,b,k,N[D].identifier,N[D]))&&(js(b),A("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 p(b,k,N,I,B,D){var A=o.copy(),E=At(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:A}),I))!=null)return P=j.x-E[0]||0,z=j.y-E[1]||0,function O(_,T,R){var L=E,q;switch(_){case"start":i[B]=O,q=a++;break;case"end":delete i[B],--a;case"drag":E=At(R||T,k),q=a;break}A.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]-L[0],dy:E[1]-L[1],dispatch:A}),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 $o(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,x=f-l,M=u*u+x*x,S,y;if(M<ac)y=Math.log(m/d)/n,S=function(I){return[c+I*u,l+I*x,d*Math.exp(n*I*y)]};else{var v=Math.sqrt(M),p=(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(p*p+1)-p),N=Math.log(Math.sqrt(b*b+1)-b);y=(N-k)/n,S=function(I){var B=I*y,D=$o(k),A=d/(s*v)*(D*lc(n*B+k)-ic(k));return[c+A*u,l+A*x,d*D/$o(n*B+k)]}}return S.duration=y*1e3*n/Math.SQRT2,S}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 Oo(){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 si(){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=Ja("start","zoom","end"),h,f,m,u=500,x=150,M=0,S=10;function y(j){j.property("__zoom",Oo).on("wheel.zoom",B,{passive:!1}).on("mousedown.zoom",D).on("dblclick.zoom",A).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",Oo),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,L=typeof O=="function"?O.apply(this,arguments):O;return R*L},_,T)},y.scaleTo=function(j,O,_,T){y.transform(j,function(){var R=n.apply(this,arguments),L=this.__zoom,q=_==null?b(R):typeof _=="function"?_.apply(this,arguments):_,Y=L.invert(q),F=typeof O=="function"?O.apply(this,arguments):O;return s(p(v(L,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 L=n.apply(this,arguments),q=this.__zoom,Y=T==null?b(L):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):-_),L,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 p(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,L=arguments,q=N(R,L).event(T),Y=n.apply(R,L),F=_==null?b(Y):typeof _=="function"?_.apply(R,L):_,Q=Math.max(Y[1][0]-Y[0][0],Y[1][1]-Y[0][1]),$=R.__zoom,C=typeof O=="function"?O.apply(R,L):O,V=l($.invert(F).concat(Q/$.k),C.invert(F).concat(Q/C.k));return function(W){if(W===1)W=C;else{var H=V(W),K=Q/H[2];W=new vs(K,F[0]-H[0]*K,F[1]-H[1]*K)}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)))),L=At(j);if(_.wheel)(_.mouse[0][0]!==L[0]||_.mouse[0][1]!==L[1])&&(_.mouse[1]=T.invert(_.mouse[0]=L)),clearTimeout(_.wheel);else{if(T.k===R)return;_.mouse=[L,T.invert(L)],ws(this),_.start()}lr(j),_.wheel=setTimeout(q,x),_.zoom("mouse",s(p(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),L=At(j,_),q=j.clientX,Y=j.clientY;ti(j.view),Ns(j),T.mouse=[L,this.__zoom.invert(L)],ws(this),T.start();function F($){if(lr($),!T.moved){var C=$.clientX-q,V=$.clientY-Y;T.moved=C*C+V*V>M}T.event($).zoom("mouse",s(p(T.that.__zoom,T.mouse[0]=At($,_),T.mouse[1]),T.extent,a))}function Q($){R.on("mousemove.zoom mouseup.zoom",null),ni($.view,T.moved),lr($),T.event($).end()}}function A(j,...O){if(e.apply(this,arguments)){var _=this.__zoom,T=At(j.changedTouches?j.changedTouches[0]:j,this),R=_.invert(T),L=_.k*(j.shiftKey?.5:2),q=s(p(v(_,L),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),L,q,Y,F;for(Ns(j),q=0;q<T;++q)Y=_[q],F=At(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,L=!0,R.taps=1+!!h);h&&(h=clearTimeout(h)),L&&(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,L,q,Y,F;for(lr(j),L=0;L<R;++L)q=T[L],Y=At(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],C=_.touch1[0],V=_.touch1[1],W=(W=C[0]-Q[0])*W+(W=C[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]+C[0])/2,(Q[1]+C[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(p(q,Y,F),_.extent,a))}}function z(j,...O){if(this.__zooming){var _=N(this,O).event(j),T=j.changedTouches,R=T.length,L,q;for(Ns(j),m&&clearTimeout(m),m=setTimeout(function(){m=null},u),L=0;L<R;++L)q=T[L],_.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=At(q,this),Math.hypot(f[0]-q[0],f[1]-q[1])<S)){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?(S=+j,y):S},y}function Ke(e){if(typeof e=="string"||typeof e=="number")return""+e;let n="";if(Array.isArray(e))for(let s=0,r;s<e.length;s++)(r=Ke(e[s]))!==""&&(n+=(n&&" ")+r);else for(let s in e)e[s]&&(n+=(n&&" ")+s);return n}const 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]],oi=["Enter"," ","Escape"],ai={"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 ii={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 Bo={[be.Left]:be.Right,[be.Right]:be.Left,[be.Top]:be.Bottom,[be.Bottom]:be.Top};function li(e){return e===null?null:e?"valid":"invalid"}const ci=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,x=h.height??d.height??d.initialHeight??null,M=pr(c,Kn(d)),S=(u??0)*(x??0),y=o&&M>0;(!d.internals.handleBounds||y||M>=S||d.dragging)&&l.push(d)}return l},xc=(e,n)=>{const s=new Set;return e.forEach(r=>{s.add(r.id)}),n.filter(r=>s.has(r.source)||s.has(r.target))};function bc(e,n){const s=new Map,r=n?.nodes?new Set(n.nodes.map(i=>i.id)):null;return e.forEach(i=>{i.measured.width&&i.measured.height&&(n?.includeHiddenNodes||!i.hidden)&&(!r||r.has(i.id))&&s.set(i.id,i)}),s}async function yc({nodes:e,width:n,height:s,panZoom:r,minZoom:i,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const c=bc(e,a),l=kr(c),d=Zs(l,n,s,a?.minZoom??i,a?.maxZoom??o,a?.padding??.1);return await r.setViewport(d,{duration:a?.duration,ease:a?.ease,interpolate:a?.interpolate}),Promise.resolve(!0)}function di({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,x=c.measured.height;u&&x&&(f=[[l,d],[l+u,d+x]])}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),x=!u&&m.parentId&&a.find(M=>M.id===m.parentId);(u||x)&&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(x=>x.id===m.id)&&h.push(m);if(!i)return{edges:h,nodes:a};const f=await i({nodes:a,edges:h});return typeof f=="boolean"?f?{edges:h,nodes:a}:{edges:[],nodes:[]}:f}const Zn=(e,n=0,s=1)=>Math.min(Math.max(e,n),s),Sn=(e={x:0,y:0},n,s)=>({x:Zn(e.x,n[0][0],n[1][0]-(s?.width??0)),y:Zn(e.y,n[0][1],n[1][1]-(s?.height??0))});function ui(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 zo=(e,n,s)=>e<n?Zn(Math.abs(e-n),1,n)/n:e>s?-Zn(Math.abs(e-s),1,n)/n:0,fi=(e,n,s=15,r=40)=>{const i=zo(e.x,r,n.width-r)*s,o=zo(e.y,r,n.height-r)*s;return[i,o]},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}),Kn=(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)}},hi=(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)},Ho=e=>Lt(e.width)&&Lt(e.height)&&Lt(e.x)&&Lt(e.y),Lt=e=>!isNaN(e)&&isFinite(e),wc=(e,n)=>{},jr=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),Nr=({x:e,y:n},[s,r,i],o=!1,a=[1,1])=>{const c={x:(e-s)/i,y:(n-r)/i};return o?jr(c,a):c},ts=({x:e,y:n},[s,r,i])=>({x:e*i+s,y:n*i+r});function zn(e,n){if(typeof e=="number")return Math.floor((n-n/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const s=parseFloat(e);if(!Number.isNaN(s))return Math.floor(s)}if(typeof e=="string"&&e.endsWith("%")){const s=parseFloat(e);if(!Number.isNaN(s))return Math.floor(n*s*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function kc(e,n,s){if(typeof e=="string"||typeof e=="number"){const r=zn(e,s),i=zn(e,n);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=zn(e.top??e.y??0,s),i=zn(e.bottom??e.y??0,s),o=zn(e.left??e.x??0,n),a=zn(e.right??e.x??0,n);return{top:r,right:a,bottom:i,left:o,x:o+a,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function jc(e,n,s,r,i,o){const{x:a,y:c}=ts(e,[n,s,r]),{x:l,y:d}=ts({x:e.x+e.width,y:e.y+e.height},[n,s,r]),h=i-l,f=o-d;return{left:Math.floor(a),top:Math.floor(c),right:Math.floor(h),bottom:Math.floor(f)}}const Zs=(e,n,s,r,i,o)=>{const a=kc(o,n,s),c=(n-a.x)/e.width,l=(s-a.y)/e.height,d=Math.min(c,l),h=Zn(d,r,i),f=e.x+e.width/2,m=e.y+e.height/2,u=n/2-f*h,x=s/2-m*h,M=jc(e,u,x,h,n,s),S={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-S.left+S.right,y:x-S.top+S.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 mi(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function gi(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 qo(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{...ai,...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 Ks=e=>({width:e.offsetWidth,height:e.offsetHeight}),pi=e=>e?.getRootNode?.()||window?.document,Sc=["INPUT","SELECT","TEXTAREA"];function xi(e){const n=e.composedPath?.()?.[0]||e.target;return n?.nodeType!==1?!1:Sc.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const bi=e=>"clientX"in e,Dt=(e,n)=>{const s=bi(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)}},Wo=(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,...Ks(a)}})};function yi({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 Vo({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 vi({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top,curvature:a=.25}){const[c,l]=Vo({pos:s,x1:e,y1:n,x2:r,y2:i,c:a}),[d,h]=Vo({pos:o,x1:r,y1:i,x2:e,y2:n,c:a}),[f,m,u,x]=yi({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,x]}function wi({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 ci(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 ki({sourceX:e,sourceY:n,targetX:s,targetY:r}){const[i,o,a,c]=wi({sourceX:e,sourceY:n,targetX:s,targetY:r});return[`M ${e},${n}L ${s},${r}`,i,o,a,c]}const Fo={[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},Yo=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function Ac({source:e,sourcePosition:n=be.Bottom,target:s,targetPosition:r=be.Top,center:i,offset:o,stepPosition:a}){const c=Fo[n],l=Fo[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 x=[],M,S;const y={x:0,y:0},v={x:0,y:0},[,,p,b]=wi({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,S=i.y??(d.y+h.y)/2):(M=i.x??(d.x+h.x)/2,S=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:S},{x:h.x,y:S}];c[m]===u?x=m==="x"?N:I:x=m==="x"?I:N}else{const N=[{x:d.x,y:h.y}],I=[{x:h.x,y:d.y}];if(m==="x"?x=c.x===u?I:N:x=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))&&(x=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},A=Math.max(Math.abs(B.x-x[0].x),Math.abs(D.x-x[0].x)),E=Math.max(Math.abs(B.y-x[0].y),Math.abs(D.y-x[0].y));A>=E?(M=(B.x+D.x)/2,S=x[0].y):(M=x[0].x,S=(B.y+D.y)/2)}return[[e,{x:d.x+y.x,y:d.y+y.y},...x,{x:h.x+v.x,y:h.y+v.y},s],M,S,p,b]}function Lc(e,n,s,r){const i=Math.min(Yo(e,n)/2,Yo(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,x,M]=Ac({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,p)=>{let b="";return p>0&&p<f.length-1?b=Lc(f[p-1],v,f[p+1],a):b=`${p===0?"M":"L"}${v.x} ${v.y}`,y+=b,y},""),m,u,x,M]}function Go(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(!Go(n)||!Go(s))return null;const r=n.internals.handleBounds||Zo(n.handles),i=s.internals.handleBounds||Zo(s.handles),o=Ko(r?.source??[],e.sourceHandle),a=Ko(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 Ko(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 ji=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)?ji: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:Ni(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)?ji:0,{x:m,y:u,z:x}=qc(e,h,a,c,f,l),{positionAbsolute:M}=e.internals,S=m!==M.x||u!==M.y;(S||x!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:S?{x:m,y:u}:M,z:x}})}function Ni(e,n,s){const r=Lt(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=ui(f,l,n));const m=Ni(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??Kn(c),d=hi(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,x=Math.max(h.width,Math.round(a.width)),M=Math.max(h.height,Math.round(a.height)),S=(x-h.width)*f[0],y=(M-h.height)*f[1];(m>0||u>0||S||y)&&(i.push({id:l,type:"position",position:{x:c.position.x-m+S,y:c.position.y-u+y}}),s.get(l)?.forEach(v=>{e.some(p=>p.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:x+(m?f[0]*m-S: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 x=n.get(u.id);if(!x)continue;if(x.hidden){n.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),l=!0;continue}const M=Ks(u.nodeElement),S=x.measured.width!==M.width||x.measured.height!==M.height;if(!!(M.width&&M.height&&(S||!x.internals.handleBounds||u.force))){const v=u.nodeElement.getBoundingClientRect(),p=Xn(x.extent)?x.extent:o;let{positionAbsolute:b}=x.internals;x.parentId&&x.extent==="parent"?b=ui(b,M,n.get(x.parentId)):p&&(b=Sn(b,p,M));const k={...x,measured:M,internals:{...x.internals,positionAbsolute:b,handleBounds:{source:Wo("source",u.nodeElement,v,f,x.id),target:Wo("target",u.nodeElement,v,f,x.id)}}};n.set(x.id,k),x.parentId&&Js(k,n,s,{nodeOrigin:i,zIndexMode:a}),l=!0,S&&(d.push({id:x.id,type:"dimensions",dimensions:M}),x.expandParent&&x.parentId&&m.push({id:x.id,parentId:x.parentId,rect:Kn(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 Xo(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 Ci(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}`;Xo("source",l,h,e,i,a),Xo("target",l,d,e,o,c),n.set(r.id,r)}}function Si(e,n){if(!e.parentId)return!1;const s=n.get(e.parentId);return s?s.selected?!0:Si(s,n):!1}function Uo(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||!Si(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,x=!1,M=null;function S({noDragClassName:v,handleSelector:p,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:L,onSelectionDrag:q,onError:Y,updateNodePositions:F}=n();o={x:P,y:z};let Q=!1;const $=c.size>1,C=$&&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 K={x:P-H.distance.x,y:z-H.distance.y};T&&(K=V?{x:Math.round(K.x+V.x),y:Math.round(K.y+V.y)}:jr(K,_));let J=null;if($&&O&&!H.extent&&C){const{positionAbsolute:X}=H.internals,ie=X.x-C.x+O[0][0],de=X.x+H.measured.width-C.x2+O[1][0],se=X.y-C.y+O[0][1],me=X.y+H.measured.height-C.y2+O[1][1];J=[[ie,se],[de,me]]}const{position:le,positionAbsolute:te}=di({nodeId:W,nextPosition:K,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(x=x||Q,!!Q&&(F(c,!0),M&&(r||L||!N&&q))){const[W,H]=Cs({nodeId:N,dragItems:c,nodeLookup:j});r?.(M,c,W,H),L?.(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]=fi(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 A(P){const{nodeLookup:z,multiSelectionActive:j,nodesDraggable:O,transform:_,snapGrid:T,snapToGrid:R,selectNodesOnDrag:L,onNodeDragStart:q,onSelectionDragStart:Y,unselectNodesAndEdges:F}=n();f=!0,(!L||!k)&&!j&&N&&(z.get(N)?.selected||F()),k&&L&&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[$,C]=Cs({nodeId:N,dragItems:c,nodeLookup:z});s?.(P.sourceEvent,c,$,C),q?.(P.sourceEvent,$,C),N||Y?.(P.sourceEvent,C)}}const E=ri().clickDistance(I).on("start",P=>{const{domNode:z,nodeDragThreshold:j,transform:O,snapGrid:_,snapToGrid:T}=n();h=z?.getBoundingClientRect()||null,u=!1,x=!1,M=P.sourceEvent,j===0&&A(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(),L=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&&A(P)}(o.x!==L.xSnapped||o.y!==L.ySnapped)&&c&&f&&(d=Dt(P.sourceEvent,h),B(L))}}).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(x&&(j(c,!1),x=!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||!Uo(z,`.${v}`,b))&&(!p||Uo(z,p,b))});m.call(E)}function y(){m?.on(".drag",null)}return{update:S,destroy:y}}function Zc(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,Kn(o))>0&&r.push(o);return r}const Kc=250;function Xc(e,n,s,r){let i=[],o=1/0;const a=Zc(e,s,n+Kc);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 Ei(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 Mi(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 Ii=()=>!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:x,onConnect:M,onConnectEnd:S,isValidConnection:y=Ii,onReconnectEnd:v,updateConnection:p,getTransform:b,getFromHandle:k,autoPanSpeed:N,dragThreshold:I=1,handleDomNode:B}){const D=pi(e.target);let A=0,E;const{x:P,y:z}=Dt(e),j=Mi(o,B),O=c?.getBoundingClientRect();let _=!1;if(!O||!j)return;const T=Ei(i,j,r,l,n);if(!T)return;let R=Dt(e,O),L=!1,q=null,Y=!1,F=null;function Q(){if(!h||!O)return;const[le,te]=fi(R,O,N);m({x:le,y:te}),A=requestAnimationFrame(Q)}const $={...T,nodeId:i,type:j,position:T.position},C=l.get(i);let W={inProgress:!0,isValid:null,from:En(C,$,be.Left,!0),fromHandle:$,fromPosition:$.position,fromNode:C,to:R,toHandle:null,toPosition:Bo[$.position],toNode:null,pointer:R};function H(){_=!0,p(W),x?.(e,{nodeId:i,handleId:r,handleType:j})}I===0&&H();function K(le){if(!_){const{x:me,y:ue}=Dt(le),Z=me-P,ce=ue-z;if(!(Z*Z+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,$),L||(Q(),L=!0);const X=Ti(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:Bo[$.position],toNode:X.toHandle?l.get(X.toHandle.nodeId):null,pointer:R};p(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};S?.(le,ie),o&&v?.(le,ie)}u(),cancelAnimationFrame(A),L=!1,Y=!1,q=null,F=null,D.removeEventListener("mousemove",K),D.removeEventListener("mouseup",J),D.removeEventListener("touchmove",K),D.removeEventListener("touchend",J)}}D.addEventListener("mousemove",K),D.addEventListener("mouseup",J),D.addEventListener("touchmove",K),D.addEventListener("touchend",J)}function Ti(e,{handle:n,connectionMode:s,fromNodeId:r,fromHandleId:i,fromType:o,doc:a,lib:c,flowId:l,isValidConnection:d=Ii,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:x}=Dt(e),M=a.elementFromPoint(u,x),S=M?.classList.contains(`${c}-flow__handle`)?M:m,y={handleDomNode:S,isValid:!1,connection:null,toHandle:null};if(S){const v=Mi(void 0,S),p=S.getAttribute("data-nodeid"),b=S.getAttribute("data-handleid"),k=S.classList.contains("connectable"),N=S.classList.contains("connectableend");if(!p||!v)return y;const I={source:f?p:r,sourceHandle:f?b:i,target:f?r:p,targetHandle:f?i:b};y.connection=I;const D=k&&N&&(s===Yn.Strict?f&&v==="source"||!f&&v==="target":p!==r||b!==i);y.isValid=D&&d(I),y.toHandle=Ei(p,v,b,h,s,!0)}return y}const zs={onPointerDown:Qc,isValid:Ti};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 x=p=>{if(p.sourceEvent.type!=="wheel"||!n)return;const b=s(),k=p.sourceEvent.ctrlKey&&xr()?10:1,N=-p.sourceEvent.deltaY*(p.sourceEvent.deltaMode===1?.05:p.sourceEvent.deltaMode?1:.002)*h,I=b[2]*Math.pow(2,N*k);n.scaleTo(I)};let M=[0,0];const S=p=>{(p.sourceEvent.type==="mousedown"||p.sourceEvent.type==="touchstart")&&(M=[p.sourceEvent.clientX??p.sourceEvent.touches[0].clientX,p.sourceEvent.clientY??p.sourceEvent.touches[0].clientY])},y=p=>{const b=s();if(p.sourceEvent.type!=="mousemove"&&p.sourceEvent.type!=="touchmove"||!n)return;const k=[p.sourceEvent.clientX??p.sourceEvent.touches[0].clientX,p.sourceEvent.clientY??p.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=si().on("start",S).on("zoom",f?y:null).on("zoom.wheel",m?x:null);i.call(v,{})}function a(){i.on("zoom",null)}return{update:o,destroy:a,pointer:At}}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}`),Ri=(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},_i=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 S=At(h),y=_i(h),v=f*Math.pow(2,y);r.scaleTo(s,v,S,h);return}const m=h.deltaMode===1?20:1;let u=i===Cn.Vertical?0:h.deltaX*m,x=i===Cn.Horizontal?0:h.deltaY*m;!xr()&&h.shiftKey&&i!==Cn.Vertical&&(u=h.deltaY*m,x=0),r.translateBy(s,-(u/f)*o,-(x/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&&Ri(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&&Ri(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,x=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&&!x||qn(f,c)&&x||qn(f,l)&&(!x||i&&x&&!e)||!s&&f.ctrlKey&&x)return!1;if(!s&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!m&&!i&&!u&&x||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const M=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||x)&&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=si().scaleExtent([n,s]).translateExtent(r),m=gt(e).call(f);v({x:i.x,y:i.y,zoom:Zn(i.zoom,n,s)},[[0,0],[h.width,h.height]],r);const u=m.on("wheel.zoom"),x=m.on("dblclick.zoom");f.wheelDelta(_i);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 S({noWheelClassName:E,noPanClassName:P,onPaneContextMenu:z,userSelectionActive:j,panOnScroll:O,panOnDrag:_,panOnScrollMode:T,panOnScrollSpeed:R,preventScrolling:L,zoomOnPinch:q,zoomOnScroll:Y,zoomOnDoubleClick:F,zoomActivationKeyPressed:Q,lib:$,onTransformChange:C,connectionInProgress:V,paneClickDistance:W,selectionOnDrag:H}){j&&!d.isZoomingOrPanning&&y();const K=O&&!Q&&!j;f.clickDistance(H?1/0:!Lt(W)||W<0?0:W);const J=K?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:L,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:C});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",x):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 p(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 A(E){const P=!Lt(E)||E<0?0:E;f?.clickDistance(P)}return{update:S,destroy:y,setViewport:p,setViewportConstrained:v,getViewport:k,scaleTo:N,scaleBy:I,setScaleExtent:B,setTranslateExtent:D,syncViewport:b,setClickDistance:A}}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 Qo(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 Jo(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:x}=s,{minWidth:M,maxWidth:S,minHeight:y,maxHeight:v}=r,{x:p,y:b,width:k,height:N,aspectRatio:I}=e;let B=Math.floor(h?u-e.pointerX:0),D=Math.floor(f?x-e.pointerY:0);const A=k+(l?-B:B),E=N+(d?-D:D),P=-o[0]*k,z=-o[1]*N;let j=Wr(A,M,S),O=Wr(E,y,v);if(a){let R=0,L=0;l&&B<0?R=on(p+B+P,a[0][0]):!l&&B>0&&(R=an(p+A+P,a[1][0])),d&&D<0?L=on(b+D+z,a[0][1]):!d&&D>0&&(L=an(b+E+z,a[1][1])),j=Math.max(j,R),O=Math.max(O,L)}if(c){let R=0,L=0;l&&B>0?R=an(p+B,c[0][0]):!l&&B<0&&(R=on(p+A,c[1][0])),d&&D>0?L=an(b+D,c[0][1]):!d&&D<0&&(L=on(b+E,c[1][1])),j=Math.max(j,R),O=Math.max(O,L)}if(i){if(h){const R=Wr(A/I,y,v)*I;if(j=Math.max(j,R),a){let L=0;!l&&!d||l&&!d&&m?L=an(b+z+A/I,a[1][1])*I:L=on(b+z+(l?B:-B)/I,a[0][1])*I,j=Math.max(j,L)}if(c){let L=0;!l&&!d||l&&!d&&m?L=on(b+A/I,c[1][1])*I:L=an(b+(l?B:-B)/I,c[0][1])*I,j=Math.max(j,L)}}if(f){const R=Wr(E*I,M,S)/I;if(O=Math.max(O,R),a){let L=0;!l&&!d||d&&!l&&m?L=an(p+E*I+P,a[1][0])/I:L=on(p+(d?D:-D)*I+P,a[0][0])/I,O=Math.max(O,L)}if(c){let L=0;!l&&!d||d&&!l&&m?L=on(p+E*I,c[1][0])/I:L=an(p+(d?D:-D)*I,c[0][0])/I,O=Math.max(O,L)}}}D=D+(D<0?O:-O),B=B+(B<0?j:-j),i&&(m?A>E*I?D=(Jo(l,d)?-B:B)/I:B=(Jo(l,d)?-D:D)*I:h?(D=B/I,d=l):(B=D*I,l=d));const _=l?p+B:p,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:Qo("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:x,onResizeEnd:M,shouldResize:S}){let y={...Ai},v={...dd};a={boundaries:h,resizeDirection:m,keepAspectRatio:f,controlDirection:Qo(d)};let p,b=null,k=[],N,I,B,D=!1;const A=ri().on("start",E=>{const{nodeLookup:P,transform:z,snapGrid:j,snapToGrid:O,nodeOrigin:_,paneDomNode:T}=s();if(p=P.get(n),!p)return;b=T?.getBoundingClientRect()??null;const{xSnapped:R,ySnapped:L}=dr(E.sourceEvent,{transform:z,snapGrid:j,snapToGrid:O,containerBounds:b});y={width:p.measured.width??0,height:p.measured.height??0,x:p.position.x??0,y:p.position.y??0},v={...y,pointerX:R,pointerY:L,aspectRatio:y.width/y.height},N=void 0,p.parentId&&(p.extent==="parent"||p.expandParent)&&(N=P.get(p.parentId),I=N&&p.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,p,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(!p)return;const{x:R,y:L,width:q,height:Y}=y,F={},Q=p.origin??O,{width:$,height:C,x:V,y:W}=cd(v,a.controlDirection,_,a.boundaries,a.keepAspectRatio,Q,I,B),H=$!==q,K=C!==Y,J=V!==R&&H,le=W!==L&&K;if(!J&&!le&&!H&&!K)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-L;for(const me of k)me.position={x:me.position.x-de+Q[0]*($-q),y:me.position.y-se+Q[1]*(C-Y)},T.push(me)}if((H||K)&&(F.width=H&&(!a.resizeDirection||a.resizeDirection==="horizontal")?$:y.width,F.height=K&&(!a.resizeDirection||a.resizeDirection==="vertical")?C:y.height,y.width=F.width,y.height=F.height),N&&p.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};S?.(E,X)!==!1&&(D=!0,x?.(E,X),r(F,T))}).on("end",E=>{D&&(M?.(E,{...y}),i?.({...y}),D=!1)});o.call(A)}function l(){o.on(".drag",null)}return{update:c,destroy:l}}var Ms={exports:{}},Is={};var ea;function md(){if(ea)return Is;ea=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 x=o(null);if(x.current===null){var M={hasValue:!1,value:null};x.current=M}else M=x.current;x=c(function(){function y(N){if(!v){if(v=!0,p=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(p,N))return I;var B=m(N);return u!==void 0&&u(I,B)?(p=N,I):(p=N,b=B)}var v=!1,p,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 S=i(d,x[0],x[1]);return a(function(){M.hasValue=!0,M.value=S},[S]),l(S),S},Is}var ta;function gd(){return ta||(ta=1,Ms.exports=md()),Ms.exports}var pd=gd();const xd=Hl(pd),bd={},na=e=>{let n;const s=new Set,r=(h,f)=>{const m=typeof h=="function"?h(n):h;if(!Object.is(m,n)){const u=n;n=f??(typeof m!="object"||m===null)?m:Object.assign({},n,m),s.forEach(x=>x(n,u))}},i=()=>n,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?na(e):na,{useDebugValue:vd}=ql,{useSyncExternalStoreWithSelector:wd}=xd,kd=e=>e;function Li(e,n=kd,s){const r=wd(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,s);return vd(r),r}const ra=(e,n)=>{const s=yd(e),r=(i,o=n)=>Li(s,i,o);return Object.assign(r,s),r},jd=(e,n)=>e?ra(e,n):ra;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,Di=zt.error001();function Ie(e,n){const s=g.useContext(cs);if(s===null)throw new Error(Di);return Li(s,e,n)}function Be(){const e=g.useContext(cs);if(e===null)throw new Error(Di);return g.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const sa={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%)"},Pi="react-flow__node-desc",$i="react-flow__edge-desc",Sd="react-flow__aria-live",Ed=e=>e.ariaLiveMessage,Md=e=>e.ariaLabelConfig;function Id({rfId:e}){const n=Ie(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=Ie(Md);return t.jsxs(t.Fragment,{children:[t.jsx("div",{id:`${Pi}-${e}`,style:sa,children:n?s["node.a11yDescription.default"]:s["node.a11yDescription.keyboardDisabled"]}),t.jsx("div",{id:`${$i}-${e}`,style:sa,children:s["edge.a11yDescription.default"]}),!n&&t.jsx(Id,{rfId:e})]})}const ds=g.forwardRef(({position:e="top-left",children:n,className:s,style:r,...i},o)=>{const a=`${e}`.split("-");return t.jsx("div",{className:Ke(["react-flow__panel",s,...a]),style:r,ref:o,...i,children:n})});ds.displayName="Panel";function Rd({proOptions:e,position:n="bottom-right"}){return e?.hideAttribution?null:t.jsx(ds,{position:n,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:t.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const _d=e=>{const n=[],s=[];for(const[,r]of e.nodeLookup)r.selected&&n.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&s.push(r);return{selectedNodes:n,selectedEdges:s}},Vr=e=>e.id;function Ad(e,n){return qe(e.selectedNodes.map(Vr),n.selectedNodes.map(Vr))&&qe(e.selectedEdges.map(Vr),n.selectedEdges.map(Vr))}function Ld({onSelectionChange:e}){const n=Be(),{selectedNodes:s,selectedEdges:r}=Ie(_d,Ad);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=Ie(Dd);return e||n?t.jsx(Ld,{onSelectionChange:e}):null}const Oi=[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"],oa=[...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}),aa={translateExtent:mr,nodeOrigin:Oi,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}=Ie(Bd,qe),d=Be();g.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{h.current=aa,c()}),[]);const h=g.useRef(aa);return g.useEffect(()=>{for(const f of oa){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},oa.map(f=>e[f])),null}function ia(){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=ia(),i=()=>s(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),n!==null?n:ia()?.matches?"dark":"light"}const la=typeof document<"u"?document:null;function br(e=null,n={target:la,actInsideInputWithModifier:!0}){const[s,r]=g.useState(!1),i=g.useRef(!1),o=g.useRef(new Set([])),[a,c]=g.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
2
- `).replace(`
3
-
4
- `,`
5
- +`).split(`
6
- `)),h=d.reduce((f,m)=>f.concat(...m),[]);return[d,h]}return[[],[]]},[e]);return g.useEffect(()=>{const l=n?.target??la,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)&&xi(u))return!1;const M=da(u.code,c);if(o.current.add(u[M]),ca(a,o.current,!1)){const S=u.composedPath?.()?.[0]||u.target,y=S?.nodeName==="BUTTON"||S?.nodeName==="A";n.preventDefault!==!1&&(i.current||!y)&&u.preventDefault(),r(!0)}},f=u=>{const x=da(u.code,c);ca(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(u[x]),u.key==="Meta"&&o.current.clear(),i.current=!1},m=()=>{o.current.clear(),r(!1)};return 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 ca(e,n,s){return e.filter(r=>s||r.length===n.size).some(r=>r.every(i=>n.has(i)))}function da(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=Zs(n,r,i,o,a,s?.padding??.1);return c?(await c.setViewport(l,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(n,s={})=>{const{transform:r,snapGrid:i,snapToGrid:o,domNode:a}=e.getState();if(!a)return n;const{x:c,y:l}=a.getBoundingClientRect(),d={x:n.x-c,y:n.y-l},h=s.snapGrid??i,f=s.snapToGrid??o;return Nr(d,r,f,h)},flowToScreenPosition:n=>{const{transform:s,domNode:r}=e.getState();if(!r)return n;const{x:i,y:o}=r.getBoundingClientRect(),a=ts(n,s);return{x:a.x+i,y:a.y+o}}}),[])};function Bi(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 zi(e,n){return Bi(e,n)}function Hi(e,n){return Bi(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 ua({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 fa(e){return{id:e.id,type:"remove"}}const ha=e=>gc(e),Vd=e=>ci(e);function qi(e){return g.forwardRef(e)}const Fd=typeof window<"u"?g.useLayoutEffect:g.useEffect;function ma(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 Wi=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:x}=n.getState();let M=l;for(const y of c)M=typeof y=="function"?y(M):y;let S=ua({items:M,lookup:m});for(const y of x.values())S=y(S);h&&d(M),S.length>0?f?.(S):u&&window.requestAnimationFrame(()=>{const{fitViewQueued:y,nodes:v,setNodes:p}=n.getState();y&&p(v)})},[]),r=ma(s),i=g.useCallback(c=>{const{edges:l=[],setEdges:d,hasDefaultEdges:h,onEdgesChange:f,edgeLookup:m}=n.getState();let u=l;for(const x of c)u=typeof x=="function"?x(u):x;h?d(u):f&&f(ua({items:u,lookup:m}))},[]),o=ma(i),a=g.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return t.jsx(Wi.Provider,{value:a,children:e})}function Zd(){const e=g.useContext(Wi);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Kd=e=>!!e.panZoom;function to(){const e=qd(),n=Be(),s=Zd(),r=Ie(Kd),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(),x=ha(f)?f:m.get(f.id),M=x.parentId?gi(x.position,x.measured,x.parentId,m,u):x.position,S={...x,position:M,width:x.measured?.width??x.width,height:x.measured?.height??x.height};return Kn(S)},d=(f,m,u={replace:!1})=>{a(x=>x.map(M=>{if(M.id===f){const S=typeof m=="function"?m(M):m;return u.replace&&ha(S)?S:{...M,...S}}return M}))},h=(f,m,u={replace:!1})=>{c(x=>x.map(M=>{if(M.id===f){const S=typeof m=="function"?m(M):m;return u.replace&&Vd(S)?S:{...M,...S}}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(),[x,M,S]=u;return{nodes:f.map(y=>({...y})),edges:m.map(y=>({...y})),viewport:{x,y:M,zoom:S}}},deleteElements:async({nodes:f=[],edges:m=[]})=>{const{nodes:u,edges:x,onNodesDelete:M,onEdgesDelete:S,triggerNodeChanges:y,triggerEdgeChanges:v,onDelete:p,onBeforeDelete:b}=n.getState(),{nodes:k,edges:N}=await vc({nodesToRemove:f,edgesToRemove:m,nodes:u,edges:x,onBeforeDelete:b}),I=N.length>0,B=k.length>0;if(I){const D=N.map(fa);S?.(N),v(D)}if(B){const D=k.map(fa);M?.(k),y(D)}return(B||I)&&p?.({nodes:k,edges:N}),{deletedNodes:k,deletedEdges:N}},getIntersectingNodes:(f,m=!0,u)=>{const x=Ho(f),M=x?f:l(f),S=u!==void 0;return M?(u||n.getState().nodes).filter(y=>{const v=n.getState().nodeLookup.get(y.id);if(v&&!x&&(y.id===f.id||!v.internals.positionAbsolute))return!1;const p=Kn(S?y:v),b=pr(p,M);return m&&b>0||b>=p.width*p.height||b>=M.width*M.height}):[]},isNodeIntersecting:(f,m,u=!0)=>{const M=Ho(f)?f:l(f);if(!M)return!1;const S=pr(M,m);return u&&S>0||S>=m.width*m.height||S>=M.width*M.height},updateNode:d,updateNodeData:(f,m,u={replace:!1})=>{d(f,x=>{const M=typeof m=="function"?m(x):m;return u.replace?{...x,data:M}:{...x,data:{...x.data,...M}}},u)},updateEdge:h,updateEdgeData:(f,m,u={replace:!1})=>{h(f,x=>{const M=typeof m=="function"?m(x):m;return u.replace?{...x,data:M}:{...x,data:{...x.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 ga=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(ga),edges:a.filter(ga)}),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=Ks(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:x,noWheelClassName:M,noPanClassName:S,onViewportChange:y,isControlledViewport:v,paneClickDistance:p,selectionOnDrag:b}){const k=Be(),N=g.useRef(null),{userSelectionActive:I,lib:B,connectionInProgress:D}=Ie(Jd,qe),A=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:L}=k.getState();L?.(_,T),R?.(T)},onPanZoom:(_,T)=>{const{onViewportChange:R,onMove:L}=k.getState();L?.(_,T),R?.(T)},onPanZoomEnd:(_,T)=>{const{onViewportChangeEnd:R,onMoveEnd:L}=k.getState();L?.(_,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:A,preventScrolling:u,noPanClassName:S,userSelectionActive:I,noWheelClassName:M,lib:B,onTransformChange:P,connectionInProgress:D,selectionOnDrag:b,paneClickDistance:p})},[e,n,s,r,i,o,a,c,A,u,S,I,M,B,P,D,b,p]),t.jsx("div",{className:"react-flow__renderer",ref:N,style:us,children:x})}const tu=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function nu(){const{userSelectionActive:e,userSelectionRect:n}=Ie(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:x}){const M=Be(),{userSelectionActive:S,elementsSelectable:y,dragging:v,connectionInProgress:p}=Ie(ru,qe),b=y&&(e||S),k=g.useRef(null),N=g.useRef(),I=g.useRef(new Set),B=g.useRef(new Set),D=g.useRef(!1),A=R=>{if(D.current||p){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:L}=M.getState();if(N.current=L?.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:L,transform:q,nodeLookup:Y,edgeLookup:F,connectionLookup:Q,triggerNodeChanges:$,triggerEdgeChanges:C,defaultEdgeOptions:V,resetSelectedElements:W}=M.getState();if(!N.current||!L)return;const{x:H,y:K}=Dt(R.nativeEvent,N.current),{startX:J,startY:le}=L;if(!D.current){const se=n?0:i;if(Math.hypot(H-J,K-le)<=se)return;W(),a?.(R)}D.current=!0;const te={startX:J,startY:le,x:H<J?H:J,y:K<le?K:le,width:Math.abs(H-J),height:Math.abs(K-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 Z=F.get(ue);Z&&(Z.selectable??de)&&B.current.add(ue)}}if(!qo(X,I.current)){const se=Wn(Y,I.current,!0);$(se)}if(!qo(ie,B.current)){const se=Wn(F,B.current);C(se)}M.setState({userSelectionRect:te,userSelectionActive:!0,nodesSelectionActive:!1})},_=R=>{R.button===0&&(R.target?.releasePointerCapture?.(R.pointerId),!S&&R.target===k.current&&M.getState().userSelectionRect&&A?.(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:Ke(["react-flow__pane",{draggable:T,dragging:v,selection:e}]),onClick:b?void 0:Ts(A,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:[x,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 Vi({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 Fi(){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,x=i?o[1]:5,M=s.direction.x*u*s.factor,S=s.direction.y*x*s.factor;for(const[,y]of d){if(!m(y))continue;let v={x:y.internals.positionAbsolute.x+M,y:y.internals.positionAbsolute.y+S};i&&(v=jr(v,o));const{position:p,positionAbsolute:b}=di({nodeId:y.id,nextPosition:v,nodeLookup:d,nodeExtent:r,nodeOrigin:h,onError:c});y.position=p,y.internals.positionAbsolute=b,f.set(y.id,y)}l(f)},[])}const no=g.createContext(null),au=no.Provider;no.Consumer;const Yi=()=>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 x=a||null,M=e==="target",S=Be(),y=Yi(),{connectOnClick:v,noPanClassName:p,rfId:b}=Ie(iu,qe),{connectingFrom:k,connectingTo:N,clickConnecting:I,isPossibleEndHandle:B,connectionInProcess:D,clickConnectionInProcess:A,valid:E}=Ie(lu(y,x,e),qe);y||S.getState().onError?.("010",zt.error010());const P=O=>{const{defaultEdgeOptions:_,onConnect:T,hasDefaultEdges:R}=S.getState(),L={..._,...O};if(R){const{edges:q,setEdges:Y}=S.getState();Y(Rc(L,q))}T?.(L),c?.(L)},z=O=>{if(!y)return;const _=bi(O.nativeEvent);if(i&&(_&&O.button===0||!_)){const T=S.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:x,nodeId:y,flowId:T.rfId,panBy:T.panBy,cancelConnection:T.cancelConnection,onConnectStart:T.onConnectStart,onConnectEnd:(...R)=>S.getState().onConnectEnd?.(...R),updateConnection:T.updateConnection,onConnect:P,isValidConnection:s||((...R)=>S.getState().isValidConnection?.(...R)??!0),getTransform:()=>S.getState().transform,getFromHandle:()=>S.getState().connection.fromHandle,autoPanSpeed:T.autoPanSpeed,dragThreshold:T.connectionDragThreshold})}_?h?.(O):f?.(O)},j=O=>{const{onClickConnectStart:_,onClickConnectEnd:T,connectionClickStartHandle:R,connectionMode:L,isValidConnection:q,lib:Y,rfId:F,nodeLookup:Q,connection:$}=S.getState();if(!y||!R&&!i)return;if(!R){_?.(O.nativeEvent,{nodeId:y,handleId:x,handleType:e}),S.setState({connectionClickStartHandle:{nodeId:y,type:e,id:x}});return}const C=pi(O.target),V=s||q,{connection:W,isValid:H}=zs.isValid(O.nativeEvent,{handle:{nodeId:y,id:x,type:e},connectionMode:L,fromNodeId:R.nodeId,fromHandleId:R.id||null,fromType:R.type,isValidConnection:V,flowId:F,doc:C,lib:Y,nodeLookup:Q});H&&W&&P(W);const K=structuredClone($);delete K.inProgress,K.toPosition=K.toHandle?K.toHandle.position:null,T?.(O,K),S.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":x,"data-nodeid":y,"data-handlepos":n,"data-id":`${b}-${y}-${x}-${e}`,className:Ke(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",p,d,{source:!M,target:M,connectable:r,connectablestart:i,connectableend:o,clickconnecting:I,connectingfrom:k,connectingto:N,valid:E,connectionindicator:r&&(!D||B)&&(D||A?o:i)}]),onMouseDown:z,onTouchStart:z,onClick:v?j:void 0,ref:u,...m,children:l})}const dn=g.memo(qi(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}},pa={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:Lt(n)?n:null,height:Lt(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}=Ie(gu,qe),l=Fi(),d=g.useRef(null);g.useEffect(()=>{s||d.current?.focus({preventScroll:!0})},[s]);const h=!c&&i!==null&&o!==null;if(Vi({nodeRef:d,disabled:!h}),!h)return null;const f=e?u=>{const x=r.getState().nodes.filter(M=>M.selected);e(u,x)}:void 0,m=u=>{Object.prototype.hasOwnProperty.call(ns,u.key)&&(u.preventDefault(),l({direction:ns[u.key],factor:u.shiftKey?4:1}))};return t.jsx("div",{className:Ke(["react-flow__nodesselection","react-flow__container",n]),style:{transform:a},children:t.jsx("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:s?void 0:-1,onKeyDown:s?void 0:m,style:{width:i,height:o}})})}const xa=typeof window<"u"?window:void 0,xu=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Gi({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:x,panActivationKeyCode:M,zoomActivationKeyCode:S,elementsSelectable:y,zoomOnScroll:v,zoomOnPinch:p,panOnScroll:b,panOnScrollSpeed:k,panOnScrollMode:N,zoomOnDoubleClick:I,panOnDrag:B,defaultViewport:D,translateExtent:A,minZoom:E,maxZoom:P,preventScrolling:z,onSelectionContextMenu:j,noWheelClassName:O,noPanClassName:_,disableKeyboardA11y:T,onViewportChange:R,isControlledViewport:L}){const{nodesSelectionActive:q,userSelectionActive:Y}=Ie(xu,qe),F=br(d,{target:xa}),Q=br(M,{target:xa}),$=Q||B,C=Q||b,V=h&&$!==!0,W=F||Y||V;return Ud({deleteKeyCode:l,multiSelectionKeyCode:x}),t.jsx(eu,{onPaneContextMenu:o,elementsSelectable:y,zoomOnScroll:v,zoomOnPinch:p,panOnScroll:C,panOnScrollSpeed:k,panOnScrollMode:N,zoomOnDoubleClick:I,panOnDrag:!F&&$,defaultViewport:D,translateExtent:A,minZoom:E,maxZoom:P,zoomActivationKeyCode:S,preventScrolling:z,noWheelClassName:O,noPanClassName:_,onViewportChange:R,isControlledViewport:L,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})]})})}Gi.displayName="FlowRenderer";const bu=g.memo(Gi),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 Ie(g.useCallback(yu(e),[e]),qe)}const wu=e=>e.updateNodeInternals;function ku(){const e=Ie(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:x,rfId:M,nodeTypes:S,nodeClickDistance:y,onError:v}){const{node:p,internals:b,isParent:k}=Ie(H=>{const K=H.nodeLookup.get(e),J=H.parentLookup.has(e);return{node:K,internals:K.internals,isParent:J}},qe);let N=p.type||"default",I=S?.[N]||pa[N];I===void 0&&(v?.("003",zt.error003(N)),N="default",I=S?.default||pa.default);const B=!!(p.draggable||c&&typeof p.draggable>"u"),D=!!(p.selectable||l&&typeof p.selectable>"u"),A=!!(p.connectable||d&&typeof p.connectable>"u"),E=!!(p.focusable||h&&typeof p.focusable>"u"),P=Be(),z=mi(p),j=ju({node:p,nodeType:N,hasDimensions:z,resizeObserver:f}),O=Vi({nodeRef:j,disabled:p.hidden||!B,noDragClassName:m,handleSelector:p.dragHandle,nodeId:e,isSelectable:D,nodeClickDistance:y}),_=Fi();if(p.hidden)return null;const T=Qt(p),R=mu(p),L=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,C=H=>{const{selectNodesOnDrag:K,nodeDragThreshold:J}=P.getState();D&&(!K||!B||J>0)&&Hs({id:e,store:P,nodeRef:j}),n&&n(H,{...b.userNode})},V=H=>{if(!(xi(H.nativeEvent)||x)){if(oi.includes(H.key)&&D){const K=H.key==="Escape";Hs({id:e,store:P,unselect:K,nodeRef:j})}else if(B&&p.selected&&Object.prototype.hasOwnProperty.call(ns,H.key)){H.preventDefault();const{ariaLabelConfig:K}=P.getState();P.setState({ariaLiveMessage:K["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(x||!j.current?.matches(":focus-visible"))return;const{transform:H,width:K,height:J,autoPanOnNodeFocus:le,setCenter:te}=P.getState();if(!le)return;Gs(new Map([[e,p]]),{x:0,y:0,width:K,height:J},H,!0).length>0||te(p.position.x+T.width/2,p.position.y+T.height/2,{zoom:H[2]})};return t.jsx("div",{className:Ke(["react-flow__node",`react-flow__node-${N}`,{[u]:B},p.className,{selected:p.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:L?"all":"none",visibility:z?"visible":"hidden",...p.style,...R},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:q,onMouseMove:Y,onMouseLeave:F,onContextMenu:Q,onClick:C,onDoubleClick:$,onKeyDown:E?V:void 0,tabIndex:E?0:void 0,onFocus:E?W:void 0,role:p.ariaRole??(E?"group":void 0),"aria-roledescription":"node","aria-describedby":x?void 0:`${Pi}-${M}`,"aria-label":p.ariaLabel,...p.domAttributes,children:t.jsx(au,{value:e,children:t.jsx(I,{id:e,data:p.data,type:N,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:p.selected??!1,selectable:D,draggable:B,deletable:p.deletable??!0,isConnectable:A,sourcePosition:p.sourcePosition,targetPosition:p.targetPosition,dragging:O,dragHandle:p.dragHandle,zIndex:b.z,parentId:p.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}=Ie(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 Ie(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"})},ba={[Gn.Arrow]:Iu,[Gn.ArrowClosed]:Tu};function Ru(e){const n=Be();return g.useMemo(()=>Object.prototype.hasOwnProperty.call(ba,e)?ba[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},Ki=({defaultColor:e,rfId:n})=>{const s=Ie(o=>o.edges),r=Ie(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};Ki.displayName="MarkerDefinitions";var Au=g.memo(Ki);function Xi({x:e,y:n,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:c=2,children:l,className:d,...h}){const[f,m]=g.useState({x:1,y:0,width:0,height:0}),u=Ke(["react-flow__edge-textwrapper",d]),x=g.useRef(null);return g.useEffect(()=>{if(x.current){const M=x.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:x,style:r,children:s}),l]}):null}Xi.displayName="EdgeText";const Lu=g.memo(Xi);function fs({path:e,labelX:n,labelY:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,interactionWidth:d=20,...h}){return t.jsxs(t.Fragment,{children:[t.jsx("path",{...h,d:e,fill:"none",className:Ke(["react-flow__edge-path",h.className])}),d?t.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:d,className:"react-flow__edge-interaction"}):null,r&&Lt(n)&&Lt(s)?t.jsx(Lu,{x:n,y:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null]})}function ya({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 Ui({sourceX:e,sourceY:n,sourcePosition:s=be.Bottom,targetX:r,targetY:i,targetPosition:o=be.Top}){const[a,c]=ya({pos:s,x1:e,y1:n,x2:r,y2:i}),[l,d]=ya({pos:o,x1:r,y1:i,x2:e,y2:n}),[h,f,m,u]=yi({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 Qi(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:x,markerEnd:M,markerStart:S,interactionWidth:y})=>{const[v,p,b]=Ui({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:p,labelY:b,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:M,markerStart:S,interactionWidth:y})})}const Du=Qi({isInternal:!1}),Ji=Qi({isInternal:!0});Du.displayName="SimpleBezierEdge";Ji.displayName="SimpleBezierEdgeInternal";function el(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:x=be.Top,markerEnd:M,markerStart:S,pathOptions:y,interactionWidth:v})=>{const[p,b,k]=$s({sourceX:s,sourceY:r,sourcePosition:u,targetX:i,targetY:o,targetPosition:x,borderRadius:y?.borderRadius,offset:y?.offset,stepPosition:y?.stepPosition}),N=e.isInternal?void 0:n;return t.jsx(fs,{id:N,path:p,labelX:b,labelY:k,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:M,markerStart:S,interactionWidth:v})})}const tl=el({isInternal:!1}),nl=el({isInternal:!0});tl.displayName="SmoothStepEdge";nl.displayName="SmoothStepEdgeInternal";function rl(e){return g.memo(({id:n,...s})=>{const r=e.isInternal?void 0:n;return t.jsx(tl,{...s,id:r,pathOptions:g.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const Pu=rl({isInternal:!1}),sl=rl({isInternal:!0});Pu.displayName="StepEdge";sl.displayName="StepEdgeInternal";function ol(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:x,interactionWidth:M})=>{const[S,y,v]=ki({sourceX:s,sourceY:r,targetX:i,targetY:o}),p=e.isInternal?void 0:n;return t.jsx(fs,{id:p,path:S,labelX:y,labelY:v,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:x,interactionWidth:M})})}const $u=ol({isInternal:!1}),al=ol({isInternal:!0});$u.displayName="StraightEdge";al.displayName="StraightEdgeInternal";function il(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:x,markerEnd:M,markerStart:S,pathOptions:y,interactionWidth:v})=>{const[p,b,k]=vi({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:p,labelX:b,labelY:k,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:M,markerStart:S,interactionWidth:v})})}const Ou=il({isInternal:!1}),ll=il({isInternal:!0});Ou.displayName="BezierEdge";ll.displayName="BezierEdgeInternal";const va={default:ll,straight:al,step:sl,smoothstep:nl,simplebezier:Ji},wa={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,ka="react-flow__edgeupdater";function ja({position:e,centerX:n,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:o,onMouseOut:a,type:c}){return t.jsx("circle",{onMouseDown:i,onMouseEnter:o,onMouseOut:a,className:Ke([ka,`${ka}-${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 x=Be(),M=(b,k)=>{if(b.button!==0)return;const{autoPanOnConnect:N,domNode:I,connectionMode:B,connectionRadius:D,lib:A,onConnectStart:E,cancelConnection:P,nodeLookup:z,rfId:j,panBy:O,updateConnection:_}=x.getState(),T=k.type==="target",R=(Y,F)=>{m(!1),f?.(Y,s,k.type,F)},L=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:A,flowId:j,cancelConnection:P,panBy:O,isValidConnection:(...Y)=>x.getState().isValidConnection?.(...Y)??!0,onConnect:L,onConnectStart:q,onConnectEnd:(...Y)=>x.getState().onConnectEnd?.(...Y),onReconnectEnd:R,updateConnection:_,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,dragThreshold:x.getState().connectionDragThreshold,handleDomNode:b.currentTarget})},S=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),p=()=>u(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(ja,{position:c,centerX:r,centerY:i,radius:n,onMouseDown:S,onMouseEnter:v,onMouseOut:p,type:"source"}),(e===!0||e==="target")&&t.jsx(ja,{position:l,centerX:o,centerY:a,radius:n,onMouseDown:y,onMouseEnter:v,onMouseOut:p,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:x,edgeTypes:M,noPanClassName:S,onError:y,disableKeyboardA11y:v}){let p=Ie(te=>te.edgeLookup.get(e));const b=Ie(te=>te.defaultEdgeOptions);p=b?{...b,...p}:p;let k=p.type||"default",N=M?.[k]||va[k];N===void 0&&(y?.("011",zt.error011(k)),k="default",N=M?.default||va.default);const I=!!(p.focusable||n&&typeof p.focusable>"u"),B=typeof f<"u"&&(p.reconnectable||s&&typeof p.reconnectable>"u"),D=!!(p.selectable||r&&typeof p.selectable>"u"),A=g.useRef(null),[E,P]=g.useState(!1),[z,j]=g.useState(!1),O=Be(),{zIndex:_,sourceX:T,sourceY:R,targetX:L,targetY:q,sourcePosition:Y,targetPosition:F}=Ie(g.useCallback(te=>{const X=te.nodeLookup.get(p.source),ie=te.nodeLookup.get(p.target);if(!X||!ie)return{zIndex:p.zIndex,...wa};const de=Dc({id:e,sourceNode:X,targetNode:ie,sourceHandle:p.sourceHandle||null,targetHandle:p.targetHandle||null,connectionMode:te.connectionMode,onError:y});return{zIndex:Ec({selected:p.selected,zIndex:p.zIndex,sourceNode:X,targetNode:ie,elevateOnSelect:te.elevateEdgesOnSelect,zIndexMode:te.zIndexMode}),...de||wa}},[p.source,p.target,p.sourceHandle,p.targetHandle,p.selected,p.zIndex]),qe),Q=g.useMemo(()=>p.markerStart?`url('#${Os(p.markerStart,x)}')`:void 0,[p.markerStart,x]),$=g.useMemo(()=>p.markerEnd?`url('#${Os(p.markerEnd,x)}')`:void 0,[p.markerEnd,x]);if(p.hidden||T===null||R===null||L===null||q===null)return null;const C=te=>{const{addSelectedEdges:X,unselectNodesAndEdges:ie,multiSelectionActive:de}=O.getState();D&&(O.setState({nodesSelectionActive:!1}),p.selected&&de?(ie({nodes:[],edges:[p]}),A.current?.blur()):X([e])),i&&i(te,p)},V=o?te=>{o(te,{...p})}:void 0,W=a?te=>{a(te,{...p})}:void 0,H=c?te=>{c(te,{...p})}:void 0,K=l?te=>{l(te,{...p})}:void 0,J=d?te=>{d(te,{...p})}:void 0,le=te=>{if(!v&&oi.includes(te.key)&&D){const{unselectNodesAndEdges:X,addSelectedEdges:ie}=O.getState();te.key==="Escape"?(A.current?.blur(),X({edges:[p]})):ie([e])}};return t.jsx("svg",{style:{zIndex:_},children:t.jsxs("g",{className:Ke(["react-flow__edge",`react-flow__edge-${k}`,p.className,S,{selected:p.selected,animated:p.animated,inactive:!D&&!i,updating:E,selectable:D}]),onClick:C,onDoubleClick:V,onContextMenu:W,onMouseEnter:H,onMouseMove:K,onMouseLeave:J,onKeyDown:I?le:void 0,tabIndex:I?0:void 0,role:p.ariaRole??(I?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":p.ariaLabel===null?void 0:p.ariaLabel||`Edge from ${p.source} to ${p.target}`,"aria-describedby":I?`${$i}-${x}`:void 0,ref:A,...p.domAttributes,children:[!z&&t.jsx(N,{id:e,source:p.source,target:p.target,type:p.type,selected:p.selected,animated:p.animated,selectable:D,deletable:p.deletable??!0,label:p.label,labelStyle:p.labelStyle,labelShowBg:p.labelShowBg,labelBgStyle:p.labelBgStyle,labelBgPadding:p.labelBgPadding,labelBgBorderRadius:p.labelBgBorderRadius,sourceX:T,sourceY:R,targetX:L,targetY:q,sourcePosition:Y,targetPosition:F,data:p.data,style:p.style,sourceHandleId:p.sourceHandle,targetHandleId:p.targetHandle,markerStart:Q,markerEnd:$,pathOptions:"pathOptions"in p?p.pathOptions:void 0,interactionWidth:p.interactionWidth}),B&&t.jsx(Hu,{edge:p,isReconnectable:B,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,sourceX:T,sourceY:R,targetX:L,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 cl({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:x,disableKeyboardA11y:M}){const{edgesFocusable:S,edgesReconnectable:y,elementsSelectable:v,onError:p}=Ie(Vu,qe),b=Mu(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx(Au,{defaultColor:e,rfId:s}),b.map(k=>t.jsx(Wu,{id:k,edgesFocusable:S,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:x,rfId:s,onError:p,edgeTypes:r,disableKeyboardA11y:M},k))]})}cl.displayName="EdgeRenderer";const Fu=g.memo(cl),Yu=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Gu({children:e}){const n=Ie(Yu);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function Zu(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 Ku=e=>e.panZoom?.syncViewport;function Xu(e){const n=Ie(Ku),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 Ie(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}=Ie(ef,qe);return!(o&&i&&l)?null:t.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:t.jsx("g",{className:Ke(["react-flow__connection",li(c)]),children:t.jsx(dl,{style:n,type:s,CustomComponent:r,isValid:c})})})}const dl=({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:li(r),toNode:h,toHandle:f,pointer:u});let x="";const M={sourceX:o.x,sourceY:o.y,sourcePosition:l,targetX:d.x,targetY:d.y,targetPosition:m};switch(n){case ln.Bezier:[x]=vi(M);break;case ln.SimpleBezier:[x]=Ui(M);break;case ln.Step:[x]=$s({...M,borderRadius:0});break;case ln.SmoothStep:[x]=$s(M);break;default:[x]=ki(M)}return t.jsx("path",{d:x,fill:"none",className:"react-flow__connection-path",style:e})};dl.displayName="ConnectionLine";const nf={};function Na(e=nf){g.useRef(e),Be(),g.useEffect(()=>{},[e])}function rf(){Be(),g.useRef(!1),g.useEffect(()=>{},[])}function ul({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:x,connectionLineStyle:M,connectionLineComponent:S,connectionLineContainerStyle:y,selectionKeyCode:v,selectionOnDrag:p,selectionMode:b,multiSelectionKeyCode:k,panActivationKeyCode:N,zoomActivationKeyCode:I,deleteKeyCode:B,onlyRenderVisibleElements:D,elementsSelectable:A,defaultViewport:E,translateExtent:P,minZoom:z,maxZoom:j,preventScrolling:O,defaultMarkerColor:_,zoomOnScroll:T,zoomOnPinch:R,panOnScroll:L,panOnScrollSpeed:q,panOnScrollMode:Y,zoomOnDoubleClick:F,panOnDrag:Q,onPaneClick:$,onPaneMouseEnter:C,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneScroll:H,onPaneContextMenu:K,paneClickDistance:J,nodeClickDistance:le,onEdgeContextMenu:te,onEdgeMouseEnter:X,onEdgeMouseMove:ie,onEdgeMouseLeave:de,reconnectRadius:se,onReconnect:me,onReconnectStart:ue,onReconnectEnd:Z,noDragClassName:ce,noWheelClassName:ge,noPanClassName:ve,disableKeyboardA11y:fe,nodeExtent:re,rfId:xe,viewport:Ee,onViewportChange:ye}){return Na(e),Na(n),rf(),Zu(s),Xu(Ee),t.jsx(bu,{onPaneClick:$,onPaneMouseEnter:C,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneContextMenu:K,onPaneScroll:H,paneClickDistance:J,deleteKeyCode:B,selectionKeyCode:v,selectionOnDrag:p,selectionMode:b,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:k,panActivationKeyCode:N,zoomActivationKeyCode:I,elementsSelectable:A,zoomOnScroll:T,zoomOnPinch:R,zoomOnDoubleClick:F,panOnScroll:L,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:Z,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:x,component:S,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"})]})})}ul.displayName="GraphView";const sf=g.memo(ul),Ca=({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,x=new Map,M=new Map,S=new Map,y=r??n??[],v=s??e??[],p=h??[0,0],b=f??mr;Ci(M,S,y);const k=Bs(v,u,x,{nodeOrigin:p,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:A}=Zs(I,i,o,l,d,c?.padding??.1);N=[B,D,A]}return{rfId:"1",width:i??0,height:o??0,transform:N,nodes:v,nodesInitialized:k,nodeLookup:u,parentLookup:x,edges:y,edgeLookup:S,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:p,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:a??!1,fitViewOptions:c,fitViewResolver:null,connection:{...ii},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:ai,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,x)=>{async function M(){const{nodeLookup:S,panZoom:y,fitViewOptions:v,fitViewResolver:p,width:b,height:k,minZoom:N,maxZoom:I}=x();y&&(await yc({nodes:S,width:b,height:k,panZoom:y,minZoom:N,maxZoom:I},v),p?.resolve(!0),u({fitViewResolver:null}))}return{...Ca({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:S=>{const{nodeLookup:y,parentLookup:v,nodeOrigin:p,elevateNodesOnSelect:b,fitViewQueued:k,zIndexMode:N}=x(),I=Bs(S,y,v,{nodeOrigin:p,nodeExtent:f,elevateNodesOnSelect:b,checkEquality:!0,zIndexMode:N});k&&I?(M(),u({nodes:S,nodesInitialized:I,fitViewQueued:!1,fitViewOptions:void 0})):u({nodes:S,nodesInitialized:I})},setEdges:S=>{const{connectionLookup:y,edgeLookup:v}=x();Ci(y,v,S),u({edges:S})},setDefaultNodesAndEdges:(S,y)=>{if(S){const{setNodes:v}=x();v(S),u({hasDefaultNodes:!0})}if(y){const{setEdges:v}=x();v(y),u({hasDefaultEdges:!0})}},updateNodeInternals:S=>{const{triggerNodeChanges:y,nodeLookup:v,parentLookup:p,domNode:b,nodeOrigin:k,nodeExtent:N,debug:I,fitViewQueued:B,zIndexMode:D}=x(),{changes:A,updatedInternals:E}=Wc(S,v,p,b,k,N,D);E&&(Bc(v,p,{nodeOrigin:k,nodeExtent:N,zIndexMode:D}),B?(M(),u({fitViewQueued:!1,fitViewOptions:void 0})):u({}),A?.length>0&&(I&&console.log("React Flow: trigger node changes",A),y?.(A)))},updateNodePositions:(S,y=!1)=>{const v=[];let p=[];const{nodeLookup:b,triggerNodeChanges:k,connection:N,updateConnection:I,onNodesChangeMiddlewareMap:B}=x();for(const[D,A]of S){const E=b.get(D),P=!!(E?.expandParent&&E?.parentId&&A?.position),z={id:D,type:"position",position:P?{x:Math.max(0,A.position.x),y:Math.max(0,A.position.y)}:A.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:{...A.internals.positionAbsolute,width:A.measured.width??0,height:A.measured.height??0}}),p.push(z)}if(v.length>0){const{parentLookup:D,nodeOrigin:A}=x(),E=eo(v,b,D,A);p.push(...E)}for(const D of B.values())p=D(p);k(p)},triggerNodeChanges:S=>{const{onNodesChange:y,setNodes:v,nodes:p,hasDefaultNodes:b,debug:k}=x();if(S?.length){if(b){const N=zi(S,p);v(N)}k&&console.log("React Flow: trigger node changes",S),y?.(S)}},triggerEdgeChanges:S=>{const{onEdgesChange:y,setEdges:v,edges:p,hasDefaultEdges:b,debug:k}=x();if(S?.length){if(b){const N=Hi(S,p);v(N)}k&&console.log("React Flow: trigger edge changes",S),y?.(S)}},addSelectedNodes:S=>{const{multiSelectionActive:y,edgeLookup:v,nodeLookup:p,triggerNodeChanges:b,triggerEdgeChanges:k}=x();if(y){const N=S.map(I=>Nn(I,!0));b(N);return}b(Wn(p,new Set([...S]),!0)),k(Wn(v))},addSelectedEdges:S=>{const{multiSelectionActive:y,edgeLookup:v,nodeLookup:p,triggerNodeChanges:b,triggerEdgeChanges:k}=x();if(y){const N=S.map(I=>Nn(I,!0));k(N);return}k(Wn(v,new Set([...S]))),b(Wn(p,new Set,!0))},unselectNodesAndEdges:({nodes:S,edges:y}={})=>{const{edges:v,nodes:p,nodeLookup:b,triggerNodeChanges:k,triggerEdgeChanges:N}=x(),I=S||p,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 A=[];for(const E of B)E.selected&&A.push(Nn(E.id,!1));k(D),N(A)},setMinZoom:S=>{const{panZoom:y,maxZoom:v}=x();y?.setScaleExtent([S,v]),u({minZoom:S})},setMaxZoom:S=>{const{panZoom:y,minZoom:v}=x();y?.setScaleExtent([v,S]),u({maxZoom:S})},setTranslateExtent:S=>{x().panZoom?.setTranslateExtent(S),u({translateExtent:S})},resetSelectedElements:()=>{const{edges:S,nodes:y,triggerNodeChanges:v,triggerEdgeChanges:p,elementsSelectable:b}=x();if(!b)return;const k=y.reduce((I,B)=>B.selected?[...I,Nn(B.id,!1)]:I,[]),N=S.reduce((I,B)=>B.selected?[...I,Nn(B.id,!1)]:I,[]);v(k),p(N)},setNodeExtent:S=>{const{nodes:y,nodeLookup:v,parentLookup:p,nodeOrigin:b,elevateNodesOnSelect:k,nodeExtent:N,zIndexMode:I}=x();S[0][0]===N[0][0]&&S[0][1]===N[0][1]&&S[1][0]===N[1][0]&&S[1][1]===N[1][1]||(Bs(y,v,p,{nodeOrigin:b,nodeExtent:S,elevateNodesOnSelect:k,checkEquality:!1,zIndexMode:I}),u({nodeExtent:S}))},panBy:S=>{const{transform:y,width:v,height:p,panZoom:b,translateExtent:k}=x();return Vc({delta:S,panZoom:b,transform:y,translateExtent:k,width:v,height:p})},setCenter:async(S,y,v)=>{const{width:p,height:b,maxZoom:k,panZoom:N}=x();if(!N)return Promise.resolve(!1);const I=typeof v?.zoom<"u"?v.zoom:k;return await N.setViewport({x:p/2-S*I,y:b/2-y*I,zoom:I},{duration:v?.duration,ease:v?.ease,interpolate:v?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{u({connection:{...ii}})},updateConnection:S=>{u({connection:S})},reset:()=>u({...Ca()})}},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[x]=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:x,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:x,onConnectEnd:M,onClickConnectStart:S,onClickConnectEnd:y,onNodeMouseEnter:v,onNodeMouseMove:p,onNodeMouseLeave:b,onNodeContextMenu:k,onNodeDoubleClick:N,onNodeDragStart:I,onNodeDrag:B,onNodeDragStop:D,onNodesDelete:A,onEdgesDelete:E,onDelete:P,onSelectionChange:z,onSelectionDragStart:j,onSelectionDrag:O,onSelectionDragStop:_,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:L,onBeforeDelete:q,connectionMode:Y,connectionLineType:F=ln.Bezier,connectionLineStyle:Q,connectionLineComponent:$,connectionLineContainerStyle:C,deleteKeyCode:V="Backspace",selectionKeyCode:W="Shift",selectionOnDrag:H=!1,selectionMode:K=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:Z,nodesFocusable:ce,nodeOrigin:ge=Oi,edgesFocusable:ve,edgesReconnectable:fe,elementsSelectable:re=!0,defaultViewport:xe=$d,minZoom:Ee=.5,maxZoom:ye=2,translateExtent:Re=mr,preventScrolling:pt=!0,nodeExtent:nt,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:Ae,onPaneScroll:Ue,onPaneContextMenu:qt,paneClickDistance:Wt=1,nodeClickDistance:_e=0,children:Ye,onReconnect:tt,onReconnectStart:un,onReconnectEnd:Mn,onEdgeContextMenu:Ge,onEdgeDoubleClick:Le,onEdgeMouseEnter:ze,onEdgeMouseMove:De,onEdgeMouseLeave:He,reconnectRadius:dt=10,onNodesChange:Je,onEdgesChange:it,noDragClassName:ut="nodrag",noWheelClassName:en="nowheel",noPanClassName:Vt="nopan",fitView:St,fitViewOptions:Et,connectOnClick:et,attributionPosition:ft,proOptions:fn,defaultEdgeOptions:ot,elevateNodesOnSelect:$t=!0,elevateEdgesOnSelect:vt=!1,disableKeyboardA11y:ht=!1,autoPanOnConnect:G,autoPanOnNodeDrag:pe,autoPanSpeed:je,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:Ke(["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:nt,zIndexMode:xn,children:[t.jsx(sf,{onInit:d,onNodeClick:c,onEdgeClick:l,onNodeMouseEnter:v,onNodeMouseMove:p,onNodeMouseLeave:b,onNodeContextMenu:k,onNodeDoubleClick:N,nodeTypes:o,edgeTypes:a,connectionLineType:F,connectionLineStyle:Q,connectionLineComponent:$,connectionLineContainerStyle:C,selectionKeyCode:W,selectionOnDrag:H,selectionMode:K,deleteKeyCode:V,multiSelectionKeyCode:le,panActivationKeyCode:J,zoomActivationKeyCode:te,onlyRenderVisibleElements:de,defaultViewport:xe,translateExtent:Re,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:Ae,onPaneScroll:Ue,onPaneContextMenu:qt,paneClickDistance:Wt,nodeClickDistance:_e,onSelectionContextMenu:T,onSelectionStart:R,onSelectionEnd:L,onReconnect:tt,onReconnectStart:un,onReconnectEnd:Mn,onEdgeContextMenu:Ge,onEdgeDoubleClick:Le,onEdgeMouseEnter:ze,onEdgeMouseMove:De,onEdgeMouseLeave:He,reconnectRadius:dt,defaultMarkerColor:Nt,noDragClassName:ut,noWheelClassName:en,noPanClassName:Vt,rfId:It,disableKeyboardA11y:ht,nodeExtent:nt,viewport:Jn,onViewportChange:hn}),t.jsx(zd,{nodes:e,edges:n,defaultNodes:s,defaultEdges:r,onConnect:u,onConnectStart:x,onConnectEnd:M,onClickConnectStart:S,onClickConnectEnd:y,nodesDraggable:me,autoPanOnNodeFocus:ue,nodesConnectable:Z,nodesFocusable:ce,edgesFocusable:ve,edgesReconnectable:fe,elementsSelectable:re,elevateNodesOnSelect:$t,elevateEdgesOnSelect:vt,minZoom:Ee,maxZoom:ye,nodeExtent:nt,onNodesChange:Je,onEdgesChange:it,snapToGrid:X,snapGrid:ie,connectionMode:Y,translateExtent:Re,connectOnClick:et,defaultEdgeOptions:ot,fitView:St,fitViewOptions:Et,onNodesDelete:A,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:je,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=qi(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=>zi(i,o)),[]);return[n,s,r]}function mf(e){const[n,s]=g.useState(e),r=g.useCallback(i=>s(o=>Hi(i,o)),[]);return[n,s,r]}function gf({dimensions:e,lineWidth:n,variant:s,className:r}){return t.jsx("path",{strokeWidth:n,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Ke(["react-flow__background-pattern",s,r])})}function pf({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Ke(["react-flow__background-pattern","dots",n])})}var 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 fl({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}=Ie(bf,qe),x=r||xf[n],M=n===cn.Dots,S=n===cn.Cross,y=Array.isArray(s)?s:[s,s],v=[y[0]*m[2]||1,y[1]*m[2]||1],p=x*m[2],b=Array.isArray(o)?o:[o,o],k=S?[p,p]:v,N=[b[0]*m[2]||1+k[0]/2,b[1]*m[2]||1+k[1]/2],I=`${u}${e||""}`;return t.jsxs("svg",{className:Ke(["react-flow__background",d]),style:{...l,...us,"--xy-background-color-props":c,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[t.jsx("pattern",{id:I,x:m[0]%v[0],y:m[1]%v[1],width:v[0],height:v[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${N[0]},-${N[1]})`,children:M?t.jsx(pf,{radius:p/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})`})]})}fl.displayName="Background";const yf=g.memo(fl);function vf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:t.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function wf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:t.jsx("path",{d:"M0 0h32v4.2H0z"})})}function kf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:t.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function jf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function Nf(){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:t.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Fr({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:Ke(["react-flow__controls-button",n]),...s,children:e})}const Cf=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function hl({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 x=Be(),{isInteractive:M,minZoomReached:S,maxZoomReached:y,ariaLabelConfig:v}=Ie(Cf,qe),{zoomIn:p,zoomOut:b,fitView:k}=to(),N=()=>{p(),o?.()},I=()=>{b(),a?.()},B=()=>{k(i),c?.()},D=()=>{x.setState({nodesDraggable:!M,nodesConnectable:!M,elementsSelectable:!M}),l?.(!M)},A=m==="horizontal"?"horizontal":"vertical";return t.jsxs(ds,{className:Ke(["react-flow__controls",A,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:S,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]})}hl.displayName="Controls";const Sf=g.memo(hl);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:x,backgroundColor:M}=o||{},S=a||x||M;return t.jsx("rect",{className:Ke(["react-flow__minimap-node",{selected:m},d]),x:n,y:s,rx:h,ry:h,width:r,height:i,style:{fill:S,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=Ie(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}=Ie(x=>{const M=x.nodeLookup.get(e);if(!M)return{node:void 0,x:0,y:0,width:0,height:0};const S=M.internals.userNode,{x:y,y:v}=M.internals.positionAbsolute,{width:p,height:b}=Qt(S);return{node:S,x:y,y:v,width:p,height:b}},qe);return!d||d.hidden||!mi(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 Af=g.memo(Tf);const Lf=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?hi(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 ml({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:x,pannable:M=!1,zoomable:S=!1,ariaLabel:y,inversePan:v,zoomStep:p=1,offsetScale:b=5}){const k=Be(),N=g.useRef(null),{boundingRect:I,viewBB:B,rfId:D,panZoom:A,translateExtent:E,flowWidth:P,flowHeight:z,ariaLabelConfig:j}=Ie($f,qe),O=e?.width??Lf,_=e?.height??Df,T=I.width/O,R=I.height/_,L=Math.max(T,R),q=L*O,Y=L*_,F=b*L,Q=I.x-(q-I.width)/2-F,$=I.y-(Y-I.height)/2-F,C=q+F*2,V=Y+F*2,W=`${Of}-${D}`,H=g.useRef(0),K=g.useRef();H.current=L,g.useEffect(()=>{if(N.current&&A)return K.current=Jc({domNode:N.current,panZoom:A,getTransform:()=>k.getState().transform,getViewScale:()=>H.current}),()=>{K.current?.destroy()}},[A]),g.useEffect(()=>{K.current?.update({translateExtent:E,width:P,height:z,inversePan:v,pannable:M,zoomStep:p,zoomable:S})},[M,S,v,p,E,P,z]);const J=u?X=>{const[ie,de]=K.current?.pointer(X)||[0,0];u(X,{x:ie,y:de})}:void 0,le=x?g.useCallback((X,ie)=>{const de=k.getState().nodeLookup.get(ie).internals.userNode;x(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*L:void 0,"--xy-minimap-node-background-color-props":typeof r=="string"?r:void 0,"--xy-minimap-node-stroke-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-width-props":typeof a=="number"?a:void 0},className:Ke(["react-flow__minimap",n]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:O,height:_,viewBox:`${Q} ${$} ${C} ${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(Af,{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${C+F*2}v${V+F*2}h${-C-F*2}z
7
- M${B.x},${B.y}h${B.width}v${B.height}h${-B.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}ml.displayName="MiniMap";const Bf=g.memo(ml),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:x,onResizeStart:M,onResize:S,onResizeEnd:y}){const v=Yi(),p=typeof e=="string"?e:v,b=Be(),k=g.useRef(null),N=s===Un.Handle,I=Ie(g.useCallback(zf(N&&u),[N,u]),qe),B=g.useRef(null),D=n??Hf[s];g.useEffect(()=>{if(!(!k.current||!p))return B.current||(B.current=hd({domNode:k.current,nodeId:p,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},L=j.get(p);if(L&&L.expandParent&&L.parentId){const q=L.origin??_,Y=E.width??L.measured.width??0,F=E.height??L.measured.height??0,Q={id:L.id,parentId:L.parentId,rect:{width:Y,height:F,...gi({x:E.x??L.position.x,y:E.y??L.position.y},{width:Y,height:F},L.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:p,type:"position",position:{...R}};T.push(q)}if(E.width!==void 0&&E.height!==void 0){const Y={id:p,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:p,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:S,onResizeEnd:y,shouldResize:x}),()=>{B.current?.destroy()}},[D,c,l,d,h,f,M,S,y,x]);const A=D.split("-");return t.jsx("div",{className:Ke(["react-flow__resize-control","nodrag",...A,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(C=>Object.keys($._in[C]).length===0)}sinks(){var $=this;return this.nodes().filter(C=>Object.keys($._out[C]).length===0)}setNodes($,C){var V=arguments,W=this;return $.forEach(function(H){V.length>1?W.setNode(H,C):W.setNode(H)}),this}setNode($,C){return Object.hasOwn(this._nodes,$)?(arguments.length>1&&(this._nodes[$]=C),this):(this._nodes[$]=arguments.length>1?C: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 C=this;if(Object.hasOwn(this._nodes,$)){var V=W=>C.removeEdge(C._edgeObjs[W]);delete this._nodes[$],this._isCompound&&(this._removeFromParentsChildList($),delete this._parent[$],this.children($).forEach(function(W){C.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($,C){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(C===void 0)C=_;else{C+="";for(var V=C;V!==void 0;V=this.parent(V))if(V===$)throw new Error("Setting "+C+" as parent of "+$+" would create a cycle");this.setNode(C)}return this.setNode($),this._removeFromParentsChildList($),this._parent[$]=C,this._children[C][$]=!0,this}_removeFromParentsChildList($){delete this._children[this._parent[$]][$]}parent($){if(this._isCompound){var C=this._parent[$];if(C!==_)return C}}children($=_){if(this._isCompound){var C=this._children[$];if(C)return Object.keys(C)}else{if($===_)return this.nodes();if(this.hasNode($))return[]}}predecessors($){var C=this._preds[$];if(C)return Object.keys(C)}successors($){var C=this._sucs[$];if(C)return Object.keys(C)}neighbors($){var C=this.predecessors($);if(C){let W=new Set(C);for(var V of this.successors($))W.add(V);return Array.from(W.values())}}isLeaf($){var C;return this.isDirected()?C=this.successors($):C=this.neighbors($),C.length===0}filterNodes($){var C=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});C.setGraph(this.graph());var V=this;Object.entries(this._nodes).forEach(function([K,J]){$(K)&&C.setNode(K,J)}),Object.values(this._edgeObjs).forEach(function(K){C.hasNode(K.v)&&C.hasNode(K.w)&&C.setEdge(K,V.edge(K))});var W={};function H(K){var J=V.parent(K);return J===void 0||C.hasNode(J)?(W[K]=J,J):J in W?W[J]:H(J)}return this._isCompound&&C.nodes().forEach(K=>C.setParent(K,H(K))),C}setDefaultEdgeLabel($){return this._defaultEdgeLabelFn=$,typeof $!="function"&&(this._defaultEdgeLabelFn=()=>$),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath($,C){var V=this,W=arguments;return $.reduce(function(H,K){return W.length>1?V.setEdge(H,K,C):V.setEdge(H,K),K}),this}setEdge(){var $,C,V,W,H=!1,K=arguments[0];typeof K=="object"&&K!==null&&"v"in K?($=K.v,C=K.w,V=K.name,arguments.length===2&&(W=arguments[1],H=!0)):($=K,C=arguments[1],V=arguments[3],arguments.length>2&&(W=arguments[2],H=!0)),$=""+$,C=""+C,V!==void 0&&(V=""+V);var J=Y(this._isDirected,$,C,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(C),this._edgeLabels[J]=H?W:this._defaultEdgeLabelFn($,C,V);var le=F(this._isDirected,$,C,V);return $=le.v,C=le.w,Object.freeze(le),this._edgeObjs[J]=le,L(this._preds[C],$),L(this._sucs[$],C),this._in[C][J]=le,this._out[$][J]=le,this._edgeCount++,this}edge($,C,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,C,V);return this._edgeLabels[W]}edgeAsObj(){let $=this.edge(...arguments);return typeof $!="object"?{label:$}:$}hasEdge($,C,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,C,V);return Object.hasOwn(this._edgeLabels,W)}removeEdge($,C,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,$,C,V),H=this._edgeObjs[W];return H&&($=H.v,C=H.w,delete this._edgeLabels[W],delete this._edgeObjs[W],q(this._preds[C],$),q(this._sucs[$],C),delete this._in[C][W],delete this._out[$][W],this._edgeCount--),this}inEdges($,C){return this.isDirected()?this.filterEdges(this._in[$],$,C):this.nodeEdges($,C)}outEdges($,C){return this.isDirected()?this.filterEdges(this._out[$],$,C):this.nodeEdges($,C)}nodeEdges($,C){if($ in this._nodes)return this.filterEdges({...this._in[$],...this._out[$]},$,C)}filterEdges($,C,V){if($){var W=Object.values($);return V?W.filter(function(H){return H.v===C&&H.w===V||H.v===V&&H.w===C}):W}}};function L($,C){$[C]?$[C]++:$[C]=1}function q($,C){--$[C]||delete $[C]}function Y($,C,V,W){var H=""+C,K=""+V;if(!$&&H>K){var J=H;H=K,K=J}return H+T+K+T+(W===void 0?O:W)}function F($,C,V,W){var H=""+C,K=""+V;if(!$&&H>K){var J=H;H=K,K=J}var le={v:H,w:K};return W&&(le.name=W),le}function Q($,C){return Y($,C.v,C.w,C.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:L};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 L(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,L,q,Y){return T(R,String(L),q||O,Y||function(F){return R.outEdges(F)})}function T(R,L,q,Y){var F={},Q=!0,$=0,C=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(){C.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})})})};C.forEach(function(J){var le=J===L?0:Number.POSITIVE_INFINITY;F[J]={distance:le}});for(var H=C.length,K=1;K<H&&(Q=!1,$++,W(),!!Q);K++);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=[],L;function q(Y){Object.hasOwn(T,Y)||(T[Y]=!0,L.push(Y),_.successors(Y).forEach(q),_.predecessors(Y).forEach(q))}return _.nodes().forEach(function(Y){L=[],q(Y),L.length&&R.push(L)}),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 L=this._arr,q=L.length;return R[_]=q,L.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*_,L=R+1,q=_;R<T.length&&(q=T[R].priority<T[q].priority?R:q,L<T.length&&(q=T[L].priority<T[q].priority?L:q),q!==_&&(this._swap(_,q),this._heapify(q)))}_decrease(_){for(var T=this._arr,R=T[_].priority,L;_!==0&&(L=_>>1,!(T[L].priority<R));)this._swap(_,L),_=L}_swap(_,T){var R=this._arr,L=this._keyIndices,q=R[_],Y=R[T];R[_]=Y,R[T]=q,L[Y.key]=_,L[q.key]=T}};j.exports=O}),u=i((z,j)=>{var O=m();j.exports=T;var _=()=>1;function T(L,q,Y,F){var Q=function($){return L.outEdges($)};return R(L,String(q),Y||_,F||Q)}function R(L,q,Y,F){var Q={},$=new O,C,V,W=function(H){var K=H.v!==C?H.v:H.w,J=Q[K],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=C,$.decrease(K,te))};for(L.nodes().forEach(function(H){var K=H===q?0:Number.POSITIVE_INFINITY;Q[H]={distance:K},$.add(H,K)});$.size()>0&&(C=$.removeMin(),V=Q[C],V.distance!==Number.POSITIVE_INFINITY);)F(C).forEach(W);return Q}}),x=i((z,j)=>{var O=u();j.exports=_;function _(T,R,L){return T.nodes().reduce(function(q,Y){return q[Y]=O(T,Y,R,L),q},{})}}),M=i((z,j)=>{j.exports=O;function O(T,R,L){if(T[R].predecessor!==void 0)throw new Error("Invalid source vertex");if(T[L].predecessor===void 0&&L!==R)throw new Error("Invalid destination vertex");return{weight:T[L].distance,path:_(T,R,L)}}function _(T,R,L){for(var q=[],Y=L;Y!==R;)q.push(Y),Y=T[Y].predecessor;return q.push(R),q.reverse()}}),S=i((z,j)=>{j.exports=O;function O(_){var T=0,R=[],L={},q=[];function Y(F){var Q=L[F]={onStack:!0,lowlink:T,index:T++};if(R.push(F),_.successors(F).forEach(function(V){Object.hasOwn(L,V)?L[V].onStack&&(Q.lowlink=Math.min(Q.lowlink,L[V].index)):(Y(V),Q.lowlink=Math.min(Q.lowlink,L[V].lowlink))}),Q.lowlink===Q.index){var $=[],C;do C=R.pop(),L[C].onStack=!1,$.push(C);while(F!==C);q.push($)}}return _.nodes().forEach(function(F){Object.hasOwn(L,F)||Y(F)}),q}}),y=i((z,j)=>{var O=S();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,L,q){return T(R,L||O,q||function(Y){return R.outEdges(Y)})}function T(R,L,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 C=$.v===Q?$.w:$.v,V=L($);Y[Q][C]={distance:V,predecessor:Q}})}),F.forEach(function(Q){var $=Y[Q];F.forEach(function(C){var V=Y[C];F.forEach(function(W){var H=V[Q],K=$[W],J=V[W],le=H.distance+K.distance;le<J.distance&&(J.distance=le,J.predecessor=K.predecessor)})})}),Y}}),p=i((z,j)=>{function O(T){var R={},L={},q=[];function Y(F){if(Object.hasOwn(L,F))throw new _;Object.hasOwn(R,F)||(L[F]=!0,R[F]=!0,T.predecessors(F).forEach(Y),delete L[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=p();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,L,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,$,L==="post",Q,F,q,Y)}),Y}function _(T,R,L,q,Y,F,Q){return Object.hasOwn(q,R)||(q[R]=!0,L||(Q=F(Q,R)),Y(R).forEach(function($){Q=_(T,$,L,q,Y,F,Q)}),L&&(Q=F(Q,R))),Q}}),N=i((z,j)=>{var O=k();j.exports=_;function _(T,R,L){return O(T,R,L,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,L){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 K=L(V);K<H&&(Y[W]=Q,F.decrease(W,K))}}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 C=!1;F.size()>0;){if(Q=F.removeMin(),Object.hasOwn(Y,Q))q.setEdge(Q,Y[Q]);else{if(C)throw new Error("Input graph is not connected: "+R);C=!0}R.nodeEdges(Q).forEach($)}return q}}),A=i((z,j)=>{var O=u(),_=h();j.exports=T;function T(L,q,Y,F){return R(L,q,Y,F||function(Q){return L.outEdges(Q)})}function R(L,q,Y,F){if(Y===void 0)return O(L,q,Y,F);for(var Q=!1,$=L.nodes(),C=0;C<$.length;C++){for(var V=F($[C]),W=0;W<V.length;W++){var H=V[W],K=H.v===$[C]?H.v:H.w,J=K===H.v?H.w:H.v;Y({v:K,w:J})<0&&(Q=!0)}if(Q)return _(L,q,Y,F)}return O(L,q,Y,F)}}),E=i((z,j)=>{j.exports={bellmanFord:h(),components:f(),dijkstra:u(),dijkstraAll:x(),extractPath:M(),findCycles:y(),floydWarshall:v(),isAcyclic:b(),postorder:I(),preorder:B(),prim:D(),shortestPaths:A(),reduce:k(),tarjan:S(),topsort:p()}}),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(x=>f.outEdges(x.v,x.w))}function a(f,m,u){let x=[],M=m[m.length-1],S=m[0],y;for(;f.nodeCount();){for(;y=S.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){x=x.concat(c(f,m,u,y,!0));break}}}return x}function c(f,m,u,x,M){let S=M?[]:void 0;return f.inEdges(x.v).forEach(y=>{let v=f.edge(y),p=f.node(y.v);M&&S.push({v:y.v,w:y.w}),p.out-=v,d(m,u,p)}),f.outEdges(x.v).forEach(y=>{let v=f.edge(y),p=y.w,b=f.node(p);b.in-=v,d(m,u,b)}),f.removeNode(x.v),S}function l(f,m){let u=new s,x=0,M=0;f.nodes().forEach(v=>{u.setNode(v,{v,in:0,out:0})}),f.edges().forEach(v=>{let p=u.edge(v.v,v.w)||0,b=m(v),k=p+b;u.setEdge(v.v,v.w,k),M=Math.max(M,u.node(v.v).out+=b),x=Math.max(x,u.node(v.w).in+=b)});let S=h(M+x+3).map(()=>new r),y=x+1;return u.nodes().forEach(v=>{d(S,y,u.node(v))}),{graph:u,buckets:S,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}}),Ze=Pe((e,n)=>{var s=Pt().Graph;n.exports={addBorderNode:m,addDummyNode:r,applyWithChunking:M,asNonCompoundGraph:o,buildLayerMatrix:d,intersectRect:l,mapValues:B,maxRank:S,normalizeRanks:h,notime:p,partition:y,pick:I,predecessorWeights:c,range:N,removeEmptyRanks:f,simplify:i,successorWeights:a,time:v,uniqueId:k,zipObject:D};function r(A,E,P,z){for(var j=z;A.hasNode(j);)j=k(z);return P.dummy=E,A.setNode(j,P),j}function i(A){let E=new s().setGraph(A.graph());return A.nodes().forEach(P=>E.setNode(P,A.node(P))),A.edges().forEach(P=>{let z=E.edge(P.v,P.w)||{weight:0,minlen:1},j=A.edge(P);E.setEdge(P.v,P.w,{weight:z.weight+j.weight,minlen:Math.max(z.minlen,j.minlen)})}),E}function o(A){let E=new s({multigraph:A.isMultigraph()}).setGraph(A.graph());return A.nodes().forEach(P=>{A.children(P).length||E.setNode(P,A.node(P))}),A.edges().forEach(P=>{E.setEdge(P,A.edge(P))}),E}function a(A){let E=A.nodes().map(P=>{let z={};return A.outEdges(P).forEach(j=>{z[j.w]=(z[j.w]||0)+A.edge(j).weight}),z});return D(A.nodes(),E)}function c(A){let E=A.nodes().map(P=>{let z={};return A.inEdges(P).forEach(j=>{z[j.v]=(z[j.v]||0)+A.edge(j).weight}),z});return D(A.nodes(),E)}function l(A,E){let P=A.x,z=A.y,j=E.x-P,O=E.y-z,_=A.width/2,T=A.height/2;if(!j&&!O)throw new Error("Not possible to find intersection inside of the rectangle");let R,L;return Math.abs(O)*_>Math.abs(j)*T?(O<0&&(T=-T),R=T*j/O,L=T):(j<0&&(_=-_),R=_,L=_*O/j),{x:P+R,y:z+L}}function d(A){let E=N(S(A)+1).map(()=>[]);return A.nodes().forEach(P=>{let z=A.node(P),j=z.rank;j!==void 0&&(E[j][z.order]=P)}),E}function h(A){let E=A.nodes().map(z=>{let j=A.node(z).rank;return j===void 0?Number.MAX_VALUE:j}),P=M(Math.min,E);A.nodes().forEach(z=>{let j=A.node(z);Object.hasOwn(j,"rank")&&(j.rank-=P)})}function f(A){let E=A.nodes().map(_=>A.node(_).rank).filter(_=>_!==void 0),P=M(Math.min,E),z=[];A.nodes().forEach(_=>{let T=A.node(_).rank-P;z[T]||(z[T]=[]),z[T].push(_)});let j=0,O=A.graph().nodeRankFactor;Array.from(z).forEach((_,T)=>{_===void 0&&T%O!==0?--j:_!==void 0&&j&&_.forEach(R=>A.node(R).rank+=j)})}function m(A,E,P,z){let j={width:0,height:0};return arguments.length>=4&&(j.rank=P,j.order=z),r(A,"border",j,E)}function u(A,E=x){let P=[];for(let z=0;z<A.length;z+=E){let j=A.slice(z,z+E);P.push(j)}return P}var x=65535;function M(A,E){if(E.length>x){let P=u(E);return A.apply(null,P.map(z=>A.apply(null,z)))}else return A.apply(null,E)}function S(A){let E=A.nodes().map(P=>{let z=A.node(P).rank;return z===void 0?Number.MIN_VALUE:z});return M(Math.max,E)}function y(A,E){let P={lhs:[],rhs:[]};return A.forEach(z=>{E(z)?P.lhs.push(z):P.rhs.push(z)}),P}function v(A,E){let P=Date.now();try{return E()}finally{console.log(A+" time: "+(Date.now()-P)+"ms")}}function p(A,E){return E()}var b=0;function k(A){var E=++b;return A+(""+E)}function N(A,E,P=1){E==null&&(E=A,A=0);let z=O=>O<E;P<0&&(z=O=>E<O);let j=[];for(let O=A;z(O);O+=P)j.push(O);return j}function I(A,E){let P={};for(let z of E)A[z]!==void 0&&(P[z]=A[z]);return P}function B(A,E){let P=E;return typeof E=="string"&&(P=z=>z[E]),Object.entries(A).reduce((z,[j,O])=>(z[j]=P(O,j),z),{})}function D(A,E){return A.reduce((P,z,j)=>(P[z]=E[j],P),{})}}),Ff=Pe((e,n)=>{var s=Vf(),r=Ze().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=Ze();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),x=u.labelRank;if(f===d+1)return;a.removeEdge(c);let M,S,y;for(y=0,++d;d<f;++y,++d)u.points=[],S={width:0,height:0,edgeLabel:u,edgeObj:c,rank:d},M=s.addDummyNode(a,"edge",S,"_d"),d===x&&(S.width=u.width,S.height=u.height,S.dummy="edge-label",S.labelpos=u.labelpos),a.setEdge(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}=Ze();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}}),gl=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,x=f===u?m.w:u;!l.hasNode(x)&&!r(d,m)&&(l.setNode(x,{}),l.setEdge(f,x,{}),h(x))})}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=gl(),r=rs().slack,i=rs().longestPath,o=Pt().alg.preorder,a=Pt().alg.postorder,c=Ze().simplify;n.exports=l,l.initLowLimValues=m,l.initCutValues=d,l.calcCutValue=f,l.leaveEdge=x,l.enterEdge=M,l.exchangeEdges=S;function l(b){b=c(b),i(b);var k=s(b);m(k),d(k,b);for(var N,I;N=x(k);)I=M(k,b,N),S(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,A=k.edge(N,B),E=0;return A||(D=!1,A=k.edge(B,N)),E=A.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,A=b.node(I);return k[I]=!0,b.neighbors(I).forEach(E=>{Object.hasOwn(k,E)||(N=u(b,k,N,E,I))}),A.low=D,A.lim=N++,B?A.parent=B:delete A.parent,N}function x(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),A=b.node(B),E=D,P=!1;D.lim>A.lim&&(E=A,P=!0);var z=k.edges().filter(j=>P===p(b,b.node(j.v),E)&&P!==p(b,b.node(j.w),E));return z.reduce((j,O)=>r(k,O)<r(k,j)?O:j)}function S(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,A=k.edge(B,D),E=!1;A||(A=k.edge(D,B),E=!0),k.node(B).rank=k.node(D).rank+(E?A.minlen:-A.minlen)})}function v(b,k,N){return b.hasEdge(k,N)}function p(b,k,N){return N.low<=k.lim&&k.lim<=N.lim}}),Zf=Pe((e,n)=>{var s=rs(),r=s.longestPath,i=gl(),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)}}),Kf=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,x=f[u],M=!0;for(;c!==d.w;){if(l=o.node(c),M){for(;(x=f[u])!==m&&o.node(x).maxRank<l.rank;)u++;x===m&&(M=!1)}if(!M){for(;u<f.length-1&&o.node(x=f[u+1]).minRank<=l.rank;)u++;x=f[u]}o.setParent(c,x),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,x;u=c;do u=o.parent(u),d.push(u);while(u&&(a[u].low>f||m>a[u].lim));for(x=u,u=l;(u=o.parent(u))!==x;)h.push(u);return{path:d.concat(h.reverse()),lca:x}}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=Ze();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 x=a(l)+1;l.children().forEach(M=>i(l,d,u,x,m,h,M)),l.graph().nodeRankFactor=u}function i(l,d,h,f,m,u,x){let M=l.children(x);if(!M.length){x!==d&&l.setEdge(d,x,{weight:0,minlen:h});return}let S=s.addBorderNode(l,"_bt"),y=s.addBorderNode(l,"_bb"),v=l.node(x);l.setParent(S,x),v.borderTop=S,l.setParent(y,x),v.borderBottom=y,M.forEach(p=>{i(l,d,h,f,m,u,p);let b=l.node(p),k=b.borderTop?b.borderTop:p,N=b.borderBottom?b.borderBottom:p,I=b.borderTop?f:2*f,B=k!==N?1:m-u[x]+1;l.setEdge(S,k,{weight:I,minlen:B,nestingEdge:!0}),l.setEdge(N,y,{weight:I,minlen:B,nestingEdge:!0})}),l.parent(x)||l.setEdge(d,S,{weight:0,minlen:m+u[x]})}function o(l){var d={};function h(f,m){var u=l.children(f);u&&u.length&&u.forEach(x=>h(x,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=Ze();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=Ze();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=Ze().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((x,M)=>M)),d=a.flatMap(x=>o.outEdges(x).map(M=>({pos:l[M.w],weight:o.edge(M).weight})).sort((M,S)=>M.pos-S.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(x=>{let M=x.pos+h;m[M]+=x.weight;let S=0;for(;M>0;)M%2&&(S+=m[M+1]),M=M-1>>1,m[M]+=x.weight;u+=x.weight*S}),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=Ze();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=Ze();n.exports=r;function r(a,c){let l=s.partition(a,S=>Object.hasOwn(S,"barycenter")),d=l.lhs,h=l.rhs.sort((S,y)=>y.i-S.i),f=[],m=0,u=0,x=0;d.sort(o(!!c)),x=i(f,h,x),d.forEach(S=>{x+=S.vs.length,f.push(S.vs),m+=S.barycenter*S.weight,u+=S.weight,x=i(f,h,x)});let 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),x=u?u.borderLeft:void 0,M=u?u.borderRight:void 0,S={};x&&(m=m.filter(b=>b!==x&&b!==M));let y=s(l,m);y.forEach(b=>{if(l.children(b.v).length){let k=o(l,b.v,h,f);S[b.v]=k,Object.hasOwn(k,"barycenter")&&c(b,k)}});let v=r(y,h);a(v,S);let p=i(v,f);if(x&&(p.vs=[x,p.vs,M].flat(!0),l.predecessors(x).length)){let b=l.node(l.predecessors(x)[0]),k=l.node(l.predecessors(M)[0]);Object.hasOwn(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+b.order+k.order)/(p.weight+2),p.weight+=2}return p}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=Ze();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),x=a.parent(m);(u.rank===c||u.minRank<=c&&c<=u.maxRank)&&(f.setNode(m),f.setParent(m,x||h),a[l](m).forEach(M=>{let S=M.v===m?M.w:M.v,y=f.edge(S,m),v=y!==void 0?y.weight:0;f.setEdge(S,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=Ze();n.exports=d;function d(u,x={}){if(typeof x.customOrder=="function"){x.customOrder(u,d);return}let M=l.maxRank(u),S=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),x.disableOptimalOrderHeuristic)return;let p=Number.POSITIVE_INFINITY,b,k=x.constraints||[];for(let N=0,I=0;I<4;++N,++I){f(N%2?S:y,N%4>=2,k),v=l.buildLayerMatrix(u);let B=r(u,v);B<p?(I=0,b=Object.assign({},v),p=B):B===p&&(b=structuredClone(v))}m(u,b)}function h(u,x,M){let S=new Map,y=(v,p)=>{S.has(v)||S.set(v,[]),S.get(v).push(p)};for(let v of u.nodes()){let p=u.node(v);if(typeof p.rank=="number"&&y(p.rank,v),typeof p.minRank=="number"&&typeof p.maxRank=="number")for(let b=p.minRank;b<=p.maxRank;b++)b!==p.rank&&y(b,v)}return x.map(function(v){return o(u,v,M,S.get(v)||[])})}function f(u,x,M){let S=new c;u.forEach(function(y){M.forEach(b=>S.setEdge(b.left,b.right));let v=y.graph().root,p=i(y,v,S,x);p.vs.forEach((b,k)=>y.node(b).order=k),a(y,S,p.vs)})}function m(u,x){Object.values(x).forEach(M=>M.forEach((S,y)=>u.node(S).order=y))}}),lh=Pe((e,n)=>{var s=Pt().Graph,r=Ze();n.exports={positionX:M,findType1Conflicts:i,findType2Conflicts:o,addConflict:c,hasConflict:l,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:u,findSmallestWidthAlignment:m,balance:x};function i(v,p){let b={};function k(N,I){let B=0,D=0,A=N.length,E=I[I.length-1];return I.forEach((P,z)=>{let j=a(v,P),O=j?v.node(j).order:A;(j||P===E)&&(I.slice(D,z+1).forEach(_=>{v.predecessors(_).forEach(T=>{let R=v.node(T),L=R.order;(L<B||O<L)&&!(R.dummy&&v.node(_).dummy)&&c(b,T,_)})}),D=z+1,B=O)}),I}return p.length&&p.reduce(k),b}function o(v,p){let b={};function k(I,B,D,A,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<A||O.order>E)&&c(b,j,P)})})}function N(I,B){let D=-1,A,E=0;return B.forEach((P,z)=>{if(v.node(P).dummy==="border"){let j=v.predecessors(P);j.length&&(A=v.node(j[0]).order,k(B,E,z,D,A),E=z,D=A)}k(B,E,B.length,A,I.length)}),B}return p.length&&p.reduce(N),b}function a(v,p){if(v.node(p).dummy)return v.predecessors(p).find(b=>v.node(b).dummy)}function c(v,p,b){if(p>b){let N=p;p=b,b=N}let k=v[p];k||(v[p]=k={}),k[b]=!0}function l(v,p,b){if(p>b){let k=p;p=b,b=k}return!!v[p]&&Object.hasOwn(v[p],b)}function d(v,p,b,k){let N={},I={},B={};return p.forEach(D=>{D.forEach((A,E)=>{N[A]=A,I[A]=A,B[A]=E})}),p.forEach(D=>{let A=-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&&A<B[_]&&!l(b,E,_)&&(I[_]=E,I[E]=N[E]=N[_],A=B[_])}}})}),{root:N,align:I}}function h(v,p,b,k,N){let I={},B=f(v,p,b,N),D=N?"borderLeft":"borderRight";function A(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 A(E,B.predecessors.bind(B)),A(P,B.successors.bind(B)),Object.keys(k).forEach(z=>I[z]=I[b[z]]),I}function f(v,p,b,k){let N=new s,I=v.graph(),B=S(I.nodesep,I.edgesep,k);return p.forEach(D=>{let A;D.forEach(E=>{let P=b[E];if(N.setNode(P),A){var z=b[A],j=N.edge(z,P);N.setEdge(z,P,Math.max(B(v,E,A),j||0))}A=E})}),N}function m(v,p){return Object.values(p).reduce((b,k)=>{let N=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;Object.entries(k).forEach(([D,A])=>{let E=y(v,D)/2;N=Math.max(A+E,N),I=Math.min(A-E,I)});let B=N-I;return B<b[0]&&(b=[B,k]),b},[Number.POSITIVE_INFINITY,null])[1]}function u(v,p){let b=Object.values(p),k=r.applyWithChunking(Math.min,b),N=r.applyWithChunking(Math.max,b);["u","d"].forEach(I=>{["l","r"].forEach(B=>{let D=I+B,A=v[D];if(A===p)return;let E=Object.values(A),P=k-r.applyWithChunking(Math.min,E);B!=="l"&&(P=N-r.applyWithChunking(Math.max,E)),P&&(v[D]=r.mapValues(A,z=>z+P))})})}function x(v,p){return r.mapValues(v.ul,(b,k)=>{if(p)return v[p.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 p=r.buildLayerMatrix(v),b=Object.assign(i(v,p),o(v,p)),k={},N;["u","d"].forEach(B=>{N=B==="u"?p:Object.values(p).reverse(),["l","r"].forEach(D=>{D==="r"&&(N=N.map(z=>Object.values(z).reverse()));let A=(B==="u"?v.predecessors:v.successors).bind(v),E=d(v,N,b,A),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),x(k,v.graph().align)}function S(v,p,b){return(k,N,I)=>{let B=k.node(N),D=k.node(I),A=0,E;if(A+=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&&(A+=b?E:-E),E=0,A+=(B.dummy?p:v)/2,A+=(D.dummy?p:v)/2,A+=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&&(A+=b?E:-E),E=0,A}}function y(v,p){return v.node(p).width}}),ch=Pe((e,n)=>{var s=Ze(),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,x)=>{let M=a.node(x).height;return u>M?u:M},0);f.forEach(u=>{let x=a.node(u);d==="top"?x.y=h+x.height/2:d==="bottom"?x.y=h+m-x.height/2:x.y=h+m/2}),h+=m+l})}}),dh=Pe((e,n)=>{var s=Ff(),r=Yf(),i=Zf(),o=Ze().normalizeRanks,a=Kf(),c=Ze().removeEmptyRanks,l=Xf(),d=Uf(),h=Qf(),f=ih(),m=ch(),u=Ze(),x=Pt().Graph;n.exports=M;function M(C,V={}){let W=V.debugTiming?u.time:u.notime;return W("layout",()=>{let H=W(" buildLayoutGraph",()=>A(C));return W(" runLayout",()=>S(H,W,V)),W(" updateInputGraph",()=>y(C,H)),H})}function S(C,V,W){V(" makeSpaceForEdgeLabels",()=>E(C)),V(" removeSelfEdges",()=>q(C)),V(" acyclic",()=>s.run(C)),V(" nestingGraph.run",()=>l.run(C)),V(" rank",()=>i(u.asNonCompoundGraph(C))),V(" injectEdgeLabelProxies",()=>P(C)),V(" removeEmptyRanks",()=>c(C)),V(" nestingGraph.cleanup",()=>l.cleanup(C)),V(" normalizeRanks",()=>o(C)),V(" assignRankMinMax",()=>z(C)),V(" removeEdgeLabelProxies",()=>j(C)),V(" normalize.run",()=>r.run(C)),V(" parentDummyChains",()=>a(C)),V(" addBorderSegments",()=>d(C)),V(" order",()=>f(C,W)),V(" insertSelfEdges",()=>Y(C)),V(" adjustCoordinateSystem",()=>h.adjust(C)),V(" position",()=>m(C)),V(" positionSelfEdges",()=>F(C)),V(" removeBorderNodes",()=>L(C)),V(" normalize.undo",()=>r.undo(C)),V(" fixupEdgeLabelCoords",()=>T(C)),V(" undoCoordinateSystem",()=>h.undo(C)),V(" translateGraph",()=>O(C)),V(" assignNodeIntersects",()=>_(C)),V(" reversePoints",()=>R(C)),V(" acyclic.undo",()=>s.undo(C))}function y(C,V){C.nodes().forEach(W=>{let H=C.node(W),K=V.node(W);H&&(H.x=K.x,H.y=K.y,H.order=K.order,H.rank=K.rank,V.children(W).length&&(H.width=K.width,H.height=K.height))}),C.edges().forEach(W=>{let H=C.edge(W),K=V.edge(W);H.points=K.points,Object.hasOwn(K,"x")&&(H.x=K.x,H.y=K.y)}),C.graph().width=V.graph().width,C.graph().height=V.graph().height}var v=["nodesep","edgesep","ranksep","marginx","marginy"],p={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 A(C){let V=new x({multigraph:!0,compound:!0}),W=$(C.graph());return V.setGraph(Object.assign({},p,Q(W,v),u.pick(W,b))),C.nodes().forEach(H=>{let K=$(C.node(H)),J=Q(K,k);Object.keys(N).forEach(le=>{J[le]===void 0&&(J[le]=N[le])}),V.setNode(H,J),V.setParent(H,C.parent(H))}),C.edges().forEach(H=>{let K=$(C.edge(H));V.setEdge(H,Object.assign({},B,Q(K,I),u.pick(K,D)))}),V}function E(C){let V=C.graph();V.ranksep/=2,C.edges().forEach(W=>{let H=C.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(C){C.edges().forEach(V=>{let W=C.edge(V);if(W.width&&W.height){let H=C.node(V.v),K={rank:(C.node(V.w).rank-H.rank)/2+H.rank,e:V};u.addDummyNode(C,"edge-proxy",K,"_ep")}})}function z(C){let V=0;C.nodes().forEach(W=>{let H=C.node(W);H.borderTop&&(H.minRank=C.node(H.borderTop).rank,H.maxRank=C.node(H.borderBottom).rank,V=Math.max(V,H.maxRank))}),C.graph().maxRank=V}function j(C){C.nodes().forEach(V=>{let W=C.node(V);W.dummy==="edge-proxy"&&(C.edge(W.e).labelRank=W.rank,C.removeNode(V))})}function O(C){let V=Number.POSITIVE_INFINITY,W=0,H=Number.POSITIVE_INFINITY,K=0,J=C.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),K=Math.max(K,se+ue/2)}C.nodes().forEach(ie=>X(C.node(ie))),C.edges().forEach(ie=>{let de=C.edge(ie);Object.hasOwn(de,"x")&&X(de)}),V-=le,H-=te,C.nodes().forEach(ie=>{let de=C.node(ie);de.x-=V,de.y-=H}),C.edges().forEach(ie=>{let de=C.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=K-H+te}function _(C){C.edges().forEach(V=>{let W=C.edge(V),H=C.node(V.v),K=C.node(V.w),J,le;W.points?(J=W.points[0],le=W.points[W.points.length-1]):(W.points=[],J=K,le=H),W.points.unshift(u.intersectRect(H,J)),W.points.push(u.intersectRect(K,le))})}function T(C){C.edges().forEach(V=>{let W=C.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(C){C.edges().forEach(V=>{let W=C.edge(V);W.reversed&&W.points.reverse()})}function L(C){C.nodes().forEach(V=>{if(C.children(V).length){let W=C.node(V),H=C.node(W.borderTop),K=C.node(W.borderBottom),J=C.node(W.borderLeft[W.borderLeft.length-1]),le=C.node(W.borderRight[W.borderRight.length-1]);W.width=Math.abs(le.x-J.x),W.height=Math.abs(K.y-H.y),W.x=J.x+W.width/2,W.y=H.y+W.height/2}}),C.nodes().forEach(V=>{C.node(V).dummy==="border"&&C.removeNode(V)})}function q(C){C.edges().forEach(V=>{if(V.v===V.w){var W=C.node(V.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:V,label:C.edge(V)}),C.removeEdge(V)}})}function Y(C){var V=u.buildLayerMatrix(C);V.forEach(W=>{var H=0;W.forEach((K,J)=>{var le=C.node(K);le.order=J+H,(le.selfEdges||[]).forEach(te=>{u.addDummyNode(C,"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(C){C.nodes().forEach(V=>{var W=C.node(V);if(W.dummy==="selfedge"){var H=C.node(W.e.v),K=H.x+H.width/2,J=H.y,le=W.x-K,te=H.height/2;C.setEdge(W.e,W.label),C.removeNode(V),W.label.points=[{x:K+2*le/3,y:J-te},{x:K+5*le/6,y:J-te},{x:K+le,y:J},{x:K+5*le/6,y:J+te},{x:K+2*le/3,y:J+te}],W.label.x=W.x,W.label.y=W.y}})}function Q(C,V){return u.mapValues(u.pick(C,V),Number)}function $(C){var V={};return C&&Object.entries(C).forEach(([W,H])=>{typeof W=="string"&&(W=W.toLowerCase()),V[W]=H}),V}}),uh=Pe((e,n)=>{var s=Ze(),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:Ze().time,notime:Ze().notime},version:fh()}});const Sa=hh();const Ea={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=Ea[s.status]??Ea.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 Ma={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"}},Ia={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=Ma[s.status]??Ma.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 Ta(e,n,s="TB"){const r=o=>{const a=new Sa.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 Sa.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 Ra(e,n){if(e.length===0)return{nodes:[],direction:"TB"};const s=kh(e,n);if(s.length===1)return Ta(e,n);let r="TB";const i=s.map(m=>{const{nodes:u,direction:x}=Ta(m.nodes,m.edges);r=x;let M=1/0,S=-1/0,y=1/0,v=-1/0;for(const p of u)M=Math.min(M,p.position.x),S=Math.max(S,p.position.x+Ur),y=Math.min(y,p.position.y),v=Math.max(v,p.position.y+Qr);for(const p of u)p.position.x-=M,p.position.y-=y;return{nodes:u,w:S-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)),_a=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:x}=We(["work","common"]),M=wh(),[S,y]=g.useState(null),[v,p]=g.useState(null),[b,k]=g.useState(()=>new Set(Yr)),[N,I]=g.useState(m??null),[B,D]=g.useState(r??!1),A=r??B,E=g.useCallback(fe=>{const re=typeof fe=="function"?fe(A):fe;D(re),i?.(re)},[A,i]);g.useEffect(()=>{r!==void 0&&D(r)},[r]),g.useEffect(()=>{m&&I(m)},[m]);const P=g.useMemo(()=>e.filter(fe=>_a(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=Ia[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]),L=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:C,topLevelIds:V}=g.useMemo(()=>{const fe=(Ce,Xe)=>{const $e=new Set,Ae=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),Ae.push({id:Ye,type:"requirement",data:{req:_e,selected:_e.id===h},position:{x:0,y:0}})}const Ue=[];for(const _e of Ce)if(_e.blockedBy)for(const Ye of _e.blockedBy)$e.has(Ye)&&Ue.push(Q(Ye,_e.id,_e.status));const qt=new Set,Wt=(_e,Ye)=>{const tt=`${_e}->${Ye}`;qt.has(tt)||(qt.add(tt),Ue.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:Ae,edges:Ue}},re=e.filter(Ce=>z.has(Ce.status)&&(A||!_a(Ce))),xe=new Set;for(const Ce of Vn)b.has(Ce.id)&&xe.add(Ce.id);const Ee=n.filter(Ce=>{const Xe=Ia[Ce.status];return Xe&&xe.has(Xe)}),{nodes:ye,edges:Re}=fe(re,Ee),pt=new Set;for(const Ce of Re)pt.add(Ce.target);const nt=new Set(ye.filter(Ce=>!pt.has(Ce.id)).map(Ce=>Ce.id));if(!N||!nt.has(N)){const Ce=ye.filter(Ue=>nt.has(Ue.id)),{nodes:Xe,direction:$e}=Ra(Ce,[]);return{initialNodes:Xe.map(Ue=>({...Ue,data:{...Ue.data,direction:$e}})),initialEdges:[],topLevelIds:nt}}const{nodes:Nt,edges:Ct}=fe(e,n),st=Nh(N,R,L,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}=Ra(Ht,xt);return{initialNodes:Jt.map(Ce=>({...Ce,data:{...Ce.data,direction:bt}})),initialEdges:xt,topLevelIds:nt}},[e,n,T,R,L,Q,z,b,A,d,h,N,Y]),[W,H,K]=hf($),[J,le,te]=mf(C),X=g.useRef(null),ie=g.useRef({groupFilter:b,showArchived:A});g.useEffect(()=>{const fe=ie.current;(fe.groupFilter!==b||fe.showArchived!==A)&&(q.current=!1,I(null),ie.current={groupFilter:b,showArchived:A})},[b,A]),g.useEffect(()=>{H($),le(C),q.current||requestAnimationFrame(()=>{X.current?.fitView({padding:.2,duration:300})})},[$,C,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=L.get(re.id.slice(4));xe&&a&&a(xe)}else{const xe=R.get(re.id);xe&&o&&o(xe)}},[R,L,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)){_(x("work:dag.toast.dependencyExists"),"error");return}if(jh(R,re,xe)){_(x("work:dag.toast.cycleError"),"error");return}const ye=[...Ee.blockedBy??[],re];try{await ae.tasks.update(xe,{blockedBy:ye}),_(x("work:dag.toast.dependencyAdded")),l?.()}catch(Re){_(x("work:dag.toast.failed",{message:Re instanceof Error?Re.message:String(Re)}),"error")}},[R,_,l,x]),ue=g.useCallback((fe,re)=>{p(re)},[]),Z=g.useCallback(async()=>{if(!v)return;const fe=R.get(v.target);if(!fe){p(null);return}const re=(fe.blockedBy??[]).filter(xe=>xe!==v.source);try{await ae.tasks.update(v.target,{blockedBy:re}),_(x("work:dag.toast.dependencyRemoved")),l?.()}catch(xe){_(x("work:dag.toast.failed",{message:xe instanceof Error?xe.message:String(xe)}),"error")}p(null)},[v,R,_,l,x]);if(e.length===0)return t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"flex flex-col items-center gap-3 max-w-sm text-center",children:[t.jsx("svg",{className:"w-10 h-10 text-fg-quaternary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:x("work:task.dagEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:x("work:task.dagEmptyDesc")})]})});const ce=b.size===Yr.size&&[...Yr].every(fe=>b.has(fe))&&!A,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:K,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:x(`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 ${A?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:x("work:dag.archivedToggle",{count: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:x("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:x("work:dag.backToOverview")}):t.jsx("span",{children:x("work:dag.expandHint")}),t.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),t.jsx("span",{children:x("work:dag.dragHint")})]})]}),S&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${S.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:S.msg}),v&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>p(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:fe=>fe.stopPropagation(),children:[t.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:x("work:dag.removeDependencyTitle")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:x("work:dag.removeDependencyBody",{target:ve?.title??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:()=>p(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:x("common:cancel")}),t.jsx("button",{onClick:Z,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:x("common:remove")})]})]})})]})}function 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([]),[x,M]=g.useState([]),[S,y]=g.useState(!1),[v,p]=g.useState(""),[b,k]=g.useState(!1),N=vr();g.useEffect(()=>{ae.teams.list().then(D=>M(D.teams)).catch(()=>{})},[]),g.useEffect(()=>{const D=A=>{A.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()||S)){y(!0),p("");try{const A=l.trim()?[{url:l.trim(),defaultBranch:h.trim()||"main"}]:[],E=await ae.projects.create({name:i.trim(),description:a.trim()||void 0,repositories:A.length>0?A:void 0,teamIds:m.length>0?m:void 0,orgId:e??"default"});n(E.project)}catch(A){p(A instanceof Error?A.message:r("project.failedToCreate"))}y(!1)}},[i,a,l,h,m,e,S,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),p("")},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})]}),x.length>0&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.assignTeams")}),t.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:x.map(D=>{const A=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:A,onChange:()=>u(E=>A?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()||S,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:r(S?"common:creating":"project.createProject")})]})]})]})}),document.body)}function 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:x}=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:x("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:x("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:x("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:x("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:x("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:x("work:task.all")})}),(i??0)>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:i})]}),e.map(S=>{const y=!M&&S.id===n,v=r[S.id]??0,p=S.status==="paused";return t.jsxs("button",{type:"button","data-project-id":S.id,onClick:()=>a(S.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:S.name[0]?.toUpperCase()??"?"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block text-[12px] font-medium truncate",children:S.name}),p&&t.jsx("span",{className:"block text-[10px] text-amber-500/80",children:x("work:project.statusPaused")})]}),v>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:v})]},S.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:Ua({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(Qa,{entries:e,isActive:!0,onCollapse:()=>s("compact"),embedded:!0})})}function pl(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),x=pl(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??"",S=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&&x&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:x.flipUp?{bottom:window.innerHeight-x.top,left:x.left,width:x.width}:{top:x.top,left:x.left,width:x.width},children:S.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):S.map(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),x=pl(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)),S=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&&x&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:x.flipUp?{bottom:window.innerHeight-x.top,left:x.left,width:x.width}:{top:x.top,left:x.left,width:x.width},children:S.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):S.map(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 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 Th({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 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&&(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 _h=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function xl(e){const n=e.match(_h);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 La=[{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 Lh(e){let n=0;for(let s=0;s<e.length;s++)n=(n<<5)-n+e.charCodeAt(s)|0;return La[Math.abs(n)%La.length]}function Dh({note:e,compact:n}){const{t:s}=We(["work","common"]),r=xl(e),i=s("work:task.systemAuthor"),o=Lh(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 Ph=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"}],Da={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"},Pa={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"},$a={low:"bg-gray-500/15 text-fg-tertiary",medium:"bg-blue-500/15 text-blue-500",high:"bg-amber-500/15 text-amber-600",urgent:"bg-red-500/15 text-red-500"},Oa={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-brand-500/15 text-brand-500",completed:"bg-green-500/15 text-green-600",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-600/15 text-fg-tertiary",archived:"bg-gray-600/10 text-fg-tertiary/60"};function bl(e){return Object.keys(Pa).reduce((n,s)=>(n[s]={label:e(`work:status.task.${s}`),cls:Pa[s]},n),{})}function yl(e){return Object.keys(Da).reduce((n,s)=>(n[s]={label:e(`work:status.sub.${s}`),cls:Da[s]},n),{})}function $h(e){return Object.keys($a).reduce((n,s)=>(n[s]={label:e(`work:priority.${s}`),cls:$a[s]},n),{})}function ao(e){return Object.keys(Oa).reduce((n,s)=>(n[s]={label:e(`work:status.requirement.${s}`),cls:Oa[s]},n),{})}const Ba=["low","medium","high","urgent"],za=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],Ha=["pending","in_progress","completed","rejected","cancelled"],qa={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"},Wa={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function Oh({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([]),[x,M]=g.useState(!1),S=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]),p=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=>Ua(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(()=>Ls(m.map(As).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:p,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:r(h?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&t.jsxs("button",{onClick:()=>{const 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:S,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:x?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:r("work:task.loadingExecutionLog")}):b.length===0?t.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:r("work:task.noExecutionLogAvailable")}):t.jsx(Qa,{entries:m,isActive:!1,onCollapse:()=>f(!1),embedded:!0})})]}),l&&t.jsx(Oh,{agent:l.agent,anchorRect:{top:l.top,left:l.left},onClose:()=>d(null)})]})}function Bh({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 p=v.payload.comment;a(b=>b.some(k=>k.id===p.id)?b:[...b,p]),(p.authorType==="agent"||p.authorId?.startsWith("agt_"))&&(l(b=>{const k=b.filter(N=>N.id!==p.authorId);return k.length===0&&d.current&&(clearTimeout(d.current),d.current=null),k}),f(b=>{const k=new Map(b);return k.delete(p.authorId),k}))}}),[e.id]),g.useEffect(()=>{if(c.length===0)return;const y=new Set(c.map(p=>p.id));return jt.on("agent:activity_log",p=>{const b=p.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 p=xl(v);let b;if(p.timestamp){const k=p.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,p)=>v.ts.getTime()-p.ts.getTime()),y},[e.notes,o]),[u,x]=g.useState(null),M=async(y,v,p,b)=>{let k;p.length>0&&(k=(await ae.uploads.upload(p.map(A=>({dataUrl:A.dataUrl,name:A.name})),"comments")).files.map(A=>({type:"image",url:A.url,name:A.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 A=n.find(E=>E.id===D);A&&N.push({id:A.id,name:A.name,avatarUrl:A.avatarUrl})};for(const D of v){const A=n.find(E=>E.name.toLowerCase()===D.toLowerCase());A&&B(A.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))},S=g.useCallback(y=>{x({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(Dh,{note:y.note,compact:!0},`n-${v}`):t.jsx(ur,{comment:y.comment,agents:n,onReply:S},`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(ei,{agents:n,humans:s,onSubmit:M,replyTo:u,onCancelReply:()=>x(null),placeholder:i("work:task.commentPlaceholder")})]})}function zh({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([]),[x,M]=g.useState(""),[S,y]=g.useState(n),[v,p]=g.useState(!0),[b,k]=g.useState(new Set),[N,I]=g.useState(""),[B,D]=g.useState(!1),[A,E]=g.useState([]),P=g.useRef(null),[z,j]=g.useState(new Map),[O,_]=g.useState([]),[T,R]=g.useState([]),[L,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(()=>{p(!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){p(!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]])),p(!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},Z=ue.executionRound??1;c(ce=>ce.find(ve=>ve.round===Z)?ce:[...ce,{round:Z,logCount:0,toolCount:0,firstAt:ue.createdAt,lastAt:ue.createdAt,status:"running"}]),k(ce=>ce.has(Z)?ce:new Set(ce).add(Z)),d(ce=>{const ge=ce.get(Z)??[];return ue.id&&ge.some(ve=>ve.id===ue.id)?ce:new Map(ce).set(Z,[...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===Z?{...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(Z=>Z.some(ce=>ce.id===ue.id)?Z:[...Z,ue]),(ue.authorType==="agent"||ue.authorId?.startsWith("agt_"))&&(E(Z=>{const ce=Z.filter(ge=>ge.id!==ue.authorId);return ce.length===0&&P.current&&(clearTimeout(P.current),P.current=null),ce}),j(Z=>{const ce=new Map(Z);return ce.delete(ue.authorId),ce}))});return()=>{X(),ie(),de()}},[i]),g.useEffect(()=>{if(A.length===0)return;const X=new Set(A.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(Z=>so(Z,me,ue))})},[A]);const C=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(()=>C.map(X=>_o(X)),[C]),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=""}},K=async()=>{if(!(!N.trim()&&O.length===0)){D(!0);try{let X;O.length>0&&(X=(await ae.uploads.upload(O.map(Z=>({dataUrl:Z.url,name:Z.name})),"comments")).files.map(Z=>({type:"image",url:Z.url,name:Z.name})));const ie=await ae.tasks.addComment(i,N,s?.name,X,s?.id);ie.comment&&u(ue=>ue.some(Z=>Z.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 Z=r.find(ce=>ce.id===ue);Z&&de.push({id:Z.id,name:Z.name,avatarUrl:Z.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(),K())},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:()=>{K()},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&&!x){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 Z="📋",ce=o("work:task.emptyLogs.default"),ge=o("work:task.emptyLogs.defaultHint");return ue?(Z="👤",ce=o("work:task.emptyLogs.noAgent"),ge=o("work:task.emptyLogs.noAgentHint")):se?(Z="⏳",ce=o("work:task.emptyLogs.pending"),ge=o("work:task.emptyLogs.pendingHint")):me&&de?(Z="🔄",ce=o("work:task.emptyLogs.agentBusy",{agent:X?.name??e.assignedAgentId}),ge=o("work:task.emptyLogs.agentBusyHint")):me&&(Z="⏳",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:L?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:Z}),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=>As(se)).filter(se=>se!==null),ie=Ao(C,Ls(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(Lo,{entry:se.entry,showTime:!0,isLast:me===de.length-1},`e-${me}`)),S&&x&&t.jsx(Do,{content:x}),S&&!x&&ie.length>0&&t.jsx(Po,{})]}),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),Z=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})}),Z.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",Z.length]}),se&&S&&t.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.toolCount",{count: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=>_o(ye)).map(ye=>As(ye)).filter(ye=>ye!==null),Ee=[...Ao(me,Ls(re)).map(ye=>({kind:"entry",entry:ye,ts:ye.timestamp?new Date(ye.timestamp).getTime():0})),...Z.map(ye=>({kind:"comment",comment:ye,ts:new Date(ye.createdAt).getTime()}))];return Ee.sort((ye,Re)=>ye.ts-Re.ts),Ee.map((ye,Re)=>ye.kind==="comment"?t.jsx(ur,{comment:ye.comment,agents:r},`c-${ye.comment.id}`):t.jsx(Lo,{entry:ye.entry,showTime:!0,isLast:Re===Ee.length-1},`e-${Re}`))})(),se&&S&&x&&t.jsx(Do,{content:x}),se&&S&&!x&&!ue&&t.jsx(Po,{})]})]},X.round)}),A.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:A.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 Va=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 Hh({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]),x=()=>o(k=>k.length>1?k.slice(0,-1):k),M=i.length>1,S=k=>{ae.files.reveal(k).catch(()=>{})},y=k=>{k.isDirectory||Va.has(k.ext)?u(k.path):S(k.path)},v=a.split("/").pop()??a,p=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:x,className:"text-fg-tertiary hover:text-fg-primary text-sm shrink-0 p-1 -ml-1 rounded hover:bg-surface-elevated/60 transition-colors",title:r("common:back"),children:t.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),p?t.jsx("svg",{className:"w-4 h-4 text-amber-500 shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l.872.87A.5.5 0 008.665 3.5H13.5A1.5 1.5 0 0115 5v8.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-10z"})}):t.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),t.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),t.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:v}),p&&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():S(a),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:r(s?"work:task.openInDeliverables":"work:task.openInFinder"),children:t.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),t.jsx("button",{onClick:n,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]})]}),t.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:a})}),t.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[f&&t.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.filePreviewLoading")}),d&&t.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:d}),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&&!Va.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:()=>S(a),className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",children:r("work:task.openInFinder")})]}):t.jsx(Ql,{content:c.content,format:c.type==="text"?"text":c.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function Fa({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"]),x=g.useMemo(()=>bl(u),[u]),[M,S]=g.useState([]),[y,v]=g.useState(""),[p,b]=g.useState(!1),[k,N]=g.useState(!1),[I,B]=g.useState(null),[D,A]=g.useState(null),[E,P]=g.useState(!1),[z,j]=g.useState(!1),[O,_]=g.useState(!1),[T,R]=g.useState("every"),[L,q]=g.useState(""),[Y,F]=g.useState(""),[Q,$]=g.useState(""),[C,V]=g.useState(!1),[W,H]=g.useState("details"),K=g.useRef(null),[J,le]=g.useState("none"),te=g.useCallback(G=>{H(G),requestAnimationFrame(()=>{K.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=K.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 je=new ResizeObserver(pe);return je.observe(G),()=>{G.removeEventListener("scroll",pe),je.disconnect()}},[W]),g.useEffect(()=>{if(!d)return;H("details");const G=setTimeout(()=>{const pe=K.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),[Z,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[Re,pt]=g.useState(!1),[nt,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);S(G.subtasks)}catch{}},[e.id]);g.useEffect(()=>{$e()},[$e]);const Ae=async G=>{if(!C){V(!0);try{await G(),c(),await $e()}catch(pe){se(String(pe).replace("Error: ",""))}finally{V(!1)}}},Ue=G=>Ae(()=>ae.tasks.update(e.id,{priority:G})),qt=G=>Ae(()=>ae.tasks.assign(e.id,G||null)),Wt=G=>Ae(()=>ae.tasks.update(e.id,{projectId:G||null})),_e=async()=>{if(!C){V(!0);try{await ae.tasks.pause(e.id),c()}finally{V(!1)}}},Ye=async()=>{if(!C){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(!C){V(!0);try{await ae.tasks.updateStatus(e.id,"in_progress"),c()}finally{V(!1)}}},Le=async()=>{if(!C){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(!C){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,Je=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(je=>je.id===G);return pe&&pe.status==="completed"})),Vt=e.status==="completed",St=e.status==="failed",Et=e.status==="rejected",et=e.status==="cancelled",ft=e.status==="archived",fn=Vt||St||Et||et||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=x[e.status];return G?t.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${G.cls}`,children:G.label}):t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium bg-gray-500/15 text-fg-tertiary whitespace-nowrap align-middle",children:e.status.replace(/_/g," ")})})(),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:K,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(zh,{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&&Ae(()=>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),je=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 ${je?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:je?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${je?"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.jsxs("select",{value:"",onChange:async G=>{const pe=G.target.value;if(!pe)return;const je=[...e.blockedBy??[],pe];await ae.tasks.update(e.id,{blockedBy:je}),c()},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"",children:u("work:task.addDependency")}),i.filter(G=>G.id!==e.id&&!(e.blockedBy??[]).includes(G.id)).map(G=>t.jsx("option",{value:G.id,children:G.title},G.id))]})]}),t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.projectLabel")}),t.jsxs("select",{value:e.projectId??"",onChange:G=>{Wt(G.target.value)},disabled:C,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=>Ae(()=>ae.tasks.update(e.id,{requirementId:G.target.value||null})),disabled:C,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:C,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 je=pe.startsWith("human:"),Me=pe.replace(/^(human|agent):/,"");(Me!==e.reviewerId||(je?"human":"agent")!==(e.reviewerType??"agent"))&&Ae(()=>ae.tasks.update(e.id,{reviewerId:Me,reviewerType:je?"human":"agent"}))},disabled:C,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=>{Ue(G.target.value)},disabled:C,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:[Je>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:Je})}),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&&!p&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:u("work:task.noSubtasksYet")}),p&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value: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"},je=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:je.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(Bh,{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"},je=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})}),je>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,"/",je]}),t.jsx("button",{disabled:Ct>=je,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:()=>K.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=K.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 je=Math.floor(pe/60);return je<24?u("work:task.scheduleInHoursMinutes",{h:je,m:pe%60}):u("work:task.scheduleInDaysHours",{d:Math.floor(je/24),h:je%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:L,onChange:G=>q(G.target.value),className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[t.jsx("option",{value:"30m",children:u("work:task.freq30m")}),t.jsx("option",{value:"1h",children:u("work:task.freq1h")}),t.jsx("option",{value:"2h",children:u("work:task.freq2h")}),t.jsx("option",{value:"4h",children:u("work:task.freq4h")}),t.jsx("option",{value:"8h",children:u("work:task.freq8h")}),t.jsx("option",{value:"12h",children:u("work:task.freq12h")}),t.jsx("option",{value:"1d",children:u("work:task.freq1d")}),t.jsx("option",{value:"1w",children:u("work:task.freq1w")})]}):t.jsx("input",{value: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=L:G.cron=Y.trim(),Q&&(G.maxRuns=parseInt(Q,10)),await Ae(()=>ae.tasks.updateSchedule(e.id,G)),_(!1)},disabled:C,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 je=Math.floor(pe/60);return je<24?u("work:task.noteTimeHours",{count:je}):u("work:task.noteTimeDays",{count:Math.floor(je/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}Ae(()=>ae.tasks.approve(e.id))},disabled:C,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);A({dependentCount:G})},disabled:C,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:C,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:()=>{Ae(()=>ae.tasks.accept(e.id,l?.id))},disabled:C,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")}),Re?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:nt,onChange:G=>Nt(G.target.value),onKeyDown:G=>{G.key==="Enter"&&nt.trim()&&(Ae(()=>ae.tasks.revision(e.id,nt.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:()=>{Ae(()=>ae.tasks.revision(e.id,nt.trim()||u("work:task.revisionsNeededDefault"),l?.id)),pt(!1),Nt("")},disabled:C,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:C,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:C,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:()=>{Le()},disabled:C,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:C,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:C?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:()=>{Le()},disabled:C,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:C,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||et)&&!ft&&t.jsx("button",{onClick:()=>{ze()},disabled:C,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:C?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:()=>{Ae(()=>ae.tasks.resumeSchedule(e.id))},disabled:C,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:()=>{Ae(()=>ae.tasks.pauseSchedule(e.id))},disabled:C,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||et)&&t.jsx("button",{onClick:()=>j(!0),disabled:C,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:C,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);A({dependentCount:G})},disabled:C,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),Ae(()=>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),Ae(()=>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:()=>A(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:()=>{A(null),Ae(()=>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:()=>{A(null),Ae(()=>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:()=>A(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:()=>{A(null),Ae(()=>ae.tasks.cancel(e.id))},onCancel:()=>A(null)}),Z&&t.jsx(Hh,{filePath:Z,onClose:()=>ce(null),onOpenExternal:()=>{ce(null),ae.deliverables.search({taskId:e.id,limit:100}).then(({results:G})=>{const pe=G.find(je=>je.reference===Z);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:C,onClick:()=>{ue(!1),Ae(()=>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:C,onClick:()=>{ue(!1),Ae(()=>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 qh({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),[x,M]=g.useState(""),[S,y]=g.useState("main"),[v,p]=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){p(!0);try{await o({status:E}),a()}finally{p(!1)}}},D=async()=>{const E=x.trim();if(!E)return;const P=[...e.repositories??[],{url:"",localPath:E,defaultBranch:S||"main"}];await o({repositories:P}),M(""),y("main"),u(!1),a()},A=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(Rh,{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:()=>A(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:x,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:S,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:!x.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children: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"},Wh={urgent:0,high:1,medium:2,low:3},os={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Ya={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"},Vh={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"},Fh=["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 Ga(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 Zr({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:x}=We(["work","common"]),M=g.useMemo(()=>bl(x),[x]),S=g.useMemo(()=>ao(x),[x]),y=g.useMemo(()=>$h(x),[x]),v=e.data.status,p=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:x("work:task.requirementShort")}):e.data.taskType==="scheduled"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600",children:x("work:task.schedShort")}):t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:x("work:task.taskShort")});return m?t.jsxs("div",{"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 ${Ya[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(Zr,{value:v,options:e.kind==="task"?za.map(I=>({value:I,label:M[I]?.label??I,cls:M[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Ha.map(I=>({value:I,label:S[I]?.label??I,cls:S[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?qa[v]:qs[v],onSelect:I=>{d(e,I)}})}),t.jsx("div",{onClick:I=>I.stopPropagation(),children:t.jsx(Zr,{value:p,options:Ba.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:`${Wa[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:Ga(e.data.updatedAt??"",x)})]})]}):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 ${Ya[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(Zr,{value:v,options:e.kind==="task"?za.map(I=>({value:I,label:M[I]?.label??I,cls:M[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Ha.map(I=>({value:I,label:S[I]?.label??I,cls:S[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?qa[v]:qs[v],onSelect:I=>{d(e,I)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:I=>I.stopPropagation(),children:t.jsx(Zr,{value:p,options:Ba.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 ${Wa[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:Ga(e.data.updatedAt??"",x)})]})}function Yh({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,x]=g.useState(null),[M,S]=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 L=y.get(R);return L&&L.status==="completed"}),[y]),p=g.useMemo(()=>{const T=[];for(const R of e){const L=wl(R.status);T.push({kind:"task",data:R,group:L,groupOrder:os[L]??5})}for(const R of n){const L=Jr[R.status]??"todo";T.push({kind:"req",data:R,group:L,groupOrder:os[L]??5})}if(f==="status")T.sort((R,L)=>{if(R.groupOrder!==L.groupOrder)return R.groupOrder-L.groupOrder;const q=new Date(R.data.updatedAt??0).getTime();return new Date(L.data.updatedAt??0).getTime()-q});else{const R=L=>Wh[L.data.priority]??2;T.sort((L,q)=>{const Y=R(L),F=R(q);return Y!==F?Y-F:new Date(q.data.updatedAt??0).getTime()-new Date(L.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)=>{x(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",x(null),S(null)},B=(T,R)=>{T.preventDefault(),T.dataTransfer.dropEffect="move",M!==R&&S(R)},D=async(T,R)=>{if(T.preventDefault(),S(null),u==null)return;const L=p[u];if(!L||L.group===R)return;const q=ss.find(Y=>Y.id===R);if(q){try{if(L.kind==="task"){if(L.data.status==="pending")return;await ae.tasks.updateStatus(L.data.id,q.dropStatus)}else{const Y=vl[R];Y&&await ae.requirements.updateStatus(L.data.id,Y)}a()}catch{}x(null)}},A=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 p)T[R.group]=(T[R.group]??0)+1;return T},[p]),{rowsByGroup:j,rowIndexMap:O}=g.useMemo(()=>{const T=new Map,R=new Map;for(let L=0;L<p.length;L++){const q=p[L];R.set(q,L);const Y=T.get(q.group)??[];Y.push(q),T.set(q.group,Y)}return{rowsByGroup:T,rowIndexMap:R}},[p]),_=g.useMemo(()=>{if(f!=="status")return null;const T=new Set(p.map(q=>q.group)),R=[],L=new Set;T.has("failed")&&(R.push("failed"),L.add("failed"));for(const q of P)R.push(q),L.add(q);for(const q of p)L.has(q.group)||(R.push(q.group),L.add(q.group));return R},[p,f]);return t.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${h?"overflow-x-hidden w-full":""}`,children:t.jsxs("div",{className:h?"w-full":"w-fit min-w-full",children:[!h&&t.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider sticky top-0 z-20 bg-surface-primary",children:[t.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:p.length}),t.jsx("div",{className:"flex-1 min-w-[200px]",children:d("work:task.backlogTitle")}),t.jsxs("button",{onClick:()=>m("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[d("work:filters.status")," ",f==="status"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsxs("button",{onClick:()=>m("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${f==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[d("work:filters.priority")," ",f==="priority"&&t.jsx("span",{className:"text-[8px]",children:"▼"})]}),t.jsx("div",{className:"w-[120px] shrink-0",children:d("work:filters.assignee")}),t.jsx("div",{className:"w-[120px] shrink-0",children:d("work:task.projectLabel")}),t.jsx("div",{className:"w-[90px] shrink-0 text-right",children:d("work:task.backlogUpdated")})]}),t.jsxs("div",{children:[f==="status"&&_?_.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 ${Vh[T]??""} ${M===T?"ring-1 ring-brand-500/40":""}`,onDragOver:L=>B(L,T),onDragLeave:()=>S(null),onDrop:L=>{D(L,T)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:d(`work:boardColumn.${T}`)}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:z[T]??0})]}),R.map(L=>t.jsx(Za,{row:L,idx:O.get(L)??0,dragIdx:u,agentMap:A,projMap:E,onTaskClick:i,onReqClick:o,onRowDragStart:N,onRowDragEnd:I,handleStatusChange:b,handlePriorityChange:k,selected:L.kind==="task"?L.data.id===c:L.data.id===l,isMobile:h,isAbnormalBlocked:L.kind==="task"?v(L.data):!1},`${L.kind}-${L.data.id}`))]},T)}):p.map((T,R)=>t.jsx(Za,{row:T,idx:R,dragIdx:u,agentMap:A,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}`)),p.length===0&&t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3 max-w-sm mx-auto text-center",children:[t.jsx("svg",{className:"w-10 h-10 text-fg-quaternary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),t.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:d("work:task.backlogEmptyTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:d("work:task.backlogEmptyDesc")})]})]})]})})}function Ws(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function Gh(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 Kr(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function Zh(e,n,s){const r=[];r.push(`name: ${Kr(e)}`),r.push(`description: ${Kr(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: ${Kr(i.name)}`),r.push(" type: agent_task"),r.push(` role: ${Kr(i.role)}`),i.depends_on.length>0&&r.push(` depends_on: [${i.depends_on.join(", ")}]`),i.depends_on.length>0){r.push(" inputs:");for(const o of i.depends_on)r.push(` - from: ${o}`),r.push(` as: ${o}_output`)}r.push(" prompt: |");for(const o of i.prompt.split(`
8
- `))r.push(` ${o}`);r.push("")}return r.join(`
9
- `)}function Kh({req:e,tasks:n,agents:s,teamId:r,onClose:i,onSaved:o}){const{t:a}=We(["work"]),c=g.useMemo(()=>{const D={};for(const A of s)D[A.id]=A.name;return D},[s]),l=g.useMemo(()=>Gh(n,c),[n,c]),[d,h]=g.useState(()=>Ws(e.title)),[f,m]=g.useState(e.description||e.title),[u,x]=g.useState(l),[M,S]=g.useState(!1),[y,v]=g.useState(null),p=(D,A,E)=>{x(P=>P.map((z,j)=>j===D?{...z,[A]:E}:z))},b=D=>{const A=u[D]?.id;x(E=>E.filter((P,z)=>z!==D).map(P=>({...P,depends_on:P.depends_on.filter(z=>z!==A)})))},[k,N]=g.useState(!1),I=async()=>{if(d.trim()){S(!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))}S(!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,A)=>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:A+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=>p(A,"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=>p(A,"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(A),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 Ka({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 Xh({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),[x,M]=g.useState({}),[S,y]=g.useState(!1),[v,p]=g.useState(null),[b,k]=g.useState([]),[N,I]=g.useState(null),[B,D]=g.useState(null),[A,E]=g.useState({}),[P,z]=g.useState(null),[j,O]=g.useState(null),[_,T]=g.useState(null),[R,L]=g.useState([]),[q,Y]=g.useState({}),[F,Q]=g.useState(null),[$,C]=g.useState({}),[V,W]=g.useState(new Set),H=e??N;g.useEffect(()=>{e||ae.teams.list().then(({teams:Z})=>{k(Z.map(ce=>({id:ce.id,name:ce.name})))}).catch(()=>{})},[e]),g.useMemo(()=>{const Z={};for(const ce of s)Z[ce.id]=ce.name;return Z},[s]);const K=g.useCallback(async()=>{const Z=H?[H]:b.map(ce=>ce.id);if(Z.length!==0){f(!0);try{const ce=[],ge={},ve={};await Promise.all(Z.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),C(ve)}catch{}f(!1)}},[H,b]);g.useEffect(()=>{K()},[K]);const J=Z=>H??$[Z],le=async Z=>{if(B===Z.name){D(null);return}D(Z.name);const ce=J(Z.name);if(!A[Z.name]&&ce)try{const{template:ge}=await ae.workflows.get(ce,Z.name);E(ve=>({...ve,[Z.name]:ge}))}catch{}},te=Z=>{const ce={};for(const re of Z.params??[])re.default&&(ce[re.name]=re.default);M(ce),p(null),L([]),Y({});const ge=localStorage.getItem(`markus_wf_project_${Z.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(Z);const fe=J(Z.name);fe&&ae.workflows.roles(fe,Z.name).then(({roles:re})=>L(re)).catch(()=>{})},X=async()=>{const Z=F??r[0]?.id,ce=m?J(m.name):void 0;if(!m||!ce||!Z){p(Z?o("work:task.workflowNoTeam","Cannot determine team for this workflow"):o("work:task.workflowNoProject","Please select a project"));return}y(!0),p(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,Z,x,ge),localStorage.setItem(`markus_wf_project_${m.name}`,Z),localStorage.setItem("markus_wf_project_last",Z),u(null),K()}catch(ge){p(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 Z=>{z(Z),O(null);try{await ae.workflows.cancelRun(Z),K()}catch{}z(null)},de=async Z=>{T(Z.id);try{Z.status==="running"?await ae.workflows.pauseRun(Z.id):Z.status==="paused"&&await ae.workflows.resumeRun(Z.id),K()}catch{}T(null)},se=Z=>{Z.requirementId&&i&&i(Z.requirementId)},me=Z=>{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[Z]??"bg-gray-500/20 text-gray-400"}`,children:Z})},ue=m&&(m.params??[]).some(Z=>Z.required&&!x[Z.name]?.trim());return t.jsxs("div",{className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:[!e&&b.length>0&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-4",children:[t.jsx("button",{onClick:()=>{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(Z=>t.jsx("button",{onClick:()=>{N!==Z.id&&(I(Z.id),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${N===Z.id?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:Z.name},Z.id))]}),a.length===0&&!h?t.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:t.jsx(Ka,{teamId:H,agents:s})}):t.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[a.map(Z=>{const ce=B===Z.name,ge=A[Z.name],fe=(l[Z.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(Z),children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("svg",{className:`w-3.5 h-3.5 text-fg-tertiary shrink-0 transition-transform ${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:Z.displayName||Z.name}),t.jsx("span",{className:"text-[11px] text-fg-tertiary",children:o("work:task.workflowStepsCount","{{count}} steps",{count:Z.stepCount})})]})}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t.jsxs("span",{className:"text-[10px] text-fg-quaternary font-mono cursor-pointer hover:text-fg-tertiary transition-colors",title:o("work:task.workflowSendToAgent","Send to agent chat"),onClick:re=>{re.stopPropagation();const xe=J(Z.name),ye=(xe?s.find(Re=>Re.teamId===xe&&Re.agentRole==="manager"):void 0)?.id??s.find(Re=>Re.agentRole==="manager")?.id??s[0]?.id;ye&&Bt.navigate(Fe.TEAM,{agentId:ye,prefillMessage:`@[${Z.displayName||Z.name}](workflow:${Z.name}) `})},children:[t.jsx("svg",{className:"w-3.5 h-3.5 inline mr-0.5 -mt-px",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),Z.name]}),Z.hasSchedule&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-500/20 text-purple-400",children:o("work:task.workflowScheduled","Scheduled")}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["v",Z.version]}),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(Z)},className:"px-3 py-1 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:o("work:task.workflowRun","Run")})]})]}),ce&&ge&&t.jsxs("div",{className:"border-t border-border-default/30 pt-3 mt-1 ml-5 space-y-3",children:[Z.description&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:Z.description}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:o("work:task.workflowSteps","Steps")}),t.jsx("div",{className:"space-y-1.5",children: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[Z.name]??[];if(re.length===0)return null;const xe=V.has(Z.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 Re=new Set(ye);return Re.has(Z.name)?Re.delete(Z.name):Re.add(Z.name),Re}),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:Re=>{Re.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:Re=>{Re.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))})]})})()]},Z.name)}),t.jsx(Ka,{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:Z=>Z.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-1",children:o("work:task.workflowRunTitle","Run: {{name}}",{name:m.displayName||m.name})}),t.jsx("p",{className:"text-xs text-fg-tertiary mb-4",children:m.description}),(m.params??[]).length>0&&t.jsx("div",{className:"space-y-3 mb-4",children:(m.params??[]).map(Z=>t.jsxs("div",{children:[t.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[Z.label||Z.name,Z.required&&t.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),Z.type==="enum"&&Z.options?t.jsxs("select",{value:x[Z.name]??"",onChange:ce=>M(ge=>({...ge,[Z.name]:ce.target.value})),className:"input-field text-xs w-full",children:[t.jsx("option",{value:"",children:"—"}),Z.options.map(ce=>t.jsx("option",{value:ce,children:ce},ce))]}):t.jsx("textarea",{value:x[Z.name]??"",onChange:ce=>{M(fe=>({...fe,[Z.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:Z.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},Z.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(Z=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs text-fg-secondary w-24 shrink-0 font-medium",children:Z.role}),t.jsx("select",{value:q[Z.role]??Z.recommended??"",onChange:ce=>Y(ge=>({...ge,[Z.role]:ce.target.value})),className:"input-field text-xs flex-1",children:Z.candidates.map(ce=>t.jsxs("option",{value:ce.agentId,children:[ce.agentName,ce.agentId===Z.recommended?" ★":""]},ce.agentId))})]},Z.role))})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1",children:o("work:task.workflowProject","Project")}),t.jsxs("select",{value:F??"",onChange:Z=>{const ce=Z.target.value||null;Q(ce),p(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(Z=>t.jsx("option",{value:Z.id,children:Z.name},Z.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:S||!!ue,className:"btn-primary text-xs px-4 py-1.5",children:S?o("work:task.workflowStarting","Starting..."):o("work:task.workflowStartRun","Start Run")})]})]})}),j&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>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:Z=>Z.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-2",children:o("work:task.workflowConfirmCancelTitle","Cancel Workflow Run")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-5",children:o("work:task.workflowConfirmCancelDesc","This will cancel all running and pending tasks in this workflow run. This action cannot be undone.")}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>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 rm({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(()=>ao(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[x,M]=g.useState(()=>{if(n)return!1;try{return localStorage.getItem(Aa)==="1"}catch{return!1}}),S=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"}),p=6,b=!l&&!x?v.width+p:0,k=Math.max(0,(m||window.innerWidth)-b-p-8),N=Math.max(320,Math.round(k/2)),[I,B]=g.useState("auto"),D=Math.max(320,k-280),A=I==="auto"?Math.min(N,D):I,E=Math.max(320,Math.min(A,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=Ne=>{const we=Math.max(320,Math.min(z.current,ee+(U-Ne.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,L]=g.useState(s?.projects??[]),[q,Y]=g.useState("all"),[F,Q]=g.useState(null),[$,C]=g.useState("closed"),[V,W]=g.useState("projects"),[H,K]=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,Z]=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,Re]=g.useState(""),[pt,nt]=g.useState(""),[Nt,Ct]=g.useState("medium"),[st,Ht]=g.useState(""),[xt,Jt]=g.useState(""),[bt,yt]=g.useState(""),[Ce,Xe]=g.useState(""),[$e,Ae]=g.useState([]),[Ue,qt]=g.useState("standard"),[Wt,_e]=g.useState("4h"),[Ye,tt]=g.useState(""),[un,Mn]=g.useState(!1),[Ge,Le]=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&&C("item")},[]);const[He,dt]=g.useState(new Set),[Je,it]=g.useState(!1),[ut,en]=g.useState(new Set),Vt=g.useRef(new Set),[St,Et]=g.useState(null),[et,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,et,ft),ht=g.useRef(null),G=g.useMemo(()=>({scrollContainerRef:ht}),[]),pe=_s($t,et,ft,G),[je,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,io]=g.useState(!1),[lo,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"&&(C("closed"),Le(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]),co=g.useCallback(()=>{F&&(Le(null),De(null),C("project"),B("auto"),l&&_(!0))},[F,l]),Mr=g.useCallback(()=>{if($==="project"){C("closed"),l&&_(!1);return}co()},[$,co,l]);g.useEffect(()=>{Vt.current=ut},[ut]);const bn=g.useCallback(async()=>{try{const{projects:w}=await ae.projects.list();L(w)}catch{}},[]),rt=g.useCallback(async()=>{const w={};q==="project"&&F&&(w.projectId=F);try{const{board:U}=await ae.tasks.board(w);K(U)}catch{}},[q,F]),nr=g.useCallback(async()=>{try{const{agents:w}=await ae.agents.list();le(w)}catch{}},[]),uo=g.useCallback(async()=>{try{const{teams:w}=await ae.teams.list();X(w.map(U=>({id:U.id,name:U.name})))}catch{}},[]),fo=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{}},[]),ho=g.useCallback(async()=>{await Promise.all([bn(),rt(),nr(),fo(),Rt(),uo()]),Z(!1)},[bn,rt,nr,fo,Rt,uo]);g.useEffect(()=>{n||ho()},[n,ho]),g.useEffect(()=>{!n||!s||(L(s.projects??[]),K(s.board??{}),le(s.agents??[]),de(s.users??[]),me(s.allRequirements??[]))},[n,s]);const Ir=g.useCallback(w=>{W("items"),Le(U=>U?.id===w.id&&$==="item"?(C("closed"),l&&T.current&&_(!1),null):(C("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"?(C("closed"),l&&T.current&&_(!1),null):(C("item"),B("auto"),l&&(_(!0),history.pushState({mobileDetail:Fe.WORK},"",window.location.hash)),w)),Le(null)},[l,$]),yn=g.useCallback(()=>{Le(null),De(null),C("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 An=g.useRef(x);An.current=x;const gs=g.useRef(et);gs.current=et;const Nl=g.useCallback(()=>{Le(null),Gt.current||(C("closed"),l&&T.current&&_(!1))},[l]);g.useEffect(()=>{if(!l)return;const w=()=>{T.current&&(_(!1),Le(null),De(null),C("closed"))};return window.addEventListener("popstate",w),()=>window.removeEventListener("popstate",w)},[l]),g.useEffect(()=>{if(n||!i)return;rt(),nr(),Rt();const w=Yt.current?12e4:45e3,U=setInterval(()=>{rt(),nr(),Rt()},w);let ee=null;const ne=()=>{ee||(ee=setTimeout(()=>{ee=null,rt()},800))};let he=null;const Ne=()=>{he||(he=setTimeout(()=>{he=null,Rt()},800))},we=jt.on("task:update",Oe=>{_t("/taskboard"),ne();const ke=Oe?.payload;ke?.taskId&&(Le(Ve=>{if(!Ve||Ve.id!==ke.taskId)return Ve;const Te={};return typeof ke.status=="string"&&(Te.status=ke.status),Array.isArray(ke.deliverables)&&(Te.deliverables=ke.deliverables),Array.isArray(ke.notes)&&(Te.notes=ke.notes),ke.result!==void 0&&(Te.result=ke.result),{...Ve,...Te}}),Yt.current?.id===ke.taskId&&(_t("/tasks/"+ke.taskId),ae.tasks.get(ke.taskId).then(Ve=>{Ve.task&&Le(Te=>Te?.id===Ve.task.id?Ve.task:Te)}).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"),Ne();const Ve=ke?.payload,Te=Ve?.id??Ve?.requirementId;Te&&Gt.current?.id===Te&&(_t("/requirements/"+Te),ae.requirements.get(Te).then(Xt=>{Xt.requirement&&De(jn=>jn?.id===Xt.requirement.id?Xt.requirement:jn)}).catch(()=>{}))})),mt=()=>{_t("/taskboard"),_t("/tasks"),_t("/requirements"),rt(),Rt(),Yt.current&&ae.tasks.get(Yt.current.id).then(Oe=>{Oe.task&&Le(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,rt,nr,Rt]);const mo=g.useRef(H);mo.current=H;const go=g.useRef(se);go.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&&Le(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)=>{Le(w),De(null),C("item"),W("items"),B("auto"),U?.scrollToComments&&rr(!0),l&&_(!0)},[l]),Ln=g.useCallback((w,U)=>{De(w),Le(null),C("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),Ln(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),Ln(ee.requirement))}).catch(()=>{Pn.current=null}))},[se,Ln,sn]);const Ot=g.useCallback((w,U)=>{en(new Set),Q(w),Y("project"),W(x?"items":"projects"),U?.keepItemDetail||(Le(null),De(null),C(ee=>ee==="closed"?ee:"project")),history.replaceState(null,"",ys(Fe.WORK,w))},[x]),Zt=g.useCallback(w=>{en(new Set),Q(null),Y("all"),W(x?"items":"projects"),w?.keepItemDetail||(Le(null),De(null),C(U=>U==="closed"?U:U==="project"?"closed":"empty")),history.replaceState(null,"",ys(Fe.WORK))},[x]),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,Zt({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,Zt({keepItemDetail:!0})}},[ue,Tt,F,Zt,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}):Zt({keepItemDetail:!0}))},U=async ee=>{const ne=ee.detail;if(Br(ne.page)===Fe.WORK){if(ne.params?.openTask){const he=ne.params.openTask,Ne=ne.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let we=Object.values(mo.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:Ne}))}if(ne.params?.openRequirement){const he=ne.params.openRequirement,Ne=ne.params.scrollToComments==="true";let we=go.current.find(oe=>oe.id===he);if(!we)try{we=(await ae.requirements.get(he)).requirement}catch{}we&&(sn(we.projectId),Ln(we,{scrollToComments:Ne}))}if(ne.params?.projectId&&Ot(ne.params.projectId),ne.params?.statusFilter){const he=ne.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),Ph.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")),L(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&&Zt(),ct(r("work:task.projectDeleted")),bn(),rt()}catch(U){ct(r("work:task.errorGeneric",{message:String(U)}))}},po=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,Ue!=="standard"?Ue:void 0,Ue==="scheduled"?{every:Wt}:void 0,w?"human":"agent");Re(""),nt(""),Ae([]),Xe(""),qt("standard"),_e("4h"),Ee(!1),rt(),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}))},xo=()=>{_t("/taskboard"),rt(),Ge&&($n({taskId:Ge.id}),_t("/tasks/"+Ge.id),ae.tasks.get(Ge.id).then(w=>{w.task&&Le(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(()=>{}))},bo=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(""),io(!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&&Ln(w)}catch(w){rn(w instanceof Error?w.message:String(w))}finally{io(!1)}}},xs=async w=>{try{await ae.requirements.approve(w),ct(r("work:task.requirementApproved")),$n({requirementId:w}),kn(),rt()}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))}}},yo=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"},vo=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)},Al=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 Ne=he.dropStatus;if(ee.status===Ne||ee.status==="pending")return;try{await ae.tasks.updateStatus(ee.id,Ne),rt()}catch{}}else if(ne){const he=vl[U];if(!he||ne.status===he)return;try{await ae.requirements.updateStatus(ne.id,he),Rt()}catch{}}},wo=w=>{dt(U=>{const ee=new Set(U);return ee.has(w)?ee.delete(w):ee.add(w),ee})},Rr=w=>{Ot(w)},Ll=new Set(["rejected","cancelled","archived"]),_r=w=>Ll.has(w.status),or=(w,U=!1)=>{let ee=w.filter(ne=>je||!_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))),Je&&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]),ko=w=>w.statuses.flatMap(U=>or(H[U]??[])),Kt=g.useMemo(()=>{let w=se;return je||(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))),Je&&e?.id&&(w=w.filter(U=>U.createdBy===e.id)),w},[se,je,q,F,ut,He,Je,e?.id,Pl]),jo=g.useCallback(w=>Kt.filter(U=>Jr[U.status]===w.id),[Kt]),$l=o.filter(w=>{if(w.id==="failed"||w.id==="closed"){const U=ko(w),ee=jo(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,No=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 Ne=ee.has(ne.id)?0:1,we=ee.has(he.id)?0:1;return Ne-we})},[J,H,F]),Ar=g.useMemo(()=>{const w=new Map,U=[];for(const ne of No)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},[No,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[...je?R:R.filter(he=>he.status!=="archived")].sort((he,Ne)=>{const we=he.status==="archived"?1:0,oe=Ne.status==="archived"?1:0;if(we!==oe)return we-oe;const Qe=ee.has(he.id)?0:1,kt=ee.has(Ne.id)?0:1;return Qe!==kt?Qe-kt:he.name.localeCompare(Ne.name)})},[R,H,je]);const Lr=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(Lr).reduce((w,U)=>w+U,0),Ol=F?Lr[F]??0:Dr,Co=g.useMemo(()=>{const w=or(Object.values(H).flat()),U=[];if(et==="kanban"){for(const ne of ss){const he=ne.statuses.flatMap(oe=>w.filter(Qe=>Qe.status===oe)),we=[...Kt.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,Qe)=>Qe.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 Kt){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,Kt,et,je,Se,F,ut,He,Je,e?.id,q]),Pr=g.useRef(Co);Pr.current=Co;const So=g.useRef(Tt);So.current=Tt;const bs=g.useRef(F);bs.current=F;const On=g.useCallback(w=>{w.kind==="req"?(De(w.data),Le(null)):(Le(w.data),De(null)),C("item"),B("auto"),W("items")},[]),Eo=g.useCallback(()=>{if(vn.current==="item"||vn.current==="empty"){C("closed"),Le(null),De(null);return}if(Yt.current||Gt.current){C("item"),B("auto"),W("items");return}const w=Pr.current;if(w.length>0){On(w[0]);return}Le(null),De(null),C("empty"),B("auto")},[On]);g.useEffect(()=>{if(!l)if(x){if(W("items"),vn.current==="project")if(Yt.current||Gt.current)C("item");else{const w=Pr.current;w.length>0?On(w[0]):C("closed")}}else _n.current==="items"&&vn.current==="closed"||!x&&vn.current==="closed"&&W("projects")},[x,l,On]);const ir=d?.keyboardPane??"content",Mo=g.useRef(ir);if(g.useEffect(()=>{if(n||l||!i)return;const w=Mo.current;Mo.current=ir,ir==="l1"&&(W("projects"),w!=="l1"&&An.current&&(S(!1),d?.setLeftCollapsed(!1)))},[ir,n,l,i,S,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),Te=ee.shiftKey?ke[(Ve-1+ke.length)%ke.length]:ke[(Ve+1)%ke.length];ft(Te);return}if(ne&&!ee.altKey&&!ee.shiftKey){const ke=ee.key.toLowerCase();if(ke==="j"){ee.preventDefault(),Mr();return}if(ke==="l"){ee.preventDefault(),Eo();return}}if(ne||ee.altKey||ee.ctrlKey||ee.metaKey||Kl(ee.target))return;const he=ee.key.length===1?ee.key.toLowerCase():ee.key;if(he==="h"||he==="ArrowLeft"){if(An.current){ee.preventDefault(),S(!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)&&!An.current&&_n.current==="projects"){ee.preventDefault(),W("items"),d?.setKeyboardPane("content");return}if((he==="l"||he==="ArrowRight")&&(An.current||_n.current==="items")){ee.preventDefault();return}const Ne=he==="j"||he==="ArrowDown"?1:he==="k"||he==="ArrowUp"?-1:0;if(!Ne)return;if((An.current?"items":_n.current)==="projects"){ee.preventDefault(),d?.setKeyboardPane("l1");const ke=So.current,Ve=ke.length+1;if(ke.length===0)return;const Te=bs.current==null?0:ke.findIndex(Bn=>Bn.id===bs.current)+1,Xt=Te<0?0:Te,jn=Math.max(0,Math.min(Ve-1,Xt+Ne));if(jn===0)Zt(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const Bn=ke[jn-1];Ot(Bn.id),vn.current!=="closed"&&(C("project"),Le(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 Qe=Pr.current;if(Qe.length===0){C(ke=>ke==="closed"?"empty":ke);return}const kt=Yt.current?.id??Gt.current?.id??null;let mt=kt?Qe.findIndex(ke=>ke.data.id===kt):-1;mt<0&&(mt=Ne>0?-1:0);const Oe=Math.max(0,Math.min(Qe.length-1,mt+Ne));On(Qe[Oe]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${Qe[Oe].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",U,!0),()=>document.removeEventListener("keydown",U,!0)},[n,l,i,Mr,Eo,Ot,Zt,On,S,d]),ue)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:r("work:task.loadingPage")});const Io=$!=="closed"||!!(Ge||ze),$r=!l&&!!(Ge&&ze)&&$==="item",To=l?O:Io;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:Lr,totalTaskCount:Dr,onSelectAll:()=>{Zt(),W("projects")},onSelectProject:w=>{Ot(w),W("projects")},onCreateProject:()=>re(!0),onCollapse:()=>{const w=!x;S(w),d?.setLeftCollapsed(w)},width:v.width,onResizeStart:v.onResizeStart,hidden:x,focused:ir==="l1"&&V==="projects"&&!x,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(Zl,{}),wt?t.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[t.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:wt.name}),t.jsx("button",{onClick:Mr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${$==="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 ${et===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 ${je?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:je?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||Je?"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+(Je?1:0)>0?r("work:task.filterWithCount",{count:He.size+(Je?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(Th,{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 ${je?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:je?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 ${et===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&&et!=="workflows"&&(Ar.length>0||e?.id)&&(Ol>0||Kt.length>0||He.size>0||Je)&&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||Je?"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 ${Je?"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")}),Ar.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(Ne=>He.has(Ne)),he=!ne&&w.agentIds.some(Ne=>He.has(Ne));return t.jsxs("button",{onClick:()=>{dt(Ne=>{const we=new Set(Ne);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:()=>wo(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&&Kt.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||Je?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")})]})]})]})}):et==="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(Yh,{tasks:or(Object.values(H).flat()),requirements:Kt,agents:J,projects:R,onTaskClick:w=>Ir(w),onReqClick:w=>Tr(w),onRefresh:()=>{rt(),Rt()},selectedTaskId:Ge?.id,selectedReqId:ze?.id})}):et==="workflows"?t.jsx(Xh,{teamId:jl,projectId:F,agents:J,projects:R,onViewRunTasks:w=>{const U=ne=>{Ln(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(()=>{})}}):et==="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]:Kt,agents:J,showArchived:je,onShowArchivedChange:Me,onTaskClick:w=>Ir(w),onReqClick:w=>Tr(w),onCollapseDAG:()=>{Le(null),De(null),ot(null)},onDependencyChange:rt,selectedTaskId:Ge?.id,selectedReqId:ze?.id,hasDetailPanel:Io,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=ko(w),ee=jo(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:Ne=>Rl(Ne,w.id),onDragLeave:Ne=>_l(Ne,w.id),onDrop:Ne=>{Al(Ne,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 Ne=[...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 Ne.sort((we,oe)=>oe.time-we.time),Ne.map(we=>{if(we.kind==="req"){const oe=we.data,Qe=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(Te=>Te.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:Te=>Tl(Te,oe),onDragEnd:vo,onClick:()=>Tr(oe),onKeyDown:Te=>Te.key==="Enter"&&Tr(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
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 ${Qe.cls}`,children:Qe.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:Te=>{Te.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:Te=>{Te.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,Qe=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,Te=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"},Ro=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:vo,onClick:()=>Ir(oe),onKeyDown:at=>at.key==="Enter"&&Ir(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Ro?"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}),Ro&&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||Te||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}),Te&&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:Te,children:["# ",Te]}),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:[Qe>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Qe]}),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&&To&&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"})}),To&&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(qh,{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(Xa,{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=>{yo(w),De(null)},onStatusChange:async(w,U)=>{try{await ae.requirements.updateStatus(w,U),ct(`Requirement status → ${U}`),$n({requirementId:w}),kn(),rt()}catch(ee){ct(`Error: ${ee}`)}},onRefresh:kn,authUser:e,onTaskClick:w=>{Le(w),C("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(Fa,{task:Ge,agents:J,projects:R,requirements:se,allTasks:Object.values(H).flat(),users:ie,onClose:Nl,onRefresh:xo,authUser:e,scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{De(U=>U?.id===w.id?null:w),C("item")},onProjectClick:Rr})})]}):Ge?t.jsx(Fa,{task:Ge,agents:J,projects:R,requirements:se,allTasks:Object.values(H).flat(),users:ie,onClose:yn,onRefresh:xo,authUser:e,scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{De(w),Le(null),C("item")},onProjectClick:Rr}):ze?t.jsx(Xa,{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=>{yo(w),yn()},onStatusChange:async(w,U)=>{try{await ae.requirements.updateStatus(w,U),ct(`Requirement status → ${U}`),$n({requirementId:w}),kn(),rt()}catch(ee){ct(`Error: ${ee}`)}},scrollToComments:ps,onScrollToCommentsDone:()=>rr(!1),onRefresh:kn,authUser:e,onTaskClick:w=>{Le(w),De(null),C("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=>Re(w.target.value),onKeyDown:w=>{w.key==="Enter"&&po()},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=>nt(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 ${Ue==="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:Ue,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")})]})]}),Ue==="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=>Ae([...$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:()=>Ae($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:()=>{po()},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()&&bo()}})]}),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:()=>{bo()},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})]}),lo&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:lo}),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||Je)&&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:()=>{Zt(),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=Lr[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 ${Je?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:r("work:task.myTasks")})}),Ar.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:Ar.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(Ne=>He.has(Ne)),he=!ne&&w.agentIds.some(Ne=>He.has(Ne));return t.jsxs("button",{onClick:()=>{dt(Ne=>{const we=new Set(Ne);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:()=>wo(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 Uh({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 p=v.payload.comment;c(b=>b.some(k=>k.id===p.id)?b:[...b,p]),(p.authorType==="agent"||p.authorId?.startsWith("agt_"))&&(d(b=>{const k=b.filter(N=>N.id!==p.authorId);return k.length===0&&h.current&&(clearTimeout(h.current),h.current=null),k}),m(b=>{const k=new Map(b);return k.delete(p.authorId),k}))}}),[e]),g.useEffect(()=>{if(l.length===0)return;const y=new Set(l.map(p=>p.id));return jt.on("agent:activity_log",p=>{const b=p.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,x]=g.useState(null),M=async(y,v,p,b)=>{let k;p.length>0&&(k=(await ae.uploads.upload(p.map(A=>({dataUrl:A.dataUrl,name:A.name})),"comments")).files.map(A=>({type:"image",url:A.url,name:A.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 A=s.find(E=>E.id===D);A&&N.push({id:A.id,name:A.name,avatarUrl:A.avatarUrl})};for(const D of v){const A=s.find(E=>E.name.toLowerCase()===D.toLowerCase());A&&B(A.id)}n?.startsWith("agt_")&&B(n),N.length>0&&(h.current&&clearTimeout(h.current),d(N),h.current=setTimeout(()=>d([]),12e4))},S=g.useCallback(y=>{x({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:S},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(ei,{agents:s,humans:r,onSubmit:M,replyTo:u,onCancelReply:()=>x(null)})]})}function Xa({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:x,onCreateTask:M,onProjectClick:S,previewMode:y}){const{t:v}=We(["work","common"]),p=g.useMemo(()=>ao(v),[v]),b=g.useMemo(()=>yl(v),[v]),k=vr(),[N,I]=g.useState(!1),[B,D]=g.useState(e.description),[A,E]=g.useState(!1),[P,z]=g.useState(!1),[j,O]=g.useState(!1),_=g.useRef(null),[T,R]=g.useState("none"),L=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 Z=de<30,ce=de+me>=se-30;R(Z?"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=p[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},Q=e.source==="agent",$=Q&&e.status==="pending",C=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),K=r.filter(te=>e.taskIds.includes(te.id)),J=W?.teamIds?.[0]??null;g.useMemo(()=>new Map(K.map(te=>[te.id,te])),[K]);const le=K.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:L,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(L.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 ${S?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:S?()=>S(W.id):void 0,role:S?"button":void 0,tabIndex:S?0:void 0,onKeyDown:S?te=>te.key==="Enter"&&S(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:K.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")]})]})]}),K.length>0?(()=>{const te=new Map(K.map(ue=>[ue.id,ue]));if(!K.some(ue=>ue.blockedBy?.some(Z=>te.has(Z))))return t.jsx("div",{className:"space-y-1.5",children:K.map(ue=>{const Z=b[ue.status];return t.jsxs("div",{onClick:()=>x?.(ue),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${x?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${yr[ue.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ue.title}),Z&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Z.cls}`,children:Z.label})]},ue.id)})});const ie=new Map,de=new Set;for(const ue of K)for(const Z of ue.blockedBy??[])if(te.has(Z)){de.add(ue.id);const ce=ie.get(Z)??[];ce.push(ue.id),ie.set(Z,ce)}const se=K.filter(ue=>!de.has(ue.id)),me=(ue,Z)=>{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:()=>x?.(ue),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${x?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:Z>0?{marginLeft:Z*20}:void 0,children:[Z>0&&t.jsx("span",{className:"text-fg-quaternary text-[10px] shrink-0",children:"↳"}),t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${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,Z+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(Uh,{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:Fh.map(te=>{const X=p[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"}),C&&!$&&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(Kh,{req:e,tasks:K,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"),x=m.changedByType==="human"?"bg-blue-500/20 text-blue-500":m.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${x}`,children:u})};return t.jsxs("div",{className:"px-6 py-4",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:s("work:task.statusHistory","Status History")}),h&&t.jsx("button",{onClick:()=>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{rm as WorkPage};